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

CONVERT(x USING binary) declares its result width in characters: materialization truncates multi-byte values

    XMLWordPrintable

Details

    Description

      CONVERT(x USING binary) names its result width after the character count of the argument instead of its byte count. The value returned by a direct SELECT is correct, but every path that materializes the declared width (derived table, DISTINCT, CREATE TABLE ... AS SELECT) silently truncates it.

      Reproduced on 10.11.19 (debug build):

      CREATE TABLE c (v VARCHAR(2) CHARACTER SET utf8mb4);
      INSERT INTO c VALUES (0xF09F9880F09F9880);            -- two emoji, 8 bytes
       
      SELECT LENGTH(CONVERT(v USING binary)) FROM c;         -- 8  (correct)
      SELECT LENGTH(b) FROM
        (SELECT DISTINCT CONVERT(v USING binary) AS b FROM c) d;   -- 2  (truncated)
       
      SET sql_mode='';
      CREATE TABLE t AS SELECT CONVERT(v USING binary) AS b FROM c;
      -- information_schema says varbinary(2); the stored value is 2 bytes

      Expected: the reserved width, and the materialized value, is 8 bytes.

      Attachments

        Activity

          People

            raghunandan.bhat Raghunandan Bhat
            chunlingqin chunlingqin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0d
                0d
                Remaining:
                Remaining Estimate - 2d
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified

                Git Integration

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