Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A33631337B34 for ; Sun, 26 Dec 2010 13:24:57 -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 13104-03 for ; Sun, 26 Dec 2010 17:24:50 +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 0BFE41336FA7 for ; Sun, 26 Dec 2010 13:24:49 -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 oBQHOlJS017714; Sun, 26 Dec 2010 12:24:47 -0500 (EST) To: Marti Raudsepp cc: Ben , pgsql-performance@postgresql.org Subject: Re: encourging bitmap AND In-reply-to: References: <5297F6A0-AB39-49F1-80BB-8EE60F3E243E@gmail.com> <27812.1293137532@sss.pgh.pa.us> Comments: In-reply-to Marti Raudsepp message dated "Sun, 26 Dec 2010 08:50:49 +0200" Date: Sun, 26 Dec 2010 12:24:47 -0500 Message-ID: <17713.1293384287@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/312 X-Sequence-Number: 41764 Marti Raudsepp writes: > On Thu, Dec 23, 2010 at 22:52, Tom Lane wrote: >> 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. > Why is it unsuited for this query? It expands to (150 < s AND 150 > e) > which should work nicely with bitmap AND as far as I can tell. Well, maybe for small values of "nicely". If you do it like that, then on average each indexscan will scan about half of its index and return a bitmap representing about half the rows in the table. That's an expensive indexscan, and an expensive bitmap-AND operation, even if the final number of rows out of the AND is small. Plus you're at serious risk that the bitmaps will become lossy, which degrades the performance of the final bitmap heapscan. If you're doing interval queries enough to worry about having an index for them, you really want an indexing structure that is designed to do interval queries efficiently. regards, tom lane