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

Commit 8a8ed91

Browse files
committed
Handle PlaceHolderVar case in replace_varno_walker
This commit also retires sje_walker. This increases the generalty of replacing varno in the parse tree and simplifies the code. Discussion: https://postgr.es/m/18187-831da249cbd2ff8e%40postgresql.org Author: Richard Guo Reviewed-by: Andrei Lepikhov
1 parent 12915a5 commit 8a8ed91

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/backend/optimizer/plan/analyzejoins.c

+12-22
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,16 @@ replace_varno_walker(Node *node, ReplaceVarnoContext *ctx)
14561456
}
14571457
return false;
14581458
}
1459-
if (IsA(node, RestrictInfo))
1459+
else if (IsA(node, PlaceHolderVar))
1460+
{
1461+
PlaceHolderVar *phv = (PlaceHolderVar *) node;
1462+
1463+
phv->phrels = replace_relid(phv->phrels, ctx->from, ctx->to);
1464+
phv->phnullingrels = replace_relid(phv->phnullingrels, ctx->from, ctx->to);
1465+
1466+
/* fall through to recurse into the placeholder's expression */
1467+
}
1468+
else if (IsA(node, RestrictInfo))
14601469
{
14611470
RestrictInfo *rinfo = (RestrictInfo *) node;
14621471
int relid = -1;
@@ -1641,26 +1650,6 @@ update_eclasses(EquivalenceClass *ec, int from, int to)
16411650
ec->ec_relids = replace_relid(ec->ec_relids, from, to);
16421651
}
16431652

1644-
static bool
1645-
sje_walker(Node *node, ReplaceVarnoContext *ctx)
1646-
{
1647-
if (node == NULL)
1648-
return false;
1649-
1650-
if (IsA(node, Var))
1651-
{
1652-
Var *var = (Var *) node;
1653-
1654-
if (var->varno == ctx->from)
1655-
{
1656-
var->varno = ctx->to;
1657-
var->varnosyn = ctx->to;
1658-
}
1659-
return false;
1660-
}
1661-
return expression_tree_walker(node, sje_walker, (void *) ctx);
1662-
}
1663-
16641653
/*
16651654
* Remove a relation after we have proven that it participates only in an
16661655
* unneeded unique self join.
@@ -1868,7 +1857,8 @@ remove_self_join_rel(PlannerInfo *root, PlanRowMark *kmark, PlanRowMark *rmark,
18681857
}
18691858

18701859
/* Replace varno in all the query structures */
1871-
query_tree_walker(root->parse, sje_walker, &ctx, QTW_EXAMINE_SORTGROUP);
1860+
query_tree_walker(root->parse, replace_varno_walker, &ctx,
1861+
QTW_EXAMINE_SORTGROUP);
18721862

18731863
/* Replace links in the planner info */
18741864
remove_rel_from_query(root, toRemove, toKeep->relid, NULL, NULL);

0 commit comments

Comments
 (0)