pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Create routine able to set single-call SRFs for Materialize mode
Date: Mon, 07 Mar 2022 01:27:02 +0000
Message-ID: <E1nR29N-001GQT-Ui@gemulon.postgresql.org> (raw)

Create routine able to set single-call SRFs for Materialize mode

Set-returning functions that use the Materialize mode, creating a
tuplestore to include all the tuples returned in a set rather than doing
so in multiple calls, use roughly the same set of steps to prepare
ReturnSetInfo for this job:
- Check if ReturnSetInfo supports returning a tuplestore and if the
materialize mode is enabled.
- Create a tuplestore for all the tuples part of the returned set in the
per-query memory context, stored in ReturnSetInfo->setResult.
- Build a tuple descriptor mostly from get_call_result_type(), then
stored in ReturnSetInfo->setDesc.  Note that there are some cases where
the SRF's tuple descriptor has to be the one specified by the function
caller.

This refactoring is done so as there are (well, should be) no behavior
changes in any of the in-core functions refactored, and the centralized
function that checks and sets up the function's ReturnSetInfo can be
controlled with a set of bits32 options.  Two of them prove to be
necessary now:
- SRF_SINGLE_USE_EXPECTED to use expectedDesc as tuple descriptor, as
expected by the function's caller.
- SRF_SINGLE_BLESS to validate the tuple descriptor for the SRF.

The same initialization pattern is simplified in 28 places per my
count as of src/backend/, shaving up to ~900 lines of code.  These
mostly come from the removal of the per-query initializations and the
sanity checks now grouped in a single location.  There are more
locations that could be simplified in contrib/, that are left for a
follow-up cleanup.

fcc2817, 07daca5 and d61a361 have prepared the areas of the code related
to this change, to ease this refactoring.

Author: Melanie Plageman, Michael Paquier
Reviewed-by: Álvaro Herrera, Justin Pryzby
Discussion: https://postgr.es/m/CAAKRu_azyd1Z3W_r7Ou4sorTjRCs+PxeHw1CWJeXKofkE6TuZg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9e98583898c347e007958c8a09911be2ea4acfb9

Modified Files
--------------
src/backend/commands/event_trigger.c           |  62 ++---------
src/backend/commands/extension.c               |  93 ++--------------
src/backend/commands/prepare.c                 |  34 +-----
src/backend/foreign/foreign.c                  |  34 +-----
src/backend/libpq/hba.c                        |  46 ++------
src/backend/replication/logical/launcher.c     |  31 +-----
src/backend/replication/logical/logicalfuncs.c |  21 +---
src/backend/replication/logical/origin.c       |  32 +-----
src/backend/replication/slotfuncs.c            |  31 +-----
src/backend/replication/walsender.c            |  31 +-----
src/backend/storage/ipc/shmem.c                |  35 +-----
src/backend/utils/adt/datetime.c               |  30 +-----
src/backend/utils/adt/genfile.c                |  61 +----------
src/backend/utils/adt/jsonfuncs.c              | 141 ++-----------------------
src/backend/utils/adt/mcxtfuncs.c              |  33 +-----
src/backend/utils/adt/misc.c                   |  33 +-----
src/backend/utils/adt/pgstatfuncs.c            |  91 ++--------------
src/backend/utils/adt/varlena.c                |  27 +----
src/backend/utils/fmgr/README                  |   4 +
src/backend/utils/fmgr/funcapi.c               |  69 ++++++++++++
src/backend/utils/misc/guc.c                   |  31 +-----
src/backend/utils/misc/pg_config.c             |  29 +----
src/backend/utils/mmgr/portalmem.c             |  37 +------
src/include/funcapi.h                          |  12 ++-
24 files changed, 176 insertions(+), 872 deletions(-)



Message-ID: <E1nR29N-001GQT-Ui@gemulon.postgresql.org>
Permalink:  ../E1nR29N-001GQT-Ui@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1nR29N-001GQT-Ui@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz
  Subject: Re: pgsql: Create routine able to set single-call SRFs for Materialize mode
  In-Reply-To: <E1nR29N-001GQT-Ui@gemulon.postgresql.org>
  References: <E1nR29N-001GQT-Ui@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox