Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Today's Posts

 
 
Thread Tools Search this Thread Rating: Thread Rating: 1 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
Old 2008-08-22, 01:16 PM   #6
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
It boils down to performance really. No matter what, when you do order by rand(), you force mysql to create a temporary file with all of the results and order it. If your query is well indexed, and you have 15 results, its not a big deal. order by rand() can never be optimized, so, can never take advantage of the mysql query cache. What's worse is getting 2300 results and doing order by rand() limit 10. Coupled with select * and a join and you've got the makings of half of the "professional" scripts out there.

select * is bad for a few reasons. First, you probably don't need every field returned, and if someone later alters that table to add a text field or other unneeded data for its current use, you are buffering it and retrieving that data regardless. If you structure your data in a particular way, you could actually never touch the mysql data file and get your results from the mysql index file. Second, when you do select *, from a code maintenance standpoint you don't immediately know what the variables are that are present in the table forcing you to keep a copy of the database schema handy.

For small quick projects, these things seem like overkill, but, when you come back in 6 months to fix something or add a new feature, you'll end up saving time.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:57 AM.


Mark Read
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc