pingcap/tidb

Incorrect query result

sayJason opened this issue · 3 comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE t1(c1 BOOL);
INSERT INTO t1(c1) VALUES (1);
SELECT c1 FROM t1 WHERE 1| DATE_FORMAT(0, BINARY (c1 IS NULL)); -- actual: {}, expected: {1}

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

SELECT returns the column c1's value 1

3. What did you see instead (Required)

SELECT returns nothing

4. What is your TiDB version? (Required)

Release Version: v7.0.0
Edition: Community
Git Commit Hash: 7376954
Git Branch: heads/refs/tags/v7.0.0
UTC Build Time: 2023-03-29 13:32:13
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv

mysql> SELECT c1 FROM t1 WHERE 1| DATE_FORMAT(0, BINARY (c1 IS NULL)); 
Empty set, 1 warning (0.01 sec)

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

in mysql8:

mysql> SELECT c1 FROM t1 WHERE 1| DATE_FORMAT(0, BINARY (c1 IS NULL)); 
+------+
| c1   |
+------+
|    1 |
+------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                      |
+---------+------+----------------------------------------------------------------------------------------------+
| Warning | 1287 | 'BINARY expr' is deprecated and will be removed in a future release. Please use CAST instead |
+---------+------+----------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql>