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

TiDB is not treating '0000-00-00' date and '0000-00-00 00:00:00' as NULL #30359

Open
ramanich1 opened this issue Dec 2, 2021 · 2 comments
Open

Comments

@ramanich1
Copy link
Collaborator

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists t1,t2;
CREATE TABLE t1 (a date  NOT NULL, b datetime NOT NULL);
INSERT IGNORE INTO t1 VALUES ('0000-00-00' ,'0000-00-00 00:00:00');
SELECT * FROM t1 WHERE a IS NULL and b IS NULL;

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

mysql> SELECT * FROM t1 WHERE a IS NULL and b IS NULL;
+------------+---------------------+
| a          | b                   |
+------------+---------------------+
| 0000-00-00 | 0000-00-00 00:00:00 |
+------------+---------------------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

mysql> SELECT * FROM t1 WHERE a IS NULL and b IS NULL;
Empty set (0.00 sec)

4. What is your TiDB version? (Required)

| Release Version: v5.4.0-alpha-264-g6efa36df6
Edition: Community
Git Commit Hash: 6efa36df6cff325106f67ecfe3d79816ba37ca6a
Git Branch: master
UTC Build Time: 2021-11-29 16:57:51
GoVersion: go1.17.2
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
@ramanich1 ramanich1 added the type/bug The issue is confirmed as a bug. label Dec 2, 2021
@mjonss
Copy link
Contributor

mjonss commented Dec 2, 2021

I would claim that this is rather a bug in MySQL that we should not be bug compatible with, since only NULL should match IS NULL

MySQL gives this weird result:

mysql> SELECT * FROM t1 WHERE a IS NOT NULL and b IS NOT NULL AND a IS NULL and
b IS NULL;
+------------+---------------------+
| a          | b                   |
+------------+---------------------+
| 0000-00-00 | 0000-00-00 00:00:00 |
+------------+---------------------+
1 row in set (0,00 sec)

But apparently it is intended for ODBC compatibility:
https://bugs.mysql.com/bug.php?id=95416
@morgo what is your opinion on this? Should we also compare ZERO DATE/DATETIME with both NULL and NOT NULL?

@morgo
Copy link
Contributor

morgo commented Dec 2, 2021

I would claim that this is rather a bug in MySQL that we should not be bug compatible with, since only NULL should match IS NULL

It's not a bug if it is documented and intentional :( Even if I have the same reaction as you 🤮

But apparently it is intended for ODBC compatibility: https://bugs.mysql.com/bug.php?id=95416 @morgo what is your opinion on this? Should we also compare ZERO DATE/DATETIME with both NULL and NOT NULL?

This is a duplicate of #10485

My suggestion is: we close this as a duplicate, but leave the other issue open as a feature request so that users have something to refer to and request it be added. If we identify an application as affected, we can look at adding support for it.

@aytrack aytrack added sig/execution SIG execution type/compatibility and removed type/bug The issue is confirmed as a bug. labels Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants