Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 3AC012E021E for ; Tue, 11 Mar 2008 05:41:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 88772-05 for ; Tue, 11 Mar 2008 05:41:21 -0300 (ADT) X-Greylist: delayed 00:06:38.803376 by SQLgrey-1.7.5 Received: from mails1.interdominios.com (mails1.interdominios.com [89.248.97.42]) by postgresql.org (Postfix) with ESMTP id C5DBC2E0210 for ; Tue, 11 Mar 2008 05:41:20 -0300 (ADT) Received: (qmail 21952 invoked from network); 11 Mar 2008 10:22:28 +0100 Received: from unknown (HELO sardina) (83.175.220.10) by lujojes.com with SMTP; 11 Mar 2008 10:22:27 +0100 From: Albert Cervera Areny Organization: Sedifa, S.L. To: pgsql-performance@postgresql.org Subject: Re: count * performance issue Date: Tue, 11 Mar 2008 09:34:30 +0100 User-Agent: KMail/1.9.5 Cc: "Scott Marlowe" , "Robins Tharakan" References: <36af4bed0803101957u6078127fq78dc3384fe78de5d@mail.gmail.com> 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: <200803110934.31254.albert@sedifa.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/224 X-Sequence-Number: 29178 A Dimarts 11 Mar=E7 2008 04:11, Scott Marlowe va escriure: > On Mon, Mar 10, 2008 at 7:57 PM, Robins Tharakan wro= te: > > Hi, > > > > I have been reading this conversation for a few days now and I just > > wanted to ask this. From the release notes, one of the new additions in > > 8.3 is (Allow col IS NULL to use an index (Teodor)). > > > > Sorry, if I am missing something here, but shouldn't something like this > > allow us to get a (fast) accurate count ? > > > > SELECT COUNT(*) from table WHERE indexed_field IS NULL > > + > > SELECT COUNT(*) from table WHERE indexed_field IS NOT NULL > > It really depends on the distribution of the null / not nulls in the > table. If it's 50/50 there's no advantage to using the index, as you > still have to check visibility info in the table itself. > > OTOH, if NULL (or converserly not null) are rare, then yes, the index > can help. I.e. if 1% of the tuples are null, the select count(*) from > table where field is null can use the index efficiently. But you'll get a sequential scan with the NOT NULL case which will end up=20 taking more time. (Seq Scan + Index Scan > Seq Scan) =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