pingcap / pingcap/tidb

Unexpected errors from SQL with plan cache and mismatched data types

Open
#58,928 2 comments 0 reactions 0 assignees View on GitHub
epic/plan-cache severity/minor sig/planner type/bug
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)

```sql
CREATE TABLE t1 (col1 int, col2 int, col3 datetime);
insert into t1 values(1, 1, now());

prepare p1 from "update t1 set col1 = 2 where col3 >= ? or col2 < ? ";
set @i0 = '2017-07-20',@i1 = 2;
execute p1 using @i0,@i1;

set @i0 = 'abc',@i1 = 2;
execute p1 using @i0,@i1;
```

### 2. What did you expect to see? (Required)

Succeed with warning, like:

```sql

mysql> update t1 set col1 = 2 where col3 >= "abc" or col2 < 2;
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> show warnings;
+---------+------+----------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------+
| Warning | 1292 | evaluation failed: Incorrect datetime value: 'abc' |
+---------+------+----------------------------------------------------+
1 row in set (0.00 sec)
```

### 3. What did you see instead (Required)

```
execute p1 using @i0,@i1;
ERROR 1815 (HY000): expression or(ge(test.t1.col3, cast(abc, datetime(6) BINARY)), lt(test.t1.col2, 2)) cannot be pushed down
```

### 4. What is your TiDB version? (Required)
```
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v9.0.0-alpha-112-ga3cc774869
Edition: Community
Git Commit Hash: a3cc774869aa581892fbeba869190796197e0bb3
Git Branch: master
UTC Build Time: 2025-01-15 02:00:53
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.