我刚刚运行了mysql explain来检查一个查询,我惊讶地发现它必须检查超过250000条记录才能对结果进行排序,但是我有where子句索引,无论mysql explain给出的是什么,我完全同意,因为添加了很多新行,所以如何排序这个问题.mysql表结构是
tableA is a forum where users can post the content
id userid created title
1 3 12232 xyz
2 etc...............我的mysql查询是
explain SELECT * from tableA where userid='2' order by created desc limit 3这个explain查询的输出是
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tableA ref userid userid 4 const 275216 Using where; Using temporary; Using filesort我担心的是如何将其减少到3-4,因为我只对显示三个结果感兴趣,但mysql在显示输出之前搜索了275216条记录。由于用户i 2在论坛上发布后已经创建了275216条记录,但是如何告诉mysql只查找特定数据,以便它可以从非常小的行集中搜索结果,我希望最多20-30行mysql应该搜索到服务器3行
发布于 2013-02-03 20:20:50
试试这个::
SELECT * from tableA FORCE INDEX (userid) where userid=2 order by created desc limit 3https://stackoverflow.com/questions/14672338
复制相似问题