pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Glaesemann <grzm@seespotcode.net>
To: Tyler Durden <tylersticky@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Seq Scan
Date: Fri, 1 Jun 2007 12:03:30 -0500
Message-ID: <96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net> (raw)
In-Reply-To: <ab07320e0706010948m7c4eb1b8s9cdaf79b1c400125@mail.gmail.com>
References: <ab07320e0706010948m7c4eb1b8s9cdaf79b1c400125@mail.gmail.com>


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





view thread (3+ messages)

Message-ID: <96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net>
Permalink:  ../96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net/
Also on:    postgresql.org/message-id/96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: grzm@seespotcode.net, tylersticky@gmail.com
  Subject: Re: Seq Scan
  In-Reply-To: <96F60F91-F3A7-4134-8DD0-E519C8941CDB@seespotcode.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox