gpt4 book ai didi

mysql 确定查询的哪一部分最慢

转载 作者:行者123 更新时间:2023-11-29 02:20:16 24 4
gpt4 key购买 nike

我在 mySQL 中写了一个 select 语句。持续时间为 50 秒,抓取时间为 206 秒。这是一个很长的时间。我想了解我的查询的哪些部分效率低下,因此我可以改进它的运行时间,但我不确定如何在 mySQL 中做到这一点。

我的表有超过 1,000,000 条记录。我也有一个内置索引:

KEY `idKey` (`id`,`name`),

这是我的查询:

SELECT name, id, alt_id, count(id), min(cost), avg(resale), code from
history where name like "%brian%" group by id;

我查看了 mySQL 执行计划,但我无法从中找出问题所在:

enter image description here

如果我突出显示图像的“全索引扫描”部分,我会看到:

Access Type: Index
Full Index Scan
Key/Index:
Used Key Parts: id, name
Possible Keys: idKey, id-Key, nameKey
Attach Condition:
(`allhistory`.`history`.`name` LIKE '%brian%')

Rows Examined Per Scan: 1098181
Rows Produced Per Join: 1098181
Filter: 100%

我知道我可以通过在查询中添加 LIMIT 100 来扫描较小的数据子集,虽然它可以使时间更短,(28 秒持续时间,0.000 秒获取,) 我还想查看所有记录 - 所以我真的不想对其设置限制。

是否有人对此主题有更多的了解,可以建议我的查询、索引或方法在哪些方面可能对我要完成的任务效率低下?

最佳答案

此题仅在mysql全文搜索功能中有解

我不认为使用 like 是可行的解决方案。表扫描不是具有数百万行的解决方案。

我在这个 link 中写了一个答案,我希望你能通过引用和快速浏览找到适合你的可行解决方案。

这是 Full Text Search 上的 Mysql 手册页之一.

关于mysql 确定查询的哪一部分最慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33155007/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com