summaryrefslogtreecommitdiff
path: root/src/include/commands/explain.h
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2016-07-11 18:14:29 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2016-07-11 18:14:29 -0400
commit4d042999f94a4bc41b86baca5920cd4829e16895 (patch)
tree69228855271eb021a1965c5f8956d4f3c73e0491 /src/include/commands/explain.h
parenta670c24c382693c4f75e99c9292b2ed0f0d40a72 (diff)
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>
Diffstat (limited to 'src/include/commands/explain.h')
-rw-r--r--src/include/commands/explain.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/include/commands/explain.h b/src/include/commands/explain.h
index 2e48f0f2331..3d0a5abbc2f 100644
--- a/src/include/commands/explain.h
+++ b/src/include/commands/explain.h
@@ -35,13 +35,15 @@ typedef struct ExplainState
bool timing; /* print detailed node timing */
bool summary; /* print total planning and execution timing */
ExplainFormat format; /* output format */
- /* other states */
+ /* state for output formatting --- not reset for each new plan tree */
+ int indent; /* current indentation level */
+ List *grouping_stack; /* format-specific grouping state */
+ /* state related to the current plan tree (filled by ExplainPrintPlan) */
PlannedStmt *pstmt; /* top of plan */
List *rtable; /* range table */
List *rtable_names; /* alias names for RTEs */
- int indent; /* current indentation level */
- List *grouping_stack; /* format-specific grouping state */
List *deparse_cxt; /* context list for deparsing expressions */
+ Bitmapset *printed_subplans; /* ids of SubPlans we've printed */
} ExplainState;
/* Hook for plugins to get control in ExplainOneQuery() */