Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 261242E0095 for ; Tue, 11 Mar 2008 00:08:56 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 60673-02 for ; Tue, 11 Mar 2008 00:08:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by postgresql.org (Postfix) with ESMTP id 5D33A2E003B for ; Tue, 11 Mar 2008 00:08:50 -0300 (ADT) Received: from jd-laptop (or-69-34-217-90.sta.embarqhsd.net [69.34.217.90]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id m2B39F1G011313 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 10 Mar 2008 20:09:16 -0700 Date: Mon, 10 Mar 2008 20:08:44 -0700 From: "Joshua D. Drake" To: "Robins Tharakan" Cc: pgsql-performance@postgresql.org Subject: Re: count * performance issue Message-ID: <20080310200844.2281f0e8@jd-laptop> In-Reply-To: <36af4bed0803101957u6078127fq78dc3384fe78de5d@mail.gmail.com> References: <47D00DB2.7040007@emolecules.com> <18451.1204824562@sss.pgh.pa.us> <200803071727.36146.josh@agliodbs.com> <13345.1204940295@sss.pgh.pa.us> <87r6eia9tz.fsf@oxford.xeocode.com> <12ba3bf00803101354w15b023e1o237f564a1b01105f@mail.gmail.com> <36af4bed0803101957u6078127fq78dc3384fe78de5d@mail.gmail.com> Organization: Joshua D. Drake X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.0; i486-pc-linux-gnu) Mime-Version: 1.0 Content-Type: multipart/signed; boundary="Sig_/oJfUE0/RZwjOO3jR9mdvTCH"; protocol="application/pgp-signature"; micalg=PGP-SHA1 X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (lists.commandprompt.com [207.173.203.159]); Mon, 10 Mar 2008 20:09:16 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200803/220 X-Sequence-Number: 29174 --Sig_/oJfUE0/RZwjOO3jR9mdvTCH Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Tue, 11 Mar 2008 08:27:05 +0530 "Robins Tharakan" wrote: > SELECT COUNT(*) from table WHERE indexed_field IS NULL > + > SELECT COUNT(*) from table WHERE indexed_field IS NOT NULL If the selectivity is appropriate yes. However if you have 1 million rows, and 200k of those rows are null (or not null), it is still going to seqscan. joshua d. drake --=20 The PostgreSQL Company since 1997: http://www.commandprompt.com/=20 PostgreSQL Community Conference: http://www.postgresqlconference.org/ Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate PostgreSQL SPI Liaison | SPI Director | PostgreSQL political pundit --Sig_/oJfUE0/RZwjOO3jR9mdvTCH Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) iD8DBQFH1fe/ATb/zqfZUUQRAjE3AJ0fUACzxS9REyOzNJBOSHyy/oEfYQCeMIJB X68cmUhoyAIqilI9OeOcoAo= =fTl/ -----END PGP SIGNATURE----- --Sig_/oJfUE0/RZwjOO3jR9mdvTCH--