Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id D8FBC1336971 for ; Tue, 12 Oct 2010 04:56:15 -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 81829-08 for ; Tue, 12 Oct 2010 07:56:08 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com [209.85.161.46]) by mail.postgresql.org (Postfix) with ESMTP id 388BA1336705 for ; Tue, 12 Oct 2010 04:56:07 -0300 (ADT) Received: by fxm4 with SMTP id 4so882731fxm.19 for ; Tue, 12 Oct 2010 00:56:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=rXmHzSoH8/mqPnCsPcN0QRTmPENMMZ3/wttYgX3P+VI=; b=fZSvWu8TZYZqYNKSxbbXLeIJivCEzorCDtaCiuRZaxJYTFYl5QO43mxQ40s4mty1Me cwhpCJgB3bBg8itms+3KmfdYzEnnZTOjluN8DOZueYdiopD9BsLO/UsgMUbBqQfU6CH6 xJsGeUktgAYrXNEgxvMqkyC4POwLlurtLtGP4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=ZqORC532GMa53bvxtbO8lcoAWAAiL2ZgrhxbLO9sFQxKke1kD7ycDdaPoXYdJfCBMs 4XBTbRRVtfV01kp/SBPZWqBJ/ZEtb8egxwEfXhLEc6g/YGhSIvbAKADHeHvv6kuC1w50 xrfwhkhT4G0fyhs9gmlhQCtUAO1Hp8fA2UIxg= Received: by 10.103.108.3 with SMTP id k3mr769984mum.41.1286870166738; Tue, 12 Oct 2010 00:56:06 -0700 (PDT) Received: from [10.1.1.57] (skuns.zoral.com.ua [91.193.166.194]) by mx.google.com with ESMTPS id m8sm1322324faj.1.2010.10.12.00.56.05 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 12 Oct 2010 00:56:05 -0700 (PDT) Message-ID: <4CB4149D.8030803@gmail.com> Date: Tue, 12 Oct 2010 10:56:13 +0300 From: Vitalii Tymchyshyn User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100915 Thunderbird/3.0.8 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Slow count(*) again... References: <201010091626.18636.neil.whelchel@gmail.com> <4CB34D69.6060108@emolecules.com> In-Reply-To: <4CB34D69.6060108@emolecules.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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/134 X-Sequence-Number: 40553 11.10.10 20:46, Craig James написав(ла): > > First of all, it's not true. There are plenty of applications that > need an exact answer. Second, even if it is only 1%, that means it's > 1% of the queries, not 1% of people. Sooner or later a large fraction > of developers will run into this. It's probably been the most-asked > question I've seen on this forum in the four years I've been here. > It's a real problem, and it needs a real solution. > > I know it's a hard problem to solve, but can we stop hinting that > those of us who have this problem are somehow being dense? > BTW: There is a lot of talk about MVCC, but is next solution possible: 1) Create a page information map that for each page in the table will tell you how may rows are within and if any write (either successful or not) were done to this page. This even can be two maps to make second one really small (a bit per page) - so that it could be most time in-memory. 2) When you need to to count(*) or index check - first check if there were no writes to the page. If not - you can use count information from page info/index data without going to the page itself 3) Let vacuum clear the bit after frozing all the tuples in the page (am I using terminology correctly?). In this case all read-only (archive) data will be this bit off and index/count(*) will be really fast. Am I missing something? Best regards, Vitalii Tymchyshyn.