summaryrefslogtreecommitdiff
path: root/sql/item_subselect.cc
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2005-06-28 20:52:15 +0400
committerunknown <konstantin@mysql.com>2005-06-28 20:52:15 +0400
commit79c1be9e442f3ba8f735e14a0454533f5914a817 (patch)
tree367d829814e646f5d2f02ee7f128a163a27d9846 /sql/item_subselect.cc
parent26a52bbe9439659d8642decb053663577ee45c18 (diff)
downloadmariadb-git-79c1be9e442f3ba8f735e14a0454533f5914a817.tar.gz
A fix and a test case for Bug#10736 "mysql_stmt_attr_set
CURSOR_TYPE_READ_ONLY select within select". The bug was caused by the reset of thd->mem_root to thd->main_mem_root in Item_subselect::exec, which in turn triggered too early free_root() for data which was needed on subsequent fetches from a cursor. This reset also caused a memory leak in stored procedures, as subsequent executions of instructions containing a subselect were allocating memory in thd->main_mem_root, which is not freed until the end of the entire SP, instead of the per-call mem_root, which is freed in the end of execution of the instruction. sql/item_subselect.cc: Don't try to protect subqueries from the code that assumes that it can reset thd->mem_root and get away with it: it's responsibility of the caller to ensure that no assumption about the life span of the allocated memory made by the called code is broken. Besides, this didn't work well with cursors and stored procedures, where the runtime memory root is not the same as &thd->main_mem_root. sql/opt_range.cc: In get_mm_leaf restore the original mem_root of the thd which has been temporarily reset with the quick select mem_root earlier: if thd->mem_root points to the QUICK...::mem_root, the memory allocated in JOIN::exec during evaluation of a subquery gets freed too early. tests/mysql_client_test.c: A test case for Bug#10736 "mysql_stmt_attr_set CURSOR_TYPE_READ_ONLY select within select"
Diffstat (limited to 'sql/item_subselect.cc')
-rw-r--r--sql/item_subselect.cc7
1 files changed, 0 insertions, 7 deletions
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 7ea72f3c858..c7587686ecd 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -194,15 +194,8 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
bool Item_subselect::exec()
{
int res;
- MEM_ROOT *old_root= thd->mem_root;
- /*
- As this is execution, all objects should be allocated through the main
- mem root
- */
- thd->mem_root= &thd->main_mem_root;
res= engine->exec();
- thd->mem_root= old_root;
if (engine_changed)
{