summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2019-03-22 16:26:42 +1000
committerMarko Mäkelä <marko.makela@mariadb.com>2019-12-29 12:16:04 +0200
commit720e9bd5bed73fdc5b2452a6400431e08ae7eb6f (patch)
treebccb0e9de01281ad94942679d4302ee1e9f24246
parent808bc919eb94ac888f2014275b443ebdaf733ae5 (diff)
downloadmariadb-git-720e9bd5bed73fdc5b2452a6400431e08ae7eb6f.tar.gz
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.
-rw-r--r--mysql-test/suite/versioning/r/trx_id.result13
-rw-r--r--mysql-test/suite/versioning/t/trx_id.test15
-rw-r--r--sql/handler.cc3
3 files changed, 30 insertions, 1 deletions
diff --git a/mysql-test/suite/versioning/r/trx_id.result b/mysql-test/suite/versioning/r/trx_id.result
index 413272f55f9..7c4a540c52a 100644
--- a/mysql-test/suite/versioning/r/trx_id.result
+++ b/mysql-test/suite/versioning/r/trx_id.result
@@ -476,3 +476,16 @@ SET @@SYSTEM_VERSIONING_ALTER_HISTORY=ERROR;
SELECT count(*) from mysql.transaction_registry where begin_timestamp>=commit_timestamp;
count(*)
0
+# MDEV-18875 Assertion `thd->transaction.stmt.ha_list == __null ||
+# trans == &thd->transaction.stmt' failed or bogus ER_DUP_ENTRY upon
+# ALTER TABLE with versioning
+create or replace table t (x int) engine=innodb;
+set autocommit= 0;
+alter table t
+algorithm=copy,
+add column row_start bigint unsigned as row start,
+add column row_end bigint unsigned as row end,
+add period for system_time(row_start,row_end),
+with system versioning;
+set autocommit= 1;
+create or replace database test;
diff --git a/mysql-test/suite/versioning/t/trx_id.test b/mysql-test/suite/versioning/t/trx_id.test
index 617c46a9332..97935ffc975 100644
--- a/mysql-test/suite/versioning/t/trx_id.test
+++ b/mysql-test/suite/versioning/t/trx_id.test
@@ -498,3 +498,18 @@ DROP TABLE t;
SET @@SYSTEM_VERSIONING_ALTER_HISTORY=ERROR;
SELECT count(*) from mysql.transaction_registry where begin_timestamp>=commit_timestamp;
+
+--echo # MDEV-18875 Assertion `thd->transaction.stmt.ha_list == __null ||
+--echo # trans == &thd->transaction.stmt' failed or bogus ER_DUP_ENTRY upon
+--echo # ALTER TABLE with versioning
+create or replace table t (x int) engine=innodb;
+set autocommit= 0;
+alter table t
+ algorithm=copy,
+ add column row_start bigint unsigned as row start,
+ add column row_end bigint unsigned as row end,
+ add period for system_time(row_start,row_end),
+ with system versioning;
+set autocommit= 1;
+
+create or replace database test;
diff --git a/sql/handler.cc b/sql/handler.cc
index 1494060e24d..4e2c6afda80 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -1446,7 +1446,8 @@ int ha_commit_trans(THD *thd, bool all)
#if 1 // FIXME: This should be done in ha_prepare().
if (rw_trans || (thd->lex->sql_command == SQLCOM_ALTER_TABLE &&
- thd->lex->alter_info.flags & ALTER_ADD_SYSTEM_VERSIONING))
+ thd->lex->alter_info.flags & ALTER_ADD_SYSTEM_VERSIONING &&
+ is_real_trans))
{
ulonglong trx_start_id= 0, trx_end_id= 0;
for (Ha_trx_info *ha_info= trans->ha_list; ha_info; ha_info= ha_info->next())