Re: performance discrepancy indexing one column versus

From: Gavin Sherry <swm(at)alcove(dot)com(dot)au>
To: Mark Dilger <pgsql(at)markdilger(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: performance discrepancy indexing one column versus
Date: 2005-09-11 08:05:03
Message-ID: Pine.LNX.4.58.0509111757110.4486@linuxworld.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Sun, 11 Sep 2005, Mark Dilger wrote:

> All,
>
> In the psql output below, I would expect the second query to run faster,
> because the b-tree index on two columns knows the values of 'b' for any
> given value of 'a', and hence does not need to fetch a row from the
> actual table. I am not seeing a speed-up, however, so I expect my
> understanding of the index mechanism is wrong. Could anyone enlighten
> me?

A common but incorrect assumption. We must consult the underlying table
when we do an index scan so that we can check visibility information. The
reason it is stored there in the table is so that we have only one place
to check for tuple visibility and therefore avoid race conditions.

A brief explanation of this system is described here:
http://www.postgresql.org/docs/8.0/static/mvcc.html.

and this page shows what information we store in the to do visibility
checks:

http://www.postgresql.org/docs/8.0/static/storage-page-layout.html

Thanks,

Gavin

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Guido Neitzer 2005-09-11 08:29:09 Index not used with prepared statement
Previous Message Mark Dilger 2005-09-11 07:43:18 performance discrepancy indexing one column versus two columns