stoneatom / stonedb

StoneDB is an Open-Source MySQL HTAP and MySQL-Native DataBase for OLTP, Real-Time Analytics, a counterpart of MySQLHeatWave. (https://stonedb.io)
https://stonedb.io/
GNU General Public License v2.0
865 stars 141 forks source link

bug: the length of NULL, return wrong result #1890

Closed davidshiz closed 1 year ago

davidshiz commented 1 year ago

Have you read the Contributing Guidelines on issues?

Please confirm if bug report does NOT exists already ?

Describe the problem

mysql> CREATE TABLE t(a CHAR(10));
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO t(a) VALUES (''), (NULL), ('   '), (' a ');
Query OK, 4 rows affected (0.05 sec)
Records: 4  Duplicates: 0  Warnings: 0

mysql> select length(a) from t;
+-----------+
| length(a) |
+-----------+
|         0 |
|         0 |
|         0 |
|         2 |
+-----------+
4 rows in set (0.00 sec)

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

Expected behavior

mysql> select length(a) from t;
+-----------+
| length(a) |
+-----------+
|         0 |
|      NULL |
|         0 |
|         2 |
+-----------+
4 rows in set (0.01 sec)

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

How To Reproduce

No response

Environment

[root@stonedb-test mysql-test]# /stonedb57/install/bin/mysqld --version
/stonedb57/install/bin/mysqld  Ver 5.7.36-StoneDB-v1.0.1 for Linux on x86_64 (bu
build information as follow:
        Repository address: https://github.com/stoneatom/stonedb.git:stonedb-5.7
        Branch name: stonedb-5.7-dev
        Last commit ID: f180323
        Last commit time: Date:   Wed Jun 14 15:44:47 2023 +0800
        Build time: Date: Thu Jun 15 07:27:24 UTC 2023

Are you interested in submitting a PR to solve the problem?

davidshiz commented 1 year ago

The value of length(null) should also be NULL

RingsC commented 1 year ago
mysql> select version();
+---------------------------------+
| version()                       |
+---------------------------------+
| 5.7.36-StoneDB-v1.0.1.60a8cf71f |
+---------------------------------+
1 row in set (0.00 sec)

mysql> select * from t;
+------+
| a    |
+------+
|      |
| NULL |
|      |
|  a   |
+------+
4 rows in set (0.00 sec)

mysql> select length(a) from t;
+-----------+
| length(a) |
+-----------+
|         0 |
|      NULL |
|         0 |
|         2 |
+-----------+
4 rows in set (0.00 sec)

@davidshiz , recheck it with the latest code.

davidshiz commented 1 year ago

ok