Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id E3AA81337B95 for ; Wed, 13 Oct 2010 04:46:43 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 97389-01-4 for ; Wed, 13 Oct 2010 07:46:36 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from 26.mail-out.ovh.net (26.mail-out.ovh.net [91.121.27.225]) by mail.postgresql.org (Postfix) with SMTP id A4D1D1337BED for ; Wed, 13 Oct 2010 04:46:33 -0300 (ADT) Received: (qmail 3528 invoked by uid 503); 13 Oct 2010 07:51:29 -0000 Received: from b6.ovh.net (HELO mail612.ha.ovh.net) (213.186.33.56) by 26.mail-out.ovh.net with SMTP; 13 Oct 2010 07:51:29 -0000 Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 13 Oct 2010 09:46:31 +0200 Received: from par69-8-88-161-102-87.fbx.proxad.net (HELO apollo13) (lists%peufeu.com@88.161.102.87) by ns0.ovh.net with SMTP; 13 Oct 2010 09:46:30 +0200 Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "pgsql-performance@postgresql.org" , "Neil Whelchel" Subject: Re: Slow count(*) again... References: <201010091626.18636.neil.whelchel@gmail.com> <201010111936.46207.neil.whelchel@gmail.com> <201010121619.34839.neil.whelchel@gmail.com> Date: Wed, 13 Oct 2010 09:46:25 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pierre C" Message-ID: In-Reply-To: <201010121619.34839.neil.whelchel@gmail.com> User-Agent: Opera Mail/10.62 (Linux) X-Ovh-Tracer-Id: 7193937455286584881 X-Ovh-Remote: 88.161.102.87 (par69-8-88-161-102-87.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N 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, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201010/196 X-Sequence-Number: 40615 > I guess I have to comment here again and point out that while I am > having this > issue with text searches, I avoid using count(*) in such cases, I just > use > next and previous links. Unfortunately sometimes you got to do an ORDER BY on search results, and then all the rows got to be read... > Where the real problem (for me) is that when someone > searches a date or time range. My application keeps track of huge Have you tried CLUSTER ? Also, it is sad to say, but if you need an engine able to use index-only scans which would fit this type of query, replicate the table to MyISAM. Unfortunately, the MySQL optimizer is really not so smart about complex reporting queries (no hash joins, no hash aggregates) so if you don't have a multicolumn index covering that you can use for index-only scan in your query, you'll get either a really huge sort or a really nasty nested loop index scan...