Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A66141337BBC for ; Wed, 12 Jan 2011 10:27:03 -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 74850-07 for ; Wed, 12 Jan 2011 14:26:56 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mh7.mail.rice.edu (mh7.mail.rice.edu [128.42.199.46]) by mail.postgresql.org (Postfix) with ESMTP id 3AC491337BBB for ; Wed, 12 Jan 2011 10:26:56 -0400 (AST) Received: from mh7.mail.rice.edu (localhost.localdomain [127.0.0.1]) by mh7.mail.rice.edu (Postfix) with ESMTP id 3A01428F93D; Wed, 12 Jan 2011 08:26:56 -0600 (CST) X-Virus-Scanned: by amavis-2.6.4 at mh7.mail.rice.edu, auth channel Received: from mh7.mail.rice.edu ([127.0.0.1]) by mh7.mail.rice.edu (mh7.mail.rice.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id io9lhW7nPFma; Wed, 12 Jan 2011 08:26:56 -0600 (CST) X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no X-SMTP-Auth: no Received: from aart.is.rice.edu (aart.is.rice.edu [168.7.56.48]) by mh7.mail.rice.edu (Postfix) with ESMTP id 054E728F898; Wed, 12 Jan 2011 08:26:56 -0600 (CST) Received: by aart.is.rice.edu (Postfix, from userid 18612) id 349E12D5A6; Wed, 12 Jan 2011 08:26:54 -0600 (CST) Date: Wed, 12 Jan 2011 08:26:54 -0600 From: Kenneth Marshall To: Laszlo Nagy Cc: Florian Weimer , "pgsql-performance@postgresql.org" , Daniel Fekete Subject: Re: Slow query + why bitmap index scan?? Message-ID: <20110112142654.GJ5474@aart.is.rice.edu> References: <4D2D9B1E.7080302@shopzeus.com> <82y66qp7al.fsf@mid.bfk.de> <4D2DB8F9.9050609@shopzeus.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4D2DB8F9.9050609@shopzeus.com> User-Agent: Mutt/1.5.16 (2007-06-09) 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: 201101/70 X-Sequence-Number: 41857 On Wed, Jan 12, 2011 at 03:21:45PM +0100, Laszlo Nagy wrote: > On 2011-01-12 14:42, Florian Weimer wrote: >> * Laszlo Nagy: >> >>> This query: >>> >>> select hid from product_price_history where id=35547581 >>> >>> Returns 759 rows in 8837 msec! How can this be that slow??? >> If most records are on different heap pages, processing this query >> requires many seeks. 11ms per seek is not too bad if most of them are >> cache misses. > How about this: > > select id,hdate from product_price_history where id=35547581 -- 759 rows, > 8837 ms > Query time average: 3 sec. > Query plan: > > "Bitmap Heap Scan on product_price_history (cost=13.91..1871.34 rows=474 > width=16)" > " Recheck Cond: (id = 35547582)" > " -> Bitmap Index Scan on idx_product_price_history_id_hdate > (cost=0.00..13.79 rows=474 width=0)" > " Index Cond: (id = 35547582)" > > Why still the heap scan here? All fields in the query are in the index... > Wouldn't a simple index scan be faster? (This is only a theoretical > question, just I'm curious.) > Because of PostgreSQL's MVCC design, it must visit each heap tuple to check its visibility as well as look it up in the index. > My first idea to speed things up is to cluster this table regularly. That > would convert (most of the) rows into a few pages. Few page reads -> faster > query. Is it a good idea? > Yes, clustering this table would greatly speed up this type of query. > Another question. Do you think that increasing shared_mem would make it > faster? I doubt it. > > Currently we have: > > shared_mem = 6GB > work_mem = 512MB > total system memory=24GB > > Total database size about 30GB, but there are other programs running on the > system, and many other tables. > > Thanks, > > Laszlo > Clustering is your best option until we get indexes with visibility information. Cheers, Ken