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

QUOTE(null) should return 'NULL' string instead of NULL value #11556

Closed
DQinYuan opened this issue Aug 1, 2019 · 5 comments · Fixed by #11592
Closed

QUOTE(null) should return 'NULL' string instead of NULL value #11556

DQinYuan opened this issue Aug 1, 2019 · 5 comments · Fixed by #11592
Labels
type/bug The issue is confirmed as a bug.

Comments

@DQinYuan
Copy link
Contributor

DQinYuan commented Aug 1, 2019

Bug Report

In doc:

image

quote(null) should return 'NULL' string, but tidb return NULL value instead.

  1. What did you do?
select quote(null) is NULL;
  1. What did you expect to see?

in mysql:

mysql> select quote(null) is NULL;
+---------------------+
| quote(null) is NULL |
+---------------------+
|                   0 |
+---------------------+
1 row in set (0.00 sec)
  1. What did you see instead?

In TiDB:

mysql> select quote(null) is NULL;
+---------------------+
| quote(null) is NULL |
+---------------------+
|                   1 |
+---------------------+
1 row in set (0.00 sec)
  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?
mysql> select tidb_version();
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                              |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v3.0.0
Git Commit Hash: 60965b006877ca7234adaced7890d7b029ed1306
Git Branch: HEAD
UTC Build Time: 2019-06-28 12:14:07
GoVersion: go version go1.12 linux/amd64
Race Enabled: false
TiKV Min Version: 2.1.0-alpha.1-ff3dd160846b7d1aed9079c389fc188f7f5ea13e
Check Table Before Drop: false |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Mysql version is 5.7

@DQinYuan DQinYuan added the type/bug The issue is confirmed as a bug. label Aug 1, 2019
@gaoxingliang
Copy link
Contributor

I will check this issue

@gaoxingliang
Copy link
Contributor

gaoxingliang commented Aug 2, 2019

I looked into the definition here. but it's weird for mysql impl (or I can say it's wrong).
See below cases:

mysql> SELECT QUOTE(NULL);
+-------------+
| QUOTE(NULL) |
+-------------+
| NULL        |
+-------------+
1 row in set (0.00 sec)

mysql> SELECT NULL is NULL;
+--------------+
| NULL is NULL |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT "" is NULL;
+------------+
| "" is NULL |
+------------+
|          0 |
+------------+
1 row in set (0.00 sec)

mysql> SELECT QUOTE(NULL) IS null;
+---------------------+
| QUOTE(NULL) IS null |
+---------------------+
|                   0 |
+---------------------+
1 row in set (0.00 sec)
mysql> select @@version;
+-----------+
| @@version |
+-----------+
| 5.7.13    |
+-----------+
1 row in set (0.00 sec)

as you can see, the NULL IS NULL = true = 1 and according to the doc, the quote(NULL) should be NULL. so the value should be 1 instead of 0.
I think this is wrong for mysql's implementation.

I will compare with latest mysql and check in the community

@gaoxingliang
Copy link
Contributor

Aha, I got more information about this issue.
the cause is the doc is wrong. the quote(null) will return a string "NULL" instead of NULL is mysql.
see my below test:

mysql> select length(quote(null));
+---------------------+
| length(quote(null)) |
+---------------------+
|                   4 |
+---------------------+
1 row in set (0.00 sec)

mysql> select quote(null) REGEXP 'NULL'
    -> ;
+---------------------------+
| quote(null) REGEXP 'NULL' |
+---------------------------+
|                         1 |
+---------------------------+
1 row in set (0.00 sec)

mysql> select quote(null) REGEXP 'null'
    -> ;
+---------------------------+
| quote(null) REGEXP 'null' |
+---------------------------+
|                         1 |
+---------------------------+

it's the upper case "NULL" instead of null.
See the case sensitive version:

mysql> select quote(null) REGEXP binary 'null'
    -> ;
+----------------------------------+
| quote(null) REGEXP binary 'null' |
+----------------------------------+
|                                0 |
+----------------------------------+
1 row in set (0.00 sec)

mysql> select quote(null) REGEXP binary 'NULL';
+----------------------------------+
| quote(null) REGEXP binary 'NULL' |
+----------------------------------+
|                                1 |
+----------------------------------+
1 row in set (0.00 sec)

@DQinYuan
Copy link
Contributor Author

DQinYuan commented Aug 2, 2019

@gaoxingliang I think doc say very clearly quote(null) will return string 'NULL', and mysql impl is right

@gaoxingliang
Copy link
Contributor

Yes. u r right. I confirmed. I will try to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants