Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 31A8F2E0056 for ; Thu, 15 May 2008 10:15:50 -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 24124-08 for ; Thu, 15 May 2008 10:15:32 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from py-out-1112.google.com (py-out-1112.google.com [64.233.166.177]) by developer.postgresql.org (Postfix) with ESMTP id F01002E0052 for ; Thu, 15 May 2008 10:15:34 -0300 (ADT) Received: by py-out-1112.google.com with SMTP id d37so402520pye.29 for ; Thu, 15 May 2008 06:15:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id:sender; bh=Dd+V0FxEo4IdH3+tdYd1TRiXEheMKqwwR8tKiiNd0gA=; b=Uf1cG9XHfM4f2t2GChk7wpB9xV1fBoo2Ve4QITyU674vqkOqy6Wr3vNcOCrbiAzy5Rin/5wqAJLCasBCpr/gRmO3QXSHLGPvkR6moh6CJD+W6ajIqn6S9ewSF6rHF74VGyORveIbW1cFzhm8yTLVsc5qoBe0UiU8tLvTIObDDu0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:user-agent:cc:references:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:message-id:sender; b=sdj02HJNJfJHxTowxwCJqCmn92AbgaWk77bFwqSX5TuhQQvWZXTxhtjbWT0xKWGr1u8gQ1FiSotsh41UeMV792y9Zen9NQTQ/UulZvlYBLq2SLC1LXjOWIl/GixNVS6CWK//sBfZ+P4mpkm2RX89SfsoP5TwOhl9ttS6fTrdH78= Received: by 10.65.44.11 with SMTP id w11mr3411689qbj.11.1210857333222; Thu, 15 May 2008 06:15:33 -0700 (PDT) Received: from kitchener.toronto.digitalfairway.ca ( [24.235.117.179]) by mx.google.com with ESMTPS id q13sm3321167qbq.15.2008.05.15.06.15.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 15 May 2008 06:15:32 -0700 (PDT) From: Jan de Visser To: Tom Lane Subject: Re: I/O on select count(*) Date: Thu, 15 May 2008 09:15:40 -0400 User-Agent: KMail/1.9.9 Cc: "Greg Smith" , "Alvaro Herrera" , pgsql-performance@postgresql.org References: <920841.71690.qm@web44808.mail.sp1.yahoo.com> <1159c1e90805141938j5f85b490rb5c1cfdf9e428bce@mail.gmail.com> <28324.1210834939@sss.pgh.pa.us> In-Reply-To: <28324.1210834939@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200805150915.40793.jdevisser@digitalfairway.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/207 X-Sequence-Number: 30175 On Thursday 15 May 2008 03:02:19 Tom Lane wrote: > "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 True. But it still contributes to the fact that queries sometimes behave in a non-deterministic way, which IMHO is the major annoyance when starting to work with pgsql. And contrary to other causes (vacuum, checkpoints) this is woefully underdocumented. jan