Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 891282E002D for ; Fri, 4 Apr 2008 07:59:19 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 19972-08 for ; Fri, 4 Apr 2008 07:59:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from h07.llord.com (unknown [195.140.142.194]) by developer.postgresql.org (Postfix) with ESMTP id 67D3C2E00A3 for ; Fri, 4 Apr 2008 07:59:12 -0300 (ADT) Received: from par69-8-88-161-102-87.fbx.proxad.net ([88.161.102.87] helo=apollo13.peufeu.com) by h07.llord.com with esmtpa (Exim 4.68) (envelope-from ) id 1JhjdV-00061S-Ul for pgsql-performance@postgresql.org; Fri, 04 Apr 2008 12:59:10 +0200 Date: Fri, 04 Apr 2008 13:02:59 +0200 To: pgsql-performance@postgresql.org Subject: Re: Forcing more agressive index scans for BITMAP AND From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <1207280383.28172.26.camel@neuromancer.home.net> Content-Transfer-Encoding: Quoted-Printable Message-ID: In-Reply-To: User-Agent: Opera Mail/9.24 (Linux) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - h07.llord.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - peufeu.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.984 tagged_above=0 required=5 tests=AWL=0.884, RDNS_NONE=0.1 X-Spam-Level: X-Archive-Number: 200804/44 X-Sequence-Number: 29537 > On Fri, 4 Apr 2008, Ow Mun Heng wrote: >> select * from table >> where A=3DX >> and B =3D Y >> and C =3D Z >> and D =3D AA >> and E =3D BB With that kind of WHERE condition, Postgres will use a Bitmap Index Sca= n = to combine your indices. If, however, postgres notices while looking at = = the statistics gathered during ANALYZE, that for one of your columns, yo= u = request a value that happens in a large percentage of the rows (like 20%= ), = and this value has a rather random distribution, Postgres will not bothe= r = scanning the index, because it is very likely that all the pages would = contain a row satisfying your condition anyway, so the time taken to sca= n = this huge index and mark the bitmap would be lost because it would not = allow a better selectivity, since all the pages would get selected for = scan anyway. I would guess that Postgres uses Bitmap Index Scan only on your columns= = that have good selectivity (ie. lots of different values). So : If you use conditions on (a,b) or (a,b,c) or (a,b,c,d) etc, you will = benefit GREATLY from a multicolumn index on (a,b,c,d...). However, even if postgres can use some clever tricks, a multicolumn ind= ex = on (a,b,c,d) will not be optimal for a condition on (b,c,d) for instance= . So, if you mostly use conditions on a left-anchored subset of = (a,b,c,d,e), the multicolumn index will be a great tool. A multicolumn index on (a,b,c,d,e) is always slightly slower than an = index on (a) if you only use a condition on (a), but it is immensely = faster when you use a multicolumn condition. Can you tell us more about what those columns mean and what you store i= n = them, how many distinct values, etc ?