Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 53BC01337B49 for ; Thu, 23 Dec 2010 16:52:21 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 20437-02 for ; Thu, 23 Dec 2010 20:52:14 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id C5C1313364DE for ; Thu, 23 Dec 2010 16:52:13 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id oBNKqCd7027813; Thu, 23 Dec 2010 15:52:13 -0500 (EST) To: Ben cc: pgsql-performance@postgresql.org Subject: Re: encourging bitmap AND In-reply-to: <5297F6A0-AB39-49F1-80BB-8EE60F3E243E@gmail.com> References: <5297F6A0-AB39-49F1-80BB-8EE60F3E243E@gmail.com> Comments: In-reply-to Ben message dated "Thu, 23 Dec 2010 12:06:40 -0800" Date: Thu, 23 Dec 2010 15:52:12 -0500 Message-ID: <27812.1293137532@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/301 X-Sequence-Number: 41753 Ben writes: > i have a schema similar to the following > create index foo_s_idx on foo using btree (s); > create index foo_e_idx on foo using btree (e); > i want to do queries like > select * from foo where 150 between s and e; That index structure is really entirely unsuited to what you want to do, so it's not surprising that the planner isn't impressed with the idea of a bitmap AND. I'd suggest setting up something involving a gist index over an interval-ish datatype. The PERIOD datatype that Jeff Davis is fooling with would do what you want --- see http://pgfoundry.org/projects/temporal http://thoughts.j-davis.com/2009/11/08/temporal-keys-part-2/ If you don't want any add-on parts involved, you could fake it by using a box or possibly lseg. regards, tom lane