# [KB]关于 TiDB 设置 sql_select_limit 导致 SQL Binding 不起作用

## Issue

设置了 sql_select_limit 会导致 [SQL Binding](https://docs.pingcap.com/zh/tidb/stable/sql-plan-management#%E6%89%A7%E8%A1%8C%E8%AE%A1%E5%88%92%E7%BB%91%E5%AE%9A-sql-binding) 不起作用。

## Root Cause

sql_select_limit 配置和 SQL Binding 冲突，Github Issue：[https://github.com/pingcap/tidb/issues/27949](https://github.com/pingcap/tidb/issues/27949)

## Diagnostic Steps

```sql
create table t (a int, b int, key(b));
explain select \* from t where b=1;
create global binding for select \* from t where b=1 using select \* from t ignore index(b) where b=1;

mysql> explain select \* from t where b=1;
+-------------------------+----------+-----------+---------------+--------------------------------+
| id                      | estRows  | task      | access object | operator info                  |
+-------------------------+----------+-----------+---------------+--------------------------------+
| TableReader_7           | 10.00    | root      |               | data:Selection_6               |
| └─Selection_6           | 10.00    | cop[tikv] |               | eq(test.t.b, 1)                |
|   └─TableFullScan_5     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo |
+-------------------------+----------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

mysql> 
mysql> set @@sql_select_limit=100;
Query OK, 0 rows affected (0.00 sec)

mysql> 
mysql> explain select \* from t where b=1;
+--------------------------------+---------+-----------+---------------------+---------------------------------------------+
| id                             | estRows | task      | access object       | operator info                               |
+--------------------------------+---------+-----------+---------------------+---------------------------------------------+
| IndexLookUp_17                 | 10.00   | root      |                     | limit embedded(offset:0, count:100)         |
| ├─Limit_16(Build)              | 10.00   | cop[tikv] |                     | offset:0, count:100                         |
| │ └─IndexRangeScan_14          | 10.00   | cop[tikv] | table:t, index:b(b) | range:[1,1], keep order:false, stats:pseudo |
| └─TableRowIDScan_15(Probe)     | 10.00   | cop[tikv] | table:t             | keep order:false, stats:pseudo              |
+--------------------------------+---------+-----------+---------------------+---------------------------------------------+
4 rows in set (0.00 sec)
```

## Resolution

目前只在 master 修复了这个问题，预估 v5.0.6 版本修复这个问题。

## Workaround

1. 通过 Optimizer Hints 方式修改程序代码中的 SQL语句；
2. 去掉 sql_select_limit 的设置，可能是程序，也有可能是框架