Search Postgresql Archives

Re: Seq Scan

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tyler Durden wrote:

I'm having some problems in performance in a simple select count(id)
from.... I have 700 000 records in one table, and when I do:

# explain select (id) from table_name;
-[ RECORD 1 ]---------------------------------------------------------------- QUERY PLAN | Seq Scan on table_name (cost=0.00..8601.30 rows=266730 width=4)

I had created an index for id(btree), but still shows "Seq Scan".
What I'm doing wrong?

You mention SELECT COUNT(ID), but your example shows SELECT ID. In either case, the planner is choosing the correct plan. Indexes exist to save the engine from visiting every row in the table, but both of these queries require every row to be visited anyway.

Perhaps you think that these queries can be satisfied without visiting the actual table rows at all, using only the index. This is incorrect - PG doesn't work that way.

- John Burger
  MITRE



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux