Commit b118f92b authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views.

Enable the FLUSH TABLES for views. It works now.
parent be8e51c4
......@@ -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;
......
......@@ -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
......
......@@ -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;
......
......@@ -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 #
......
......@@ -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;
}
}
......
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment