aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/sequence.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-10-25 19:15:01 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-10-25 19:15:01 +0000
commit9f3309858f6520d0d7b71d40f563bf08af769259 (patch)
tree5a34eda350716a482ff8a64b0d98e9e98cc17198 /src/backend/commands/sequence.c
parent72fb03b8c87acfb4c5be253f086170b8e20d7101 (diff)
downloadpostgresql-9f3309858f6520d0d7b71d40f563bf08af769259.tar.gz
postgresql-9f3309858f6520d0d7b71d40f563bf08af769259.zip
Ugly patch to make ALTER SEQUENCE OWNED BY not affect the currval() state
of the sequence. Since OWNED BY never existed before 8.2, this seems unlikely to create any compatibility issues. Other forms of ALTER SEQUENCE continue to do what they did before, namely update currval to match the sequence's actual last_val. That seems wrong on consideration, but we'll not change it in a minor release --- 8.3 will make that fix.
Diffstat (limited to 'src/backend/commands/sequence.c')
-rw-r--r--src/backend/commands/sequence.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index b73069cf1b6..9404efa379f 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.141 2006/10/06 17:13:58 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.141.2.1 2007/10/25 19:15:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -315,6 +315,7 @@ AlterSequence(AlterSeqStmt *stmt)
Form_pg_sequence seq;
FormData_pg_sequence new;
List *owned_by;
+ int64 save_increment;
/* open and AccessShareLock sequence */
relid = RangeVarGetRelid(stmt->sequence, false);
@@ -325,6 +326,9 @@ AlterSequence(AlterSeqStmt *stmt)
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
stmt->sequence->relname);
+ /* hack to keep ALTER SEQUENCE OWNED BY from changing currval state */
+ save_increment = elm->increment;
+
/* lock page' buffer and read tuple into new sequence structure */
seq = read_info(elm, seqrel, &buf);
page = BufferGetPage(buf);
@@ -338,10 +342,18 @@ AlterSequence(AlterSeqStmt *stmt)
/* 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
+ if (owned_by)
+ {
+ /* Restore previous state of elm (assume nothing else changes) */
+ elm->increment = save_increment;
+ }
+ else
+ {
+ /* 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) */
+ }
START_CRIT_SECTION();