select * from xxx order by rand() limit 1000
执行速度:0.444315
select * from xxxx where fid >= (select floor(rand() * ((select MAX(fid) from xxxx)-(select MIN(fid) from xxxx))+(select MIN(fid) from xxxx))) order by fid limit 1000
执行速度:0.049867
SELECT * FROM `xxxx` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(fid) FROM `xxxx`)-(SELECT MIN(fid) FROM `xxxx`))+(SELECT MIN(fid) FROM `xxxx`)) AS fid) AS t2 WHERE t1.fid >= t2.fid ORDER BY t1.fid LIMIT 1000
为何表面上看似更多次的查询却带来了更快的查询速度
谁能解释一下Behold·I send you forth as sheep in the midst of wolves·《马太福音》·10·16
帖子134 精华2 积分391 阅读权限100 性别男 来自辽宁 上海 在线时间175 小时 注册时间2005-5-21 最后登录2008-7-16 查看个人网站 查看详细资料引用报告回复 TOP