1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Further adjustments to PlaceHolderVar removal.

A new test case from Andreas Seltenreich showed that we were still a bit
confused about removing PlaceHolderVars during join removal.  Specifically,
remove_rel_from_query would remove a PHV that was used only underneath
the removable join, even if the place where it's used was the join partner
relation and not the join clause being deleted.  This would lead to a
"too late to create a new PlaceHolderInfo" error later on.  We can defend
against that by checking ph_eval_at to see if the PHV could possibly be
getting used at some partner rel.

Also improve some nearby LATERAL-related logic.  I decided that the check
on ph_lateral needed to take precedence over the check on ph_needed, in
case there's a lateral reference underneath the join being considered.
(That may be impossible, but I'm not convinced of it, and it's easy enough
to defend against the case.)  Also, I realized that remove_rel_from_query's
logic for updating LateralJoinInfos is dead code, because we don't build
those at all until after join removal.

Back-patch to 9.3.  Previous versions didn't have the LATERAL issues, of
course, and they also didn't attempt to remove PlaceHolderInfos during join
removal.  (I'm starting to wonder if changing that was really such a great
idea.)
This commit is contained in:
Tom Lane
2015-08-07 14:13:38 -04:00
parent 846f8c9483
commit 89db83922a
3 changed files with 83 additions and 27 deletions

View File

@ -3878,6 +3878,47 @@ select t1.* from
Seq Scan on uniquetbl t1
(1 row)
explain (costs off)
select t0.*
from
text_tbl t0
left join
(select case t1.ten when 0 then 'doh!'::text else null::text end as case1,
t1.stringu2
from tenk1 t1
join int4_tbl i4 ON i4.f1 = t1.unique2
left join uniquetbl u1 ON u1.f1 = t1.string4) ss
on t0.f1 = ss.case1
where ss.stringu2 !~* ss.case1;
QUERY PLAN
--------------------------------------------------------------------------------------------
Nested Loop
Join Filter: (CASE t1.ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END = t0.f1)
-> Nested Loop
-> Seq Scan on int4_tbl i4
-> Index Scan using tenk1_unique2 on tenk1 t1
Index Cond: (unique2 = i4.f1)
Filter: (stringu2 !~* CASE ten WHEN 0 THEN 'doh!'::text ELSE NULL::text END)
-> Materialize
-> Seq Scan on text_tbl t0
(9 rows)
select t0.*
from
text_tbl t0
left join
(select case t1.ten when 0 then 'doh!'::text else null::text end as case1,
t1.stringu2
from tenk1 t1
join int4_tbl i4 ON i4.f1 = t1.unique2
left join uniquetbl u1 ON u1.f1 = t1.string4) ss
on t0.f1 = ss.case1
where ss.stringu2 !~* ss.case1;
f1
------
doh!
(1 row)
rollback;
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs
select * from

View File

@ -1260,6 +1260,31 @@ select t1.* from
left join uniquetbl t3
on t2.d1 = t3.f1;
explain (costs off)
select t0.*
from
text_tbl t0
left join
(select case t1.ten when 0 then 'doh!'::text else null::text end as case1,
t1.stringu2
from tenk1 t1
join int4_tbl i4 ON i4.f1 = t1.unique2
left join uniquetbl u1 ON u1.f1 = t1.string4) ss
on t0.f1 = ss.case1
where ss.stringu2 !~* ss.case1;
select t0.*
from
text_tbl t0
left join
(select case t1.ten when 0 then 'doh!'::text else null::text end as case1,
t1.stringu2
from tenk1 t1
join int4_tbl i4 ON i4.f1 = t1.unique2
left join uniquetbl u1 ON u1.f1 = t1.string4) ss
on t0.f1 = ss.case1
where ss.stringu2 !~* ss.case1;
rollback;
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs