Re: Suboptimal query plan fixed by replacing OR with UNION

Поиск
Список
Период
Сортировка
От Steven Schlansker
Тема Re: Suboptimal query plan fixed by replacing OR with UNION
Дата
Msg-id 07D74A4C-F0A1-4DDE-A8D4-CD17BDFD00BE@likeness.com
обсуждение исходный текст
Ответ на Re: Suboptimal query plan fixed by replacing OR with UNION  (Gurjeet Singh <singh.gurjeet@gmail.com>)
Список pgsql-general
On Jul 6, 2012, at 9:24 PM, Gurjeet Singh wrote:

> On Thu, Jul 5, 2012 at 7:16 PM, Steven Schlansker <steven@likeness.com> wrote:
>
> On Jul 5, 2012, at 3:51 PM, Tom Lane wrote:
>
> > Steven Schlansker <steven@likeness.com> writes:
> >> Why is using an OR so awful here?
> >
> > Because the OR stops it from being a join (it possibly needs to return
> > some rows that are not in the semijoin of the two tables).
> >
> >> Why does it pick a sequential scan?  Is this an optimizer bug
> >
> > No.  It can't transform OR into a UNION because the results might not
> > be the same.  I assume you don't care about removal of duplicates, or
> > have some reason to know that there won't be any ... but the planner
> > doesn't know that.
> >
>
> Thanks for the insight here.  It still seems unfortunate that it picks a
> sequential scan -- but if there really is no more efficient way to do this,
> I will just rewrite the query.
>
> It might not be applicable to this case (because of the use of ANY in second branch of OR clause), but some databases
providea feature called OR-Optimization, where the optimizer breaks up the query at OR clause boundaries and uses UNION
ALLoperator to join the resulting queries, just like you did. Optimizer does need to add additional AND clauses to some
ofthe branches to make sure the result set is not affected. 
>

That sounds like a great optimization for Postgres, but unfortunately it's far outside of my skill set / time to
contribute,so I'd have to wait for a "real" PG dev to get to it :) 

> Just a thought.
> --
> Gurjeet Singh
> EnterpriseDB Corporation
> The Enterprise PostgreSQL Company
>


В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: recover as much as possible (xlog flush request not satisfied)
Следующее
От: Willy-Bas Loos
Дата:
Сообщение: Re: Tutorial On Connecting LibreOffice to PostgreSQL Available