Re: Seq Scan

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Tyler Durden <tylersticky(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Seq Scan
Date: 2007-06-01 17:03:30
Message-ID: 96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On Jun 1, 2007, at 11:48 , Tyler Durden wrote:

> I'm having some problems in performance in a simple select count(id)
> from....

Unrestricted count() (i.e., no WHERE clause) will perform a
sequential scan. If you're looking for faster ways to store table row
count information, please search the archives, as this has been
discussed many times before.

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

The query returns the id column value for each row in the table. The
fastest way to do this is visiting every row., i.e., a sequential
scan. Using an index would require (1) looking in the index and (2)
looking up the corresponding row.

Michael Glaesemann
grzm seespotcode net

In response to

  • Seq Scan at 2007-06-01 16:48:56 from Tyler Durden

Browse pgsql-performance by date

  From Date Subject
Next Message Craig James 2007-06-01 17:57:56 Autodetect of software RAID1+0 fails
Previous Message Dan Harris 2007-06-01 16:59:01 Re: Seq Scan