pgsql: Avoid passing query tlist around separately fromroot->processed - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Avoid passing query tlist around separately fromroot->processed
Date
Msg-id E1h9Bsh-0001k6-KZ@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Avoid passing query tlist around separately from root->processed_tlist.

In the dim past, the planner kept the fully-processed version of the query
targetlist (the result of preprocess_targetlist) in grouping_planner's
local variable "tlist", and only grudgingly passed it to individual other
routines as needed.  Later we discovered a need to still have it available
after grouping_planner finishes, and invented the root->processed_tlist
field for that purpose, but it wasn't used internally to grouping_planner;
the tlist was still being passed around separately in the same places as
before.

Now comes a proposed patch to allow appendrel expansion to add entries
to the processed tlist, well after preprocess_targetlist has finished
its work.  To avoid having to pass around the tlist explicitly, it's
proposed to allow appendrel expansion to modify root->processed_tlist.
That makes aliasing the tlist with assorted parameters and local
variables really scary.  It would accidentally work as long as the
tlist is initially nonempty, because then the List header won't move
around, but it's not exactly hard to think of ways for that to break.
Aliased values are poor programming practice anyway.

Hence, get rid of local variables and parameters that can be identified
with root->processed_tlist, in favor of just using that field directly.
And adjust comments to match.  (Some of the new comments speak as though
it's already possible for appendrel expansion to modify the tlist; that's
not true yet, but will happen in a later patch.)

Discussion: https://postgr.es/m/9d7c5112-cb99-6a47-d3be-cf1ee6862a1d@lab.ntt.co.jp

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/333ed246c6f351c4e8fe22c764b97793c4101b00

Modified Files
--------------
src/backend/optimizer/plan/planagg.c  | 19 +++++-----
src/backend/optimizer/plan/planmain.c |  6 ++--
src/backend/optimizer/plan/planner.c  | 65 +++++++++++++----------------------
src/include/nodes/pathnodes.h         |  9 +++--
src/include/optimizer/planmain.h      |  4 +--
5 files changed, 45 insertions(+), 58 deletions(-)


pgsql-committers by date:

Previous
From: Alvaro Herrera
Date:
Subject: pgsql: pgbench: doExecuteCommand -> executeMetaCommand
Next
From: Tomas Vondra
Date:
Subject: pgsql: Add support for multivariate MCV lists