mirror of
https://github.com/postgres/postgres.git
synced 2025-05-29 16:21:20 +03:00
Fix old oversight in join removal logic.
Commit 9e7e29c75ad441450f9b8287bd51c13521641e3b introduced an Assert that join removal didn't reduce the eval_at set of any PlaceHolderVar to empty. At first glance it looks like join_is_removable ensures that's true --- but actually, the loop in join_is_removable skips PlaceHolderVars that are not referenced above the join due to be removed. So, if we don't want any empty eval_at sets, the right thing to do is to delete any now-unreferenced PlaceHolderVars from the data structure entirely. Per fuzz testing by Andreas Seltenreich. Back-patch to 9.3 where the aforesaid Assert was added.
This commit is contained in:
parent
e663f75616
commit
de0227d8ae
@ -464,17 +464,25 @@ remove_rel_from_query(PlannerInfo *root, int relid, Relids joinrelids)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Likewise remove references from PlaceHolderVar data structures.
|
* Likewise remove references from PlaceHolderVar data structures,
|
||||||
|
* removing any no-longer-needed placeholders entirely.
|
||||||
*/
|
*/
|
||||||
foreach(l, root->placeholder_list)
|
for (l = list_head(root->placeholder_list); l != NULL; l = nextl)
|
||||||
{
|
{
|
||||||
PlaceHolderInfo *phinfo = (PlaceHolderInfo *) lfirst(l);
|
PlaceHolderInfo *phinfo = (PlaceHolderInfo *) lfirst(l);
|
||||||
|
|
||||||
|
nextl = lnext(l);
|
||||||
|
if (bms_is_subset(phinfo->ph_needed, joinrelids))
|
||||||
|
root->placeholder_list = list_delete_ptr(root->placeholder_list,
|
||||||
|
phinfo);
|
||||||
|
else
|
||||||
|
{
|
||||||
phinfo->ph_eval_at = bms_del_member(phinfo->ph_eval_at, relid);
|
phinfo->ph_eval_at = bms_del_member(phinfo->ph_eval_at, relid);
|
||||||
Assert(!bms_is_empty(phinfo->ph_eval_at));
|
Assert(!bms_is_empty(phinfo->ph_eval_at));
|
||||||
Assert(!bms_is_member(relid, phinfo->ph_lateral));
|
Assert(!bms_is_member(relid, phinfo->ph_lateral));
|
||||||
phinfo->ph_needed = bms_del_member(phinfo->ph_needed, relid);
|
phinfo->ph_needed = bms_del_member(phinfo->ph_needed, relid);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove any joinquals referencing the rel from the joininfo lists.
|
* Remove any joinquals referencing the rel from the joininfo lists.
|
||||||
|
@ -3862,6 +3862,22 @@ SELECT * FROM
|
|||||||
1 | 4567890123456789 | -4567890123456789 | 4567890123456789
|
1 | 4567890123456789 | -4567890123456789 | 4567890123456789
|
||||||
(5 rows)
|
(5 rows)
|
||||||
|
|
||||||
|
rollback;
|
||||||
|
-- another join removal bug: we must clean up correctly when removing a PHV
|
||||||
|
begin;
|
||||||
|
create temp table uniquetbl (f1 text unique);
|
||||||
|
explain (costs off)
|
||||||
|
select t1.* from
|
||||||
|
uniquetbl as t1
|
||||||
|
left join (select *, '***'::text as d1 from uniquetbl) t2
|
||||||
|
on t1.f1 = t2.f1
|
||||||
|
left join uniquetbl t3
|
||||||
|
on t2.d1 = t3.f1;
|
||||||
|
QUERY PLAN
|
||||||
|
--------------------------
|
||||||
|
Seq Scan on uniquetbl t1
|
||||||
|
(1 row)
|
||||||
|
|
||||||
rollback;
|
rollback;
|
||||||
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs
|
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs
|
||||||
select * from
|
select * from
|
||||||
|
@ -1247,6 +1247,21 @@ SELECT * FROM
|
|||||||
|
|
||||||
rollback;
|
rollback;
|
||||||
|
|
||||||
|
-- another join removal bug: we must clean up correctly when removing a PHV
|
||||||
|
begin;
|
||||||
|
|
||||||
|
create temp table uniquetbl (f1 text unique);
|
||||||
|
|
||||||
|
explain (costs off)
|
||||||
|
select t1.* from
|
||||||
|
uniquetbl as t1
|
||||||
|
left join (select *, '***'::text as d1 from uniquetbl) t2
|
||||||
|
on t1.f1 = t2.f1
|
||||||
|
left join uniquetbl t3
|
||||||
|
on t2.d1 = t3.f1;
|
||||||
|
|
||||||
|
rollback;
|
||||||
|
|
||||||
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs
|
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs
|
||||||
|
|
||||||
select * from
|
select * from
|
||||||
|
Loading…
x
Reference in New Issue
Block a user