SELECT t1...."> SELECT t1....">
 
Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Feb 2001
Posts: 2,268
Junior Member
Junior Member
Offline
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:

Code
 $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?...

Sponsored Links
Joined: May 1999
Posts: 3,039
Guru
Guru
Offline
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
Offline
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...


Link Copied to Clipboard
Donate Today!
Donate via PayPal

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.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Nettomo
Nettomo
Germany, Bremen
Posts: 417
Joined: November 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)