Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 53F781337BD2 for ; Mon, 11 Oct 2010 23:36:55 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 88123-10 for ; Tue, 12 Oct 2010 02:36:48 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from kuva.firstlight.net (kuva.firstlight.net [216.86.201.22]) by mail.postgresql.org (Postfix) with ESMTP id 2B3E61337BCA for ; Mon, 11 Oct 2010 23:36:48 -0300 (ADT) Received: from carbon.firstlight.net (unknown [75.79.180.65]) by kuva.firstlight.net (Postfix) with ESMTPA id 8E19B270BD for ; Mon, 11 Oct 2010 19:36:47 -0700 (PDT) From: Neil Whelchel Organization: Go-Automation To: "pgsql-performance@postgresql.org" Subject: Re: Slow count(*) again... Date: Mon, 11 Oct 2010 19:36:45 -0700 User-Agent: KMail/1.13.5 (Linux/2.6.35.5; KDE/4.5.1; i686; ; ) References: <201010091626.18636.neil.whelchel@gmail.com> <201010111254.58479.neil.whelchel@gmail.com> <4CB3A2CC.9070009@vmsinfo.com> In-Reply-To: <4CB3A2CC.9070009@vmsinfo.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201010111936.46207.neil.whelchel@gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201010/124 X-Sequence-Number: 40543 On Monday 11 October 2010 16:50:36 you wrote: > On 10/11/2010 3:54 PM, Neil Whelchel wrote: > > 1. A faster count(*), or something like my proposed estimate(*). > > 2. A way to get the total rows matched when using LIMIT and OFFSET before > > LIMIT and OFFSET are applied. > > The biggest single problem with "select count(*)" is that it is > seriously overused. People use that idiom to establish existence, which > usually leads to a performance disaster in the application using it, > unless the table has no more than few hundred records. SQL language, of > which PostgreSQL offers an excellent implementation, offers [NOT] > EXISTS clause since its inception in the Jurassic era. The problem is > with the sequential scan, not with counting. I'd even go as far as to > suggest that 99% instances of the "select count(*)" idiom are probably > bad use of the SQL language. I agree, I have seen many very bad examples of using count(*). I will go so far as to question the use of count(*) in my examples here. It there a better way to come up with a page list than using count(*)? What is the best method to make a page of results and a list of links to other pages of results? Am I barking up the wrong tree here? -Neil-