Re: A Costly function + LIMIT

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: cgg007(at)yahoo(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: A Costly function + LIMIT
Date: 2002-12-13 18:20:49
Message-ID: 6048.1039803649@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Chris Gamache <cgg007(at)yahoo(dot)com> 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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jie Liang 2002-12-13 18:33:16 Re: server terminated by a query in 7.3
Previous Message Chris Gamache 2002-12-13 18:14:35 A Costly function + LIMIT