aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/explain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-07-03 01:35:22 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-07-03 01:35:22 -0400
commitd3d3ec0d890412f3b39a70e8fd08edf17e3c9f7c (patch)
tree3664ff32406e18ee4f81c790e79267db630bb954 /src/backend/commands/explain.c
parent4b09299e4723276c70c5b25de38578d642490179 (diff)
downloadpostgresql-d3d3ec0d890412f3b39a70e8fd08edf17e3c9f7c.tar.gz
postgresql-d3d3ec0d890412f3b39a70e8fd08edf17e3c9f7c.zip
Fix EXPLAIN to handle gating Result nodes within inner-indexscan subplans.
It is possible for a NestLoop plan node to pass an OUTER Var into an "inner indexscan" that is an Append construct (derived from an inheritance tree or UNION ALL subquery). The OUTER tuple is then passed down at runtime to the leaf indexscan node(s) where it will actually be used. EXPLAIN has to likewise pass the information about the nestloop's outer subplan down through the Append node, else it will fail to print the outer-reference Vars (with complaints like "bogus varno: 65001"). However, there was a case missed in all this: we could also have gating Result nodes that were inserted into the appendrel plan tree to deal with pseudoconstant qual conditions. So EXPLAIN has to pass down the outer plan node to a Result's subplan, too. Per example from Jon Nelson. The problem is gone in 9.1 because we replaced the nestloop outer-tuple kluge with a Param-based data transfer mechanism. Also, so far as I can tell, the case can't happen before 8.4 because of restrictions on what sorts of appendrel members could be pulled up into the parent query. So this patch is only needed for 8.4 and 9.0.
Diffstat (limited to 'src/backend/commands/explain.c')
-rw-r--r--src/backend/commands/explain.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 45e8edf5957..54f82e6dada 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -980,11 +980,14 @@ explain_outNode(StringInfo str,
/*
* Ordinarily we don't pass down our own outer_plan value to our child
* nodes, but in bitmap scan trees we must, since the bottom
- * BitmapIndexScan nodes may have outer references.
+ * BitmapIndexScan nodes may have outer references. Also, we must do
+ * so at a Result node, because it might be a pseudoconstant-qual
+ * gating node inserted into an inner indexscan plan.
*/
explain_outNode(str, outerPlan(plan),
outerPlanState(planstate),
- IsA(plan, BitmapHeapScan) ? outer_plan : NULL,
+ (IsA(plan, BitmapHeapScan) ||
+ IsA(plan, Result)) ? outer_plan : NULL,
indent + 3, es);
}