]> granicus.if.org Git - postgresql/commit
Print a given subplan only once in EXPLAIN.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 Jul 2016 22:14:29 +0000 (18:14 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 11 Jul 2016 22:14:29 +0000 (18:14 -0400)
commit4d042999f94a4bc41b86baca5920cd4829e16895
tree69228855271eb021a1965c5f8956d4f3c73e0491
parenta670c24c382693c4f75e99c9292b2ed0f0d40a72
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>
src/backend/commands/explain.c
src/include/commands/explain.h