Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d1a4db8

Browse files
committed
Improve EXPLAIN's ability to cope with LATERAL references in plans.
push_child_plan/pop_child_plan didn't bother to adjust the "ancestors" list of parent plan nodes when descending to a child plan node. I think this was okay when it was written, but it's not okay in the presence of LATERAL references, since a subplan node could easily be returning a LATERAL value back up to the same nestloop node that provides the value. Per changed regression test results, the omission led to failure to interpret Param nodes that have perfectly good interpretations.
1 parent e1a6375 commit d1a4db8

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/backend/utils/adt/ruleutils.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -2312,14 +2312,8 @@ push_child_plan(deparse_namespace *dpns, PlanState *ps,
23122312
/* Save state for restoration later */
23132313
*save_dpns = *dpns;
23142314

2315-
/*
2316-
* Currently we don't bother to adjust the ancestors list, because an
2317-
* OUTER_VAR or INNER_VAR reference really shouldn't contain any Params
2318-
* that would be set by the parent node itself. If we did want to adjust
2319-
* the list, lcons'ing dpns->planstate onto dpns->ancestors would be the
2320-
* appropriate thing --- and pop_child_plan would need to undo the change
2321-
* to the list.
2322-
*/
2315+
/* Link current plan node into ancestors list */
2316+
dpns->ancestors = lcons(dpns->planstate, dpns->ancestors);
23232317

23242318
/* Set attention on selected child */
23252319
set_deparse_planstate(dpns, ps);
@@ -2331,8 +2325,16 @@ push_child_plan(deparse_namespace *dpns, PlanState *ps,
23312325
static void
23322326
pop_child_plan(deparse_namespace *dpns, deparse_namespace *save_dpns)
23332327
{
2328+
List *ancestors;
2329+
2330+
/* Get rid of ancestors list cell added by push_child_plan */
2331+
ancestors = list_delete_first(dpns->ancestors);
2332+
23342333
/* Restore fields changed by push_child_plan */
23352334
*dpns = *save_dpns;
2335+
2336+
/* Make sure dpns->ancestors is right (may be unnecessary) */
2337+
dpns->ancestors = ancestors;
23362338
}
23372339

23382340
/*

src/test/regress/expected/join.out

+1-1
Original file line numberDiff line numberDiff line change
@@ -3172,7 +3172,7 @@ explain (costs off)
31723172
Nested Loop
31733173
-> Seq Scan on int8_tbl a
31743174
-> Hash Left Join
3175-
Hash Cond: (x.q2 = ($0))
3175+
Hash Cond: (x.q2 = (a.q1))
31763176
-> Seq Scan on int8_tbl x
31773177
-> Hash
31783178
-> Seq Scan on int4_tbl y

0 commit comments

Comments
 (0)