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 81286D931F; Fri, 23 Sep 2005 15:15:56 -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 38634-08; Fri, 23 Sep 2005 18:15:53 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 2C006D930B; Fri, 23 Sep 2005 15:15:53 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j8NIFemK005442; Fri, 23 Sep 2005 14:15:40 -0400 (EDT) To: Mark Lewis Cc: Ron Peacetree , Simon Riggs , pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org Subject: Re: [PERFORM] Releasing memory during External sorting? In-reply-to: <1127497383.23567.218.camel@archimedes> References: <2559192.1127494115558.JavaMail.root@elwamui-huard.atl.sa.earthlink.net> <5021.1127495844@sss.pgh.pa.us> <1127497383.23567.218.camel@archimedes> Comments: In-reply-to Mark Lewis message dated "Fri, 23 Sep 2005 10:43:02 -0700" Date: Fri, 23 Sep 2005 14:15:40 -0400 Message-ID: <5441.1127499340@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200509/1025 X-Sequence-Number: 73422 Mark Lewis writes: > operations != passes. If you were clever, you could probably write a > modified bubble-sort algorithm that only made 2 passes. A pass is a > disk scan, operations are then performed (hopefully in memory) on what > you read from the disk. So there's no theoretical log N lower-bound on > the number of disk passes. Given infinite memory that might be true, but I don't think I believe it for limited memory. If you have room for K tuples in memory then it's impossible to perform more than K*N useful comparisons per pass (ie, as each tuple comes off the disk you can compare it to all the ones currently in memory; anything more is certainly redundant work). So if K < logN it's clearly not gonna work. It's possible that you could design an algorithm that works in a fixed number of passes if you are allowed to assume you can hold O(log N) tuples in memory --- and in practice that would probably work fine, if the constant factor implied by the O() isn't too big. But it's not really solving the general external-sort problem. regards, tom lane