Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A9CB51337BE0 for ; Tue, 12 Oct 2010 15:58:25 -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 03712-03 for ; Tue, 12 Oct 2010 18:58:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id CFA4E1337BDB for ; Tue, 12 Oct 2010 15:58:17 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o9CIwDCn004293; Tue, 12 Oct 2010 14:58:13 -0400 (EDT) To: Jesper Krogh cc: Mladen Gogala , "david@lang.hm" , Craig Ringer , Vitalii Tymchyshyn , "pgsql-performance@postgresql.org" Subject: Re: Slow count(*) again... In-reply-to: <4CB4A749.3080705@krogh.cc> References: <201010091626.18636.neil.whelchel@gmail.com> <4CB34D69.6060108@emolecules.com> <4CB4149D.8030803@gmail.com> <4CB41902.1020503@postnewspapers.com.au> <4CB4542E.5010406@vmsinfo.com> <23516.1286891790@sss.pgh.pa.us> <4CB46AE2.7030006@vmsinfo.com> <27107.1286903278@sss.pgh.pa.us> <4CB4A749.3080705@krogh.cc> Comments: In-reply-to Jesper Krogh message dated "Tue, 12 Oct 2010 20:22:01 +0200" Date: Tue, 12 Oct 2010 14:58:13 -0400 Message-ID: <4292.1286909893@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/175 X-Sequence-Number: 40594 Jesper Krogh writes: > On 2010-10-12 19:07, Tom Lane wrote: >> Anyway, if anyone is hot to make COUNT(*) faster, that's where to look. > Just having 32 bytes bytes of "payload" would more or less double > you time to count if I read you test results correctly?. .. and in the > situation where diskaccess would be needed .. way more. > Dividing by pg_relation_size by the amout of tuples in our production > system I end up having no avg tuple size less than 100bytes. Well, yeah. I deliberately tested with a very narrow table so as to stress the per-row CPU costs as much as possible. With any wider table you're just going to be I/O bound. > .. without having complete insigt.. a visibillity map that could be used in > conjunction with indices would solve that. What the cost would be > of maintaining it is also a factor. I'm less than convinced that that approach will result in a significant win. It's certainly not going to do anything to convert COUNT(*) into an O(1) operation, which frankly is what the complainants are expecting. There's basically no hope of solving the "PR problem" without somehow turning COUNT(*) into a materialized-view reference. We've discussed that in the past, and know how to do it in principle, but the complexity and distributed overhead are daunting. regards, tom lane