Commit c97a547a authored by Tom Lane's avatar Tom Lane

Partially restore qual scope checks in distribute_qual_to_rels().

The LATERAL implementation is now basically complete, and I still don't
see a cost-effective way to make an exact qual scope cross-check in the
presence of LATERAL.  However, I did add a PlannerInfo.hasLateralRTEs flag
along the way, so it's easy to make the check only when not hasLateralRTEs.
That seems to still be useful, and it beats having no check at all.
parent da3df998
...@@ -1103,21 +1103,20 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause, ...@@ -1103,21 +1103,20 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
relids = pull_varnos(clause); relids = pull_varnos(clause);
/* /*
* Cross-check: clause should contain no relids not within its scope. * Normally relids is a subset of qualscope, and we like to check that
* Otherwise the parser messed up. * here as a crosscheck on the parser and rewriter. That need not be the
* case when there are LATERAL RTEs, however: the clause could contain
* references to rels outside its syntactic scope as a consequence of
* pull-up of such references from a LATERAL subquery below it. So, only
* check if the query contains no LATERAL RTEs.
* *
* XXX temporarily disable the qualscope cross-check, which tends to * However, if it's an outer-join clause, we always insist that relids be
* reject quals pulled up from LATERAL subqueries. This is only in the * a subset of ojscope. This is safe because is_simple_subquery()
* nature of a debugging crosscheck anyway. I'm loath to remove it * disallows pullup of LATERAL subqueries that could cause the restriction
* permanently, but need to think a bit harder about how to replace it. * to be violated.
* See also disabled Assert below. (The ojscope test is still okay
* because we prevent pullup of LATERAL subqueries that might cause it to
* be violated.)
*/ */
#ifdef NOT_USED if (!root->hasLateralRTEs && !bms_is_subset(relids, qualscope))
if (!bms_is_subset(relids, qualscope))
elog(ERROR, "JOIN qualification cannot refer to other relations"); elog(ERROR, "JOIN qualification cannot refer to other relations");
#endif
if (ojscope && !bms_is_subset(relids, ojscope)) if (ojscope && !bms_is_subset(relids, ojscope))
elog(ERROR, "JOIN qualification cannot refer to other relations"); elog(ERROR, "JOIN qualification cannot refer to other relations");
...@@ -1272,9 +1271,8 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause, ...@@ -1272,9 +1271,8 @@ distribute_qual_to_rels(PlannerInfo *root, Node *clause,
if (outerjoin_delayed) if (outerjoin_delayed)
{ {
/* Should still be a subset of current scope ... */ /* Should still be a subset of current scope ... */
#ifdef NOT_USED /* XXX temporarily disabled for LATERAL */ Assert(root->hasLateralRTEs || bms_is_subset(relids, qualscope));
Assert(bms_is_subset(relids, qualscope)); Assert(ojscope == NULL || bms_is_subset(relids, ojscope));
#endif
/* /*
* Because application of the qual will be delayed by outer join, * Because application of the qual will be delayed by outer join,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment