Store information about range-table flattening in the final plan.

Suppose that we're currently planning a query and, when that same
query was previously planned and executed, we learned something about
how a certain table within that query should be planned. We want to
take note when that same table is being planned during the current
planning cycle, but this is difficult to do, because the RTI of the
table from the previous plan won't necessarily be equal to the RTI
that we see during the current planning cycle. This is because each
subquery has a separate range table during planning, but these are
flattened into one range table when constructing the final plan,
changing RTIs.

Commit 8c49a484e8ebb0199fba4bd68eaaedaf49b48ed0 allows us to match up
subqueries seen in the previous planning cycles with the subqueries
currently being planned just by comparing textual names, but that's
not quite enough to let us deduce anything about individual tables,
because we don't know where each subquery's range table appears in
the final, flattened range table.

To fix that, store a list of SubPlanRTInfo objects in the final
planned statement, each including the name of the subplan, the offset
at which it begins in the flattened range table, and whether or not
it was a dummy subplan -- if it was, some RTIs may have been dropped
from the final range table, but also there's no need to control how
a dummy subquery gets planned. The toplevel subquery has no name and
always begins at rtoffset 0, so we make no entry for it.

This commit teaches pg_overexplain's RANGE_TABLE option to make use
of this new data to display the subquery name for each range table
entry.

Reviewed-by: Lukas Fittl <[email protected]>
Reviewed-by: Jakub Wartak <[email protected]>
Reviewed-by: Greg Burd <[email protected]>
Reviewed-by: Jacob Champion <[email protected]>
Reviewed-by: Amit Langote <[email protected]>
Reviewed-by: Haibo Yan <[email protected]>
Reviewed-by: Alexandra Wang <[email protected]>
Discussion: 
http://postgr.es/m/CA+TgmoZ-Jh1T6QyWoCODMVQdhTUPYkaZjWztzP1En4=zhok...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/adbad833f3d9e9176e8d7005f15ea6056900227d

Modified Files
--------------
contrib/pg_overexplain/expected/pg_overexplain.out | 109 +++++++++++++++++++++
contrib/pg_overexplain/pg_overexplain.c            |  36 +++++++
contrib/pg_overexplain/sql/pg_overexplain.sql      |  10 ++
src/backend/optimizer/plan/planner.c               |   1 +
src/backend/optimizer/plan/setrefs.c               |  20 ++++
src/include/nodes/pathnodes.h                      |   3 +
src/include/nodes/plannodes.h                      |  17 ++++
src/tools/pgindent/typedefs.list                   |   1 +
8 files changed, 197 insertions(+)

Reply via email to