Cast double as datetime bug and adding expression causes different result
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
```
CREATE TABLE t0(c0 double, c2 BOOL , PRIMARY KEY(c2));
CREATE TABLE t1 LIKE t0;
INSERT INTO t0(c0, c2) VALUES (0.6, true), (0.5, false);
INSERT INTO t1(c2, c0) VALUES (true, 0.4);
select (((CAST(t0.c0 AS DATETIME)<=(t0.c2)))) from t0;
SELECT t0.c2 FROM t0 where (((CAST(t0.c0 AS DATETIME)<=(t0.c2))));
SELECT t0.c2 FROM t0 where (((CAST(t0.c0 AS DATETIME)<=(t0.c2)))AND((NOT (t0.c2))));
```
### 2. What did you expect to see? (Required)
```
Q1:
NULL
NULL
Q2:
Empty Result
Q3:
Empty Result
```
### 3. What did you see instead (Required)
```
Q1:
NULL
NULL
Q2:
0
1
Q3:
Empty Result
```
If Q2 produces 2 rows in TiDB's current evaluation, why does Q3 produce empty result if I add `and (NOT (t0.c2)` in the where condition? Shouldn't the result of Q3 be 0 in the context of Q2's evaluation?
### 4. What is your TiDB version? (Required)
```
| Release Version: v9.0.0-beta.1.pre-389-g21f9bb7b7a
Edition: Community
Git Commit Hash: 21f9bb7b7a7478d825c4dee4fbf2ce913e3e7cf1
Git Branch: HEAD
UTC Build Time: 2025-03-11 09:37:34
GoVersion: go1.23.7
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
```
Contributor guide
Assessment
This issue has not been assessed yet.