If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > What's Wrong With This Query?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-21-05, 14:02
kirkja08 kirkja08 is offline
Registered User
 
Join Date: Jan 2005
Posts: 1
What's Wrong With This Query?

Anyone know why this query is so slow? It the nature of a left join just slow? Any suggestions on how to write it better? Thanks in advance for the help.

NOTES: All tables have a unique, auto-incremented, primary key.


SELECT res_id, resumes.location_id, locations.location_id, locations.location_name, resumes.priority, users.first_name, users.last_name, DATE_FORMAT(`posted_date`, '%m.%d.%y') AS posted_date, resumes.job_title, resumes.experience
FROM resumes, users
LEFT JOIN locations ON resumes.location_id = locations.location_id
WHERE locations.location_name LIKE 'US' and resumes.keywords LIKE '%assistant%' and users.username = resumes.username
ORDER BY resumes.priority, posted_date DESC
LIMIT $from, $max_results
Reply With Quote
  #2 (permalink)  
Old 01-21-05, 21:48
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Code:
select res_id
     , resumes.location_id
     , locations.location_id
     , locations.location_name
     , resumes.priority
     , users.first_name
     , users.last_name
     , DATE_FORMAT(posted_date
                 , '%m.%d.%y') AS posted_date
     , resumes.job_title
     , resumes.experience 
  from resumes
inner
  join users
    on resumes.username
     = users.username 
left outer
  join locations 
    on resumes.location_id 
     = locations.location_id
   and locations.location_name = 'US' 
 where resumes.keywords LIKE '%assistant%' 
order 
    by resumes.priority
     , posted_date DESC
limit $from
     , $max_results
make sure you have indexes on resumes.username, users.username, resumes.location_id, locations.location_id, and locations.location_name

an index on resumes.keyword may not help because of the way you're searching it

but at least the joins will be efficient
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On