Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 4A8679F9FDA for ; Tue, 5 Dec 2006 13:36:58 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-new, port 10024) with ESMTP id 66553-06 for ; Tue, 5 Dec 2006 13:36:57 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from exprod6og55.obsmtp.com (exprod6og55.obsmtp.com [64.18.1.191]) by postgresql.org (Postfix) with SMTP id 3AE899FA2CB for ; Tue, 5 Dec 2006 13:36:56 -0400 (AST) Received: from source ([63.240.6.46]) by exprod6ob55.postini.com ([64.18.5.12]) with SMTP; Tue, 05 Dec 2006 09:36:53 PST Received: from 172.16.1.114 by mail.mi8.com with ESMTP (- Welcome to Mi8 Corporation www.Mi8.com (D2)); Tue, 05 Dec 2006 12:36:46 -0500 X-Server-Uuid: 7829E76E-BB9E-4995-8473-3C0929DF7DD1 Received: from MI8NYCMAIL08.Mi8.com ([172.16.1.164]) by d01smtp07.Mi8.com with Microsoft SMTPSVC(6.0.3790.1830); Tue, 5 Dec 2006 12:36:46 -0500 Received: from 69.181.100.71 ([69.181.100.71]) by MI8NYCMAIL08.Mi8.com ( [172.16.1.190]) via Exchange Front-End Server mi8owa.mi8.com ( [172.16.1.106]) with Microsoft Exchange Server HTTP-DAV ; Tue, 5 Dec 2006 17:36:45 +0000 User-Agent: Microsoft-Entourage/11.2.5.060620 Date: Tue, 05 Dec 2006 09:36:44 -0800 Subject: Re: Performance of ORDER BY From: "Luke Lonergan" To: "Glenn Sullivan" , pgsql-performance@postgresql.org Message-ID: Thread-Topic: [PERFORM] Performance of ORDER BY Thread-Index: AccYk+5DLJOTRoSHEduIcAAWy4o9DA== In-Reply-To: <4575A863.6040504@varianinc.com> MIME-Version: 1.0 X-OriginalArrivalTime: 05 Dec 2006 17:36:46.0013 (UTC) FILETIME=[EF7686D0:01C71893] X-WSS-ID: 696B71A41XK21954350-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/84 X-Sequence-Number: 22140 Glenn, On 12/5/06 9:12 AM, "Glenn Sullivan" wrote: > I am wanting some ideas about improving the performance of ORDER BY in > our use. I have a DB on the order of 500,000 rows and 50 columns. > The results are always sorted with ORDER BY. Sometimes, the users end up > with a search that matches most of the rows. In that case, I have a > LIMIT 5000 to keep the returned results under control. However, the > sorting seems to take 10-60 sec. If I do the same search without the > ORDER BY, it takes about a second. > > I am currently on version 8.0.1 on Windows XP using a Dell Optiplex 280 > with 1Gb of ram. I have set sort_mem=100000 set. > > Any ideas? Upgrade to 8.1 or 8.2, there were very large performance improvements to the sort code made for 8.1+. Also, when you've upgraded, you can experiment with increasing work_mem to get better performance. At some value of work_mem (probably > 32MB) you will reach a plateau of performance, probably 4-5 times faster than what you see with 8.0. - Luke