1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Fix bogus handling of "postponed" lateral quals.

When pulling a "postponed" qual from a LATERAL subquery up into the quals
of an outer join, we must make sure that the postponed qual is included
in those seen by make_outerjoininfo().  Otherwise we might compute a
too-small min_lefthand or min_righthand for the outer join, leading to
"JOIN qualification cannot refer to other relations" failures from
distribute_qual_to_rels.  Subtler errors in the created plan seem possible,
too, if the extra qual would only affect join ordering constraints.

Per bug #9041 from David Leverton.  Back-patch to 9.3.
This commit is contained in:
Tom Lane
2014-01-30 14:51:19 -05:00
parent e3ec8015d0
commit a4aa854cad
3 changed files with 59 additions and 27 deletions

View File

@@ -4012,6 +4012,28 @@ select c.*,a.*,ss1.q1,ss2.q1,ss3.* from
Output: i.f1
(34 rows)
-- check processing of postponed quals (bug #9041)
explain (verbose, costs off)
select * from
(select 1 as x) x cross join (select 2 as y) y
left join lateral (
select * from (select 3 as z) z where z.z = x.x
) zz on zz.z = y.y;
QUERY PLAN
----------------------------------------------
Nested Loop Left Join
Output: (1), (2), (3)
Join Filter: (((3) = (1)) AND ((3) = (2)))
-> Nested Loop
Output: (1), (2)
-> Result
Output: 1
-> Result
Output: 2
-> Result
Output: 3
(11 rows)
-- test some error cases where LATERAL should have been used but wasn't
select f1,g from int4_tbl a, (select f1 as g) ss;
ERROR: column "f1" does not exist

View File

@@ -1120,6 +1120,14 @@ select c.*,a.*,ss1.q1,ss2.q1,ss3.* from
) on c.q2 = ss2.q1,
lateral (select * from int4_tbl i where ss2.y > f1) ss3;
-- check processing of postponed quals (bug #9041)
explain (verbose, costs off)
select * from
(select 1 as x) x cross join (select 2 as y) y
left join lateral (
select * from (select 3 as z) z where z.z = x.x
) zz on zz.z = y.y;
-- test some error cases where LATERAL should have been used but wasn't
select f1,g from int4_tbl a, (select f1 as g) ss;
select f1,g from int4_tbl a, (select a.f1 as g) ss;