ALTER SEQUENCE RESTART did the wrong thing if sequence last_value was
authorTom Lane
Tue, 6 Apr 2004 16:39:30 +0000 (16:39 +0000)
committerTom Lane
Tue, 6 Apr 2004 16:39:30 +0000 (16:39 +0000)
equal to the desired restart value (must clear is_called, did not).
Per bug report #1127 from Piotr Konieczny.

src/backend/commands/sequence.c

index 1d487b6d98b121cfae85bb35c2c90a66d15662d5..de4499124d58a98729d7ccdc9d9c7336eccba7a7 100644 (file)
@@ -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 */