Re: Counting all rows - Mailing list pgsql-sql

From Andreas Kretschmer
Subject Re: Counting all rows
Date
Msg-id 20070623103856.GE7307@KanotixBox
Whole thread Raw
In response to Counting all rows  ("Stefan Arentz" <stefan.arentz@gmail.com>)
Responses Re: Counting all rows  ("Stefan Arentz" <stefan.arentz@gmail.com>)
Re: Counting all rows  (manchicken <manchicken@notsosoft.net>)
List pgsql-sql
Stefan Arentz <stefan.arentz@gmail.com> schrieb:

> I need to get statistics from a bunch of tables. Simply the number of
> records in them.
> 
> The query plan looks like this:
> 
> => explain select count(id) from stuff;
>                             QUERY PLAN
> -------------------------------------------------------------------
>  Aggregate  (cost=1629.69..1629.70 rows=1 width=8)
>    ->  Seq Scan on stuff  (cost=0.00..1517.75 rows=44775 width=8)
> 
> The sequential scan kind of worries me. Is there a better/faster way to do 
> this?

Yes. 

A "select count(*) from foo;" enforces a seq. scan. Solutions for this
are discussed here: http://www.varlena.com/GeneralBits/120.php


Andreas
-- 
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect.                              (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly."    (unknow)
Kaufbach, Saxony, Germany, Europe.              N 51.05082°, E 13.56889°


pgsql-sql by date:

Previous
From: "Stefan Arentz"
Date:
Subject: Counting all rows
Next
From: Ragnar
Date:
Subject: Re: join problem