Apply the "LIMIT 1" optimization to partial DISTINCT

Поиск
Список
Период
Сортировка
От Richard Guo
Тема Apply the "LIMIT 1" optimization to partial DISTINCT
Дата
Msg-id CAMbWs49JC0qvfUbzs-TVzgMpSSBiMJ_6sN=BaA9iohBgYkr=LA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Apply the "LIMIT 1" optimization to partial DISTINCT  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-hackers
In 5543677ec9 we introduced an optimization that uses Limit instead of
Unique to implement DISTINCT when all the DISTINCT pathkeys have been
marked as redundant.  I happened to notice that this optimization was
not applied to partial DISTINCT, which I think should be.  This can
improve plans in some cases, such as

-- on master
explain (costs off) select distinct four from tenk1 where four = 4;
                  QUERY PLAN
----------------------------------------------
 Limit
   ->  Gather
         Workers Planned: 4
         ->  Unique
               ->  Parallel Seq Scan on tenk1
                     Filter: (four = 4)
(6 rows)

-- patched
explain (costs off) select distinct four from tenk1 where four = 4;
                  QUERY PLAN
----------------------------------------------
 Limit
   ->  Gather
         Workers Planned: 4
         ->  Limit
               ->  Parallel Seq Scan on tenk1
                     Filter: (four = 4)
(6 rows)

Such queries might not be that common, but it's very cheap to apply this
optimization.

Attached is a patch for that.

Thanks
Richard
Вложения

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

Предыдущее
От: Masahiko Sawada
Дата:
Сообщение: Re: Remove unused fields in ReorderBufferTupleBuf
Следующее
От: David Rowley
Дата:
Сообщение: Re: A performance issue with Memoize