Re: Why is it not using an index?

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Dmitry Tkach <dmitry(at)openratings(dot)com>
Cc: Gregory Wood <gregw(at)com-stock(dot)com>, PostgreSQL-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Why is it not using an index?
Date: 2002-03-15 20:12:14
Message-ID: 20020315120934.Y54258-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-sql


On Fri, 15 Mar 2002, Dmitry Tkach wrote:

> explain select count (x) from a ;
>
> Aggregate (cost=100175934.05..100175934.05 rows=1 width=2)
> -> Seq Scan on a (cost=100000000.00..100150659.04 rows=10110004 width=2)
>
> Am I missing something here again, or will it just not use an index
> for aggregation?

It won't for something like the above because it needs to test each row
to see if it's currently visible to your transaction (which involves
reading from the table file anyway) which means you end up reading the
entire table plus the index (and paying some costs in random access).
If the index had the transaction information the index would be usable
but there are issues about doing that as well (you might want to check
past messages - especially ones from Tom Lane - on the subject)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Luc Lachance 2002-03-15 20:25:47 Re: Why is it not using an index?
Previous Message Dmitry Tkach 2002-03-15 20:01:17 Re: Why is it not using an index?

Browse pgsql-sql by date

  From Date Subject
Next Message Jean-Luc Lachance 2002-03-15 20:25:47 Re: Why is it not using an index?
Previous Message Dmitry Tkach 2002-03-15 20:01:17 Re: Why is it not using an index?