From b118f92be6b8d7294f3b57f824559ced3dcccc6b Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 9 Feb 2021 00:59:55 +0400 Subject: [PATCH] MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views. Enable the FLUSH TABLES for views. It works now. --- mysql-test/main/flush-innodb.result | 2 +- mysql-test/main/flush-innodb.test | 2 +- mysql-test/main/flush.result | 60 ++++++++++++++++++++++++--- mysql-test/main/flush.test | 64 ++++++++++++++++++++++++++--- sql/sql_reload.cc | 6 ++- sql/sql_yacc.yy | 2 - 6 files changed, 120 insertions(+), 16 deletions(-) diff --git a/mysql-test/main/flush-innodb.result b/mysql-test/main/flush-innodb.result index 21e5bda778595..2c886e4f9fcc6 100644 --- a/mysql-test/main/flush-innodb.result +++ b/mysql-test/main/flush-innodb.result @@ -60,7 +60,7 @@ DROP TABLE export; CREATE VIEW v1 AS SELECT 1; CREATE TEMPORARY TABLE t1 (a INT); FLUSH TABLES v1 FOR EXPORT; -ERROR HY000: 'test.v1' is not of type 'BASE TABLE' +UNLOCK TABLES; FLUSH TABLES t1 FOR EXPORT; ERROR 42S02: Table 'test.t1' doesn't exist FLUSH TABLES non_existent FOR EXPORT; diff --git a/mysql-test/main/flush-innodb.test b/mysql-test/main/flush-innodb.test index bf7b79bb5a3b2..309ec5de014a0 100644 --- a/mysql-test/main/flush-innodb.test +++ b/mysql-test/main/flush-innodb.test @@ -93,8 +93,8 @@ DROP TABLE export; CREATE VIEW v1 AS SELECT 1; CREATE TEMPORARY TABLE t1 (a INT); ---error ER_WRONG_OBJECT FLUSH TABLES v1 FOR EXPORT; +UNLOCK TABLES; --error ER_NO_SUCH_TABLE FLUSH TABLES t1 FOR EXPORT; --error ER_NO_SUCH_TABLE diff --git a/mysql-test/main/flush.result b/mysql-test/main/flush.result index 39e0b9432feb1..54f104430c8ef 100644 --- a/mysql-test/main/flush.result +++ b/mysql-test/main/flush.result @@ -295,16 +295,16 @@ create view v1 as select 1; create view v2 as select * from t1; create view v3 as select * from v2; flush table v1, v2, v3 with read lock; -ERROR HY000: 'test.v1' is not of type 'BASE TABLE' +unlock tables; flush table v1 with read lock; -ERROR HY000: 'test.v1' is not of type 'BASE TABLE' +unlock tables; flush table v2 with read lock; -ERROR HY000: 'test.v2' is not of type 'BASE TABLE' +unlock tables; flush table v3 with read lock; -ERROR HY000: 'test.v3' is not of type 'BASE TABLE' +unlock tables; create temporary table v1 (a int); flush table v1 with read lock; -ERROR HY000: 'test.v1' is not of type 'BASE TABLE' +unlock tables; drop view v1; create table v1 (a int); flush table v1 with read lock; @@ -556,6 +556,56 @@ UNLOCK TABLES; DROP VIEW v1; DROP TABLE t1; # +# MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views. +# +create table t1 (a int); +insert into t1 values (1), (2), (3); +create view v1 as select * from t1; +create view v2 as select * from v1; +flush table v1 with read lock; +connect con1, localhost, root; +insert into v1 values (4); +connection default; +# Wait until INSERT starts to wait for FTWRL to go away. +select * from t1; +a +1 +2 +3 +unlock tables; +connection con1; +connection default; +select * from t1; +a +1 +2 +3 +4 +flush table v2 with read lock; +connection con1; +insert into t1 values (5); +connection default; +# Wait until INSERT starts to wait for FTWRL to go away. +select * from t1; +a +1 +2 +3 +4 +unlock tables; +connection con1; +connection default; +select * from t1; +a +1 +2 +3 +4 +5 +drop view v1, v2; +drop table t1; +disconnect con1; +# # Test FLUSH THREADS # flush threads; diff --git a/mysql-test/main/flush.test b/mysql-test/main/flush.test index 6d76196bf5474..38735641bbfc0 100644 --- a/mysql-test/main/flush.test +++ b/mysql-test/main/flush.test @@ -377,17 +377,17 @@ create view v1 as select 1; create view v2 as select * from t1; create view v3 as select * from v2; ---error ER_WRONG_OBJECT flush table v1, v2, v3 with read lock; ---error ER_WRONG_OBJECT +unlock tables; flush table v1 with read lock; ---error ER_WRONG_OBJECT +unlock tables; flush table v2 with read lock; ---error ER_WRONG_OBJECT +unlock tables; flush table v3 with read lock; +unlock tables; create temporary table v1 (a int); ---error ER_WRONG_OBJECT flush table v1 with read lock; +unlock tables; drop view v1; create table v1 (a int); flush table v1 with read lock; @@ -669,6 +669,60 @@ UNLOCK TABLES; DROP VIEW v1; DROP TABLE t1; +--echo # +--echo # MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views. +--echo # + +create table t1 (a int); +insert into t1 values (1), (2), (3); +create view v1 as select * from t1; +create view v2 as select * from v1; + +flush table v1 with read lock; +connect(con1, localhost, root); +--send insert into v1 values (4) +--sleep 1 +connection default; +--echo # Wait until INSERT starts to wait for FTWRL to go away. +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table metadata lock" + and info = "insert into v1 values (4)"; +--source include/wait_condition.inc +select * from t1; +unlock tables; + +connection con1; +reap; + +connection default; +select * from t1; + +flush table v2 with read lock; +connection con1; +--send insert into t1 values (5) +--sleep 1 +connection default; +--echo # Wait until INSERT starts to wait for FTWRL to go away. +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table metadata lock" + and info = "insert into t1 values (5)"; +--source include/wait_condition.inc +select * from t1; +unlock tables; + +connection con1; +reap; + +connection default; +select * from t1; + +drop view v1, v2; +drop table t1; +disconnect con1; + + --echo # --echo # Test FLUSH THREADS --echo # diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index 2974c770252f7..0fa2fa10df812 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -592,7 +592,8 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) for (TABLE_LIST *table_list= all_tables; table_list; table_list= table_list->next_global) { - if (!(table_list->table->file->ha_table_flags() & HA_CAN_EXPORT)) + if (!(table_list->is_view() || + table_list->table->file->ha_table_flags() & HA_CAN_EXPORT)) { my_error(ER_ILLEGAL_HA, MYF(0),table_list->table->file->table_type(), table_list->db.str, table_list->table_name.str); @@ -606,7 +607,8 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) for (auto table_list= all_tables; table_list; table_list= table_list->next_global) { - if (table_list->table->file->extra(HA_EXTRA_FLUSH)) + if (!table_list->is_view() && + table_list->table->file->extra(HA_EXTRA_FLUSH)) goto error_reset_bits; } } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 37cdfc20030ab..6c553e4878f9d 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -14426,8 +14426,6 @@ opt_flush_lock: for (; tables; tables= tables->next_global) { tables->mdl_request.set_type(MDL_SHARED_NO_WRITE); - /* Don't try to flush views. */ - tables->required_type= TABLE_TYPE_NORMAL; /* Ignore temporary tables. */ tables->open_type= OT_BASE_ONLY; }