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

Commit 62ce0c7

Browse files
committed
Fix catalog data of pg_stop_backup(), labelled v2
This function has been incorrectly marked as a set-returning function with prorows (estimated number of rows) set to 1 since its creation in 7117685, that introduced non-exclusive backups. There is no need for that as the function is designed to return only one tuple. This commit fixes the catalog definition of pg_stop_backup_v2() so as it is not marked as proretset anymore, with prorows set to 0. This simplifies its internals by removing one tuplestore (used for one single record anyway) and by removing all the checks related to a set-returning function. Issue found during my quest to simplify some of the logic used in in-core system functions. Bump catalog version. Reviewed-by: Aleksander Alekseev, Kyotaro Horiguchi Discussion: https://postgr.es/m/Yh8guT78f1Ercfzw@paquier.xyz
1 parent 50f0347 commit 62ce0c7

File tree

4 files changed

+11
-35
lines changed

4 files changed

+11
-35
lines changed

src/backend/access/transam/xlogfuncs.c

+6-30
Original file line numberDiff line numberDiff line change
@@ -165,43 +165,20 @@ pg_stop_backup(PG_FUNCTION_ARGS)
165165
Datum
166166
pg_stop_backup_v2(PG_FUNCTION_ARGS)
167167
{
168-
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
168+
#define PG_STOP_BACKUP_V2_COLS 3
169169
TupleDesc tupdesc;
170-
Tuplestorestate *tupstore;
171-
MemoryContext per_query_ctx;
172-
MemoryContext oldcontext;
173-
Datum values[3];
174-
bool nulls[3];
170+
Datum values[PG_STOP_BACKUP_V2_COLS];
171+
bool nulls[PG_STOP_BACKUP_V2_COLS];
175172

176173
bool exclusive = PG_GETARG_BOOL(0);
177174
bool waitforarchive = PG_GETARG_BOOL(1);
178175
XLogRecPtr stoppoint;
179176
SessionBackupState status = get_backup_status();
180177

181-
/* check to see if caller supports us returning a tuplestore */
182-
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
183-
ereport(ERROR,
184-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
185-
errmsg("set-valued function called in context that cannot accept a set")));
186-
if (!(rsinfo->allowedModes & SFRM_Materialize))
187-
ereport(ERROR,
188-
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
189-
errmsg("materialize mode required, but it is not allowed in this context")));
190-
191-
/* Build a tuple descriptor for our result type */
178+
/* Initialize attributes information in the tuple descriptor */
192179
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
193180
elog(ERROR, "return type must be a row type");
194181

195-
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
196-
oldcontext = MemoryContextSwitchTo(per_query_ctx);
197-
198-
tupstore = tuplestore_begin_heap(true, false, work_mem);
199-
rsinfo->returnMode = SFRM_Materialize;
200-
rsinfo->setResult = tupstore;
201-
rsinfo->setDesc = tupdesc;
202-
203-
MemoryContextSwitchTo(oldcontext);
204-
205182
MemSet(values, 0, sizeof(values));
206183
MemSet(nulls, 0, sizeof(nulls));
207184

@@ -251,9 +228,8 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
251228
/* Stoppoint is included on both exclusive and nonexclusive backups */
252229
values[0] = LSNGetDatum(stoppoint);
253230

254-
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
255-
256-
return (Datum) 0;
231+
/* Returns the record as Datum */
232+
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
257233
}
258234

259235
/*

src/backend/catalog/system_functions.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ CREATE OR REPLACE FUNCTION
384384
CREATE OR REPLACE FUNCTION pg_stop_backup (
385385
exclusive boolean, wait_for_archive boolean DEFAULT true,
386386
OUT lsn pg_lsn, OUT labelfile text, OUT spcmapfile text)
387-
RETURNS SETOF record STRICT VOLATILE LANGUAGE internal as 'pg_stop_backup_v2'
387+
RETURNS record STRICT VOLATILE LANGUAGE internal as 'pg_stop_backup_v2'
388388
PARALLEL RESTRICTED;
389389

390390
CREATE OR REPLACE FUNCTION

src/include/catalog/catversion.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 202203011
56+
#define CATALOG_VERSION_NO 202203031
5757

5858
#endif

src/include/catalog/pg_proc.dat

+3-3
Original file line numberDiff line numberDiff line change
@@ -6275,9 +6275,9 @@
62756275
proname => 'pg_stop_backup', provolatile => 'v', proparallel => 'r',
62766276
prorettype => 'pg_lsn', proargtypes => '', prosrc => 'pg_stop_backup' },
62776277
{ oid => '2739', descr => 'finish taking an online backup',
6278-
proname => 'pg_stop_backup', prorows => '1', proretset => 't',
6279-
provolatile => 'v', proparallel => 'r', prorettype => 'record',
6280-
proargtypes => 'bool bool', proallargtypes => '{bool,bool,pg_lsn,text,text}',
6278+
proname => 'pg_stop_backup', provolatile => 'v', proparallel => 'r',
6279+
prorettype => 'record', proargtypes => 'bool bool',
6280+
proallargtypes => '{bool,bool,pg_lsn,text,text}',
62816281
proargmodes => '{i,i,o,o,o}',
62826282
proargnames => '{exclusive,wait_for_archive,lsn,labelfile,spcmapfile}',
62836283
prosrc => 'pg_stop_backup_v2' },

0 commit comments

Comments
 (0)