Re: Why no performance boost although I added an index?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Holger Marzen <holger(at)marzen(dot)de>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why no performance boost although I added an index?
Date: 2003-04-07 21:31:29
Message-ID: 20030407142628.G39215-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 7 Apr 2003, Holger Marzen wrote:

> I have an accounting table on postgres 7.2.4, and my favourite select
> gets no performance boost if I add an index on the date column. But it
> should be faster.
>

Not necessarily (see below)

> So the index is used, but the execution time is greater than without
> index. Why that? Is the overhead using an index the biggest factor
> because there are only a few thousand rows in the table?

If the index scan is reading a large enough percentage of the rows (and
depending on the clustering of values), it may be reading enough pages
that there's no advantage (or even a disadvantage) to using the index.
This is due to both the reads of the index itself and the fact that it'll
often be reading the values in the main table (it still needs to get the
commit info from the table data) in random order rather than sequential
order which can lose some optimizations the OS often gives to sequential
reads.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jonathan Bartlett 2003-04-07 22:05:43 Re: Why no performance boost although I added an index?
Previous Message Dennis Gearon 2003-04-07 21:17:23 Re: FK deadlock problem addressed