Querying distinct values from a large table

Поиск
Список
Период
Сортировка
От Igor Lobanov
Тема Querying distinct values from a large table
Дата
Msg-id 45BF02DE.7080605@swsoft.com
обсуждение исходный текст
Ответы Re: Querying distinct values from a large table  (Richard Huxton <dev@archonet.com>)
Re: Querying distinct values from a large table  (Bruno Wolff III <bruno@wolff.to>)
Список pgsql-performance
Greetings!

I have rather large table with about 5 millions of rows and a dozen of
columns. Let's suppose that columns are named 'a', 'b', 'c' etc. I need
to query distinct pairs of ('a';'b') from this table.

I use following query:

SELECT DISTINCT a, b FROM tbl;

but unfortunately, it takes forever to complete. Explaining gives me
information that bottleneck is seqscan on 'tbl', which eats much time.

Creating compound index on this table using following statement:

CREATE INDEX tbl_a_b_idx ON tbl( a, b );

gives no effect, postgres simply ignores it, at least according to the
EXPLAIN output.

Is there any way to somehow improve the performance of this operation?
Table can not be changed.

--
Igor Lobanov
Internal Development Engineer
SWsoft, Inc.


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

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: Partitioning
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: Querying distinct values from a large table