aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/sequence.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2024-02-26 17:03:18 +0900
committerMichael Paquier <michael@paquier.xyz>2024-02-26 17:03:18 +0900
commit6e951bf98e2e0230ed95db2fafc244536bd7502f (patch)
tree741ea1218304a3328fa835aae0a1cf18d37651a8 /src/backend/commands/sequence.c
parent449e798c77ed9a03f8bb04e5d324d4e3cfbbae8e (diff)
downloadpostgresql-6e951bf98e2e0230ed95db2fafc244536bd7502f.tar.gz
postgresql-6e951bf98e2e0230ed95db2fafc244536bd7502f.zip
Group more closely cache updates for backends in sequence.c
Information of sequences is cached for each backend for currval() and nextval(), and the update of some cached information was mixed in the middle of computations based on the other properties of a sequence, for the increment value in nextval() and the cached state when altering a sequence. Grouping them makes the code easier to follow and to refactor in the future, when splitting the computation and the SeqTable change parts. Note that the cached data is untouched between the areas where these cache updates are moved. Issue noticed while doing some refactoring of the sequence code. Author: Michael Paquier Reviewed-by: Tomas Vondra Discussion: https://postgr.es/m/ZWlohtKAs0uVVpZ3@paquier.xyz
Diffstat (limited to 'src/backend/commands/sequence.c')
-rw-r--r--src/backend/commands/sequence.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index d019fbdede6..1bed9c74d17 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -489,10 +489,6 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
seqform, newdataform,
&need_seq_rewrite, &owned_by);
- /* Clear local cache so that we don't think we have cached numbers */
- /* Note that we do not change the currval() state */
- elm->cached = elm->last;
-
/* If needed, rewrite the sequence relation itself */
if (need_seq_rewrite)
{
@@ -520,6 +516,10 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
fill_seq_with_data(seqrel, newdatatuple);
}
+ /* Clear local cache so that we don't think we have cached numbers */
+ /* Note that we do not change the currval() state */
+ elm->cached = elm->last;
+
/* process OWNED BY if given */
if (owned_by)
process_owned_by(seqrel, owned_by, stmt->for_identity);
@@ -683,7 +683,6 @@ nextval_internal(Oid relid, bool check_permissions)
seq = read_seq_tuple(seqrel, &buf, &seqdatatuple);
page = BufferGetPage(buf);
- elm->increment = incby;
last = next = result = seq->last_value;
fetch = cache;
log = seq->log_cnt;
@@ -781,6 +780,7 @@ nextval_internal(Oid relid, bool check_permissions)
Assert(log >= 0);
/* save info in local cache */
+ elm->increment = incby;
elm->last = result; /* last returned number */
elm->cached = last; /* last fetched number */
elm->last_valid = true;