Re: [HACKERS] Idea for speeding up uncorrelated subqueries - Mailing list pgsql-hackers

From Vadim Mikheev
Subject Re: [HACKERS] Idea for speeding up uncorrelated subqueries
Date
Msg-id 37AA5E35.66C03F2E@krs.ru
Whole thread Raw
In response to Re: [HACKERS] Idea for speeding up uncorrelated subqueries  (Bruce Momjian <maillist@candle.pha.pa.us>)
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] Idea for speeding up uncorrelated subqueries
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] Idea for speeding up uncorrelated subqueries