X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id CA9F39DC81E for ; Mon, 26 Dec 2005 17:57:15 -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 04587-06 for ; Mon, 26 Dec 2005 17:57:17 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id A2ED49DC80E for ; Mon, 26 Dec 2005 17:57:13 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBQLvB6p012554; Mon, 26 Dec 2005 16:57:11 -0500 (EST) To: Ivan Voras cc: pgsql-performance@postgresql.org Subject: Re: Bitmap indexes etc. In-reply-to: <20051226222915.G87624@geri.cc.fer.hr> References: <20051226222915.G87624@geri.cc.fer.hr> Comments: In-reply-to Ivan Voras message dated "Mon, 26 Dec 2005 22:32:13 +0100" Date: Mon, 26 Dec 2005 16:57:11 -0500 Message-ID: <12553.1135634231@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.047 required=5 tests=[AWL=0.047] X-Spam-Score: 0.047 X-Spam-Level: X-Archive-Number: 200512/622 X-Sequence-Number: 16443 Ivan Voras writes: > This is PostgreSQL 8.1.0. > - what does "Bitmap Heap Scan" phase do? A plain indexscan fetches one tuple-pointer at a time from the index, and immediately visits that tuple in the table. A bitmap scan fetches all the tuple-pointers from the index in one go, sorts them using an in-memory "bitmap" data structure, and then visits the table tuples in physical tuple-location order. The bitmap scan improves locality of reference to the table at the cost of more bookkeeping overhead to manage the "bitmap" data structure --- and at the cost that the data is no longer retrieved in index order, which doesn't matter for your query but would matter if you said ORDER BY. > - what is "Recheck condition" and why is it needed? If the bitmap gets too large we convert it to "lossy" style, in which we only remember which pages contain matching tuples instead of remembering each tuple individually. When that happens, the table-visiting phase has to examine each tuple on the page and recheck the scan condition to see which tuples to return. > - why are proposed "width" fields in the plan different between the two > plans? Updated statistics about average column widths, presumably. > (actually, a nice explanation what exactly are those widths would also > be nice :) ) Sum of the average widths of the columns being fetched from the table. > - I thought "Bitmap Index Scan" was only used when there are two or more > applicable indexes in the plan, so I don't understand why is it used > now? True, we can combine multiple bitmaps via AND/OR operations to merge results from multiple indexes before visiting the table ... but it's still potentially worthwhile even for one index. A rule of thumb is that plain indexscan wins for fetching a small number of tuples, bitmap scan wins for a somewhat larger number of tuples, and seqscan wins if you're fetching a large percentage of the whole table. regards, tom lane