pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
A Costly function + LIMIT
2+ messages / 2 participants
[nested] [flat]

* A Costly function + LIMIT
@ 2002-12-13 18:14  Chris Gamache <cgg007@yahoo.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Chris Gamache @ 2002-12-13 18:14 UTC (permalink / raw)
  To: pgsql-sql

PostgreSQL 7.2.3

I have a function that is quite costly to run on 1000's of records... Let's
call it "widget". 

I have a query

(SELECT name, address, city, state, zip, widget(name, address, city, state,
zip) 
FROM eastern_usa 
ORDER BY state, city, zip, name 
LIMIT 5000)

UNION ALL

(SELECT name, address, city, state, zip, widget(name, address, city, state,
zip) 
FROM western_usa 
ORDER BY state, city, zip, name 
LIMIT 5000)

ORDER BY 4, 3, 5, 1 LIMIT 100 OFFSET 0;

It runs "widget" on 10000 records. The damage would be negligible if it could
run on the 100... 

Any ideas?

CG

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: A Costly function + LIMIT
@ 2002-12-13 18:20  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Chris Gamache <cgg007@yahoo.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2002-12-13 18:20 UTC (permalink / raw)
  To: cgg007@yahoo.com; +Cc: pgsql-sql

Chris Gamache <cgg007@yahoo.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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-12-13 18:20 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-12-13 18:14 A Costly function + LIMIT Chris Gamache <cgg007@yahoo.com>
2002-12-13 18:20 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox