summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/var.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-08-18 14:10:17 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-08-18 14:10:17 -0400
commit084a29c94f94b5a08aec9f68f3cfaf252f4fa17c (patch)
tree2db6b7aa778f8299fce6cbfde5ce63efc91eb5cf /src/backend/optimizer/util/var.c
parent18226849ea12c566fb2b3be505448e0ba289ea10 (diff)
Another round of planner fixes for LATERAL.
Formerly, subquery pullup had no need to examine other entries in the range table, since they could not contain any references to the subquery being pulled up. That's no longer true with LATERAL, so now we need to be able to visit rangetable subexpressions to replace Vars referencing the pulled-up subquery. Also, this means that extract_lateral_references must be unsurprised at encountering lateral PlaceHolderVars, since such might be created when pulling up a subquery that's underneath an outer join with respect to the lateral reference.
Diffstat (limited to 'src/backend/optimizer/util/var.c')
-rw-r--r--src/backend/optimizer/util/var.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/backend/optimizer/util/var.c b/src/backend/optimizer/util/var.c
index 1d88a778203..21b7753f05d 100644
--- a/src/backend/optimizer/util/var.c
+++ b/src/backend/optimizer/util/var.c
@@ -247,11 +247,8 @@ pull_varattnos_walker(Node *node, pull_varattnos_context *context)
/*
* pull_vars_of_level
- * Create a list of all Vars referencing the specified query level
- * in the given parsetree.
- *
- * This is used on unplanned parsetrees, so we don't expect to see any
- * PlaceHolderVars.
+ * Create a list of all Vars (and PlaceHolderVars) referencing the
+ * specified query level in the given parsetree.
*
* Caution: the Vars are not copied, only linked into the list.
*/
@@ -288,7 +285,15 @@ pull_vars_walker(Node *node, pull_vars_context *context)
context->vars = lappend(context->vars, var);
return false;
}
- Assert(!IsA(node, PlaceHolderVar));
+ if (IsA(node, PlaceHolderVar))
+ {
+ PlaceHolderVar *phv = (PlaceHolderVar *) node;
+
+ if (phv->phlevelsup == context->sublevels_up)
+ context->vars = lappend(context->vars, phv);
+ /* we don't want to look into the contained expression */
+ return false;
+ }
if (IsA(node, Query))
{
/* Recurse into RTE subquery or not-yet-planned sublink subquery */