Which RAND() method works FASTEST in MYSQL
Posted: Fri Jun 06, 2008 9:20 am
Hi guys as we all know in MYSQL is SLOOOW method if we got huge database.
Which solution you think is best to use as fastest method:
Method 1:
Method 2:
or to use something else perhaps? 
Code: Select all
ORDER BY RAND()Which solution you think is best to use as fastest method:
Method 1:
Code: Select all
$db->query("SELECT id, title, date, alt_name, short_story, rating, news_read FROM " . PREFIX . "_post WHERE approve='$conf[allow_index_metka]' AND category regexp '[[:<:]]($conf[cat_num_1])[[:>:]]' AND id >= (SELECT MIN(id) + ROUND( ( MAX(id)-MIN(id) ) * RAND() ) FROM " . PREFIX . "_post ) ORDER BY id LIMIT 4");Code: Select all
$db->query("SELECT id, title, date, alt_name, short_story, rating, news_read FROM " . PREFIX . "_post WHERE approve='$conf[allow_index_metka]' AND category regexp '[[:<:]]($conf[cat_num_1])[[:>:]]' AND id >= (SELECT FLOOR( MAX(id) * RAND()) FROM " . PREFIX . "_post ) ORDER BY id LIMIT 4");

