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

Logic bug: NAME_CONST CTAS creates CHAR(0) column

    XMLWordPrintable

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.11, 11.4, 11.8, 12.3, 12.2.2
    • 10.11, 12.3
    • Optimizer
    • Ubuntu 24.04

    Description

      The optimizer/wrapper path appears to preserve optimized constant metadata from
      `NAME_CONST` rather than converting it into generic expression metadata before
      CTAS column creation. `LIMIT 0` shows the bad metadata without inserting data;
      the row-producing variant fails when `"81"` is inserted into a `char(0)`
      column.

      DROP DATABASE IF EXISTS db;
      CREATE DATABASE db;
      USE db;
       
      CREATE TABLE t (
        id INT PRIMARY KEY,
        p INT NOT NULL,
        o INT NOT NULL,
        v INT NOT NULL
      ) ENGINE=InnoDB;
      INSERT INTO t VALUES (1, 1, 1, 9);
       
      CREATE TABLE t_source_meta AS
      SELECT ROW_NUMBER() OVER (ORDER BY o) AS rn,
             CONCAT(NAME_CONST('p', 9) * NAME_CONST('v', 9)) AS vc
      FROM t
      LIMIT 0;
       
      CREATE TABLE t_reference_meta AS
      SELECT 1 AS rn,
             CONCAT(9 * 9) AS vc
      FROM t
      LIMIT 0;
       
      SHOW CREATE TABLE t_source_meta;
      SHOW CREATE TABLE t_reference_meta;
       
      CREATE TABLE t_source_run AS
      SELECT ROW_NUMBER() OVER (ORDER BY o) AS rn,
             CONCAT(NAME_CONST('p', 9) * NAME_CONST('v', 9)) AS vc
      FROM t;
       
      CREATE TABLE t_reference_run AS
      SELECT 1 AS rn,
             CONCAT(9 * 9) AS vc
      FROM t;
       
      SELECT * FROM t_reference_run;
       
      DROP DATABASE IF EXISTS db;
      

      Expected Result

      `t_source_meta.vc` and `t_reference_meta.vc` should have compatible metadata,
      and both row-producing CTAS statements should succeed.

      Actual Result

      `t_source_meta.vc` is created as `char(0)`. The row-producing `t_source_run`
      CTAS fails with `ERROR 1406 Data too long for column vc`.

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            imchifan 刘启帆
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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