From: John Meinel <john@johnmeinel.com>
To: Francisco Reyes <lists@natserv.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: why my query is not using index??
Date: Mon, 11 Oct 2004 19:12:45 -0500
Message-ID: <416B217D.9090000@johnmeinel.com> (raw)
In-Reply-To: <20041011163756.M97379@zoraida.natserv.net>
References: <41639F3C.4050103@siche.net>
<200410111425.02671.vygen@gmx.de>
<20041011163756.M97379@zoraida.natserv.net>
Francisco Reyes wrote:
> On Mon, 11 Oct 2004, Janning Vygen wrote:
>
[...]
> When I saw the default explain I was surprised to see that indexes were
> not been used. For example the join on lines 4,5 are exactly the primary
> key of the tables yet a sequential scan was used.
>
Note this:
> The default explain was:
>
> Sort (cost=382.01..382.15 rows=56 width=196)
> Sort Key: accounts.account_group, accounts.account_name,
[...]
Versus this:
>
> After set enable_seqscan to off;
> It becomes
>
> Sort (cost=490.82..490.96 rows=56 width=196)
> Sort Key: accounts.account_group, accounts.account_name,
[...]
Postgres believes that it will cost 382 to do a sequential scan, versus
490 for an indexed scan. Hence why it prefers to do the sequential scan.
Try running explain analyze to see if how accurate it is.
As Janning mentioned, sometimes sequential scans *are* faster. If the
number of entries that will be found is large compared to the number of
total entries (I don't know the percentages, but probably >30-40%), then
it is faster to just load the data and scan through it, rather than
doing a whole bunch of indexed lookups.
John
=:->
Attachments:
signature.asc (application/pgp-signature, 252B) download
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-performance@postgresql.org
Cc: john@johnmeinel.com, lists@natserv.com
Subject: Re: why my query is not using index??
In-Reply-To: <416B217D.9090000@johnmeinel.com>
* 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