Skip to content

Commit 909158d

Browse files
authored
SPM: add binding usage (#21948)
1 parent d580659 commit 909158d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

sql-plan-management.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,24 @@ SHOW binding_cache status;
478478
1 row in set (0.00 sec)
479479
```
480480

481+
### Binding usage statistics <span class="version-mark">New in v9.0.0</span>
482+
483+
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.
484+
485+
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.
486+
487+
For example, you can check the last usage time of a binding by executing the following SQL statement:
488+
489+
```sql
490+
SELECT sql_digest, last_used_date FROM mysql.bind_info LIMIT 1;
491+
492+
+------------------------------------------------------------------+----------------+
493+
| sql_digest | last_used_date |
494+
+------------------------------------------------------------------+----------------+
495+
| 5d3975ef2160c1e0517353798dac90a9914095d82c025e7cd97bd55aeb804798 | 2025-10-21 |
496+
+------------------------------------------------------------------+----------------+
497+
```
498+
481499
## Utilize the statement summary table to obtain queries that need to be bound
482500

483501
[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).

0 commit comments

Comments
 (0)