Re: Removing useless DISTINCT clauses - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Removing useless DISTINCT clauses
Date
Msg-id 25619.1535076216@sss.pgh.pa.us
Whole thread Raw
In response to Re: Removing useless DISTINCT clauses  (Stephen Frost <sfrost@snowman.net>)
Responses Re: Removing useless DISTINCT clauses
List pgsql-hackers
Stephen Frost <sfrost@snowman.net> writes:
> * David Rowley (david.rowley@2ndquadrant.com) wrote:
>> On 24 August 2018 at 11:34, Stephen Frost <sfrost@snowman.net> wrote:
>>> * David Rowley (david.rowley@2ndquadrant.com) wrote:
>>>> My personal opinion of only being able to completely remove the
>>>> DISTINCT when there's a single item in the rtable (or a single base
>>>> table) is that it's just too poor to bother with.

> Hm, so you're suggesting that this isn't the right place for this
> optimization to be implemented, even now, with the single-relation
> caveat?

There is no case where planner optimizations should depend on the length
of the rtable.  Full stop.

It could make sense to optimize if there is just one baserel in the join
tree --- although even that is best checked only after join removal.
As an example of the difference, such an optimization should be able to
optimize "select * from view" if the view contains just one base table.
The rtable will list both the view and the base table, but the view
is only hanging around for permissions-checking purposes; it should not
affect the planner's behavior.

I've not read the patch, but David's reaction makes it sound like its
processing is done too early.  There are right places and wrong places
to do most everything in the planner, and I do not wish to accept a
patch that does something in the wrong place.

            regards, tom lane


pgsql-hackers by date:

Previous
From: Haribabu Kommi
Date:
Subject: Re: Pluggable Storage - Andres's take
Next
From: Stephen Frost
Date:
Subject: Re: Removing useless DISTINCT clauses