SQL Binding fails silently when SQL is too long - binding created but not visible in SHOW GLOBAL BINDINGS
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
**Step 1: Create a SQL Binding with a large number of values in the IN clause (long SQL)**
```sql
-- Example: Create a SQL Binding with IN clause containing many values
CREATE GLOBAL BINDING FOR
SELECT * FROM table_name WHERE id IN (1, 2, 3, 4, 5, ..., 1000) -- Actually contains many values
USING
SELECT * FROM table_name USE INDEX(idx_id) WHERE id IN (1, 2, 3, 4, 5, ..., 1000);
```
**Step 2: Check if the Binding was created successfully**
```sql
-- No error reported, execution appears successful
SHOW GLOBAL BINDINGS;
-- Result: The binding just created is NOT visible
```
**Step 3: Check the system table**
```sql
SELECT original_sql, bind_sql, LENGTH(original_sql), LENGTH(bind_sql), status
FROM mysql.bind_info
ORDER BY create_time DESC
LIMIT 1;
-- Result: The binding record exists, but the SQL content is truncated
```
**Step 4: Test with a simplified version (only 3 values in IN clause)**
```sql
CREATE GLOBAL BINDING FOR
SELECT * FROM table_name WHERE id IN (1, 2, 3)
USING
SELECT * FROM table_name USE INDEX(idx_id) WHERE id IN (1, 2, 3);
SHOW GLOBAL BINDINGS;
-- Result: The binding is visible and works correctly
```
### 2. What did you expect to see? (Required)
Expected to see one of the following:
**Case 1: Successful creation**
- `CREATE GLOBAL BINDING` executes successfully
- `SHOW GLOBAL BINDINGS` displays the complete binding information
- The binding takes effect properly
**Case 2: Clear error message**
- If the SQL length exceeds the limit, a clear error should be returned, such as:
```
ERROR: SQL binding text is too long (maximum length: XXXX characters)
```
- Prevent creating bindings that will be truncated
### 3. What did you see instead (Required)
Actual behavior observed:
1. **Silent failure**: `CREATE GLOBAL BINDING` executed **without any error**, appearing to succeed
2. **Data inconsistency**:
- `SHOW GLOBAL BINDINGS` **does NOT show** the binding
- `mysql.bind_info` system table **contains** the binding record
- SQL content in the system table is **truncated**
3. **Comparison test results**:
- Long SQL (IN clause with many values): Silent failure, NOT visible in `SHOW GLOBAL BINDINGS`
- Short SQL (IN clause with only 3 values): Works correctly, visible in `SHOW GLOBAL BINDINGS`
4. **User experience issues**:
- Users believe the binding was created successfully (because no error was shown)
- In reality, the binding does not take effect
- The issue can only be discovered by checking the `mysql.bind_info` system table
**Preliminary root cause analysis:**
- SQL length exceeds the storage limit of fields in the `mysql.bind_info` table
- Lack of SQL length validation before creating the binding
- `SHOW GLOBAL BINDINGS` filters out truncated or invalid bindings
- No error handling for SQL truncation during data insertion
### 4. What is your TiDB version? (Required)
```
Release Version: v8.5.4
Edition: Community
Git Commit Hash: e4e814fdc0afe9c3a6e5e96f129d83df802ab820
Git Branch: HEAD
UTC Build Time: 2025-11-26 15:53:39
GoVersion: go1.23.12
Race Enabled: false
Check Table Before Drop: false
Store: tikv
```
Contributor guide
Assessment
This issue has not been assessed yet.