From a914087fabe08cef0fa8c494df80b95a1370993b Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sat, 2 Nov 2024 18:25:10 +0700 Subject: [PATCH] MDEV-35307 Unexpected error WARN_SORTING_ON_TRUNCATED_LENGTH or assertion failure in diagnostics area #2 When strict mode is enabled, all warnings during `INSERT` are converted to errors regardless of their actual severity. `WARN_SORTING_ON_TRUNCATED_LENGTH` is not considered severe enough to be elevated to the ERROR level, and this commit fixes that --- .../sys_vars/r/max_sort_length_func.result | 10 +++++++ .../sys_vars/t/max_sort_length_func.test | 13 ++++++++++ sql/sql_class.cc | 26 +++++++++++++++++++ sql/sql_class.h | 18 +------------ 4 files changed, 50 insertions(+), 17 deletions(-) diff --git a/mysql-test/suite/sys_vars/r/max_sort_length_func.result b/mysql-test/suite/sys_vars/r/max_sort_length_func.result index 9eb29c16c81..8e18831c13b 100644 --- a/mysql-test/suite/sys_vars/r/max_sort_length_func.result +++ b/mysql-test/suite/sys_vars/r/max_sort_length_func.result @@ -513,6 +513,16 @@ select a from t1; a 3 drop table t1; +# +# MDEV-35307 Unexpected WARN_SORTING_ON_TRUNCATED_LENGTH or assertion +# failure in diagnostics area #2 +# +create table t1 (a varchar(1024)) engine=innodb; +insert into t1 values (repeat('a',1000)),(repeat('b',1000)); +insert into t1 (a) select a from t1 order by a; +Warnings: +Warning 4202 2 values were longer than max_sort_length. Sorting used only the first 70 bytes +drop table t1; connection default; disconnect test_con1; disconnect test_con2; diff --git a/mysql-test/suite/sys_vars/t/max_sort_length_func.test b/mysql-test/suite/sys_vars/t/max_sort_length_func.test index 7dcb4a9021e..190ef78a225 100644 --- a/mysql-test/suite/sys_vars/t/max_sort_length_func.test +++ b/mysql-test/suite/sys_vars/t/max_sort_length_func.test @@ -303,6 +303,19 @@ select a from t1; drop table t1; +--echo # +--echo # MDEV-35307 Unexpected WARN_SORTING_ON_TRUNCATED_LENGTH or assertion +--echo # failure in diagnostics area #2 +--echo # + +--source include/have_innodb.inc + +create table t1 (a varchar(1024)) engine=innodb; +insert into t1 values (repeat('a',1000)),(repeat('b',1000)); +insert into t1 (a) select a from t1 order by a; + +drop table t1; + # # Cleanup # diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9119711e47a..d53a37901d2 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -8632,6 +8632,32 @@ error: } + +/* + Push post-execution warnings, which may be some kinds of aggregate messages + like number of times max_sort_length was reached during sorting/grouping +*/ +void THD::push_final_warnings() +{ + if (num_of_strings_sorted_on_truncated_length) + { + /* + WARN_SORTING_ON_TRUNCATED_LENGTH is not considered important enough to be + elevated to the ERROR level, so reset abort_on_warning flag before pushing + */ + bool saved_abort_on_warning= abort_on_warning; + abort_on_warning= false; + push_warning_printf(this, Sql_condition::WARN_LEVEL_WARN, + WARN_SORTING_ON_TRUNCATED_LENGTH, + ER_THD(this, WARN_SORTING_ON_TRUNCATED_LENGTH), + num_of_strings_sorted_on_truncated_length, + variables.max_sort_length); + num_of_strings_sorted_on_truncated_length= 0; + abort_on_warning= saved_abort_on_warning; + } +} + + void AUTHID::copy(MEM_ROOT *mem_root, const LEX_CSTRING *user_name, const LEX_CSTRING *host_name) { diff --git a/sql/sql_class.h b/sql/sql_class.h index 6b533ac6e78..b4589e761e9 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -6067,23 +6067,7 @@ public: bool need_report_unit_results(); bool report_collected_unit_results(); bool init_collecting_unit_results(); - - /* - Push post-execution warnings, which may be some kinds of aggregate messages - like number of times max_sort_length was reached during sorting/grouping - */ - void push_final_warnings() - { - if (num_of_strings_sorted_on_truncated_length) - { - push_warning_printf(this, Sql_condition::WARN_LEVEL_WARN, - WARN_SORTING_ON_TRUNCATED_LENGTH, - ER_THD(this, WARN_SORTING_ON_TRUNCATED_LENGTH), - num_of_strings_sorted_on_truncated_length, - variables.max_sort_length); - num_of_strings_sorted_on_truncated_length= 0; - } - } + void push_final_warnings(); };