[BUGS] Re: Query planner skipping index depending on DISTINCT parameterorder (2)

Поиск
Список
Период
Сортировка
От Tomas Vondra
Тема [BUGS] Re: Query planner skipping index depending on DISTINCT parameterorder (2)
Дата
Msg-id eaee8428-8d38-9ee6-b129-a29eeb8a80c2@2ndquadrant.com
обсуждение исходный текст
Ответ на [BUGS] Re: Query planner skipping index depending on DISTINCT parameterorder (2)  (Greg Stark <stark@mit.edu>)
Список pgsql-bugs

On 09/25/2017 12:43 PM, Greg Stark wrote:
> On 17 September 2017 at 18:15, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
>> For plain DISTINCT, yeah we could consider other orderings ... but
>> we're rather unlikely to find an index that matches all the output
>> columns, regardless of what order they're in.  So it's just not that
>> exciting.
> 
> I don't follow this part. Are you saying a simple "select distinct a,b
> from table" is unlikely to find a matching index on <b,a>? Don't we
> already do exactly this for "select a,b from table group by a,b"?

FWIW we don't do that:
   create table t (a int, b int);   insert into t select mod(i, 1000), mod(i, 1000)                  from
generate_series(1,1000000)S(i);   create index on t (a,b);   vacuum analyze t;
 
   explain (costs off) select a, b, count(*) from t group by a , b;                    QUERY PLAN
--------------------------------------------   GroupAggregate      Group Key: a, b      ->  Index Only Scan using
t_a_b_idxon t   (3 rows)
 
   explain (costs off) select a, b, count(*) from t group by b , a;           QUERY PLAN   ---------------------------
 GroupAggregate      Group Key: b, a      ->  Sort            Sort Key: b, a            ->  Seq Scan on t   (5 rows)
 

But yeah, fixing this is probably more worthwhile than the original
DISTINCT ON issue ...

regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

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

Предыдущее
От: evan.r.rempel@gmail.com
Дата:
Сообщение: [BUGS] BUG #14839: failed archive log messages are merged as 1 message
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: [BUGS] BUG #14815: event trigger in extension