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

On 6/23/07, Andreas Kretschmer <akretschmer@spamfence.net> wrote:
> 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

Thank you Andreas. That is exactly what I was looking for.

 S.



view thread (4+ messages)  latest in thread

Message-ID: <adf34c300706230615j4763748dn9e1dae2cb5c2524c@mail.gmail.com>
Permalink:  ../adf34c300706230615j4763748dn9e1dae2cb5c2524c@mail.gmail.com/
Also on:    postgresql.org/message-id/adf34c300706230615j4763748dn9e1dae2cb5c2524c@mail.gmail.com

 · 

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: stefan.arentz@gmail.com, akretschmer@spamfence.net
  Subject: Re: Counting all rows
  In-Reply-To: <adf34c300706230615j4763748dn9e1dae2cb5c2524c@mail.gmail.com>

* 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