Re: Removing useless DISTINCT clauses

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephen Frost <sfrost(at)snowman(dot)net>
Cc: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, "Finnerty, Jim" <jfinnert(at)amazon(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Removing useless DISTINCT clauses
Date: 2018-08-24 02:03:36
Message-ID: 25619.1535076216@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Stephen Frost <sfrost(at)snowman(dot)net> writes:
> * David Rowley (david(dot)rowley(at)2ndquadrant(dot)com) wrote:
>> On 24 August 2018 at 11:34, Stephen Frost <sfrost(at)snowman(dot)net> wrote:
>>> * David Rowley (david(dot)rowley(at)2ndquadrant(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2018-08-24 02:12:14 Re: Removing useless DISTINCT clauses
Previous Message Haribabu Kommi 2018-08-24 01:55:41 Re: Pluggable Storage - Andres's take