美文网首页
通过show_profile找出慢查询的原因

通过show_profile找出慢查询的原因

作者: 养一只tom猫 | 来源:发表于2021-10-08 16:45 被阅读0次

    SET @query_id = 52;
    SELECT
    state,
    SUM( Duration ) AS total_r,
    ROUND( 100 * SUM( Duration ) / ( SELECT SUM( Duration ) FROM information_schema.PROFILING WHERE query_id = @query_id ), 2 ) AS pct_r,
    COUNT() AS calls,
    SUM( duration ) / COUNT(
    ) AS 'r/call'
    FROM
    information_schema.PROFILING
    WHERE
    Query_ID = @query_id
    GROUP BY
    state
    ORDER BY
    total_r DESC;#查看该语句每一步具体执行时间并进行排序

    SELECT * FROM contract_review;#需要优化的SQL语句
    SHOW PROFILES;#查找需要优化的SQL语句的queryId
    SHOW PROFILE FOR QUERY 38;#查看该语句每一步具体执行时间

    相关文章

      网友评论

          本文标题:通过show_profile找出慢查询的原因

          本文链接:https://www.haomeiwen.com/subject/dtmxoltx.html