View Full Version : Reducing the number of queries
Coding a hack and was pretty shocked to see a
Executed 35 queries
at the base of the page ( in debug mode ).
And the functonality is merely at a quater of what I expect the final page to be showing....
That's rather high ain't it, for a simple listing page.
How can one go about reducing the number of queries ?
Even outputting the base template ( WITH NO CODE ), just evaluating the nav bar, gives me 5 queries.
Am i missing something here ?
Paul M
01-03-2005, 11:28 AM
It would be impossible to answer your question without seeing your code, but I notice a lot of people worry too much about sql queries. Most queries run in a few milliseconds or less and most peoples mysql is spending 80%+ of it's time doing nothing.
If you have access to you server, view the mysql processlist (or install mytop) and see what your mysql is doing - the chances are that most of the time you won't see much listed as the queries are running too fast to be caught and displayed.
Dean C
01-03-2005, 11:48 AM
Chances are you have a query loop in there. Between 10-20 queries on one page is more or less an average, but chances are there are more efficient ways of doing things if you have 35 :)
As Paul said, if you show us the code maybe we can help out a little.
Xenon
01-03-2005, 12:03 PM
Also often custom hacks forget to add created templates to the template cache, so each template will produce one extra query...
Yep Stefan, I make sure all the templates called are in the template cache ( cos the queries count warns me if otherwise :D ).
Ok, perhaps I shall post the hack when fully functional, and then concentrate on query optimizations.
Gotta admit while it is looking good, the queries are rather messy.....and loop-y (Dean, you're right :p)
p.s query count now stands at 42 ... argh
AN-net
01-03-2005, 04:39 PM
Yep Stefan, I make sure all the templates called are in the template cache ( cos the queries count warns me if otherwise :D ).
Ok, perhaps I shall post the hack when fully functional, and then concentrate on query optimizations.
Gotta admit while it is looking good, the queries are rather messy.....and loop-y (Dean, you're right :p)
p.s query count now stands at 42 ... argh
possible to combine queries together?
possible to combine queries together?
I'd rather have 3 fast queries than a big slow one.. But it depends on the query, so i can't really argue with you.
Xenon
01-03-2005, 09:14 PM
the most important: clean out that loop ^^
AN-net
01-03-2005, 09:55 PM
I'd rather have 3 fast queries than a big slow one.. But it depends on the query, so i can't really argue with you.
of course but for 35 queries some must be able to be combined:)
I think it is very possible but due to my limited knowledge, I would need help from you folks.
Will start a new thread in the near future with the code specifics for you folks to help me out :D
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.