From fdcb443e62d272cad2bf0e6358c5d569e52736c4 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 5 Oct 2023 09:59:13 +0300 Subject: [PATCH] Remember first error in Dummy_error_handler Use Dummy_error_handler in open_stat_tables() to ignore all errors when opening statistics tables. --- sql/sql_base.h | 1 - sql/sql_class.h | 16 ++++++++++++---- sql/sql_statistics.cc | 8 ++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/sql/sql_base.h b/sql/sql_base.h index 89ff3401c54..ef4d481c30d 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -658,7 +658,6 @@ 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: diff --git a/sql/sql_class.h b/sql/sql_class.h index 54cb6e8a597..e6580d2432c 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1989,11 +1989,17 @@ private: /** Implements the trivial error handler which cancels all error states and prevents an SQLSTATE to be set. + Remembers the first error */ class Dummy_error_handler : public Internal_error_handler { + uint m_unhandled_errors; + uint first_error; public: + Dummy_error_handler() + : m_unhandled_errors(0), first_error(0) + {} bool handle_condition(THD *thd, uint sql_errno, const char* sqlstate, @@ -2001,13 +2007,15 @@ public: const char* msg, Sql_condition ** cond_hdl) { - /* Ignore error */ - return TRUE; + m_unhandled_errors++; + 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. */ diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index e3adae073c2..ba4f5ec2d02 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -293,17 +293,17 @@ static inline int open_stat_table_for_ddl(THD *thd, TABLE_LIST *table, const LEX_CSTRING *stat_tab_name) { table->init_one_table(&MYSQL_SCHEMA_NAME, stat_tab_name, NULL, TL_WRITE); - No_such_table_error_handler nst_handler; - thd->push_internal_handler(&nst_handler); + Dummy_error_handler error_handler; + thd->push_internal_handler(&error_handler); int res= open_system_tables_for_read(thd, table); 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, 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); + error_handler.got_error(), stat_table_name->str); } return res; }