Details
-
Bug
-
Status: Open (View Workflow)
-
Critical
-
Resolution: Unresolved
-
11.4, 11.8, 12.3, 13.1, 13.2, 13.3
Description
Likely cause: MDEV-16329, which added online ALTER TABLE with ALGORITHM=COPY in CS 11.2.1. Its commit 8cdd66134114ec9bd85c083e9ed42d7e74ecdd6b keeps the changes of other connections also on a rollback when the table engine has no rollback. For a partitioned table, the server checks the partition engine, which has no rollback, and not InnoDB. CS 10.11 does not allow writes during an ALTER TABLE that copies the table.
--source include/have_debug_sync.inc
|
--source include/have_innodb.inc
|
--source include/have_partition.inc
|
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ENGINE=InnoDB PARTITION BY HASH (a) PARTITIONS 2; |
INSERT INTO t1 VALUES (1, 1), (2, 2); |
--connect (con1, localhost, root,,)
|
--connection default
|
SET DEBUG_SYNC= 'alter_table_online_downgraded SIGNAL downgraded WAIT_FOR goon'; |
--send ALTER TABLE t1 FORCE, ALGORITHM=COPY, LOCK=NONE
|
--connection con1
|
SET DEBUG_SYNC= 'now WAIT_FOR downgraded'; |
BEGIN; |
INSERT INTO t1 VALUES (3, 3); |
ROLLBACK; |
BEGIN; |
INSERT INTO t1 VALUES (4, 4); |
SAVEPOINT s1;
|
INSERT INTO t1 VALUES (5, 5); |
ROLLBACK TO SAVEPOINT s1; |
COMMIT; |
--error ER_DUP_ENTRY
|
INSERT INTO t1 VALUES (6, 6), (1, 1); |
SET DEBUG_SYNC= 'now SIGNAL goon'; |
--connection default
|
--reap
|
SET DEBUG_SYNC= 'RESET'; |
--let $c= query_get_value(SELECT COUNT(*) AS c FROM t1 WHERE a = 3, c, 1)
|
if ($c != 0) |
{
|
--die A row from a rolled-back transaction is in the table after an online ALTER of the partitioned table. |
}
|
--let $c= query_get_value(SELECT COUNT(*) AS c FROM t1 WHERE a = 5, c, 1)
|
if ($c != 0) |
{
|
--die A row rolled back to a savepoint is in the table after an online ALTER of the partitioned table. |
}
|
--let $c= query_get_value(SELECT COUNT(*) AS c FROM t1 WHERE a = 6, c, 1)
|
if ($c != 0) |
{
|
--die A row from a failed INSERT is in the table after an online ALTER of the partitioned table. |
}
|
SET DEBUG_SYNC= 'alter_table_online_downgraded SIGNAL downgraded WAIT_FOR goon'; |
--send ALTER TABLE t1 FORCE, ALGORITHM=COPY, LOCK=NONE
|
--connection con1
|
SET DEBUG_SYNC= 'now WAIT_FOR downgraded'; |
BEGIN; |
DELETE FROM t1 WHERE a = 1; |
ROLLBACK; |
UPDATE t1 SET b = 10 WHERE a = 1; |
SET DEBUG_SYNC= 'now SIGNAL goon'; |
--connection default
|
--error 0,ER_KEY_NOT_FOUND
|
--reap
|
--let $err= $mysql_errno
|
SET DEBUG_SYNC= 'RESET'; |
if ($err) |
{
|
--die The online ALTER of the partitioned table failed with error $err after a rolled-back DELETE. |
}
|
--disconnect con1
|
DROP TABLE t1; |
Leads to:
|
CS 13.1.2 c8e6ab229f030119c19f3208d40f415decb41dae (Debug, Clang 22.1.8-20260622) Build 19/11/2026 |
mysqltest: At line 30: A row from a rolled-back transaction is in the table after an online ALTER of the partitioned table.
|
Partitioning changes the result of an online ALTER TABLE. After the first ALTER TABLE, t1 holds the rows 1 to 6. Row 3 comes from the ROLLBACK, row 5 from the ROLLBACK TO SAVEPOINT and row 6 from the failed INSERT. Without partitioning, t1 holds the rows 1, 2 and 4.
The second ALTER TABLE fails with error 1032, "Can't find record in 't1'", and the error log gets the same message. It looks like the rolled-back DELETE removes row 1 from the new table, so the UPDATE finds no row there. Without partitioning, this ALTER TABLE works.
An optimized build gives the same without DEBUG_SYNC. With 1000000 rows in t1, a plain ALTER TABLE t1 MODIFY b BIGINT keeps a row from a ROLLBACK and a row from a failed INSERT that run while it copies the table.
MySQL 8.0.36 and 9.1.0 do not allow writes during an ALTER TABLE that copies the table: ALGORITHM=COPY, LOCK=NONE gives "LOCK=NONE is not supported. Reason: COPY algorithm requires a lock. Try LOCK=SHARED."
From the code it seems that setup_cache_data() in sql/online_alter.cc takes the engine of the online ALTER TABLE cache from share->db_type(), which for a partitioned table is the partition engine. That engine has no rollback and no savepoint_set. So online_alter_end_trans() treats the cache as non-transactional and writes the cached changes to the online ALTER TABLE log also on a rollback, and online_alter_savepoint_set() and online_alter_savepoint_rollback() skip the cache.
Attachments
Issue Links
- is caused by
-
MDEV-16329 Engine-independent online ALTER TABLE
-
- Closed
-
- relates to
-
MDEV-42344 Online ALTER TABLE (ALGORITHM=COPY, LOCK=NONE, the default): a statement that fails in a concurrent transaction is rolled back in InnoDB, but the rows it had already logged are applied to the new table at COMMIT; committed rows get deleted
-
- In Review
-