From 7d1467e9e92d5ce64ceed0d6ab0ff69bc0f49daa Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 2 May 2024 19:07:41 +0300 Subject: [PATCH] MDEV-34054 Memory leak in Window_func_runner::exec after encountering "temporary space limit reached" error --- mysql-test/main/tmp_space_usage.result | 7 +++++++ mysql-test/main/tmp_space_usage.test | 9 +++++++++ sql/sql_window.cc | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/mysql-test/main/tmp_space_usage.result b/mysql-test/main/tmp_space_usage.result index 5d3d9a8a9e3..6ca102a1a37 100644 --- a/mysql-test/main/tmp_space_usage.result +++ b/mysql-test/main/tmp_space_usage.result @@ -192,4 +192,11 @@ DROP TABLE t1; connection default; disconnect c1; set @@global.max_tmp_total_space_usage=@save_max_tmp_total_space_usage; +# +# MDEV-34054 +# Memory leak in Window_func_runner::exec after encountering +# "temporary space limit reached" error +SET max_tmp_session_space_usage= 64*1024; +SELECT MIN(VARIABLE_VALUE) OVER (), NTILE(1) OVER (), MAX(VARIABLE_NAME) OVER () FROM information_schema.SESSION_STATUS; +ERROR HY000: Local temporary space limit reached # End of 11.5 tests diff --git a/mysql-test/main/tmp_space_usage.test b/mysql-test/main/tmp_space_usage.test index a9060c6897d..581e9d13c7d 100644 --- a/mysql-test/main/tmp_space_usage.test +++ b/mysql-test/main/tmp_space_usage.test @@ -250,4 +250,13 @@ connection default; disconnect c1; set @@global.max_tmp_total_space_usage=@save_max_tmp_total_space_usage; +--echo # +--echo # MDEV-34054 +--echo # Memory leak in Window_func_runner::exec after encountering +--echo # "temporary space limit reached" error + +SET max_tmp_session_space_usage= 64*1024; +--error 200 +SELECT MIN(VARIABLE_VALUE) OVER (), NTILE(1) OVER (), MAX(VARIABLE_NAME) OVER () FROM information_schema.SESSION_STATUS; + --echo # End of 11.5 tests diff --git a/sql/sql_window.cc b/sql/sql_window.cc index 38f65007288..c5668d7f046 100644 --- a/sql/sql_window.cc +++ b/sql/sql_window.cc @@ -2859,6 +2859,7 @@ bool compute_window_func(THD *thd, { List_iterator_fast iter_win_funcs(window_functions); List_iterator_fast iter_cursor_managers(cursor_managers); + bool ret= false; uint err; READ_RECORD info; @@ -2921,19 +2922,27 @@ bool compute_window_func(THD *thd, /* Check if we found any error in the window function while adding values through cursors. */ if (unlikely(thd->is_error() || thd->is_killed())) + { + ret= true; break; + } /* Return to current row after notifying cursors for each window function. */ if (tbl->file->ha_rnd_pos(tbl->record[0], rowid_buf)) - return true; + { + ret= true; + break; + } } /* We now have computed values for each window function. They can now be saved in the current row. */ if (save_window_function_values(window_functions, tbl, rowid_buf)) - return true; - + { + ret= true; + break; + } rownum++; } @@ -2941,7 +2950,7 @@ bool compute_window_func(THD *thd, partition_trackers.delete_elements(); end_read_record(&info); - return false; + return ret; } /* Make a list that is a concation of two lists of ORDER elements */