pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <akretschmer@spamfence.net>
To: pgsql-sql@postgresql.org
Subject: Re: Counting all rows
Date: Sat, 23 Jun 2007 12:38:56 +0200
Message-ID: <20070623103856.GE7307@KanotixBox> (raw)
In-Reply-To: <adf34c300706230315y43ba92daqf0804b7c377ffd29@mail.gmail.com>
References: <adf34c300706230315y43ba92daqf0804b7c377ffd29@mail.gmail.com>

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°



view thread (4+ messages)  latest in thread

Message-ID: <20070623103856.GE7307@KanotixBox>
Permalink:  ../20070623103856.GE7307@KanotixBox/
Also on:    postgresql.org/message-id/20070623103856.GE7307@KanotixBox

 · 

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-sql@postgresql.org
  Cc: akretschmer@spamfence.net
  Subject: Re: Counting all rows
  In-Reply-To: <20070623103856.GE7307@KanotixBox>

* 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