去评论
dz插件网

mysql大数据量随机查询rand()优化

迪巴拉
2022/03/23 19:15:16
原语句: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;

速度飞快