Unexpected result when comparing `TIMESTAMP` null values
- 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
DROP DATABASE IF EXISTS db0;
CREATE DATABASE db0;
USE db0;
CREATE TABLE t0(c0 INT, c1 TIMESTAMP);
INSERT INTO t0(c0) VALUES (1);
CREATE INDEX t0i0 ON t0(c1 , c0); -- necessary to trigger the bug
SELECT t0.c0 FROM t0; -- 1
SELECT t0.c0 FROM t0 WHERE (t0.c1<>(CAST(1 AS YEAR))); -- 1 (unexpected)
SELECT t0.c0 FROM t0 WHERE (((t0.c1<>(CAST(1 AS YEAR)))) IS NULL); -- 1
```
### 2. What did you expect to see? (Required)
As `t0.c1` is `NULL`, then the expression `t0.c1<>(CAST(1 AS YEAR))` should also be evaluated to `NULL`, and thus this query should return no row. However, `1` is returned. Have tried to search past issues but haven't found a similar one. Kindly lemme know if it's a duplicate.
MySQL 8.0 works well on it.
### 3. What did you see instead (Required)
As mentioned above.
### 4. What is your TiDB version? (Required)
```
elect tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.4.0-alpha-244-ga5e07a2
Edition: Community
Git Commit Hash: a5e07a2ed360f29216c912775ce482f536f4102b
Git Branch: HEAD
UTC Build Time: 2024-09-25 05:10:21
GoVersion: go1.21.13
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.