sort/limit across union all

Поиск
Список
Период
Сортировка
От Marc Morin
Тема sort/limit across union all
Дата
Msg-id 2BCEB9A37A4D354AA276774EE13FB8C263B0F4@mailserver.sandvine.com
обсуждение исходный текст
Список pgsql-performance
We have a large DB with partitioned tables in postgres.   We have had trouble with a ORDER/LIMIT type query.  The order and limit are not pushed down to the sub-tables....
 
CREATE TABLE base (
    foo int
);
 
CREATE TABLE bar_0
    extra int
) INHERITS (base);
ALTER TABLE bar ADD PRIMARY KEY (foo);
 
-- repeated for bar_0... bar_40
 
SELECT foo FROM base ORDER BY foo LIMIT 10;
 
is real slow. What is required to make the query planner generate the following instead... (code change i know, but how hard would it be?)
 
SELECT
    foo
FROM
(
    SELECT
        *
    FROM bar_0
    ORDER BY foo LIMIT 10
UNION ALL
    SELECT
        *
    FROM bar_1
    ORDER BY foo LIMIT 10
....
) AS base
ORDER BY foo
LIMIT 10;
 
 

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

Предыдущее
От: Ron
Дата:
Сообщение: Re: Hardware/OS recommendations for large databases
Следующее
От: Leigh Dyer
Дата:
Сообщение: Re: Help speeding up delete