Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 287759FB2AE for ; Tue, 5 Dec 2006 14:02:26 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 50180-04 for ; Tue, 5 Dec 2006 14:02:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id DDDD99FB2A5 for ; Tue, 5 Dec 2006 14:02:07 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id kB5I26mG007091; Tue, 5 Dec 2006 13:02:07 -0500 (EST) To: Glenn Sullivan cc: pgsql-performance@postgresql.org Subject: Re: Performance of ORDER BY In-reply-to: <4575A863.6040504@varianinc.com> References: <4575A863.6040504@varianinc.com> Comments: In-reply-to Glenn Sullivan message dated "Tue, 05 Dec 2006 10:12:03 -0700" Date: Tue, 05 Dec 2006 13:02:06 -0500 Message-ID: <7090.1165341726@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200612/86 X-Sequence-Number: 22142 Glenn Sullivan writes: > 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. Does the ORDER BY match an index? If so, is it using the index? (See EXPLAIN.) > 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. In 8.0 that might be counterproductively high --- we have seen cases where more sort_mem = slower with the older sorting code. I concur with Luke's advice that you should update to 8.2 (not 8.1) to get the improved sorting code. regards, tom lane