Commit 4c8d2410 authored by Monty's avatar Monty

Give warnings if open_stat_table_for_ddl() fails

The warning is given in case of table not found or if there is a lock
timeout. The warning is needed as in case of a lock timeout then the
persistent table stats are going to be wrong.
parent 684f7f81
...@@ -2,6 +2,9 @@ create table t1 (a int); ...@@ -2,6 +2,9 @@ create table t1 (a int);
alter table mysql.column_stats rename to mysql.column_stats1; alter table mysql.column_stats rename to mysql.column_stats1;
flush tables; flush tables;
alter table t1 change a b varchar(100); 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; show create table t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
......
...@@ -73,6 +73,8 @@ No_such_table_error_handler::handle_condition(THD *, ...@@ -73,6 +73,8 @@ No_such_table_error_handler::handle_condition(THD *,
Sql_condition ** cond_hdl) Sql_condition ** cond_hdl)
{ {
*cond_hdl= NULL; *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) if (sql_errno == ER_NO_SUCH_TABLE || sql_errno == ER_NO_SUCH_TABLE_IN_ENGINE)
{ {
m_handled_errors++; m_handled_errors++;
...@@ -95,7 +97,6 @@ bool No_such_table_error_handler::safely_trapped_errors() ...@@ -95,7 +97,6 @@ bool No_such_table_error_handler::safely_trapped_errors()
return ((m_handled_errors > 0) && (m_unhandled_errors == 0)); return ((m_handled_errors > 0) && (m_unhandled_errors == 0));
} }
/** /**
This internal handler is used to trap ER_NO_SUCH_TABLE and This internal handler is used to trap ER_NO_SUCH_TABLE and
ER_WRONG_MRG_TABLE errors during CHECK/REPAIR TABLE for MERGE ER_WRONG_MRG_TABLE errors during CHECK/REPAIR TABLE for MERGE
......
...@@ -643,7 +643,7 @@ class No_such_table_error_handler : public Internal_error_handler ...@@ -643,7 +643,7 @@ class No_such_table_error_handler : public Internal_error_handler
{ {
public: public:
No_such_table_error_handler() 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, bool handle_condition(THD *thd,
...@@ -658,11 +658,12 @@ class No_such_table_error_handler : public Internal_error_handler ...@@ -658,11 +658,12 @@ class No_such_table_error_handler : public Internal_error_handler
trapped and no other errors have been seen. FALSE otherwise. trapped and no other errors have been seen. FALSE otherwise.
*/ */
bool safely_trapped_errors(); bool safely_trapped_errors();
bool any_error() { return m_handled_errors == 0 || m_unhandled_errors == 0; }
uint got_error() { return first_error; }
private: private:
int m_handled_errors; int m_handled_errors;
int m_unhandled_errors; int m_unhandled_errors;
uint first_error;
}; };
#endif /* SQL_BASE_INCLUDED */ #endif /* SQL_BASE_INCLUDED */
...@@ -284,6 +284,10 @@ static int open_stat_tables(THD *thd, TABLE_LIST *tables, bool for_write) ...@@ -284,6 +284,10 @@ static int open_stat_tables(THD *thd, TABLE_LIST *tables, bool for_write)
@details @details
This is used by DDLs. When a column or index is dropped or renamed, This is used by DDLs. When a column or index is dropped or renamed,
stat tables need to be adjusted accordingly. 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, static inline int open_stat_table_for_ddl(THD *thd, TABLE_LIST *table,
const LEX_CSTRING *stat_tab_name) const LEX_CSTRING *stat_tab_name)
...@@ -293,6 +297,14 @@ static inline int open_stat_table_for_ddl(THD *thd, TABLE_LIST *table, ...@@ -293,6 +297,14 @@ static inline int open_stat_table_for_ddl(THD *thd, TABLE_LIST *table,
thd->push_internal_handler(&nst_handler); thd->push_internal_handler(&nst_handler);
int res= open_system_tables_for_read(thd, table); int res= open_system_tables_for_read(thd, table);
thd->pop_internal_handler(); 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; return res;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment