}
/*
- * 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);
- phinfo->ph_eval_at = bms_del_member(phinfo->ph_eval_at, relid);
- Assert(!bms_is_empty(phinfo->ph_eval_at));
- Assert(!bms_is_member(relid, phinfo->ph_lateral));
- phinfo->ph_needed = bms_del_member(phinfo->ph_needed, relid);
+ 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);
+ Assert(!bms_is_empty(phinfo->ph_eval_at));
+ Assert(!bms_is_member(relid, phinfo->ph_lateral));
+ phinfo->ph_needed = bms_del_member(phinfo->ph_needed, relid);
+ }
}
/*
1 | 4567890123456789 | -4567890123456789 | 4567890123456789
(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;
-- bug #8444: we've historically allowed duplicate aliases within aliased JOINs
select * from
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
select * from