diff --git a/sql/handler.cc b/sql/handler.cc index 06abd149aa5a9..80e9896fcb797 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -5105,20 +5105,17 @@ static my_bool discover_handlerton(THD *thd, plugin_ref plugin, int ha_discover_table(THD *thd, TABLE_SHARE *share) { DBUG_ENTER("ha_discover_table"); - int found; DBUG_ASSERT(share->error == OPEN_FRM_OPEN_ERROR); // share is not OK yet - if (!engines_with_discover) - found= FALSE; - else if (share->db_plugin) - found= discover_handlerton(thd, share->db_plugin, share); - else - found= plugin_foreach(thd, discover_handlerton, - MYSQL_STORAGE_ENGINE_PLUGIN, share); - - if (!found) - open_table_error(share, OPEN_FRM_OPEN_ERROR, ENOENT); // not found + if (engines_with_discover) + { + if (share->db_plugin) + (void) discover_handlerton(thd, share->db_plugin, share); + else + (void) plugin_foreach(thd, discover_handlerton, + MYSQL_STORAGE_ENGINE_PLUGIN, share); + } DBUG_RETURN(share->error != OPEN_FRM_OK); } @@ -5155,44 +5152,6 @@ static my_bool discover_existence(THD *thd, plugin_ref plugin, return ht->discover_table_existence(ht, args->db, args->table_name); } -class Table_exists_error_handler : public Internal_error_handler -{ -public: - Table_exists_error_handler() - : m_handled_errors(0), m_unhandled_errors(0) - {} - - bool handle_condition(THD *thd, - uint sql_errno, - const char* sqlstate, - Sql_condition::enum_warning_level *level, - const char* msg, - Sql_condition ** cond_hdl) - { - *cond_hdl= NULL; - if (sql_errno == ER_NO_SUCH_TABLE || - sql_errno == ER_NO_SUCH_TABLE_IN_ENGINE || - sql_errno == ER_WRONG_OBJECT) - { - m_handled_errors++; - return TRUE; - } - - if (*level == Sql_condition::WARN_LEVEL_ERROR) - m_unhandled_errors++; - return FALSE; - } - - bool safely_trapped_errors() - { - return ((m_handled_errors > 0) && (m_unhandled_errors == 0)); - } - -private: - int m_handled_errors; - int m_unhandled_errors; -}; - /** Check if a given table exists, without doing a full discover, if possible @@ -5294,11 +5253,11 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_n if (!hton) flags|= GTS_NOLOCK; - Table_exists_error_handler no_such_table_handler; - thd->push_internal_handler(&no_such_table_handler); table.init_one_table(db, table_name, 0, TL_READ); TABLE_SHARE *share= tdc_acquire_share(thd, &table, flags); - thd->pop_internal_handler(); + + if (!share) + DBUG_RETURN(FALSE); if (hton && share) { @@ -5306,8 +5265,6 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_n tdc_release_share(share); } - // the table doesn't exist if we've caught ER_NO_SUCH_TABLE and nothing else - DBUG_RETURN(!no_such_table_handler.safely_trapped_errors()); } DBUG_RETURN(FALSE); diff --git a/sql/table.cc b/sql/table.cc index 549814a57bc4a..fe20eeb183071 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -576,7 +576,6 @@ inline bool is_system_table_name(const char *name, size_t length) enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) { - bool error_given= false; File file; uchar *buf; uchar head[FRM_HEADER_SIZE]; @@ -606,9 +605,8 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) if ((flags & GTS_TABLE) && (flags & GTS_USE_DISCOVERY)) { ha_discover_table(thd, share); - error_given= true; + DBUG_RETURN(share->error); } - goto err_not_open; } if (mysql_file_read(file, head, sizeof(head), MYF(MY_NABP))) @@ -671,7 +669,6 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) frmlen= read_length + sizeof(head); share->init_from_binary_frm_image(thd, false, buf, frmlen); - error_given= true; // init_from_binary_frm_image has already called my_error() my_free(buf); goto err_not_open; @@ -680,7 +677,7 @@ enum open_frm_error open_table_def(THD *thd, TABLE_SHARE *share, uint flags) mysql_file_close(file, MYF(MY_WME)); err_not_open: - if (share->error && !error_given) + if (share->error) { share->open_errno= my_errno; open_table_error(share, share->error, share->open_errno);