diff options
-rw-r--r-- | mysql-test/r/flush.result | 50 | ||||
-rw-r--r-- | mysql-test/t/flush.test | 31 | ||||
-rw-r--r-- | sql/sql_base.cc | 6 | ||||
-rw-r--r-- | sql/sql_base.h | 5 | ||||
-rw-r--r-- | sql/sql_reload.cc | 42 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 4 |
6 files changed, 117 insertions, 21 deletions
diff --git a/mysql-test/r/flush.result b/mysql-test/r/flush.result index aee18d91edf..ced8306c3ab 100644 --- a/mysql-test/r/flush.result +++ b/mysql-test/r/flush.result @@ -373,3 +373,53 @@ commit; # --> connection con2 # --> connection default drop table t1; +# +# Test for bug #55273 "FLUSH TABLE tm WITH READ LOCK for Merge table +# causes assert failure". +# +drop table if exists t1, t2, tm; +create table t1 (i int); +create table t2 (i int); +create table tm (i int) engine=merge union=(t1, t2); +insert into t1 values (1), (2); +insert into t2 values (3), (4); +# The below statement should succeed and lock merge +# table for read. Only merge table gets flushed and +# not underlying tables. +flush tables tm with read lock; +select * from tm; +i +1 +2 +3 +4 +# Check that underlying tables are locked. +select * from t1; +i +1 +2 +select * from t2; +i +3 +4 +unlock tables; +# This statement should succeed as well and flush +# all tables in the list. +flush tables tm, t1, t2 with read lock; +select * from tm; +i +1 +2 +3 +4 +# Naturally, underlying tables should be locked in this case too. +select * from t1; +i +1 +2 +select * from t2; +i +3 +4 +unlock tables; +drop tables tm, t1, t2; diff --git a/mysql-test/t/flush.test b/mysql-test/t/flush.test index d4c3533847d..1cafbe3e6bd 100644 --- a/mysql-test/t/flush.test +++ b/mysql-test/t/flush.test @@ -546,3 +546,34 @@ disconnect con2; connection default; drop table t1; + +--echo # +--echo # Test for bug #55273 "FLUSH TABLE tm WITH READ LOCK for Merge table +--echo # causes assert failure". +--echo # +--disable_warnings +drop table if exists t1, t2, tm; +--enable_warnings +create table t1 (i int); +create table t2 (i int); +create table tm (i int) engine=merge union=(t1, t2); +insert into t1 values (1), (2); +insert into t2 values (3), (4); +--echo # The below statement should succeed and lock merge +--echo # table for read. Only merge table gets flushed and +--echo # not underlying tables. +flush tables tm with read lock; +select * from tm; +--echo # Check that underlying tables are locked. +select * from t1; +select * from t2; +unlock tables; +--echo # This statement should succeed as well and flush +--echo # all tables in the list. +flush tables tm, t1, t2 with read lock; +select * from tm; +--echo # Naturally, underlying tables should be locked in this case too. +select * from t1; +select * from t2; +unlock tables; +drop tables tm, t1, t2; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 8cd0ce4432a..e2eb836a958 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4522,13 +4522,15 @@ lock_table_names(THD *thd, ! (flags & MYSQL_OPEN_SKIP_TEMPORARY) && find_temporary_table(thd, table)))) { - if (schema_set.insert(table)) + if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) && + schema_set.insert(table)) return TRUE; mdl_requests.push_front(&table->mdl_request); } } - if (! mdl_requests.is_empty()) + if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) && + ! mdl_requests.is_empty()) { /* Scoped locks: Take intention exclusive locks on all involved diff --git a/sql/sql_base.h b/sql/sql_base.h index a21850355b4..b1a730ad277 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -122,6 +122,11 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update, (LONG_TIMEOUT = 1 year) rather than the user-supplied timeout value. */ #define MYSQL_LOCK_IGNORE_TIMEOUT 0x0800 +/** + When acquiring "strong" (SNW, SNRW, X) metadata locks on tables to + be open do not acquire global and schema-scope IX locks. +*/ +#define MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK 0x1000 /** Please refer to the internals manual. */ #define MYSQL_OPEN_REOPEN (MYSQL_OPEN_IGNORE_FLUSH |\ diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index bf38af78536..35f27408247 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -328,7 +328,6 @@ bool reload_acl_and_cache(THD *thd, unsigned long options, ------------------------------------- - you can't flush WITH READ LOCK a non-existent table - you can't flush WITH READ LOCK under LOCK TABLES - - currently incompatible with the GRL (@todo: fix) Effect on views and temporary tables. ------------------------------------ @@ -338,6 +337,13 @@ bool reload_acl_and_cache(THD *thd, unsigned long options, if there is a base table, it's used, otherwise ER_NO_SUCH_TABLE is returned. + Handling of MERGE tables + ------------------------ + For MERGE table this statement will open and lock child tables + for read (it is impossible to lock parent table without it). + Child tables won't be flushed unless they are explicitly present + in the statement's table list. + Implicit commit --------------- This statement causes an implicit commit before and @@ -354,7 +360,6 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) { Lock_tables_prelocking_strategy lock_tables_prelocking_strategy; TABLE_LIST *table_list; - MDL_request_list mdl_requests; /* This is called from SQLCOM_FLUSH, the transaction has @@ -368,17 +373,13 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) } /* - Acquire SNW locks on tables to be flushed. We can't use - lock_table_names() here as this call will also acquire global IX - and database-scope IX locks on the tables, and this will make + Acquire SNW locks on tables to be flushed. Don't acquire global + IX and database-scope IX locks on the tables as this will make this statement incompatible with FLUSH TABLES WITH READ LOCK. */ - for (table_list= all_tables; table_list; - table_list= table_list->next_global) - mdl_requests.push_front(&table_list->mdl_request); - - if (thd->mdl_context.acquire_locks(&mdl_requests, - thd->variables.lock_wait_timeout)) + if (lock_table_names(thd, all_tables, NULL, + thd->variables.lock_wait_timeout, + MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK)) goto error; DEBUG_SYNC(thd,"flush_tables_with_read_lock_after_acquire_locks"); @@ -390,21 +391,24 @@ bool flush_tables_with_read_lock(THD *thd, TABLE_LIST *all_tables) tdc_remove_table(thd, TDC_RT_REMOVE_UNUSED, table_list->db, table_list->table_name, FALSE); - - /* Skip views and temporary tables. */ - table_list->required_type= FRMTYPE_TABLE; /* Don't try to flush views. */ - table_list->open_type= OT_BASE_ONLY; /* Ignore temporary tables. */ + /* Reset ticket to satisfy asserts in open_tables(). */ + table_list->mdl_request.ticket= NULL; } /* Before opening and locking tables the below call also waits for old shares to go away, so the fact that we don't pass MYSQL_LOCK_IGNORE_FLUSH flag to it is important. + Also we don't pass MYSQL_OPEN_HAS_MDL_LOCK flag as we want + to open underlying tables if merge table is flushed. + For underlying tables of the merge the below call has to + acquire SNW locks to ensure that they can be locked for + read without further waiting. */ - if (open_and_lock_tables(thd, all_tables, FALSE, - MYSQL_OPEN_HAS_MDL_LOCK, - &lock_tables_prelocking_strategy) || - thd->locked_tables_list.init_locked_tables(thd)) + if (open_and_lock_tables(thd, all_tables, FALSE, + MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK, + &lock_tables_prelocking_strategy) || + thd->locked_tables_list.init_locked_tables(thd)) { goto error; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 83e9078f5cb..2ee2d83f9d2 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -11278,7 +11278,11 @@ opt_with_read_lock: TABLE_LIST *tables= Lex->query_tables; Lex->type|= REFRESH_READ_LOCK; for (; tables; tables= tables->next_global) + { tables->mdl_request.set_type(MDL_SHARED_NO_WRITE); + tables->required_type= FRMTYPE_TABLE; /* Don't try to flush views. */ + tables->open_type= OT_BASE_ONLY; /* Ignore temporary tables. */ + } } ; |