Re: Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant
Date: 2022-10-12 11:29:58
Message-ID: CAMbWs4-1Ui1WXpv2_t-ukGH29fVpxr++C_CD1UKj4--==HtyXg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Oct 12, 2022 at 5:19 PM David Rowley <dgrowleyml(at)gmail(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2022-10-12 11:40:21 Re: make_ctags: use -I option to ignore pg_node_attr macro
Previous Message Amit Kapila 2022-10-12 10:52:37 Re: create subscription - improved warning message