How to Monitor Changes in SQL Execution Plans in TiDB

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: TiDB如何监控SQL执行计划的变化

| username: alfred

To improve efficiency, please provide the following information. A clear problem description will help resolve the issue faster:

【Overview】 Scenario + Problem Overview

【Application Framework and Business Logic Adaptation】

【Background】 Actions Taken

【Phenomenon】 Business and Database Phenomenon

【Problem】 Current Issue Encountered

【Business Impact】

【TiDB Version】

【Attachments】 Relevant Logs and Monitoring (https://metricstool.pingcap.com/)


For questions related to performance optimization or troubleshooting, please download and run the script. Be sure to select all terminal output and copy-paste it for upload.

| username: Meditator | Original post link

Each type of SQL has an optimal execution plan. If a type of SQL has two execution plans, meaning there are two records in the system table, this situation can be considered as the execution plan having changed. Normally, there should only be one record (one execution plan) for a type of SQL in this system table. The specific system table needs to be identified, as I have forgotten the exact one.

| username: h5n1 | Original post link

CLUSTER_STATEMENTS_SUMMARY and CLUSTER_STATEMENTS_SUMMARY_HISTORY tables with the same DIGEST or DIGEST_TEXT represent a type of SQL that has multiple execution plans, and there will be multiple PLAN_DIGESTs.

| username: forever | Original post link

It would be great if we could check the current execution plan just like with Oracle.

| username: h5n1 | Original post link

At present, apart from Oracle, there are no other databases that are as detailed. However, TiDB allows you to view the historical execution plans of SQL, which is already quite good.