-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zero date IS NULL
is different from MySQL
#10485
Comments
@imtbkcat Could you post the sql modes used in mysql and tidb respectively? |
guess there is a sql mode that regards zero time values as null.. |
TiDB SQL mode:
MySQL sql mode:
|
This issue is nothing to do with
I think the difference lays on whether date mysql> set @@sql_mode="";
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> create table t1(a date not null); Query OK, 0 rows affected (0.03 sec)
mysql> insert ignore into t1 values (0); Query OK, 1 row affected (0.01 sec)
mysql> select * from t1;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)
mysql> select * from t1 where a is null;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)
mysql> select * from t1 where a = '0000-00-00';
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec) In TIDB: mysql> set @@sql_mode='';
Query OK, 0 rows affected (0.00 sec)
mysql> create table t1(a date not null);
Query OK, 0 rows affected (0.01 sec)
mysql> insert ignore into t1 values (0);
Query OK, 1 row affected (0.01 sec)
mysql> select * from t1;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.01 sec)
mysql> select * from t1 where a is null;
Empty set (0.00 sec)
mysql> select * from t1 where a = '0000-00-00';
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec) MySQL seems treat date |
MySQL's behavior is interesting...... mysql> select * from t1 where a is null
-> ;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)
mysql>
mysql> select a, a is null, a is not null from t1;
+------------+-----------+---------------+
| a | a is null | a is not null |
+------------+-----------+---------------+
| 0000-00-00 | 0 | 1 |
+------------+-----------+---------------+
1 row in set (0.00 sec)
mysql> select * from t1 where a is not null;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)
mysql> select * from t1 where a = '0000-00-00';
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)
mysql> select * from t1 where a != '0000-00-00';
Empty set (0.00 sec)
I tend to treat MySQL's behavior as a bug. I think a value can't be |
mysql> select * from t1 where a is null;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)
mysql> select * from t1 where a is not null;
+------------+
| a |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec) conclusion 1: mysql> select a, a is null, a is not null from t1;
+------------+-----------+---------------+
| a | a is null | a is not null |
+------------+-----------+---------------+
| 0000-00-00 | 0 | 1 |
+------------+-----------+---------------+
1 row in set (0.00 sec) conclusion 2: @morgo How do you think? What's the reasonable behavior? |
😂 |
Reported as https://bugs.mysql.com/bug.php?id=95416 - let's wait a few days to see if there is an insightful answer :-) |
Update: This is confirmed as intentional (and documented) behavior since some ODBC drivers do not allow to select for NULL(?) I think because it is intended, we may need to support it as well. |
@morgo yeah... I just read the issue details... its tricky indeed.. since it's a feature other than a bug, maybe we need to support it .... |
I meet some issue in update test too 🤣 mysql add a test to fix this bug https://bugs.mysql.com/bug.php?id=14186 if test case is |
Confirming this is still an issue: mysql> insert ignore into t1 values (0);
Query OK, 1 row affected (0.03 sec)
mysql> select * from t1 where a is null;
Empty set (0.00 sec)
mysql> delete from t1 where a is null;
Query OK, 0 rows affected (0.00 sec)
mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
| 1 |
+----------+
1 row in set (0.01 sec)
mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-870-g2a8b96845
Edition: Community
Git Commit Hash: 2a8b968453520e4fcf9d6ff46c9f23b4ad23feee
Git Branch: master
UTC Build Time: 2020-07-31 08:45:35
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec) |
IS NULL
is different from MySQLIS NULL
is different from MySQL
I have updated the description to make the testcase clearer. There are a couple of different issues here:
How to fix these issues is not clear to me, since the MySQL behavior does not really make sense. It is also not really easy to compare to other database impliementations, since the "zero date" is a MySQL-ism. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
If possible, provide a recipe for reproducing the error.
In MySQL:
in TiDB:
tidb-server -V
or runselect tidb_version();
on TiDB)?The text was updated successfully, but these errors were encountered: