diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-11-16 20:06:09 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-11-16 20:06:09 -0500 |
commit | adaf34241acd83afaa45a8b614b6484a285da847 (patch) | |
tree | 0707fe1e75854c32c0fbadf071040fdfb22fc5d9 /src/backend/utils/adt/ruleutils.c | |
parent | 5db195f76f279a120edee448ad74d43578f56edd (diff) | |
download | postgresql-adaf34241acd83afaa45a8b614b6484a285da847.tar.gz postgresql-adaf34241acd83afaa45a8b614b6484a285da847.zip |
Improve ruleutils' printout of LATERAL references within subplans.
Commit 1cc29fe7c, which taught EXPLAIN to print PARAM_EXEC Params as
the referenced expressions, included some checks to prevent matching
Params found in SubPlans or InitPlans to NestLoopParams of upper query
levels. At the time, this seemed possibly necessary to avoid false
matches because of the planner's habit of re-using the same PARAM_EXEC
slot in multiple places in a plan. Furthermore, in the absence of
LATERAL no such reference could be valid anyway. But it's possible
now that we have LATERAL, and in the wake of 46c508fbc and 1db5667ba
I believe the false-match hazard is gone. Hence, remove the
in_same_plan_level checks. As shown in the regression test changes,
this provides a useful improvement in readability for EXPLAIN of
LATERAL-using subplans.
Richard Guo, reviewed by Greg Stark and myself
Discussion: https://postgr.es/m/CAMbWs4-YSOcQXAagJetP95cAeZPqzOy5kM5yijG0PVW5ztRb4w@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r-- | src/backend/utils/adt/ruleutils.c | 33 |
1 files changed, 4 insertions, 29 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c index c5a49d0be34..b4c04075887 100644 --- a/src/backend/utils/adt/ruleutils.c +++ b/src/backend/utils/adt/ruleutils.c @@ -7896,12 +7896,10 @@ find_param_referent(Param *param, deparse_context *context, { deparse_namespace *dpns; Plan *child_plan; - bool in_same_plan_level; ListCell *lc; dpns = (deparse_namespace *) linitial(context->namespaces); child_plan = dpns->plan; - in_same_plan_level = true; foreach(lc, dpns->ancestors) { @@ -7909,13 +7907,10 @@ find_param_referent(Param *param, deparse_context *context, ListCell *lc2; /* - * NestLoops transmit params to their inner child only; also, once - * we've crawled up out of a subplan, this couldn't possibly be - * the right match. + * NestLoops transmit params to their inner child only. */ if (IsA(ancestor, NestLoop) && - child_plan == innerPlan(ancestor) && - in_same_plan_level) + child_plan == innerPlan(ancestor)) { NestLoop *nl = (NestLoop *) ancestor; @@ -7973,34 +7968,14 @@ find_param_referent(Param *param, deparse_context *context, } } - /* We have emerged from a subplan. */ - in_same_plan_level = false; - /* SubPlan isn't a kind of Plan, so skip the rest */ continue; } /* - * Check to see if we're emerging from an initplan of the current - * ancestor plan. Initplans never have any parParams, so no need - * to search that list, but we need to know if we should reset - * in_same_plan_level. + * We need not consider the ancestor's initPlan list, since + * initplans never have any parParams. */ - foreach(lc2, ((Plan *) ancestor)->initPlan) - { - SubPlan *subplan = lfirst_node(SubPlan, lc2); - - if (child_plan != (Plan *) list_nth(dpns->subplans, - subplan->plan_id - 1)) - continue; - - /* No parameters to be had here. */ - Assert(subplan->parParam == NIL); - - /* We have emerged from an initplan. */ - in_same_plan_level = false; - break; - } /* No luck, crawl up to next ancestor */ child_plan = (Plan *) ancestor; |