Commit 715dc5f9 authored by Igor Babaev's avatar Igor Babaev

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.
parent 42b928ca
Branches unavailable
Tags unavailable
No related merge requests found
...@@ -739,15 +739,17 @@ INSERT INTO t1 VALUES ('c'); ...@@ -739,15 +739,17 @@ INSERT INTO t1 VALUES ('c');
CREATE TABLE t2 (a varchar(1) , KEY (a)) ; CREATE TABLE t2 (a varchar(1) , KEY (a)) ;
INSERT INTO t2 VALUES ('c'), (NULL), ('r'); INSERT INTO t2 VALUES ('c'), (NULL), ('r');
CREATE TABLE t3 (a varchar(1), b varchar(1)); CREATE TABLE t3 (a varchar(1), b varchar(1));
INSERT INTO t3 VALUES ('e', 'c'), ('c', 'c'), ('c', 'r'); INSERT INTO t3 VALUES
('e', 'c'), ('c', 'c'), ('c', 'r'), ('g', 'a'), ('b', 'x'), ('b', 'y'),
('h', 'w'), ('d', 'z'), ('k', 'v'), ('j', 's'), ('m', 'p'), ('l', 'q');
CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t3 GROUP BY a; CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t3 GROUP BY a;
EXPLAIN EXPLAIN
SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b; SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 system NULL NULL NULL NULL 1 1 PRIMARY t1 system NULL NULL NULL NULL 1
1 PRIMARY t2 ref a a 4 const 1 Using index 1 PRIMARY t2 ref a a 4 const 1 Using index
1 PRIMARY <derived2> ref key1 key1 10 test.t1.a,test.t1.a 2 1 PRIMARY <derived2> ref key0 key0 10 const,const 1
2 DERIVED t3 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort 2 DERIVED t3 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort
SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b; SELECT * FROM t1, t2, v1 WHERE t2.a=t1.a AND t2.a=v1.a AND t2.a=v1.b;
a a a b a a a b
c c c c c c c c
...@@ -1014,7 +1016,9 @@ INSERT INTO t1 VALUES (0); ...@@ -1014,7 +1016,9 @@ INSERT INTO t1 VALUES (0);
CREATE TABLE t2 (a varchar(32), b int, KEY (a)) ; CREATE TABLE t2 (a varchar(32), b int, KEY (a)) ;
INSERT INTO t2 VALUES INSERT INTO t2 VALUES
('j',28), ('c',29), ('i',26), ('c',29), ('k',27), ('j',28), ('c',29), ('i',26), ('c',29), ('k',27),
('j',28), ('c',29), ('i',25), ('d',26), ('k',27); ('j',28), ('c',29), ('i',25), ('d',26), ('k',27),
('n',28), ('d',29), ('m',26), ('e',29), ('p',27),
('w',28), ('x',29), ('y',25), ('z',26), ('s',27);
CREATE TABLE t3 (a varchar(32)); CREATE TABLE t3 (a varchar(32));
INSERT INTO t3 VALUES ('j'), ('c'); INSERT INTO t3 VALUES ('j'), ('c');
CREATE VIEW v1 AS SELECT DISTINCT t2.b FROM t1,t2,t3 WHERE t3.a = t2.a; CREATE VIEW v1 AS SELECT DISTINCT t2.b FROM t1,t2,t3 WHERE t3.a = t2.a;
......
...@@ -497,6 +497,8 @@ DROP TABLE t1; ...@@ -497,6 +497,8 @@ DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(255), b INT, FULLTEXT(a), KEY(b)); CREATE TABLE t1 (a VARCHAR(255), b INT, FULLTEXT(a), KEY(b));
INSERT INTO t1 VALUES('test', 1),('test', 1),('test', 1),('test', 1), INSERT INTO t1 VALUES('test', 1),('test', 1),('test', 1),('test', 1),
('test', 1),('test', 2),('test', 3),('test', 4); ('test', 1),('test', 2),('test', 3),('test', 4);
INSERT INTO t1 VALUES('test', 5),('test', 6),('test', 7),('test', 8),
('test', 5),('test', 6),('test', 7),('test', 8);
EXPLAIN SELECT * FROM t1 EXPLAIN SELECT * FROM t1
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1; WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
...@@ -512,15 +514,15 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -512,15 +514,15 @@ id select_type table type possible_keys key key_len ref rows Extra
EXPLAIN SELECT * FROM t1 IGNORE INDEX(a) EXPLAIN SELECT * FROM t1 IGNORE INDEX(a)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1; WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 5 const 4 Using where 1 SIMPLE t1 ref b b 5 const 5 Using where
EXPLAIN SELECT * FROM t1 USE INDEX(b) EXPLAIN SELECT * FROM t1 USE INDEX(b)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1; WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 5 const 4 Using where 1 SIMPLE t1 ref b b 5 const 5 Using where
EXPLAIN SELECT * FROM t1 FORCE INDEX(b) EXPLAIN SELECT * FROM t1 FORCE INDEX(b)
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1; WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 5 const 4 Using where 1 SIMPLE t1 ref b b 5 const 5 Using where
DROP TABLE t1; DROP TABLE t1;
create table t1(a text,b date,fulltext index(a))engine=myisam; create table t1(a text,b date,fulltext index(a))engine=myisam;
insert into t1 set a='water',b='2008-08-04'; insert into t1 set a='water',b='2008-08-04';
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -1478,6 +1478,8 @@ create table t2 like t1; ...@@ -1478,6 +1478,8 @@ create table t2 like t1;
insert into t2 select if(t1.a is null, 10, t1.a) from t1; insert into t2 select if(t1.a is null, 10, t1.a) from t1;
create table t3 (a int, b int, index idx(a)); create table t3 (a int, b int, index idx(a));
insert into t3 values (1, 100), (3, 301), (4, 402), (1, 102), (1, 101); insert into t3 values (1, 100), (3, 301), (4, 402), (1, 102), (1, 101);
insert into t3 values (11, 100), (33, 301), (44, 402), (11, 102), (11, 101);
insert into t3 values (22, 100), (53, 301), (64, 402), (22, 102), (22, 101);
analyze table t1,t2,t3; analyze table t1,t2,t3;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status OK test.t1 analyze status OK
......
...@@ -1487,6 +1487,8 @@ create table t2 like t1; ...@@ -1487,6 +1487,8 @@ create table t2 like t1;
insert into t2 select if(t1.a is null, 10, t1.a) from t1; insert into t2 select if(t1.a is null, 10, t1.a) from t1;
create table t3 (a int, b int, index idx(a)); create table t3 (a int, b int, index idx(a));
insert into t3 values (1, 100), (3, 301), (4, 402), (1, 102), (1, 101); insert into t3 values (1, 100), (3, 301), (4, 402), (1, 102), (1, 101);
insert into t3 values (11, 100), (33, 301), (44, 402), (11, 102), (11, 101);
insert into t3 values (22, 100), (53, 301), (64, 402), (22, 102), (22, 101);
analyze table t1,t2,t3; analyze table t1,t2,t3;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status OK test.t1 analyze status OK
......
...@@ -344,7 +344,9 @@ pk int NOT NULL, i int NOT NULL, v varchar(1) NOT NULL, ...@@ -344,7 +344,9 @@ pk int NOT NULL, i int NOT NULL, v varchar(1) NOT NULL,
PRIMARY KEY (pk), INDEX idx (v, i) PRIMARY KEY (pk), INDEX idx (v, i)
) ENGINE=ARIA; ) ENGINE=ARIA;
INSERT INTO t3 SELECT * FROM t1; INSERT INTO t3 SELECT * FROM t1;
INSERT INTO t3 VALUES (88, 442, 'y'), (99, 445, 'w') ; INSERT INTO t3 VALUES
(88, 442, 'y'), (99, 445, 'w'), (87, 442, 'z'), (98, 445, 'v'), (86, 442, 'x'),
(97, 445, 't'), (85, 442, 'b'), (96, 445, 'l'), (84, 442, 'a'), (95, 445, 'k');
SELECT COUNT(t1.v) FROM t1, t2 IGNORE INDEX (idx), t3 IGNORE INDEX (idx) SELECT COUNT(t1.v) FROM t1, t2 IGNORE INDEX (idx), t3 IGNORE INDEX (idx)
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0; WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
COUNT(t1.v) COUNT(t1.v)
...@@ -355,7 +357,7 @@ WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0; ...@@ -355,7 +357,7 @@ WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL idx 7 NULL 15 Using index 1 SIMPLE t1 index NULL idx 7 NULL 15 Using index
1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 16 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 16 Using where; Using join buffer (flat, BNL join)
1 SIMPLE t3 ALL PRIMARY NULL NULL NULL 17 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t3 ALL PRIMARY NULL NULL NULL 25 Using where; Using join buffer (flat, BNL join)
SELECT COUNT(t1.v) FROM t1, t2, t3 SELECT COUNT(t1.v) FROM t1, t2, t3
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0; WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
COUNT(t1.v) COUNT(t1.v)
...@@ -381,11 +383,8 @@ PRIMARY KEY (pk), ...@@ -381,11 +383,8 @@ PRIMARY KEY (pk),
KEY col_varchar_1024_latin1_key (col_varchar_1024_latin1_key) KEY col_varchar_1024_latin1_key (col_varchar_1024_latin1_key)
) ENGINE=Aria; ) ENGINE=Aria;
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
(1,'z'), (1,'z'), (2,'abcdefjhjkl'), (3,'in'), (4,'abcdefjhjkl'), (6,'abcdefjhjkl'),
(2,'abcdefjhjkl'), (11,'zx'), (12,'abcdefjhjm'), (13,'jn'), (14,'abcdefjhjp'), (16,'abcdefjhjr');
(3,'in'),
(4,'abcdefjhjkl'),
(6,'abcdefjhjkl');
CREATE TABLE t2 ( CREATE TABLE t2 (
col_varchar_10_latin1 varchar(10) DEFAULT NULL col_varchar_10_latin1 varchar(10) DEFAULT NULL
) ENGINE=Aria; ) ENGINE=Aria;
......
...@@ -69,9 +69,10 @@ DROP TABLE t1,t2,t3; ...@@ -69,9 +69,10 @@ DROP TABLE t1,t2,t3;
# #
create table t1(a int, b int, index(b)); create table t1(a int, b int, index(b));
insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2); insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2);
insert into t1 values (2, 11), (1, 11), (4, 14), (3, 14), (6, 12), (5, 12);
explain select * from t1 where b=1 or b is null order by a; explain select * from t1 where b=1 or b is null order by a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null b b 5 const 3 Using index condition; Using filesort 1 SIMPLE t1 ref_or_null b b 5 const 4 Using index condition; Using filesort
select * from t1 where b=1 or b is null order by a; select * from t1 where b=1 or b is null order by a;
a b a b
1 1 1 1
...@@ -80,7 +81,7 @@ a b ...@@ -80,7 +81,7 @@ a b
4 NULL 4 NULL
explain select * from t1 where b=2 or b is null order by a; explain select * from t1 where b=2 or b is null order by a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null b b 5 const 4 Using index condition; Using filesort 1 SIMPLE t1 ref_or_null b b 5 const 3 Using index condition; Using filesort
select * from t1 where b=2 or b is null order by a; select * from t1 where b=2 or b is null order by a;
a b a b
3 NULL 3 NULL
......
...@@ -329,7 +329,7 @@ ALTER TABLE t1 ADD INDEX t1 (a, b, c, d, e); ...@@ -329,7 +329,7 @@ ALTER TABLE t1 ADD INDEX t1 (a, b, c, d, e);
ERROR 42000: Specified key was too long; max key length is 1000 bytes ERROR 42000: Specified key was too long; max key length is 1000 bytes
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a)); 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);
create table t2 (a int not null, b int, c int, key(b), key(c), key(a)); 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); INSERT into t2 values (1,1,1), (2,2,2);
optimize table t1; optimize table t1;
...@@ -355,10 +355,34 @@ explain select * from t1 force index(a),t2 force index(a) where t1.a=t2.a; ...@@ -355,10 +355,34 @@ 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL a NULL NULL NULL 2 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 3
INSERT into t1 values (2,4,5), (7,8,4), (8,3,1), (9,7,2), (5,5,9);
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize 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 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.b=t2.b; explain select * from t1,t2 where t1.b=t2.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL b NULL NULL NULL 2 Using where 1 SIMPLE t2 ALL b NULL NULL NULL 2 Using where
1 SIMPLE t1 ref b b 5 test.t2.b 1 1 SIMPLE t1 ref b b 5 test.t2.b 1
delete from t1 where t1.a>1;
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize 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
explain select * from t1,t2 force index(c) where t1.a=t2.a; 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 1 SIMPLE t2 ALL NULL NULL NULL NULL 2
......
...@@ -488,6 +488,14 @@ INSERT INTO t1 VALUES ...@@ -488,6 +488,14 @@ INSERT INTO t1 VALUES
(22,142,'b','b'),(23,3,'y','y'),(24,0,'v','v'), (22,142,'b','b'),(23,3,'y','y'),(24,0,'v','v'),
(25,3,'m','m'),(26,5,'z','z'),(27,9,'n','n'), (25,3,'m','m'),(26,5,'z','z'),(27,9,'n','n'),
(28,1,'d','d'),(29,107,'a','a'); (28,1,'d','d'),(29,107,'a','a');
INSERT INTO t1 VALUES
(110,8,'v','v'),(111,8,'f','f'), (112,5,'v','v'),
(113,8,'s','s'),(114,8,'a','a'),(115,6,'p','p'),
(116,7,'z','z'),(117,2,'a','a'),(118,5,'h','h'),
(119,7,'h','h'),(120,2,'v','v'),(121,9,'v','v'),
(122,142,'b','b'),(123,3,'y','y'),(124,0,'v','v'),
(125,3,'m','m'),(126,5,'z','z'),(127,9,'n','n'),
(128,1,'d','d'),(129,107,'a','a');
SELECT COUNT(*) SELECT COUNT(*)
FROM FROM
t1 AS table2, t1 AS table3 t1 AS table2, t1 AS table3
...@@ -496,7 +504,7 @@ table3.col_varchar_key = table2.col_varchar_key AND ...@@ -496,7 +504,7 @@ table3.col_varchar_key = table2.col_varchar_key AND
table3.col_varchar_key = table2.col_varchar_nokey AND table3.col_varchar_key = table2.col_varchar_nokey AND
table3.pk<>0; table3.pk<>0;
COUNT(*) COUNT(*)
50 200
EXPLAIN SELECT COUNT(*) EXPLAIN SELECT COUNT(*)
FROM FROM
t1 AS table2, t1 AS table3 t1 AS table2, t1 AS table3
...@@ -505,8 +513,8 @@ table3.col_varchar_key = table2.col_varchar_key AND ...@@ -505,8 +513,8 @@ table3.col_varchar_key = table2.col_varchar_key AND
table3.col_varchar_key = table2.col_varchar_nokey AND table3.col_varchar_key = table2.col_varchar_nokey AND
table3.pk<>0; table3.pk<>0;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE table2 ALL col_varchar_key NULL NULL NULL 20 Using where 1 SIMPLE table2 ALL col_varchar_key NULL NULL NULL 40 Using where
1 SIMPLE table3 ref PRIMARY,col_varchar_key col_varchar_key 3 test.table2.col_varchar_key 3 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE table3 ref PRIMARY,col_varchar_key col_varchar_key 3 test.table2.col_varchar_key 5 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
set join_cache_level= @save_join_cache_level; set join_cache_level= @save_join_cache_level;
set join_buffer_size= @save_join_buffer_size; set join_buffer_size= @save_join_buffer_size;
drop table t1; drop table t1;
......
...@@ -642,9 +642,10 @@ id ...@@ -642,9 +642,10 @@ id
drop table t1; drop table t1;
create table t1(a int, b int, index(b)); create table t1(a int, b int, index(b));
insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2); insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2);
insert into t1 values (12, 11), (11, 11), (14, 3), (13, 5), (16, 12), (15, 12);
explain select * from t1 where b=1 or b is null order by a; explain select * from t1 where b=1 or b is null order by a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null b b 5 const 3 Using where; Using filesort 1 SIMPLE t1 ref_or_null b b 5 const 4 Using where; Using filesort
select * from t1 where b=1 or b is null order by a; select * from t1 where b=1 or b is null order by a;
a b a b
1 1 1 1
...@@ -653,7 +654,7 @@ a b ...@@ -653,7 +654,7 @@ a b
4 NULL 4 NULL
explain select * from t1 where b=2 or b is null order by a; explain select * from t1 where b=2 or b is null order by a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null b b 5 const 4 Using where; Using filesort 1 SIMPLE t1 ref_or_null b b 5 const 3 Using where; Using filesort
select * from t1 where b=2 or b is null order by a; select * from t1 where b=2 or b is null order by a;
a b a b
3 NULL 3 NULL
...@@ -1464,7 +1465,7 @@ INSERT INTO t1 VALUES (1, 10), (2, NULL); ...@@ -1464,7 +1465,7 @@ INSERT INTO t1 VALUES (1, 10), (2, NULL);
EXPLAIN EXPLAIN
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 1 Using where 1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort
# Must return 1 row # Must return 1 row
SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c;
col col
......
...@@ -2340,16 +2340,17 @@ drop table t1; ...@@ -2340,16 +2340,17 @@ drop table t1;
create table t1 (a int not null, b int not null, key(a), key(b)) create table t1 (a int not null, b int not null, key(a), key(b))
partition by hash(a) partitions 4; partition by hash(a) partitions 4;
insert into t1 values (1,1),(2,2),(3,3),(4,4); insert into t1 values (1,1),(2,2),(3,3),(4,4);
insert into t1 values (5,5),(6,6),(7,7),(8,8);
explain partitions explain partitions
select * from t1 X, t1 Y select * from t1 X, t1 Y
where X.b = Y.b and (X.a=1 or X.a=2) and (Y.a=2 or Y.a=3); where X.b = Y.b and (X.a=1 or X.a=2) and (Y.a=2 or Y.a=3);
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE X p1,p2 ALL a,b NULL NULL NULL 2 Using where 1 SIMPLE X p1,p2 range a,b a 4 NULL 4 Using where
1 SIMPLE Y p2,p3 ref a,b b 4 test.X.b 2 Using where 1 SIMPLE Y p2,p3 ref a,b b 4 test.X.b 2 Using where
explain partitions explain partitions
select * from t1 X, t1 Y where X.a = Y.a and (X.a=1 or X.a=2); select * from t1 X, t1 Y where X.a = Y.a and (X.a=1 or X.a=2);
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE X p1,p2 ALL a NULL NULL NULL 2 Using where 1 SIMPLE X p1,p2 range a a 4 NULL 4 Using where
1 SIMPLE Y p1,p2 ref a a 4 test.X.a 2 1 SIMPLE Y p1,p2 ref a a 4 test.X.a 2
drop table t1; drop table t1;
create table t1 (a int) partition by hash(a) partitions 20; create table t1 (a int) partition by hash(a) partitions 20;
......
...@@ -698,6 +698,18 @@ INSERT INTO t1 VALUES ...@@ -698,6 +698,18 @@ INSERT INTO t1 VALUES
'd8c4177d09f8b11f5.52725521'), 'd8c4177d09f8b11f5.52725521'),
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11, ('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725521'); 'd8c4177d09f8b11f5.52725521');
INSERT INTO t1 VALUES
('d8c4177d09f8b11f5.52725522','oxrootid',1,40,'d8c4177d09f8b11f5.52725522'),
('d8c4177d151affab2.81582771','d8c4177d09f8b11f5.52725521',2,3,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d206a333d2.74422678','d8c4177d09f8b11f5.52725521',4,5,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d225791924.30714721','d8c4177d09f8b11f5.52725521',6,7,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d2380fc201.39666694','d8c4177d09f8b11f5.52725521',8,9,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d24ccef970.14957925','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725522');
EXPLAIN EXPLAIN
SELECT s.oxid FROM t1 v, t1 s SELECT s.oxid FROM t1 v, t1 s
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
...@@ -705,7 +717,7 @@ v.oxrootid ='d8c4177d09f8b11f5.52725521' AND ...@@ -705,7 +717,7 @@ v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
s.oxleft > v.oxleft AND s.oxleft < v.oxright; s.oxleft > v.oxleft AND s.oxleft < v.oxright;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 Using where 1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 Using where
1 SIMPLE s ALL OXLEFT NULL NULL NULL 6 Range checked for each record (index map: 0x4) 1 SIMPLE s ALL OXLEFT NULL NULL NULL 12 Range checked for each record (index map: 0x4)
SELECT s.oxid FROM t1 v, t1 s SELECT s.oxid FROM t1 v, t1 s
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
......
...@@ -700,6 +700,18 @@ INSERT INTO t1 VALUES ...@@ -700,6 +700,18 @@ INSERT INTO t1 VALUES
'd8c4177d09f8b11f5.52725521'), 'd8c4177d09f8b11f5.52725521'),
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11, ('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725521'); 'd8c4177d09f8b11f5.52725521');
INSERT INTO t1 VALUES
('d8c4177d09f8b11f5.52725522','oxrootid',1,40,'d8c4177d09f8b11f5.52725522'),
('d8c4177d151affab2.81582771','d8c4177d09f8b11f5.52725521',2,3,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d206a333d2.74422678','d8c4177d09f8b11f5.52725521',4,5,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d225791924.30714721','d8c4177d09f8b11f5.52725521',6,7,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d2380fc201.39666694','d8c4177d09f8b11f5.52725521',8,9,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d24ccef970.14957925','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725522');
EXPLAIN EXPLAIN
SELECT s.oxid FROM t1 v, t1 s SELECT s.oxid FROM t1 v, t1 s
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
...@@ -707,7 +719,7 @@ v.oxrootid ='d8c4177d09f8b11f5.52725521' AND ...@@ -707,7 +719,7 @@ v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
s.oxleft > v.oxleft AND s.oxleft < v.oxright; s.oxleft > v.oxleft AND s.oxleft < v.oxright;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 Using index condition 1 SIMPLE v ref OXLEFT,OXRIGHT,OXROOTID OXROOTID 34 const 5 Using index condition
1 SIMPLE s ALL OXLEFT NULL NULL NULL 6 Range checked for each record (index map: 0x4) 1 SIMPLE s ALL OXLEFT NULL NULL NULL 12 Range checked for each record (index map: 0x4)
SELECT s.oxid FROM t1 v, t1 s SELECT s.oxid FROM t1 v, t1 s
WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND WHERE s.oxrootid = 'd8c4177d09f8b11f5.52725521' AND
v.oxrootid ='d8c4177d09f8b11f5.52725521' AND v.oxrootid ='d8c4177d09f8b11f5.52725521' AND
......
...@@ -2394,6 +2394,7 @@ CREATE TABLE t1 ( a BLOB, INDEX (a(20)) ); ...@@ -2394,6 +2394,7 @@ CREATE TABLE t1 ( a BLOB, INDEX (a(20)) );
CREATE TABLE t2 ( a BLOB, INDEX (a(20)) ); CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a; EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t1 ALL NULL NULL NULL NULL 5
......
...@@ -2403,6 +2403,7 @@ CREATE TABLE t1 ( a BLOB, INDEX (a(20)) ); ...@@ -2403,6 +2403,7 @@ CREATE TABLE t1 ( a BLOB, INDEX (a(20)) );
CREATE TABLE t2 ( a BLOB, INDEX (a(20)) ); CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a; EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t1 ALL NULL NULL NULL NULL 5
......
...@@ -2394,6 +2394,7 @@ CREATE TABLE t1 ( a BLOB, INDEX (a(20)) ); ...@@ -2394,6 +2394,7 @@ CREATE TABLE t1 ( a BLOB, INDEX (a(20)) );
CREATE TABLE t2 ( a BLOB, INDEX (a(20)) ); CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a; EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 5 1 SIMPLE t1 ALL NULL NULL NULL NULL 5
......
...@@ -64,14 +64,16 @@ analyze table t1; ...@@ -64,14 +64,16 @@ analyze table t1;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t1 analyze status OK test.t1 analyze status OK
insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"); insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a");
insert into t1 values (null,"b"),(null,"b"),(null,"c"),(null,"c"),(null,"d"),(null,"d"),(null,"e"),(null,"e"),(null,"a"),(null,"e");
insert into t1 values (null,"x"),(null,"x"),(null,"y"),(null,"y"),(null,"z"),(null,"z"),(null,"v"),(null,"v"),(null,"a"),(null,"v");
explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b; explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL b NULL NULL NULL 21 Using where 1 SIMPLE t1 ALL b NULL NULL NULL 41 Using where
1 SIMPLE t2 ref b b 21 test.t1.b 6 1 SIMPLE t2 ref b b 21 test.t1.b 6
set MAX_SEEKS_FOR_KEY=1; set MAX_SEEKS_FOR_KEY=1;
explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b; explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL b NULL NULL NULL 21 Using where 1 SIMPLE t1 ALL b NULL NULL NULL 41 Using where
1 SIMPLE t2 ref b b 21 test.t1.b 6 1 SIMPLE t2 ref b b 21 test.t1.b 6
SET MAX_SEEKS_FOR_KEY=DEFAULT; SET MAX_SEEKS_FOR_KEY=DEFAULT;
drop table t1; drop table t1;
......
...@@ -125,14 +125,14 @@ DOCID DOCNAME DOCTYPEID FOLDERID AUTHOR CREATED TITLE SUBTITLE DOCABSTRACT PUBLI ...@@ -125,14 +125,14 @@ DOCID DOCNAME DOCTYPEID FOLDERID AUTHOR CREATED TITLE SUBTITLE DOCABSTRACT PUBLI
c373e9f5ad07993f3859444553544200 Last Discussion c373e9f5ad079174ff17444553544200 c373e9f5ad0796c0eca4444553544200 Goldilocks 2003-06-09 11:21:06 Title: Last Discussion NULL Setting new abstract and keeping doc checked out 2003-06-09 10:51:26 2003-06-09 10:51:26 NULL NULL NULL 03eea05112b845949f3fd03278b5fe43 2003-06-09 11:21:06 admin 0 NULL Discussion NULL NULL c373e9f5ad07993f3859444553544200 Last Discussion c373e9f5ad079174ff17444553544200 c373e9f5ad0796c0eca4444553544200 Goldilocks 2003-06-09 11:21:06 Title: Last Discussion NULL Setting new abstract and keeping doc checked out 2003-06-09 10:51:26 2003-06-09 10:51:26 NULL NULL NULL 03eea05112b845949f3fd03278b5fe43 2003-06-09 11:21:06 admin 0 NULL Discussion NULL NULL
EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JOIN t4 ON t2.DOCTYPEID = t4.DOCTYPEID LEFT OUTER JOIN t1 ON t2.DOCID = t1.DOCID WHERE t2.FOLDERID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t3.FOLDERNAME = 'Level1') AND t3.FOLDERNAME = 'Level2') AND t3.FOLDERNAME = 'Level3') AND t3.FOLDERNAME = 'CopiedFolder') AND t3.FOLDERNAME = 'Movie Reviews') AND t2.DOCNAME = 'Last Discussion'; EXPLAIN SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JOIN t4 ON t2.DOCTYPEID = t4.DOCTYPEID LEFT OUTER JOIN t1 ON t2.DOCID = t1.DOCID WHERE t2.FOLDERID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t3.FOLDERNAME = 'Level1') AND t3.FOLDERNAME = 'Level2') AND t3.FOLDERNAME = 'Level3') AND t3.FOLDERNAME = 'CopiedFolder') AND t3.FOLDERNAME = 'Movie Reviews') AND t2.DOCNAME = 'Last Discussion';
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 const 6 Using index condition; Using where 1 PRIMARY t4 ALL PRIMARY NULL NULL NULL 10
1 PRIMARY t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 Using where
1 PRIMARY t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 Using where
1 PRIMARY t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 Using where
1 PRIMARY t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 Using where
1 PRIMARY t2 ALL DDOCTYPEID_IDX,DFOLDERID_IDX NULL NULL NULL 9 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t2 ALL DDOCTYPEID_IDX,DFOLDERID_IDX NULL NULL NULL 9 Using where; Using join buffer (flat, BNL join)
1 PRIMARY t1 eq_ref PRIMARY PRIMARY 34 test.t2.DOCID 1 1 PRIMARY t1 eq_ref PRIMARY PRIMARY 34 test.t2.DOCID 1
1 PRIMARY t4 eq_ref PRIMARY PRIMARY 34 test.t2.DOCTYPEID 1 1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t2.FOLDERID 1 Using where
1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where
1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where
1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where
1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where
drop table t1, t2, t3, t4; drop table t1, t2, t3, t4;
CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB; CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB;
INSERT INTO t1 VALUES (1),(2); INSERT INTO t1 VALUES (1),(2);
......
...@@ -82,6 +82,7 @@ insert into t1 values ...@@ -82,6 +82,7 @@ insert into t1 values
(2, 3), (2, 3),
(2, NULL), (2, NULL),
(3, NULL); (3, NULL);
insert into t1 values (5, 7), (8, 9), (4, 1);
create table t2 (a int, oref int); create table t2 (a int, oref int);
insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4); insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2; select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
...@@ -104,7 +105,7 @@ oref a ...@@ -104,7 +105,7 @@ oref a
1 1 1 1
show status like '%Handler_read_rnd_next'; show status like '%Handler_read_rnd_next';
Variable_name Value Variable_name Value
Handler_read_rnd_next 11 Handler_read_rnd_next 14
delete from t2; delete from t2;
insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0); insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);
set optimizer_switch='subquery_cache=off'; set optimizer_switch='subquery_cache=off';
...@@ -122,7 +123,7 @@ Handler_read_key 0 ...@@ -122,7 +123,7 @@ Handler_read_key 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
Handler_read_rnd 0 Handler_read_rnd 0
Handler_read_rnd_next 35 Handler_read_rnd_next 50
select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z; select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
Z Z
No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1. No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.
...@@ -1135,9 +1136,9 @@ insert into t4 select a from t3; ...@@ -1135,9 +1136,9 @@ insert into t4 select a from t3;
explain select * from t3 where a in (select t1.kp1 from t1,t4 where kp1<20 explain select * from t3 where a in (select t1.kp1 from t1,t4 where kp1<20
and t4.pk=t1.c); and t4.pk=t1.c);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where 1 PRIMARY t1 range kp1 kp1 5 NULL 48 Using where; LooseScan
1 PRIMARY t1 ref kp1 kp1 5 test.t3.a 1 Using where 1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 Using index; FirstMatch(t1)
1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 Using index; FirstMatch(t3) 1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
drop table t1, t3, t4; drop table t1, t3, t4;
create table t1 (a int) as select * from t0 where a < 5; create table t1 (a int) as select * from t0 where a < 5;
set @save_max_heap_table_size=@@max_heap_table_size; set @save_max_heap_table_size=@@max_heap_table_size;
......
...@@ -91,6 +91,7 @@ insert into t1 values ...@@ -91,6 +91,7 @@ insert into t1 values
(2, 3), (2, 3),
(2, NULL), (2, NULL),
(3, NULL); (3, NULL);
insert into t1 values (5, 7), (8, 9), (4, 1);
create table t2 (a int, oref int); create table t2 (a int, oref int);
insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4); insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2; select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2;
...@@ -113,7 +114,7 @@ oref a ...@@ -113,7 +114,7 @@ oref a
1 1 1 1
show status like '%Handler_read_rnd_next'; show status like '%Handler_read_rnd_next';
Variable_name Value Variable_name Value
Handler_read_rnd_next 11 Handler_read_rnd_next 14
delete from t2; delete from t2;
insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0); insert into t2 values (NULL, 0),(NULL, 0), (NULL, 0), (NULL, 0);
set optimizer_switch='subquery_cache=off'; set optimizer_switch='subquery_cache=off';
...@@ -131,7 +132,7 @@ Handler_read_key 0 ...@@ -131,7 +132,7 @@ Handler_read_key 0
Handler_read_next 0 Handler_read_next 0
Handler_read_prev 0 Handler_read_prev 0
Handler_read_rnd 0 Handler_read_rnd 0
Handler_read_rnd_next 35 Handler_read_rnd_next 50
select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z; select 'No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.' Z;
Z Z
No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1. No key lookups, seq reads: 29= 5 reads from t2 + 4 * 6 reads from t1.
...@@ -821,6 +822,8 @@ LEFT JOIN t1 AS INNR ON ( INNR2.int_key = INNR.int_key ) ...@@ -821,6 +822,8 @@ LEFT JOIN t1 AS INNR ON ( INNR2.int_key = INNR.int_key )
WHERE INNR.varchar_key > 'n{' WHERE INNR.varchar_key > 'n{'
); );
varchar_nokey varchar_nokey
NULL
p
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a INT); CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2), (11); INSERT INTO t1 VALUES (1), (2), (11);
...@@ -1144,9 +1147,9 @@ insert into t4 select a from t3; ...@@ -1144,9 +1147,9 @@ insert into t4 select a from t3;
explain select * from t3 where a in (select t1.kp1 from t1,t4 where kp1<20 explain select * from t3 where a in (select t1.kp1 from t1,t4 where kp1<20
and t4.pk=t1.c); and t4.pk=t1.c);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where 1 PRIMARY t1 range kp1 kp1 5 NULL 48 Using index condition; Using where; Rowid-ordered scan; LooseScan
1 PRIMARY t1 ref kp1 kp1 5 test.t3.a 1 Using where 1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 Using index; FirstMatch(t1)
1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 Using index; FirstMatch(t3) 1 PRIMARY t3 ALL NULL NULL NULL NULL 100 Using where; Using join buffer (flat, BNL join)
drop table t1, t3, t4; drop table t1, t3, t4;
create table t1 (a int) as select * from t0 where a < 5; create table t1 (a int) as select * from t0 where a < 5;
set @save_max_heap_table_size=@@max_heap_table_size; set @save_max_heap_table_size=@@max_heap_table_size;
......
...@@ -343,18 +343,20 @@ select count(*) ...@@ -343,18 +343,20 @@ select count(*)
from CountryLanguage from CountryLanguage
where (Language, Country) NOT IN where (Language, Country) NOT IN
(SELECT City.Name, Country.Code (SELECT City.Name, Country.Code
FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000)); FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000))
AND Language IN ('English','Spanish');
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY CountryLanguage index NULL PRIMARY 33 NULL 984 Using where; Using index 1 PRIMARY CountryLanguage range Language Language 30 NULL 72 Using index condition; Using where; Rowid-ordered scan
2 DEPENDENT SUBQUERY City ref CityName CityName 35 func 2 Using index condition 2 DEPENDENT SUBQUERY City ref CityName CityName 35 func 2 Using index condition
2 DEPENDENT SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index 2 DEPENDENT SUBQUERY Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using index
select count(*) select count(*)
from CountryLanguage from CountryLanguage
where (Language, Country) NOT IN where (Language, Country) NOT IN
(SELECT City.Name, Country.Code (SELECT City.Name, Country.Code
FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000)); FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000))
AND Language IN ('English','Spanish');
count(*) count(*)
979 88
Q2.3m: Q2.3m:
MATERIALIZATION with the PARTIAL_MATCH_MERGE strategy, because the HAVING MATERIALIZATION with the PARTIAL_MATCH_MERGE strategy, because the HAVING
clause prevents the use of the index on City(Name), and in practice reduces clause prevents the use of the index on City(Name), and in practice reduces
......
...@@ -64,6 +64,12 @@ KEY c3 (c3,c2)); ...@@ -64,6 +64,12 @@ KEY c3 (c3,c2));
INSERT INTO t1 VALUES (10,7,8,'v','v'); INSERT INTO t1 VALUES (10,7,8,'v','v');
INSERT INTO t1 VALUES (11,1,9,'r','r'); INSERT INTO t1 VALUES (11,1,9,'r','r');
INSERT INTO t1 VALUES (12,5,9,'a','a'); INSERT INTO t1 VALUES (12,5,9,'a','a');
INSERT INTO t1 VALUES (13,7,18,'v','v');
INSERT INTO t1 VALUES (14,1,19,'r','r');
INSERT INTO t1 VALUES (15,5,29,'a','a');
INSERT INTO t1 VALUES (17,7,38,'v','v');
INSERT INTO t1 VALUES (18,1,39,'r','r');
INSERT INTO t1 VALUES (19,5,49,'a','a');
create table t1a like t1; create table t1a like t1;
insert into t1a select * from t1; insert into t1a select * from t1;
create table t1b like t1; create table t1b like t1;
...@@ -88,13 +94,13 @@ FROM (t1b JOIN t2 ON t2.c3 = t1b.c4) LEFT JOIN ...@@ -88,13 +94,13 @@ FROM (t1b JOIN t2 ON t2.c3 = t1b.c4) LEFT JOIN
t1a ON (t1a.c2 = t1b.pk AND 2) t1a ON (t1a.c2 = t1b.pk AND 2)
WHERE t1.pk) ; WHERE t1.pk) ;
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where 1 PRIMARY t1 ALL NULL NULL NULL NULL 9 100.00 Using where
2 DEPENDENT SUBQUERY t2 index c3 c3 9 NULL 2 100.00 Using index 2 DEPENDENT SUBQUERY t1b ALL NULL NULL NULL NULL 9 100.00
2 DEPENDENT SUBQUERY t1b ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t1a ref c2 c2 5 test.t1b.pk 1 100.00 Using where
2 DEPENDENT SUBQUERY t1a ref c2 c2 5 test.t1b.pk 2 100.00 Using where 2 DEPENDENT SUBQUERY t2 index c3 c3 9 NULL 2 100.00 Using where; Using index; Using join buffer (flat, BNL join)
Warnings: Warnings:
Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t1a`.`c1` from `test`.`t1b` join `test`.`t2` left join `test`.`t1a` on((2 and (`test`.`t1a`.`c2` = `test`.`t1b`.`pk`))) where ((`test`.`t1`.`pk` <> 0) and (<cache>(`test`.`t1`.`c1`) = `test`.`t1a`.`c1`) and (`test`.`t1b`.`c4` = `test`.`t2`.`c3`)))) Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`c1`,<exists>(select `test`.`t1a`.`c1` from `test`.`t1b` join `test`.`t2` left join `test`.`t1a` on((2 and (`test`.`t1a`.`c2` = `test`.`t1b`.`pk`))) where ((`test`.`t1`.`pk` <> 0) and (<cache>(`test`.`t1`.`c1`) = `test`.`t1a`.`c1`) and (`test`.`t2`.`c3` = `test`.`t1b`.`c4`))))
SELECT pk SELECT pk
FROM t1 FROM t1
WHERE c1 IN WHERE c1 IN
......
...@@ -1779,6 +1779,7 @@ set @tmp834739=@@optimizer_switch; ...@@ -1779,6 +1779,7 @@ set @tmp834739=@@optimizer_switch;
set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off'; set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off';
CREATE TABLE t2 ( b int, c int, KEY (b)) ; CREATE TABLE t2 ( b int, c int, KEY (b)) ;
INSERT INTO t2 VALUES (1,0),(1,0),(9,0),(1,0),(5,0); INSERT INTO t2 VALUES (1,0),(1,0),(9,0),(1,0),(5,0);
INSERT INTO t2 VALUES (2,0),(3,0),(8,0),(6,0),(5,0);
CREATE TABLE t3 ( a int); CREATE TABLE t3 ( a int);
INSERT INTO t3 VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0); INSERT INTO t3 VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
CREATE TABLE t4 ( a int); CREATE TABLE t4 ( a int);
......
...@@ -16,6 +16,7 @@ b int, ...@@ -16,6 +16,7 @@ b int,
key(b) key(b)
); );
insert into t2 select a, a/2 from t0; insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
select * from t1; select * from t1;
a b a b
1 1 1 1
...@@ -33,6 +34,16 @@ a b ...@@ -33,6 +34,16 @@ a b
7 4 7 4
8 4 8 4
9 5 9 5
10 5
11 6
12 7
13 8
14 9
15 10
16 11
17 12
18 13
19 14
explain select * from t2 where b in (select a from t1); explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary
...@@ -51,6 +62,7 @@ pk1 char(200), pk2 char(200), pk3 char(200), ...@@ -51,6 +62,7 @@ pk1 char(200), pk2 char(200), pk3 char(200),
primary key(pk1, pk2, pk3) primary key(pk1, pk2, pk3)
) engine=innodb; ) engine=innodb;
insert into t3 select a,a, a,a,a from t0; insert into t3 select a,a, a,a,a from t0;
insert into t3 select a,a, a+100,a+100,a+100 from t0;
explain select * from t3 where b in (select a from t1); explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary
...@@ -58,6 +70,8 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -58,6 +70,8 @@ id select_type table type possible_keys key key_len ref rows Extra
select * from t3 where b in (select a from t1); select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3 a b pk1 pk2 pk3
1 1 1 1 1 1 1 1 1 1
1 1 101 101 101
2 2 102 102 102
2 2 2 2 2 2 2 2 2 2
set @save_max_heap_table_size= @@max_heap_table_size; set @save_max_heap_table_size= @@max_heap_table_size;
set max_heap_table_size=16384; set max_heap_table_size=16384;
...@@ -420,6 +434,7 @@ create table t0 (a int); ...@@ -420,6 +434,7 @@ create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4); insert into t0 values (0),(1),(2),(3),(4);
create table t1 (a int, b int, key(a)); create table t1 (a int, b int, key(a));
insert into t1 select a,a from t0; insert into t1 select a,a from t0;
insert into t1 select a+5,a from t0;
create table t2 (a int, b int, primary key(a)); create table t2 (a int, b int, primary key(a));
insert into t2 select * from t1; insert into t2 select * from t1;
Table t2, unlike table t1, should be displayed as pulled out Table t2, unlike table t1, should be displayed as pulled out
...@@ -428,11 +443,11 @@ where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and ...@@ -428,11 +443,11 @@ where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and
t1.b=t2.b); t1.b=t2.b);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 5 100.00 Using where 1 PRIMARY t0 ALL NULL NULL NULL NULL 5 100.00 Using where
1 PRIMARY t1 ref a a 5 test.t0.a 1 100.00 Start temporary 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t0.a 1 100.00
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t0.a 1 100.00 Using where; End temporary 1 PRIMARY t1 ref a a 5 test.t0.a 1 100.00 Using where; FirstMatch(t2)
Warnings: Warnings:
Note 1276 Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) join `test`.`t0` where ((`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t1`.`a` = `test`.`t0`.`a`) and (`test`.`t2`.`a` = `test`.`t0`.`a`)) Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) join `test`.`t0` where ((`test`.`t1`.`b` = `test`.`t2`.`b`) and (`test`.`t2`.`a` = `test`.`t0`.`a`) and (`test`.`t1`.`a` = `test`.`t0`.`a`))
update t1 set a=3, b=11 where a=4; update t1 set a=3, b=11 where a=4;
update t2 set b=11 where a=3; update t2 set b=11 where a=3;
select * from t0 where t0.a in select * from t0 where t0.a in
......
...@@ -25,6 +25,7 @@ b int, ...@@ -25,6 +25,7 @@ b int,
key(b) key(b)
); );
insert into t2 select a, a/2 from t0; insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
select * from t1; select * from t1;
a b a b
1 1 1 1
...@@ -42,6 +43,16 @@ a b ...@@ -42,6 +43,16 @@ a b
7 4 7 4
8 4 8 4
9 5 9 5
10 5
11 6
12 7
13 8
14 9
15 10
16 11
17 12
18 13
19 14
explain select * from t2 where b in (select a from t1); explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary
...@@ -60,6 +71,7 @@ pk1 char(200), pk2 char(200), pk3 char(200), ...@@ -60,6 +71,7 @@ pk1 char(200), pk2 char(200), pk3 char(200),
primary key(pk1, pk2, pk3) primary key(pk1, pk2, pk3)
) engine=innodb; ) engine=innodb;
insert into t3 select a,a, a,a,a from t0; insert into t3 select a,a, a,a,a from t0;
insert into t3 select a,a, a+100,a+100,a+100 from t0;
explain select * from t3 where b in (select a from t1); explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Start temporary
...@@ -67,6 +79,8 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -67,6 +79,8 @@ id select_type table type possible_keys key key_len ref rows Extra
select * from t3 where b in (select a from t1); select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3 a b pk1 pk2 pk3
1 1 1 1 1 1 1 1 1 1
1 1 101 101 101
2 2 102 102 102
2 2 2 2 2 2 2 2 2 2
set @save_max_heap_table_size= @@max_heap_table_size; set @save_max_heap_table_size= @@max_heap_table_size;
set max_heap_table_size=16384; set max_heap_table_size=16384;
...@@ -429,6 +443,7 @@ create table t0 (a int); ...@@ -429,6 +443,7 @@ create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4); insert into t0 values (0),(1),(2),(3),(4);
create table t1 (a int, b int, key(a)); create table t1 (a int, b int, key(a));
insert into t1 select a,a from t0; insert into t1 select a,a from t0;
insert into t1 select a+5,a from t0;
create table t2 (a int, b int, primary key(a)); create table t2 (a int, b int, primary key(a));
insert into t2 select * from t1; insert into t2 select * from t1;
Table t2, unlike table t1, should be displayed as pulled out Table t2, unlike table t1, should be displayed as pulled out
...@@ -436,12 +451,12 @@ explain extended select * from t0 ...@@ -436,12 +451,12 @@ explain extended select * from t0
where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and
t1.b=t2.b); t1.b=t2.b);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary 1 PRIMARY t0 ALL NULL NULL NULL NULL 5 100.00 Using where
1 PRIMARY t1 ref a a 5 test.t0.a 1 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t0.a 1 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t0.a 1 100.00 Using where; End temporary; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 PRIMARY t1 ref a a 5 test.t0.a 1 100.00 Using where; FirstMatch(t2); Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan
Warnings: Warnings:
Note 1276 Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) join `test`.`t0` where ((`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t1`.`a` = `test`.`t0`.`a`) and (`test`.`t2`.`a` = `test`.`t0`.`a`)) Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) join `test`.`t0` where ((`test`.`t1`.`b` = `test`.`t2`.`b`) and (`test`.`t2`.`a` = `test`.`t0`.`a`) and (`test`.`t1`.`a` = `test`.`t0`.`a`))
update t1 set a=3, b=11 where a=4; update t1 set a=3, b=11 where a=4;
update t2 set b=11 where a=3; update t2 set b=11 where a=3;
# Not anymore: # Not anymore:
......
...@@ -18,6 +18,7 @@ b int, ...@@ -18,6 +18,7 @@ b int,
key(b) key(b)
); );
insert into t2 select a, a/2 from t0; insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
select * from t1; select * from t1;
a b a b
1 1 1 1
...@@ -35,6 +36,16 @@ a b ...@@ -35,6 +36,16 @@ a b
7 4 7 4
8 4 8 4
9 5 9 5
10 5
11 6
12 7
13 8
14 9
15 10
16 11
17 12
18 13
19 14
explain select * from t2 where b in (select a from t1); explain select * from t2 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3
...@@ -54,14 +65,17 @@ pk1 char(200), pk2 char(200), pk3 char(200), ...@@ -54,14 +65,17 @@ pk1 char(200), pk2 char(200), pk3 char(200),
primary key(pk1, pk2, pk3) primary key(pk1, pk2, pk3)
) engine=innodb; ) engine=innodb;
insert into t3 select a,a, a,a,a from t0; insert into t3 select a,a, a,a,a from t0;
insert into t3 select a,a, a+100,a+100,a+100 from t0;
explain select * from t3 where b in (select a from t1); explain select * from t3 where b in (select a from t1);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t3 ALL b NULL NULL NULL 10 1 PRIMARY t3 ALL b NULL NULL NULL 20
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
2 SUBQUERY t1 ALL NULL NULL NULL NULL 3 2 SUBQUERY t1 ALL NULL NULL NULL NULL 3
select * from t3 where b in (select a from t1); select * from t3 where b in (select a from t1);
a b pk1 pk2 pk3 a b pk1 pk2 pk3
1 1 1 1 1 1 1 1 1 1
1 1 101 101 101
2 2 102 102 102
2 2 2 2 2 2 2 2 2 2
set @save_max_heap_table_size= @@max_heap_table_size; set @save_max_heap_table_size= @@max_heap_table_size;
set max_heap_table_size=16384; set max_heap_table_size=16384;
...@@ -106,9 +120,8 @@ set join_buffer_size= @save_join_buffer_size; ...@@ -106,9 +120,8 @@ set join_buffer_size= @save_join_buffer_size;
set max_heap_table_size= @save_max_heap_table_size; set max_heap_table_size= @save_max_heap_table_size;
explain select * from t1 where a in (select b from t2); explain select * from t1 where a in (select b from t2);
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1 1 PRIMARY t2 ref b b 5 test.t1.a 2 Using index; FirstMatch(t1)
2 SUBQUERY t2 index b b 5 NULL 10 Using index
select * from t1; select * from t1;
a b a b
1 1 1 1
...@@ -432,6 +445,7 @@ create table t0 (a int); ...@@ -432,6 +445,7 @@ create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4); insert into t0 values (0),(1),(2),(3),(4);
create table t1 (a int, b int, key(a)); create table t1 (a int, b int, key(a));
insert into t1 select a,a from t0; insert into t1 select a,a from t0;
insert into t1 select a+5,a from t0;
create table t2 (a int, b int, primary key(a)); create table t2 (a int, b int, primary key(a));
insert into t2 select * from t1; insert into t2 select * from t1;
Table t2, unlike table t1, should be displayed as pulled out Table t2, unlike table t1, should be displayed as pulled out
...@@ -440,11 +454,11 @@ where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and ...@@ -440,11 +454,11 @@ where t0.a in ( select t1.a from t1,t2 where t2.a=t0.a and
t1.b=t2.b); t1.b=t2.b);
id select_type table type possible_keys key key_len ref rows filtered Extra id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t0 ALL NULL NULL NULL NULL 5 100.00 Using where 1 PRIMARY t0 ALL NULL NULL NULL NULL 5 100.00 Using where
1 PRIMARY t1 ref a a 5 test.t0.a 1 100.00 Start temporary 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t0.a 1 100.00
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t0.a 1 100.00 Using where; End temporary 1 PRIMARY t1 ref a a 5 test.t0.a 1 100.00 Using where; FirstMatch(t2)
Warnings: Warnings:
Note 1276 Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1 Note 1276 Field or reference 'test.t0.a' of SELECT #2 was resolved in SELECT #1
Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) join `test`.`t0` where ((`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t1`.`a` = `test`.`t0`.`a`) and (`test`.`t2`.`a` = `test`.`t0`.`a`)) Note 1003 select `test`.`t0`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1`) join `test`.`t0` where ((`test`.`t1`.`b` = `test`.`t2`.`b`) and (`test`.`t2`.`a` = `test`.`t0`.`a`) and (`test`.`t1`.`a` = `test`.`t0`.`a`))
update t1 set a=3, b=11 where a=4; update t1 set a=3, b=11 where a=4;
update t2 set b=11 where a=3; update t2 set b=11 where a=3;
select * from t0 where t0.a in select * from t0 where t0.a in
......
...@@ -1790,6 +1790,7 @@ set @tmp834739=@@optimizer_switch; ...@@ -1790,6 +1790,7 @@ set @tmp834739=@@optimizer_switch;
set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off'; set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off';
CREATE TABLE t2 ( b int, c int, KEY (b)) ; CREATE TABLE t2 ( b int, c int, KEY (b)) ;
INSERT INTO t2 VALUES (1,0),(1,0),(9,0),(1,0),(5,0); INSERT INTO t2 VALUES (1,0),(1,0),(9,0),(1,0),(5,0);
INSERT INTO t2 VALUES (2,0),(3,0),(8,0),(6,0),(5,0);
CREATE TABLE t3 ( a int); CREATE TABLE t3 ( a int);
INSERT INTO t3 VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0); INSERT INTO t3 VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
CREATE TABLE t4 ( a int); CREATE TABLE t4 ( a int);
...@@ -1922,6 +1923,8 @@ CREATE TABLE t0 (a INT); ...@@ -1922,6 +1923,8 @@ CREATE TABLE t0 (a INT);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4); INSERT INTO t0 VALUES (0),(1),(2),(3),(4);
CREATE TABLE t1 (a INT, b INT, KEY(a)); CREATE TABLE t1 (a INT, b INT, KEY(a));
INSERT INTO t1 SELECT a, a from t0; INSERT INTO t1 SELECT a, a from t0;
INSERT INTO t1 SELECT a+5, a from t0;
INSERT INTO t1 SELECT a+10, a from t0;
CREATE TABLE t2 (a INT, b INT, PRIMARY KEY(a)); CREATE TABLE t2 (a INT, b INT, PRIMARY KEY(a));
INSERT INTO t2 SELECT * FROM t1; INSERT INTO t2 SELECT * FROM t1;
UPDATE t1 SET a=3, b=11 WHERE a=4; UPDATE t1 SET a=3, b=11 WHERE a=4;
......
...@@ -272,7 +272,8 @@ drop table t1, t2; ...@@ -272,7 +272,8 @@ drop table t1, t2;
create table t1 (a char(10) primary key); create table t1 (a char(10) primary key);
insert into t1 values ('foo'),('bar'); insert into t1 values ('foo'),('bar');
create table t2 (a char(10), unique key(a(2))); create table t2 (a char(10), unique key(a(2)));
insert into t2 values ('foo'),('bar'); insert into t2 values
('foo'),('bar'),('boo'),('car'),('coo'),('par'),('doo'),('tar');
explain select t1.* from t1 left join t2 on t2.a=t1.a; explain select t1.* from t1 left join t2 on t2.a=t1.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index NULL PRIMARY 10 NULL 2 Using index 1 SIMPLE t1 index NULL PRIMARY 10 NULL 2 Using index
......
...@@ -361,7 +361,8 @@ ALTER TABLE t1 ADD INDEX t1 (a, b, c, d, e); ...@@ -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 ERROR 42000: Specified key was too long; max key length is 1208 bytes
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a)); 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)); 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); INSERT into t2 values (1,1,1), (2,2,2);
optimize table t1; optimize table t1;
...@@ -372,24 +373,24 @@ Table Op Msg_type Msg_text ...@@ -372,24 +373,24 @@ Table Op Msg_type Msg_text
test.t1 check status OK test.t1 check status OK
show index from t1; show index from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment 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 b 1 b A 10 NULL NULL YES BTREE
t1 1 c 1 c A 5 NULL NULL YES BTREE t1 1 c 1 c A 10 NULL NULL YES BTREE
t1 1 a 1 a A 1 NULL NULL BTREE t1 1 a 1 a A 10 NULL NULL BTREE
t1 1 a 2 b A 5 NULL NULL YES BTREE t1 1 a 2 b A 10 NULL NULL YES BTREE
t1 1 c_2 1 c A 5 NULL NULL YES BTREE t1 1 c_2 1 c A 10 NULL NULL YES BTREE
t1 1 c_2 2 a A 5 NULL NULL BTREE t1 1 c_2 2 a A 10 NULL NULL BTREE
explain select * from t1,t2 where t1.a=t2.a; explain select * from t1,t2 where t1.a=t2.a;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL a NULL NULL NULL 2 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; 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL a NULL NULL NULL 2 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; 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL a NULL NULL NULL 2 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; explain select * from t1,t2 where t1.b=t2.b;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL b NULL NULL NULL 2 Using where 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 ...@@ -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; 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 id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 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; explain select * from t1 where a=0 or a=2;
id select_type table type possible_keys key key_len ref rows Extra 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; 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 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; explain select * from t1 where c=1;
id select_type table type possible_keys key key_len ref rows Extra 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; explain select * from t1 use index() where c=1;
id select_type table type possible_keys key key_len ref rows Extra 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; drop table t1,t2;
create table t1 (a int not null auto_increment primary key, b varchar(255)); 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)); insert into t1 (b) values (repeat('a',100)),(repeat('b',100)),(repeat('c',100));
......
...@@ -386,7 +386,8 @@ DROP TABLE t1; ...@@ -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)); 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)); 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); INSERT into t2 values (1,1,1), (2,2,2);
optimize table t1; optimize table t1;
......
...@@ -1017,6 +1017,7 @@ id select_type table type possible_keys key key_len ref rows Extra ...@@ -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 ATTENTION: the above EXPLAIN has several competing QEPs with identical
. costs. To combat the plan change it uses --sorted_result and . costs. To combat the plan change it uses --sorted_result and
. and --replace tricks . 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_b ON t1(b);
CREATE INDEX idx_a ON t0(a); CREATE INDEX idx_a ON t0(a);
EXPLAIN EXPLAIN
...@@ -1041,7 +1042,7 @@ ON t6.b >= 2 AND t5.b=t7.b ...@@ -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 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.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 t9
WHERE t0.a=1 AND WHERE t0.a=1 AND
t0.b=t1.b AND t0.b=t1.b AND
...@@ -1089,7 +1090,7 @@ ON t6.b >= 2 AND t5.b=t7.b ...@@ -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 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.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 t9
WHERE t0.a=1 AND WHERE t0.a=1 AND
t0.b=t1.b AND t0.b=t1.b AND
......
...@@ -6,7 +6,12 @@ KEY (a), ...@@ -6,7 +6,12 @@ KEY (a),
KEY (b) KEY (b)
); );
INSERT INTO t1 VALUES ('A','B'),('b','A'),('C','c'),('D','E'),('a','a'); 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
A B A B A B A B
b A A B b A A B
...@@ -33,11 +38,14 @@ b A a a ...@@ -33,11 +38,14 @@ b A a a
C c a a C c a a
D E a a D E a a
a a 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 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 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 b
A B a a A B a a
A B b 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, ...@@ -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 . costs. To combat the plan change it uses --sorted_result and
--echo . and --replace tricks --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_b ON t1(b);
CREATE INDEX idx_a ON t0(a); 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, ...@@ -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 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.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 t9
WHERE t0.a=1 AND WHERE t0.a=1 AND
t0.b=t1.b 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, ...@@ -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 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.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 t9
WHERE t0.a=1 AND WHERE t0.a=1 AND
t0.b=t1.b AND t0.b=t1.b AND
......
...@@ -13,11 +13,19 @@ CREATE TABLE t1 ( ...@@ -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 ('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; select * from t1,t1 as t2
explain select t1.*,t2.* from t1,t1 as t2 where t1.A=t2.B; 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;
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'; select * from t1 where a='a';
drop table t1; drop table t1;
......
...@@ -139,6 +139,9 @@ create table t2 (c int, d int, v int as (d+1), index idx(c)); ...@@ -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 insert into t2(c,d) values
(20, 100), (20, 300), (30, 100), (30, 200), (40, 500), (20, 100), (20, 300), (30, 100), (30, 200), (40, 500),
(70, 100), (40, 300), (60, 100), (40, 100), (70, 100); (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; set join_cache_level=6;
explain explain
select * from t1,t2 where t1.b=t2.c and d <= 100; 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)); ...@@ -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 insert into t2(c,d) values
(20, 100), (20, 300), (30, 100), (30, 200), (40, 500), (20, 100), (20, 300), (30, 100), (30, 200), (40, 500),
(70, 100), (40, 300), (60, 100), (40, 100), (70, 100); (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; set join_cache_level=6;
explain explain
......
...@@ -363,7 +363,9 @@ CREATE TABLE t2 (a varchar(1) , KEY (a)) ; ...@@ -363,7 +363,9 @@ CREATE TABLE t2 (a varchar(1) , KEY (a)) ;
INSERT INTO t2 VALUES ('c'), (NULL), ('r'); INSERT INTO t2 VALUES ('c'), (NULL), ('r');
CREATE TABLE t3 (a varchar(1), b varchar(1)); CREATE TABLE t3 (a varchar(1), b varchar(1));
INSERT INTO t3 VALUES ('e', 'c'), ('c', 'c'), ('c', 'r'); INSERT INTO t3 VALUES
('e', 'c'), ('c', 'c'), ('c', 'r'), ('g', 'a'), ('b', 'x'), ('b', 'y'),
('h', 'w'), ('d', 'z'), ('k', 'v'), ('j', 's'), ('m', 'p'), ('l', 'q');
CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t3 GROUP BY a; CREATE VIEW v1 AS SELECT a, MIN(b) AS b FROM t3 GROUP BY a;
...@@ -599,7 +601,10 @@ INSERT INTO t1 VALUES (0); ...@@ -599,7 +601,10 @@ INSERT INTO t1 VALUES (0);
CREATE TABLE t2 (a varchar(32), b int, KEY (a)) ; CREATE TABLE t2 (a varchar(32), b int, KEY (a)) ;
INSERT INTO t2 VALUES INSERT INTO t2 VALUES
('j',28), ('c',29), ('i',26), ('c',29), ('k',27), ('j',28), ('c',29), ('i',26), ('c',29), ('k',27),
('j',28), ('c',29), ('i',25), ('d',26), ('k',27); ('j',28), ('c',29), ('i',25), ('d',26), ('k',27),
('n',28), ('d',29), ('m',26), ('e',29), ('p',27),
('w',28), ('x',29), ('y',25), ('z',26), ('s',27);
CREATE TABLE t3 (a varchar(32)); CREATE TABLE t3 (a varchar(32));
INSERT INTO t3 VALUES ('j'), ('c'); INSERT INTO t3 VALUES ('j'), ('c');
......
...@@ -428,6 +428,8 @@ DROP TABLE t1; ...@@ -428,6 +428,8 @@ DROP TABLE t1;
CREATE TABLE t1 (a VARCHAR(255), b INT, FULLTEXT(a), KEY(b)); CREATE TABLE t1 (a VARCHAR(255), b INT, FULLTEXT(a), KEY(b));
INSERT INTO t1 VALUES('test', 1),('test', 1),('test', 1),('test', 1), INSERT INTO t1 VALUES('test', 1),('test', 1),('test', 1),('test', 1),
('test', 1),('test', 2),('test', 3),('test', 4); ('test', 1),('test', 2),('test', 3),('test', 4);
INSERT INTO t1 VALUES('test', 5),('test', 6),('test', 7),('test', 8),
('test', 5),('test', 6),('test', 7),('test', 8);
EXPLAIN SELECT * FROM t1 EXPLAIN SELECT * FROM t1
WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1; WHERE MATCH(a) AGAINST('test' IN BOOLEAN MODE) AND b=1;
......
This diff is collapsed.
...@@ -454,6 +454,7 @@ SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b ...@@ -454,6 +454,7 @@ SELECT t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
ON t3.a=1 AND t2.b=t4.b ON t3.a=1 AND t2.b=t4.b
WHERE t1.a <= 2; WHERE t1.a <= 2;
INSERT INTO t2 VALUES (-1,9,0), (-3,10,0), (-2,8,0), (-4,11,0), (-5,15,0);
CREATE INDEX idx_b ON t2(b); CREATE INDEX idx_b ON t2(b);
EXPLAIN EXTENDED EXPLAIN EXTENDED
...@@ -461,12 +462,12 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b ...@@ -461,12 +462,12 @@ SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM (t3,t4) FROM (t3,t4)
LEFT JOIN LEFT JOIN
(t1,t2) (t1,t2)
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b; ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b AND t2.a>0;
SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b SELECT t2.a,t2.b,t3.a,t3.b,t4.a,t4.b
FROM (t3,t4) FROM (t3,t4)
LEFT JOIN LEFT JOIN
(t1,t2) (t1,t2)
ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b; ON t3.a=1 AND t3.b=t2.b AND t2.b=t4.b AND t2.a>0;
EXPLAIN EXTENDED EXPLAIN EXTENDED
SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
...@@ -477,7 +478,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -477,7 +478,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t2 t2
LEFT JOIN LEFT JOIN
(t3, t4) (t3, t4)
ON t3.a=1 AND t2.b=t4.b, ON t3.a=1 AND t2.b=t4.b AND t2.a>0,
t5 t5
LEFT JOIN LEFT JOIN
( (
...@@ -504,6 +505,8 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -504,6 +505,8 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
(t8.b=t9.b OR t8.c IS NULL) AND (t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1); (t9.a=1);
INSERT INTO t4 VALUES (-3,12,0), (-4,13,0), (-1,11,0), (-3,11,0), (-5,15,0);
INSERT INTO t5 VALUES (-3,11,0), (-2,12,0), (-3,13,0), (-4,12,0);
CREATE INDEX idx_b ON t4(b); CREATE INDEX idx_b ON t4(b);
CREATE INDEX idx_b ON t5(b); CREATE INDEX idx_b ON t5(b);
...@@ -516,7 +519,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -516,7 +519,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t2 t2
LEFT JOIN LEFT JOIN
(t3, t4) (t3, t4)
ON t3.a=1 AND t2.b=t4.b, ON t3.a=1 AND t2.b=t4.b AND t2.a>0 AND t4.a>0,
t5 t5
LEFT JOIN LEFT JOIN
( (
...@@ -525,7 +528,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -525,7 +528,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t8 t8
ON t7.b=t8.b AND t6.b < 10 ON t7.b=t8.b AND t6.b < 10
) )
ON t6.b >= 2 AND t5.b=t7.b ON t6.b >= 2 AND t5.b=t7.b AND t5.a>0
) )
ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND 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.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
...@@ -543,6 +546,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -543,6 +546,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
(t8.b=t9.b OR t8.c IS NULL) AND (t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1); (t9.a=1);
INSERT INTO t8 VALUES (-3,12,0), (-1,14,0), (-5,15,0), (-1,11,0), (-4,13,0);
CREATE INDEX idx_b ON t8(b); CREATE INDEX idx_b ON t8(b);
EXPLAIN EXTENDED EXPLAIN EXTENDED
...@@ -554,16 +558,16 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -554,16 +558,16 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
t2 t2
LEFT JOIN LEFT JOIN
(t3, t4) (t3, t4)
ON t3.a=1 AND t2.b=t4.b, ON t3.a=1 AND t2.b=t4.b AND t2.a>0 AND t4.a>0,
t5 t5
LEFT JOIN LEFT JOIN
( (
(t6, t7) (t6, t7)
LEFT JOIN LEFT JOIN
t8 t8
ON t7.b=t8.b AND t6.b < 10 ON t7.b=t8.b AND t6.b < 10 AND t8.a>=0
) )
ON t6.b >= 2 AND t5.b=t7.b ON t6.b >= 2 AND t5.b=t7.b AND t5.a>0
) )
ON (t3.b=2 OR t3.c IS NULL) AND (t6.b=2 OR t6.c IS NULL) AND 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.b=t5.b OR t3.c IS NULL OR t6.c IS NULL or t8.c IS NULL) AND
...@@ -581,6 +585,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -581,6 +585,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b,
(t8.b=t9.b OR t8.c IS NULL) AND (t8.b=t9.b OR t8.c IS NULL) AND
(t9.a=1); (t9.a=1);
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_b ON t1(b);
CREATE INDEX idx_a ON t0(a); CREATE INDEX idx_a ON t0(a);
...@@ -606,7 +611,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -606,7 +611,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 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.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 t9
WHERE t0.a=1 AND WHERE t0.a=1 AND
t0.b=t1.b AND t0.b=t1.b AND
...@@ -641,7 +646,7 @@ SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, ...@@ -641,7 +646,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 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.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 t9
WHERE t0.a=1 AND WHERE t0.a=1 AND
t0.b=t1.b AND t0.b=t1.b AND
......
...@@ -26,6 +26,9 @@ INSERT INTO t5 VALUES (1,1,0), (2,2,0), (3,3,0); ...@@ -26,6 +26,9 @@ INSERT INTO t5 VALUES (1,1,0), (2,2,0), (3,3,0);
INSERT INTO t6 VALUES (1,2,0), (3,2,0), (6,1,0); INSERT INTO t6 VALUES (1,2,0), (3,2,0), (6,1,0);
INSERT INTO t7 VALUES (1,1,0), (2,2,0); INSERT INTO t7 VALUES (1,1,0), (2,2,0);
INSERT INTO t8 VALUES (0,2,0), (1,2,0); INSERT INTO t8 VALUES (0,2,0), (1,2,0);
INSERT INTO t6 VALUES (-1,12,0), (-3,13,0), (-6,11,0), (-4,14,0);
INSERT INTO t7 VALUES (-1,11,0), (-2,12,0), (-3,13,0), (-4,14,0), (-5,15,0);
INSERT INTO t8 VALUES (-3,13,0), (-1,12,0), (-2,14,0), (-5,15,0), (-4,16,0);
EXPLAIN EXPLAIN
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
...@@ -35,10 +38,10 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b ...@@ -35,10 +38,10 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
(t6, t7) (t6, t7)
LEFT JOIN LEFT JOIN
t8 t8
ON t7.b=t8.b AND t6.b < 10 ON t7.b=t8.b AND t6.b < 10
) )
ON t6.b >= 2 AND t5.b=t7.b AND ON t6.b >= 2 AND t5.b=t7.b AND
(t8.a > 0 OR t8.c IS NULL); (t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0;
SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
FROM t5 FROM t5
...@@ -50,7 +53,7 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b ...@@ -50,7 +53,7 @@ SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b
ON t7.b=t8.b AND t6.b < 10 ON t7.b=t8.b AND t6.b < 10
) )
ON t6.b >= 2 AND t5.b=t7.b AND ON t6.b >= 2 AND t5.b=t7.b AND
(t8.a > 0 OR t8.c IS NULL); (t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0;
DELETE FROM t5; DELETE FROM t5;
DELETE FROM t6; DELETE FROM t6;
......
...@@ -1064,6 +1064,8 @@ insert into t2 select if(t1.a is null, 10, t1.a) from t1; ...@@ -1064,6 +1064,8 @@ insert into t2 select if(t1.a is null, 10, t1.a) from t1;
create table t3 (a int, b int, index idx(a)); create table t3 (a int, b int, index idx(a));
insert into t3 values (1, 100), (3, 301), (4, 402), (1, 102), (1, 101); insert into t3 values (1, 100), (3, 301), (4, 402), (1, 102), (1, 101);
insert into t3 values (11, 100), (33, 301), (44, 402), (11, 102), (11, 101);
insert into t3 values (22, 100), (53, 301), (64, 402), (22, 102), (22, 101);
analyze table t1,t2,t3; analyze table t1,t2,t3;
......
...@@ -74,7 +74,9 @@ CREATE TABLE t3( ...@@ -74,7 +74,9 @@ CREATE TABLE t3(
PRIMARY KEY (pk), INDEX idx (v, i) PRIMARY KEY (pk), INDEX idx (v, i)
) ENGINE=ARIA; ) ENGINE=ARIA;
INSERT INTO t3 SELECT * FROM t1; INSERT INTO t3 SELECT * FROM t1;
INSERT INTO t3 VALUES (88, 442, 'y'), (99, 445, 'w') ; INSERT INTO t3 VALUES
(88, 442, 'y'), (99, 445, 'w'), (87, 442, 'z'), (98, 445, 'v'), (86, 442, 'x'),
(97, 445, 't'), (85, 442, 'b'), (96, 445, 'l'), (84, 442, 'a'), (95, 445, 'k');
SELECT COUNT(t1.v) FROM t1, t2 IGNORE INDEX (idx), t3 IGNORE INDEX (idx) SELECT COUNT(t1.v) FROM t1, t2 IGNORE INDEX (idx), t3 IGNORE INDEX (idx)
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0; WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
...@@ -105,11 +107,8 @@ CREATE TABLE t1 ( ...@@ -105,11 +107,8 @@ CREATE TABLE t1 (
) ENGINE=Aria; ) ENGINE=Aria;
INSERT INTO t1 VALUES INSERT INTO t1 VALUES
(1,'z'), (1,'z'), (2,'abcdefjhjkl'), (3,'in'), (4,'abcdefjhjkl'), (6,'abcdefjhjkl'),
(2,'abcdefjhjkl'), (11,'zx'), (12,'abcdefjhjm'), (13,'jn'), (14,'abcdefjhjp'), (16,'abcdefjhjr');
(3,'in'),
(4,'abcdefjhjkl'),
(6,'abcdefjhjkl');
CREATE TABLE t2 ( CREATE TABLE t2 (
col_varchar_10_latin1 varchar(10) DEFAULT NULL col_varchar_10_latin1 varchar(10) DEFAULT NULL
......
...@@ -57,6 +57,7 @@ DROP TABLE t1,t2,t3; ...@@ -57,6 +57,7 @@ DROP TABLE t1,t2,t3;
--echo # --echo #
create table t1(a int, b int, index(b)); create table t1(a int, b int, index(b));
insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2); insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2);
insert into t1 values (2, 11), (1, 11), (4, 14), (3, 14), (6, 12), (5, 12);
explain select * from t1 where b=1 or b is null order by a; explain select * from t1 where b=1 or b is null order by a;
select * from t1 where b=1 or b is null order by a; select * from t1 where b=1 or b is null order by a;
explain select * from t1 where b=2 or b is null order by a; explain select * from t1 where b=2 or b is null order by a;
......
...@@ -350,7 +350,7 @@ DROP TABLE t1; ...@@ -350,7 +350,7 @@ DROP TABLE t1;
# #
CREATE TABLE t1 (a int not null, b int, c int, key(b), key(c), key(a,b), key(c,a)); 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);
create table t2 (a int not null, b int, c int, key(b), key(c), key(a)); 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); INSERT into t2 values (1,1,1), (2,2,2);
optimize table t1; optimize table t1;
...@@ -358,7 +358,13 @@ show index from t1; ...@@ -358,7 +358,13 @@ show index from t1;
explain select * from t1,t2 where t1.a=t2.a; explain select * from t1,t2 where t1.a=t2.a;
explain select * from t1,t2 force index(a) where t1.a=t2.a; explain select * from t1,t2 force index(a) where t1.a=t2.a;
explain select * from t1 force index(a),t2 force index(a) where t1.a=t2.a; explain select * from t1 force index(a),t2 force index(a) where t1.a=t2.a;
INSERT into t1 values (2,4,5), (7,8,4), (8,3,1), (9,7,2), (5,5,9);
optimize table t1;
show index from t1;
explain select * from t1,t2 where t1.b=t2.b; explain select * from t1,t2 where t1.b=t2.b;
delete from t1 where t1.a>1;
optimize table t1;
show index from t1;
explain select * from t1,t2 force index(c) where t1.a=t2.a; explain select * from t1,t2 force index(c) where t1.a=t2.a;
explain select * from t1 where a=0 or a=2; explain select * from t1 where a=0 or a=2;
explain select * from t1 force index (a) where a=0 or a=2; explain select * from t1 force index (a) where a=0 or a=2;
......
...@@ -199,6 +199,14 @@ INSERT INTO t1 VALUES ...@@ -199,6 +199,14 @@ INSERT INTO t1 VALUES
(22,142,'b','b'),(23,3,'y','y'),(24,0,'v','v'), (22,142,'b','b'),(23,3,'y','y'),(24,0,'v','v'),
(25,3,'m','m'),(26,5,'z','z'),(27,9,'n','n'), (25,3,'m','m'),(26,5,'z','z'),(27,9,'n','n'),
(28,1,'d','d'),(29,107,'a','a'); (28,1,'d','d'),(29,107,'a','a');
INSERT INTO t1 VALUES
(110,8,'v','v'),(111,8,'f','f'), (112,5,'v','v'),
(113,8,'s','s'),(114,8,'a','a'),(115,6,'p','p'),
(116,7,'z','z'),(117,2,'a','a'),(118,5,'h','h'),
(119,7,'h','h'),(120,2,'v','v'),(121,9,'v','v'),
(122,142,'b','b'),(123,3,'y','y'),(124,0,'v','v'),
(125,3,'m','m'),(126,5,'z','z'),(127,9,'n','n'),
(128,1,'d','d'),(129,107,'a','a');
SELECT COUNT(*) SELECT COUNT(*)
FROM FROM
......
...@@ -440,6 +440,7 @@ drop table t1; ...@@ -440,6 +440,7 @@ drop table t1;
create table t1(a int, b int, index(b)); create table t1(a int, b int, index(b));
insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2); insert into t1 values (2, 1), (1, 1), (4, NULL), (3, NULL), (6, 2), (5, 2);
insert into t1 values (12, 11), (11, 11), (14, 3), (13, 5), (16, 12), (15, 12);
explain select * from t1 where b=1 or b is null order by a; explain select * from t1 where b=1 or b is null order by a;
select * from t1 where b=1 or b is null order by a; select * from t1 where b=1 or b is null order by a;
explain select * from t1 where b=2 or b is null order by a; explain select * from t1 where b=2 or b is null order by a;
......
...@@ -872,6 +872,7 @@ drop table t1; ...@@ -872,6 +872,7 @@ drop table t1;
create table t1 (a int not null, b int not null, key(a), key(b)) create table t1 (a int not null, b int not null, key(a), key(b))
partition by hash(a) partitions 4; partition by hash(a) partitions 4;
insert into t1 values (1,1),(2,2),(3,3),(4,4); insert into t1 values (1,1),(2,2),(3,3),(4,4);
insert into t1 values (5,5),(6,6),(7,7),(8,8);
explain partitions explain partitions
select * from t1 X, t1 Y select * from t1 X, t1 Y
......
...@@ -554,6 +554,18 @@ INSERT INTO t1 VALUES ...@@ -554,6 +554,18 @@ INSERT INTO t1 VALUES
'd8c4177d09f8b11f5.52725521'), 'd8c4177d09f8b11f5.52725521'),
('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11, ('d8c4177d24ccef970.14957924','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725521'); 'd8c4177d09f8b11f5.52725521');
INSERT INTO t1 VALUES
('d8c4177d09f8b11f5.52725522','oxrootid',1,40,'d8c4177d09f8b11f5.52725522'),
('d8c4177d151affab2.81582771','d8c4177d09f8b11f5.52725521',2,3,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d206a333d2.74422678','d8c4177d09f8b11f5.52725521',4,5,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d225791924.30714721','d8c4177d09f8b11f5.52725521',6,7,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d2380fc201.39666694','d8c4177d09f8b11f5.52725521',8,9,
'd8c4177d09f8b11f5.52725522'),
('d8c4177d24ccef970.14957925','d8c4177d09f8b11f5.52725521',10,11,
'd8c4177d09f8b11f5.52725522');
EXPLAIN EXPLAIN
SELECT s.oxid FROM t1 v, t1 s SELECT s.oxid FROM t1 v, t1 s
......
...@@ -1961,6 +1961,7 @@ CREATE TABLE t2 ( a BLOB, INDEX (a(20)) ); ...@@ -1961,6 +1961,7 @@ CREATE TABLE t2 ( a BLOB, INDEX (a(20)) );
INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t1 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five'); INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
INSERT INTO t2 VALUES ('one'),('two'),('three'),('four'),('five');
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a; EXPLAIN SELECT * FROM t1 LEFT JOIN t2 USE INDEX (a) ON t1.a=t2.a;
EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a; EXPLAIN SELECT * FROM t1 LEFT JOIN t2 FORCE INDEX (a) ON t1.a=t2.a;
......
...@@ -58,6 +58,8 @@ SELECT * from t1; ...@@ -58,6 +58,8 @@ SELECT * from t1;
# #
analyze table t1; analyze table t1;
insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"); insert into t1 values (null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a"),(null,"a");
insert into t1 values (null,"b"),(null,"b"),(null,"c"),(null,"c"),(null,"d"),(null,"d"),(null,"e"),(null,"e"),(null,"a"),(null,"e");
insert into t1 values (null,"x"),(null,"x"),(null,"y"),(null,"y"),(null,"z"),(null,"z"),(null,"v"),(null,"v"),(null,"a"),(null,"v");
explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b; explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b;
set MAX_SEEKS_FOR_KEY=1; set MAX_SEEKS_FOR_KEY=1;
explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b; explain select STRAIGHT_JOIN * from t1,t1 as t2 where t1.b=t2.b;
......
...@@ -81,6 +81,7 @@ insert into t1 values ...@@ -81,6 +81,7 @@ insert into t1 values
(2, 3), (2, 3),
(2, NULL), (2, NULL),
(3, NULL); (3, NULL);
insert into t1 values (5, 7), (8, 9), (4, 1);
create table t2 (a int, oref int); create table t2 (a int, oref int);
insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4); insert into t2 values (1, 1), (2,2), (NULL, 3), (NULL, 4);
......
...@@ -222,13 +222,15 @@ select count(*) ...@@ -222,13 +222,15 @@ select count(*)
from CountryLanguage from CountryLanguage
where (Language, Country) NOT IN where (Language, Country) NOT IN
(SELECT City.Name, Country.Code (SELECT City.Name, Country.Code
FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000)); FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000))
AND Language IN ('English','Spanish');
select count(*) select count(*)
from CountryLanguage from CountryLanguage
where (Language, Country) NOT IN where (Language, Country) NOT IN
(SELECT City.Name, Country.Code (SELECT City.Name, Country.Code
FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000)); FROM City LEFT JOIN Country ON (Country = Code and City.Population < 10000))
AND Language IN ('English','Spanish');
-- echo Q2.3m: -- echo Q2.3m:
-- echo MATERIALIZATION with the PARTIAL_MATCH_MERGE strategy, because the HAVING -- echo MATERIALIZATION with the PARTIAL_MATCH_MERGE strategy, because the HAVING
......
...@@ -89,6 +89,12 @@ CREATE TABLE t1 ( ...@@ -89,6 +89,12 @@ CREATE TABLE t1 (
INSERT INTO t1 VALUES (10,7,8,'v','v'); INSERT INTO t1 VALUES (10,7,8,'v','v');
INSERT INTO t1 VALUES (11,1,9,'r','r'); INSERT INTO t1 VALUES (11,1,9,'r','r');
INSERT INTO t1 VALUES (12,5,9,'a','a'); INSERT INTO t1 VALUES (12,5,9,'a','a');
INSERT INTO t1 VALUES (13,7,18,'v','v');
INSERT INTO t1 VALUES (14,1,19,'r','r');
INSERT INTO t1 VALUES (15,5,29,'a','a');
INSERT INTO t1 VALUES (17,7,38,'v','v');
INSERT INTO t1 VALUES (18,1,39,'r','r');
INSERT INTO t1 VALUES (19,5,49,'a','a');
create table t1a like t1; create table t1a like t1;
insert into t1a select * from t1; insert into t1a select * from t1;
......
...@@ -1625,6 +1625,7 @@ set @tmp834739=@@optimizer_switch; ...@@ -1625,6 +1625,7 @@ set @tmp834739=@@optimizer_switch;
set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off'; set optimizer_switch='semijoin=on,loosescan=on,materialization=off,firstmatch=off';
CREATE TABLE t2 ( b int, c int, KEY (b)) ; CREATE TABLE t2 ( b int, c int, KEY (b)) ;
INSERT INTO t2 VALUES (1,0),(1,0),(9,0),(1,0),(5,0); INSERT INTO t2 VALUES (1,0),(1,0),(9,0),(1,0),(5,0);
INSERT INTO t2 VALUES (2,0),(3,0),(8,0),(6,0),(5,0);
CREATE TABLE t3 ( a int); CREATE TABLE t3 ( a int);
INSERT INTO t3 VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0); INSERT INTO t3 VALUES (0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
......
...@@ -28,6 +28,7 @@ create table t2 ( ...@@ -28,6 +28,7 @@ create table t2 (
key(b) key(b)
); );
insert into t2 select a, a/2 from t0; insert into t2 select a, a/2 from t0;
insert into t2 select a+10, a+10/2 from t0;
select * from t1; select * from t1;
select * from t2; select * from t2;
...@@ -43,6 +44,8 @@ create table t3 ( ...@@ -43,6 +44,8 @@ create table t3 (
primary key(pk1, pk2, pk3) primary key(pk1, pk2, pk3)
) engine=innodb; ) engine=innodb;
insert into t3 select a,a, a,a,a from t0; insert into t3 select a,a, a,a,a from t0;
insert into t3 select a,a, a+100,a+100,a+100 from t0;
explain select * from t3 where b in (select a from t1); explain select * from t3 where b in (select a from t1);
select * from t3 where b in (select a from t1); select * from t3 where b in (select a from t1);
...@@ -575,6 +578,7 @@ insert into t0 values (0),(1),(2),(3),(4); ...@@ -575,6 +578,7 @@ insert into t0 values (0),(1),(2),(3),(4);
create table t1 (a int, b int, key(a)); create table t1 (a int, b int, key(a));
insert into t1 select a,a from t0; insert into t1 select a,a from t0;
insert into t1 select a+5,a from t0;
create table t2 (a int, b int, primary key(a)); create table t2 (a int, b int, primary key(a));
insert into t2 select * from t1; insert into t2 select * from t1;
......
...@@ -22,6 +22,8 @@ CREATE TABLE t0 (a INT); ...@@ -22,6 +22,8 @@ CREATE TABLE t0 (a INT);
INSERT INTO t0 VALUES (0),(1),(2),(3),(4); INSERT INTO t0 VALUES (0),(1),(2),(3),(4);
CREATE TABLE t1 (a INT, b INT, KEY(a)); CREATE TABLE t1 (a INT, b INT, KEY(a));
INSERT INTO t1 SELECT a, a from t0; INSERT INTO t1 SELECT a, a from t0;
INSERT INTO t1 SELECT a+5, a from t0;
INSERT INTO t1 SELECT a+10, a from t0;
CREATE TABLE t2 (a INT, b INT, PRIMARY KEY(a)); CREATE TABLE t2 (a INT, b INT, PRIMARY KEY(a));
INSERT INTO t2 SELECT * FROM t1; INSERT INTO t2 SELECT * FROM t1;
UPDATE t1 SET a=3, b=11 WHERE a=4; UPDATE t1 SET a=3, b=11 WHERE a=4;
......
...@@ -223,7 +223,8 @@ create table t1 (a char(10) primary key); ...@@ -223,7 +223,8 @@ create table t1 (a char(10) primary key);
insert into t1 values ('foo'),('bar'); insert into t1 values ('foo'),('bar');
create table t2 (a char(10), unique key(a(2))); create table t2 (a char(10), unique key(a(2)));
insert into t2 values ('foo'),('bar'); insert into t2 values
('foo'),('bar'),('boo'),('car'),('coo'),('par'),('doo'),('tar');
explain select t1.* from t1 left join t2 on t2.a=t1.a; explain select t1.* from t1 left join t2 on t2.a=t1.a;
......
...@@ -5177,7 +5177,7 @@ best_access_path(JOIN *join, ...@@ -5177,7 +5177,7 @@ best_access_path(JOIN *join,
tmp= table->file->keyread_time(key, 1, (ha_rows) tmp); tmp= table->file->keyread_time(key, 1, (ha_rows) tmp);
else else
tmp= table->file->read_time(key, 1, tmp= table->file->read_time(key, 1,
(ha_rows) min(tmp,s->worst_seeks)-1); (ha_rows) min(tmp,s->worst_seeks));
tmp*= record_count; tmp*= record_count;
} }
} }
...@@ -5341,13 +5341,14 @@ best_access_path(JOIN *join, ...@@ -5341,13 +5341,14 @@ best_access_path(JOIN *join,
tmp= table->file->keyread_time(key, 1, (ha_rows) tmp); tmp= table->file->keyread_time(key, 1, (ha_rows) tmp);
else else
tmp= table->file->read_time(key, 1, tmp= table->file->read_time(key, 1,
(ha_rows) min(tmp,s->worst_seeks)-1); (ha_rows) min(tmp,s->worst_seeks));
tmp*= record_count; tmp*= record_count;
} }
else else
tmp= best_time; // Do nothing tmp= best_time; // Do nothing
} }
DBUG_ASSERT(tmp > 0 || record_count == 0);
tmp += s->startup_cost; tmp += s->startup_cost;
loose_scan_opt.check_ref_access_part2(key, start_key, records, tmp); loose_scan_opt.check_ref_access_part2(key, start_key, records, tmp);
} /* not ft_key */ } /* not ft_key */
......
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