Re: Multiple Uniques - Mailing list pgsql-performance

From Tom Lane
Subject Re: Multiple Uniques
Date
Msg-id 19516.1094134957@sss.pgh.pa.us
Whole thread Raw
In response to Multiple Uniques  (Markus Schaber <schabios@logi-track.com>)
Responses Re: Multiple Uniques
List pgsql-performance
Markus Schaber <schabios@logi-track.com> writes:
> Today, we stumbled about the following query plan on PostGreSQL 7.4.1:

> logigis=# explain select count(id) from (select distinct id from (select distinct ref_in_id as id from streets union
selectdistinct nref_in_id as id from streets) as blubb) as blabb;  

> I was somehow irritated by the fact that the Query Plan contains 4 Uniques.

Well, if you write a silly query, you can get a silly plan ...

As you appear to have realized later, given the definition of UNION,
all three of the explicit DISTINCTs are redundant.

> So, now my question is, why does the query optimizer not recognize that
> it can throw away those "non-unique" Sort/Unique passes?

Because the issue doesn't come up often enough to justify expending
cycles to check for it.

            regards, tom lane

pgsql-performance by date:

Previous
From: Markus Schaber
Date:
Subject: Multiple Uniques
Next
From: Greg Stark
Date:
Subject: Re: Multiple Uniques