Re: database not using indexes - Mailing list pgsql-admin

From Craig Ringer
Subject Re: database not using indexes
Date
Msg-id 4EBB39BA.5090102@ringerc.id.au
Whole thread Raw
In response to Re: database not using indexes  ("Ruslan A. Bondar" <fsat@list.ru>)
List pgsql-admin
On 09/11/11 23:58, Ruslan A. Bondar wrote:
>
> Why have you decided it isn't using indexes?
> If index exists - postgres will use it.

Actually that's not necessarily the case.

PostgreSQL will only use an index if (a) the index can be used for that
kind of query and (b) using the index will be faster than doing a
sequential scan.

If a query requires all the data in a table, PostgreSQL is quite likely
to do a sequential scan of the table, because it'll need to read every
block anyway. Reading just the table (without reading the index) in
order is much faster than reading the index then doing semi-random reads
of the table.

Additionally, not all indexes can be used for all operations. For
example, a LIKE query with a prefix wildcard eg "%FRED" cannot use a
btree index, so any btree index on the searched field will be ignored.

--
Craig Ringer

pgsql-admin by date:

Previous
From: Craig Ringer
Date:
Subject: Re: How to deal with corrupted database?
Next
From: Craig Ringer
Date:
Subject: Re: database not using indexes