Skip to content

Commit 720e9bd

Browse files
FooBarriordr-m
authored andcommitted
MDEV-18875 Assertion `thd->transaction.stmt.ha_list == __null || trans == &thd->transaction.stmt' failed or bogus ER_DUP_ENTRY upon ALTER TABLE with versioning
Cause: * when autocommit=0 (or transaction is issued by user), `ha_commit_trans` is called twice on ALTER TABLE, causing a duplicated insert into `transaction_registry` (ER_DUP_ENTRY). Solution: * ALTER TABLE makes an implicit commit by a second call. We actually need to make an insert only when it is a real commit. So is_real variable is additionally checked.
1 parent 808bc91 commit 720e9bd

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

mysql-test/suite/versioning/r/trx_id.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,3 +476,16 @@ SET @@SYSTEM_VERSIONING_ALTER_HISTORY=ERROR;
476476
SELECT count(*) from mysql.transaction_registry where begin_timestamp>=commit_timestamp;
477477
count(*)
478478
0
479+
# MDEV-18875 Assertion `thd->transaction.stmt.ha_list == __null ||
480+
# trans == &thd->transaction.stmt' failed or bogus ER_DUP_ENTRY upon
481+
# ALTER TABLE with versioning
482+
create or replace table t (x int) engine=innodb;
483+
set autocommit= 0;
484+
alter table t
485+
algorithm=copy,
486+
add column row_start bigint unsigned as row start,
487+
add column row_end bigint unsigned as row end,
488+
add period for system_time(row_start,row_end),
489+
with system versioning;
490+
set autocommit= 1;
491+
create or replace database test;

mysql-test/suite/versioning/t/trx_id.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,18 @@ DROP TABLE t;
498498
SET @@SYSTEM_VERSIONING_ALTER_HISTORY=ERROR;
499499

500500
SELECT count(*) from mysql.transaction_registry where begin_timestamp>=commit_timestamp;
501+
502+
--echo # MDEV-18875 Assertion `thd->transaction.stmt.ha_list == __null ||
503+
--echo # trans == &thd->transaction.stmt' failed or bogus ER_DUP_ENTRY upon
504+
--echo # ALTER TABLE with versioning
505+
create or replace table t (x int) engine=innodb;
506+
set autocommit= 0;
507+
alter table t
508+
algorithm=copy,
509+
add column row_start bigint unsigned as row start,
510+
add column row_end bigint unsigned as row end,
511+
add period for system_time(row_start,row_end),
512+
with system versioning;
513+
set autocommit= 1;
514+
515+
create or replace database test;

sql/handler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,8 @@ int ha_commit_trans(THD *thd, bool all)
14461446

14471447
#if 1 // FIXME: This should be done in ha_prepare().
14481448
if (rw_trans || (thd->lex->sql_command == SQLCOM_ALTER_TABLE &&
1449-
thd->lex->alter_info.flags & ALTER_ADD_SYSTEM_VERSIONING))
1449+
thd->lex->alter_info.flags & ALTER_ADD_SYSTEM_VERSIONING &&
1450+
is_real_trans))
14501451
{
14511452
ulonglong trx_start_id= 0, trx_end_id= 0;
14521453
for (Ha_trx_info *ha_info= trans->ha_list; ha_info; ha_info= ha_info->next())

0 commit comments

Comments
 (0)