X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 978F4D6EBB; Thu, 29 Sep 2005 23:57:25 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 71213-04; Fri, 30 Sep 2005 02:57:19 +0000 (GMT) Received: from pop-knobcone.atl.sa.earthlink.net (pop-knobcone.atl.sa.earthlink.net [207.69.195.64]) by svr1.postgresql.org (Postfix) with ESMTP id AFC9DD6E1F; Thu, 29 Sep 2005 23:57:21 -0300 (ADT) Received: from elwamui-polski.atl.sa.earthlink.net ([209.86.224.45]) by pop-knobcone.atl.sa.earthlink.net with esmtp (Exim 3.36 #10) id 1ELB5L-0000Mg-00; Thu, 29 Sep 2005 22:57:19 -0400 Message-ID: <6812451.1128049039096.JavaMail.root@elwamui-polski.atl.sa.earthlink.net> Date: Thu, 29 Sep 2005 22:57:19 -0400 (EDT) From: Ron Peacetree Reply-To: Ron Peacetree To: Zeugswetter Andreas DAZ SD , pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org Subject: Re: [PERFORM] A Better External Sort? Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Earthlink Zoo Mail 1.0 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.26 required=5 tests=[AWL=-0.114, DNS_FROM_RFC_ABUSE=0.374] X-Spam-Level: X-Archive-Number: 200509/1406 X-Sequence-Number: 73803 >From: Zeugswetter Andreas DAZ SD >Sent: Sep 29, 2005 9:28 AM >Subject: RE: [HACKERS] [PERFORM] A Better External Sort? > >>In my original example, a sequential scan of the 1TB of 2KB >>or 4KB records, => 250M or 500M records of data, being sorted >>on a binary value key will take ~1000x more time than reading >>in the ~1GB Btree I described that used a Key+RID (plus node >>pointers) representation of the data. > >Imho you seem to ignore the final step your algorithm needs of >collecting the data rows. After you sorted the keys the collect >step will effectively access the tuples in random order (given a >sufficiently large key range). > "Collecting" the data rows can be done for each RAM buffer full of of data in one pass through RAM after we've built the Btree. Then if desired those data rows can be read out to HD in sorted order in essentially one streaming burst. This combination of index build + RAM buffer rearrangement + write results to HD can be repeat as often as needed until we end up with an overall Btree index and a set of sorted sublists on HD. Overall HD IO for the process is only two effectively sequential passes through the data. Subsequent retrieval of the sorted information from HD can be done at full HD streaming speed and whatever we've decided to save to HD can be reused later if we desire. Hope this helps, Ron