> I imagined making this work by delaying the plan creation for
> subqueries until the same time as create_plan() for the outer query.
Do you mean sublinks rather than subqueries? if so, we can get another
benefit I want very much.
explain (costs off) select * from t1 where t1.a = 1
and exists (select 1 from t2 where t2.a = t1.a and random() > 0);
QUERY PLAN
-----------------------------------------------------------------------
Seq Scan on t1
Filter: ((a = 1) AND EXISTS(SubPlan 1))
SubPlan 1
-> Seq Scan on t2
Filter: ((a = t1.a) AND (random() > '0'::double precision))
As for now, when we are planing the sublinks, we don't know t1.a = 1
which may lost some optimization chance. Considering the t2.a is a
partition key of t2, this would yield some big improvement for planning
a big number of partitioned table.
--
Best Regards
Andy Fan