Skip site navigation (1) Skip section navigation (2)

Re: Counting all rows

From: "Stefan Arentz" <stefan(dot)arentz(at)gmail(dot)com>
To: "Andreas Kretschmer" <akretschmer(at)spamfence(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Counting all rows
Date: 2007-06-23 13:15:22
Message-ID: adf34c300706230615j4763748dn9e1dae2cb5c2524c@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-sql
On 6/23/07, Andreas Kretschmer <akretschmer(at)spamfence(dot)net> wrote:
> Stefan Arentz <stefan(dot)arentz(at)gmail(dot)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.

In response to

pgsql-sql by date

Next:From: manchickenDate: 2007-06-23 15:13:32
Subject: Re: Counting all rows
Previous:From: RagnarDate: 2007-06-23 12:46:22
Subject: Re: join problem

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group