From: Tom Lane <tgl@sss.pgh.pa.us>
To: Manfred Koizar <mkoi-pg@aon.at>
Cc: Edmund Dengler <edmundd@eSentire.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Unable to use index?
Date: Thu, 29 Apr 2004 19:41:01 -0400
Message-ID: <18132.1083282061@sss.pgh.pa.us> (raw)
In-Reply-To: <qt9290h3lfvkiitt4muiblbg882ua7r4sj@email.aon.at>
References: <Pine.BSO.4.58.0404290940420.21603@cyclops4.esentire.com>
<qt9290h3lfvkiitt4muiblbg882ua7r4sj@email.aon.at>
Manfred Koizar <mkoi-pg@aon.at> writes:
> The planner thinks that the seq scan has a startup cost of 0.00, i.e.
> that it can return the first tuple immediately, which is obviously not
> true in the presence of a filter condition.
Not really --- the startup cost is really defined as "cost expended
before we can start scanning for results". The estimated cost to select
N tuples is actually "startup_cost + N*(total_cost-startup_cost)/M",
where M is the estimated total rows returned. This is why the LIMIT
shows a nonzero estimate for the cost to fetch 1 row.
> Unfortunately there's no
> easy way to fix this, because the statistics information does not have
> information about the physical position of tuples with certain vaules.
Yeah, I think the real problem is that the desired rows are not
uniformly distributed, and in fact there are none near the start of the
table. We do not keep stats detailed enough to let the planner discover
this, so it has to estimate on the assumption of uniform distribution.
On that assumption, it looks like a seqscan will hit a suitable tuple
quickly enough to be faster than using the index.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, mkoi-pg@aon.at, edmundd@eSentire.com
Subject: Re: Unable to use index?
In-Reply-To: <18132.1083282061@sss.pgh.pa.us>
References: <Pine.BSO.4.58.0404290940420.21603@cyclops4.esentire.com> <qt9290h3lfvkiitt4muiblbg882ua7r4sj@email.aon.at> <18132.1083282061@sss.pgh.pa.us>
* 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