diff options
author | Michael Paquier <michael@paquier.xyz> | 2022-03-08 10:12:22 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2022-03-08 10:12:22 +0900 |
commit | 5b81703787bfc1e6072c8e37125eba0c5598b807 (patch) | |
tree | 64fa53f8604641fc8ba17da54cf2b127b5016dac /contrib/dblink | |
parent | d5ed9da41d96988d905b49bebb273a9b2d6e2915 (diff) | |
download | postgresql-5b81703787bfc1e6072c8e37125eba0c5598b807.tar.gz |
Simplify SRFs using materialize mode in contrib/ modules
9e98583 introduced a helper to centralize building their needed state
(tuplestore, tuple descriptors, etc.), checking for any errors. This
commit updates all places of contrib/ that can be switched to use
SetSingleFuncCall() as a drop-in replacement, resulting in the removal
of a lot of boilerplate code in all the modules updated by this commit.
Per analysis, some places remain as they are:
- pg_logdir_ls() in adminpack/ uses historically TYPEFUNC_RECORD as
return type, and I suspect that changing it may cause issues at run-time
with some of its past versions, down to 1.0.
- dblink/ uses a wrapper function doing exactly the work of
SetSingleFuncCall(). Here the switch should be possible, but rather
invasive so it does not seem the extra backpatch maintenance cost.
- tablefunc/, similarly, uses multiple helper functions with portions of
SetSingleFuncCall() spread across the code paths of this module.
Author: Melanie Plageman
Discussion: https://postgr.es/m/CAAKRu_bvDPJoL9mH6eYwvBpPtTGQwbDzfJbCM-OjkSZDu5yTPg@mail.gmail.com
Diffstat (limited to 'contrib/dblink')
-rw-r--r-- | contrib/dblink/dblink.c | 26 |
1 files changed, 2 insertions, 24 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index efc4c94301..a06d4bd12d 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -1928,12 +1928,6 @@ dblink_get_notify(PG_FUNCTION_ARGS) PGconn *conn; PGnotify *notify; ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; - TupleDesc tupdesc; - Tuplestorestate *tupstore; - MemoryContext per_query_ctx; - MemoryContext oldcontext; - - prepTuplestoreResult(fcinfo); dblink_init(); if (PG_NARGS() == 1) @@ -1941,23 +1935,7 @@ dblink_get_notify(PG_FUNCTION_ARGS) else conn = pconn->conn; - /* create the tuplestore in per-query memory */ - per_query_ctx = rsinfo->econtext->ecxt_per_query_memory; - oldcontext = MemoryContextSwitchTo(per_query_ctx); - - tupdesc = CreateTemplateTupleDesc(DBLINK_NOTIFY_COLS); - TupleDescInitEntry(tupdesc, (AttrNumber) 1, "notify_name", - TEXTOID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 2, "be_pid", - INT4OID, -1, 0); - TupleDescInitEntry(tupdesc, (AttrNumber) 3, "extra", - TEXTOID, -1, 0); - - tupstore = tuplestore_begin_heap(true, false, work_mem); - rsinfo->setResult = tupstore; - rsinfo->setDesc = tupdesc; - - MemoryContextSwitchTo(oldcontext); + SetSingleFuncCall(fcinfo, 0); PQconsumeInput(conn); while ((notify = PQnotifies(conn)) != NULL) @@ -1980,7 +1958,7 @@ dblink_get_notify(PG_FUNCTION_ARGS) else nulls[2] = true; - tuplestore_putvalues(tupstore, tupdesc, values, nulls); + tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls); PQfreemem(notify); PQconsumeInput(conn); |