The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
"Heavy" queries
How do you know whether a query in your code is too heavy for the server?
What are the criteria? |
#2
|
||||
|
||||
If you enable debug mode on your board you can see the types of queries being performed, how long they take to execute, and the amount of memory exhausted in executing them.
|
#3
|
|||
|
|||
Yes but that would depend on my server ...right?
A hack will be installed in different systems, so I was wondering if there are any "general rules". For instance a "SELECT * FROM ..." would be bad if the table had too many records? If the query returned too many records? And if so, how many records would be considered "a lot"? |
#4
|
||||
|
||||
Really depends on the server.
|
#5
|
||||
|
||||
A few tips...
|
#6
|
|||
|
|||
SirAdrian, if I do need all fields (exept one perhaps) why shouldn't I use SELECT *?
Also, is there a case that 2 queries are better than one? Because currently I try just to limit the number of queries and I'm not sure I'm doing the right thing... |
#7
|
||||
|
||||
Because it uses a bit more overhead, and it's bad practice because you aren't clearly defining what you are reading from the database. It's similar to using the highest error reporting... you have way more control of what is going on, and you will spot any funny business much faster.
As for the # of queries... while this generally doesn't matter (generally, but i have worked on a site where one query * 5000 active users makes a HUGE difference!) it is good to combine them when there is a relationship between the data from the two queries. The most common is the use of joins to get results from different tables (ex: post + user table). I would have to say this depends greatly on the query. Sometimes two queries is faster if the relationship isn't a good one, which goes back to my normalization comment. Some common improvements you can make: Code:
SELECT * FROM messages LIMIT 10; Code:
SELECT id, body, dateline FROM messages WHERE dateline >= X ORDER BY dateline DESC LIMIT 10 Code:
SELECT * FROM messages WHERE id = 5; Code:
SELECT * FROM user WHERE userid = $message[userid]; Code:
SELECT messages.id, messages.body, messages.dateline, messages.userid, user.username FROM messages LEFT JOIN user USING (userid) WHERE messages.id = 5; |
#8
|
|||
|
|||
Oh, no matter what I've read about these evil JOINS I was never able to understand how they work It's perhaps the only thing that I had such great difficulty understanding it
|
#9
|
||||
|
||||
The EXPLAIN data provides a lot of useful information and can help you in optimizing your queries.
The key is to learn how to interpret the EXPLAIN data. TIP: When creating any modification, query, etc, you should always build for large sites. This will help reduce problems and/or inquiries during the cycle of your modification. "Testing" your modification on a small test site does not help .. your test site should have MANY members, MANY posts, MANY x rows so that you can actually see how effective your queries are. Yes, it does help if you have access to a Big Board. You can always create a script that will add fake members, fake posts, fake x etc for testing purposes. Quote:
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|