revision-id: 41a6e949504bb2ee4d81d24f8952b675e971625b (mariadb-10.2.23-130-g41a6e949504) parent(s): 8ce702aa90c174566f4ac950e85cc7570bf9b647 author: Varun Gupta committer: Varun Gupta timestamp: 2019-05-13 15:15:06 +0530 message: MDEV-18015: Assertion `global_status_var.global_memory_used == 0' failed when using UDF , window functions and views Adding destructor for Group_bound_tracker to free Cached_item_str. The Cached_item for window functions are allocated on THD:mem_root but the Cached_item_str has value of type string which is allocated on the heap, so we need to call free() for it --- mysql-test/r/win.result | 33 +++++++++++++++++++++++++++++++++ mysql-test/t/win.test | 17 +++++++++++++++++ sql/item_windowfunc.h | 12 ++++-------- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 5da8a7f8a3c..2c50ba29d11 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3607,5 +3607,38 @@ b row_number() over (partition by sum(a)+1) 2000 1 drop table t1; # +# MDEV-18015: Assertion `global_status_var.global_memory_used == 0' failed when using UDF, +# window functions and views +# +create table t1 (id int, n1 int); +insert into t1 values (1,1),(2,1),(3,2),(4,4); +explain +select max(n1) over (partition by 'abc') from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary +select max(n1) over (partition by 'abc') from t1; +max(n1) over (partition by 'abc') +4 +4 +4 +4 +explain +select rank() over (partition by 'abc' order by 'xyz') from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using temporary +select rank() over (partition by 'abc' order by 'xyz') from t1; +rank() over (partition by 'abc' order by 'xyz') +1 +1 +1 +1 +select lag(id) over (order by null desc), sum(id) over (order by null) from t1; +lag(id) over (order by null desc) sum(id) over (order by null) +NULL 10 +1 10 +2 10 +3 10 +drop table t1; +# # End of 10.2 tests # diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 15c48c31250..7c2514b7114 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2325,6 +2325,23 @@ select b, row_number() over (partition by sum(a)+1) from t1 group by b; drop table t1; +--echo # +--echo # MDEV-18015: Assertion `global_status_var.global_memory_used == 0' failed when using UDF, +--echo # window functions and views +--echo # + +create table t1 (id int, n1 int); +insert into t1 values (1,1),(2,1),(3,2),(4,4); +explain +select max(n1) over (partition by 'abc') from t1; +select max(n1) over (partition by 'abc') from t1; + +explain +select rank() over (partition by 'abc' order by 'xyz') from t1; +select rank() over (partition by 'abc' order by 'xyz') from t1; +select lag(id) over (order by null desc), sum(id) over (order by null) from t1; +drop table t1; + --echo # --echo # End of 10.2 tests --echo # diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 21270733051..b9df1b7482b 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -28,11 +28,6 @@ class Group_bound_tracker first_check= true; } - void cleanup() - { - group_fields.empty(); - } - /* Check if the current row is in a different group than the previous row this function was called for. @@ -70,6 +65,10 @@ class Group_bound_tracker } return 0; } + ~Group_bound_tracker() + { + group_fields.delete_elements(); + } private: List<Cached_item> group_fields; @@ -199,7 +198,6 @@ class Item_sum_rank: public Item_sum_int { if (peer_tracker) { - peer_tracker->cleanup(); delete peer_tracker; peer_tracker= NULL; } @@ -269,7 +267,6 @@ class Item_sum_dense_rank: public Item_sum_int { if (peer_tracker) { - peer_tracker->cleanup(); delete peer_tracker; peer_tracker= NULL; } @@ -537,7 +534,6 @@ class Item_sum_percent_rank: public Item_sum_window_with_row_count { if (peer_tracker) { - peer_tracker->cleanup(); delete peer_tracker; peer_tracker= NULL; }