Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 878FA1337B61 for ; Wed, 12 Jan 2011 08:25:02 -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 32886-07 for ; Wed, 12 Jan 2011 12:24:55 +0000 (UTC) X-Greylist: delayed 00:10:27.378662 by SQLgrey-1.7.6 Received: from 10610.x.rootbsd.net (10610.x.rootbsd.net [204.109.60.69]) by mail.postgresql.org (Postfix) with ESMTP id EBEAF1336971 for ; Wed, 12 Jan 2011 08:24:54 -0400 (AST) Received: from [192.168.10.101] (localhost [127.0.0.1]) by 10610.x.rootbsd.net (8.14.3/8.14.3) with ESMTP id p0CCG3h0051280; Wed, 12 Jan 2011 12:16:05 GMT (envelope-from gandalf@shopzeus.com) Message-ID: <4D2D9B1E.7080302@shopzeus.com> Date: Wed, 12 Jan 2011 13:14:22 +0100 From: Laszlo Nagy User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7 MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" , Daniel Fekete Subject: Slow query + why bitmap index scan?? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201101/65 X-Sequence-Number: 41852 This will be simple question to answer. :-) There is a single table: select count(*) from product_price_history -- 12982555 rows This table has exactly one index and on primary key constraint: CREATE INDEX idx_product_price_history_id_hdate ON product_price_history USING btree (id, hdate); ALTER TABLE product_price_history ADD CONSTRAINT pk_product_price_history PRIMARY KEY(hid); No more constraints or indexes defined on this table. Rows are never updated or deleted in this table, they are only inserted. It was vacuum-ed and reindex-ed today. Stats on the table: seq scans=13, index scans=108, table size=3770MB, toast table size=8192 bytes, indexes size=666MB This query: select hid from product_price_history where id=35547581 Returns 759 rows in 8837 msec! How can this be that slow??? The query plan is: "Bitmap Heap Scan on product_price_history (cost=13.90..1863.51 rows=472 width=8)" " Recheck Cond: (id = 35547581)" " -> Bitmap Index Scan on idx_product_price_history_id_hdate (cost=0.00..13.78 rows=472 width=0)" " Index Cond: (id = 35547581)" I don't understand why PostgreSQL uses bitmap heap scan + bitmap index scan? Why not just use an regular index scan? Data in a btree index is already sorted. A normal index scan should take no more than a few page reads. This sould never take 8 seconds. Thanks, Laszlo