Re: same plan, different time

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: same plan, different time
Дата
Msg-id 1580.1090039384@sss.pgh.pa.us
обсуждение исходный текст
Ответ на same plan, different time  (Litao Wu <litaowu@yahoo.com>)
Список pgsql-performance
Litao Wu <litaowu@yahoo.com> writes:
> SELECT *
> FROM user U LEFT JOIN user_timestamps T USING
> (user_id), user_alias A
> WHERE U.user_id = A.user_id  AND A.domain_id=7551070;

Ick.  Try changing the join order, perhaps

SELECT *
FROM (user U JOIN user_alias A ON (U.user_id = A.user_id))
     LEFT JOIN user_timestamps T USING (user_id)
WHERE A.domain_id=7551070;

As you have it, the entire LEFT JOIN has to be formed first,
and the useful restriction clause only gets applied later.

The fact that the case with 7551070 finishes quickly is just
blind luck --- the slow case is much more representative.

            regards, tom lane

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

Предыдущее
От: "Fred Moyer"
Дата:
Сообщение: Scaling with lazy index updates
Следующее
От: Josh Berkus
Дата:
Сообщение: Re: Scaling with lazy index updates