X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id EF7269DCC9F for ; Wed, 15 Mar 2006 15:37:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13118-06 for ; Wed, 15 Mar 2006 15:37:00 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.202]) by postgresql.org (Postfix) with ESMTP id 9BEE99DCB70 for ; Wed, 15 Mar 2006 15:36:54 -0400 (AST) Received: by zproxy.gmail.com with SMTP id 4so256056nzn for ; Wed, 15 Mar 2006 11:36:52 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=I1jKsEqjwQdjltqEwcIzkdgHjS0hI3kt8fmAAgSTo/0c3o80Myupm5yKmeWwR4S1BWZQ6GZzmenGqkHU6+/DqQqdVrVb5DFbhOBc9y8TdbSjtTYPAmPrqzIk4orSFtXofI8qzR3o4O/7Ez+7zHasaZa038CLB4k29c1SgzpzAvI= Received: by 10.65.98.12 with SMTP id a12mr563498qbm; Wed, 15 Mar 2006 11:36:51 -0800 (PST) Received: by 10.65.137.20 with HTTP; Wed, 15 Mar 2006 11:36:51 -0800 (PST) Message-ID: Date: Wed, 15 Mar 2006 14:36:51 -0500 From: "Merlin Moncure" To: "Kevin Grittner" Subject: Re: [PERFORM] BETWEEN optimizer problems with single-value range Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org In-Reply-To: <44180105.EE98.0025.0@wicourts.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <44180105.EE98.0025.0@wicourts.gov> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.14 required=5 tests=[AWL=0.140] X-Spam-Score: 0.14 X-Spam-Level: X-Archive-Number: 200603/722 X-Sequence-Number: 81120 On 3/15/06, Kevin Grittner wrote: > Attached is a simplified example of a performance problem we have seen, > with a workaround and a suggestion for enhancement (hence both the > performance and hackers lists). Hi Kevin. In postgres 8.2 you will be able to use the row-wise comparison for your query which should guarantee good worst case performance without having to maintain two separate query forms. it is also a more elegant syntax as you will see. SELECT "CA"."calDate", "CA"."startTime" FROM "Cal" "CA" WHERE ("CA"."ctofcNo", "CA"."calDate") BETWEEN (2192, '2006-03-15') and (2192, '2006-03-15') ORDER BY "ctofcNo", "calDate", "startTime"; Be warned this will not work properly in pg < 8.2. IMO, row-wise is the best way to write this type of a query. Please note the row constructor and the addition of ctofcNo into the order by clause to force use of the index. Merlin