mysql大数据量随机查询rand()优化
原语句:select id from table order by rand() limit n;
优化后语句:select id from table t1 join (select round(rand()*(select max(id) from table)) as idd) as t2 on t1.id>t2.idd limit n;
速度飞快
优化后语句:select id from table t1 join (select round(rand()*(select max(id) from table)) as idd) as t2 on t1.id>t2.idd limit n;
速度飞快