diff --git a/mysql-test/main/stat_tables_missing.result b/mysql-test/main/stat_tables_missing.result index 3f8f9e982ae..f7a1fcfbb90 100644 --- a/mysql-test/main/stat_tables_missing.result +++ b/mysql-test/main/stat_tables_missing.result @@ -2,6 +2,9 @@ create table t1 (a int); alter table mysql.column_stats rename to mysql.column_stats1; flush tables; alter table t1 change a b varchar(100); +Warnings: +Warning 1177 Got error 1146 when trying to open statistics table `table_stats` for updating statistics +Warning 1177 Got error 1146 when trying to open statistics table `table_stats` for updating statistics show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 5398763b16e..fceafcb1a18 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -73,6 +73,8 @@ No_such_table_error_handler::handle_condition(THD *, Sql_condition ** cond_hdl) { *cond_hdl= NULL; + if (!first_error) + first_error= sql_errno; if (sql_errno == ER_NO_SUCH_TABLE || sql_errno == ER_NO_SUCH_TABLE_IN_ENGINE) { m_handled_errors++; @@ -95,7 +97,6 @@ bool No_such_table_error_handler::safely_trapped_errors() return ((m_handled_errors > 0) && (m_unhandled_errors == 0)); } - /** This internal handler is used to trap ER_NO_SUCH_TABLE and ER_WRONG_MRG_TABLE errors during CHECK/REPAIR TABLE for MERGE diff --git a/sql/sql_base.h b/sql/sql_base.h index a67d28f47c9..89ff3401c54 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -643,7 +643,7 @@ class No_such_table_error_handler : public Internal_error_handler { public: No_such_table_error_handler() - : m_handled_errors(0), m_unhandled_errors(0) + : m_handled_errors(0), m_unhandled_errors(0), first_error(0) {} bool handle_condition(THD *thd, @@ -658,11 +658,12 @@ public: trapped and no other errors have been seen. FALSE otherwise. */ bool safely_trapped_errors(); + bool any_error() { return m_handled_errors == 0 || m_unhandled_errors == 0; } + uint got_error() { return first_error; } private: int m_handled_errors; int m_unhandled_errors; + uint first_error; }; - - #endif /* SQL_BASE_INCLUDED */ diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 5cc85bd5d59..e3adae073c2 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -284,6 +284,10 @@ static int open_stat_tables(THD *thd, TABLE_LIST *tables, bool for_write) @details This is used by DDLs. When a column or index is dropped or renamed, stat tables need to be adjusted accordingly. + + This function should not generate any errors as the callers are not checking + the result of delete_statistics_for_table() + */ static inline int open_stat_table_for_ddl(THD *thd, TABLE_LIST *table, const LEX_CSTRING *stat_tab_name) @@ -293,6 +297,14 @@ static inline int open_stat_table_for_ddl(THD *thd, TABLE_LIST *table, thd->push_internal_handler(&nst_handler); int res= open_system_tables_for_read(thd, table); thd->pop_internal_handler(); + if (res && nst_handler.any_error()) + { + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_CHECK_NO_SUCH_TABLE, + "Got error %d when trying to open statistics " + "table %`s for updating statistics", + nst_handler.got_error(), stat_table_name->str); + } return res; }