pingcap / pingcap/tidb

expr varchar=datetime return incorrect result

Open
#61,143 1 comment 0 reactions 0 assignees View on GitHub
severity/moderate sig/execution 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)

```
DROP TABLE IF EXISTS t1;

CREATE TABLE t1 (
a VARCHAR(20),
b DATETIME
);

INSERT INTO t1 VALUES
('891113052160','2024-01-02 12:34:56');

select a=b from t1 order by a;
```

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

```
result from mysql

MySQL [fuzztest]> select a=b from t1 order by a;
+------+
| a=b |
+------+
| 0 |
+------+
1 row in set, 1 warning (0.00 sec)

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

```
result from tidb

MySQL [testdb_1747239281507]> select a=b from t1 order by a;
+------+
| a=b |
+------+
| NULL |
+------+
1 row in set, 1 warning (0.01 sec)

MySQL [testdb_1747239281507]> select version();
+--------------------+
| version() |
+--------------------+
| 8.0.11-TiDB-v8.5.1 |
+--------------------+
1 row in set (0.01 sec)
```
### 4. What is your TiDB version? (Required)

```
MySQL [testdb_1747239281507]> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.1
Edition: Community
Git Commit Hash: fea86c8e35ad4a86a5e1160701f99493c2ee547c
Git Branch: HEAD
UTC Build Time: 2025-01-16 07:38:34
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
```

Contributor guide

Open the contributing guide

Research direction

No source file or test is named. Start by reproducing the supplied VARCHAR-to-DATETIME comparison in TiDB and compare it with MySQL, then trace the SQL comparison and type-conversion entry points. Done means the query returns 0 rather than NULL while preserving the expected warning behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.