X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 859CCD1B91B for ; Thu, 26 Feb 2004 08:03:22 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 19480-04 for ; Thu, 26 Feb 2004 04:03:18 -0400 (AST) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by svr1.postgresql.org (Postfix) with ESMTP id A75BBD1B903 for ; Thu, 26 Feb 2004 04:03:16 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.35 #1) id 1AwGUG-000GOm-0Z; Thu, 26 Feb 2004 08:03:16 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 1ABD216A1E; Thu, 26 Feb 2004 08:03:14 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 2B38316800; Thu, 26 Feb 2004 08:03:12 +0000 (GMT) From: Richard Huxton To: Tom Lane Subject: Re: Scalar in a range (but textual not numeric) Date: Thu, 26 Feb 2004 08:03:11 +0000 User-Agent: KMail/1.5 Cc: pgsql-sql@postgresql.org References: <200402251918.20289.dev@archonet.com> <7179.1077748348@sss.pgh.pa.us> <7219.1077748650@sss.pgh.pa.us> In-Reply-To: <7219.1077748650@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402260803.11523.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/358 X-Sequence-Number: 17048 On Wednesday 25 February 2004 22:37, Tom Lane wrote: > I wrote: > > try writing > > WHERE 'ABCDE' >= pr_min AND 'ABCDE' <= pr_max > > AND pr_min < (SELECT pr_min FROM table > > WHERE pr_min > 'ABCDE' > > ORDER BY pr_min LIMIT 1) > > The idea here is to add an upper bound on pr_min to the index scan > > conditions, so that the scan can stop short of the end of the index. > > Argh, got that backwards. What you are missing is a *lower* bound on > pr_min, and the index scan will therefore run from the start of the > index up to pr_min = 'ABCDE'. So reverse the sense of the added test: > > AND pr_min >= (SELECT pr_min FROM table > WHERE pr_min <= 'ABCDE' > ORDER BY pr_min DESC LIMIT 1) Aha! I was trying something like that, but couldn't get it quite right and it was getting too late for me to see clearly. Thanks Tom, I'll have a play with this later today. -- Richard Huxton Archonet Ltd