MySQL选择计数(1)语句在桌上太慢,数百万行
以下语句需要0.73秒,并产生54,000个结果:
SELECT COUNT(1) FROM `table` WHERE MATCH(tagline, location, country) AGAINST(' +Germany' IN BOOLEAN MODE)
此说明需要28秒,并产生33万秒的结果:
SELECT COUNT(1) FROM `table` WHERE MATCH(tagline, location, country) AGAINST(' +United +States' IN BOOLEAN MODE)
有没有办法通过以某种方式将结果限制为一百万?
这样的事情:
COUNT THIS -->
SELECT * FROM `table` WHERE MATCH(tagline, location, country) AGAINST(' +United +States' IN BOOLEAN MODE)
LIMIT 1000000
The following statement takes 0.73 seconds and generates 54,000 results:
SELECT COUNT(1) FROM `table` WHERE MATCH(tagline, location, country) AGAINST(' +Germany' IN BOOLEAN MODE)
This statement takes 28 seconds and generates 3.3 millions results:
SELECT COUNT(1) FROM `table` WHERE MATCH(tagline, location, country) AGAINST(' +United +States' IN BOOLEAN MODE)
Is there a way to limit the query time by somehow capping the results at one million?
Something like this:
COUNT THIS -->
SELECT * FROM `table` WHERE MATCH(tagline, location, country) AGAINST(' +United +States' IN BOOLEAN MODE)
LIMIT 1000000
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答我自己的问题:
将您的选择查询包裹在此:
我的选择查询对此进行了更改,以便结果可以受到限制:
将两个问题放在一起:
“德国” - > 54,000个结果(0.76秒)
“美国” ---> “超过一百万的结果”(2.4秒)
Answering my own question:
Wrap your select query in this:
My select query is altered to this so that results can be limited:
Put this two together:
"Germany" --> 54,000 results (0.76 seconds)
"United States" ---> "More than one million results" (2.4 seconds)
您应该运行解释计划并找到效率低下。您可以在本文中查看如何分析解释平原:
https://dev.mysql.com/doc/refman/8.0/en/execution-plan-information.html
要点:
根据您的SQL,您使用MySQL似乎是您的。
最终结果可能是添加索引。本文应有助于创建您的索引:
https://www.tutorialspoint.com/mysql.com/mysql /mysql-indexes.htm
关键点:
在tutorials_tbl(tutorial_author desc)上创建索引fure_index
You should run explain plan and find your inefficiencies. You can see how to analyze explain plain at this article:
https://dev.mysql.com/doc/refman/8.0/en/execution-plan-information.html
Key points:
Based on your SQL it appears your using MySQL.
The end result might be to add indexes. This article should help to create your indexes:
https://www.tutorialspoint.com/mysql/mysql-indexes.htm
Key Points:
CREATE INDEX AUTHOR_INDEX ON tutorials_tbl (tutorial_author DESC)