diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index a678c03763c..978a299d23b 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -345,5 +345,14 @@ create trigger tr before insert on t2 for each row select table_rows from information_schema.tables where table_name = 't1' into @a; insert into t2 values (1); +# MDEV-14740 Locking assertion for system_time partitioning +create or replace table t1 (i int) with system versioning +partition by system_time interval 1 week ( +partition p1 history, +partition pn current); +create or replace table t2 (f int); +create trigger tr before insert on t2 +for each row select count(*) from t1 into @a; +insert into t2 values (1); drop table t1; drop table t2; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index 10eb44357dc..0f962f74f65 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -293,6 +293,16 @@ for each row select table_rows from information_schema.tables where table_name = 't1' into @a; insert into t2 values (1); +--echo # MDEV-14740 Locking assertion for system_time partitioning +create or replace table t1 (i int) with system versioning +partition by system_time interval 1 week ( + partition p1 history, + partition pn current); +create or replace table t2 (f int); +create trigger tr before insert on t2 +for each row select count(*) from t1 into @a; +insert into t2 values (1); + drop table t1; drop table t2; diff --git a/sql/partition_info.cc b/sql/partition_info.cc index ec6cebcafb8..98f83209874 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -1035,18 +1035,20 @@ class Table_locker { THD *thd; TABLE &table; - thr_lock_type saved_mode; - TABLE_LIST table_list; + thr_lock_type saved_type; MYSQL_LOCK *saved_lock; + enum_locked_tables_mode saved_mode; + TABLE_LIST table_list; bool locked; public: Table_locker(THD *_thd, TABLE &_table, thr_lock_type lock_type) : thd(_thd), table(_table), - saved_mode(table.reginfo.lock_type), - table_list(_table, lock_type), + saved_type(table.reginfo.lock_type), saved_lock(_thd->lock), + saved_mode(_thd->locked_tables_mode), + table_list(_table, lock_type), locked(false) { table.reginfo.lock_type= lock_type; @@ -1066,8 +1068,9 @@ public: { if (locked) mysql_unlock_tables(thd, thd->lock); - table.reginfo.lock_type= saved_mode; + table.reginfo.lock_type= saved_type; thd->lock= saved_lock; + thd->locked_tables_mode= saved_mode; if (locked && !thd->in_sub_stmt) ha_commit_trans(thd, false); }