Loading Slow

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
rklockner
Forum Newbie
Posts: 22
Joined: Tue Feb 09, 2010 9:56 am

Loading Slow

Post 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.
Last edited by Benjamin on Thu Mar 25, 2010 6:05 pm, edited 1 time in total.
Reason: Added [code=sql] tags.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Loading Slow

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply