Re: improving performance of UNION and ORDER BY

Поиск
Список
Период
Сортировка
От Jean-Luc Lachance
Тема Re: improving performance of UNION and ORDER BY
Дата
Msg-id 3C7FF3B6.B27B00E0@nsd.ca
обсуждение исходный текст
Ответ на improving performance of UNION and ORDER BY  (Chris Gamache <cgg007@yahoo.com>)
Ответы Re: improving performance of UNION and ORDER BY  (Chris Gamache <cgg007@yahoo.com>)
Список pgsql-general
Chris,

I believe you can cut down the processing time by including the order by
and limit in each select:

(SELECT ... ORDER BY 2 DESC, 4 LIMIT 20)
union
(SELECT ... ORDER BY 2 DESC, 4 LIMIT 20)
ORDER BY 2 DESC, 4 LIMIT 20

Give it a try and let me know


JLL

P.S.

Question:  Why not have a single table with a field log_type in ( 'A',
'B') ???



Chris Gamache wrote:
>
> Three tables...
> [...]
>
> I imagine the combination of UNION and ORDER BY causes the problem, since
> Postgres has to locate all the rows that match the search criteria, merge them,
> order them, then return the top 20...
>
> Any suggestions? Did I forget to provide any data that would make things
> clearer?

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

Предыдущее
От: "Cornelia Boenigk"
Дата:
Сообщение: Qestion about CREATE FUNCTION
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Qestion about CREATE FUNCTION