Re: Apply the "LIMIT 1" optimization to partial DISTINCT

Поиск
Список
Период
Сортировка
От David Rowley
Тема Re: Apply the "LIMIT 1" optimization to partial DISTINCT
Дата
Msg-id CAApHDvqU7_Wryoi0v_PeCPhtgKUzgttrRb2DAzBf+R1PpMzMTw@mail.gmail.com
обсуждение исходный текст
Ответ на Apply the "LIMIT 1" optimization to partial DISTINCT  (Richard Guo <guofenglinux@gmail.com>)
Ответы Re: Apply the "LIMIT 1" optimization to partial DISTINCT  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-hackers
On Fri, 26 Jan 2024 at 20:42, Richard Guo <guofenglinux@gmail.com> wrote:
>
> 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.

It seems very likely that the parallel plan would only be chosen if
the planner estimated there'd just be 1 row before the distinct.
Otherwise, the non-partial path's LIMIT would come out so cheap that
it would be unlikely that the parallel plan would be picked.

I think your test case only chooses the parallel plan because you're
doing FROM tenk1 WHERE four=4.  And that column only contains values
0..3.

However, having said that. Parallel plans are often picked when there
is some highly selective qual as parallel_tuple_cost has to be applied
to fewer tuples for such plans, so probably this is worth doing.

David



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

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: proposal: psql: show current user in prompt
Следующее
От: Junwang Zhao
Дата:
Сообщение: Re: Make COPY format extendable: Extract COPY TO format implementations