Markus Schaber <[EMAIL PROTECTED]> 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 select distinct 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 ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings