Skip to content

Commit 2098ec6

Browse files
committed
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.
1 parent 055b0d2 commit 2098ec6

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/backend/commands/sequence.c

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.108 2004/01/10 23:28:44 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.109 2004/04/06 16:39:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -315,32 +315,17 @@ AlterSequence(AlterSeqStmt *stmt)
315315
seq = read_info(elm, seqrel, &buf);
316316
page = BufferGetPage(buf);
317317

318-
/* copy old values of options */
319-
new.increment_by = seq->increment_by;
320-
new.max_value = seq->max_value;
321-
new.min_value = seq->min_value;
322-
new.cache_value = seq->cache_value;
323-
new.is_cycled = seq->is_cycled;
324-
new.last_value = seq->last_value;
318+
/* Copy old values of options into workspace */
319+
memcpy(&new, seq, sizeof(FormData_pg_sequence));
325320

326321
/* Check and set new values */
327322
init_params(stmt->options, &new, false);
328323

329324
/* Now okay to update the on-disk tuple */
330-
seq->increment_by = new.increment_by;
331-
seq->max_value = new.max_value;
332-
seq->min_value = new.min_value;
333-
seq->cache_value = new.cache_value;
334-
seq->is_cycled = new.is_cycled;
335-
if (seq->last_value != new.last_value)
336-
{
337-
seq->last_value = new.last_value;
338-
seq->is_called = false;
339-
seq->log_cnt = 1;
340-
}
325+
memcpy(seq, &new, sizeof(FormData_pg_sequence));
341326

342-
/* save info in local cache */
343-
elm->last = new.last_value; /* last returned number */
327+
/* Clear local cache so that we don't think we have cached numbers */
328+
elm->last = new.last_value; /* last returned number */
344329
elm->cached = new.last_value; /* last cached number (forget
345330
* cached values) */
346331

@@ -1008,13 +993,19 @@ init_params(List *options, Form_pg_sequence new, bool isInit)
1008993

1009994
/* START WITH */
1010995
if (last_value != NULL)
996+
{
1011997
new->last_value = defGetInt64(last_value);
998+
new->is_called = false;
999+
new->log_cnt = 1;
1000+
}
10121001
else if (isInit)
10131002
{
10141003
if (new->increment_by > 0)
10151004
new->last_value = new->min_value; /* ascending seq */
10161005
else
10171006
new->last_value = new->max_value; /* descending seq */
1007+
new->is_called = false;
1008+
new->log_cnt = 1;
10181009
}
10191010

10201011
/* crosscheck */

0 commit comments

Comments
 (0)