X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5E19F5E4733 for ; Thu, 2 Sep 2004 11:22:37 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 77589-10 for ; Thu, 2 Sep 2004 14:22:36 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 8973F5E4730 for ; Thu, 2 Sep 2004 11:22:33 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.11/8.12.11) with ESMTP id i82EMcc3019517; Thu, 2 Sep 2004 10:22:38 -0400 (EDT) To: Markus Schaber Cc: PostgreSQL Performance List Subject: Re: Multiple Uniques In-reply-to: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> Comments: In-reply-to Markus Schaber message dated "Thu, 02 Sep 2004 15:43:40 +0200" Date: Thu, 02 Sep 2004 10:22:37 -0400 Message-ID: <19516.1094134957@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/18 X-Sequence-Number: 8146 Markus Schaber 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