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

UNION is not symmetric when mixing INT and CHAR

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.1, 10.2, 10.3
    • Fix Version/s: 10.3.1
    • Component/s: OTHER
    • Labels:

      Description

      CREATE OR REPLACE TABLE t1 AS SELECT 1, 'a' AS c1 UNION SELECT 'a', 1;
      SHOW CREATE TABLE t1;
      

      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                  |
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `1` varchar(1) CHARACTER SET utf8 NOT NULL DEFAULT '',
        `c1` varchar(20) CHARACTER SET utf8 NOT NULL DEFAULT ''
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      

      Notice:

      • INT+CHAR created a varchar(1) column
      • CHAR+INT created a varchar(20) column

      Note, if I mix the same expression in hybrid functions, the results are symmetric:

      CREATE OR REPLACE TABLE t1 AS SELECT COALESCE(1,'a'), COALESCE('a',1);
      SHOW CREATE TABLE t1;
      

      +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | Table | Create Table                                                                                                                                                                                            |
      +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      | t1    | CREATE TABLE `t1` (
        `COALESCE(1,'a')` varchar(1) CHARACTER SET utf8 NOT NULL DEFAULT '',
        `COALESCE('a',1)` varchar(1) CHARACTER SET utf8 NOT NULL DEFAULT ''
      ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
      +-------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: