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 DADFD329E40 for ; Fri, 10 Sep 2004 00:06:24 +0100 (BST) 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 32770-03 for ; Thu, 9 Sep 2004 23:06:18 +0000 (GMT) Received: from sue.samurai.com (sue.samurai.com [205.207.28.74]) by svr1.postgresql.org (Postfix) with ESMTP id E316A329E3A for ; Fri, 10 Sep 2004 00:06:19 +0100 (BST) Received: from localhost (localhost [127.0.0.1]) by sue.samurai.com (Postfix) with ESMTP id 6F3A93F14; Thu, 9 Sep 2004 19:06:19 -0400 (EDT) Received: from sue.samurai.com ([127.0.0.1]) by localhost (sue.samurai.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 57340-01; Thu, 9 Sep 2004 19:06:18 -0400 (EDT) Received: from [127.0.0.1] (unknown [61.88.101.19]) by sue.samurai.com (Postfix) with ESMTP id 8E4073E73; Thu, 9 Sep 2004 19:06:17 -0400 (EDT) Message-ID: <4140E1EF.1040303@samurai.com> Date: Fri, 10 Sep 2004 09:06:23 +1000 From: Neil Conway User-Agent: Mozilla Thunderbird 0.7 (Macintosh/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Tom Lane Cc: Markus Schaber , PostgreSQL Performance List Subject: Re: Multiple Uniques References: <20040902154340.5b1a669a@kingfisher.intern.logi-track.com> <19516.1094134957@sss.pgh.pa.us> In-Reply-To: <19516.1094134957@sss.pgh.pa.us> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at mailbox.samurai.com 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/57 X-Sequence-Number: 8185 Tom Lane wrote: > Markus Schaber writes: >>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. How many cycles are we really talking about, though? I have a patch which I'll send along in a few days which implements a similar optimization: if a subselect is referenced by EXISTS or IN, we can discard DISTINCT and ORDER BY clauses in the subquery (actually, we can't discard ORDER BY in the case of IN if LIMIT is also specified, but the point remains). It's very cheap computationally for the planner to do this simplification, and I'd imagine doing the equivalent simplifications for UNION is similarly cheap. While I understand what you're saying WRT to it being a silly query, in the real world people make mistakes... -Neil