You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MySQL查询耗时138秒,求优化及EXPLAIN结果解读

查询性能优化求助:大表关联查询耗时过长
  • product_sub_locations表共701269条数据
  • 已为所有关联字段添加索引,但查询仍耗时138秒

查询语句

EXPLAIN SELECT
    P.sku,
    PL.name,
    L.name,
    SUM(PSL.qty) as total_qty
FROM
    product_sub_locations PSL
    INNER JOIN products P ON P.id = PSL.product_id
    INNER JOIN categories C ON C.id = P.category_id AND C.is_finish_good = 1
    INNER JOIN sub_locations SL ON SL.id = PSL.sub_location_id
    INNER JOIN locations L ON L.id = SL.location_id
    INNER JOIN locations PL ON PL.id = L.parent_location_id
WHERE
    1 = 1
GROUP BY
    P.id, L.id
ORDER BY
    P.sku, PL.name, L.name

现有查询耗时日志截图及EXPLAIN执行计划截图,恳请帮忙解读EXPLAIN结果,并提供查询性能优化方案。

内容的提问来源于stack exchange,提问作者Hardeep Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 22:09:22