mirror of
https://github.com/MariaDB/server.git
synced 2026-05-15 19:37:16 +02:00
Fixed a cost estimation bug introduced into in the function best_access_path
of the 5.3 code line after a merge with 5.2 on 2010-10-28 in order not to allow the cost to access a joined table to be equal to 0 ever. Expanded data sets for many test cases to get the same execution plans as before.
This commit is contained in:
parent
42b928ca05
commit
715dc5f99d
61 changed files with 703 additions and 217 deletions
|
|
@ -361,7 +361,8 @@ ALTER TABLE t1 ADD INDEX t1 (a, b, c, d, e);
|
|||
ERROR 42000: Specified key was too long; max key length is 1208 bytes
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a));
|
||||
INSERT into t1 values (0, null, 0), (0, null, 1), (0, null, 2), (0, null,3), (1,1,4);
|
||||
INSERT into t1 values (0,null,0), (0,null,1), (0,null,2), (0,null,3), (1,1,4);
|
||||
INSERT into t1 values (2,4,5), (7,8,4), (8,3,1), (9,7,2), (5,5,9);
|
||||
create table t2 (a int not null, b int, c int, key(b), key(c), key(a));
|
||||
INSERT into t2 values (1,1,1), (2,2,2);
|
||||
optimize table t1;
|
||||
|
|
@ -372,24 +373,24 @@ Table Op Msg_type Msg_text
|
|||
test.t1 check status OK
|
||||
show index from t1;
|
||||
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
|
||||
t1 1 b 1 b A 5 NULL NULL YES BTREE
|
||||
t1 1 c 1 c A 5 NULL NULL YES BTREE
|
||||
t1 1 a 1 a A 1 NULL NULL BTREE
|
||||
t1 1 a 2 b A 5 NULL NULL YES BTREE
|
||||
t1 1 c_2 1 c A 5 NULL NULL YES BTREE
|
||||
t1 1 c_2 2 a A 5 NULL NULL BTREE
|
||||
t1 1 b 1 b A 10 NULL NULL YES BTREE
|
||||
t1 1 c 1 c A 10 NULL NULL YES BTREE
|
||||
t1 1 a 1 a A 10 NULL NULL BTREE
|
||||
t1 1 a 2 b A 10 NULL NULL YES BTREE
|
||||
t1 1 c_2 1 c A 10 NULL NULL YES BTREE
|
||||
t1 1 c_2 2 a A 10 NULL NULL BTREE
|
||||
explain select * from t1,t2 where t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL a NULL NULL NULL 2
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 3
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 1
|
||||
explain select * from t1,t2 force index(a) where t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL a NULL NULL NULL 2
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 3
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 1
|
||||
explain select * from t1 force index(a),t2 force index(a) where t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL a NULL NULL NULL 2
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 3
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 1
|
||||
explain select * from t1,t2 where t1.b=t2.b;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL b NULL NULL NULL 2 Using where
|
||||
|
|
@ -397,19 +398,19 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||
explain select * from t1,t2 force index(c) where t1.a=t2.a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 3
|
||||
1 SIMPLE t1 ref a a 4 test.t2.a 1
|
||||
explain select * from t1 where a=0 or a=2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 4 NULL 4 Using where
|
||||
1 SIMPLE t1 range a a 4 NULL 5 Using where
|
||||
explain select * from t1 force index (a) where a=0 or a=2;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range a a 4 NULL 4 Using where
|
||||
1 SIMPLE t1 range a a 4 NULL 5 Using where
|
||||
explain select * from t1 where c=1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ref c,c_2 c 5 const 1
|
||||
1 SIMPLE t1 ref c,c_2 c 5 const 2
|
||||
explain select * from t1 use index() where c=1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using where
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where
|
||||
drop table t1,t2;
|
||||
create table t1 (a int not null auto_increment primary key, b varchar(255));
|
||||
insert into t1 (b) values (repeat('a',100)),(repeat('b',100)),(repeat('c',100));
|
||||
|
|
|
|||
|
|
@ -386,7 +386,8 @@ DROP TABLE t1;
|
|||
#
|
||||
|
||||
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a));
|
||||
INSERT into t1 values (0, null, 0), (0, null, 1), (0, null, 2), (0, null,3), (1,1,4);
|
||||
INSERT into t1 values (0,null,0), (0,null,1), (0,null,2), (0,null,3), (1,1,4);
|
||||
INSERT into t1 values (2,4,5), (7,8,4), (8,3,1), (9,7,2), (5,5,9);
|
||||
create table t2 (a int not null, b int, c int, key(b), key(c), key(a));
|
||||
INSERT into t2 values (1,1,1), (2,2,2);
|
||||
optimize table t1;
|
||||
|
|
|
|||
|
|
@ -1017,6 +1017,7 @@ id select_type table type possible_keys key key_len ref rows Extra
|
|||
ATTENTION: the above EXPLAIN has several competing QEPs with identical
|
||||
. costs. To combat the plan change it uses --sorted_result and
|
||||
. and --replace tricks
|
||||
INSERT INTO t1 VALUES (-1,133,0), (-2,12,0), (-3,11,0), (-5,15,0);
|
||||
CREATE INDEX idx_b ON t1(b);
|
||||
CREATE INDEX idx_a ON t0(a);
|
||||
EXPLAIN
|
||||
|
|
@ -1041,7 +1042,7 @@ ON t6.b >= 2 AND t5.b=t7.b
|
|||
)
|
||||
ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
|
||||
(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
|
||||
(t1.a != 2),
|
||||
(t1.a != 2) AND t1.a>0,
|
||||
t9
|
||||
WHERE t0.a=1 AND
|
||||
t0.b=t1.b AND
|
||||
|
|
@ -1089,7 +1090,7 @@ ON t6.b >= 2 AND t5.b=t7.b
|
|||
)
|
||||
ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
|
||||
(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
|
||||
(t1.a != 2),
|
||||
(t1.a != 2) AND t1.a>0,
|
||||
t9
|
||||
WHERE t0.a=1 AND
|
||||
t0.b=t1.b AND
|
||||
|
|
|
|||
|
|
@ -6,7 +6,12 @@ KEY (a),
|
|||
KEY (b)
|
||||
);
|
||||
INSERT INTO t1 VALUES ('A','B'),('b','A'),('C','c'),('D','E'),('a','a');
|
||||
select * from t1,t1 as t2;
|
||||
INSERT INTO t1 VALUES
|
||||
('AA','BB'),('bb','AA'),('CC','cc'),('DD','EE'),('aa','aa');
|
||||
INSERT INTO t1 VALUES
|
||||
('AAA','BBB'),('bbb','AAA'),('CCC','ccc'),('DDD','EEE'),('aaa','aaa');
|
||||
select * from t1,t1 as t2
|
||||
where length(t1.A)=1 and length(t2.B)=1 ;
|
||||
a b a b
|
||||
A B A B
|
||||
b A A B
|
||||
|
|
@ -33,11 +38,14 @@ b A a a
|
|||
C c a a
|
||||
D E a a
|
||||
a a a a
|
||||
explain select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B;
|
||||
explain select t1.*,t2.* from t1,t1 as t2
|
||||
where t1.A=t2.B and length(t1.A)=1 and length(t2.B)=1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL a NULL NULL NULL 5
|
||||
1 SIMPLE t1 ALL a NULL NULL NULL 15 Using where
|
||||
1 SIMPLE t2 ref b b 4 test.t1.a 1 Using where
|
||||
select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B order by binary t1.a,t2.a;
|
||||
select t1.*,t2.* from t1,t1 as t2
|
||||
where t1.A=t2.B and length(t1.A)=1 and length(t2.B)=1
|
||||
order by binary t1.a,t2.a;
|
||||
a b a b
|
||||
A B a a
|
||||
A B b A
|
||||
|
|
|
|||
|
|
@ -587,6 +587,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
|
|||
--echo . costs. To combat the plan change it uses --sorted_result and
|
||||
--echo . and --replace tricks
|
||||
|
||||
INSERT INTO t1 VALUES (-1,133,0), (-2,12,0), (-3,11,0), (-5,15,0);
|
||||
CREATE INDEX idx_b ON t1(b);
|
||||
CREATE INDEX idx_a ON t0(a);
|
||||
|
||||
|
|
@ -614,7 +615,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
|
|||
)
|
||||
ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
|
||||
(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
|
||||
(t1.a != 2),
|
||||
(t1.a != 2) AND t1.a>0,
|
||||
t9
|
||||
WHERE t0.a=1 AND
|
||||
t0.b=t1.b AND
|
||||
|
|
@ -653,7 +654,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
|
|||
)
|
||||
ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND
|
||||
(t1.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
|
||||
(t1.a != 2),
|
||||
(t1.a != 2) AND t1.a>0,
|
||||
t9
|
||||
WHERE t0.a=1 AND
|
||||
t0.b=t1.b AND
|
||||
|
|
|
|||
|
|
@ -13,11 +13,19 @@ CREATE TABLE t1 (
|
|||
);
|
||||
|
||||
INSERT INTO t1 VALUES ('A','B'),('b','A'),('C','c'),('D','E'),('a','a');
|
||||
INSERT INTO t1 VALUES
|
||||
('AA','BB'),('bb','AA'),('CC','cc'),('DD','EE'),('aa','aa');
|
||||
INSERT INTO t1 VALUES
|
||||
('AAA','BBB'),('bbb','AAA'),('CCC','ccc'),('DDD','EEE'),('aaa','aaa');
|
||||
|
||||
select * from t1,t1 as t2;
|
||||
explain select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B;
|
||||
select * from t1,t1 as t2
|
||||
where length(t1.A)=1 and length(t2.B)=1 ;
|
||||
explain select t1.*,t2.* from t1,t1 as t2
|
||||
where t1.A=t2.B and length(t1.A)=1 and length(t2.B)=1;
|
||||
#select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B;
|
||||
select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B order by binary t1.a,t2.a;
|
||||
select t1.*,t2.* from t1,t1 as t2
|
||||
where t1.A=t2.B and length(t1.A)=1 and length(t2.B)=1
|
||||
order by binary t1.a,t2.a;
|
||||
select * from t1 where a='a';
|
||||
drop table t1;
|
||||
|
||||
|
|
|
|||
|
|
@ -139,6 +139,9 @@ create table t2 (c int, d int, v int as (d+1), index idx(c));
|
|||
insert into t2(c,d) values
|
||||
(20, 100), (20, 300), (30, 100), (30, 200), (40, 500),
|
||||
(70, 100), (40, 300), (60, 100), (40, 100), (70, 100);
|
||||
insert into t2(c,d) values
|
||||
(120, 100), (150, 300), (130, 100), (130, 200), (140, 500),
|
||||
(170, 100), (180, 300), (160, 100), (40, 100), (170, 100);
|
||||
set join_cache_level=6;
|
||||
explain
|
||||
select * from t1,t2 where t1.b=t2.c and d <= 100;
|
||||
|
|
|
|||
|
|
@ -151,6 +151,9 @@ create table t2 (c int, d int, v int as (d+1), index idx(c));
|
|||
insert into t2(c,d) values
|
||||
(20, 100), (20, 300), (30, 100), (30, 200), (40, 500),
|
||||
(70, 100), (40, 300), (60, 100), (40, 100), (70, 100);
|
||||
insert into t2(c,d) values
|
||||
(120, 100), (150, 300), (130, 100), (130, 200), (140, 500),
|
||||
(170, 100), (180, 300), (160, 100), (40, 100), (170, 100);
|
||||
|
||||
set join_cache_level=6;
|
||||
explain
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue