MySQL 进程使用超过 100% CPU 使用率,需要大约 1 GB 内存

发布于 2024-08-10 20:08:14 字数 1456 浏览 9 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

放肆 2024-08-17 20:08:14

查询中最重的部分是 SELECT:

Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer
Where UserID Between 1 and 5000
and CustomerID in (Select CustId from Cust_Details Where CustName like 'Mi%')

嵌套查询可能会为每一行重复。您可以检查此正在运行的 EXPLAIN PLAN + 所有 SELECT 查询。我猜想“like”运算符是针对非索引列使用的。在这种情况下(如“xyz%”),简单的索引可以显着提高性能。

[补充:此外,SELECT CustId ... 必须输出大于 5000 的 id,但根本不需要。 Cust_Details 上的复合索引(CustId、CustName)也一定很有用。]

尝试使用连接:

Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer c, Cust_Details cd
Where c.UserID Between 1 and 5000
and c.CustomerID=cd.CustId
and left(cd.CustName) = 'Mi'

The heaviest part in your query is the SELECT:

Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer
Where UserID Between 1 and 5000
and CustomerID in (Select CustId from Cust_Details Where CustName like 'Mi%')

The nested query probably is repeated for each row. You can check this running EXPLAIN PLAN + all the SELECT query. I guess the 'like' operator is used against a non-indexed column. In this case (like 'xyz%') a simple index can improve performance a lot.

[Added: moreover, SELECT CustId ... must output id's that are greater than 5000, that aren't needed at all. A composite index (CustId, CustName) on Cust_Details must also be useful.]

Try usign a join instead:

Select FirstName, LastName, CountryID, Address, Phone
From Test2.Customer c, Cust_Details cd
Where c.UserID Between 1 and 5000
and c.CustomerID=cd.CustId
and left(cd.CustName) = 'Mi'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文