summaryrefslogtreecommitdiff
path: root/sql/opt_range.cc
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@Sun.com>2009-10-17 00:19:51 +0400
committerAlexey Kopytov <Alexey.Kopytov@Sun.com>2009-10-17 00:19:51 +0400
commit8e931fe53c55e203b285f30c892f24f106b56249 (patch)
tree1b3100a0a72e06878015ac5a3ce9ed73dbd42b55 /sql/opt_range.cc
parent0e11bad589849ef5422dd5c4aca593ba01886dd8 (diff)
downloadmariadb-git-8e931fe53c55e203b285f30c892f24f106b56249.tar.gz
Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN
The problem was in incorrect handling of predicates involving NULL as a constant value by the range optimizer. For example, when creating a SEL_ARG node from a condition of the form "field < const" (which would normally result in the "NULL < field < const" SEL_ARG), the special case when "const" is NULL was not taken into account, so "NULL < field < NULL" was produced for the "field < NULL" condition. As a result, SEL_ARG structures of this form could not be further optimized which in turn could lead to incorrectly constructed SEL_ARG trees. In particular, code assuming SEL_ARG structures to always form a sequence of ordered disjoint intervals could enter an infinite loop under some circumstances. Fixed by changing get_mm_leaf() so that for any sargable predicate except "<=>" involving NULL as a constant, "empty" SEL_ARG is returned, since such a predicate is always false.
Diffstat (limited to 'sql/opt_range.cc')
-rw-r--r--sql/opt_range.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 119f90bc97a..04dae4fd815 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -5891,6 +5891,17 @@ get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field,
goto end;
}
field->table->in_use->variables.sql_mode= orig_sql_mode;
+
+ /*
+ Any sargable predicate except "<=>" involving NULL as a constant is always
+ FALSE
+ */
+ if (type != Item_func::EQUAL_FUNC && field->is_real_null())
+ {
+ tree= &null_element;
+ goto end;
+ }
+
str= (uchar*) alloc_root(alloc, key_part->store_length+1);
if (!str)
goto end;