2.7.3.3 查询见解

Query Insights 提供:

  • 成功执行查询的运行时

  • 查询的运行时估计 EXPLAIN

  • 使用取消的查询的运行时估计 Ctrl+C

  • 由于内存不足错误而失败的查询的运行时估计。

运行时数据可用于查询优化、故障排除或估算在 HeatWave 上运行特定查询或工作负载的成本。

查询见解语法
Press CTRL+C to copy
CALL sys.heatwave_advisor ([options]); options: { JSON_OBJECT("key","value"[,"key","value"] ...) "key","value": ["output",{"normal"|"silent"|"help"}] ["target_schema",JSON_ARRAY({"schema_name"[,"schema_name"]}] ["exclude_query",JSON_ARRAY("query_id"[,"query_id"] ...)] ["query_session_id",JSON_ARRAY("query_session_id"[,"query_session_id"] ...)] ["query_insights",{TRUE|FALSE}] }

有关语法示例,请参阅 第 2.7.3.4 节,“Advisor 示例”

JSONAdvisor 选项被指定为-object 格式 的键值对 。选项包括:

  • output:定义 Advisor 如何生成输出。允许的值为:

  • target_schema:定义一个或多个模式。该列表以 JSON-array 格式指定。如果未指定目标架构,则会考虑 HeatWave 中的所有架构。

  • exclude_query:定义要排除的查询的 ID。要识别查询 ID,请查询 performance_schema.rpd_query_stats 表。有关查询示例,请参阅 第 2.7.3.4 节,“顾问示例”

  • query_session_id:定义会话 ID,用于按会话 ID 过滤查询。要识别会话 ID,请查询该 performance_schema.rpd_query_stats 表。有关查询示例,请参阅 第 2.7.3.4 节,“顾问示例”

  • query_insights:为成功执行的查询提供运行时,为EXPLAIN查询、使用 取消的Ctrl+C查询以及由于内存不足错误而失败的查询提供运行时估计。默认设置为FALSE

运行查询见解

要让 Query Insights 提供运行时数据,查询历史记录必须可用。Query Insights 提供最多 1000 个查询的运行时数据,这是 HeatWave 查询历史限制。查看当前的HeatWave查询历史,查询 performance_schema.rpd_query_stats 表:

Press CTRL+C to copy
mysql> SELECT query_id, LEFT(query_text,160) FROM performance_schema.rpd_query_stats;

以下示例展示了如何使用 Query Insights 检索整个查询历史记录的运行时数据。在此示例中,查询历史记录中有三个查询:成功执行的查询、因内存不足错误而失败的查询以及使用 取消的查询 Ctrl+C。有关 Query Insights 数据的说明,请参阅 Query Insights Data

Press CTRL+C to copy
mysql> CALL sys.heatwave_advisor(JSON_OBJECT("query_insights", TRUE)); +-------------------------------+ | INITIALIZING HEATWAVE ADVISOR | +-------------------------------+ | Version: 1.12 | | | | Output Mode: normal | | Excluded Queries: 0 | | Target Schemas: All | | | +-------------------------------+ 6 rows in set (0.01 sec) +---------------------------------------------------------+ | ANALYZING LOADED DATA | +---------------------------------------------------------+ | Total 8 tables loaded in HeatWave for 1 schemas | | Tables excluded by user: 0 (within target schemas) | | | | SCHEMA TABLES COLUMNS | | NAME LOADED LOADED | | ------ ------ ------ | | `tpch128` 8 61 | | | +---------------------------------------------------------+ 8 rows in set (0.02 sec) +-------------------------------------------------------------------------------------+ | QUERY INSIGHTS | +-------------------------------------------------------------------------------------+ | Queries executed on Heatwave: 4 | | Session IDs (as filter): None | | | | QUERY-ID SESSION-ID QUERY-STRING EXEC-RUNTIME COMMENT | | -------- ---------- ------------ ------------ ------- | | 1 32 SELECT COUNT(*) | | FROM tpch128.LINEITEM 0.628 | | 2 32 SELECT COUNT(*) | | FROM tpch128.ORDERS 0.114 (est.) Explain. | | 3 32 SELECT COUNT(*) | | FROM tpch128.ORDERS, | | tpch128.LINEITEM 5.207 (est.) Out of memory | | error during | | query execution | | in RAPID. | | 4 32 SELECT COUNT(*) | | FROM tpch128.SUPPLIER, | | tpch128.LINEITEM 3.478 (est.) Operation was | | interrupted by | | the user. | | TOTAL ESTIMATED: 3 EXEC-RUNTIME: 8.798 sec | | TOTAL EXECUTED: 1 EXEC-RUNTIME: 0.628 sec | | | | | | Retrieve detailed query statistics using the query below: | | SELECT log FROM sys.heatwave_advisor_report WHERE stage = "QUERY_INSIGHTS" AND | | type = "info"; | | | +-------------------------------------------------------------------------------------+ mysql> SELECT log FROM sys.heatwave_advisor_report WHERE stage = "QUERY_INSIGHTS" AND type = "info"; +--------------------------------------------------------------------------------------+ | log | +--------------------------------------------------------------------------------------+ | {"comment": "", "query_id": 1, "query_text": "SELECT COUNT(*) FROM tpch128.LINEITEM",| | "session_id": 32, "runtime_executed_ms": 627.6099681854248, | | "runtime_estimated_ms": 454.398817} | | | | {"comment": "Explain.", "query_id": 2, "query_text": "SELECT COUNT(*) | | FROM tpch128.ORDERS", "session_id": 32, "runtime_executed_ms": null, | | "runtime_estimated_ms": 113.592768} | | | | {"comment": "Out of memory error during query execution in RAPID.", "query_id": 3, | | "query_text": "SELECT COUNT(*) FROM tpch128.ORDERS, tpch128.LINEITEM", | | "session_id": 32, "runtime_executed_ms": null, "runtime_estimated_ms": 5206.80822} | | | | {"comment": "Operation was interrupted by the user.", "query_id": 4, | | "query_text": "SELECT COUNT(*) FROM tpch128.SUPPLIER, tpch128.LINEITEM", | | "session_id": 32, "runtime_executed_ms": null, "runtime_estimated_ms": 3477.720953} | +--------------------------------------------------------------------------------------+ 4 rows in set (0.00 sec)

有关按模式和会话 ID 过滤结果的 Query InsightsCALL语句示例,请参阅 第 2.7.3.4 节,“顾问示例”

查询洞察数据

Query Insights 提供以下数据:

  • QUERY-ID

    查询 ID。

  • SESSION-ID

    发出查询的会话 ID。

  • QUERY-STRING

    查询字符串。 EXPLAIN,如果指定,则不会显示在查询字符串中。

  • EXEC-RUNTIME

    以秒为单位的查询执行运行时间。运行时间估计与实际运行时间的区别在于运行时间旁边出现以下文本:(est.)。显示成功执行的查询的实际运行时间。EXPLAIN显示查询、被取消的Ctrl+C查询以及因内存不足错误而失败的 查询的运行时估计 。

  • COMMENT

    与查询关联的评论。评论可能包括:

    • Explain: 查询是用 运行的 EXPLAIN

    • Operation was interrupted by the user:查询已成功卸载到 HeatWave,但被 Ctrl+C 组合键中断。

    • Out of memory error during query execution in RAPID: 查询已成功卸载到 HeatWave,但由于内存不足错误而失败。

  • TOTAL-ESTIMATEDEXEC-RUNTIME

    具有运行时估计和总执行运行时间(估计)的查询总数。

  • TOTAL-EXECUTEDEXEC-RUNTIME

    成功执行的查询总数和总执行运行时间(实际)。

  • Retrieve detailed statistics using the query below

    sys.heatwave_advisor_report该查询从表中 检索详细的查询统计信息 。有关详细统计信息的示例,请参阅 运行查询见解

Query Insights 数据可以以机器可读格式检索,以便在脚本中使用;请参阅 第 2.7.3.4 节,“顾问示例”。Query Insights 数据也可以JSON通过查询表以格式或 SQL 表格式 检索sys.heatwave_advisor_report。请参阅 第 2.7.3.5 节,“顾问报告表”