为什么MariaDB-10.2.8 UNHEX()返回NULL?

时间:2017-09-12 04:11:46

标签: mysql sql mariadb

我有一个适用于MySQL的SQL脚本(最新版本)。我在Linux机器上从源代码构建了MariaDB-10.2.8的副本,并启动并运行了数据库。但是,我的SQL脚本失败了,因为MariaDB从UNHEX()调用返回NULL,它不应该在那里。

该调用以特定格式产生一个20字节的随机二进制字符串(它是一个BitTorrent节点ID)。我将一些必需字节与一些随机字节连接起来,某些字节仅限于特定的值范围。它们被构造为一个40个字符的十六进制字符串,然后我通过UNHEX()运行。

SQL是:

    unhex( concat( '414C2',
              hex( 8 + round( rand() * 7 ) ),
              substr( sha( uuid( ) ), 6, 33 ),
              hex( 2 + round( rand( ) ) * 8 ) ) )

如果你取消UNHEX()函数,你会得到一个40个字符的十六进制字符串:

MariaDB [bt]> select concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8));
+-----------------------------------------------------------------------------------------+
| concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8)) |
+-----------------------------------------------------------------------------------------+
| 414c29115056f1bd332d4e2e3eb5edd3fc90c0a2                                                |
+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

但如果你UNHEX()它:

MariaDB [bt]> select unhex(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8)));
+------------------------------------------------------------------------------------------------+
| unhex(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8))) |
+------------------------------------------------------------------------------------------------+
| NULL                                                                                           |
+------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

相比之下,MySQL实例上的命令相同:

mysql> select unhex(upper(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8))));
+-------------------------------------------------------------------------------------------------------+
| unhex(upper(concat('414c2', hex(8+round(rand()*7)),substr(sha(uuid()),6,33),hex(2+round(rand())*8)))) |
+-------------------------------------------------------------------------------------------------------+
| AL*w??
???r?%??                                                                                            |
+-------------------------------------------------------------------------------------------------------+
1 row in set (0.02 sec)

一个40个字符的十六进制字符串的UNHEX(),其中所有字节都是可打印的,在MariaDB上可以正常工作:

MariaDB [bt]> select unhex('4142434445464748494a4b4c4d4e4f5051525354');
+---------------------------------------------------+
| unhex('4142434445464748494a4b4c4d4e4f5051525354') |
+---------------------------------------------------+
| ABCDEFGHIJKLMNOPQRST                              |
+---------------------------------------------------+
1 row in set (0.00 sec)

知道为什么随机十六进制字符串不起作用吗?

1 个答案:

答案 0 :(得分:1)

看起来像个错误。我们已经为此提交了一份报告: https://jira.mariadb.org/browse/MDEV-13793