Re: Subquery in a JOIN not getting restricted?

Поиск
Список
Период
Сортировка
От Merlin Moncure
Тема Re: Subquery in a JOIN not getting restricted?
Дата
Msg-id CAHyXU0zWLRquK9xu4SbTrxyOTA2kbT1b3r4_H4KdEzE-hvVgoA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Subquery in a JOIN not getting restricted?  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Ответы Re: Subquery in a JOIN not getting restricted?  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Список pgsql-performance
On Wed, Nov 9, 2011 at 9:15 AM, Kevin Grittner
<Kevin.Grittner@wicourts.gov> wrote:
> Jay Levitt <jay.levitt@gmail.com> wrote:
>
>> I don't get why the GROUP BY in this subquery forces it to scan
>> the entire users table (seq scan here, index scan on a larger
>> table) when there's only one row in users that can match:
>
>> explain analyze
>> select questions.id
>> from questions
>> join (
>>    select u.id
>>    from users as u
>>    group by u.id
>> ) as s
>> on s.id = questions.user_id
>> where questions.id = 1;
>
>>   Total runtime: 1.262 ms
>
> Are you sure there's a plan significantly faster than 1.3 ms?

Well, this may not fit the OP's 'real' query, but the inner subquery
is probably better written as a semi-join (WHERE EXISTS).

merlin

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

Предыдущее
От: Greg Smith
Дата:
Сообщение: Re: WAL partition filling up after high WAL activity
Следующее
От: "Kevin Grittner"
Дата:
Сообщение: Re: Subquery in a JOIN not getting restricted?