mirror of
https://github.com/MariaDB/server.git
synced 2025-01-22 14:54:20 +01:00
Backport into build-200911241145-5.1.40sp1
> ------------------------------------------------------------ > revno: 3181 > revision-id: alexey.kopytov@sun.com-20091016201951-fsht0wm8xn8vkzsx > parent: joerg@mysql.com-20091016164025-kb4sbrggq5o7zufc > committer: Alexey Kopytov <Alexey.Kopytov@Sun.com> > branch nick: mysql-5.1-bugteam > timestamp: Sat 2009-10-17 00:19:51 +0400 > message: > 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.
This commit is contained in:
parent
b84555efae
commit
233dc05f39
5 changed files with 30 additions and 4 deletions
|
@ -1272,10 +1272,9 @@ INSERT INTO t1 VALUES (1, '2009-01-01'), (2, NULL);
|
|||
# test with an invalid date, which lead to item->null_value is set.
|
||||
EXPLAIN PARTITIONS SELECT * FROM t1 WHERE b < CAST('2009-04-99' AS DATETIME);
|
||||
id select_type table partitions type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 p20090401 ALL NULL NULL NULL NULL 2 Using where
|
||||
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
Warnings:
|
||||
Warning 1292 Incorrect datetime value: '2009-04-99'
|
||||
Warning 1292 Incorrect datetime value: '2009-04-99'
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1
|
||||
(a INT NOT NULL AUTO_INCREMENT,
|
||||
|
|
|
@ -1216,6 +1216,14 @@ select 'In following EXPLAIN the access method should be ref, #rows~=500 (and no
|
|||
Z
|
||||
In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)
|
||||
explain select * from t2 where a=1000 and b<11;
|
||||
#
|
||||
# Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN
|
||||
#
|
||||
CREATE TABLE t1(a INT, KEY(a));
|
||||
INSERT INTO t1 VALUES (1), (NULL);
|
||||
SELECT * FROM t1 WHERE a <> NULL and (a <> NULL or a <= NULL);
|
||||
a
|
||||
DROP TABLE t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ref a a 5 const 502 Using where
|
||||
drop table t1, t2;
|
||||
|
|
|
@ -4403,8 +4403,7 @@ FROM t1
|
|||
WHERE a = 230;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
2 DEPENDENT SUBQUERY st1 index NULL a 5 NULL 2 Using index
|
||||
2 DEPENDENT SUBQUERY st2 index b b 5 NULL 2 Using where; Using index; Using join buffer
|
||||
2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
||||
SELECT MAX(b), (SELECT COUNT(*) FROM st1,st2 WHERE st2.b <= t1.b)
|
||||
FROM t1
|
||||
WHERE a = 230;
|
||||
|
|
|
@ -1043,6 +1043,15 @@ alter table t2 add index (a,b);
|
|||
|
||||
select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z;
|
||||
explain select * from t2 where a=1000 and b<11;
|
||||
--echo #
|
||||
--echo # Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1(a INT, KEY(a));
|
||||
INSERT INTO t1 VALUES (1), (NULL);
|
||||
SELECT * FROM t1 WHERE a <> NULL and (a <> NULL or a <= NULL);
|
||||
DROP TABLE t1;
|
||||
|
||||
|
||||
drop table t1, t2;
|
||||
|
||||
|
|
|
@ -5911,6 +5911,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;
|
||||
|
|
Loading…
Add table
Reference in a new issue