Commit d1417ad5 authored by igor@rurik.mysql.com's avatar igor@rurik.mysql.com

Added a test case for bug #18940:in 5.0 the optimizer chose

a worse execution plan than in 4.1 for some queries.
It happened due the fact that at some conditions the 
optimizer always preferred range or full index scan access
methods to lookup access methods even when the latter were much
cheaper. 
The problem was not observed in 4.1 for the reported query
because the WHERE condition was not of a form that could
cause the problem.
Equality propagation introduced on 5.0 added an extra 
predicate and changed the WHERE condition. The new condition
provoked the optimizer to make a bad choice.

The problem was fixed by the patch for bug 17379.
parent d24b4d6e
......@@ -3427,3 +3427,22 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE A range PRIMARY PRIMARY 12 NULL 3 Using where
1 SIMPLE B ref PRIMARY PRIMARY 8 const,test.A.e 10
drop table t1, t2;
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b));
INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2),
(3,1), (5,1), (8,9), (2,2), (0,9);
CREATE TABLE t2 (c int, d int, f int, INDEX(c,f));
INSERT INTO t2 VALUES
(1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1),
(5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1),
(0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1);
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using where
1 SIMPLE t2 ref c c 5 test.t1.a 2 Using where
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 range PRIMARY,b b 5 NULL 3 Using where
1 SIMPLE t2 ref c c 5 test.t1.a 2 Using where
DROP TABLE t1, t2;
......@@ -2899,3 +2899,24 @@ select 'In next EXPLAIN, B.rows must be exactly 10:' Z;
explain select * from t2 A, t2 B where A.a=5 and A.b=5 and A.C<5
and B.a=5 and B.b=A.e and (B.b =1 or B.b = 3 or B.b=5);
drop table t1, t2;
#
#Bug #18940: selection of optimal execution plan caused by equality
# propagation (the bug was fixed by the patch for bug #17379)
CREATE TABLE t1 (a int PRIMARY KEY, b int, INDEX(b));
INSERT INTO t1 VALUES (1, 3), (9,4), (7,5), (4,5), (6,2),
(3,1), (5,1), (8,9), (2,2), (0,9);
CREATE TABLE t2 (c int, d int, f int, INDEX(c,f));
INSERT INTO t2 VALUES
(1,0,0), (1,0,1), (2,0,0), (2,0,1), (3,0,0), (4,0,1),
(5,0,0), (5,0,1), (6,0,0), (0,0,1), (7,0,0), (7,0,1),
(0,0,0), (0,0,1), (8,0,0), (8,0,1), (9,0,0), (9,0,1);
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6;
EXPLAIN
SELECT a, c, d, f FROM t1,t2 WHERE a=c AND b BETWEEN 4 AND 6 AND a > 0;
DROP TABLE t1, t2;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment