Re: Get more from indices.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Get more from indices.
Дата
Msg-id 23472.1383231585@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Get more from indices.  (Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp>)
Ответы Re: Get more from indices.  (Robert Haas <robertmhaas@gmail.com>)
Re: Get more from indices.  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp> writes:
> Unique indexes can sort the tuples in corresponding tables
> prefectly. So this query might can use index.

>> uniquetest=# create table t (a int, b int, c int, d text);
>> uniquetest=# create unique index i_t_pkey on t(a, b);
>> uniquetest=# insert into t
>> (select a % 10, a / 10, a, 't' from generate_series(0, 100000) a);
>> uniquetest=# analyze;
>> 
>> uniquetest=# explain (costs off, analyze on) select distinct * from t;

ISTM the right way to deal with this is not what you've done here, but
just to deem the DISTINCT a no-op if there's a unique index on some subset
of the distinct-ed columns.  This query is actually legally satisfied by
a simple seqscan, which would be faster than either of the plans you
mention.  In any case, it seems like a bad idea to me to conflate
distinct-ness with ordering, so I don't like what you did to PathKeys.

Having said that, there is the kernel of a useful idea here, I think.
The reason you don't get an indexscan already is that the DISTINCT
assumes it needs to sort by (a,b,c,d), which an index on just (a,b)
doesn't appear to satisfy.  However, if the index is unique, wouldn't
scanning the index produce data that actually satisfies the longer sort
key?  It doesn't matter what the values of c,d are if there are no
duplicates in the a,b columns.  So maybe as a separate patch, we could
look at claiming that a unique index satisfies the entire query_pathkeys
if it matches the first N columns of that.
        regards, tom lane



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

Предыдущее
От: Noah Misch
Дата:
Сообщение: ERROR during end-of-xact/FATAL
Следующее
От: "MauMau"
Дата:
Сообщение: Re: [bug fix] PostgreSQL fails to start on Windows if it crashes after tablespace creation