X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CF0B7D7985 for ; Tue, 6 Sep 2005 11:09:07 -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 69772-10 for ; Tue, 6 Sep 2005 14:09:01 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id 2E425D8385 for ; Tue, 6 Sep 2005 11:09:04 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id F3AD235388; Tue, 6 Sep 2005 07:09:08 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id F227B35320; Tue, 6 Sep 2005 07:09:08 -0700 (PDT) Date: Tue, 6 Sep 2005 07:09:08 -0700 (PDT) From: Stephan Szabo To: Merlin Moncure Cc: Carlos Benkendorf , pgsql-performance@postgresql.org Subject: Re: Improving performance of a query In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB3417DD278@Herge.rcsinc.local> Message-ID: <20050906070119.K35524@megazone.bigpanda.com> References: <6EE64EF3AB31D5448D0007DD34EEB3417DD278@Herge.rcsinc.local> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200509/86 X-Sequence-Number: 14394 On Tue, 6 Sep 2005, Merlin Moncure wrote: > Carlos wrote: > SELECT * FROM SSIRRA where > (YEAR = 2004 and CUSTOMER = 0000000004 and CODE = 00 and PART >= 00) or > (YEAR = 2004 and CUSTOMER = 0000000004 and CODE > 00) or > (YEAR = 2004 and CUSTOMER > 0000000004) or > (YEAR > 2004) > [snip] > > ah, the positional query. You can always rewrite this query in the > following form: > > (YEAR >= 2004) and > (YEAR = 2004 or CUSTOMER >= 0000000004) and > (YEAR = 2004 or CUSTOMER = 0000000004 or CODE >= 00) and > (YEAR = 2004 or CUSTOMER = 0000000004 or CODE = 00 or PART > 00) Unless I'm not seeing something, I don't think that's a correct reformulation in general. If customer < 4 and year > 2004 the original clause would return true but the reformulation would return false since (year=2004 or customer >= 4) would be false.