pgsql: Create ResultRelInfos later in InitPlan, index them by RT index. - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Create ResultRelInfos later in InitPlan, index them by RT index.
Date
Msg-id E1kSHEJ-0008UU-Sd@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Create ResultRelInfos later in InitPlan, index them by RT index.

Instead of allocating all the ResultRelInfos upfront in one big array,
allocate them in ExecInitModifyTable(). es_result_relations is now an
array of ResultRelInfo pointers, rather than an array of structs, and it
is indexed by the RT index.

This simplifies things: we get rid of the separate concept of a "result
rel index", and don't need to set it in setrefs.c anymore. This also
allows follow-up optimizations (not included in this commit yet) to skip
initializing ResultRelInfos for target relations that were not needed at
runtime, and removal of the es_result_relation_info pointer.

The EState arrays of regular result rels and root result rels are merged
into one array. Similarly, the resultRelations and rootResultRelations
lists in PlannedStmt are merged into one. It's not actually clear to me
why they were kept separate in the first place, but now that the
es_result_relations array is indexed by RT index, it certainly seems
pointless.

The PlannedStmt->resultRelations list is now only needed for
ExecRelationIsTargetRelation(). One visible effect of this change is that
ExecRelationIsTargetRelation() will now return 'true' also for the
partition root, if a partitioned table is updated. That seems like a good
thing, although the function isn't used in core code, and I don't see any
reason for an FDW to call it on a partition root.

Author: Amit Langote
Discussion:
https://www.postgresql.org/message-id/CA%2BHiwqGEmiib8FLiHMhKB%2BCH5dRgHSLc5N5wnvc4kym%2BZYpQEQ%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1375422c7826a2bf387be29895e961614f69de4b

Modified Files
--------------
src/backend/commands/copy.c              |  24 +--
src/backend/commands/explain.c           |  17 +-
src/backend/commands/tablecmds.c         |   9 +-
src/backend/commands/trigger.c           |   2 +-
src/backend/executor/execMain.c          | 256 +++++++++----------------------
src/backend/executor/execParallel.c      |   1 -
src/backend/executor/execUtils.c         |  57 ++++---
src/backend/executor/nodeModifyTable.c   |  24 ++-
src/backend/nodes/copyfuncs.c            |   3 -
src/backend/nodes/outfuncs.c             |   4 -
src/backend/nodes/readfuncs.c            |   3 -
src/backend/optimizer/plan/createplan.c  |   2 -
src/backend/optimizer/plan/planner.c     |   3 -
src/backend/optimizer/plan/setrefs.c     |  17 +-
src/backend/replication/logical/worker.c |  32 ++--
src/include/executor/executor.h          |   5 +-
src/include/nodes/execnodes.h            |  18 +--
src/include/nodes/pathnodes.h            |   2 -
src/include/nodes/plannodes.h            |   8 -
19 files changed, 184 insertions(+), 303 deletions(-)


pgsql-committers by date:

Previous
From: Amit Kapila
Date:
Subject: pgsql: Fix the unstable output of tests added by commit 8fccf75834.
Next
From: Fujii Masao
Date:
Subject: Re: pgsql: postgres_fdw: reestablish new connection if cached one is detect