summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc15
1 files changed, 12 insertions, 3 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 04cc0baa0aa..634c9db18a8 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -3604,9 +3604,18 @@ static SEL_TREE *get_mm_tree(PARAM *param,COND *cond)
/* Here when simple cond */
if (cond->const_item())
{
- if (cond->val_int())
- DBUG_RETURN(new SEL_TREE(SEL_TREE::ALWAYS));
- DBUG_RETURN(new SEL_TREE(SEL_TREE::IMPOSSIBLE));
+ /*
+ During the cond->val_int() evaluation we can come across a subselect
+ item which may allocate memory on the thd->mem_root and assumes
+ all the memory allocated has the same life span as the subselect
+ item itself. So we have to restore the thread's mem_root here.
+ */
+ MEM_ROOT *tmp_root= param->mem_root;
+ param->thd->mem_root= param->old_root;
+ tree= cond->val_int() ? new(tmp_root) SEL_TREE(SEL_TREE::ALWAYS) :
+ new(tmp_root) SEL_TREE(SEL_TREE::IMPOSSIBLE);
+ param->thd->mem_root= tmp_root;
+ DBUG_RETURN(tree);
}
table_map ref_tables= 0;