Re: Query rewrite(optimization) using constraints - Mailing list pgsql-hackers

From Justin Pryzby
Subject Re: Query rewrite(optimization) using constraints
Date
Msg-id 20211008180111.GO27491@telsasoft.com
Whole thread Raw
In response to Query rewrite(optimization) using constraints  (Lily Liu <lilyliupku@gmail.com>)
List 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



pgsql-hackers by date:

Previous
From: Max Shore
Date:
Subject: ERROR: unexpected duplicate for tablespace 16389, relfilenode 484036
Next
From: Tom Lane
Date:
Subject: Re: Query rewrite(optimization) using constraints