Activity Stream
48,167 MEMBERS
64899 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 5 of 5
  1.     
    #1
    Respected Developer
    Website's:
    X4B.org

    Default [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"); 
    enjoy.
    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

  2.   Sponsored Links

  3.     
    #2
    Member
    Website's:
    zomgbbqpizza.com evilddl.com scenemarket.org
    Im guessing this is faster than say:
    Code: 
    SELECT * FROM my_table ORDER BY RAND() LIMIT 1;
    ??

  4.     
    #3
    Member
    Website's:
    CodeSociety.net
    rand is very slow, so the more rows u add the slower it gets. rand on php is much faster



  5.     
    #4
    Member
    $sval = rand(0,$row[0]-15001);
    15001 isn't correct, what if you don't have 15001 counts ?

  6.     
    #5
    Respected Developer
    Website's:
    X4B.org
    Lol i said large table i.e 5m rows like me. I got a new version at home

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How Should I Organize My SQL Tables?
    By Robin Hood in forum Web Development Area
    Replies: 7
    Last Post: 22nd Aug 2012, 03:54 PM
  2. Exporting tables from one to another [help req]
    By xtone in forum Web Development Area
    Replies: 6
    Last Post: 27th Sep 2011, 11:05 PM
  3. Help with PHP & Tables
    By Sponge Bob in forum Webmaster Discussion
    Replies: 14
    Last Post: 6th May 2011, 04:53 AM
  4. help me mysql tables are corupted
    By awaisdik2003 in forum vBulletin
    Replies: 0
    Last Post: 21st Sep 2010, 12:38 PM
  5. IP tables warning..how to fix it
    By lucy fox in forum Server Management
    Replies: 2
    Last Post: 22nd Apr 2010, 11:04 AM

Tags for this Thread

BE SOCIAL