This query is against a MyISAM table:
SELECT * FROM table
WHERE link_id = 1 and counted = 1
Now, if I don't pass counted, it gets it really fast. When I pass counted to it, it just takes forever. It is a big table, but I don't see the reason why it should get stuck instead of just showing me an empty table.
有什么想法吗?
This query is against a MyISAM table:
SELECT * FROM table
WHERE link_id = 1 and counted = 1
Now, if I don't pass counted, it gets it really fast. When I pass counted to it, it just takes forever. It is a big table, but I don't see the reason why it should get stuck instead of just showing me an empty table.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Run this to see if you're table has proper indexes. Perhaps counted does not have an index?
(link_id, counted) 上的索引将使查询速度更快。
An index on (link_id, counted) will make that query fast.
这是因为它必须过滤每一行的
counted=1
。您是否在link_id
上设置了索引?如果是这样,您可以设置一个计数
It's because it has to filter
counted=1
through each and every row. Do you have an index set up onlink_id
? If so, you can set one up forcounted
我的猜测是你只是缺少一个索引。试试这个:
您是否在
column_name
字段中看到counted
?如果没有,那么您可能想要:
接下来我会看看
EXPLAIN
(Micah 解释了 此处)。 (我只建议解释第二个,因为我的经验是,大多数情况下,如果查询很慢,问题只是缺少索引。)My guess is that you are simply missing an index. Try this:
Do you see
counted
in thecolumn_name
field?If not, then you probably want to:
I would next look to
EXPLAIN
(which Micah explains here). (I only suggest explain second because my experience is that the majority of the time the problem is simply a missing index if a query is slow.)