Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a83a944

Browse files
committed
Rename pg_sequence_read_tuple() to pg_get_sequence_data()
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/Zsvka3r-y2ZoXAdH@paquier.xyz
1 parent 43f2e76 commit a83a944

File tree

6 files changed

+22
-23
lines changed

6 files changed

+22
-23
lines changed

src/backend/commands/sequence.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,23 +1781,22 @@ pg_sequence_parameters(PG_FUNCTION_ARGS)
17811781
* without needing to individually query each sequence relation.
17821782
*/
17831783
Datum
1784-
pg_sequence_read_tuple(PG_FUNCTION_ARGS)
1784+
pg_get_sequence_data(PG_FUNCTION_ARGS)
17851785
{
1786+
#define PG_GET_SEQUENCE_DATA_COLS 2
17861787
Oid relid = PG_GETARG_OID(0);
17871788
SeqTable elm;
17881789
Relation seqrel;
1789-
Datum values[SEQ_COL_LASTCOL] = {0};
1790-
bool isnull[SEQ_COL_LASTCOL] = {0};
1790+
Datum values[PG_GET_SEQUENCE_DATA_COLS] = {0};
1791+
bool isnull[PG_GET_SEQUENCE_DATA_COLS] = {0};
17911792
TupleDesc resultTupleDesc;
17921793
HeapTuple resultHeapTuple;
17931794
Datum result;
17941795

1795-
resultTupleDesc = CreateTemplateTupleDesc(SEQ_COL_LASTCOL);
1796+
resultTupleDesc = CreateTemplateTupleDesc(PG_GET_SEQUENCE_DATA_COLS);
17961797
TupleDescInitEntry(resultTupleDesc, (AttrNumber) 1, "last_value",
17971798
INT8OID, -1, 0);
1798-
TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "log_cnt",
1799-
INT8OID, -1, 0);
1800-
TupleDescInitEntry(resultTupleDesc, (AttrNumber) 3, "is_called",
1799+
TupleDescInitEntry(resultTupleDesc, (AttrNumber) 2, "is_called",
18011800
BOOLOID, -1, 0);
18021801
resultTupleDesc = BlessTupleDesc(resultTupleDesc);
18031802

@@ -1818,8 +1817,7 @@ pg_sequence_read_tuple(PG_FUNCTION_ARGS)
18181817
seq = read_seq_tuple(seqrel, &buf, &seqtuple);
18191818

18201819
values[0] = Int64GetDatum(seq->last_value);
1821-
values[1] = Int64GetDatum(seq->log_cnt);
1822-
values[2] = BoolGetDatum(seq->is_called);
1820+
values[1] = BoolGetDatum(seq->is_called);
18231821

18241822
UnlockReleaseBuffer(buf);
18251823
}
@@ -1831,6 +1829,7 @@ pg_sequence_read_tuple(PG_FUNCTION_ARGS)
18311829
resultHeapTuple = heap_form_tuple(resultTupleDesc, values, isnull);
18321830
result = HeapTupleGetDatum(resultHeapTuple);
18331831
PG_RETURN_DATUM(result);
1832+
#undef PG_GET_SEQUENCE_DATA_COLS
18341833
}
18351834

18361835

src/bin/pg_dump/pg_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17381,7 +17381,7 @@ collectSequences(Archive *fout)
1738117381
* versions, but for now it seems unlikely to be worth it.
1738217382
*
1738317383
* Since version 18, we can gather the sequence data in this query with
17384-
* pg_sequence_read_tuple(), but we only do so for non-schema-only dumps.
17384+
* pg_get_sequence_data(), but we only do so for non-schema-only dumps.
1738517385
*/
1738617386
if (fout->remoteVersion < 100000)
1738717387
return;
@@ -17401,7 +17401,7 @@ collectSequences(Archive *fout)
1740117401
"seqcache, seqcycle, "
1740217402
"last_value, is_called "
1740317403
"FROM pg_catalog.pg_sequence, "
17404-
"pg_sequence_read_tuple(seqrelid) "
17404+
"pg_get_sequence_data(seqrelid) "
1740517405
"ORDER BY seqrelid;";
1740617406

1740717407
res = ExecuteSqlQuery(fout, query, PGRES_TUPLES_OK);

src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@
5757
*/
5858

5959
/* yyyymmddN */
60-
#define CATALOG_VERSION_NO 202408122
60+
#define CATALOG_VERSION_NO 202408301
6161

6262
#endif

src/include/catalog/pg_proc.dat

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,11 +3330,11 @@
33303330
prorettype => 'int8', proargtypes => 'regclass',
33313331
prosrc => 'pg_sequence_last_value' },
33323332
{ oid => '9876', descr => 'return sequence tuple, for use by pg_dump',
3333-
proname => 'pg_sequence_read_tuple', provolatile => 'v', proparallel => 'u',
3333+
proname => 'pg_get_sequence_data', provolatile => 'v', proparallel => 'u',
33343334
prorettype => 'record', proargtypes => 'regclass',
3335-
proallargtypes => '{regclass,int8,int8,bool}', proargmodes => '{i,o,o,o}',
3336-
proargnames => '{sequence_oid,last_value,log_cnt,is_called}',
3337-
prosrc => 'pg_sequence_read_tuple' },
3335+
proallargtypes => '{regclass,int8,bool}', proargmodes => '{i,o,o}',
3336+
proargnames => '{sequence_oid,last_value,is_called}',
3337+
prosrc => 'pg_get_sequence_data' },
33383338

33393339
{ oid => '275', descr => 'return the next oid for a system table',
33403340
proname => 'pg_nextoid', provolatile => 'v', proparallel => 'u',

src/test/regress/expected/sequence.out

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,11 +839,11 @@ SELECT nextval('test_seq1');
839839
3
840840
(1 row)
841841

842-
-- pg_sequence_read_tuple
843-
SELECT * FROM pg_sequence_read_tuple('test_seq1');
844-
last_value | log_cnt | is_called
845-
------------+---------+-----------
846-
10 | 32 | t
842+
-- pg_get_sequence_data
843+
SELECT * FROM pg_get_sequence_data('test_seq1');
844+
last_value | is_called
845+
------------+-----------
846+
10 | t
847847
(1 row)
848848

849849
DROP SEQUENCE test_seq1;

src/test/regress/sql/sequence.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ SELECT nextval('test_seq1');
413413
SELECT nextval('test_seq1');
414414
SELECT nextval('test_seq1');
415415

416-
-- pg_sequence_read_tuple
417-
SELECT * FROM pg_sequence_read_tuple('test_seq1');
416+
-- pg_get_sequence_data
417+
SELECT * FROM pg_get_sequence_data('test_seq1');
418418

419419
DROP SEQUENCE test_seq1;

0 commit comments

Comments
 (0)