发布于 2024-12-02 16:24:50 字数 378 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

往事随风而去 2024-12-09 16:24:50
EXPLAIN SELECT * FROM table WHERE link_id = 1 and counted = 1

Run this to see if you're table has proper indexes. Perhaps counted does not have an index?

EXPLAIN SELECT * FROM table WHERE link_id = 1 and counted = 1
无声静候 2024-12-09 16:24:50

(link_id, counted) 上的索引将使查询速度更快。

An index on (link_id, counted) will make that query fast.

过潦 2024-12-09 16:24:50

这是因为它必须过滤每一行的 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 on link_id? If so, you can set one up for counted

机场等船 2024-12-09 16:24:50

我的猜测是你只是缺少一个索引。试试这个:

SHOW INDEXES FROM <your table name>

您是否在 column_name 字段中看到 counted

如果没有,那么您可能想要:

CREATE INDEX <nifty index name> ON <your table name> (counted);

接下来我会看看 EXPLAIN (Micah 解释了 此处)。 (我只建议解释第二个,因为我的经验是,大多数情况下,如果查询很慢,问题只是缺少索引。)

My guess is that you are simply missing an index. Try this:

SHOW INDEXES FROM <your table name>

Do you see counted in the column_name field?

If not, then you probably want to:

CREATE INDEX <nifty index name> ON <your table name> (counted);

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文