Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id CE0871337B58 for ; Wed, 6 Oct 2010 17:28:13 -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 08281-06 for ; Wed, 6 Oct 2010 20:28:06 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id A55DB1337B56 for ; Wed, 6 Oct 2010 17:28:05 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Wed, 06 Oct 2010 15:28:04 -0500 Message-Id: <4CAC957B02000025000365D8@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Wed, 06 Oct 2010 15:27:55 -0500 From: "Kevin Grittner" To: "hsienwen chu" , Subject: Re: Question about the IO on full table scan operation References: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.21 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201010/63 X-Sequence-Number: 35804 hsienwen chu wrote: > the situation is that: I have a table, and the size is about 10M, > I run the database on Redhat Linux platform. for OS, a IO can hand > 1M data, the file system block is 4k, database block is 8k, > > my question is that: when do the full table scan on the table, how > many IO will be done? 10M/1M=10 ? or 10M/8k=1280? or 10M/4k=2560? Well, it will be looking at one 8kB block at a time, but the number of I/O operations to the actual disk is hard to estimate and may vary from run to run, especially if another table scan is going on at the same time. Some pages may be found in shared buffers, and therefore generate no disk access. PostgreSQL reads go through the OS cache, so some pages may be found there, and generate no disk access. Most serious database servers have a RAID controller with a cache, which may also avoid disk access. You might even read from a write-through cache on a drive without actually going to the disk. On top of that, many operating systems will notice a pattern of sequential reads through a file and do larger block read-ahead access for performance. And PostgreSQL has its own tricks -- if you start a sequential table scan while another process is already doing one, your scan will start where the other one is, to avoid double-reads. About all I can say with any certainty is that it *won't* be doing 10M/4k=2560 reads. And even there I won't be too surprised if someone corrects me with an explanation of then *that* might happen. ;-) -Kevin