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

COPY ALTER causes a dependent expression default to evaluate as NULL on later inserts

    XMLWordPrintable

Details

    Description

      After ALTER TABLE ... ALGORITHM=COPY adds an expression-default column to a temporary Aria table, a later insert produces NULL for that column. An equivalent table created directly produces the expected value.

      Run the following script in one MariaDB session so that both temporary tables remain available:

      CREATE DATABASE defaults_test;
      USE defaults_test;
      CREATE TEMPORARY TABLE altered (a INT, b INT DEFAULT (a + 1)) ENGINE=Aria;
      INSERT INTO altered(a) VALUES (1);
      ALTER TABLE altered ADD c INT DEFAULT (b + 1), ALGORITHM=COPY;
      CREATE TEMPORARY TABLE control (a INT, b INT DEFAULT (a + 1), c INT DEFAULT (b + 1)) ENGINE=Aria;
      INSERT INTO altered(a) VALUES (10);
      INSERT INTO control(a) VALUES (10);
      SELECT 'altered' AS variant,a,b,c FROM altered ORDER BY a;
      SELECT 'control' AS variant,a,b,c FROM control;
      SELECT 'oracle' AS check_name,
             (SELECT COUNT(*) FROM altered WHERE a=1 AND b=2 AND c=3)=1 AS copy_ok,
             (SELECT COUNT(*) FROM altered WHERE a=10 AND b=11 AND c=12)=1 AS insert_ok,
             (SELECT COUNT(*) FROM control WHERE a=10 AND b=11 AND c=12)=1 AS control_ok;
      DROP TEMPORARY TABLE altered,control;
      DROP DATABASE defaults_test;

      The statements complete without an error and return:

      variant  a   b   c
      altered  1   2   3
      altered  10  11  NULL
      variant  a   b   c
      control  10  11  12
      check_name  copy_ok  insert_ok  control_ok
      oracle      1        0          1

      The row copied during the ALTER is correct: (1,2,3). The later insert into the altered table computes b=11 but leaves c as NULL, whereas the directly created control table computes c=12 from the same default definitions.

      Both schemas are equivalent for the later insert, so the expression defaults should be evaluated in dependency order and both tables should produce (10,11,12).

      This occurs when COPY ALTER adds an expression default that depends on an existing expression-default column of a temporary Aria table.

      Attachments

        Activity

          People

            sanja Oleksandr Byelkin
            Wren Qin
            Votes:
            0 Vote for this issue
            Watchers:
            2 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.