pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kenneth Marshall <ktm@rice.edu>
To: Laszlo Nagy <gandalf@shopzeus.com>
Cc: Florian Weimer <fweimer@bfk.de>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Cc: Daniel Fekete <danieleff@gmail.com>
Subject: Re: Slow query + why bitmap index scan??
Date: Wed, 12 Jan 2011 08:26:54 -0600
Message-ID: <20110112142654.GJ5474@aart.is.rice.edu> (raw)
In-Reply-To: <4D2DB8F9.9050609@shopzeus.com>
References: <4D2D9B1E.7080302@shopzeus.com>
	<82y66qp7al.fsf@mid.bfk.de>
	<4D2DB8F9.9050609@shopzeus.com>

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



view thread (8+ messages)  latest in thread

Message-ID: <20110112142654.GJ5474@aart.is.rice.edu>
Permalink:  ../20110112142654.GJ5474@aart.is.rice.edu/
Also on:    postgresql.org/message-id/20110112142654.GJ5474@aart.is.rice.edu

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: ktm@rice.edu, gandalf@shopzeus.com, fweimer@bfk.de, danieleff@gmail.com
  Subject: Re: Slow query + why bitmap index scan??
  In-Reply-To: <20110112142654.GJ5474@aart.is.rice.edu>
  References: <4D2D9B1E.7080302@shopzeus.com> <82y66qp7al.fsf@mid.bfk.de> <4D2DB8F9.9050609@shopzeus.com> <20110112142654.GJ5474@aart.is.rice.edu>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox