From f1823a38c7a5d0ccd26bf2d6a4702308d2175bd4 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 21 Oct 2025 13:24:18 +0800 Subject: [PATCH 01/11] 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 02/11] 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 03/11] 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 04/11] 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 05/11] 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 06/11] 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. From 5d284b299fc7d3fda79b343b0f56d16126f92455 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Tue, 30 Dec 2025 13:58:13 +0800 Subject: [PATCH 07/11] remove info about v8.5.5 --- 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 0e9a2a3a3a7df..96c87e8cbdf43 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.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. +Starting from v9.0.0, TiDB introduces the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-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. From 0c3cd3d8a5e8e256328808b87d94e962f2b35078 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 19 Mar 2026 10:44:40 +0800 Subject: [PATCH 08/11] Update sql-plan-management.md --- sql-plan-management.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql-plan-management.md b/sql-plan-management.md index 96c87e8cbdf43..bbb9dad460999 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -478,9 +478,9 @@ SHOW binding_cache status; 1 row in set (0.00 sec) ``` -### Binding usage statistics +### Binding usage statistics New in v9.0.0 -Starting from v9.0.0, TiDB introduces the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v900) system variable to control whether to collect the usage statistics of SQL plan bindings. +You can use the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-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. From 71d2ef7056caa5552ea3bdac6624893dcd0d736e Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 19 Mar 2026 11:02:37 +0800 Subject: [PATCH 09/11] 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 bbb9dad460999..be08722e24f23 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -480,7 +480,7 @@ SHOW binding_cache status; ### Binding usage statistics New in v9.0.0 -You can use the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v900) system variable to control whether to collect the usage statistics of SQL plan bindings. +You can use the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v900) system variable (`ON` by default) 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. From f4dfad12dc9bc08a29848ac46de94af09fb5a815 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 19 Mar 2026 11:02:44 +0800 Subject: [PATCH 10/11] 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 be08722e24f23..8b7ed0d8e8941 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -482,7 +482,7 @@ SHOW binding_cache status; You can use the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_binding_usage-new-in-v900) system variable (`ON` by default) 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. +When this variable is `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 b89157ea4a0e3e8938fb7cadb7fa199b0ecab577 Mon Sep 17 00:00:00 2001 From: Grace Cai Date: Thu, 19 Mar 2026 11:04:56 +0800 Subject: [PATCH 11/11] Update sql-plan-management.md --- sql-plan-management.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql-plan-management.md b/sql-plan-management.md index 8b7ed0d8e8941..49a8fe94bea4e 100644 --- a/sql-plan-management.md +++ b/sql-plan-management.md @@ -484,6 +484,8 @@ You can use the [`tidb_enable_binding_usage`](/system-variables.md#tidb_enable_b When this variable is `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. +For example, you can check the last usage time of a binding by executing the following SQL statement: + ```sql SELECT sql_digest, last_used_date FROM mysql.bind_info LIMIT 1;