PS_NITPICKS_20240703_SEQ_0001.txt

text/plain

Filename: PS_NITPICKS_20240703_SEQ_0001.txt
Type: text/plain
Part: 0
Message: Re: Logical Replication of sequences
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 3dd4805..83f87c1 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -19521,11 +19521,11 @@ SELECT setval('myseq', 42, false);    <lineannotation>Next <function>nextval</fu
        </para>
        <para>
         Returns information about the sequence. <literal>lsn</literal> is the
-        page lsn of the sequence, <literal>last_value</literal> is the value
-        most recently returned by <function>nextval</function> in the current
+        page lsn of the sequence, <literal>last_value</literal> is the most
+        recent value returned by <function>nextval</function> in the current
         session, <literal>log_cnt</literal> shows how many fetches remain
-        before a new WAL record has to be written and
-        <literal>is_called</literal> indicates whethere the sequence has been
+        before a new WAL record has to be written, and
+        <literal>is_called</literal> indicates whether the sequence has been
         used.
        </para>
        <para>
diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c
index cd7639f..f33f689 100644
--- a/src/backend/commands/sequence.c
+++ b/src/backend/commands/sequence.c
@@ -338,7 +338,7 @@ ResetSequence(Oid seq_relid)
  * responsible for permissions checking.
  *
  * Note: This function resembles do_setval but does not include the locking and
- * verification steps, as those are managed in a slightly diffrent manner for
+ * verification steps, as those are managed in a slightly different manner for
  * logical replication.
  */
 void
@@ -1262,7 +1262,9 @@ init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel)
  * *buf receives the reference to the pinned-and-ex-locked buffer
  * *seqdatatuple receives the reference to the sequence tuple proper
  *		(this arg should point to a local variable of type HeapTupleData)
- * *lsn_ret will be set to page LSN if the caller requested it
+ * *lsn_ret will be set to the page LSN if the caller requested it.
+ *		This allows the caller to determine which sequence changes are
+ *		before/after the returned sequence state.
  *
  * Function's return value points to the data payload of the tuple
  */
@@ -1285,11 +1287,7 @@ read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple,
 		elog(ERROR, "bad magic number in sequence \"%s\": %08X",
 			 RelationGetRelationName(rel), sm->magic);
 
-	/*
-	 * 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 the caller requested it, return the page LSN. */
 	if (lsn_ret)
 		*lsn_ret = PageGetLSN(page);
 
@@ -1957,9 +1955,9 @@ pg_sequence_state(PG_FUNCTION_ARGS)
 
 	seq = read_seq_tuple(seqrel, &buf, &seqtuple, &lsn);
 
-	is_called = seq->is_called;
 	last_value = seq->last_value;
 	log_cnt = seq->log_cnt;
+	is_called = seq->is_called;
 
 	UnlockReleaseBuffer(buf);
 	relation_close(seqrel, NoLock);
@@ -1970,13 +1968,10 @@ pg_sequence_state(PG_FUNCTION_ARGS)
 	/* The value most recently returned by nextval in the current session */
 	values[1] = Int64GetDatum(last_value);
 
-	/*
-	 * Shows how many fetches remain before a new WAL record has to be
-	 * written.
-	 */
+	/* How many fetches remain before a new WAL record has to be written */
 	values[2] = Int64GetDatum(log_cnt);
 
-	/* Indicates whethere the sequence has been used */
+	/* Indicates whether the sequence has been used */
 	values[3] = BoolGetDatum(is_called);
 
 	tuple = heap_form_tuple(tupdesc, values, nulls);