Re: Query rewrite(optimization) using constraints

From: Justin Pryzby <pryzby(at)telsasoft(dot)com>
To: Lily Liu <lilyliupku(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Query rewrite(optimization) using constraints
Date: 2021-10-08 18:01:11
Message-ID: 20211008180111.GO27491@telsasoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Oct 08, 2021 at 10:24:33AM -0700, Lily Liu wrote:
> 1) Remove DISTINCT
>
> A simple example is SELECT DISTINCT(name) FROM R. If there is a unique
> constraint on the name column. The DISTINCT keyword can be removed safely.
> Query plans without the DISTINCT keyword might be much cheaper since
> DISTINCT is expensive.

There's an ongoing discussion and patches for this here.

Erase the distinctClause if the result is unique by definition
https://commitfest.postgresql.org/35/2433/

Perhaps you could help to test or review the patch ?

--
Justin

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-10-08 18:17:04 Re: Query rewrite(optimization) using constraints
Previous Message Max Shore 2021-10-08 18:00:23 ERROR: unexpected duplicate for tablespace 16389, relfilenode 484036