static void init_params(ParseState *pstate, List *options, bool for_identity,
bool isInit,
Form_pg_sequence seqform,
+ bool *changed_seqform,
Form_pg_sequence_data seqdataform, List **owned_by);
static void do_setval(Oid relid, int64 next, bool iscalled);
static void process_owned_by(Relation seqrel, List *owned_by, bool for_identity);
{
FormData_pg_sequence seqform;
FormData_pg_sequence_data seqdataform;
+ bool changed_seqform = false; /* not used here */
List *owned_by;
CreateStmt *stmt = makeNode(CreateStmt);
Oid seqoid;
}
/* Check and set all option values */
- init_params(pstate, seq->options, seq->for_identity, true, &seqform, &seqdataform, &owned_by);
+ init_params(pstate, seq->options, seq->for_identity, true, &seqform, &changed_seqform, &seqdataform, &owned_by);
/*
* Create relation (and fill value[] and null[] for the tuple)
Form_pg_sequence seqform;
Form_pg_sequence_data seqdata;
FormData_pg_sequence_data newseqdata;
+ bool changed_seqform = false;
List *owned_by;
ObjectAddress address;
Relation rel;
/* lock page' buffer and read tuple into new sequence structure */
seqdata = read_seq_tuple(seqrel, &buf, &seqdatatuple);
- /* Copy old values of options into workspace */
+ /* Copy old sequence data into workspace */
memcpy(&newseqdata, seqdata, sizeof(FormData_pg_sequence_data));
rel = heap_open(SequenceRelationId, RowExclusiveLock);
seqform = (Form_pg_sequence) GETSTRUCT(tuple);
/* Check and set new values */
- init_params(pstate, stmt->options, stmt->for_identity, false, seqform, &newseqdata, &owned_by);
+ init_params(pstate, stmt->options, stmt->for_identity, false, seqform, &changed_seqform, &newseqdata, &owned_by);
/* Clear local cache so that we don't think we have cached numbers */
/* Note that we do not change the currval() state */
relation_close(seqrel, NoLock);
- CatalogTupleUpdate(rel, &tuple->t_self, tuple);
+ if (changed_seqform)
+ CatalogTupleUpdate(rel, &tuple->t_self, tuple);
heap_close(rel, RowExclusiveLock);
return address;
}
/*
- * init_params: process the options list of CREATE or ALTER SEQUENCE,
- * and store the values into appropriate fields of *new. Also set
- * *owned_by to any OWNED BY option, or to NIL if there is none.
+ * init_params: process the options list of CREATE or ALTER SEQUENCE, and
+ * store the values into appropriate fields of seqform, for changes that go
+ * into the pg_sequence catalog, and seqdataform for changes to the sequence
+ * relation itself. Set *changed_seqform to true if seqform was changed
+ * (interesting for ALTER SEQUENCE). Also set *owned_by to any OWNED BY
+ * option, or to NIL if there is none.
*
* If isInit is true, fill any unspecified options with default values;
* otherwise, do not change existing options that aren't explicitly overridden.
init_params(ParseState *pstate, List *options, bool for_identity,
bool isInit,
Form_pg_sequence seqform,
- Form_pg_sequence_data seqdataform, List **owned_by)
+ bool *changed_seqform,
+ Form_pg_sequence_data seqdataform,
+ List **owned_by)
{
DefElem *as_type = NULL;
DefElem *start_value = NULL;
defel->defname);
}
+ *changed_seqform = false;
+
/*
* We must reset log_cnt when isInit or when changing any parameters that
* would affect future nextval allocations.
}
seqform->seqtypid = newtypid;
+ *changed_seqform = true;
}
else if (isInit)
+ {
seqform->seqtypid = INT8OID;
+ *changed_seqform = true;
+ }
/* INCREMENT BY */
if (increment_by != NULL)
{
seqform->seqincrement = defGetInt64(increment_by);
+ *changed_seqform = true;
if (seqform->seqincrement == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
seqdataform->log_cnt = 0;
}
else if (isInit)
+ {
seqform->seqincrement = 1;
+ *changed_seqform = true;
+ }
/* CYCLE */
if (is_cycled != NULL)
{
seqform->seqcycle = intVal(is_cycled->arg);
+ *changed_seqform = true;
Assert(BoolIsValid(seqform->seqcycle));
seqdataform->log_cnt = 0;
}
else if (isInit)
+ {
seqform->seqcycle = false;
+ *changed_seqform = true;
+ }
/* MAXVALUE (null arg means NO MAXVALUE) */
if (max_value != NULL && max_value->arg)
{
seqform->seqmax = defGetInt64(max_value);
+ *changed_seqform = true;
seqdataform->log_cnt = 0;
}
else if (isInit || max_value != NULL || reset_max_value)
}
else
seqform->seqmax = -1; /* descending seq */
+ *changed_seqform = true;
seqdataform->log_cnt = 0;
}
if (min_value != NULL && min_value->arg)
{
seqform->seqmin = defGetInt64(min_value);
+ *changed_seqform = true;
seqdataform->log_cnt = 0;
}
else if (isInit || min_value != NULL || reset_min_value)
}
else
seqform->seqmin = 1; /* ascending seq */
+ *changed_seqform = true;
seqdataform->log_cnt = 0;
}
/* START WITH */
if (start_value != NULL)
+ {
seqform->seqstart = defGetInt64(start_value);
+ *changed_seqform = true;
+ }
else if (isInit)
{
if (seqform->seqincrement > 0)
seqform->seqstart = seqform->seqmin; /* ascending seq */
else
seqform->seqstart = seqform->seqmax; /* descending seq */
+ *changed_seqform = true;
}
/* crosscheck START */
if (cache_value != NULL)
{
seqform->seqcache = defGetInt64(cache_value);
+ *changed_seqform = true;
if (seqform->seqcache <= 0)
{
char buf[100];
seqdataform->log_cnt = 0;
}
else if (isInit)
+ {
seqform->seqcache = 1;
+ *changed_seqform = true;
+ }
}
/*