Skip to content

Commit b118f92

Browse files
author
Alexey Botchkov
committed
MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views.
Enable the FLUSH TABLES for views. It works now.
1 parent be8e51c commit b118f92

File tree

6 files changed

+120
-16
lines changed

6 files changed

+120
-16
lines changed

mysql-test/main/flush-innodb.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ DROP TABLE export;
6060
CREATE VIEW v1 AS SELECT 1;
6161
CREATE TEMPORARY TABLE t1 (a INT);
6262
FLUSH TABLES v1 FOR EXPORT;
63-
ERROR HY000: 'test.v1' is not of type 'BASE TABLE'
63+
UNLOCK TABLES;
6464
FLUSH TABLES t1 FOR EXPORT;
6565
ERROR 42S02: Table 'test.t1' doesn't exist
6666
FLUSH TABLES non_existent FOR EXPORT;

mysql-test/main/flush-innodb.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ DROP TABLE export;
9393
CREATE VIEW v1 AS SELECT 1;
9494
CREATE TEMPORARY TABLE t1 (a INT);
9595

96-
--error ER_WRONG_OBJECT
9796
FLUSH TABLES v1 FOR EXPORT;
97+
UNLOCK TABLES;
9898
--error ER_NO_SUCH_TABLE
9999
FLUSH TABLES t1 FOR EXPORT;
100100
--error ER_NO_SUCH_TABLE

mysql-test/main/flush.result

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,16 +295,16 @@ create view v1 as select 1;
295295
create view v2 as select * from t1;
296296
create view v3 as select * from v2;
297297
flush table v1, v2, v3 with read lock;
298-
ERROR HY000: 'test.v1' is not of type 'BASE TABLE'
298+
unlock tables;
299299
flush table v1 with read lock;
300-
ERROR HY000: 'test.v1' is not of type 'BASE TABLE'
300+
unlock tables;
301301
flush table v2 with read lock;
302-
ERROR HY000: 'test.v2' is not of type 'BASE TABLE'
302+
unlock tables;
303303
flush table v3 with read lock;
304-
ERROR HY000: 'test.v3' is not of type 'BASE TABLE'
304+
unlock tables;
305305
create temporary table v1 (a int);
306306
flush table v1 with read lock;
307-
ERROR HY000: 'test.v1' is not of type 'BASE TABLE'
307+
unlock tables;
308308
drop view v1;
309309
create table v1 (a int);
310310
flush table v1 with read lock;
@@ -556,6 +556,56 @@ UNLOCK TABLES;
556556
DROP VIEW v1;
557557
DROP TABLE t1;
558558
#
559+
# MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views.
560+
#
561+
create table t1 (a int);
562+
insert into t1 values (1), (2), (3);
563+
create view v1 as select * from t1;
564+
create view v2 as select * from v1;
565+
flush table v1 with read lock;
566+
connect con1, localhost, root;
567+
insert into v1 values (4);
568+
connection default;
569+
# Wait until INSERT starts to wait for FTWRL to go away.
570+
select * from t1;
571+
a
572+
1
573+
2
574+
3
575+
unlock tables;
576+
connection con1;
577+
connection default;
578+
select * from t1;
579+
a
580+
1
581+
2
582+
3
583+
4
584+
flush table v2 with read lock;
585+
connection con1;
586+
insert into t1 values (5);
587+
connection default;
588+
# Wait until INSERT starts to wait for FTWRL to go away.
589+
select * from t1;
590+
a
591+
1
592+
2
593+
3
594+
4
595+
unlock tables;
596+
connection con1;
597+
connection default;
598+
select * from t1;
599+
a
600+
1
601+
2
602+
3
603+
4
604+
5
605+
drop view v1, v2;
606+
drop table t1;
607+
disconnect con1;
608+
#
559609
# Test FLUSH THREADS
560610
#
561611
flush threads;

mysql-test/main/flush.test

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,17 +377,17 @@ create view v1 as select 1;
377377
create view v2 as select * from t1;
378378
create view v3 as select * from v2;
379379

380-
--error ER_WRONG_OBJECT
381380
flush table v1, v2, v3 with read lock;
382-
--error ER_WRONG_OBJECT
381+
unlock tables;
383382
flush table v1 with read lock;
384-
--error ER_WRONG_OBJECT
383+
unlock tables;
385384
flush table v2 with read lock;
386-
--error ER_WRONG_OBJECT
385+
unlock tables;
387386
flush table v3 with read lock;
387+
unlock tables;
388388
create temporary table v1 (a int);
389-
--error ER_WRONG_OBJECT
390389
flush table v1 with read lock;
390+
unlock tables;
391391
drop view v1;
392392
create table v1 (a int);
393393
flush table v1 with read lock;
@@ -669,6 +669,60 @@ UNLOCK TABLES;
669669
DROP VIEW v1;
670670
DROP TABLE t1;
671671

672+
--echo #
673+
--echo # MDEV-15888 Implement FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK for views.
674+
--echo #
675+
676+
create table t1 (a int);
677+
insert into t1 values (1), (2), (3);
678+
create view v1 as select * from t1;
679+
create view v2 as select * from v1;
680+
681+
flush table v1 with read lock;
682+
connect(con1, localhost, root);
683+
--send insert into v1 values (4)
684+
--sleep 1
685+
connection default;
686+
--echo # Wait until INSERT starts to wait for FTWRL to go away.
687+
let $wait_condition=
688+
select count(*) = 1 from information_schema.processlist
689+
where state = "Waiting for table metadata lock"
690+
and info = "insert into v1 values (4)";
691+
--source include/wait_condition.inc
692+
select * from t1;
693+
unlock tables;
694+
695+
connection con1;
696+
reap;
697+
698+
connection default;
699+
select * from t1;
700+
701+
flush table v2 with read lock;
702+
connection con1;
703+
--send insert into t1 values (5)
704+
--sleep 1
705+
connection default;
706+
--echo # Wait until INSERT starts to wait for FTWRL to go away.
707+
let $wait_condition=
708+
select count(*) = 1 from information_schema.processlist
709+
where state = "Waiting for table metadata lock"
710+
and info = "insert into t1 values (5)";
711+
--source include/wait_condition.inc
712+
select * from t1;
713+
unlock tables;
714+
715+
connection con1;
716+
reap;
717+
718+
connection default;
719+
select * from t1;
720+
721+
drop view v1, v2;
722+
drop table t1;
723+
disconnect con1;
724+
725+
672726
--echo #
673727
--echo # Test FLUSH THREADS
674728
--echo #

sql/sql_reload.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables)
592592
for (TABLE_LIST *table_list= all_tables; table_list;
593593
table_list= table_list->next_global)
594594
{
595-
if (!(table_list->table->file->ha_table_flags() & HA_CAN_EXPORT))
595+
if (!(table_list->is_view() ||
596+
table_list->table->file->ha_table_flags() & HA_CAN_EXPORT))
596597
{
597598
my_error(ER_ILLEGAL_HA, MYF(0),table_list->table->file->table_type(),
598599
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)
606607
for (auto table_list= all_tables; table_list;
607608
table_list= table_list->next_global)
608609
{
609-
if (table_list->table->file->extra(HA_EXTRA_FLUSH))
610+
if (!table_list->is_view() &&
611+
table_list->table->file->extra(HA_EXTRA_FLUSH))
610612
goto error_reset_bits;
611613
}
612614
}

sql/sql_yacc.yy

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14426,8 +14426,6 @@ opt_flush_lock:
1442614426
for (; tables; tables= tables->next_global)
1442714427
{
1442814428
tables->mdl_request.set_type(MDL_SHARED_NO_WRITE);
14429-
/* Don't try to flush views. */
14430-
tables->required_type= TABLE_TYPE_NORMAL;
1443114429
/* Ignore temporary tables. */
1443214430
tables->open_type= OT_BASE_ONLY;
1443314431
}

0 commit comments

Comments
 (0)