Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 7675E2E0102 for ; Thu, 15 May 2008 04:54:52 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 98832-02-3 for ; Thu, 15 May 2008 04:54:27 -0300 (ADT) 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 developer.postgresql.org (Postfix) with ESMTP id 6878F2E00C7 for ; Thu, 15 May 2008 04:02:22 -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 m4F72Jok028325; Thu, 15 May 2008 03:02:19 -0400 (EDT) To: "Jan de Visser" cc: "Greg Smith" , "Alvaro Herrera" , pgsql-performance@postgresql.org Subject: Re: I/O on select count(*) In-reply-to: <1159c1e90805141938j5f85b490rb5c1cfdf9e428bce@mail.gmail.com> References: <920841.71690.qm@web44808.mail.sp1.yahoo.com> <482B1D5F.EE98.0025.0@wicourts.gov> <20080515020553.GN9838@alvh.no-ip.org> <1159c1e90805141938j5f85b490rb5c1cfdf9e428bce@mail.gmail.com> Comments: In-reply-to "Jan de Visser" message dated "Wed, 14 May 2008 22:38:08 -0400" Date: Thu, 15 May 2008 03:02:19 -0400 Message-ID: <28324.1210834939@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/198 X-Sequence-Number: 30166 "Jan de Visser" writes: > Obviously, this issue is tied to the slow count(*) one, as I found out > the hard way. Consider the following scenario: > * Insert row > * Update that row a couple of times > * Rinse and repeat many times > Now somewhere during that cycle, do a select count(*) just to see > where you are. You will be appalled by how slow that is, due to not > only the usual 'slow count(*)' reasons. This whole hint bit business > makes it even worse, as demonstrated by the fact that running a vacuum > before the count(*) makes the latter noticably faster. Uh, well, you can't blame that entirely on hint-bit updates. The vacuum has simply *removed* two-thirds of the rows in the system, resulting in a large drop in the number of rows that the select even has to look at. It's certainly true that hint-bit updates cost something, but quantifying how much isn't easy. The off-the-cuff answer is to do the select count(*) twice and see how much cheaper the second one is. But there are two big holes in that answer: the first is the possible cache effects from having already read in the pages, and the second is that the follow-up scan gets to avoid the visits to pg_clog that the first scan had to make (which after all is the point of the hint bits). I don't know any easy way to disambiguate the three effects that are at work here. But blaming it all on the costs of writing out hint-bit updates is wrong. regards, tom lane