summaryrefslogtreecommitdiff
path: root/mysql-test/t/subselect.test
diff options
context:
space:
mode:
authorunknown <gkodinov/kgeorge@macbook.gmz>2006-10-17 16:20:26 +0300
committerunknown <gkodinov/kgeorge@macbook.gmz>2006-10-17 16:20:26 +0300
commit841ea461ce2b6782ce280806039c32e7a5b7dcdd (patch)
treee9d042b9e6f984142988ab80b1e498e226ff394a /mysql-test/t/subselect.test
parent21be389b46ae539a4a917539027636644d7f4dec (diff)
downloadmariadb-git-841ea461ce2b6782ce280806039c32e7a5b7dcdd.tar.gz
Bug#21798: memory leak during query execution with subquery in column
list using a function When executing dependent subqueries they are re-inited and re-exec() for each row of the outer context. The cause for the bug is that during subquery reinitialization/re-execution, the optimizer reallocates JOIN::join_tab, JOIN::table in make_simple_join() and the local variable in 'sortorder' in create_sort_index(), which is allocated by make_unireg_sortorder(). Care must be taken not to allocate anything into the thread's memory pool while re-initializing query plan structures between subquery re-executions. All such items mush be cached and reused because the thread's memory pool is freed at the end of the whole query. Note that they must be cached and reused even for queries that are not otherwise cacheable because otherwise it will grow the thread's memory pool every time a cacheable query is re-executed. We provide additional members to the JOIN structure to store references to the items that need to be cached. mysql-test/r/subselect.result: Bug#21798: memory leak during query execution with subquery in column list using a function - test case mysql-test/t/subselect.test: Bug#21798: memory leak during query execution with subquery in column list using a function - test case sql/mysql_priv.h: Bug#21798: memory leak during query execution with subquery in column list using a function - cache the entities allocated in the threads memory pool by JOIN::exec (). sql/sql_delete.cc: Bug#21798: memory leak during query execution with subquery in column list using a function - cache the SORT_ORDER, TABLE * and JOIN_TAB allocated in the thread's memory pool by JOIN::exec (). sql/sql_select.cc: Bug#21798: memory leak during query execution with subquery in column list using a function - cache the SORT_ORDER, TABLE * and JOIN_TAB allocated in the thread's memory pool by JOIN::exec (). sql/sql_select.h: Bug#21798: memory leak during query execution with subquery in column list using a function - cache the SORT_ORDER, TABLE * and JOIN_TAB allocated in the thread's memory pool by JOIN::exec (). sql/sql_table.cc: Bug#21798: memory leak during query execution with subquery in column list using a function - cache the SORT_ORDER, TABLE * and JOIN_TAB allocated in the thread's memory pool by JOIN::exec (). sql/sql_update.cc: Bug#21798: memory leak during query execution with subquery in column list using a function - cache the SORT_ORDER, TABLE * and JOIN_TAB allocated in the thread's memory pool by JOIN::exec ().
Diffstat (limited to 'mysql-test/t/subselect.test')
-rw-r--r--mysql-test/t/subselect.test26
1 files changed, 26 insertions, 0 deletions
diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test
index 740cb08c5bd..eefec96203a 100644
--- a/mysql-test/t/subselect.test
+++ b/mysql-test/t/subselect.test
@@ -2306,3 +2306,29 @@ explain select * from t1 where not exists
((select t11.i from t1 t11) union (select t12.i from t1 t12));
DROP TABLE t1;
+
+#
+# Bug#21798: memory leak during query execution with subquery in column
+# list using a function
+#
+CREATE TABLE t1 (a VARCHAR(250), b INT auto_increment, PRIMARY KEY (b));
+insert into t1 (a) values (FLOOR(rand() * 100));
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+insert into t1 (a) select FLOOR(rand() * 100) from t1;
+
+SELECT a,
+ (SELECT REPEAT(' ',250) FROM t1 i1
+ WHERE i1.b=t1.a ORDER BY RAND() LIMIT 1) AS a
+FROM t1 ORDER BY a LIMIT 5;
+DROP TABLE t1;