20.10 查询分析顾问

本节介绍查询分析 顾问程序。

平均语句执行时间顾问

监控规范化 SQL 语句的平均执行时间,并在执行时间超过定义的阈值时生成事件。

该顾问具有以下参数:

  • 平均执行时间阈值:如果平均执行时间超过定义的阈值,则生成事件。

  • Minimum Execution Count:规范化语句在生成事件之前必须执行的最少次数。

  • 每个查询一个警报:指定事件的生成方式。可能的值是:

    • :为每个超过阈值的规范化查询生成一个事件

    • :为每个 MySQL 服务器生成一个事件,汇总所有超过阈值的查询。这是默认行为。

  • 仅限 DML 语句:指定为哪些语句生成事件。可能的值是:

    • :仅为 DML 语句生成事件。

    • :为所有 SQL 语句生成事件。

查询 Pileup Advisor

当查询堆积发生时发出警报,当运行的线程数在短时间内迅速增加时。例如,根据此顾问程序的默认值,如果 Threads_running 的指数移动平均值在过去 1 分钟内增加了 50% 或更多但低于 80%,它会发出警告警报。

  • 窗口大小:进行监视的移动平均窗口的持续时间。

  • 增长率阈值:在定义的移动平均窗口期间运行语句的百分比增长率。

  • Minimum Running Threads:在生成事件之前运行的线程的最小数量。

SQL 语句生成警告或错误

Generates events when a normalized SQL statement generates errors or warnings over a period of time.

  • One Alert Per Query: generate events for queries which return errors or warnings. Possible values are:

    • Yes: generate an event for each normalized query which returns an error or warning.

    • No: generate a single event, per MySQL server, summarizing all queries which generated errors or warnings.

  • Notification level when discovering queries with errors: select the desired notification level for queries with errors.

  • Notification level when discovering queries with warnings: select the desired notification level for queries with warnings.

Query Analysis Reporting

Enables capturing and reporting of query analysis data.

  • Enable Example Query: provides detailed data about the queries and their parameters. Enabling this parameter increases the RAM used by the monitoring agent.

    Important

    This feature requires events_statements_history_long be enabled in performance_schema.setup_consumers. This is disabled by default in MySQL 5.6.

  • Enable Example Explain: executes EXPLAIN on the selected statement. This is executed for statements whose runtime exceeds the value defined in Auto-Explain Threshold.

  • Auto-Explain Threshold: Explains are executed for statements whose runtime is longer than the value defined here.

Important

Explains are generated for query data supplied by the Performance Schema.

Explain is supported for all DML statements on MySQL 5.6.3 or higher. On earlier versions, only SELECT is supported.