pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tv@fuzzy.cz
To: "������" <asen_huang@qq.com>
Cc: tv <tv@fuzzy.cz>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Cc: tgl <tgl@sss.pgh.pa.us>
Subject: Re: Why dose the planner select one bad scan plan.
Date: Thu, 11 Nov 2010 09:43:35 +0100
Message-ID: <52b7e2bd248406996574a0db8f5f6cb6.squirrel@sq.gransy.com> (raw)
In-Reply-To: <tencent_7D7D734B000FD7EA1CF49B10@qq.com>
References: <tencent_7D7D734B000FD7EA1CF49B10@qq.com>

> But I doubt your answer. I think the essence of the problem is when the
> planner selects 'Bitmap Index Scan' and how the planner computes the cost
> of 'Bitmap Index Scan'.

The essence of the problem obviously is a bad estimate of the cost. The
planner considers the two plans, computes the costs and then chooses the
one with the lower cost. But obviously the cost does not reflect the
reality (first time when the query is executed and the filesystem cache is
empty).

> Tom Lane said ��In principle a bitmap index scan should be significantly
> faster if the index can return the bitmap more or less "natively" rather
> than having to construct it. My recollection though is that a significant
> amount of work is needed to make that happen, and that there is no
> existing patch that tackled the problem. So I'm not sure that this report
> should be taken as indicating that there's no chance of a SELECT
> performance improvement. What it does say is that we have to do that work
> if we want to make bitmap indexes useful.��

Tom Lane is right (as usual). The point is that when computing the cost,
planner does not know whether the data are already in the filesystem cache
or if it has to fetch  them from the disk (which is much slower).

> Okay, I want to know how the planner computes the cost of constructing
> bitmap. And when the planner computes the cost of 'Bitmap Index Scan', if
> it considers the influence of memory cache? As when I do not clear the
> memory cache, I find the 'Bitmap Index Scan' is real fast than 'Seq
> Scan'.

There are two things here - loading the data from a disk into a cache
(filesystem cache at the OS level / shared buffers at the PG level), and
then the execution itself.

PostgreSQL estimates the first part using an effective_cache_size hint,
and uses that to estimate the probability that the data are already in the
filesystem cache. But you're confusing him by the 'reboot' which results
in an empty cache.

The plan itself seems fine to me - you might play with the cost variables,
but I think it won't improve the overall perfomance.

Actually what you see is a worst case scenario - the plan is not bad if
the data are in a cache (filesystem or shared buffers), but when Pg has to
read the data from the disk, performance sucks. But is this reflecting
reality? How often is the query executed? What other queries are executed
on the box? What is the size of shared_buffers?

If the query is executed often (compared to other queries) and the shared
buffers is set high enough, most of the table will remain in the shared
buffers and everything will work fine.

Tomas




view thread (5+ messages)  latest in thread

Message-ID: <52b7e2bd248406996574a0db8f5f6cb6.squirrel@sq.gransy.com>
Permalink:  ../52b7e2bd248406996574a0db8f5f6cb6.squirrel@sq.gransy.com/
Also on:    postgresql.org/message-id/52b7e2bd248406996574a0db8f5f6cb6.squirrel@sq.gransy.com

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tv@fuzzy.cz, asen_huang@qq.com, tgl@sss.pgh.pa.us
  Subject: Re: Why dose the planner select one bad scan plan.
  In-Reply-To: <52b7e2bd248406996574a0db8f5f6cb6.squirrel@sq.gransy.com>

* 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