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 83e16f4e202..9eb29c16c81 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 @@ -492,6 +492,27 @@ Warning 4202 30 values were longer than max_sort_length. Sorting used only the f drop function f1; drop view v1; drop table t1, t2, t3; +set max_sort_length = default; +# +# MDEV-35275 Unexpected WARN_SORTING_ON_TRUNCATED_LENGTH or assertion +# failure in diagnostics area +# +create table t1 (a int, b varchar(1024)); +insert into t1 values (1,repeat('x',513)), (2,repeat('y',650)); +insert into t1 select * from t1 order by b limit 1; +Warnings: +Warning 4202 2 values were longer than max_sort_length. Sorting used only the first 70 bytes +update t1 set a = 3 order by b limit 1; +Warnings: +Warning 4202 3 values were longer than max_sort_length. Sorting used only the first 70 bytes +delete from t1 where a < 3 order by b; +Warnings: +Warning 4202 2 values were longer than max_sort_length. Sorting used only the first 70 bytes +# Make sure warnings from previous statements do not overflow to next ones +select a from t1; +a +3 +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 a98abaf2c70..7dcb4a9021e 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 @@ -282,6 +282,27 @@ drop function f1; drop view v1; drop table t1, t2, t3; +set max_sort_length = default; + +--echo # +--echo # MDEV-35275 Unexpected WARN_SORTING_ON_TRUNCATED_LENGTH or assertion +--echo # failure in diagnostics area +--echo # + +create table t1 (a int, b varchar(1024)); +insert into t1 values (1,repeat('x',513)), (2,repeat('y',650)); + +insert into t1 select * from t1 order by b limit 1; + +update t1 set a = 3 order by b limit 1; + +delete from t1 where a < 3 order by b; + +--echo # Make sure warnings from previous statements do not overflow to next ones +select a from t1; + +drop table t1; + # # Cleanup # diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 660dbbbbe68..70fad4aba21 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1434,6 +1434,7 @@ values_loop_end: thd->lex->current_select->leaf_tables_saved= true; } + thd->push_final_warnings(); my_free(readbuff); #ifndef EMBEDDED_LIBRARY if (lock_type == TL_WRITE_DELAYED && table->expr_arena) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d6e9818a5a2..f781d003ec2 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -34267,6 +34267,7 @@ bool Sql_cmd_dml::execute(THD *thd) if (res) goto err; + thd->push_final_warnings(); res= unit->cleanup(); /* "Unprepare" this object since unit->cleanup actually unprepares */