Inconsistent behavior in TiDB for string-to-DATETIME comparison in derived-table query
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
```sql
-- create table
DROP TABLE IF EXISTS t0;
CREATE TABLE t0 (c0 mediumtext) CHARSET=utf8mb4;
INSERT INTO t0 VALUES ('-1438676116');
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (c0 mediumtext) CHARSET=utf8mb4;
INSERT INTO t1 VALUES ('-1438676116');
-- query
SELECT subq.c0, t0.c0
FROM (
SELECT t1.c0 AS c0
FROM t0
JOIN t1 ON t0.c0 = t1.c0
) AS subq
CROSS JOIN t0
WHERE subq.c0 <> FROM_UNIXTIME(1700000000);
```
### 2. What did you expect to see? (Required)
When I execute in DBMSs such as MySQL and Mariadb, the result is as follows:
```
+-------------+-------------+
| c0 | c0 |
+-------------+-------------+
| -1438676116 | -1438676116 |
+-------------+-------------+
```
### 3. What did you see instead (Required)
```
mysql> SELECT subq.c0, t0.c0
-> FROM (
-> SELECT t1.c0 AS c0
-> FROM t0
-> JOIN t1 ON t0.c0 = t1.c0
-> ) AS subq
-> CROSS JOIN t0
-> WHERE subq.c0 <> FROM_UNIXTIME(1700000000);
Empty set, 2 warnings (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```
mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.5
Edition: Community
Git Commit Hash: 1fa258b833ff113883beeba40bc130be7ce66610
Git Branch: HEAD
UTC Build Time: 2026-03-23 14:08:54
GoVersion: go1.25.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.