mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
ALTER SEQUENCE RESTART did the wrong thing if sequence last_value was
equal to the desired restart value (must clear is_called, did not). Per bug report #1127 from Piotr Konieczny.
This commit is contained in:
parent
055b0d27f6
commit
2098ec6e37
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.108 2004/01/10 23:28:44 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.109 2004/04/06 16:39:30 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -315,32 +315,17 @@ AlterSequence(AlterSeqStmt *stmt)
|
||||
seq = read_info(elm, seqrel, &buf);
|
||||
page = BufferGetPage(buf);
|
||||
|
||||
/* copy old values of options */
|
||||
new.increment_by = seq->increment_by;
|
||||
new.max_value = seq->max_value;
|
||||
new.min_value = seq->min_value;
|
||||
new.cache_value = seq->cache_value;
|
||||
new.is_cycled = seq->is_cycled;
|
||||
new.last_value = seq->last_value;
|
||||
/* Copy old values of options into workspace */
|
||||
memcpy(&new, seq, sizeof(FormData_pg_sequence));
|
||||
|
||||
/* Check and set new values */
|
||||
init_params(stmt->options, &new, false);
|
||||
|
||||
/* Now okay to update the on-disk tuple */
|
||||
seq->increment_by = new.increment_by;
|
||||
seq->max_value = new.max_value;
|
||||
seq->min_value = new.min_value;
|
||||
seq->cache_value = new.cache_value;
|
||||
seq->is_cycled = new.is_cycled;
|
||||
if (seq->last_value != new.last_value)
|
||||
{
|
||||
seq->last_value = new.last_value;
|
||||
seq->is_called = false;
|
||||
seq->log_cnt = 1;
|
||||
}
|
||||
memcpy(seq, &new, sizeof(FormData_pg_sequence));
|
||||
|
||||
/* save info in local cache */
|
||||
elm->last = new.last_value; /* last returned number */
|
||||
/* Clear local cache so that we don't think we have cached numbers */
|
||||
elm->last = new.last_value; /* last returned number */
|
||||
elm->cached = new.last_value; /* last cached number (forget
|
||||
* cached values) */
|
||||
|
||||
@ -1008,13 +993,19 @@ init_params(List *options, Form_pg_sequence new, bool isInit)
|
||||
|
||||
/* START WITH */
|
||||
if (last_value != NULL)
|
||||
{
|
||||
new->last_value = defGetInt64(last_value);
|
||||
new->is_called = false;
|
||||
new->log_cnt = 1;
|
||||
}
|
||||
else if (isInit)
|
||||
{
|
||||
if (new->increment_by > 0)
|
||||
new->last_value = new->min_value; /* ascending seq */
|
||||
else
|
||||
new->last_value = new->max_value; /* descending seq */
|
||||
new->is_called = false;
|
||||
new->log_cnt = 1;
|
||||
}
|
||||
|
||||
/* crosscheck */
|
||||
|
Loading…
Reference in New Issue
Block a user