Bruce Momjian wrote:
>
> Isn't it something that takes only a few hours to implement. We can't
> keep telling people to us EXISTS, especially because most SQL people
> think correlated queries are slower that non-correlated ones. Can we
> just on-the-fly rewrite the query to use exists?
This seems easy to implement. We could look does subquery have
aggregates or not before calling union_planner() in
subselect.c:_make_subplan() and rewrite it (change
slink->subLinkType from IN to EXISTS and add quals).
Without caching implemented IN-->EXISTS rewriting always
has sence.
After implementation of caching we probably should call union_planner()
for both original/modified subqueries and compare costs/sizes
of EXISTS/IN_with_caching plans and maybe even make
decision what plan to use after parent query is planned
and we know for how many parent rows subplan will be executed.
Vadim