Page 1 of 1

Loading Slow

Posted: Thu Mar 25, 2010 2:44 pm
by rklockner
I have a query that is used to create a dropdown, which returns roughly 4,000 rows (I am only pulling 3 fields back). The query itself runs in about .5 seconds, but when run on the page, it adds 20-25 seconds to the page load time.

Code: Select all

 
SELECT leadid, firstname, lastname 
FROM lead 
LEFT JOIN user_partner ON user_partner.userid = lead.affiliateid AND (user_partner.userid = '9' OR user_partner.userid = '12')
GROUP BY leadid
ORDER BY lastname
 
NOTE: I have also tried putting "(user_partner.userid = '9' OR user_partner.userid = '12')" as part of the WHERE clause, I also tried "FROM lead, user_partner" instead of a LEFT JOIN... They all seem to have the same load time (give or take 5 econds).

This query should not take that long to load (I don't think), so I guess I am looking for some tips/general knowledge that I may be missing.

Bonus Question: Would storing the results in a session variable be a bad idea? That way, the data is called once, then doesn't need to be called again.

Re: Loading Slow

Posted: Thu Mar 25, 2010 5:20 pm
by pickle
Sure the query is running in 0.5 seconds, but you also need to iterate through that list to generate HTML to display. Your browser also needs to render that HTML to the screen. I bet if you take all the query processing stuff out of your script, you'll see a drastic page load time decrease.

What can you do to speed it up? Other than checking your code to make sure you're not doing anything on each iteration that you only need to do once, the only thing you really can do is add pagination.