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 2FA49D1E296 for ; Wed, 25 Feb 2004 22:09:02 +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 42656-09 for ; Wed, 25 Feb 2004 18:09:02 -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 DD07ED1E288 for ; Wed, 25 Feb 2004 18:08:58 -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 1Aw7D9-000Lcr-0Z; Wed, 25 Feb 2004 22:09:00 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 36C1B16A1D; Wed, 25 Feb 2004 22:08:59 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id E0DB11591F; Wed, 25 Feb 2004 22:08:56 +0000 (GMT) From: Richard Huxton To: Tom Lane Subject: Re: Scalar in a range (but textual not numeric) Date: Wed, 25 Feb 2004 22:08:55 +0000 User-Agent: KMail/1.5 Cc: pgsql-sql@postgresql.org References: <200402251918.20289.dev@archonet.com> <6803.1077744728@sss.pgh.pa.us> In-Reply-To: <6803.1077744728@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: <200402252208.55502.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/350 X-Sequence-Number: 17040 On Wednesday 25 February 2004 21:32, Tom Lane wrote: > Richard Huxton writes: > > Large table representing non-overlapping blocks: > > blocks(id int4, min varchar, max varchar) > > > > SELECT * FROM blocks WHERE 'ABCDE' BETWEEN min AND max; > > > > The estimator gets the wrong plan because it doesn't realise there's > > (at most) only one block that can match. > > Even if it did realize that, it couldn't do much, because this query > isn't indexable as it stands. Well, it is in the sense that an index can be used. Here I'd defined pkey as (min,max,id) and set enable_seqscan=off -> Index Scan using prnblock_range_pkey on prnblock_range (cost=0.00..1403.99 rows=892 width=33) (actual time=23.88..24.07 rows=1 loops=1) Index Cond: (('09050091234'::character varying >= pr_min) AND ('09050091234'::character varying <= pr_max)) Of course, what I really want is a "varchar_range" type with its own indexing... > I wonder whether you could adapt the "line segment" datatype > (see contrib/seg/) into a sort of "text segment" thingy and use the > GiST indexing support on that. You'd have a query like > WHERE min_max_object overlaps-operator 'ABCDE' > and the overlaps operator would be a GiST-indexable one. Yep, that's the sort of thing I was wanting, just not worth the trouble in this case. It's not the heart of the system, only a corner case. Thanks anyway Tom -- Richard Huxton Archonet Ltd