Re: sequential scan on select distinct

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: sequential scan on select distinct
Дата
Msg-id 87sm8ry5rl.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: sequential scan on select distinct  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: sequential scan on select distinct
Список pgsql-performance
Tom Lane <tgl@sss.pgh.pa.us> writes:

> Greg Stark <gsstark@mit.edu> writes:
> > why isn't a "skip index scan" plan available? Well, nobody's written the code
> > yet.
>
> I don't really think it would be a useful plan anyway.

Well it would clearly be useful in this test case, where has a small number of
distinct values in a large table, and an index on the column. His plpgsql
function that emulates such a plan is an order of magnitude faster than the
hash aggregate plan even though it has to do entirely separate index scans for
each key value.

I'm not sure where the break-even point would be, but it would probably be
pretty low. Probably somewhere around the order of 1% distinct values in the
table. That might be uncommon, but certainly not impossible.

But regardless of how uncommon it is, it could be considered important in
another sense: when you need it there really isn't any alternative. It's an
algorithmic improvement with no bound on the performance difference. Nothing
short of using a manually maintained materialized view would bring the
performance into the same ballpark.

So even if it's only useful occasionally, not having the plan available can
leave postgres with no effective plan for what should be an easy query.


--
greg

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: sequential scan on select distinct
Следующее
От: Doug Y
Дата:
Сообщение: The never ending quest for clarity on shared_buffers