Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9871B4770BD for ; Fri, 13 Dec 2002 13:21:48 -0500 (EST) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by postgresql.org (Postfix) with ESMTP id 6064547703D for ; Fri, 13 Dec 2002 13:20:50 -0500 (EST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.6/8.12.6) with ESMTP id gBDIKopd006049; Fri, 13 Dec 2002 13:20:50 -0500 (EST) To: cgg007@yahoo.com Cc: pgsql-sql@postgresql.org Subject: Re: A Costly function + LIMIT In-reply-to: <20021213181435.31771.qmail@web13804.mail.yahoo.com> References: <20021213181435.31771.qmail@web13804.mail.yahoo.com> Comments: In-reply-to Chris Gamache message dated "Fri, 13 Dec 2002 10:14:35 -0800" Date: Fri, 13 Dec 2002 13:20:49 -0500 Message-ID: <6048.1039803649@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/182 X-Sequence-Number: 10770 Chris Gamache writes: > It runs "widget" on 10000 records. The damage would be negligible if it could > run on the 100... So do the function calculation outside the UNION/ORDER BY. SELECT name, address, city, state, zip, widget(name, address, city, state, zip) FROM ((SELECT * FROM eastern_usa ORDER BY state, city, zip, name LIMIT 5000 UNION ALL SELECT * FROM western_usa ORDER BY state, city, zip, name LIMIT 5000) ORDER BY 4, 3, 5, 1 LIMIT 100 OFFSET 0) ss; You might have to fool with the parenthesization a little to get it to parse ... regards, tom lane