diff options
-rw-r--r-- | mysql-test/suite/innodb/r/stat_tables.result | 15 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/stat_tables.test | 17 | ||||
-rw-r--r-- | sql/sql_class.h | 4 | ||||
-rw-r--r-- | sql/sql_statistics.cc | 2 |
4 files changed, 38 insertions, 0 deletions
diff --git a/mysql-test/suite/innodb/r/stat_tables.result b/mysql-test/suite/innodb/r/stat_tables.result new file mode 100644 index 00000000000..bb449570479 --- /dev/null +++ b/mysql-test/suite/innodb/r/stat_tables.result @@ -0,0 +1,15 @@ +rename table mysql.table_stats to mysql.table_stats_save; +flush tables; +set use_stat_tables= PREFERABLY; +create table t1 (a int) engine=InnoDB; +start transaction; +insert t1 values (1); +insert t1 values (2); +commit; +select * from t1; +a +1 +2 +drop table t1; +rename table mysql.table_stats_save to mysql.table_stats; +flush tables; diff --git a/mysql-test/suite/innodb/t/stat_tables.test b/mysql-test/suite/innodb/t/stat_tables.test new file mode 100644 index 00000000000..68344b3f425 --- /dev/null +++ b/mysql-test/suite/innodb/t/stat_tables.test @@ -0,0 +1,17 @@ +source include/have_innodb.inc; + +# +# MDEV-20354 All but last insert ignored in InnoDB tables when table locked +# +rename table mysql.table_stats to mysql.table_stats_save; +flush tables; +set use_stat_tables= PREFERABLY; +create table t1 (a int) engine=InnoDB; +start transaction; +insert t1 values (1); +insert t1 values (2); +commit; +select * from t1; +drop table t1; +rename table mysql.table_stats_save to mysql.table_stats; +flush tables; diff --git a/sql/sql_class.h b/sql/sql_class.h index 6c622648ac7..56bb9f45877 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1444,12 +1444,16 @@ public: /** @class Sub_statement_state @brief Used to save context when executing a function or trigger + + operations on stat tables aren't technically a sub-statement, but they are + similar in a sense that they cannot change the transaction status. */ /* Defines used for Sub_statement_state::in_sub_stmt */ #define SUB_STMT_TRIGGER 1 #define SUB_STMT_FUNCTION 2 +#define SUB_STMT_STAT_TABLES 4 class Sub_statement_state diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 4a1ed9cde4e..f002a5a5eab 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -268,7 +268,9 @@ inline int open_stat_tables(THD *thd, TABLE_LIST *tables, thd->push_internal_handler(&deh); init_table_list_for_stat_tables(tables, for_write); init_mdl_requests(tables); + thd->in_sub_stmt|= SUB_STMT_STAT_TABLES; rc= open_system_tables_for_read(thd, tables, backup); + thd->in_sub_stmt&= ~SUB_STMT_STAT_TABLES; thd->pop_internal_handler(); |