Re: BUG #1127: ALTER SEQUENCE bug

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Piotr Konieczny" <znahor(at)vix(dot)netsync(dot)pl>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1127: ALTER SEQUENCE bug
Date: 2004-04-06 16:40:43
Message-ID: 27441.1081269643@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org> writes:
> ALTER SEQUENCE doesn't work properly, when only first value has been readed
> from sequence:

Yup, you're right; this was sloppily coded. I've applied the attached
patch.

regards, tom lane

Index: sequence.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/sequence.c,v
retrieving revision 1.103.2.1
diff -c -r1.103.2.1 sequence.c
*** sequence.c 24 Nov 2003 16:54:15 -0000 1.103.2.1
--- sequence.c 6 Apr 2004 16:28:03 -0000
***************
*** 315,346 ****
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;

/* 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;
! }

! /* save info in local cache */
! elm->last = new.last_value; /* last returned number */
elm->cached = new.last_value; /* last cached number (forget
* cached values) */

--- 315,331 ----
seq = read_info(elm, seqrel, &buf);
page = BufferGetPage(buf);

! /* 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 */
! memcpy(seq, &new, sizeof(FormData_pg_sequence));

! /* 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,1020 ****
--- 993,1011 ----

/* START WITH */
if (last_value != (DefElem *) 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 */

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-04-06 19:05:33 Re: could not devise a query plan
Previous Message Tom Lane 2004-04-06 15:14:13 Re: BUG #1128: horology tests fails while make check (7.4.2)