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

From: Jonathan Bartlett <johnnyb(at)eskimo(dot)com>
To: Dan Langille <dan(at)langille(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Why no performance boost although I added an index?
Date: 2003-04-08 03:55:36
Message-ID: Pine.GSU.4.44.0304072048290.22523-100000@eskimo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

The problem is that if you are iterating over a large portion of your
dataset using an index, your disk has to do this:

Seek to the next index entry

Seek to the corresponding table entry

Seek to the next index entry

Seek to the corresponding table entry

...

If you get a lot of that, your disk will spend more time seeking
back-and-forth than actually reading data. Imagine if you used a CD
player and were constantly switching back between track 5 and track 9 of
the CD every 2 seconds - you would spend more time seeking than listening.

With two disks, you have one read-write head on the index, and one on the
table, so although they may be jumping around a little in the file, they
aren't moving nearly as much as if they are on the same disk. Buffering
may take the jumps out completely.

For small index scans, it makes little difference. For large index scans,
having the index on the same drive can really kill you.

To put them on different disks, you have to do the following:

Find the OID of the entity you wish to move.
Stop the database.
Move the entity to wherever you want it.
Symlink it to the original location.

The problems with this method are that:

a) The DB has to be down to do it

b) The symlink gets destroyed if you rebuild the index or cluster the
table.

Having said all that, I must say that I don't normally do this to my
databases, I just keep myself aware of the potential problems.

Jon

On Mon, 7 Apr 2003, Dan Langille wrote:

> On 7 Apr 2003 at 15:05, Jonathan Bartlett wrote:
>
> > This is a really big lose if your index and table are on the same
> > disk.
>
> Can you quantity "really big" for us please? Not all of us have more
> than one disk per box. I haven't looked into the ability for PG to
> put tables and indexes on specific disks.
> --
> Dan Langille : http://www.langille.org/
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-04-08 04:02:55 Re: Optimizer not using index on 120M row table
Previous Message Jim C. Nasby 2003-04-08 03:54:21 Re: Optimizer not using index on 120M row table