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 B27BDD90CA; Fri, 23 Sep 2005 12:31:39 -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 00171-02; Fri, 23 Sep 2005 15:31:33 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 252C7D92E1; Fri, 23 Sep 2005 12:31:32 -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 j8NFVSNg004203; Fri, 23 Sep 2005 11:31:28 -0400 (EDT) To: Simon Riggs Cc: pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org Subject: Re: Releasing memory during External sorting? In-reply-to: <1127487978.19345.43.camel@localhost.localdomain> References: <1127468233.4145.178.camel@localhost.localdomain> <3465.1127484579@sss.pgh.pa.us> <1127487978.19345.43.camel@localhost.localdomain> Comments: In-reply-to Simon Riggs message dated "Fri, 23 Sep 2005 16:06:18 +0100" Date: Fri, 23 Sep 2005 11:31:28 -0400 Message-ID: <4202.1127489488@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/1016 X-Sequence-Number: 73413 Simon Riggs writes: > Since we know the predicted size of the sort set prior to starting the > sort node, could we not use that information to allocate memory > appropriately? i.e. if sort size is predicted to be more than twice the > size of work_mem, then just move straight to the external sort algorithm > and set the work_mem down at the lower limit? Have you actually read the sort code? During the run-forming phase it's definitely useful to eat all the memory you can: that translates directly to longer initial runs and hence fewer merge passes. During the run-merging phase it's possible that using less memory would not hurt performance any, but as already stated, I don't think it will actually end up cutting the backend's memory footprint --- the sbrk point will be established during the run forming phase and it's unlikely to move back much until transaction end. Also, if I recall the development of that code correctly, the reason for using more than minimum memory during the merge phase is that writing or reading lots of tuples at once improves sequentiality of access to the temp files. So I'm not sure that cutting down the memory wouldn't hurt performance. regards, tom lane