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 9D060D8F59; Fri, 23 Sep 2005 15:40:48 -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 47148-02; Fri, 23 Sep 2005 18:40:43 +0000 (GMT) Received: from pop-gadwall.atl.sa.earthlink.net (pop-gadwall.atl.sa.earthlink.net [207.69.195.61]) by svr1.postgresql.org (Postfix) with ESMTP id BFAB2D7B65; Fri, 23 Sep 2005 15:40:42 -0300 (ADT) Received: from elwamui-huard.atl.sa.earthlink.net ([209.86.224.35]) by pop-gadwall.atl.sa.earthlink.net with esmtp (Exim 3.36 #10) id 1EIsTP-0002hm-00; Fri, 23 Sep 2005 14:40:39 -0400 Message-ID: <24018329.1127500839434.JavaMail.root@elwamui-huard.atl.sa.earthlink.net> Date: Fri, 23 Sep 2005 14:40:39 -0400 (EDT) From: Ron Peacetree Reply-To: Ron Peacetree To: Mark Lewis , Tom Lane , pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org Subject: Re: [PERFORM] Releasing memory during External sorting? 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.28 required=5 tests=[AWL=-0.093, DNS_FROM_RFC_ABUSE=0.374] X-Spam-Level: X-Archive-Number: 200509/1033 X-Sequence-Number: 73430 Yep. Also, bear in mind that the lg(n!)= ~ nlgn - n lower bound on the number of comparisions: a= says nothing about the amount of data movement used. b= only holds for generic comparison based sorting algorithms. As Knuth says (vol 3, p180), Distribution Counting sorts without ever comparing elements to each other at all, and so does Radix Sort. Similar comments can be found in many algorithms texts. Any time we know that the range of the data to be sorted is substantially restricted compared to the number of items to be sorted, we can sort in less than O(lg(n!)) time. DB fields tend to take on few values and are therefore "substantially restricted". Given the proper resources and algorithms, O(n) sorts are very plausible when sorting DB records. All of the fastest external sorts of the last decade or so take advantage of this. Check out that URL I posted. Ron -----Original Message----- From: Mark Lewis Sent: Sep 23, 2005 1:43 PM To: Tom Lane Subject: Re: [PERFORM] Releasing memory during External sorting? 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. Not that I have anything else useful to add to this discussion, just a tidbit I remembered from my CS classes back in college :) -- Mark On Fri, 2005-09-23 at 13:17 -0400, Tom Lane wrote: > Ron Peacetree writes: > > 2= No optimal external sorting algorithm should use more than 2 passes. > > 3= Optimal external sorting algorithms should use 1 pass if at all possible. > > A comparison-based sort must use at least N log N operations, so it > would appear to me that if you haven't got approximately log N passes > then your algorithm doesn't work. > > regards, tom lane