mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed LP bug #707848.
This was another bug in the patch for bug 698882. The new code from this patch did not ensured that substitutions of fields for best equal fields were performed on all AND-OR levels. As a result substitutions for best fields in some predicates that had been used by the range optimizer were not actually performed while range plans could employ these substitutions. This could lead to inconsistent data structures and ultimately to a crash.
This commit is contained in:
@ -1643,4 +1643,34 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 index NULL a 8 NULL 10 Using index; Using temporary; Using filesort
|
||||
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 Using where
|
||||
DROP TABLE t1, t2;
|
||||
#
|
||||
# Bug #707848: WHERE condition with OR + ORDER BY + field substitution
|
||||
#
|
||||
CREATE TABLE t1 (a int PRIMARY KEY);
|
||||
INSERT INTO t1 VALUES
|
||||
(9), (7), (11), (15), (2), (4), (1), (5), (14), (54), (3), (8);
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 r JOIN t1 s ON r.a = s.a
|
||||
WHERE s.a IN (2,9) OR s.a < 100 AND s.a != 0
|
||||
ORDER BY 1 LIMIT 10;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE r index PRIMARY PRIMARY 4 NULL 10 120.00 Using where; Using index
|
||||
1 SIMPLE s eq_ref PRIMARY PRIMARY 4 test.r.a 1 100.00 Using index
|
||||
Warnings:
|
||||
Note 1003 select `test`.`r`.`a` AS `a`,`test`.`s`.`a` AS `a` from `test`.`t1` `r` join `test`.`t1` `s` where ((`test`.`s`.`a` = `test`.`r`.`a`) and ((`test`.`r`.`a` in (2,9)) or ((`test`.`r`.`a` < 100) and (`test`.`r`.`a` <> 0)))) order by 1 limit 10
|
||||
SELECT * FROM t1 r JOIN t1 s ON r.a = s.a
|
||||
WHERE s.a IN (2,9) OR s.a < 100 AND s.a != 0
|
||||
ORDER BY 1 LIMIT 10;
|
||||
a a
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
5 5
|
||||
7 7
|
||||
8 8
|
||||
9 9
|
||||
11 11
|
||||
14 14
|
||||
DROP TABLE t1;
|
||||
End of 5.1 tests
|
||||
|
@ -1497,5 +1497,23 @@ LIMIT 2;
|
||||
|
||||
DROP TABLE t1, t2;
|
||||
|
||||
--echo #
|
||||
--echo # Bug #707848: WHERE condition with OR + ORDER BY + field substitution
|
||||
--echo #
|
||||
|
||||
CREATE TABLE t1 (a int PRIMARY KEY);
|
||||
INSERT INTO t1 VALUES
|
||||
(9), (7), (11), (15), (2), (4), (1), (5), (14), (54), (3), (8);
|
||||
|
||||
EXPLAIN EXTENDED
|
||||
SELECT * FROM t1 r JOIN t1 s ON r.a = s.a
|
||||
WHERE s.a IN (2,9) OR s.a < 100 AND s.a != 0
|
||||
ORDER BY 1 LIMIT 10;
|
||||
|
||||
SELECT * FROM t1 r JOIN t1 s ON r.a = s.a
|
||||
WHERE s.a IN (2,9) OR s.a < 100 AND s.a != 0
|
||||
ORDER BY 1 LIMIT 10;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 5.1 tests
|
||||
|
@ -9902,12 +9902,16 @@ static COND* substitute_for_best_equal_field(COND *cond,
|
||||
cond= eliminate_item_equal(0, cond_equal, item_equal);
|
||||
return cond ? cond : org_cond;
|
||||
}
|
||||
else if (cond_equal)
|
||||
else
|
||||
{
|
||||
List_iterator_fast<Item_equal> it(cond_equal->current_level);
|
||||
while((item_equal= it++))
|
||||
while (cond_equal)
|
||||
{
|
||||
cond= cond->transform(&Item::replace_equal_field, (uchar *) item_equal);
|
||||
List_iterator_fast<Item_equal> it(cond_equal->current_level);
|
||||
while((item_equal= it++))
|
||||
{
|
||||
cond= cond->transform(&Item::replace_equal_field, (uchar *) item_equal);
|
||||
}
|
||||
cond_equal= cond_equal->upper_levels;
|
||||
}
|
||||
}
|
||||
return cond;
|
||||
|
Reference in New Issue
Block a user