PS_NITPICKS_20240626_SEQ_0001.txt
text/plain
Filename: PS_NITPICKS_20240626_SEQ_0001.txt
Type: text/plain
Part: 0
Message:
Re: Logical Replication of sequences
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index 57453a7..9bad121 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -349,7 +349,7 @@ SetSequence(Oid seq_relid, int64 value)
/* open and lock sequence */
init_sequence(seq_relid, &elm, &seqrel);
- /* lock page' buffer and read tuple */
+ /* lock page buffer and read tuple */
seq = read_seq_tuple(seqrel, &buf, &seqdatatuple, NULL);
/* check the comment above nextval_internal()'s equivalent call. */
@@ -397,8 +397,10 @@ SetSequence(Oid seq_relid, int64 value)
UnlockReleaseBuffer(buf);
- /* Clear local cache so that we don't think we have cached numbers */
- /* Note that we do not change the currval() state */
+ /*
+ * 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;
relation_close(seqrel, NoLock);
@@ -1275,8 +1277,9 @@ read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple,
RelationGetRelationName(rel), sm->magic);
/*
- * If the caller requested it, set the page LSN. This allows deciding
- * which sequence changes are before/after the returned sequence state.
+ * If the caller requested it, return the page LSN. This allows the
+ * caller to determine which sequence changes are before/after the
+ * returned sequence state.
*/
if (lsn)
*lsn = PageGetLSN(page);
@@ -1912,7 +1915,7 @@ pg_sequence_last_value(PG_FUNCTION_ARGS)
Datum
pg_sequence_state(PG_FUNCTION_ARGS)
{
- Oid relid = PG_GETARG_OID(0);
+ Oid seq_relid = PG_GETARG_OID(0);
SeqTable elm;
Relation seqrel;
Buffer buf;
@@ -1920,21 +1923,21 @@ pg_sequence_state(PG_FUNCTION_ARGS)
Form_pg_sequence_data seq;
Datum result;
+ XLogRecPtr lsn;
int64 last_value;
int64 log_cnt;
bool is_called;
- XLogRecPtr lsn;
TupleDesc tupdesc;
HeapTuple tuple;
Datum values[4];
- bool nulls[4];
+ bool nulls[4] = {false, false, false, false};
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "return type must be a row type");
/* open and lock sequence */
- init_sequence(relid, &elm, &seqrel);
+ init_sequence(seq_relid, &elm, &seqrel);
if (pg_class_aclcheck(elm->relid, GetUserId(),
ACL_SELECT | ACL_USAGE) != ACLCHECK_OK)
@@ -1957,8 +1960,6 @@ pg_sequence_state(PG_FUNCTION_ARGS)
values[2] = Int64GetDatum(log_cnt);
values[3] = BoolGetDatum(is_called);
- memset(nulls, 0, sizeof(nulls));
-
tuple = heap_form_tuple(tupdesc, values, nulls);
result = HeapTupleGetDatum(tuple);