aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/allpaths.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/path/allpaths.c')
-rw-r--r--src/backend/optimizer/path/allpaths.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index 8e8f43735e0..27bec72d452 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -3295,8 +3295,10 @@ qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
Assert(!contain_window_function(qual));
/*
- * Examine all Vars used in clause; since it's a restriction clause, all
- * such Vars must refer to subselect output columns.
+ * Examine all Vars used in clause. Since it's a restriction clause, all
+ * such Vars must refer to subselect output columns ... unless this is
+ * part of a LATERAL subquery, in which case there could be lateral
+ * references.
*/
vars = pull_var_clause(qual, PVC_INCLUDE_PLACEHOLDERS);
foreach(vl, vars)
@@ -3316,7 +3318,19 @@ qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
break;
}
- Assert(var->varno == rti);
+ /*
+ * Punt if we find any lateral references. It would be safe to push
+ * these down, but we'd have to convert them into outer references,
+ * which subquery_push_qual lacks the infrastructure to do. The case
+ * arises so seldom that it doesn't seem worth working hard on.
+ */
+ if (var->varno != rti)
+ {
+ safe = false;
+ break;
+ }
+
+ /* Subqueries have no system columns */
Assert(var->varattno >= 0);
/* Check point 4 */