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
|
* 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);
|
seq = read_info(elm, seqrel, &buf);
|
||||||
page = BufferGetPage(buf);
|
page = BufferGetPage(buf);
|
||||||
|
|
||||||
/* copy old values of options */
|
/* Copy old values of options into workspace */
|
||||||
new.increment_by = seq->increment_by;
|
memcpy(&new, seq, sizeof(FormData_pg_sequence));
|
||||||
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;
|
|
||||||
|
|
||||||
/* Check and set new values */
|
/* Check and set new values */
|
||||||
init_params(stmt->options, &new, false);
|
init_params(stmt->options, &new, false);
|
||||||
|
|
||||||
/* Now okay to update the on-disk tuple */
|
/* Now okay to update the on-disk tuple */
|
||||||
seq->increment_by = new.increment_by;
|
memcpy(seq, &new, sizeof(FormData_pg_sequence));
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save info in local cache */
|
/* Clear local cache so that we don't think we have cached numbers */
|
||||||
elm->last = new.last_value; /* last returned number */
|
elm->last = new.last_value; /* last returned number */
|
||||||
elm->cached = new.last_value; /* last cached number (forget
|
elm->cached = new.last_value; /* last cached number (forget
|
||||||
* cached values) */
|
* cached values) */
|
||||||
|
|
||||||
@ -1008,13 +993,19 @@ init_params(List *options, Form_pg_sequence new, bool isInit)
|
|||||||
|
|
||||||
/* START WITH */
|
/* START WITH */
|
||||||
if (last_value != NULL)
|
if (last_value != NULL)
|
||||||
|
{
|
||||||
new->last_value = defGetInt64(last_value);
|
new->last_value = defGetInt64(last_value);
|
||||||
|
new->is_called = false;
|
||||||
|
new->log_cnt = 1;
|
||||||
|
}
|
||||||
else if (isInit)
|
else if (isInit)
|
||||||
{
|
{
|
||||||
if (new->increment_by > 0)
|
if (new->increment_by > 0)
|
||||||
new->last_value = new->min_value; /* ascending seq */
|
new->last_value = new->min_value; /* ascending seq */
|
||||||
else
|
else
|
||||||
new->last_value = new->max_value; /* descending seq */
|
new->last_value = new->max_value; /* descending seq */
|
||||||
|
new->is_called = false;
|
||||||
|
new->log_cnt = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* crosscheck */
|
/* crosscheck */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user