Skip to content

Commit a19e5ce

Browse files
committedOct 18, 2022
Rename SetSingleFuncCall() to InitMaterializedSRF()
Per discussion, the existing routine name able to initialize a SRF function with materialize mode is unpopular, so rename it. Equally, the flags of this function are renamed, as of: - SRF_SINGLE_USE_EXPECTED -> MAT_SRF_USE_EXPECTED_DESC - SRF_SINGLE_BLESS -> MAT_SRF_BLESS The previous function and flags introduced in 9e98583 are kept around for compatibility purposes, so as any extension code already compiled with v15 continues to work as-is. The declarations introduced here for compatibility will be removed from HEAD in a follow-up commit. The new names have been suggested by Andres Freund and Melanie Plageman. Discussion: https://postgr.es/m/[email protected] Backpatch-through: 15
1 parent 77dd153 commit a19e5ce

36 files changed

+72
-58
lines changed
 

‎contrib/amcheck/verify_heapam.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ verify_heapam(PG_FUNCTION_ARGS)
278278
ctx.attnum = -1;
279279

280280
/* Construct the tuplestore and tuple descriptor */
281-
SetSingleFuncCall(fcinfo, 0);
281+
InitMaterializedSRF(fcinfo, 0);
282282
ctx.tupdesc = rsinfo->setDesc;
283283
ctx.tupstore = rsinfo->setResult;
284284

‎contrib/dblink/dblink.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,7 @@ dblink_get_notify(PG_FUNCTION_ARGS)
19331933
else
19341934
conn = pconn->conn;
19351935

1936-
SetSingleFuncCall(fcinfo, 0);
1936+
InitMaterializedSRF(fcinfo, 0);
19371937

19381938
PQconsumeInput(conn);
19391939
while ((notify = PQnotifies(conn)) != NULL)

‎contrib/pageinspect/brinfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ brin_page_items(PG_FUNCTION_ARGS)
147147
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
148148
errmsg("must be superuser to use raw page functions")));
149149

150-
SetSingleFuncCall(fcinfo, 0);
150+
InitMaterializedSRF(fcinfo, 0);
151151

152152
indexRel = index_open(indexRelid, AccessShareLock);
153153

‎contrib/pageinspect/gistfuncs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ gist_page_items_bytea(PG_FUNCTION_ARGS)
127127
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
128128
errmsg("must be superuser to use raw page functions")));
129129

130-
SetSingleFuncCall(fcinfo, 0);
130+
InitMaterializedSRF(fcinfo, 0);
131131

132132
page = get_page_from_raw(raw_page);
133133

@@ -211,7 +211,7 @@ gist_page_items(PG_FUNCTION_ARGS)
211211
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
212212
errmsg("must be superuser to use raw page functions")));
213213

214-
SetSingleFuncCall(fcinfo, 0);
214+
InitMaterializedSRF(fcinfo, 0);
215215

216216
/* Open the relation */
217217
indexRel = index_open(indexRelid, AccessShareLock);

‎contrib/pg_stat_statements/pg_stat_statements.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,7 @@ pg_stat_statements_internal(FunctionCallInfo fcinfo,
15521552
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
15531553
errmsg("pg_stat_statements must be loaded via shared_preload_libraries")));
15541554

1555-
SetSingleFuncCall(fcinfo, 0);
1555+
InitMaterializedSRF(fcinfo, 0);
15561556

15571557
/*
15581558
* Check we have the expected number of output arguments. Aside from

‎contrib/pg_walinspect/pg_walinspect.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ GetWALRecordsInfo(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
330330
Datum values[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
331331
bool nulls[PG_GET_WAL_RECORDS_INFO_COLS] = {0};
332332

333-
SetSingleFuncCall(fcinfo, 0);
333+
InitMaterializedSRF(fcinfo, 0);
334334

335335
xlogreader = InitXLogReaderState(start_lsn);
336336

@@ -548,7 +548,7 @@ GetWalStats(FunctionCallInfo fcinfo, XLogRecPtr start_lsn,
548548
Datum values[PG_GET_WAL_STATS_COLS] = {0};
549549
bool nulls[PG_GET_WAL_STATS_COLS] = {0};
550550

551-
SetSingleFuncCall(fcinfo, 0);
551+
InitMaterializedSRF(fcinfo, 0);
552552

553553
xlogreader = InitXLogReaderState(start_lsn);
554554

‎contrib/pgrowlocks/pgrowlocks.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
7575
AclResult aclresult;
7676
char **values;
7777

78-
SetSingleFuncCall(fcinfo, 0);
78+
InitMaterializedSRF(fcinfo, 0);
7979

8080
/* Access the table */
8181
relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));

‎contrib/postgres_fdw/connection.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ postgres_fdw_get_connections(PG_FUNCTION_ARGS)
16681668
HASH_SEQ_STATUS scan;
16691669
ConnCacheEntry *entry;
16701670

1671-
SetSingleFuncCall(fcinfo, 0);
1671+
InitMaterializedSRF(fcinfo, 0);
16721672

16731673
/* If cache doesn't exist, we return no records */
16741674
if (!ConnectionHash)

‎contrib/xml2/xpath.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ xpath_table(PG_FUNCTION_ARGS)
511511
PgXmlErrorContext *xmlerrcxt;
512512
volatile xmlDocPtr doctree = NULL;
513513

514-
SetSingleFuncCall(fcinfo, SRF_SINGLE_USE_EXPECTED);
514+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC);
515515

516516
/* must have at least one output column (for the pkey) */
517517
if (rsinfo->setDesc->natts < 1)

‎src/backend/access/transam/rmgr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pg_get_wal_resource_managers(PG_FUNCTION_ARGS)
145145
Datum values[PG_GET_RESOURCE_MANAGERS_COLS];
146146
bool nulls[PG_GET_RESOURCE_MANAGERS_COLS] = {0};
147147

148-
SetSingleFuncCall(fcinfo, 0);
148+
InitMaterializedSRF(fcinfo, 0);
149149

150150
for (int rmid = 0; rmid <= RM_MAX_ID; rmid++)
151151
{

‎src/backend/access/transam/xlogprefetcher.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ pg_stat_get_recovery_prefetch(PG_FUNCTION_ARGS)
834834
Datum values[PG_STAT_GET_RECOVERY_PREFETCH_COLS];
835835
bool nulls[PG_STAT_GET_RECOVERY_PREFETCH_COLS];
836836

837-
SetSingleFuncCall(fcinfo, 0);
837+
InitMaterializedSRF(fcinfo, 0);
838838

839839
for (int i = 0; i < PG_STAT_GET_RECOVERY_PREFETCH_COLS; ++i)
840840
nulls[i] = false;

‎src/backend/commands/event_trigger.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ pg_event_trigger_dropped_objects(PG_FUNCTION_ARGS)
13051305
"pg_event_trigger_dropped_objects()")));
13061306

13071307
/* Build tuplestore to hold the result rows */
1308-
SetSingleFuncCall(fcinfo, 0);
1308+
InitMaterializedSRF(fcinfo, 0);
13091309

13101310
slist_foreach(iter, &(currentEventTriggerState->SQLDropList))
13111311
{
@@ -1832,7 +1832,7 @@ pg_event_trigger_ddl_commands(PG_FUNCTION_ARGS)
18321832
"pg_event_trigger_ddl_commands()")));
18331833

18341834
/* Build tuplestore to hold the result rows */
1835-
SetSingleFuncCall(fcinfo, 0);
1835+
InitMaterializedSRF(fcinfo, 0);
18361836

18371837
foreach(lc, currentEventTriggerState->commandList)
18381838
{

‎src/backend/commands/extension.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ pg_available_extensions(PG_FUNCTION_ARGS)
19461946
struct dirent *de;
19471947

19481948
/* Build tuplestore to hold the result rows */
1949-
SetSingleFuncCall(fcinfo, 0);
1949+
InitMaterializedSRF(fcinfo, 0);
19501950

19511951
location = get_extension_control_directory();
19521952
dir = AllocateDir(location);
@@ -2026,7 +2026,7 @@ pg_available_extension_versions(PG_FUNCTION_ARGS)
20262026
struct dirent *de;
20272027

20282028
/* Build tuplestore to hold the result rows */
2029-
SetSingleFuncCall(fcinfo, 0);
2029+
InitMaterializedSRF(fcinfo, 0);
20302030

20312031
location = get_extension_control_directory();
20322032
dir = AllocateDir(location);
@@ -2281,7 +2281,7 @@ pg_extension_update_paths(PG_FUNCTION_ARGS)
22812281
check_valid_extension_name(NameStr(*extname));
22822282

22832283
/* Build tuplestore to hold the result rows */
2284-
SetSingleFuncCall(fcinfo, 0);
2284+
InitMaterializedSRF(fcinfo, 0);
22852285

22862286
/* Read the extension's control file */
22872287
control = read_extension_control_file(NameStr(*extname));

‎src/backend/commands/prepare.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
672672
* We put all the tuples into a tuplestore in one scan of the hashtable.
673673
* This avoids any issue of the hashtable possibly changing between calls.
674674
*/
675-
SetSingleFuncCall(fcinfo, 0);
675+
InitMaterializedSRF(fcinfo, 0);
676676

677677
/* hash table might be uninitialized */
678678
if (prepared_queries)

‎src/backend/foreign/foreign.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ pg_options_to_table(PG_FUNCTION_ARGS)
517517
rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
518518

519519
/* prepare the result set */
520-
SetSingleFuncCall(fcinfo, SRF_SINGLE_USE_EXPECTED);
520+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC);
521521

522522
foreach(cell, options)
523523
{

‎src/backend/replication/logical/launcher.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ pg_stat_get_subscription(PG_FUNCTION_ARGS)
930930
int i;
931931
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
932932

933-
SetSingleFuncCall(fcinfo, 0);
933+
InitMaterializedSRF(fcinfo, 0);
934934

935935
/* Make sure we get consistent view of the workers. */
936936
LWLockAcquire(LogicalRepWorkerLock, LW_SHARED);

‎src/backend/replication/logical/logicalfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pg_logical_slot_get_changes_guts(FunctionCallInfo fcinfo, bool confirm, bool bin
188188
}
189189
}
190190

191-
SetSingleFuncCall(fcinfo, 0);
191+
InitMaterializedSRF(fcinfo, 0);
192192
p->tupstore = rsinfo->setResult;
193193
p->tupdesc = rsinfo->setDesc;
194194

‎src/backend/replication/logical/origin.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@ pg_show_replication_origin_status(PG_FUNCTION_ARGS)
15031503
/* we want to return 0 rows if slot is set to zero */
15041504
replorigin_check_prerequisites(false, true);
15051505

1506-
SetSingleFuncCall(fcinfo, 0);
1506+
InitMaterializedSRF(fcinfo, 0);
15071507

15081508
/* prevent slots from being concurrently dropped */
15091509
LWLockAcquire(ReplicationOriginLock, LW_SHARED);

‎src/backend/replication/slotfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pg_get_replication_slots(PG_FUNCTION_ARGS)
242242
* name, which shouldn't contain anything particularly sensitive.
243243
*/
244244

245-
SetSingleFuncCall(fcinfo, 0);
245+
InitMaterializedSRF(fcinfo, 0);
246246

247247
currlsn = GetXLogWriteRecPtr();
248248

‎src/backend/replication/walsender.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3459,7 +3459,7 @@ pg_stat_get_wal_senders(PG_FUNCTION_ARGS)
34593459
int num_standbys;
34603460
int i;
34613461

3462-
SetSingleFuncCall(fcinfo, 0);
3462+
InitMaterializedSRF(fcinfo, 0);
34633463

34643464
/*
34653465
* Get the currently active synchronous standbys. This could be out of

‎src/backend/storage/ipc/shmem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ pg_get_shmem_allocations(PG_FUNCTION_ARGS)
543543
Datum values[PG_GET_SHMEM_SIZES_COLS];
544544
bool nulls[PG_GET_SHMEM_SIZES_COLS];
545545

546-
SetSingleFuncCall(fcinfo, 0);
546+
InitMaterializedSRF(fcinfo, 0);
547547

548548
LWLockAcquire(ShmemIndexLock, LW_SHARED);
549549

‎src/backend/utils/adt/datetime.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5058,7 +5058,7 @@ pg_timezone_names(PG_FUNCTION_ARGS)
50585058
Interval *resInterval;
50595059
struct pg_itm_in itm_in;
50605060

5061-
SetSingleFuncCall(fcinfo, 0);
5061+
InitMaterializedSRF(fcinfo, 0);
50625062

50635063
/* initialize timezone scanning code */
50645064
tzenum = pg_tzenumerate_start();

‎src/backend/utils/adt/genfile.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ pg_ls_dir(PG_FUNCTION_ARGS)
561561
include_dot_dirs = PG_GETARG_BOOL(2);
562562
}
563563

564-
SetSingleFuncCall(fcinfo, SRF_SINGLE_USE_EXPECTED);
564+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC);
565565

566566
dirdesc = AllocateDir(location);
567567
if (!dirdesc)
@@ -619,7 +619,7 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir, bool missing_ok)
619619
DIR *dirdesc;
620620
struct dirent *de;
621621

622-
SetSingleFuncCall(fcinfo, 0);
622+
InitMaterializedSRF(fcinfo, 0);
623623

624624
/*
625625
* Now walk the directory. Note that we must do this within a single SRF

‎src/backend/utils/adt/hbafuncs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pg_hba_file_rules(PG_FUNCTION_ARGS)
421421
* also more efficient than having to look up our current position in the
422422
* parsed list every time.
423423
*/
424-
SetSingleFuncCall(fcinfo, 0);
424+
InitMaterializedSRF(fcinfo, 0);
425425

426426
/* Fill the tuplestore */
427427
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -554,7 +554,7 @@ pg_ident_file_mappings(PG_FUNCTION_ARGS)
554554
* also more efficient than having to look up our current position in the
555555
* parsed list every time.
556556
*/
557-
SetSingleFuncCall(fcinfo, 0);
557+
InitMaterializedSRF(fcinfo, 0);
558558

559559
/* Fill the tuplestore */
560560
rsi = (ReturnSetInfo *) fcinfo->resultinfo;

‎src/backend/utils/adt/jsonfuncs.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -1921,7 +1921,7 @@ each_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
19211921
funcname)));
19221922

19231923
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
1924-
SetSingleFuncCall(fcinfo, SRF_SINGLE_BLESS);
1924+
InitMaterializedSRF(fcinfo, MAT_SRF_BLESS);
19251925

19261926
tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
19271927
"jsonb_each temporary cxt",
@@ -2001,7 +2001,7 @@ each_worker(FunctionCallInfo fcinfo, bool as_text)
20012001

20022002
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
20032003

2004-
SetSingleFuncCall(fcinfo, SRF_SINGLE_BLESS);
2004+
InitMaterializedSRF(fcinfo, MAT_SRF_BLESS);
20052005
state->tuple_store = rsi->setResult;
20062006
state->ret_tdesc = rsi->setDesc;
20072007

@@ -2164,8 +2164,7 @@ elements_worker_jsonb(FunctionCallInfo fcinfo, const char *funcname,
21642164

21652165
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
21662166

2167-
SetSingleFuncCall(fcinfo,
2168-
SRF_SINGLE_USE_EXPECTED | SRF_SINGLE_BLESS);
2167+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC | MAT_SRF_BLESS);
21692168

21702169
tmp_cxt = AllocSetContextCreate(CurrentMemoryContext,
21712170
"jsonb_array_elements temporary cxt",
@@ -2243,7 +2242,7 @@ elements_worker(FunctionCallInfo fcinfo, const char *funcname, bool as_text)
22432242
state = palloc0(sizeof(ElementsState));
22442243
sem = palloc0(sizeof(JsonSemAction));
22452244

2246-
SetSingleFuncCall(fcinfo, SRF_SINGLE_USE_EXPECTED | SRF_SINGLE_BLESS);
2245+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC | MAT_SRF_BLESS);
22472246
rsi = (ReturnSetInfo *) fcinfo->resultinfo;
22482247
state->tuple_store = rsi->setResult;
22492248
state->ret_tdesc = rsi->setDesc;

‎src/backend/utils/adt/mcxtfuncs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pg_get_backend_memory_contexts(PG_FUNCTION_ARGS)
121121
{
122122
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
123123

124-
SetSingleFuncCall(fcinfo, 0);
124+
InitMaterializedSRF(fcinfo, 0);
125125
PutMemoryContextsStatsTupleStore(rsinfo->setResult, rsinfo->setDesc,
126126
TopMemoryContext, NULL, 0);
127127

‎src/backend/utils/adt/misc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
208208
DIR *dirdesc;
209209
struct dirent *de;
210210

211-
SetSingleFuncCall(fcinfo, SRF_SINGLE_USE_EXPECTED);
211+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC);
212212

213213
if (tablespaceOid == GLOBALTABLESPACE_OID)
214214
{

‎src/backend/utils/adt/pgstatfuncs.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ pg_stat_get_progress_info(PG_FUNCTION_ARGS)
502502
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
503503
errmsg("invalid command name: \"%s\"", cmd)));
504504

505-
SetSingleFuncCall(fcinfo, 0);
505+
InitMaterializedSRF(fcinfo, 0);
506506

507507
/* 1-based index */
508508
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
@@ -559,7 +559,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
559559
int pid = PG_ARGISNULL(0) ? -1 : PG_GETARG_INT32(0);
560560
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
561561

562-
SetSingleFuncCall(fcinfo, 0);
562+
InitMaterializedSRF(fcinfo, 0);
563563

564564
/* 1-based index */
565565
for (curr_backend = 1; curr_backend <= num_backends; curr_backend++)
@@ -1800,7 +1800,7 @@ pg_stat_get_slru(PG_FUNCTION_ARGS)
18001800
int i;
18011801
PgStat_SLRUStats *stats;
18021802

1803-
SetSingleFuncCall(fcinfo, 0);
1803+
InitMaterializedSRF(fcinfo, 0);
18041804

18051805
/* request SLRU stats from the cumulative stats system */
18061806
stats = pgstat_fetch_slru();

‎src/backend/utils/adt/varlena.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4810,7 +4810,7 @@ text_to_table(PG_FUNCTION_ARGS)
48104810
SplitTextOutputData tstate;
48114811

48124812
tstate.astate = NULL;
4813-
SetSingleFuncCall(fcinfo, SRF_SINGLE_USE_EXPECTED);
4813+
InitMaterializedSRF(fcinfo, MAT_SRF_USE_EXPECTED_DESC);
48144814
tstate.tupstore = rsi->setResult;
48154815
tstate.tupdesc = rsi->setDesc;
48164816

‎src/backend/utils/fmgr/README

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ If available, the expected tuple descriptor is passed in ReturnSetInfo;
305305
in other contexts the expectedDesc field will be NULL. The function need
306306
not pay attention to expectedDesc, but it may be useful in special cases.
307307

308-
SetSingleFuncCall() is a helper function able to setup the function's
308+
InitMaterializedSRF() is a helper function able to setup the function's
309309
ReturnSetInfo for a single call, filling in the Tuplestore and the
310310
TupleDesc with the proper configuration for Materialize mode.
311311

‎src/backend/utils/fmgr/funcapi.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,32 @@ static TypeFuncClass get_type_func_class(Oid typid, Oid *base_typeid);
5757

5858

5959
/*
60-
* SetSingleFuncCall
60+
* Compatibility function for v15.
61+
*/
62+
void
63+
SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
64+
{
65+
InitMaterializedSRF(fcinfo, flags);
66+
}
67+
68+
/*
69+
* InitMaterializedSRF
6170
*
6271
* Helper function to build the state of a set-returning function used
6372
* in the context of a single call with materialize mode. This code
6473
* includes sanity checks on ReturnSetInfo, creates the Tuplestore and
6574
* the TupleDesc used with the function and stores them into the
6675
* function's ReturnSetInfo.
6776
*
68-
* "flags" can be set to SRF_SINGLE_USE_EXPECTED, to use the tuple
77+
* "flags" can be set to MAT_SRF_USE_EXPECTED_DESC, to use the tuple
6978
* descriptor coming from expectedDesc, which is the tuple descriptor
70-
* expected by the caller. SRF_SINGLE_BLESS can be set to complete the
79+
* expected by the caller. MAT_SRF_BLESS can be set to complete the
7180
* information associated to the tuple descriptor, which is necessary
7281
* in some cases where the tuple descriptor comes from a transient
7382
* RECORD datatype.
7483
*/
7584
void
76-
SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
85+
InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
7786
{
7887
bool random_access;
7988
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
@@ -88,7 +97,7 @@ SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
8897
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
8998
errmsg("set-valued function called in context that cannot accept a set")));
9099
if (!(rsinfo->allowedModes & SFRM_Materialize) ||
91-
((flags & SRF_SINGLE_USE_EXPECTED) != 0 && rsinfo->expectedDesc == NULL))
100+
((flags & MAT_SRF_USE_EXPECTED_DESC) != 0 && rsinfo->expectedDesc == NULL))
92101
ereport(ERROR,
93102
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
94103
errmsg("materialize mode required, but it is not allowed in this context")));
@@ -101,7 +110,7 @@ SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
101110
old_context = MemoryContextSwitchTo(per_query_ctx);
102111

103112
/* build a tuple descriptor for our result type */
104-
if ((flags & SRF_SINGLE_USE_EXPECTED) != 0)
113+
if ((flags & MAT_SRF_USE_EXPECTED_DESC) != 0)
105114
stored_tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc);
106115
else
107116
{
@@ -110,7 +119,7 @@ SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags)
110119
}
111120

112121
/* If requested, bless the tuple descriptor */
113-
if ((flags & SRF_SINGLE_BLESS) != 0)
122+
if ((flags & MAT_SRF_BLESS) != 0)
114123
BlessTupleDesc(stored_tupdesc);
115124

116125
random_access = (rsinfo->allowedModes & SFRM_Materialize_Random) != 0;

‎src/backend/utils/misc/guc_funcs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ show_all_file_settings(PG_FUNCTION_ARGS)
996996
conf = ProcessConfigFileInternal(PGC_SIGHUP, false, DEBUG3);
997997

998998
/* Build a tuplestore to return our results in */
999-
SetSingleFuncCall(fcinfo, 0);
999+
InitMaterializedSRF(fcinfo, 0);
10001000

10011001
/* Process the results and create a tuplestore */
10021002
for (seqno = 1; conf != NULL; conf = conf->next, seqno++)

‎src/backend/utils/misc/pg_config.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pg_config(PG_FUNCTION_ARGS)
3030
int i = 0;
3131

3232
/* initialize our tuplestore */
33-
SetSingleFuncCall(fcinfo, 0);
33+
InitMaterializedSRF(fcinfo, 0);
3434

3535
configdata = get_configdata(my_exec_path, &configdata_len);
3636
for (i = 0; i < configdata_len; i++)

‎src/backend/utils/mmgr/portalmem.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ pg_cursor(PG_FUNCTION_ARGS)
11391139
* We put all the tuples into a tuplestore in one scan of the hashtable.
11401140
* This avoids any issue of the hashtable possibly changing between calls.
11411141
*/
1142-
SetSingleFuncCall(fcinfo, 0);
1142+
InitMaterializedSRF(fcinfo, 0);
11431143

11441144
hash_seq_init(&hash_seq, PortalHashTable);
11451145
while ((hentry = hash_seq_search(&hash_seq)) != NULL)

‎src/include/funcapi.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ HeapTupleGetDatum(const HeapTupleData *tuple)
282282
* memory allocated in multi_call_memory_ctx, but holding file descriptors or
283283
* other non-memory resources open across calls is a bug. SRFs that need
284284
* such resources should not use these macros, but instead populate a
285-
* tuplestore during a single call, as set up by SetSingleFuncCall() (see
285+
* tuplestore during a single call, as set up by InitMaterializedSRF() (see
286286
* fmgr/README). Alternatively, set up a callback to release resources
287287
* at query shutdown, using RegisterExprContextCallback().
288288
*
@@ -291,9 +291,15 @@ HeapTupleGetDatum(const HeapTupleData *tuple)
291291

292292
/* from funcapi.c */
293293

294-
/* flag bits for SetSingleFuncCall() */
295-
#define SRF_SINGLE_USE_EXPECTED 0x01 /* use expectedDesc as tupdesc */
296-
#define SRF_SINGLE_BLESS 0x02 /* validate tuple for SRF */
294+
/* flag bits for InitMaterializedSRF() */
295+
#define MAT_SRF_USE_EXPECTED_DESC 0x01 /* use expectedDesc as tupdesc. */
296+
#define MAT_SRF_BLESS 0x02 /* "Bless" a tuple descriptor with
297+
* BlessTupleDesc(). */
298+
extern void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags);
299+
300+
/* Compatibility declarations, for v15 */
301+
#define SRF_SINGLE_USE_EXPECTED MAT_SRF_USE_EXPECTED_DESC
302+
#define SRF_SINGLE_BLESS MAT_SRF_BLESS
297303
extern void SetSingleFuncCall(FunctionCallInfo fcinfo, bits32 flags);
298304

299305
extern FuncCallContext *init_MultiFuncCall(PG_FUNCTION_ARGS);

‎src/test/modules/test_ddl_deparse/test_ddl_deparse.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ get_altertable_subcmdinfo(PG_FUNCTION_ARGS)
9393
if (cmd->type != SCT_AlterTable)
9494
elog(ERROR, "command is not ALTER TABLE");
9595

96-
SetSingleFuncCall(fcinfo, 0);
96+
InitMaterializedSRF(fcinfo, 0);
9797

9898
if (cmd->d.alterTable.subcmds == NIL)
9999
elog(ERROR, "empty alter table subcommand list");

0 commit comments

Comments
 (0)
Please sign in to comment.