Re: Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant
Date
Msg-id CAMbWs4-1Ui1WXpv2_t-ukGH29fVpxr++C_CD1UKj4--==HtyXg@mail.gmail.com
Whole thread Raw
In response to Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant
List pgsql-hackers

On Wed, Oct 12, 2022 at 5:19 PM David Rowley <dgrowleyml@gmail.com> wrote:
When all the distinct pathkeys are redundant then there can only be,
at most, 1 single distinct value. There may be many rows with that
value, but we can remove those extra ones with a LIMIT 1 rather than
troubling over needlessly uniquifing them.
 
I'm not sure if this case is common enough in practice, but since this
patch is very straightforward and adds no more costs, I think it's worth
doing.

I also have concerns about the 2 Limit nodes pointed by the comment
inside the patch. Maybe we can check with limit_needed() and manually
add the limit node only if there is no LIMIT clause in the origin query?

Thanks
Richard

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: create subscription - improved warning message
Next
From: Tatsuo Ishii
Date:
Subject: Re: make_ctags: use -I option to ignore pg_node_attr macro