PostgreSQL: Why does this simple query not use the index?

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2011-02-04T22:43:58Z Indexed on 2011/02/04 23:25 UTC
Read the original article Hit count: 256

I have a table t with a column c, which is an int and has a btree index on it.

Why does the following query not utilize this index?

explain select c from t group by c;

The result I get is:

HashAggregate  (cost=1005817.55..1005817.71 rows=16 width=4)
  ->  Seq Scan on t  (cost=0.00..946059.84 rows=23903084 width=4)

My understanding of indexes is limited, but I thought such queries were the purpose of indexes.

© Stack Overflow or respective owner

Related posts about database

Related posts about postgresql