|
Joined: Feb 2001
Posts: 2,268
Junior Member
|
Junior Member
Joined: Feb 2001
Posts: 2,268 |
Here's my question: Does the order that you chose for your databs query make a difference? Example: I have this query: $query = "<br />SELECT t1.B_Number,t1.B_Posted,t1.B_Last_Post,t1.B_Subject,t1.B_Body,t1.B_Main,t1.B_Replies,t1.B_Counter,t2.U_Username,t2.U_Picture,t2.U_PicWidth,t2.U_PicHeight<br />FROM {$config['tbprefix']}Posts AS t1,<br />{$config['tbprefix']}Users AS t2<br />WHERE t1.B_Number = t1.B_Main<br />AND t1.B_Board = '$Newsboard_q'<br />AND t1.B_Approved = 'yes'<br />AND t1.B_PosterId = t2.U_Number<br />AND t1.B_Posted >= '$time'<br />ORDER BY t1.B_Posted DESC<br />"; The first thing I'm looking for is the first post in a thread, but the second line drills down to the posts from a single board. Would it make more sense / be fasted if the board was listed first, then go for the first post. Or does MySQL look at the query as a whole so that the order of the query doesn't matter?...
|
|
|
|
Joined: May 1999
Posts: 3,039
Guru
|
Guru
Joined: May 1999
Posts: 3,039 |
The main speed difference depends on if mysql can use an index for a query and how many rows that index forces it to scan.
The best thing you can do is take the actual query that is executed (after the code is compiled) and then add EXPLAIN to the front of it. That will tell you what indexes it could possibly use, what index it actually used, how many rows it had to scan, if it had to create a temporary table, etc. Lots of valuable information to optimize your queries.
UBB.threads Developer
|
|
|
|
Joined: Feb 2001
Posts: 2,268
Junior Member
|
Junior Member
Joined: Feb 2001
Posts: 2,268 |
Thanks for the reply Scream! After re-reading my initial post I'm stunned anyone could give me an answer -must have more coffee...
|
|
|
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
|
|
Posts: 449
Joined: February 2008
|
|
Forums63
Topics37,573
Posts293,925
Members13,849
|
Most Online5,166 Sep 15th, 2019
|
|
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
|
|
|
|