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

Hybrid functions create wrong VARBINARY length when mixing character and binary data

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.1, 10.2, 10.3
    • 10.3.1
    • OTHER

    Description

      I run this script in Linux console:

      SET sql_mode='';
      SET NAMES utf8;
      CREATE OR REPLACE TABLE t1 AS SELECT COALESCE('ßa',_binary 'a');
      SHOW WARNINGS;
      SELECT * FROM t1;
      SHOW CREATE TABLE t1;
      

      Notice, it returns a warning:

      +---------+------+------------------------------------------------------------------+
      | Level   | Code | Message                                                          |
      +---------+------+------------------------------------------------------------------+
      | Warning | 1265 | Data truncated for column 'COALESCE('ßa',_binary 'a')' at row 1  |
      +---------+------+------------------------------------------------------------------+
      

      The data was indeed truncated:

      +-----------------------------+
      | COALESCE('ßa',_binary 'a')  |
      +-----------------------------+
      | ß                           |
      +-----------------------------+
      

      And the reason for truncation is a wrong field type:

      +-------+-----------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                |
      +-------+-----------------------------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `COALESCE('ßa',_binary 'a')` varbinary(2) NOT NULL DEFAULT ''
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1  |
      +-------+-----------------------------------------------------------------------------------------------------------------------------+
      

      It should create VARBINARY(3):

      SELECT OCTET_LENGTH('ßa');
      

      +---------------------+
      | OCTET_LENGTH('ßa')  |
      +---------------------+
      |                   3 |
      +---------------------+
      

      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.