Rename pg_sequence_read_tuple() to pg_get_sequence_data()
authorMichael Paquier <[email protected]>
Thu, 29 Aug 2024 23:49:24 +0000 (08:49 +0900)
committerMichael Paquier <[email protected]>
Thu, 29 Aug 2024 23:49:24 +0000 (08:49 +0900)
This commit removes log_cnt from the tuple returned by the SQL function.
This field is an internal counter that tracks when a WAL record should
be generated for a sequence, and it is reset each time the sequence is
restored or recovered.  It is not necessary to rebuild the sequence DDL
commands for pg_dump and pg_upgrade where this function is used.  The
field can still be queried with a scan of the "table" created
under-the-hood for a sequence.

Issue noticed while hacking on a feature that can rely on this new
function rather than pg_sequence_last_value(), aimed at making sequence
computation more easily pluggable.

Bump catalog version.

Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/[email protected]

src/backend/commands/sequence.c
src/bin/pg_dump/pg_dump.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/test/regress/expected/sequence.out
src/test/regress/sql/sequence.sql

index 8c1131f02028595316f3a06248b770f13f8c08bc..b37fd688d34bfd8a235ad2aed342f9e9ed7119ec 100644 (file)
@@ -1781,23 +1781,22 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
  * without needing to individually query each sequence relation.
  */
 Datum
-pg_sequence_read_tuple(PG_FUNCTION_ARGS)
+pg_get_sequence_data(PG_FUNCTION_ARGS)
 {
+#define PG_GET_SEQUENCE_DATA_COLS  2
    Oid         relid = PG_GETARG_OID(0);
    SeqTable    elm;
    Relation    seqrel;
-   Datum       values[SEQ_COL_LASTCOL] = {0};
-   bool        isnull[SEQ_COL_LASTCOL] = {0};
+   Datum       values[PG_GET_SEQUENCE_DATA_COLS] = {0};
+   bool        isnull[PG_GET_SEQUENCE_DATA_COLS] = {0};
    TupleDesc   resultTupleDesc;
    HeapTuple   resultHeapTuple;
    Datum       result;
 
-   resultTupleDesc = CreateTemplateTupleDesc(SEQ_COL_LASTCOL);
+   resultTupleDesc = CreateTemplateTupleDesc(PG_GET_SEQUENCE_DATA_COLS);
    TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "last_value",
                       INT8OID, -1, 0);
-   TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "log_cnt",
-                      INT8OID, -1, 0);
-   TupleDescInitEntry(resultTupleDesc, (AttrNumber) 3, "is_called",
+   TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "is_called",
                       BOOLOID, -1, 0);
    resultTupleDesc = BlessTupleDesc(resultTupleDesc);
 
@@ -1818,8 +1817,7 @@ pg_sequence_read_tuple(PG_FUNCTION_ARGS)
        seq = read_seq_tuple(seqrel, &buf, &seqtuple);
 
        values[0] = Int64GetDatum(seq->last_value);
-       values[1] = Int64GetDatum(seq->log_cnt);
-       values[2] = BoolGetDatum(seq->is_called);
+       values[1] = BoolGetDatum(seq->is_called);
 
        UnlockReleaseBuffer(buf);
    }
@@ -1831,6 +1829,7 @@ pg_sequence_read_tuple(PG_FUNCTION_ARGS)
    resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
    result = HeapTupleGetDatum(resultHeapTuple);
    PG_RETURN_DATUM(result);
+#undef PG_GET_SEQUENCE_DATA_COLS
 }
 
 
index b6e01d3d2923d09cf17d91321ded261c3e982e91..f7720ad53b749d9b218da8363a59f427ba97f5fd 100644 (file)
@@ -17381,7 +17381,7 @@ collectSequences(Archive *fout)
     * versions, but for now it seems unlikely to be worth it.
     *
     * Since version 18, we can gather the sequence data in this query with
-    * pg_sequence_read_tuple(), but we only do so for non-schema-only dumps.
+    * pg_get_sequence_data(), but we only do so for non-schema-only dumps.
     */
    if (fout->remoteVersion < 100000)
        return;
@@ -17401,7 +17401,7 @@ collectSequences(Archive *fout)
            "seqcache, seqcycle, "
            "last_value, is_called "
            "FROM pg_catalog.pg_sequence, "
-           "pg_sequence_read_tuple(seqrelid) "
+           "pg_get_sequence_data(seqrelid) "
            "ORDER BY seqrelid;";
 
    res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);
index 9a0ae278239a2130cd825f78c9747510a9b21bfd..1980d492c3dba3b5904d80970655bd0feb41be43 100644 (file)
@@ -57,6 +57,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 202408122
+#define CATALOG_VERSION_NO 202408301
 
 #endif
index 4abc6d95262cc33f7cf3b60fa2595dc7e262d700..85f42be1b3cdfc65a852e8ff02dcd9bf32e3024e 100644 (file)
   prorettype => 'int8', proargtypes => 'regclass',
   prosrc => 'pg_sequence_last_value' },
 { oid => '9876', descr => 'return sequence tuple, for use by pg_dump',
-  proname => 'pg_sequence_read_tuple', provolatile => 'v', proparallel => 'u',
+  proname => 'pg_get_sequence_data', provolatile => 'v', proparallel => 'u',
   prorettype => 'record', proargtypes => 'regclass',
-  proallargtypes => '{regclass,int8,int8,bool}', proargmodes => '{i,o,o,o}',
-  proargnames => '{sequence_oid,last_value,log_cnt,is_called}',
-  prosrc => 'pg_sequence_read_tuple' },
+  proallargtypes => '{regclass,int8,bool}', proargmodes => '{i,o,o}',
+  proargnames => '{sequence_oid,last_value,is_called}',
+  prosrc => 'pg_get_sequence_data' },
 
 { oid => '275', descr => 'return the next oid for a system table',
   proname => 'pg_nextoid', provolatile => 'v', proparallel => 'u',
index e749c4574e35e8603b7cc4a7524df13ca05fdf04..15925d99c8a38256c59f76424c361164a8140c21 100644 (file)
@@ -839,11 +839,11 @@ SELECT nextval('test_seq1');
        3
 (1 row)
 
--- pg_sequence_read_tuple
-SELECT * FROM pg_sequence_read_tuple('test_seq1');
- last_value | log_cnt | is_called 
-------------+---------+-----------
-         10 |      32 | t
+-- pg_get_sequence_data
+SELECT * FROM pg_get_sequence_data('test_seq1');
+ last_value | is_called 
+------------+-----------
+         10 | t
 (1 row)
 
 DROP SEQUENCE test_seq1;
index ea447938aea12562f2828edbb54052683c264183..2c220b60749ea58d98f5d2c26716a5b6ad645d86 100644 (file)
@@ -413,7 +413,7 @@ SELECT nextval('test_seq1');
 SELECT nextval('test_seq1');
 SELECT nextval('test_seq1');
 
--- pg_sequence_read_tuple
-SELECT * FROM pg_sequence_read_tuple('test_seq1');
+-- pg_get_sequence_data
+SELECT * FROM pg_get_sequence_data('test_seq1');
 
 DROP SEQUENCE test_seq1;