[MDEV-13793] Wrong result with combination of CONCAT,SUBSTR,SHA Created: 2017-09-13  Updated: 2017-09-13  Resolved: 2017-09-13

Status: Closed
Project: MariaDB Server
Component/s: OTHER
Affects Version/s: 10.0, 10.1, 10.2, 10.3
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Duplicate Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-13790 UNHEX() of a somewhat complicated CON... Closed
Relates
relates to MDEV-10306 Wrong results with combination of CON... Closed

 Description   

This query erroneously returns NULL:

SELECT UNHEX(CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8)));

If I remove HEX, it correctly returns a string in hexadecimal format:

SELECT CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8));

+------------------------------------------------------------------------------------+
| CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8)) |
+------------------------------------------------------------------------------------+
| 414c2B3ee5e6bA                                                                     |
+------------------------------------------------------------------------------------+

If I now add a user variable assignment, it erroneously returns a broken hexadecimal string:

SELECT @a:=CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8));

+----------------------------------------------------------------------------------------+
| @a:=CONCAT('414c2', HEX(8+ROUND(RAND()*7)),SUBSTR(SHA(''),6,7),HEX(2+ROUND(RAND())*8)) |
+----------------------------------------------------------------------------------------+
| 414c299 ee56b2                                                                         |
+----------------------------------------------------------------------------------------+

The same problem is reproducible in a simplified query:

SELECT @a:=CONCAT('2', '2', SUBSTR(SHA(''),6,7));

+-------------------------------------------+
| @a:=CONCAT('2', '2', SUBSTR(SHA(''),6,7)) |
+-------------------------------------------+
| 223ee5 6b                                 |
+-------------------------------------------+


Generated at Thu Feb 08 08:08:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.