Re: sub-query optimization

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: sub-query optimization
Дата
Msg-id 11481.1045260507@sss.pgh.pa.us
обсуждение исходный текст
Ответ на sub-query optimization  (Brad Hilton <bhilton@vpop.net>)
Ответы Re: sub-query optimization  (Brad Hilton <bhilton@vpop.net>)
Список pgsql-sql
Brad Hilton <bhilton@vpop.net> writes:
> I am hoping someone can help explain why modifying the following query
> can effect such a huge change in speed.  The query is:

>       select * from articles
>       where exists
>        ( select 1 from article_categories
>          where
>          article_categories.article_id = articles.id and
>          article_categories.category_id is null
>        )

> ... If I modify the query slightly:

> --------
> select 1 from article_categories
>   -->
> select 1 from articles, article_categories
> ---------

> the query takes 98 msec.

Yeah, because then the sub-query is a constant (it doesn't depend on the
current outer row at all) and so it is only evaluated once, not once per
outer row.  Unfortunately, that approach probably gives the wrong
answers...
        regards, tom lane


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

Предыдущее
От: Robert Treat
Дата:
Сообщение: Re: postmaster -i & establishes three connections why?
Следующее
От: Brad Hilton
Дата:
Сообщение: Re: sub-query optimization