Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 577C09FB875 for ; Thu, 22 Mar 2007 08:15:08 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 83971-08 for ; Thu, 22 Mar 2007 08:15:03 -0300 (ADT) X-Greylist: delayed 00:06:38.674321 by SQLgrey-1.7.4 Received: from correo14.acens.net (correo14.acens.net [217.116.0.88]) by postgresql.org (Postfix) with ESMTP id 8FBFC9FB896 for ; Thu, 22 Mar 2007 08:15:03 -0300 (ADT) Received: (qmail 24613 invoked from network); 22 Mar 2007 11:08:22 -0000 Received: from unknown (HELO albert.sedifa.com) ([83.175.220.10]) (envelope-sender ) by correo14.acens.net (qmail-ldap-1.03) with SMTP for ; 22 Mar 2007 11:08:22 -0000 From: Albert Cervera Areny Organization: Sedifa, S.L. To: pgsql-performance@postgresql.org Subject: Re: Performance of count(*) Date: Thu, 22 Mar 2007 12:08:19 +0100 User-Agent: KMail/1.9.5 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200703221208.19358.albert@sedifa.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.051 tagged_above=0 required=5 tests=AWL, BAYES_50 X-Spam-Level: X-Archive-Number: 200703/305 X-Sequence-Number: 23710 As you can see, PostgreSQL needs to do a sequencial scan to count because i= ts=20 MVCC nature and indices don't have transaction information. It's a known=20 drawback inherent to the way PostgreSQL works and which gives very good=20 results in other areas. It's been talked about adding some kind of=20 approximated count which wouldn't need a full table scan but I don't think= =20 there's anything there right now. A Dijous 22 Mar=E7 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=3D196969.77..196969.77 rows=3D1 width=3D0) > -> Seq Scan on agiraw (cost=3D0.00..185197.41 rows=3D4708941 width= =3D0) > (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. =2D-=20 Albert Cervera Areny Dept. Inform=E0tica Sedifa, S.L. Av. Can Bordoll, 149 08202 - Sabadell (Barcelona) Tel. 93 715 51 11 =46ax. 93 715 51 12 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2E....................... AVISO LEGAL ............................ La presente comunicaci=F3n 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=FAn fin. Su contenido puede tener informaci=F3n confidencial o protegida legalmente y =FAnicamente expresa la opini=F3n del remitente. El uso del correo electr=F3nico v=EDa Internet no permite asegurar ni la confidencialidad de los mensajes ni su correcta recepci=F3n. En el caso de que el destinatario no consintiera la utilizaci=F3n del correo electr=F3nico, deber=E1 ponerlo en nuestro conocimiento inmediatamente. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2E.......................... 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. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20