Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Major
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.1, 12.3.3
-
Linux x86_64; MariaDB 12.3.3-MariaDB-ubu2404
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.