Skip to content

Commit

Permalink
MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ…
Browse files Browse the repository at this point in the history
… LOCK for views.

Enable the FLUSH TABLES for views. It works now.
  • Loading branch information
Alexey Botchkov committed May 31, 2021
1 parent be8e51c commit b118f92
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 16 deletions.
2 changes: 1 addition & 1 deletion mysql-test/main/flush-innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/main/flush-innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
60 changes: 55 additions & 5 deletions mysql-test/main/flush.result
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
64 changes: 59 additions & 5 deletions mysql-test/main/flush.test
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 #
Expand Down
6 changes: 4 additions & 2 deletions sql/sql_reload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down
2 changes: 0 additions & 2 deletions sql/sql_yacc.yy
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b118f92

Please sign in to comment.