Re: Strange Postgresql Indexing Behavior - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Strange Postgresql Indexing Behavior
Date
Msg-id 20020314131631.A3954@svana.org
Whole thread Raw
In response to Strange Postgresql Indexing Behavior  (Brian Knox <laotse@aol.net>)
List pgsql-general
On Wed, Mar 13, 2002 at 04:28:00PM -0500, Brian Knox wrote:
>
> I'm having an interesting time trying to figure out some behavior with
> postgresql indexes that I am trying to understand.

[snip]

> I did more queries and confirmed that when the number of rows returned is
> below a certain number (I don't have enough data to determine the exact
> number) the index is used, and when it is above a certain number, it is
> not used.
>
> Can anyone explain to me what is happening / why it is happening / how to
> make the indexes work correctly?

Well, checking a tuple from an index is more expensive than checking a tuple
from a sequential scan. So, if you want to select 50% of the table, it's
faster to read the whole table than it is to use the index.

The planner tries to guess where the break-even point is. Above, seq scan,
below index scan.

This is a FAQ, IIRC.

HTH,
--
Martijn van Oosterhout <kleptog@svana.org>
http://svana.org/kleptog/
> 11/9/2001 - a new beginning or the beginning of the end?

pgsql-general by date:

Previous
From: Fernando Lozano
Date:
Subject: Distributed databases
Next
From: "Artigas, Ricardo Y."
Date:
Subject: Re: Standby databases