| 指标 | 数值 |
|---|---|
| 统计区间 | 2026-11-05 00:00:00 ~ 23:59:59(Asia/Shanghai,UTC+8) |
| 环境 | staging |
| 慢日志总条数 | 5,622 |
| 慢查询累计耗时 | 60,093 s ≈ 16.7 小时 |
| 其中备份(user=backup)占比 | 14,084 s ≈ 3.9 小时(23.4%) |
| 非备份累计耗时 | 46,009 s ≈ 12.8 小时 |
| 涉及实例(server_name) | LAN_addcn_27、27_3307、37、40_3308、44、46、51、81、84 共 9 台 |
| 最突出问题 | aiworkflow 库(staging/8891)批量任务 SQL 全天累计 ≈7 小时,其中 21 条单条 35 分钟以上 |
| # | Query_time | Lock_time | Rows_examined | Rows_sent | 用户 | 库 | 实例(alias) | SQL 摘要 | 初步判定 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 3412.06s | 0.0004s | 66,081 | 0 | addcn8891_test | aiworkflow | staging/8891 | SELECT qa_hub_executionrun.* (29列含longtext) INNER JOIN core_testrequirement LEFT JOIN qa_hub_executionevidence LEFT JOIN qa_hub_executionevent … GROUP BY id LIMIT 60 | GROUP BY+大字段+等待(见分析 A) |
| 2 | 2971.47s | 0.0003s | 12,102 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上(同一指纹模式) | 同上 |
| 3 | 2957.00s | 0.0002s | 11,747 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上 | 同上 |
| 4 | 2889.79s | 0.0004s | 11,236 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上 | 同上 |
| 5 | 2889.60s | 0.0004s | 11,442 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上 | 同上 |
| 6 | 2845.64s | 0.0003s | 10,836 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上 | 同上 |
| 7 | 2732.51s | 0.0005s | 10,312 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上 | 同上 |
| 8 | 2616.20s | 0.0004s | 9,886 | 0 | addcn8891_test | aiworkflow | staging/8891 | 同上 | 同上 |
| 9 | 1900.68s | 0.0006s | 5,693,964 | 5,693,964 | backup | t8891 | staging/8891 | SELECT /*!40001 SQL_NO_CACHE */ * FROM t8891.t_item_modi_histories | 备份全表导出(569 万行) |
| 10 | 1393.91s | 0.0790s | 3,290,762 | 3,290,762 | backup | t8891 | staging/8891 | SELECT /*!40001 SQL_NO_CACHE */ * FROM t8891.t_sele_item_infos | 备份全表导出(329 万行) |
前 8 条为同一 SQL 指纹(Django ORM 生成的列表页聚合查询),全天共出现 21 次、累计 23,475s;单条扫描行数仅 1~6.6 万,Lock_time 微小但 rows_sent=0——不是索引问题,详见深度分析 A。
| # | 条数 | 平均耗时 | 最大耗时 | 累计耗时 | 用户 | 库 | SQL 指纹 | 标注 |
|---|---|---|---|---|---|---|---|---|
| 1 | 1,500 | 3.67s | 22.26s | 5,511s | addcn8891_test | aiworkflow | SELECT DISTINCT core_userprofile.* WHERE is_active=? AND role_types LIKE ? | 触发深析(B) |
| 2 | 1,079 | 3.65s | 13.79s | 3,939s | addcn8891_test | aiworkflow | SELECT qa_hub_designinput.* JOIN designmission LEFT JOIN designnode WHERE flow_id=? OR mission_id=? ORDER BY id | 触发深析(C) |
| 3 | 239 | 4.19s | 296.66s | 1,002s | log/sonic | 多库 | commit; | 实例 IO/刷盘压力信号 |
| 4 | 213 | 1.62s | 2.75s | 345s | jmysql | — | SHOW ENGINE INNODB STATUS; | 监控采集,本身是被压信号 |
| 5 | 183 | 4.05s | 252.51s | 741s | 多用户 | 多库 | COMMIT; | 实例 IO/长事务信号 |
| # | 条数 | 平均耗时 | 最大耗时 | 累计耗时 | 用户 | 库 | SQL 指纹 | 标注 |
|---|---|---|---|---|---|---|---|---|
| 1 | 21 | 1,117.89s | 23,475.7s(max 单条 3412s) | 23,475.7s | addcn8891_test | aiworkflow | SELECT executionrun 29列 + COUNT(DISTINCT evidence/event) 3表 JOIN GROUP BY id LIMIT ? | 触发深析(A) |
| 2 | 1,500 | 3.67s | 22.26s | 5,511.0s | addcn8891_test | aiworkflow | 同条数表 #1 | 触发深析(B) |
| 3 | 1,079 | 3.65s | 13.79s | 3,939.4s | addcn8891_test | aiworkflow | 同条数表 #2 | 触发深析(C) |
| 4 | 106 | 24.77s | 108.48s | 2,625.8s | addcn8891_test | aiworkflow | SELECT designartifact.* WHERE mission_id=? AND kind=? AND round=? ORDER BY id DESC LIMIT 1 | 触发深析(D) |
| 5 | 1 | 1,900.68s | 1,900.68s | 1,900.7s | backup | t8891 | SELECT * FROM t8891.t_item_modi_histories | 🗄️ 备份模式,不做深析 |
🗄️ 备份模式说明:user=backup 的 mysqldump 全表导出全天约 30 张表、累计 14,084s,集中在 01:00~02:15(如t_item_modi_histories1900s/569万行、t_sele_item_infos1394s/329万行、yahoo_car_details582s)。条数与单表耗时与日常备份量级一致,无明显环比异常,按口径不触发深度分析。
qa_hub_executionrun 三表 JOIN 聚合(21 条 / 累计 6.5 小时,Top1-8 全部是它)qa_hub_executionrun:PK(id),UNIQUE(user_id,request_id),KEY(requirement_id),KEY(state);29 列中含 source_snapshot/result 等 longtext 大字段。qa_hub_executionevidence:PK(id),UNIQUE(run_id,key)。qa_hub_executionevent:PK(id),UNIQUE(run_id,event_id),UNIQUE(run_id,sequence)。core_testrequirement:PK(id),KEY(user_id)。qa_hub_executionrun 走 qa_execution_request_unique(user_id)(ref,扫描 ~2 行),core_testrequirement eq_ref PK,两个 LEFT JOIN 子表均走 run_id 前缀索引;GROUP BY 出现 using_temporary_table: true, using_filesort: true,总 cost 仅 301。source_snapshot/result)进入 JOIN 与 GROUP BY,临时表落盘;rows_sent=0 说明结果未取回即超时/被杀;同时段该实例 GET_LOCK 平均等待 5.9s、COMMIT/SHOW ENGINE INNODB STATUS 集体变慢,指向实例级 IO 压力/长事务串行。source_snapshot、result 等),详情再按 id 回表取;或把大字段拆到独立附表。COUNT(DISTINCT evidence.id)/COUNT(DISTINCT event.id) 改为对两张子表各一条 GROUP BY run_id 的预聚合子查询,避免 JOIN 产生笛卡尔放大与临时表。requirement_id IN (子查询) 可改为先查 id 列表再 IN 常量列表。information_schema.innodb_trx),确认是否有 30 分钟级事务阻塞该查询的元数据锁。core_userprofile DISTINCT + JSON LIKE(1,500 条 / 累计 1.53 小时)access_type: ALL 全表扫描,但该表仅 ~22 行(AUTO_INCREMENT=26),cost 5.4,attached_condition 含 role_types LIKE '%"executive"%'(JSON 列 like)。qa_hub_designinput 三表 JOIN(1,079 条 / 累计 1.09 小时)qa_hub_designmission 走 requirement_id 索引(using_index),qa_hub_designnode 走 mission_id 索引,qa_hub_designinput 走 design_input_content_unique(mission_id) 前缀;ORDER BY id ASC 触发 using_temporary_table + using_filesort,cost 561。content(longtext)、original(longblob) 大列;WHERE 为 OR 条件(designnode.flow_id=? OR designinput.mission_id=?)导致无法走单索引精确定位,逐 mission 展开;实测样本 rows_examined=30 但耗时 2.4s,瓶颈在 longtext/longblob 的 IO 读取。content/original 大列(按 id 需要时再取)。UNION 两支各自走索引(designnode(flow_id) 需有索引:当前 designnode 只有 mission_id 键,建议加 KEY idx_flow_id(flow_id);designinput 走现有 unique(mission_id,kind,digest) 前缀)。qa_hub_designartifact 按 mission 查(182 条 + 106 条变体 / 累计 1 小时)qa_hub_designartifac_mission_id_62c9b43e_fk(mission_id)(ref,每次扫描 ~114 行),ORDER BY id 借助索引无 filesort;106 条变体(mission_id+kind+round LIMIT 1)同样只扫 114 行。payload 大列,114 行/次 × 288 次/天的 longtext 读取造成 IO 放大,叠加实例压力(该模式 max 108s 明显是排队所致)。payload、source_snapshot、content 等大列全部拖进每轮查询。统一做「列表瘦查询 + 详情按 id 回表」改造收益最大。GET_LOCK('tapd-api:…', 74)(152 条 / 累计 15 分钟,平均 5.9s、最大 42.8s)commit;/COMMIT;(422 条 / 累计 ~29 分钟)、SHOW ENGINE INNODB STATUS(213 条)commit 最大单次 296s。✔ 这是 IO 刷盘/长事务压力的典型信号,与 A/B/D 的「计划很便宜却跑数秒」互相印证。建议检查 staging/8891(192.168.8.84)主机 IO 与 innodb_flush_log_at_trx_commit 场景压力,并排查是否有未及时提交的长连接事务。source_snapshot、result、content、original、payload 等大字段,改为按 id 回表取详情;预计可消除全天约 5.5 小时慢日志(占非备份总量 43%)。ALTER TABLE aiworkflow.qa_hub_designnode ADD KEY idx_flow_id(flow_id);(低峰执行),配合 OR→UNION 改写。es_slow_logs / es_search / describe_schema / explain,全程只读)mysql_slow-*,@timestamp 过滤 [2026-11-05T00:00:00+08:00, 2026-11-06T00:00:00+08:00),全量 5,622 条(search_after 时间游标翻页,无丢弃)?,保留库表与 SQL 骨架;共 684 个模式