Greenguy's Board


Go Back   Greenguy's Board > Programming & Scripting
Register FAQ Calendar Search Today's Posts Mark Forums Read

 
 
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, 02:20 PM   #8
cd34
a.k.a. Sparky
 
cd34's Avatar
 
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
no question that it is better to do order by rand() limit 10 than to take 2300 results and do a shuffle/array_slice. Its also better do select the 2-3 fields you need rather than select * if you're going to do an order by rand() since mysql will have to create a temporary table to contain the results before doing the order. If you had to do an order by rand() on 2300 results, its possible a subquery would handle the results a little faster if structured properly. I don't know as I haven't tested it, but, knowing how the query optimizer works with indexing, I can see some potential for it being a little quicker.

It also depends on how often you do that query. Does the page need to be generated each time the page is loaded? I've seen linklists that generate the page on every pageview where the results only change once a day or after reviews are done. Its all about handing the page to the surfer as quickly as possible, and, each time you do an SQL query, you slow down page generation a fraction and have the potential for losing your customer.

order by rand() just has so much potential for abuse -- that's why I dislike it.
__________________
SnapReplay.com a different way to share photos - iPhone & Android
cd34 is offline   Reply With Quote
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 01:16 AM.


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