gpt4 book ai didi

MySQL慢查询不规律地飙升

转载 作者:行者123 更新时间:2023-11-29 21:36:40 25 4
gpt4 key购买 nike

我正在使用 MySQL 运行移动服务。

通常会有一些慢日志。 (小于 0.5/秒)但有时它会在短时间内变得如此之高。 (超过 6 次/秒)

enter image description here

我检查了慢查询日志,它们不是特定的查询,而是我的所有查询。所以我猜这可能是锁定问题,但在慢查询日志中只有“query_time”,“lock_time”始终为0。

我检查了服务器状态,但没有什么特别的。

现在我连头绪都没有了。我应该先看什么?

最佳答案

尝试查看标记为慢的查询。使用联接、where 和组语句中的列在查询中相关的所有表中创建索引。

示例

Select 
a.name,
count(*) as trans_count,
sum(b.trans_value) as trans_tot_value
From
tbl_customer a inner join
tbl_orders b
on a.customer_id = b.customer_id
Where
a.city ='jakarta'
and b.date = today()
Group by a.name

那么你应该创建索引

  1. tbl_customer 上的 Idx_customer_id 由 customer_id 列组成。
  2. tbl_orders 上的 Idx_customer_id 由 customer_id 列组成。
  3. tbl_customer 上的 Idx_city 由城市列组成。
  4. tbl_orders 上的 Idx_trans_date 由日期列组成。
  5. tbl_customer 上的 Idx_customer_name 由客户名​​称列组成。

分析表上使用的查询和索引有助于提高性能。

关于MySQL慢查询不规律地飙升,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34869489/

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