【发布时间】:2015-08-25 13:02:59
【问题描述】:
我的查询很简单
SELECT id,url,submitted FROM links where submit_after<CURDATE() and submitted<4 order by ord limit 1438;
表 links 有 10 000 000 行和索引提交,submit_after,ord。 ord 字段经常变化,因为它被用作随机字段来获取总是随机的行。查询的限制也是 rand(1000,4000)。查询需要 10 秒才能执行
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE links index submitted,submit_after ord 4 NULL 3849 Using where
对如何获得更好的性能有什么建议吗?
【问题讨论】:
-
你试过
order by RAND()吗? -
使用 rand() 是一个糟糕的选择,请参阅stackoverflow.com/questions/4329396/…
-
rand() 正在杀死 10m 行的 mysql
-
不下单需要多少时间?
-
考虑创建一个预先计算好的随机数表,该表有一个滑动窗口,仅供一次性使用,由一个单独的进程启动/重新刷新,而不是它的使用者
标签: mysql