Remember first error in Dummy_error_handler

Use Dummy_error_handler in open_stat_tables() to ignore all errors
when opening statistics tables.
This commit is contained in:
Monty 2023-10-05 09:59:13 +03:00
parent 8941bdc474
commit fdcb443e62
3 changed files with 16 additions and 9 deletions

View File

@ -658,7 +658,6 @@ public:
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; } uint got_error() { return first_error; }
private: private:

View File

@ -1989,11 +1989,17 @@ private:
/** /**
Implements the trivial error handler which cancels all error states Implements the trivial error handler which cancels all error states
and prevents an SQLSTATE to be set. and prevents an SQLSTATE to be set.
Remembers the first error
*/ */
class Dummy_error_handler : public Internal_error_handler class Dummy_error_handler : public Internal_error_handler
{ {
uint m_unhandled_errors;
uint first_error;
public: public:
Dummy_error_handler()
: m_unhandled_errors(0), first_error(0)
{}
bool handle_condition(THD *thd, bool handle_condition(THD *thd,
uint sql_errno, uint sql_errno,
const char* sqlstate, const char* sqlstate,
@ -2001,13 +2007,15 @@ public:
const char* msg, const char* msg,
Sql_condition ** cond_hdl) Sql_condition ** cond_hdl)
{ {
/* Ignore error */ m_unhandled_errors++;
return TRUE; if (!first_error)
first_error= sql_errno;
return TRUE; // Ignore error
} }
Dummy_error_handler() = default; /* Remove gcc warning */ bool any_error() { return m_unhandled_errors != 0; }
uint got_error() { return first_error; }
}; };
/** /**
Implements the trivial error handler which counts errors as they happen. Implements the trivial error handler which counts errors as they happen.
*/ */

View File

@ -293,17 +293,17 @@ 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)
{ {
table->init_one_table(&MYSQL_SCHEMA_NAME, stat_tab_name, NULL, TL_WRITE); table->init_one_table(&MYSQL_SCHEMA_NAME, stat_tab_name, NULL, TL_WRITE);
No_such_table_error_handler nst_handler; Dummy_error_handler error_handler;
thd->push_internal_handler(&nst_handler); thd->push_internal_handler(&error_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()) if (res && error_handler.any_error())
{ {
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_CHECK_NO_SUCH_TABLE, ER_CHECK_NO_SUCH_TABLE,
"Got error %d when trying to open statistics " "Got error %d when trying to open statistics "
"table %`s for updating statistics", "table %`s for updating statistics",
nst_handler.got_error(), stat_table_name->str); error_handler.got_error(), stat_table_name->str);
} }
return res; return res;
} }