From: Martijn van Oosterhout <kleptog@svana.org>
To: Brian Knox <laotse@aol.net>
Cc: pgsql-general@postgresql.org
Subject: Re: Strange Postgresql Indexing Behavior
Date: Thu, 14 Mar 2002 13:16:31 +1100
Message-ID: <20020314131631.A3954@svana.org> (raw)
In-Reply-To: <Pine.LNX.4.40.0203131618190.25172-100000@tao.office.aol.com>
References: <19463.1014409239@sss.pgh.pa.us>
<Pine.LNX.4.40.0203131618190.25172-100000@tao.office.aol.com>
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?
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: kleptog@svana.org, laotse@aol.net, pgsql-general@postgresql.org
Subject: Re: Strange Postgresql Indexing Behavior
In-Reply-To: <20020314131631.A3954@svana.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox