mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-03-13 19:57:53 +08:00
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
This commit is contained in:
parent
50f03473ed
commit
62ce0c758d
@ -165,43 +165,20 @@ pg_stop_backup(PG_FUNCTION_ARGS)
|
|||||||
Datum
|
Datum
|
||||||
pg_stop_backup_v2(PG_FUNCTION_ARGS)
|
pg_stop_backup_v2(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
#define PG_STOP_BACKUP_V2_COLS 3
|
||||||
TupleDesc tupdesc;
|
TupleDesc tupdesc;
|
||||||
Tuplestorestate *tupstore;
|
Datum values[PG_STOP_BACKUP_V2_COLS];
|
||||||
MemoryContext per_query_ctx;
|
bool nulls[PG_STOP_BACKUP_V2_COLS];
|
||||||
MemoryContext oldcontext;
|
|
||||||
Datum values[3];
|
|
||||||
bool nulls[3];
|
|
||||||
|
|
||||||
bool exclusive = PG_GETARG_BOOL(0);
|
bool exclusive = PG_GETARG_BOOL(0);
|
||||||
bool waitforarchive = PG_GETARG_BOOL(1);
|
bool waitforarchive = PG_GETARG_BOOL(1);
|
||||||
XLogRecPtr stoppoint;
|
XLogRecPtr stoppoint;
|
||||||
SessionBackupState status = get_backup_status();
|
SessionBackupState status = get_backup_status();
|
||||||
|
|
||||||
/* check to see if caller supports us returning a tuplestore */
|
/* Initialize attributes information in the tuple descriptor */
|
||||||
if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo))
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
||||||
errmsg("set-valued function called in context that cannot accept a set")));
|
|
||||||
if (!(rsinfo->allowedModes & SFRM_Materialize))
|
|
||||||
ereport(ERROR,
|
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
|
||||||
errmsg("materialize mode required, but it is not allowed in this context")));
|
|
||||||
|
|
||||||
/* Build a tuple descriptor for our result type */
|
|
||||||
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
|
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
|
||||||
elog(ERROR, "return type must be a row type");
|
elog(ERROR, "return type must be a row type");
|
||||||
|
|
||||||
per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
|
|
||||||
oldcontext = MemoryContextSwitchTo(per_query_ctx);
|
|
||||||
|
|
||||||
tupstore = tuplestore_begin_heap(true, false, work_mem);
|
|
||||||
rsinfo->returnMode = SFRM_Materialize;
|
|
||||||
rsinfo->setResult = tupstore;
|
|
||||||
rsinfo->setDesc = tupdesc;
|
|
||||||
|
|
||||||
MemoryContextSwitchTo(oldcontext);
|
|
||||||
|
|
||||||
MemSet(values, 0, sizeof(values));
|
MemSet(values, 0, sizeof(values));
|
||||||
MemSet(nulls, 0, sizeof(nulls));
|
MemSet(nulls, 0, sizeof(nulls));
|
||||||
|
|
||||||
@ -251,9 +228,8 @@ pg_stop_backup_v2(PG_FUNCTION_ARGS)
|
|||||||
/* Stoppoint is included on both exclusive and nonexclusive backups */
|
/* Stoppoint is included on both exclusive and nonexclusive backups */
|
||||||
values[0] = LSNGetDatum(stoppoint);
|
values[0] = LSNGetDatum(stoppoint);
|
||||||
|
|
||||||
tuplestore_putvalues(tupstore, tupdesc, values, nulls);
|
/* Returns the record as Datum */
|
||||||
|
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
|
||||||
return (Datum) 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -384,7 +384,7 @@ CREATE OR REPLACE FUNCTION
|
|||||||
CREATE OR REPLACE FUNCTION pg_stop_backup (
|
CREATE OR REPLACE FUNCTION pg_stop_backup (
|
||||||
exclusive boolean, wait_for_archive boolean DEFAULT true,
|
exclusive boolean, wait_for_archive boolean DEFAULT true,
|
||||||
OUT lsn pg_lsn, OUT labelfile text, OUT spcmapfile text)
|
OUT lsn pg_lsn, OUT labelfile text, OUT spcmapfile text)
|
||||||
RETURNS SETOF record STRICT VOLATILE LANGUAGE internal as 'pg_stop_backup_v2'
|
RETURNS record STRICT VOLATILE LANGUAGE internal as 'pg_stop_backup_v2'
|
||||||
PARALLEL RESTRICTED;
|
PARALLEL RESTRICTED;
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION
|
CREATE OR REPLACE FUNCTION
|
||||||
|
@ -53,6 +53,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/* yyyymmddN */
|
/* yyyymmddN */
|
||||||
#define CATALOG_VERSION_NO 202203011
|
#define CATALOG_VERSION_NO 202203031
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6275,9 +6275,9 @@
|
|||||||
proname => 'pg_stop_backup', provolatile => 'v', proparallel => 'r',
|
proname => 'pg_stop_backup', provolatile => 'v', proparallel => 'r',
|
||||||
prorettype => 'pg_lsn', proargtypes => '', prosrc => 'pg_stop_backup' },
|
prorettype => 'pg_lsn', proargtypes => '', prosrc => 'pg_stop_backup' },
|
||||||
{ oid => '2739', descr => 'finish taking an online backup',
|
{ oid => '2739', descr => 'finish taking an online backup',
|
||||||
proname => 'pg_stop_backup', prorows => '1', proretset => 't',
|
proname => 'pg_stop_backup', provolatile => 'v', proparallel => 'r',
|
||||||
provolatile => 'v', proparallel => 'r', prorettype => 'record',
|
prorettype => 'record', proargtypes => 'bool bool',
|
||||||
proargtypes => 'bool bool', proallargtypes => '{bool,bool,pg_lsn,text,text}',
|
proallargtypes => '{bool,bool,pg_lsn,text,text}',
|
||||||
proargmodes => '{i,i,o,o,o}',
|
proargmodes => '{i,i,o,o,o}',
|
||||||
proargnames => '{exclusive,wait_for_archive,lsn,labelfile,spcmapfile}',
|
proargnames => '{exclusive,wait_for_archive,lsn,labelfile,spcmapfile}',
|
||||||
prosrc => 'pg_stop_backup_v2' },
|
prosrc => 'pg_stop_backup_v2' },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user