Skip to content
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

Null datetime is not compatible with MySQL #9763

Closed
qw4990 opened this issue Mar 18, 2019 · 5 comments
Closed

Null datetime is not compatible with MySQL #9763

qw4990 opened this issue Mar 18, 2019 · 5 comments
Labels
challenge-program component/expression duplicate Issues or pull requests already exists. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/P3 The issue has P3 priority. Assigned to backlog. severity/major sig/execution SIG execution type/compatibility

Comments

@qw4990
Copy link
Contributor

qw4990 commented Mar 18, 2019

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
CREATE TABLE t1 (a datetime not null);
insert ignore into t1 values (0);
select * from t1 where a is null;

CREATE TABLE t2 (a date not null);
insert ignore into t2 values (0);
select * from t2 where a is null;
  1. What did you expect to see?
    In MySQL
mysql> CREATE TABLE t1 (a datetime not null);
Query OK, 0 rows affected (0.01 sec)

mysql> insert ignore into t1 values (0);
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from t1 where a is null;
+---------------------+
| a                   |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
1 row in set (0.01 sec)
  1. What did you see instead?
    In TiDB
mysql> CREATE TABLE t1 (a datetime 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 where a is null;
Empty set (0.01 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                                                           |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.0-beta-227-g06183393e-dirty
Git Commit Hash: 06183393ed536aa248248b72d4bf9f5010947f66
Git Branch: master
UTC Build Time: 2019-03-15 08:22:53
GoVersion: go version go1.12 darwin/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

SIG slack channel

#sig-exec

Score

  • 300

Mentor

@qw4990 qw4990 added type/bug The issue is confirmed as a bug. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. component/expression type/compatibility and removed component/expression labels Mar 18, 2019
@zhuozl
Copy link

zhuozl commented Apr 11, 2019

This problem should be solved at the "TIKV" layer ???

MySQL [test2]> explain select * from t1 where a is null;
+---------------------+-------+------+-------------------------------------------------------------+
| id                  | count | task | operator info                                               |
+---------------------+-------+------+-------------------------------------------------------------+
| TableReader_7       | 0.00  | root | data:Selection_6                                            |
| └─Selection_6       | 0.00  | cop  | isnull(test2.t1.a)                                          |
|   └─TableScan_5     | 1.00  | cop  | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+-------+------+-------------------------------------------------------------+
3 rows in set (0.00 sec)

@qw4990
Copy link
Contributor Author

qw4990 commented Apr 29, 2019

After investigation, the reason is that TiDB's builtin function ScalarFuncSig_TimeIsNull is not compatible with MySQL.

As MySQL's documents describe:

For DATE and DATETIME columns that are declared as NOT NULL, 
you can find the special date '0000-00-00' by using a statement like this:
"SELECT * FROM tbl_name WHERE date_column IS NULL"

And TiDB doesn't check if these DATETIME columns are declared as NOT NULL.

@ghost
Copy link

ghost commented Jul 13, 2020

Confirming this issue still exists in master:

DROP TABLE IF EXISTS t1, t2;

CREATE TABLE t1 (a datetime not null);
insert ignore into t1 values (0);
select * from t1 where a is null;

CREATE TABLE t2 (a date not null);
insert ignore into t2 values (0);
select * from t2 where a is null;

..


mysql> select * from t1 where a is null;
Empty set (0.01 sec)

mysql> 
mysql> CREATE TABLE t2 (a date not null);
Query OK, 0 rows affected (0.09 sec)

mysql> insert ignore into t2 values (0);
Query OK, 1 row affected (0.02 sec)

mysql> select * from t2 where a is null;
Empty set (0.00 sec)

mysql> select tidb_version()
    -> \G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-750-g8a661044c
Edition: Community
Git Commit Hash: 8a661044cedf8daad1de4fbf79a390962b6f6c3b
Git Branch: master
UTC Build Time: 2020-07-10 10:52:37
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)

@ghost ghost added the priority/P3 The issue has P3 priority. Assigned to backlog. label Aug 12, 2020
@ghost
Copy link

ghost commented Nov 19, 2020

I am going to close this as a duplicate of #10485

There is a discussion in this issue which shows some of the nuances of MySQL's behavior. I don't think it all makes sense, so it is categorized as a feature request and not a bug. Feedback welcome of course if there are known applications that are impacted. Thanks :-)

@ghost ghost closed this as completed Nov 19, 2020
@ti-srebot
Copy link
Contributor

ti-srebot commented Nov 19, 2020

Please edit this comment or add a new comment to complete the following information

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Duplicate of #10485

@ghost ghost added the duplicate Issues or pull requests already exists. label Nov 19, 2020
@ghost ghost added need-more-info and removed type/bug The issue is confirmed as a bug. labels Nov 19, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge-program component/expression duplicate Issues or pull requests already exists. good first issue Denotes an issue ready for a new contributor, according to the "help wanted" guidelines. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/P3 The issue has P3 priority. Assigned to backlog. severity/major sig/execution SIG execution type/compatibility
Projects
None yet
4 participants