Why count(*) doest use index?

From: <obamabarak(at)e1(dot)ru>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Why count(*) doest use index?
Date: 2011-03-03 13:29:09
Message-ID: f2c79335414803f3993cb45b434134be@e1.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I use pgsql 9.0.3 and I know that postgresql tries to use the fields
in indexes instead of the original table if it possible

But when I run

SELECT COUNT(id) FROM tab

or

SELECT COUNT(*) FROM tab

where
there "id" is PRIMARY KEY and there are other indexes there I get
execution plan that doesnt use any indexes, but sequentab scanning the
original table.

"Aggregate (cost=38685.98..38685.99 rows=1 width=0)"

" -> Seq Scan on tab (cost=0.00..36372.38 rows=925438 width=0)"

Why is
it so?

---

Paul

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-03-03 14:15:06 Re: I need your help to get opinions about this situation
Previous Message Willy-Bas Loos 2011-03-03 13:28:17 Re: Integrated Trigers