From 38c91c067ba36e1bdc11ded707db9b9f0c84b871 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 28 Nov 2013 16:39:17 +0100 Subject: [PATCH] MDEV-4955 discover of table non-existance on CREATE when frm file exists, but the table does not. In recover_from_failed_open(), allow the discovery to fail without an error, when open_strategy == TABLE_LIST::OPEN_IF_EXISTS. --- mysql-test/suite/archive/discover.result | 6 +++++ mysql-test/suite/archive/discover.test | 10 +++++++++ sql/sql_base.cc | 28 ++++++++++++++++-------- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/archive/discover.result b/mysql-test/suite/archive/discover.result index a2a0bfcd8d5..c4f4bb4104f 100644 --- a/mysql-test/suite/archive/discover.result +++ b/mysql-test/suite/archive/discover.result @@ -130,3 +130,9 @@ a flush tables; select * from t1; ERROR 42S02: Table 'test.t1' doesn't exist +create table t1 (a int) engine=archive; +select * from t1; +a +flush tables; +create table t1 (a int) engine=archive; +drop table t1; diff --git a/mysql-test/suite/archive/discover.test b/mysql-test/suite/archive/discover.test index ad53ffa78c8..8dfe09f7b33 100644 --- a/mysql-test/suite/archive/discover.test +++ b/mysql-test/suite/archive/discover.test @@ -118,3 +118,13 @@ remove_file $mysqld_datadir/test/t1.ARZ; select * from t1; --list_files $mysqld_datadir/test +# +# MDEV-4955 discover of table non-existance on CREATE +# +create table t1 (a int) engine=archive; +select * from t1; +flush tables; +remove_file $mysqld_datadir/test/t1.ARZ; +create table t1 (a int) engine=archive; +drop table t1; + diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 0eed69e093e..62def81b6ed 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2269,12 +2269,12 @@ bool open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root, { if (!ha_table_exists(thd, table_list->db, table_list->table_name)) DBUG_RETURN(FALSE); - - /* Table exists. Let us try to open it. */ } else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB) DBUG_RETURN(FALSE); + /* Table exists. Let us try to open it. */ + if (table_list->i_s_requested_object & OPEN_TABLE_ONLY) gts_flags= GTS_TABLE; else if (table_list->i_s_requested_object & OPEN_VIEW_ONLY) @@ -3290,6 +3290,7 @@ request_backoff_action(enum_open_table_action action_arg, table->table_name, table->table_name_length, table->alias, TL_WRITE); + m_failed_table->open_strategy= table->open_strategy; m_failed_table->mdl_request.set_type(MDL_EXCLUSIVE); } m_action= action_arg; @@ -3310,8 +3311,7 @@ request_backoff_action(enum_open_table_action action_arg, */ bool -Open_table_context:: -recover_from_failed_open(THD *thd) +Open_table_context::recover_from_failed_open(THD *thd) { bool result= FALSE; /* Execute the action. */ @@ -3333,11 +3333,21 @@ recover_from_failed_open(THD *thd) thd->get_stmt_da()->clear_warning_info(thd->query_id); thd->clear_error(); // Clear error message - if ((result= - !tdc_acquire_share(thd, m_failed_table->db, - m_failed_table->table_name, - GTS_TABLE | GTS_FORCE_DISCOVERY | GTS_NOLOCK))) - break; + No_such_table_error_handler no_such_table_handler; + bool open_if_exists= m_failed_table->open_strategy == TABLE_LIST::OPEN_IF_EXISTS; + + if (open_if_exists) + thd->push_internal_handler(&no_such_table_handler); + + result= !tdc_acquire_share(thd, m_failed_table->db, + m_failed_table->table_name, + GTS_TABLE | GTS_FORCE_DISCOVERY | GTS_NOLOCK); + if (open_if_exists) + { + thd->pop_internal_handler(); + if (result && no_such_table_handler.safely_trapped_errors()) + result= FALSE; + } thd->mdl_context.release_transactional_locks(); break;