summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2019-06-04 12:41:52 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2019-06-04 23:23:10 +0530
commit7906bee67bf3b9f9124da12dd1492d7b766bd53e (patch)
treef049c30099aea1ad8fcf5679e1f7811d66c7b04e
parentaa83b9cf4f23d7f61b1f6abf92e8280e8c1757cb (diff)
downloadmariadb-git-7906bee67bf3b9f9124da12dd1492d7b766bd53e.tar.gz
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
-rw-r--r--mysql-test/r/win.result27
-rw-r--r--mysql-test/t/win.test16
-rw-r--r--sql/item_windowfunc.h12
3 files changed, 47 insertions, 8 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result
index 5da8a7f8a3c..13d452f3ef2 100644
--- a/mysql-test/r/win.result
+++ b/mysql-test/r/win.result
@@ -3607,5 +3607,32 @@ 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
+drop table t1;
+#
# End of 10.2 tests
#
diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test
index 15c48c31250..a4d42ce2b91 100644
--- a/mysql-test/t/win.test
+++ b/mysql-test/t/win.test
@@ -2326,5 +2326,21 @@ 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;
+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 @@ public:
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 @@ public:
}
return 0;
}
+ ~Group_bound_tracker()
+ {
+ group_fields.delete_elements();
+ }
private:
List<Cached_item> group_fields;
@@ -199,7 +198,6 @@ public:
{
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;
}