Re: Performance of count(*) - Mailing list pgsql-performance

From ismo.tuononen@solenovo.fi
Subject Re: Performance of count(*)
Date
Msg-id Pine.LNX.4.64.0703221323590.1503@ismoli.solenovo.jns
Whole thread Raw
In response to Re: Performance of count(*)  (Albert Cervera Areny <albert@sedifa.com>)
Responses Re: Performance of count(*)
Re: Performance of count(*)
Re: Performance of count(*)
List pgsql-performance
approximated count?????

why? who would need it? where you can use it?

calculating costs and desiding how to execute query needs
approximated count, but it's totally worthless information for any user
IMO.

Ismo

On Thu, 22 Mar 2007, Albert Cervera Areny wrote:

> As you can see, PostgreSQL needs to do a sequencial scan to count because its
> MVCC nature and indices don't have transaction information. It's a known
> drawback inherent to the way PostgreSQL works and which gives very good
> results in other areas. It's been talked about adding some kind of
> approximated count which wouldn't need a full table scan but I don't think
> there's anything there right now.
>
> A Dijous 22 Març 2007 11:53, Andreas Tille va escriure:
> > Hi,
> >
> > I just try to find out why a simple count(*) might last that long.
> > At first I tried explain, which rather quickly knows how many rows
> > to check, but the final count is two orders of magnitude slower.
> >
> > My MS_SQL server using colleague can't believe that.
> >
> > $ psql InfluenzaWeb -c 'explain SELECT count(*) from agiraw ;'
> >                                QUERY PLAN
> > -----------------------------------------------------------------------
> >   Aggregate  (cost=196969.77..196969.77 rows=1 width=0)
> >     ->  Seq Scan on agiraw  (cost=0.00..185197.41 rows=4708941 width=0)
> > (2 rows)
> >
> > real    0m0.066s
> > user    0m0.024s
> > sys     0m0.008s
> >
> > $ psql InfluenzaWeb -c 'SELECT count(*) from agiraw ;'
> >    count
> > ---------
> >   4708941
> > (1 row)
> >
> > real    0m4.474s
> > user    0m0.036s
> > sys     0m0.004s
> >
> >
> > Any explanation?
> >
> > Kind regards
> >
> >           Andreas.
>
> --
> Albert Cervera Areny
> Dept. Informàtica Sedifa, S.L.
>
> Av. Can Bordoll, 149
> 08202 - Sabadell (Barcelona)
> Tel. 93 715 51 11
> Fax. 93 715 51 12
>
> ====================================================================
> ........................  AVISO LEGAL  ............................
> La   presente  comunicación  y sus anexos tiene como destinatario la
> persona a  la  que  va  dirigida, por  lo  que  si  usted lo  recibe
> por error  debe  notificarlo  al  remitente  y   eliminarlo   de  su
> sistema,  no  pudiendo  utilizarlo,  total  o   parcialmente,   para
> ningún  fin.  Su  contenido  puede  tener información confidencial o
> protegida legalmente   y   únicamente   expresa  la  opinión     del
> remitente.  El   uso   del   correo   electrónico   vía Internet  no
> permite   asegurar    ni  la   confidencialidad   de   los  mensajes
> ni    su    correcta     recepción.   En    el  caso   de   que   el
> destinatario no consintiera la utilización  del correo  electrónico,
> deberá ponerlo en nuestro conocimiento inmediatamente.
> ====================================================================
> ........................... DISCLAIMER .............................
> This message and its  attachments are  intended  exclusively for the
> named addressee. If you  receive  this  message  in   error,  please
> immediately delete it from  your  system  and notify the sender. You
> may  not  use  this message  or  any  part  of it  for any  purpose.
> The   message   may  contain  information  that  is  confidential or
> protected  by  law,  and  any  opinions  expressed  are those of the
> individual    sender.  Internet  e-mail   guarantees   neither   the
> confidentiality   nor  the  proper  receipt  of  the  message  sent.
> If  the  addressee  of  this  message  does  not  consent to the use
> of   internet    e-mail,    please    inform     us    inmmediately.
> ====================================================================
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
>                 http://www.postgresql.org/about/donate
>

pgsql-performance by date:

Previous
From: ismo.tuononen@solenovo.fi
Date:
Subject: Re: Performance of count(*)
Next
From: Andreas Tille
Date:
Subject: Re: Performance of count(*)