X-Original-To: pgsql-hackers-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 90FF09FA48B for ; Wed, 26 Jul 2006 04:23:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 29250-08 for ; Wed, 26 Jul 2006 04:23:33 -0300 (ADT) X-Greylist: delayed 00:27:22.942833 by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 04AE49FB1C3 for ; Wed, 26 Jul 2006 04:23:00 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from mail.Mi8.com (d01gw01.mi8.com [63.240.6.47]) by svr4.postgresql.org (Postfix) with ESMTP id BF29A5AFB25 for ; Wed, 26 Jul 2006 06:55:36 +0000 (GMT) Received: from 172.16.1.25 by mail.Mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D1)); Wed, 26 Jul 2006 02:52:05 -0400 X-Server-Uuid: 241911D6-425B-44B9-A073-E3FE0F8FC774 Received: from MI8NYCMAIL05.Mi8.com ([172.16.1.189]) by D01HOST03.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Wed, 26 Jul 2006 02:52:05 -0400 Received: from 198.145.28.117 ([198.145.28.117]) by MI8NYCMAIL05.Mi8.com ([172.16.1.77]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.118]) with Microsoft Exchange Server HTTP-DAV ; Wed, 26 Jul 2006 06:52:02 +0000 User-Agent: Microsoft-Entourage/11.0.0.040405 Date: Tue, 25 Jul 2006 23:51:45 -0700 Subject: Re: On-disk bitmap index patch From: "Ayush Parashar" To: "Tom Lane" , "Luke Lonergan" Cc: mark@mark.mielke.cc, "Bruce Momjian" , "Jie Zhang" , "Hannu Krosing" , "Gavin Sherry" , "majordomo@postgresql.org" Message-ID: In-Reply-To: <17917.1153847188@sss.pgh.pa.us> MIME-Version: 1.0 X-OriginalArrivalTime: 26 Jul 2006 06:52:05.0519 (UTC) FILETIME=[019089F0:01C6B080] X-WSS-ID: 68D9CE9F4BS24649-01-01 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.5 tagged_above=0 required=5 tests=RCVD_NUMERIC_HELO X-Spam-Level: * X-Archive-Number: 200607/1252 X-Sequence-Number: 87107 > I find those results moderately unconvincing, primarily because they > are based on choosing the least efficient possible data representation > (viz char(n)), and thus the btree indexes suffer severe and quite > artificial bloat. A database schema chosen with even minimal attention The specific data was chosen in presentation, because it comes from TPC-H definition (data that everybody understands) and they were the only columns where bitmap index will be more beneficial (i.e. the columns were low cardinality ones).=20 > to PG-specific tuning would probably have btree indexes half the size. > That wouldn't completely eliminate the performance differential shown, > but it would bring it down into the ballpark where you have to question > whether it makes sense to support another index AM. Comparison of index creation time and index size for similar cardinalities for *integer* and *numeric* data-types for b-tree and bitmap index. Benefit= s are seen in all the cases, index creation time, space taken by index as wel= l as querying: =20 Total rows in the table: 2 million Size of table in kbytes: 431976 Table definition and column cardinalities: Column | Type | Cardinality --------+-------------------+----------- c1 | integer | i10 | integer | 10 i50 | integer | 50 n10 | numeric | 10 n50 | numeric | 50 ctext | character varying | Note: Time in seconds and size in kbytes (as seen from select pg_relation_size()): ------------------------------------------------------------------------- Column B-tree size Bitmap size B-tree time Bitmap time ------------------------------------------------------------------------- i10 35056 2392 11.8 6.0 i50 35056 4328 10.8 6.4 n10 52264 2656 34.8 9.6 n50 52616 4272 34.3 11.7 ------------------------------------------------------------------------- Query timings (in seconds): ------------------------------------------------------------------------- Query B-tree Bitmap ------------------------------------------------------------------------- select count(*) from btree_test where 4.08 1.61 i10=3D5 and i50=3D2 and n10=3D0.1 and n50=3D0.05; ------------------------------------------------------------------------- This test case fits in memory, the benefits seen will be more if we take bigger test case. =20 I will like to re-iterate the benefits of bitmap index: 1. Size and time to create bitmap index is less than b-tree index for low cardinality column of any data-type. 2. The gain in query performance can be attributed to =8CBitmap And=B9 and =8CBitmap Or=B9 operations being more efficient for bitmap indexes as compared to b-trees. Note that both bitmap and b-tree indexes use the bitmap index scan access method, however the behavior is different for each. With a b-tree index, the b-tree indexes are scanned to create a temporary in-memor= y bitmap index. With the Bizgres on-disk bitmap index, the bitmap scan retrieves several on-disk bitmap pages at once and provides them to the =8CBitmap And=B9 and =8CBitmap Or=B9 operators. The smaller size of the bitmap indexes combined with the efficiency of the And and Or operators are the reasons for the increase in query speed. Ayush