pgsql: Print a given subplan only once in EXPLAIN. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Print a given subplan only once in EXPLAIN.
Date
Msg-id E1bMjTI-0003Ti-6G@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Print a given subplan only once in EXPLAIN.

We have, for a very long time, allowed the same subplan (same member of the
PlannedStmt.subplans list) to be referenced by more than one SubPlan node;
this avoids problems for cases such as subplans within an IndexScan's
indxqual and indxqualorig fields.  However, EXPLAIN had not gotten the memo
and would print each reference as though it were an independent identical
subplan.  To fix, track plan_ids of subplans we've printed and don't print
the same plan_id twice.  Per report from Pavel Stehule.

BTW: the particular case of IndexScan didn't cause visible duplication
in a plain EXPLAIN, only EXPLAIN ANALYZE, because in the former case we
short-circuit executor startup before the indxqual field is processed by
ExecInitExpr.  That seems like it could easily lead to other EXPLAIN
problems in future, but it's not clear how to avoid it without breaking
the "EXPLAIN a plan using hypothetical indexes" use-case.  For now I've
left that issue alone.

Although this is a longstanding bug, it's purely cosmetic (no great harm
is done by the repeat printout) and we haven't had field complaints before.
So I'm hesitant to back-patch it, especially since there is some small risk
of ABI problems due to the need to add a new field to ExplainState.

In passing, rearrange order of fields in ExplainState to be less random,
and update some obsolete comments about when/where to initialize them.

Report: <CAFj8pRAimq+NK-menjt+3J4-LFoodDD8Or6=Lc_stcFD+eD4DA@mail.gmail.com>

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4d042999f94a4bc41b86baca5920cd4829e16895

Modified Files
--------------
src/backend/commands/explain.c | 22 ++++++++++++++++++++--
src/include/commands/explain.h |  8 +++++---
2 files changed, 25 insertions(+), 5 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Improve output of psql's \df+ command.
Next
From: Peter Eisentraut
Date:
Subject: pgsql: doc: Fix typo