summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
authorunknown <evgen@moonbone.local>2007-11-19 20:00:25 +0000
committerunknown <evgen@moonbone.local>2007-11-19 20:00:25 +0000
commit13105534fa6107c5afb139a4459c659329525b2e (patch)
treeeb5c9cb7114544579d9ef880e1d9a4245bf66db0 /sql/opt_range.cc
parent6a8e10d2ce64e506a5c58ef3b58178105f4b5973 (diff)
downloadmariadb-git-13105534fa6107c5afb139a4459c659329525b2e.tar.gz
Bug#31048: Many nested subqueries may cause server crash.
This bug is actually two. The first one manifests itself on an EXPLAIN SELECT query with nested subqueries that employs the filesort algorithm. The whole SELECT under explain is marked as UNCACHEABLE_EXPLAIN to preserve some temporary structures for explain. As a side-effect of this values of nested subqueries weren't cached and subqueries were re-evaluated many times. Each time buffer for filesort was allocated but wasn't freed because freeing occurs at the end of topmost SELECT. Thus all available memory was eaten up step by step and OOM event occur. The second bug manifests itself on SELECT queries with conditions where a subquery result is compared with a key field and the subquery itself also has such condition. When a long chain of such nested subqueries is present the stack overrun occur. This happens because at some point the range optimizer temporary puts the PARAM structure on the stack. Its size if about 8K and the stack is exhausted very fast. Now the subselect_single_select_engine::exec function allows subquery result caching when the UNCACHEABLE_EXPLAIN flag is set. Now the SQL_SELECT::test_quick_select function calls the check_stack_overrun function for stack checking purposes to prevent server crash. mysql-test/t/subselect.test: Added a test case for the bug#31048: Many nested subqueries may cause server crash. mysql-test/r/subselect.result: Added a test case for the bug#31048: Many nested subqueries may cause server crash. sql/opt_range.cc: Bug#31048: Many nested subqueries may cause server crash. Now the SQL_SELECT::test_quick_select function calls the check_stack_overrun function for stack checking purposes to preven server crash. sql/item_subselect.cc: Bug31048: Many nested subqueries may cause server crash. Now the subselect_single_select_engine::exec function allows subquery result caching when the UNCACHEABLE_EXPLAIN flag is set.
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 969777d4792..dbdb2b919dc 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -1978,12 +1978,18 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
keys_to_use.intersect(head->keys_in_use_for_query);
if (!keys_to_use.is_clear_all())
{
+#ifndef EMBEDDED_LIBRARY // Avoid compiler warning
+ char buff[STACK_BUFF_ALLOC];
+#endif
MEM_ROOT alloc;
SEL_TREE *tree= NULL;
KEY_PART *key_parts;
KEY *key_info;
PARAM param;
+ if (check_stack_overrun(thd, STACK_MIN_SIZE, buff))
+ DBUG_RETURN(0); // Fatal error flag is set
+
/* set up parameter that is passed to all functions */
param.thd= thd;
param.baseflag=head->file->table_flags();