diff options
Diffstat (limited to 'mysql-test/main')
145 files changed, 3984 insertions, 2668 deletions
diff --git a/mysql-test/main/costs.result b/mysql-test/main/costs.result new file mode 100644 index 00000000000..779a6b3ea40 --- /dev/null +++ b/mysql-test/main/costs.result @@ -0,0 +1,91 @@ +create table t1 (a int primary key, b int, c int, d int, e int, key ba (b,a), key bda (b,d,a), key cba (c,b,a), key cb (c,b), key d (d)) engine=aria; +insert into t1 select seq,seq,seq,seq,seq from seq_1_to_10; +insert into t1 values(20,2,2,2,2),(21,3,4,5,6); +# +# Get different scan costs +# +explain select sum(e) as "table_scan" from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 12 +Last_query_cost 6.100000 +explain select sum(a) as "index scan" from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL PRIMARY 4 NULL 12 Using index +Last_query_cost 3.202929 +# +# Range scans should be used if we don't examine all rows in the table +# +explain select count(a) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Last_query_cost 0.000000 +explain select count(*) from t1 where a > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 12 Using where; Using index +Last_query_cost 3.202929 +explain select count(*) from t1 where a > 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index PRIMARY PRIMARY 4 NULL 12 Using where; Using index +Last_query_cost 3.202929 +explain select count(*) from t1 where a > 2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 11 Using where; Using index +Last_query_cost 2.997685 +# +# Shorter indexes are prefered over longer indexs +# +explain select sum(a+b) from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL ba 9 NULL 12 Using index +Last_query_cost 3.204394 +explain select count(*) from t1 where b between 5 and 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range ba,bda ba 5 NULL 6 Using where; Using index +Last_query_cost 1.872197 +explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index +Last_query_cost 0.970781 +# Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd' +explain select count(*) from t1 where b > 6; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range ba,bda ba 5 NULL 5 Using where; Using index +Last_query_cost 1.646831 +explain select count(*) from t1 where d > 6; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range d d 5 NULL 5 Using where; Using index +Last_query_cost 1.646343 +# +# Check covering index usage +# +explain select a,b,c from t1 where a=b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL cba 14 NULL 12 Using where; Using index +Last_query_cost 3.205859 +# +# Prefer ref keys over ranges +# +explain select count(*) from t1 where b=2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref ba,bda ba 5 const 2 Using index +Last_query_cost 0.950732 +explain select count(*) from t1 where b=2 and c=2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref ba,bda,cba,cb cb 10 const,const 2 Using index +Last_query_cost 0.950781 +explain select count(*) from t1 where b=3 and c between 3 and 4; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range ba,bda,cba,cb cb 10 NULL 2 Using where; Using index +Last_query_cost 0.970781 +# +# Prefer eq keys over ref keys +# +explain select a,b,e from t1 where a=10 or a=11; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition +Last_query_cost 2.520488 +explain select a,b,e from t1 where d=10 or d=11; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range d d 5 NULL 2 Using index condition +Last_query_cost 2.520537 +drop table t1; diff --git a/mysql-test/main/costs.test b/mysql-test/main/costs.test new file mode 100644 index 00000000000..6dcc41b57a3 --- /dev/null +++ b/mysql-test/main/costs.test @@ -0,0 +1,75 @@ +# +# Test of cost calcuations. This test is using the Aria engine as the cost +# calculations are stable for it. +# +--source include/have_sequence.inc + +create table t1 (a int primary key, b int, c int, d int, e int, key ba (b,a), key bda (b,d,a), key cba (c,b,a), key cb (c,b), key d (d)) engine=aria; +insert into t1 select seq,seq,seq,seq,seq from seq_1_to_10; +insert into t1 values(20,2,2,2,2),(21,3,4,5,6); + +--echo # +--echo # Get different scan costs +--echo # + +explain select sum(e) as "table_scan" from t1; +--source include/last_query_cost.inc +explain select sum(a) as "index scan" from t1; +--source include/last_query_cost.inc + +--echo # +--echo # Range scans should be used if we don't examine all rows in the table +--echo # +explain select count(a) from t1; +--source include/last_query_cost.inc +explain select count(*) from t1 where a > 0; +--source include/last_query_cost.inc +explain select count(*) from t1 where a > 1; +--source include/last_query_cost.inc +explain select count(*) from t1 where a > 2; +--source include/last_query_cost.inc + +--echo # +--echo # Shorter indexes are prefered over longer indexs +--echo # +explain select sum(a+b) from t1; +--source include/last_query_cost.inc +explain select count(*) from t1 where b between 5 and 10; +--source include/last_query_cost.inc +explain select sum(b+c) from t1 where b between 5 and 6 and c between 5 and 6; +--source include/last_query_cost.inc + +--echo # Cost of 'd' should be slightly smaller as key 'ba' is longer than 'd' +explain select count(*) from t1 where b > 6; +--source include/last_query_cost.inc +explain select count(*) from t1 where d > 6; +--source include/last_query_cost.inc + + +--echo # +--echo # Check covering index usage +--echo # +explain select a,b,c from t1 where a=b; +--source include/last_query_cost.inc + +--echo # +--echo # Prefer ref keys over ranges +--echo # + +explain select count(*) from t1 where b=2; +--source include/last_query_cost.inc +explain select count(*) from t1 where b=2 and c=2; +--source include/last_query_cost.inc +explain select count(*) from t1 where b=3 and c between 3 and 4; +--source include/last_query_cost.inc + +--echo # +--echo # Prefer eq keys over ref keys +--echo # + +explain select a,b,e from t1 where a=10 or a=11; +--source include/last_query_cost.inc +explain select a,b,e from t1 where d=10 or d=11; +--source include/last_query_cost.inc + +drop table t1; diff --git a/mysql-test/main/cte_recursive.result b/mysql-test/main/cte_recursive.result index 20ebf4f0c81..e4f6c854129 100644 --- a/mysql-test/main/cte_recursive.result +++ b/mysql-test/main/cte_recursive.result @@ -4456,9 +4456,9 @@ id select_type table type possible_keys key key_len ref rows Extra 4 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 5 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 2 NULL UNION RESULT <union3,4,5> ALL NULL NULL NULL NULL NULL -2 DERIVED h ALL NULL NULL NULL NULL 12 -2 DERIVED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) -2 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (incremental, BNL join) +2 DERIVED h ALL NULL NULL NULL NULL 12 Using where +2 DERIVED <derived3> ref key0 key0 5 test.h.id 2 +2 DERIVED w ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) prepare stmt from "with recursive ancestor_couples(h_id, h_name, h_dob, h_father, h_mother, w_id, w_name, w_dob, w_father, w_mother) diff --git a/mysql-test/main/ctype_binary.result b/mysql-test/main/ctype_binary.result index 05f31f13dc7..4936ea1d18f 100644 --- a/mysql-test/main/ctype_binary.result +++ b/mysql-test/main/ctype_binary.result @@ -2763,6 +2763,7 @@ id INT(11) DEFAULT NULL, date_column DATE DEFAULT NULL, KEY(date_column)); INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01'); +INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01'); EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition diff --git a/mysql-test/main/ctype_cp1251.result b/mysql-test/main/ctype_cp1251.result index 5d0bf3be615..1c41d4310de 100644 --- a/mysql-test/main/ctype_cp1251.result +++ b/mysql-test/main/ctype_cp1251.result @@ -3175,6 +3175,7 @@ id INT(11) DEFAULT NULL, date_column DATE DEFAULT NULL, KEY(date_column)); INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01'); +INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01'); EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition diff --git a/mysql-test/main/ctype_latin1.result b/mysql-test/main/ctype_latin1.result index 0b16d1cf6f2..5d203dd8a90 100644 --- a/mysql-test/main/ctype_latin1.result +++ b/mysql-test/main/ctype_latin1.result @@ -3484,6 +3484,7 @@ id INT(11) DEFAULT NULL, date_column DATE DEFAULT NULL, KEY(date_column)); INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01'); +INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01'); EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition diff --git a/mysql-test/main/ctype_ucs.result b/mysql-test/main/ctype_ucs.result index 6c14ca3ab66..98f1c54ad7a 100644 --- a/mysql-test/main/ctype_ucs.result +++ b/mysql-test/main/ctype_ucs.result @@ -1569,7 +1569,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range a a 23 NULL 1 Using where; Using index EXPLAIN SELECT * FROM t1 WHERE a LIKE 'c%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 23 NULL 31 Using where; Using index +1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index SELECT * FROM t1 WHERE a LIKE 'c%'; a ca @@ -1585,7 +1585,7 @@ ch ALTER TABLE t1 MODIFY a VARCHAR(10) CHARACTER SET ucs2 COLLATE ucs2_croatian_ci; EXPLAIN SELECT * FROM t1 WHERE a LIKE 'd%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 23 NULL 31 Using where; Using index +1 SIMPLE t1 index a a 23 NULL 31 Using where; Using index SELECT hex(concat('d',_ucs2 0x017E,'%')); hex(concat('d',_ucs2 0x017E,'%')) 0064017E0025 @@ -4368,6 +4368,7 @@ id INT(11) DEFAULT NULL, date_column DATE DEFAULT NULL, KEY(date_column)); INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01'); +INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01'); EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition diff --git a/mysql-test/main/ctype_utf8.result b/mysql-test/main/ctype_utf8.result index 6eebc8f4cf2..d469ba3ee9d 100644 --- a/mysql-test/main/ctype_utf8.result +++ b/mysql-test/main/ctype_utf8.result @@ -5235,6 +5235,7 @@ id INT(11) DEFAULT NULL, date_column DATE DEFAULT NULL, KEY(date_column)); INSERT INTO t1 VALUES (1,'2010-09-01'),(2,'2010-10-01'); +INSERT INTO t1 VALUES (3,'2012-09-01'),(4,'2012-10-01'),(5,'2012-10-01'); EXPLAIN SELECT * FROM t1 WHERE date_column BETWEEN '2010-09-01' AND '2010-10-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range date_column date_column 4 NULL 2 Using index condition diff --git a/mysql-test/main/derived.result b/mysql-test/main/derived.result index 006f41236f5..dc58bdca0ef 100644 --- a/mysql-test/main/derived.result +++ b/mysql-test/main/derived.result @@ -236,7 +236,7 @@ count(*) explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 THEMAX.E2 1 Using where +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 2 DERIVED A ALL NULL NULL NULL NULL 2 Using where 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where drop table t1; diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 558b960cb98..76f36299647 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -9684,11 +9684,22 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "<derived2>", + "table_name": "t1", "access_type": "ALL", "rows": 2, "filtered": 100, - "attached_condition": "1 in (0,dt1.a)", + "attached_condition": "1 in (0,t1.a) and t1.a is not null" + }, + "table": { + "table_name": "<derived2>", + "access_type": "ref", + "possible_keys": ["key0"], + "key": "key0", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["test.t1.a"], + "rows": 2, + "filtered": 100, "materialized": { "query_block": { "select_id": 2, @@ -9706,18 +9717,6 @@ EXPLAIN } } } - }, - "block-nl-join": { - "table": { - "table_name": "t1", - "access_type": "ALL", - "rows": 2, - "filtered": 100 - }, - "buffer_type": "flat", - "buffer_size": "65", - "join_type": "BNL", - "attached_condition": "t1.a = dt1.a" } } } @@ -9743,11 +9742,22 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "<derived2>", + "table_name": "t1", "access_type": "ALL", "rows": 2, "filtered": 100, - "attached_condition": "dt.a in (1,dt.a)", + "attached_condition": "t1.a in (1,t1.a) and t1.a is not null" + }, + "table": { + "table_name": "<derived2>", + "access_type": "ref", + "possible_keys": ["key0"], + "key": "key0", + "key_length": "5", + "used_key_parts": ["a"], + "ref": ["test.t1.a"], + "rows": 2, + "filtered": 100, "materialized": { "query_block": { "select_id": 2, @@ -9765,18 +9775,6 @@ EXPLAIN } } } - }, - "block-nl-join": { - "table": { - "table_name": "t1", - "access_type": "ALL", - "rows": 2, - "filtered": 100 - }, - "buffer_type": "flat", - "buffer_size": "119", - "join_type": "BNL", - "attached_condition": "t1.a = dt.a" } } } @@ -10376,11 +10374,22 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "<derived3>", + "table_name": "t1", "access_type": "ALL", "rows": 2, "filtered": 100, - "attached_condition": "t.f2 < 2", + "attached_condition": "t1.f2 < 2 and t1.f2 is not null" + }, + "table": { + "table_name": "<derived3>", + "access_type": "ref", + "possible_keys": ["key0"], + "key": "key0", + "key_length": "5", + "used_key_parts": ["f2"], + "ref": ["test.t1.f2"], + "rows": 2, + "filtered": 100, "materialized": { "query_block": { "select_id": 3, @@ -10393,13 +10402,6 @@ EXPLAIN } } } - }, - "table": { - "table_name": "t1", - "access_type": "ALL", - "rows": 2, - "filtered": 100, - "attached_condition": "t1.f2 = t.f2" } } } @@ -10417,11 +10419,22 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "<derived3>", + "table_name": "t1", "access_type": "ALL", "rows": 2, "filtered": 100, - "attached_condition": "t.f2 < 2", + "attached_condition": "t1.f2 < 2 and t1.f2 is not null" + }, + "table": { + "table_name": "<derived3>", + "access_type": "ref", + "possible_keys": ["key0"], + "key": "key0", + "key_length": "5", + "used_key_parts": ["f2"], + "ref": ["test.t1.f2"], + "rows": 1, + "filtered": 100, "materialized": { "query_block": { "select_id": 3, @@ -10436,18 +10449,6 @@ EXPLAIN } } } - }, - "block-nl-join": { - "table": { - "table_name": "t1", - "access_type": "ALL", - "rows": 2, - "filtered": 100 - }, - "buffer_type": "flat", - "buffer_size": "65", - "join_type": "BNL", - "attached_condition": "t1.f2 = t.f2" } } } @@ -14390,8 +14391,8 @@ a b c a b c 3 21 500 3 21 231 explain select * from v1,t2 where (v1.b=t2.b) and (v1.a<4); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 Using where -1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t2 ALL NULL NULL NULL NULL 9 Using where +1 PRIMARY <derived2> ref key0 key0 5 test.t2.b 2 Using where 2 DERIVED t3 range i1 i1 5 NULL 2 Using index condition 3 UNION t3 range i1 i1 5 NULL 1 Using index condition NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL @@ -14401,9 +14402,21 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "<derived2>", + "table_name": "t2", "access_type": "ALL", - "rows": 3, + "rows": 9, + "filtered": 100, + "attached_condition": "t2.b is not null" + }, + "table": { + "table_name": "<derived2>", + "access_type": "ref", + "possible_keys": ["key0"], + "key": "key0", + "key_length": "5", + "used_key_parts": ["b"], + "ref": ["test.t2.b"], + "rows": 2, "filtered": 100, "attached_condition": "v1.a < 4", "materialized": { @@ -14449,18 +14462,6 @@ EXPLAIN } } } - }, - "block-nl-join": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 9, - "filtered": 100 - }, - "buffer_type": "flat", - "buffer_size": "173", - "join_type": "BNL", - "attached_condition": "t2.b = v1.b" } } } @@ -16839,7 +16840,7 @@ DROP TABLE t1; CREATE TABLE t1 (pk1 INT PRIMARY KEY, f INT) ENGINE=Aria; INSERT INTO t1 VALUES (1,0),(2,0); CREATE TABLE t2 (pk2 INT PRIMARY KEY) ENGINE=Aria; -INSERT INTO t2 VALUES (1),(2),(3); +INSERT INTO t2 VALUES (1),(2),(3),(11),(12),(13); CREATE VIEW v2 AS SELECT pk2, COUNT(*) AS cnt FROM t2 GROUP BY pk2; SELECT * FROM t1 INNER JOIN v2 ON pk1 = pk2 WHERE f <> 5; pk1 f pk2 cnt @@ -17147,8 +17148,8 @@ explain extended select id, a from t1 where id in (select id from v1); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00 1 PRIMARY <derived3> ref key0 key0 4 test.t1.id 2 100.00 FirstMatch(t1) -3 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00 -3 LATERAL DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where +3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort +3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`v1`) where `v1`.`id` = `test`.`t1`.`id` select id, a from t1 @@ -17185,10 +17186,10 @@ group by t1.id) dt); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 20 100.00 1 PRIMARY <derived3> ref key0 key0 4 test.t1.id 2 100.00 FirstMatch(t1) -3 LATERAL DERIVED t1 eq_ref PRIMARY PRIMARY 4 test.t1.id 1 100.00 -3 LATERAL DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where +3 DERIVED t1 ALL PRIMARY NULL NULL NULL 20 100.00 Using temporary; Using filesort +3 DERIVED t2 ref ro_id ro_id 4 test.t1.id 1 100.00 Using where Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((/* select#3 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`ro_id` = `test`.`t1`.`id` and `test`.`t2`.`flag` = 1) where `test`.`t1`.`id` = `test`.`t1`.`id` group by `test`.`t1`.`id`) `dt`) where `dt`.`id` = `test`.`t1`.`id` +Note 1003 /* select#1 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` semi join ((/* select#3 */ select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` left join `test`.`t2` on(`test`.`t2`.`ro_id` = `test`.`t1`.`id` and `test`.`t2`.`flag` = 1) where 1 group by `test`.`t1`.`id`) `dt`) where `dt`.`id` = `test`.`t1`.`id` drop view v1; drop table t1,t2; # diff --git a/mysql-test/main/derived_cond_pushdown.test b/mysql-test/main/derived_cond_pushdown.test index d738ed33128..7707280759e 100644 --- a/mysql-test/main/derived_cond_pushdown.test +++ b/mysql-test/main/derived_cond_pushdown.test @@ -3324,7 +3324,7 @@ CREATE TABLE t1 (pk1 INT PRIMARY KEY, f INT) ENGINE=Aria; INSERT INTO t1 VALUES (1,0),(2,0); CREATE TABLE t2 (pk2 INT PRIMARY KEY) ENGINE=Aria; -INSERT INTO t2 VALUES (1),(2),(3); +INSERT INTO t2 VALUES (1),(2),(3),(11),(12),(13); CREATE VIEW v2 AS SELECT pk2, COUNT(*) AS cnt FROM t2 GROUP BY pk2; diff --git a/mysql-test/main/derived_opt.result b/mysql-test/main/derived_opt.result index cf0c1cb617f..4033f381458 100644 --- a/mysql-test/main/derived_opt.result +++ b/mysql-test/main/derived_opt.result @@ -111,7 +111,7 @@ count(*) explain select count(*) from t1 INNER JOIN (SELECT A.E1, A.E2, A.E3 FROM t1 AS A WHERE A.E3 = (SELECT MAX(B.E3) FROM t1 AS B WHERE A.E2 = B.E2)) AS THEMAX ON t1.E1 = THEMAX.E2 AND t1.E1 = t1.E2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY A ALL NULL NULL NULL NULL 2 Using where -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.A.E2 1 Using where +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) 3 DEPENDENT SUBQUERY B ALL NULL NULL NULL NULL 2 Using where drop table t1; create table t1 (a int); diff --git a/mysql-test/main/derived_split_innodb.result b/mysql-test/main/derived_split_innodb.result index b30da26f7da..b0b004355e6 100644 --- a/mysql-test/main/derived_split_innodb.result +++ b/mysql-test/main/derived_split_innodb.result @@ -21,7 +21,7 @@ WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort 1 PRIMARY <derived2> ref key0 key0 8 test.t1.n1,test.t1.n2 2 -2 LATERAL DERIVED t1 ref c1,n1_c1_n2 n1_c1_n2 4 test.t1.n1 1 Using where; Using index +2 DERIVED t1 ref c1,n1_c1_n2 c1 1 const 2 Using index condition; Using where; Using temporary; Using filesort SELECT t1.n1 FROM t1, (SELECT n1, n2 FROM t1 WHERE c1 = 'a' GROUP BY n1) as t WHERE t.n1 = t1.n1 AND t.n2 = t1.n2 AND c1 = 'a' GROUP BY n1; n1 @@ -175,8 +175,8 @@ t1.a = dt.a; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 index a,a_2 a_2 10 NULL 6 Using where; Using index 1 PRIMARY <derived3> ref key0 key0 5 test.t1.a 2 -3 LATERAL DERIVED t1 ref a,a_2 a 5 test.t1.a 1 Using where; Using temporary; Using filesort -3 LATERAL DERIVED t2 ref c c 5 test.t1.b 1 Using index +3 DERIVED t1 index a,a_2 a_2 10 NULL 6 Using where; Using index; Using temporary; Using filesort +3 DERIVED t2 ref c c 5 test.t1.b 1 Using index DROP TABLE t1, t2; # # Bug mdev-25714: usage non-splitting covering index is cheaper than @@ -210,7 +210,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 1 PRIMARY t1 ref idx idx 4 test.t2.id 1 1 PRIMARY <derived2> ref key0 key0 9 test.t2.id,test.t1.id 2 -2 DERIVED t3 ref idx1,idx2 idx1 4 const 5 Using where; Using index +2 LATERAL DERIVED t3 ref idx1,idx2 idx2 4 test.t1.itemid 1 Using where select t1.id, t1.itemid, dt.id, t2.id from t1, (select itemid, max(id) as id from t3 where userid = 1 group by itemid) dt, diff --git a/mysql-test/main/derived_view.result b/mysql-test/main/derived_view.result index 3c13cc976aa..538fc3bc762 100644 --- a/mysql-test/main/derived_view.result +++ b/mysql-test/main/derived_view.result @@ -1805,14 +1805,14 @@ WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM t3 t); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t unique_subquery PRIMARY,c PRIMARY 4 func 1 Using where +2 DEPENDENT SUBQUERY t index_subquery PRIMARY,c c 8 func,func 2 Using index; Using where EXPLAIN SELECT * FROM t1 , t2 WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM (SELECT * FROM t3) t); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -2 DEPENDENT SUBQUERY t3 unique_subquery PRIMARY,c PRIMARY 4 func 1 Using where +2 DEPENDENT SUBQUERY t3 index_subquery PRIMARY,c c 8 func,func 2 Using index; Using where SELECT * FROM t1 , t2 WHERE (t2.a ,t1.b) NOT IN (SELECT DISTINCT c,a FROM (SELECT * FROM t3) t); b a @@ -1855,8 +1855,8 @@ WHERE t3.b IN (SELECT v1.b FROM v1, t2 WHERE t2.c = v1.c AND t2.c = v1.b AND v1.b = t3.c); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 -1 PRIMARY <derived3> ref key1 key1 8 const,const 0 Start temporary -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY <derived3> ref key1 key1 8 const,const 0 FirstMatch(t3) 3 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM t3 WHERE t3.b IN (SELECT v1.b FROM v1, t2 diff --git a/mysql-test/main/distinct.result b/mysql-test/main/distinct.result index 284fe2ecd1a..bd0bba2de02 100644 --- a/mysql-test/main/distinct.result +++ b/mysql-test/main/distinct.result @@ -173,9 +173,9 @@ INSERT INTO t2 values (1),(2),(3); INSERT INTO t3 VALUES (1,'1'),(2,'2'),(1,'1'),(2,'2'); explain SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using temporary +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where; Using temporary 1 SIMPLE t2 ref a a 4 test.t1.a 2 Using index -1 SIMPLE t3 index a a 5 NULL 6 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t3 ref a a 5 test.t1.b 2 Using index SELECT distinct t3.a FROM t3,t2,t1 WHERE t3.a=t1.b AND t1.a=t2.a; a 1 diff --git a/mysql-test/main/explain.result b/mysql-test/main/explain.result index bc3c53d01d3..3c83ed6af2c 100644 --- a/mysql-test/main/explain.result +++ b/mysql-test/main/explain.result @@ -325,7 +325,7 @@ DROP TABLE t1; # Bug#56814 Explain + subselect + fulltext crashes server # CREATE TABLE t1(f1 VARCHAR(6) NOT NULL, -FULLTEXT KEY(f1),UNIQUE(f1)); +FULLTEXT KEY `fulltext` (f1), UNIQUE `unique` (f1)); INSERT INTO t1 VALUES ('test'); EXPLAIN SELECT 1 FROM t1 WHERE 1 > ALL((SELECT t1.f1 FROM t1 JOIN t1 a ON (MATCH(t1.f1) AGAINST ("")) @@ -333,7 +333,9 @@ WHERE t1.f1 GROUP BY t1.f1)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'test' PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 WHERE 1 > ALL((SELECT t1.f1 FROM t1 RIGHT OUTER JOIN t1 a @@ -343,12 +345,16 @@ EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'test' EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'test' DEALLOCATE PREPARE stmt; PREPARE stmt FROM 'EXPLAIN SELECT 1 FROM t1 @@ -359,12 +365,15 @@ EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +2 SUBQUERY t1 index unique,fulltext unique 8 NULL 1 Using where; Using index +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'test' +INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5'); EXECUTE stmt; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 SUBQUERY a system NULL NULL NULL NULL 1 -2 SUBQUERY t1 fulltext f1_2,f1 f1 0 1 Using where +1 PRIMARY t1 index NULL unique 8 NULL 6 Using index +2 SUBQUERY t1 fulltext unique,fulltext fulltext 0 1 Using where +2 SUBQUERY a index NULL unique 8 NULL 6 Using index DEALLOCATE PREPARE stmt; DROP TABLE t1; End of 5.1 tests. diff --git a/mysql-test/main/explain.test b/mysql-test/main/explain.test index 0fa4a5af215..c8ed617590d 100644 --- a/mysql-test/main/explain.test +++ b/mysql-test/main/explain.test @@ -254,7 +254,7 @@ DROP TABLE t1; --echo # CREATE TABLE t1(f1 VARCHAR(6) NOT NULL, -FULLTEXT KEY(f1),UNIQUE(f1)); +FULLTEXT KEY `fulltext` (f1), UNIQUE `unique` (f1)); INSERT INTO t1 VALUES ('test'); EXPLAIN SELECT 1 FROM t1 @@ -279,6 +279,7 @@ PREPARE stmt FROM WHERE t1.f1 GROUP BY t1.f1))'; EXECUTE stmt; +INSERT into t1 values('test1'),('test2'),('test3'),('test4'),('test5'); EXECUTE stmt; DEALLOCATE PREPARE stmt; diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result index 98a2fec91fa..70a6762f49c 100644 --- a/mysql-test/main/explain_json.result +++ b/mysql-test/main/explain_json.result @@ -778,9 +778,9 @@ drop table t0; # MDEV-7265: "Full scan on NULL key", the join case # CREATE TABLE t1 (a INT, KEY(a)); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(5),(6),(7); CREATE TABLE t2 (b INT); -INSERT INTO t2 VALUES (3),(4); +INSERT INTO t2 VALUES (3),(4),(9),(10),(11); EXPLAIN FORMAT=JSON SELECT * FROM t1 AS outer_t1 WHERE a <> ALL ( SELECT a FROM t1, t2 WHERE b <> outer_t1.a ); EXPLAIN { @@ -792,7 +792,7 @@ EXPLAIN "key": "a", "key_length": "5", "used_key_parts": ["a"], - "rows": 2, + "rows": 5, "filtered": 100, "attached_condition": "!<in_optimizer>(outer_t1.a,<exists>(subquery#2))", "using_index": true @@ -811,7 +811,7 @@ EXPLAIN "key_length": "5", "used_key_parts": ["a"], "ref": ["func"], - "rows": 2, + "rows": 3, "filtered": 100, "attached_condition": "trigcond(<cache>(outer_t1.a) = t1.a or t1.a is null)", "using_index": true @@ -821,7 +821,7 @@ EXPLAIN "table": { "table_name": "t2", "access_type": "ALL", - "rows": 2, + "rows": 5, "filtered": 100 }, "buffer_type": "flat", diff --git a/mysql-test/main/explain_json.test b/mysql-test/main/explain_json.test index cfbc0cfa10c..e527b70c486 100644 --- a/mysql-test/main/explain_json.test +++ b/mysql-test/main/explain_json.test @@ -163,10 +163,10 @@ drop table t0; --echo # CREATE TABLE t1 (a INT, KEY(a)); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(5),(6),(7); CREATE TABLE t2 (b INT); -INSERT INTO t2 VALUES (3),(4); +INSERT INTO t2 VALUES (3),(4),(9),(10),(11); EXPLAIN FORMAT=JSON SELECT * FROM t1 AS outer_t1 WHERE a <> ALL ( SELECT a FROM t1, t2 WHERE b <> outer_t1.a ); diff --git a/mysql-test/main/func_group.result b/mysql-test/main/func_group.result index 177f0950a77..0959bfe0f8e 100644 --- a/mysql-test/main/func_group.result +++ b/mysql-test/main/func_group.result @@ -604,11 +604,11 @@ AME AME explain select min(a1) from t1 where a1 > 'KKK' or a1 < 'XXX'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 0 NULL 15 Using where; Using index +1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 Using where; Using index explain select min(a1) from t1 where (a1 < 'KKK' or a1 > 'KKK'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 3 NULL 14 Using where; Using index +1 SIMPLE t1 index PRIMARY PRIMARY 3 NULL 15 Using where; Using index explain select max(a3) from t1 where a2 < 2 and a3 < 'SEA'; id select_type table type possible_keys key key_len ref rows Extra @@ -653,7 +653,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select concat(min(t1.a1),min(t2.a4)) from t1, t2 where t2.a4 <> 'AME'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range k2 k2 4 NULL 6 Using where; Using index +1 SIMPLE t2 index k2 k2 4 NULL 7 Using where; Using index 1 SIMPLE t1 index NULL PRIMARY 3 NULL 15 Using index; Using join buffer (flat, BNL join) drop table t1, t2; create table t1 (a char(10)); @@ -1857,9 +1857,8 @@ NULL EXPLAIN EXTENDED SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch 1 PRIMARY t1 range a a 4 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join) -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where Warnings: Note 1003 select max(`test`.`t1`.`a`) AS `MAX(a)` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`a` = 1 and `test`.`t2`.`b` = 2 and `test`.`t1`.`a` < 10 SELECT MAX(a) FROM t1 WHERE (1,2) IN (SELECT a,b FROM t2 WHERE b<5) and a<10; diff --git a/mysql-test/main/func_in.result b/mysql-test/main/func_in.result index 569fdfe4cbf..1363a017dfd 100644 --- a/mysql-test/main/func_in.result +++ b/mysql-test/main/func_in.result @@ -522,7 +522,7 @@ a b explain select f1 from t1 where f1 in ('a','b'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range t1f1_idx t1f1_idx 2 NULL 2 Using where; Using index +1 SIMPLE t1 index t1f1_idx t1f1_idx 2 NULL 3 Using where; Using index select f1 from t1 where f1 in (2,1); f1 1 diff --git a/mysql-test/main/greedy_optimizer.result b/mysql-test/main/greedy_optimizer.result index 1a9390b0384..a83d32e06dc 100644 --- a/mysql-test/main/greedy_optimizer.result +++ b/mysql-test/main/greedy_optimizer.result @@ -127,7 +127,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -139,7 +139,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -151,7 +151,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1561.741393 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -163,7 +163,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1561.741393 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -175,7 +175,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1565.285143 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -187,7 +187,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1565.285143 set optimizer_prune_level=0; select @@optimizer_prune_level; @@optimizer_prune_level @@ -202,24 +202,24 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2705.237037 +Last_query_cost 2694.988350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2705.237037 +Last_query_cost 2694.988350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -231,7 +231,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 753.272751 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -243,7 +243,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 753.272751 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -255,7 +255,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 762.722751 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -267,7 +267,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 762.722751 set optimizer_search_depth=1; select @@optimizer_search_depth; @@optimizer_search_depth @@ -283,7 +283,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -295,7 +295,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -307,7 +307,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2070.748851 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -319,7 +319,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2070.748851 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -331,7 +331,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2075.473851 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -343,7 +343,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2075.473851 set optimizer_search_depth=62; select @@optimizer_search_depth; @@optimizer_search_depth @@ -354,24 +354,24 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2705.237037 +Last_query_cost 2694.988350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.c22 1 1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.c42 1 +1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 2705.237037 +Last_query_cost 2694.988350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -383,7 +383,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 753.272751 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -395,7 +395,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 753.272751 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -407,7 +407,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 762.722751 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where @@ -419,7 +419,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 701.018727 +Last_query_cost 762.722751 set optimizer_prune_level=1; select @@optimizer_prune_level; @@optimizer_prune_level @@ -439,7 +439,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -451,7 +451,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -463,7 +463,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1561.741393 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -475,7 +475,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1561.741393 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -487,7 +487,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1565.285143 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -499,7 +499,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1565.285143 set optimizer_search_depth=1; select @@optimizer_search_depth; @@optimizer_search_depth @@ -515,7 +515,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -527,7 +527,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -539,7 +539,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2070.748851 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -551,7 +551,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2070.748851 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -563,7 +563,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2075.473851 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 3 Using where @@ -575,7 +575,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1678.037037 +Last_query_cost 2075.473851 set optimizer_search_depth=62; select @@optimizer_search_depth; @@optimizer_search_depth @@ -591,7 +591,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c12 = t2.c21 and t2.c22 = t3.c31 and t3.c32 = t4.c41 and t4.c42 = t5.c51 and t5.c52 = t6.c61 and t6.c62 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 @@ -603,7 +603,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 4 test.t6.c62 1 Using index show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 3350.237037 +Last_query_cost 2698.288350 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -615,7 +615,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1561.741393 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -627,7 +627,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1561.741393 explain select t1.c11 from t1, t2, t3, t4, t5, t6, t7 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -639,7 +639,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1565.285143 explain select t1.c11 from t7, t6, t5, t4, t3, t2, t1 where t1.c11 = t2.c21 and t1.c12 = t3.c31 and t1.c13 = t4.c41 and t1.c14 = t5.c51 and t1.c15 = t6.c61 and t1.c16 = t7.c71 and t2.c22 = t3.c32 and t2.c23 = t4.c42 and t2.c24 = t5.c52 and t2.c25 = t6.c62 and t2.c26 = t7.c72 and t3.c33 = t4.c43 and t3.c34 = t5.c53 and t3.c35 = t6.c63 and t3.c36 = t7.c73 and t4.c42 = t5.c54 and t4.c43 = t6.c64 and t4.c44 = t7.c74 and t5.c52 = t6.c65 and t5.c53 = t7.c75 and t6.c62 = t7.c76; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 6 @@ -651,7 +651,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) show status like 'Last_query_cost'; Variable_name Value -Last_query_cost 1276.787037 +Last_query_cost 1565.285143 drop table t1,t2,t3,t4,t5,t6,t7; CREATE TABLE t1 (a int, b int, d int, i int); INSERT INTO t1 VALUES (1,1,1,1); diff --git a/mysql-test/main/group_by.result b/mysql-test/main/group_by.result index d0273fe2090..12c596d53e3 100644 --- a/mysql-test/main/group_by.result +++ b/mysql-test/main/group_by.result @@ -2457,7 +2457,7 @@ test.t1 analyze status OK EXPLAIN SELECT SQL_BUFFER_RESULT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref b b 4 const 6 Using where; Using index; Using temporary +1 SIMPLE t1 range b b 9 NULL 2 Using where; Using index for group-by; Using temporary SELECT SQL_BUFFER_RESULT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b; MIN(a) b @@ -2465,7 +2465,7 @@ MIN(a) b EXPLAIN SELECT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref b b 4 const 6 Using where; Using index +1 SIMPLE t1 range b b 9 NULL 2 Using where; Using index for group-by SELECT MIN(a), b FROM t1 WHERE t1.b = 'a' GROUP BY b; MIN(a) b diff --git a/mysql-test/main/group_min_max.result b/mysql-test/main/group_min_max.result index 0539c938899..b2642fb1ba6 100644 --- a/mysql-test/main/group_min_max.result +++ b/mysql-test/main/group_min_max.result @@ -2080,7 +2080,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain extended select a1,a2,min(b),max(b) from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 97.06 Using where; Using index +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 100.00 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,min(`test`.`t1`.`b`) AS `min(b)`,max(`test`.`t1`.`b`) AS `max(b)` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2` explain extended select a1,a2,b,min(c),max(c) from t1 @@ -2100,7 +2100,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index NULL idx_t2_1 163 NULL 548 Using where; Using index explain extended select a1,a2,b from t1 where (a1 = 'b' or a1 = 'd' or a1 = 'a' or a1 = 'c') and (a2 > 'a') and (c > 'a111') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 97.06 Using where; Using index +1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 130 NULL 276 100.00 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a1` = 'b' or `test`.`t1`.`a1` = 'd' or `test`.`t1`.`a1` = 'a' or `test`.`t1`.`a1` = 'c') and `test`.`t1`.`a2` > 'a' and `test`.`t1`.`c` > 'a111' group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b` explain select a1,a2,min(b),c from t2 where (a2 = 'a') and (c = 'a111') group by a1; @@ -2368,11 +2368,11 @@ CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a,b,c)); INSERT INTO t2 SELECT a,b,b FROM t1; explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 10 NULL 6 Using where; Using index +1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by insert into t1 select 1,seq from seq_1_to_100; explain SELECT MAX(b), a FROM t1 WHERE b < 2 AND a = 1 GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 10 NULL 6 Using where; Using index +1 SIMPLE t1 range a,b a 10 NULL 2 Using where; Using index for group-by analyze table t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected @@ -2460,7 +2460,7 @@ EXPLAIN SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer index NULL a 10 NULL 15 Using index -2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index +2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE EXISTS (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra @@ -2470,31 +2470,31 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE -2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index +2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE a IN (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 1 PRIMARY t1_outer ref a a 5 <subquery2>.max(b) 3 Using index -2 MATERIALIZED t1 range a a 5 NULL 5 Using where; Using index +2 MATERIALIZED t1 range a a 5 NULL 2 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer GROUP BY a HAVING a > (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer range NULL a 5 NULL 6 Using index for group-by -2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index +2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by EXPLAIN SELECT 1 FROM t1 AS t1_outer1 JOIN t1 AS t1_outer2 ON t1_outer1.a = (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) AND t1_outer1.b = t1_outer2.b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer1 ref a a 5 const 1 Using where; Using index 1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using where; Using index; Using join buffer (flat, BNL join) -2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index +2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by EXPLAIN SELECT (SELECT (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) x FROM t1 AS t1_outer) x2 FROM t1 AS t1_outer2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_outer2 index NULL a 10 NULL 15 Using index 2 SUBQUERY t1_outer index NULL a 10 NULL 15 Using index -3 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index +3 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by CREATE TABLE t3 LIKE t1; FLUSH STATUS; INSERT INTO t3 SELECT a,MAX(b) FROM t1 GROUP BY a; @@ -3794,7 +3794,7 @@ CREATE INDEX break_it ON t1 (a, b); EXPLAIN SELECT distinct a, b FROM t1 where a = '3' ORDER BY b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref break_it break_it 5 const 6 Using where; Using index; Using filesort +1 SIMPLE t1 range break_it break_it 10 NULL 2 Using where; Using index for group-by; Using filesort SELECT distinct a, b FROM t1 where a = '3' ORDER BY b; a b 3 1 @@ -4036,10 +4036,10 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away explain select min(a) from t1 where a between "a" and "Cafeeeeeeeeeeeeeeeeeeeeeeeeee"; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 13 NULL 2 Using where; Using index +1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index explain select min(a) from t1 where a between "abbbbbbbbbbbbbbbbbbbb" and "Cafe2"; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 13 NULL 2 Using where; Using index +1 SIMPLE t1 index a a 13 NULL 2 Using where; Using index drop table t1; # # MDEV-15433: Optimizer does not use group by optimization with distinct diff --git a/mysql-test/main/index_intersect.result b/mysql-test/main/index_intersect.result index 3ec98216479..79cd7a32c1a 100644 --- a/mysql-test/main/index_intersect.result +++ b/mysql-test/main/index_intersect.result @@ -75,7 +75,7 @@ EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 300000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Population,Name Name 35 NULL # Using index condition; Using where +1 SIMPLE City index_merge Population,Name Name,Population 35,4 NULL # Using sort_intersect(Name,Population); Using where EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 7000000; @@ -355,9 +355,6 @@ COUNT(*) SELECT COUNT(*) FROM City WHERE Country LIKE 'C%'; COUNT(*) 551 -SELECT COUNT(*) FROM City WHERE Country LIKE 'B%'; -COUNT(*) -339 SELECT COUNT(*) FROM City WHERE Country LIKE 'J%'; COUNT(*) 256 @@ -370,7 +367,7 @@ EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Country,Name Population,Country,Name 4,3,35 NULL # Using sort_intersect(Population,Country,Name); Using where +1 SIMPLE City index_merge Population,Country,Name Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%'; @@ -476,7 +473,7 @@ EXPLAIN SELECT * FROM City WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country Country,PRIMARY 3,4 NULL # Using sort_intersect(Country,PRIMARY); Using where +1 SIMPLE City range PRIMARY,Population,Country Country 3 NULL # Using index condition; Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3701 AND 4000 AND Population > 1000000 @@ -488,7 +485,7 @@ SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 AND Country BETWEEN 'S' AND 'Z' ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country Population 4 NULL # Using index condition; Using where +1 SIMPLE City index_merge PRIMARY,Population,Country Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where SELECT * FROM City USE INDEX () WHERE ID BETWEEN 501 AND 1000 AND Population > 700000 AND Country LIKE 'C%'; ID Name Country Population @@ -715,18 +712,18 @@ EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Population,Country,Name Name 35 NULL # Using index condition; Using where +1 SIMPLE City index_merge Population,Country,Name Name,Country 35,3 NULL # Using sort_intersect(Name,Country); Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country Population 4 NULL # Using index condition; Using where +1 SIMPLE City index_merge PRIMARY,Population,Country Population,PRIMARY 4,4 NULL # Using sort_intersect(Population,PRIMARY); Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 AND Country BETWEEN 'S' AND 'Z'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country Population 4 NULL # Using index condition; Using where +1 SIMPLE City index_merge PRIMARY,Population,Country Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where SELECT * FROM City WHERE Name LIKE 'C%' AND Population > 1000000; ID Name Country Population @@ -966,7 +963,7 @@ EXPLAIN SELECT * FROM t1 WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,f4 f4 35 NULL # Using index condition; Using where +1 SIMPLE t1 index_merge PRIMARY,f4 f4,PRIMARY 35,4 NULL # Using sort_intersect(f4,PRIMARY); Using where SELECT * FROM t1 WHERE (f1 < 535 OR f1 > 985) AND ( f4='r' OR f4 LIKE 'a%' ) ; f1 f4 f5 diff --git a/mysql-test/main/index_intersect.test b/mysql-test/main/index_intersect.test index 26937fd5eef..d6208f67a92 100644 --- a/mysql-test/main/index_intersect.test +++ b/mysql-test/main/index_intersect.test @@ -120,7 +120,6 @@ SELECT COUNT(*) FROM City WHERE Name BETWEEN 'G' AND 'K'; SELECT COUNT(*) FROM City WHERE Population > 1000000; SELECT COUNT(*) FROM City WHERE Population > 500000; SELECT COUNT(*) FROM City WHERE Country LIKE 'C%'; -SELECT COUNT(*) FROM City WHERE Country LIKE 'B%'; SELECT COUNT(*) FROM City WHERE Country LIKE 'J%'; diff --git a/mysql-test/main/index_intersect_innodb.result b/mysql-test/main/index_intersect_innodb.result index 44407dbcd30..5ee4f88fddd 100644 --- a/mysql-test/main/index_intersect_innodb.result +++ b/mysql-test/main/index_intersect_innodb.result @@ -81,12 +81,12 @@ EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 300000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Population,Name Name 35 NULL # Using index condition; Using where +1 SIMPLE City index_merge Population,Name Name,Population 35,4 NULL # Using sort_intersect(Name,Population); Using where EXPLAIN SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 7000000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Name Population,Name 4,35 NULL # Using sort_intersect(Population,Name); Using where +1 SIMPLE City range Population,Name Population 4 NULL # Using index condition; Using where SELECT * FROM City USE INDEX () WHERE Name LIKE 'C%' AND Population > 1000000; ID Name Country Population @@ -341,8 +341,8 @@ ID Name Country Population SELECT * FROM City WHERE Name LIKE 'M%' AND Population > 7000000; ID Name Country Population -1024 Mumbai (Bombay) IND 10500000 3580 Moscow RUS 8389200 +1024 Mumbai (Bombay) IND 10500000 SELECT COUNT(*) FROM City WHERE Name BETWEEN 'M' AND 'N'; COUNT(*) 301 @@ -361,9 +361,6 @@ COUNT(*) SELECT COUNT(*) FROM City WHERE Country LIKE 'C%'; COUNT(*) 551 -SELECT COUNT(*) FROM City WHERE Country LIKE 'B%'; -COUNT(*) -339 SELECT COUNT(*) FROM City WHERE Country LIKE 'J%'; COUNT(*) 256 @@ -371,17 +368,17 @@ EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Country,Name Population,Name,Country 4,35,3 NULL # Using sort_intersect(Population,Name,Country); Using where +1 SIMPLE City index_merge Population,Country,Name Population,Name 4,35 NULL # Using sort_intersect(Population,Name); Using where EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'K' AND Population > 1000000 AND Country LIKE 'J%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Population,Country,Name Population,Country,Name 4,3,35 NULL # Using sort_intersect(Population,Country,Name); Using where +1 SIMPLE City index_merge Population,Country,Name Population,Country 4,3 NULL # Using sort_intersect(Population,Country); Using where EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'K' AND Population > 500000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Population,Name,Country Name # NULL # Using index condition; Using where +1 SIMPLE City index_merge Population,Name,Country Name,Population,Country # NULL # Using sort_intersect(Name,Population,Country); Using where SELECT * FROM City USE INDEX () WHERE Name BETWEEN 'M' AND 'N' AND Population > 1000000 AND Country LIKE 'C%'; ID Name Country Population @@ -482,13 +479,13 @@ EXPLAIN SELECT * FROM City WHERE ID BETWEEN 2001 AND 2500 AND Population > 300000 AND Country LIKE 'H%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where +1 SIMPLE City range PRIMARY,Population,Country Country 7 NULL # Using index condition; Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3701 AND 4000 AND Population > 1000000 AND Country BETWEEN 'S' AND 'Z'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where +1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population 4,4 NULL # Using sort_intersect(PRIMARY,Population); Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 @@ -721,7 +718,7 @@ EXPLAIN SELECT * FROM City WHERE Name BETWEEN 'G' AND 'J' AND Population > 500000 AND Country LIKE 'C%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range Population,Country,Name Name 35 NULL # Using index condition; Using where +1 SIMPLE City index_merge Population,Country,Name Name,Population,Country 35,4,3 NULL # Using sort_intersect(Name,Population,Country); Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 1 AND 500 AND Population > 700000 AND Country LIKE 'C%'; @@ -732,7 +729,7 @@ SELECT * FROM City WHERE ID BETWEEN 3001 AND 4000 AND Population > 600000 AND Country BETWEEN 'S' AND 'Z'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country PRIMARY 4 NULL # Using where +1 SIMPLE City index_merge PRIMARY,Population,Country PRIMARY,Population,Country 4,4,7 NULL # Using sort_intersect(PRIMARY,Population,Country); Using where SELECT * FROM City WHERE Name LIKE 'C%' AND Population > 1000000; ID Name Country Population diff --git a/mysql-test/main/index_merge_myisam.result b/mysql-test/main/index_merge_myisam.result index 053239b7fb1..89762b2407f 100644 --- a/mysql-test/main/index_merge_myisam.result +++ b/mysql-test/main/index_merge_myisam.result @@ -671,7 +671,7 @@ key1 key2 key3 key4 filler1 -1 -1 100 100 key4-key3 explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 2 Using intersect(key1,key2,key3); Using where; Using index +1 SIMPLE t1 index_merge key1,key2,key3 key1,key2 5,5 NULL 77 Using intersect(key1,key2); Using where select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; key1 key2 key3 100 100 100 @@ -756,7 +756,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a sta_swt21a 12 const,const,const 971 explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1a_2b 8 const,const 3879 Using where +1 SIMPLE t1 ref stb_swt1a_2b,stb_swt1b,st_b stb_swt1b 8 const,const 3885 Using where explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index_merge sta_swt12a,sta_swt1a,sta_swt2a,sta_swt21a,st_a,stb_swt1a_2b,stb_swt1b,st_b sta_swt12a,stb_swt1a_2b 12,12 NULL 58 Using intersect(sta_swt12a,stb_swt1a_2b); Using where @@ -898,7 +898,7 @@ INSERT INTO t1 (key1, key2, filler) SELECT seq/4, seq/8, 'filler-data' FROM seq_30_to_0; explain select pk from t1 where key1 = 1 and key2 = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref key1,key2 key1 5 const 4 Using where +1 SIMPLE t1 index_merge key1,key2 key1,key2 5,4 NULL 1 Using intersect(key1,key2); Using where select pk from t1 where key2 = 1 and key1 = 1; pk 26 @@ -1475,7 +1475,7 @@ EXPLAIN SELECT t1.f1 FROM t1 WHERE (SELECT COUNT(*) FROM t2 WHERE t2.f3 = 'h' AND t2.f2 = t1.f1) = 0 AND t1.f1 = 2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 -2 SUBQUERY t2 ref f2,f3 f3 2 const 2 Using index condition; Using where +2 SUBQUERY t2 index_merge f2,f3 f3,f2 2,5 NULL 1 Using intersect(f3,f2); Using where; Using index DROP TABLE t1,t2; create table t0 (a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); diff --git a/mysql-test/main/innodb_ext_key,off.rdiff b/mysql-test/main/innodb_ext_key,off.rdiff index 4d6c65c9971..75f5a3432b4 100644 --- a/mysql-test/main/innodb_ext_key,off.rdiff +++ b/mysql-test/main/innodb_ext_key,off.rdiff @@ -1,17 +1,20 @@ ---- innodb_ext_key.result -+++ innodb_ext_key,off.result +--- main/innodb_ext_key.result ++++ main/innodb_ext_key,off.reject @@ -9,7 +9,7 @@ explain select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 8 const,const 1 Using index -+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index ++1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey,i_l_shipdate 4,4 NULL 1 Using intersect(i_l_orderkey,i_l_shipdate); Using where; Using index flush status; select count(*) from lineitem where l_orderkey=130 and l_shipdate='1992-07-01'; count(*) -@@ -19,7 +19,7 @@ +@@ -17,9 +17,9 @@ + show status like 'handler_read%'; + Variable_name Value Handler_read_first 0 - Handler_read_key 1 +-Handler_read_key 1 ++Handler_read_key 2 Handler_read_last 0 -Handler_read_next 1 +Handler_read_next 6 @@ -95,13 +98,16 @@ where l_shipdate='1992-07-01' and l_orderkey=130; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away -+1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 const 6 Using where; Using index ++1 SIMPLE lineitem index_merge PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey,i_l_shipdate 4,4 NULL 1 Using intersect(i_l_orderkey,i_l_shipdate); Using where; Using index flush status; select max(l_linenumber) from lineitem where l_shipdate='1992-07-01' and l_orderkey=130; -@@ -145,7 +145,7 @@ +@@ -143,9 +143,9 @@ + show status like 'handler_read%'; + Variable_name Value Handler_read_first 0 - Handler_read_key 1 +-Handler_read_key 1 ++Handler_read_key 2 Handler_read_last 0 -Handler_read_next 0 +Handler_read_next 6 @@ -249,7 +255,7 @@ drop table t1,t2,t3; # # Bug mdev-4340: performance regression with extended_keys=on -@@ -714,13 +714,13 @@ +@@ -725,13 +725,13 @@ select * from t1 force index(index_date_updated) where index_date_updated= 10 and index_id < 800; id select_type table type possible_keys key key_len ref rows Extra @@ -265,7 +271,7 @@ drop table t0,t1,t2; # # MDEV-11196: Error:Run-Time Check Failure #2 - Stack around the variable 'key_buff' -@@ -755,11 +755,12 @@ +@@ -766,13 +766,14 @@ "select_id": 1, "table": { "table_name": "t1", @@ -279,9 +285,12 @@ + "used_key_parts": ["f2"], + "ref": ["const"], "rows": 1, - "filtered": 100, +- "filtered": 50, ++ "filtered": 100, "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", -@@ -788,8 +789,8 @@ + "attached_condition": "t1.f1 <= '3'" + } +@@ -799,8 +800,8 @@ "access_type": "range", "possible_keys": ["k1"], "key": "k1", @@ -290,5 +299,5 @@ + "key_length": "3007", + "used_key_parts": ["pk1", "f2"], "rows": 1, - "filtered": 100, + "filtered": 50, "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", diff --git a/mysql-test/main/innodb_ext_key.result b/mysql-test/main/innodb_ext_key.result index 27c2299c2ec..8cc7cfce861 100644 --- a/mysql-test/main/innodb_ext_key.result +++ b/mysql-test/main/innodb_ext_key.result @@ -385,8 +385,8 @@ SELECT a FROM t1 AS t, t2 WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t index a,b b 7 NULL 10 Using index -1 PRIMARY t1 ref b b 3 test.t.b 2 Using index; Start temporary -1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t1 ref b b 3 test.t.b 2 Using index +1 PRIMARY t2 index NULL PRIMARY 4 NULL 11 Using index; FirstMatch(t) 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t.a 1 Using index SELECT a FROM t1 AS t, t2 WHERE c = a AND b IN (SELECT b FROM t1, t2 WHERE b = t.b); @@ -638,14 +638,14 @@ test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK explain select a from t1 where b is null order by a desc limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index b PRIMARY 8 NULL 2 Using where +1 SIMPLE t1 range b b 9 NULL 3 Using where; Using filesort select a from t1 where b is null order by a desc limit 2; a 3 2 explain select a from t2 where b is null order by a desc limit 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range b b 9 NULL 3 Using where; Using filesort +1 SIMPLE t2 index b PRIMARY 8 NULL 2 Using where select a from t2 where b is null order by a desc limit 2; a 3 @@ -772,7 +772,7 @@ EXPLAIN "key_length": "3070", "used_key_parts": ["f2", "pk1"], "rows": 1, - "filtered": 100, + "filtered": 50, "index_condition": "t1.pk1 <= 5 and t1.pk2 <= 5 and t1.f2 = 'abc'", "attached_condition": "t1.f1 <= '3'" } @@ -802,7 +802,7 @@ EXPLAIN "key_length": "3011", "used_key_parts": ["pk1", "f2", "pk2"], "rows": 1, - "filtered": 100, + "filtered": 50, "index_condition": "t1.f2 <= 5 and t1.pk2 <= 5 and t1.pk1 = 'abc'", "attached_condition": "t1.f1 <= '3'" } diff --git a/mysql-test/main/innodb_icp.result b/mysql-test/main/innodb_icp.result index e08faa142cf..54594e2496a 100644 --- a/mysql-test/main/innodb_icp.result +++ b/mysql-test/main/innodb_icp.result @@ -436,8 +436,8 @@ SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where +2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index 2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using where -2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); pk i diff --git a/mysql-test/main/join.result b/mysql-test/main/join.result index 6ea42ea6588..942fc3af4ea 100644 --- a/mysql-test/main/join.result +++ b/mysql-test/main/join.result @@ -880,7 +880,7 @@ select @a:= A.a + 10*(B.a + 10*C.a), @a, 'filler' from t1 A, t1 B, t1 C; insert into t3 select * from t2 where a < 800; explain select * from t2,t3 where t2.a < 200 and t2.b=t3.b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL a,b NULL NULL NULL 1000 Using where +1 SIMPLE t2 range a,b a 5 NULL 198 Using index condition; Using where 1 SIMPLE t3 ref b b 5 test.t2.b 1 drop table t1, t2, t3; create table t1 (a int); @@ -892,13 +892,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 show status like '%cost%'; Variable_name Value -Last_query_cost 6.016090 +Last_query_cost 4.008545 select 'The cost of accessing t1 (dont care if it changes' '^'; The cost of accessing t1 (dont care if it changes The cost of accessing t1 (dont care if it changes^ select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z; Z vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv +set @@optimizer_cache_hit_ratio=0; explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 10 Using where @@ -906,10 +907,11 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE B eq_ref PRIMARY PRIMARY 4 test.A.b 1 show status like '%cost%'; Variable_name Value -Last_query_cost 34.016090 -select '^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error' Z; +Last_query_cost 49.027829 +select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z; Z -^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error +^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error +set @@optimizer_cache_hit_ratio=default; drop table t1, t2; CREATE TABLE t1 (a INT PRIMARY KEY, b INT); CREATE TABLE t2 (c INT PRIMARY KEY, d INT); @@ -1274,20 +1276,24 @@ test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK test.t2 analyze status Engine-independent statistics collected test.t2 analyze status OK +explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL ix2 NULL NULL NULL 2 Using where; Using temporary; Using filesort +1 SIMPLE t1 ref ix1 ix1 5 test.t2.v 1 FLUSH STATUS; SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; pk v pk v SHOW STATUS LIKE 'Handler_read_%'; Variable_name Value Handler_read_first 0 -Handler_read_key 14 +Handler_read_key 0 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_retry 0 Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 1 +Handler_read_rnd_next 4 DROP TABLE t1, t2; End of 5.1 tests # @@ -1473,8 +1479,8 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE DU system dog_id NULL NULL NULL 1 1 SIMPLE D system PRIMARY NULL NULL NULL 1 1 SIMPLE DSAR system NULL NULL NULL NULL 1 -1 SIMPLE DSA ref PRIMARY PRIMARY 4 const 3 Using where; Using index -1 SIMPLE DT ALL t_id NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +1 SIMPLE DT ALL t_id NULL NULL NULL 2 Using where +1 SIMPLE DSA ref PRIMARY PRIMARY 8 const,test.DT.t_id,func 1 Using index SELECT * FROM t5 DU, t1 D, t4 DT, t2 DSA, t3 DSAR WHERE DU.dog_id=D.dog_id AND D.dog_id=DT.dog_id AND D.birthday=DT.birthday AND DT.t_id=DSA.t_id AND DT.birthday=DSA.birthday AND DSA.dog_id=DSAR.dog_id; diff --git a/mysql-test/main/join.test b/mysql-test/main/join.test index bc8a83c0bb8..e21d0c12360 100644 --- a/mysql-test/main/join.test +++ b/mysql-test/main/join.test @@ -697,12 +697,11 @@ select 'The cost of accessing t1 (dont care if it changes' '^'; select 'vv: Following query must use ALL(t1), eq_ref(A), eq_ref(B): vv' Z; +set @@optimizer_cache_hit_ratio=0; explain select * from t1, t2 A, t2 B where A.a = t1.a and B.a=A.b; show status like '%cost%'; -select '^^: The above should be ~= 20 + cost(select * from t1). Value less than 20 is an error' Z; - - - +select '^^: The above should be ~= 40 + cost(select * from t1). Value less than 40 is an error' Z; +set @@optimizer_cache_hit_ratio=default; drop table t1, t2; # @@ -957,6 +956,9 @@ INSERT INTO t1 VALUES (3,'b'),(4,NULL),(5,'c'),(6,'cc'),(7,'d'), (8,'dd'),(9,'e'),(10,'ee'); INSERT INTO t2 VALUES (2,NULL); ANALYZE TABLE t1,t2; +# This will ensure that status tables are read now and not part of the later +# Handler_read% counts +explain SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; FLUSH STATUS; SELECT * FROM t1 JOIN t2 ON t1.v = t2.v WHERE t2.v IS NULL ORDER BY 1; SHOW STATUS LIKE 'Handler_read_%'; diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index f035503d0ef..807aea7465b 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -53,6 +53,7 @@ set join_cache_level=1; show variables like 'join_cache_level'; Variable_name Value join_cache_level 1 +# Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -60,6 +61,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join) +# Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -79,6 +81,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -91,6 +94,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join) 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join) +# Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -131,6 +135,7 @@ set join_cache_level=2; show variables like 'join_cache_level'; Variable_name Value join_cache_level 2 +# join_cache_level 2, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -138,6 +143,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join) +# join_cache_level 2, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -157,6 +163,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 2, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -169,6 +176,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join) 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (incremental, BNL join) +# join_cache_level 2, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -209,6 +217,7 @@ set join_cache_level=3; show variables like 'join_cache_level'; Variable_name Value join_cache_level 3 +# join_cache_level 3, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -216,6 +225,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# join_cache_level 3, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -235,6 +245,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 3, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -247,6 +258,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# join_cache_level 3, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -287,6 +299,7 @@ set join_cache_level=4; show variables like 'join_cache_level'; Variable_name Value join_cache_level 4 +# join_cache_level 4, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -294,6 +307,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# join_cache_level 4, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -313,6 +327,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 4, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -325,6 +340,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (incremental, BNLH join) +# join_cache_level 4, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -361,6 +377,7 @@ Ludwigshafen am Rhein Germany German Lungtan Taiwan Min L´Hospitalet de Llobregat Spain Spanish Lázaro Cárdenas Mexico Spanish +# join_cache_level 4, Query 5 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 @@ -379,6 +396,7 @@ Canada 31147000 NULL NULL Cuba 11201000 NULL NULL Côte d?Ivoire 14786000 NULL NULL Czech Republic 10278100 NULL NULL +# join_cache_level 4, Query 6 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND @@ -404,6 +422,7 @@ Czech Republic 10278100 NULL NULL CREATE INDEX City_Population ON City(Population); CREATE INDEX City_Name ON City(Name); ANALYZE TABLE City; +# After Analyze, Query 1 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City @@ -412,6 +431,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City hash_range City_Population #hash#$hj:City_Population 3:4 world.Country.Code 24 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +# After Analyze, Query 2 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 @@ -430,6 +450,7 @@ Canada 31147000 NULL NULL Cuba 11201000 NULL NULL Côte d?Ivoire 14786000 NULL NULL Czech Republic 10278100 NULL NULL +# After Analyze, Query 3 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City @@ -439,6 +460,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City hash_index_merge City_Population,City_Name #hash#$hj:City_Population,City_Name 3:4,35 world.Country.Code 96 Using sort_union(City_Population,City_Name); Using where; Using join buffer (flat, BNLH join) +# After Analyze, Query 4 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND @@ -471,6 +493,7 @@ join_buffer_size 256 show variables like 'join_cache_level'; Variable_name Value join_cache_level 1 +# join_cache_level 1, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -478,6 +501,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join) +# join_cache_level 1, Join_buffer_size, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -497,6 +521,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 1, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -509,6 +534,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join) 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join) +# join_cache_level 1, Join_buffer_size, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -549,6 +575,7 @@ set join_cache_level=2; show variables like 'join_cache_level'; Variable_name Value join_cache_level 2 +# join_cache_level 2, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -556,6 +583,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (flat, BNL join) +# join_cache_level 2, Join_buffer_size, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -575,6 +603,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 2, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -587,6 +616,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage ALL NULL NULL NULL NULL 984 Using where; Using join buffer (flat, BNL join) 1 SIMPLE City ALL NULL NULL NULL NULL 4079 Using where; Using join buffer (incremental, BNL join) +# join_cache_level 2, Join_buffer_size, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -627,6 +657,7 @@ set join_cache_level=3; show variables like 'join_cache_level'; Variable_name Value join_cache_level 3 +# join_cache_level 3, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -634,6 +665,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# join_cache_level 3, Join_buffer_size, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -653,6 +685,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 3, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -665,6 +698,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# join_cache_level 3, Join_buffer_size, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -705,6 +739,7 @@ set join_cache_level=4; show variables like 'join_cache_level'; Variable_name Value join_cache_level 4 +# join_cache_level 4, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -712,6 +747,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# join_cache_level 4, Join_buffer_size, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -731,6 +767,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# join_cache_level 4, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -743,6 +780,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage hash_ALL NULL #hash#$hj 3 world.Country.Code 984 Using where; Using join buffer (flat, BNLH join) 1 SIMPLE City hash_ALL NULL #hash#$hj 3 world.Country.Code 4079 Using where; Using join buffer (incremental, BNLH join) +# join_cache_level 4, Join_buffer_size, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -816,6 +854,7 @@ set join_cache_level=3; show variables like 'join_cache_level'; Variable_name Value join_cache_level 3 +# Part 2, join_cache_level=3, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -823,6 +862,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan 1 SIMPLE City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=3, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -842,6 +882,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# Part 2, join_cache_level=3, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -851,9 +892,10 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (flat, BNLH join); Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.Country.Code 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE City hash_ALL Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=3, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -890,6 +932,7 @@ Ludwigshafen am Rhein Germany German Lungtan Taiwan Min L´Hospitalet de Llobregat Spain Spanish Lázaro Cárdenas Mexico Spanish +# Part 2, join_cache_level=3, Query 5 EXPLAIN SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND @@ -897,6 +940,7 @@ City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan 1 PRIMARY City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=3, Query 6 SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND City.Population > 100000; @@ -916,6 +960,7 @@ Kaunas Klaipeda ?iauliai Panevezys +# Part 2, join_cache_level=3, Query 7 EXPLAIN SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON @@ -925,6 +970,7 @@ Country.Population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage hash_ALL PRIMARY #hash#PRIMARY 33 world.Country.Code,const 984 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=3, Query 8 SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON (CountryLanguage.Country=Country.Code AND Language='English') @@ -1016,6 +1062,7 @@ set join_cache_level=4; show variables like 'join_cache_level'; Variable_name Value join_cache_level 4 +# Part 2, join_cache_level=4, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND @@ -1023,6 +1070,7 @@ Country.Name LIKE 'L%' AND City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan 1 SIMPLE City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=4, Query 2 SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; @@ -1042,6 +1090,7 @@ Tripoli Lebanon Tripoli Libyan Arab Jamahiriya Vientiane Laos Vilnius Lithuania +# Part 2, join_cache_level=4, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -1051,9 +1100,10 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (incremental, BNLH join); Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.Country.Code 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE City hash_ALL Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (incremental, BNLH join) +# Part 2, join_cache_level=4, Query 4 SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -1090,6 +1140,7 @@ Ludwigshafen am Rhein Germany German Lungtan Taiwan Min L´Hospitalet de Llobregat Spain Spanish Lázaro Cárdenas Mexico Spanish +# Part 2, join_cache_level=4, Query 5 EXPLAIN SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND @@ -1097,6 +1148,7 @@ City.Population > 100000; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY Country range PRIMARY,Name Name 52 NULL 10 Using index condition; Rowid-ordered scan 1 PRIMARY City hash_ALL Population,Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=4, Query 6 SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND City.Population > 100000; @@ -1116,6 +1168,7 @@ Kaunas Klaipeda ?iauliai Panevezys +# Part 2, join_cache_level=4, Query 7 EXPLAIN SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON @@ -1125,6 +1178,7 @@ Country.Population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country ALL NULL NULL NULL NULL 239 Using where 1 SIMPLE CountryLanguage hash_ALL PRIMARY #hash#PRIMARY 33 world.Country.Code,const 984 Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=4, Query 8 SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON (CountryLanguage.Country=Country.Code AND Language='English') @@ -1209,6 +1263,7 @@ Belarus NULL Venezuela NULL Russian Federation NULL Vietnam NULL +# Part 2, join_cache_level=4, Query 9 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City @@ -1217,6 +1272,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country range Name Name 52 NULL # Using index condition; Using where; Rowid-ordered scan 1 SIMPLE City hash_range Population,Country #hash#Country:Population 3:4 world.Country.Code # Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=4, Query 10 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 @@ -1236,6 +1292,7 @@ Cuba 11201000 NULL NULL Côte d?Ivoire 14786000 NULL NULL Czech Republic 10278100 NULL NULL CREATE INDEX City_Name ON City(Name); +# Part 2, join_cache_level=4, City_Name, Query 1 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City @@ -1245,6 +1302,7 @@ WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE Country range Name Name 52 NULL 17 Using index condition; Using where; Rowid-ordered scan 1 SIMPLE City hash_index_merge Population,Country,City_Name #hash#Country:Population,City_Name 3:4,35 world.Country.Code 96 Using sort_union(Population,City_Name); Using where; Using join buffer (flat, BNLH join) +# Part 2, join_cache_level=4, City_Name, Query 2 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND @@ -1310,9 +1368,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -1507,9 +1565,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -1704,9 +1762,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -1901,9 +1959,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2102,9 +2160,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (flat, BNLH join); Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.Country.Code 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE City hash_ALL Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (flat, BNLH join) SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2206,9 +2264,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country hash_ALL PRIMARY #hash#PRIMARY 3 world.City.Country 239 Using where; Using join buffer (flat, BNLH join) -1 SIMPLE CountryLanguage hash_ALL|filter PRIMARY,Percentage #hash#PRIMARY|Percentage 3|4 world.City.Country 984 (19%) Using where; Using join buffer (incremental, BNLH join); Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage hash_range PRIMARY,Percentage #hash#PRIMARY:Percentage 3:4 world.Country.Code 185 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) +1 SIMPLE City hash_ALL Country #hash#Country 3 world.Country.Code 4079 Using where; Using join buffer (incremental, BNLH join) SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2310,9 +2368,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2414,9 +2472,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2518,9 +2576,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -2622,9 +2680,9 @@ City.Name LIKE 'L%' AND Country.Population > 3000000 AND CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL Country NULL NULL NULL 4079 Using where -1 SIMPLE Country eq_ref PRIMARY PRIMARY 3 world.City.Country 1 Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.City.Country 4 (19%) Using index condition(BKA); Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE Country ALL PRIMARY NULL NULL NULL 239 Using where +1 SIMPLE CountryLanguage ref|filter PRIMARY,Percentage PRIMARY|Percentage 3|4 world.Country.Code 4 (19%) Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE City ref Country Country 3 world.Country.Code 17 Using where; Using join buffer (incremental, BKAH join); Key-ordered Rowid-ordered scan SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage WHERE City.Country=Country.Code AND @@ -3067,15 +3125,15 @@ t1.metaid = t2.metaid AND t1.affiliateid = '2'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t6 system PRIMARY NULL NULL NULL 1 1 SIMPLE t5 ref PRIMARY,t5_formattypeid t5_formattypeid 4 const 1 -1 SIMPLE t9 index PRIMARY,t9_subgenreid,t9_metaid PRIMARY 8 NULL 2 Using index; Using join buffer (flat, BNL join) -1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t9.metaid 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t7 ref PRIMARY PRIMARY 4 test.t9.metaid 1 Using index -1 SIMPLE t8 eq_ref PRIMARY PRIMARY 4 test.t7.artistid 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t1 ref t1_affiliateid,t1_metaid t1_affiliateid 4 const 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t7 ref PRIMARY PRIMARY 4 test.t1.metaid 1 Using index +1 SIMPLE t9 index PRIMARY,t9_subgenreid,t9_metaid PRIMARY 8 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.metaid 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t8 eq_ref PRIMARY PRIMARY 4 test.t7.artistid 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t10 eq_ref PRIMARY,t10_genreid PRIMARY 4 test.t9.subgenreid 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t11 eq_ref PRIMARY PRIMARY 4 test.t10.genreid 1 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t3 ref t3_metaid,t3_formatid,t3_metaidformatid t3_metaidformatid 4 test.t9.metaid 1 Using index condition; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t3 ref t3_metaid,t3_formatid,t3_metaidformatid t3_metaidformatid 4 test.t1.metaid 1 Using index condition; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan 1 SIMPLE t4 eq_ref PRIMARY,t4_formatclassid,t4_formats_idx PRIMARY 4 test.t3.formatid 1 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan -1 SIMPLE t1 ref t1_affiliateid,t1_metaid t1_affiliateid 4 const 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t1.uniquekey, t1.xml AS affiliateXml, t8.name AS artistName, t8.artistid, t11.name AS genreName, t11.genreid, t11.priority AS genrePriority, @@ -3191,7 +3249,7 @@ Warning 1292 Truncated incorrect join_buffer_size value: '32' set join_cache_level=8; EXPLAIN SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range idx idx 5 NULL 3 Using index condition; Using where; Rowid-ordered scan +1 SIMPLE t1 ALL idx NULL NULL NULL 7 Using where 1 SIMPLE t2 ref idx idx 5 test.t1.a 2 Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan SELECT * FROM t1,t2 WHERE t1.a=t2.a AND t1.b >= 30; a b a b @@ -3371,8 +3429,8 @@ set join_cache_level=6; set join_buffer_size=1024; EXPLAIN SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 2050 Using where -1 SIMPLE t2 ref idx idx 5 test.t1.a 640 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t2 ALL idx NULL NULL NULL 1280 Using where +1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t2.b 2050 Using where; Using join buffer (flat, BNLH join) SELECT AVG(c) FROM t1,t2 WHERE t1.a=t2.b; AVG(c) 5.0000 @@ -4969,8 +5027,8 @@ FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1) LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 -1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 1 Using where -1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.a2 1 Using index +1 SIMPLE t3 index PRIMARY PRIMARY 4 NULL 1 Using where; Using index +1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t3.a3 1 Using where 1 SIMPLE t4 ALL NULL NULL NULL NULL 1 Using where 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t2.a2 1 Using where SELECT t4.a4, t5.b5 @@ -5054,13 +5112,15 @@ CREATE TABLE t2 ( f3 int(11), f2 varchar(1024), f4 varchar(10), PRIMARY KEY (f3) ); INSERT INTO t2 VALUES (6,'RPOYT','y'),(10,'JINQE','m'); +INSERT INTO t2 VALUES (100,'Q','q'),(101,'Q','q'),(102,'Q','q'),(103,'Q','q'); +INSERT INTO t2 VALUES (104,'Q','q'),(105,'Q','q'),(106,'Q','q'),(107,'Q','q'); SET SESSION join_cache_level = 1; SET SESSION optimizer_switch = 'index_condition_pushdown=off'; EXPLAIN SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); @@ -5070,7 +5130,7 @@ EXPLAIN SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Rowid-ordered scan +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where 1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) SELECT * FROM t1,t2 WHERE t1.f1 = t2.f4 AND (t1.f3 = 1 AND t2.f3 = 4 OR t1.f3 = 2 AND t2.f3 = 6); @@ -5523,7 +5583,7 @@ and t2.uid=t1.fid; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ref uid uid 5 const 4 Using where; Start temporary 1 PRIMARY t4 eq_ref PRIMARY PRIMARY 4 test.t3.fid 1 Using index -1 PRIMARY t1 ALL uid NULL NULL NULL 11 Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t1 ref uid uid 5 test.t3.fid 2 Using where; End temporary; Using join buffer (flat, BKAH join); Rowid-ordered scan 1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.fid 1 Using join buffer (flat, BKAH join); Rowid-ordered scan select name from t2, t1 where t1.uid in (select t4.uid from t4, t3 where t3.uid=1 and t4.uid=t3.fid) @@ -6151,8 +6211,8 @@ a b c explain select t1.a, t1.b, t1.c from t1,t2 where t2.a = t1.a and t2.b = t1.b and t2.c=t1.c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where -1 SIMPLE t2 hash_index PRIMARY #hash#PRIMARY:PRIMARY 12:12 test.t1.c,test.t1.a,test.t1.b 2 Using index; Using join buffer (flat, BNLH join) +1 SIMPLE t2 index PRIMARY PRIMARY 12 NULL 2 Using index +1 SIMPLE t1 hash_ALL NULL #hash#$hj 15 test.t2.a,test.t2.b,test.t2.c 2 Using where; Using join buffer (flat, BNLH join) drop table t1,t2; set join_cache_level=@save_join_cache_level; # @@ -6197,7 +6257,7 @@ EXPLAIN "select_id": 1, "table": { "table_name": "a", - "access_type": "range", + "access_type": "index", "possible_keys": ["PRIMARY"], "key": "PRIMARY", "key_length": "4", diff --git a/mysql-test/main/join_cache.test b/mysql-test/main/join_cache.test index 4b659345db4..4b6231719c9 100644 --- a/mysql-test/main/join_cache.test +++ b/mysql-test/main/join_cache.test @@ -4,6 +4,7 @@ DROP DATABASE IF EXISTS world; --enable_warnings --source include/default_optimizer_switch.inc --source include/default_charset.inc +--source include/have_innodb.inc set @org_optimizer_switch=@@optimizer_switch; set @save_join_cache_level=@@join_cache_level; @@ -51,16 +52,19 @@ set join_cache_level=1; show variables like 'join_cache_level'; +--echo # Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -70,6 +74,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -82,16 +87,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language set join_cache_level=2; show variables like 'join_cache_level'; +--echo # join_cache_level 2, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 2, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 2, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -101,6 +109,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 2, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -113,16 +122,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language set join_cache_level=3; show variables like 'join_cache_level'; +--echo # join_cache_level 3, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 3, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 3, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -132,7 +144,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; - +--echo # join_cache_level 3, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -146,16 +158,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language set join_cache_level=4; show variables like 'join_cache_level'; +--echo # join_cache_level 4, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 4, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 4, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -165,6 +180,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 4, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -175,11 +191,13 @@ SELECT City.Name, Country.Name, CountryLanguage.Language LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 4, Query 5 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +--echo # join_cache_level 4, Query 6 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND @@ -193,17 +211,20 @@ CREATE INDEX City_Name ON City(Name); ANALYZE TABLE City; --enable_result_log +--echo # After Analyze, Query 1 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +--echo # After Analyze, Query 2 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +--echo # After Analyze, Query 3 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City @@ -211,6 +232,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population (City.Population > 5000000 OR City.Name LIKE 'Za%') WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +--echo # After Analyze, Query 4 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND @@ -227,16 +249,19 @@ show variables like 'join_buffer_size'; show variables like 'join_cache_level'; +--echo # join_cache_level 1, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 1, Join_buffer_size, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 1, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -246,6 +271,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 1, Join_buffer_size, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -258,16 +284,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language set join_cache_level=2; show variables like 'join_cache_level'; +--echo # join_cache_level 2, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 2, Join_buffer_size, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 2, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -277,6 +306,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 2, Join_buffer_size, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -289,16 +319,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language set join_cache_level=3; show variables like 'join_cache_level'; +--echo # join_cache_level 3, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 3, Join_buffer_size, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 3, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -308,6 +341,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 3, Join_buffer_size, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -320,16 +354,19 @@ SELECT City.Name, Country.Name, CountryLanguage.Language set join_cache_level=4; show variables like 'join_cache_level'; +--echo # join_cache_level 4, Join_buffer_size, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 4, Join_buffer_size, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # join_cache_level 4, Join_buffer_size, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -339,6 +376,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # join_cache_level 4, Join_buffer_size, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -372,16 +410,19 @@ show variables like 'join_buffer_size'; set join_cache_level=3; show variables like 'join_cache_level'; +--echo # Part 2, join_cache_level=3, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # Part 2, join_cache_level=3, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # Part 2, join_cache_level=3, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -391,6 +432,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # Part 2, join_cache_level=3, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -400,15 +442,18 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # Part 2, join_cache_level=3, Query 5 EXPLAIN SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND City.Population > 100000; +--echo # Part 2, join_cache_level=3, Query 6 SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND City.Population > 100000; +--echo # Part 2, join_cache_level=3, Query 7 EXPLAIN SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON @@ -416,6 +461,7 @@ SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.P WHERE Country.Population > 10000000; +--echo # Part 2, join_cache_level=3, Query 8 SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON (CountryLanguage.Country=Country.Code AND Language='English') @@ -426,16 +472,19 @@ show variables like 'join_buffer_size'; set join_cache_level=4; show variables like 'join_cache_level'; +--echo # Part 2, join_cache_level=4, Query 1 EXPLAIN SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # Part 2, join_cache_level=4, Query 2 --sorted_result SELECT City.Name, Country.Name FROM City,Country WHERE City.Country=Country.Code AND Country.Name LIKE 'L%' AND City.Population > 100000; +--echo # Part 2, join_cache_level=4, Query 3 EXPLAIN SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -445,6 +494,7 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # Part 2, join_cache_level=4, Query 4 --sorted_result SELECT City.Name, Country.Name, CountryLanguage.Language FROM City,Country,CountryLanguage @@ -454,15 +504,18 @@ SELECT City.Name, Country.Name, CountryLanguage.Language CountryLanguage.Percentage > 50 AND LENGTH(Language) < LENGTH(City.Name) - 2; +--echo # Part 2, join_cache_level=4, Query 5 EXPLAIN SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND City.Population > 100000; +--echo # Part 2, join_cache_level=4, Query 6 SELECT Name FROM City WHERE City.Country IN (SELECT Code FROM Country WHERE Country.Name LIKE 'L%') AND City.Population > 100000; +--echo # Part 2, join_cache_level=4, Query 7 EXPLAIN SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON @@ -470,13 +523,14 @@ SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.P WHERE Country.Population > 10000000; +--echo # Part 2, join_cache_level=4, Query 8 SELECT Country.Name, IF(ISNULL(CountryLanguage.Country), NULL, CountryLanguage.Percentage) FROM Country LEFT JOIN CountryLanguage ON (CountryLanguage.Country=Country.Code AND Language='English') WHERE Country.Population > 10000000; - +--echo # Part 2, join_cache_level=4, Query 9 --replace_column 9 # EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population @@ -484,6 +538,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population ON City.Country=Country.Code AND City.Population > 5000000 WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +--echo # Part 2, join_cache_level=4, Query 10 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND City.Population > 5000000 @@ -491,6 +546,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population CREATE INDEX City_Name ON City(Name); +--echo # Part 2, join_cache_level=4, City_Name, Query 1 EXPLAIN SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City @@ -498,6 +554,7 @@ SELECT Country.Name, Country.Population, City.Name, City.Population (City.Population > 5000000 OR City.Name LIKE 'Za%') WHERE Country.Name LIKE 'C%' AND Country.Population > 10000000; +--echo # Part 2, join_cache_level=4, City_Name, Query 2 SELECT Country.Name, Country.Population, City.Name, City.Population FROM Country LEFT JOIN City ON City.Country=Country.Code AND @@ -3175,6 +3232,8 @@ CREATE TABLE t2 ( f3 int(11), f2 varchar(1024), f4 varchar(10), PRIMARY KEY (f3) ); INSERT INTO t2 VALUES (6,'RPOYT','y'),(10,'JINQE','m'); +INSERT INTO t2 VALUES (100,'Q','q'),(101,'Q','q'),(102,'Q','q'),(103,'Q','q'); +INSERT INTO t2 VALUES (104,'Q','q'),(105,'Q','q'),(106,'Q','q'),(107,'Q','q'); SET SESSION join_cache_level = 1; @@ -3777,8 +3836,6 @@ drop table t0,t1,t2; --echo # of LEFT JOIN operations when using join buffer --echo # ---source include/have_innodb.inc - CREATE TABLE t1 ( id int(11) NOT NULL AUTO_INCREMENT, col1 varchar(255) NOT NULL DEFAULT '', diff --git a/mysql-test/main/join_nested.result b/mysql-test/main/join_nested.result index 2c66733adea..b63436326ec 100644 --- a/mysql-test/main/join_nested.result +++ b/mysql-test/main/join_nested.result @@ -1062,9 +1062,9 @@ t0.b=t1.b AND (t8.b=t9.b OR t8.c IS NULL) AND (t9.a=1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t0 ref idx_a idx_a 5 const 2 100.00 +1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 Using where +1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t1 ALL idx_b NULL NULL NULL 7 75.00 Using where; Using join buffer (flat, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where 1 SIMPLE t4 ref idx_b idx_b 5 test.t2.b 2 100.00 Using where @@ -1111,20 +1111,20 @@ t0.b=t1.b AND a b a b a b a b a b a b a b a b a b a b 1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 1 1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 2 +1 2 3 2 4 2 1 2 3 2 2 2 6 2 2 2 0 2 1 2 1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 1 -1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 1 -1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1 -1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1 -1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 1 -1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 2 -1 2 3 2 4 2 1 2 3 2 2 2 6 2 2 2 0 2 1 2 +1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 2 -1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2 1 2 3 2 4 2 1 2 4 2 2 2 6 2 2 2 0 2 1 2 +1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1 +1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2 +1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 2 -1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 2 1 2 3 2 5 3 NULL NULL NULL NULL 2 2 6 2 2 2 0 2 1 2 +1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 1 +1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 2 +1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 2 SELECT t2.a,t2.b FROM t2; @@ -1744,9 +1744,9 @@ ON t4.carrier = t1.carrier; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index package_id package_id 5 NULL 45 Using where; Using index 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.package_id 1 +1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index 1 SIMPLE t4 eq_ref PRIMARY,id PRIMARY 2 test.t1.carrier 1 Using where 1 SIMPLE t5 ref carrier_id carrier_id 5 test.t4.id 22 Using index -1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index SELECT COUNT(*) FROM ((t2 JOIN t1 ON t2.package_id = t1.id) JOIN t3 ON t3.package_id = t1.id) diff --git a/mysql-test/main/join_nested.test b/mysql-test/main/join_nested.test index 864218371f4..f0c6a9b65e0 100644 --- a/mysql-test/main/join_nested.test +++ b/mysql-test/main/join_nested.test @@ -637,6 +637,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 (t9.a=1); +--sorted_result SELECT t0.a,t0.b,t1.a,t1.b,t2.a,t2.b,t3.a,t3.b,t4.a,t4.b, t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b,t9.a,t9.b FROM t0,t1 diff --git a/mysql-test/main/join_nested_jcl6.result b/mysql-test/main/join_nested_jcl6.result index 795e22c3ed2..40fe97d7e34 100644 --- a/mysql-test/main/join_nested_jcl6.result +++ b/mysql-test/main/join_nested_jcl6.result @@ -920,16 +920,16 @@ t0.b=t1.b AND id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t0 ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t1 hash_ALL NULL #hash#$hj 5 test.t0.b 3 100.00 Using where; Using join buffer (flat, BNLH join) +1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t7 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t6 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t8 hash_ALL NULL #hash#$hj 5 test.t5.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (incremental, BNL join) -1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) -1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t4 hash_ALL NULL #hash#$hj 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BNLH join) Warnings: -Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`a` > 0 and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t3`.`b` = `test`.`t4`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t9`.`b` = `test`.`t8`.`b` or `test`.`t8`.`c` is null) +Note 1003 select `test`.`t0`.`a` AS `a`,`test`.`t0`.`b` AS `b`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b`,`test`.`t5`.`a` AS `a`,`test`.`t5`.`b` AS `b`,`test`.`t6`.`a` AS `a`,`test`.`t6`.`b` AS `b`,`test`.`t7`.`a` AS `a`,`test`.`t7`.`b` AS `b`,`test`.`t8`.`a` AS `a`,`test`.`t8`.`b` AS `b`,`test`.`t9`.`a` AS `a`,`test`.`t9`.`b` AS `b` from `test`.`t0` join `test`.`t1` left join (`test`.`t2` left join (`test`.`t3` join `test`.`t4`) on(`test`.`t3`.`a` = 1 and `test`.`t4`.`b` = `test`.`t2`.`b` and `test`.`t2`.`a` > 0 and `test`.`t2`.`b` is not null) join `test`.`t5` left join (`test`.`t6` join `test`.`t7` left join `test`.`t8` on(`test`.`t8`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` < 10 and `test`.`t5`.`b` is not null)) on(`test`.`t7`.`b` = `test`.`t5`.`b` and `test`.`t6`.`b` >= 2 and `test`.`t5`.`b` is not null)) on((`test`.`t3`.`b` = 2 or `test`.`t3`.`c` is null) and (`test`.`t6`.`b` = 2 or `test`.`t6`.`c` is null) and (`test`.`t5`.`b` = `test`.`t0`.`b` or `test`.`t3`.`c` is null or `test`.`t6`.`c` is null or `test`.`t8`.`c` is null) and `test`.`t1`.`a` <> 2) join `test`.`t9` where `test`.`t0`.`a` = 1 and `test`.`t1`.`b` = `test`.`t0`.`b` and `test`.`t9`.`a` = 1 and (`test`.`t2`.`a` >= 4 or `test`.`t2`.`c` is null) and (`test`.`t3`.`a` < 5 or `test`.`t3`.`c` is null) and (`test`.`t4`.`b` = `test`.`t3`.`b` or `test`.`t3`.`c` is null or `test`.`t4`.`c` is null) and (`test`.`t5`.`a` >= 2 or `test`.`t5`.`c` is null) and (`test`.`t6`.`a` >= 4 or `test`.`t6`.`c` is null) and (`test`.`t7`.`a` <= 2 or `test`.`t7`.`c` is null) and (`test`.`t8`.`a` < 1 or `test`.`t8`.`c` is null) and (`test`.`t8`.`b` = `test`.`t9`.`b` or `test`.`t8`.`c` is null) 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); @@ -1071,9 +1071,9 @@ t0.b=t1.b AND (t8.b=t9.b OR t8.c IS NULL) AND (t9.a=1); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t0 ref idx_a idx_a 5 const 2 100.00 -1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) -1 SIMPLE t1 ALL idx_b NULL NULL NULL 7 75.00 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t0 ALL idx_a NULL NULL NULL 3 66.67 Using where +1 SIMPLE t1 ref idx_b idx_b 5 test.t0.b 2 100.00 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t9 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t2 ALL NULL NULL NULL NULL 8 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t3 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t4 ref idx_b idx_b 5 test.t2.b 2 100.00 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan @@ -1118,14 +1118,16 @@ t0.b=t1.b AND (t8.b=t9.b OR t8.c IS NULL) AND (t9.a=1); a b a b a b a b a b a b a b a b a b a b -1 2 3 2 4 2 1 2 4 2 2 2 6 2 2 2 0 2 1 2 +1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 1 +1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 2 1 2 3 2 4 2 1 2 3 2 2 2 6 2 2 2 0 2 1 2 1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 1 1 2 3 2 4 2 1 2 3 2 3 1 6 2 1 1 NULL NULL 1 2 -1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1 -1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2 1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 4 2 1 2 3 2 3 3 NULL NULL NULL NULL NULL NULL 1 2 +1 2 3 2 4 2 1 2 4 2 2 2 6 2 2 2 0 2 1 2 +1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 1 +1 2 3 2 4 2 1 2 4 2 3 1 6 2 1 1 NULL NULL 1 2 1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 4 2 1 2 4 2 3 3 NULL NULL NULL NULL NULL NULL 1 2 1 2 3 2 5 3 NULL NULL NULL NULL 2 2 6 2 2 2 0 2 1 2 @@ -1133,8 +1135,6 @@ a b a b a b a b a b a b a b a b a b a b 1 2 3 2 5 3 NULL NULL NULL NULL 3 1 6 2 1 1 NULL NULL 1 2 1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 1 1 2 3 2 5 3 NULL NULL NULL NULL 3 3 NULL NULL NULL NULL NULL NULL 1 2 -1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 1 -1 2 2 2 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 1 2 SELECT t2.a,t2.b FROM t2; a b @@ -1753,9 +1753,9 @@ ON t4.carrier = t1.carrier; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index package_id package_id 5 NULL 45 Using where; Using index 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.package_id 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index 1 SIMPLE t4 eq_ref PRIMARY,id PRIMARY 2 test.t1.carrier 1 Using where 1 SIMPLE t5 ref carrier_id carrier_id 5 test.t4.id 22 Using index -1 SIMPLE t3 ref package_id package_id 5 test.t2.package_id 1 Using index SELECT COUNT(*) FROM ((t2 JOIN t1 ON t2.package_id = t1.id) JOIN t3 ON t3.package_id = t1.id) @@ -2033,8 +2033,8 @@ ON t6.b >= 2 AND t5.b=t7.b AND (t8.a > 0 OR t8.c IS NULL) AND t6.a>0 AND t7.a>0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t5 ALL NULL NULL NULL NULL 3 -1 SIMPLE t7 range PRIMARY,b_i PRIMARY 4 NULL 2 Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) -1 SIMPLE t6 range|filter PRIMARY,b_i PRIMARY|b_i 4|5 NULL 3 (86%) Using where; Rowid-ordered scan; Using join buffer (incremental, BNL join); Using rowid filter +1 SIMPLE t7 ref|filter PRIMARY,b_i b_i|PRIMARY 5|4 test.t5.b 2 (29%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +1 SIMPLE t6 ALL PRIMARY,b_i NULL NULL NULL 7 Using where; Using join buffer (incremental, BNL join) 1 SIMPLE t8 ref b_i b_i 5 test.t5.b 2 Using where; Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan SELECT t5.a,t5.b,t6.a,t6.b,t7.a,t7.b,t8.a,t8.b FROM t5 diff --git a/mysql-test/main/join_outer.result b/mysql-test/main/join_outer.result index fcffeb6d161..184897aa726 100644 --- a/mysql-test/main/join_outer.result +++ b/mysql-test/main/join_outer.result @@ -2276,7 +2276,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 left join t2 on t2.c is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 9 -1 SIMPLE t2 ALL c NULL NULL NULL 1000 Using where +1 SIMPLE t2 ref c c 5 const 393 Using where drop table t1,t2; # # MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause diff --git a/mysql-test/main/join_outer_innodb.result b/mysql-test/main/join_outer_innodb.result index 6f87048cdc1..33f5062ec16 100644 --- a/mysql-test/main/join_outer_innodb.result +++ b/mysql-test/main/join_outer_innodb.result @@ -440,6 +440,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where 1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where; Using index +1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1 1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1 @@ -453,7 +454,6 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where 1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where; Using index 1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where -1 SIMPLE t10 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) explain select * from v1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL a4,a6,a5,a7 NULL NULL NULL 3 Using where @@ -462,6 +462,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 4 test.t1.a2 1 Using index 1 SIMPLE t5 eq_ref PRIMARY PRIMARY 4 test.t4.d1 1 Using where 1 SIMPLE t6 eq_ref PRIMARY PRIMARY 4 test.t1.a3 1 Using where; Using index +1 SIMPLE t10 eq_ref PRIMARY PRIMARY 1 test.t1.a6 1 1 SIMPLE t8 eq_ref PRIMARY PRIMARY 1 test.t1.a4 1 Using index 1 SIMPLE t7 eq_ref PRIMARY PRIMARY 1 test.t1.a7 1 1 SIMPLE t9 ref PRIMARY PRIMARY 1 test.t1.a4 1 @@ -475,7 +476,6 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t14 eq_ref PRIMARY PRIMARY 2 test.t1.a8 1 Using where 1 SIMPLE t15 eq_ref PRIMARY PRIMARY 2 test.t1.a9 1 Using where; Using index 1 SIMPLE t16 ref PRIMARY PRIMARY 2 test.t15.o1 1 Using where -1 SIMPLE t10 ALL PRIMARY NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) drop view v1; drop table t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13,t14,t15,t16; # diff --git a/mysql-test/main/join_outer_jcl6.result b/mysql-test/main/join_outer_jcl6.result index 371518e5e4e..d7147b273e5 100644 --- a/mysql-test/main/join_outer_jcl6.result +++ b/mysql-test/main/join_outer_jcl6.result @@ -2283,7 +2283,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select * from t1 left join t2 on t2.c is null; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 9 -1 SIMPLE t2 ALL c NULL NULL NULL 1000 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ref c c 5 const 393 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan drop table t1,t2; # # MDEV-10006: optimizer doesn't convert outer join to inner on views with WHERE clause diff --git a/mysql-test/main/key.result b/mysql-test/main/key.result index a35d1c872e6..2ebee91f824 100644 --- a/mysql-test/main/key.result +++ b/mysql-test/main/key.result @@ -232,11 +232,14 @@ numeropost 1 EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const numreponse numreponse 4 const 1 Using index +1 SIMPLE t1 const numreponse numreponse 4 const 1 FLUSH TABLES; SELECT numeropost FROM t1 WHERE numreponse='1'; numeropost 1 +EXPLAIN SELECT numreponse+0 FROM t1 WHERE numreponse='1'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const numreponse numreponse 4 const 1 Using index drop table t1; create table t1 (c varchar(30) character set utf8, t text character set utf8, unique (c(2)), unique (t(3))) engine=myisam; show create table t1; @@ -611,7 +614,7 @@ EXPLAIN SELECT 1 FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE -2 SUBQUERY t1 range a a 5 NULL 5 Using where; Using index +2 SUBQUERY t1 range a a 5 NULL 2 Using where; Using index for group-by SELECT 1 as RES FROM t1 AS t1_outer WHERE (SELECT max(b) FROM t1 GROUP BY a HAVING a < 2) > 12; RES @@ -629,19 +632,19 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort SHOW STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 10.412184 +Last_query_cost 8.806592 EXPLAIN SELECT a, SUM( b ) FROM t1 USE INDEX( a ) GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort SHOW STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 10.412184 +Last_query_cost 8.806592 EXPLAIN SELECT a, SUM( b ) FROM t1 FORCE INDEX( a ) GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL a 5 NULL 6 SHOW STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 15.399000 +Last_query_cost 8.806592 DROP TABLE t1; # # MDEV-21480: Unique key using ref access though eq_ref access can be used diff --git a/mysql-test/main/key.test b/mysql-test/main/key.test index 4e3e02c8add..5c5ba69dd0c 100644 --- a/mysql-test/main/key.test +++ b/mysql-test/main/key.test @@ -230,9 +230,12 @@ drop table t1; CREATE TABLE t1 (numeropost mediumint(8) unsigned NOT NULL default '0', numreponse int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (numeropost,numreponse), UNIQUE KEY numreponse (numreponse)); INSERT INTO t1 (numeropost,numreponse) VALUES ('1','1'),('1','2'),('2','3'),('2','4'); SELECT numeropost FROM t1 WHERE numreponse='1'; +# No 'Using index' EXPLAIN SELECT numeropost FROM t1 WHERE numreponse='1'; FLUSH TABLES; SELECT numeropost FROM t1 WHERE numreponse='1'; +# This one will have 'Using index' +EXPLAIN SELECT numreponse+0 FROM t1 WHERE numreponse='1'; drop table t1; # diff --git a/mysql-test/main/key_cache.result b/mysql-test/main/key_cache.result index c8bdc979387..0e6bad70af0 100644 --- a/mysql-test/main/key_cache.result +++ b/mysql-test/main/key_cache.result @@ -440,25 +440,25 @@ VARIABLE_NAME VARIABLE_VALUE KEY_BLOCKS_NOT_FLUSHED 0 KEY_BLOCKS_USED 4 KEY_BLOCKS_WARM 0 -KEY_READ_REQUESTS 22 +KEY_READ_REQUESTS 21 KEY_READS 0 KEY_WRITE_REQUESTS 26 KEY_WRITES 6 select variable_value into @key_blocks_unused from information_schema.session_status where variable_name = 'Key_blocks_unused'; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default NULL NULL 2097152 1024 4 # 0 22 0 26 6 +default NULL NULL 2097152 1024 4 # 0 21 0 26 6 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 delete from t2 where a='zzzz'; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default NULL NULL 2097152 1024 4 # 0 29 0 32 9 +default NULL NULL 2097152 1024 4 # 0 28 0 32 9 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 delete from t1; delete from t2; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default NULL NULL 2097152 1024 4 # 0 29 0 32 9 +default NULL NULL 2097152 1024 4 # 0 28 0 32 9 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 set global key_cache_segments=2; select @@key_cache_segments; @@ -488,7 +488,7 @@ VARIABLE_NAME VARIABLE_VALUE KEY_BLOCKS_NOT_FLUSHED 0 KEY_BLOCKS_USED 4 KEY_BLOCKS_WARM 0 -KEY_READ_REQUESTS 22 +KEY_READ_REQUESTS 21 KEY_READS 0 KEY_WRITE_REQUESTS 26 KEY_WRITES 6 @@ -497,13 +497,13 @@ variable_value < @key_blocks_unused 1 select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 2 NULL 2097152 1024 4 # 0 22 0 26 6 +default 2 NULL 2097152 1024 4 # 0 21 0 26 6 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 delete from t1; delete from t2; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 2 NULL 2097152 1024 4 # 0 22 0 26 6 +default 2 NULL 2097152 1024 4 # 0 21 0 26 6 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 set global key_cache_segments=1; select @@key_cache_segments; @@ -533,7 +533,7 @@ VARIABLE_NAME VARIABLE_VALUE KEY_BLOCKS_NOT_FLUSHED 0 KEY_BLOCKS_USED 4 KEY_BLOCKS_WARM 0 -KEY_READ_REQUESTS 22 +KEY_READ_REQUESTS 21 KEY_READS 0 KEY_WRITE_REQUESTS 26 KEY_WRITES 6 @@ -542,13 +542,13 @@ variable_value = @key_blocks_unused 1 select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 1 NULL 2097152 1024 4 # 0 22 0 26 6 +default 1 NULL 2097152 1024 4 # 0 21 0 26 6 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 delete from t1; delete from t2; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 1 NULL 2097152 1024 4 # 0 22 0 26 6 +default 1 NULL 2097152 1024 4 # 0 21 0 26 6 small NULL NULL 1048576 1024 1 # 0 1 0 2 1 flush tables; flush status; @@ -586,7 +586,7 @@ update t1 set p=3 where p=1; update t2 set i=2 where i=1; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 2 NULL 32768 1024 4 # 0 22 0 26 6 +default 2 NULL 32768 1024 4 # 0 21 0 26 6 small NULL NULL 1048576 1024 1 # 0 0 0 0 0 insert into t1(a) select a from t1; insert into t1(a) select a from t1; @@ -606,7 +606,7 @@ insert into t2(i,a) select i,a from t2; insert into t2(i,a) select i,a from t2; select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 2 NULL 32768 1024 # # 0 6733 # 3684 103 +default 2 NULL 32768 1024 # # 0 6732 # 3684 103 small NULL NULL 1048576 1024 # # 0 0 # 0 0 select * from t1 where p between 1010 and 1020 ; p a @@ -625,7 +625,7 @@ p i a 1020 3 zzzz select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -default 2 NULL 32768 1024 # # 0 6750 # 3684 103 +default 2 NULL 32768 1024 # # 0 6749 # 3684 103 small NULL NULL 1048576 1024 # # 0 0 # 0 0 flush tables; flush status; @@ -699,7 +699,7 @@ update t2 set p=p+3000, i=2 where a='qqqq'; select * from information_schema.key_caches where key_cache_name like "key%" and segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -keycache1 7 NULL 262143 2048 25 # 0 2082 25 1071 19 +keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19 set global keycache2.key_buffer_size=1024*1024; cache index t2 in keycache2; Table Op Msg_type Msg_text @@ -712,7 +712,7 @@ keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3 select * from information_schema.key_caches where key_cache_name like "key%" and segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES -keycache1 7 NULL 262143 2048 25 # 0 2082 25 1071 19 +keycache1 7 NULL 262143 2048 25 # 0 2114 25 1071 19 keycache2 NULL NULL 1048576 1024 6 # 0 6 6 3 3 cache index t2 in keycache1; Table Op Msg_type Msg_text @@ -753,7 +753,7 @@ select * from information_schema.key_caches where segment_number is null; KEY_CACHE_NAME SEGMENTS SEGMENT_NUMBER FULL_SIZE BLOCK_SIZE USED_BLOCKS UNUSED_BLOCKS DIRTY_BLOCKS READ_REQUESTS READS WRITE_REQUESTS WRITES default 2 NULL 32768 1024 # # 0 3172 24 1552 18 small NULL NULL 1048576 1024 # # 0 0 0 0 0 -keycache1 7 NULL 262143 2048 # # 0 3229 43 1594 30 +keycache1 7 NULL 262143 2048 # # 0 3277 43 1594 30 keycache2 NULL NULL 1048576 1024 # # 0 6 6 3 3 set global keycache1.key_cache_block_size=2*1024; insert into t2 values (7000, 3, 'yyyy'); diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result index f0a22b8f3f2..e87dd25cac9 100644 --- a/mysql-test/main/limit_rows_examined.result +++ b/mysql-test/main/limit_rows_examined.result @@ -255,7 +255,7 @@ select * from t1i where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 6; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index +1 PRIMARY t1i index PRIMARY PRIMARY 2 NULL 4 Using where; Using index 1 PRIMARY t2i eq_ref PRIMARY PRIMARY 2 test.t1i.c1 1 Using index select * from t1i where c1 IN (select * from t2i where c2 > ' ') @@ -395,7 +395,7 @@ select * from t1i where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1i index NULL PRIMARY 2 NULL 4 Using where; Using index -2 MATERIALIZED t2i range PRIMARY PRIMARY 2 NULL 4 Using where; Using index +2 MATERIALIZED t2i index PRIMARY PRIMARY 2 NULL 4 Using where; Using index select * from t1i where c1 IN (select * from t2i where c2 > ' ') LIMIT ROWS EXAMINED 17; c1 diff --git a/mysql-test/main/long_unique.result b/mysql-test/main/long_unique.result index 4521eaa11d0..99643c17a0a 100644 --- a/mysql-test/main/long_unique.result +++ b/mysql-test/main/long_unique.result @@ -1196,20 +1196,20 @@ ERROR 42S22: Unknown column 'DB_ROW_HASH_1' in 'IN/ALL/ANY subquery' select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2); DB_ROW_HASH_1 DB_ROW_HASH_2 11 1 -22 2 -33 3 -44 4 11 1 -22 2 -33 3 -44 4 11 1 -22 2 -33 3 -44 4 11 1 22 2 +22 2 +22 2 +22 2 +33 3 +33 3 33 3 +33 3 +44 4 +44 4 +44 4 44 4 select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1); DB_ROW_HASH_1 DB_ROW_HASH_2 diff --git a/mysql-test/main/long_unique.test b/mysql-test/main/long_unique.test index c2cf3f635ce..0d91913fd7b 100644 --- a/mysql-test/main/long_unique.test +++ b/mysql-test/main/long_unique.test @@ -389,6 +389,7 @@ select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1; select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2; --error ER_BAD_FIELD_ERROR select * from t1 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2); +--sorted_result select DB_ROW_HASH_1, DB_ROW_HASH_2 from t1,t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t2); select * from t2 where DB_ROW_HASH_1 in (select DB_ROW_HASH_1 from t1); --error ER_BAD_FIELD_ERROR diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result index a6bfe843738..3ec9ea0caa5 100644 --- a/mysql-test/main/multi_update.result +++ b/mysql-test/main/multi_update.result @@ -1092,8 +1092,8 @@ a b c a b c set optimizer_switch='firstmatch=off'; explain update t1, t2 set t2.c=1 where t1.a=t2.a and t1.b in (select b from t3 where t3.c< t2.c) order by t2.c, t1.c limit 10; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using temporary; Using filesort -1 PRIMARY t1 ALL a NULL NULL NULL 10 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 10 Using where; Using temporary; Using filesort +1 PRIMARY t1 ref a a 5 test.t2.a 1 1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where; Start temporary; End temporary update t1, t2 set t2.c=1 where t1.a=t2.a and t1.b in (select b from t3 where t3.c<=t2.c) order by t2.c, t1.c limit 5; select * from t2; diff --git a/mysql-test/main/myisam.result b/mysql-test/main/myisam.result index 5c551a25afa..ff2ea680138 100644 --- a/mysql-test/main/myisam.result +++ b/mysql-test/main/myisam.result @@ -641,10 +641,14 @@ create table t1 ( a tinytext, b char(1), index idx (a(1),b) ); insert into t1 values (null,''), (null,''); explain select count(*) from t1 where a is null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx idx 4 const 2 Using where +1 SIMPLE t1 ALL idx NULL NULL NULL 2 Using where select count(*) from t1 where a is null; count(*) 2 +insert into t1 values (1,''), (2,''); +explain select count(*) from t1 where a is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref idx idx 4 const 2 Using where drop table t1; create table t1 (c1 int, c2 varchar(4) not null default '', key(c2(3))) default charset=utf8; @@ -2533,6 +2537,7 @@ DROP TABLE t1, t2, t3; # # BUG#51307 - widespread corruption with partitions and insert...select # +call mtr.add_suppression("Enabling keys got errno 12 on test.t1, retrying"); CREATE TABLE t1(a CHAR(255), KEY(a)); SELECT * FROM t1, t1 AS a1; a a diff --git a/mysql-test/main/myisam.test b/mysql-test/main/myisam.test index 2ae4da671e6..096be265cb4 100644 --- a/mysql-test/main/myisam.test +++ b/mysql-test/main/myisam.test @@ -595,6 +595,8 @@ create table t1 ( a tinytext, b char(1), index idx (a(1),b) ); insert into t1 values (null,''), (null,''); explain select count(*) from t1 where a is null; select count(*) from t1 where a is null; +insert into t1 values (1,''), (2,''); +explain select count(*) from t1 where a is null; drop table t1; # @@ -1678,6 +1680,9 @@ DROP TABLE t1, t2, t3; --echo # --echo # BUG#51307 - widespread corruption with partitions and insert...select --echo # + +call mtr.add_suppression("Enabling keys got errno 12 on test.t1, retrying"); + CREATE TABLE t1(a CHAR(255), KEY(a)); SELECT * FROM t1, t1 AS a1; SET myisam_sort_buffer_size=4; diff --git a/mysql-test/main/myisam_explain_non_select_all.result b/mysql-test/main/myisam_explain_non_select_all.result index 83e18f3906f..9714685df88 100644 --- a/mysql-test/main/myisam_explain_non_select_all.result +++ b/mysql-test/main/myisam_explain_non_select_all.result @@ -256,9 +256,8 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t1 WHERE 1 IN (SELECT 1 FROM t2 WHERE t2.b < 3); 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 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; FirstMatch +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using join buffer (flat, BNL join) Warnings: Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b` < 3 # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution @@ -268,8 +267,8 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_key 5 -Handler_read_rnd_next 8 +Handler_read_key 4 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_read_key 4 @@ -791,12 +790,12 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 Using where +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 Using where; Using filesort FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t1 WHERE t1.a > 0 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 6 100.00 Using where; Using filesort # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 3 @@ -819,8 +818,11 @@ Handler_read_next 3 # Status of testing query execution: Variable_name Value Handler_delete 3 -Handler_read_key 4 -Handler_read_next 3 +Handler_read_key 3 +Handler_read_rnd 3 +Handler_read_rnd_next 7 +Sort_rows 3 +Sort_scan 1 DROP TABLE t1; #17 @@ -1494,12 +1496,12 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +1 SIMPLE t2 index NULL a 15 NULL 5 Using where FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED DELETE FROM t2 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -1523,11 +1525,9 @@ Handler_read_next 26 # Status of testing query execution: Variable_name Value Handler_delete 1 +Handler_read_first 1 Handler_read_key 8 -Handler_read_rnd 1 -Handler_read_rnd_next 27 -Sort_rows 1 -Sort_scan 1 +Handler_read_next 26 DROP TABLE t1, t2; #32 @@ -2009,12 +2009,12 @@ Warnings: Warning 1287 '<select expression> INTO <destination>;' is deprecated and will be removed in a future release. Please use 'SELECT <select list> INTO <destination> FROM...' instead EXPLAIN UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 26 Using where; Using filesort +1 SIMPLE t2 index NULL a 15 NULL 5 Using where; Using buffer FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 26 100.00 Using where; Using filesort +1 SIMPLE t2 index NULL a 15 NULL 5 100.00 Using where; Using buffer # Status of EXPLAIN EXTENDED query Variable_name Value Handler_read_key 8 @@ -2037,13 +2037,11 @@ Handler_read_key 8 Handler_read_next 26 # Status of testing query execution: Variable_name Value +Handler_read_first 1 Handler_read_key 8 +Handler_read_next 26 Handler_read_rnd 1 -Handler_read_rnd_next 27 Handler_update 1 -Sort_priority_queue_sorts 1 -Sort_rows 1 -Sort_scan 1 DROP TABLE t1, t2; #42 diff --git a/mysql-test/main/myisam_icp.result b/mysql-test/main/myisam_icp.result index d0614913480..803b16ecd79 100644 --- a/mysql-test/main/myisam_icp.result +++ b/mysql-test/main/myisam_icp.result @@ -407,7 +407,7 @@ WHERE (pk BETWEEN 4 AND 5 OR pk < 2) AND c1 < 240 ORDER BY c1 LIMIT 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range|filter PRIMARY,k1 PRIMARY|k1 4|5 NULL 3 (50%) Using index condition; Using where; Rowid-ordered scan; Using filesort; Using rowid filter +1 SIMPLE t1 range PRIMARY,k1 PRIMARY 4 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using filesort DROP TABLE t1; # # @@ -429,8 +429,8 @@ SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL # Using where +2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index 2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func # Using index condition -2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL # Using index; Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); pk i @@ -506,7 +506,7 @@ WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Rowid-ordered scan -1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); @@ -922,7 +922,7 @@ DROP TABLE t1; # Bug#870046: ICP for a GROUP BY query # CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b)); -INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y'); +INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y'), (6,'a','b'), (7,'a','b'); SET SESSION optimizer_switch='index_condition_pushdown=off'; EXPLAIN SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a; diff --git a/mysql-test/main/myisam_icp.test b/mysql-test/main/myisam_icp.test index a115d0f7caa..7b4ff23b50e 100644 --- a/mysql-test/main/myisam_icp.test +++ b/mysql-test/main/myisam_icp.test @@ -215,7 +215,7 @@ DROP TABLE t1; --echo # CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b)); -INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y'); +INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y'), (6,'a','b'), (7,'a','b'); SET SESSION optimizer_switch='index_condition_pushdown=off'; EXPLAIN diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result index a8aa461c863..704a40a8c24 100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@ -693,6 +693,11 @@ The following specify which files/extra groups are read (specified before remain max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors (Automatically configured unless set explicitly) + --optimizer-cache-hit-ratio=# + Expected hit rate of the row and index cache in storage + engines. The value should be an integer between 0 and 99, + where 0 means cache is empty and 99 means that value is + almost always in the cache --optimizer-max-sel-arg-weight=# The maximum weight of the SEL_ARG graph. Set to 0 for no limit @@ -1654,6 +1659,7 @@ old-alter-table DEFAULT old-mode UTF8_IS_UTF8MB3 old-passwords FALSE old-style-user-limits FALSE +optimizer-cache-hit-ratio 50 optimizer-max-sel-arg-weight 32000 optimizer-prune-level 1 optimizer-search-depth 62 diff --git a/mysql-test/main/negation_elimination.result b/mysql-test/main/negation_elimination.result index 7b9a76d86b2..0ad23e547b0 100644 --- a/mysql-test/main/negation_elimination.result +++ b/mysql-test/main/negation_elimination.result @@ -4,7 +4,7 @@ insert into t1 values (NULL), (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19); explain select * from t1 where not(not(a)); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 20 Using where; Using index +1 SIMPLE t1 index a a 5 NULL 21 Using where; Using index select * from t1 where not(not(a)); a 1 @@ -55,7 +55,7 @@ a 10 explain select * from t1 where not(a = 10); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 19 Using where; Using index +1 SIMPLE t1 index a a 5 NULL 21 Using where; Using index select * from t1 where not(a = 10); a 0 @@ -500,7 +500,7 @@ NULL NULL 3 1 explain extended select a, not(not(a)), not(a <= 2 and not(a)), not(a not like "1"), not (a not in (1,2)), not(a != 2) from t1 where not(not(a)) having not(not(a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range a a 5 NULL 4 100.00 Using where; Using index +1 SIMPLE t1 index a a 5 NULL 5 80.00 Using where; Using index Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`a` <> 0 AS `not(not(a))`,`test`.`t1`.`a` > 2 or `test`.`t1`.`a` <> 0 AS `not(a <= 2 and not(a))`,`test`.`t1`.`a` like '1' AS `not(a not like "1")`,`test`.`t1`.`a` in (1,2) AS `not (a not in (1,2))`,`test`.`t1`.`a` = 2 AS `not(a != 2)` from `test`.`t1` where `test`.`t1`.`a` <> 0 having `test`.`t1`.`a` <> 0 drop table t1; diff --git a/mysql-test/main/null_key.result b/mysql-test/main/null_key.result index d59a1cd0a2e..572d7302b74 100644 --- a/mysql-test/main/null_key.result +++ b/mysql-test/main/null_key.result @@ -160,12 +160,12 @@ a b 7 NULL explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a,b a 10 NULL 4 Using where; Using index +1 SIMPLE t1 ref_or_null a,b a 5 const 5 Using where; Using index select * from t1 where (a = 7 or a is null) and (b=7 or b is null); a b -NULL 7 7 NULL 7 7 +NULL 7 explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref_or_null a a 5 const 5 Using where; Using index @@ -258,10 +258,11 @@ PRIMARY KEY (id) ) ENGINE=MyISAM; INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); INSERT INTO t1 VALUES (11,5),(12,6),(13,7),(14,8),(15,9); +INSERT INTO t1 VALUES (1000,1000),(1010,1010); INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); explain select id from t1 where uniq_id is null; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL idx1 NULL NULL NULL 15 Using where +1 SIMPLE t1 ref idx1 idx1 5 const 6 Using index condition explain select id from t1 where uniq_id =1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const idx1 idx1 5 const 1 @@ -285,6 +286,7 @@ id 110 DELETE FROM t1 WHERE uniq_id IS NULL; DELETE FROM t2 WHERE uniq_id IS NULL; +DELETE FROM t1 WHERE id >= 1000; SELECT * FROM t1 ORDER BY uniq_id, id; id uniq_id 3 1 diff --git a/mysql-test/main/null_key.test b/mysql-test/main/null_key.test index a5781cc8524..90ed142d5c7 100644 --- a/mysql-test/main/null_key.test +++ b/mysql-test/main/null_key.test @@ -104,6 +104,7 @@ CREATE TABLE t2 ( INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); INSERT INTO t1 VALUES (11,5),(12,6),(13,7),(14,8),(15,9); +INSERT INTO t1 VALUES (1000,1000),(1010,1010); INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL); # # Check IS NULL optimization @@ -122,6 +123,12 @@ select id from t2 where uniq_id is null; # DELETE FROM t1 WHERE uniq_id IS NULL; DELETE FROM t2 WHERE uniq_id IS NULL; + +# +# Delete extra records that were used to force null optimization +# +DELETE FROM t1 WHERE id >= 1000; + # # Select what is left -- notice the difference # diff --git a/mysql-test/main/opt_trace.result b/mysql-test/main/opt_trace.result index 64a5b18f415..7241f4362ba 100644 --- a/mysql-test/main/opt_trace.result +++ b/mysql-test/main/opt_trace.result @@ -118,7 +118,8 @@ select * from v1 { "table": "t1", "table_scan": { "rows": 2, - "cost": 2.004394531 + "read_cost": 1.102197266, + "read_and_compare_cost": 1.602197266 } } ] @@ -129,23 +130,29 @@ select * from v1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 1, - "cost": 2.404394531, + "rows": 2, + "rows_after_scan": 1, + "rows_after_filter": 1, + "cost": 1.602197266, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 1, - "cost": 2.404394531, + "cost": 1.602197266, "uses_join_buffering": false } }, "rows_for_plan": 1, - "cost_for_plan": 2.604394531, + "cost_for_plan": 1.602197266, "estimated_join_cardinality": 1 } ] @@ -153,7 +160,8 @@ select * from v1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 2.603394531 + "rows": 1, + "cost": 1.602197266 } }, { @@ -272,7 +280,8 @@ select * from (select * from t1 where t1.a=1)q { "table": "t1", "table_scan": { "rows": 2, - "cost": 2.004394531 + "read_cost": 1.102197266, + "read_and_compare_cost": 1.602197266 } } ] @@ -283,23 +292,29 @@ select * from (select * from t1 where t1.a=1)q { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 1, - "cost": 2.404394531, + "rows": 2, + "rows_after_scan": 1, + "rows_after_filter": 1, + "cost": 1.602197266, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 1, - "cost": 2.404394531, + "cost": 1.602197266, "uses_join_buffering": false } }, "rows_for_plan": 1, - "cost_for_plan": 2.604394531, + "cost_for_plan": 1.602197266, "estimated_join_cardinality": 1 } ] @@ -307,7 +322,8 @@ select * from (select * from t1 where t1.a=1)q { { "best_join_order": ["t1"], "best_access_method": { - "cost": 2.603394531 + "rows": 1, + "cost": 1.602197266 } }, { @@ -431,7 +447,8 @@ select * from v2 { "table": "t1", "table_scan": { "rows": 2, - "cost": 2.004394531 + "read_cost": 1.102197266, + "read_and_compare_cost": 1.602197266 } } ] @@ -442,11 +459,17 @@ select * from v2 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 1, - "cost": 2.404394531, + "rows": 2, + "rows_after_scan": 1, + "rows_after_filter": 1, + "cost": 1.602197266, + "index_only": false, "chosen": true, "use_tmp_table": true } @@ -454,12 +477,12 @@ select * from v2 { "chosen_access_method": { "type": "scan", "records": 1, - "cost": 2.404394531, + "cost": 1.602197266, "uses_join_buffering": false } }, "rows_for_plan": 1, - "cost_for_plan": 2.604394531, + "cost_for_plan": 1.602197266, "cost_for_sorting": 1, "estimated_join_cardinality": 1 } @@ -468,7 +491,8 @@ select * from v2 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 3.603394531 + "rows": 1, + "cost": 2.602197266 } }, { @@ -507,7 +531,8 @@ select * from v2 { "table": "<derived2>", "table_scan": { "rows": 2, - "cost": 2 + "read_cost": 2, + "read_and_compare_cost": 2.5 } } ] @@ -518,23 +543,29 @@ select * from v2 { "plan_prefix": [], "table": "<derived2>", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 2, - "cost": 2.4, + "rows": 2, + "rows_after_scan": 2, + "rows_after_filter": 2, + "cost": 2.5, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 2, - "cost": 2.4, + "cost": 2.5, "uses_join_buffering": false } }, "rows_for_plan": 2, - "cost_for_plan": 2.8, + "cost_for_plan": 2.5, "estimated_join_cardinality": 2 } ] @@ -542,7 +573,8 @@ select * from v2 { { "best_join_order": ["<derived2>"], "best_access_method": { - "cost": 2.799 + "rows": 2, + "cost": 2.5 } }, { @@ -648,7 +680,8 @@ explain select * from v2 { "table": "t2", "table_scan": { "rows": 10, - "cost": 2.021972656 + "read_cost": 1.510986328, + "read_and_compare_cost": 4.010986328 } } ] @@ -659,23 +692,29 @@ explain select * from v2 { "plan_prefix": [], "table": "t2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 4.021972656, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 4.010986328, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 10, - "cost": 4.021972656, + "cost": 4.010986328, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 6.021972656, + "cost_for_plan": 4.010986328, "estimated_join_cardinality": 10 } ] @@ -683,7 +722,8 @@ explain select * from v2 { { "best_join_order": ["t2"], "best_access_method": { - "cost": 6.020972656 + "rows": 10, + "cost": 4.010986328 } }, { @@ -768,7 +808,8 @@ explain select * from v1 { "table": "t1", "table_scan": { "rows": 10, - "cost": 2.021972656 + "read_cost": 1.510986328, + "read_and_compare_cost": 4.010986328 } } ] @@ -779,11 +820,17 @@ explain select * from v1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 4.021972656, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 4.010986328, + "index_only": false, "chosen": true, "use_tmp_table": true } @@ -791,12 +838,12 @@ explain select * from v1 { "chosen_access_method": { "type": "scan", "records": 10, - "cost": 4.021972656, + "cost": 4.010986328, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 6.021972656, + "cost_for_plan": 4.010986328, "cost_for_sorting": 10, "estimated_join_cardinality": 10 } @@ -805,7 +852,8 @@ explain select * from v1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 16.02097266 + "rows": 10, + "cost": 14.01098633 } }, { @@ -838,7 +886,8 @@ explain select * from v1 { "table": "<derived2>", "table_scan": { "rows": 10, - "cost": 10 + "read_cost": 10, + "read_and_compare_cost": 12.5 } } ] @@ -849,23 +898,29 @@ explain select * from v1 { "plan_prefix": [], "table": "<derived2>", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 12, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 12.5, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 10, - "cost": 12, + "cost": 12.5, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 14, + "cost_for_plan": 12.5, "estimated_join_cardinality": 10 } ] @@ -873,7 +928,8 @@ explain select * from v1 { { "best_join_order": ["<derived2>"], "best_access_method": { - "cost": 13.999 + "rows": 10, + "cost": 12.5 } }, { @@ -1004,14 +1060,16 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "table": "t1", "table_scan": { "rows": 100, - "cost": 2.317382812 + "read_cost": 6.158691406, + "read_and_compare_cost": 31.15869141 } }, { "table": "t2", "table_scan": { "rows": 100, - "cost": 2.317382812 + "read_cost": 6.158691406, + "read_and_compare_cost": 31.15869141 } } ] @@ -1022,28 +1080,37 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 100, - "cost": 22.31738281, + "rows": 100, + "rows_after_scan": 100, + "rows_after_filter": 100, + "cost": 31.15869141, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 100, - "cost": 22.31738281, + "cost": 31.15869141, "uses_join_buffering": false } }, "rows_for_plan": 100, - "cost_for_plan": 42.31738281, + "cost_for_plan": 31.15869141, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t2", "best_access_path": { + "plan_details": { + "record_count": 100 + }, "considered_access_paths": [ { "access_type": "ref", @@ -1051,28 +1118,28 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "used_range_estimates": false, "cause": "not available", "rows": 1, - "found_matching_rows_cost": 2.200585794, - "startup_cost": 0, - "rows": 1, - "cost": 220.0585794, + "cost": 125.0585794, "chosen": true }, { - "access_type": "scan", - "resulting_rows": 75, - "cost": 1522.317383, + "access_type": "scan_with_join_cache", + "rows": 100, + "rows_after_scan": 75, + "rows_after_filter": 75, + "cost": 1906.158691, + "index_only": false, "chosen": false } ], "chosen_access_method": { "type": "ref", "records": 1, - "cost": 220.0585794, + "cost": 125.0585794, "uses_join_buffering": false } }, "rows_for_plan": 100, - "cost_for_plan": 282.3759623, + "cost_for_plan": 156.2172709, "estimated_join_cardinality": 100 } ] @@ -1081,28 +1148,37 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "plan_prefix": [], "table": "t2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 100, - "cost": 22.31738281, + "rows": 100, + "rows_after_scan": 100, + "rows_after_filter": 100, + "cost": 31.15869141, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 100, - "cost": 22.31738281, + "cost": 31.15869141, "uses_join_buffering": false } }, "rows_for_plan": 100, - "cost_for_plan": 42.31738281, + "cost_for_plan": 31.15869141, "rest_of_plan": [ { "plan_prefix": ["t2"], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 100 + }, "considered_access_paths": [ { "access_type": "ref", @@ -1110,28 +1186,28 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { "used_range_estimates": false, "cause": "not available", "rows": 1, - "found_matching_rows_cost": 2.200585794, - "startup_cost": 0, - "rows": 1, - "cost": 220.0585794, + "cost": 125.0585794, "chosen": true }, { - "access_type": "scan", - "resulting_rows": 75, - "cost": 1522.317383, + "access_type": "scan_with_join_cache", + "rows": 100, + "rows_after_scan": 75, + "rows_after_filter": 75, + "cost": 1906.158691, + "index_only": false, "chosen": false } ], "chosen_access_method": { "type": "ref", "records": 1, - "cost": 220.0585794, + "cost": 125.0585794, "uses_join_buffering": false } }, "rows_for_plan": 100, - "cost_for_plan": 282.3759623, + "cost_for_plan": 156.2172709, "pruned_by_cost": true } ] @@ -1141,7 +1217,8 @@ explain select * from t1,t2 where t1.a=t2.b+2 and t2.a= t1.b { { "best_join_order": ["t1", "t2"], "best_access_method": { - "cost": 282.3749623 + "rows": 100, + "cost": 156.2172709 } }, { @@ -1223,7 +1300,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 { "range_analysis": { "table_scan": { "rows": 65536, - "cost": 13255.2 + "cost": 16457 }, "potential_range_indexes": [ { @@ -1239,9 +1316,8 @@ EXPLAIN SELECT DISTINCT a FROM t1 { ], "best_covering_index_scan": { "index": "a", - "cost": 13377.39141, - "chosen": false, - "cause": "cost" + "cost": 14898.29141, + "chosen": true }, "group_index_range": { "distinct_query": true, @@ -1294,10 +1370,15 @@ EXPLAIN SELECT DISTINCT a FROM t1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "index_merge", - "resulting_rows": 5, + "rows": 5, + "rows_after_scan": 5, + "rows_after_filter": 5, "cost": 6.5, "chosen": true } @@ -1310,7 +1391,7 @@ EXPLAIN SELECT DISTINCT a FROM t1 { } }, "rows_for_plan": 5, - "cost_for_plan": 7.5, + "cost_for_plan": 6.5, "estimated_join_cardinality": 5 } ] @@ -1318,7 +1399,8 @@ EXPLAIN SELECT DISTINCT a FROM t1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 7.499 + "rows": 5, + "cost": 6.5 } }, { @@ -1414,7 +1496,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "range_analysis": { "table_scan": { "rows": 7, - "cost": 5.429052734 + "cost": 2.764526367 }, "potential_range_indexes": [ { @@ -1425,7 +1507,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { ], "best_covering_index_scan": { "index": "a", - "cost": 2.409226263, + "cost": 2.084226263, "chosen": true }, "setup_range_conditions": [], @@ -1487,11 +1569,17 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 1, - "cost": 3.429052734, + "rows": 7, + "rows_after_scan": 1, + "rows_after_filter": 1, + "cost": 2.084226263, + "index_only": true, "chosen": true, "use_tmp_table": true } @@ -1499,12 +1587,12 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "chosen_access_method": { "type": "scan", "records": 1, - "cost": 3.429052734, + "cost": 2.084226263, "uses_join_buffering": false } }, "rows_for_plan": 1, - "cost_for_plan": 3.629052734, + "cost_for_plan": 2.084226263, "cost_for_sorting": 1, "estimated_join_cardinality": 1 } @@ -1513,7 +1601,8 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { { "best_join_order": ["t1"], "best_access_method": { - "cost": 4.628052734 + "rows": 1, + "cost": 3.084226263 } }, { @@ -1537,7 +1626,7 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "reconsidering_access_paths_for_index_ordering": { "clause": "GROUP BY", "fanout": 1, - "read_time": 3.430052734, + "read_time": 2.084226263, "table": "t1", "rows_estimation": 7, "possible_keys": [ @@ -1545,8 +1634,8 @@ EXPLAIN SELECT MIN(d) FROM t1 where b=2 and c=3 group by a { "index": "a", "can_resolve_order": true, "updated_limit": 7, - "index_scan_time": 7, - "records": 7, + "index_scan_cost": 2.084226263, + "rows": 7, "chosen": true } ] @@ -1635,7 +1724,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { "range_analysis": { "table_scan": { "rows": 16, - "cost": 7.23125 + "cost": 5.015625 }, "potential_range_indexes": [ { @@ -1646,7 +1735,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { ], "best_covering_index_scan": { "index": "id", - "cost": 4.21171589, + "cost": 4.11171589, "chosen": true }, "setup_range_conditions": [], @@ -1708,10 +1797,15 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "index_merge", - "resulting_rows": 9, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, "cost": 3.25, "chosen": true, "use_tmp_table": true @@ -1725,7 +1819,7 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { } }, "rows_for_plan": 9, - "cost_for_plan": 5.05, + "cost_for_plan": 3.25, "cost_for_sorting": 9, "estimated_join_cardinality": 9 } @@ -1734,7 +1828,8 @@ EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104e0 GROUP BY id { { "best_join_order": ["t1"], "best_access_method": { - "cost": 14.049 + "rows": 9, + "cost": 12.25 } }, { @@ -1826,7 +1921,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { "range_analysis": { "table_scan": { "rows": 16, - "cost": 7.23125 + "cost": 5.015625 }, "potential_range_indexes": [ { @@ -1837,7 +1932,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { ], "best_covering_index_scan": { "index": "id", - "cost": 4.21171589, + "cost": 4.11171589, "chosen": true }, "setup_range_conditions": [], @@ -1899,10 +1994,15 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "index_merge", - "resulting_rows": 9, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, "cost": 3.25, "chosen": true, "use_tmp_table": true @@ -1916,7 +2016,7 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { } }, "rows_for_plan": 9, - "cost_for_plan": 5.05, + "cost_for_plan": 3.25, "cost_for_sorting": 9, "estimated_join_cardinality": 9 } @@ -1925,7 +2025,8 @@ EXPLAIN SELECT * FROM t1 WHERE a = 20010104e0 GROUP BY id { { "best_join_order": ["t1"], "best_access_method": { - "cost": 14.049 + "rows": 9, + "cost": 12.25 } }, { @@ -2063,7 +2164,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "range_analysis": { "table_scan": { "rows": 1000, - "cost": 232.5644531 + "cost": 265.2822266 }, "potential_range_indexes": [ { @@ -2092,7 +2193,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "using_mrr": false, "index_only": false, "rows": 180, - "cost": 216.2943776, + "cost": 135.6693776, "chosen": true }, { @@ -2102,7 +2203,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "using_mrr": false, "index_only": false, "rows": 21, - "cost": 25.36242739, + "cost": 16.28742739, "chosen": true } ], @@ -2123,7 +2224,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "ranges": ["(1,2) <= (a,b) <= (1,2)"] }, "rows_for_plan": 21, - "cost_for_plan": 25.36242739, + "cost_for_plan": 16.28742739, "chosen": true } } @@ -2133,12 +2234,12 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "rowid_filters": [ { "key": "a_b", - "build_cost": 0.886777098, + "build_cost": 1.127362357, "rows": 21 }, { "key": "a_c", - "build_cost": 10.52169992, + "build_cost": 6.264109827, "rows": 180 } ] @@ -2172,16 +2273,16 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "ref", "index": "a_c", "used_range_estimates": true, "rows": 180, - "found_matching_rows_cost": 216.2743776, - "startup_cost": 0, - "rows": 180, - "cost": 216.2743776, + "cost": 135.6493776, "chosen": true }, { @@ -2189,10 +2290,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "index": "a_b", "used_range_estimates": true, "rows": 21, - "found_matching_rows_cost": 25.34242739, - "startup_cost": 0, - "rows": 21, - "cost": 25.34242739, + "cost": 16.26742739, "chosen": true }, { @@ -2204,12 +2302,12 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "chosen_access_method": { "type": "ref", "records": 21, - "cost": 25.34242739, + "cost": 16.26742739, "uses_join_buffering": false } }, "rows_for_plan": 21, - "cost_for_plan": 29.54242739, + "cost_for_plan": 16.26742739, "estimated_join_cardinality": 21 } ] @@ -2217,7 +2315,8 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 29.54142739 + "rows": 21, + "cost": 16.26742739 } }, { @@ -2241,7 +2340,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "reconsidering_access_paths_for_index_ordering": { "clause": "ORDER BY", "fanout": 1, - "read_time": 25.34342739, + "read_time": 16.26742739, "table": "t1", "rows_estimation": 21, "possible_keys": [ @@ -2249,7 +2348,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "index": "a_a", "can_resolve_order": true, "updated_limit": 47, - "index_scan_time": 47, + "index_scan_cost": 35.77753234, "usable": false, "cause": "cost" }, @@ -2257,9 +2356,9 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "index": "a_c", "can_resolve_order": true, "updated_limit": 47, - "range_scan_time": 4.331020747, - "index_scan_time": 4.331020747, - "records": 180, + "index_scan_cost": 35.78900415, + "range_scan_cost": 6.375520747, + "rows": 180, "chosen": true }, { @@ -2304,7 +2403,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "using_mrr": false, "index_only": false, "rows": 180, - "cost": 216.2943776, + "cost": 135.6693776, "chosen": true } ], @@ -2325,7 +2424,7 @@ explain select * from t1 where a=1 and b=2 order by c limit 1 { "ranges": ["(1) <= (a) <= (1)"] }, "rows_for_plan": 180, - "cost_for_plan": 216.2943776, + "cost_for_plan": 135.6693776, "chosen": true } } @@ -2431,7 +2530,8 @@ select t1.a from t1 left join t2 on t1.a=t2.a { "table": "t1", "table_scan": { "rows": 4, - "cost": 2.006835938 + "read_cost": 1.203417969, + "read_and_compare_cost": 2.203417969 } }, { @@ -2448,23 +2548,29 @@ select t1.a from t1 left join t2 on t1.a=t2.a { "plan_prefix": ["t2"], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 4, - "cost": 2.806835937, + "rows": 4, + "rows_after_scan": 4, + "rows_after_filter": 4, + "cost": 2.203417969, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 4, - "cost": 2.806835937, + "cost": 2.203417969, "uses_join_buffering": false } }, "rows_for_plan": 4, - "cost_for_plan": 3.606835937, + "cost_for_plan": 2.203417969, "estimated_join_cardinality": 4 } ] @@ -2472,7 +2578,8 @@ select t1.a from t1 left join t2 on t1.a=t2.a { { "best_join_order": ["t2", "t1"], "best_access_method": { - "cost": 3.605835937 + "rows": 4, + "cost": 2.203417969 } }, { @@ -2571,14 +2678,16 @@ explain select * from t1 left join t2 on t2.a=t1.a { "table": "t1", "table_scan": { "rows": 4, - "cost": 2.006835938 + "read_cost": 1.203417969, + "read_and_compare_cost": 2.203417969 } }, { "table": "t2", "table_scan": { "rows": 2, - "cost": 2.004394531 + "read_cost": 1.102197266, + "read_and_compare_cost": 1.602197266 } } ] @@ -2589,55 +2698,64 @@ explain select * from t1 left join t2 on t2.a=t1.a { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 4, - "cost": 2.806835937, + "rows": 4, + "rows_after_scan": 4, + "rows_after_filter": 4, + "cost": 2.203417969, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 4, - "cost": 2.806835937, + "cost": 2.203417969, "uses_join_buffering": false } }, "rows_for_plan": 4, - "cost_for_plan": 3.606835937, + "cost_for_plan": 2.203417969, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t2", "best_access_path": { + "plan_details": { + "record_count": 4 + }, "considered_access_paths": [ { "access_type": "eq_ref", "index": "PRIMARY", "rows": 1, - "found_matching_rows_cost": 1.2, - "startup_cost": 0, - "rows": 1, - "cost": 4.8, + "cost": 5.002147913, "chosen": true }, { "access_type": "scan", - "resulting_rows": 1.5, - "cost": 10.81757812, + "rows": 2, + "rows_after_scan": 1.5, + "rows_after_filter": 1.5, + "cost": 6.408789063, + "index_only": false, "chosen": false } ], "chosen_access_method": { "type": "eq_ref", "records": 1, - "cost": 4.8, + "cost": 5.002147913, "uses_join_buffering": false } }, "rows_for_plan": 4, - "cost_for_plan": 9.206835937, + "cost_for_plan": 7.205565882, "estimated_join_cardinality": 4 } ] @@ -2647,7 +2765,8 @@ explain select * from t1 left join t2 on t2.a=t1.a { { "best_join_order": ["t1", "t2"], "best_access_method": { - "cost": 9.205835937 + "rows": 4, + "cost": 7.205565882 } }, { @@ -2780,7 +2899,8 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and "table": "t1", "table_scan": { "rows": 4, - "cost": 2.006835938 + "read_cost": 1.203417969, + "read_and_compare_cost": 2.203417969 } }, { @@ -2803,23 +2923,29 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and "plan_prefix": ["t3", "t2"], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 4, - "cost": 2.806835937, + "rows": 4, + "rows_after_scan": 4, + "rows_after_filter": 4, + "cost": 2.203417969, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 4, - "cost": 2.806835937, + "cost": 2.203417969, "uses_join_buffering": false } }, "rows_for_plan": 4, - "cost_for_plan": 3.606835937, + "cost_for_plan": 2.203417969, "estimated_join_cardinality": 4 } ] @@ -2827,7 +2953,8 @@ explain select t1.a from t1 left join (t2 join t3 on t2.b=t3.b) on t2.a=t1.a and { "best_join_order": ["t3", "t2", "t1"], "best_access_method": { - "cost": 3.605835937 + "rows": 4, + "cost": 2.203417969 } }, { @@ -2987,14 +3114,16 @@ explain extended select * from t1 where a in (select pk from t10) { "table": "t1", "table_scan": { "rows": 3, - "cost": 2.006591797 + "read_cost": 1.153295898, + "read_and_compare_cost": 1.903295898 } }, { "table": "t10", "table_scan": { "rows": 10, - "cost": 2.021972656 + "read_cost": 1.510986328, + "read_and_compare_cost": 4.010986328 } } ] @@ -3013,23 +3142,29 @@ explain extended select * from t1 where a in (select pk from t10) { "plan_prefix": [], "table": "t10", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 4.021972656, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 4.010986328, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 10, - "cost": 4.021972656, + "cost": 4.010986328, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 6.021972656, + "cost_for_plan": 4.010986328, "estimated_join_cardinality": 10 } ] @@ -3043,61 +3178,76 @@ explain extended select * from t1 where a in (select pk from t10) { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.606591797, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.903295898, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.606591797, + "cost": 1.903295898, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.206591797, + "cost_for_plan": 1.903295898, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t10", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 10, - "cost": 10.02197266, + "access_type": "scan_with_join_cache", + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 11.51098633, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 10, - "cost": 10.02197266, + "cost": 11.51098633, "uses_join_buffering": true } }, "rows_for_plan": 30, - "cost_for_plan": 19.22856445, + "cost_for_plan": 13.41428223, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "records": 3, - "read_time": 19.22856445 + "cost": 13.41428223 }, { "strategy": "SJ-Materialization", "records": 3, - "cost": 7.878564453 + "cost": 7.564282227 }, { "strategy": "DuplicateWeedout", "records": 3, - "read_time": 35.72856445 + "dups_cost": 13.41428223, + "write_cost": 2.5, + "full_lookup_cost": 15, + "total_cost": 30.91428223 }, { "chosen_strategy": "SJ-Materialization" @@ -3111,23 +3261,29 @@ explain extended select * from t1 where a in (select pk from t10) { "plan_prefix": [], "table": "t10", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 4.021972656, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 4.010986328, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 10, - "cost": 4.021972656, + "cost": 4.010986328, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 6.021972656, + "cost_for_plan": 4.010986328, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -3148,7 +3304,8 @@ explain extended select * from t1 where a in (select pk from t10) { { "best_join_order": ["t1", "<subquery2>"], "best_access_method": { - "cost": 7.877564453 + "rows": 3, + "cost": 7.564282227 } }, { @@ -3311,7 +3468,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "range_analysis": { "table_scan": { "rows": 10, - "cost": 6.031738281 + "cost": 3.515869141 }, "potential_range_indexes": [ { @@ -3332,7 +3489,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { ], "best_covering_index_scan": { "index": "pk_a_b", - "cost": 3.010739566, + "cost": 2.760739566, "chosen": true }, "setup_range_conditions": [], @@ -3345,7 +3502,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345585794, + "cost": 1.270585794, "chosen": true }, { @@ -3355,7 +3512,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345829876, + "cost": 1.270829876, "chosen": false, "cause": "cost" }, @@ -3366,7 +3523,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "using_mrr": false, "index_only": true, "rows": 1, - "cost": 0.346073957, + "cost": 0.746073957, "chosen": true } ], @@ -3374,10 +3531,10 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "intersecting_indexes": [ { "index": "pk", - "index_scan_cost": 1.000585794, - "cumulated_index_scan_cost": 1.000585794, - "disk_sweep_cost": 0.90078125, - "cumulative_total_cost": 1.901367044, + "index_scan_cost": 0.525585794, + "cumulated_index_scan_cost": 0.525585794, + "disk_sweep_cost": 0.75, + "cumulative_total_cost": 1.275585794, "usable": true, "matching_rows_now": 1, "intersect_covering_with_this_index": false, @@ -3415,7 +3572,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "ranges": ["(2,5,1) <= (pk,a,b) <= (2,5,1)"] }, "rows_for_plan": 1, - "cost_for_plan": 0.346073957, + "cost_for_plan": 0.746073957, "chosen": true } } @@ -3425,17 +3582,17 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "rowid_filters": [ { "key": "pk", - "build_cost": 0.130585794, + "build_cost": 0.526585794, "rows": 1 }, { "key": "pk_a", - "build_cost": 0.130829876, + "build_cost": 0.526829876, "rows": 1 }, { "key": "pk_a_b", - "build_cost": 0.131073957, + "build_cost": 0.527073957, "rows": 1 } ] @@ -3469,16 +3626,16 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "ref", "index": "pk", "used_range_estimates": true, "rows": 1, - "found_matching_rows_cost": 1.325585794, - "startup_cost": 0, - "rows": 1, - "cost": 1.325585794, + "cost": 1.250585794, "chosen": true }, { @@ -3486,10 +3643,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "index": "pk_a", "used_range_estimates": true, "rows": 1, - "found_matching_rows_cost": 1.325829876, - "startup_cost": 0, - "rows": 1, - "cost": 1.325829876, + "cost": 1.250829876, "chosen": false, "cause": "cost" }, @@ -3498,10 +3652,7 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "index": "pk_a_b", "used_range_estimates": true, "rows": 1, - "found_matching_rows_cost": 0.326073957, - "startup_cost": 0, - "rows": 1, - "cost": 0.326073957, + "cost": 0.726073957, "chosen": true }, { @@ -3513,12 +3664,12 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { "chosen_access_method": { "type": "ref", "records": 1, - "cost": 0.326073957, + "cost": 0.726073957, "uses_join_buffering": false } }, "rows_for_plan": 1, - "cost_for_plan": 0.526073957, + "cost_for_plan": 0.726073957, "estimated_join_cardinality": 1 } ] @@ -3526,7 +3677,8 @@ explain select * from t1 where pk = 2 and a=5 and b=1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 0.525073957 + "rows": 1, + "cost": 0.726073957 } }, { @@ -3623,7 +3775,8 @@ select f1(a) from t1 { "table": "t1", "table_scan": { "rows": 4, - "cost": 2.006835938 + "read_cost": 1.203417969, + "read_and_compare_cost": 2.203417969 } } ] @@ -3634,23 +3787,29 @@ select f1(a) from t1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 4, - "cost": 2.806835937, + "rows": 4, + "rows_after_scan": 4, + "rows_after_filter": 4, + "cost": 2.203417969, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 4, - "cost": 2.806835937, + "cost": 2.203417969, "uses_join_buffering": false } }, "rows_for_plan": 4, - "cost_for_plan": 3.606835937, + "cost_for_plan": 2.203417969, "estimated_join_cardinality": 4 } ] @@ -3658,7 +3817,8 @@ select f1(a) from t1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 3.605835937 + "rows": 4, + "cost": 2.203417969 } }, { @@ -3723,7 +3883,8 @@ select f2(a) from t1 { "table": "t1", "table_scan": { "rows": 4, - "cost": 2.006835938 + "read_cost": 1.203417969, + "read_and_compare_cost": 2.203417969 } } ] @@ -3734,23 +3895,29 @@ select f2(a) from t1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 4, - "cost": 2.806835937, + "rows": 4, + "rows_after_scan": 4, + "rows_after_filter": 4, + "cost": 2.203417969, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 4, - "cost": 2.806835937, + "cost": 2.203417969, "uses_join_buffering": false } }, "rows_for_plan": 4, - "cost_for_plan": 3.606835937, + "cost_for_plan": 2.203417969, "estimated_join_cardinality": 4 } ] @@ -3758,7 +3925,8 @@ select f2(a) from t1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 3.605835937 + "rows": 4, + "cost": 2.203417969 } }, { @@ -3800,7 +3968,7 @@ a 2 select length(trace) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; length(trace) -2226 +2530 set optimizer_trace_max_mem_size=100; select * from t1; a @@ -3814,7 +3982,7 @@ select * from t1 { "join_preparation": { "select_id": 1, "steps": [ - 2126 0 + 2430 0 set optimizer_trace_max_mem_size=0; select * from t1; a @@ -3822,7 +3990,7 @@ a 2 select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES -select * from t1 2226 0 +select * from t1 2530 0 drop table t1; set optimizer_trace='enabled=off'; set @@optimizer_trace_max_mem_size= @save_optimizer_trace_max_mem_size; @@ -3847,7 +4015,7 @@ explain delete from t0 where t0.a<3 { "range_analysis": { "table_scan": { "rows": 10, - "cost": 6.021972656 + "cost": 3.510986328 }, "potential_range_indexes": [ { @@ -3866,7 +4034,7 @@ explain delete from t0 where t0.a<3 { "using_mrr": false, "index_only": false, "rows": 3, - "cost": 3.746757383, + "cost": 2.771757383, "chosen": true } ], @@ -3884,7 +4052,7 @@ explain delete from t0 where t0.a<3 { "ranges": ["(NULL) < (a) < (3)"] }, "rows_for_plan": 3, - "cost_for_plan": 3.746757383, + "cost_for_plan": 2.771757383, "chosen": true } } @@ -3985,7 +4153,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "range_analysis": { "table_scan": { "rows": 10, - "cost": 6.021972656 + "cost": 3.510986328 }, "potential_range_indexes": [ { @@ -3996,7 +4164,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { ], "best_covering_index_scan": { "index": "a", - "cost": 3.005857945, + "cost": 2.755857945, "chosen": true }, "setup_range_conditions": [], @@ -4009,7 +4177,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "using_mrr": false, "index_only": true, "rows": 3, - "cost": 0.746757383, + "cost": 1.196757383, "chosen": true } ], @@ -4030,7 +4198,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "ranges": ["(NULL) < (a) < (3)"] }, "rows_for_plan": 3, - "cost_for_plan": 0.746757383, + "cost_for_plan": 1.196757383, "chosen": true } } @@ -4050,7 +4218,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "range_analysis": { "table_scan": { "rows": 10, - "cost": 6.021972656 + "cost": 3.510986328 }, "potential_range_indexes": [ { @@ -4061,7 +4229,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { ], "best_covering_index_scan": { "index": "a", - "cost": 3.005857945, + "cost": 2.755857945, "chosen": true }, "setup_range_conditions": [], @@ -4074,7 +4242,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "using_mrr": false, "index_only": true, "rows": 3, - "cost": 0.746757383, + "cost": 1.196757383, "chosen": true } ], @@ -4095,7 +4263,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "ranges": ["(NULL) < (a) < (3)"] }, "rows_for_plan": 3, - "cost_for_plan": 0.746757383, + "cost_for_plan": 1.196757383, "chosen": true } } @@ -4118,28 +4286,36 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "plan_prefix": [], "table": "t0", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "range", - "resulting_rows": 3, - "cost": 0.746757383, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.196757383, "chosen": true } ], "chosen_access_method": { "type": "range", "records": 3, - "cost": 0.746757383, + "cost": 1.196757383, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 1.346757383, + "cost_for_plan": 1.196757383, "rest_of_plan": [ { "plan_prefix": ["t0"], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { "access_type": "ref", @@ -4147,10 +4323,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "used_range_estimates": false, "cause": "not better than ref estimates", "rows": 1, - "found_matching_rows_cost": 1.200585794, - "startup_cost": 0, - "rows": 1, - "cost": 3.601757383, + "cost": 2.176757383, "chosen": true }, { @@ -4162,12 +4335,12 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "chosen_access_method": { "type": "ref", "records": 1, - "cost": 3.601757383, + "cost": 2.176757383, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 5.548514767, + "cost_for_plan": 3.373514767, "estimated_join_cardinality": 3 } ] @@ -4176,28 +4349,36 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "range", - "resulting_rows": 3, - "cost": 0.746757383, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.196757383, "chosen": true } ], "chosen_access_method": { "type": "range", "records": 3, - "cost": 0.746757383, + "cost": 1.196757383, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 1.346757383, + "cost_for_plan": 1.196757383, "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t0", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { "access_type": "ref", @@ -4206,10 +4387,7 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "used_range_estimates": false, "cause": "not better than ref estimates", "rows": 2, - "found_matching_rows_cost": 1.401171589, - "startup_cost": 0, - "rows": 2, - "cost": 4.203514767, + "cost": 2.853514767, "chosen": true }, { @@ -4221,12 +4399,12 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { "chosen_access_method": { "type": "ref", "records": 2, - "cost": 4.203514767, + "cost": 2.853514767, "uses_join_buffering": false } }, "rows_for_plan": 6, - "cost_for_plan": 6.75027215, + "cost_for_plan": 4.05027215, "pruned_by_cost": true } ] @@ -4236,7 +4414,8 @@ explain delete t0,t1 from t0, t1 where t0.a=t1.a and t1.a<3 { { "best_join_order": ["t0", "t1"], "best_access_method": { - "cost": 5.547514767 + "rows": 3, + "cost": 3.373514767 } }, { @@ -4346,7 +4525,8 @@ explain select * from (select rand() from t1)q { "table": "t1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } } ] @@ -4357,23 +4537,29 @@ explain select * from (select rand() from t1)q { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "estimated_join_cardinality": 3 } ] @@ -4381,7 +4567,8 @@ explain select * from (select rand() from t1)q { { "best_join_order": ["t1"], "best_access_method": { - "cost": 3.204126953 + "rows": 3, + "cost": 1.902563477 } }, { @@ -4414,7 +4601,8 @@ explain select * from (select rand() from t1)q { "table": "<derived2>", "table_scan": { "rows": 3, - "cost": 3 + "read_cost": 3, + "read_and_compare_cost": 3.75 } } ] @@ -4425,23 +4613,29 @@ explain select * from (select rand() from t1)q { "plan_prefix": [], "table": "<derived2>", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 3.6, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 3.75, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 3.6, + "cost": 3.75, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 4.2, + "cost_for_plan": 3.75, "estimated_join_cardinality": 3 } ] @@ -4449,7 +4643,8 @@ explain select * from (select rand() from t1)q { { "best_join_order": ["<derived2>"], "best_access_method": { - "cost": 4.199 + "rows": 3, + "cost": 3.75 } }, { @@ -4602,21 +4797,24 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "table": "t1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } }, { "table": "t_inner_1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } }, { "table": "t_inner_2", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } } ] @@ -4635,45 +4833,57 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "plan_prefix": [], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "rest_of_plan": [ { "plan_prefix": ["t_inner_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "estimated_join_cardinality": 9 } ] @@ -4682,23 +4892,29 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "plan_prefix": [], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "pruned_by_heuristic": true } ] @@ -4712,84 +4928,105 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t1"], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t1", "t_inner_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 8.005126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 10.00256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 8.005126953, + "cost": 10.00256348, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 22.81538086, + "cost_for_plan": 16.05769043, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "records": 3, - "read_time": 48.86665039 + "cost": 24.7333252 }, { "strategy": "SJ-Materialization", "records": 3, - "cost": 10.81538086 + "cost": 9.55769043 }, { "strategy": "DuplicateWeedout", "records": 3, - "read_time": 27.31538086 + "dups_cost": 16.05769043, + "write_cost": 1.45, + "full_lookup_cost": 4.05, + "total_cost": 21.55769043 }, { "chosen_strategy": "SJ-Materialization" @@ -4803,23 +5040,29 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "plan_prefix": ["t1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -4829,23 +5072,29 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "plan_prefix": [], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -4853,23 +5102,29 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ "plan_prefix": [], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -4893,7 +5148,8 @@ explain select * from t1 where a in (select t_inner_1.a from t1 t_inner_1, t1 t_ { "best_join_order": ["t1", "<subquery2>"], "best_access_method": { - "cost": 10.81438086 + "rows": 3, + "cost": 9.55769043 } }, { @@ -4945,11 +5201,11 @@ explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t_outer_1 ALL NULL NULL NULL NULL 3 -1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Start temporary; Using join buffer (flat, BNL join) -1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 End temporary; Using join buffer (incremental, BNL join) -1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Start temporary; Using join buffer (incremental, BNL join) +1 PRIMARY t_inner_1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t_inner_2 ALL NULL NULL NULL NULL 9 FirstMatch(t_outer_1); Using join buffer (incremental, BNL join) 1 PRIMARY t_outer_2 ALL NULL NULL NULL NULL 9 Using join buffer (incremental, BNL join) -1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; End temporary; Using join buffer (incremental, BNL join) +1 PRIMARY t_inner_4 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +1 PRIMARY t_inner_3 ALL NULL NULL NULL NULL 9 Using where; FirstMatch(t_outer_2); Using join buffer (incremental, BNL join) select * from INFORMATION_SCHEMA.OPTIMIZER_TRACE; QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES explain select * from t1 t_outer_1,t2 t_outer_2 where t_outer_1.a in (select t_inner_1.a from t2 t_inner_2, t1 t_inner_1) and @@ -5108,42 +5364,48 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "table": "t_outer_1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } }, { "table": "t_outer_2", "table_scan": { "rows": 9, - "cost": 2.015380859 + "read_cost": 1.45769043, + "read_and_compare_cost": 3.70769043 } }, { "table": "t_inner_2", "table_scan": { "rows": 9, - "cost": 2.015380859 + "read_cost": 1.45769043, + "read_and_compare_cost": 3.70769043 } }, { "table": "t_inner_1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } }, { "table": "t_inner_3", "table_scan": { "rows": 9, - "cost": 2.015380859 + "read_cost": 1.45769043, + "read_and_compare_cost": 3.70769043 } }, { "table": "t_inner_4", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } } ] @@ -5169,82 +5431,103 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_outer_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1"], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 28.00769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 28.00769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 45.62563477, + "cost_for_plan": 34.06281738, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "records": 3, - "read_time": 81.35893555 + "cost": 40.97946777 }, { "strategy": "DuplicateWeedout", "records": 3, - "read_time": 58.22563477 + "dups_cost": 34.06281738, + "write_cost": 1.45, + "full_lookup_cost": 12.15, + "total_cost": 47.66281738 }, { - "chosen_strategy": "DuplicateWeedout" + "chosen_strategy": "FirstMatch" } ], "rest_of_plan": [ @@ -5252,23 +5535,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 13.15769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 13.15769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 72.84101562, + "cost_for_plan": 54.1371582, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -5280,23 +5569,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 18.80512695, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 34.30256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 18.80512695, + "cost": 34.30256348, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 107.8461426, + "cost_for_plan": 88.43972168, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -5309,36 +5604,45 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 331.7576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 331.7576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 403.2615234, + "cost_for_plan": 420.1974121, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "records": 27, - "read_time": 776.225293 + "cost": 405.8292969 }, { "strategy": "DuplicateWeedout", "records": 27, - "read_time": 516.6615234 + "dups_cost": 420.1974121, + "write_cost": 5.05, + "full_lookup_cost": 109.35, + "total_cost": 534.5974121 }, { - "chosen_strategy": "DuplicateWeedout" + "chosen_strategy": "FirstMatch" } ], "estimated_join_cardinality": 27 @@ -5354,23 +5658,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 52.41538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 100.9076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 52.41538086, + "cost": 100.9076904, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 173.8563965, + "cost_for_plan": 155.0448486, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -5380,23 +5690,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 5.052563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 5.052563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 64.43076172, + "cost_for_plan": 46.03203125, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -5408,23 +5724,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 36.10769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 36.10769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 100.6461426, + "cost_for_plan": 82.13972168, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -5437,34 +5759,43 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 331.7576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 331.7576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 396.0615234, + "cost_for_plan": 413.8974121, "semijoin_strategy_choice": [ { "strategy": "DuplicateWeedout", "records": 27, - "read_time": 509.4615234 + "dups_cost": 413.8974121, + "write_cost": 5.05, + "full_lookup_cost": 109.35, + "total_cost": 528.2974121 }, { "chosen_strategy": "DuplicateWeedout" } ], - "estimated_join_cardinality": 27 + "pruned_by_cost": true } ] }, @@ -5477,23 +5808,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 36.10769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 36.10769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 100.6461426, + "cost_for_plan": 82.13972168, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -5503,23 +5840,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 13.15769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 13.15769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 72.84101562, + "cost_for_plan": 54.1371582, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -5529,178 +5872,100 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 28.00769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 28.00769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 45.62563477, + "cost_for_plan": 34.06281738, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 258.8576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 258.8576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 341.0410156, + "cost_for_plan": 292.9205078, "semijoin_strategy_choice": [ { "strategy": "DuplicateWeedout", "records": 27, - "read_time": 454.4410156 + "dups_cost": 292.9205078, + "write_cost": 5.05, + "full_lookup_cost": 109.35, + "total_cost": 407.3205078 }, { "chosen_strategy": "DuplicateWeedout" } ], - "rest_of_plan": [ - { - "plan_prefix": [ - "t_outer_1", - "t_inner_1", - "t_outer_2", - "t_inner_2" - ], - "table": "t_inner_4", - "best_access_path": { - "considered_access_paths": [ - { - "access_type": "scan", - "resulting_rows": 3, - "cost": 18.80512695, - "chosen": true - } - ], - "chosen_access_method": { - "type": "scan", - "records": 3, - "cost": 18.80512695, - "uses_join_buffering": true - } - }, - "rows_for_plan": 81, - "cost_for_plan": 489.4461426, - "semijoin_strategy_choice": [], - "rest_of_plan": [ - { - "plan_prefix": [ - "t_outer_1", - "t_inner_1", - "t_outer_2", - "t_inner_2", - "t_inner_4" - ], - "table": "t_inner_3", - "best_access_path": { - "considered_access_paths": [ - { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, - "chosen": true - } - ], - "chosen_access_method": { - "type": "scan", - "records": 9, - "cost": 149.6153809, - "uses_join_buffering": true - } - }, - "rows_for_plan": 729, - "cost_for_plan": 784.8615234, - "semijoin_strategy_choice": [ - { - "strategy": "DuplicateWeedout", - "records": 27, - "read_time": 898.2615234 - }, - { - "chosen_strategy": "DuplicateWeedout" - } - ], - "pruned_by_cost": true - } - ] - }, - { - "plan_prefix": [ - "t_outer_1", - "t_inner_1", - "t_outer_2", - "t_inner_2" - ], - "table": "t_inner_3", - "best_access_path": { - "considered_access_paths": [ - { - "access_type": "scan", - "resulting_rows": 9, - "cost": 52.41538086, - "chosen": true - } - ], - "chosen_access_method": { - "type": "scan", - "records": 9, - "cost": 52.41538086, - "uses_join_buffering": true - } - }, - "rows_for_plan": 243, - "cost_for_plan": 555.4563965, - "semijoin_strategy_choice": [], - "pruned_by_cost": true - } - ] + "pruned_by_cost": true }, { "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 51.20512695, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 86.95256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 51.20512695, + "cost": 86.95256348, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 145.4307617, + "cost_for_plan": 121.0153809, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -5712,23 +5977,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 243 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 441.2153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 878.5076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 441.2153809, + "cost": 878.5076904, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1024.046143, + "cost_for_plan": 999.5230713, "semijoin_strategy_choice": [], "pruned_by_cost": true }, @@ -5741,23 +6012,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 243 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 441.2153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 878.5076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 441.2153809, + "cost": 878.5076904, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1024.046143, + "cost_for_plan": 999.5230713, "semijoin_strategy_choice": [], "pruned_by_cost": true } @@ -5767,93 +6044,31 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_outer_2"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 258.8576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 258.8576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 341.0410156, + "cost_for_plan": 292.9205078, "semijoin_strategy_choice": [], - "rest_of_plan": [ - { - "plan_prefix": [ - "t_outer_1", - "t_inner_1", - "t_outer_2", - "t_inner_3" - ], - "table": "t_inner_4", - "best_access_path": { - "considered_access_paths": [ - { - "access_type": "scan", - "resulting_rows": 3, - "cost": 440.005127, - "chosen": true - } - ], - "chosen_access_method": { - "type": "scan", - "records": 3, - "cost": 440.005127, - "uses_join_buffering": true - } - }, - "rows_for_plan": 2187, - "cost_for_plan": 1218.446143, - "semijoin_strategy_choice": [ - { - "strategy": "FirstMatch", - "records": 81, - "read_time": 3420.209033 - }, - { - "chosen_strategy": "FirstMatch" - } - ], - "pruned_by_cost": true - }, - { - "plan_prefix": [ - "t_outer_1", - "t_inner_1", - "t_outer_2", - "t_inner_3" - ], - "table": "t_inner_2", - "best_access_path": { - "considered_access_paths": [ - { - "access_type": "scan", - "resulting_rows": 9, - "cost": 1316.015381, - "chosen": true - } - ], - "chosen_access_method": { - "type": "scan", - "records": 9, - "cost": 1316.015381, - "uses_join_buffering": true - } - }, - "rows_for_plan": 6561, - "cost_for_plan": 2969.256396, - "semijoin_strategy_choice": [], - "pruned_by_cost": true - } - ] + "pruned_by_heuristic": true } ] }, @@ -5861,46 +6076,58 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 8.005126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 10.00256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 8.005126953, + "cost": 10.00256348, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 22.81538086, + "cost_for_plan": 16.05769043, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 52.41538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 88.75769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 52.41538086, + "cost": 88.75769043, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 123.8307617, + "cost_for_plan": 104.8153809, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -5912,23 +6139,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 243 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 441.2153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 878.5076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 441.2153809, + "cost": 878.5076904, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1002.446143, + "cost_for_plan": 983.3230713, "semijoin_strategy_choice": [], "pruned_by_cost": true }, @@ -5941,23 +6174,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 243 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 441.2153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 878.5076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 441.2153809, + "cost": 878.5076904, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1002.446143, + "cost_for_plan": 983.3230713, "semijoin_strategy_choice": [], "pruned_by_cost": true } @@ -5967,23 +6206,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 52.41538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 88.75769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 52.41538086, + "cost": 88.75769043, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 123.8307617, + "cost_for_plan": 104.8153809, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -5991,23 +6236,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 52.41538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 88.75769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 52.41538086, + "cost": 88.75769043, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 123.8307617, + "cost_for_plan": 104.8153809, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -6017,46 +6268,58 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 28.00769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 28.00769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 45.62563477, + "cost_for_plan": 34.06281738, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 258.8576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 258.8576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 341.0410156, + "cost_for_plan": 292.9205078, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -6068,23 +6331,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 729 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 440.005127, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 876.7025635, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 440.005127, + "cost": 876.7025635, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1218.446143, + "cost_for_plan": 1169.623071, "semijoin_strategy_choice": [], "pruned_by_cost": true }, @@ -6097,23 +6366,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 729 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 1316.015381, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 2628.10769, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 1316.015381, + "cost": 2628.10769, "uses_join_buffering": true } }, "rows_for_plan": 6561, - "cost_for_plan": 2969.256396, + "cost_for_plan": 2921.028198, "semijoin_strategy_choice": [], "pruned_by_cost": true } @@ -6123,23 +6398,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 51.20512695, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 86.95256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 51.20512695, + "cost": 86.95256348, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 145.4307617, + "cost_for_plan": 121.0153809, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -6151,23 +6432,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 243 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 441.2153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 878.5076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 441.2153809, + "cost": 878.5076904, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1024.046143, + "cost_for_plan": 999.5230713, "semijoin_strategy_choice": [], "pruned_by_cost": true }, @@ -6180,23 +6467,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 243 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 441.2153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 878.5076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 441.2153809, + "cost": 878.5076904, "uses_join_buffering": true } }, "rows_for_plan": 2187, - "cost_for_plan": 1024.046143, + "cost_for_plan": 999.5230713, "semijoin_strategy_choice": [], "pruned_by_cost": true } @@ -6206,23 +6499,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_3"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 258.8576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 258.8576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 341.0410156, + "cost_for_plan": 292.9205078, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -6234,23 +6533,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6258,23 +6563,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6282,23 +6593,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6306,23 +6623,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -6332,23 +6655,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6356,23 +6685,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6380,23 +6715,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6404,23 +6745,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -6428,23 +6775,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -6453,10 +6806,114 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { { "fix_semijoin_strategies_for_picked_join_order": [ { - "semi_join_strategy": "DuplicateWeedout" + "semi_join_strategy": "FirstMatch", + "join_order": [ + { + "table": "t_inner_4" + }, + "best_access_path": { + "plan_details": { + "record_count": 27 + }, + "considered_access_paths": [ + { + "access_type": "scan", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 51.36921387, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 3, + "cost": 51.36921387, + "uses_join_buffering": false + } + }, + { + "table": "t_inner_3" + }, + "best_access_path": { + "plan_details": { + "record_count": 81 + }, + "considered_access_paths": [ + { + "access_type": "scan", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 300.3229248, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 9, + "cost": 300.3229248, + "uses_join_buffering": false + } + } + ] }, { - "semi_join_strategy": "DuplicateWeedout" + "semi_join_strategy": "FirstMatch", + "join_order": [ + { + "table": "t_inner_1" + }, + "best_access_path": { + "plan_details": { + "record_count": 3 + }, + "considered_access_paths": [ + { + "access_type": "scan", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 5.70769043, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 3, + "cost": 5.70769043, + "uses_join_buffering": false + } + }, + { + "table": "t_inner_2" + }, + "best_access_path": { + "plan_details": { + "record_count": 9 + }, + "considered_access_paths": [ + { + "access_type": "scan", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 33.36921387, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 9, + "cost": 33.36921387, + "uses_join_buffering": false + } + } + ] } ] }, @@ -6465,12 +6922,13 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "t_outer_1", "t_inner_1", "t_inner_2", - "t_inner_4", "t_outer_2", + "t_inner_4", "t_inner_3" ], "best_access_method": { - "cost": 509.4605234 + "rows": 27, + "cost": 405.8292969 } }, { @@ -6496,11 +6954,11 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "attached": null }, { - "table": "t_inner_4", + "table": "t_outer_2", "attached": null }, { - "table": "t_outer_2", + "table": "t_inner_4", "attached": null }, { @@ -6691,42 +7149,48 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "table": "t_outer_1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } }, { "table": "t_outer_2", "table_scan": { "rows": 9, - "cost": 2.015380859 + "read_cost": 1.45769043, + "read_and_compare_cost": 3.70769043 } }, { "table": "t_inner_2", "table_scan": { "rows": 9, - "cost": 2.015380859 + "read_cost": 1.45769043, + "read_and_compare_cost": 3.70769043 } }, { "table": "t_inner_1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } }, { "table": "t_inner_3", "table_scan": { "rows": 9, - "cost": 2.015380859 + "read_cost": 1.45769043, + "read_and_compare_cost": 3.70769043 } }, { "table": "t_inner_4", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } } ] @@ -6750,45 +7214,57 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "rest_of_plan": [ { "plan_prefix": ["t_inner_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "estimated_join_cardinality": 27 } ] @@ -6797,23 +7273,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "pruned_by_heuristic": true } ] @@ -6824,45 +7306,57 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "rest_of_plan": [ { "plan_prefix": ["t_inner_4"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "estimated_join_cardinality": 27 } ] @@ -6871,23 +7365,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "pruned_by_heuristic": true } ] @@ -6901,84 +7401,105 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_outer_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1"], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "semijoin_strategy_choice": [], "rest_of_plan": [ { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 28.00769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 28.00769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 45.62563477, + "cost_for_plan": 34.06281738, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "records": 3, - "read_time": 81.35893555 + "cost": 40.97946777 }, { "strategy": "SJ-Materialization", "records": 3, - "cost": 16.52563477 + "cost": 16.76281738 }, { "strategy": "DuplicateWeedout", "records": 3, - "read_time": 58.22563477 + "dups_cost": 34.06281738, + "write_cost": 1.45, + "full_lookup_cost": 12.15, + "total_cost": 47.66281738 }, { "chosen_strategy": "SJ-Materialization" @@ -6989,23 +7510,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 13.15769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 13.15769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 31.14101563, + "cost_for_plan": 29.92050781, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -7017,23 +7544,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 18.80512695, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 34.30256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 18.80512695, + "cost": 34.30256348, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 66.14614258, + "cost_for_plan": 64.22307129, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -7046,38 +7579,47 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 81 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 149.6153809, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 331.7576904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 149.6153809, + "cost": 331.7576904, "uses_join_buffering": true } }, "rows_for_plan": 729, - "cost_for_plan": 361.5615234, + "cost_for_plan": 395.9807617, "semijoin_strategy_choice": [ { "strategy": "FirstMatch", "records": 27, - "read_time": 734.525293 + "cost": 381.6126465 }, { "strategy": "SJ-Materialization", "records": 27, - "cost": 45.66152344 + "cost": 45.98076172 }, { "strategy": "DuplicateWeedout", "records": 27, - "read_time": 474.9615234 + "dups_cost": 395.9807617, + "write_cost": 5.05, + "full_lookup_cost": 109.35, + "total_cost": 510.3807617 }, { "chosen_strategy": "SJ-Materialization" @@ -7096,23 +7638,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 27 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 52.41538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 100.9076904, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 52.41538086, + "cost": 100.9076904, "uses_join_buffering": true } }, "rows_for_plan": 243, - "cost_for_plan": 132.1563965, + "cost_for_plan": 130.8281982, "semijoin_strategy_choice": [], "pruned_by_cost": true } @@ -7122,23 +7670,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 5.052563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 5.052563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 22.73076172, + "cost_for_plan": 21.81538086, "semijoin_strategy_choice": [], "rest_of_plan": [ { @@ -7150,23 +7704,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 36.10769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 36.10769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 58.94614258, + "cost_for_plan": 57.92307129, "semijoin_strategy_choice": [], "pruned_by_cost": true }, @@ -7179,23 +7739,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { ], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 36.10769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 36.10769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 58.94614258, + "cost_for_plan": 57.92307129, "semijoin_strategy_choice": [], "pruned_by_cost": true } @@ -7205,23 +7771,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_2"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 13.15769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 13.15769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 31.14101563, + "cost_for_plan": 29.92050781, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -7231,23 +7803,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 28.00769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 28.00769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 45.62563477, + "cost_for_plan": 34.06281738, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7255,47 +7833,150 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 8.005126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 10.00256348, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 8.005126953, + "cost": 10.00256348, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 22.81538086, + "cost_for_plan": 16.05769043, "semijoin_strategy_choice": [], - "pruned_by_heuristic": true + "rest_of_plan": [ + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], + "table": "t_outer_2", + "best_access_path": { + "plan_details": { + "record_count": 27 + }, + "considered_access_paths": [ + { + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 88.75769043, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 9, + "cost": 88.75769043, + "uses_join_buffering": true + } + }, + "rows_for_plan": 243, + "cost_for_plan": 104.8153809, + "semijoin_strategy_choice": [], + "pruned_by_cost": true + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], + "table": "t_inner_2", + "best_access_path": { + "plan_details": { + "record_count": 27 + }, + "considered_access_paths": [ + { + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 88.75769043, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 9, + "cost": 88.75769043, + "uses_join_buffering": true + } + }, + "rows_for_plan": 243, + "cost_for_plan": 104.8153809, + "semijoin_strategy_choice": [], + "pruned_by_cost": true + }, + { + "plan_prefix": ["t_outer_1", "t_inner_1", "t_inner_4"], + "table": "t_inner_3", + "best_access_path": { + "plan_details": { + "record_count": 27 + }, + "considered_access_paths": [ + { + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 88.75769043, + "index_only": false, + "chosen": true + } + ], + "chosen_access_method": { + "type": "scan", + "records": 9, + "cost": 88.75769043, + "uses_join_buffering": true + } + }, + "rows_for_plan": 243, + "cost_for_plan": 104.8153809, + "semijoin_strategy_choice": [], + "pruned_by_cost": true + } + ] }, { "plan_prefix": ["t_outer_1", "t_inner_1"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 9 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 20.01538086, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 28.00769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 20.01538086, + "cost": 28.00769043, "uses_join_buffering": true } }, "rows_for_plan": 81, - "cost_for_plan": 45.62563477, + "cost_for_plan": 34.06281738, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -7305,23 +7986,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7329,23 +8016,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7353,23 +8046,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 3, - "cost": 4.405126953, + "access_type": "scan_with_join_cache", + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 4.152563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 4.405126953, + "cost": 4.152563477, "uses_join_buffering": true } }, "rows_for_plan": 9, - "cost_for_plan": 9.410253906, + "cost_for_plan": 6.055126953, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7377,23 +8076,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": ["t_outer_1"], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 3 + }, "considered_access_paths": [ { - "access_type": "scan", - "resulting_rows": 9, - "cost": 9.215380859, + "access_type": "scan_with_join_cache", + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 10.45769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 9.215380859, + "cost": 10.45769043, "uses_join_buffering": true } }, "rows_for_plan": 27, - "cost_for_plan": 17.82050781, + "cost_for_plan": 12.36025391, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -7403,23 +8108,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7427,23 +8138,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7451,23 +8168,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_outer_2", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7475,23 +8198,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_4", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "semijoin_strategy_choice": [], "pruned_by_heuristic": true }, @@ -7499,23 +8228,29 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "plan_prefix": [], "table": "t_inner_3", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 9, - "cost": 3.815380859, + "rows": 9, + "rows_after_scan": 9, + "rows_after_filter": 9, + "cost": 3.70769043, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 9, - "cost": 3.815380859, + "cost": 3.70769043, "uses_join_buffering": false } }, "rows_for_plan": 9, - "cost_for_plan": 5.615380859, + "cost_for_plan": 3.70769043, "semijoin_strategy_choice": [], "pruned_by_heuristic": true } @@ -7555,7 +8290,8 @@ t_outer_2.a in (select t_inner_3.a from t2 t_inner_3, t1 t_inner_4) { "<subquery3>" ], "best_access_method": { - "cost": 45.66052344 + "rows": 27, + "cost": 45.98076172 } }, { @@ -7663,7 +8399,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": true, "rows": 1, - "cost": 0.345829876, + "cost": 0.745829876, "chosen": true } ], @@ -7697,7 +8433,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": true, "rows": 107, - "cost": 21.63379668, + "cost": 24.68379668, "chosen": true } ], @@ -7734,7 +8470,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1000, - "cost": 1203.877243, + "cost": 756.2522431, "chosen": true } ], @@ -7779,7 +8515,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 4, - "cost": 4.948710032, + "cost": 3.523710032, "chosen": true } ], @@ -7818,7 +8554,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.346171589, + "cost": 1.271171589, "chosen": true } ], @@ -7852,7 +8588,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.346171589, + "cost": 1.271171589, "chosen": true } ], @@ -7894,7 +8630,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345927508, + "cost": 1.270927508, "chosen": true } ], @@ -7929,7 +8665,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345878692, + "cost": 1.270878692, "chosen": true } ], @@ -7964,7 +8700,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345927508, + "cost": 1.270927508, "chosen": true } ], @@ -8002,7 +8738,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345878692, + "cost": 1.270878692, "chosen": true } ], @@ -8043,7 +8779,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.394255553, + "cost": 1.319255553, "chosen": true } ], @@ -8063,7 +8799,7 @@ INSERT INTO t1 VALUES (2, 'ab\n'); set optimizer_trace=1; EXPLAIN SELECT * FROM t1 WHERE b='ab\n'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref i_b i_b 13 const 2 Using index condition +1 SIMPLE t1 ALL i_b NULL NULL NULL 2 Using where select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) [ @@ -8082,8 +8818,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 2, - "cost": 2.546855016, - "chosen": true + "cost": 2.021855016, + "chosen": false, + "cause": "cost" } ], "analyzing_roworder_intersect": @@ -8138,7 +8875,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1000, - "cost": 1203.877243, + "cost": 756.2522431, "chosen": true } ], @@ -8197,13 +8934,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "A", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 5.9375, - "cost": 4.017089844, + "rows": 10, + "rows_after_scan": 5.9375, + "rows_after_filter": 5.9375, + "cost": 4.008544922, + "index_only": false, "chosen": true } ], @@ -8211,12 +8955,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 5.9375, - "cost": 4.017089844, + "cost": 4.008544922, "uses_join_buffering": false } }, "rows_for_plan": 5.9375, - "cost_for_plan": 5.204589844, + "cost_for_plan": 4.008544922, "rest_of_plan": [ @@ -8228,13 +8972,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "B", "best_access_path": { + "plan_details": + { + "record_count": 5.9375 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 804.6875, - "cost": 2167.987671, + "rows": 1000, + "rows_after_scan": 804.6875, + "rows_after_filter": 804.6875, + "cost": 1793.710632, + "index_only": false, "chosen": true } ], @@ -8242,12 +8993,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 804.6875, - "cost": 2167.987671, + "cost": 1793.710632, "uses_join_buffering": false } }, "rows_for_plan": 4777.832031, - "cost_for_plan": 3128.758667, + "cost_for_plan": 1797.719177, "estimated_join_cardinality": 4777.832031 } ] @@ -8260,13 +9011,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "B", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 804.6875, - "cost": 204.1972656, + "rows": 1000, + "rows_after_scan": 804.6875, + "rows_after_filter": 804.6875, + "cost": 302.0986328, + "index_only": false, "chosen": true } ], @@ -8274,12 +9032,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 804.6875, - "cost": 204.1972656, + "cost": 302.0986328, "uses_join_buffering": false } }, "rows_for_plan": 804.6875, - "cost_for_plan": 365.1347656, + "cost_for_plan": 302.0986328, "pruned_by_heuristic": true } ] @@ -8303,13 +9061,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "A", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 4.017089844, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 4.008544922, + "index_only": false, "chosen": true } ], @@ -8317,12 +9082,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 10, - "cost": 4.017089844, + "cost": 4.008544922, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 6.017089844, + "cost_for_plan": 4.008544922, "rest_of_plan": [ @@ -8334,6 +9099,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "B", "best_access_path": { + "plan_details": + { + "record_count": 10 + }, "considered_access_paths": [ @@ -8343,30 +9112,26 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "used_range_estimates": false, "cause": "not available", "rows": 1, - "found_matching_rows_cost": 2.200585794, - "startup_cost": 0, - "rows": 1, - "cost": 22.00585794, + "cost": 12.50585794, "chosen": true }, { - "access_type": "scan", - "resulting_rows": 603.515625, - "cost": 1411.228516, - "chosen": false + "type": "scan", + "chosen": false, + "cause": "cost" } ], "chosen_access_method": { "type": "ref", "records": 1, - "cost": 22.00585794, + "cost": 12.50585794, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 30.02294779, + "cost_for_plan": 16.51440287, "selectivity": 0.8046875, "remaining_rows_for_plan": 8.046875, "estimated_join_cardinality": 8.046875 @@ -8381,13 +9146,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "B", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 804.6875, - "cost": 204.1972656, + "rows": 1000, + "rows_after_scan": 804.6875, + "rows_after_filter": 804.6875, + "cost": 302.0986328, + "index_only": false, "chosen": true } ], @@ -8395,12 +9167,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 804.6875, - "cost": 204.1972656, + "cost": 302.0986328, "uses_join_buffering": false } }, "rows_for_plan": 804.6875, - "cost_for_plan": 365.1347656, + "cost_for_plan": 302.0986328, "pruned_by_cost": true } ] @@ -8434,7 +9206,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.357887479, + "cost": 1.282887479, "chosen": true } ], @@ -8460,9 +9232,9 @@ insert into t3 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); explain select * from t3 where (a,a) in (select t1.a, t2.a from t1, t2 where t1.b=t2.b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 5 -1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where -1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 10 Using where +1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using where select JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; JSON_DETAILED(JSON_EXTRACT(trace, '$**.semijoin_table_pullout')) [ @@ -8500,7 +9272,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives')) "using_mrr": false, "index_only": true, "rows": 1, - "cost": 0.345829876, + "cost": 0.745829876, "chosen": true } ] @@ -8531,13 +9303,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "t1", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10, - "cost": 4.021972656, + "rows": 10, + "rows_after_scan": 10, + "rows_after_filter": 10, + "cost": 4.010986328, + "index_only": false, "chosen": true } ], @@ -8545,12 +9324,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 10, - "cost": 4.021972656, + "cost": 4.010986328, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 6.021972656, + "cost_for_plan": 4.010986328, "rest_of_plan": [ @@ -8562,6 +9341,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "t2", "best_access_path": { + "plan_details": + { + "record_count": 10 + }, "considered_access_paths": [ @@ -8571,17 +9354,17 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "used_range_estimates": false, "cause": "not available", "rows": 1, - "found_matching_rows_cost": 2.200585794, - "startup_cost": 0, - "rows": 1, - "cost": 22.00585794, + "cost": 12.50585794, "chosen": true }, { - "access_type": "scan", - "resulting_rows": 75, - "cost": 172.2197266, + "access_type": "scan_with_join_cache", + "rows": 100, + "rows_after_scan": 75, + "rows_after_filter": 75, + "cost": 218.6098633, + "index_only": false, "chosen": false } ], @@ -8589,12 +9372,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "ref", "records": 1, - "cost": 22.00585794, + "cost": 12.50585794, "uses_join_buffering": false } }, "rows_for_plan": 10, - "cost_for_plan": 30.0278306, + "cost_for_plan": 16.51684427, "cost_for_sorting": 10, "estimated_join_cardinality": 10 } @@ -8608,13 +9391,20 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "t2", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 100, - "cost": 22.21972656, + "rows": 100, + "rows_after_scan": 100, + "rows_after_filter": 100, + "cost": 31.10986328, + "index_only": false, "chosen": true, "use_tmp_table": true } @@ -8623,12 +9413,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "scan", "records": 100, - "cost": 22.21972656, + "cost": 31.10986328, "uses_join_buffering": false } }, "rows_for_plan": 100, - "cost_for_plan": 42.21972656, + "cost_for_plan": 31.10986328, "pruned_by_cost": true } ] @@ -8744,7 +9534,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.range_scan_alternatives')) "using_mrr": false, "index_only": false, "rows": 0, - "cost": 0.145, + "cost": 0.52, "chosen": true } ] @@ -8837,7 +9627,8 @@ select count(*) from seq_1_to_10000000 { "table": "seq_1_to_10000000", "table_scan": { "rows": 10000000, - "cost": 10000000 + "read_cost": 5000000, + "read_and_compare_cost": 7250000 } } ] @@ -8848,23 +9639,29 @@ select count(*) from seq_1_to_10000000 { "plan_prefix": [], "table": "seq_1_to_10000000", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 10000000, - "cost": 12000000, + "rows": 10000000, + "rows_after_scan": 10000000, + "rows_after_filter": 10000000, + "cost": 7250000, + "index_only": true, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 10000000, - "cost": 12000000, + "cost": 7250000, "uses_join_buffering": false } }, "rows_for_plan": 10000000, - "cost_for_plan": 14000000, + "cost_for_plan": 7250000, "estimated_join_cardinality": 10000000 } ] @@ -8872,7 +9669,8 @@ select count(*) from seq_1_to_10000000 { { "best_join_order": ["seq_1_to_10000000"], "best_access_method": { - "cost": 14000000 + "rows": 10000000, + "cost": 7250000 } }, { @@ -8937,9 +9735,8 @@ set @tmp=@@in_predicate_conversion_threshold; set in_predicate_conversion_threshold=3; explain select * from t0 where a in (1,2,3,4,5,6); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t0 ALL NULL NULL NULL NULL 10 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 6 +1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where +1 PRIMARY <derived3> ref key0 key0 4 test.t0.a 2 FirstMatch(t0) 3 DERIVED NULL NULL NULL NULL NULL NULL NULL No tables used select json_detailed(json_extract(trace, '$**.in_to_subquery_conversion')) from information_schema.optimizer_trace; @@ -9041,9 +9838,9 @@ create table t3 (a int, b int, c int); insert into t3 values (0,0,0),(1,1,1),(2,2,2),(3,3,3),(4,4,4); explain select * from t2,t1,t3 where t2.b= t1.b and t1.a=t3.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 2 -1 SIMPLE t1 index PRIMARY PRIMARY 12 NULL 5 Using where; Using index; Using join buffer (flat, BNL join) -1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (incremental, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL 5 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t1 ref PRIMARY PRIMARY 8 test.t3.a,test.t2.b 1 Using index set @trace=(select trace from information_schema.optimizer_trace); set @path= (select json_search(@trace, 'one', 'no predicate for first keypart')); set @sub_path= substr(@path, 2, locate('.best_access_path', @path)-2); @@ -9253,6 +10050,10 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting')) "table": "t2", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ @@ -9262,10 +10063,7 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting')) "used_range_estimates": false, "cause": "not available", "rows": 1.8367, - "found_matching_rows_cost": 2.367925794, - "startup_cost": 0, - "rows": 1.8367, - "cost": 2.367925794, + "cost": 1.417925794, "chosen": true }, @@ -9279,12 +10077,12 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting')) { "type": "ref", "records": 1.8367, - "cost": 2.367925794, + "cost": 1.417925794, "uses_join_buffering": false } }, "rows_for_plan": 1.8367, - "cost_for_plan": 2.735265794, + "cost_for_plan": 1.417925794, "cost_for_sorting": 1.8367, "estimated_join_cardinality": 1.8367 } @@ -9297,8 +10095,8 @@ json_detailed(json_extract(trace, '$**.choose_best_splitting')) "table": "t2", "key": "idx_a", "record_count": 4, - "cost": 2.856285919, - "unsplit_cost": 43.72361682 + "cost": 3.651150919, + "unsplit_cost": 51.1794762 } } ] @@ -9311,8 +10109,8 @@ json_detailed(json_extract(trace, '$**.lateral_derived')) [ { - "startup_cost": 11.42514368, - "splitting_cost": 2.856285919, + "startup_cost": 14.60460368, + "splitting_cost": 3.651150919, "records": 1 } ] diff --git a/mysql-test/main/opt_trace_index_merge.result b/mysql-test/main/opt_trace_index_merge.result index ee9ad1be2ba..a729ca9ea71 100644 --- a/mysql-test/main/opt_trace_index_merge.result +++ b/mysql-test/main/opt_trace_index_merge.result @@ -73,7 +73,7 @@ explain select * from t1 where a=1 or b=1 { "range_analysis": { "table_scan": { "rows": 1000, - "cost": 231.5878906 + "cost": 264.7939453 }, "potential_range_indexes": [ { @@ -111,12 +111,12 @@ explain select * from t1 where a=1 or b=1 { "using_mrr": false, "index_only": true, "rows": 1, - "cost": 0.345585794, + "cost": 0.745585794, "chosen": true } ], "index_to_merge": "a", - "cumulated_cost": 0.345585794 + "cumulated_cost": 0.745585794 }, { "range_scan_alternatives": [ @@ -127,15 +127,15 @@ explain select * from t1 where a=1 or b=1 { "using_mrr": false, "index_only": true, "rows": 1, - "cost": 0.345585794, + "cost": 0.745585794, "chosen": true } ], "index_to_merge": "b", - "cumulated_cost": 0.691171589 + "cumulated_cost": 1.491171589 } ], - "cost_of_reading_ranges": 0.691171589, + "cost_of_reading_ranges": 1.491171589, "use_roworder_union": true, "cause": "always cheaper than non roworder retrieval", "analyzing_roworder_scans": [ @@ -158,7 +158,7 @@ explain select * from t1 where a=1 or b=1 { } } ], - "index_roworder_union_cost": 2.484903732, + "index_roworder_union_cost": 2.595171589, "members": 2, "chosen": true } @@ -187,7 +187,7 @@ explain select * from t1 where a=1 or b=1 { ] }, "rows_for_plan": 2, - "cost_for_plan": 2.484903732, + "cost_for_plan": 2.595171589, "chosen": true } } @@ -209,23 +209,28 @@ explain select * from t1 where a=1 or b=1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "index_merge", - "resulting_rows": 2, - "cost": 2.484903732, + "rows": 2, + "rows_after_scan": 2, + "rows_after_filter": 2, + "cost": 2.595171589, "chosen": true } ], "chosen_access_method": { "type": "index_merge", "records": 2, - "cost": 2.484903732, + "cost": 2.595171589, "uses_join_buffering": false } }, "rows_for_plan": 2, - "cost_for_plan": 2.884903732, + "cost_for_plan": 2.595171589, "estimated_join_cardinality": 2 } ] @@ -233,7 +238,8 @@ explain select * from t1 where a=1 or b=1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 2.883903732 + "rows": 2, + "cost": 2.595171589 } }, { @@ -315,7 +321,7 @@ set optimizer_trace='enabled=on'; # 3-way ROR-intersection explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 index_merge key1,key2,key3 key1,key2,key3 5,5,5 NULL 2 Using intersect(key1,key2,key3); Using where; Using index +1 SIMPLE t1 index_merge key1,key2,key3 key1,key2 5,5 NULL 77 Using intersect(key1,key2); Using where select JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) [ @@ -334,7 +340,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 2243, - "cost": 2700.058937, + "cost": 1695.083937, "chosen": true }, @@ -348,7 +354,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 2243, - "cost": 2700.058937, + "cost": 1695.083937, "chosen": false, "cause": "cost" }, @@ -363,7 +369,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 2243, - "cost": 2700.058937, + "cost": 1695.083937, "chosen": false, "cause": "cost" } @@ -375,10 +381,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key1", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 10.31393703, - "disk_sweep_cost": 1923.144061, - "cumulative_total_cost": 1933.457998, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 61.88893703, + "disk_sweep_cost": 1682.25, + "cumulative_total_cost": 1744.138937, "usable": true, "matching_rows_now": 2243, "intersect_covering_with_this_index": false, @@ -387,10 +393,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key2", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 20.62787405, - "disk_sweep_cost": 84.51771758, - "cumulative_total_cost": 105.1455916, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 123.7778741, + "disk_sweep_cost": 57.75, + "cumulative_total_cost": 181.5278741, "usable": true, "matching_rows_now": 77.6360508, "intersect_covering_with_this_index": false, @@ -399,14 +405,15 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key3", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 30.94181108, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 185.6668111, "disk_sweep_cost": 0, - "cumulative_total_cost": 30.94181108, + "cumulative_total_cost": 185.6668111, "usable": true, "matching_rows_now": 2.687185191, "intersect_covering_with_this_index": true, - "chosen": true + "chosen": false, + "cause": "does not reduce cost" } ], "clustered_pk": @@ -414,9 +421,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "clustered_pk_added_to_intersect": false, "cause": "no clustered pk index" }, - "rows": 2, - "cost": 30.94181108, - "covering": true, + "rows": 77, + "cost": 197.0550842, + "covering": false, "chosen": true }, "analyzing_index_merge_union": @@ -432,9 +439,9 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) "range_access_plan": { "type": "index_roworder_intersect", - "rows": 2, - "cost": 30.94181108, - "covering": true, + "rows": 77, + "cost": 197.0550842, + "covering": false, "clustered_pk_scan": false, "intersect_of": [ @@ -457,21 +464,11 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) [ "(100) <= (key2) <= (100)" ] - }, - - { - "type": "range_scan", - "index": "key3", - "rows": 2243, - "ranges": - [ - "(100) <= (key3) <= (100)" - ] } ] }, - "rows_for_plan": 2, - "cost_for_plan": 30.94181108, + "rows_for_plan": 77, + "cost_for_plan": 197.0550842, "chosen": true } ] @@ -512,7 +509,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": true, "rows": 2243, - "cost": 457.058937, + "cost": 517.508937, "chosen": true }, @@ -526,13 +523,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": true, "rows": 2243, - "cost": 457.058937, + "cost": 517.508937, "chosen": false, "cause": "cost" } ], "index_to_merge": "key1", - "cumulated_cost": 457.058937 + "cumulated_cost": 517.508937 }, { @@ -549,7 +546,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": true, "rows": 2243, - "cost": 457.058937, + "cost": 517.508937, "chosen": true }, @@ -563,16 +560,16 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": true, "rows": 2243, - "cost": 457.058937, + "cost": 517.508937, "chosen": false, "cause": "cost" } ], "index_to_merge": "key3", - "cumulated_cost": 914.1178741 + "cumulated_cost": 1035.017874 } ], - "cost_of_reading_ranges": 914.1178741, + "cost_of_reading_ranges": 1035.017874, "use_roworder_union": true, "cause": "always cheaper than non roworder retrieval", "analyzing_roworder_scans": @@ -593,10 +590,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key1", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 10.31393703, - "disk_sweep_cost": 1923.144061, - "cumulative_total_cost": 1933.457998, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 61.88893703, + "disk_sweep_cost": 1682.25, + "cumulative_total_cost": 1744.138937, "usable": true, "matching_rows_now": 2243, "intersect_covering_with_this_index": false, @@ -605,10 +602,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key2", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 20.62787405, - "disk_sweep_cost": 84.51771758, - "cumulative_total_cost": 105.1455916, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 123.7778741, + "disk_sweep_cost": 57.75, + "cumulative_total_cost": 181.5278741, "usable": true, "matching_rows_now": 77.6360508, "intersect_covering_with_this_index": false, @@ -621,7 +618,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "cause": "no clustered pk index" }, "rows": 77, - "cost": 105.1455916, + "cost": 197.0550842, "covering": false, "chosen": true } @@ -642,10 +639,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key3", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 10.31393703, - "disk_sweep_cost": 1923.144061, - "cumulative_total_cost": 1933.457998, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 61.88893703, + "disk_sweep_cost": 1682.25, + "cumulative_total_cost": 1744.138937, "usable": true, "matching_rows_now": 2243, "intersect_covering_with_this_index": false, @@ -654,10 +651,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) { "index": "key4", - "index_scan_cost": 10.31393703, - "cumulated_index_scan_cost": 20.62787405, - "disk_sweep_cost": 84.51771758, - "cumulative_total_cost": 105.1455916, + "index_scan_cost": 61.88893703, + "cumulated_index_scan_cost": 123.7778741, + "disk_sweep_cost": 57.75, + "cumulative_total_cost": 181.5278741, "usable": true, "matching_rows_now": 77.6360508, "intersect_covering_with_this_index": false, @@ -670,13 +667,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "cause": "no clustered pk index" }, "rows": 77, - "cost": 105.1455916, + "cost": 197.0550842, "covering": false, "chosen": true } } ], - "index_roworder_union_cost": 194.9771115, + "index_roworder_union_cost": 332.5637481, "members": 2, "chosen": true } @@ -697,7 +694,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) { "type": "index_roworder_intersect", "rows": 77, - "cost": 105.1455916, + "cost": 197.0550842, "covering": false, "clustered_pk_scan": false, "intersect_of": @@ -728,7 +725,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) { "type": "index_roworder_intersect", "rows": 77, - "cost": 105.1455916, + "cost": 197.0550842, "covering": false, "clustered_pk_scan": false, "intersect_of": @@ -758,7 +755,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary')) ] }, "rows_for_plan": 154, - "cost_for_plan": 194.9771115, + "cost_for_plan": 332.5637481, "chosen": true } ] diff --git a/mysql-test/main/opt_trace_index_merge_innodb.result b/mysql-test/main/opt_trace_index_merge_innodb.result index d3081bd6b9d..1569f3763b4 100644 --- a/mysql-test/main/opt_trace_index_merge_innodb.result +++ b/mysql-test/main/opt_trace_index_merge_innodb.result @@ -88,7 +88,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "range_analysis": { "table_scan": { "rows": 1000, - "cost": 206 + "cost": 253 }, "potential_range_indexes": [ { @@ -117,7 +117,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "using_mrr": false, "index_only": false, "rows": 1000, - "cost": 204.27, + "cost": 252.02, "chosen": true }, { @@ -127,7 +127,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "using_mrr": false, "index_only": false, "rows": 1, - "cost": 1.345146475, + "cost": 1.270146475, "chosen": true } ], @@ -135,10 +135,10 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "intersecting_indexes": [ { "index": "key1", - "index_scan_cost": 1.000146475, - "cumulated_index_scan_cost": 1.000146475, - "disk_sweep_cost": 1.004153686, - "cumulative_total_cost": 2.004300162, + "index_scan_cost": 0.525146475, + "cumulated_index_scan_cost": 0.525146475, + "disk_sweep_cost": 0.752076843, + "cumulative_total_cost": 1.277223319, "usable": true, "matching_rows_now": 1, "intersect_covering_with_this_index": false, @@ -166,7 +166,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "ranges": ["(1) <= (key1) <= (1)"] }, "rows_for_plan": 1, - "cost_for_plan": 1.345146475, + "cost_for_plan": 1.270146475, "chosen": true } } @@ -176,7 +176,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "rowid_filters": [ { "key": "key1", - "build_cost": 0.130146475, + "build_cost": 0.526146475, "rows": 1 } ] @@ -203,16 +203,16 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "ref", "index": "key1", "used_range_estimates": true, "rows": 1, - "found_matching_rows_cost": 1.325146475, - "startup_cost": 0, - "rows": 1, - "cost": 1.325146475, + "cost": 1.250146475, "chosen": true }, { @@ -224,12 +224,12 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { "chosen_access_method": { "type": "ref", "records": 1, - "cost": 1.325146475, + "cost": 1.250146475, "uses_join_buffering": false } }, "rows_for_plan": 1, - "cost_for_plan": 1.525146475, + "cost_for_plan": 1.250146475, "estimated_join_cardinality": 1 } ] @@ -237,7 +237,8 @@ explain select * from t1 where pk1 != 0 and key1 = 1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 1.524146475 + "rows": 1, + "cost": 1.250146475 } }, { diff --git a/mysql-test/main/opt_trace_security.result b/mysql-test/main/opt_trace_security.result index d9e5fbee5ef..9caf2309261 100644 --- a/mysql-test/main/opt_trace_security.result +++ b/mysql-test/main/opt_trace_security.result @@ -80,7 +80,8 @@ select * from db1.t1 { "table": "t1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } } ] @@ -91,23 +92,29 @@ select * from db1.t1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "estimated_join_cardinality": 3 } ] @@ -115,7 +122,8 @@ select * from db1.t1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 3.204126953 + "rows": 3, + "cost": 1.902563477 } }, { @@ -205,7 +213,8 @@ select * from db1.v1 { "table": "t1", "table_scan": { "rows": 3, - "cost": 2.005126953 + "read_cost": 1.152563477, + "read_and_compare_cost": 1.902563477 } } ] @@ -216,23 +225,29 @@ select * from db1.v1 { "plan_prefix": [], "table": "t1", "best_access_path": { + "plan_details": { + "record_count": 1 + }, "considered_access_paths": [ { "access_type": "scan", - "resulting_rows": 3, - "cost": 2.605126953, + "rows": 3, + "rows_after_scan": 3, + "rows_after_filter": 3, + "cost": 1.902563477, + "index_only": false, "chosen": true } ], "chosen_access_method": { "type": "scan", "records": 3, - "cost": 2.605126953, + "cost": 1.902563477, "uses_join_buffering": false } }, "rows_for_plan": 3, - "cost_for_plan": 3.205126953, + "cost_for_plan": 1.902563477, "estimated_join_cardinality": 3 } ] @@ -240,7 +255,8 @@ select * from db1.v1 { { "best_join_order": ["t1"], "best_access_method": { - "cost": 3.204126953 + "rows": 3, + "cost": 1.902563477 } }, { diff --git a/mysql-test/main/opt_trace_selectivity.result b/mysql-test/main/opt_trace_selectivity.result index 8d1f50ff48d..dc850c7ca1d 100644 --- a/mysql-test/main/opt_trace_selectivity.result +++ b/mysql-test/main/opt_trace_selectivity.result @@ -42,6 +42,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "t1", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ @@ -50,10 +54,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "a", "used_range_estimates": true, "rows": 104, - "found_matching_rows_cost": 124.96562, - "startup_cost": 0, - "rows": 104, - "cost": 124.96562, + "cost": 78.54062004, "chosen": true }, @@ -62,10 +63,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "b", "used_range_estimates": true, "rows": 340, - "found_matching_rows_cost": 408.2577963, - "startup_cost": 0, - "rows": 340, - "cost": 408.2577963, + "cost": 255.6327963, "chosen": false, "cause": "cost" }, @@ -75,18 +73,17 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "c", "used_range_estimates": true, "rows": 632, - "found_matching_rows_cost": 758.7718449, - "startup_cost": 0, - "rows": 632, - "cost": 758.7718449, + "cost": 475.2468449, "chosen": false, "cause": "cost" }, { "access_type": "index_merge", - "resulting_rows": 7, - "cost": 2.173416331, + "rows": 7, + "rows_after_scan": 7, + "rows_after_filter": 7, + "cost": 13.79559815, "chosen": true } ], @@ -94,12 +91,12 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) { "type": "index_merge", "records": 7, - "cost": 2.173416331, + "cost": 13.79559815, "uses_join_buffering": false } }, "rows_for_plan": 7, - "cost_for_plan": 3.573416331, + "cost_for_plan": 13.79559815, "estimated_join_cardinality": 7 } ] @@ -141,6 +138,10 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "table": "t1", "best_access_path": { + "plan_details": + { + "record_count": 1 + }, "considered_access_paths": [ @@ -149,10 +150,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "a", "used_range_estimates": true, "rows": 6, - "found_matching_rows_cost": 7.327343464, - "startup_cost": 0, - "rows": 6, - "cost": 7.327343464, + "cost": 5.002343464, "chosen": true }, @@ -161,10 +159,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "b", "used_range_estimates": true, "rows": 232, - "found_matching_rows_cost": 278.6156139, - "startup_cost": 0, - "rows": 232, - "cost": 278.6156139, + "cost": 174.5906139, "chosen": false, "cause": "cost" }, @@ -174,32 +169,30 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) "index": "c", "used_range_estimates": true, "rows": 293, - "found_matching_rows_cost": 351.8394392, - "startup_cost": 0, - "rows": 293, - "cost": 351.8394392, + "cost": 220.3644392, "chosen": false, "cause": "cost" }, { - "access_type": "index_merge", - "resulting_rows": 1, - "cost": 2.092957403, - "chosen": true + "type": "scan", + "chosen": false, + "cause": "cost" } ], "chosen_access_method": { - "type": "index_merge", - "records": 1, - "cost": 2.092957403, + "type": "ref", + "records": 6, + "cost": 5.002343464, "uses_join_buffering": false } }, - "rows_for_plan": 1, - "cost_for_plan": 2.292957403, - "estimated_join_cardinality": 1 + "rows_for_plan": 6, + "cost_for_plan": 5.002343464, + "selectivity": 0.1, + "remaining_rows_for_plan": 0.6, + "estimated_join_cardinality": 0.6 } ] ] diff --git a/mysql-test/main/opt_trace_selectivity.test b/mysql-test/main/opt_trace_selectivity.test index 4d59d4974cd..3ebf4d97ed9 100644 --- a/mysql-test/main/opt_trace_selectivity.test +++ b/mysql-test/main/opt_trace_selectivity.test @@ -19,7 +19,9 @@ select count(*) from t1 where c=5 and b=5; set optimizer_trace="enabled=on"; select count(*) from t1 where a=2 and b=5 and c=10; + select JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; + select JSON_DETAILED(JSON_EXTRACT(trace, '$**.selectivity_for_indexes')) from INFORMATION_SCHEMA.OPTIMIZER_TRACE; select count(*) from t1 where a=2 and b=5 and c=5; diff --git a/mysql-test/main/opt_trace_ucs2.result b/mysql-test/main/opt_trace_ucs2.result index 5de1fc5c3e9..c4b36902bce 100644 --- a/mysql-test/main/opt_trace_ucs2.result +++ b/mysql-test/main/opt_trace_ucs2.result @@ -38,7 +38,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives')) "using_mrr": false, "index_only": false, "rows": 2, - "cost": 2.547733708, + "cost": 2.022733708, "chosen": true } ], diff --git a/mysql-test/main/opt_tvc.result b/mysql-test/main/opt_tvc.result index a68e70e8a25..60782fe5db8 100644 --- a/mysql-test/main/opt_tvc.result +++ b/mysql-test/main/opt_tvc.result @@ -444,7 +444,7 @@ where b in (3,5) group by b ) as dr_table; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort 2 DERIVED <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00 @@ -464,7 +464,7 @@ as tvc_0 group by b ) as dr_table; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY <derived2> ALL NULL NULL NULL NULL 12 100.00 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 100.00 2 DERIVED t1 ALL NULL NULL NULL NULL 6 100.00 Using temporary; Using filesort 2 DERIVED <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 3 MATERIALIZED <derived4> ALL NULL NULL NULL NULL 2 100.00 @@ -526,7 +526,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` semi join ((values (1,2),(3,4)) `tvc_0`) where 1 set @@in_predicate_conversion_threshold= 2; -# trasformation works for the one IN predicate and doesn't work for the other +# transformation works for the one IN predicate and doesn't work for the other set @@in_predicate_conversion_threshold= 5; select * from t2 where (a,b) in ((1,2),(8,9)) and @@ -539,11 +539,10 @@ where (a,b) in ((1,2),(8,9)) and (a,c) in ((1,3),(8,0),(5,1)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00 -2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <derived3> ref key0 key0 8 test.t2.a,test.t2.c 2 100.00 FirstMatch(t2) 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` semi join ((values (1,3),(8,0),(5,1)) `tvc_0`) where (`test`.`t2`.`a`,`test`.`t2`.`b`) in (<cache>((1,2)),<cache>((8,9))) +Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` semi join ((values (1,3),(8,0),(5,1)) `tvc_0`) where `tvc_0`.`_col_1` = `test`.`t2`.`a` and `tvc_0`.`_col_2` = `test`.`t2`.`c` and (`test`.`t2`.`a`,`test`.`t2`.`b`) in (<cache>((1,2)),<cache>((8,9))) set @@in_predicate_conversion_threshold= 2; # # mdev-14281: conversion of NOT IN predicate into subquery predicate @@ -568,18 +567,18 @@ explain extended select * from t1 where (a,b) not in ((1,2),(8,9), (5,1)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where -2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `tvc_0`.`_col_1`,`tvc_0`.`_col_2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`_col_1` and `test`.`t1`.`b` = `<subquery2>`.`_col_2`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t1`.`a`) = `tvc_0`.`_col_1`) and trigcond(<cache>(`test`.`t1`.`b`) = `tvc_0`.`_col_2`))))) explain extended select * from t1 where (a,b) not in (select * from (values (1,2),(8,9), (5,1)) as tvc_0); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where -2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `tvc_0`.`1`,`tvc_0`.`2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`1` and `test`.`t1`.`b` = `<subquery2>`.`2`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t1`.`a`) = `tvc_0`.`1`) and trigcond(<cache>(`test`.`t1`.`b`) = `tvc_0`.`2`))))) select * from t1 where b < 7 and (a,b) not in ((1,2),(8,9), (5,1)); a b @@ -590,10 +589,10 @@ explain extended select * from t1 where b < 7 and (a,b) not in ((1,2),(8,9), (5,1)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 6 100.00 Using where -2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` < 7 and !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),(`test`.`t1`.`a`,`test`.`t1`.`b`) in ( <materialize> (/* select#2 */ select `tvc_0`.`_col_1`,`tvc_0`.`_col_2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`_col_1` and `test`.`t1`.`b` = `<subquery2>`.`_col_2`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` < 7 and !<expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>((`test`.`t1`.`a`,`test`.`t1`.`b`),<exists>(<index_lookup>(<cache>(`test`.`t1`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t1`.`a`) = `tvc_0`.`_col_1`) and trigcond(<cache>(`test`.`t1`.`b`) = `tvc_0`.`_col_2`))))) select * from t2 where (a,c) not in ((1,2),(8,9), (5,1)); a b c @@ -606,10 +605,10 @@ explain extended select * from t2 where (a,c) not in ((1,2),(8,9), (5,1)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where -2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY <derived3> index_subquery key0 key0 8 func,func 2 100.00 Using where; Full scan on NULL key 3 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: -Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`c`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`c`),(`test`.`t2`.`a`,`test`.`t2`.`c`) in ( <materialize> (/* select#2 */ select `tvc_0`.`_col_1`,`tvc_0`.`_col_2` from (values (1,2),(8,9),(5,1)) `tvc_0` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`_col_1` and `test`.`t2`.`c` = `<subquery2>`.`_col_2`)))) +Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t2`.`c` AS `c` from `test`.`t2` where !<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`c`>(<in_optimizer>((`test`.`t2`.`a`,`test`.`t2`.`c`),<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in (temporary) on key0 where trigcond(<cache>(`test`.`t2`.`a`) = `tvc_0`.`_col_1`) and trigcond(<cache>(`test`.`t2`.`c`) = `tvc_0`.`_col_2`))))) drop table t1, t2, t3; set @@in_predicate_conversion_threshold= default; # diff --git a/mysql-test/main/opt_tvc.test b/mysql-test/main/opt_tvc.test index e4e8c6d7919..e07a7be67c7 100644 --- a/mysql-test/main/opt_tvc.test +++ b/mysql-test/main/opt_tvc.test @@ -276,7 +276,7 @@ eval $query; eval explain extended $query; set @@in_predicate_conversion_threshold= 2; ---echo # trasformation works for the one IN predicate and doesn't work for the other +--echo # transformation works for the one IN predicate and doesn't work for the other set @@in_predicate_conversion_threshold= 5; diff --git a/mysql-test/main/order_by.result b/mysql-test/main/order_by.result index 153cccf822e..70f21cacc98 100644 --- a/mysql-test/main/order_by.result +++ b/mysql-test/main/order_by.result @@ -1193,7 +1193,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index k2 k3 5 NULL 111 Using where EXPLAIN SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 index k2 k3 5 NULL 22318 Using where +1 SIMPLE t2 ref k2 k2 5 const 7341 Using where; Using filesort EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 10 AND 12 ORDER BY c3 LIMIT 20; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 index k2 k3 5 NULL 73 Using where @@ -1222,6 +1222,10 @@ id c3 176 14 186 14 196 14 +ALTER TABLE t2 DROP INDEX k3, ADD INDEX k3 (c3,c2); +EXPLAIN SELECT c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index k2 k3 10 NULL 22318 Using where; Using index DROP TABLE t1,t2; CREATE TABLE t1 ( a INT, @@ -1552,11 +1556,17 @@ INSERT INTO t1 VALUES (1, 10), (2, NULL); EXPLAIN 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 -1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort +1 SIMPLE t1 range a_c,a a_c 10 NULL 2 Using where; Using index # Must return 1 row SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; col 1 +# With more rows "range" changes to "ref_or_null" +INSERT INTO t1 select seq,seq from seq_1_to_10; +EXPLAIN +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 +1 SIMPLE t1 ref_or_null a_c,a a_c 10 const,const 2 Using where; Using index; Using filesort # Must use ref-or-null on the a_c index EXPLAIN SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c DESC; @@ -3408,10 +3418,9 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "r_limit": 5, - "r_used_priority_queue": false, - "r_output_rows": 100, - "r_buffer_size": "REPLACED", - "r_sort_mode": "sort_key,packed_addon_fields", + "r_used_priority_queue": true, + "r_output_rows": 6, + "r_sort_mode": "sort_key,rowid", "table": { "table_name": "t1", "access_type": "ALL", @@ -3447,7 +3456,7 @@ CREATE TABLE t2 SELECT * FROM t1; EXPLAIN SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 -2 DEPENDENT SUBQUERY t1 index PRIMARY b 5 NULL 1 Using where +2 DEPENDENT SUBQUERY t1 eq_ref PRIMARY PRIMARY 4 test.t2.b 1 Using where SELECT (SELECT 1 FROM t1 WHERE t1.a=t2.b ORDER BY t1.b LIMIT 1) AS c FROM t2; c 1 @@ -3495,11 +3504,10 @@ WHERE books.library_id = 8663 AND books.scheduled_for_removal=0 ) ORDER BY wings.id; id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 100.00 Using filesort -1 PRIMARY wings eq_ref PRIMARY PRIMARY 4 test.books.wings_id 1 100.00 -2 MATERIALIZED books ref library_idx library_idx 4 const 2 100.00 Using where +1 PRIMARY wings ALL PRIMARY NULL NULL NULL 2 100.00 Using temporary; Using filesort +1 PRIMARY books ALL library_idx NULL NULL NULL 2 100.00 Using where; FirstMatch(wings); Using join buffer (flat, BNL join) Warnings: -Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`wings`.`id` = `test`.`books`.`wings_id` order by `test`.`wings`.`id` +Note 1003 select `test`.`wings`.`id` AS `wing_id`,`test`.`wings`.`department_id` AS `department_id` from `test`.`wings` semi join (`test`.`books`) where `test`.`books`.`library_id` = 8663 and `test`.`books`.`scheduled_for_removal` = 0 and `test`.`books`.`wings_id` = `test`.`wings`.`id` order by `test`.`wings`.`id` set optimizer_switch= @save_optimizer_switch; DROP TABLE books, wings; # diff --git a/mysql-test/main/order_by.test b/mysql-test/main/order_by.test index 9ad0af1d21f..70cf10df446 100644 --- a/mysql-test/main/order_by.test +++ b/mysql-test/main/order_by.test @@ -3,6 +3,7 @@ # call mtr.add_suppression("Sort aborted.*"); +--source include/have_sequence.inc --disable_warnings drop table if exists t1,t2,t3; @@ -804,6 +805,10 @@ EXPLAIN SELECT id,c3 FROM t2 WHERE c2 BETWEEN 20 AND 30 ORDER BY c3 LIMIT 4000; SELECT id,c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 20; +# Show that order by optimization takes into account index only scans +ALTER TABLE t2 DROP INDEX k3, ADD INDEX k3 (c3,c2); +EXPLAIN SELECT c3 FROM t2 WHERE c2=11 ORDER BY c3 LIMIT 4000; + DROP TABLE t1,t2; # @@ -913,6 +918,11 @@ SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; --echo # Must return 1 row SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; +--echo # With more rows "range" changes to "ref_or_null" +INSERT INTO t1 select seq,seq from seq_1_to_10; +EXPLAIN +SELECT 1 AS col FROM t1 WHERE a=2 AND (c=10 OR c IS NULL) ORDER BY c; + # part 2 of the problem : DESC test cases --echo # Must use ref-or-null on the a_c index --replace_column 1 x 2 x 3 x 6 x 7 x 8 x 9 x 10 x diff --git a/mysql-test/main/order_by_innodb.result b/mysql-test/main/order_by_innodb.result index 14b9b861a14..d157297bb5f 100644 --- a/mysql-test/main/order_by_innodb.result +++ b/mysql-test/main/order_by_innodb.result @@ -61,17 +61,29 @@ KEY a_c (a,c), KEY a_b (a,b) ) ENGINE=InnoDB; insert into t1 select A.a , B.a, C.a from t0 A, t0 B, t0 C; +select count(*) from t1; +count(*) +1000 +select count(*) from t1 where a=1; +count(*) +200 +select count(*) from t1 where a=1 and c=2; +count(*) +20 # should use ref access explain select a,b,c from t1 where a=1 and c=2 order by b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort -# both should use range access -explain select a,b,c from t1 where a=1 and c=2 order by b limit 1000; +# all should use range access +explain select a,b,c from t1 where a=1 and c=2 order by b limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort +explain select a,b,c from t1 where a=1 and c=2 order by b limit 300; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a_c,a_b a_b 5 NULL 200 Using where -explain select a,b,c from t1 where a=1 and c=2 order by b limit 2000; +1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort +explain select a,b,c from t1 where a=1 and c=2 order by b limit 1000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a_c,a_b a_b 5 NULL 200 Using where +1 SIMPLE t1 ref a_c,a_b a_c 10 const,const 20 Using where; Using filesort drop table t1,t0; # Start of 10.2 tests # diff --git a/mysql-test/main/order_by_innodb.test b/mysql-test/main/order_by_innodb.test index 97c043b8dbc..b4ea2de8b05 100644 --- a/mysql-test/main/order_by_innodb.test +++ b/mysql-test/main/order_by_innodb.test @@ -77,13 +77,17 @@ KEY a_c (a,c), KEY a_b (a,b) ) ENGINE=InnoDB; insert into t1 select A.a , B.a, C.a from t0 A, t0 B, t0 C; +select count(*) from t1; +select count(*) from t1 where a=1; +select count(*) from t1 where a=1 and c=2; --echo # should use ref access explain select a,b,c from t1 where a=1 and c=2 order by b; ---echo # both should use range access +--echo # all should use range access +explain select a,b,c from t1 where a=1 and c=2 order by b limit 10; +explain select a,b,c from t1 where a=1 and c=2 order by b limit 300; explain select a,b,c from t1 where a=1 and c=2 order by b limit 1000; -explain select a,b,c from t1 where a=1 and c=2 order by b limit 2000; drop table t1,t0; --echo # Start of 10.2 tests diff --git a/mysql-test/main/order_by_sortkey.result b/mysql-test/main/order_by_sortkey.result index c1d9609eb47..853823f5f61 100644 --- a/mysql-test/main/order_by_sortkey.result +++ b/mysql-test/main/order_by_sortkey.result @@ -40,6 +40,9 @@ INSERT INTO tmp SELECT f1,f2 FROM t1; INSERT INTO t1(f1,f2) SELECT * FROM tmp; INSERT INTO tmp SELECT f1,f2 FROM t1; INSERT INTO t1(f1,f2) SELECT * FROM tmp; +select count(*) from t1; +count(*) +87700 set sort_buffer_size= 32768; FLUSH STATUS; SHOW SESSION STATUS LIKE 'Sort%'; @@ -49,6 +52,9 @@ Sort_priority_queue_sorts 0 Sort_range 0 Sort_rows 0 Sort_scan 0 +explain SELECT * FROM t1 ORDER BY f2 LIMIT 100; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 87700 Using filesort SELECT * FROM t1 ORDER BY f2 LIMIT 100; f0 f1 f2 1 0 0 @@ -158,4 +164,9 @@ Sort_priority_queue_sorts 1 Sort_range 0 Sort_rows 100 Sort_scan 1 +SHOW STATUS LIKE 'Handler_read_rnd%'; +Variable_name Value +Handler_read_rnd 100 +Handler_read_rnd_deleted 0 +Handler_read_rnd_next 87701 DROP TABLE t1, tmp; diff --git a/mysql-test/main/order_by_sortkey.test b/mysql-test/main/order_by_sortkey.test index 43de028496e..d3f8ba396d8 100644 --- a/mysql-test/main/order_by_sortkey.test +++ b/mysql-test/main/order_by_sortkey.test @@ -50,6 +50,7 @@ INSERT INTO tmp SELECT f1,f2 FROM t1; INSERT INTO t1(f1,f2) SELECT * FROM tmp; INSERT INTO tmp SELECT f1,f2 FROM t1; INSERT INTO t1(f1,f2) SELECT * FROM tmp; +select count(*) from t1; # Test when only sortkeys fits to memory set sort_buffer_size= 32768; @@ -57,8 +58,12 @@ set sort_buffer_size= 32768; FLUSH STATUS; SHOW SESSION STATUS LIKE 'Sort%'; +explain SELECT * FROM t1 ORDER BY f2 LIMIT 100; SELECT * FROM t1 ORDER BY f2 LIMIT 100; +# Check that Sort_priority_queue_sorts is used SHOW SESSION STATUS LIKE 'Sort%'; +# Check that we did scan the whole table and did LIMIT lookups +SHOW STATUS LIKE 'Handler_read_rnd%'; DROP TABLE t1, tmp; diff --git a/mysql-test/main/partition_pruning.result b/mysql-test/main/partition_pruning.result index 519bf590b9b..cabcc2eada5 100644 --- a/mysql-test/main/partition_pruning.result +++ b/mysql-test/main/partition_pruning.result @@ -15,13 +15,13 @@ PARTITION max VALUES LESS THAN MAXVALUE); INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8); EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -# # # # # # # # # 3 # +# # # # range # # # # 3 # EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7; id select_type table partitions type possible_keys key key_len ref rows Extra -# # # # # # # # # 8 # +# # # # range # # # # 8 # EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -# # # # # # # # # 3 # +# # # # range # # # # 3 # DROP TABLE t1; # # Bug#49742: Partition Pruning not working correctly for RANGE @@ -2888,12 +2888,12 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where explain extended select * from t2 where b in (2,4,6); id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL b NULL NULL NULL 910 25.38 Using where +1 SIMPLE t2 range b b 5 NULL 231 100.00 Using where Warnings: Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` in (2,4,6) explain partitions select * from t2 where b in (2,4,6); id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where +1 SIMPLE t2 p0,p1,p2,p3,p4 range b b 5 NULL 231 Using where explain extended select * from t2 where b in (7,8,9); id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 ALL b NULL NULL NULL 910 36.81 Using where @@ -2912,12 +2912,12 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where explain extended select * from t2 where b > 5 and b < 8; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL b NULL NULL NULL 910 22.20 Using where +1 SIMPLE t2 range b b 5 NULL 202 100.00 Using where Warnings: Note 1003 select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2` where `test`.`t2`.`b` > 5 and `test`.`t2`.`b` < 8 explain partitions select * from t2 where b > 5 and b < 8; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t2 p0,p1,p2,p3,p4 ALL b NULL NULL NULL 910 Using where +1 SIMPLE t2 p0,p1,p2,p3,p4 range b b 5 NULL 202 Using where explain extended select * from t2 where b > 5 and b < 7; id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 range b b 5 NULL 77 100.00 Using where @@ -2946,10 +2946,10 @@ flush status; update t2 set a = 111 where b in (5,6); show status like 'Handler_read_rnd_next'; Variable_name Value -Handler_read_rnd_next 915 +Handler_read_rnd_next 0 show status like 'Handler_read_key'; Variable_name Value -Handler_read_key 0 +Handler_read_key 10 flush status; update t2 set a = 222 where b = 7; show status like 'Handler_read_rnd_next'; @@ -3378,7 +3378,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1 const PRIMARY PRIMARY 8 const,const 1 EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 >= 1; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where +1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 > 1; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where @@ -3387,7 +3387,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1 range PRIMARY PRIMARY 8 NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 1 AND c2 <= 3; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where +1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 <= 3; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where @@ -3405,7 +3405,7 @@ id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 2 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 <= 4; id select_type table partitions type possible_keys key key_len ref rows Extra -1 SIMPLE t1 p1,p2 range PRIMARY PRIMARY 8 NULL 3 Using where +1 SIMPLE t1 p1,p2 ref PRIMARY PRIMARY 4 const 1 Using where EXPLAIN PARTITIONS SELECT * FROM t1 WHERE c1 = 2 AND c2 = 4; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 p2 const PRIMARY PRIMARY 8 const,const 1 @@ -3465,8 +3465,8 @@ select * from t1 where company_id = 1000 and dept_id in (select dept_id from t2 where COMPANY_ID = 1000); id select_type table partitions type possible_keys key key_len ref rows Extra -1 PRIMARY t2 p_1000 ref PRIMARY PRIMARY 8 const 3 Using index -1 PRIMARY t1 p_1000 ALL PRIMARY NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 p_1000 ref PRIMARY PRIMARY 8 const 6 Using where +1 PRIMARY t2 p_1000 eq_ref PRIMARY PRIMARY 16 const,test.t1.dept_id 1 Using index drop table t1,t2; # # MDEV-9505: Valgrind failure in SEL_ARG::store_min,find_used_partitions,... diff --git a/mysql-test/main/partition_pruning.test b/mysql-test/main/partition_pruning.test index d59f52be313..78924d27550 100644 --- a/mysql-test/main/partition_pruning.test +++ b/mysql-test/main/partition_pruning.test @@ -25,11 +25,11 @@ PARTITION max VALUES LESS THAN MAXVALUE); INSERT INTO t1 VALUES (-1),(0),(1),(2),(3),(4),(5),(6),(7),(8); ---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 # +--replace_column 1 # 2 # 3 # 4 # 6 # 7 # 8 # 9 # 11 # EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; ---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 # +--replace_column 1 # 2 # 3 # 4 # 6 # 7 # 8 # 9 # 11 # EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a < 7; ---replace_column 1 # 2 # 3 # 4 # 5 # 6 # 7 # 8 # 9 # 11 # +--replace_column 1 # 2 # 3 # 4 # 6 # 7 # 8 # 9 # 11 # EXPLAIN PARTITIONS SELECT * FROM t1 WHERE a <= 1; DROP TABLE t1; diff --git a/mysql-test/main/partition_range.result b/mysql-test/main/partition_range.result index 320a15fa5b5..2c6b735560c 100644 --- a/mysql-test/main/partition_range.result +++ b/mysql-test/main/partition_range.result @@ -9,11 +9,11 @@ COUNT(*) 3 EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index +1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by alter table t1 partition by hash(a) partitions 1; EXPLAIN SELECT a, MAX(b) FROM t1 WHERE a IN (10000, 1000000, 3000) GROUP BY a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 4 Using where; Using index +1 SIMPLE t1 range a a 5 NULL 3 Using where; Using index for group-by alter table t1 remove partitioning; insert into t1 (a,b) select seq,seq from seq_4001_to_4100; insert into t1 (a,b) select seq,seq from seq_10001_to_10100; diff --git a/mysql-test/main/ps_1general.result b/mysql-test/main/ps_1general.result index 05a40f54a52..3ccd4a69e2d 100644 --- a/mysql-test/main/ps_1general.result +++ b/mysql-test/main/ps_1general.result @@ -451,7 +451,7 @@ def Extra 253 255 14 N 1 39 8 id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using filesort SET @arg00=1 ; -prepare stmt1 from ' explain select a from t1 where a > ? order by b '; +prepare stmt1 from ' explain select a from t1 force index (primary) where a > ? order by b '; execute stmt1 using @arg00; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def id 8 3 1 Y 32928 0 63 diff --git a/mysql-test/main/ps_1general.test b/mysql-test/main/ps_1general.test index b0f408e3bcf..580fabf525d 100644 --- a/mysql-test/main/ps_1general.test +++ b/mysql-test/main/ps_1general.test @@ -437,8 +437,10 @@ prepare stmt3 from ' unlock tables ' ; ## Load/Unload table contents --let $datafile = $MYSQLTEST_VARDIR/tmp/data.txt +--disable_warnings --error 0,1 --remove_file $datafile +--enable_warnings --replace_result $MYSQLTEST_VARDIR <MYSQLTEST_VARDIR> eval prepare stmt1 from ' load data infile ''$datafile'' @@ -494,7 +496,7 @@ prepare stmt1 from ' explain select a from t1 order by b '; execute stmt1; --disable_metadata SET @arg00=1 ; -prepare stmt1 from ' explain select a from t1 where a > ? order by b '; +prepare stmt1 from ' explain select a from t1 force index (primary) where a > ? order by b '; --enable_metadata --replace_result 4096 4_OR_8_K 8192 4_OR_8_K execute stmt1 using @arg00; diff --git a/mysql-test/main/range.result b/mysql-test/main/range.result index e9a73cf0215..77058712fd5 100644 --- a/mysql-test/main/range.result +++ b/mysql-test/main/range.result @@ -252,7 +252,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref x x 5 const 1 Using index explain select count(*) from t1 where x in (1,2,3,4); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range x x 5 NULL 4 Using where; Using index +1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index drop table t1; CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1)); INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1); @@ -261,12 +261,12 @@ INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2); explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref j1 j1 4 const 1 Using index -1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) explain select * from t1 force index(i1), t2 force index(j1) where (t1.key1 <t2.keya + 1) and t2.keya=3; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref j1 j1 4 const 1 Using index -1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) DROP TABLE t1,t2; CREATE TABLE t1 ( a int(11) default NULL, @@ -281,7 +281,7 @@ INSERT INTO t1 VALUES (33,5),(33,5),(33,5),(33,5),(34,5),(35,5); EXPLAIN SELECT * FROM t1 WHERE a IN(1,2) AND b=5; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 2 (41%) Using index condition; Using where; Using rowid filter +1 SIMPLE t1 ref|filter a,b b|a 5|5 const 15 (5%) Using where; Using rowid filter SELECT * FROM t1 WHERE a IN(1,2) AND b=5; a b DROP TABLE t1; @@ -676,7 +676,7 @@ create table t1(a char(2), key(a(1))); insert into t1 values ('x'), ('xx'); explain select a from t1 where a > 'x'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 2 NULL 2 Using where +1 SIMPLE t1 ALL a NULL NULL NULL 2 Using where select a from t1 where a > 'x'; a xx @@ -1138,7 +1138,7 @@ INSERT INTO t1 VALUES ('A2','2005-12-01 08:00:00',1000); EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 3 Using index condition +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; item started price Warnings: @@ -1236,14 +1236,13 @@ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t2 (a int, b int, filler char(100)); insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A, t1 B, t1 C where A.a < 5; -insert into t2 select 1000, b, 'filler' from t2; +insert into t2 select 1000, b, 'filler' from t2 limit 250; alter table t2 add index (a,b); -select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z; -Z -In following EXPLAIN the access method should be ref, #rows~=500 (and not 2) +# In following EXPLAIN the access method should be ref, #rows~=250 +# (and not 2) when we are not using rowid-ordered scans explain select * from t2 where a=1000 and b<11; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ref a a 5 const 503 Using index condition +1 SIMPLE t2 range a a 10 NULL 253 Using index condition drop table t1, t2; CREATE TABLE t1( a INT, b INT, KEY( a, b ) ); CREATE TABLE t2( a INT, b INT, KEY( a, b ) ); @@ -2530,7 +2529,7 @@ insert into t2 values explain select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(2,2)); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 3 (60%) Using index condition; Using where; Using rowid filter +1 SIMPLE t2 range idx1,idx2 idx1 5 NULL 3 Using index condition; Using where 1 SIMPLE t1 ref idx idx 5 test.t2.d 8 explain format=json select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(2,2)); @@ -2545,16 +2544,8 @@ EXPLAIN "key": "idx1", "key_length": "5", "used_key_parts": ["d"], - "rowid_filter": { - "range": { - "key": "idx2", - "used_key_parts": ["e"] - }, - "rows": 12, - "selectivity_pct": 60 - }, "rows": 3, - "filtered": 60, + "filtered": 100, "index_condition": "t2.d is not null", "attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((2,2)))" }, @@ -2610,8 +2601,8 @@ insert into t2 values explain select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 8 (14%) Using index condition; Using where; Using rowid filter -1 SIMPLE t1 ref idx idx 5 test.t2.d 8 +1 SIMPLE t1 range idx idx 5 NULL 6 Using index condition +1 SIMPLE t2 ref|filter idx1,idx2 idx1|idx2 5|5 test.t1.a 12 (14%) Using where; Using rowid filter explain format=json select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1; EXPLAIN @@ -2619,12 +2610,24 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "t2", + "table_name": "t1", "access_type": "range", + "possible_keys": ["idx"], + "key": "idx", + "key_length": "5", + "used_key_parts": ["a"], + "rows": 6, + "filtered": 100, + "index_condition": "t1.a is not null" + }, + "table": { + "table_name": "t2", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], "key": "idx1", "key_length": "5", "used_key_parts": ["d"], + "ref": ["test.t1.a"], "rowid_filter": { "range": { "key": "idx2", @@ -2633,58 +2636,46 @@ EXPLAIN "rows": 15, "selectivity_pct": 14.42307692 }, - "rows": 8, + "rows": 12, "filtered": 14.42307663, - "index_condition": "t2.d is not null", - "attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1" - }, - "table": { - "table_name": "t1", - "access_type": "ref", - "possible_keys": ["idx"], - "key": "idx", - "key_length": "5", - "used_key_parts": ["a"], - "ref": ["test.t2.d"], - "rows": 8, - "filtered": 100 + "attached_condition": "(t1.a,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1" } } } select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1; a b c d e f -3 2 uuuw 3 3 i 3 2 uuua 3 3 i -3 3 zzzz 3 3 i -3 3 zyxw 3 3 i -3 3 zzza 3 3 i -3 3 zyxa 3 3 i -3 2 uuuw 3 3 i 3 2 uuua 3 3 i -3 3 zzzz 3 3 i +3 2 uuuw 3 3 i +3 2 uuuw 3 3 i +3 3 zyxa 3 3 i +3 3 zyxa 3 3 i +3 3 zyxw 3 3 i 3 3 zyxw 3 3 i 3 3 zzza 3 3 i -3 3 zyxa 3 3 i -7 7 xxxyy 7 7 h +3 3 zzza 3 3 i +3 3 zzzz 3 3 i +3 3 zzzz 3 3 i 7 7 xxxya 7 7 h -7 8 xxxxx 7 7 h +7 7 xxxyy 7 7 h 7 8 xxxxa 7 7 h +7 8 xxxxx 7 7 h prepare stmt from "select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1"; execute stmt; a b c d e f 3 2 uuuw 3 3 i -3 2 uuua 3 3 i -3 3 zzzz 3 3 i -3 3 zyxw 3 3 i -3 3 zzza 3 3 i -3 3 zyxa 3 3 i 3 2 uuuw 3 3 i 3 2 uuua 3 3 i +3 2 uuua 3 3 i 3 3 zzzz 3 3 i +3 3 zzzz 3 3 i +3 3 zyxw 3 3 i 3 3 zyxw 3 3 i 3 3 zzza 3 3 i +3 3 zzza 3 3 i +3 3 zyxa 3 3 i 3 3 zyxa 3 3 i 7 7 xxxyy 7 7 h 7 7 xxxya 7 7 h @@ -2693,17 +2684,17 @@ a b c d e f execute stmt; a b c d e f 3 2 uuuw 3 3 i -3 2 uuua 3 3 i -3 3 zzzz 3 3 i -3 3 zyxw 3 3 i -3 3 zzza 3 3 i -3 3 zyxa 3 3 i 3 2 uuuw 3 3 i 3 2 uuua 3 3 i +3 2 uuua 3 3 i +3 3 zzzz 3 3 i 3 3 zzzz 3 3 i 3 3 zyxw 3 3 i +3 3 zyxw 3 3 i +3 3 zzza 3 3 i 3 3 zzza 3 3 i 3 3 zyxa 3 3 i +3 3 zyxa 3 3 i 7 7 xxxyy 7 7 h 7 7 xxxya 7 7 h 7 8 xxxxx 7 7 h @@ -2715,8 +2706,8 @@ insert into t1 select * from t1; explain select * from t1,t2 where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range|filter idx1,idx2 idx1|idx2 5|5 NULL 7 (7%) Using index condition; Using where; Using rowid filter -1 SIMPLE t1 ref idx idx 5 test.t2.d 11 +1 SIMPLE t1 range idx idx 5 NULL 15 Using index condition +1 SIMPLE t2 ref|filter idx1,idx2 idx1|idx2 5|5 test.t1.a 12 (7%) Using where; Using rowid filter explain format=json select * from t1,t2 where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1; EXPLAIN @@ -2724,12 +2715,24 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "t2", + "table_name": "t1", "access_type": "range", + "possible_keys": ["idx"], + "key": "idx", + "key_length": "5", + "used_key_parts": ["a"], + "rows": 15, + "filtered": 100, + "index_condition": "t1.a is not null" + }, + "table": { + "table_name": "t2", + "access_type": "ref", "possible_keys": ["idx1", "idx2"], "key": "idx1", "key_length": "5", "used_key_parts": ["d"], + "ref": ["test.t1.a"], "rowid_filter": { "range": { "key": "idx2", @@ -2738,35 +2741,23 @@ EXPLAIN "rows": 7, "selectivity_pct": 6.730769231 }, - "rows": 7, - "filtered": 14.28571415, - "index_condition": "t2.d is not null", - "attached_condition": "(t2.d,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1" - }, - "table": { - "table_name": "t1", - "access_type": "ref", - "possible_keys": ["idx"], - "key": "idx", - "key_length": "5", - "used_key_parts": ["a"], - "ref": ["test.t2.d"], - "rows": 11, - "filtered": 100 + "rows": 12, + "filtered": 6.730769157, + "attached_condition": "(t1.a,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1" } } } select * from t1,t2 where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1; a b c d e f -7 7 xxxyy 7 7 h 7 7 xxxya 7 7 h -7 7 xxxyy 7 7 h 7 7 xxxya 7 7 h -7 8 xxxxx 7 7 h +7 7 xxxyy 7 7 h +7 7 xxxyy 7 7 h 7 8 xxxxa 7 7 h -7 8 xxxxx 7 7 h 7 8 xxxxa 7 7 h +7 8 xxxxx 7 7 h +7 8 xxxxx 7 7 h alter table t2 drop index idx1, drop index idx2, add index idx3(d,e); # join order: (t2,t1) with ref access of t1 # range access to t2 by 2-component keys for index idx3 @@ -2858,22 +2849,22 @@ EXPLAIN select * from t1,t2 where a = d and (a,e) in ((4,d+1),(7,d+1),(8,d+1)) and length(f) = 1; a b c d e f -4 3 zyx 4 5 a 4 3 zya 4 5 a -4 3 zyx 4 5 a 4 3 zya 4 5 a -4 5 ww 4 5 a +4 3 zyx 4 5 a +4 3 zyx 4 5 a 4 5 wa 4 5 a -4 5 ww 4 5 a 4 5 wa 4 5 a -7 7 xxxyy 7 8 b +4 5 ww 4 5 a +4 5 ww 4 5 a 7 7 xxxya 7 8 b -7 7 xxxyy 7 8 b 7 7 xxxya 7 8 b -7 8 xxxxx 7 8 b +7 7 xxxyy 7 8 b +7 7 xxxyy 7 8 b 7 8 xxxxa 7 8 b -7 8 xxxxx 7 8 b 7 8 xxxxa 7 8 b +7 8 xxxxx 7 8 b +7 8 xxxxx 7 8 b # join order: (t1,t2) with ref access of t2 # no range access explain select * from t1,t2 @@ -2912,14 +2903,14 @@ EXPLAIN select * from t1,t2 where a = d and (a,e) in ((e,d+1),(7,7),(8,8)) and length(f) = 1; a b c d e f -7 8 xxxxx 7 7 h -7 7 xxxyy 7 7 h -7 8 xxxxa 7 7 h 7 7 xxxya 7 7 h -7 8 xxxxx 7 7 h +7 7 xxxya 7 7 h +7 7 xxxyy 7 7 h 7 7 xxxyy 7 7 h 7 8 xxxxa 7 7 h -7 7 xxxya 7 7 h +7 8 xxxxa 7 7 h +7 8 xxxxx 7 7 h +7 8 xxxxx 7 7 h # join order: (t1,t2) with ref access of t2 # range access to t1 by 1-component keys for index idx explain select * from t1,t2 diff --git a/mysql-test/main/range.test b/mysql-test/main/range.test index 6d43ad9090d..0103dc34735 100644 --- a/mysql-test/main/range.test +++ b/mysql-test/main/range.test @@ -1024,7 +1024,7 @@ create table t2 (a int, b int, filler char(100)); insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A, t1 B, t1 C where A.a < 5; -insert into t2 select 1000, b, 'filler' from t2; +insert into t2 select 1000, b, 'filler' from t2 limit 250; alter table t2 add index (a,b); # t2 values # ( 1 , 10, 'filler') @@ -1032,13 +1032,14 @@ alter table t2 add index (a,b); # ( 3 , 10, 'filler') # (... , 10, 'filler') # ... -# (1000, 10, 'filler') - 500 times +# (1000, 10, 'filler') - 250 times -# 500 rows, 1 row +# 250 rows, 1 row -select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z; -explain select * from t2 where a=1000 and b<11; +--echo # In following EXPLAIN the access method should be ref, #rows~=250 +--echo # (and not 2) when we are not using rowid-ordered scans +explain select * from t2 where a=1000 and b<11; drop table t1, t2; # @@ -1967,6 +1968,7 @@ select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1; eval explain $q5; eval explain format=json $q5; +--sorted_result eval $q5; eval prepare stmt from "$q5"; execute stmt; @@ -1982,6 +1984,7 @@ select * from t1,t2 where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1; eval explain $q6; eval explain format=json $q6; +--sorted_result eval $q6; alter table t2 drop index idx1, drop index idx2, add index idx3(d,e); @@ -2002,6 +2005,7 @@ select * from t1,t2 where a = d and (a,e) in ((4,d+1),(7,d+1),(8,d+1)) and length(f) = 1; eval explain $q8; eval explain format=json $q8; +--sorted_result eval $q8; --echo # join order: (t1,t2) with ref access of t2 @@ -2011,6 +2015,7 @@ select * from t1,t2 where a = d and (a,e) in ((e,d+1),(7,7),(8,8)) and length(f) = 1; eval explain $q9; eval explain format=json $q9; +--sorted_result eval $q9; --echo # join order: (t1,t2) with ref access of t2 diff --git a/mysql-test/main/range_innodb.result b/mysql-test/main/range_innodb.result index be7e89b9fd2..058a6caee2c 100644 --- a/mysql-test/main/range_innodb.result +++ b/mysql-test/main/range_innodb.result @@ -57,9 +57,9 @@ set optimizer_switch='extended_keys=on'; explain select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 2 -1 SIMPLE t1 ref PRIMARY,idx1,idx2 idx1 5 const 3 Using index condition -1 SIMPLE t3 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t2 ALL NULL NULL NULL NULL # +1 SIMPLE t3 ALL NULL NULL NULL NULL # Using join buffer (flat, BNL join) +1 SIMPLE t1 ALL PRIMARY,idx1,idx2 NULL NULL NULL # Using where; Using join buffer (incremental, BNL join) select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0'; pk a b 1 6 0 @@ -87,6 +87,7 @@ drop table t1,t2; # MDEV-14440: Server crash in in handler::ha_external_lock or Assertion `inited==RND' # failed in handler::ha_rnd_end upon SELECT from partitioned table # +call mtr.add_suppression("Got error .* when reading table"); set @optimizer_switch_save= @@optimizer_switch; set optimizer_switch='index_merge_sort_intersection=off'; create table t0 (a int)engine=innodb; diff --git a/mysql-test/main/range_innodb.test b/mysql-test/main/range_innodb.test index f79104fde85..dabb4afaa5a 100644 --- a/mysql-test/main/range_innodb.test +++ b/mysql-test/main/range_innodb.test @@ -64,6 +64,8 @@ insert into t3 values (3),(-1),(4); set @save_optimizer_switch=@@optimizer_switch; set optimizer_switch='extended_keys=on'; +# InnoDB sometimes returns 4 other times 5 records for t1 +--replace_column 9 # explain select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0'; select pk, a, b from t1,t2,t3 where b >= d and pk < c and b = '0'; @@ -95,6 +97,8 @@ drop table t1,t2; --echo # failed in handler::ha_rnd_end upon SELECT from partitioned table --echo # +call mtr.add_suppression("Got error .* when reading table"); + set @optimizer_switch_save= @@optimizer_switch; set optimizer_switch='index_merge_sort_intersection=off'; create table t0 (a int)engine=innodb; diff --git a/mysql-test/main/range_mrr_icp.result b/mysql-test/main/range_mrr_icp.result index 1a76f41ead7..1a31835eb9d 100644 --- a/mysql-test/main/range_mrr_icp.result +++ b/mysql-test/main/range_mrr_icp.result @@ -255,7 +255,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref x x 5 const 1 Using index explain select count(*) from t1 where x in (1,2,3,4); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range x x 5 NULL 4 Using where; Using index +1 SIMPLE t1 index x x 5 NULL 9 Using where; Using index drop table t1; CREATE TABLE t1 (key1 int(11) NOT NULL default '0', KEY i1 (key1)); INSERT INTO t1 VALUES (0),(0),(0),(0),(0),(1),(1); @@ -264,12 +264,12 @@ INSERT INTO t2 VALUES (0),(0),(1),(1),(2),(2); explain select * from t1, t2 where (t1.key1 <t2.keya + 1) and t2.keya=3; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref j1 j1 4 const 1 Using index -1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) explain select * from t1 force index(i1), t2 force index(j1) where (t1.key1 <t2.keya + 1) and t2.keya=3; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref j1 j1 4 const 1 Using index -1 SIMPLE t1 range i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) +1 SIMPLE t1 index i1 i1 4 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) DROP TABLE t1,t2; CREATE TABLE t1 ( a int(11) default NULL, @@ -679,7 +679,7 @@ create table t1(a char(2), key(a(1))); insert into t1 values ('x'), ('xx'); explain select a from t1 where a > 'x'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 2 NULL 2 Using where +1 SIMPLE t1 ALL a NULL NULL NULL 2 Using where select a from t1 where a > 'x'; a xx @@ -1141,7 +1141,7 @@ INSERT INTO t1 VALUES ('A2','2005-12-01 08:00:00',1000); EXPLAIN SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref PRIMARY PRIMARY 20 const 3 Using index condition +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 4 Using where SELECT * FROM t1 WHERE item='A1' AND started<='2005-12-01 24:00:00'; item started price Warnings: @@ -1239,14 +1239,13 @@ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t2 (a int, b int, filler char(100)); insert into t2 select A.a + 10 * (B.a + 10 * C.a), 10, 'filler' from t1 A, t1 B, t1 C where A.a < 5; -insert into t2 select 1000, b, 'filler' from t2; +insert into t2 select 1000, b, 'filler' from t2 limit 250; alter table t2 add index (a,b); -select 'In following EXPLAIN the access method should be ref, #rows~=500 (and not 2)' Z; -Z -In following EXPLAIN the access method should be ref, #rows~=500 (and not 2) +# In following EXPLAIN the access method should be ref, #rows~=250 +# (and not 2) when we are not using rowid-ordered scans explain select * from t2 where a=1000 and b<11; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ref a a 5 const 503 Using index condition +1 SIMPLE t2 range a a 10 NULL 253 Using index condition; Rowid-ordered scan drop table t1, t2; CREATE TABLE t1( a INT, b INT, KEY( a, b ) ); CREATE TABLE t2( a INT, b INT, KEY( a, b ) ); @@ -2552,7 +2551,7 @@ EXPLAIN "key_length": "5", "used_key_parts": ["d"], "rows": 3, - "filtered": 60, + "filtered": 100, "index_condition": "t2.d is not null", "attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((2,2)))", "mrr_type": "Rowid-ordered scan" @@ -2625,7 +2624,7 @@ EXPLAIN "key_length": "5", "used_key_parts": ["d"], "rows": 8, - "filtered": 14.42307663, + "filtered": 100, "index_condition": "t2.d is not null", "attached_condition": "(t2.d,t2.e) in (<cache>((3,3)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1", "mrr_type": "Rowid-ordered scan" @@ -2646,22 +2645,22 @@ EXPLAIN select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1; a b c d e f -3 2 uuuw 3 3 i 3 2 uuua 3 3 i -3 3 zzzz 3 3 i +3 2 uuua 3 3 i +3 2 uuuw 3 3 i +3 2 uuuw 3 3 i +3 3 zyxa 3 3 i +3 3 zyxa 3 3 i +3 3 zyxw 3 3 i 3 3 zyxw 3 3 i 3 3 zzza 3 3 i -3 3 zyxa 3 3 i -7 7 xxxyy 7 7 h +3 3 zzza 3 3 i +3 3 zzzz 3 3 i +3 3 zzzz 3 3 i 7 7 xxxya 7 7 h -7 8 xxxxx 7 7 h +7 7 xxxyy 7 7 h 7 8 xxxxa 7 7 h -3 2 uuuw 3 3 i -3 2 uuua 3 3 i -3 3 zzzz 3 3 i -3 3 zyxw 3 3 i -3 3 zzza 3 3 i -3 3 zyxa 3 3 i +7 8 xxxxx 7 7 h prepare stmt from "select * from t1,t2 where a = d and (a,e) in ((3,3),(7,7),(8,8)) and length(f) = 1"; execute stmt; @@ -2723,7 +2722,7 @@ EXPLAIN "key_length": "5", "used_key_parts": ["d"], "rows": 7, - "filtered": 14.28571415, + "filtered": 100, "index_condition": "t2.d is not null", "attached_condition": "(t2.d,t2.e) in (<cache>((4,4)),<cache>((7,7)),<cache>((8,8))) and octet_length(t2.f) = 1", "mrr_type": "Rowid-ordered scan" @@ -2744,14 +2743,14 @@ EXPLAIN select * from t1,t2 where a = d and (a,e) in ((4,4),(7,7),(8,8)) and length(f) = 1; a b c d e f -7 7 xxxyy 7 7 h 7 7 xxxya 7 7 h -7 7 xxxyy 7 7 h 7 7 xxxya 7 7 h -7 8 xxxxx 7 7 h +7 7 xxxyy 7 7 h +7 7 xxxyy 7 7 h 7 8 xxxxa 7 7 h -7 8 xxxxx 7 7 h 7 8 xxxxa 7 7 h +7 8 xxxxx 7 7 h +7 8 xxxxx 7 7 h alter table t2 drop index idx1, drop index idx2, add index idx3(d,e); # join order: (t2,t1) with ref access of t1 # range access to t2 by 2-component keys for index idx3 @@ -2845,22 +2844,22 @@ EXPLAIN select * from t1,t2 where a = d and (a,e) in ((4,d+1),(7,d+1),(8,d+1)) and length(f) = 1; a b c d e f -4 5 ww 4 5 a -7 8 xxxxx 7 8 b +4 3 zya 4 5 a +4 3 zya 4 5 a +4 3 zyx 4 5 a 4 3 zyx 4 5 a -7 7 xxxyy 7 8 b 4 5 wa 4 5 a -7 8 xxxxa 7 8 b -4 3 zya 4 5 a -7 7 xxxya 7 8 b +4 5 wa 4 5 a 4 5 ww 4 5 a -7 8 xxxxx 7 8 b -4 3 zyx 4 5 a +4 5 ww 4 5 a +7 7 xxxya 7 8 b +7 7 xxxya 7 8 b +7 7 xxxyy 7 8 b 7 7 xxxyy 7 8 b -4 5 wa 4 5 a 7 8 xxxxa 7 8 b -4 3 zya 4 5 a -7 7 xxxya 7 8 b +7 8 xxxxa 7 8 b +7 8 xxxxx 7 8 b +7 8 xxxxx 7 8 b # join order: (t1,t2) with ref access of t2 # no range access explain select * from t1,t2 @@ -2899,14 +2898,14 @@ EXPLAIN select * from t1,t2 where a = d and (a,e) in ((e,d+1),(7,7),(8,8)) and length(f) = 1; a b c d e f -7 8 xxxxx 7 7 h -7 7 xxxyy 7 7 h -7 8 xxxxa 7 7 h 7 7 xxxya 7 7 h -7 8 xxxxx 7 7 h +7 7 xxxya 7 7 h +7 7 xxxyy 7 7 h 7 7 xxxyy 7 7 h 7 8 xxxxa 7 7 h -7 7 xxxya 7 7 h +7 8 xxxxa 7 7 h +7 8 xxxxx 7 7 h +7 8 xxxxx 7 7 h # join order: (t1,t2) with ref access of t2 # range access to t1 by 1-component keys for index idx explain select * from t1,t2 diff --git a/mysql-test/main/range_notembedded.result b/mysql-test/main/range_notembedded.result index eeab230e72f..9810b965a1e 100644 --- a/mysql-test/main/range_notembedded.result +++ b/mysql-test/main/range_notembedded.result @@ -13,7 +13,7 @@ set @tmp_21958=@@optimizer_trace; set optimizer_trace=1; explain select * from t2 where key1 in (1,2,3) and pk not in (1,2,3); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 range PRIMARY,key1 key1 5 NULL 3 Using index condition +1 SIMPLE t2 ALL PRIMARY,key1 NULL NULL NULL 5 Using where # This should show only ranges in form "(1) <= (key1) <= (1)" # ranges over "pk" should not be constructed. select json_detailed(JSON_EXTRACT(trace, '$**.ranges')) @@ -25,12 +25,6 @@ json_detailed(JSON_EXTRACT(trace, '$**.ranges')) "(1) <= (key1) <= (1)", "(2) <= (key1) <= (2)", "(3) <= (key1) <= (3)" - ], - - [ - "(1) <= (key1) <= (1)", - "(2) <= (key1) <= (2)", - "(3) <= (key1) <= (3)" ] ] set optimizer_trace=@tmp_21958; @@ -235,9 +229,10 @@ user_id int(10) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (notification_type_id,item_id,item_parent_id,user_id) ); insert into t1 values (1,1,1,1), (2,2,2,2), (3,3,3,3); +insert into t1 select seq,seq,seq,seq from seq_10_to_30; # Run crashing query id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 2 NULL 3 Using where +1 SIMPLE t1 range PRIMARY PRIMARY 2 NULL 5 Using where drop table t1; # # MDEV-25069: Assertion `root->weight >= ...' failed in SEL_ARG::tree_delete #2 diff --git a/mysql-test/main/range_notembedded.test b/mysql-test/main/range_notembedded.test index 4e77d6a4810..e541018f6af 100644 --- a/mysql-test/main/range_notembedded.test +++ b/mysql-test/main/range_notembedded.test @@ -122,6 +122,7 @@ CREATE TABLE t1 ( PRIMARY KEY (notification_type_id,item_id,item_parent_id,user_id) ); insert into t1 values (1,1,1,1), (2,2,2,2), (3,3,3,3); +insert into t1 select seq,seq,seq,seq from seq_10_to_30; let $consts=`select group_concat(concat("'",seq,"'")) from seq_1_to_4642`; diff --git a/mysql-test/main/range_vs_index_merge.result b/mysql-test/main/range_vs_index_merge.result index 7108fd89a7d..3babbc989b3 100644 --- a/mysql-test/main/range_vs_index_merge.result +++ b/mysql-test/main/range_vs_index_merge.result @@ -333,7 +333,7 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City ALL PRIMARY NULL NULL NULL 4079 Using where +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 1200 Using index condition EXPLAIN SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG'; id select_type table type possible_keys key key_len ref rows Extra @@ -1077,7 +1077,7 @@ EXPLAIN SELECT Name, Country, Population FROM City WHERE (Name='Samara' AND Country='RUS') OR (Name='Seattle' AND Country='USA'); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge Country,CountryPopulation,CountryName,CityName CountryName,CityName 38,35 NULL 28 Using sort_union(CountryName,CityName); Using where +1 SIMPLE City range Country,CountryPopulation,CountryName,CityName CountryName 38 NULL 28 Using index condition SELECT Name, Country, Population FROM City WHERE (Name='Manila' AND Country='PHL') OR (Name='Addis Abeba' AND Country='ETH') OR @@ -1810,7 +1810,7 @@ EXPLAIN SELECT * FROM t1 WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,idx PRIMARY 0 NULL 2 Using index condition; Using where +1 SIMPLE t1 ALL PRIMARY,idx NULL NULL NULL 2 Using where SELECT * FROM t1 WHERE a BETWEEN 4 AND 5 AND b IN (255,4) OR a IN (2,14,25) OR (a<2 or a>2); a b diff --git a/mysql-test/main/range_vs_index_merge.test b/mysql-test/main/range_vs_index_merge.test index 670762bcb2f..a8e86e44b9e 100644 --- a/mysql-test/main/range_vs_index_merge.test +++ b/mysql-test/main/range_vs_index_merge.test @@ -658,7 +658,7 @@ let $cond = (Name='Lugansk' AND Country='UKR') OR (Name='Caracas' AND Country='VEN') OR (Name='Samara' AND Country='RUS') OR -(Name='Seattle' AND Country='USA'); +(Name='Seattle' AND Country='USA'); eval EXPLAIN SELECT Name, Country, Population FROM City WHERE diff --git a/mysql-test/main/range_vs_index_merge_innodb.result b/mysql-test/main/range_vs_index_merge_innodb.result index 79a670aedb2..de345f66161 100644 --- a/mysql-test/main/range_vs_index_merge_innodb.result +++ b/mysql-test/main/range_vs_index_merge_innodb.result @@ -365,7 +365,7 @@ WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) OR ((ID BETWEEN 900 AND 1500) AND (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 105000))); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,PRIMARY 39,3,4 NULL 683 Using sort_union(Name,Country,PRIMARY); Using where +1 SIMPLE City index_merge PRIMARY,Population,Country,Name Name,Country,Population 39,3,4 NULL 212 Using sort_union(Name,Country,Population); Using where EXPLAIN SELECT * FROM City WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) @@ -620,7 +620,7 @@ WHERE ((Population > 101000 AND Population < 102000) AND ((ID BETWEEN 3400 AND 3800) AND (Country < 'AGO' OR Name LIKE 'Pa%')); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City index_merge PRIMARY,Population,Country,Name Population,PRIMARY 4,4 NULL 440 Using sort_union(Population,PRIMARY); Using where +1 SIMPLE City index_merge PRIMARY,Population,Country,Name Country,Name,Population 3,39,4 NULL 115 Using sort_union(Country,Name,Population); Using where EXPLAIN SELECT * FROM City WHERE ((Population > 101000 AND Population < 110000) AND @@ -1804,7 +1804,7 @@ SELECT * FROM t1 WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND (t1.c=0 OR t1.a=500); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,idx idx 5 NULL 2 Using where; Using index +1 SIMPLE t1 range PRIMARY,idx PRIMARY 4 NULL 1 Using where SELECT * FROM t1 WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND (t1.c=0 OR t1.a=500); diff --git a/mysql-test/main/rowid_filter.result b/mysql-test/main/rowid_filter.result index 774fbd87ed9..cba4087148f 100644 --- a/mysql-test/main/rowid_filter.result +++ b/mysql-test/main/rowid_filter.result @@ -228,7 +228,7 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_shipDATE"], "rows": 509, - "filtered": 11.69025803, + "filtered": 100, "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", "attached_condition": "lineitem.l_quantity > 45" } @@ -238,7 +238,7 @@ set statement optimizer_switch='rowid_filter=off' for ANALYZE SELECT l_orderkey, WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 509 510.00 11.69 11.76 Using index condition; Using where +1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 509 510.00 100.00 11.76 Using index condition; Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_orderkey, l_linenumber, l_shipdate, l_quantity FROM lineitem WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45; @@ -260,7 +260,7 @@ ANALYZE "r_rows": 510, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 11.69025803, + "filtered": 100, "r_filtered": 11.76470588, "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", "attached_condition": "lineitem.l_quantity > 45" @@ -336,8 +336,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 Using index condition -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND @@ -347,40 +347,40 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "rows": 69, + "filtered": 100, + "index_condition": "orders.o_totalprice between 200000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "rows": 98, - "filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 69, - "selectivity_pct": 4.6 + "rows": 98, + "selectivity_pct": 1.631973356 }, - "rows": 1, - "filtered": 4.599999905, - "attached_condition": "orders.o_totalprice between 200000 and 230000" + "rows": 4, + "filtered": 1.631973386, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" } } } @@ -389,8 +389,8 @@ FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_shipdate 4 NULL 98 98.00 100.00 100.00 Using index condition -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (5%) 0.11 (10%) 4.60 100.00 Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 71.00 100.00 100.00 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (2%) 0.15 (2%) 1.63 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-01-31' AND @@ -402,54 +402,54 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", - "possible_keys": [ - "PRIMARY", - "i_l_shipdate", - "i_l_orderkey", - "i_l_orderkey_quantity" - ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], "r_loops": 1, - "rows": 98, - "r_rows": 98, + "rows": 69, + "r_rows": 71, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 100, "r_filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" + "index_condition": "orders.o_totalprice between 200000 and 230000" }, "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "table_name": "lineitem", + "access_type": "ref", + "possible_keys": [ + "PRIMARY", + "i_l_shipdate", + "i_l_orderkey", + "i_l_orderkey_quantity" + ], + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 69, - "selectivity_pct": 4.6, - "r_rows": 71, - "r_selectivity_pct": 10.41666667, + "rows": 98, + "selectivity_pct": 1.631973356, + "r_rows": 98, + "r_selectivity_pct": 2.31092437, "r_buffer_size": "REPLACED", "r_filling_time_ms": "REPLACED" }, - "r_loops": 98, - "rows": 1, - "r_rows": 0.112244898, + "r_loops": 71, + "rows": 4, + "r_rows": 0.154929577, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 4.599999905, + "filtered": 1.631973386, "r_filtered": 100, - "attached_condition": "orders.o_totalprice between 200000 and 230000" + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-01-31'" } } } @@ -593,8 +593,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45 AND o_totalprice between 180000 and 230000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) Using index condition; Using where; Using rowid filter -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -605,8 +605,19 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "rows": 139, + "filtered": 100, + "index_condition": "orders.o_totalprice between 180000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", @@ -614,41 +625,21 @@ EXPLAIN "i_l_orderkey_quantity", "i_l_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "rowid_filter": { - "range": { - "key": "i_l_quantity", - "used_key_parts": ["l_quantity"] - }, - "rows": 702, - "selectivity_pct": 11.69025812 - }, - "rows": 509, - "filtered": 11.69025803, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", - "attached_condition": "lineitem.l_quantity > 45" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 139, - "selectivity_pct": 9.266666667 + "rows": 509, + "selectivity_pct": 8.476269775 }, - "rows": 1, - "filtered": 9.266666412, - "attached_condition": "orders.o_totalprice between 180000 and 230000" + "rows": 4, + "filtered": 0.990897834, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45" } } } @@ -658,8 +649,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45 AND o_totalprice between 180000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) 60.00 (11%) 11.69 100.00 Using index condition; Using where; Using rowid filter -1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) 0.27 (25%) 9.27 100.00 Using where; Using rowid filter +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 144.00 100.00 100.00 Using index condition +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.54 (8%) 0.99 20.51 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -672,8 +663,24 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "r_loops": 1, + "rows": 139, + "r_rows": 144, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100, + "index_condition": "orders.o_totalprice between 180000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", @@ -681,59 +688,30 @@ ANALYZE "i_l_orderkey_quantity", "i_l_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "rowid_filter": { - "range": { - "key": "i_l_quantity", - "used_key_parts": ["l_quantity"] - }, - "rows": 702, - "selectivity_pct": 11.69025812, - "r_rows": 605, - "r_selectivity_pct": 11.76470588, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, - "r_loops": 1, - "rows": 509, - "r_rows": 60, - "r_table_time_ms": "REPLACED", - "r_other_time_ms": "REPLACED", - "filtered": 11.69025803, - "r_filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", - "attached_condition": "lineitem.l_quantity > 45" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_o_totalprice", - "used_key_parts": ["o_totalprice"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 139, - "selectivity_pct": 9.266666667, - "r_rows": 144, - "r_selectivity_pct": 25.42372881, + "rows": 509, + "selectivity_pct": 8.476269775, + "r_rows": 510, + "r_selectivity_pct": 8.176100629, "r_buffer_size": "REPLACED", "r_filling_time_ms": "REPLACED" }, - "r_loops": 60, - "rows": 1, - "r_rows": 0.266666667, + "r_loops": 144, + "rows": 4, + "r_rows": 0.541666667, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 9.266666412, - "r_filtered": 100, - "attached_condition": "orders.o_totalprice between 180000 and 230000" + "filtered": 0.990897834, + "r_filtered": 20.51282051, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45" } } } @@ -765,8 +743,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45 AND o_totalprice between 180000 and 230000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate 4 NULL 509 Using index condition; Using where -1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 Using index condition +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where set statement optimizer_switch='rowid_filter=off' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -777,8 +755,19 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "rows": 139, + "filtered": 100, + "index_condition": "orders.o_totalprice between 180000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", @@ -786,25 +775,13 @@ EXPLAIN "i_l_orderkey_quantity", "i_l_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "rows": 509, - "filtered": 11.69025803, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", - "attached_condition": "lineitem.l_quantity > 45" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], - "rows": 1, - "filtered": 9.266666412, - "attached_condition": "orders.o_totalprice between 180000 and 230000" + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], + "rows": 4, + "filtered": 0.990897834, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45" } } } @@ -814,8 +791,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45 AND o_totalprice between 180000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate 4 NULL 509 510.00 11.69 11.76 Using index condition; Using where -1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 9.27 26.67 Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 139 144.00 100.00 100.00 Using index condition +1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.62 0.99 1.68 Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -828,8 +805,24 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "r_loops": 1, + "rows": 139, + "r_rows": 144, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100, + "index_condition": "orders.o_totalprice between 180000 and 230000" + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", @@ -837,35 +830,18 @@ ANALYZE "i_l_orderkey_quantity", "i_l_quantity" ], - "key": "i_l_shipdate", - "key_length": "4", - "used_key_parts": ["l_shipDATE"], - "r_loops": 1, - "rows": 509, - "r_rows": 510, - "r_table_time_ms": "REPLACED", - "r_other_time_ms": "REPLACED", - "filtered": 11.69025803, - "r_filtered": 11.76470588, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", - "attached_condition": "lineitem.l_quantity > 45" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], - "r_loops": 60, - "rows": 1, - "r_rows": 1, + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], + "r_loops": 144, + "rows": 4, + "r_rows": 6.625, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 9.266666412, - "r_filtered": 26.66666667, - "attached_condition": "orders.o_totalprice between 180000 and 230000" + "filtered": 0.990897834, + "r_filtered": 1.677148847, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45" } } } @@ -891,13 +867,21 @@ o_orderkey l_linenumber l_shipdate l_quantity o_totalprice 5829 5 1997-01-31 49 183734.56 5895 2 1997-04-27 47 201419.83 5895 3 1997-03-15 49 201419.83 +set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT STRAIGHT_JOIN o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice +FROM lineitem JOIN orders ON o_orderkey=l_orderkey +WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND +l_quantity > 45 AND +o_totalprice between 180000 and 230000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 509 (12%) Using index condition; Using where; Using rowid filter +1 SIMPLE orders eq_ref|filter PRIMARY,i_o_totalprice PRIMARY|i_o_totalprice 4|9 dbt3_s001.lineitem.l_orderkey 1 (9%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 Using index condition -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -930,6 +914,14 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 509, + "selectivity_pct": 8.476269775 + }, "rows": 4, "filtered": 8.476269722, "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'" @@ -942,7 +934,7 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND o_totalprice between 200000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 69 71.00 100.00 100.00 Using index condition -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.70 8.48 7.77 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.52 (7%) 8.48 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -982,13 +974,25 @@ ANALYZE "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 509, + "selectivity_pct": 8.476269775, + "r_rows": 510, + "r_selectivity_pct": 7.773109244, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 71, "rows": 4, - "r_rows": 6.704225352, + "r_rows": 0.521126761, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 8.476269722, - "r_filtered": 7.773109244, + "r_filtered": 100, "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'" } } @@ -1219,7 +1223,7 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_receiptDATE"], "rows": 18, - "filtered": 5.555555344, + "filtered": 100, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" }, @@ -1244,7 +1248,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND o_totalprice BETWEEN 200000 AND 250000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where +1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where 1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 7.47 14.29 Using where set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice FROM orders, lineitem @@ -1276,7 +1280,7 @@ ANALYZE "r_rows": 18, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 5.555555344, + "filtered": 100, "r_filtered": 38.88888889, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" @@ -1341,7 +1345,7 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_receiptDATE"], "rows": 18, - "filtered": 5.555555344, + "filtered": 100, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" }, @@ -1366,7 +1370,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND o_totalprice BETWEEN 200000 AND 250000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where +1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where 1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 7.47 14.29 Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice FROM orders, lineitem @@ -1398,7 +1402,7 @@ ANALYZE "r_rows": 18, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 5.555555344, + "filtered": 100, "r_filtered": 38.88888889, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" @@ -1445,7 +1449,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM orders, lineitem WHERE o_orderkey=l_orderkey AND @@ -1464,7 +1468,7 @@ EXPLAIN "key_length": "9", "used_key_parts": ["o_totaldiscount"], "rows": 39, - "filtered": 3.200000048, + "filtered": 100, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" }, @@ -1481,6 +1485,14 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045 + }, "rows": 4, "filtered": 3.047460556, "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" @@ -1494,8 +1506,8 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 3.20 2.44 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 100.00 2.44 Using index condition; Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) 3.05 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM orders, lineitem WHERE o_orderkey=l_orderkey AND @@ -1520,7 +1532,7 @@ ANALYZE "r_rows": 41, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 3.200000048, + "filtered": 100, "r_filtered": 2.43902439, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" @@ -1538,13 +1550,25 @@ ANALYZE "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045, + "r_rows": 183, + "r_selectivity_pct": 66.66666667, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, "rows": 4, - "r_rows": 6, + "r_rows": 4, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 3.047460556, - "r_filtered": 66.66666667, + "r_filtered": 100, "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" } } @@ -1587,7 +1611,7 @@ EXPLAIN "key_length": "9", "used_key_parts": ["o_totaldiscount"], "rows": 39, - "filtered": 3.200000048, + "filtered": 100, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" }, @@ -1617,7 +1641,7 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 3.20 2.44 Using index condition; Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 100.00 2.44 Using index condition; Using where 1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM orders, lineitem @@ -1643,7 +1667,7 @@ ANALYZE "r_rows": 41, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 3.200000048, + "filtered": 100, "r_filtered": 2.43902439, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" @@ -1694,7 +1718,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM v1, lineitem WHERE o_orderkey=l_orderkey AND @@ -1735,6 +1759,14 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045 + }, "rows": 4, "filtered": "REPLACED", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" @@ -1749,7 +1781,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 39 41.00 # 2.44 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) # 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM v1, lineitem WHERE o_orderkey=l_orderkey AND @@ -1797,13 +1829,25 @@ ANALYZE "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045, + "r_rows": 183, + "r_selectivity_pct": 66.66666667, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, "rows": 4, - "r_rows": 6, + "r_rows": 4, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": "REPLACED", - "r_filtered": 66.66666667, + "r_filtered": 100, "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" } } @@ -2063,7 +2107,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1 <> pk2 AND pk1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 eq_ref PRIMARY,b1 PRIMARY 4 test.t2.a2 1 87.00 Using where +1 PRIMARY t1 eq_ref|filter PRIMARY,b1 PRIMARY|b1 4|4 test.t2.a2 1 (87%) 87.00 Using where; Using rowid filter 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`pk1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t2`.`a2` <> `test`.`t2`.`pk2` @@ -2088,6 +2132,14 @@ EXPLAIN "key_length": "4", "used_key_parts": ["pk1"], "ref": ["test.t2.a2"], + "rowid_filter": { + "range": { + "key": "b1", + "used_key_parts": ["b1"] + }, + "rows": 87, + "selectivity_pct": 87 + }, "rows": 1, "filtered": 87, "attached_condition": "t1.b1 <= (subquery#2)" @@ -2160,7 +2212,7 @@ INSERT INTO t1 VALUES (0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4); explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 1 (29%) Using index condition; Using where; Using rowid filter +1 SIMPLE t1 range a,b a 5 NULL 1 Using index condition; Using where SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 diff --git a/mysql-test/main/rowid_filter.test b/mysql-test/main/rowid_filter.test index 163b71b6153..fbbd9746ef8 100644 --- a/mysql-test/main/rowid_filter.test +++ b/mysql-test/main/rowid_filter.test @@ -115,6 +115,13 @@ eval $without_filter ANALYZE FORMAT=JSON $q3; --sorted_result eval $without_filter $q3; +# Check different optimization +eval $with_filter EXPLAIN SELECT STRAIGHT_JOIN o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice + FROM lineitem JOIN orders ON o_orderkey=l_orderkey + WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND + l_quantity > 45 AND + o_totalprice between 180000 and 230000; + let $q4= SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey diff --git a/mysql-test/main/rowid_filter_innodb.result b/mysql-test/main/rowid_filter_innodb.result index 55b6d99464b..d459776d218 100644 --- a/mysql-test/main/rowid_filter_innodb.result +++ b/mysql-test/main/rowid_filter_innodb.result @@ -231,7 +231,7 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_shipDATE"], "rows": 510, - "filtered": 10.07493782, + "filtered": 100, "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", "attached_condition": "lineitem.l_quantity > 45" } @@ -241,7 +241,7 @@ set statement optimizer_switch='rowid_filter=off' for ANALYZE SELECT l_orderkey, WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 510 510.00 10.07 11.76 Using index condition; Using where +1 SIMPLE lineitem range i_l_shipdate,i_l_quantity i_l_shipdate 4 NULL 510 510.00 100.00 11.76 Using index condition; Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_orderkey, l_linenumber, l_shipdate, l_quantity FROM lineitem WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45; @@ -263,7 +263,7 @@ ANALYZE "r_rows": 510, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 10.07493782, + "filtered": 100, "r_filtered": 11.76470588, "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", "attached_condition": "lineitem.l_quantity > 45" @@ -580,8 +580,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45 AND o_totalprice between 180000 and 230000; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) Using index condition; Using where; Using rowid filter -1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 144 Using where; Using index +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -592,8 +592,20 @@ EXPLAIN "query_block": { "select_id": 1, "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "rows": 144, + "filtered": 100, + "attached_condition": "orders.o_totalprice between 180000 and 230000", + "using_index": true + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", @@ -601,33 +613,21 @@ EXPLAIN "i_l_orderkey_quantity", "i_l_quantity" ], - "key": "i_l_shipdate", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["l_shipDATE"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_l_quantity", - "used_key_parts": ["l_quantity"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 605, - "selectivity_pct": 10.07493755 + "rows": 510, + "selectivity_pct": 8.492922565 }, - "rows": 510, - "filtered": 10.07493782, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", - "attached_condition": "lineitem.l_quantity > 45" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", - "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], - "rows": 1, - "filtered": 9.600000381, - "attached_condition": "orders.o_totalprice between 180000 and 230000" + "rows": 4, + "filtered": 0.855656624, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45" } } } @@ -637,8 +637,8 @@ WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND l_quantity > 45 AND o_totalprice between 180000 and 230000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) 60.00 (11%) 10.07 100.00 Using index condition; Using where; Using rowid filter -1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 9.60 26.67 Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice i_o_totalprice 9 NULL 144 144.00 100.00 100.00 Using where; Using index +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (8%) 0.54 (8%) 0.86 20.51 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -651,8 +651,25 @@ ANALYZE "r_loops": 1, "r_total_time_ms": "REPLACED", "table": { - "table_name": "lineitem", + "table_name": "orders", "access_type": "range", + "possible_keys": ["PRIMARY", "i_o_totalprice"], + "key": "i_o_totalprice", + "key_length": "9", + "used_key_parts": ["o_totalprice"], + "r_loops": 1, + "rows": 144, + "r_rows": 144, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100, + "attached_condition": "orders.o_totalprice between 180000 and 230000", + "using_index": true + }, + "table": { + "table_name": "lineitem", + "access_type": "ref", "possible_keys": [ "PRIMARY", "i_l_shipdate", @@ -660,47 +677,30 @@ ANALYZE "i_l_orderkey_quantity", "i_l_quantity" ], - "key": "i_l_shipdate", + "key": "i_l_orderkey", "key_length": "4", - "used_key_parts": ["l_shipDATE"], + "used_key_parts": ["l_orderkey"], + "ref": ["dbt3_s001.orders.o_orderkey"], "rowid_filter": { "range": { - "key": "i_l_quantity", - "used_key_parts": ["l_quantity"] + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] }, - "rows": 605, - "selectivity_pct": 10.07493755, - "r_rows": 605, - "r_selectivity_pct": 11.76470588, + "rows": 510, + "selectivity_pct": 8.492922565, + "r_rows": 510, + "r_selectivity_pct": 8.176100629, "r_buffer_size": "REPLACED", "r_filling_time_ms": "REPLACED" }, - "r_loops": 1, - "rows": 510, - "r_rows": 60, - "r_table_time_ms": "REPLACED", - "r_other_time_ms": "REPLACED", - "filtered": 10.07493782, - "r_filtered": 100, - "index_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30'", - "attached_condition": "lineitem.l_quantity > 45" - }, - "table": { - "table_name": "orders", - "access_type": "eq_ref", - "possible_keys": ["PRIMARY", "i_o_totalprice"], - "key": "PRIMARY", - "key_length": "4", - "used_key_parts": ["o_orderkey"], - "ref": ["dbt3_s001.lineitem.l_orderkey"], - "r_loops": 60, - "rows": 1, - "r_rows": 1, + "r_loops": 144, + "rows": 4, + "r_rows": 0.541666667, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 9.600000381, - "r_filtered": 26.66666667, - "attached_condition": "orders.o_totalprice between 180000 and 230000" + "filtered": 0.855656624, + "r_filtered": 20.51282051, + "attached_condition": "lineitem.l_shipDATE between '1997-01-01' and '1997-06-30' and lineitem.l_quantity > 45" } } } @@ -858,6 +858,14 @@ o_orderkey l_linenumber l_shipdate l_quantity o_totalprice 5829 5 1997-01-31 49 183734.56 5895 2 1997-04-27 47 201419.83 5895 3 1997-03-15 49 201419.83 +set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT STRAIGHT_JOIN o_orderkey, l_linenumber, l_shipdate, l_quantity, o_totalprice +FROM lineitem JOIN orders ON o_orderkey=l_orderkey +WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND +l_quantity > 45 AND +o_totalprice between 180000 and 230000; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE lineitem range|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity,i_l_quantity i_l_shipdate|i_l_quantity 4|9 NULL 510 (10%) Using index condition; Using where; Using rowid filter +1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where set statement optimizer_switch='rowid_filter=on' for EXPLAIN SELECT o_orderkey, l_linenumber, l_shipdate, o_totalprice FROM orders JOIN lineitem ON o_orderkey=l_orderkey WHERE l_shipdate BETWEEN '1997-01-01' AND '1997-06-30' AND @@ -1190,7 +1198,7 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_receiptDATE"], "rows": 18, - "filtered": 5.555555344, + "filtered": 100, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" }, @@ -1215,7 +1223,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND o_totalprice BETWEEN 200000 AND 250000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where +1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where 1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 5.67 14.29 Using where set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice FROM orders, lineitem @@ -1247,7 +1255,7 @@ ANALYZE "r_rows": 18, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 5.555555344, + "filtered": 100, "r_filtered": 38.88888889, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" @@ -1312,7 +1320,7 @@ EXPLAIN "key_length": "4", "used_key_parts": ["l_receiptDATE"], "rows": 18, - "filtered": 5.555555344, + "filtered": 100, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" }, @@ -1337,7 +1345,7 @@ l_shipdate BETWEEN '1996-10-01' AND '1996-10-10' AND l_receiptdate BETWEEN '1996-10-05' AND '1996-10-10' AND o_totalprice BETWEEN 200000 AND 250000; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 5.56 38.89 Using index condition; Using where +1 SIMPLE lineitem range PRIMARY,i_l_shipdate,i_l_receiptdate,i_l_orderkey,i_l_orderkey_quantity i_l_receiptdate 4 NULL 18 18.00 100.00 38.89 Using index condition; Using where 1 SIMPLE orders eq_ref PRIMARY,i_o_totalprice PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 1.00 5.67 14.29 Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT l_shipdate, l_receiptdate, o_totalprice FROM orders, lineitem @@ -1369,7 +1377,7 @@ ANALYZE "r_rows": 18, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 5.555555344, + "filtered": 100, "r_filtered": 38.88888889, "index_condition": "lineitem.l_receiptDATE between '1996-10-05' and '1996-10-10'", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-10-10'" @@ -1416,7 +1424,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM orders, lineitem WHERE o_orderkey=l_orderkey AND @@ -1435,7 +1443,7 @@ EXPLAIN "key_length": "9", "used_key_parts": ["o_totaldiscount"], "rows": 41, - "filtered": 3.333333254, + "filtered": 100, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" }, @@ -1448,10 +1456,18 @@ EXPLAIN "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045 + }, "rows": 4, "filtered": 3.047460556, "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" @@ -1465,8 +1481,8 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 3.33 2.44 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 100.00 2.44 Using index condition; Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) 3.05 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM orders, lineitem WHERE o_orderkey=l_orderkey AND @@ -1491,7 +1507,7 @@ ANALYZE "r_rows": 41, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 3.333333254, + "filtered": 100, "r_filtered": 2.43902439, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" @@ -1505,17 +1521,29 @@ ANALYZE "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045, + "r_rows": 183, + "r_selectivity_pct": 66.66666667, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, "rows": 4, - "r_rows": 6, + "r_rows": 4, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 3.047460556, - "r_filtered": 66.66666667, + "r_filtered": 100, "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" } } @@ -1558,7 +1586,7 @@ EXPLAIN "key_length": "9", "used_key_parts": ["o_totaldiscount"], "rows": 41, - "filtered": 3.333333254, + "filtered": 100, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" }, @@ -1588,7 +1616,7 @@ o_totaldiscount BETWEEN 18000 AND 20000 AND o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 3.33 2.44 Using index condition; Using where +1 SIMPLE orders range PRIMARY,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 100.00 2.44 Using index condition; Using where 1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 3.05 66.67 Using where set statement optimizer_switch='rowid_filter=off' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM orders, lineitem @@ -1614,7 +1642,7 @@ ANALYZE "r_rows": 41, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", - "filtered": 3.333333254, + "filtered": 100, "r_filtered": 2.43902439, "index_condition": "orders.o_totaldiscount between 18000 and 20000", "attached_condition": "orders.o_totalprice between 200000 and 220000" @@ -1665,7 +1693,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for EXPLAIN FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM v1, lineitem WHERE o_orderkey=l_orderkey AND @@ -1702,10 +1730,18 @@ EXPLAIN "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045 + }, "rows": 4, "filtered": "REPLACED", "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" @@ -1720,7 +1756,7 @@ o_totalprice BETWEEN 200000 AND 220000 AND l_shipdate BETWEEN '1996-10-01' AND '1996-12-01'; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra 1 SIMPLE orders range PRIMARY,i_o_orderdate,i_o_totalprice,i_o_totaldiscount i_o_totaldiscount 9 NULL 41 41.00 # 2.44 Using index condition; Using where -1 SIMPLE lineitem ref PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity PRIMARY 4 dbt3_s001.orders.o_orderkey 4 6.00 # 66.67 Using where +1 SIMPLE lineitem ref|filter PRIMARY,i_l_shipdate,i_l_orderkey,i_l_orderkey_quantity i_l_orderkey|i_l_shipdate 4|4 dbt3_s001.orders.o_orderkey 4 (3%) 4.00 (66%) # 100.00 Using where; Using rowid filter set statement optimizer_switch='rowid_filter=on' for ANALYZE FORMAT=JSON SELECT o_totaldiscount, o_totalprice, l_shipdate FROM v1, lineitem WHERE o_orderkey=l_orderkey AND @@ -1764,17 +1800,29 @@ ANALYZE "i_l_orderkey", "i_l_orderkey_quantity" ], - "key": "PRIMARY", + "key": "i_l_orderkey", "key_length": "4", "used_key_parts": ["l_orderkey"], "ref": ["dbt3_s001.orders.o_orderkey"], + "rowid_filter": { + "range": { + "key": "i_l_shipdate", + "used_key_parts": ["l_shipDATE"] + }, + "rows": 183, + "selectivity_pct": 3.04746045, + "r_rows": 183, + "r_selectivity_pct": 66.66666667, + "r_buffer_size": "REPLACED", + "r_filling_time_ms": "REPLACED" + }, "r_loops": 1, "rows": 4, - "r_rows": 6, + "r_rows": 4, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": "REPLACED", - "r_filtered": 66.66666667, + "r_filtered": 100, "attached_condition": "lineitem.l_shipDATE between '1996-10-01' and '1996-12-01'" } } @@ -2034,7 +2082,7 @@ EXPLAIN EXTENDED SELECT * FROM t1 INNER JOIN t2 ON ( pk1 <> pk2 AND pk1 = a2 ) WHERE b1 <= ( SELECT MAX(b2) FROM t2 WHERE pk2 <= 1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 101 100.00 Using where -1 PRIMARY t1 eq_ref PRIMARY,b1 PRIMARY 4 test.t2.a2 1 87.00 Using where +1 PRIMARY t1 eq_ref|filter PRIMARY,b1 PRIMARY|b1 4|4 test.t2.a2 1 (87%) 87.00 Using where; Using rowid filter 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 1 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`pk1` AS `pk1`,`test`.`t1`.`a1` AS `a1`,`test`.`t1`.`b1` AS `b1`,`test`.`t2`.`pk2` AS `pk2`,`test`.`t2`.`a2` AS `a2`,`test`.`t2`.`b2` AS `b2` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`pk1` = `test`.`t2`.`a2` and `test`.`t1`.`b1` <= (/* select#2 */ select max(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`pk2` <= 1) and `test`.`t2`.`a2` <> `test`.`t2`.`pk2` @@ -2059,6 +2107,14 @@ EXPLAIN "key_length": "4", "used_key_parts": ["pk1"], "ref": ["test.t2.a2"], + "rowid_filter": { + "range": { + "key": "b1", + "used_key_parts": ["b1"] + }, + "rows": 87, + "selectivity_pct": 87 + }, "rows": 1, "filtered": 87, "attached_condition": "t1.b1 <= (subquery#2)" @@ -2131,7 +2187,7 @@ INSERT INTO t1 VALUES (0,0),(1,0),(-1,1), (-2,1), (-2,3), (-3,4), (-2,4); explain SELECT * FROM t1 WHERE a > 0 AND b=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range|filter a,b a|b 5|5 NULL 1 (29%) Using index condition; Using where; Using rowid filter +1 SIMPLE t1 range a,b a 5 NULL 1 Using index condition; Using where SELECT * FROM t1 WHERE a > 0 AND b=0; a b 1 0 @@ -2174,8 +2230,8 @@ union ( select * from t1 where (f1 is null and f2 is null) and (f2 between 'a' and 'z' or f1 in ('a'))); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ref|filter f1,f2 f1|f1 13|13 const 1 (2%) Using index condition; Using where; Using rowid filter -2 UNION t1 ref|filter f1,f2 f1|f1 13|13 const 1 (2%) Using index condition; Using where; Using rowid filter +1 PRIMARY t1 index_merge f1,f2 f1,f2 13,33 NULL 1 Using intersect(f1,f2); Using where +2 UNION t1 index_merge f1,f2 f1,f2 13,33 NULL 1 Using intersect(f1,f2); Using where NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL explain format=json ( select * from t1 where (f1 is null and f2 is null) and (f2 between 'a' and 'z' or f1 in ('a'))) @@ -2194,24 +2250,24 @@ EXPLAIN "select_id": 1, "table": { "table_name": "t1", - "access_type": "ref", + "access_type": "index_merge", "possible_keys": ["f1", "f2"], - "key": "f1", - "key_length": "13", - "used_key_parts": ["f1"], - "ref": ["const"], - "rowid_filter": { - "range": { - "key": "f1", - "used_key_parts": ["f1"] - }, - "rows": 1, - "selectivity_pct": 1.587301587 + "key_length": "13,33", + "index_merge": { + "intersect": { + "range": { + "key": "f1", + "used_key_parts": ["f1"] + }, + "range": { + "key": "f2", + "used_key_parts": ["f2"] + } + } }, "rows": 1, - "filtered": 1.587301612, - "index_condition": "t1.f1 is null", - "attached_condition": "t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')" + "filtered": 100, + "attached_condition": "t1.f1 is null and t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')" } } }, @@ -2221,24 +2277,24 @@ EXPLAIN "operation": "UNION", "table": { "table_name": "t1", - "access_type": "ref", + "access_type": "index_merge", "possible_keys": ["f1", "f2"], - "key": "f1", - "key_length": "13", - "used_key_parts": ["f1"], - "ref": ["const"], - "rowid_filter": { - "range": { - "key": "f1", - "used_key_parts": ["f1"] - }, - "rows": 1, - "selectivity_pct": 1.587301587 + "key_length": "13,33", + "index_merge": { + "intersect": { + "range": { + "key": "f1", + "used_key_parts": ["f1"] + }, + "range": { + "key": "f2", + "used_key_parts": ["f2"] + } + } }, "rows": 1, - "filtered": 1.587301612, - "index_condition": "t1.f1 is null", - "attached_condition": "t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')" + "filtered": 100, + "attached_condition": "t1.f1 is null and t1.f2 is null and (t1.f2 between 'a' and 'z' or t1.f1 = 'a')" } } } @@ -2284,7 +2340,7 @@ count(*) 6 explain extended select count(*) from t1 where a in (22,83,11) and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range b,a a 5 NULL 33 5.90 Using index condition; Using where +1 SIMPLE t1 range b,a a 5 NULL 33 100.00 Using index condition; Using where Warnings: Note 1003 select count(0) AS `count(*)` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (22,83,11) select * from t1 where a in (22,83,11) and b=2; @@ -2569,7 +2625,7 @@ WHERE 1 = 1 AND domain = 'www.mailhost.i-dev.fr' AND timestamp >= DATE_ADD(CURRENT_TIMESTAMP, INTERVAL -1 MONTH) ORDER BY timestamp DESC; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range|filter ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainTimestamp|ixEventWhoisDomainDomain 4|767 NULL 1 (29%) 100.00 Using where; Using rowid filter +1 SIMPLE t1 range ixEventWhoisDomainDomain,ixEventWhoisDomainTimestamp ixEventWhoisDomainTimestamp 4 NULL 1 100.00 Using where Warnings: Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`domain` AS `domain`,`test`.`t1`.`registrant_name` AS `registrant_name`,`test`.`t1`.`registrant_organization` AS `registrant_organization`,`test`.`t1`.`registrant_street1` AS `registrant_street1`,`test`.`t1`.`registrant_street2` AS `registrant_street2`,`test`.`t1`.`registrant_street3` AS `registrant_street3`,`test`.`t1`.`registrant_street4` AS `registrant_street4`,`test`.`t1`.`registrant_street5` AS `registrant_street5`,`test`.`t1`.`registrant_city` AS `registrant_city`,`test`.`t1`.`registrant_postal_code` AS `registrant_postal_code`,`test`.`t1`.`registrant_country` AS `registrant_country`,`test`.`t1`.`registrant_email` AS `registrant_email`,`test`.`t1`.`registrant_telephone` AS `registrant_telephone`,`test`.`t1`.`administrative_name` AS `administrative_name`,`test`.`t1`.`administrative_organization` AS `administrative_organization`,`test`.`t1`.`administrative_street1` AS `administrative_street1`,`test`.`t1`.`administrative_street2` AS `administrative_street2`,`test`.`t1`.`administrative_street3` AS `administrative_street3`,`test`.`t1`.`administrative_street4` AS `administrative_street4`,`test`.`t1`.`administrative_street5` AS `administrative_street5`,`test`.`t1`.`administrative_city` AS `administrative_city`,`test`.`t1`.`administrative_postal_code` AS `administrative_postal_code`,`test`.`t1`.`administrative_country` AS `administrative_country`,`test`.`t1`.`administrative_email` AS `administrative_email`,`test`.`t1`.`administrative_telephone` AS `administrative_telephone`,`test`.`t1`.`technical_name` AS `technical_name`,`test`.`t1`.`technical_organization` AS `technical_organization`,`test`.`t1`.`technical_street1` AS `technical_street1`,`test`.`t1`.`technical_street2` AS `technical_street2`,`test`.`t1`.`technical_street3` AS `technical_street3`,`test`.`t1`.`technical_street4` AS `technical_street4`,`test`.`t1`.`technical_street5` AS `technical_street5`,`test`.`t1`.`technical_city` AS `technical_city`,`test`.`t1`.`technical_postal_code` AS `technical_postal_code`,`test`.`t1`.`technical_country` AS `technical_country`,`test`.`t1`.`technical_email` AS `technical_email`,`test`.`t1`.`technical_telephone` AS `technical_telephone`,`test`.`t1`.`json` AS `json`,`test`.`t1`.`timestamp` AS `timestamp` from `test`.`t1` where `test`.`t1`.`domain` = 'www.mailhost.i-dev.fr' and `test`.`t1`.`timestamp` >= <cache>(current_timestamp() + interval -1 month) order by `test`.`t1`.`timestamp` desc SET optimizer_switch=@save_optimizer_switch; @@ -2616,7 +2672,7 @@ SELECT * FROM t1 WHERE (a BETWEEN 9 AND 10 OR a IS NULL) AND (b BETWEEN 9 AND 10 OR b = 9) ORDER BY pk LIMIT 1; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 index a,b PRIMARY 4 NULL 75 54.55 Using where +1 SIMPLE t1 index a,b PRIMARY 4 NULL 75 100.00 Using where Warnings: Note 1003 select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (`test`.`t1`.`a` between 9 and 10 or `test`.`t1`.`a` is null) and (`test`.`t1`.`b` between 9 and 10 or `test`.`t1`.`b` = 9) order by `test`.`t1`.`pk` limit 1 ANALYZE @@ -2624,7 +2680,7 @@ SELECT * FROM t1 WHERE (a BETWEEN 9 AND 10 OR a IS NULL) AND (b BETWEEN 9 AND 10 OR b = 9) ORDER BY pk LIMIT 1; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 index a,b PRIMARY 4 NULL 3008 3008.00 1.36 0.00 Using where +1 SIMPLE t1 index a,b PRIMARY 4 NULL 3008 3008.00 6.38 0.00 Using where DROP TABLE t1; SET global innodb_stats_persistent= @stats.save; # @@ -2784,7 +2840,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where -1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 1 (17%) 17.14 Using where; Using rowid filter +1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 1 17.14 Using where Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -2840,7 +2896,7 @@ fi.fh in (6311439873746261694,-397087483897438286, id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t index_merge PRIMARY,acli_rid,acli_tp acli_tp,acli_rid 2,767 NULL 2 100.00 Using intersect(acli_tp,acli_rid); Using where; Using index 1 SIMPLE a ref PRIMARY,acei_aclid acei_aclid 8 test.t.id 1 100.00 Using where; Using join buffer (flat, BKA join); Rowid-ordered scan -1 SIMPLE fi ref|filter filt_aceid,filt_fh filt_aceid|filt_fh 8|8 test.a.id 1 (17%) 17.14 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan; Using rowid filter +1 SIMPLE fi ref filt_aceid,filt_fh filt_aceid 8 test.a.id 1 17.14 Using where; Using join buffer (incremental, BKA join); Rowid-ordered scan Warnings: Note 1003 select `test`.`t`.`id` AS `id`,`test`.`fi`.`id` AS `id`,`test`.`fi`.`aceid` AS `aceid`,`test`.`fi`.`clid` AS `clid`,`test`.`fi`.`fh` AS `fh` from `test`.`acli` `t` join `test`.`acei` `a` join `test`.`filt` `fi` where `test`.`t`.`tp` = 121 and `test`.`a`.`atp` = 1 and `test`.`fi`.`aceid` = `test`.`a`.`id` and `test`.`a`.`aclid` = `test`.`t`.`id` and `test`.`t`.`rid` = 'B5FCC8C7111E4E3CBC21AAF5012F59C2' and `test`.`fi`.`fh` in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774) set statement optimizer_switch='rowid_filter=on' for select t.id, fi.* @@ -2930,21 +2986,9 @@ ANALYZE "key_length": "8", "used_key_parts": ["aceid"], "ref": ["test.a.id"], - "rowid_filter": { - "range": { - "key": "filt_fh", - "used_key_parts": ["fh"] - }, - "rows": 6, - "selectivity_pct": 17.14285714, - "r_rows": 5, - "r_selectivity_pct": 40, - "r_buffer_size": "REPLACED", - "r_filling_time_ms": "REPLACED" - }, "r_loops": 1, "rows": 1, - "r_rows": 2, + "r_rows": 5, "r_table_time_ms": "REPLACED", "r_other_time_ms": "REPLACED", "filtered": 17.1428566, @@ -2955,7 +2999,7 @@ ANALYZE "join_type": "BKA", "mrr_type": "Rowid-ordered scan", "attached_condition": "fi.fh in (6311439873746261694,-397087483897438286,8518228073041491534,-5420422472375069774)", - "r_filtered": 100 + "r_filtered": 40 } } } diff --git a/mysql-test/main/select.result b/mysql-test/main/select.result index dad1ce6b012..2104f78c3ac 100644 --- a/mysql-test/main/select.result +++ b/mysql-test/main/select.result @@ -3597,7 +3597,7 @@ CREATE TABLE t1(id int PRIMARY KEY, b int, e int); CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a)); CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c)); INSERT INTO t1 VALUES -(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79), +(1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79), (6,63,67), (5,55,58), (3,38,39), (8,81,89); INSERT INTO t2 VALUES (21,210), (41,410), (82,820), (83,830), (84,840), @@ -3625,6 +3625,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 1 SIMPLE t2 range si,ai si 5 NULL 4 Using index condition; Using where 1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter +EXPLAIN +SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 +WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND +t3.a=t2.a AND t3.c IN ('bb','ee'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +1 SIMPLE t2 range si si 5 NULL 13 Using index condition; Using where +1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter EXPLAIN SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND @@ -3717,7 +3725,7 @@ COUNT(*) EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ; id select_type table type possible_keys key key_len ref rows Extra @@ -3731,7 +3739,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null); EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ; id select_type table type possible_keys key key_len ref rows Extra @@ -3744,7 +3752,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); @@ -3765,7 +3773,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2 AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 -1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where +1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30 AND t1.ts BETWEEN t2.dt1 AND t2.dt2 AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31"; @@ -4031,7 +4039,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2 ON ( f1.b=f2.b AND f1.a<f2.a ) WHERE 1 AND f1.b NOT IN (100,2232,3343,51111); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index +1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index 1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index DROP TABLE t1; CREATE TABLE t1 (c1 INT, c2 INT); diff --git a/mysql-test/main/select.test b/mysql-test/main/select.test index b9891280c45..9d64d0b595c 100644 --- a/mysql-test/main/select.test +++ b/mysql-test/main/select.test @@ -1530,7 +1530,6 @@ INSERT INTO t4 (companynr, companyname) VALUES (68,'company 10'); INSERT INTO t4 (companynr, companyname) VALUES (50,'company 11'); INSERT INTO t4 (companynr, companyname) VALUES (00,'Unknown'); --enable_query_log - # # Test of stright join to force a full join. # @@ -3121,7 +3120,7 @@ CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a)); CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c)); INSERT INTO t1 VALUES - (1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79), + (1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79), (6,63,67), (5,55,58), (3,38,39), (8,81,89); INSERT INTO t2 VALUES (21,210), (41,410), (82,820), (83,830), (84,840), @@ -3143,6 +3142,11 @@ SELECT t3.a FROM t1,t2,t3 WHERE t1.id = 8 AND t2.i BETWEEN t1.b AND t1.e AND t3.a=t2.a AND t3.c IN ('bb','ee') ; +EXPLAIN +SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 + WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND + t3.a=t2.a AND t3.c IN ('bb','ee'); + EXPLAIN SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND diff --git a/mysql-test/main/select_jcl6.result b/mysql-test/main/select_jcl6.result index 51d652fa245..b93ba17e174 100644 --- a/mysql-test/main/select_jcl6.result +++ b/mysql-test/main/select_jcl6.result @@ -1391,16 +1391,16 @@ id select_type table type possible_keys key key_len ref rows Extra delete from t2 where fld1=999999; explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where -1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join) explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where -1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join) explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where -1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 hash_ALL NULL #hash#$hj 1 test.t4.companynr 1199 Using where; Using join buffer (flat, BNLH join) explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where @@ -3608,7 +3608,7 @@ CREATE TABLE t1(id int PRIMARY KEY, b int, e int); CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a)); CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c)); INSERT INTO t1 VALUES -(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79), +(1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79), (6,63,67), (5,55,58), (3,38,39), (8,81,89); INSERT INTO t2 VALUES (21,210), (41,410), (82,820), (83,830), (84,840), @@ -3636,6 +3636,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 1 SIMPLE t2 range si,ai si 5 NULL 4 Using index condition; Using where; Rowid-ordered scan 1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan; Using rowid filter +EXPLAIN +SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 +WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND +t3.a=t2.a AND t3.c IN ('bb','ee'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +1 SIMPLE t3 range PRIMARY,ci ci 5 NULL 6 Using index condition; Rowid-ordered scan +1 SIMPLE t2 hash_range si #hash#$hj:si 5:5 test.t3.a 13 Using where; Rowid-ordered scan; Using join buffer (flat, BNLH join) EXPLAIN SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND @@ -3728,7 +3736,7 @@ COUNT(*) EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ; id select_type table type possible_keys key key_len ref rows Extra @@ -3742,7 +3750,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null); EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ; id select_type table type possible_keys key key_len ref rows Extra @@ -3755,7 +3763,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); @@ -3776,7 +3784,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2 AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 -1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where; Rowid-ordered scan +1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30 AND t1.ts BETWEEN t2.dt1 AND t2.dt2 AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31"; @@ -4042,7 +4050,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2 ON ( f1.b=f2.b AND f1.a<f2.a ) WHERE 1 AND f1.b NOT IN (100,2232,3343,51111); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index +1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index 1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index DROP TABLE t1; CREATE TABLE t1 (c1 INT, c2 INT); diff --git a/mysql-test/main/select_pkeycache.result b/mysql-test/main/select_pkeycache.result index dad1ce6b012..2104f78c3ac 100644 --- a/mysql-test/main/select_pkeycache.result +++ b/mysql-test/main/select_pkeycache.result @@ -3597,7 +3597,7 @@ CREATE TABLE t1(id int PRIMARY KEY, b int, e int); CREATE TABLE t2(i int, a int, INDEX si(i), INDEX ai(a)); CREATE TABLE t3(a int PRIMARY KEY, c char(4), INDEX ci(c)); INSERT INTO t1 VALUES -(1,10,19), (2,20,22), (4,41,42), (9,93,95), (7, 77,79), +(1,10,19), (2,20,22), (4,41,42), (9,39,95), (7, 77,79), (6,63,67), (5,55,58), (3,38,39), (8,81,89); INSERT INTO t2 VALUES (21,210), (41,410), (82,820), (83,830), (84,840), @@ -3625,6 +3625,14 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 1 SIMPLE t2 range si,ai si 5 NULL 4 Using index condition; Using where 1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter +EXPLAIN +SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 +WHERE t1.id = 9 AND t2.i BETWEEN t1.b AND t1.e AND +t3.a=t2.a AND t3.c IN ('bb','ee'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +1 SIMPLE t2 range si si 5 NULL 13 Using index condition; Using where +1 SIMPLE t3 eq_ref|filter PRIMARY,ci PRIMARY|ci 4|5 test.t2.a 1 (30%) Using where; Using rowid filter EXPLAIN SELECT t3.a FROM t1,t2 FORCE INDEX (si),t3 WHERE t1.id = 8 AND (t2.i=t1.b OR t2.i=t1.e) AND t3.a=t2.a AND @@ -3717,7 +3725,7 @@ COUNT(*) EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null=3 IS NULL ; id select_type table type possible_keys key key_len ref rows Extra @@ -3731,7 +3739,7 @@ CREATE UNIQUE INDEX idx1 ON t1(ID1_with_null,ID2_with_null); EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND ID2_with_null=3 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 index_merge idx1,idx2 idx2,idx1 4,10 NULL 1 Using intersect(idx2,idx1); Using where; Using index EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null=3 AND ID2_with_null IS NULL ; id select_type table type possible_keys key key_len ref rows Extra @@ -3744,7 +3752,7 @@ EXPLAIN SELECT * FROM t1 WHERE ID_better=1 AND ID1_with_null IS NULL AND (ID2_with_null=1 OR ID2_with_null=2); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref idx1,idx2 idx2 4 const 2 Using where +1 SIMPLE t1 ref|filter idx1,idx2 idx1|idx2 5|4 const 2 (1%) Using index condition; Using where; Using rowid filter DROP TABLE t1; CREATE TABLE t1 (a INT, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, KEY ts(ts)); INSERT INTO t1 VALUES (30,"2006-01-03 23:00:00"), (31,"2006-01-03 23:00:00"); @@ -3765,7 +3773,7 @@ AND t1.ts BETWEEN t2.dt1 AND t2.dt2 AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31"; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1 -1 SIMPLE t1 range ts ts 4 NULL 2 Using index condition; Using where +1 SIMPLE t1 ALL ts NULL NULL NULL 2 Using where SELECT * FROM t1 LEFT JOIN t2 ON (t1.a=t2.a) WHERE t1.a=30 AND t1.ts BETWEEN t2.dt1 AND t2.dt2 AND t1.ts BETWEEN "2006-01-01" AND "2006-12-31"; @@ -4031,7 +4039,7 @@ EXPLAIN SELECT COUNT(*) FROM t1 f1 INNER JOIN t1 f2 ON ( f1.b=f2.b AND f1.a<f2.a ) WHERE 1 AND f1.b NOT IN (100,2232,3343,51111); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE f1 range inx inx 5 NULL 7 Using where; Using index +1 SIMPLE f1 index inx inx 10 NULL 7 Using where; Using index 1 SIMPLE f2 ref inx inx 5 test.f1.b 1 Using where; Using index DROP TABLE t1; CREATE TABLE t1 (c1 INT, c2 INT); diff --git a/mysql-test/main/select_safe.result b/mysql-test/main/select_safe.result index 649e2dc484e..90ed1a4e785 100644 --- a/mysql-test/main/select_safe.result +++ b/mysql-test/main/select_safe.result @@ -74,8 +74,8 @@ id select_type table type possible_keys key key_len ref rows Extra set MAX_SEEKS_FOR_KEY=1; 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 -1 SIMPLE t1 ALL b NULL NULL NULL 11 -1 SIMPLE t2 ALL b NULL NULL NULL 11 Using where; Using join buffer (flat, BNL join) +1 SIMPLE t1 ALL b NULL NULL NULL 11 Using where +1 SIMPLE t2 ref b b 21 test.t1.b 5 SET MAX_SEEKS_FOR_KEY=DEFAULT; drop table t1; create table t1 (a int); diff --git a/mysql-test/main/selectivity.result b/mysql-test/main/selectivity.result index 9931ca7ddce..6bd3d871edd 100644 --- a/mysql-test/main/selectivity.result +++ b/mysql-test/main/selectivity.result @@ -541,8 +541,8 @@ limit 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort 1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 -1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 4.17 Using where; Start temporary; Using join buffer (flat, BNL join) -1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; End temporary +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 4.17 Using where +1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier) 4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 15.14 Using where Warnings: Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 @@ -1661,7 +1661,7 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` # gives selectivity data explain extended select * from t1 where a in (17,51,5) and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range|filter b,a a|b 5|5 NULL 29 (6%) 5.80 Using index condition; Using where; Using rowid filter +1 SIMPLE t1 ref|filter b,a b|a 5|5 const 58 (3%) 2.90 Using where; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5) drop table t1; @@ -1790,7 +1790,7 @@ set optimizer_use_condition_selectivity=2; explain extended select t1.b,t2.a,t3.a,t3.b from t1,t2,t3 where t1.c = t2.a AND t1.d = t3.a and t1.a = 50 and t1.b <= 100; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range a a 10 NULL 9 9.00 Using index condition; Using where +1 SIMPLE t1 range a a 10 NULL 9 100.00 Using index condition; Using where 1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t1.d 1 100.00 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.c 1 100.00 Using index Warnings: diff --git a/mysql-test/main/selectivity_innodb.result b/mysql-test/main/selectivity_innodb.result index 3bd03dfc289..d31c0c3cacd 100644 --- a/mysql-test/main/selectivity_innodb.result +++ b/mysql-test/main/selectivity_innodb.result @@ -82,13 +82,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where 1 PRIMARY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where 1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where -2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where 2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where 2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 DEPENDENT SUBQUERY region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 20.00 Using where Warnings: Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` +Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`region`.`r_regionkey` = `dbt3_s001`.`nation`.`n_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` set optimizer_use_condition_selectivity=4; explain extended select @@ -123,13 +123,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where 1 PRIMARY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where 1 PRIMARY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where -2 DEPENDENT SUBQUERY region ALL PRIMARY NULL NULL NULL 5 20.00 Using where 2 DEPENDENT SUBQUERY partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 2 DEPENDENT SUBQUERY supplier eq_ref PRIMARY,i_s_nationkey PRIMARY 4 dbt3_s001.partsupp.ps_suppkey 1 100.00 Using where 2 DEPENDENT SUBQUERY nation eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 100.00 Using where +2 DEPENDENT SUBQUERY region eq_ref PRIMARY PRIMARY 4 dbt3_s001.nation.n_regionkey 1 20.00 Using where Warnings: Note 1276 Field or reference 'dbt3_s001.part.p_partkey' of SELECT #2 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` +Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_acctbal` AS `s_acctbal`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`nation`.`n_name` AS `n_name`,`dbt3_s001`.`part`.`p_partkey` AS `p_partkey`,`dbt3_s001`.`part`.`p_mfgr` AS `p_mfgr`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`dbt3_s001`.`supplier`.`s_comment` AS `s_comment` from `dbt3_s001`.`part` join `dbt3_s001`.`supplier` join `dbt3_s001`.`partsupp` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`part`.`p_size` = 9 and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`nation`.`n_regionkey` = `dbt3_s001`.`region`.`r_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_type` like '%TIN' and `dbt3_s001`.`partsupp`.`ps_supplycost` = <expr_cache><`dbt3_s001`.`part`.`p_partkey`>((/* select#2 */ select min(`dbt3_s001`.`partsupp`.`ps_supplycost`) from `dbt3_s001`.`partsupp` join `dbt3_s001`.`supplier` join `dbt3_s001`.`nation` join `dbt3_s001`.`region` where `dbt3_s001`.`supplier`.`s_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`nation`.`n_nationkey` = `dbt3_s001`.`supplier`.`s_nationkey` and `dbt3_s001`.`region`.`r_regionkey` = `dbt3_s001`.`nation`.`n_regionkey` and `dbt3_s001`.`region`.`r_name` = 'ASIA' and `dbt3_s001`.`part`.`p_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey`)) order by `dbt3_s001`.`supplier`.`s_acctbal` desc,`dbt3_s001`.`nation`.`n_name`,`dbt3_s001`.`supplier`.`s_name`,`dbt3_s001`.`part`.`p_partkey` === Q15 === create view revenue0 (supplier_no, total_revenue) as select l_suppkey, sum(l_extendedprice * (1 - l_discount)) @@ -171,7 +171,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY supplier index PRIMARY PRIMARY 4 NULL 10 100.00 1 PRIMARY <derived3> ref key0 key0 5 dbt3_s001.supplier.s_suppkey 10 100.00 Using where 3 DERIVED lineitem range i_l_shipdate,i_l_suppkey i_l_shipdate 4 NULL 229 100.00 Using where; Using temporary; Using filesort -2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 228 100.00 +2 SUBQUERY <derived4> ALL NULL NULL NULL NULL 229 100.00 4 DERIVED lineitem range i_l_shipdate i_l_shipdate 4 NULL 229 100.00 Using where; Using temporary; Using filesort Warnings: Note 1003 /* select#1 */ select `dbt3_s001`.`supplier`.`s_suppkey` AS `s_suppkey`,`dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address`,`dbt3_s001`.`supplier`.`s_phone` AS `s_phone`,`revenue0`.`total_revenue` AS `total_revenue` from `dbt3_s001`.`supplier` join `dbt3_s001`.`revenue0` where `revenue0`.`supplier_no` = `dbt3_s001`.`supplier`.`s_suppkey` and `revenue0`.`total_revenue` = (/* select#2 */ select max(`revenue0`.`total_revenue`) from `dbt3_s001`.`revenue0`) order by `dbt3_s001`.`supplier`.`s_suppkey` @@ -602,14 +602,13 @@ limit 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort 1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.03 Using where -2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.03 Using where +1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier) 4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where Warnings: Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 -Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10 +Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10 select sql_calc_found_rows s_name, s_address from supplier, nation @@ -658,14 +657,13 @@ limit 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort 1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where -2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier) 4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where Warnings: Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 -Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10 +Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10 select sql_calc_found_rows s_name, s_address from supplier, nation @@ -714,14 +712,13 @@ limit 10; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY nation ALL PRIMARY NULL NULL NULL 25 4.00 Using where; Using temporary; Using filesort 1 PRIMARY supplier ref PRIMARY,i_s_nationkey i_s_nationkey 5 dbt3_s001.nation.n_nationkey 1 100.00 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED part ALL PRIMARY NULL NULL NULL 200 7.81 Using where -2 MATERIALIZED partsupp ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 4 dbt3_s001.part.p_partkey 3 100.00 Using where +1 PRIMARY part ALL PRIMARY NULL NULL NULL 200 7.81 Using where +1 PRIMARY partsupp eq_ref PRIMARY,i_ps_partkey,i_ps_suppkey PRIMARY 8 dbt3_s001.part.p_partkey,dbt3_s001.supplier.s_suppkey 1 100.00 Using where; FirstMatch(supplier) 4 DEPENDENT SUBQUERY lineitem ref i_l_shipdate,i_l_suppkey_partkey,i_l_partkey,i_l_suppkey i_l_suppkey_partkey 10 dbt3_s001.partsupp.ps_partkey,dbt3_s001.partsupp.ps_suppkey 8 14.40 Using where Warnings: Note 1276 Field or reference 'dbt3_s001.partsupp.ps_partkey' of SELECT #4 was resolved in SELECT #2 Note 1276 Field or reference 'dbt3_s001.partsupp.ps_suppkey' of SELECT #4 was resolved in SELECT #2 -Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10 +Note 1003 /* select#1 */ select sql_calc_found_rows `dbt3_s001`.`supplier`.`s_name` AS `s_name`,`dbt3_s001`.`supplier`.`s_address` AS `s_address` from `dbt3_s001`.`supplier` semi join (`dbt3_s001`.`part` join `dbt3_s001`.`partsupp`) join `dbt3_s001`.`nation` where `dbt3_s001`.`supplier`.`s_nationkey` = `dbt3_s001`.`nation`.`n_nationkey` and `dbt3_s001`.`nation`.`n_name` = 'UNITED STATES' and `dbt3_s001`.`partsupp`.`ps_partkey` = `dbt3_s001`.`part`.`p_partkey` and `dbt3_s001`.`partsupp`.`ps_suppkey` = `dbt3_s001`.`supplier`.`s_suppkey` and `dbt3_s001`.`partsupp`.`ps_availqty` > <expr_cache><`dbt3_s001`.`partsupp`.`ps_partkey`,`dbt3_s001`.`partsupp`.`ps_suppkey`>((/* select#4 */ select 0.5 * sum(`dbt3_s001`.`lineitem`.`l_quantity`) from `dbt3_s001`.`lineitem` where `dbt3_s001`.`lineitem`.`l_partkey` = `dbt3_s001`.`partsupp`.`ps_partkey` and `dbt3_s001`.`lineitem`.`l_suppkey` = `dbt3_s001`.`partsupp`.`ps_suppkey` and `dbt3_s001`.`lineitem`.`l_shipDATE` >= <cache>(cast('1993-01-01' as date)) and `dbt3_s001`.`lineitem`.`l_shipDATE` < <cache>(cast('1993-01-01' as date) + interval '1' year))) and `dbt3_s001`.`part`.`p_name` like 'g%' order by `dbt3_s001`.`supplier`.`s_name` limit 10 select sql_calc_found_rows s_name, s_address from supplier, nation @@ -808,10 +805,9 @@ explain extended select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 1 100.00 Using where -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) Warnings: -Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` > 3 +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b` = `test`.`t1`.`a` and `test`.`t1`.`a` > 3 select * from t1 where a in ( select b from t2 ) AND ( a > 3 ); a drop table t1,t2; @@ -1673,7 +1669,7 @@ Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` # gives selectivity data explain extended select * from t1 where a in (17,51,5) and b=2; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t1 range|filter b,a a|b 5|5 NULL 29 (6%) 5.90 Using index condition; Using where; Using rowid filter +1 SIMPLE t1 ref|filter b,a b|a 5|5 const 59 (3%) 2.90 Using where; Using rowid filter Warnings: Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where `test`.`t1`.`b` = 2 and `test`.`t1`.`a` in (17,51,5) drop table t1; diff --git a/mysql-test/main/selectivity_no_engine.result b/mysql-test/main/selectivity_no_engine.result index 3811b12a1be..d8c2b83df2e 100644 --- a/mysql-test/main/selectivity_no_engine.result +++ b/mysql-test/main/selectivity_no_engine.result @@ -237,7 +237,7 @@ explain select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz'; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref f1 f1 325 const,const 2 Using index condition; Using where -1 SIMPLE t1 eq_ref PRIMARY PRIMARY 122 test.t2.t1_id 1 +1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) select * from t1,t2 where t1.id = t2.t1_id and t2.f2='qux' and t2.f1='baz'; id dt t1_id f1 f2 foo 2011-04-12 05:18:08 foo baz qux diff --git a/mysql-test/main/show_explain.result b/mysql-test/main/show_explain.result index 317a12ef311..8fd4c828bdc 100644 --- a/mysql-test/main/show_explain.result +++ b/mysql-test/main/show_explain.result @@ -28,7 +28,7 @@ select count(*) from t1 where a < 100000; connection default; show explain for $thr2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range a a 5 NULL 999 Using where; Using index +1 SIMPLE t1 index a a 5 NULL 1000 Using where; Using index Warnings: Note 1003 select count(*) from t1 where a < 100000 connection con1; @@ -620,8 +620,8 @@ SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`) connection default; show explain for $thr2; id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 20 1 PRIMARY <subquery2> const distinct_key distinct_key 8 const,const 1 -1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using join buffer (flat, BNL join) 2 MATERIALIZED t2 index NULL a1 4 NULL 20 Using index Warnings: Note 1003 SELECT * FROM t2 WHERE (5, 78) IN (SELECT `a1`, MAX(`a1`) FROM t2 GROUP BY `a1`) diff --git a/mysql-test/main/single_delete_update.result b/mysql-test/main/single_delete_update.result index 1f0299ac0fc..6a17895ef8a 100644 --- a/mysql-test/main/single_delete_update.result +++ b/mysql-test/main/single_delete_update.result @@ -151,19 +151,19 @@ Variable_name Value Sort_merge_passes 0 Sort_priority_queue_sorts 0 Sort_range 0 -Sort_rows 1 -Sort_scan 1 +Sort_rows 0 +Sort_scan 0 SHOW STATUS LIKE 'Handler_read_%'; Variable_name Value -Handler_read_first 0 +Handler_read_first 1 Handler_read_key 0 Handler_read_last 0 -Handler_read_next 0 +Handler_read_next 16 Handler_read_prev 0 Handler_read_retry 0 -Handler_read_rnd 1 +Handler_read_rnd 0 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 17 +Handler_read_rnd_next 0 ## should be 5 (previous LIMIT) SELECT 1 - COUNT(*) FROM t2 WHERE b = 10; 1 - COUNT(*) @@ -332,6 +332,7 @@ DROP TABLE t2; # CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2)); INSERT INTO t2 (key1, key2) SELECT i, i FROM t1; +INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1; FLUSH STATUS; SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; i key1 key2 @@ -754,21 +755,21 @@ UPDATE t2 SET d = 10 WHERE b = 10 ORDER BY a, c LIMIT 5; SHOW SESSION STATUS LIKE 'Sort%'; Variable_name Value Sort_merge_passes 0 -Sort_priority_queue_sorts 1 +Sort_priority_queue_sorts 0 Sort_range 0 -Sort_rows 1 -Sort_scan 1 +Sort_rows 0 +Sort_scan 0 SHOW STATUS LIKE 'Handler_read_%'; Variable_name Value -Handler_read_first 0 +Handler_read_first 1 Handler_read_key 0 Handler_read_last 0 -Handler_read_next 0 +Handler_read_next 16 Handler_read_prev 0 Handler_read_retry 0 Handler_read_rnd 1 Handler_read_rnd_deleted 0 -Handler_read_rnd_next 17 +Handler_read_rnd_next 0 ## should be 5 (previous LIMIT) SELECT COUNT(*) FROM t2 WHERE b = 10 AND d = 10 ORDER BY a, c; COUNT(*) @@ -939,6 +940,7 @@ DROP TABLE t2; # CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2)); INSERT INTO t2 (key1, key2) SELECT i, i FROM t1; +INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1; FLUSH STATUS; SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; i key1 key2 diff --git a/mysql-test/main/single_delete_update.test b/mysql-test/main/single_delete_update.test index ec939641ea3..d8a8ff1918b 100644 --- a/mysql-test/main/single_delete_update.test +++ b/mysql-test/main/single_delete_update.test @@ -143,6 +143,7 @@ DROP TABLE t2; CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2)); INSERT INTO t2 (key1, key2) SELECT i, i FROM t1; +INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1; FLUSH STATUS; SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; @@ -368,6 +369,7 @@ DROP TABLE t2; CREATE TABLE t2 (i INT, key1 INT, key2 INT, INDEX (key1), INDEX (key2)); INSERT INTO t2 (key1, key2) SELECT i, i FROM t1; +INSERT INTO t2 (key1, key2) SELECT i+100, i+100 FROM t1; FLUSH STATUS; SELECT * FROM t2 WHERE key1 < 13 or key2 < 14 ORDER BY key1; diff --git a/mysql-test/main/stat_tables.result b/mysql-test/main/stat_tables.result index a753aaa2e5d..35659bc0076 100644 --- a/mysql-test/main/stat_tables.result +++ b/mysql-test/main/stat_tables.result @@ -852,6 +852,7 @@ set histogram_size=0; # create table t1 (a int, b int); insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10); +insert into t1 select seq,seq from seq_10_to_100; set use_stat_tables= preferably_for_queries; # # with use_stat_tables= PREFERABLY_FOR_QUERIES @@ -865,7 +866,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_length avg_fr analyze select * from t1 where a = 1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 10.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 100.00 0.99 Using where # # with use_stat_tables= PREFERABLY_FOR_QUERIES # analyze table t1 will collect statistics if we use PERSISTENT @@ -877,12 +878,12 @@ test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Table is already up to date select * from mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram -test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL +test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL # filtered shows that we used the data from stat tables analyze select * from t1 where a = 1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 25.00 10.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 1.05 0.99 Using where # # with use_stat_tables= PREFERABLY # analyze table t1 will collect statistics @@ -894,13 +895,13 @@ test.t1 analyze status Engine-independent statistics collected test.t1 analyze status Table is already up to date select * from mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram -test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL -test t1 b 2 10 0.0000 4.0000 1.1111 0 NULL NULL +test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL +test t1 b 2 100 0.0000 4.0000 1.0202 0 NULL NULL # filtered shows that we used the data from stat tables analyze select * from t1 where a=1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 10.00 10.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 0.99 0.99 Using where drop table t1; set @@global.histogram_size=@save_histogram_size; # End of 10.4 tests diff --git a/mysql-test/main/stat_tables.test b/mysql-test/main/stat_tables.test index 9955908bd60..48d0e913079 100644 --- a/mysql-test/main/stat_tables.test +++ b/mysql-test/main/stat_tables.test @@ -1,5 +1,6 @@ --source include/have_stat_tables.inc --source include/have_partition.inc +--source include/have_sequence.inc select @@global.use_stat_tables; select @@session.use_stat_tables; @@ -598,6 +599,7 @@ set histogram_size=0; create table t1 (a int, b int); insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10); +insert into t1 select seq,seq from seq_10_to_100; set use_stat_tables= preferably_for_queries; --echo # --echo # with use_stat_tables= PREFERABLY_FOR_QUERIES diff --git a/mysql-test/main/stat_tables_innodb.result b/mysql-test/main/stat_tables_innodb.result index 732300e70e1..f874f6a0ff6 100644 --- a/mysql-test/main/stat_tables_innodb.result +++ b/mysql-test/main/stat_tables_innodb.result @@ -251,7 +251,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE n2 eq_ref PRIMARY PRIMARY 4 dbt3_s001.supplier.s_nationkey 1 1 SIMPLE orders eq_ref PRIMARY,i_o_orderdate,i_o_custkey PRIMARY 4 dbt3_s001.lineitem.l_orderkey 1 Using where 1 SIMPLE customer eq_ref PRIMARY,i_c_nationkey PRIMARY 4 dbt3_s001.orders.o_custkey 1 Using where -1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey PRIMARY 4 dbt3_s001.customer.c_nationkey 1 Using where +1 SIMPLE n1 eq_ref PRIMARY,i_n_regionkey i_n_regionkey 9 dbt3_s001.region.r_regionkey,dbt3_s001.customer.c_nationkey 1 Using index select o_year, sum(case when nation = 'UNITED STATES' then volume else 0 end) / sum(volume) as mkt_share @@ -884,6 +884,7 @@ set histogram_size=0; # create table t1 (a int, b int); insert into t1(a,b) values (1,2),(1,3),(1,4),(1,5),(2,6),(2,7),(3,8),(3,9),(3,9),(4,10); +insert into t1 select seq,seq from seq_10_to_100; set use_stat_tables= preferably_for_queries; # # with use_stat_tables= PREFERABLY_FOR_QUERIES @@ -897,7 +898,7 @@ db_name table_name column_name min_value max_value nulls_ratio avg_length avg_fr analyze select * from t1 where a = 1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 100.00 10.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 100.00 0.99 Using where # # with use_stat_tables= PREFERABLY_FOR_QUERIES # analyze table t1 will collect statistics if we use PERSISTENT @@ -909,12 +910,12 @@ test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK select * from mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram -test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL +test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL # filtered shows that we used the data from stat tables analyze select * from t1 where a = 1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 25.00 10.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 1.05 0.99 Using where # # with use_stat_tables= PREFERABLY # analyze table t1 will collect statistics @@ -926,13 +927,13 @@ test.t1 analyze status Engine-independent statistics collected test.t1 analyze status OK select * from mysql.column_stats; db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram -test t1 a 1 4 0.0000 4.0000 2.5000 0 NULL NULL -test t1 b 2 10 0.0000 4.0000 1.1111 0 NULL NULL +test t1 a 1 100 0.0000 4.0000 1.0632 0 NULL NULL +test t1 b 2 100 0.0000 4.0000 1.0202 0 NULL NULL # filtered shows that we used the data from stat tables analyze select * from t1 where a=1 and b=3; id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 10 10.00 10.00 10.00 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL 101 101.00 0.99 0.99 Using where drop table t1; set @@global.histogram_size=@save_histogram_size; # End of 10.4 tests diff --git a/mysql-test/main/status.result b/mysql-test/main/status.result index 7b177b63727..21874b4d2d7 100644 --- a/mysql-test/main/status.result +++ b/mysql-test/main/status.result @@ -71,10 +71,10 @@ a 6 show status like 'last_query_cost'; Variable_name Value -Last_query_cost 22.084449 +Last_query_cost 16.042725 show status like 'last_query_cost'; Variable_name Value -Last_query_cost 22.084449 +Last_query_cost 16.042725 select 1; 1 1 @@ -134,13 +134,13 @@ a 1 SHOW SESSION STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 2.802418 +Last_query_cost 1.601709 EXPLAIN SELECT a FROM t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 SHOW SESSION STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 2.802418 +Last_query_cost 1.601709 SELECT a FROM t1 UNION SELECT a FROM t1 ORDER BY a; a 1 @@ -173,7 +173,7 @@ a a 1 1 SHOW SESSION STATUS LIKE 'Last_query_cost'; Variable_name Value -Last_query_cost 6.805836 +Last_query_cost 4.203418 DROP TABLE t1; connect con1,localhost,root,,; show status like 'com_show_status'; diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result index bda01f7fe5f..1d9c165b150 100644 --- a/mysql-test/main/subselect.result +++ b/mysql-test/main/subselect.result @@ -922,10 +922,10 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` drop table t1,t2,t3; # check correct NULL Processing for normal IN/ALL/ANY # and 2 ways of max/min optimization @@ -1449,21 +1449,21 @@ a 4 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30 +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); a 2 3 explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 -1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a` +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a` drop table t1, t2, t3; create table t1 (a int, b int, index a (a,b)); create table t2 (a int, index a (a)); @@ -1503,7 +1503,7 @@ a explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index -1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index 1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2) Warnings: Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a` @@ -1611,21 +1611,21 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index @@ -2418,16 +2418,18 @@ a 3 DROP TABLE t1; create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); a b 1 2 3 4 +5 6 +7 8 explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00 Warnings: Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1 @@ -3100,7 +3102,7 @@ retailerID statusID changed drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3113,7 +3115,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using where +2 SUBQUERY t2 ref cb cb 5 const 1 Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3125,7 +3127,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using index condition +2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -4438,7 +4440,7 @@ out_a MIN(b) DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); 2 @@ -4447,7 +4449,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Warnings: @@ -4457,7 +4459,7 @@ EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL @@ -4541,15 +4543,15 @@ SET @save_join_cache_level=@@join_cache_level; SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` > 3 group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1 @@ -6080,8 +6082,7 @@ WHERE col_varchar_nokey IN (SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index +1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot) SELECT col_int_nokey FROM ot WHERE col_varchar_nokey IN (SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); @@ -6093,8 +6094,7 @@ WHERE (col_varchar_nokey, 'x') IN (SELECT col_varchar_key, col_varchar_key2 FROM it2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 -2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index +1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot) SELECT col_int_nokey FROM ot WHERE (col_varchar_nokey, 'x') IN (SELECT col_varchar_key, col_varchar_key2 FROM it2); diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test index 19c30bd6dc8..2093b4ff2d7 100644 --- a/mysql-test/main/subselect.test +++ b/mysql-test/main/subselect.test @@ -7,6 +7,7 @@ # as possible. # # Initialise +--source include/have_sequence.inc --disable_warnings drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t11,t12; drop view if exists v2; @@ -999,6 +1000,7 @@ create table t1 (s1 char(5), index s1(s1)); create table t2 (s1 char(5), index s1(s1)); insert into t1 values ('a1'),('a2'),('a3'); insert into t2 values ('a1'),('a2'); + select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; select s1, s1 = ANY (SELECT s1 FROM t2) from t1; select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; @@ -1423,7 +1425,7 @@ DROP TABLE t1; # SELECT(EXISTS * ...)optimisation # create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); drop table t1; @@ -2033,7 +2035,7 @@ drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3326,7 +3328,7 @@ DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); diff --git a/mysql-test/main/subselect2.result b/mysql-test/main/subselect2.result index 34e6e857d14..9685d4f87e4 100644 --- a/mysql-test/main/subselect2.result +++ b/mysql-test/main/subselect2.result @@ -132,7 +132,7 @@ id select_type table type possible_keys key key_len ref rows Extra 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 ref|filter PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX FFOLDERID_IDX|CMFLDRPARNT_IDX 34|35 test.t3.PARENTID 1 (29%) Using where; Using rowid filter +1 PRIMARY t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 Using where drop table t1, t2, t3, t4; CREATE TABLE t1 (a int(10) , PRIMARY KEY (a)) Engine=InnoDB; INSERT INTO t1 VALUES (1),(2); @@ -163,7 +163,7 @@ SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM t1) OR a = b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index a a 5 NULL 2 Using where; Using index 1 PRIMARY t3 ref b b 5 test.t2.a 2 Using index -2 SUBQUERY t1 const PRIMARY,a PRIMARY 4 const 1 Using where +2 SUBQUERY t1 const PRIMARY,a a 9 const,const 1 Using where; Using index SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM t1) OR a = b; pk a b 0 4 4 @@ -172,7 +172,7 @@ SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM v1) OR a = b; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 index a a 5 NULL 2 Using where; Using index 1 PRIMARY t3 ref b b 5 test.t2.a 2 Using index -2 SUBQUERY t1 const PRIMARY,a PRIMARY 4 const 1 Using where +2 SUBQUERY t1 const PRIMARY,a a 9 const,const 1 Using where; Using index SELECT * FROM t2,t3 WHERE (2,9) IN (SELECT DISTINCT a,pk FROM v1) OR a = b; pk a b 0 4 4 @@ -287,7 +287,7 @@ ORDER BY mirror_date ASC ) AS calculated_result; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 -2 DERIVED t1 range date date 6 NULL 3 Using index condition; Using where; Rowid-ordered scan; Using filesort +2 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort SELECT * FROM ( SELECT node_uid, date, mirror_date, @result := 0 AS result FROM t1 @@ -310,7 +310,7 @@ ORDER BY mirror_date ASC ) AS calculated_result; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3 -2 DERIVED t1 range date date 6 NULL 3 Using index condition; Using where; Using filesort +2 DERIVED t1 ALL date NULL NULL NULL 3 Using where; Using filesort SELECT * FROM ( SELECT node_uid, date, mirror_date, @result := 0 AS result FROM t1 diff --git a/mysql-test/main/subselect3.result b/mysql-test/main/subselect3.result index 299faadeff7..b30ab0a1b18 100644 --- a/mysql-test/main/subselect3.result +++ b/mysql-test/main/subselect3.result @@ -96,10 +96,10 @@ explain extended select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 -2 DEPENDENT SUBQUERY t1 ALL a NULL NULL NULL 8 100.00 Using where +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 3 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`oref` = `test`.`t2`.`oref` and trigcond(<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a` or `test`.`t1`.`a` is null) having trigcond(`test`.`t1`.`a` is null)))) AS `Z` from `test`.`t2` +Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where `test`.`t1`.`oref` = `test`.`t2`.`oref` having trigcond(`test`.`t1`.`a` is null))))) AS `Z` from `test`.`t2` flush status; select oref, a from t2 where a in (select a from t1 where oref=t2.oref); oref a @@ -1339,9 +1339,9 @@ insert into t2 select * from t2; explain select * from t1 where (a,b,c) in (select X.a, Y.a, Z.a from t2 X, t2 Y, t2 Z where X.b=33); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -1 PRIMARY X ALL NULL NULL NULL NULL 6 Using where; Start temporary; Using join buffer (flat, BNL join) -1 PRIMARY Y ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) -1 PRIMARY Z ALL NULL NULL NULL NULL 6 Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY X ALL NULL NULL NULL NULL 6 Using where +1 PRIMARY Y ALL NULL NULL NULL NULL 6 Using where +1 PRIMARY Z ALL NULL NULL NULL NULL 6 Using where; FirstMatch(t1) drop table t0,t1,t2; set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/main/subselect3_jcl6.result b/mysql-test/main/subselect3_jcl6.result index 65002329588..071f5bfebf8 100644 --- a/mysql-test/main/subselect3_jcl6.result +++ b/mysql-test/main/subselect3_jcl6.result @@ -99,10 +99,10 @@ explain extended select oref, a, a in (select a from t1 where oref=t2.oref) Z from t2; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 4 100.00 -2 DEPENDENT SUBQUERY t1 ALL a NULL NULL NULL 8 100.00 Using where +2 DEPENDENT SUBQUERY t1 index_subquery a a 5 func 3 100.00 Using where; Full scan on NULL key Warnings: Note 1276 Field or reference 'test.t2.oref' of SELECT #2 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where `test`.`t1`.`oref` = `test`.`t2`.`oref` and trigcond(<cache>(`test`.`t2`.`a`) = `test`.`t1`.`a` or `test`.`t1`.`a` is null) having trigcond(`test`.`t1`.`a` is null)))) AS `Z` from `test`.`t2` +Note 1003 /* select#1 */ select `test`.`t2`.`oref` AS `oref`,`test`.`t2`.`a` AS `a`,<expr_cache><`test`.`t2`.`a`,`test`.`t2`.`oref`>(<in_optimizer>(`test`.`t2`.`a`,<exists>(<index_lookup>(<cache>(`test`.`t2`.`a`) in t1 on a checking NULL where `test`.`t1`.`oref` = `test`.`t2`.`oref` having trigcond(`test`.`t1`.`a` is null))))) AS `Z` from `test`.`t2` flush status; select oref, a from t2 where a in (select a from t1 where oref=t2.oref); oref a @@ -622,8 +622,8 @@ aa 1 1 bb NULL NULL select oref, a from t2 where a in (select ie from t1 where oref=t2.oref); oref a -aa 1 cc 5 +aa 1 select oref, a from t2 where a not in (select ie from t1 where oref=t2.oref); oref a ee NULL diff --git a/mysql-test/main/subselect4.result b/mysql-test/main/subselect4.result index e2199ab9578..7b2baa16bb5 100644 --- a/mysql-test/main/subselect4.result +++ b/mysql-test/main/subselect4.result @@ -714,8 +714,7 @@ WHERE ( t1.f10 ) IN ( SELECT f11 FROM t2 GROUP BY f11 )); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 -2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE f3 = ( SELECT t1.f3 FROM t1 @@ -729,8 +728,7 @@ WHERE ( f10, f10 ) IN ( SELECT f11, f11 FROM t2 GROUP BY f11 )); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2 -2 SUBQUERY <subquery3> eq_ref distinct_key distinct_key 8 func,func 1 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE f3 = ( SELECT f3 FROM t1 @@ -1369,7 +1367,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system NULL NULL NULL NULL 1 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 Using where 3 SUBQUERY SQ1_t1 index NULL f4 5 NULL 2 Using index; Using temporary -3 SUBQUERY SQ1_t3 range f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +3 SUBQUERY SQ1_t3 index f4 f4 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE (SELECT f2 FROM t2 WHERE f4 <= ALL @@ -1389,8 +1387,8 @@ INSERT INTO t2 VALUES (1), (2); EXPLAIN SELECT i FROM t1 WHERE (1) NOT IN (SELECT i FROM t2); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 system NULL NULL NULL NULL 1 -2 SUBQUERY t2 index_subquery k k 5 const 2 Using index +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY t2 index k k 5 NULL 2 Using where; Using index DROP TABLE t2; DROP TABLE t1; # @@ -1786,7 +1784,7 @@ SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 2 SUBQUERY t3 system NULL NULL NULL NULL 1 -2 SUBQUERY t2 ref_or_null f10 f10 10 const,const 2 Using where; Using index +2 SUBQUERY t2 index f10 f10 10 NULL 2 Using where; Using index SELECT * FROM t1 WHERE ( 6 ) NOT IN ( SELECT t2.f3 FROM t2 JOIN t3 ON t3.f10 = t2.f10); f4 drop table t1,t2,t3; diff --git a/mysql-test/main/subselect_exists2in.result b/mysql-test/main/subselect_exists2in.result index a473f48e0f6..c01c28fc258 100644 --- a/mysql-test/main/subselect_exists2in.result +++ b/mysql-test/main/subselect_exists2in.result @@ -902,9 +902,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where -3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where -3 DEPENDENT SUBQUERY <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00 -4 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 +3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch +3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'sq1.f1' of SELECT #3 was resolved in SELECT #1 @@ -922,9 +921,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where -3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where -3 DEPENDENT SUBQUERY <subquery4> eq_ref distinct_key distinct_key 4 func 1 100.00 -4 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 +3 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch +3 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'sq1.pk' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'sq1.f1' of SELECT #3 was resolved in SELECT #1 diff --git a/mysql-test/main/subselect_exists2in_costmat.result b/mysql-test/main/subselect_exists2in_costmat.result index 1c9574aafd3..5630f8f275a 100644 --- a/mysql-test/main/subselect_exists2in_costmat.result +++ b/mysql-test/main/subselect_exists2in_costmat.result @@ -64,8 +64,8 @@ Code = Country) OR Name LIKE 'L%') AND surfacearea > 1000000; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where -2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where +1 PRIMARY Country range Name,SurfaceArea SurfaceArea 4 NULL 71 Using index condition; Using where; Rowid-ordered scan +2 DEPENDENT SUBQUERY City index_subquery Population,Country Country 3 func 17 Using where SELECT Name FROM Country WHERE (EXISTS (select 1 from City where City.Population > 100000 and Code = Country) OR diff --git a/mysql-test/main/subselect_exists2in_costmat.test b/mysql-test/main/subselect_exists2in_costmat.test index 371f0936d1a..dd3890496f5 100644 --- a/mysql-test/main/subselect_exists2in_costmat.test +++ b/mysql-test/main/subselect_exists2in_costmat.test @@ -67,6 +67,7 @@ set @@optimizer_switch = 'exists_to_in=on,in_to_exists=on,semijoin=on,materializ -- echo Q1.1m: -- echo MATERIALIZATION: there are too many rows in the outer query -- echo to be looked up in the inner table. + EXPLAIN SELECT Name FROM Country WHERE (EXISTS (select 1 from City where City.Population > 100000 and diff --git a/mysql-test/main/subselect_extra.result b/mysql-test/main/subselect_extra.result index c654fdfca13..057d05e0038 100644 --- a/mysql-test/main/subselect_extra.result +++ b/mysql-test/main/subselect_extra.result @@ -451,8 +451,8 @@ WHERE t3.b IN (SELECT v1.b FROM v1, t2 WHERE t2.c = v1.c AND t2.c = v1.b AND v1.b = t3.c); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 system NULL NULL NULL NULL 1 -1 PRIMARY <derived3> ref key1 key1 8 const,const 0 Start temporary -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY <derived3> ref key1 key1 8 const,const 0 FirstMatch(t3) 3 DERIVED t1 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM t3 WHERE t3.b IN (SELECT v1.b FROM v1, t2 diff --git a/mysql-test/main/subselect_innodb.result b/mysql-test/main/subselect_innodb.result index 7239d64d81e..0d75ad32f45 100644 --- a/mysql-test/main/subselect_innodb.result +++ b/mysql-test/main/subselect_innodb.result @@ -312,7 +312,7 @@ EXPLAIN SELECT 1 FROM t1 WHERE NOT EXISTS (SELECT 1 FROM t2 WHERE d = (SELECT d FROM t2 WHERE a >= 1) ORDER BY d); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 1 Using where -2 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY,d PRIMARY 1 func 1 Using where +2 DEPENDENT SUBQUERY t2 unique_subquery PRIMARY,d d 2 func 1 Using index; Using where 3 DEPENDENT SUBQUERY t2 index NULL d 2 NULL 1 Using index DROP TABLE t2; CREATE TABLE t2 (b INT, c INT, UNIQUE KEY (b), UNIQUE KEY (b, c )) ENGINE=INNODB; @@ -608,11 +608,10 @@ INNER JOIN ON ( 1 IN ( SELECT f4 FROM t4 ) ) ) ON ( f1 >= f2 ); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 -1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 -1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t4 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (flat, BNL join) +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; Using join buffer (incremental, BNL join) 1 PRIMARY t3 ALL NULL NULL NULL NULL 2 100.00 Using join buffer (incremental, BNL join) -3 MATERIALIZED t4 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` semi join (`test`.`t4`) join `test`.`t3` where `test`.`t4`.`f4` = 1 and `test`.`t1`.`f1` >= `test`.`t2`.`f2` DROP TABLE t1,t2,t3,t4; diff --git a/mysql-test/main/subselect_mat.result b/mysql-test/main/subselect_mat.result index 3d014730c6a..29dcc706444 100644 --- a/mysql-test/main/subselect_mat.result +++ b/mysql-test/main/subselect_mat.result @@ -105,7 +105,7 @@ explain extended select * from t1i where a1 in (select b1 from t2i where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where; -2 MATERIALIZED t2i range it2i1,it2i3 it2i1 # NULL 5 100.00 Using where; +2 MATERIALIZED t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where; Warnings: Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1`)))) select * from t1i where a1 in (select b1 from t2i where b1 > '0'); @@ -127,7 +127,7 @@ explain extended select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1i index NULL _it1_idx # NULL 3 100.00 Using where; -2 MATERIALIZED t2i range it2i1,it2i3 it2i3 # NULL 5 100.00 Using where; +2 MATERIALIZED t2i index it2i1,it2i3 it2i3 # NULL 5 100.00 Using where; Warnings: Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); @@ -340,7 +340,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1i index NULL # # # 3 100.00 # 3 MATERIALIZED t3i index NULL # # # 4 100.00 # 4 MATERIALIZED t2i index it2i2 # # # 5 100.00 # -2 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 # +2 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 # Warnings: Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#3 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#4 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery4>`.`b1` and `test`.`t3i`.`c2` = `<subquery4>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery3>`.`c1` and `test`.`t1i`.`a2` = `<subquery3>`.`c2`)))) select * from t1i @@ -423,7 +423,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 7 UNION t1i index NULL # # # 3 100.00 # 9 MATERIALIZED t3i index NULL # # # 4 100.00 # 10 MATERIALIZED t2i index it2i2 # # # 5 100.00 # -8 MATERIALIZED t2i range it2i1,it2i3 # # # 5 100.00 # +8 MATERIALIZED t2i index it2i1,it2i3 # # # 5 100.00 # NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL # Warnings: Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (/* select#5 */ select `test`.`t3`.`c1`,`test`.`t3`.`c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`,`test`.`t3`.`c2`>(<in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery6>`.`b1` and `test`.`t3`.`c2` = `<subquery6>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery5>`.`c1` and `test`.`t1`.`a2` = `<subquery5>`.`c2`))))) union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#8 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery8>`.`b1` and `test`.`t1i`.`a2` = `<subquery8>`.`b2`)))) and <expr_cache><`test`.`t1i`.`a1`,`test`.`t1i`.`a2`>(<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (/* select#9 */ select `test`.`t3i`.`c1`,`test`.`t3i`.`c2` from `test`.`t3i` where <expr_cache><`test`.`t3i`.`c1`,`test`.`t3i`.`c2`>(<in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (/* select#10 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key where `test`.`t3i`.`c1` = `<subquery10>`.`b1` and `test`.`t3i`.`c2` = `<subquery10>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery9>`.`c1` and `test`.`t1i`.`a2` = `<subquery9>`.`c2`))))) @@ -1534,8 +1534,7 @@ SET @@optimizer_switch='semijoin=on,materialization=on'; EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan +1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); pk 2 @@ -1889,8 +1888,8 @@ WHERE alias4.c = alias3.b ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables -3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2 Using where -3 MATERIALIZED alias4 ref c c 11 test.alias3.b 2 Using where; Using index +3 MATERIALIZED alias3 ALL NULL NULL NULL NULL 2 +3 MATERIALIZED alias4 index c c 11 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) DROP TABLE t1,t2; # # BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result @@ -1953,11 +1952,11 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(/*always not null*/ 1 is null) or `<subquery2>`.`MAX(c)` = 7) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `<subquery2>`.`MAX(c)` = `test`.`t1`.`a` and (`test`.`t1`.`a` is null or `test`.`t1`.`a` = 7) SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); a b @@ -1966,8 +1965,8 @@ EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b); @@ -2241,9 +2240,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY sq1 ALL NULL NULL NULL NULL 2 Using where -2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where -2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 -3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; FirstMatch +2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) # this checks the result set above set optimizer_switch= 'materialization=off,semijoin=off'; SELECT sq1.f2 FROM t1 AS sq1 @@ -2275,10 +2273,9 @@ WHERE EXISTS ( SELECT * FROM t2, t3 WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where -2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index -2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 100.00 Using where; FirstMatch +2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index -3 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 100.00 Warnings: Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where <expr_cache><`test`.`t1`.`f1`>(exists(/* select#2 */ select 1 from `test`.`t2` semi join (`test`.`t3`) join `test`.`t3` where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`f1` = `test`.`t3`.`f3` limit 1)) @@ -2314,9 +2311,8 @@ SELECT pk, f1, ( SELECT COUNT(*) FROM t2 WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 -2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`f1` AS `f1`,<expr_cache><`test`.`t1`.`pk`>((/* select#2 */ select count(0) from `test`.`t2` semi join (`test`.`t2`) where `test`.`t1`.`pk` = `test`.`t2`.`f2`)) AS `sq` from `test`.`t1` @@ -2399,11 +2395,10 @@ WHERE t2.ugroup = t3_i.sys_id AND t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND t2.user = '86826bf03710200044e0bfc8bcbe5d79'); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 +1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary 1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where; End temporary 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index -2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where -2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where SELECT t1.assignment_group FROM t1, t3 WHERE t1.assignment_group = t3.sys_id AND @@ -2435,8 +2430,7 @@ explain SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 9 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); 1 1 @@ -2447,8 +2441,8 @@ alter table t1 add key(id); explain SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); 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 t1 ref id id 4 test.t2.i1 2 Using index +1 PRIMARY t1 index id id 4 NULL 9 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); 1 @@ -2504,8 +2498,8 @@ INSERT INTO t2 VALUES (11,11),(12,12),(13,13); CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2; explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1); 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 t1 ref id id 4 test.t2.i1 2 Using index +1 PRIMARY t1 index id id 4 NULL 9 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1); 1 @@ -2802,6 +2796,7 @@ PRIMARY KEY (pk) INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); CREATE TABLE t2 LIKE t1; INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); +insert into t2 select -seq,"","","","" from seq_1_to_10; SET @@optimizer_switch='default,semijoin=on,materialization=on'; EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); id select_type table type possible_keys key key_len ref rows Extra diff --git a/mysql-test/main/subselect_mat.test b/mysql-test/main/subselect_mat.test index fc43d19ae11..be295f8925d 100644 --- a/mysql-test/main/subselect_mat.test +++ b/mysql-test/main/subselect_mat.test @@ -2,7 +2,7 @@ # Hash semi-join regression tests # (WL#1110: Subquery optimization: materialization) # - +--source include/have_sequence.inc # force the use of materialization set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off'; @@ -111,6 +111,7 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff'); CREATE TABLE t2 LIKE t1; INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff'); +insert into t2 select -seq,"","","","" from seq_1_to_10; SET @@optimizer_switch='default,semijoin=on,materialization=on'; EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); diff --git a/mysql-test/main/subselect_mat_cost.result b/mysql-test/main/subselect_mat_cost.result index 66d48b549c4..be0f0a6fcfd 100644 --- a/mysql-test/main/subselect_mat_cost.result +++ b/mysql-test/main/subselect_mat_cost.result @@ -59,15 +59,15 @@ set @@optimizer_switch = 'in_to_exists=on,semijoin=on,materialization=on,partial Q1.1m: MATERIALIZATION: there are too many rows in the outer query to be looked up in the inner table. -EXPLAIN +set statement optimizer_cache_hit_ratio=20 for EXPLAIN SELECT Name FROM Country WHERE (Code IN (select Country from City where City.Population > 100000) OR Name LIKE 'L%') AND surfacearea > 1000000; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY Country ALL Name,SurfaceArea NULL NULL NULL 239 Using where -2 MATERIALIZED City ALL Population,Country NULL NULL NULL 4079 Using where -SELECT Name FROM Country +3 DEPENDENT SUBQUERY City index_subquery Population,Country Country 3 func 17 Using where +set statement optimizer_cache_hit_ratio=20 for SELECT Name FROM Country WHERE (Code IN (select Country from City where City.Population > 100000) OR Name LIKE 'L%') AND surfacearea > 1000000; @@ -133,9 +133,9 @@ Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND (select Language from CountryLanguage where Percentage > 50) OR City.name LIKE '%Island%'); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where +1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 47 Using index condition; Rowid-ordered scan 1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where -2 MATERIALIZED CountryLanguage ALL Percentage,Language NULL NULL NULL 984 Using where +2 MATERIALIZED CountryLanguage range Percentage,Language Percentage 4 NULL 197 Using index condition; Rowid-ordered scan SELECT * FROM Country, City WHERE City.Country = Country.Code AND @@ -158,7 +158,7 @@ Country.SurfaceArea < 3000 AND Country.SurfaceArea > 10 AND (select Language from CountryLanguage where Percentage > 50) OR Country.name LIKE '%Island%'); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where +1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 47 Using index condition; Using where; Rowid-ordered scan 1 PRIMARY City ref Country Country 3 world.Country.Code 17 2 DEPENDENT SUBQUERY CountryLanguage index_subquery Percentage,Language Language 30 func 2 Using where SELECT * @@ -203,7 +203,7 @@ OR (Country.Code, City.Name) IN (select Country, Language from CountryLanguage)); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY Country ALL PRIMARY,SurfaceArea NULL NULL NULL 239 Using where +1 PRIMARY Country range PRIMARY,SurfaceArea SurfaceArea 4 NULL 73 Using index condition; Rowid-ordered scan 1 PRIMARY City ref Country Country 3 world.Country.Code 17 Using where 3 MATERIALIZED CountryLanguage index PRIMARY,Language PRIMARY 33 NULL 984 Using index 2 DEPENDENT SUBQUERY CountryLanguage unique_subquery PRIMARY,Percentage,Language PRIMARY 33 func,func 1 Using where diff --git a/mysql-test/main/subselect_mat_cost.test b/mysql-test/main/subselect_mat_cost.test index 8fe38849735..12263e75cfc 100644 --- a/mysql-test/main/subselect_mat_cost.test +++ b/mysql-test/main/subselect_mat_cost.test @@ -73,13 +73,13 @@ set @@optimizer_switch = 'in_to_exists=on,semijoin=on,materialization=on,partial -- echo Q1.1m: -- echo MATERIALIZATION: there are too many rows in the outer query -- echo to be looked up in the inner table. -EXPLAIN +set statement optimizer_cache_hit_ratio=20 for EXPLAIN SELECT Name FROM Country WHERE (Code IN (select Country from City where City.Population > 100000) OR Name LIKE 'L%') AND surfacearea > 1000000; -SELECT Name FROM Country +set statement optimizer_cache_hit_ratio=20 for SELECT Name FROM Country WHERE (Code IN (select Country from City where City.Population > 100000) OR Name LIKE 'L%') AND surfacearea > 1000000; @@ -210,7 +210,6 @@ WHERE Code NOT IN (SELECT Country FROM CountryLanguage WHERE Language = 'English -- echo MATERIALIZATION because the outer query filters less rows than Q5-a, -- echo so there are more lookups. - set statement optimizer_switch='rowid_filter=off' for EXPLAIN SELECT Country.Name @@ -369,6 +368,7 @@ drop index CountryCapital on Country; # TODO: the cost estimates for subqueries in the HAVING clause need to be changed # to take into account that the subquery predicate is executed #times ~ to the # number of groups, not number of rows + EXPLAIN SELECT City.Name, City.Population FROM City JOIN Country ON City.Country = Country.Code diff --git a/mysql-test/main/subselect_mat_cost_bugs.result b/mysql-test/main/subselect_mat_cost_bugs.result index 26deb2d326a..f94fcf60c5e 100644 --- a/mysql-test/main/subselect_mat_cost_bugs.result +++ b/mysql-test/main/subselect_mat_cost_bugs.result @@ -197,7 +197,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 Using where; Using filesort 1 PRIMARY alias1 eq_ref PRIMARY PRIMARY 4 alias2.f3 1 Using index 3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 -3 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) +3 DEPENDENT SUBQUERY t1 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) 2 DERIVED t2 ALL NULL NULL NULL NULL 2 SELECT alias2.f2 AS field1 FROM t1 AS alias1 JOIN ( SELECT * FROM t2 ) AS alias2 ON alias2.f3 = alias1.f1 @@ -363,8 +363,8 @@ WHERE t4.a >= t3.b AND a = SOME (SELECT b FROM t5)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where -2 DEPENDENT SUBQUERY t5 index c c 10 NULL 2 Using where; Using index; Start temporary -2 DEPENDENT SUBQUERY t4 eq_ref PRIMARY PRIMARY 4 test.t5.b 1 Using index condition; Using where; End temporary +2 DEPENDENT SUBQUERY t4 ALL PRIMARY NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t5 index c c 10 NULL 2 Using where; Using index; Start temporary; End temporary; Using join buffer (flat, BNL join) SELECT * FROM t3 WHERE t3.b > ALL ( diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result index a568a2d25a1..81c508b7921 100644 --- a/mysql-test/main/subselect_no_exists_to_in.result +++ b/mysql-test/main/subselect_no_exists_to_in.result @@ -926,10 +926,10 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` drop table t1,t2,t3; # check correct NULL Processing for normal IN/ALL/ANY # and 2 ways of max/min optimization @@ -1453,21 +1453,21 @@ a 4 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30 +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); a 2 3 explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 -1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a` +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a` drop table t1, t2, t3; create table t1 (a int, b int, index a (a,b)); create table t2 (a int, index a (a)); @@ -1507,7 +1507,7 @@ a explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index -1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index 1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2) Warnings: Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a` @@ -1615,21 +1615,21 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index @@ -2422,15 +2422,17 @@ a 3 DROP TABLE t1; create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); a b 1 2 3 4 +5 6 +7 8 explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where Warnings: Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(exists(/* select#2 */ select 1 from `test`.`t1` where `test`.`t1`.`a` = `test`.`up`.`a` limit 1)) @@ -3103,7 +3105,7 @@ retailerID statusID changed drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3116,7 +3118,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using where +2 SUBQUERY t2 ref cb cb 5 const 1 Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3128,7 +3130,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using index condition +2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -4441,7 +4443,7 @@ out_a MIN(b) DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); 2 @@ -4450,7 +4452,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 @@ -4459,7 +4461,7 @@ EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL @@ -4543,15 +4545,15 @@ SET @save_join_cache_level=@@join_cache_level; SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` > 3 group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1 @@ -6080,8 +6082,7 @@ WHERE col_varchar_nokey IN (SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index +1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot) SELECT col_int_nokey FROM ot WHERE col_varchar_nokey IN (SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); @@ -6093,8 +6094,7 @@ WHERE (col_varchar_nokey, 'x') IN (SELECT col_varchar_key, col_varchar_key2 FROM it2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 -2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index +1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot) SELECT col_int_nokey FROM ot WHERE (col_varchar_nokey, 'x') IN (SELECT col_varchar_key, col_varchar_key2 FROM it2); diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result index 8ca53e0f64d..367a468b517 100644 --- a/mysql-test/main/subselect_no_mat.result +++ b/mysql-test/main/subselect_no_mat.result @@ -929,10 +929,10 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` drop table t1,t2,t3; # check correct NULL Processing for normal IN/ALL/ANY # and 2 ways of max/min optimization @@ -1456,21 +1456,21 @@ a 4 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30 +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); a 2 3 explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 -1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a` +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a` drop table t1, t2, t3; create table t1 (a int, b int, index a (a,b)); create table t2 (a int, index a (a)); @@ -1510,7 +1510,7 @@ a explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index -1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index 1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2) Warnings: Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a` @@ -1618,21 +1618,21 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!<expr_cache><`test`.`t1`.`s1`>(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index @@ -2425,15 +2425,17 @@ a 3 DROP TABLE t1; create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); a b 1 2 3 4 +5 6 +7 8 explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(up); Using join buffer (flat, BNL join) +1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where; FirstMatch(up); Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where `test`.`t1`.`a` = `test`.`up`.`a` @@ -3105,7 +3107,7 @@ retailerID statusID changed drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3118,7 +3120,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using where +2 SUBQUERY t2 ref cb cb 5 const 1 Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3130,7 +3132,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using index condition +2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -4228,8 +4230,8 @@ INSERT INTO t2 VALUES (7), (5), (1), (3); SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id); id st -3 FL 1 GA +3 FL 7 FL SELECT id, st FROM t1 WHERE st IN ('GA','FL') AND EXISTS(SELECT 1 FROM t2 WHERE t2.id=t1.id) @@ -4441,7 +4443,7 @@ out_a MIN(b) DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); 2 @@ -4450,7 +4452,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 @@ -4459,7 +4461,7 @@ EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL @@ -5687,9 +5689,9 @@ WHERE (ot1.a,ot4.a) IN (SELECT it2.a,it3.a FROM it2,it3); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot1 ALL NULL NULL NULL NULL 2 -1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where; Start temporary; Using join buffer (flat, BNL join) -1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join) -1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY ot4 ALL NULL NULL NULL NULL 8 Using join buffer (flat, BNL join) +1 PRIMARY it2 ALL NULL NULL NULL NULL 4 Using where +1 PRIMARY it3 ALL NULL NULL NULL NULL 6 Using where; FirstMatch(ot4) DROP TABLE IF EXISTS ot1, ot4, it2, it3; # # Bug#729039: NULL keys used to evaluate subquery diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result index 5c5055da2f5..065db205c5f 100644 --- a/mysql-test/main/subselect_no_opts.result +++ b/mysql-test/main/subselect_no_opts.result @@ -925,10 +925,10 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null)) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null)) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` drop table t1,t2,t3; # check correct NULL Processing for normal IN/ALL/ANY # and 2 ways of max/min optimization @@ -1614,21 +1614,21 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index @@ -2421,15 +2421,17 @@ a 3 DROP TABLE t1; create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); a b 1 2 3 4 +5 6 +7 8 explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 4 100.00 Using where Warnings: Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <in_optimizer>(`test`.`up`.`a`,<exists>(/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where <cache>(`test`.`up`.`a`) = `test`.`t1`.`a`)) @@ -3101,7 +3103,7 @@ retailerID statusID changed drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3114,7 +3116,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using where +2 SUBQUERY t2 ref cb cb 5 const 1 Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3126,7 +3128,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using index condition +2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -4437,7 +4439,7 @@ out_a MIN(b) DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); 2 @@ -4446,7 +4448,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 @@ -4455,7 +4457,7 @@ EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result index e6354f05a7f..ed0bc65584f 100644 --- a/mysql-test/main/subselect_no_scache.result +++ b/mysql-test/main/subselect_no_scache.result @@ -928,10 +928,10 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 DEPENDENT SUBQUERY t2 ref_or_null a a 5 func 2 100.00 Using where; Using index -2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 3 100.00 +2 DEPENDENT SUBQUERY t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t2`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null)) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` and (<cache>(`test`.`t1`.`a`) = `test`.`t2`.`a` or `test`.`t2`.`a` is null) having `test`.`t2`.`a` is null)) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` drop table t1,t2,t3; # check correct NULL Processing for normal IN/ALL/ANY # and 2 ways of max/min optimization @@ -1455,21 +1455,21 @@ a 4 explain extended select * from t2 where t2.a in (select a from t1 where t1.b <> 30); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 Using where +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t1`.`a` = `test`.`t2`.`a` and `test`.`t1`.`b` <> 30 +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`a` = `test`.`t1`.`a` and `test`.`t1`.`b` <> 30 select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); a 2 3 explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 4 100.00 Using index -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.a 1 100.00 -1 PRIMARY t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index Warnings: -Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t1`.`a` = `test`.`t2`.`a` +Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t1` join `test`.`t3` join `test`.`t2` where `test`.`t3`.`a` = `test`.`t1`.`b` and `test`.`t2`.`a` = `test`.`t1`.`a` drop table t1, t2, t3; create table t1 (a int, b int, index a (a,b)); create table t2 (a int, index a (a)); @@ -1509,7 +1509,7 @@ a explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index a a 5 NULL 4 100.00 Using where; Using index -1 PRIMARY t3 range a a 5 NULL 3 100.00 Using where; Using index +1 PRIMARY t3 index a a 5 NULL 3 100.00 Using where; Using index 1 PRIMARY t1 ref a a 10 test.t2.a,test.t3.a 116 100.00 Using index; FirstMatch(t2) Warnings: Note 1003 select `test`.`t2`.`a` AS `a` from `test`.`t2` semi join (`test`.`t1` join `test`.`t3`) where `test`.`t1`.`b` = `test`.`t3`.`a` and `test`.`t1`.`a` = `test`.`t2`.`a` @@ -1617,21 +1617,21 @@ a3 1 explain extended select s1, s1 NOT IN (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 NOT IN (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 = ANY (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null))) AS `s1 = ANY (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 <> ALL (SELECT s1 FROM t2) from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index -2 SUBQUERY t2 index_subquery s1 s1 6 func 2 100.00 Using index; Full scan on NULL key +2 DEPENDENT SUBQUERY t2 index s1 s1 6 NULL 2 100.00 Using where; Using index Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(<index_lookup>(<cache>(`test`.`t1`.`s1`) in t2 on s1 checking NULL having trigcond(`test`.`t2`.`s1` is null))))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` +Note 1003 /* select#1 */ select `test`.`t1`.`s1` AS `s1`,!(<in_optimizer>(`test`.`t1`.`s1`,<exists>(/* select#2 */ select `test`.`t2`.`s1` from `test`.`t2` where trigcond(<cache>(`test`.`t1`.`s1`) = `test`.`t2`.`s1` or `test`.`t2`.`s1` is null) having trigcond(`test`.`t2`.`s1` is null)))) AS `s1 <> ALL (SELECT s1 FROM t2)` from `test`.`t1` explain extended select s1, s1 NOT IN (SELECT s1 FROM t2 WHERE s1 < 'a2') from t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL s1 6 NULL 3 100.00 Using index @@ -2424,16 +2424,18 @@ a 3 DROP TABLE t1; create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); a b 1 2 3 4 +5 6 +7 8 explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00 Warnings: Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 Note 1003 select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` semi join (`test`.`t1`) where 1 @@ -3106,7 +3108,7 @@ retailerID statusID changed drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3119,7 +3121,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using where +2 SUBQUERY t2 ref cb cb 5 const 1 Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3131,7 +3133,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using index condition +2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -4444,7 +4446,7 @@ out_a MIN(b) DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); 2 @@ -4453,7 +4455,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Warnings: @@ -4463,7 +4465,7 @@ EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL @@ -4547,15 +4549,15 @@ SET @save_join_cache_level=@@join_cache_level; SET join_cache_level=0; EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary Warnings: Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1 EXPLAIN EXTENDED SELECT 1 FROM t1 WHERE 1 IN (SELECT min(a) FROM t1 WHERE a > 3 GROUP BY a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 Using where; Using temporary Warnings: Note 1003 /* select#1 */ select 1 AS `1` from <materialize> (/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` where `test`.`t1`.`a` > 3 group by `test`.`t1`.`a`) join `test`.`t1` where `<subquery2>`.`min(a)` = 1 @@ -6086,8 +6088,7 @@ WHERE col_varchar_nokey IN (SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index +1 PRIMARY it1 ref idx_cvk_cik idx_cvk_cik 9 const,const 1 Using where; Using index; FirstMatch(ot) SELECT col_int_nokey FROM ot WHERE col_varchar_nokey IN (SELECT col_varchar_key FROM it1 WHERE col_int_key IS NULL); @@ -6099,8 +6100,7 @@ WHERE (col_varchar_nokey, 'x') IN (SELECT col_varchar_key, col_varchar_key2 FROM it2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY ot system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 -2 MATERIALIZED it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index +1 PRIMARY it2 ref idx_cvk_cvk2_cik,idx_cvk_cik idx_cvk_cvk2_cik 8 const,const 1 Using where; Using index; FirstMatch(ot) SELECT col_int_nokey FROM ot WHERE (col_varchar_nokey, 'x') IN (SELECT col_varchar_key, col_varchar_key2 FROM it2); diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result index d9058965082..32cb9acd477 100644 --- a/mysql-test/main/subselect_no_semijoin.result +++ b/mysql-test/main/subselect_no_semijoin.result @@ -925,8 +925,8 @@ a t1.a in (select t2.a from t2,t3 where t3.a=t2.a) explain extended SELECT t1.a, t1.a in (select t2.a from t2,t3 where t3.a=t2.a) FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 index NULL PRIMARY 4 NULL 4 100.00 Using index -2 MATERIALIZED t3 ALL NULL NULL NULL NULL 3 100.00 -2 MATERIALIZED t2 index a a 5 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2 ref a a 5 test.t3.a 2 100.00 Using index Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,<expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`a` from `test`.`t2` join `test`.`t3` where `test`.`t2`.`a` = `test`.`t3`.`a` ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`a`)))) AS `t1.a in (select t2.a from t2,t3 where t3.a=t2.a)` from `test`.`t1` drop table t1,t2,t3; @@ -1463,8 +1463,8 @@ a explain extended select * from t2 where t2.a in (select t1.a from t1,t3 where t1.b=t3.a); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 index NULL PRIMARY 4 NULL 4 100.00 Using where; Using index -2 MATERIALIZED t1 ALL PRIMARY NULL NULL NULL 4 100.00 -2 MATERIALIZED t3 index PRIMARY PRIMARY 4 NULL 3 75.00 Using where; Using index; Using join buffer (flat, BNL join) +2 MATERIALIZED t1 ALL PRIMARY NULL NULL NULL 4 100.00 Using where +2 MATERIALIZED t3 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00 Using index Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`a` AS `a` from `test`.`t2` where <expr_cache><`test`.`t2`.`a`>(<in_optimizer>(`test`.`t2`.`a`,`test`.`t2`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`a` = `test`.`t1`.`b` ), <primary_index_lookup>(`test`.`t2`.`a` in <temporary table> on distinct_key where `test`.`t2`.`a` = `<subquery2>`.`a`)))) drop table t1, t2, t3; @@ -2421,15 +2421,17 @@ a 3 DROP TABLE t1; create table t1 (a int, b int); -insert into t1 values (1,2),(3,4); +insert into t1 values (1,2),(3,4),(5,6),(7,8); select * from t1 up where exists (select * from t1 where t1.a=up.a); a b 1 2 3 4 +5 6 +7 8 explain extended select * from t1 up where exists (select * from t1 where t1.a=up.a); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY up ALL NULL NULL NULL NULL 2 100.00 Using where -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 100.00 +1 PRIMARY up ALL NULL NULL NULL NULL 4 100.00 Using where +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 4 100.00 Warnings: Note 1276 Field or reference 'test.up.a' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`up`.`a` AS `a`,`test`.`up`.`b` AS `b` from `test`.`t1` `up` where <expr_cache><`test`.`up`.`a`>(<in_optimizer>(`test`.`up`.`a`,`test`.`up`.`a` in ( <materialize> (/* select#2 */ select `test`.`t1`.`a` from `test`.`t1` where 1 ), <primary_index_lookup>(`test`.`up`.`a` in <temporary table> on distinct_key where `test`.`up`.`a` = `<subquery2>`.`a`)))) @@ -3101,7 +3103,7 @@ retailerID statusID changed drop table t1; create table t1(a int, primary key (a)); insert into t1 values (10); -create table t2 (a int primary key, b varchar(32), c int, unique key b(c, b)); +create table t2 (a int primary key, b varchar(32), c int, unique key cb(c, b)); insert into t2(a, c, b) values (1,10,'359'), (2,10,'35988'), (3,10,'35989'); insert into t2(a, c, b) values (4,10,'360'), (5,10,'35998'), (6,10,'35999'); analyze table t1; @@ -3114,7 +3116,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using where +2 SUBQUERY t2 ref cb cb 5 const 1 Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c DESC, t2.b DESC LIMIT 1) WHERE t1.a = 10; @@ -3126,7 +3128,7 @@ ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 1 PRIMARY r const PRIMARY PRIMARY 4 const 1 -2 SUBQUERY t2 range b b 40 NULL 3 Using index condition +2 SUBQUERY t2 ref cb cb 5 const 1 Using index condition; Using where SELECT sql_no_cache t1.a, r.a, r.b FROM t1 LEFT JOIN t2 r ON r.a = (SELECT t2.a FROM t2 WHERE t2.c = t1.a AND t2.b <= '359899' ORDER BY t2.c, t2.b LIMIT 1) WHERE t1.a = 10; @@ -4437,7 +4439,7 @@ out_a MIN(b) DROP TABLE t1; CREATE TABLE t1 (a INT); CREATE TABLE t2 (a INT); -INSERT INTO t1 VALUES (1),(2); +INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t2 VALUES (1),(2); SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); 2 @@ -4446,7 +4448,7 @@ SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 Warnings: Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1 @@ -4455,7 +4457,7 @@ EXPLAIN EXTENDED SELECT 2 FROM t1 WHERE EXISTS ((SELECT 1 FROM t2 WHERE t1.a=t2.a) UNION (SELECT 1 FROM t2 WHERE t1.a = t2.a)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 100.00 Using where 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 2 100.00 Using where NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL @@ -5731,8 +5733,8 @@ SET join_cache_level=0; EXPLAIN SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 MATERIALIZED t2 index NULL PRIMARY 4 NULL 3 Using index -2 MATERIALIZED it index PRIMARY PRIMARY 4 NULL 3 Using index +2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index +2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using index SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON 1); pk i 11 0 diff --git a/mysql-test/main/subselect_sj.result b/mysql-test/main/subselect_sj.result index 42605ab9d2c..d130ed4c2a2 100644 --- a/mysql-test/main/subselect_sj.result +++ b/mysql-test/main/subselect_sj.result @@ -160,26 +160,26 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY s47 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 PRIMARY s48 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) 1 PRIMARY s49 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m00 ALL NULL NULL NULL NULL 3 -2 MATERIALIZED m01 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m02 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m03 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m04 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m05 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m06 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m07 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m08 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m09 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m10 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m11 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m12 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m13 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m14 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m15 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m16 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m17 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m18 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m19 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m00 ALL NULL NULL NULL NULL 3 Using where +2 DEPENDENT SUBQUERY m01 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m02 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m03 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m04 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m05 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m06 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m07 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m08 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m09 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m10 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m11 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m12 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m13 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m14 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m15 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m16 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m17 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m18 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m19 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10)) where t1.a < 5; @@ -205,10 +205,10 @@ a b a b insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B; explain extended select * from t1 where a in (select pk from t10 where pk<3); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t10 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index -1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where +1 PRIMARY t10 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t10`.`pk` and `test`.`t10`.`pk` < 3 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t10`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 drop table t0, t1, t2; drop table t10, t11, t12; @@ -344,8 +344,8 @@ WHERE PNUM IN (SELECT PNUM FROM PROJ)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY STAFF ALL NULL NULL NULL NULL 5 -1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Start temporary -1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; End temporary +1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 +1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; FirstMatch(STAFF) SELECT EMPNUM, EMPNAME FROM STAFF WHERE EMPNUM IN @@ -763,16 +763,16 @@ explain extended select a from t1 where a in (select c from t2 where d >= some(select e from t3 where b=e)); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Start temporary -1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 6 100.00 Using where; FirstMatch(t1) 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`c` = `test`.`t1`.`a` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))) show warnings; Level Code Message Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`c` = `test`.`t1`.`a` and <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where `test`.`t1`.`b` = `test`.`t3`.`e` and <cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`)))) select a from t1 where a in (select c from t2 where d >= some(select e from t3 where b=e)); a @@ -802,6 +802,7 @@ PRIMARY KEY (pk) INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff', 'ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')); CREATE TABLE t2 LIKE t1; INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')); +insert into t2 (pk) values (-1),(0); EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 @@ -1249,8 +1250,8 @@ INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1); EXPLAIN SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 5 -1 PRIMARY t2 index k k 10 NULL 4 Using where; Using index; Start temporary; End temporary +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where +1 PRIMARY t2 ref k k 5 test.t1.i 1 Using where; Using index; Start temporary; End temporary SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0); i 1 @@ -1610,7 +1611,7 @@ A.t1field IN (SELECT C.t2field FROM t2 C WHERE C.t2field IN (SELECT D.t2field FROM t2 D)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY A index PRIMARY PRIMARY 4 NULL 3 Using index -1 PRIMARY B index NULL PRIMARY 4 NULL 3 Using index; Start temporary; End temporary +1 PRIMARY B index NULL PRIMARY 4 NULL 3 Using index; FirstMatch(A) 1 PRIMARY C eq_ref PRIMARY PRIMARY 4 test.A.t1field 1 Using index 1 PRIMARY D eq_ref PRIMARY PRIMARY 4 test.A.t1field 1 Using index SELECT * FROM t1 A @@ -1980,7 +1981,7 @@ f1 f3 f4 f2 f4 DROP TABLE t1,t2,t3; # # BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90 -# (Original testcase) +# (Original, slightly modified testcase) # CREATE TABLE t1 (f1 int, f2 int ); INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL); @@ -1990,24 +1991,23 @@ CREATE TABLE t3 ( f1 int, f3 int ); INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0); CREATE TABLE t4 ( f2 int, KEY (f2) ); INSERT INTO t4 VALUES (0),(NULL); -CREATE VIEW v4 AS SELECT DISTINCT f2 FROM t4 ; +INSERT INTO t4 VALUES (0),(NULL),(-1),(-2),(-3); # The following must not have outer joins: explain extended -SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4); +SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join) -2 MATERIALIZED t4 index f2 f2 5 NULL 2 100.00 Using index +2 MATERIALIZED t4 ref_or_null f2 f2 5 const 4 100.00 Using where; Using index Warnings: -Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2` -SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4); +Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2` and (`test`.`t4`.`f2` = 0 or `test`.`t4`.`f2` is null) +SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL); f1 f2 f3 f3 2 0 0 0 4 0 0 0 4 0 0 0 -drop view v4; drop table t1, t2, t3, t4; # # BUG#803303: Wrong result with semijoin=on, outer join in maria-5.3-subqueries-mwl90 @@ -2153,8 +2153,8 @@ INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5); explain SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; Start temporary +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY t3 ref b b 5 test.t1.b 2 Start temporary 1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; End temporary; Using join buffer (flat, BNL join) SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3); b a @@ -2350,8 +2350,8 @@ SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 9 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 -2 MATERIALIZED t2 index b b 8 NULL 7 Using where; Using index +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 Using where +2 MATERIALIZED t2 ref b b 4 test.t3.a 1 Using index SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a); a 19 @@ -2499,10 +2499,9 @@ SELECT * FROM t1, t2 WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1 -1 PRIMARY t1 ref a a 5 const 1 Using index -1 PRIMARY t2 ref a a 5 func 1 Using index -2 MATERIALIZED t4 ALL NULL NULL NULL NULL 0 +1 PRIMARY t2 ref a a 5 const 1 Using index +1 PRIMARY t4 ALL NULL NULL NULL NULL 0 FirstMatch(t2); Using join buffer (flat, BNL join) +1 PRIMARY t1 ref a a 5 func 1 Using index SELECT * FROM t1, t2 WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4); a a @@ -2574,33 +2573,33 @@ SELECT a, b, d FROM t1, t2 WHERE ( b, d ) IN ( SELECT b, d FROM t1, t2 WHERE b = c ); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 7 -1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; LooseScan -1 PRIMARY t2 ref c c 5 test.t1.b 1 Using where; FirstMatch(t1) +1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; Start temporary +1 PRIMARY t2 ref c c 5 test.t1.b 1 1 PRIMARY t1 ref b b 5 test.t1.b 2 +1 PRIMARY t2 ALL NULL NULL NULL NULL 7 Using where; End temporary; Using join buffer (flat, BNL join) SELECT a, b, d FROM t1, t2 WHERE ( b, d ) IN ( SELECT b, d FROM t1, t2 WHERE b = c ); a b d -2 1 2 -7 1 2 -8 4 2 1 2 1 -4 2 1 +1 2 1 10 2 1 +10 2 1 +2 1 2 +2 1 2 3 3 3 +3 3 3 +4 2 1 +4 2 1 +5 5 5 +6 3 3 6 3 3 -9 3 3 -2 1 2 +7 1 2 7 1 2 8 4 2 -5 5 5 -3 3 3 -6 3 3 +8 4 2 +9 3 3 9 3 3 -1 2 1 -4 2 1 -10 2 1 DROP TABLE t1, t2; # Another testcase for the above that still uses LooseScan: create table t0(a int primary key); @@ -2768,22 +2767,22 @@ SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_1 ALL NULL NULL NULL NULL 11 Using where -1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 -1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Using where; FirstMatch(t1_2) +1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Start temporary +1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 Using where; End temporary 3 DERIVED t1 ALL NULL NULL NULL NULL 11 SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 ); a b a b -3 1 9 1 -5 8 4 0 -3 9 9 1 2 4 4 0 2 4 6 8 2 6 4 0 2 6 6 8 +3 1 9 1 +3 9 9 1 5 4 4 0 -7 7 7 7 5 4 4 0 +5 8 4 0 +7 7 7 7 DROP VIEW v1; DROP TABLE t1; set @@join_cache_level= @tmp_jcl_978479; @@ -2927,9 +2926,9 @@ alias2.col_int_key = alias1.col_int_key WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o' ); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where; Start temporary -1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); End temporary +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where +1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); FirstMatch(t2) SELECT * FROM t2 WHERE (field1) IN (SELECT alias1.col_varchar_nokey AS field1 @@ -3289,8 +3288,7 @@ explain extended SELECT Id FROM t1 WHERE Id in (SELECT t1_Id FROM t2 WHERE t2.col1 IS NULL); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 100.00 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t2 ref col1 col1 5 const 2 100.00 Using index condition; Using where +1 PRIMARY t2 ALL col1 NULL NULL NULL 2 100.00 Using where; FirstMatch(t1) Warnings: Note 1003 select 1 AS `Id` from (`test`.`t2`) where `test`.`t2`.`t1_Id` = 1 and `test`.`t2`.`col1` is null DROP TABLE t1, t2; diff --git a/mysql-test/main/subselect_sj.test b/mysql-test/main/subselect_sj.test index c5c3354bc32..4725aeda037 100644 --- a/mysql-test/main/subselect_sj.test +++ b/mysql-test/main/subselect_sj.test @@ -738,6 +738,7 @@ INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','f CREATE TABLE t2 LIKE t1; INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')); +insert into t2 (pk) values (-1),(0); # Test that materialization is skipped for semijoins where materialized # table would contain GEOMETRY or different kinds of BLOB/TEXT columns @@ -1738,7 +1739,7 @@ DROP TABLE t1,t2,t3; --echo # --echo # BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90 ---echo # (Original testcase) +--echo # (Original, slightly modified testcase) --echo # CREATE TABLE t1 (f1 int, f2 int ); @@ -1752,15 +1753,13 @@ INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0); CREATE TABLE t4 ( f2 int, KEY (f2) ); INSERT INTO t4 VALUES (0),(NULL); - -CREATE VIEW v4 AS SELECT DISTINCT f2 FROM t4 ; +INSERT INTO t4 VALUES (0),(NULL),(-1),(-2),(-3); --echo # The following must not have outer joins: explain extended -SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4); -SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4); +SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL); +SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL); -drop view v4; drop table t1, t2, t3, t4; --echo # @@ -2248,6 +2247,7 @@ INSERT INTO t1 VALUES CREATE TABLE t2 ( a INT, b INT, KEY(a)) ENGINE=MyISAM; INSERT INTO t2 VALUES (3,20),(2,21),(3,22); +--sorted_result SELECT * FROM t1 AS alias1, t1 AS alias2 WHERE ( alias1.c, alias2.c ) @@ -2298,6 +2298,7 @@ explain SELECT a, b, d FROM t1, t2 WHERE ( b, d ) IN ( SELECT b, d FROM t1, t2 WHERE b = c ); +--sorted_result SELECT a, b, d FROM t1, t2 WHERE ( b, d ) IN ( SELECT b, d FROM t1, t2 WHERE b = c ); @@ -2448,6 +2449,7 @@ EXPLAIN SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 ); +--sorted_result SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 ); diff --git a/mysql-test/main/subselect_sj2.result b/mysql-test/main/subselect_sj2.result index 477c6034f89..a2eaf0aef23 100644 --- a/mysql-test/main/subselect_sj2.result +++ b/mysql-test/main/subselect_sj2.result @@ -54,9 +54,9 @@ a b 19 14 explain select * from t2 where b in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL b NULL NULL NULL 20 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t2 ref b b 5 test.t1.a 2 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where select * from t2 where b in (select a from t1); a b 1 1 @@ -82,9 +82,9 @@ test.t3 analyze status Engine-independent statistics collected test.t3 analyze status OK explain select * from t3 where b in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 ALL b NULL NULL NULL 20 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t3 ref b b 5 test.t1.a 2 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where select * from t3 where b in (select a from t1); a b pk1 pk2 pk3 1 1 1 1 1 @@ -108,9 +108,9 @@ A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B where B.a <5; explain select * from t3 where b in (select a from t0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 ALL b NULL NULL NULL # -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # -2 MATERIALIZED t0 ALL NULL NULL NULL NULL # +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL # +1 PRIMARY t3 ref b b 5 test.t0.a # +2 MATERIALIZED t0 ALL NULL NULL NULL NULL # Using where select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5); a b pk1 pk2 0 0 0 0 @@ -303,7 +303,7 @@ from t0 where a in id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t0 ALL NULL NULL NULL NULL 10 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where -2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index +2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index 2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index 2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index drop table t0, t1,t2,t3; @@ -730,9 +730,8 @@ alter table t3 add primary key(id), add key(a); The following must use loose index scan over t3, key a: explain select count(a) from t2 where a in ( SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 index a a 5 NULL 1000 Using index -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t3 index a a 5 NULL 30000 Using index +1 PRIMARY t2 index a a 5 NULL 1000 Using where; Using index +1 PRIMARY t3 ref a a 5 test.t2.a 30 Using index; FirstMatch(t2) select count(a) from t2 where a in ( SELECT a FROM t3); count(a) 1000 @@ -758,10 +757,9 @@ c2 in (select 1 from t3, t2) and c1 in (select convert(c6,char(1)) from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where -1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t2) 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch((sj-nest)) -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch(t2) drop table t2, t3; # # BUG#761598: InnoDB: Error: row_search_for_mysql() is called without ha_innobase::external_lock() in maria-5.3 @@ -826,9 +824,9 @@ SELECT * FROM t3 WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index -1 PRIMARY alias2 index f12 f12 7 NULL # Using index; Start temporary -1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index -1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan +1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; FirstMatch(alias2) +1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join) SELECT * FROM t3 WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); f12 @@ -1211,9 +1209,9 @@ explain SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index -1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Start temporary -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; End temporary +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where +1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; FirstMatch(t3) DROP TABLE t1,t2,t3,t4; # # MDEV-6263: Wrong result when using IN subquery with order by @@ -1333,8 +1331,8 @@ T3_0_.t3idref= 1 id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary 1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 test.T3_0_.t2idref 1 -1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index -1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index; End temporary +1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index +1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index; End temporary drop table t3,t2,t1; set optimizer_search_depth=@tmp7474; # diff --git a/mysql-test/main/subselect_sj2.test b/mysql-test/main/subselect_sj2.test index be2d91571e7..419deb6f7e7 100644 --- a/mysql-test/main/subselect_sj2.test +++ b/mysql-test/main/subselect_sj2.test @@ -1305,8 +1305,6 @@ SELECT * FROM t1 WHERE 9 IN ( SELECT b FROM t2 WHERE 1 IN ( SELECT MIN(c) FROM t DROP TABLE t1,t2,t3; ---source include/have_innodb.inc - --disable_warnings DROP TABLE IF EXISTS t1,t2,t3,t4; --enable_warnings diff --git a/mysql-test/main/subselect_sj2_jcl6.result b/mysql-test/main/subselect_sj2_jcl6.result index ad169028373..f51f06b141c 100644 --- a/mysql-test/main/subselect_sj2_jcl6.result +++ b/mysql-test/main/subselect_sj2_jcl6.result @@ -65,9 +65,9 @@ a b 19 14 explain select * from t2 where b in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL b NULL NULL NULL 20 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t2 ref b b 5 test.t1.a 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where select * from t2 where b in (select a from t1); a b 1 1 @@ -93,9 +93,9 @@ test.t3 analyze status Engine-independent statistics collected test.t3 analyze status OK explain select * from t3 where b in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 ALL b NULL NULL NULL 20 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t3 ref b b 5 test.t1.a 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where select * from t3 where b in (select a from t1); a b pk1 pk2 pk3 1 1 1 1 1 @@ -119,9 +119,9 @@ A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B where B.a <5; explain select * from t3 where b in (select a from t0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 ALL b NULL NULL NULL # -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # -2 MATERIALIZED t0 ALL NULL NULL NULL NULL # +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL # +1 PRIMARY t3 ref b b 5 test.t0.a # Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +2 MATERIALIZED t0 ALL NULL NULL NULL NULL # Using where select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5); a b pk1 pk2 0 0 0 0 @@ -314,7 +314,7 @@ from t0 where a in id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t0 ALL NULL NULL NULL NULL 10 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where -2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index +2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index 2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index 2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index drop table t0, t1,t2,t3; @@ -743,9 +743,8 @@ alter table t3 add primary key(id), add key(a); The following must use loose index scan over t3, key a: explain select count(a) from t2 where a in ( SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 index a a 5 NULL 1000 Using index -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t3 index a a 5 NULL 30000 Using index +1 PRIMARY t2 index a a 5 NULL 1000 Using where; Using index +1 PRIMARY t3 ref a a 5 test.t2.a 30 Using index; FirstMatch(t2) select count(a) from t2 where a in ( SELECT a FROM t3); count(a) 1000 @@ -771,10 +770,9 @@ c2 in (select 1 from t3, t2) and c1 in (select convert(c6,char(1)) from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where -1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where -1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch((sj-nest)); Using join buffer (incremental, BNL join) -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t2); Using join buffer (flat, BNL join) +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using join buffer (incremental, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch(t2); Using join buffer (incremental, BNL join) drop table t2, t3; # # BUG#761598: InnoDB: Error: row_search_for_mysql() is called without ha_innobase::external_lock() in maria-5.3 @@ -1346,8 +1344,8 @@ T3_0_.t3idref= 1 id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary 1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 test.T3_0_.t2idref 1 Using join buffer (flat, BKA join); Key-ordered scan -1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index -1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index; End temporary +1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index +1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index; End temporary drop table t3,t2,t1; set optimizer_search_depth=@tmp7474; # @@ -1425,10 +1423,9 @@ SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b WHERE c IN (SELECT t4.b FROM t4 JOIN t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ALL NULL NULL NULL NULL 1 Using where -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join) +1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; FirstMatch(t3); Using join buffer (incremental, BNL join) 1 PRIMARY t1 ref b b 4 test.t3.b 1 Using index -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 -2 MATERIALIZED t4 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) SELECT t3.* FROM t1 JOIN t3 ON t3.b = t1.b WHERE c IN (SELECT t4.b FROM t4 JOIN t2); b c @@ -1446,7 +1443,7 @@ INSERT INTO t2 VALUES (8); CREATE TABLE t3 (pk int PRIMARY KEY, a int); INSERT INTO t3 VALUES (1, 6), (2, 8); CREATE TABLE t4 (b int) ENGINE=InnoDB; -INSERT INTO t4 VALUES (2); +INSERT INTO t4 VALUES (2),(88),(99); set @tmp_optimizer_switch=@@optimizer_switch; SET optimizer_switch = 'semijoin_with_cache=on'; SET join_cache_level = 2; @@ -1454,10 +1451,9 @@ EXPLAIN SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +1 PRIMARY t4 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 Using where; FirstMatch(t2) 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) -2 MATERIALIZED t4 ALL NULL NULL NULL NULL 1 Using where -2 MATERIALIZED t3 eq_ref PRIMARY PRIMARY 4 test.t4.b 1 SELECT * FROM t1, t2 WHERE b IN (SELECT a FROM t3, t4 WHERE b = pk); pk a b 1 6 8 @@ -1479,8 +1475,7 @@ EXPLAIN SELECT * FROM t1 WHERE b IN (SELECT a FROM t2 GROUP BY a); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE b IN (SELECT a FROM t2 GROUP BY a); a b v v diff --git a/mysql-test/main/subselect_sj2_jcl6.test b/mysql-test/main/subselect_sj2_jcl6.test index a0c8a6c0f04..ea3f07b289a 100644 --- a/mysql-test/main/subselect_sj2_jcl6.test +++ b/mysql-test/main/subselect_sj2_jcl6.test @@ -66,7 +66,7 @@ INSERT INTO t2 VALUES (8); CREATE TABLE t3 (pk int PRIMARY KEY, a int); INSERT INTO t3 VALUES (1, 6), (2, 8); CREATE TABLE t4 (b int) ENGINE=InnoDB; -INSERT INTO t4 VALUES (2); +INSERT INTO t4 VALUES (2),(88),(99); set @tmp_optimizer_switch=@@optimizer_switch; diff --git a/mysql-test/main/subselect_sj2_mat.result b/mysql-test/main/subselect_sj2_mat.result index dd434ff69a9..ec4841fab3d 100644 --- a/mysql-test/main/subselect_sj2_mat.result +++ b/mysql-test/main/subselect_sj2_mat.result @@ -56,9 +56,9 @@ a b 19 14 explain select * from t2 where b in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL b NULL NULL NULL 20 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t2 ref b b 5 test.t1.a 2 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where select * from t2 where b in (select a from t1); a b 1 1 @@ -84,9 +84,9 @@ test.t3 analyze status Engine-independent statistics collected test.t3 analyze status OK explain select * from t3 where b in (select a from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 ALL b NULL NULL NULL 20 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 3 +1 PRIMARY t3 ref b b 5 test.t1.a 2 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 Using where select * from t3 where b in (select a from t1); a b pk1 pk2 pk3 1 1 1 1 1 @@ -110,9 +110,9 @@ A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a, A.a + 10*B.a from t0 A, t0 B where B.a <5; explain select * from t3 where b in (select a from t0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 ALL b NULL NULL NULL # -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func # -2 MATERIALIZED t0 ALL NULL NULL NULL NULL # +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL # +1 PRIMARY t3 ref b b 5 test.t0.a # +2 MATERIALIZED t0 ALL NULL NULL NULL NULL # Using where select * from t3 where b in (select A.a+B.a from t0 A, t0 B where B.a<5); a b pk1 pk2 0 0 0 0 @@ -305,7 +305,7 @@ from t0 where a in id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t0 ALL NULL NULL NULL NULL 10 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func 1 Using where -2 MATERIALIZED t1 range a a 5 NULL 10 Using where; Using index +2 MATERIALIZED t1 index a a 5 NULL 10 Using where; Using index 2 MATERIALIZED t2 ref a a 5 test.t1.a 1 Using index 2 MATERIALIZED t3 ref a a 5 test.t1.a 1 Using index drop table t0, t1,t2,t3; @@ -732,9 +732,8 @@ alter table t3 add primary key(id), add key(a); The following must use loose index scan over t3, key a: explain select count(a) from t2 where a in ( SELECT a FROM t3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 index a a 5 NULL 1000 Using index -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t3 index a a 5 NULL 30000 Using index +1 PRIMARY t2 index a a 5 NULL 1000 Using where; Using index +1 PRIMARY t3 ref a a 5 test.t2.a 30 Using index; FirstMatch(t2) select count(a) from t2 where a in ( SELECT a FROM t3); count(a) 1000 @@ -760,10 +759,9 @@ c2 in (select 1 from t3, t2) and c1 in (select convert(c6,char(1)) from t2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where -1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where; FirstMatch(t2) 1 PRIMARY t2 ALL NULL NULL NULL NULL 1 -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch((sj-nest)) -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 1 +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 FirstMatch(t2) drop table t2, t3; # # BUG#761598: InnoDB: Error: row_search_for_mysql() is called without ha_innobase::external_lock() in maria-5.3 @@ -828,9 +826,9 @@ SELECT * FROM t3 WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY alias1 const PRIMARY PRIMARY 4 const # Using index -1 PRIMARY alias2 index f12 f12 7 NULL # Using index; Start temporary -1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index -1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY alias2 index f12 f12 7 NULL # Using index; LooseScan +1 PRIMARY t1 index NULL PRIMARY 4 NULL # Using index; FirstMatch(alias2) +1 PRIMARY t3 ALL NULL NULL NULL NULL # Using where; Using join buffer (flat, BNL join) SELECT * FROM t3 WHERE f12 IN (SELECT alias2.f12 FROM t1 AS alias1, t2 AS alias2, t1 WHERE alias1.f13 = 24); f12 @@ -1213,9 +1211,9 @@ explain SELECT * FROM t1, t3 WHERE t3_c IN ( SELECT t1_pk2 FROM t4, t2 WHERE t2_c = t1_pk2 AND t2_i >= t3_i ) AND ( t1_pk1 = 'POL' ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ref PRIMARY PRIMARY 5 const 1 Using where; Using index -1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Start temporary -1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; End temporary +1 PRIMARY t3 ALL NULL NULL NULL NULL 2 Using join buffer (flat, BNL join) +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where +1 PRIMARY t4 index NULL PRIMARY 59 NULL 2 Using where; Using index; FirstMatch(t3) DROP TABLE t1,t2,t3,t4; # # MDEV-6263: Wrong result when using IN subquery with order by @@ -1335,8 +1333,8 @@ T3_0_.t3idref= 1 id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY T3_0_ ref PRIMARY,FK_T3_T2Id PRIMARY 8 const 3 Using index; Start temporary 1 PRIMARY T2_1_ eq_ref PRIMARY,FK_T2_T1Id PRIMARY 8 test.T3_0_.t2idref 1 -1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index -1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index; End temporary +1 PRIMARY T2_0_ ref FK_T2_T1Id FK_T2_T1Id 8 test.T2_1_.t1idref 1 Using index +1 PRIMARY T1_1_ eq_ref PRIMARY PRIMARY 8 test.T2_1_.t1idref 1 Using index; End temporary drop table t3,t2,t1; set optimizer_search_depth=@tmp7474; # @@ -1511,9 +1509,8 @@ t3.cat_id IN (SELECT cat_id FROM t2) AND t3.sack_id = 33479 AND t3.kit_id = 6; id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 ref PRIMARY PRIMARY 5 const,const 5 Using index -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 Using where -1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t3.cat_id 1 Using index -2 MATERIALIZED t2 index cat_id cat_id 4 NULL 19 Using index +1 PRIMARY t2 ref cat_id cat_id 4 test.t3.cat_id 2 Using where; Using index; FirstMatch(t3) +1 PRIMARY t1 eq_ref PRIMARY PRIMARY 4 test.t2.cat_id 1 Using where; Using index SELECT count(*) FROM t1, t3 WHERE t1.cat_id = t3.cat_id AND t3.cat_id IN (SELECT cat_id FROM t2) AND @@ -1725,7 +1722,7 @@ WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' ) HAVING f1 != 'foo' ORDER BY f1; id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 range f1 f1 11 NULL 2 Using where; Using index +1 PRIMARY t1 index f1 f1 11 NULL 2 Using where; Using index 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 11 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where DROP TABLE t1,t2; @@ -1929,20 +1926,20 @@ AND t3.id_product IN (SELECT id_product FROM t2 t2_3 WHERE t2_3.id_t2 = 18 OR t2 AND t3.id_product IN (SELECT id_product FROM t2 t2_4 WHERE t2_4.id_t2 = 34 OR t2_4.id_t2 = 23) AND t3.id_product IN (SELECT id_product FROM t2 t2_5 WHERE t2_5.id_t2 = 29 OR t2_5.id_t2 = 28 OR t2_5.id_t2 = 26); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <subquery3> ALL distinct_key NULL NULL NULL 12 -1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t2_2.id_product 1 Using where; Using index +1 PRIMARY t1 index NULL PRIMARY 8 NULL 73 Using index +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 4 test.t1.id_product 1 Using index 1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 4 func 1 Using where -1 PRIMARY t5 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) -1 PRIMARY <subquery6> eq_ref distinct_key distinct_key 4 func 1 Using where -1 PRIMARY t4 eq_ref PRIMARY PRIMARY 8 test.t3.id_product,const 1 Using where; Using index 1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 func 1 Using where -1 PRIMARY t1 index NULL PRIMARY 8 NULL 73 Using where; Using index; Using join buffer (flat, BNL join) +1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 func 1 Using where 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 Using where -3 MATERIALIZED t2_2 ref id_t2,id_product id_t2 5 const 12 Using where +1 PRIMARY t4 eq_ref PRIMARY PRIMARY 8 test.t1.id_product,const 1 Using where; Using index +1 PRIMARY <subquery6> eq_ref distinct_key distinct_key 4 func 1 Using where +1 PRIMARY t5 ALL NULL NULL NULL NULL 18 Using where; Using join buffer (flat, BNL join) 5 MATERIALIZED t2_4 range id_t2,id_product id_t2 5 NULL 18 Using index condition; Using where -6 MATERIALIZED t2_5 range id_t2,id_product id_t2 5 NULL 31 Using index condition; Using where 4 MATERIALIZED t2_3 range id_t2,id_product id_t2 5 NULL 33 Using index condition; Using where -2 MATERIALIZED t2_1 ALL id_t2,id_product NULL NULL NULL 223 Using where +3 MATERIALIZED t2_2 ref id_t2,id_product id_t2 5 const 12 +2 MATERIALIZED t2_1 ref id_t2,id_product id_t2 5 const 51 +6 MATERIALIZED t2_5 range id_t2,id_product id_t2 5 NULL 31 Using index condition; Using where set optimizer_switch='rowid_filter=default'; drop table t1,t2,t3,t4,t5; set global innodb_stats_persistent= @innodb_stats_persistent_save; diff --git a/mysql-test/main/subselect_sj_jcl6.result b/mysql-test/main/subselect_sj_jcl6.result index c24fcb28977..ee06bf4f9a0 100644 --- a/mysql-test/main/subselect_sj_jcl6.result +++ b/mysql-test/main/subselect_sj_jcl6.result @@ -171,26 +171,26 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY s47 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) 1 PRIMARY s48 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) 1 PRIMARY s49 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m00 ALL NULL NULL NULL NULL 3 -2 MATERIALIZED m01 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) -2 MATERIALIZED m02 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m03 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m04 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m05 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m06 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m07 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m08 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m09 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m10 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m11 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m12 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m13 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m14 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m15 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m16 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m17 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m18 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) -2 MATERIALIZED m19 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m00 ALL NULL NULL NULL NULL 3 Using where +2 DEPENDENT SUBQUERY m01 ALL NULL NULL NULL NULL 3 Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY m02 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m03 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m04 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m05 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m06 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m07 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m08 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m09 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m10 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m11 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m12 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m13 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m14 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m15 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m16 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m17 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m18 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) +2 DEPENDENT SUBQUERY m19 ALL NULL NULL NULL NULL 3 Using join buffer (incremental, BNL join) select * from t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10)) where t1.a < 5; @@ -216,10 +216,10 @@ a b a b insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B; explain extended select * from t1 where a in (select pk from t10 where pk<3); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t10 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index -1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where +1 PRIMARY t10 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 100.00 Using index Warnings: -Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t1`.`a` = `test`.`t10`.`pk` and `test`.`t10`.`pk` < 3 +Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where `test`.`t10`.`pk` = `test`.`t1`.`a` and `test`.`t1`.`a` < 3 drop table t0, t1, t2; drop table t10, t11, t12; @@ -355,8 +355,8 @@ WHERE PNUM IN (SELECT PNUM FROM PROJ)); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY STAFF ALL NULL NULL NULL NULL 5 -1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Start temporary; Using join buffer (flat, BNL join) -1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; End temporary; Using join buffer (incremental, BNL join) +1 PRIMARY PROJ ALL NULL NULL NULL NULL 6 Using join buffer (flat, BNL join) +1 PRIMARY WORKS ALL NULL NULL NULL NULL 12 Using where; FirstMatch(STAFF); Using join buffer (incremental, BNL join) SELECT EMPNUM, EMPNAME FROM STAFF WHERE EMPNUM IN @@ -813,6 +813,7 @@ PRIMARY KEY (pk) INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff', 'ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')); CREATE TABLE t2 LIKE t1; INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii','iiii','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')), (2,'f','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff','ffff',GeomFromText('POLYGON((0 0, 0 2, 2 2, 2 0, 0 0))')); +insert into t2 (pk) values (-1),(0); EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 @@ -1260,8 +1261,8 @@ INSERT INTO t2 VALUES (1, 0), (1, 1), (2, 0), (2, 1); EXPLAIN SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 5 -1 PRIMARY t2 index k k 10 NULL 4 Using where; Using index; Start temporary; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 5 Using where +1 PRIMARY t2 ref k k 5 test.t1.i 1 Using where; Using index; Start temporary; End temporary SELECT * FROM t1 WHERE (i) IN (SELECT i FROM t2 where j > 0); i 1 @@ -1991,7 +1992,7 @@ f1 f3 f4 f2 f4 DROP TABLE t1,t2,t3; # # BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90 -# (Original testcase) +# (Original, slightly modified testcase) # CREATE TABLE t1 (f1 int, f2 int ); INSERT INTO t1 VALUES (2,0),(4,0),(0,NULL); @@ -2001,24 +2002,23 @@ CREATE TABLE t3 ( f1 int, f3 int ); INSERT INTO t3 VALUES (2,0),(4,0),(0,NULL),(4,0),(8,0); CREATE TABLE t4 ( f2 int, KEY (f2) ); INSERT INTO t4 VALUES (0),(NULL); -CREATE VIEW v4 AS SELECT DISTINCT f2 FROM t4 ; +INSERT INTO t4 VALUES (0),(NULL),(-1),(-2),(-3); # The following must not have outer joins: explain extended -SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4); +SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) 1 PRIMARY t3 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (incremental, BNL join) -2 MATERIALIZED t4 index f2 f2 5 NULL 2 100.00 Using index +2 MATERIALIZED t4 ref_or_null f2 f2 5 const 4 100.00 Using where; Using index Warnings: -Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2` -SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4); +Note 1003 select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3`,`test`.`t3`.`f3` AS `f3` from `test`.`t1` semi join (`test`.`t4`) join `test`.`t2` join `test`.`t3` where `test`.`t3`.`f1` = `test`.`t1`.`f1` and `test`.`t1`.`f2` = `test`.`t2`.`f2` and (`test`.`t4`.`f2` = 0 or `test`.`t4`.`f2` is null) +SELECT * FROM t1 NATURAL LEFT JOIN (t2, t3) WHERE t2.f3 IN (SELECT * FROM t4 where f2 = 0 or f2 IS NULL); f1 f2 f3 f3 2 0 0 0 4 0 0 0 4 0 0 0 -drop view v4; drop table t1, t2, t3, t4; # # BUG#803303: Wrong result with semijoin=on, outer join in maria-5.3-subqueries-mwl90 @@ -2164,8 +2164,8 @@ INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5); explain SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; Start temporary; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY t3 ref b b 5 test.t1.b 2 Start temporary; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan 1 PRIMARY t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index; End temporary; Using join buffer (incremental, BNL join) SELECT * FROM t1, t2 WHERE (t2.a , t1.b) IN (SELECT a, b FROM t3); b a @@ -2361,8 +2361,8 @@ SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 9 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 -2 MATERIALIZED t2 index b b 8 NULL 7 Using where; Using index; Using join buffer (flat, BNL join) +2 MATERIALIZED t3 ALL NULL NULL NULL NULL 13 Using where +2 MATERIALIZED t2 ref b b 4 test.t3.a 1 Using index SELECT * FROM t1 WHERE (a) IN (SELECT a FROM t2 JOIN t3 ON b = a); a 19 @@ -2510,10 +2510,9 @@ SELECT * FROM t1, t2 WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t3 system NULL NULL NULL NULL 1 -1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1 -1 PRIMARY t1 ref a a 5 const 1 Using index -1 PRIMARY t2 ref a a 5 func 1 Using index -2 MATERIALIZED t4 ALL NULL NULL NULL NULL 0 +1 PRIMARY t2 ref a a 5 const 1 Using index +1 PRIMARY t4 ALL NULL NULL NULL NULL 0 FirstMatch(t2); Using join buffer (flat, BNL join) +1 PRIMARY t1 ref a a 5 func 1 Using index SELECT * FROM t1, t2 WHERE t1.a = t2.a AND t2.a IN (SELECT b FROM t3 STRAIGHT_JOIN t4); a a @@ -2585,16 +2584,18 @@ SELECT a, b, d FROM t1, t2 WHERE ( b, d ) IN ( SELECT b, d FROM t1, t2 WHERE b = c ); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 7 -1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; LooseScan -1 PRIMARY t2 ref c c 5 test.t1.b 1 Using where; FirstMatch(t1) -1 PRIMARY t1 ref b b 5 test.t1.b 2 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 PRIMARY t1 index b b 5 NULL 10 Using where; Using index; Start temporary +1 PRIMARY t2 ref c c 5 test.t1.b 1 Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +1 PRIMARY t1 ref b b 5 test.t1.b 2 Using join buffer (incremental, BKA join); Key-ordered Rowid-ordered scan +1 PRIMARY t2 ALL NULL NULL NULL NULL 7 Using where; End temporary; Using join buffer (incremental, BNL join) SELECT a, b, d FROM t1, t2 WHERE ( b, d ) IN ( SELECT b, d FROM t1, t2 WHERE b = c ); a b d 1 2 1 1 2 1 +10 2 1 +10 2 1 2 1 2 2 1 2 3 3 3 @@ -2610,8 +2611,6 @@ a b d 8 4 2 9 3 3 9 3 3 -10 2 1 -10 2 1 DROP TABLE t1, t2; # Another testcase for the above that still uses LooseScan: create table t0(a int primary key); @@ -2779,22 +2778,22 @@ SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1_1 ALL NULL NULL NULL NULL 11 Using where -1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 -1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Using where; FirstMatch(t1_2) +1 PRIMARY <derived3> ref key0 key0 5 test.t1_1.a 2 Start temporary +1 PRIMARY t1_2 ALL NULL NULL NULL NULL 11 Using where; End temporary 3 DERIVED t1 ALL NULL NULL NULL NULL 11 SELECT * FROM t1 AS t1_1, t1 AS t1_2 WHERE (t1_1.a, t1_2.a) IN ( SELECT a, b FROM v1 ); a b a b -3 1 9 1 -5 8 4 0 -3 9 9 1 2 4 4 0 2 4 6 8 2 6 4 0 2 6 6 8 +3 1 9 1 +3 9 9 1 5 4 4 0 -7 7 7 7 5 4 4 0 +5 8 4 0 +7 7 7 7 DROP VIEW v1; DROP TABLE t1; set @@join_cache_level= @tmp_jcl_978479; @@ -2938,9 +2937,9 @@ alias2.col_int_key = alias1.col_int_key WHERE alias1.pk = 58 OR alias1.col_varchar_key = 'o' ); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where; Start temporary -1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) -1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); End temporary +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +1 PRIMARY alias1 index_merge PRIMARY,col_int_key,col_varchar_key PRIMARY,col_varchar_key 4,4 NULL 2 Using sort_union(PRIMARY,col_varchar_key); Using where +1 PRIMARY alias2 ALL col_int_key NULL NULL NULL 12 Range checked for each record (index map: 0x2); FirstMatch(t2) SELECT * FROM t2 WHERE (field1) IN (SELECT alias1.col_varchar_nokey AS field1 @@ -3300,8 +3299,7 @@ explain extended SELECT Id FROM t1 WHERE Id in (SELECT t1_Id FROM t2 WHERE t2.col1 IS NULL); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 system PRIMARY NULL NULL NULL 1 100.00 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 -2 MATERIALIZED t2 ref col1 col1 5 const 2 100.00 Using index condition; Using where +1 PRIMARY t2 ALL col1 NULL NULL NULL 2 100.00 Using where; FirstMatch(t1) Warnings: Note 1003 select 1 AS `Id` from (`test`.`t2`) where `test`.`t2`.`t1_Id` = 1 and `test`.`t2`.`col1` is null DROP TABLE t1, t2; diff --git a/mysql-test/main/subselect_sj_mat.result b/mysql-test/main/subselect_sj_mat.result index 40a501b66f2..afd8e3b0734 100644 --- a/mysql-test/main/subselect_sj_mat.result +++ b/mysql-test/main/subselect_sj_mat.result @@ -107,9 +107,9 @@ a1 a2 explain extended select * from t1i where a1 in (select b1 from t2i where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1i range _it1_idx _it1_idx # NULL 3 100.00 Using where; +1 PRIMARY t1i index _it1_idx _it1_idx # NULL 3 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key # func 1 100.00 -2 MATERIALIZED t2i range it2i1,it2i3 it2i1 # NULL 5 100.00 Using where; +2 MATERIALIZED t2i index it2i1,it2i3 it2i1 # NULL 5 100.00 Using where; Warnings: Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t2i`.`b1` > '0' select * from t1i where a1 in (select b1 from t2i where b1 > '0'); @@ -131,9 +131,9 @@ a1 a2 explain extended select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1i range _it1_idx _it1_idx # NULL 3 100.00 Using where; +1 PRIMARY t1i index _it1_idx _it1_idx # NULL 3 100.00 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key # func,func 1 100.00 -2 MATERIALIZED t2i range it2i1,it2i2,it2i3 it2i3 # NULL 5 100.00 Using where; +2 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 100.00 Using where; Warnings: Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t2i`.`b1` > '0' select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); @@ -278,10 +278,11 @@ a1 a2 explain extended select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 50.00 Using where; Using index; LooseScan -1 PRIMARY t1i ref it1i1,it1i2,it1i3 it1i3 18 test.t2i.b1,test.t2i.b2 1 100.00 Using index +1 PRIMARY t1i index it1i1,it1i2,it1i3 it1i3 18 NULL 3 100.00 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +2 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 100.00 Using index Warnings: -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) where 1 select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2); a1 a2 1 - 01 2 - 01 @@ -352,14 +353,12 @@ where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and (a1, a2) in (select c1, c2 from t3i where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY t1i range it1i1,it1i2,it1i3 # # # 3 100.00 # -1 PRIMARY <subquery3> eq_ref distinct_key # # # 1 100.00 # -1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 # -3 MATERIALIZED t3i range it3i1,it3i2,it3i3 # # # 4 100.00 # -3 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 # -2 MATERIALIZED t2i range it2i1,it2i2,it2i3 # # # 5 100.00 # +1 PRIMARY t2i index it2i1,it2i2,it2i3 # # # 5 50.00 # +1 PRIMARY t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 # +1 PRIMARY t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 # +1 PRIMARY t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 # Warnings: -Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t2i`.`b1` = `test`.`t3i`.`c1` and `test`.`t2i`.`b2` = `test`.`t3i`.`c2` and `test`.`t2i`.`b1` > '0' and `test`.`t3i`.`c2` > '0' +Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0' select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and (a1, a2) in (select c1, c2 from t3i @@ -402,15 +401,15 @@ b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 99.22 -1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 16 func,func 1 100.00 1 PRIMARY t2 ALL NULL NULL NULL NULL 5 99.22 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 16 func,func 1 100.00 5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 99.22 Using where 5 MATERIALIZED t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t3c.c1,test.t3c.c2 1 100.00 Using index 4 MATERIALIZED t3b ALL NULL NULL NULL NULL 4 100.00 Using where 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where `test`.`t2i`.`b1` = `test`.`t3c`.`c1` and `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t2i`.`b2` = `test`.`t3c`.`c2` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(/* select#3 */ select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where `test`.`t3a`.`c1` = `test`.`t1`.`a1` and <cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where `test`.`t3b`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3c`.`c2` > '0' +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t2i`.`b1` = `test`.`t3c`.`c1` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and `test`.`t2i`.`b2` = `test`.`t3c`.`c2` and (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(/* select#3 */ select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where `test`.`t3a`.`c1` = `test`.`t1`.`a1` and <cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where `test`.`t3b`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3c`.`c2` > '0' select * from t1 where (a1, a2) in (select b1, b2 from t2 where b2 in (select c2 from t3 t3a where c1 = a1) or @@ -442,15 +441,13 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 2 MATERIALIZED t2 ALL NULL # # # 5 99.22 # 4 MATERIALIZED t3 ALL NULL # # # 4 100.00 # 3 MATERIALIZED t3 ALL NULL # # # 4 100.00 # -7 UNION t1i range it1i1,it1i2,it1i3 # # # 3 100.00 # -7 UNION <subquery9> eq_ref distinct_key # # # 1 100.00 # -7 UNION <subquery8> eq_ref distinct_key # # # 1 100.00 # -9 MATERIALIZED t3i range it3i1,it3i2,it3i3 # # # 4 100.00 # -9 MATERIALIZED t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 # -8 MATERIALIZED t2i range it2i1,it2i2,it2i3 # # # 5 100.00 # +7 UNION t2i index it2i1,it2i2,it2i3 # # # 5 50.00 # +7 UNION t1i ref it1i1,it1i2,it1i3 # # # 1 100.00 # +7 UNION t3i ref it3i1,it3i2,it3i3 # # # 1 100.00 # +7 UNION t2i ref it2i1,it2i2,it2i3 # # # 1 100.00 # NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL # Warnings: -Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3`.`c2` > '0') union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t2i`.`b1` = `test`.`t3i`.`c1` and `test`.`t2i`.`b2` = `test`.`t3i`.`c2` and `test`.`t2i`.`b1` > '0' and `test`.`t3i`.`c2` > '0') +Note 1003 (/* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and (<expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#3 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%02' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery3>`.`c2`)))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c2` from `test`.`t3` where `test`.`t3`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) and `test`.`t3`.`c2` > '0') union (/* select#7 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` semi join (`test`.`t2i`) semi join (`test`.`t2i` join `test`.`t3i`) where `test`.`t1i`.`a1` = `test`.`t2i`.`b1` and `test`.`t3i`.`c1` = `test`.`t2i`.`b1` and `test`.`t2i`.`b1` = `test`.`t2i`.`b1` and `test`.`t1i`.`a2` = `test`.`t2i`.`b2` and `test`.`t3i`.`c2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b2` = `test`.`t2i`.`b2` and `test`.`t2i`.`b1` > '0' and `test`.`t2i`.`b2` > '0') (select * from t1 where (a1, a2) in (select b1, b2 from t2 where b2 in (select c2 from t3 where c2 LIKE '%02') or @@ -542,15 +539,15 @@ b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2)); 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 t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) 1 PRIMARY t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t1.a1,test.t1.a2 1 100.00 Using index; Start temporary 1 PRIMARY t3c ALL NULL NULL NULL NULL 4 100.00 Using where; End temporary; Using join buffer (flat, BNL join) -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) 4 MATERIALIZED t3b ALL NULL NULL NULL NULL 4 100.00 Using where 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where Warnings: Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1 Note 1276 Field or reference 'test.t1.a2' of SELECT #6 was resolved in SELECT #1 -Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where `test`.`t2i`.`b1` = `test`.`t1`.`a1` and `test`.`t3c`.`c1` = `test`.`t1`.`a1` and `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t2i`.`b2` = `test`.`t1`.`a2` and `test`.`t3c`.`c2` = `test`.`t1`.`a2` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(/* select#3 */ select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where `test`.`t3a`.`c1` = `test`.`t1`.`a1` and <cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where `test`.`t3b`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) semi join (`test`.`t2i` join `test`.`t3` `t3c`) where `test`.`t2`.`b1` = `test`.`t1`.`a1` and `test`.`t2i`.`b1` = `test`.`t1`.`a1` and `test`.`t3c`.`c1` = `test`.`t1`.`a1` and `test`.`t2`.`b2` = `test`.`t1`.`a2` and `test`.`t2i`.`b2` = `test`.`t1`.`a2` and `test`.`t3c`.`c2` = `test`.`t1`.`a2` and (<expr_cache><`test`.`t2`.`b2`,`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t2`.`b2`,<exists>(/* select#3 */ select `test`.`t3a`.`c2` from `test`.`t3` `t3a` where `test`.`t3a`.`c1` = `test`.`t1`.`a1` and <cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`))) or <expr_cache><`test`.`t2`.`b2`>(<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (/* select#4 */ select `test`.`t3b`.`c2` from `test`.`t3` `t3b` where `test`.`t3b`.`c2` like '%03' ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where `test`.`t2`.`b2` = `<subquery4>`.`c2`))))) explain extended select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01'); id select_type table type possible_keys key key_len ref rows filtered Extra @@ -1573,8 +1570,7 @@ SET @@optimizer_switch='semijoin=on,materialization=on'; EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Rowid-ordered scan +1 PRIMARY t2 ALL PRIMARY NULL NULL NULL 2 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); pk 2 @@ -1993,11 +1989,11 @@ EXPLAIN EXTENDED SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); id select_type table type possible_keys key key_len ref rows filtered Extra -1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 100.00 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 100.00 Warnings: -Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(/*always not null*/ 1 is null) or `<subquery2>`.`MAX(c)` = 7) +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from <materialize> (/* select#2 */ select max(`test`.`t2`.`c`) from `test`.`t2` having `MAX(c)` is null or `MAX(c)` = 7) join `test`.`t1` where `test`.`t1`.`b` = 7 and `<subquery2>`.`MAX(c)` = `test`.`t1`.`a` and (`test`.`t1`.`a` is null or `test`.`t1`.`a` = 7) SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); a b @@ -2006,8 +2002,8 @@ EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 Using where 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where SELECT * FROM t1 WHERE a IN (SELECT MAX(c) FROM t2 WHERE c < 4) AND b=7 AND (a IS NULL OR a=b); @@ -2283,9 +2279,8 @@ WHERE EXISTS ( SELECT * FROM t1 AS sq2 WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY sq1 ALL NULL NULL NULL NULL 2 Using where -2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where -2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 -3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where; FirstMatch +2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) # this checks the result set above set optimizer_switch= 'materialization=off,semijoin=off'; SELECT sq1.f2 FROM t1 AS sq1 @@ -2317,10 +2312,9 @@ WHERE EXISTS ( SELECT * FROM t2, t3 WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where -2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index -2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 8 100.00 Using where; FirstMatch +2 DEPENDENT SUBQUERY t2 index i2 i2 5 NULL 3 100.00 Using where; Using index; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t3 ref i3 i3 5 test.t2.i2 2 100.00 Using index -3 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 100.00 Warnings: Note 1276 Field or reference 'test.t1.f1' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1` from `test`.`t1` where <expr_cache><`test`.`t1`.`f1`>(exists(/* select#2 */ select 1 from `test`.`t2` semi join (`test`.`t3`) join `test`.`t3` where `test`.`t3`.`i3` = `test`.`t2`.`i2` and `test`.`t1`.`f1` = `test`.`t3`.`f3` limit 1)) @@ -2356,9 +2350,8 @@ SELECT pk, f1, ( SELECT COUNT(*) FROM t2 WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 -2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 -2 DEPENDENT SUBQUERY <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 -3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; FirstMatch +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) Warnings: Note 1276 Field or reference 'test.t1.pk' of SELECT #2 was resolved in SELECT #1 Note 1003 /* select#1 */ select `test`.`t1`.`pk` AS `pk`,`test`.`t1`.`f1` AS `f1`,<expr_cache><`test`.`t1`.`pk`>((/* select#2 */ select count(0) from `test`.`t2` semi join (`test`.`t2`) where `test`.`t1`.`pk` = `test`.`t2`.`f2`)) AS `sq` from `test`.`t1` @@ -2441,11 +2434,10 @@ WHERE t2.ugroup = t3_i.sys_id AND t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND t2.user = '86826bf03710200044e0bfc8bcbe5d79'); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2 +1 PRIMARY t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary 1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where; End temporary 1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index -2 MATERIALIZED t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where -2 MATERIALIZED t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where SELECT t1.assignment_group FROM t1, t3 WHERE t1.assignment_group = t3.sys_id AND @@ -2477,8 +2469,7 @@ explain SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 9 -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 -2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL 3 Using where; FirstMatch(t1); Using join buffer (flat, BNL join) SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); 1 1 @@ -2489,8 +2480,8 @@ alter table t1 add key(id); explain SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); 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 t1 ref id id 4 test.t2.i1 2 Using index +1 PRIMARY t1 index id id 4 NULL 9 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where SELECT 1 FROM t1 where t1.id IN (SELECT t2.i1 FROM t2 WHERE t2.i1 = t2.i2); 1 @@ -2546,8 +2537,8 @@ INSERT INTO t2 VALUES (11,11),(12,12),(13,13); CREATE VIEW v1 AS SELECT t2.i1 FROM t2 where t2.i1 = t2.i2; explain SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1); 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 t1 ref id id 4 test.t2.i1 2 Using index +1 PRIMARY t1 index id id 4 NULL 9 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where SELECT 1 FROM t1 where t1.id IN (SELECT v1.i1 from v1); 1 diff --git a/mysql-test/main/subselect_sj_nonmerged.result b/mysql-test/main/subselect_sj_nonmerged.result index 422af02c31a..b97dfbfda9b 100644 --- a/mysql-test/main/subselect_sj_nonmerged.result +++ b/mysql-test/main/subselect_sj_nonmerged.result @@ -47,8 +47,8 @@ id select_type table type possible_keys key key_len ref rows Extra # Compare to this which really will have 50 record combinations: explain select * from t3 where a in (select max(t2.a) from t1, t2 group by t2.b, t1.b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 index PRIMARY PRIMARY 8 NULL 100 Using index -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 test.t3.a 1 Using where +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 50 +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using temporary 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join) SET @save_optimizer_switch=@@optimizer_switch; @@ -57,8 +57,8 @@ SET optimizer_switch='outer_join_with_cache=off'; explain select * from t3 where a in (select max(t2.a) from t1 left join t2 on t1.a=t2.a group by t2.b, t1.b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t3 index PRIMARY PRIMARY 8 NULL 100 Using index -1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 test.t3.a 1 Using where +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 50 +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 8 <subquery2>.max(t2.a) 1 Using where; Using index 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using temporary 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using where SET optimizer_switch=@save_optimizer_switch; @@ -67,8 +67,8 @@ insert into t4 select A.a + 10*B.a, A.a + 10*B.a, 'filler' from t0 A, t0 B; explain select * from t0, t4 where t4.b=t0.a and t4.a in (select max(t2.a) from t1, t2 group by t2.b); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 -1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t0 ALL NULL NULL NULL NULL 10 Using where +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 5 Using join buffer (flat, BNL join) 1 PRIMARY t4 eq_ref a a 10 <subquery2>.max(t2.a),test.t0.a 1 2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 Using temporary 2 MATERIALIZED t1 ALL NULL NULL NULL NULL 10 Using join buffer (flat, BNL join) diff --git a/mysql-test/main/table_elim.result b/mysql-test/main/table_elim.result index deff0623370..80fa135c6d4 100644 --- a/mysql-test/main/table_elim.result +++ b/mysql-test/main/table_elim.result @@ -337,7 +337,7 @@ id select_type table type possible_keys key key_len ref rows Extra explain select t1.a from t1 left join t2 on t2.pk between 0.5 and 1.5; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 -1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index +1 SIMPLE t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index explain select t1.a from t1 left join t2 on t2.pk between 10 and 10; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 @@ -408,7 +408,7 @@ select t1.* from t1 left join t2 on t2.pk=3 or t2.pk= 4; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 -1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Using index +1 SIMPLE t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index explain select t1.* from t1 left join t2 on t2.pk=3 or t2.pk= 3; @@ -419,7 +419,7 @@ select t1.* from t1 left join t2 on (t2.pk=3 and t2.b=3) or (t2.pk= 4 and t2.b=3); id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 4 -1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where +1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 2 Using where drop table t1, t2; # # LPBUG#523593: Running RQG optimizer_no_subquery crashes MariaDB @@ -562,10 +562,7 @@ LEFT JOIN t1 ON t4.f1 = t1.f1 JOIN t5 ON t4.f3 ON t3.f1 = t5.f5 ON t2.f4 = t3.f4 WHERE t3.f2 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 ALL NULL NULL NULL NULL 2 Using where -1 SIMPLE t5 ref f5 f5 5 test.t3.f1 2 Using where; Using index -1 SIMPLE t4 ALL NULL NULL NULL NULL 3 Using where -1 SIMPLE t2 ALL f4 NULL NULL NULL 11 Using where; Using join buffer (flat, BNL join) +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables # ^^ The above must not produce a QEP of t3,t5,t2,t4 # as that violates the "no interleaving of outer join nests" rule. DROP TABLE t1,t2,t3,t4,t5; diff --git a/mysql-test/main/tmp_table_count-7586.result b/mysql-test/main/tmp_table_count-7586.result index 637e7385685..ebb2333113f 100644 --- a/mysql-test/main/tmp_table_count-7586.result +++ b/mysql-test/main/tmp_table_count-7586.result @@ -52,6 +52,7 @@ Created_tmp_disk_tables 0 Created_tmp_files 0 Created_tmp_tables 2 drop table t3; +set @@optimizer_switch="firstmatch=off"; EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 @@ -69,6 +70,7 @@ Variable_name Value Created_tmp_disk_tables 0 Created_tmp_files 0 Created_tmp_tables 1 +set @@optimizer_switch=default; drop table t1,t2,t3; truncate table performance_schema.events_statements_history_long; flush status; diff --git a/mysql-test/main/tmp_table_count-7586.test b/mysql-test/main/tmp_table_count-7586.test index 8bfb0e7c5cf..b994410650b 100644 --- a/mysql-test/main/tmp_table_count-7586.test +++ b/mysql-test/main/tmp_table_count-7586.test @@ -43,6 +43,7 @@ select sum(created_tmp_tables) from performance_schema.events_statements_history show status like '%Created_tmp%'; drop table t3; +set @@optimizer_switch="firstmatch=off"; EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a); truncate table performance_schema.events_statements_history_long; flush status; @@ -50,6 +51,7 @@ CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a); --echo # Performance schema should be the same as "Created_tmp_tables" variable below select sum(created_tmp_tables) from performance_schema.events_statements_history_long; show status like '%Created_tmp%'; +set @@optimizer_switch=default; drop table t1,t2,t3; diff --git a/mysql-test/main/type_blob.result b/mysql-test/main/type_blob.result index c2739e4b166..1ea53475155 100644 --- a/mysql-test/main/type_blob.result +++ b/mysql-test/main/type_blob.result @@ -625,7 +625,7 @@ id txt 3 NULL explain select * from t1 where txt='Chevy' or txt is NULL; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref_or_null txt_index txt_index 23 const 3 Using where +1 SIMPLE t1 ALL txt_index NULL NULL NULL 6 Using where explain select * from t1 FORCE INDEX (`txt_index`) where txt='Chevy' or txt is NULL; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ref_or_null txt_index txt_index 23 const 3 Using where diff --git a/mysql-test/main/type_datetime.result b/mysql-test/main/type_datetime.result index 77d77d218f0..76337ca23fb 100644 --- a/mysql-test/main/type_datetime.result +++ b/mysql-test/main/type_datetime.result @@ -105,7 +105,7 @@ date numfacture expedition 0000-00-00 00:00:00 1212 0001-00-00 00:00:00 EXPLAIN SELECT * FROM t1 WHERE expedition='0001-00-00 00:00:00'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref expedition expedition 5 const 2 +1 SIMPLE t1 ALL expedition NULL NULL NULL 2 Using where drop table t1; create table t1 (a datetime not null, b datetime not null); insert into t1 values (now(), now()); @@ -545,7 +545,7 @@ select * from t1 where id in (select id from t1 as x1 where (t1.cur_date is null)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where -1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary +1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t1) Warnings: Note 1276 Field or reference 'test.t1.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`cur_date` AS `cur_date` from `test`.`t1` semi join (`test`.`t1` `x1`) where `test`.`x1`.`id` = `test`.`t1`.`id` and `test`.`t1`.`cur_date` = 0 @@ -557,7 +557,7 @@ select * from t2 where id in (select id from t2 as x1 where (t2.cur_date is null)); id select_type table type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where -1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; Start temporary; End temporary +1 PRIMARY x1 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(t2) Warnings: Note 1276 Field or reference 'test.t2.cur_date' of SELECT #2 was resolved in SELECT #1 Note 1003 select `test`.`t2`.`id` AS `id`,`test`.`t2`.`cur_date` AS `cur_date` from `test`.`t2` semi join (`test`.`t2` `x1`) where `test`.`x1`.`id` = `test`.`t2`.`id` and `test`.`t2`.`cur_date` = 0 diff --git a/mysql-test/main/user_var.result b/mysql-test/main/user_var.result index de339b4b037..43b41c616b2 100644 --- a/mysql-test/main/user_var.result +++ b/mysql-test/main/user_var.result @@ -22,7 +22,7 @@ i @vv1:=if(sv1.i,1,0) @vv2:=if(sv2.i,1,0) @vv3:=if(sv3.i,1,0) @vv1+@vv2+@vv3 2 1 0 0 1 explain select * from t1 where i=@vv1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref i i 4 const 2 +1 SIMPLE t1 ALL i NULL NULL NULL 3 Using where select @vv1,i,v from t1 where i=@vv1; @vv1 i v 1 1 1 @@ -35,7 +35,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 index NULL i 4 NULL 3 Using where; Using index explain select * from t1 where i=@vv1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref i i 4 const 2 +1 SIMPLE t1 ALL i NULL NULL NULL 3 Using where drop table t1,t2; set @a=0,@b=0; select @a:=10, @b:=1, @a > @b, @a < @b; diff --git a/mysql-test/main/view.test b/mysql-test/main/view.test index 4bc688efa3d..4d6e0be87de 100644 --- a/mysql-test/main/view.test +++ b/mysql-test/main/view.test @@ -1890,7 +1890,9 @@ CREATE VIEW v1 AS SELECT id, f FROM t1 WHERE id <= 2; INSERT INTO t1 VALUES (2, 'foo2'); INSERT INTO t1 VALUES (1, 'foo1'); +--sorted_result SELECT * FROM v1; +--sorted_result SELECT * FROM v1; DROP VIEW v1; diff --git a/mysql-test/main/xtradb_mrr.result b/mysql-test/main/xtradb_mrr.result index 34fd8300423..2406424fe64 100644 --- a/mysql-test/main/xtradb_mrr.result +++ b/mysql-test/main/xtradb_mrr.result @@ -431,6 +431,12 @@ INSERT INTO `t1` VALUES (97,7,0,'z','z'); INSERT INTO `t1` VALUES (98,1,1,'j','j'); INSERT INTO `t1` VALUES (99,7,8,'c','c'); INSERT INTO `t1` VALUES (100,2,5,'f','f'); +EXPLAIN SELECT table1 .`col_varchar_key` +FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE table1 index NULL col_varchar_key 9 NULL 6 Using index +1 SIMPLE table3 ALL NULL NULL NULL NULL 6 Using where; Using join buffer (flat, BNL join) +1 SIMPLE table4 eq_ref PRIMARY PRIMARY 4 test.table3.col_int_nokey 1 Using where SELECT table1 .`col_varchar_key` FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ; col_varchar_key diff --git a/mysql-test/main/xtradb_mrr.test b/mysql-test/main/xtradb_mrr.test index 9de9b192b06..fcb4f83af36 100644 --- a/mysql-test/main/xtradb_mrr.test +++ b/mysql-test/main/xtradb_mrr.test @@ -151,6 +151,8 @@ INSERT INTO `t1` VALUES (97,7,0,'z','z'); INSERT INTO `t1` VALUES (98,1,1,'j','j'); INSERT INTO `t1` VALUES (99,7,8,'c','c'); INSERT INTO `t1` VALUES (100,2,5,'f','f'); +EXPLAIN SELECT table1 .`col_varchar_key` +FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ; SELECT table1 .`col_varchar_key` FROM t1 table1 STRAIGHT_JOIN ( t1 table3 JOIN t1 table4 ON table4 .`pk` = table3 .`col_int_nokey` ) ON table4 .`col_varchar_nokey` ; DROP TABLE t1; |