Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-13793

Wrong result with combination of CONCAT,SUBSTR,SHA

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 10.0, 10.1, 10.2, 10.3
    • N/A
    • OTHER
    • None

    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                                 |
      +-------------------------------------------+
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.