From f1823a38c7a5d0ccd26bf2d6a4702308d2175bd4 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 21 Oct 2025 13:24:18 +0800 Subject: [PATCH 1/6] spm: add binding usage Signed-off-by: Weizhen Wang --- sql-plan-management.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sql-plan-management.md b/sql-plan-management.md index 3caa4169f21c2..69efd3214496c 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -478,6 +478,22 @@ SHOW binding_cache status; 1 row in set (0.00 sec) ``` +### Binding Usage + +Binding Usage helps you collect usage statistics of SQL bindings, which can assist you in identifying and managing unused bindings. You can use these statistics to optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance. + +You can use the `tidb_enable_binding_usage` system variable to control whether to enable the usage statistics collection for SQL plan bindings. When this variable is set to `ON`, every six hours, the usage of bindinfo will be written into TiKV. + +```sql +select sql_digest,last_used_date from mysql.bind_info limit 1; + ++------------------------------------------------------------------+----------------+ +| sql_digest | last_used_date | ++------------------------------------------------------------------+----------------+ +| 5d3975ef2160c1e0517353798dac90a9914095d82c025e7cd97bd55aeb804798 | 2026-10-21 | ++------------------------------------------------------------------+----------------+ +``` + ## Utilize the statement summary table to obtain queries that need to be bound [Statement summary](/statement-summary-tables.md) records recent SQL execution information, such as latency, execution times, and corresponding query plans. You can query statement summary tables to get qualified `plan_digest`, and then [create bindings according to these historical execution plans](/sql-plan-management.md#create-a-binding-according-to-a-historical-execution-plan). From 695c9a37ef01ce2d0764c7f731783baea834801d Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 21 Oct 2025 15:44:53 +0800 Subject: [PATCH 2/6] Update sql-plan-management.md Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- sql-plan-management.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-plan-management.md b/sql-plan-management.md index 69efd3214496c..b573063aa1f04 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -478,7 +478,7 @@ SHOW binding_cache status; 1 row in set (0.00 sec) ``` -### Binding Usage +### Binding usage Binding Usage helps you collect usage statistics of SQL bindings, which can assist you in identifying and managing unused bindings. You can use these statistics to optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance. From dc25a264226b888ea1bbc042eec8b3fd78c99a74 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 3 Nov 2025 10:54:17 +0800 Subject: [PATCH 3/6] Apply suggestions from code review Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- sql-plan-management.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql-plan-management.md b/sql-plan-management.md index b573063aa1f04..4bd17444a360e 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -480,12 +480,12 @@ SHOW binding_cache status; ### Binding usage -Binding Usage helps you collect usage statistics of SQL bindings, which can assist you in identifying and managing unused bindings. You can use these statistics to optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance. +The binding usage feature collects usage statistics of SQL plan bindings. You can use these statistics to identify unused bindings and optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance. -You can use the `tidb_enable_binding_usage` system variable to control whether to enable the usage statistics collection for SQL plan bindings. When this variable is set to `ON`, every six hours, the usage of bindinfo will be written into TiKV. +You can use the `tidb_enable_binding_usage` system variable to control the collection of binding usage statistics. When it is set to `ON`, TiDB writes the binding usage statistics to the `mysql.bind_info` table every six hours. ```sql -select sql_digest,last_used_date from mysql.bind_info limit 1; +SELECT sql_digest, last_used_date FROM mysql.bind_info LIMIT 1; +------------------------------------------------------------------+----------------+ | sql_digest | last_used_date | From e30399552db4d6df3d578c433cf197da4bcecd36 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 3 Nov 2025 11:10:54 +0800 Subject: [PATCH 4/6] Apply suggestions from code review --- sql-plan-management.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql-plan-management.md b/sql-plan-management.md index 4bd17444a360e..c5d73f8cbfc4a 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -478,11 +478,11 @@ SHOW binding_cache status; 1 row in set (0.00 sec) ``` -### Binding usage +### Binding usage statistics -The binding usage feature collects usage statistics of SQL plan bindings. You can use these statistics to identify unused bindings and optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance. +Starting from v8.5.4 and v9.0.0, TiDB introduces the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v854-and-v900) system variable to control whether to collect the usage statistics of SQL plan bindings. -You can use the `tidb_enable_binding_usage` system variable to control the collection of binding usage statistics. When it is set to `ON`, TiDB writes the binding usage statistics to the `mysql.bind_info` table every six hours. +When this variable is set to `ON`, TiDB writes the binding usage statistics to the `mysql.bind_info` table every six hours. You can use these statistics to identify unused bindings and optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance. ```sql SELECT sql_digest, last_used_date FROM mysql.bind_info LIMIT 1; From 7b1721ed87915e0331c20600e07dd5c39d80805c Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Mon, 3 Nov 2025 11:39:28 +0800 Subject: [PATCH 5/6] Update sql-plan-management.md --- sql-plan-management.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-plan-management.md b/sql-plan-management.md index c5d73f8cbfc4a..ab60e2872df8a 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -490,7 +490,7 @@ SELECT sql_digest, last_used_date FROM mysql.bind_info LIMIT 1; +------------------------------------------------------------------+----------------+ | sql_digest | last_used_date | +------------------------------------------------------------------+----------------+ -| 5d3975ef2160c1e0517353798dac90a9914095d82c025e7cd97bd55aeb804798 | 2026-10-21 | +| 5d3975ef2160c1e0517353798dac90a9914095d82c025e7cd97bd55aeb804798 | 2025-10-21 | +------------------------------------------------------------------+----------------+ ``` From 8c0a33d04ea34969f861c19f972b2f7ec4531466 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 6 Nov 2025 14:05:56 +0800 Subject: [PATCH 6/6] Update sql-plan-management.md --- sql-plan-management.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql-plan-management.md b/sql-plan-management.md index ab60e2872df8a..0e9a2a3a3a7df 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -480,7 +480,7 @@ SHOW binding_cache status; ### Binding usage statistics -Starting from v8.5.4 and v9.0.0, TiDB introduces the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v854-and-v900) system variable to control whether to collect the usage statistics of SQL plan bindings. +Starting from v8.5.5 and v9.0.0, TiDB introduces the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v854-and-v900) system variable to control whether to collect the usage statistics of SQL plan bindings. When this variable is set to `ON`, TiDB writes the binding usage statistics to the `mysql.bind_info` table every six hours. You can use these statistics to identify unused bindings and optimize your binding management strategy, such as removing bindings that are no longer needed or adjusting existing bindings to improve query performance.