Skip to content

Commit a914087

Browse files
committed
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
1 parent a4cb03e commit a914087

File tree

4 files changed

+50
-17
lines changed

4 files changed

+50
-17
lines changed

mysql-test/suite/sys_vars/r/max_sort_length_func.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,16 @@ select a from t1;
513513
a
514514
3
515515
drop table t1;
516+
#
517+
# MDEV-35307 Unexpected WARN_SORTING_ON_TRUNCATED_LENGTH or assertion
518+
# failure in diagnostics area #2
519+
#
520+
create table t1 (a varchar(1024)) engine=innodb;
521+
insert into t1 values (repeat('a',1000)),(repeat('b',1000));
522+
insert into t1 (a) select a from t1 order by a;
523+
Warnings:
524+
Warning 4202 2 values were longer than max_sort_length. Sorting used only the first 70 bytes
525+
drop table t1;
516526
connection default;
517527
disconnect test_con1;
518528
disconnect test_con2;

mysql-test/suite/sys_vars/t/max_sort_length_func.test

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,19 @@ select a from t1;
303303

304304
drop table t1;
305305

306+
--echo #
307+
--echo # MDEV-35307 Unexpected WARN_SORTING_ON_TRUNCATED_LENGTH or assertion
308+
--echo # failure in diagnostics area #2
309+
--echo #
310+
311+
--source include/have_innodb.inc
312+
313+
create table t1 (a varchar(1024)) engine=innodb;
314+
insert into t1 values (repeat('a',1000)),(repeat('b',1000));
315+
insert into t1 (a) select a from t1 order by a;
316+
317+
drop table t1;
318+
306319
#
307320
# Cleanup
308321
#

sql/sql_class.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8632,6 +8632,32 @@ bool THD::report_collected_unit_results()
86328632

86338633
}
86348634

8635+
8636+
/*
8637+
Push post-execution warnings, which may be some kinds of aggregate messages
8638+
like number of times max_sort_length was reached during sorting/grouping
8639+
*/
8640+
void THD::push_final_warnings()
8641+
{
8642+
if (num_of_strings_sorted_on_truncated_length)
8643+
{
8644+
/*
8645+
WARN_SORTING_ON_TRUNCATED_LENGTH is not considered important enough to be
8646+
elevated to the ERROR level, so reset abort_on_warning flag before pushing
8647+
*/
8648+
bool saved_abort_on_warning= abort_on_warning;
8649+
abort_on_warning= false;
8650+
push_warning_printf(this, Sql_condition::WARN_LEVEL_WARN,
8651+
WARN_SORTING_ON_TRUNCATED_LENGTH,
8652+
ER_THD(this, WARN_SORTING_ON_TRUNCATED_LENGTH),
8653+
num_of_strings_sorted_on_truncated_length,
8654+
variables.max_sort_length);
8655+
num_of_strings_sorted_on_truncated_length= 0;
8656+
abort_on_warning= saved_abort_on_warning;
8657+
}
8658+
}
8659+
8660+
86358661
void AUTHID::copy(MEM_ROOT *mem_root, const LEX_CSTRING *user_name,
86368662
const LEX_CSTRING *host_name)
86378663
{

sql/sql_class.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6067,23 +6067,7 @@ class THD: public THD_count, /* this must be first */
60676067
bool need_report_unit_results();
60686068
bool report_collected_unit_results();
60696069
bool init_collecting_unit_results();
6070-
6071-
/*
6072-
Push post-execution warnings, which may be some kinds of aggregate messages
6073-
like number of times max_sort_length was reached during sorting/grouping
6074-
*/
6075-
void push_final_warnings()
6076-
{
6077-
if (num_of_strings_sorted_on_truncated_length)
6078-
{
6079-
push_warning_printf(this, Sql_condition::WARN_LEVEL_WARN,
6080-
WARN_SORTING_ON_TRUNCATED_LENGTH,
6081-
ER_THD(this, WARN_SORTING_ON_TRUNCATED_LENGTH),
6082-
num_of_strings_sorted_on_truncated_length,
6083-
variables.max_sort_length);
6084-
num_of_strings_sorted_on_truncated_length= 0;
6085-
}
6086-
}
6070+
void push_final_warnings();
60876071
};
60886072

60896073

0 commit comments

Comments
 (0)