Results 1 to 5 of 5
-
27th Aug 2009, 09:47 AM #1OPRespected DeveloperWebsite's:
X4B.org[PHP] alternative to ORDER BY RAND() on large tables
Never run ORDER BY statements on large tables (e.g 4M tables).
Heres some code that will work as an alternative in most cases.
PHP Code:$resv = mysql_query('SELECT COUNT(*) FROM v3links');
$row = mysql_fetch_row($resv);
$sval = rand(0,$row[0]-15001);
$query=mysql_query("SELECT `id`,`fileid`,`type`, `filename` FROM `v3links` LIMIT ".$sval.",15000");
SplitIce Reviewed by SplitIce on . [PHP] alternative to ORDER BY RAND() on large tables Never run ORDER BY statements on large tables (e.g 4M tables). Heres some code that will work as an alternative in most cases. $resv = mysql_query('SELECT COUNT(*) FROM v3links'); $row = mysql_fetch_row($resv); $sval = rand(0,$row-15001); $query=mysql_query("SELECT `id`,`fileid`,`type`, `filename` FROM `v3links` LIMIT ".$sval.",15000"); Rating: 5
-
29th Aug 2009, 04:45 PM #2MemberWebsite's:
zomgbbqpizza.com evilddl.com scenemarket.orgIm guessing this is faster than say:
Code:SELECT * FROM my_table ORDER BY RAND() LIMIT 1;
-
29th Aug 2009, 05:35 PM #3MemberWebsite's:
CodeSociety.netrand is very slow, so the more rows u add the slower it gets. rand on php is much faster
-
30th Aug 2009, 06:03 PM #4Member
$sval = rand(0,$row[0]-15001);
15001 isn't correct, what if you don't have 15001 counts ?
-
30th Aug 2009, 10:24 PM #5OPRespected DeveloperWebsite's:
X4B.org
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
How Should I Organize My SQL Tables?
By Robin Hood in forum Web Development AreaReplies: 7Last Post: 22nd Aug 2012, 03:54 PM -
Exporting tables from one to another [help req]
By xtone in forum Web Development AreaReplies: 6Last Post: 27th Sep 2011, 11:05 PM -
Help with PHP & Tables
By Sponge Bob in forum Webmaster DiscussionReplies: 14Last Post: 6th May 2011, 04:53 AM -
help me mysql tables are corupted
By awaisdik2003 in forum vBulletinReplies: 0Last Post: 21st Sep 2010, 12:38 PM -
IP tables warning..how to fix it
By lucy fox in forum Server ManagementReplies: 2Last Post: 22nd Apr 2010, 11:04 AM
themaCreator - create posts from...
Version 3.53 released. Open older version (or...