Unix Technical Forum

Re: slow query using sub select

This is a discussion on Re: slow query using sub select within the Pgsql Performance forums, part of the PostgreSQL category; --> that worked like a champ nice call as always! thanks Tim Jones Healthcare Project Manager Optio Software, Inc. (770) ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Performance

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 08:50 AM
Tim Jones
 
Posts: n/a
Default Re: slow query using sub select

that worked like a champ nice call as always!

thanks

Tim Jones
Healthcare Project Manager
Optio Software, Inc.
(770) 576-3555

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Monday, May 22, 2006 7:07 PM
To: Tim Jones
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] slow query using sub select

"Tim Jones" <TJones@optio.com> writes:
> I am having a problem with a sub select query being kinda slow. The


> query is as follows:


> select batterycode, batterydescription, observationdate from Battery
> t1 where patientidentifier=611802158 and observationdate = (select
> max(observationdate) from Battery t2 where
> t2.batterycode=t1.batterycode and patientidentifier=611802158) order

by batterydescription.

Yeah, this is essentially impossible for the planner to optimize,
because it doesn't see any way to de-correlate the subselect, so it does
it over again for every row. You might find it works better if you cast
the thing as a SELECT DISTINCT ON problem (look at the "weather report"
example in the SELECT reference page).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com