[Commits] 1e613c3: MDEV-12387 Push conditions into materialized subqueries
revision-id: 1e613c31fdda201a2c3477cb32d5337710bdaaaa (mariadb-10.3.5-262-g1e613c3) parent(s): b20039dd807007bb5662a9cd74b1ed31a21b7eac 79a7641b40c7b12dda4a6e30e7688b2f796e6a98 author: Galina Shalygina committer: Galina Shalygina timestamp: 2018-05-05 20:51:42 +0200 message: MDEV-12387 Push conditions into materialized subqueries The logic and the implementation scheme are similar with the MDEV-9197 Pushdown conditions into non-mergeable views/derived tables How the push down is made on the example: select * from t1 where a>3 and b>10 and (a,b) in (select x,max(y) from t2 group by x); --> select * from t1 where a>3 and b>10 and (a,b) in (select x,max(y) from t2 where x>3 group by x having max(y)>10); The implementation scheme: 1. Search for the condition cond that depends only on the fields from the left part of the IN subquery (left_part) 2. Find fields F_group in the select of the right part of the IN subquery (right_part) that are used in the GROUP BY 3. Extract from the cond condition cond_where that depends only on the fields from the left_part that stay at the same places in the left_part (have the same indexes) as the F_group fields in the projection of the right_part 4. Transform cond_where so it can be pushed into the WHERE clause of the right_part and delete cond_where from the cond 5. Transform cond so it can be pushed into the HAVING clause of the right_part The optimization is made in the Item_in_subselect::pushdown_cond_for_in_subquery() and is controlled by the variable condition_pushdown_for_subquery. New test file in_subq_cond_pushdown.test is created. There are also some changes made for setup_jtbm_semi_joins(). Now it is decomposed into the 2 procedures: setup_degenerate_jtbm_semi_joins() that is called before optimize_cond() for cond and setup_jtbm_semi_joins() that is called after optimize_cond(). New setup_jtbm_semi_joins() is made in the way so that the result of its work is the same as if it was called before optimize_cond(). The code that is common for pushdown into materialized derived and into materialized IN subqueries is factored out into pushdown_cond_for_derived(), Item_in_subselect::pushdown_cond_for_in_subquery() and st_select_lex::pushdown_cond_into_where_clause(). mysql-test/main/derived.result | 2 +- mysql-test/main/in_subq_cond_pushdown.result | 3801 ++++++++++++++++++++ mysql-test/main/in_subq_cond_pushdown.test | 759 ++++ mysql-test/main/mysqld--help.result | 5 +- mysql-test/main/subselect_mat.result | 2 +- mysql-test/main/subselect_sj_mat.result | 2 +- .../suite/sys_vars/r/optimizer_switch_basic.result | 36 +- .../sys_vars/r/sysvars_server_notembedded.result | 8 +- sql/item.cc | 243 +- sql/item.h | 77 +- sql/item_cmpfunc.h | 8 +- sql/item_func.h | 5 + sql/item_row.h | 5 + sql/item_subselect.h | 13 +- sql/opt_subselect.cc | 946 ++++- sql/opt_subselect.h | 11 +- sql/sql_derived.cc | 211 +- sql/sql_lex.cc | 156 +- sql/sql_lex.h | 29 +- sql/sql_priv.h | 4 +- sql/sql_select.cc | 56 +- sql/sql_select.h | 18 +- sql/sys_vars.cc | 1 + sql/table.cc | 194 - sql/table.h | 2 - .../mysql-test/tokudb/r/ext_key_1_innodb.result | 2 +- .../mysql-test/tokudb/r/ext_key_1_tokudb.result | 2 +- .../mysql-test/tokudb/r/ext_key_2_innodb.result | 2 +- .../mysql-test/tokudb/r/ext_key_2_tokudb.result | 2 +- 29 files changed, 6102 insertions(+), 500 deletions(-) diff --cc mysql-test/main/derived.result index ebbc08a,0000000..a1dd1a7 mode 100644,000000..100644 --- a/mysql-test/main/derived.result +++ b/mysql-test/main/derived.result @@@ -1,1164 -1,0 +1,1164 @@@ +drop table if exists t1,t2,t3; +set @save_derived_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +select * from (select 2 from DUAL) b; +2 +2 +SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT 1 as a FROM (SELECT a UNION SELECT 1) b; +ERROR 42S22: Unknown column 'a' in 'field list' +CREATE TABLE t1 (a int not null, b char (10) not null); +insert into t1 values(1,'a'),(2,'b'),(3,'c'),(3,'c'); +CREATE TABLE t2 (a int not null, b char (10) not null); +insert into t2 values (3,'c'),(4,'d'),(5,'f'),(6,'e'); +select t1.a,t3.y from t1,(select a as y from t2 where b='c') as t3 where t1.a = t3.y; +a y +3 3 +3 3 +select t1.a,t3.a from t1,(select * from t2 where b='c') as t3 where t1.a = t3.a; +a a +3 3 +3 3 +CREATE TABLE t3 (a int not null, b char (10) not null); +insert into t3 values (3,'f'),(4,'y'),(5,'z'),(6,'c'); +select t1.a,t4.y from t1,(select t2.a as y from t2,(select t3.b from t3 where t3.a>3) as t5 where t2.b=t5.b) as t4 where t1.a = t4.y; +a y +3 3 +3 3 +SELECT a FROM (SELECT 1 FROM (SELECT 1) a HAVING a=1) b; +ERROR 42S22: Unknown column 'a' in 'having clause' +SELECT a,b as a FROM (SELECT '1' as a,'2' as b) b HAVING a=1; +ERROR 23000: Column 'a' in having clause is ambiguous +SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=2; +a a +1 2 +SELECT a,2 as a FROM (SELECT '1' as a) b HAVING a=1; +a a +SELECT 1 FROM (SELECT 1) a WHERE a=2; +ERROR 42S22: Unknown column 'a' in 'where clause' +SELECT (SELECT 1) as a FROM (SELECT 1 FROM t1 HAVING a=1) as a; +ERROR 42S22: Unknown column 'a' in 'having clause' +select * from t1 as x1, (select * from t1) as x2; +a b a b +1 a 1 a +2 b 1 a +3 c 1 a +3 c 1 a +1 a 2 b +2 b 2 b +3 c 2 b +3 c 2 b +1 a 3 c +2 b 3 c +3 c 3 c +3 c 3 c +1 a 3 c +2 b 3 c +3 c 3 c +3 c 3 c +explain select * from t1 as x1, (select * from t1) as x2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY x1 ALL NULL NULL NULL NULL 4 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) +2 DERIVED t1 ALL NULL NULL NULL NULL 4 +drop table if exists t2,t3; +select * from (select 1) as a; +1 +1 +select a from (select 1 as a) as b; +a +1 +select 1 from (select 1) as a; +1 +1 +select * from (select * from t1 union select * from t1) a; +a b +1 a +2 b +3 c +select * from (select * from t1 union all select * from t1) a; +a b +1 a +2 b +3 c +3 c +1 a +2 b +3 c +3 c +select * from (select * from t1 union all select * from t1 limit 2) a; +a b +1 a +2 b +explain select * from (select * from t1 union select * from t1) a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 8 +2 DERIVED t1 ALL NULL NULL NULL NULL 4 +3 UNION t1 ALL NULL NULL NULL NULL 4 +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +explain select * from (select * from t1 union all select * from t1) a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 8 +2 DERIVED t1 ALL NULL NULL NULL NULL 4 +3 UNION t1 ALL NULL NULL NULL NULL 4 +CREATE TABLE t2 (a int not null); +insert into t2 values(1); +select * from (select * from t1 where t1.a=(select a from t2 where t2.a=t1.a)) a; +a b +1 a +select * from (select * from t1 where t1.a=(select t2.a from t2 where t2.a=t1.a) union select t1.a, t1.b from t1) a; +a b +1 a +2 b +3 c +explain select * from (select t1.*, t2.a as t2a from t1,t2 where t1.a=t2.a) t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 4 +2 DERIVED t2 system NULL NULL NULL NULL 1 +2 DERIVED t1 ALL NULL NULL NULL NULL 4 Using where +drop table t1, t2; +create table t1(a int not null, t char(8), index(a)); +SELECT * FROM (SELECT * FROM t1) as b ORDER BY a ASC LIMIT 0,20; +a t +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 +9 9 +10 10 +11 11 +12 12 +13 13 +14 14 +15 15 +16 16 +17 17 +18 18 +19 19 +20 20 +explain select count(*) from t1 as tt1, (select * from t1) as tt2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY tt1 index NULL a 4 NULL 10000 Using index +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 10000 Using join buffer (flat, BNL join) +2 DERIVED t1 ALL NULL NULL NULL NULL 10000 +drop table t1; +SELECT * FROM (SELECT (SELECT * FROM (SELECT 1 as a) as a )) as b; +(SELECT * FROM (SELECT 1 as a) as a ) +1 +select * from (select 1 as a) b left join (select 2 as a) c using(a); +a +1 +SELECT * FROM (SELECT 1 UNION SELECT a) b; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT 1 as a FROM (SELECT a UNION SELECT 1) b; +ERROR 42S22: Unknown column 'a' in 'field list' +SELECT 1 as a FROM (SELECT 1 UNION SELECT a) b; +ERROR 42S22: Unknown column 'a' in 'field list' +select 1 from (select 2) a order by 0; +ERROR 42S22: Unknown column '0' in 'order clause' +create table t1 (id int); +insert into t1 values (1),(2),(3); +describe select * from (select * from t1 group by id) bar; +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 ALL NULL NULL NULL NULL 3 Using temporary; Using filesort +drop table t1; +create table t1 (mat_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, matintnum CHAR(6) NOT NULL, test MEDIUMINT UNSIGNED NULL); +create table t2 (mat_id MEDIUMINT UNSIGNED NOT NULL, pla_id MEDIUMINT UNSIGNED NOT NULL); +insert into t1 values (NULL, 'a', 1), (NULL, 'b', 2), (NULL, 'c', 3), (NULL, 'd', 4), (NULL, 'e', 5), (NULL, 'f', 6), (NULL, 'g', 7), (NULL, 'h', 8), (NULL, 'i', 9); +insert into t2 values (1, 100), (1, 101), (1, 102), (2, 100), (2, 103), (2, 104), (3, 101), (3, 102), (3, 105); +SELECT STRAIGHT_JOIN d.pla_id, m2.mat_id FROM t1 m2 INNER JOIN (SELECT mp.pla_id, MIN(m1.matintnum) AS matintnum FROM t2 mp INNER JOIN t1 m1 ON mp.mat_id=m1.mat_id GROUP BY mp.pla_id) d ON d.matintnum=m2.matintnum; +pla_id mat_id +100 1 +101 1 +102 1 +103 2 +104 2 +105 3 +SELECT STRAIGHT_JOIN d.pla_id, m2.test FROM t1 m2 INNER JOIN (SELECT mp.pla_id, MIN(m1.matintnum) AS matintnum FROM t2 mp INNER JOIN t1 m1 ON mp.mat_id=m1.mat_id GROUP BY mp.pla_id) d ON d.matintnum=m2.matintnum; +pla_id test +100 1 +101 1 +102 1 +103 2 +104 2 +105 3 +explain SELECT STRAIGHT_JOIN d.pla_id, m2.mat_id FROM t1 m2 INNER JOIN (SELECT mp.pla_id, MIN(m1.matintnum) AS matintnum FROM t2 mp INNER JOIN t1 m1 ON mp.mat_id=m1.mat_id GROUP BY mp.pla_id) d ON d.matintnum=m2.matintnum; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY m2 ALL NULL NULL NULL NULL 9 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 Using where; Using join buffer (flat, BNL join) +2 DERIVED mp ALL NULL NULL NULL NULL 9 Using temporary; Using filesort +2 DERIVED m1 eq_ref PRIMARY PRIMARY 3 test.mp.mat_id 1 +explain SELECT STRAIGHT_JOIN d.pla_id, m2.test FROM t1 m2 INNER JOIN (SELECT mp.pla_id, MIN(m1.matintnum) AS matintnum FROM t2 mp INNER JOIN t1 m1 ON mp.mat_id=m1.mat_id GROUP BY mp.pla_id) d ON d.matintnum=m2.matintnum; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY m2 ALL NULL NULL NULL NULL 9 +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 9 Using where; Using join buffer (flat, BNL join) +2 DERIVED mp ALL NULL NULL NULL NULL 9 Using temporary; Using filesort +2 DERIVED m1 eq_ref PRIMARY PRIMARY 3 test.mp.mat_id 1 +drop table t1,t2; +SELECT a.x FROM (SELECT 1 AS x) AS a HAVING a.x = 1; +x +1 +create user mysqltest_1; +create table t1 select 1 as a; +connect con1,localhost,mysqltest_1,,*NO-ONE*,$MASTER_MYPORT,$MASTER_MYSOCK; +connection con1; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +select 2 as a from (select * from t1) b; +ERROR 3D000: No database selected +use test; +select 2 as a from (select * from t1) b; +a +2 +drop table t1; +select mail_id, if(folder.f_description!='', folder.f_description, folder.f_name) as folder_name, date, address_id, phrase, address, subject from folder, (select mail.mail_id as mail_id, date_format(mail.h_date, '%b %e, %Y %h:%i') as date, mail.folder_id, sender.address_id as address_id, sender.phrase as phrase, sender.address as address, mail.h_subject as subject from mail left join mxa as mxa_sender on mail.mail_id=mxa_sender.mail_id and mxa_sender.type='from' left join address as sender on mxa_sender.address_id=sender.address_id mxa as mxa_recipient, address as recipient, where 1 and mail.mail_id=mxa_recipient.mail_id and mxa_recipient.address_id=recipient.address_id and mxa_recipient.type='to' and match(sender.phrase, sender.address, sender.comment) against ('jeremy' in boolean mode) and match(recipient.phrase, recipient.address, recipient.comment) against ('monty' in boolean mode) order by mail.h_date desc limit 0, 25 ) as query where quer y.folder _id=folder.folder_id; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'mxa as mxa_recipient, address as recipient, where 1 and mail.mail_id=mxa_r' at line 1 +create table t1 (a int); +insert into t1 values (1),(2),(3); +update (select * from t1) as t1 set a = 5; +ERROR HY000: The target table t1 of the UPDATE is not updatable +delete from (select * from t1); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select * from t1)' at line 1 +insert into (select * from t1) values (5); +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(select * from t1) values (5)' at line 1 +drop table t1; +create table t1 (E1 INTEGER UNSIGNED NOT NULL, E2 INTEGER UNSIGNED NOT NULL, E3 INTEGER UNSIGNED NOT NULL, PRIMARY KEY(E1) +); +insert into t1 VALUES(1,1,1), (2,2,1); +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; +count(*) +2 +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 +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; +create table t1 (a int); +insert into t1 values (1),(2); +select * from ( select * from t1 union select * from t1) a,(select * from t1 union select * from t1) b; +a a +1 1 +2 1 +1 2 +2 2 +explain select * from ( select * from t1 union select * from t1) a,(select * from t1 union select * from t1) b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 4 +1 PRIMARY <derived4> ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) +4 DERIVED t1 ALL NULL NULL NULL NULL 2 +5 UNION t1 ALL NULL NULL NULL NULL 2 +NULL UNION RESULT <union4,5> ALL NULL NULL NULL NULL NULL +2 DERIVED t1 ALL NULL NULL NULL NULL 2 +3 UNION t1 ALL NULL NULL NULL NULL 2 +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL +drop table t1; +CREATE TABLE `t1` ( +`N` int(11) unsigned NOT NULL default '0', +`M` tinyint(1) default '0' +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +INSERT INTO `t1` (N, M) VALUES (1, 0),(1, 0),(1, 0),(2, 0),(2, 0),(3, 0); +UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2; +select * from t1; +N M +1 2 +1 2 +1 2 +2 2 +2 2 +3 0 +UPDATE `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2, P2.N = 2; +ERROR HY000: The target table P2 of the UPDATE is not updatable +UPDATE `t1` AS P1 INNER JOIN (SELECT aaaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N SET P1.M = 2; +ERROR 42S22: Unknown column 'aaaa' in 'field list' +delete P1.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N; +select * from t1; +N M +3 0 +delete P1.*,p2.* from `t1` AS P1 INNER JOIN (SELECT N FROM `t1` GROUP BY N HAVING Count(M) > 1) AS p2 ON P1.N = p2.N; +ERROR HY000: The target table p2 of the DELETE is not updatable +delete P1.* from `t1` AS P1 INNER JOIN (SELECT aaa FROM `t1` GROUP BY N HAVING Count(M) > 1) AS P2 ON P1.N = P2.N; +ERROR 42S22: Unknown column 'aaa' in 'field list' +drop table t1; +CREATE TABLE t1 ( +OBJECTID int(11) NOT NULL default '0', +SORTORDER int(11) NOT NULL auto_increment, +KEY t1_SortIndex (SORTORDER), +KEY t1_IdIndex (OBJECTID) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; +CREATE TABLE t2 ( +ID int(11) default NULL, +PARID int(11) default NULL, +UNIQUE KEY t2_ID_IDX (ID), +KEY t2_PARID_IDX (PARID) +) engine=MyISAM DEFAULT CHARSET=latin1; +INSERT INTO t2 VALUES (1000,0),(1001,0),(1002,0),(1003,0),(1008,1),(1009,1),(1010,1),(1011,1),(1016,2); +CREATE TABLE t3 ( +ID int(11) default NULL, +DATA decimal(10,2) default NULL, +UNIQUE KEY t3_ID_IDX (ID) +) engine=MyISAM DEFAULT CHARSET=latin1; +INSERT INTO t3 VALUES (1000,0.00),(1001,0.25),(1002,0.50),(1003,0.75),(1008,1.00),(1009,1.25),(1010,1.50),(1011,1.75); +select 497, TMP.ID, NULL from (select 497 as ID, MAX(t3.DATA) as DATA from t1 join t2 on (t1.ObjectID = t2.ID) join t3 on (t1.ObjectID = t3.ID) group by t2.ParID order by DATA DESC) as TMP; +497 ID NULL +drop table t1, t2, t3; +CREATE TABLE t1 (name char(1) default NULL, val int(5) default NULL); +INSERT INTO t1 VALUES ('a',1), ('a',2), ('a',2), ('a',2), ('a',3), ('a',6), ('a',7), ('a',11), ('a',11), ('a',12), ('a',13), ('a',13), ('a',20), ('b',2), ('b',3), ('b',4), ('b',5); +SELECT s.name, AVG(s.val) AS median FROM (SELECT x.name, x.val FROM t1 x, t1 y WHERE x.name=y.name GROUP BY x.name, x.val HAVING SUM(y.val <= x.val) >= COUNT(*)/2 AND SUM(y.val >= x.val) >= COUNT(*)/2) AS s GROUP BY s.name; +name median +a 7.0000 +b 3.5000 +explain SELECT s.name, AVG(s.val) AS median FROM (SELECT x.name, x.val FROM t1 x, t1 y WHERE x.name=y.name GROUP BY x.name, x.val HAVING SUM(y.val <= x.val) >= COUNT(*)/2 AND SUM(y.val >= x.val) >= COUNT(*)/2) AS s GROUP BY s.name; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 289 Using temporary; Using filesort +2 DERIVED x ALL NULL NULL NULL NULL 17 Using temporary; Using filesort +2 DERIVED y ALL NULL NULL NULL NULL 17 Using where; Using join buffer (flat, BNL join) +drop table t1; +create table t2 (a int, b int, primary key (a)); +insert into t2 values (1,7),(2,7); +explain select a from t2 where a>1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index +explain select a from (select a from t2 where a>1) tt; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +2 DERIVED t2 index PRIMARY PRIMARY 4 NULL 2 Using where; Using index +drop table t2; +CREATE TABLE `t1` ( `itemid` int(11) NOT NULL default '0', `grpid` varchar(15) NOT NULL default '', `vendor` int(11) NOT NULL default '0', `date_` date NOT NULL default '0000-00-00', `price` decimal(12,2) NOT NULL default '0.00', PRIMARY KEY (`itemid`,`grpid`,`vendor`,`date_`), KEY `itemid` (`itemid`,`vendor`), KEY `itemid_2` (`itemid`,`date_`)); +insert into t1 values (128, 'rozn', 2, curdate(), 10), +(128, 'rozn', 1, curdate(), 10); +SELECT MIN(price) min, MAX(price) max, AVG(price) avg FROM (SELECT SUBSTRING( MAX(concat(date_,";",price)), 12) price FROM t1 WHERE itemid=128 AND grpid='rozn' GROUP BY itemid, grpid, vendor) lastprices; +min max avg +10.00 10.00 10 +DROP TABLE t1; +create table t1 (a integer, b integer); +insert into t1 values (1,4), (2,2),(2,2), (4,1),(4,1),(4,1),(4,1); +select distinct sum(b) from t1 group by a; +sum(b) +4 +select distinct sum(b) from (select a,b from t1) y group by a; +sum(b) +4 +drop table t1; +CREATE TABLE t1 (a char(10), b char(10)); +INSERT INTO t1 VALUES ('root','localhost'), ('root','%'); +SELECT * FROM (SELECT (SELECT a.a FROM t1 AS a WHERE a.a = b.a) FROM t1 AS b) AS c; +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1; +create table t1(a int); +create table t2(a int); +create table t3(a int); +insert into t1 values(1),(1); +insert into t2 values(2),(2); +insert into t3 values(3),(3); +select * from t1 union distinct select * from t2 union all select * from t3; +a +1 +2 +3 +3 +select * from (select * from t1 union distinct select * from t2 union all select * from t3) X; +a +1 +2 +3 +3 +drop table t1, t2, t3; +create table t1 (a int); +create table t2 (a int); +select * from (select * from t1,t2) foo; +ERROR 42S21: Duplicate column name 'a' +drop table t1,t2; +create table t1 (ID int unsigned not null auto_increment, +DATA varchar(5) not null, primary key (ID)); +create table t2 (ID int unsigned not null auto_increment, +DATA varchar(5) not null, FID int unsigned not null, +primary key (ID)); +select A.* from (t1 inner join (select * from t2) as A on t1.ID = A.FID); +ID DATA FID +select t2.* from ((select * from t1) as A inner join t2 on A.ID = t2.FID); +ID DATA FID +select t2.* from (select * from t1) as A inner join t2 on A.ID = t2.FID; +ID DATA FID +drop table t1, t2; +connection con1; +disconnect con1; +connection default; +drop user mysqltest_1; +# End of 4.1 tests +SELECT 0 FROM +(SELECT 0) t01, (SELECT 0) t02, (SELECT 0) t03, (SELECT 0) t04, (SELECT 0) t05, +(SELECT 0) t06, (SELECT 0) t07, (SELECT 0) t08, (SELECT 0) t09, (SELECT 0) t10, +(SELECT 0) t11, (SELECT 0) t12, (SELECT 0) t13, (SELECT 0) t14, (SELECT 0) t15, +(SELECT 0) t16, (SELECT 0) t17, (SELECT 0) t18, (SELECT 0) t19, (SELECT 0) t20, +(SELECT 0) t21, (SELECT 0) t22, (SELECT 0) t23, (SELECT 0) t24, (SELECT 0) t25, +(SELECT 0) t26, (SELECT 0) t27, (SELECT 0) t28, (SELECT 0) t29, (SELECT 0) t30, +(SELECT 0) t31, (SELECT 0) t32, (SELECT 0) t33, (SELECT 0) t34, (SELECT 0) t35, +(SELECT 0) t36, (SELECT 0) t37, (SELECT 0) t38, (SELECT 0) t39, (SELECT 0) t40, +(SELECT 0) t41, (SELECT 0) t42, (SELECT 0) t43, (SELECT 0) t44, (SELECT 0) t45, +(SELECT 0) t46, (SELECT 0) t47, (SELECT 0) t48, (SELECT 0) t49, (SELECT 0) t50, +(SELECT 0) t51, (SELECT 0) t52, (SELECT 0) t53, (SELECT 0) t54, (SELECT 0) t55, +(SELECT 0) t56, (SELECT 0) t57, (SELECT 0) t58, (SELECT 0) t59, (SELECT 0) t60, +(SELECT 0) t61; +0 +0 +# +# A nested materialized derived table is used before being populated. +# (addon for bug#19077) +# +CREATE TABLE t1 (i INT, j BIGINT); +INSERT INTO t1 VALUES (1, 2), (2, 2), (3, 2); +SELECT * FROM (SELECT MIN(i) FROM t1 +WHERE j = SUBSTRING('12', (SELECT * FROM (SELECT MIN(j) FROM t1) t2))) t3; +MIN(i) +1 +DROP TABLE t1; +# End of 5.0 tests +# +# MDEV-5005: Subquery in Procedure somehow affecting temporary table +# +create temporary table if not exists t1 (id int not null); +select A.* from ( select tt.* from t1 tt ) A; +id +prepare stmt from "select A.* from ( select tt.* from t1 tt ) A "; +execute stmt; +id +deallocate prepare stmt; +drop temporary table t1; +CREATE PROCEDURE p () +BEGIN +select A.* from ( select tt.* from t1 tt ) A ; +END | +create temporary table if not exists t1 (id int not null); +CALL p(); +id +CALL p(); +id +drop procedure p; +drop temporary table t1; +# +# MDEV-5143: update of a joined table with a nested subquery with +# a syntax error crashes mysqld with signal 11 +# +create table t1 (id int(11) not null auto_increment, val varchar(100) null,primary key (id)); +create table t2 (id int(11) not null auto_increment, val varchar(100) null,primary key (id)); +insert into t1 (val) values('a'); +insert into t2 (val) values('1'); +update +( +select +val +from +( +select +v.val +from +t2 wrong_table_alias +) t4 +) t3 +inner join t1 on +t1.id=t3.val +set +t1.val=t3.val +; +ERROR 42S22: Unknown column 'v.val' in 'field list' +drop table t1, t2; +# +# MDEV-5353: server crash on subselect if WHERE applied to some +# result field +# +SELECT * FROM +( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp +WHERE tmp.b; +a b +100 200 +SELECT * FROM +( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp +WHERE tmp.a; +a b +100 200 +# +# MDEV-5356: Server crashes in Item_equal::contains on 2nd +# execution of a PS +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,2),(3,4); +CREATE TABLE t2 (c INT); +INSERT INTO t2 VALUES (5),(6); +CREATE TABLE t3 (d INT); +INSERT INTO t3 VALUES (7),(8); +CREATE PROCEDURE pr() +UPDATE t3, +(SELECT c FROM +(SELECT 1 FROM t1 WHERE a=72 AND NOT b) sq, +t2 +) sq2 +SET d=sq2.c; +CALL pr(); +CALL pr(); +CALL pr(); +drop procedure pr; +drop table t1,t2,t3; +# End of 5.3 tests +# +# Bug#58730 Assertion failed: table->key_read == 0 in close_thread_table, +# temptable views +# +CREATE TABLE t1 (a INT); +CREATE TABLE t2 (b INT, KEY (b)); +INSERT INTO t1 VALUES (1),(1); +INSERT INTO t2 VALUES (1),(1); +CREATE algorithm=temptable VIEW v1 AS +SELECT 1 FROM t1 LEFT JOIN t1 t3 ON 1 > (SELECT 1 FROM t1); +CREATE algorithm=temptable VIEW v2 AS SELECT 1 FROM t2; +EXPLAIN SELECT 1 FROM t1 JOIN v1 ON 1 > (SELECT 1 FROM v2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +1 PRIMARY <derived3> ALL NULL NULL NULL NULL 4 Using join buffer (flat, BNL join) +3 DERIVED t1 ALL NULL NULL NULL NULL 2 +3 DERIVED t3 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +4 SUBQUERY t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY <derived5> ALL NULL NULL NULL NULL 2 +5 DERIVED t2 index NULL b 5 NULL 2 Using index +SELECT 1 FROM t1 JOIN v1 ON 1 > (SELECT 1 FROM v2); +ERROR 21000: Subquery returns more than 1 row +DROP TABLE t1, t2; +DROP VIEW v1, v2; +create table t1 (n bigint(20) unsigned, d1 datetime, d2 datetime, key (d1)); +insert t1 values (2085,'2012-01-01 00:00:00','2013-01-01 00:00:00'); +insert t1 values (2084,'2012-02-01 00:00:00','2013-01-01 00:00:00'); +insert t1 values (2088,'2012-03-01 00:00:00','2013-01-01 00:00:00'); +select * from ( +select n, d1, d2, @result := 0 as result +from t1 +where d1 < '2012-12-12 12:12:12' and n in (2085, 2084) order by d2 asc +) as calculated_result; +n d1 d2 result +2085 2012-01-01 00:00:00 2013-01-01 00:00:00 0 +2084 2012-02-01 00:00:00 2013-01-01 00:00:00 0 +drop table t1; +set @save_derived_optimizer_switch_bug=@@optimizer_switch; +SET optimizer_switch = 'derived_merge=on,derived_with_keys=on,in_to_exists=on'; +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (8); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1),(7); +EXPLAIN SELECT * FROM (SELECT * FROM t1) AS table1, +(SELECT DISTINCT * FROM t2) AS table2 WHERE b = a AND a <> ANY (SELECT 9); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY <derived3> ref key0 key0 5 const 0 +3 DERIVED t2 ALL NULL NULL NULL NULL 2 Using where; Using temporary +Warnings: +Note 1249 Select 4 was reduced during optimization +DROP TABLE t1, t2; +set optimizer_switch=@save_derived_optimizer_switch_bug; +# +# MDEV-6163: Error while executing an update query that has the +# same table in a sub-query +# +set @save_derived_optimizer_switch_bug=@@optimizer_switch; +SET optimizer_switch = 'derived_merge=on'; +create table t1 (balance float, accountId varchar(64), primary key (accountId)); +insert into t1 (accountId,balance) values +('dealer-1',199354.0),('dealer-2',0),('dealer-3',0),('dealer-5',0),('FINANCE',-200000),('OPERATOR',0); +update t1 set balance=(select sum(balance) from (SELECT balance FROM t1 where accountId like 'dealer%') AS copied) where accountId = 'OPERATOR'; +set optimizer_switch=@save_derived_optimizer_switch_bug; +drop table t1; +# +# MDEV-6219:Server crashes in Bitmap<64u>::merge +# (this=0x180, map2=...) on 2nd execution of PS with INSERT .. SELECT, +# derived_merge +# +CREATE TABLE t1 (a VARCHAR(8)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'),('bar'); +create procedure p1() +INSERT INTO t1 SELECT * FROM ( +SELECT * FROM t1 +) AS sq +WHERE sq.a IN ( SELECT 'baz' FROM DUAL ); +call p1(); +call p1(); +drop procedure p1; +PREPARE stmt FROM " + INSERT INTO t1 SELECT * FROM ( + SELECT * FROM t1 + ) AS sq + WHERE sq.a IN ( SELECT 'baz' FROM DUAL ) +"; +EXECUTE stmt; +EXECUTE stmt; +deallocate prepare stmt; +drop table t1; +# +# MDEV-6892: WHERE does not apply +# +create table t1 (id int); +create table t2 (id int); +insert into t1 values(1),(2),(3); +insert into t2 values(4),(5),(6); +select x.id, message from (select id from t1) x left join +(select id, 1 as message from t2) y on x.id=y.id +where coalesce(message,0) <> 0; +id message +drop table t1,t2; +# +# MDEV-7827: Assertion `!table || (!table->read_set || +# bitmap_is_set(table->read_set, field_index))' failed +# in Field_long::val_str on EXPLAIN EXTENDED +# +CREATE TABLE t1 (f1 INT, f2 INT, KEY(f2)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (6,9); +CREATE TABLE t2 (f3 INT) ENGINE=MyISAM; +INSERT INTO t2 VALUES (2),(0); +EXPLAIN EXTENDED +SELECT f1 FROM ( SELECT * FROM t1 ) AS sq +WHERE f1 IN ( +SELECT f3 FROM t2 WHERE f2 IN ( +SELECT f3 FROM t2 HAVING f3 >= 8 +) +); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 1 100.00 +1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 4 const 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00 Using where; FirstMatch(<subquery4>); Using join buffer (flat, BNL join) +4 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 +2 DERIVED t1 system NULL NULL NULL NULL 1 100.00 +Warnings: +Note 1276 Field or reference 'sq.f2' of SELECT #3 was resolved in SELECT #1 - Note 1003 /* select#1 */ select 6 AS `f1` from <materialize> (/* select#4 */ select `test`.`t2`.`f3` from `test`.`t2` having `test`.`t2`.`f3` >= 8) semi join (`test`.`t2`) where `test`.`t2`.`f3` = 6 and `<subquery4>`.`f3` = 9 ++Note 1003 /* select#1 */ select 6 AS `f1` from <materialize> (/* select#4 */ select `test`.`t2`.`f3` from `test`.`t2` having `test`.`t2`.`f3` >= 8) semi join (`test`.`t2`) where `<subquery4>`.`f3` = 9 and `test`.`t2`.`f3` = 6 +DROP TABLE t2,t1; +# +# MDEV-9462: Out of memory using explain on 2 empty tables +# +CREATE TABLE `t1` ( +`REC_GROUP` char(2) DEFAULT NULL, +`CLIENT_INFO` text CHARACTER SET utf8, +`NAME` text, +`PHONE_NUMBER` text, +`ATTENTION_NAME` text, +`PAYMENT_TERM` text CHARACTER SET utf8, +`CREDIT_LIMIT` decimal(12,2) DEFAULT NULL, +`LAST_PAY_DATE` text CHARACTER SET utf8, +`TOTAL` double DEFAULT NULL, +`TOTAL_MCL` double DEFAULT NULL, +`TOTAL_MFS` double DEFAULT NULL, +`TOTAL_MIS` double DEFAULT NULL, +`BEFORE_DUE_7_MCL` double DEFAULT NULL, +`BEFORE_DUE_7_MFS` double DEFAULT NULL, +`BEFORE_DUE_7_MIS` double DEFAULT NULL, +`PER1_MCL` double DEFAULT NULL, +`PER1_MFS` double DEFAULT NULL, +`PER1_MIS` double DEFAULT NULL, +`PER2_MCL` double DEFAULT NULL, +`PER2_MFS` double DEFAULT NULL, +`PER2_MIS` double DEFAULT NULL, +`PER3_MCL` double DEFAULT NULL, +`PER3_MFS` double DEFAULT NULL, +`PER3_MIS` double DEFAULT NULL, +`PER4_MCL` double DEFAULT NULL, +`PER4_MFS` double DEFAULT NULL, +`PER4_MIS` double DEFAULT NULL, +`PER5_MCL` double DEFAULT NULL, +`PER5_MFS` double DEFAULT NULL, +`PER5_MIS` double DEFAULT NULL, +`PER6_MCL` double DEFAULT NULL, +`PER6_MFS` double DEFAULT NULL, +`PER6_MIS` double DEFAULT NULL, +`PER7_MCL` double DEFAULT NULL, +`PER7_MFS` double DEFAULT NULL, +`PER7_MIS` double DEFAULT NULL, +`BEFORE_DUE_7` double DEFAULT NULL, +`PER1` double DEFAULT NULL, +`PER2` double DEFAULT NULL, +`PER3` double DEFAULT NULL, +`PER4` double DEFAULT NULL, +`PER5` double DEFAULT NULL, +`PER6` double DEFAULT NULL, +`PER7` double DEFAULT NULL, +`REF` varchar(30) DEFAULT NULL, +`TYPE` varchar(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL +); +CREATE TABLE `t2` ( +`RECEIVABLE_GROUP` char(2) DEFAULT NULL, +`CLIENT_NUMBER` varchar(35) DEFAULT NULL, +`CLIENT_NAME` varchar(73) DEFAULT NULL, +`PHONE_NUMBER` char(12) DEFAULT NULL, +`ATTENTION_NAME` char(26) DEFAULT NULL, +`PAYMENT_TERM` varchar(26) CHARACTER SET utf8 DEFAULT NULL, +`CREDIT_LIMIT` decimal(12,2) DEFAULT NULL, +`LAST_PAY_DATE` varchar(42) CHARACTER SET utf8 DEFAULT NULL, +`TOTAL` decimal(12,2) DEFAULT NULL, +`BEFORE_DUE_7` decimal(12,2) DEFAULT NULL, +`PER1` decimal(12,2) DEFAULT NULL, +`PER2` decimal(12,2) DEFAULT NULL, +`PER3` decimal(12,2) DEFAULT NULL, +`PER4` decimal(12,2) DEFAULT NULL, +`PER5` decimal(12,2) DEFAULT NULL, +`PER6` decimal(12,2) DEFAULT NULL, +`PER7` decimal(12,2) DEFAULT NULL, +`DIVISION` varchar(3) CHARACTER SET utf8 NOT NULL, +`CLIENT_INFO` varchar(294) CHARACTER SET utf8 DEFAULT NULL, +`EXCHANGE_RATE` double NOT NULL, +`REF` varchar(30) DEFAULT NULL +); +explain +SELECT A.RECEIVABLE_GROUP,A.CLIENT_INFO,A.CLIENT_NAME,A.PHONE_NUMBER,A.ATTENTION_NAME,A.PAYMENT_TERM,A.CREDIT_LIMIT,A.LAST_PAY_DATE,A.TOTAL, +COALESCE(B.TOTAL_MCL,0) AS TOTAL_MCL, +COALESCE(C.TOTAL_MFS,0) AS TOTAL_MFS, +COALESCE(D.TOTAL_MIS,0) AS TOTAL_MIS, +COALESCE(F.BEFORE_DUE_7_MCL,0) AS BEFORE_DUE_7_MCL, +COALESCE(G.BEFORE_DUE_7_MFS,0) AS BEFORE_DUE_7_MFS, +COALESCE(H.BEFORE_DUE_7_MIS,0) AS BEFORE_DUE_7_MIS, +COALESCE(I.PER1_MCL,0) AS PER1_MCL, +COALESCE(J.PER1_MFS,0) AS PER1_MFS, +COALESCE(K.PER1_MIS,0) AS PER1_MIS, +COALESCE(L.PER2_MCL,0) AS PER2_MCL, +COALESCE(M.PER2_MFS,0) AS PER2_MFS, +COALESCE(N.PER2_MIS,0) AS PER2_MIS, +COALESCE(O.PER3_MCL,0) AS PER3_MCL, +COALESCE(P.PER3_MFS,0) AS PER3_MFS, +COALESCE(R.PER3_MIS,0) AS PER3_MIS, +COALESCE(S.PER4_MCL,0) AS PER4_MCL, +COALESCE(T.PER4_MFS,0) AS PER4_MFS, +COALESCE(U.PER4_MIS,0) AS PER4_MIS, +COALESCE(V.PER5_MCL,0) AS PER5_MCL, +COALESCE(X.PER5_MFS,0) AS PER5_MFS, +COALESCE(Z.PER5_MIS,0) AS PER5_MIS, +COALESCE(Q.PER6_MCL,0) AS PER6_MCL, +COALESCE(Y.PER6_MFS,0) AS PER6_MFS, +COALESCE(W.PER6_MIS,0) AS PER6_MIS, +COALESCE(A1.PER7_MCL,0) AS PER7_MCL, +COALESCE(B1.PER7_MFS,0) AS PER7_MFS, +COALESCE(C1.PER7_MIS,0) AS PER7_MIS, +A.BEFORE_DUE_7,A.PER1,A.PER2,A.PER3,A.PER4,A.PER5,A.PER6,A.PER7, +CONCAT(A.DIVISION,'-',A.CLIENT_NUMBER) AS REF,"2" AS TYPE FROM +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER, +GROUP_CONCAT(DISTINCT CLIENT_INFO SEPARATOR '<br>') AS CLIENT_INFO, +GROUP_CONCAT(DISTINCT CLIENT_NAME SEPARATOR '<br>') AS CLIENT_NAME, +GROUP_CONCAT( DISTINCT `PHONE_NUMBER` SEPARATOR '<br>' ) AS PHONE_NUMBER , +GROUP_CONCAT( DISTINCT `ATTENTION_NAME` SEPARATOR '<br>' ) AS ATTENTION_NAME, +GROUP_CONCAT( DISTINCT `PAYMENT_TERM` SEPARATOR '<br>' ) AS PAYMENT_TERM, +CREDIT_LIMIT , +GROUP_CONCAT( `LAST_PAY_DATE` SEPARATOR '<br>' ) AS LAST_PAY_DATE, +SUM( `TOTAL`*EXCHANGE_RATE ) AS TOTAL, +SUM( `BEFORE_DUE_7`*EXCHANGE_RATE ) AS BEFORE_DUE_7, +SUM( `PER1`*EXCHANGE_RATE ) AS PER1, +SUM( `PER2`*EXCHANGE_RATE ) AS PER2, +SUM( `PER3`*EXCHANGE_RATE ) AS PER3, +SUM( `PER4`*EXCHANGE_RATE ) AS PER4, +SUM( `PER5`*EXCHANGE_RATE ) AS PER5, +SUM( `PER6`*EXCHANGE_RATE ) AS PER6, +SUM( `PER7`*EXCHANGE_RATE ) AS PER7 +FROM `t2` +WHERE REF IS NULL GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS A +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( `TOTAL`*EXCHANGE_RATE ) AS TOTAL_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS B ON A.CLIENT_NUMBER=B.CLIENT_NUMBER AND +A.DIVISION=B.DIVISION AND A.RECEIVABLE_GROUP=B.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=B.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( `TOTAL`*EXCHANGE_RATE ) AS TOTAL_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS C ON A.CLIENT_NUMBER=C.CLIENT_NUMBER +AND +A.DIVISION=C.DIVISION AND A.RECEIVABLE_GROUP=C.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=C.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( `TOTAL`*EXCHANGE_RATE ) AS TOTAL_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS D ON A.CLIENT_NUMBER=D.CLIENT_NUMBER AND +A.DIVISION=D.DIVISION AND A.RECEIVABLE_GROUP=D.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=D.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( BEFORE_DUE_7*EXCHANGE_RATE ) AS BEFORE_DUE_7_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS F ON A.CLIENT_NUMBER=F.CLIENT_NUMBER AND +A.DIVISION=F.DIVISION AND A.RECEIVABLE_GROUP=F.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=F.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( BEFORE_DUE_7*EXCHANGE_RATE ) AS BEFORE_DUE_7_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS G ON A.CLIENT_NUMBER=G.CLIENT_NUMBER AND +A.DIVISION=G.DIVISION AND A.RECEIVABLE_GROUP=G.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=G.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( BEFORE_DUE_7*EXCHANGE_RATE ) AS BEFORE_DUE_7_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS H ON A.CLIENT_NUMBER=H.CLIENT_NUMBER AND +A.DIVISION=H.DIVISION AND A.RECEIVABLE_GROUP=H.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=H.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER1*EXCHANGE_RATE ) AS PER1_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS I ON A.CLIENT_NUMBER=I.CLIENT_NUMBER AND +A.DIVISION=I.DIVISION AND A.RECEIVABLE_GROUP=I.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=I.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER1*EXCHANGE_RATE ) AS PER1_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS J ON A.CLIENT_NUMBER=J.CLIENT_NUMBER AND +A.DIVISION=J.DIVISION AND A.RECEIVABLE_GROUP=J.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=J.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER1*EXCHANGE_RATE ) AS PER1_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS K ON A.CLIENT_NUMBER=K.CLIENT_NUMBER AND +A.DIVISION=K.DIVISION AND A.RECEIVABLE_GROUP=K.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=K.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER2*EXCHANGE_RATE ) AS PER2_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS L ON A.CLIENT_NUMBER=L.CLIENT_NUMBER AND +A.DIVISION=L.DIVISION AND A.RECEIVABLE_GROUP=L.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=L.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER2*EXCHANGE_RATE ) AS PER2_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS M ON A.CLIENT_NUMBER=M.CLIENT_NUMBER AND +A.DIVISION=M.DIVISION AND A.RECEIVABLE_GROUP=M.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=M.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER2*EXCHANGE_RATE ) AS PER2_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS N ON A.CLIENT_NUMBER=N.CLIENT_NUMBER AND +A.DIVISION=N.DIVISION AND A.RECEIVABLE_GROUP=N.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=N.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER3*EXCHANGE_RATE ) AS PER3_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS O ON A.CLIENT_NUMBER=O.CLIENT_NUMBER AND +A.DIVISION=O.DIVISION AND A.RECEIVABLE_GROUP=O.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=O.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER3*EXCHANGE_RATE ) AS PER3_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS P ON A.CLIENT_NUMBER=P.CLIENT_NUMBER AND +A.DIVISION=P.DIVISION AND A.RECEIVABLE_GROUP=P.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=P.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER3*EXCHANGE_RATE ) AS PER3_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS R ON A.CLIENT_NUMBER=R.CLIENT_NUMBER AND +A.DIVISION=R.DIVISION AND A.RECEIVABLE_GROUP=R.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=R.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER4*EXCHANGE_RATE ) AS PER4_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS S ON A.CLIENT_NUMBER=S.CLIENT_NUMBER AND +A.DIVISION=S.DIVISION AND A.RECEIVABLE_GROUP=S.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=S.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER4*EXCHANGE_RATE ) AS PER4_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS T ON A.CLIENT_NUMBER=T.CLIENT_NUMBER AND +A.DIVISION=T.DIVISION AND A.RECEIVABLE_GROUP=T.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=T.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER4*EXCHANGE_RATE ) AS PER4_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS U ON A.CLIENT_NUMBER=U.CLIENT_NUMBER AND +A.DIVISION=U.DIVISION AND A.RECEIVABLE_GROUP=U.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=U.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER5*EXCHANGE_RATE ) AS PER5_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS V ON A.CLIENT_NUMBER=V.CLIENT_NUMBER AND +A.DIVISION=V.DIVISION AND A.RECEIVABLE_GROUP=V.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=V.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER5*EXCHANGE_RATE ) AS PER5_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS X ON A.CLIENT_NUMBER=X.CLIENT_NUMBER AND +A.DIVISION=X.DIVISION AND A.RECEIVABLE_GROUP=X.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=X.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER5*EXCHANGE_RATE ) AS PER5_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS Z ON A.CLIENT_NUMBER=Z.CLIENT_NUMBER AND +A.DIVISION=Z.DIVISION AND A.RECEIVABLE_GROUP=Z.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=Z.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER6*EXCHANGE_RATE ) AS PER6_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS Q ON A.CLIENT_NUMBER=Q.CLIENT_NUMBER AND +A.DIVISION=Q.DIVISION AND A.RECEIVABLE_GROUP=Q.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=Q.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER6*EXCHANGE_RATE ) AS PER6_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS Y ON A.CLIENT_NUMBER=Y.CLIENT_NUMBER AND +A.DIVISION=Y.DIVISION AND A.RECEIVABLE_GROUP=Y.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=Y.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER6*EXCHANGE_RATE ) AS PER6_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS W ON A.CLIENT_NUMBER=W.CLIENT_NUMBER AND +A.DIVISION=W.DIVISION AND A.RECEIVABLE_GROUP=W.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=W.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER7*EXCHANGE_RATE ) AS PER7_MCL +FROM `t2` +WHERE REF IS NULL AND DIVISION="MCL" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS A1 ON A.CLIENT_NUMBER=A1.CLIENT_NUMBER AND +A.DIVISION=A1.DIVISION AND A.RECEIVABLE_GROUP=A1.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=A1.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER7*EXCHANGE_RATE ) AS PER7_MFS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MFS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS B1 ON A.CLIENT_NUMBER=B1.CLIENT_NUMBER AND +A.DIVISION=B1.DIVISION AND A.RECEIVABLE_GROUP=B1.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=B1.CREDIT_LIMIT +LEFT JOIN +(SELECT RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT,SUM( PER7*EXCHANGE_RATE ) AS PER7_MIS +FROM `t2` +WHERE REF IS NULL AND DIVISION="MIS" GROUP BY RECEIVABLE_GROUP,DIVISION,CLIENT_NUMBER,CREDIT_LIMIT) AS C1 ON A.CLIENT_NUMBER=C1.CLIENT_NUMBER AND +A.DIVISION=C1.DIVISION AND A.RECEIVABLE_GROUP=C1.RECEIVABLE_GROUP AND A.CREDIT_LIMIT=C1.CREDIT_LIMIT +ORDER BY TOTAL DESC; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived3> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived4> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived5> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived6> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived7> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived8> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived9> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived10> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived11> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived12> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived13> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived14> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived15> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived16> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived17> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived18> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived19> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived20> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived21> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived22> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived23> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived24> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived25> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived26> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived27> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived28> system NULL NULL NULL NULL 0 Const row not found +1 PRIMARY <derived29> system NULL NULL NULL NULL 0 Const row not found +29 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +28 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +27 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +26 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +25 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +24 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +23 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +22 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +21 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +20 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +19 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +18 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +17 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +16 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +15 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +14 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +13 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +12 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +11 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +10 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +9 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +8 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +7 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +6 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +5 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +4 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +DROP TABLES t1,t2; +set optimizer_switch=@save_derived_optimizer_switch; +# +# MDEV-10663: Use of Inline table columns in HAVING clause +# throws 1463 Error +# +set @save_sql_mode = @@sql_mode; +set sql_mode='ONLY_FULL_GROUP_BY,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +CREATE TABLE `example1463` ( +`Customer` varchar(255) NOT NULL, +`DeliveryStatus` varchar(255) NOT NULL, +`OrderSize` int(11) NOT NULL +); +INSERT INTO example1463 VALUES ('Charlie', 'Success', 100); +INSERT INTO example1463 VALUES ('David', 'Success', 110); +INSERT INTO example1463 VALUES ('Charlie', 'Failed', 200); +INSERT INTO example1463 VALUES ('David', 'Success', 100); +INSERT INTO example1463 VALUES ('David', 'Unknown', 100); +INSERT INTO example1463 VALUES ('Edward', 'Success', 150); +INSERT INTO example1463 VALUES ('Edward', 'Pending', 150); +SELECT Customer, Success, SUM(OrderSize) +FROM (SELECT Customer, +CASE WHEN DeliveryStatus='Success' THEN 'Yes' ELSE 'No' END AS Success, +OrderSize +FROM example1463) as subQ +GROUP BY Success, Customer +WITH ROLLUP; +Customer Success SUM(OrderSize) +Charlie No 200 +David No 100 +Edward No 150 +NULL No 450 +Charlie Yes 100 +David Yes 210 +Edward Yes 150 +NULL Yes 460 +NULL NULL 910 +SELECT Customer, Success, SUM(OrderSize) +FROM (SELECT Customer, +CASE WHEN DeliveryStatus='Success' THEN 'Yes' ELSE 'No' END AS Success, +OrderSize +FROM example1463) as subQ +GROUP BY Success, Customer; +Customer Success SUM(OrderSize) +Charlie No 200 +David No 100 +Edward No 150 +Charlie Yes 100 +David Yes 210 +Edward Yes 150 +SELECT Customer, Success, SUM(OrderSize) +FROM (SELECT Customer, +CASE WHEN DeliveryStatus='Success' THEN 'Yes' ELSE 'No' END AS Success, +OrderSize +FROM example1463) as subQ +GROUP BY Success, Customer +HAVING Success IS NOT NULL; +Customer Success SUM(OrderSize) +Charlie No 200 +David No 100 +Edward No 150 +Charlie Yes 100 +David Yes 210 +Edward Yes 150 +DROP TABLE example1463; +set sql_mode= @save_sql_mode; +# +# MDEV-9028: SELECT DISTINCT constant column of derived table +# used as the second operand of LEFT JOIN +# +create table t1 (id int, data varchar(255)); +insert into t1 values (1,'yes'),(2,'yes'); +select distinct t1.id, tt.id, tt.data +from t1 +left join +(select t1.id, 'yes' as data from t1) as tt +on t1.id = tt.id; +id id data +1 1 yes +2 2 yes +select distinct t1.id, tt.id, tt.data +from t1 +left join +(select t1.id, 'yes' as data from t1 where id > 1) as tt +on t1.id = tt.id; +id id data +2 2 yes +1 NULL NULL +drop table t1; +# +# MDEV-14241: Server crash in key_copy / get_matching_chain_by_join_key +# or valgrind warnings +# +CREATE TABLE t1 (a VARCHAR(10)) ENGINE=MyISAM; +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v1 AS SELECT * FROM t1; +INSERT INTO t1 VALUES ('foo'),('bar'); +CREATE TABLE t2 (b integer auto_increment primary key) ENGINE=MyISAM; +INSERT INTO t2 VALUES (NULL),(NULL); +CREATE TABLE t3 (c VARCHAR(1024) CHARACTER SET utf8, d INT) ENGINE=MyISAM; +CREATE OR REPLACE ALGORITHM=TEMPTABLE VIEW v3 AS SELECT * FROM t3; +INSERT INTO t3 VALUES ('abc',NULL),('def',4); +SET join_cache_level= 8; +explain +SELECT * FROM v1, t2, v3 WHERE a = c AND b = d; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +1 PRIMARY <derived3> hash_ALL NULL #hash#$hj 3075 func 2 Using where; Using join buffer (flat, BNLH join) +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 v3.d 1 Using index +3 DERIVED t3 ALL NULL NULL NULL NULL 2 +2 DERIVED t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM v1, t2, v3 WHERE a = c AND b = d; +a b c d +DROP VIEW v1, v3; +DROP TABLE t1, t2, t3; +# +# MDEV-14786: Server crashes in Item_cond::transform on 2nd +# execution of SP querying from a view +# +create table t1 (i int, row_start timestamp(6) not null default now(), +row_end timestamp(6) not null default '2030-01-01 0:0:0'); +create view v1 as select i from t1 where i < 5 and (row_end = +TIMESTAMP'2030-01-01 0:0:0' or row_end is null); +create procedure pr(x int) select i from v1; +call pr(1); +i +call pr(2); +i +drop procedure pr; +drop view v1; +drop table t1; +# end of 5.5 +# +# Start of 10.1 tests +# +# +# MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin +# +CREATE TABLE t1 (a VARCHAR(10)); +INSERT INTO t1 VALUES ('a'),('A'); +SELECT * FROM t1 WHERE a='a' AND a <> _latin1'A' COLLATE latin1_bin; +a +a +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='a' AND a <> _latin1'A' COLLATE latin1_bin; +a +a +DROP TABLE t1; +CREATE TABLE t1 (a ENUM('5','6')); +INSERT INTO t1 VALUES ('5'),('6'); +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5'; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1; +a +5 +DROP TABLE t1; +# +# MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number2 +# +CREATE TABLE t1 (a ENUM('5','6')); +INSERT INTO t1 VALUES ('5'),('6'); +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5'; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1; +a +5 +SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1; +a +5 +DROP TABLE t1; +# +# End of 10.1 tests +# +# +# MDEV-10554: Assertion `!derived->first_select()-> +# exclude_from_table_unique_test || derived->outer_select()-> +# exclude_from_table_unique_test' +# failed in TABLE_LIST::set_check_merged() +# +CREATE TABLE t1 (f INT); +CREATE ALGORITHM = TEMPTABLE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 ) AS sq; +PREPARE stmt FROM 'SELECT * FROM v1'; +EXECUTE stmt; +f +EXECUTE stmt; +f +drop view v1; +drop table t1; +# +# MDEV-11363: Assertion `!derived->first_sel ect()->first_inner_unit() || +# derived->first_select()->first_inner_unit()->first_select()-> +# exclude_from_table_unique_test' failed in +# TABLE_LIST::set_check_materialized() +# +CREATE TABLE t1 (f1 INT); +CREATE TABLE t2 (f2 INT); +CREATE TABLE t3 (f3 INT); +CREATE VIEW v1 AS ( SELECT f1 AS f FROM t1 ) UNION ( SELECT f2 AS f FROM t2 ); +CREATE VIEW v2 AS SELECT f3 AS f FROM t3; +CREATE VIEW v3 AS SELECT f FROM ( SELECT f3 AS f FROM v1, t3 ) AS sq; +CREATE VIEW v4 AS SELECT COUNT(*) as f FROM v3; +REPLACE INTO v2 ( SELECT * FROM v4 ) UNION ( SELECT f FROM v2 ); +drop view v1,v2,v3,v4; +drop table t1,t2,t3; +# +# End of 10.2 tests +# diff --cc mysql-test/main/in_subq_cond_pushdown.result index 0000000,0000000..96f4f1f new file mode 100644 --- /dev/null +++ b/mysql-test/main/in_subq_cond_pushdown.result @@@ -1,0 -1,0 +1,3801 @@@ ++CREATE TABLE t1 (a INT, b INT, c INT, d INT); ++CREATE TABLE t2 (e INT, f INT, g INT); ++CREATE TABLE t3 (x INT, y INT); ++INSERT INTO t1 VALUES ++(1,1,18,1), (2,1,25,1), (1,3,40,1), (2,3,40,4), ++(4,2,24,4), (3,2,23,1), (1,2,40,2), (3,4,17,2), ++(5,5,65,1), (2,3,70,3), (1,4,35,3), (2,3,25,3), ++(2,2,40,4), (1,4,55,1), (5,3,72,4), (1,2,70,5); ++INSERT INTO t2 VALUES ++(1,2,38), (2,3,15), (1,3,40), (1,4,35), ++(2,2,70), (3,4,23), (5,5,12), (5,4,17), ++(3,3,17), (4,2,24), (2,5,25), (5,1,65); ++INSERT INTO t3 VALUES ++(1,25), (1,18), (2,15), (4,24), ++(1,35), (3,23), (3,17), (2,15); ++CREATE VIEW v1 AS ++( ++SELECT t3.x AS v1_x, t3.y AS v1_y FROM t3 WHERE t3.x<=3 ++); ++CREATE VIEW v2 AS ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.e ++HAVING max_g>25 ++); ++# conjunctive subformula : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.c<25 AND ++(t1.a,t1.c) IN (SELECT t2.e,MAX(t2.g) FROM t2 WHERE t2.e<5 GROUP BY t2.e); ++a b c d ++4 2 24 4 ++3 2 23 1 ++SELECT * FROM t1 ++WHERE t1.c<25 AND ++(t1.a,t1.c) IN (SELECT t2.e,MAX(t2.g) FROM t2 WHERE t2.e<5 GROUP BY t2.e); ++a b c d ++4 2 24 4 ++3 2 23 1 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.c<25 AND ++(t1.a,t1.c) IN (SELECT t2.e,MAX(t2.g) FROM t2 WHERE t2.e<5 GROUP BY t2.e); ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.c<25 AND ++(t1.a,t1.c) IN (SELECT t2.e,MAX(t2.g) FROM t2 WHERE t2.e<5 GROUP BY t2.e); ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c < 25 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` < 25", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted AND formula : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.c>55 AND t1.b<4 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE t1.c>55 AND t1.b<4 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.c>55 AND t1.b<4 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.c>55 AND t1.b<4 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c > 55 and t1.b < 4 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` > 55 and t2.f < 4", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted OR formula : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.c>60 OR t1.c<25) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++2 3 70 3 ++SELECT * FROM t1 ++WHERE (t1.c>60 OR t1.c<25) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.c>60 OR t1.c<25) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.c>60 OR t1.c<25) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.c > 60 or t1.c < 25) and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` > 60 or `MAX(t2.g)` < 25", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted AND-OR formula : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE ((t1.c>60 OR t1.c<25) AND t1.b>2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE ((t1.c>60 OR t1.c<25) AND t1.b>2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE ((t1.c>60 OR t1.c<25) AND t1.b>2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE ((t1.c>60 OR t1.c<25) AND t1.b>2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.c > 60 or t1.c < 25) and t1.b > 2 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "(`MAX(t2.g)` > 60 or `MAX(t2.g)` < 25) and t2.f > 2", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.d>3) AND t1.b>1) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++1 2 40 2 ++SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.d>3) AND t1.b>1) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++1 2 40 2 ++EXPLAIN SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.d>3) AND t1.b>1) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.d>3) AND t1.b>1) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.a < 2 or t1.d > 3) and t1.b > 1 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "t2.f > 1", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# using view IN subquery defINition : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.c>20 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++a b c d ++3 2 23 1 ++SELECT * FROM t1 ++WHERE t1.c>20 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++a b c d ++3 2 23 1 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.c>20 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.c>20 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c > 20 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["v1_x", "MAX(v1_y)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(v1_y)` > 20", ++ "temporary_table": { ++ "table": { ++ "table_name": "t3", ++ "access_type": "ALL", ++ "rows": 8, ++ "filtered": 100, ++ "attached_condition": "t3.x > 1 and t3.x <= 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# using equality : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1,v1 ++WHERE t1.c>20 AND t1.c=v1_y AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d v1_x v1_y ++3 2 23 1 3 23 ++SELECT * FROM t1,v1 ++WHERE t1.c>20 AND t1.c=v1_y AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d v1_x v1_y ++3 2 23 1 3 23 ++EXPLAIN SELECT * FROM t1,v1 ++WHERE t1.c>20 AND t1.c=v1_y AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t3 ALL NULL NULL NULL NULL 8 Using where ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where; Using join buffer (flat, BNL join) ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t3.y 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1,v1 ++WHERE t1.c>20 AND t1.c=v1_y AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t3", ++ "access_type": "ALL", ++ "rows": 8, ++ "filtered": 100, ++ "attached_condition": "t3.y > 20 and t3.x <= 3 and t3.y is not null" ++ }, ++ "block-nl-join": { ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100 ++ }, ++ "buffer_type": "flat", ++ "buffer_size": "256Kb", ++ "join_type": "BNL", ++ "attached_condition": "t1.c = t3.y and t1.a is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t3.y"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` > 20", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a<2 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++1 2 40 2 ++SELECT * FROM t1 ++WHERE t1.a<2 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++1 2 40 2 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a<2 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a<2 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a < 2 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e < 2" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted AND formula : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a>2 AND t1.a<5 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++3 2 23 1 ++SELECT * FROM t1 ++WHERE t1.a>2 AND t1.a<5 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++3 2 23 1 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a>2 AND t1.a<5 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a>2 AND t1.a<5 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 2 and t1.a < 5 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e > 2 and t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted OR formula : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.a<2 OR t1.a>=4) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++4 2 24 4 ++1 2 40 2 ++SELECT * FROM t1 ++WHERE (t1.a<2 OR t1.a>=4) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++4 2 24 4 ++1 2 40 2 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.a<2 OR t1.a>=4) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.a<2 OR t1.a>=4) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.a < 2 or t1.a >= 4) and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e >= 4)" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted AND-OR formula : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++1 4 35 3 ++SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++1 4 35 3 ++EXPLAIN SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.a < 2 or t1.a = 5) and t1.b > 3 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e = 5) and t2.f > 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# extracted AND-OR formula : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++1 4 35 3 ++SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++1 4 35 3 ++EXPLAIN SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.a < 2 or t1.a = 5) and t1.b > 3 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e = 5) and t2.f > 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.d>2) AND t1.a<2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 2 40 2 ++SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.d>2) AND t1.a<2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 2 40 2 ++EXPLAIN SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.d>2) AND t1.a<2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.d>2) AND t1.a<2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.b < 3 or t1.d > 2) and t1.a < 2 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e < 2" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# using equalities : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.d=1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++SELECT * FROM t1 ++WHERE t1.d=1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.d=1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 const,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.d=1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a = 1 and t1.d = 1 and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["const", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e = 1" ++ } ++ } ++ } ++ } ++ } ++} ++# using equality : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.d>1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++SELECT * FROM t1 ++WHERE t1.d>1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.d>1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.d>1 AND t1.a=t1.d AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.d = t1.a and t1.a > 1 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e > 1" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# using view IN subquery definition : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a<3 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++a b c d ++SELECT * FROM t1 ++WHERE t1.a<3 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++a b c d ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a<3 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t3 ALL NULL NULL NULL NULL 8 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a<3 AND ++(t1.a,t1.c) IN ++( ++SELECT v1_x,MAX(v1_y) ++FROM v1 ++WHERE v1_x>1 ++GROUP BY v1_x ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a < 3 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["v1_x", "MAX(v1_y)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t3", ++ "access_type": "ALL", ++ "rows": 8, ++ "filtered": 100, ++ "attached_condition": "t3.x > 1 and t3.x <= 3 and t3.x < 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# using equality : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1,v1 ++WHERE t1.a=v1_x AND v1_x<2 AND v1_y>30 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d v1_x v1_y ++1 3 40 1 1 35 ++1 2 40 2 1 35 ++SELECT * FROM t1,v1 ++WHERE t1.a=v1_x AND v1_x<2 AND v1_y>30 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d v1_x v1_y ++1 3 40 1 1 35 ++1 2 40 2 1 35 ++EXPLAIN SELECT * FROM t1,v1 ++WHERE t1.a=v1_x AND v1_x<2 AND v1_y>30 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t3 ALL NULL NULL NULL NULL 8 Using where ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where; Using join buffer (flat, BNL join) ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t3.x,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1,v1 ++WHERE t1.a=v1_x AND v1_x<2 AND v1_y>30 AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t3", ++ "access_type": "ALL", ++ "rows": 8, ++ "filtered": 100, ++ "attached_condition": "t3.x < 2 and t3.y > 30 and t3.x <= 3 and t3.x is not null" ++ }, ++ "block-nl-join": { ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100 ++ }, ++ "buffer_type": "flat", ++ "buffer_size": "256Kb", ++ "join_type": "BNL", ++ "attached_condition": "t1.a = t3.x and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t3.x", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e <= 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE ++# extracted OR formula : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.b=4) AND t1.a<3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 2 40 2 ++SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.b=4) AND t1.a<3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 2 40 2 ++EXPLAIN SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.b=4) AND t1.a<3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.b=4) AND t1.a<3) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "(t1.b < 3 or t1.b = 4) and t1.a < 3 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "t2.f < 3 or t2.f = 4", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e < 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using addition : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.a+t1.c>41) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE (t1.a+t1.c>41) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.a+t1.c>41) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.a+t1.c>41) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a + t1.c > 41 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "t2.e + `MAX(t2.g)` > 41", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using substitution : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.c-t1.a<35) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++3 2 23 1 ++SELECT * FROM t1 ++WHERE (t1.c-t1.a<35) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++4 2 24 4 ++3 2 23 1 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.c-t1.a<35) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.c-t1.a<35) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c - t1.a < 35 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` - t2.e < 35", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using multiplication : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.c*t1.a>100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE (t1.c*t1.a>100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.c*t1.a>100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.c*t1.a>100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c * t1.a > 100 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` * t2.e > 100", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using division : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.c/t1.a>30) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++1 2 40 2 ++2 3 70 3 ++SELECT * FROM t1 ++WHERE (t1.c/t1.a>30) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++1 2 40 2 ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.c/t1.a>30) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.c/t1.a>30) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c / t1.a > 30 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` / t2.e > 30", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using BETWEEN : pushing into HAVING ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.c BETWEEN 50 AND 100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE (t1.c BETWEEN 50 AND 100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.c BETWEEN 50 AND 100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.c BETWEEN 50 AND 100) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c between 50 and 100 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "`MAX(t2.g)` between 50 and 100", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using addition : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.a+t1.b > 5) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++4 2 24 4 ++SELECT * FROM t1 ++WHERE (t1.a+t1.b > 5) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++4 2 24 4 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.a+t1.b > 5) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.a+t1.b > 5) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a + t1.b > 5 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e + t2.f > 5" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using substitution : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.a-t1.b > 0) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++4 2 24 4 ++SELECT * FROM t1 ++WHERE (t1.a-t1.b > 0) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++4 2 24 4 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.a-t1.b > 0) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.a-t1.b > 0) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a - t1.b > 0 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e - t2.f > 0" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using multiplication : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.a*t1.b > 6) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++4 2 24 4 ++SELECT * FROM t1 ++WHERE (t1.a*t1.b > 6) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++4 2 24 4 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.a*t1.b > 6) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.a*t1.b > 6) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a * t1.b > 6 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e * t2.f > 6" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using division : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.b/t1.a > 2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++1 3 40 1 ++1 4 35 3 ++SELECT * FROM t1 ++WHERE (t1.b/t1.a > 2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++a b c d ++1 3 40 1 ++1 4 35 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.b/t1.a > 2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.b/t1.a > 2) AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e,t2.f ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.b / t1.a > 2 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.f / t2.e > 2" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula using BETWEEN : pushing into WHERE ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.a BETWEEN 1 AND 3) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++3 2 23 1 ++1 2 40 2 ++2 3 70 3 ++SELECT * FROM t1 ++WHERE (t1.a BETWEEN 1 AND 3) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++a b c d ++1 3 40 1 ++3 2 23 1 ++1 2 40 2 ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.a BETWEEN 1 AND 3) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.a BETWEEN 1 AND 3) AND ++(t1.a,t1.c) IN ++( ++SELECT t2.e,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a between 1 and 3 and t1.a is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["e", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.e between 1 and 3" ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into HAVING of the IN subquery ++# conjunctive subformula : pushing into WHERE of the view from the IN subquery ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.c>3 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++a b c d ++1 2 40 2 ++2 3 70 3 ++SELECT * FROM t1 ++WHERE t1.c>3 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++a b c d ++1 2 40 2 ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.c>3 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using temporary ++3 DERIVED t2 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.c>3 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.c > 3 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "MAX(v2.f)", "max_g"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "v2.max_g > 3", ++ "temporary_table": { ++ "table": { ++ "table_name": "<derived3>", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "v2.e < 5", ++ "materialized": { ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "max_g > 25", ++ "filesort": { ++ "sort_key": "t2.e", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100 ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE of the IN subquery ++# conjunctive subformula : pushing into WHERE of the view ++# from the IN subquery ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using temporary ++3 DERIVED t2 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "MAX(v2.f)", "max_g"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "<derived3>", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "v2.e < 5 and v2.e > 1", ++ "materialized": { ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "max_g > 25", ++ "filesort": { ++ "sort_key": "t2.e", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100 ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE and HAVING ++# of the IN subquery ++# conjunctive subformula : pushing into WHERE of the view ++# from the IN subquery ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a>1 AND t1.c<100 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++a b c d ++2 3 70 3 ++SELECT * FROM t1 ++WHERE t1.a>1 AND t1.c<100 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++a b c d ++2 3 70 3 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a>1 AND t1.c<100 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using temporary ++3 DERIVED t2 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a>1 AND t1.c<100 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT v2.e,MAX(v2.f),v2.max_g ++FROM v2 ++WHERE v2.e<5 ++GROUP BY v2.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.c < 100 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "MAX(v2.f)", "max_g"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "v2.max_g < 100", ++ "temporary_table": { ++ "table": { ++ "table_name": "<derived3>", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "v2.e < 5 and v2.e > 1", ++ "materialized": { ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "max_g > 25", ++ "filesort": { ++ "sort_key": "t2.e", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100 ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE of the IN subquery ++# extracted AND formula : pushing into HAVING of the derived table ++# from the IN subquery ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++a b c d ++2 3 40 4 ++SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++a b c d ++2 3 40 4 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using temporary ++3 DERIVED t2 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "MAX(d_tab.f)", "max_g"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "<derived3>", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "d_tab.e < 5 and d_tab.e > 1", ++ "materialized": { ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "max_g > 25", ++ "filesort": { ++ "sort_key": "t2.f", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100 ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into HAVING of the derived table ++# conjunctive subformula : pushing into WHERE of the IN subquery from ++# the derived table ++SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.e<5 ++GROUP BY t2.e ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x and d_tab.b>2; ++x y a b max_c ++2 15 2 3 70 ++2 15 2 3 70 ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++a b c d ++2 3 40 4 ++SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++a b c d ++2 3 40 4 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using temporary ++3 DERIVED t2 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "MAX(d_tab.f)", "max_g"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "<derived3>", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "d_tab.e < 5 and d_tab.e > 1", ++ "materialized": { ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "max_g > 25", ++ "filesort": { ++ "sort_key": "t2.f", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100 ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE of the derived table ++# extracted AND formula : pushing into WHERE of the IN subquery from ++# the derived table ++SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x and d_tab.a<5; ++x y a b max_c ++2 15 2 3 70 ++4 24 4 2 24 ++2 15 2 3 70 ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++a b c d ++2 3 40 4 ++SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++a b c d ++2 3 40 4 ++EXPLAIN SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++2 MATERIALIZED <derived3> ALL NULL NULL NULL NULL 12 Using where; Using temporary ++3 DERIVED t2 ALL NULL NULL NULL NULL 12 Using temporary; Using filesort ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++FROM ++( ++SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++FROM t2 ++GROUP BY t2.f ++HAVING max_g>25 ++) as d_tab ++WHERE d_tab.e<5 ++GROUP BY d_tab.e ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "MAX(d_tab.f)", "max_g"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "temporary_table": { ++ "table": { ++ "table_name": "<derived3>", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "d_tab.e < 5 and d_tab.e > 1", ++ "materialized": { ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "max_g > 25", ++ "filesort": { ++ "sort_key": "t2.f", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100 ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE and HAVING ++# of the derived table ++# extracted AND formula : pushing into WHERE of the IN subquery ++# from the derived table ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++x y a b max_c ++4 24 4 2 24 ++SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++x y a b max_c ++4 24 4 2 24 ++EXPLAIN SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t3 ALL NULL NULL NULL NULL 8 Using where ++1 PRIMARY <derived2> ref key0 key0 5 test.t3.x 2 Using where ++2 DERIVED t1 ALL NULL NULL NULL NULL 16 Using where; Using temporary; Using filesort ++2 DERIVED <subquery3> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++3 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t3", ++ "access_type": "ALL", ++ "rows": 8, ++ "filtered": 100, ++ "attached_condition": "t3.x < 5 and t3.x is not null" ++ }, ++ "table": { ++ "table_name": "<derived2>", ++ "access_type": "ref", ++ "possible_keys": ["key0"], ++ "key": "key0", ++ "key_length": "5", ++ "used_key_parts": ["a"], ++ "ref": ["test.t3.x"], ++ "rows": 2, ++ "filtered": 100, ++ "attached_condition": "d_tab.max_c < 70", ++ "materialized": { ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "max_c < 70", ++ "filesort": { ++ "sort_key": "t1.a", ++ "temporary_table": { ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.a < 5 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery3>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "t2.f < 5", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e > 1 and t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE of the derived table ++# conjunctive subformula : pushing into HAVING of the IN subquery from ++# the derived table ++SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE (t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++WHERE t2.f<4 ++GROUP BY t2.f ++) ++GROUP BY t1.a ++HAVING t1.b<5 ++) AS d_tab ++WHERE d_tab.a=t3.x and d_tab.a<5; ++x y a b max_c ++1 25 1 2 70 ++1 18 1 2 70 ++2 15 2 3 40 ++1 35 1 2 70 ++2 15 2 3 40 ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++x y a b max_c ++4 24 4 2 24 ++SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++x y a b max_c ++4 24 4 2 24 ++EXPLAIN SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t3 ALL NULL NULL NULL NULL 8 Using where ++1 PRIMARY <derived2> ref key0 key0 5 test.t3.x 2 Using where ++2 DERIVED t1 ALL NULL NULL NULL NULL 16 Using where; Using temporary; Using filesort ++2 DERIVED <subquery3> eq_ref distinct_key distinct_key 12 test.t1.a,test.t1.b,test.t1.c 1 ++3 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * ++FROM t3, ++( ++SELECT t1.a,t1.b,max(t1.c) as max_c ++FROM t1 ++WHERE t1.a>1 AND ++(t1.a,t1.b,t1.c) IN ++( ++SELECT t2.e,t2.f,MAX(t2.g) ++FROM t2 ++GROUP BY t2.e ++HAVING t2.f<5 ++) ++GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t3", ++ "access_type": "ALL", ++ "rows": 8, ++ "filtered": 100, ++ "attached_condition": "t3.x < 5 and t3.x is not null" ++ }, ++ "table": { ++ "table_name": "<derived2>", ++ "access_type": "ref", ++ "possible_keys": ["key0"], ++ "key": "key0", ++ "key_length": "5", ++ "used_key_parts": ["a"], ++ "ref": ["test.t3.x"], ++ "rows": 2, ++ "filtered": 100, ++ "attached_condition": "d_tab.max_c < 70", ++ "materialized": { ++ "query_block": { ++ "select_id": 2, ++ "having_condition": "max_c < 70", ++ "filesort": { ++ "sort_key": "t1.a", ++ "temporary_table": { ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.a > 1 and t1.a < 5 and t1.a is not null and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery3>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["e", "f", "MAX(t2.g)"], ++ "ref": ["test.t1.a", "test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 3, ++ "having_condition": "t2.f < 5", ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e > 1 and t2.e < 5" ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE ++# using WINDOW FUNCTIONS : using MAX function ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, MAX(t2.g) OVER (PARTITION BY t2.f) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++a b c d ++1 3 40 1 ++2 3 40 4 ++1 4 35 3 ++1 2 70 5 ++SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, MAX(t2.g) OVER (PARTITION BY t2.f) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++a b c d ++1 3 40 1 ++2 3 40 4 ++1 4 35 3 ++1 2 70 5 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, MAX(t2.g) OVER (PARTITION BY t2.f) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.b,test.t1.c 1 ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, MAX(t2.g) OVER (PARTITION BY t2.f) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.b > 1 and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "8", ++ "used_key_parts": ["f", "MAX(t2.g) OVER (PARTITION BY t2.f)"], ++ "ref": ["test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "window_functions_computation": { ++ "sorts": { ++ "filesort": { ++ "sort_key": "t2.f" ++ } ++ }, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.f > 1" ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++# conjunctive subformula : pushing into WHERE ++# using WINDOW FUNCTIONS : using SUM function ++SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++a b c d ++5 3 72 4 ++SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++a b c d ++5 3 72 4 ++EXPLAIN SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++id select_type table type possible_keys key key_len ref rows Extra ++1 PRIMARY t1 ALL NULL NULL NULL NULL 16 Using where ++1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 12 test.t1.b,test.t1.c 1 Using where ++2 MATERIALIZED t2 ALL NULL NULL NULL NULL 12 Using where; Using temporary ++EXPLAIN FORMAT=JSON SELECT * FROM t1 ++WHERE (t1.b>1) AND ++(t1.b, t1.c) IN ++( ++SELECT t2.f, CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT) ++FROM t2 ++WHERE t2.e<5 ++) ++; ++EXPLAIN ++{ ++ "query_block": { ++ "select_id": 1, ++ "table": { ++ "table_name": "t1", ++ "access_type": "ALL", ++ "rows": 16, ++ "filtered": 100, ++ "attached_condition": "t1.b > 1 and t1.b is not null and t1.c is not null" ++ }, ++ "table": { ++ "table_name": "<subquery2>", ++ "access_type": "eq_ref", ++ "possible_keys": ["distinct_key"], ++ "key": "distinct_key", ++ "key_length": "12", ++ "used_key_parts": ["f", "CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT)"], ++ "ref": ["test.t1.b", "test.t1.c"], ++ "rows": 1, ++ "filtered": 100, ++ "attached_condition": "t1.c = `<subquery2>`.`CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT)`", ++ "materialized": { ++ "unique": 1, ++ "query_block": { ++ "select_id": 2, ++ "window_functions_computation": { ++ "sorts": { ++ "filesort": { ++ "sort_key": "t2.f" ++ } ++ }, ++ "temporary_table": { ++ "table": { ++ "table_name": "t2", ++ "access_type": "ALL", ++ "rows": 12, ++ "filtered": 100, ++ "attached_condition": "t2.e < 5 and t2.f > 1" ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++DROP TABLE t1,t2,t3; ++DROP VIEW v1,v2; diff --cc mysql-test/main/in_subq_cond_pushdown.test index 0000000,0000000..af2ea0f new file mode 100644 --- /dev/null +++ b/mysql-test/main/in_subq_cond_pushdown.test @@@ -1,0 -1,0 +1,759 @@@ ++LET $no_pushdown= ++ SET STATEMENT optimizer_switch='condition_pushdown_for_subquery=off' FOR; ++ ++CREATE TABLE t1 (a INT, b INT, c INT, d INT); ++CREATE TABLE t2 (e INT, f INT, g INT); ++CREATE TABLE t3 (x INT, y INT); ++ ++INSERT INTO t1 VALUES ++(1,1,18,1), (2,1,25,1), (1,3,40,1), (2,3,40,4), ++(4,2,24,4), (3,2,23,1), (1,2,40,2), (3,4,17,2), ++(5,5,65,1), (2,3,70,3), (1,4,35,3), (2,3,25,3), ++(2,2,40,4), (1,4,55,1), (5,3,72,4), (1,2,70,5); ++ ++INSERT INTO t2 VALUES ++(1,2,38), (2,3,15), (1,3,40), (1,4,35), ++(2,2,70), (3,4,23), (5,5,12), (5,4,17), ++(3,3,17), (4,2,24), (2,5,25), (5,1,65); ++ ++INSERT INTO t3 VALUES ++(1,25), (1,18), (2,15), (4,24), ++(1,35), (3,23), (3,17), (2,15); ++ ++CREATE VIEW v1 AS ++( ++ SELECT t3.x AS v1_x, t3.y AS v1_y FROM t3 WHERE t3.x<=3 ++); ++ ++CREATE VIEW v2 AS ++( ++ SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++ FROM t2 ++ GROUP BY t2.e ++ HAVING max_g>25 ++); ++ ++--echo # conjunctive subformula : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE t1.c<25 AND ++ (t1.a,t1.c) IN (SELECT t2.e,MAX(t2.g) FROM t2 WHERE t2.e<5 GROUP BY t2.e); ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted AND formula : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE t1.c>55 AND t1.b<4 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted OR formula : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.c>60 OR t1.c<25) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted AND-OR formula : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE ((t1.c>60 OR t1.c<25) AND t1.b>2) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.d>3) AND t1.b>1) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # using view IN subquery defINition : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE t1.c>20 AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT v1_x,MAX(v1_y) ++ FROM v1 ++ WHERE v1_x>1 ++ GROUP BY v1_x ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # using equality : pushing into WHERE ++LET $query= ++SELECT * FROM t1,v1 ++WHERE t1.c>20 AND t1.c=v1_y AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE t1.a<2 AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted AND formula : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE t1.a>2 AND t1.a<5 AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted OR formula : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.a<2 OR t1.a>=4) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted AND-OR formula : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e,t2.f ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # extracted AND-OR formula : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE ((t1.a<2 OR t1.a=5) AND t1.b>3) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e,t2.f ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.d>2) AND t1.a<2) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # using equalities : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE t1.d=1 AND t1.a=t1.d AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # using equality : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE t1.d>1 AND t1.a=t1.d AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # using view IN subquery definition : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE t1.a<3 AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT v1_x,MAX(v1_y) ++ FROM v1 ++ WHERE v1_x>1 ++ GROUP BY v1_x ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # using equality : pushing into WHERE ++LET $query= ++SELECT * FROM t1,v1 ++WHERE t1.a=v1_x AND v1_x<2 AND v1_y>30 AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE ++--echo # extracted OR formula : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE ((t1.b<3 OR t1.b=4) AND t1.a<3) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using addition : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.a+t1.c>41) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using substitution : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.c-t1.a<35) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using multiplication : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.c*t1.a>100) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using division : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.c/t1.a>30) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using BETWEEN : pushing into HAVING ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.c BETWEEN 50 AND 100) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using addition : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.a+t1.b > 5) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e,t2.f ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using substitution : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.a-t1.b > 0) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e,t2.f ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using multiplication : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.a*t1.b > 6) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e,t2.f ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using division : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.b/t1.a > 2) AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e,t2.f ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula using BETWEEN : pushing into WHERE ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.a BETWEEN 1 AND 3) AND ++ (t1.a,t1.c) IN ++ ( ++ SELECT t2.e,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into HAVING of the IN subquery ++--echo # conjunctive subformula : pushing into WHERE of the view from the IN subquery ++LET $query= ++SELECT * FROM t1 ++WHERE t1.c>3 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT v2.e,MAX(v2.f),v2.max_g ++ FROM v2 ++ WHERE v2.e<5 ++ GROUP BY v2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE of the IN subquery ++--echo # conjunctive subformula : pushing into WHERE of the view ++--echo # from the IN subquery ++LET $query= ++SELECT * FROM t1 ++WHERE t1.a>1 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT v2.e,MAX(v2.f),v2.max_g ++ FROM v2 ++ WHERE v2.e<5 ++ GROUP BY v2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE and HAVING ++--echo # of the IN subquery ++--echo # conjunctive subformula : pushing into WHERE of the view ++--echo # from the IN subquery ++LET $query= ++SELECT * FROM t1 ++WHERE t1.a>1 AND t1.c<100 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT v2.e,MAX(v2.f),v2.max_g ++ FROM v2 ++ WHERE v2.e<5 ++ GROUP BY v2.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE of the IN subquery ++--echo # extracted AND formula : pushing into HAVING of the derived table ++--echo # from the IN subquery ++LET $query= ++SELECT * FROM t1 ++WHERE t1.a>1 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT d_tab.e,MAX(d_tab.f),d_tab.max_g ++ FROM ++ ( ++ SELECT t2.e, t2.f, MAX(t2.g) AS max_g ++ FROM t2 ++ GROUP BY t2.f ++ HAVING max_g>25 ++ ) as d_tab ++ WHERE d_tab.e<5 ++ GROUP BY d_tab.e ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into HAVING of the derived table ++--echo # conjunctive subformula : pushing into WHERE of the IN subquery from ++--echo # the derived table ++SELECT * ++FROM t3, ++( ++ SELECT t1.a,t1.b,max(t1.c) as max_c ++ FROM t1 ++ WHERE t1.a>1 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.e<5 ++ GROUP BY t2.e ++ ) ++ GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x and d_tab.b>2; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE of the derived table ++--echo # extracted AND formula : pushing into WHERE of the IN subquery from ++--echo # the derived table ++SELECT * ++FROM t3, ++( ++ SELECT t1.a,t1.b,max(t1.c) as max_c ++ FROM t1 ++ WHERE t1.a>1 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ GROUP BY t2.e ++ HAVING t2.f<5 ++ ) ++ GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x and d_tab.a<5; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE and HAVING ++--echo # of the derived table ++--echo # extracted AND formula : pushing into WHERE of the IN subquery ++--echo # from the derived table ++LET $query= ++SELECT * ++FROM t3, ++( ++ SELECT t1.a,t1.b,max(t1.c) as max_c ++ FROM t1 ++ WHERE t1.a>1 AND ++ (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ GROUP BY t2.e ++ HAVING t2.f<5 ++ ) ++ GROUP BY t1.a ++) AS d_tab ++WHERE d_tab.a=t3.x AND d_tab.a<5 AND d_tab.max_c<70; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE of the derived table ++--echo # conjunctive subformula : pushing into HAVING of the IN subquery from ++--echo # the derived table ++SELECT * ++FROM t3, ++( ++ SELECT t1.a,t1.b,max(t1.c) as max_c ++ FROM t1 ++ WHERE (t1.a,t1.b,t1.c) IN ++ ( ++ SELECT t2.e,t2.f,MAX(t2.g) ++ FROM t2 ++ WHERE t2.f<4 ++ GROUP BY t2.f ++ ) ++ GROUP BY t1.a ++ HAVING t1.b<5 ++) AS d_tab ++WHERE d_tab.a=t3.x and d_tab.a<5; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE ++--echo # using WINDOW FUNCTIONS : using MAX function ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.b>1) AND ++ (t1.b, t1.c) IN ++ ( ++ SELECT t2.f, MAX(t2.g) OVER (PARTITION BY t2.f) ++ FROM t2 ++ WHERE t2.e<5 ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++--echo # conjunctive subformula : pushing into WHERE ++--echo # using WINDOW FUNCTIONS : using SUM function ++LET $query= ++SELECT * FROM t1 ++WHERE (t1.b>1) AND ++ (t1.b, t1.c) IN ++ ( ++ SELECT t2.f, CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT) ++ FROM t2 ++ WHERE t2.e<5 ++ ) ++; ++ ++EVAL $no_pushdown $query; ++EVAL $query; ++EVAL EXPLAIN $query; ++EVAL EXPLAIN FORMAT=JSON $query; ++ ++DROP TABLE t1,t2,t3; ++DROP VIEW v1,v2; diff --cc mysql-test/main/mysqld--help.result index 356546a,0000000..052e535 mode 100644,000000..100644 --- a/mysql-test/main/mysqld--help.result +++ b/mysql-test/main/mysqld--help.result @@@ -1,1689 -1,0 +1,1690 @@@ +Windows bug: happens when a new line is exactly at the right offset. +The following options may be given as the first argument: +--print-defaults Print the program argument list and exit. +--no-defaults Don't read default options from any option file. +The following specify which files/extra groups are read (specified before remaining options): +--defaults-file=# Only read default options from the given file #. +--defaults-extra-file=# Read this file after the global files are read. +--defaults-group-suffix=# Additionally read default groups with # appended as a suffix. + + --allow-suspicious-udfs + Allows use of UDFs consisting of only one symbol xxx() + without corresponding xxx_init() or xxx_deinit(). That + also means that one can load any function from any + library, for example exit() from libc.so + -a, --ansi Use ANSI SQL syntax instead of MySQL syntax. This mode + will also set transaction isolation level 'serializable'. + --auto-increment-increment[=#] + Auto-increment columns are incremented by this + --auto-increment-offset[=#] + Offset added to Auto-increment columns. Used when + auto-increment-increment != 1 + --autocommit Set default value for autocommit (0 or 1) + (Defaults to on; use --skip-autocommit to disable.) + --automatic-sp-privileges + Creating and dropping stored procedures alters ACLs + (Defaults to on; use --skip-automatic-sp-privileges to disable.) + --back-log=# The number of outstanding connection requests MariaDB can + have. This comes into play when the main MariaDB thread + gets very many connection requests in a very short time + (Automatically configured unless set explicitly) + -b, --basedir=name Path to installation directory. All paths are usually + resolved relative to this + --big-tables Old variable, which if set to 1, allows large result sets + by saving all temporary sets to disk, avoiding 'table + full' errors. No longer needed, as the server now handles + this automatically. sql_big_tables is a synonym. + --bind-address=name IP address to bind to. + --binlog-annotate-row-events + Tells the master to annotate RBR events with the + statement that caused these events + (Defaults to on; use --skip-binlog-annotate-row-events to disable.) + --binlog-cache-size=# + The size of the transactional cache for updates to + transactional engines for the binary log. If you often + use transactions containing many statements, you can + increase this to get more performance + --binlog-checksum=name + Type of BINLOG_CHECKSUM_ALG. Include checksum for log + events in the binary log. One of: NONE, CRC32 + --binlog-commit-wait-count=# + If non-zero, binlog write will wait at most + binlog_commit_wait_usec microseconds for at least this + many commits to queue up for group commit to the binlog. + This can reduce I/O on the binlog and provide increased + opportunity for parallel apply on the slave, but too high + a value will decrease commit throughput. + --binlog-commit-wait-usec=# + Maximum time, in microseconds, to wait for more commits + to queue up for binlog group commit. Only takes effect if + the value of binlog_commit_wait_count is non-zero. + --binlog-direct-non-transactional-updates + Causes updates to non-transactional engines using + statement format to be written directly to binary log. + Before using this option make sure that there are no + dependencies between transactional and non-transactional + tables such as in the statement INSERT INTO t_myisam + SELECT * FROM t_innodb; otherwise, slaves may diverge + from the master. + --binlog-do-db=name Tells the master it should log updates for the specified + database, and exclude all others not explicitly + mentioned. + --binlog-file-cache-size=# + The size of file cache for the binary log + --binlog-format=name + What form of binary logging the master will use: either + ROW for row-based binary logging, STATEMENT for + statement-based binary logging, or MIXED. MIXED is + statement-based binary logging except for those + statements where only row-based is correct: those which + involve user-defined functions (i.e. UDFs) or the UUID() + function; for those, row-based binary logging is + automatically used. + --binlog-ignore-db=name + Tells the master that updates to the given database + should not be logged to the binary log. + --binlog-optimize-thread-scheduling + Run fast part of group commit in a single thread, to + optimize kernel thread scheduling. On by default. Disable + to run each transaction in group commit in its own + thread, which can be slower at very high concurrency. + This option is mostly for testing one algorithm versus + the other, and it should not normally be necessary to + change it. + (Defaults to on; use --skip-binlog-optimize-thread-scheduling to disable.) + --binlog-row-event-max-size=# + The maximum size of a row-based binary log event in + bytes. Rows will be grouped into events smaller than this + size if possible. The value has to be a multiple of 256. + --binlog-row-image=name + Controls whether rows should be logged in 'FULL', + 'NOBLOB' or 'MINIMAL' formats. 'FULL', means that all + columns in the before and after image are logged. + 'NOBLOB', means that mysqld avoids logging blob columns + whenever possible (eg, blob column was not changed or is + not part of primary key). 'MINIMAL', means that a PK + equivalent (PK columns or full row if there is no PK in + the table) is logged in the before image, and only + changed columns are logged in the after image. (Default: + FULL). + --binlog-stmt-cache-size=# + The size of the statement cache for updates to + non-transactional engines for the binary log. If you + often use statements updating a great number of rows, you + can increase this to get more performance. + --bootstrap Used by mysql installation scripts. + --bulk-insert-buffer-size=# + Size of tree cache used in bulk insert optimisation. Note + that this is a limit per thread! + --character-set-client-handshake + Don't ignore client side character set value sent during + handshake. + (Defaults to on; use --skip-character-set-client-handshake to disable.) + --character-set-filesystem=name + Set the filesystem character set. + -C, --character-set-server=name + Set the default character set. + --character-sets-dir=name + Directory where character sets are + -r, --chroot=name Chroot mysqld daemon during startup. + --collation-server=name + Set the default collation. + --column-compression-threshold=# + Minimum column data length eligible for compression + --column-compression-zlib-level=# + zlib compression level (1 gives best speed, 9 gives best + compression) + --column-compression-zlib-strategy=name + The strategy parameter is used to tune the compression + algorithm. Use the value DEFAULT_STRATEGY for normal + data, FILTERED for data produced by a filter (or + predictor), HUFFMAN_ONLY to force Huffman encoding only + (no string match), or RLE to limit match distances to one + (run-length encoding). Filtered data consists mostly of + small values with a somewhat random distribution. In this + case, the compression algorithm is tuned to compress them + better. The effect of FILTERED is to force more Huffman + coding and less string matching; it is somewhat + intermediate between DEFAULT_STRATEGY and HUFFMAN_ONLY. + RLE is designed to be almost as fast as HUFFMAN_ONLY, but + give better compression for PNG image data. The strategy + parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not + set appropriately. FIXED prevents the use of dynamic + Huffman codes, allowing for a simpler decoder for special + applications. + --column-compression-zlib-wrap + Generate zlib header and trailer and compute adler32 + check value. It can be used with storage engines that + don't provide data integrity verification to detect data + corruption. + --completion-type=name + The transaction completion type. One of: NO_CHAIN, CHAIN, + RELEASE + --concurrent-insert[=name] + Use concurrent insert with MyISAM. One of: NEVER, AUTO, + ALWAYS + --console Write error output on screen; don't remove the console + window on windows. + --core-file Write core on errors. + -h, --datadir=name Path to the database root directory + --date-format=name The DATE format (ignored) + --datetime-format=name + The DATETIME format (ignored) + --deadlock-search-depth-long=# + Long search depth for the two-step deadlock detection + --deadlock-search-depth-short=# + Short search depth for the two-step deadlock detection + --deadlock-timeout-long=# + Long timeout for the two-step deadlock detection (in + microseconds) + --deadlock-timeout-short=# + Short timeout for the two-step deadlock detection (in + microseconds) + --default-regex-flags=name + Default flags for the regex library. Any combination of: + DOTALL, DUPNAMES, EXTENDED, EXTRA, MULTILINE, UNGREEDY + --default-storage-engine=name + The default storage engine for new tables + --default-time-zone=name + Set the default time zone. + --default-tmp-storage-engine=name + The default storage engine for user-created temporary + tables + --default-week-format=# + The default week format used by WEEK() functions + --delay-key-write[=name] + Specifies how MyISAM tables handles CREATE TABLE + DELAY_KEY_WRITE. If set to ON, the default, any DELAY KEY + WRITEs are honored. The key buffer is then flushed only + when the table closes, speeding up writes. MyISAM tables + should be automatically checked upon startup in this + case, and --external locking should not be used, as it + can lead to index corruption. If set to OFF, DELAY KEY + WRITEs are ignored, while if set to ALL, all new opened + tables are treated as if created with DELAY KEY WRITEs + enabled. + --delayed-insert-limit=# + After inserting delayed_insert_limit rows, the INSERT + DELAYED handler will check if there are any SELECT + statements pending. If so, it allows these to execute + before continuing. + --delayed-insert-timeout=# + How long a INSERT DELAYED thread should wait for INSERT + statements before terminating + --delayed-queue-size=# + What size queue (in rows) should be allocated for + handling INSERT DELAYED. If the queue becomes full, any + client that does INSERT DELAYED will wait until there is + room in the queue again + --div-precision-increment=# + Precision of the result of '/' operator will be increased + on that value + --encrypt-binlog Encrypt binary logs (including relay logs) + --encrypt-tmp-disk-tables + Encrypt temporary on-disk tables (created as part of + query execution) + --encrypt-tmp-files Encrypt temporary files (created for filesort, binary log + cache, etc) + --enforce-storage-engine=name + Force the use of a storage engine for new tables + --event-scheduler[=name] + Enable the event scheduler. Possible values are ON, OFF, + and DISABLED (keep the event scheduler completely + deactivated, it cannot be activated run-time) + --expensive-subquery-limit=# + The maximum number of rows a subquery may examine in + order to be executed during optimization and used for + constant optimization + --expire-logs-days=# + If non-zero, binary logs will be purged after + expire_logs_days days; possible purges happen at startup + and at binary log rotation + --explicit-defaults-for-timestamp + This option causes CREATE TABLE to create all TIMESTAMP + columns as NULL with DEFAULT NULL attribute, Without this + option, TIMESTAMP columns are NOT NULL and have implicit + DEFAULT clauses. + --external-locking Use system (external) locking (disabled by default). + With this option enabled you can run myisamchk to test + (not repair) tables while the MySQL server is running. + Disable with --skip-external-locking. + --extra-max-connections=# + The number of connections on extra-port + --extra-port=# Extra port number to use for tcp connections in a + one-thread-per-connection manner. 0 means don't use + another port + --flashback Setup the server to use flashback. This enables binary + log in row mode and will enable extra logging for DDL's + needed by flashback feature + --flush Flush MyISAM tables to disk between SQL commands + --flush-time=# A dedicated thread is created to flush all tables at the + given interval + --ft-boolean-syntax=name + List of operators for MATCH ... AGAINST ( ... IN BOOLEAN + MODE) + --ft-max-word-len=# The maximum length of the word to be included in a + FULLTEXT index. Note: FULLTEXT indexes must be rebuilt + after changing this variable + --ft-min-word-len=# The minimum length of the word to be included in a + FULLTEXT index. Note: FULLTEXT indexes must be rebuilt + after changing this variable + --ft-query-expansion-limit=# + Number of best matches to use for query expansion + --ft-stopword-file=name + Use stopwords from this file instead of built-in list + --gdb Set up signals usable for debugging. Deprecated, use + --general-log Log connections and queries to a table or log file. + Defaults logging to a file 'hostname'.log or a table + mysql.general_logif --log-output=TABLE is used. + --general-log-file=name + Log connections and queries to given file + --getopt-prefix-matching + Recognize command-line options by their unambiguos + prefixes. + (Defaults to on; use --skip-getopt-prefix-matching to disable.) + --group-concat-max-len=# + The maximum length of the result of function + GROUP_CONCAT() + --gtid-domain-id=# Used with global transaction ID to identify logically + independent replication streams. When events can + propagate through multiple parallel paths (for example + multiple masters), each independent source server must + use a distinct domain_id. For simple tree-shaped + replication topologies, it can be left at its default, 0. + --gtid-ignore-duplicates + When set, different master connections in multi-source + replication are allowed to receive and process event + groups with the same GTID (when using GTID mode). Only + one will be applied, any others will be ignored. Within a + given replication domain, just the sequence number will + be used to decide whether a given GTID has been already + applied; this means it is the responsibility of the user + to ensure that GTID sequence numbers are strictly + increasing. + --gtid-pos-auto-engines=name + List of engines for which to automatically create a + mysql.gtid_slave_pos_ENGINE table, if a transaction using + that engine is replicated. This can be used to avoid + introducing cross-engine transactions, if engines are + used different from that used by table + mysql.gtid_slave_pos + --gtid-strict-mode Enforce strict seq_no ordering of events in the binary + log. Slave stops with an error if it encounters an event + that would cause it to generate an out-of-order binlog if + executed. + -?, --help Display this help and exit. + --histogram-size=# Number of bytes used for a histogram. If set to 0, no + histograms are created by ANALYZE. + --histogram-type=name + Specifies type of the histograms created by ANALYZE. + Possible values are: SINGLE_PREC_HB - single precision + height-balanced, DOUBLE_PREC_HB - double precision + height-balanced. + --host-cache-size=# How many host names should be cached to avoid resolving. + (Automatically configured unless set explicitly) + --idle-readonly-transaction-timeout=# + The number of seconds the server waits for read-only idle + transaction + --idle-transaction-timeout=# + The number of seconds the server waits for idle + transaction + --idle-write-transaction-timeout=# + The number of seconds the server waits for write idle + transaction + --ignore-builtin-innodb + Disable initialization of builtin InnoDB plugin + --ignore-db-dirs=name + Specifies a directory to add to the ignore list when + collecting database names from the datadir. Put a blank + argument to reset the list accumulated so far. + --init-connect=name Command(s) that are executed for each new connection + (unless the user has SUPER privilege) + --init-file=name Read SQL commands from this file at startup + --init-rpl-role=name + Set the replication role. One of: MASTER, SLAVE + --init-slave=name Command(s) that are executed by a slave server each time + the SQL thread starts + --interactive-timeout=# + The number of seconds the server waits for activity on an + interactive connection before closing it + --join-buffer-size=# + The size of the buffer that is used for joins + --join-buffer-space-limit=# + The limit of the space for all join buffers used by a + query + --join-cache-level=# + Controls what join operations can be executed with join + buffers. Odd numbers are used for plain join buffers + while even numbers are used for linked buffers + --keep-files-on-create + Don't overwrite stale .MYD and .MYI even if no directory + is specified + --key-buffer-size=# The size of the buffer used for index blocks for MyISAM + tables. Increase this to get better index handling (for + all reads and multiple writes) to as much as you can + afford + --key-cache-age-threshold=# + This characterizes the number of hits a hot block has to + be untouched until it is considered aged enough to be + downgraded to a warm block. This specifies the percentage + ratio of that number of hits to the total number of + blocks in key cache + --key-cache-block-size=# + The default size of key cache blocks + --key-cache-division-limit=# + The minimum percentage of warm blocks in key cache + --key-cache-file-hash-size=# + Number of hash buckets for open and changed files. If + you have a lot of MyISAM files open you should increase + this for faster flush of changes. A good value is + probably 1/10 of number of possible open MyISAM files. + --key-cache-segments=# + The number of segments in a key cache + -L, --language=name Client error messages in given language. May be given as + a full path. Deprecated. Use --lc-messages-dir instead. + --large-pages Enable support for large pages + --lc-messages=name Set the language used for the error messages. + -L, --lc-messages-dir=name + Directory where error messages are + --lc-time-names=name + Set the language used for the month names and the days of + the week. + --local-infile Enable LOAD DATA LOCAL INFILE + (Defaults to on; use --skip-local-infile to disable.) + --lock-wait-timeout=# + Timeout in seconds to wait for a lock before returning an + error. + --log-basename=name Basename for all log files and the .pid file. This sets + all log file names at once (in 'datadir') and is normally + the only option you need for specifying log files. Sets + names for --log-bin, --log-bin-index, --relay-log, + --relay-log-index, --general-log-file, + --log-slow-query-log-file, --log-error-file, and + --pid-file + --log-bin[=name] Log update queries in binary format. Optional argument + should be name for binary log. If not given + 'datadir'/'log-basename'-bin or 'datadir'/mysql-bin will + be used (the later if --log-basename is not specified). + We strongly recommend to use either --log-basename or + specify a filename to ensure that replication doesn't + stop if the real hostname of the computer changes. + --log-bin-compress Whether the binary log can be compressed + --log-bin-compress-min-len[=#] + Minimum length of sql statement(in statement mode) or + record(in row mode)that can be compressed. + --log-bin-index=name + File that holds the names for last binary log files. + --log-bin-trust-function-creators + If set to FALSE (the default), then when --log-bin is + used, creation of a stored function (or trigger) is + allowed only to users having the SUPER privilege and only + if this stored function (trigger) may not break binary + logging. Note that if ALL connections to this server + ALWAYS use row-based binary logging, the security issues + do not exist and the binary logging cannot break, so you + can safely set this to TRUE + --log-disabled-statements=name + Don't log certain types of statements to general log. Any + combination of: slave, sp + --log-error[=name] Log errors to file (instead of stdout). If file name is + not specified then 'datadir'/'log-basename'.err or the + 'pid-file' path with extension .err is used + --log-isam[=name] Log all MyISAM changes to file. + --log-output=name How logs should be written. Any combination of: NONE, + FILE, TABLE + --log-queries-not-using-indexes + Log queries that are executed without benefit of any + index to the slow log if it is open. Same as + log_slow_filter='not_using_index' + --log-short-format Don't log extra information to update and slow-query + logs. + --log-slave-updates Tells the slave to log the updates from the slave thread + to the binary log. You will need to turn it on if you + plan to daisy-chain the slaves. + --log-slow-admin-statements + Log slow OPTIMIZE, ANALYZE, ALTER and other + administrative statements to the slow log if it is open. + Resets or sets the option 'admin' in + log_slow_disabled_statements + --log-slow-disabled-statements=name + Don't log certain types of statements to slow log. Any + combination of: admin, call, slave, sp + --log-slow-filter=name + Log only certain types of queries to the slow log. If + variable empty alll kind of queries are logged. All + types are bound by slow_query_time, except + 'not_using_index' which is always logged if enabled. Any + combination of: admin, filesort, filesort_on_disk, + filesort_priority_queue, full_join, full_scan, + not_using_index, query_cache, query_cache_miss, tmp_table, + tmp_table_on_disk + --log-slow-rate-limit=# + Write to slow log every #th slow query. Set to 1 to log + everything. Increase it to reduce the size of the slow or + the performance impact of slow logging + --log-slow-slave-statements + Log slow statements executed by slave thread to the slow + log if it is open. Resets or sets the option 'slave' in + log_slow_disabled_statements + --log-slow-verbosity=name + Verbosity level for the slow log. Any combination of: + innodb, query_plan, explain + --log-tc=name Path to transaction coordinator log (used for + transactions that affect more than one storage engine, + when binary log is disabled). + --log-tc-size=# Size of transaction coordinator log. + -W, --log-warnings[=#] + Log some not critical warnings to the general log + file.Value can be between 0 and 11. Higher values mean + more verbosity + --long-query-time=# Log all queries that have taken more than long_query_time + seconds to execute to the slow query log file. The + argument will be treated as a decimal value with + microsecond precision + --low-priority-updates + INSERT/DELETE/UPDATE has lower priority than selects + --lower-case-table-names[=#] + If set to 1 table names are stored in lowercase on disk + and table names will be case-insensitive. Should be set + to 2 if you are using a case insensitive file system + --master-info-file=name + The location and name of the file that remembers the + master and where the I/O replication thread is in the + master's binlogs. Defaults to master.info + --master-retry-count=# + The number of tries the slave will make to connect to the + master before giving up. + --master-verify-checksum + Force checksum verification of logged events in the + binary log before sending them to slaves or printing them + in the output of SHOW BINLOG EVENTS + --max-allowed-packet=# + Max packet length to send to or receive from the server + --max-binlog-cache-size=# + Sets the total size of the transactional cache + --max-binlog-size=# Binary log will be rotated automatically when the size + exceeds this value. + --max-binlog-stmt-cache-size=# + Sets the total size of the statement cache + --max-connect-errors=# + If there is more than this number of interrupted + connections from a host this host will be blocked from + further connections + --max-connections=# The number of simultaneous clients allowed + --max-delayed-threads=# + Don't start more than this number of threads to handle + INSERT DELAYED statements. If set to zero INSERT DELAYED + will be not used + --max-digest-length=# + Maximum length considered for digest text. + --max-error-count=# Max number of errors/warnings to store for a statement + --max-heap-table-size=# + Don't allow creation of heap tables bigger than this + --max-join-size=# Joins that are probably going to read more than + max_join_size records return an error + --max-length-for-sort-data=# + Max number of bytes in sorted records + --max-long-data-size=# + The maximum BLOB length to send to server from + mysql_send_long_data API. Deprecated option; use + max_allowed_packet instead. + --max-prepared-stmt-count=# + Maximum number of prepared statements in the server + --max-recursive-iterations[=#] + Maximum number of iterations when executing recursive + queries + --max-relay-log-size=# + relay log will be rotated automatically when the size + exceeds this value. If 0 at startup, it's set to + max_binlog_size + --max-seeks-for-key=# + Limit assumed max number of seeks when looking up rows + based on a key + --max-session-mem-used=# + Amount of memory a single user session is allowed to + allocate. This limits the value of the session variable + MEM_USED + --max-sort-length=# The number of bytes to use when sorting BLOB or TEXT + values (only the first max_sort_length bytes of each + value are used; the rest are ignored) + --max-sp-recursion-depth[=#] + Maximum stored procedure recursion depth + --max-statement-time=# + A query that has taken more than max_statement_time + seconds will be aborted. The argument will be treated as + a decimal value with microsecond precision. A value of 0 + (default) means no timeout + --max-tmp-tables=# Unused, will be removed. + --max-user-connections=# + The maximum number of active connections for a single + user (0 = no limit) + --max-write-lock-count=# + After this many write locks, allow some read locks to run + in between + --memlock Lock mysqld in memory. + --metadata-locks-cache-size=# + Unused + --metadata-locks-hash-instances=# + Unused + --min-examined-row-limit=# + Don't write queries to slow log that examine fewer rows + than that + --mrr-buffer-size=# Size of buffer to use when using MRR with range access + --multi-range-count=# + Ignored. Use mrr_buffer_size instead + --myisam-block-size=# + Block size to be used for MyISAM index pages + --myisam-data-pointer-size=# + Default pointer size to be used for MyISAM tables + --myisam-max-sort-file-size=# + Don't use the fast sort index method to created index if + the temporary file would get bigger than this + --myisam-mmap-size=# + Restricts the total memory used for memory mapping of + MySQL tables + --myisam-recover-options[=name] + Specifies how corrupted tables should be automatically + repaired. Any combination of: DEFAULT, BACKUP, FORCE, + QUICK, BACKUP_ALL, OFF + --myisam-repair-threads=# + If larger than 1, when repairing a MyISAM table all + indexes will be created in parallel, with one thread per + index. The value of 1 disables parallel repair + --myisam-sort-buffer-size=# + The buffer that is allocated when sorting the index when + doing a REPAIR or when creating indexes with CREATE INDEX + or ALTER TABLE + --myisam-stats-method=name + Specifies how MyISAM index statistics collection code + should treat NULLs. Possible values of name are + NULLS_UNEQUAL (default behavior for 4.1 and later), + NULLS_EQUAL (emulate 4.0 behavior), and NULLS_IGNORED + --myisam-use-mmap Use memory mapping for reading and writing MyISAM tables + --mysql56-temporal-format + Use MySQL-5.6 (instead of MariaDB-5.3) format for TIME, + DATETIME, TIMESTAMP columns. + (Defaults to on; use --skip-mysql56-temporal-format to disable.) + --net-buffer-length=# + Buffer length for TCP/IP and socket communication + --net-read-timeout=# + Number of seconds to wait for more data from a connection + before aborting the read + --net-retry-count=# If a read on a communication port is interrupted, retry + this many times before giving up + --net-write-timeout=# + Number of seconds to wait for a block to be written to a + connection before aborting the write + --old Use compatible behavior from previous MariaDB version. + See also --old-mode + --old-alter-table Use old, non-optimized alter table + --old-mode=name Used to emulate old behavior from earlier MariaDB or + MySQL versions. Any combination of: + NO_DUP_KEY_WARNINGS_WITH_IGNORE, NO_PROGRESS_INFO, + ZERO_DATE_TIME_CAST + --old-passwords Use old password encryption method (needed for 4.0 and + older clients) + --old-style-user-limits + Enable old-style user limits (before 5.0.3, user + resources were counted per each user+host vs. per + account). + --open-files-limit=# + If this is not 0, then mysqld will use this value to + reserve file descriptors to use with setrlimit(). If this + value is 0 or autoset then mysqld will reserve + max_connections*5 or max_connections + table_cache*2 + (whichever is larger) number of file descriptors + (Automatically configured unless set explicitly) + --optimizer-prune-level=# + Controls the heuristic(s) applied during query + optimization to prune less-promising partial plans from + the optimizer search space. Meaning: 0 - do not apply any + heuristic, thus perform exhaustive search; 1 - prune + plans based on number of retrieved rows + --optimizer-search-depth=# + Maximum depth of search performed by the query optimizer. + Values larger than the number of relations in a query + result in better query plans, but take longer to compile + a query. Values smaller than the number of tables in a + relation result in faster optimization, but may produce + very bad query plans. If set to 0, the system will + automatically pick a reasonable value. + --optimizer-selectivity-sampling-limit=# + Controls number of record samples to check condition + selectivity + --optimizer-switch=name + Fine-tune the optimizer behavior. Takes a comma-separated + list of option=value pairs, where value is on, off, or + default, and options are: index_merge, index_merge_union, + index_merge_sort_union, index_merge_intersection, + index_merge_sort_intersection, engine_condition_pushdown, + index_condition_pushdown, derived_merge, + derived_with_keys, firstmatch, loosescan, materialization, + in_to_exists, semijoin, partial_match_rowid_merge, + partial_match_table_scan, subquery_cache, mrr, + mrr_cost_based, mrr_sort_keys, outer_join_with_cache, + semijoin_with_cache, join_cache_incremental, + join_cache_hashed, join_cache_bka, + optimize_join_buffer_size, table_elimination, + extended_keys, exists_to_in, orderby_uses_equalities, - condition_pushdown_for_derived, split_materialized ++ condition_pushdown_for_derived, split_materialized, ++ condition_pushdown_for_subquery + --optimizer-use-condition-selectivity=# + Controls selectivity of which conditions the optimizer + takes into account to calculate cardinality of a partial + join when it searches for the best execution plan + Meaning: 1 - use selectivity of index backed range + conditions to calculate the cardinality of a partial join + if the last joined table is accessed by full table scan + or an index scan, 2 - use selectivity of index backed + range conditions to calculate the cardinality of a + partial join in any case, 3 - additionally always use + selectivity of range conditions that are not backed by + any index to calculate the cardinality of a partial join, + 4 - use histograms to calculate selectivity of range + conditions that are not backed by any index to calculate + the cardinality of a partial join.5 - additionally use + selectivity of certain non-range predicates calculated on + record samples + --performance-schema + Enable the performance schema. + --performance-schema-accounts-size=# + Maximum number of instrumented user@host accounts. Use 0 + to disable, -1 for automated sizing. + --performance-schema-consumer-events-stages-current + Default startup value for the events_stages_current + consumer. + --performance-schema-consumer-events-stages-history + Default startup value for the events_stages_history + consumer. + --performance-schema-consumer-events-stages-history-long + Default startup value for the events_stages_history_long + consumer. + --performance-schema-consumer-events-statements-current + Default startup value for the events_statements_current + consumer. + (Defaults to on; use --skip-performance-schema-consumer-events-statements-current to disable.) + --performance-schema-consumer-events-statements-history + Default startup value for the events_statements_history + consumer. + --performance-schema-consumer-events-statements-history-long + Default startup value for the + events_statements_history_long consumer. + --performance-schema-consumer-events-waits-current + Default startup value for the events_waits_current + consumer. + --performance-schema-consumer-events-waits-history + Default startup value for the events_waits_history + consumer. + --performance-schema-consumer-events-waits-history-long + Default startup value for the events_waits_history_long + consumer. + --performance-schema-consumer-global-instrumentation + Default startup value for the global_instrumentation + consumer. + (Defaults to on; use --skip-performance-schema-consumer-global-instrumentation to disable.) + --performance-schema-consumer-statements-digest + Default startup value for the statements_digest consumer. + (Defaults to on; use --skip-performance-schema-consumer-statements-digest to disable.) + --performance-schema-consumer-thread-instrumentation + Default startup value for the thread_instrumentation + consumer. + (Defaults to on; use --skip-performance-schema-consumer-thread-instrumentation to disable.) + --performance-schema-digests-size=# + Size of the statement digest. Use 0 to disable, -1 for + automated sizing. + --performance-schema-events-stages-history-long-size=# + Number of rows in EVENTS_STAGES_HISTORY_LONG. Use 0 to + disable, -1 for automated sizing. + --performance-schema-events-stages-history-size=# + Number of rows per thread in EVENTS_STAGES_HISTORY. Use 0 + to disable, -1 for automated sizing. + --performance-schema-events-statements-history-long-size=# + Number of rows in EVENTS_STATEMENTS_HISTORY_LONG. Use 0 + to disable, -1 for automated sizing. + --performance-schema-events-statements-history-size=# + Number of rows per thread in EVENTS_STATEMENTS_HISTORY. + Use 0 to disable, -1 for automated sizing. + --performance-schema-events-waits-history-long-size=# + Number of rows in EVENTS_WAITS_HISTORY_LONG. Use 0 to + disable, -1 for automated sizing. + --performance-schema-events-waits-history-size=# + Number of rows per thread in EVENTS_WAITS_HISTORY. Use 0 + to disable, -1 for automated sizing. + --performance-schema-hosts-size=# + Maximum number of instrumented hosts. Use 0 to disable, + -1 for automated sizing. + --performance-schema-instrument[=name] + Default startup value for a performance schema + instrument. + --performance-schema-max-cond-classes=# + Maximum number of condition instruments. + --performance-schema-max-cond-instances=# + Maximum number of instrumented condition objects. Use 0 + to disable, -1 for automated sizing. + --performance-schema-max-digest-length=# + Maximum length considered for digest text, when stored in + performance_schema tables. + --performance-schema-max-file-classes=# + Maximum number of file instruments. + --performance-schema-max-file-handles=# + Maximum number of opened instrumented files. + --performance-schema-max-file-instances=# + Maximum number of instrumented files. Use 0 to disable, + -1 for automated sizing. + --performance-schema-max-mutex-classes=# + Maximum number of mutex instruments. + --performance-schema-max-mutex-instances=# + Maximum number of instrumented MUTEX objects. Use 0 to + disable, -1 for automated sizing. + --performance-schema-max-rwlock-classes=# + Maximum number of rwlock instruments. + --performance-schema-max-rwlock-instances=# + Maximum number of instrumented RWLOCK objects. Use 0 to + disable, -1 for automated sizing. + --performance-schema-max-socket-classes=# + Maximum number of socket instruments. + --performance-schema-max-socket-instances=# + Maximum number of opened instrumented sockets. Use 0 to + disable, -1 for automated sizing. + --performance-schema-max-stage-classes=# + Maximum number of stage instruments. + --performance-schema-max-statement-classes=# + Maximum number of statement instruments. + --performance-schema-max-table-handles=# + Maximum number of opened instrumented tables. Use 0 to + disable, -1 for automated sizing. + --performance-schema-max-table-instances=# + Maximum number of instrumented tables. Use 0 to disable, + -1 for automated sizing. + --performance-schema-max-thread-classes=# + Maximum number of thread instruments. + --performance-schema-max-thread-instances=# + Maximum number of instrumented threads. Use 0 to disable, + -1 for automated sizing. + --performance-schema-session-connect-attrs-size=# + Size of session attribute string buffer per thread. Use 0 + to disable, -1 for automated sizing. + --performance-schema-setup-actors-size=# + Maximum number of rows in SETUP_ACTORS. + --performance-schema-setup-objects-size=# + Maximum number of rows in SETUP_OBJECTS. + --performance-schema-users-size=# + Maximum number of instrumented users. Use 0 to disable, + -1 for automated sizing. + --pid-file=name Pid file used by safe_mysqld + --plugin-dir=name Directory for plugins + --plugin-load=name Semicolon-separated list of plugins to load, where each + plugin is specified as ether a plugin_name=library_file + pair or only a library_file. If the latter case, all + plugins from a given library_file will be loaded. + --plugin-load-add=name + Optional semicolon-separated list of plugins to load. + This option adds to the list specified by --plugin-load + in an incremental way. It can be specified many times, + adding more plugins every time. + --plugin-maturity=name + The lowest desirable plugin maturity. Plugins less mature + than that will not be installed or loaded. One of: + unknown, experimental, alpha, beta, gamma, stable + -P, --port=# Port number to use for connection or 0 to default to, + my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default + (3306), whatever comes first + --port-open-timeout=# + Maximum time in seconds to wait for the port to become + free. (Default: No wait). + --preload-buffer-size=# + The size of the buffer that is allocated when preloading + indexes + --profiling-history-size=# + Number of statements about which profiling information is + maintained. If set to 0, no profiles are stored. See SHOW + PROFILES. + --progress-report-time=# + Seconds between sending progress reports to the client + for time-consuming statements. Set to 0 to disable + progress reporting. + --proxy-protocol-networks=name + Enable proxy protocol for these source networks. The + syntax is a comma separated list of IPv4 and IPv6 + networks. If the network doesn't contain mask, it is + considered to be a single host. "*" represents all + networks and must the only directive on the line. String + "localhost" represents non-TCP local connections (Unix + domain socket, Windows named pipe or shared memory). + --query-alloc-block-size=# + Allocation block size for query parsing and execution + --query-cache-limit=# + Don't cache results that are bigger than this + --query-cache-min-res-unit=# + The minimum size for blocks allocated by the query cache + --query-cache-size=# + The memory allocated to store results from old queries + --query-cache-strip-comments + Strip all comments from a query before storing it in the + query cache + --query-cache-type=name + OFF = Don't cache or retrieve results. ON = Cache all + results except SELECT SQL_NO_CACHE ... queries. DEMAND = + Cache only SELECT SQL_CACHE ... queries + --query-cache-wlock-invalidate + Invalidate queries in query cache on LOCK for write + --query-prealloc-size=# + Persistent buffer for query parsing and execution + --range-alloc-block-size=# + Allocation block size for storing ranges during + optimization + --read-binlog-speed-limit=# + Maximum speed(KB/s) to read binlog from master (0 = no + limit) + --read-buffer-size=# + Each thread that does a sequential scan allocates a + buffer of this size for each table it scans. If you do + many sequential scans, you may want to increase this + value + --read-only Make all non-temporary tables read-only, with the + exception for replication (slave) threads and users with + the SUPER privilege + --read-rnd-buffer-size=# + When reading rows in sorted order after a sort, the rows + are read through this buffer to avoid a disk seeks + --relay-log=name The location and name to use for relay logs. + --relay-log-index=name + The location and name to use for the file that keeps a + list of the last relay logs + --relay-log-info-file=name + The location and name of the file that remembers where + the SQL replication thread is in the relay logs. + --relay-log-purge if disabled - do not purge relay logs. if enabled - purge + them as soon as they are no more needed. + (Defaults to on; use --skip-relay-log-purge to disable.) + --relay-log-recovery + Enables automatic relay log recovery right after the + database startup, which means that the IO Thread starts + re-fetching from the master right after the last + transaction processed. + --relay-log-space-limit=# + Maximum space to use for all relay logs + --replicate-annotate-row-events + Tells the slave to write annotate rows events received + from the master to its own binary log. Ignored if + log_slave_updates is not set + (Defaults to on; use --skip-replicate-annotate-row-events to disable.) + --replicate-do-db=name + Tells the slave thread to restrict replication to the + specified database. To specify more than one database, + use the directive multiple times, once for each database. + Note that this will only work if you do not use + cross-database queries such as UPDATE some_db.some_table + SET foo='bar' while having selected a different or no + database. If you need cross database updates to work, + make sure you have 3.23.28 or later, and use + replicate-wild-do-table=db_name.%. + --replicate-do-table=name + Tells the slave thread to restrict replication to the + specified table. To specify more than one table, use the + directive multiple times, once for each table. This will + work for cross-database updates, in contrast to + replicate-do-db. + --replicate-events-marked-for-skip=name + Whether the slave should replicate events that were + created with @@skip_replication=1 on the master. Default + REPLICATE (no events are skipped). Other values are + FILTER_ON_SLAVE (events will be sent by the master but + ignored by the slave) and FILTER_ON_MASTER (events marked + with @@skip_replication=1 will be filtered on the master + and never be sent to the slave). + --replicate-ignore-db=name + Tells the slave thread to not replicate to the specified + database. To specify more than one database to ignore, + use the directive multiple times, once for each database. + This option will not work if you use cross database + updates. If you need cross database updates to work, make + sure you have 3.23.28 or later, and use + replicate-wild-ignore-table=db_name.%. + --replicate-ignore-table=name + Tells the slave thread to not replicate to the specified + table. To specify more than one table to ignore, use the + directive multiple times, once for each table. This will + work for cross-database updates, in contrast to + replicate-ignore-db. + --replicate-rewrite-db=name + Updates to a database with a different name than the + original. Example: + replicate-rewrite-db=master_db_name->slave_db_name. + --replicate-same-server-id + In replication, if set to 1, do not skip events having + our server id. Default value is 0 (to break infinite + loops in circular replication). Can't be set to 1 if + --log-slave-updates is used. + --replicate-wild-do-table=name + Tells the slave thread to restrict replication to the + tables that match the specified wildcard pattern. To + specify more than one table, use the directive multiple + times, once for each table. This will work for + cross-database updates. Example: + replicate-wild-do-table=foo%.bar% will replicate only + updates to tables in all databases that start with foo + and whose table names start with bar. + --replicate-wild-ignore-table=name + Tells the slave thread to not replicate to the tables + that match the given wildcard pattern. To specify more + than one table to ignore, use the directive multiple + times, once for each table. This will work for + cross-database updates. Example: + replicate-wild-ignore-table=foo%.bar% will not do updates + to tables in databases that start with foo and whose + table names start with bar. + --report-host=name Hostname or IP of the slave to be reported to the master + during slave registration. Will appear in the output of + SHOW SLAVE HOSTS. Leave unset if you do not want the + slave to register itself with the master. Note that it is + not sufficient for the master to simply read the IP of + the slave off the socket once the slave connects. Due to + NAT and other routing issues, that IP may not be valid + for connecting to the slave from the master or other + hosts + --report-password=name + The account password of the slave to be reported to the + master during slave registration + --report-port=# Port for connecting to slave reported to the master + during slave registration. Set it only if the slave is + listening on a non-default port or if you have a special + tunnel from the master or other clients to the slave. If + not sure, leave this option unset + --report-user=name The account user name of the slave to be reported to the + master during slave registration + --rowid-merge-buff-size=# + The size of the buffers used [NOT] IN evaluation via + partial matching + --rpl-semi-sync-master-enabled + Enable semi-synchronous replication master (disabled by + default). + --rpl-semi-sync-master-timeout=# + The timeout value (in ms) for semi-synchronous + replication in the master + --rpl-semi-sync-master-trace-level=# + The tracing level for semi-sync replication. + --rpl-semi-sync-master-wait-no-slave + Wait until timeout when no semi-synchronous replication + slave available (enabled by default). + (Defaults to on; use --skip-rpl-semi-sync-master-wait-no-slave to disable.) + --rpl-semi-sync-master-wait-point=name + Should transaction wait for semi-sync ack after having + synced binlog, or after having committed in storage + engine.. One of: AFTER_SYNC, AFTER_COMMIT + --rpl-semi-sync-slave-delay-master + Only write master info file when ack is needed. + --rpl-semi-sync-slave-enabled + Enable semi-synchronous replication slave (disabled by + default). + --rpl-semi-sync-slave-kill-conn-timeout[=#] + Timeout for the mysql connection used to kill the slave + io_thread's connection on master. This timeout comes into + play when stop slave is executed. + --rpl-semi-sync-slave-trace-level=# + The tracing level for semi-sync replication. + --safe-mode Skip some optimize stages (for testing). Deprecated. + --safe-user-create Don't allow new user creation by the user who has no + write privileges to the mysql.user table. + --secure-auth Disallow authentication for accounts that have old + (pre-4.1) passwords + (Defaults to on; use --skip-secure-auth to disable.) + --secure-file-priv=name + Limit LOAD DATA, SELECT ... OUTFILE, and LOAD_FILE() to + files within specified directory + --server-id=# Uniquely identifies the server instance in the community + of replication partners + --session-track-schema + Track changes to the default schema. + (Defaults to on; use --skip-session-track-schema to disable.) + --session-track-state-change + Track changes to the session state. + --session-track-system-variables=name + Track changes in registered system variables. + --session-track-transaction-info=name + Track changes to the transaction attributes. OFF to + disable; STATE to track just transaction state (Is there + an active transaction? Does it have any data? etc.); + CHARACTERISTICS to track transaction state and report all + statements needed to start a transaction withthe same + characteristics (isolation level, read only/read + write,snapshot - but not any work done / data modified + within the transaction). + --show-slave-auth-info + Show user and password in SHOW SLAVE HOSTS on this + master. + --silent-startup Don't print [Note] to the error log during startup. + --skip-bdb Deprecated option; Exist only for compatibility with old + my.cnf files + --skip-grant-tables Start without grant tables. This gives all users FULL + ACCESS to all tables. + --skip-host-cache Don't cache host names. + --skip-name-resolve Don't resolve hostnames. All hostnames are IP's or + 'localhost'. + --skip-networking Don't allow connection with TCP/IP + --skip-show-database + Don't allow 'SHOW DATABASE' commands + --skip-slave-start If set, slave is not autostarted. + --slave-compressed-protocol + Use compression on master/slave protocol + --slave-ddl-exec-mode=name + How replication events should be executed. Legal values + are STRICT and IDEMPOTENT (default). In IDEMPOTENT mode, + replication will not stop for DDL operations that are + idempotent. This means that CREATE TABLE is treated as + CREATE TABLE OR REPLACE and DROP TABLE is treated as DROP + TABLE IF EXISTS. + --slave-domain-parallel-threads=# + Maximum number of parallel threads to use on slave for + events in a single replication domain. When using + multiple domains, this can be used to limit a single + domain from grabbing all threads and thus stalling other + domains. The default of 0 means to allow a domain to grab + as many threads as it wants, up to the value of + slave_parallel_threads. + --slave-exec-mode=name + How replication events should be executed. Legal values + are STRICT (default) and IDEMPOTENT. In IDEMPOTENT mode, + replication will not stop for operations that are + idempotent. For example, in row based replication + attempts to delete rows that doesn't exist will be + ignored. In STRICT mode, replication will stop on any + unexpected difference between the master and the slave. + --slave-load-tmpdir=name + The location where the slave should put its temporary + files when replicating a LOAD DATA INFILE command + --slave-max-allowed-packet=# + The maximum packet length to sent successfully from the + master to slave. + --slave-net-timeout=# + Number of seconds to wait for more data from any + master/slave connection before aborting the read + --slave-parallel-max-queued=# + Limit on how much memory SQL threads should use per + parallel replication thread when reading ahead in the + relay log looking for opportunities for parallel + replication. Only used when --slave-parallel-threads > 0. + --slave-parallel-mode=name + Controls what transactions are applied in parallel when + using --slave-parallel-threads. Possible values: + "optimistic" tries to apply most transactional DML in + parallel, and handles any conflicts with rollback and + retry. "conservative" limits parallelism in an effort to + avoid any conflicts. "aggressive" tries to maximise the + parallelism, possibly at the cost of increased conflict + rate. "minimal" only parallelizes the commit steps of + transactions. "none" disables parallel apply completely. + --slave-parallel-threads=# + If non-zero, number of threads to spawn to apply in + parallel events on the slave that were group-committed on + the master or were logged with GTID in different + replication domains. Note that these threads are in + addition to the IO and SQL threads, which are always + created by a replication slave + --slave-parallel-workers=# + Alias for slave_parallel_threads + --slave-run-triggers-for-rbr=name + Modes for how triggers in row-base replication on slave + side will be executed. Legal values are NO (default), YES + and LOGGING. NO means that trigger for RBR will not be + running on slave. YES and LOGGING means that triggers + will be running on slave, if there was not triggers + running on the master for the statement. LOGGING also + means results of that the executed triggers work will be + written to the binlog. + --slave-skip-errors=name + Tells the slave thread to continue replication when a + query event returns an error from the provided list + --slave-sql-verify-checksum + Force checksum verification of replication events after + reading them from relay log. Note: Events are always + checksum-verified by slave on receiving them from the + network before writing them to the relay log + (Defaults to on; use --skip-slave-sql-verify-checksum to disable.) + --slave-transaction-retries=# + Number of times the slave SQL thread will retry a + transaction in case it failed with a deadlock, elapsed + lock wait timeout or listed in + slave_transaction_retry_errors, before giving up and + stopping + --slave-transaction-retry-errors=name + Tells the slave thread to retry transaction for + replication when a query event returns an error from the + provided list. Deadlock and elapsed lock wait timeout + errors are automatically added to this list + --slave-transaction-retry-interval=# + Interval of the slave SQL thread will retry a transaction + in case it failed with a deadlock or elapsed lock wait + timeout or listed in slave_transaction_retry_errors + --slave-type-conversions=name + Set of slave type conversions that are enabled. If the + variable is empty, no conversions are allowed and it is + expected that the types match exactly. Any combination + of: ALL_LOSSY, ALL_NON_LOSSY + --slow-launch-time=# + If creating the thread takes longer than this value (in + seconds), the Slow_launch_threads counter will be + incremented + --slow-query-log Log slow queries to a table or log file. Defaults logging + to a file 'hostname'-slow.log or a table mysql.slow_log + if --log-output=TABLE is used. Must be enabled to + activate other slow log options. + --slow-query-log-file=name + Log slow queries to given log file. Defaults logging to + 'hostname'-slow.log. Must be enabled to activate other + slow log options + --socket=name Socket file to use for connection + --sort-buffer-size=# + Each thread that needs to do a sort allocates a buffer of + this size + --sql-mode=name Sets the sql mode. Any combination of: REAL_AS_FLOAT, + PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, + IGNORE_BAD_TABLE_OPTIONS, ONLY_FULL_GROUP_BY, + NO_UNSIGNED_SUBTRACTION, NO_DIR_IN_CREATE, POSTGRESQL, + ORACLE, MSSQL, DB2, MAXDB, NO_KEY_OPTIONS, + NO_TABLE_OPTIONS, NO_FIELD_OPTIONS, MYSQL323, MYSQL40, + ANSI, NO_AUTO_VALUE_ON_ZERO, NO_BACKSLASH_ESCAPES, + STRICT_TRANS_TABLES, STRICT_ALL_TABLES, NO_ZERO_IN_DATE, + NO_ZERO_DATE, ALLOW_INVALID_DATES, + ERROR_FOR_DIVISION_BY_ZERO, TRADITIONAL, + NO_AUTO_CREATE_USER, HIGH_NOT_PRECEDENCE, + NO_ENGINE_SUBSTITUTION, PAD_CHAR_TO_FULL_LENGTH, + EMPTY_STRING_IS_NULL, SIMULTANEOUS_ASSIGNMENT + --stack-trace Print a symbolic stack trace on failure + (Defaults to on; use --skip-stack-trace to disable.) + --standard-compliant-cte + Allow only CTEs compliant to SQL standard + (Defaults to on; use --skip-standard-compliant-cte to disable.) + --stored-program-cache=# + The soft upper limit for number of cached stored routines + for one connection. + --strict-password-validation + When password validation plugins are enabled, reject + passwords that cannot be validated (passwords specified + as a hash) + (Defaults to on; use --skip-strict-password-validation to disable.) + -s, --symbolic-links + Enable symbolic link support. + --sync-binlog=# Synchronously flush binary log to disk after every #th + event. Use 0 (default) to disable synchronous flushing + --sync-frm Sync .frm files to disk on creation + (Defaults to on; use --skip-sync-frm to disable.) + --sync-master-info=# + Synchronously flush master info to disk after every #th + event. Use 0 to disable synchronous flushing + --sync-relay-log=# Synchronously flush relay log to disk after every #th + event. Use 0 to disable synchronous flushing + --sync-relay-log-info=# + Synchronously flush relay log info to disk after every + #th transaction. Use 0 to disable synchronous flushing + --sysdate-is-now Non-default option to alias SYSDATE() to NOW() to make it + safe-replicable. Since 5.0, SYSDATE() returns a `dynamic' + value different for different invocations, even within + the same statement. + --system-versioning-alter-history=name + Versioning ALTER TABLE mode. ERROR: Fail ALTER with + error; KEEP: Keep historical system rows and subject them + to ALTER; + --table-cache=# Deprecated; use --table-open-cache instead. + --table-definition-cache=# + The number of cached table definitions + --table-open-cache=# + The number of cached open tables + --table-open-cache-instances=# + Maximum number of table cache instances + --tc-heuristic-recover=name + Decision to use in heuristic recover process. One of: OFF, + COMMIT, ROLLBACK + --tcp-keepalive-interval=# + The interval, in seconds, between when successive + keep-alive packets are sent if no acknowledgement is + received.If set to 0, system dependent default is used. + (Automatically configured unless set explicitly) + --tcp-keepalive-probes=# + The number of unacknowledged probes to send before + considering the connection dead and notifying the + application layer.If set to 0, system dependent default + is used. (Automatically configured unless set explicitly) + --tcp-keepalive-time=# + Timeout, in milliseconds, with no activity until the + first TCP keep-alive packet is sent.If set to 0, system + dependent default is used. (Automatically configured + unless set explicitly) + --thread-cache-size=# + How many threads we should keep in a cache for reuse. + These are freed after 5 minutes of idle time + --thread-pool-idle-timeout=# + Timeout in seconds for an idle thread in the thread + pool.Worker thread will be shut down after timeout + --thread-pool-max-threads=# + Maximum allowed number of worker threads in the thread + pool + --thread-pool-oversubscribe=# + How many additional active worker threads in a group are + allowed. + --thread-pool-prio-kickup-timer=# + The number of milliseconds before a dequeued low-priority + statement is moved to the high-priority queue + --thread-pool-priority=name + Threadpool priority. High priority connections usually + start executing earlier than low priority.If priority set + to 'auto', the the actual priority(low or high) is + determined based on whether or not connection is inside + transaction. + --thread-pool-size=# + Number of thread groups in the pool. This parameter is + roughly equivalent to maximum number of concurrently + executing threads (threads in a waiting state do not + count as executing). + --thread-pool-stall-limit=# + Maximum query execution time in milliseconds,before an + executing non-yielding thread is considered stalled.If a + worker thread is stalled, additional worker thread may be + created to handle remaining clients. + --thread-stack=# The stack size for each thread + --time-format=name The TIME format (ignored) + --timed-mutexes Specify whether to time mutexes. Deprecated, has no + effect. + --tmp-disk-table-size=# + Max size for data for an internal temporary on-disk + MyISAM or Aria table. + --tmp-memory-table-size=# + If an internal in-memory temporary table exceeds this + size, MariaDB will automatically convert it to an on-disk + MyISAM or Aria table. Same as tmp_table_size. + --tmp-table-size=# Alias for tmp_memory_table_size. If an internal in-memory + temporary table exceeds this size, MariaDB will + automatically convert it to an on-disk MyISAM or Aria + table. + -t, --tmpdir=name Path for temporary files. Several paths may be specified, + separated by a colon (:), in this case they are used in a + round-robin fashion + --transaction-alloc-block-size=# + Allocation block size for transactions to be stored in + binary log + --transaction-isolation=name + Default transaction isolation level. One of: + READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, + SERIALIZABLE + --transaction-prealloc-size=# + Persistent buffer for transactions to be stored in binary + log + --transaction-read-only + Default transaction access mode. True if transactions are + read-only. + --updatable-views-with-limit=name + YES = Don't issue an error message (warning only) if a + VIEW without presence of a key of the underlying table is + used in queries with a LIMIT clause for updating. NO = + Prohibit update of a VIEW, which does not contain a key + of the underlying table and the query uses a LIMIT clause + (usually get from GUI tools) + --use-stat-tables=name + Specifies how to use system statistics tables. One of: + NEVER, COMPLEMENTARY, PREFERABLY + -u, --user=name Run mysqld daemon as user. + --userstat Enables statistics gathering for USER_STATISTICS, + CLIENT_STATISTICS, INDEX_STATISTICS and TABLE_STATISTICS + tables in the INFORMATION_SCHEMA + -v, --verbose Used with --help option for detailed help. + -V, --version[=name] + Output version information and exit. + --wait-timeout=# The number of seconds the server waits for activity on a + connection before closing it + +Variables (--variable-name=value) +allow-suspicious-udfs FALSE +auto-increment-increment 1 +auto-increment-offset 1 +autocommit TRUE +automatic-sp-privileges TRUE +back-log 80 +big-tables FALSE +bind-address (No default value) +binlog-annotate-row-events TRUE +binlog-cache-size 32768 +binlog-checksum CRC32 +binlog-commit-wait-count 0 +binlog-commit-wait-usec 100000 +binlog-direct-non-transactional-updates FALSE +binlog-file-cache-size 16384 +binlog-format MIXED +binlog-optimize-thread-scheduling TRUE +binlog-row-event-max-size 8192 +binlog-row-image FULL +binlog-stmt-cache-size 32768 +bulk-insert-buffer-size 8388608 +character-set-client-handshake TRUE +character-set-filesystem binary +character-sets-dir MYSQL_CHARSETSDIR/ +chroot (No default value) +column-compression-threshold 100 +column-compression-zlib-level 6 +column-compression-zlib-strategy DEFAULT_STRATEGY +column-compression-zlib-wrap FALSE +completion-type NO_CHAIN +concurrent-insert AUTO +console TRUE +date-format %Y-%m-%d +datetime-format %Y-%m-%d %H:%i:%s +deadlock-search-depth-long 15 +deadlock-search-depth-short 4 +deadlock-timeout-long 50000000 +deadlock-timeout-short 10000 +default-regex-flags +default-storage-engine myisam +default-time-zone (No default value) +default-tmp-storage-engine (No default value) +default-week-format 0 +delay-key-write ON +delayed-insert-limit 100 +delayed-insert-timeout 300 +delayed-queue-size 1000 +div-precision-increment 4 +encrypt-binlog FALSE +encrypt-tmp-disk-tables FALSE +encrypt-tmp-files FALSE +enforce-storage-engine (No default value) +event-scheduler OFF +expensive-subquery-limit 100 +expire-logs-days 0 +explicit-defaults-for-timestamp FALSE +external-locking FALSE +extra-max-connections 1 +extra-port 0 +flashback FALSE +flush FALSE +flush-time 0 +ft-boolean-syntax + -><()~*:""&| +ft-max-word-len 84 +ft-min-word-len 4 +ft-query-expansion-limit 20 +ft-stopword-file (No default value) +gdb FALSE +general-log FALSE +getopt-prefix-matching FALSE +group-concat-max-len 1048576 +gtid-domain-id 0 +gtid-ignore-duplicates FALSE +gtid-pos-auto-engines +gtid-strict-mode FALSE +help TRUE +histogram-size 0 +histogram-type SINGLE_PREC_HB +host-cache-size 279 +idle-readonly-transaction-timeout 0 +idle-transaction-timeout 0 +idle-write-transaction-timeout 0 +ignore-builtin-innodb FALSE +ignore-db-dirs +init-connect +init-file (No default value) +init-rpl-role MASTER +init-slave +interactive-timeout 28800 +join-buffer-size 262144 +join-buffer-space-limit 2097152 +join-cache-level 2 +keep-files-on-create FALSE +key-buffer-size 134217728 +key-cache-age-threshold 300 +key-cache-block-size 1024 +key-cache-division-limit 100 +key-cache-file-hash-size 512 +key-cache-segments 0 +large-pages FALSE +lc-messages en_US +lc-messages-dir MYSQL_SHAREDIR/ +lc-time-names en_US +local-infile TRUE +lock-wait-timeout 86400 +log-bin (No default value) +log-bin-compress FALSE +log-bin-compress-min-len 256 +log-bin-index (No default value) +log-bin-trust-function-creators FALSE +log-disabled-statements sp +log-error +log-isam myisam.log +log-output FILE +log-queries-not-using-indexes FALSE +log-short-format FALSE +log-slave-updates FALSE +log-slow-admin-statements TRUE +log-slow-disabled-statements sp +log-slow-filter admin,filesort,filesort_on_disk,filesort_priority_queue,full_join,full_scan,query_cache,query_cache_miss,tmp_table,tmp_table_on_disk +log-slow-rate-limit 1 +log-slow-slave-statements TRUE +log-slow-verbosity +log-tc tc.log +log-warnings 2 +long-query-time 10 +low-priority-updates FALSE +lower-case-table-names 1 +master-info-file master.info +master-retry-count 86400 +master-verify-checksum FALSE +max-allowed-packet 16777216 +max-binlog-cache-size 18446744073709547520 +max-binlog-size 1073741824 +max-binlog-stmt-cache-size 18446744073709547520 +max-connect-errors 100 +max-connections 151 +max-delayed-threads 20 +max-digest-length 1024 +max-error-count 64 +max-heap-table-size 16777216 +max-join-size 18446744073709551615 +max-length-for-sort-data 1024 +max-long-data-size 16777216 +max-prepared-stmt-count 16382 +max-recursive-iterations 18446744073709551615 +max-relay-log-size 1073741824 +max-seeks-for-key 18446744073709551615 +max-session-mem-used 9223372036854775807 +max-sort-length 1024 +max-sp-recursion-depth 0 +max-statement-time 0 +max-tmp-tables 32 +max-user-connections 0 +max-write-lock-count 18446744073709551615 +memlock FALSE +metadata-locks-cache-size 1024 +metadata-locks-hash-instances 8 +min-examined-row-limit 0 +mrr-buffer-size 262144 +multi-range-count 256 +myisam-block-size 1024 +myisam-data-pointer-size 6 +myisam-max-sort-file-size 9223372036853727232 +myisam-mmap-size 18446744073709551615 +myisam-recover-options BACKUP,QUICK +myisam-repair-threads 1 +myisam-sort-buffer-size 134216704 +myisam-stats-method NULLS_UNEQUAL +myisam-use-mmap FALSE +mysql56-temporal-format TRUE +net-buffer-length 16384 +net-read-timeout 30 +net-retry-count 10 +net-write-timeout 60 +old FALSE +old-alter-table FALSE +old-mode +old-passwords FALSE +old-style-user-limits FALSE +optimizer-prune-level 1 +optimizer-search-depth 62 +optimizer-selectivity-sampling-limit 100 - optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on ++optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on +optimizer-use-condition-selectivity 1 +performance-schema FALSE +performance-schema-accounts-size -1 +performance-schema-consumer-events-stages-current FALSE +performance-schema-consumer-events-stages-history FALSE +performance-schema-consumer-events-stages-history-long FALSE +performance-schema-consumer-events-statements-current TRUE +performance-schema-consumer-events-statements-history FALSE +performance-schema-consumer-events-statements-history-long FALSE +performance-schema-consumer-events-waits-current FALSE +performance-schema-consumer-events-waits-history FALSE +performance-schema-consumer-events-waits-history-long FALSE +performance-schema-consumer-global-instrumentation TRUE +performance-schema-consumer-statements-digest TRUE +performance-schema-consumer-thread-instrumentation TRUE +performance-schema-digests-size -1 +performance-schema-events-stages-history-long-size -1 +performance-schema-events-stages-history-size -1 +performance-schema-events-statements-history-long-size -1 +performance-schema-events-statements-history-size -1 +performance-schema-events-waits-history-long-size -1 +performance-schema-events-waits-history-size -1 +performance-schema-hosts-size -1 +performance-schema-instrument +performance-schema-max-cond-classes 80 +performance-schema-max-cond-instances -1 +performance-schema-max-digest-length 1024 +performance-schema-max-file-classes 50 +performance-schema-max-file-handles 32768 +performance-schema-max-file-instances -1 +performance-schema-max-mutex-classes 200 +performance-schema-max-mutex-instances -1 +performance-schema-max-rwlock-classes 40 +performance-schema-max-rwlock-instances -1 +performance-schema-max-socket-classes 10 +performance-schema-max-socket-instances -1 +performance-schema-max-stage-classes 160 +performance-schema-max-statement-classes 200 +performance-schema-max-table-handles -1 +performance-schema-max-table-instances -1 +performance-schema-max-thread-classes 50 +performance-schema-max-thread-instances -1 +performance-schema-session-connect-attrs-size -1 +performance-schema-setup-actors-size 100 +performance-schema-setup-objects-size 100 +performance-schema-users-size -1 +port 3306 +port-open-timeout 0 +preload-buffer-size 32768 +profiling-history-size 15 +progress-report-time 5 +protocol-version 10 +proxy-protocol-networks +query-alloc-block-size 16384 +query-cache-limit 1048576 +query-cache-min-res-unit 4096 +query-cache-size 1048576 +query-cache-strip-comments FALSE +query-cache-type OFF +query-cache-wlock-invalidate FALSE +query-prealloc-size 24576 +range-alloc-block-size 4096 +read-binlog-speed-limit 0 +read-buffer-size 131072 +read-only FALSE +read-rnd-buffer-size 262144 +relay-log (No default value) +relay-log-index (No default value) +relay-log-info-file relay-log.info +relay-log-purge TRUE +relay-log-recovery FALSE +relay-log-space-limit 0 +replicate-annotate-row-events TRUE +replicate-events-marked-for-skip REPLICATE +replicate-same-server-id FALSE +report-host (No default value) +report-password (No default value) +report-port 0 +report-user (No default value) +rowid-merge-buff-size 8388608 +rpl-semi-sync-master-enabled FALSE +rpl-semi-sync-master-timeout 10000 +rpl-semi-sync-master-trace-level 32 +rpl-semi-sync-master-wait-no-slave TRUE +rpl-semi-sync-master-wait-point AFTER_COMMIT +rpl-semi-sync-slave-delay-master FALSE +rpl-semi-sync-slave-enabled FALSE +rpl-semi-sync-slave-kill-conn-timeout 5 +rpl-semi-sync-slave-trace-level 32 +safe-user-create FALSE +secure-auth TRUE +secure-file-priv (No default value) +server-id 1 +session-track-schema TRUE +session-track-state-change FALSE +session-track-system-variables autocommit,character_set_client,character_set_connection,character_set_results,time_zone +session-track-transaction-info OFF +show-slave-auth-info FALSE +silent-startup FALSE +skip-grant-tables TRUE +skip-name-resolve FALSE +skip-networking FALSE +skip-show-database FALSE +skip-slave-start FALSE +slave-compressed-protocol FALSE +slave-ddl-exec-mode IDEMPOTENT +slave-domain-parallel-threads 0 +slave-exec-mode STRICT +slave-max-allowed-packet 1073741824 +slave-net-timeout 60 +slave-parallel-max-queued 131072 +slave-parallel-mode conservative +slave-parallel-threads 0 +slave-parallel-workers 0 +slave-run-triggers-for-rbr NO +slave-skip-errors OFF +slave-sql-verify-checksum TRUE +slave-transaction-retries 10 +slave-transaction-retry-errors 1213,1205 +slave-transaction-retry-interval 0 +slave-type-conversions +slow-launch-time 2 +slow-query-log FALSE +sort-buffer-size 2097152 +sql-mode STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION +stack-trace TRUE +standard-compliant-cte TRUE +stored-program-cache 256 +strict-password-validation TRUE +symbolic-links FALSE +sync-binlog 0 +sync-frm FALSE +sync-master-info 10000 +sync-relay-log 10000 +sync-relay-log-info 10000 +sysdate-is-now FALSE +system-versioning-alter-history ERROR +table-cache 421 +table-definition-cache 400 +table-open-cache 421 +table-open-cache-instances 8 +tc-heuristic-recover OFF +tcp-keepalive-interval 0 +tcp-keepalive-probes 0 +tcp-keepalive-time 0 +thread-cache-size 151 +thread-pool-idle-timeout 60 +thread-pool-max-threads 65536 +thread-pool-oversubscribe 3 +thread-pool-prio-kickup-timer 1000 +thread-pool-priority auto +thread-pool-stall-limit 500 +thread-stack 299008 +time-format %H:%i:%s +timed-mutexes FALSE +tmp-disk-table-size 18446744073709551615 +tmp-memory-table-size 16777216 +tmp-table-size 16777216 +transaction-alloc-block-size 8192 +transaction-isolation REPEATABLE-READ +transaction-prealloc-size 4096 +transaction-read-only FALSE +updatable-views-with-limit YES +use-stat-tables NEVER +userstat FALSE +verbose TRUE +wait-timeout 28800 + +To see what values a running MySQL server is using, type +'mysqladmin variables' instead of 'mysqld --verbose --help'. diff --cc mysql-test/main/subselect_mat.result index 4d425d0,0000000..463ec53 mode 100644,000000..100644 --- a/mysql-test/main/subselect_mat.result +++ b/mysql-test/main/subselect_mat.result @@@ -1,2788 -1,0 +1,2788 @@@ +set @subselect_mat_test_optimizer_switch_value='materialization=on,in_to_exists=off,semijoin=off'; +set @subselect_sj_mat_tmp= @@optimizer_switch; +set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on,semijoin_with_cache=on'); +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +set @optimizer_switch_local_default= @@optimizer_switch; +set @save_join_cache_level=@@join_cache_level; +set join_cache_level=1; +drop table if exists t1, t2, t3, t4, t5, t1i, t2i, t3i; +drop table if exists columns; +drop table if exists t1_16, t2_16, t3_16; +drop view if exists v1, v2, v1m, v2m; +create table t1 (a1 char(8), a2 char(8)); +create table t2 (b1 char(8), b2 char(8)); +create table t3 (c1 char(8), c2 char(8)); +insert into t1 values ('1 - 00', '2 - 00'); +insert into t1 values ('1 - 01', '2 - 01'); +insert into t1 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 01', '2 - 01'); +insert into t2 values ('1 - 01', '2 - 01'); +insert into t2 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 03', '2 - 03'); +insert into t3 values ('1 - 01', '2 - 01'); +insert into t3 values ('1 - 02', '2 - 02'); +insert into t3 values ('1 - 03', '2 - 03'); +insert into t3 values ('1 - 04', '2 - 04'); +create table t1i (a1 char(8), a2 char(8)); +create table t2i (b1 char(8), b2 char(8)); +create table t3i (c1 char(8), c2 char(8)); +create index it1i1 on t1i (a1); +create index it1i2 on t1i (a2); +create index it1i3 on t1i (a1, a2); +create index it2i1 on t2i (b1); +create index it2i2 on t2i (b2); +create index it2i3 on t2i (b1, b2); +create index it3i1 on t3i (c1); +create index it3i2 on t3i (c2); +create index it3i3 on t3i (c1, c2); +insert into t1i select * from t1; +insert into t2i select * from t2; +insert into t3i select * from t3; +set @@optimizer_switch='materialization=on,in_to_exists=off,firstmatch=off'; +/****************************************************************************** +* Simple tests. +******************************************************************************/ +# non-indexed nullable fields +explain extended +select * from t1 where a1 in (select b1 from t2 where b1 > '0'); +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 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +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`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1`)))) +select * from t1 where a1 in (select b1 from t2 where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); +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 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +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`>(<in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (/* select#2 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1`)))) +select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); +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 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +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 `test`.`t2`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) +select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); +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 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary +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`,min(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`b1` > '0' group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`min(b2)`)))) +select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +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 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'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # 18 # 3 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # 9 # 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`>(<in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (/* select#2 */ select max(`test`.`t2i`.`b1`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`max(b1)`)))) +select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +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 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'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # # # 3 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # # # 3 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`,max(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`max(b2)`)))) +select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index NULL # # # 3 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # # # 3 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`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key where `test`.`t1i`.`a1` = `<subquery2>`.`b1` and `test`.`t1i`.`a2` = `<subquery2>`.`min(b2)`)))) +select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1); +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 +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 100.00 Using index for group-by +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`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`max(b2)`)))) +select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +prepare st1 from "explain select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)"; +execute st1; +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 t2i range NULL it2i3 9 NULL 3 Using index for group-by +execute st1; +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 t2i range NULL it2i3 9 NULL 3 Using index for group-by +prepare st2 from "select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)"; +execute st2; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +execute st2; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +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 +2 MATERIALIZED t2i range it2i1,it2i3 it2i3 18 NULL 3 100.00 Using where; Using index for group-by +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`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`min(b2)`)))) +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1); +ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +prepare st1 from +"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +prepare st1 from +"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@save_optimizer_switch; +explain extended +select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2); +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 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +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` order by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery2>`.`b1` and `test`.`t1`.`a2` = `<subquery2>`.`b2`)))) +select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +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 t1i index NULL it1i3 18 NULL 3 100.00 Using where; Using index +2 MATERIALIZED t2i index NULL it2i3 18 NULL 5 100.00 Using index +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` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <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 order by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +/****************************************************************************** +* Views, UNIONs, several levels of nesting. +******************************************************************************/ +# materialize the result of subquery over temp-table view +create algorithm=merge view v1 as +select b1, c2 from t2, t3 where b2 > c2; +create algorithm=merge view v2 as +select b1, c2 from t2, t3 group by b2, c2; +Warnings: +Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) +create algorithm=temptable view v1m as +select b1, c2 from t2, t3 where b2 > c2; +create algorithm=temptable view v2m as +select b1, c2 from t2, t3 group by b2, c2; +select * from v1 where (c2, b1) in (select c2, b1 from v2 where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1 where (c2, b1) in (select distinct c2, b1 from v2 where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1m where (c2, b1) in (select c2, b1 from v2m where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1m where (c2, b1) in (select distinct c2, b1 from v2m where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +drop view v1, v2, v1m, v2m; +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and +(a1, a2) in (select c1, c2 from t3 +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 100.00 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +4 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +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 `test`.`t2`.`b1` > '0' ), <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#3 */ 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#4 */ 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` = `<subquery4>`.`b1` and `test`.`t3`.`c2` = `<subquery4>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery3>`.`c1` and `test`.`t1`.`a2` = `<subquery3>`.`c2`)))) +select * from t1 +where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i +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 index NULL # # # 3 100.00 # +3 MATERIALIZED t3i index NULL # # # 4 100.00 # +4 MATERIALIZED t2i index it2i2 # # # 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`.`t2 i`.`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 +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')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 +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 100.00 Using where +5 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +6 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +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`)))) ), <primar y_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`))) ) +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 02 2 - 02 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +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 100.00 Using where +5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 100.00 Using where +6 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +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` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<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 <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`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`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where <expr_cache><`test`.`t3c`.`c1`,`test`.`t3c`.`c2`>(<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),(`test`.`t3c`.`c1`,`test`.`t3c`.`c2`) in ( <materialize> (/* select#6 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` where `test`.`t2i`.`b2` > '0' ), <primary_index_lookup>(`test`.`t3c`.`c1` in <temporary table> on distinct_key where `test`.`t3c`.`c1` = `<subquery6>`.`b1` and `test`.`t3c`.`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`)))) +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +(select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03') +group by b1, b2) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))) +UNION +(select * from t1i +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 t1 ALL NULL # # # 3 100.00 # +5 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +6 MATERIALIZED t2i index it2i2 # # # 5 100.00 # +2 MATERIALIZED t2 ALL NULL # # # 5 100.00 # +4 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +3 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +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 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`)))) ), <prima ry_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`)) ))) unio n (/* 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`))))) +(select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03') +group by b1, b2) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))) +UNION +(select * from t1i +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'))); +a1 a2 +1 - 02 2 - 02 +1 - 01 2 - 01 +explain extended +select * from t1 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(a1, a2) in (select c1, c2 from t3 +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 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL 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`),<exists>(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1` and <cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`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#4 */ 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`) i n ( <materialize> (/* select#5 */ 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` = `<subquery5>`.`b1` and `test`.`t3`.`c2` = `<subquery5>`.`b2`)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where `test`.`t1`.`a1` = `<subquery4>`.`c1` and `test`.`t1`.`a2` = `<subquery4>`.`c2`)))) +select * from t1 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1, t3 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(c1, c2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and +a1 = c1; +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 t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` join `test`.`t3` where `test`.`t3`.`c1` = `test`.`t1`.`a1` and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1` and <cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <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#4 */ 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#5 */ 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` = `<subquery5>`.`b1` and `test`.`t3`.`c2` = `<subquery5>`.`b2`)))) ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where `test`.`t3`.`c1` = `<subquery4>`.`c1` and `test`.`t3`.`c2` = `<subquery4>`.`c2`)))) +select * from t1, t3 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(c1, c2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and +a1 = c1; +a1 a2 c1 c2 +1 - 01 2 - 01 1 - 01 2 - 01 +1 - 02 2 - 02 1 - 02 2 - 02 +/****************************************************************************** +* Negative tests, where materialization should not be applied. +******************************************************************************/ +# UNION in a subquery +explain extended +select * from t3 +where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`>(<in_optimizer>(`test`.`t3`.`c1`,<exists>(/* select#2 */ select `test`.`t1`.`a1` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1` union /* select#3 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))) +select * from t3 +where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); +c1 c2 +1 - 01 2 - 01 +1 - 02 2 - 02 +1 - 03 2 - 03 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +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 +5 DEPENDENT SUBQUERY t3c ALL NULL NULL NULL NULL 4 100.00 Using where +6 DEPENDENT SUBQUERY t2i index_subquery it2i1,it2i2,it2i3 it2i3 18 func,func 2 100.00 Using index; Using where +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where +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` where <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where (<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 <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and <expr_cache> <`test`. `t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#5 */ select `test`.`t3c`.`c1`,`test`.`t3c`.`c2` from `test`.`t3` `t3c` where <expr_cache><`test`.`t3c`.`c1`,`test`.`t3c`.`c2`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),<exists>(<index_lookup>(<cache>(`test`.`t3c`.`c1`) in t2i on it2i3 where (`test`.`t2i`.`b2` > '0' or `test`.`t2i`.`b2` = `test`.`t1`.`a2`) and <cache>(`test`.`t3c`.`c1`) = `test`.`t2i`.`b1` and <cache>(`test`.`t3c`.`c2`) = `test`.`t2i`.`b2`)))) and <cache>(`test`.`t1`.`a1`) = `test`.`t3c`.`c1` and <cache>(`test`.`t1`.`a2`) = `test`.`t3c`.`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 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +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`),<exists>(/* select#2 */ select '1 - 01','2 - 01' having (<cache>(`test`.`t1`.`a1`) = '1 - 01' or '1 - 01' is null) and (<cache>(`test`.`t1`.`a2`) = '2 - 01' or '2 - 01' is null) and '1 - 01' is null and '2 - 01' is null))) +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01'); +a1 a2 +1 - 01 2 - 01 +explain extended +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual); +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 +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +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`),<exists>(/* select#2 */ select '1 - 01','2 - 01' having (<cache>(`test`.`t1`.`a1`) = '1 - 01' or '1 - 01' is null) and (<cache>(`test`.`t1`.`a2`) = '2 - 01' or '2 - 01' is null) and '1 - 01' is null and '2 - 01' is null))) +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual); +a1 a2 +1 - 01 2 - 01 +/****************************************************************************** +* Subqueries in other uncovered clauses. +******************************************************************************/ +/* SELECT clause */ +select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1; +((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL +0 +0 +0 +/* GROUP BY clause */ +create table columns (col int key); +insert into columns values (1), (2); +explain extended +select * from t1 group by (select col from columns limit 1); +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 +2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by (/* select#2 */ select `test`.`columns`.`col` from `test`.`columns` limit 1) +select * from t1 group by (select col from columns limit 1); +a1 a2 +1 - 00 2 - 00 +explain extended +select * from t1 group by (a1 in (select col from columns)); +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 temporary; Using filesort +2 DEPENDENT SUBQUERY columns unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where; Full scan on NULL key +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond(<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`))))) +select * from t1 group by (a1 in (select col from columns)); +a1 a2 +1 - 00 2 - 00 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '1 - 00' +Warning 1292 Truncated incorrect DOUBLE value: '1 - 01' +Warning 1292 Truncated incorrect DOUBLE value: '1 - 02' +/* ORDER BY clause */ +explain extended +select * from t1 order by (select col from columns limit 1); +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 +2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` order by (/* select#2 */ select `test`.`columns`.`col` from `test`.`columns` limit 1) +select * from t1 order by (select col from columns limit 1); +a1 a2 +1 - 00 2 - 00 +1 - 01 2 - 01 +1 - 02 2 - 02 +/****************************************************************************** +* Column types/sizes that affect materialization. +******************************************************************************/ +/* +Test that BLOBs are not materialized (except when arguments of some functions). +*/ +# force materialization to be always considered +set @prefix_len = 6; +set @blob_len = 16; +set @suffix_len = @blob_len - @prefix_len; +create table t1_16 (a1 blob(16), a2 blob(16)); +create table t2_16 (b1 blob(16), b2 blob(16)); +create table t3_16 (c1 blob(16), c2 blob(16)); +insert into t1_16 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select b1 from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select `test`.`t2_16`.`b1` from `test`.`t2_16` where `test`.`t2_16`.`b1` > '0' and <cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select b1 from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`>(<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(/* select#2 */ select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` where `test`.`t2_16`.`b1` > '0' and <cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1` and <cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))) +select left(a1,7), left(a2,7) +from t1_16 +where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (/* select#2 */ select substr(`test`.`t2_16`.`b1`,1,16) from `test`.`t2_16` where `test`.`t2_16`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where `test`.`t1_16`.`a1` = `<subquery2>`.`substring(b1,1,16)`)))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having <cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ','))))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` ), <primary_index_lookup>(`test`.`t1_16`.`a1` in <temporary table> on distinct_key where `test`.`t1_16`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended +select * from t1 +where concat(a1,'x') IN +(select left(a1,8) from t1_16 +where (a1, a2) IN +(select t2_16.b1, t2_16.b2 from t2_16, t2 +where t2.b2 = substring(t2_16.b2,1,6) and +t2.b1 IN (select c1 from t3 where c2 > '0'))); +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 +2 DEPENDENT SUBQUERY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer (flat, BNL join) +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <expr_cache><concat(`test`.`t1`.`a1`,'x')>(<in_optimizer>(concat(`test`.`t1`.`a1`,'x'),<exists>(/* select#2 */ select left(`test`.`t1_16`.`a1`,8) from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`>(<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(/* select#3 */ select `test`.`t2_16`.`b1`,`test`.`t2_16`.`b2` from `test`.`t2_16` join `test`.`t2` where `test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6) and <expr_cache><`test`.`t2`.`b1`>(<in_optimizer>(`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( <materialize> (/* select#4 */ select `test`.`t3`.`c1` from `test`.`t3` where `test`.`t3`.`c2` > '0' ), <primary_index_lookup>(`test`.`t2`.`b1` in <temporary table> on distinct_key where `test`.`t2`.`b1` = `<subquery4>`.`c1`)))) and <cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1` and <cache>(`test`.`t1_16`.`a2`) = `test`.`t2_16`.`b2`))) and < cache>(c oncat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8)))) +drop table t1_16, t2_16, t3_16; +set @blob_len = 512; +set @suffix_len = @blob_len - @prefix_len; +create table t1_512 (a1 blob(512), a2 blob(512)); +create table t2_512 (b1 blob(512), b2 blob(512)); +create table t3_512 (c1 blob(512), c2 blob(512)); +insert into t1_512 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select b1 from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,<exists>(/* select#2 */ select `test`.`t2_512`.`b1` from `test`.`t2_512` where `test`.`t2_512`.`b1` > '0' and <cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select b1 from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`>(<in_optimizer>((`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`),<exists>(/* select#2 */ select `test`.`t2_512`.`b1`,`test`.`t2_512`.`b2` from `test`.`t2_512` where `test`.`t2_512`.`b1` > '0' and <cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1` and <cache>(`test`.`t1_512`.`a2`) = `test`.`t2_512`.`b2`))) +select left(a1,7), left(a2,7) +from t1_512 +where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select substr(`test`.`t2_512`.`b1`,1,512) from `test`.`t2_512` where `test`.`t2_512`.`b1` > '0' ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where `test`.`t1_512`.`a1` = `<subquery2>`.`substring(b1,1,512)`)))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where `test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` where <expr_cache><`test`.`t1_512`.`a1`>(<in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2` ), <primary_index_lookup>(`test`.`t1_512`.`a1` in <temporary table> on distinct_key where `test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_512, t2_512, t3_512; +set @blob_len = 1024; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1024 (a1 blob(1024), a2 blob(1024)); +create table t2_1024 (b1 blob(1024), b2 blob(1024)); +create table t3_1024 (c1 blob(1024), c2 blob(1024)); +insert into t1_1024 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select b1 from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(/* select#2 */ select `test`.`t2_1024`.`b1` from `test`.`t2_1024` where `test`.`t2_1024`.`b1` > '0' and <cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select b1 from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`>(<in_optimizer>((`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`),<exists>(/* select#2 */ select `test`.`t2_1024`.`b1`,`test`.`t2_1024`.`b2` from `test`.`t2_1024` where `test`.`t2_1024`.`b1` > '0' and <cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1` and <cache>(`test`.`t1_1024`.`a2`) = `test`.`t2_1024`.`b2`))) +select left(a1,7), left(a2,7) +from t1_1024 +where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(/* select#2 */ select substr(`test`.`t2_1024`.`b1`,1,1024) from `test`.`t2_1024` where `test`.`t2_1024`.`b1` > '0' and <cache>(`test`.`t1_1024`.`a1`) = substr(`test`.`t2_1024`.`b1`,1,1024)))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where `test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` where <expr_cache><`test`.`t1_1024`.`a1`>(<in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2` ), <primary_index_lookup>(`test`.`t1_1024`.`a1` in <temporary table> on distinct_key where `test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_1024, t2_1024, t3_1024; +set @blob_len = 1025; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1025 (a1 blob(1025), a2 blob(1025)); +create table t2_1025 (b1 blob(1025), b2 blob(1025)); +create table t3_1025 (c1 blob(1025), c2 blob(1025)); +insert into t1_1025 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select b1 from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(/* select#2 */ select `test`.`t2_1025`.`b1` from `test`.`t2_1025` where `test`.`t2_1025`.`b1` > '0' and <cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select b1 from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`>(<in_optimizer>((`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`),<exists>(/* select#2 */ select `test`.`t2_1025`.`b1`,`test`.`t2_1025`.`b2` from `test`.`t2_1025` where `test`.`t2_1025`.`b1` > '0' and <cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1` and <cache>(`test`.`t1_1025`.`a2`) = `test`.`t2_1025`.`b2`))) +select left(a1,7), left(a2,7) +from t1_1025 +where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(/* select#2 */ select substr(`test`.`t2_1025`.`b1`,1,1025) from `test`.`t2_1025` where `test`.`t2_1025`.`b1` > '0' and <cache>(`test`.`t1_1025`.`a1`) = substr(`test`.`t2_1025`.`b1`,1,1025)))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where `test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` where <expr_cache><`test`.`t1_1025`.`a1`>(<in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2` ), <primary_index_lookup>(`test`.`t1_1025`.`a1` in <temporary table> on distinct_key where `test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)`)))) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_1025, t2_1025, t3_1025; +create table t1bit (a1 bit(3), a2 bit(3)); +create table t2bit (b1 bit(3), b2 bit(3)); +insert into t1bit values (b'000', b'100'); +insert into t1bit values (b'001', b'101'); +insert into t1bit values (b'010', b'110'); +insert into t2bit values (b'001', b'101'); +insert into t2bit values (b'010', b'110'); +insert into t2bit values (b'110', b'111'); +explain extended select bin(a1), bin(a2) +from t1bit +where (a1, a2) in (select b1, b2 from t2bit); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1bit ALL NULL NULL NULL NULL 3 100.00 Using where +2 MATERIALIZED t2bit ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 /* select#1 */ select conv(`test`.`t1bit`.`a1`,10,2) AS `bin(a1)`,conv(`test`.`t1bit`.`a2`,10,2) AS `bin(a2)` from `test`.`t1bit` where <expr_cache><`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`>(<in_optimizer>((`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`),(`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`) in ( <materialize> (/* select#2 */ select `test`.`t2bit`.`b1`,`test`.`t2bit`.`b2` from `test`.`t2bit` ), <primary_index_lookup>(`test`.`t1bit`.`a1` in <temporary table> on distinct_key where `test`.`t1bit`.`a1` = `<subquery2>`.`b1` and `test`.`t1bit`.`a2` = `<subquery2>`.`b2`)))) +select bin(a1), bin(a2) +from t1bit +where (a1, a2) in (select b1, b2 from t2bit); +bin(a1) bin(a2) +1 101 +10 110 +drop table t1bit, t2bit; +create table t1bb (a1 bit(3), a2 blob(3)); +create table t2bb (b1 bit(3), b2 blob(3)); +insert into t1bb values (b'000', '100'); +insert into t1bb values (b'001', '101'); +insert into t1bb values (b'010', '110'); +insert into t2bb values (b'001', '101'); +insert into t2bb values (b'010', '110'); +insert into t2bb values (b'110', '111'); +explain extended select bin(a1), a2 +from t1bb +where (a1, a2) in (select b1, b2 from t2bb); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1bb ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2bb ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` where <expr_cache><`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`>(<in_optimizer>((`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`),<exists>(/* select#2 */ select `test`.`t2bb`.`b1`,`test`.`t2bb`.`b2` from `test`.`t2bb` where <cache>(`test`.`t1bb`.`a1`) = `test`.`t2bb`.`b1` and <cache>(`test`.`t1bb`.`a2`) = `test`.`t2bb`.`b2`))) +select bin(a1), a2 +from t1bb +where (a1, a2) in (select b1, b2 from t2bb); +bin(a1) a2 +1 101 +10 110 +drop table t1bb, t2bb; +drop table t1, t2, t3, t1i, t2i, t3i, columns; +/****************************************************************************** +* Test the cache of the left operand of IN. +******************************************************************************/ +# Test that default values of Cached_item are not used for comparison +create table t1 (s1 int); +create table t2 (s2 int); +insert into t1 values (5),(1),(0); +insert into t2 values (0), (1); +select s2 from t2 where s2 in (select s1 from t1); +s2 +0 +1 +drop table t1, t2; +create table t1 (a int not null, b int not null); +create table t2 (c int not null, d int not null); +create table t3 (e int not null); +insert into t1 values (1,10); +insert into t1 values (1,20); +insert into t1 values (2,10); +insert into t1 values (2,20); +insert into t1 values (2,30); +insert into t1 values (3,20); +insert into t1 values (4,40); +insert into t2 values (2,10); +insert into t2 values (2,20); +insert into t2 values (2,40); +insert into t2 values (3,20); +insert into t2 values (4,10); +insert into t2 values (5,10); +insert into t3 values (10); +insert into t3 values (10); +insert into t3 values (20); +insert into t3 values (30); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +create index it1a on t1(a); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +insert into t2 values (1,10); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +explain extended +select a from t1 group by a having a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 group by a having a in (select c from t2 where d >= 20); +a +2 +3 +create index iab on t1(a, b); +explain extended +select a from t1 group by a having a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 group by a having a in (select c from t2 where d >= 20); +a +2 +3 +explain extended +select a from t1 group by a +having a in (select c from t2 where d >= some(select e from t3 where max(b)=e)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where +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 1981 Aggregate function 'max()' of SELECT #3 belongs to SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`,max(`test`.`t1`.`b`),max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`,max(`test`.`t1`.`b`),max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where max(`test`.`t1`.`b`) = `test`.`t3`.`e` having <cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`))))) and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))) +select a from t1 group by a +having a in (select c from t2 where d >= some(select e from t3 where max(b)=e)); +a +2 +3 +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 t1 index NULL iab 8 NULL 7 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where +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` where <expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where <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`)))) and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))) +select a from t1 +where a in (select c from t2 where d >= some(select e from t3 where b=e)); +a +1 +2 +2 +2 +3 +drop table t1, t2, t3; +create table t2 (a int, b int, key(a), key(b)); +insert into t2 values (3,3),(3,3),(3,3); +select 1 from t2 where +t2.a > 1 +or +t2.a = 3 and not t2.a not in (select t2.b from t2); +1 +1 +1 +1 +drop table t2; +create table t1 (a1 int key); +create table t2 (b1 int); +insert into t1 values (5); +explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +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 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +min(a1) +NULL +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +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 NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +min(a1) +NULL +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +explain select min(a1) from t1 where 7 in (select b1 from t2); +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 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2); +min(a1) +NULL +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +# with MariaDB and MWL#90, this particular case is solved: +explain select min(a1) from t1 where 7 in (select b1 from t2); +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 NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2); +min(a1) +NULL +# but when we go around MWL#90 code, the problem still shows up: +explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; +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 NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; +min(a1) +NULL +set @@optimizer_switch= @save_optimizer_switch; +drop table t1,t2; +create table t1 (a char(2), b varchar(10)); +insert into t1 values ('a', 'aaa'); +insert into t1 values ('aa', 'aaaa'); +explain select a,b from t1 where b in (select a from t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +select a,b from t1 where b in (select a from t1); +a b +prepare st1 from "select a,b from t1 where b in (select a from t1)"; +execute st1; +a b +execute st1; +a b +drop table t1; +# +# BUG#49630: Segfault in select_describe() with double +# nested subquery and materialization +# +CREATE TABLE t1 (t1i int); +CREATE TABLE t2 (t2i int); +CREATE TABLE t3 (t3i int); +CREATE TABLE t4 (t4i int); +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1),(2); +INSERT INTO t3 VALUES (1),(2); +INSERT INTO t4 VALUES (1),(2); + +EXPLAIN +SELECT t1i +FROM t1 JOIN t4 ON t1i=t4i +WHERE (t1i) IN ( +SELECT t2i +FROM t2 +WHERE (t2i) IN ( +SELECT max(t3i) +FROM t3 +GROUP BY t3i +) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using temporary +DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +) +; +INSERT INTO t1 ( +col_int_key, col_int_nokey, col_varchar_key +) +VALUES +(2, NULL, 'w'), +(9, 7, 'm'), +(3, 9, 'm'), +(9, 7, 'k'), +(NULL, 4, 'r'), +(9, 2, 't'), +(3, 6, 'j'), +(8, 8, 'u'), +(8, NULL, 'h'), +(53, 5, 'o'), +(0, NULL, NULL), +(5, 6, 'k'), +(166, 188, 'e'), +(3, 2, 'n'), +(0, 1, 't'), +(1, 1, 'c'), +(9, 0, 'm'), +(5, 9, 'y'), +(6, NULL, 'f'), +(2, 4, 'd') +; +SELECT table2.col_varchar_key AS field1, +table2.col_int_nokey AS field2 +FROM ( t1 AS table1 LEFT OUTER JOIN t1 AS table2 +ON (table2.col_varchar_key = table1.col_varchar_key ) ) +WHERE table1.pk = 6 +HAVING ( field2 ) IN +( SELECT SUBQUERY2_t2.col_int_nokey AS SUBQUERY2_field2 +FROM ( t1 AS SUBQUERY2_t1 JOIN t1 AS SUBQUERY2_t2 +ON (SUBQUERY2_t2.col_varchar_key = SUBQUERY2_t1.col_varchar_key ) ) ) +ORDER BY field2 +; +field1 field2 +t 1 +t 2 +drop table t1; +# +# BUG#53103: MTR test ps crashes in optimize_cond() +# when running with --debug +# +CREATE TABLE t1(track varchar(15)); +INSERT INTO t1 VALUES ('CAD'), ('CAD'); +PREPARE STMT FROM +"SELECT 1 FROM t1 + WHERE + track IN (SELECT track FROM t1 + GROUP BY track + HAVING track>='CAD')"; +EXECUTE STMT ; +1 +1 +1 +EXECUTE STMT ; +1 +1 +1 +DEALLOCATE PREPARE STMT; +DROP TABLE t1; +# End of BUG#53103 +# +# BUG#54511 - Assertion failed: cache != 0L in file +# sql_select.cc::sub_select_cache on HAVING +# +CREATE TABLE t1 (i int(11)); +CREATE TABLE t2 (c char(1)); +CREATE TABLE t3 (c char(1)); +INSERT INTO t1 VALUES (1), (2); +INSERT INTO t2 VALUES ('a'), ('b'); +INSERT INTO t3 VALUES ('x'), ('y'); +SELECT COUNT( i ),i +FROM t1 +HAVING ('c') +IN (SELECT t2.c FROM (t2 JOIN t3)); +COUNT( i ) i +DROP TABLE t1,t2,t3; +# End BUG#54511 +# +# BUG#56367 - Assertion exec_method != EXEC_MATERIALIZATION... +# on subquery in FROM +# +CREATE TABLE t1 (a INTEGER); +CREATE TABLE t2 (b INTEGER); +INSERT INTO t2 VALUES (1); +set @tmp_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +explain SELECT a FROM ( +SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a > 3 OR t2.b IN (SELECT a FROM t1) +) table1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT a FROM ( +SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a > 3 OR t2.b IN (SELECT a FROM t1) +) table1; +a +set optimizer_switch=@tmp_optimizer_switch; +DROP TABLE t1, t2; +# End BUG#56367 +# +# Bug#59833 - materialization=on/off leads to different result set +# when using IN +# +CREATE TABLE t1 ( +pk int NOT NULL, +f1 int DEFAULT NULL, +PRIMARY KEY (pk) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +pk int NOT NULL, +f1 int DEFAULT NULL, +PRIMARY KEY (pk) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (10,0); +INSERT INTO t2 VALUES (10,0),(11,0); +explain SELECT * FROM t1 JOIN t2 USING (f1) +WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER 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 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 system NULL NULL NULL NULL 1 +SELECT * FROM t1 JOIN t2 USING (f1) +WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER BY t1.f1); +f1 pk pk +DROP TABLE t1, t2; +# End Bug#59833 +# +# Bug#11852644 - CRASH IN ITEM_REF::SAVE_IN_FIELD ON SELECT DISTINCT +# +CREATE TABLE t1 ( +col_varchar_key varchar(1) DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_varchar_key (col_varchar_key)) +; +INSERT INTO t1 VALUES +('v','v'),('r','r'); +CREATE TABLE t2 ( +col_varchar_key varchar(1) DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_varchar_key(col_varchar_key)) +; +INSERT INTO t2 VALUES +('r','r'),('c','c'); +CREATE VIEW v3 AS SELECT * FROM t2; +SELECT DISTINCT alias2.col_varchar_key +FROM t1 AS alias1 JOIN v3 AS alias2 +ON alias2.col_varchar_key = alias1.col_varchar_key +HAVING col_varchar_key IN (SELECT col_varchar_nokey FROM t2) +; +col_varchar_key +r +DROP TABLE t1, t2; +DROP VIEW v3; +# End Bug#11852644 + +# Bug#12668294 - GROUP BY ON EMPTY RESULT GIVES EMPTY ROW +# INSTEAD OF NULL WHEN MATERIALIZATION ON + +CREATE TABLE t1 (col_int_nokey INT) ENGINE=MEMORY; +CREATE TABLE t2 (col_int_nokey INT) ENGINE=MEMORY; +INSERT INTO t2 VALUES (8),(7); +CREATE TABLE t3 (col_int_nokey INT) ENGINE=MEMORY; +INSERT INTO t3 VALUES (7); +SELECT MIN(t3.col_int_nokey),t1.col_int_nokey AS field3 +FROM t3 +LEFT JOIN t1 +ON t1.col_int_nokey +WHERE (194, 200) IN ( +SELECT SQ4_alias1.col_int_nokey, +SQ4_alias2.col_int_nokey +FROM t2 AS SQ4_alias1 +JOIN +t2 AS SQ4_alias2 +ON SQ4_alias2.col_int_nokey = 5 +) +GROUP BY field3 ; +MIN(t3.col_int_nokey) field3 +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; +CREATE TABLE t1 (f1 INT, f2 DECIMAL(5,3)) ENGINE=MyISAM; +INSERT INTO t1 (f1, f2) VALUES (1, 1.789); +INSERT INTO t1 (f1, f2) VALUES (13, 1.454); +INSERT INTO t1 (f1, f2) VALUES (10, 1.668); +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 VALUES (1, 1.789); +INSERT INTO t2 VALUES (13, 1.454); +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +SET @@optimizer_switch='semijoin=on,materialization=on'; +EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); +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 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); +COUNT(*) +2 +set @@optimizer_switch= @save_optimizer_switch; +DROP TABLE t1, t2; +CREATE TABLE t1 ( +pk int, +a varchar(1), +b varchar(4), +c varchar(4), +d varchar(4), +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'); +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +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 +SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +pk +2 +SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); +pk +2 +DROP TABLE t1, t2; +set optimizer_switch=@save_optimizer_switch; +# +# BUG#50019: Wrong result for IN-subquery with materialization +# +create table t1(i int); +insert into t1 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +create table t2(i int); +insert into t2 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +create table t3(i int); +insert into t3 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5); +i +1 +2 +3 +4 +set @save_optimizer_switch=@@optimizer_switch; +set session optimizer_switch='materialization=off,in_to_exists=on'; +select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5); +i +1 +2 +3 +4 +set session optimizer_switch=@save_optimizer_switch; +drop table t1, t2, t3; +create table t0 (a int); +insert into t0 values (0),(1),(2); +create table t1 (a int); +insert into t1 values (0),(1),(2); +explain select a, a in (select a from t1) from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t0 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +select a, a in (select a from t1) from t0; +a a in (select a from t1) +0 1 +1 1 +2 1 +prepare s from 'select a, a in (select a from t1) from t0'; +execute s; +a a in (select a from t1) +0 1 +1 1 +2 1 +update t1 set a=123; +execute s; +a a in (select a from t1) +0 0 +1 0 +2 0 +drop table t0, t1; +set optimizer_switch='firstmatch=on'; +# +# MWL#90, review feedback: check what happens when the subquery +# looks like candidate for MWL#90 checking at the first glance +# but then subselect_hash_sj_engine::init_permanent() discovers +# that it's not possible to perform duplicate removal for the +# selected datatypes, and so materialization isn't applicable after +# all. +# +set @blob_len = 1024; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1024 (a1 blob(1024), a2 blob(1024)); +create table t2_1024 (b1 blob(1024), b2 blob(1024)); +insert into t1_1024 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +explain select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 Using where +select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +drop table t1_1024, t2_1024; +# +# BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization +# +CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ; +INSERT INTO t1 VALUES (2,'x'),(2,'x'),(2,'j'),(2,'c'); +CREATE TABLE t2 (a int, d varchar(1)) ; +INSERT INTO t2 VALUES (1,'x'); +CREATE TABLE t3 (d varchar(1)) ; +INSERT INTO t3 VALUES ('x'),('x'),('j'),('c'); +SELECT t2.a, t1.c +FROM t1, t2 +WHERE t2.d IN ( SELECT d FROM t3 ) +AND t1.d = t2.d +GROUP BY 1 , 2; +a c +1 2 +drop table t1,t2,t3; +# +# BUG#836523: Crash in JOIN::get_partial_cost_and_fanout with semijoin+materialization +# +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('a'),('a'); +CREATE TABLE t2 (a varchar(1)); +CREATE TABLE t3 (a int); +INSERT INTO t3 VALUES (1),(2); +CREATE TABLE t4 (a varchar(1)); +INSERT INTO t4 VALUES ('a'),('a'); +SELECT t1.a +FROM t1 +WHERE t1.a IN ( +SELECT t2.a +FROM t2, t3 +) +HAVING a IN ( +SELECT a +FROM t4 +); +a +DROP TABLE t1, t2, t3, t4; +# +# BUG#836507: Crash in setup_sj_materialization_part1() with semijoin+materialization +# +CREATE TABLE t1 (a int) ; +INSERT IGNORE INTO t1 VALUES (1),(1); +CREATE TABLE t2 (a int); +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 (a int); +CREATE TABLE t4 (a int); +INSERT INTO t4 VALUES (2),(2); +CREATE TABLE t5 (a int); +INSERT INTO t5 VALUES (1); +SELECT * FROM t1 +WHERE (a) IN ( +SELECT t5.a +FROM ( +t2 +LEFT JOIN ( t3 , t4 ) +ON 1 = 1 +) +JOIN t5 +); +a +1 +1 +DROP TABLE t1,t2,t3,t4,t5; +# +# BUG#836532: Crash in Item_equal_fields_iterator::get_curr_field with semijoin+materialization +# +CREATE TABLE t2 (a int); +INSERT IGNORE INTO t2 VALUES ('a'),('a'); +Warnings: +Warning 1366 Incorrect integer value: 'a' for column 'a' at row 1 +Warning 1366 Incorrect integer value: 'a' for column 'a' at row 2 +CREATE TABLE t4 (a varchar(1)); +INSERT INTO t4 VALUES ('m'),('o'); +CREATE TABLE t3 (a varchar(1) , b varchar(1) ) ; +INSERT INTO t3 VALUES ('b','b'); +CREATE TABLE t5 (a varchar(1), KEY (a)) ; +INSERT INTO t5 VALUES ('d'),('e'); +SELECT * +FROM t2 +WHERE t2.a = ALL ( +SELECT t4.a +FROM t4 +WHERE t4.a IN ( +SELECT t3.a +FROM t3 , t5 +WHERE ( t5.a = t3.b ) +) +); +a +0 +0 +DROP TABLE t2,t3,t4,t5; +# +# BUG#860300: Second crash with get_fanout_with_deps() with semijoin + materialization +# +set @tmp_860300=@@optimizer_switch; +set optimizer_switch='semijoin=on,materialization=on,loosescan=off,firstmatch=off'; +CREATE TABLE t1 (f2 int); +INSERT INTO t1 VALUES (9),(6); +CREATE TABLE t3 (f4 int); +CREATE TABLE t4 (f6 varchar(1)); +SELECT * +FROM t3 +WHERE 'h' IN (SELECT f6 +FROM t4 +WHERE 5 IN (SELECT f2 FROM t1) +GROUP BY t4.f6); +f4 +DROP TABLE t1,t3,t4; +set optimizer_switch=@tmp_860300; +# +# BUG#860535: Assertion `keypart_map' failed in mi_rkey with semijoin +# +set @tmp_860535=@@optimizer_switch; +set optimizer_switch='semijoin=on,materialization=on,loosescan=off,firstmatch=off'; +CREATE TABLE t1 (f3 int) ; +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (f3 int , f5 varchar(1), KEY (f3)) ; +INSERT INTO t2 VALUES (7,'b'); +CREATE TABLE t3 (f3 int , f4 varchar(1) , KEY(f3), KEY (f4,f3)) ; +INSERT INTO t3 VALUES (1,'t'),(7,'g'); +CREATE TABLE t4 +SELECT f3 +FROM t1 WHERE ( f3 ) NOT IN ( +SELECT f3 +FROM t2 +WHERE f5 IN ( +SELECT f4 +FROM t3 +WHERE t3.f3 < 3 +) +); +SELECT * FROM t4; +f3 +1 +7 +DROP TABLE t1, t2, t3, t4; +set optimizer_switch=@tmp_860535; +# +# BUG#860553: Crash in create_ref_for_key with semijoin + materialization +# +CREATE TABLE t1 (f1 int) ; +CREATE TABLE t2 (f5 varchar(52) NOT NULL) ; +CREATE TABLE t3 (f1 varchar(3), f4 varchar(52) , KEY (f4), PRIMARY KEY (f1)); +CREATE TABLE t4 (f3 int, KEY (f3)); +INSERT INTO t4 VALUES (17),(20); +CREATE TABLE t5 (f2 int); +INSERT INTO t5 VALUES (0),(0); +SELECT * +FROM t1 +JOIN t2 +ON ( t2.f5 ) IN ( +SELECT t3.f4 +FROM t3 +WHERE ( 1 ) IN ( +SELECT t4.f3 +FROM t4 , t5 +) +); +f1 f5 +DROP TABLE t1, t2, t3, t4, t5; +# +# BUG#868908: Crash in check_simple_equality() with semijoin + materialization + prepared statement +# +CREATE TABLE t1 ( a int ); +CREATE TABLE t3 ( b int, c int) ; +CREATE TABLE t2 ( a int ) ; +CREATE TABLE t4 ( a int , c int) ; +PREPARE st1 FROM " +SELECT STRAIGHT_JOIN * +FROM t1 +WHERE ( 3 ) IN ( + SELECT t3.b + FROM t3 + LEFT JOIN ( + t2 STRAIGHT_JOIN t4 ON ( t4.c = t2.a ) + ) ON ( t4.a = t3.c ) +); +"; +EXECUTE st1; +a +EXECUTE st1; +a +DROP TABLE t1,t2,t3,t4; +# +# BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin +# +CREATE TABLE t1 ( a INT, KEY(a) ); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (2); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (2); +SELECT MIN(a) FROM t1, t2 WHERE b IN (SELECT c FROM t3 GROUP BY c); +MIN(a) +1 +DROP TABLE t1,t2,t3; +# +# +# BUG#902632: Crash or invalid read at st_join_table::cleanup, st_table::disable_keyread +# +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1), (2); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (3), (4); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (5), (6); +SELECT * FROM t1 WHERE EXISTS ( +SELECT DISTINCT b FROM t2 +WHERE b <= a +AND b IN ( SELECT c FROM t3 GROUP BY c ) +); +a +DROP TABLE t1,t2,t3; +# +# BUG#901506: Crash in TABLE_LIST::print on EXPLAIN EXTENDED +# +CREATE TABLE t1 ( a INT, KEY(a) ); +INSERT INTO t1 VALUES (8); +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE a IN ( SELECT MIN(a) FROM t1 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 100.00 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 /* select#1 */ select 8 AS `a` from dual where <expr_cache><8>(<in_optimizer>(8,<exists>(/* select#2 */ select min(`test`.`t1`.`a`) from `test`.`t1` having <cache>(8) = <ref_null_helper>(min(`test`.`t1`.`a`))))) +DROP TABLE t1; +# +# BUG#904432: Wrong result with LEFT JOIN, constant table, semijoin=ON,materialization=ON +# +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4); +CREATE TABLE t2 ( b INT NOT NULL, c INT ); +INSERT INTO t2 VALUES (4,2),(4,2),(4,4),(1,1); +SELECT * FROM t1 LEFT JOIN t2 ON ( a = b ) +WHERE a IN ( SELECT c FROM t2 ); +a b c +4 4 2 +4 4 2 +4 4 4 +DROP TABLE t1,t2; +# +# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*) +# +CREATE TABLE t1 ( a VARCHAR(3) ); +CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) ); +INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron'); +EXPLAIN +SELECT * FROM +( SELECT * FROM t1 ) AS alias1, +t2 AS alias2 +WHERE b = a AND a IN ( +SELECT alias3.c +FROM t2 AS alias3, t2 AS alias4 +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 +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 +# +create table t1 (a int, b int); +insert into t1 values (7,5), (3,3), (5,4), (9,3); +create table t2 (a int, b int, index i_a(a)); +insert into t2 values +(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1); +explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 Using where +2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where +select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); +a b +7 5 +3 3 +drop table t1,t2; +# +# BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +SELECT STRAIGHT_JOIN MIN(a) FROM t1 +WHERE a IN ( +SELECT a FROM t1 +WHERE 'condition'='impossible' + ); +MIN(a) +NULL +DROP TABLE t1; +# +# BUG#938131: Subquery materialization is not used in CREATE TABLE SELECT +# +CREATE TABLE t1(a int); +INSERT INTO t1 values(1),(2); +CREATE TABLE t2(a int); +INSERT INTO t2 values(1),(2); +# Should use Materialization: +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using temporary +flush status; +CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +SHOW STATUS LIKE 'Created_tmp_tables'; +Variable_name Value +Created_tmp_tables 3 +DROP TABLE t1,t2,t3; +# +# BUG#939009: Crash with aggregate function in IN subquery +# +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='materialization=on,semijoin=on'; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (7,1), (4,2), (7,7); +CREATE TABLE t2 ( c INT ); +INSERT INTO t2 VALUES (4), (7), (6); +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) +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`) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(`<subquery2>`.`MAX(c)` 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 `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(`<subquery2>`.`MAX(c)` is null) or `<subquery2>`.`MAX(c)` = 7) +SELECT * FROM t1 +WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); +a b +7 7 +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) +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); +a b +SET optimizer_switch=@save_optimizer_switch; +DROP TABLE t1,t2; +# +# BUG#946055: Crash with semijoin IN subquery when hash join is used +# +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (7); +CREATE TABLE t2 (b int, c int, d varchar(1), e varchar(1), KEY (c), KEY (d, c)); +INSERT INTO t2 VALUES +(4,2,'v','v'), (6,1,'v','v'), (0,5,'x','x'), (7,1,'x','x'), +(7,3,'i','i'), (7,1,'e','e'), (1,4,'p','p'), (1,2,'j','j'); +SET @save_optimizer_switch=@@optimizer_switch; +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=2; +EXPLAIN +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +a c +7 1 +7 1 +7 1 +SET optimizer_switch='join_cache_hashed=on'; +SET join_cache_level=4; +EXPLAIN +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 index NULL c 5 NULL 8 Using where; Using index +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 ALL NULL NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +a c +7 1 +7 1 +7 1 +SET optimizer_switch=@save_optimizer_switch; +SET join_cache_level=@save_join_cache_level; +DROP TABLE t1,t2; +# +# BUG#952297: Server crashes on 2nd execution of PS in Field::is_null with semijoin+materialization +# +CREATE TABLE t1 ( a VARCHAR(1) ); +INSERT INTO t1 VALUES ('y'),('z'); +CREATE TABLE t2 ( b VARCHAR(1), c VARCHAR(1) ); +INSERT INTO t2 VALUES ('v','v'),('v','v'); +CREATE VIEW v2 AS SELECT * FROM t2; +PREPARE ps FROM ' +SELECT a FROM t1, v2 +WHERE ( c, b ) IN ( SELECT b, b FROM t2 ) +GROUP BY a '; +EXECUTE ps; +a +y +z +EXECUTE ps; +a +y +z +DROP VIEW v2; +DROP TABLE t1, t2; +# +# BUG#1000269: Wrong result (extra rows) with semijoin+materialization, IN subqueries, join_cache_level>0 +# +CREATE TABLE t1 (a1 VARCHAR(1), a2 VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('b','b'),('e','e'); +CREATE TABLE t2 (b1 VARCHAR(1), b2 VARCHAR(1), KEY(b1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('v','v'),('s','s'),('l','l'), ('y','y'),('c','c'),('i','i'); +SELECT * FROM t1, t2 WHERE b1 IN ( SELECT b2 FROM t2 WHERE b1 > 'o' ) AND ( b1 < 'l' OR a1 IN ('b','c') ); +a1 a2 b1 b2 +b b v v +b b s s +b b y y +DROP TABLE t1,t2; +# +# MDEV-4465: Reproducible crash (mysqld got signal 11) in multi_delete::initialize_tables with semijoin+materialization +# +CREATE TABLE t1 ( +id int(11) NOT NULL +); +CREATE TABLE t2 ( +id int(11) NOT NULL, +a_id int(11) DEFAULT NULL +); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 1), (2, 1), (3, 1), (4, 2), (5, 3), (6, 3), (7, 3); +delete t2 from t2 where a_id in (select * from (select t1.id from t1 limit 2) as x); +drop table t1,t2; +# This must be at the end: +set optimizer_switch=@subselect_sj_mat_tmp; +set join_cache_level=@save_join_cache_level; +# +# MDEV-4908: Assertion `((Item_cond *) cond)->functype() == +# ((Item_cond *) new_item)->functype()' fails on a query with +# IN and equal conditions, AND/OR, materialization+semijoin +# +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch = 'materialization=on,semijoin=on'; +CREATE TABLE t1 (pk INT, a INT, b INT, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,3,5),(2,4,6); +SELECT * FROM t1 WHERE 8 IN ( SELECT MIN(pk) FROM t1 ) AND ( pk = a OR pk = b ); +pk a b +drop table t1; +SET optimizer_switch=@save_optimizer_switch; +# +# MDEV-5011: ERROR Plugin 'MEMORY' has ref_count=1 after shutdown for SJM queries +# +CREATE TABLE t1 (pk INT, a INT, b INT, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,3,5),(2,4,6); +SELECT * FROM t1 WHERE 8 IN (SELECT MIN(pk) FROM t1) AND (pk = a OR pk = b); +pk a b +DROP TABLE t1; +# +# MDEV-5368: Server crashes in Item_in_subselect::optimize on 2nd +# execution of PS with IN subqueries, materialization+semijoin +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +INSERT INTO t2 VALUES (8),(9); +PREPARE stmt FROM " +SELECT * FROM t1 WHERE 1 IN ( SELECT b FROM v2 WHERE 2 IN ( SELECT MAX(a) FROM t1 ) ) +"; +EXECUTE stmt; +a +EXECUTE stmt; +a +DROP TABLE t1, t2; +DROP VIEW v2; +# +# MDEV-5811: Server crashes in best_access_path with materialization+semijoin and big_tables=ON +# +SET @tmp_mdev5811= @@big_tables; +SET big_tables = ON; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +SELECT * FROM t1 AS t1_1, t1 AS t1_2 +WHERE ( t1_1.a, t1_2.a ) IN ( SELECT MAX(b), MIN(b) FROM t2 ); +a a +DROP TABLE t1,t2; +SET big_tables=@tmp_mdev5811; +# End of 5.3 tests +# +# MDEV-5056: Wrong result (extra rows) with materialization+semijoin, IN subqueries +# +set @tmp_mdev5056=@@join_cache_level; +SET join_cache_level = 2; +CREATE TABLE t1 ( c1 VARCHAR(2), c2 VARCHAR(2), INDEX(c1) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES +('JP','OM'),('VA','JP'),('CA','ML'),('ML','EG'),('DK','CA'), +('DK','QA'),('YE','PL'),('TR','ZW'),('DK','SK'),('SK','DK'), +('RO','ML'),('ML','BG'),('BG','ZW'),('ZW','GE'),('GE','JP'), +('PL','EG'),('QA','YE'),('WF','DK'),('DK','JP'),('EG','OM'); +CREATE TABLE t2 ( c3 VARCHAR(2), c4 VARCHAR(2) ) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('CA','ML'),('IN','HU'),('HU','IN'); +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE ( alias2.c2, alias1.c1 ) IN ( SELECT c4, c3 FROM t2 ) AND alias1.c1 IN ( SELECT c2 FROM t1 ); +c1 c2 c1 c2 +CA ML CA ML +CA ML RO ML +DROP TABLE t1,t2; +set join_cache_level=@tmp_mdev5056; +# +# MDEV-5368: Server crashes in Item_in_subselect::optimize on 2nd +# execution of PS with IN subqueries, materialization+semijoin +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +INSERT INTO t2 VALUES (8),(9); +PREPARE stmt FROM " +SELECT * FROM t1 WHERE 1 IN ( SELECT b FROM v2 WHERE 2 IN ( SELECT MAX(a) FROM t1 ) ) +"; +EXECUTE stmt; +a +EXECUTE stmt; +a +DROP TABLE t1, t2; +DROP VIEW v2; +# +# MDEV-6289 : Unexpected results when querying information_schema +# +CREATE TABLE t1 ( +id int(11) unsigned NOT NULL AUTO_INCREMENT, +db varchar(254) NOT NULL DEFAULT '', +PRIMARY KEY (id), +UNIQUE KEY db (db) +) DEFAULT CHARSET=utf8; +INSERT INTO t1 (db) VALUES ('mysqltest1'),('mysqltest2'),('mysqltest3'),('mysqltest4'); +drop database if exists mysqltest1; +drop database if exists mysqltest2; +drop database if exists mysqltest3; +drop database if exists mysqltest4; +create database mysqltest1; +create database mysqltest2; +create database mysqltest3; +create database mysqltest4; +SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC; +db +mysqltest4 +mysqltest3 +mysqltest2 +mysqltest1 +EXPLAIN EXTENDED +SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC; +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 temporary; Using filesort +1 PRIMARY t1 eq_ref db db 764 information_schema.schemata.SCHEMA_NAME 1 100.00 Using where; Using index +2 MATERIALIZED schemata ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 select `test`.`t1`.`db` AS `db` from `test`.`t1` semi join (`information_schema`.`schemata`) where `test`.`t1`.`db` = `information_schema`.`schemata`.`SCHEMA_NAME` order by `test`.`t1`.`db` desc +drop table t1; +drop database mysqltest1; +drop database mysqltest2; +drop database mysqltest3; +drop database mysqltest4; +# +# MDEV-7810 Wrong result on execution of a query as a PS +# (both 1st and further executions) +CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM; +INSERT INTO t1 VALUES (0),(8); +SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2)); +a +0 +PREPARE stmt FROM " +SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2)) +"; +execute stmt; +a +0 +execute stmt; +a +0 +drop table t1; +# +# MDEV-12429: IN subquery used in WHERE of EXISTS subquery +# +CREATE TABLE t1 ( +pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7); +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +f2 +foo +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch='exists_to_in=off'; +EXPLAIN +SELECT sq1.f2 FROM t1 AS sq1 +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 +2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +# this checks the result set above +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +f2 +foo +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1; +# +# MDEV-12145: IN subquery used in WHERE of EXISTS subquery +# +CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (i2 INT, KEY(i2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(7),(1); +CREATE TABLE t3 (f3 INT, i3 INT, KEY(i3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (8,0),(6,3),(2,8),(3,8),(1,6),(0,0),(1,0),(1,5); +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch='exists_to_in=off'; +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +f1 +6 +EXPLAIN EXTENDED +SELECT * FROM t1 +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +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`)) +# this checks the result set above +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +f1 +6 +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1,t2,t3; +# +# MDEV-9686: IN subquery used in WHERE of a subquery from select list +# +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT); +INSERT INTO t1 VALUES (1, 4),(2, 3),(3, 3),(4, 6),(5, 3); +CREATE TABLE t2 (f2 INT); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5); +# t1.pk is always IN ( SELECT f2 FROM t2 ), +# so the IN condition should be true for every row, +# and thus COUNT(*) should always return 5 +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +pk f1 sq +1 4 5 +2 3 5 +3 3 5 +4 6 5 +5 3 5 +EXPLAIN EXTENDED +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +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` +# this checks the result set above +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +pk f1 sq +1 4 5 +2 3 5 +3 3 5 +4 6 5 +5 3 5 +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1,t2; +# +# mdev-12838: scan of materialized of semi-join subquery in join +# +set @save_optimizer_switch=@@optimizer_switch; +CREATE TABLE t1 ( +dispatch_group varchar(32), +assignment_group varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx1 (dispatch_group), +KEY idx2 (assignment_group) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +ugroup varchar(32), +user varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx3 (ugroup), +KEY idx4 (user) +) ENGINE=MyISAM; +CREATE TABLE t3 ( +type mediumtext, +sys_id char(32), +PRIMARY KEY (sys_id) +) ENGINE=MyISAM; +set optimizer_switch='materialization=off'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +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 t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +set optimizer_switch='materialization=on'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +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 t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +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 +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +DROP TABLE t1,t2,t3; +set optimizer_switch=@save_optimizer_switch; +# End of 5.5 tests +# +# MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +# +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; +create table t3 as select * from t2 limit 1; +# The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1000 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4000 Using temporary +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +# Sequential reads: +# 1K is read from t1 +# 4K is read from t2 +# 1K groups is read from the tmp. table +# +# Lookups: +# 4K lookups in group by table +# 1K lookups in temp.table +# +# Writes: +# 2x 1K writes to temporary tables (grouping table and subquery materialization table +# +# The point is that neither counter should be in the millions (this +# will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 5000 +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 6003 +Handler_tmp_write 2000 +Handler_write 1000 +drop table t0,t1,t2,t3; +# +# MDEV-7971: Assertion `name != __null' failed in ACL_internal_schema_registry::lookup +# on 2nd execution os PS with multi-table update +# +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (f3 INT); +INSERT INTO t3 VALUES (5),(6); +PREPARE stmt FROM ' + UPDATE t1, t2 + SET f1 = 5 + WHERE 8 IN ( SELECT MIN(f3) FROM t3 ) +'; +EXECUTE stmt; +EXECUTE stmt; +DROP TABLE t1,t2,t3; +# +# MDEV-10389: Query returns different results on a debug vs non-debug build of the same revision +# +CREATE TABLE t1 (i1 INT, i2 INT NOT NULL); +INSERT INTO t1 VALUES (1,4),(2,6); +SELECT * FROM t1 AS alias1 +WHERE alias1.i1 IN ( +SELECT i1 FROM t1 WHERE alias1.i2 IN ( SELECT i2 FROM t1 HAVING i2 <> 7 ) +); +i1 i2 +1 4 +2 6 +DROP TABLE t1; +set @subselect_mat_test_optimizer_switch_value=null; +set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +create table t0 (a int); +insert into t0 values (0),(1),(2); +create table t1 (a int); +insert into t1 values (0),(1),(2); +explain select a, a in (select a from t1) from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t0 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +select a, a in (select a from t1) from t0; +a a in (select a from t1) +0 1 +1 1 +2 1 +prepare s from 'select a, a in (select a from t1) from t0'; +execute s; +a a in (select a from t1) +0 1 +1 1 +2 1 +update t1 set a=123; +execute s; +a a in (select a from t1) +0 0 +1 0 +2 0 +drop table t0, t1; +# +# LPBUG#609121: RQG: wrong result on aggregate + NOT IN + HAVING and +# partial_match_table_scan=on +# +create table t1 (c1 int); +create table t2 (c2 int); +insert into t1 values (1); +insert into t2 values (2); +set @@optimizer_switch='semijoin=off'; +EXPLAIN +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 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 MATERIALIZED t2 system NULL NULL NULL NULL 1 +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2); +c1_sum +NULL +EXPLAIN +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2) HAVING c1_sum; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +2 MATERIALIZED t2 system NULL NULL NULL NULL 1 +SELECT SUM(c1) c1_sum FROM t1 WHERE c1 IN (SELECT c2 FROM t2) HAVING c1_sum; +c1_sum +drop table t1, t2; +# +# BUG#52344 - Subquery materialization: +# Assertion if subquery in on-clause of outer join +# +set @@optimizer_switch='semijoin=off'; +CREATE TABLE t1 (i INTEGER); +INSERT INTO t1 VALUES (10); +CREATE TABLE t2 (j INTEGER); +INSERT INTO t2 VALUES (5); +CREATE TABLE t3 (k INTEGER); +EXPLAIN +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where +2 MATERIALIZED t3 system NULL NULL NULL NULL 0 Const row not found +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT k FROM t3); +i +10 +EXPLAIN +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where +2 MATERIALIZED t3 system NULL NULL NULL NULL 0 Const row not found +SELECT i FROM t1 LEFT JOIN t2 ON (j) IN (SELECT max(k) FROM t3); +i +10 +DROP TABLE t1, t2, t3; +# +# LPBUG#611622/BUG#52344: Subquery materialization: Assertion +# if subquery in on-clause of outer join +# +CREATE TABLE t1 (c1 int); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (c2 int); +INSERT INTO t2 VALUES (10); +PREPARE st1 FROM " +SELECT * +FROM t2 LEFT JOIN t2 t3 ON (8, 4) IN (SELECT c1, c1 FROM t1)"; +EXECUTE st1; +c2 c2 +10 NULL +EXECUTE st1; +c2 c2 +10 NULL +DROP TABLE t1, t2; +# +# Testcase backport: BUG#46548 IN-subqueries return 0 rows with materialization=on +# +CREATE TABLE t1 ( +pk int, +a varchar(1), +b varchar(4), +c varchar(4), +d varchar(4), +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'); +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 +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 +SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +pk +2 +SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); +pk +2 +DROP TABLE t1, t2; +# +# BUG#724228: Wrong result with materialization=on and three aggregates in maria-5.3-mwl90 +# +CREATE TABLE t1 ( f2 int(11)) ; +INSERT IGNORE INTO t1 VALUES ('7'),('9'),('7'),('4'),('2'),('6'),('8'),('5'),('6'),('188'),('2'),('1'),('1'),('0'),('9'),('4'); +CREATE TABLE t2 ( f1 int(11), f2 int(11)) ENGINE=MyISAM; +INSERT IGNORE INTO t2 VALUES ('1','1'); +CREATE TABLE t3 ( f1 int(11), f2 int(11), f3 int(11), PRIMARY KEY (f1)) ; +INSERT IGNORE INTO t3 VALUES ('16','6','1'),('18','3','4'),('19',NULL,'9'),('20','0','6'),('41','2','0'),('42','2','5'),('43','9','6'),('44','7','4'),('45','1','4'),('46','222','238'),('47','3','6'),('48','6','6'),('49',NULL,'1'),('50','5','1'); +SET @_save_join_cache_level = @@join_cache_level; +SET @_save_optimizer_switch = @@optimizer_switch; +SET join_cache_level = 1; +SET optimizer_switch='materialization=on'; +SELECT f1 FROM t3 +WHERE +f1 NOT IN (SELECT MAX(f2) FROM t1) AND +f3 IN (SELECT MIN(f1) FROM t2) AND +f1 IN (SELECT COUNT(f2) FROM t1); +f1 +16 +SET @@join_cache_level = @_save_join_cache_level; +SET @@optimizer_switch = @_save_optimizer_switch; +drop table t1, t2, t3; +# +# LPBUG#719198 Ordered_key::cmp_key_with_search_key(rownum_t): Assertion `!compare_pred[i]->null_value' +# failed with subquery on both sides of NOT IN and materialization +# +CREATE TABLE t1 (f1a int, f1b int) ; +INSERT IGNORE INTO t1 VALUES (1,1),(2,2); +CREATE TABLE t2 ( f2 int); +INSERT IGNORE INTO t2 VALUES (3),(4); +CREATE TABLE t3 (f3a int, f3b int); +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off'; +EXPLAIN +SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t2 WHERE (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +f2 +EXPLAIN +SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT (SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1); +(SELECT f3a FROM t3) NOT IN (SELECT f1a FROM t1) +NULL +EXPLAIN +SELECT * FROM t2 WHERE (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT * FROM t2 WHERE (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +f2 +EXPLAIN +SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL No tables used +3 SUBQUERY t1 ALL NULL NULL NULL NULL 2 Using where +2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT (SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1); +(SELECT f3a, f3b FROM t3) NOT IN (SELECT f1a, f1b FROM t1) +NULL +drop table t1, t2, t3; +# +# LPBUG#730604 Assertion `bit < (map)->n_bits' failed in maria-5.3 with +# partial_match_rowid_merge +# +CREATE TABLE t1 (f1 int NOT NULL, f2 int, f3 int) ; +CREATE TABLE t2 (f1 int NOT NULL, f2 int, f3 int) ; +INSERT INTO t1 VALUES (60, 3, null), (61, null, 77); +INSERT INTO t2 VALUES (1000,6,2); +set @@optimizer_switch='materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off,in_to_exists=off'; +EXPLAIN +SELECT (f1, f2, f3) NOT IN +(SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +FROM t2; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 system NULL NULL NULL NULL 1 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 Using filesort +SELECT (f1, f2, f3) NOT IN +(SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +FROM t2; +(f1, f2, f3) NOT IN +(SELECT COUNT(DISTINCT f2), f1, f3 FROM t1 GROUP BY f1, f3) +1 +drop table t1, t2; +# +# LPBUG#702301: MAX in select + always false WHERE with SQ +# +CREATE TABLE t1 (a int, b int, KEY (b)); +INSERT INTO t1 VALUES (3,1), (4,2); +CREATE TABLE t2 (a int); +INSERT INTO t2 VALUES (7), (8); +set @@optimizer_switch='materialization=on,in_to_exists=off,semijoin=off'; +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +max_res +NULL +EXPLAIN EXTENDED +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 100.00 +Warnings: +Note 1003 /* select#1 */ select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 +set @@optimizer_switch='materialization=off,in_to_exists=on,semijoin=off'; +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +max_res +NULL +EXPLAIN EXTENDED +SELECT MAX(t1.b) AS max_res FROM t1 WHERE (9) IN (SELECT a FROM t2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +2 SUBQUERY t2 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select max(`test`.`t1`.`b`) AS `max_res` from `test`.`t1` where 0 +DROP TABLE t1,t2; +# +# LPBUG#825095: Wrong result with materialization and NOT IN with 2 expressions +# +CREATE TABLE t1 (a int,b int); +INSERT INTO t1 VALUES (4,4),(4,2); +CREATE TABLE t2 (b int, a int); +INSERT INTO t2 VALUES (4,3),(8,4); +set @@optimizer_switch='semijoin=off,in_to_exists=off,materialization=on,partial_match_rowid_merge=on,partial_match_table_scan=off'; +EXPLAIN SELECT * +FROM t1 +WHERE (a, b) NOT IN (SELECT a, b FROM t2); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT * +FROM t1 +WHERE (a, b) NOT IN (SELECT a, b FROM t2); +a b +4 4 +4 2 +EXPLAIN +SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq +FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT a, b, (a, b) NOT IN (SELECT a, b FROM t2) as sq +FROM t1; +a b sq +4 4 1 +4 2 1 +drop table t1, t2; +# +# MDEV-15235: Assertion `length > 0' failed in create_ref_for_key +# +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f CHAR(1)); +INSERT INTO t2 VALUES ('a'),('b'); +explain +SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 ); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 2 +SELECT * FROM t2 WHERE f IN ( SELECT LEFT('foo',0) FROM t1 ORDER BY 1 ); +f +DROP TABLE t1, t2; +# +# MDEV-9489: Assertion `0' failed in Protocol::end_statement() on +# UNION ALL +# +CREATE TABLE t1 (f1 INT); +CREATE TABLE t2 (f2 INT); +INSERT INTO t1 VALUES (1),(2); +( SELECT 1 FROM t1 WHERE f1 NOT IN ( SELECT f2 FROM t2 ) LIMIT 0 ) +UNION ALL +( SELECT 1 FROM t1 WHERE f1 NOT IN ( SELECT f2 FROM t2 ) ) +; +1 +1 +1 +drop table t1, t2; diff --cc mysql-test/main/subselect_sj_mat.result index 9e18708,0000000..6a4a1a4 mode 100644,000000..100644 --- a/mysql-test/main/subselect_sj_mat.result +++ b/mysql-test/main/subselect_sj_mat.result @@@ -1,2517 -1,0 +1,2517 @@@ +set @subselect_sj_mat_tmp= @@optimizer_switch; +set optimizer_switch=ifnull(@subselect_mat_test_optimizer_switch_value, 'semijoin=on,firstmatch=on,loosescan=on,semijoin_with_cache=on'); +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +set @optimizer_switch_local_default= @@optimizer_switch; +set @save_join_cache_level=@@join_cache_level; +set join_cache_level=1; +drop table if exists t1, t2, t3, t4, t5, t1i, t2i, t3i; +drop table if exists columns; +drop table if exists t1_16, t2_16, t3_16; +drop view if exists v1, v2, v1m, v2m; +create table t1 (a1 char(8), a2 char(8)); +create table t2 (b1 char(8), b2 char(8)); +create table t3 (c1 char(8), c2 char(8)); +insert into t1 values ('1 - 00', '2 - 00'); +insert into t1 values ('1 - 01', '2 - 01'); +insert into t1 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 01', '2 - 01'); +insert into t2 values ('1 - 01', '2 - 01'); +insert into t2 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 02', '2 - 02'); +insert into t2 values ('1 - 03', '2 - 03'); +insert into t3 values ('1 - 01', '2 - 01'); +insert into t3 values ('1 - 02', '2 - 02'); +insert into t3 values ('1 - 03', '2 - 03'); +insert into t3 values ('1 - 04', '2 - 04'); +create table t1i (a1 char(8), a2 char(8)); +create table t2i (b1 char(8), b2 char(8)); +create table t3i (c1 char(8), c2 char(8)); +create index it1i1 on t1i (a1); +create index it1i2 on t1i (a2); +create index it1i3 on t1i (a1, a2); +create index it2i1 on t2i (b1); +create index it2i2 on t2i (b2); +create index it2i3 on t2i (b1, b2); +create index it3i1 on t3i (c1); +create index it3i2 on t3i (c2); +create index it3i3 on t3i (c1, c2); +insert into t1i select * from t1; +insert into t2i select * from t2; +insert into t3i select * from t3; +set @@optimizer_switch='materialization=on,in_to_exists=off,firstmatch=off'; +/****************************************************************************** +* Simple tests. +******************************************************************************/ +# non-indexed nullable fields +explain extended +select * from t1 where a1 in (select b1 from t2 where b1 > '0'); +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 8 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b1` > '0' +select * from t1 where a1 in (select b1 from t2 where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); +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 8 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b1` > '0' +select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); +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 16 func,func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`b1` > '0' +select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); +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 <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2`.`b1`,min(`test`.`t2`.`b2`) from `test`.`t2` where `test`.`t2`.`b1` > '0' group by `test`.`t2`.`b1`) join `test`.`t1` where `<subquery2>`.`b1` = `test`.`t1`.`a1` and `<subquery2>`.`min(b2)` = `test`.`t1`.`a2` +select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +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 t2i index it2i1,it2i3 it2i1 # NULL 5 50.00 Using where; Using index; LooseScan +1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00 +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`.`t2i`.`b1` > '0' +select * from t1i where a1 in (select b1 from t2i where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index it1i1,it1i3 # 18 # 3 100.00 # +1 PRIMARY <subquery2> eq_ref distinct_key # 8 # 1 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # 9 # 5 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select max(`test`.`t2i`.`b1`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `<subquery2>`.`max(b1)` = `test`.`t1i`.`a1` +select * from t1i where a1 in (select max(b1) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +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 t2i index it2i1,it2i2,it2i3 it2i3 # NULL 5 50.00 Using where; Using index; LooseScan +1 PRIMARY t1i ref _it1_idx _it1_idx # _ref_ 1 100.00 +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` and `test`.`t2i`.`b1` > '0' +select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0'); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index it1i1,it1i2,it1i3 # # # 3 100.00 # +1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # # # 3 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `<subquery2>`.`b1` = `test`.`t1i`.`a1` and `<subquery2>`.`max(b2)` = `test`.`t1i`.`a2` +select * from t1i where (a1, a2) in (select b1, max(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1i index it1i1,it1i2,it1i3 # # # 3 100.00 # +1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 # +2 MATERIALIZED t2i range it2i1,it2i3 # # # 3 100.00 # +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1i` where `<subquery2>`.`b1` = `test`.`t1i`.`a1` and `<subquery2>`.`min(b2)` = `test`.`t1i`.`a2` +select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1); +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 <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 100.00 +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 100.00 Using index for group-by +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,max(`test`.`t2i`.`b2`) from `test`.`t2i` group by `test`.`t2i`.`b1`) join `test`.`t1` where `<subquery2>`.`b1` = `test`.`t1`.`a1` and `<subquery2>`.`max(b2)` = `test`.`t1`.`a2` +select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +prepare st1 from "explain select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)"; +execute st1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 Using index for group-by +execute st1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 +2 MATERIALIZED t2i range NULL it2i3 9 NULL 3 Using index for group-by +prepare st2 from "select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)"; +execute st2; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +execute st2; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +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 <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 100.00 +2 MATERIALIZED t2i range it2i1,it2i3 it2i3 18 NULL 3 100.00 Using where; Using index for group-by +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,min(`test`.`t2i`.`b2`) from `test`.`t2i` where `test`.`t2i`.`b1` > '0' group by `test`.`t2i`.`b1`) join `test`.`t1` where `<subquery2>`.`b1` = `test`.`t1`.`a1` and `<subquery2>`.`min(b2)` = `test`.`t1`.`a2` +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1); +ERROR 42000: This version of MariaDB doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +prepare st1 from +"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +prepare st1 from +"select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)"; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +execute st1; +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +set @@optimizer_switch=@save_optimizer_switch; +explain extended +select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2); +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 <subquery2> eq_ref distinct_key distinct_key 16 test.t1.a1,test.t1.a2 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` order by `test`.`t2`.`b1`,`test`.`t2`.`b2`) join `test`.`t1` where `<subquery2>`.`b1` = `test`.`t1`.`a1` and `<subquery2>`.`b2` = `test`.`t1`.`a2` +select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +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 t1i index it1i1,it1i2,it1i3 it1i3 18 NULL 3 100.00 Using where; Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 test.t1i.a1,test.t1i.a2 1 100.00 +2 MATERIALIZED t2i index NULL it2i3 18 NULL 5 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from <materialize> (/* select#2 */ select `test`.`t2i`.`b1`,`test`.`t2i`.`b2` from `test`.`t2i` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2`) join `test`.`t1i` where `<subquery2>`.`b1` = `test`.`t1i`.`a1` and `<subquery2>`.`b2` = `test`.`t1i`.`a2` +select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +/****************************************************************************** +* Views, UNIONs, several levels of nesting. +******************************************************************************/ +# materialize the result of subquery over temp-table view +create algorithm=merge view v1 as +select b1, c2 from t2, t3 where b2 > c2; +create algorithm=merge view v2 as +select b1, c2 from t2, t3 group by b2, c2; +Warnings: +Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm) +create algorithm=temptable view v1m as +select b1, c2 from t2, t3 where b2 > c2; +create algorithm=temptable view v2m as +select b1, c2 from t2, t3 group by b2, c2; +select * from v1 where (c2, b1) in (select c2, b1 from v2 where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1 where (c2, b1) in (select distinct c2, b1 from v2 where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1m where (c2, b1) in (select c2, b1 from v2m where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +select * from v1m where (c2, b1) in (select distinct c2, b1 from v2m where b1 is not null); +b1 c2 +1 - 02 2 - 01 +1 - 02 2 - 01 +1 - 03 2 - 01 +1 - 03 2 - 02 +drop view v1, v2, v1m, v2m; +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and +(a1, a2) in (select c1, c2 from t3 +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 100.00 +1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +3 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 80.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 `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 `test`.`t2`.`b1` > '0' and `test`.`t3`.`c2` > '0' +select * from t1 +where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1i +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 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 # # # 2 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`.`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 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 +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 100.00 +1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +5 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 80.00 Using where; Using index; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 Using where +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +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' +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 02 2 - 02 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +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 100.00 +1 PRIMARY <subquery5> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +5 MATERIALIZED t3c ALL NULL NULL NULL NULL 4 100.00 Using where +5 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 80.00 Using where; Using index; 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 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' +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +(select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 where c2 LIKE '%02') or +b2 in (select c2 from t3 where c2 LIKE '%03') +group by b1, b2) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))) +UNION +(select * from t1i +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 t1 ALL NULL # # # 3 100.00 # +1 PRIMARY <subquery5> eq_ref distinct_key # # # 1 100.00 # +1 PRIMARY <subquery2> eq_ref distinct_key # # # 1 100.00 # +5 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +5 MATERIALIZED t2i index it2i1,it2i2,it2i3 # # # 5 80.00 # +2 MATERIALIZED t2 ALL NULL # # # 5 100.00 # +4 MATERIALIZED t3 ALL NULL # # # 4 100.00 # +3 MATERIALIZED t3 ALL NULL # # # 4 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 # # # 2 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`.`t1 i`.`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 +b2 in (select c2 from t3 where c2 LIKE '%03') +group by b1, b2) and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0'))) +UNION +(select * from t1i +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'))); +a1 a2 +1 - 02 2 - 02 +1 - 01 2 - 01 +explain extended +select * from t1 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(a1, a2) in (select c1, c2 from t3 +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 100.00 Using where +1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +4 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 80.00 Using where; Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL 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`.`t2i` join `test`.`t3`) where `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1` and <cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and `test`.`t3`.`c2` > '0' +select * from t1 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(a1, a2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')); +a1 a2 +1 - 01 2 - 01 +1 - 02 2 - 02 +explain extended +select * from t1, t3 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(c1, c2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and +a1 = c1; +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 t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY <subquery4> eq_ref distinct_key distinct_key 16 func,func 1 100.00 +4 MATERIALIZED t3 ALL NULL NULL NULL NULL 4 100.00 Using where +4 MATERIALIZED t2i index it2i1,it2i2,it2i3 it2i3 18 NULL 5 80.00 Using where; Using index; Using join buffer (flat, BNL join) +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` semi join (`test`.`t2i` join `test`.`t3`) join `test`.`t3` where `test`.`t3`.`c1` = `test`.`t1`.`a1` and `test`.`t2i`.`b1` = `test`.`t3`.`c1` and `test`.`t2i`.`b2` = `test`.`t3`.`c2` and <expr_cache><`test`.`t1`.`a1`,`test`.`t1`.`a2`>(<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(/* select#2 */ select `test`.`t1`.`a1`,`test`.`t1`.`a2` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1` and <cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2` union /* select#3 */ select `test`.`t2`.`b1`,`test`.`t2`.`b2` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1` and <cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`))) and `test`.`t3`.`c2` > '0' +select * from t1, t3 +where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and +(c1, c2) in (select c1, c2 from t3 +where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and +a1 = c1; +a1 a2 c1 c2 +1 - 01 2 - 01 1 - 01 2 - 01 +1 - 02 2 - 02 1 - 02 2 - 02 +/****************************************************************************** +* Negative tests, where materialization should not be applied. +******************************************************************************/ +# UNION in a subquery +explain extended +select * from t3 +where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where +NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 /* select#1 */ select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <expr_cache><`test`.`t3`.`c1`>(<in_optimizer>(`test`.`t3`.`c1`,<exists>(/* select#2 */ select `test`.`t1`.`a1` from `test`.`t1` where `test`.`t1`.`a1` > '0' and <cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1` union /* select#3 */ select `test`.`t2`.`b1` from `test`.`t2` where `test`.`t2`.`b1` < '9' and <cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))) +select * from t3 +where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9'); +c1 c2 +1 - 01 2 - 01 +1 - 02 2 - 02 +1 - 03 2 - 03 +explain extended +select * from t1 +where (a1, a2) in (select b1, b2 from t2 +where b2 in (select c2 from t3 t3a where c1 = a1) or +b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and +(a1, a2) in (select c1, c2 from t3 t3c +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 t2i ref it2i1,it2i2,it2i3 it2i3 18 test.t1.a1,test.t1.a2 2 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`)) ))) +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 +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +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`),<exists>(/* select#2 */ select '1 - 01','2 - 01' having (<cache>(`test`.`t1`.`a1`) = '1 - 01' or '1 - 01' is null) and (<cache>(`test`.`t1`.`a2`) = '2 - 01' or '2 - 01' is null) and '1 - 01' is null and '2 - 01' is null))) +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01'); +a1 a2 +1 - 01 2 - 01 +explain extended +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual); +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 +2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used +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`),<exists>(/* select#2 */ select '1 - 01','2 - 01' having (<cache>(`test`.`t1`.`a1`) = '1 - 01' or '1 - 01' is null) and (<cache>(`test`.`t1`.`a2`) = '2 - 01' or '2 - 01' is null) and '1 - 01' is null and '2 - 01' is null))) +select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual); +a1 a2 +1 - 01 2 - 01 +/****************************************************************************** +* Subqueries in other uncovered clauses. +******************************************************************************/ +/* SELECT clause */ +select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1; +((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL +0 +0 +0 +/* GROUP BY clause */ +create table columns (col int key); +insert into columns values (1), (2); +explain extended +select * from t1 group by (select col from columns limit 1); +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 +2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by (/* select#2 */ select `test`.`columns`.`col` from `test`.`columns` limit 1) +select * from t1 group by (select col from columns limit 1); +a1 a2 +1 - 00 2 - 00 +explain extended +select * from t1 group by (a1 in (select col from columns)); +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 temporary; Using filesort +2 DEPENDENT SUBQUERY columns unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where; Full scan on NULL key +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <expr_cache><`test`.`t1`.`a1`>(<in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond(<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`))))) +select * from t1 group by (a1 in (select col from columns)); +a1 a2 +1 - 00 2 - 00 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: '1 - 00' +Warning 1292 Truncated incorrect DOUBLE value: '1 - 01' +Warning 1292 Truncated incorrect DOUBLE value: '1 - 02' +/* ORDER BY clause */ +explain extended +select * from t1 order by (select col from columns limit 1); +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 +2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` order by (/* select#2 */ select `test`.`columns`.`col` from `test`.`columns` limit 1) +select * from t1 order by (select col from columns limit 1); +a1 a2 +1 - 00 2 - 00 +1 - 01 2 - 01 +1 - 02 2 - 02 +/****************************************************************************** +* Column types/sizes that affect materialization. +******************************************************************************/ +/* +Test that BLOBs are not materialized (except when arguments of some functions). +*/ +# force materialization to be always considered +set @prefix_len = 6; +set @blob_len = 16; +set @suffix_len = @blob_len - @prefix_len; +create table t1_16 (a1 blob(16), a2 blob(16)); +create table t2_16 (b1 blob(16), b2 blob(16)); +create table t3_16 (c1 blob(16), c2 blob(16)); +insert into t1_16 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_16 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_16 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select b1 from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` semi join (`test`.`t2_16`) where `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t1_16`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select b1 from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` semi join (`test`.`t2_16`) where `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t2_16`.`b2` = `test`.`t1_16`.`a2` and `test`.`t1_16`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_16 +where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 19 func 1 100.00 Using where +2 MATERIALIZED t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` semi join (`test`.`t2_16`) where `test`.`t2_16`.`b1` > '0' and `test`.`t1_16`.`a1` = substr(`test`.`t2_16`.`b1`,1,16) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from `test`.`t1_16` where <expr_cache><`test`.`t1_16`.`a1`>(<in_optimizer>(`test`.`t1_16`.`a1`,<exists>(/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2` having <cache>(`test`.`t1_16`.`a1`) = <ref_null_helper>(group_concat(`test`.`t2_16`.`b1` separator ','))))) +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_16.a1 1 100.00 Using where +2 MATERIALIZED t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_16`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_16`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_16`.`b1` separator ',') from `test`.`t2_16` group by `test`.`t2_16`.`b2`) join `test`.`t1_16` where `test`.`t1_16`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_16 +where a1 in (select group_concat(b1) from t2_16 group by b2); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended +select * from t1 +where concat(a1,'x') IN +(select left(a1,8) from t1_16 +where (a1, a2) IN +(select t2_16.b1, t2_16.b2 from t2_16, t2 +where t2.b2 = substring(t2_16.b2,1,6) and +t2.b1 IN (select c1 from t3 where c2 > '0'))); +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 t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; Using join buffer (flat, BNL join) +1 PRIMARY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +1 PRIMARY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` semi join (`test`.`t3` join `test`.`t2_16` join `test`.`t2` join `test`.`t1_16`) where `test`.`t2`.`b1` = `test`.`t3`.`c1` and `test`.`t2_16`.`b1` = `test`.`t1_16`.`a1` and `test`.`t2_16`.`b2` = `test`.`t1_16`.`a2` and `test`.`t2`.`b2` = substr(`test`.`t1_16`.`a2`,1,6) and `test`.`t3`.`c2` > '0' and concat(`test`.`t1`.`a1`,'x') = left(`test`.`t1_16`.`a1`,8) +drop table t1_16, t2_16, t3_16; +set @blob_len = 512; +set @suffix_len = @blob_len - @prefix_len; +create table t1_512 (a1 blob(512), a2 blob(512)); +create table t2_512 (b1 blob(512), b2 blob(512)); +create table t3_512 (c1 blob(512), c2 blob(512)); +insert into t1_512 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_512 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_512 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select b1 from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` semi join (`test`.`t2_512`) where `test`.`t2_512`.`b1` = `test`.`t1_512`.`a1` and `test`.`t1_512`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select b1 from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` semi join (`test`.`t2_512`) where `test`.`t2_512`.`b1` = `test`.`t1_512`.`a1` and `test`.`t2_512`.`b2` = `test`.`t1_512`.`a2` and `test`.`t1_512`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_512 +where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 516 func 1 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where +Warnings: +Note 1003 select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from `test`.`t1_512` semi join (`test`.`t2_512`) where `test`.`t2_512`.`b1` > '0' and `test`.`t1_512`.`a1` = substr(`test`.`t2_512`.`b1`,1,512) +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_512.a1 1 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2`) join `test`.`t1_512` where `test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_512.a1 1 100.00 Using where +2 MATERIALIZED t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_512`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_512`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_512`.`b1` separator ',') from `test`.`t2_512` group by `test`.`t2_512`.`b2`) join `test`.`t1_512` where `test`.`t1_512`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_512 +where a1 in (select group_concat(b1) from t2_512 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_512, t2_512, t3_512; +set @blob_len = 1024; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1024 (a1 blob(1024), a2 blob(1024)); +create table t2_1024 (b1 blob(1024), b2 blob(1024)); +create table t3_1024 (c1 blob(1024), c2 blob(1024)); +insert into t1_1024 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1024 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select b1 from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` semi join (`test`.`t2_1024`) where `test`.`t2_1024`.`b1` = `test`.`t1_1024`.`a1` and `test`.`t1_1024`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select b1 from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` semi join (`test`.`t2_1024`) where `test`.`t2_1024`.`b1` = `test`.`t1_1024`.`a1` and `test`.`t2_1024`.`b2` = `test`.`t1_1024`.`a2` and `test`.`t1_1024`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_1024 +where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1024` semi join (`test`.`t2_1024`) where `test`.`t2_1024`.`b1` > '0' and `test`.`t1_1024`.`a1` = substr(`test`.`t2_1024`.`b1`,1,1024) +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_1024.a1 1 100.00 Using where +2 MATERIALIZED t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2`) join `test`.`t1_1024` where `test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_1024.a1 1 100.00 Using where +2 MATERIALIZED t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1024`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1024`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_1024`.`b1` separator ',') from `test`.`t2_1024` group by `test`.`t2_1024`.`b2`) join `test`.`t1_1024` where `test`.`t1_1024`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_1024 +where a1 in (select group_concat(b1) from t2_1024 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_1024, t2_1024, t3_1024; +set @blob_len = 1025; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1025 (a1 blob(1025), a2 blob(1025)); +create table t2_1025 (b1 blob(1025), b2 blob(1025)); +create table t3_1025 (c1 blob(1025), c2 blob(1025)); +insert into t1_1025 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1025 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +insert into t3_1025 values +(concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len))); +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select b1 from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` semi join (`test`.`t2_1025`) where `test`.`t2_1025`.`b1` = `test`.`t1_1025`.`a1` and `test`.`t1_1025`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select b1 from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` semi join (`test`.`t2_1025`) where `test`.`t2_1025`.`b1` = `test`.`t1_1025`.`a1` and `test`.`t2_1025`.`b2` = `test`.`t1_1025`.`a2` and `test`.`t1_1025`.`a1` > '0' +select left(a1,7), left(a2,7) +from t1_1025 +where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from `test`.`t1_1025` semi join (`test`.`t2_1025`) where `test`.`t2_1025`.`b1` > '0' and `test`.`t1_1025`.`a1` = substr(`test`.`t2_1025`.`b1`,1,1025) +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +1 - 02x 2 - 02x +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_1025.a1 1 100.00 Using where +2 MATERIALIZED t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2`) join `test`.`t1_1025` where `test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +set @@group_concat_max_len = 256; +explain extended select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 260 test.t1_1025.a1 1 100.00 Using where +2 MATERIALIZED t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort +Warnings: +Note 1003 /* select#1 */ select left(`test`.`t1_1025`.`a1`,7) AS `left(a1,7)`,left(`test`.`t1_1025`.`a2`,7) AS `left(a2,7)` from <materialize> (/* select#2 */ select group_concat(`test`.`t2_1025`.`b1` separator ',') from `test`.`t2_1025` group by `test`.`t2_1025`.`b2`) join `test`.`t1_1025` where `test`.`t1_1025`.`a1` = `<subquery2>`.`group_concat(b1)` +select left(a1,7), left(a2,7) +from t1_1025 +where a1 in (select group_concat(b1) from t2_1025 group by b2); +left(a1,7) left(a2,7) +Warnings: +Warning 1260 Row 1 was cut by GROUP_CONCAT() +Warning 1260 Row 2 was cut by GROUP_CONCAT() +Warning 1260 Row 3 was cut by GROUP_CONCAT() +drop table t1_1025, t2_1025, t3_1025; +create table t1bit (a1 bit(3), a2 bit(3)); +create table t2bit (b1 bit(3), b2 bit(3)); +insert into t1bit values (b'000', b'100'); +insert into t1bit values (b'001', b'101'); +insert into t1bit values (b'010', b'110'); +insert into t2bit values (b'001', b'101'); +insert into t2bit values (b'010', b'110'); +insert into t2bit values (b'110', b'111'); +explain extended select bin(a1), bin(a2) +from t1bit +where (a1, a2) in (select b1, b2 from t2bit); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1bit ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 100.00 +2 MATERIALIZED t2bit ALL NULL NULL NULL NULL 3 100.00 +Warnings: +Note 1003 select conv(`test`.`t1bit`.`a1`,10,2) AS `bin(a1)`,conv(`test`.`t1bit`.`a2`,10,2) AS `bin(a2)` from `test`.`t1bit` semi join (`test`.`t2bit`) where 1 +select bin(a1), bin(a2) +from t1bit +where (a1, a2) in (select b1, b2 from t2bit); +bin(a1) bin(a2) +1 101 +10 110 +drop table t1bit, t2bit; +create table t1bb (a1 bit(3), a2 blob(3)); +create table t2bb (b1 bit(3), b2 blob(3)); +insert into t1bb values (b'000', '100'); +insert into t1bb values (b'001', '101'); +insert into t1bb values (b'010', '110'); +insert into t2bb values (b'001', '101'); +insert into t2bb values (b'010', '110'); +insert into t2bb values (b'110', '111'); +explain extended select bin(a1), a2 +from t1bb +where (a1, a2) in (select b1, b2 from t2bb); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1bb ALL NULL NULL NULL NULL 3 100.00 +1 PRIMARY t2bb ALL NULL NULL NULL NULL 3 100.00 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` semi join (`test`.`t2bb`) where `test`.`t2bb`.`b1` = `test`.`t1bb`.`a1` and `test`.`t2bb`.`b2` = `test`.`t1bb`.`a2` +select bin(a1), a2 +from t1bb +where (a1, a2) in (select b1, b2 from t2bb); +bin(a1) a2 +1 101 +10 110 +drop table t1bb, t2bb; +drop table t1, t2, t3, t1i, t2i, t3i, columns; +/****************************************************************************** +* Test the cache of the left operand of IN. +******************************************************************************/ +# Test that default values of Cached_item are not used for comparison +create table t1 (s1 int); +create table t2 (s2 int); +insert into t1 values (5),(1),(0); +insert into t2 values (0), (1); +select s2 from t2 where s2 in (select s1 from t1); +s2 +0 +1 +drop table t1, t2; +create table t1 (a int not null, b int not null); +create table t2 (c int not null, d int not null); +create table t3 (e int not null); +insert into t1 values (1,10); +insert into t1 values (1,20); +insert into t1 values (2,10); +insert into t1 values (2,20); +insert into t1 values (2,30); +insert into t1 values (3,20); +insert into t1 values (4,40); +insert into t2 values (2,10); +insert into t2 values (2,20); +insert into t2 values (2,40); +insert into t2 values (3,20); +insert into t2 values (4,10); +insert into t2 values (5,10); +insert into t3 values (10); +insert into t3 values (10); +insert into t3 values (20); +insert into t3 values (30); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 6 100.00 +1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t1`.`a` = `test`.`t2`.`c` and `test`.`t2`.`d` >= 20 +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +create index it1a on t1(a); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index it1a it1a 4 NULL 7 100.00 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 6 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`d` >= 20 +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +insert into t2 values (1,10); +explain extended +select a from t1 where a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index it1a it1a 4 NULL 7 100.00 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where `test`.`t2`.`d` >= 20 +select a from t1 where a in (select c from t2 where d >= 20); +a +2 +2 +2 +3 +explain extended +select a from t1 group by a having a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 group by a having a in (select c from t2 where d >= 20); +a +2 +3 +create index iab on t1(a, b); +explain extended +select a from t1 group by a having a in (select c from t2 where d >= 20); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 7 100.00 Using where +Warnings: +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`>(<in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where `test`.`t2`.`d` >= 20 ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key where `test`.`t1`.`a` = `<subquery2>`.`c`)))) +select a from t1 group by a having a in (select c from t2 where d >= 20); +a +2 +3 +explain extended +select a from t1 group by a +having a in (select c from t2 where d >= some(select e from t3 where max(b)=e)); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using index +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where +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 1981 Aggregate function 'max()' of SELECT #3 belongs to SELECT #1 +Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <expr_cache><`test`.`t1`.`a`,`test`.`t1`.`b`,max(`test`.`t1`.`b`),max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t1`.`a`,<exists>(/* select#2 */ select `test`.`t2`.`c` from `test`.`t2` where <nop>(<expr_cache><`test`.`t2`.`d`,`test`.`t1`.`b`,max(`test`.`t1`.`b`),max(`test`.`t1`.`b`)>(<in_optimizer>(`test`.`t2`.`d`,<exists>(/* select#3 */ select `test`.`t3`.`e` from `test`.`t3` where max(`test`.`t1`.`b`) = `test`.`t3`.`e` having <cache>(`test`.`t2`.`d`) >= <ref_null_helper>(`test`.`t3`.`e`))))) and <cache>(`test`.`t1`.`a`) = `test`.`t2`.`c`))) +select a from t1 group by a +having a in (select c from t2 where d >= some(select e from t3 where max(b)=e)); +a +2 +3 +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 7 100.00 Start temporary +1 PRIMARY t1 ref it1a,iab iab 4 test.t2.c 1 100.00 Using where; Using index; End temporary +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`)))) +select a from t1 +where a in (select c from t2 where d >= some(select e from t3 where b=e)); +a +2 +2 +2 +3 +1 +drop table t1, t2, t3; +create table t2 (a int, b int, key(a), key(b)); +insert into t2 values (3,3),(3,3),(3,3); +select 1 from t2 where +t2.a > 1 +or +t2.a = 3 and not t2.a not in (select t2.b from t2); +1 +1 +1 +1 +drop table t2; +create table t1 (a1 int key); +create table t2 (b1 int); +insert into t1 values (5); +explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY <subquery2> const distinct_key distinct_key 4 const 1 +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +min(a1) +NULL +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +explain select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +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 NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select max(b1) from t2 group by b1); +min(a1) +NULL +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='semijoin=off'; +explain select min(a1) from t1 where 7 in (select b1 from t2); +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 NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2); +min(a1) +NULL +set @@optimizer_switch=@optimizer_switch_local_default; +set @@optimizer_switch='materialization=off,in_to_exists=on'; +# with MariaDB and MWL#90, this particular case is solved: +explain select min(a1) from t1 where 7 in (select b1 from t2); +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 +select min(a1) from t1 where 7 in (select b1 from t2); +min(a1) +NULL +# but when we go around MWL#90 code, the problem still shows up: +explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; +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 NULL NULL NULL NULL NULL NULL NULL no matching row in const table +select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4; +min(a1) +NULL +set @@optimizer_switch= @save_optimizer_switch; +drop table t1,t2; +create table t1 (a char(2), b varchar(10)); +insert into t1 values ('a', 'aaa'); +insert into t1 values ('aa', 'aaaa'); +explain select a,b from t1 where b in (select a from t1); +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 2 func 1 Using where +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +select a,b from t1 where b in (select a from t1); +a b +prepare st1 from "select a,b from t1 where b in (select a from t1)"; +execute st1; +a b +execute st1; +a b +drop table t1; +# +# BUG#49630: Segfault in select_describe() with double +# nested subquery and materialization +# +CREATE TABLE t1 (t1i int); +CREATE TABLE t2 (t2i int); +CREATE TABLE t3 (t3i int); +CREATE TABLE t4 (t4i int); +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1),(2); +INSERT INTO t3 VALUES (1),(2); +INSERT INTO t4 VALUES (1),(2); + +EXPLAIN +SELECT t1i +FROM t1 JOIN t4 ON t1i=t4i +WHERE (t1i) IN ( +SELECT t2i +FROM t2 +WHERE (t2i) IN ( +SELECT max(t3i) +FROM t3 +GROUP BY t3i +) +); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 4 const 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Start temporary; End temporary; Using join buffer (flat, BNL join) +1 PRIMARY t4 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 Using temporary +DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 ( +pk INTEGER AUTO_INCREMENT, +col_int_nokey INTEGER, +col_int_key INTEGER, +col_varchar_key VARCHAR(1), +PRIMARY KEY (pk), +KEY (col_int_key), +KEY (col_varchar_key, col_int_key) +) +; +INSERT INTO t1 ( +col_int_key, col_int_nokey, col_varchar_key +) +VALUES +(2, NULL, 'w'), +(9, 7, 'm'), +(3, 9, 'm'), +(9, 7, 'k'), +(NULL, 4, 'r'), +(9, 2, 't'), +(3, 6, 'j'), +(8, 8, 'u'), +(8, NULL, 'h'), +(53, 5, 'o'), +(0, NULL, NULL), +(5, 6, 'k'), +(166, 188, 'e'), +(3, 2, 'n'), +(0, 1, 't'), +(1, 1, 'c'), +(9, 0, 'm'), +(5, 9, 'y'), +(6, NULL, 'f'), +(2, 4, 'd') +; +SELECT table2.col_varchar_key AS field1, +table2.col_int_nokey AS field2 +FROM ( t1 AS table1 LEFT OUTER JOIN t1 AS table2 +ON (table2.col_varchar_key = table1.col_varchar_key ) ) +WHERE table1.pk = 6 +HAVING ( field2 ) IN +( SELECT SUBQUERY2_t2.col_int_nokey AS SUBQUERY2_field2 +FROM ( t1 AS SUBQUERY2_t1 JOIN t1 AS SUBQUERY2_t2 +ON (SUBQUERY2_t2.col_varchar_key = SUBQUERY2_t1.col_varchar_key ) ) ) +ORDER BY field2 +; +field1 field2 +t 1 +t 2 +drop table t1; +# +# BUG#53103: MTR test ps crashes in optimize_cond() +# when running with --debug +# +CREATE TABLE t1(track varchar(15)); +INSERT INTO t1 VALUES ('CAD'), ('CAD'); +PREPARE STMT FROM +"SELECT 1 FROM t1 + WHERE + track IN (SELECT track FROM t1 + GROUP BY track + HAVING track>='CAD')"; +EXECUTE STMT ; +1 +1 +1 +EXECUTE STMT ; +1 +1 +1 +DEALLOCATE PREPARE STMT; +DROP TABLE t1; +# End of BUG#53103 +# +# BUG#54511 - Assertion failed: cache != 0L in file +# sql_select.cc::sub_select_cache on HAVING +# +CREATE TABLE t1 (i int(11)); +CREATE TABLE t2 (c char(1)); +CREATE TABLE t3 (c char(1)); +INSERT INTO t1 VALUES (1), (2); +INSERT INTO t2 VALUES ('a'), ('b'); +INSERT INTO t3 VALUES ('x'), ('y'); +SELECT COUNT( i ),i +FROM t1 +HAVING ('c') +IN (SELECT t2.c FROM (t2 JOIN t3)); +COUNT( i ) i +DROP TABLE t1,t2,t3; +# End BUG#54511 +# +# BUG#56367 - Assertion exec_method != EXEC_MATERIALIZATION... +# on subquery in FROM +# +CREATE TABLE t1 (a INTEGER); +CREATE TABLE t2 (b INTEGER); +INSERT INTO t2 VALUES (1); +set @tmp_optimizer_switch=@@optimizer_switch; +set optimizer_switch='derived_merge=off,derived_with_keys=off'; +explain SELECT a FROM ( +SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a > 3 OR t2.b IN (SELECT a FROM t1) +) table1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2 +2 DERIVED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +3 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL no matching row in const table +SELECT a FROM ( +SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a > 3 OR t2.b IN (SELECT a FROM t1) +) table1; +a +set optimizer_switch=@tmp_optimizer_switch; +DROP TABLE t1, t2; +# End BUG#56367 +# +# Bug#59833 - materialization=on/off leads to different result set +# when using IN +# +CREATE TABLE t1 ( +pk int NOT NULL, +f1 int DEFAULT NULL, +PRIMARY KEY (pk) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +pk int NOT NULL, +f1 int DEFAULT NULL, +PRIMARY KEY (pk) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (10,0); +INSERT INTO t2 VALUES (10,0),(11,0); +explain SELECT * FROM t1 JOIN t2 USING (f1) +WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER 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 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 const 1 +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t1 system NULL NULL NULL NULL 1 +SELECT * FROM t1 JOIN t2 USING (f1) +WHERE t1.f1 IN (SELECT t1.pk FROM t1 ORDER BY t1.f1); +f1 pk pk +DROP TABLE t1, t2; +# End Bug#59833 +# +# Bug#11852644 - CRASH IN ITEM_REF::SAVE_IN_FIELD ON SELECT DISTINCT +# +CREATE TABLE t1 ( +col_varchar_key varchar(1) DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_varchar_key (col_varchar_key)) +; +INSERT INTO t1 VALUES +('v','v'),('r','r'); +CREATE TABLE t2 ( +col_varchar_key varchar(1) DEFAULT NULL, +col_varchar_nokey varchar(1) DEFAULT NULL, +KEY col_varchar_key(col_varchar_key)) +; +INSERT INTO t2 VALUES +('r','r'),('c','c'); +CREATE VIEW v3 AS SELECT * FROM t2; +SELECT DISTINCT alias2.col_varchar_key +FROM t1 AS alias1 JOIN v3 AS alias2 +ON alias2.col_varchar_key = alias1.col_varchar_key +HAVING col_varchar_key IN (SELECT col_varchar_nokey FROM t2) +; +col_varchar_key +r +DROP TABLE t1, t2; +DROP VIEW v3; +# End Bug#11852644 + +# Bug#12668294 - GROUP BY ON EMPTY RESULT GIVES EMPTY ROW +# INSTEAD OF NULL WHEN MATERIALIZATION ON + +CREATE TABLE t1 (col_int_nokey INT) ENGINE=MEMORY; +CREATE TABLE t2 (col_int_nokey INT) ENGINE=MEMORY; +INSERT INTO t2 VALUES (8),(7); +CREATE TABLE t3 (col_int_nokey INT) ENGINE=MEMORY; +INSERT INTO t3 VALUES (7); +SELECT MIN(t3.col_int_nokey),t1.col_int_nokey AS field3 +FROM t3 +LEFT JOIN t1 +ON t1.col_int_nokey +WHERE (194, 200) IN ( +SELECT SQ4_alias1.col_int_nokey, +SQ4_alias2.col_int_nokey +FROM t2 AS SQ4_alias1 +JOIN +t2 AS SQ4_alias2 +ON SQ4_alias2.col_int_nokey = 5 +) +GROUP BY field3 ; +MIN(t3.col_int_nokey) field3 +DROP TABLE t1; +DROP TABLE t2; +DROP TABLE t3; +CREATE TABLE t1 (f1 INT, f2 DECIMAL(5,3)) ENGINE=MyISAM; +INSERT INTO t1 (f1, f2) VALUES (1, 1.789); +INSERT INTO t1 (f1, f2) VALUES (13, 1.454); +INSERT INTO t1 (f1, f2) VALUES (10, 1.668); +CREATE TABLE t2 LIKE t1; +INSERT INTO t2 VALUES (1, 1.789); +INSERT INTO t2 VALUES (13, 1.454); +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +SET @@optimizer_switch='semijoin=on,materialization=on'; +EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); +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 ALL NULL NULL NULL NULL 3 Using where; Using join buffer (flat, BNL join) +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 +SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2); +COUNT(*) +2 +set @@optimizer_switch= @save_optimizer_switch; +DROP TABLE t1, t2; +CREATE TABLE t1 ( +pk int, +a varchar(1), +b varchar(4), +c varchar(4), +d varchar(4), +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'); +set @save_optimizer_switch=@@optimizer_switch; +set @@optimizer_switch=@optimizer_switch_local_default; +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 +SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0); +pk +2 +SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0); +pk +2 +DROP TABLE t1, t2; +set optimizer_switch=@save_optimizer_switch; +# +# BUG#50019: Wrong result for IN-subquery with materialization +# +create table t1(i int); +insert into t1 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +create table t2(i int); +insert into t2 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +create table t3(i int); +insert into t3 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5); +i +1 +2 +3 +4 +set @save_optimizer_switch=@@optimizer_switch; +set session optimizer_switch='materialization=off,in_to_exists=on'; +select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5); +i +4 +3 +2 +1 +set session optimizer_switch=@save_optimizer_switch; +drop table t1, t2, t3; +create table t0 (a int); +insert into t0 values (0),(1),(2); +create table t1 (a int); +insert into t1 values (0),(1),(2); +explain select a, a in (select a from t1) from t0; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t0 ALL NULL NULL NULL NULL 3 +2 MATERIALIZED t1 ALL NULL NULL NULL NULL 3 +select a, a in (select a from t1) from t0; +a a in (select a from t1) +0 1 +1 1 +2 1 +prepare s from 'select a, a in (select a from t1) from t0'; +execute s; +a a in (select a from t1) +0 1 +1 1 +2 1 +update t1 set a=123; +execute s; +a a in (select a from t1) +0 0 +1 0 +2 0 +drop table t0, t1; +set optimizer_switch='firstmatch=on'; +# +# MWL#90, review feedback: check what happens when the subquery +# looks like candidate for MWL#90 checking at the first glance +# but then subselect_hash_sj_engine::init_permanent() discovers +# that it's not possible to perform duplicate removal for the +# selected datatypes, and so materialization isn't applicable after +# all. +# +set @blob_len = 1024; +set @suffix_len = @blob_len - @prefix_len; +create table t1_1024 (a1 blob(1024), a2 blob(1024)); +create table t2_1024 (b1 blob(1024), b2 blob(1024)); +insert into t1_1024 values +(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t1_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len))); +insert into t2_1024 values +(concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len))); +explain select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 Using where +2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 Using where +select left(a1,7), left(a2,7) from t1_1024 where (a1,3) in (select substring(b1,1,1024), count(*) from t2_1024 where b1 > '0'); +left(a1,7) left(a2,7) +1 - 01x 2 - 01x +drop table t1_1024, t2_1024; +# +# BUG##836491: Crash in Item_field::Item_field from add_ref_to_table_cond() with semijoin+materialization +# +CREATE TABLE t1 (c int, d varchar(1), KEY(d)) ; +INSERT INTO t1 VALUES (2,'x'),(2,'x'),(2,'j'),(2,'c'); +CREATE TABLE t2 (a int, d varchar(1)) ; +INSERT INTO t2 VALUES (1,'x'); +CREATE TABLE t3 (d varchar(1)) ; +INSERT INTO t3 VALUES ('x'),('x'),('j'),('c'); +SELECT t2.a, t1.c +FROM t1, t2 +WHERE t2.d IN ( SELECT d FROM t3 ) +AND t1.d = t2.d +GROUP BY 1 , 2; +a c +1 2 +drop table t1,t2,t3; +# +# BUG#836523: Crash in JOIN::get_partial_cost_and_fanout with semijoin+materialization +# +CREATE TABLE t1 (a varchar(1)); +INSERT INTO t1 VALUES ('a'),('a'); +CREATE TABLE t2 (a varchar(1)); +CREATE TABLE t3 (a int); +INSERT INTO t3 VALUES (1),(2); +CREATE TABLE t4 (a varchar(1)); +INSERT INTO t4 VALUES ('a'),('a'); +SELECT t1.a +FROM t1 +WHERE t1.a IN ( +SELECT t2.a +FROM t2, t3 +) +HAVING a IN ( +SELECT a +FROM t4 +); +a +DROP TABLE t1, t2, t3, t4; +# +# BUG#836507: Crash in setup_sj_materialization_part1() with semijoin+materialization +# +CREATE TABLE t1 (a int) ; +INSERT IGNORE INTO t1 VALUES (1),(1); +CREATE TABLE t2 (a int); +INSERT INTO t2 VALUES (1); +CREATE TABLE t3 (a int); +CREATE TABLE t4 (a int); +INSERT INTO t4 VALUES (2),(2); +CREATE TABLE t5 (a int); +INSERT INTO t5 VALUES (1); +SELECT * FROM t1 +WHERE (a) IN ( +SELECT t5.a +FROM ( +t2 +LEFT JOIN ( t3 , t4 ) +ON 1 = 1 +) +JOIN t5 +); +a +1 +1 +DROP TABLE t1,t2,t3,t4,t5; +# +# BUG#836532: Crash in Item_equal_fields_iterator::get_curr_field with semijoin+materialization +# +CREATE TABLE t2 (a int); +INSERT IGNORE INTO t2 VALUES ('a'),('a'); +Warnings: +Warning 1366 Incorrect integer value: 'a' for column 'a' at row 1 +Warning 1366 Incorrect integer value: 'a' for column 'a' at row 2 +CREATE TABLE t4 (a varchar(1)); +INSERT INTO t4 VALUES ('m'),('o'); +CREATE TABLE t3 (a varchar(1) , b varchar(1) ) ; +INSERT INTO t3 VALUES ('b','b'); +CREATE TABLE t5 (a varchar(1), KEY (a)) ; +INSERT INTO t5 VALUES ('d'),('e'); +SELECT * +FROM t2 +WHERE t2.a = ALL ( +SELECT t4.a +FROM t4 +WHERE t4.a IN ( +SELECT t3.a +FROM t3 , t5 +WHERE ( t5.a = t3.b ) +) +); +a +0 +0 +DROP TABLE t2,t3,t4,t5; +# +# BUG#860300: Second crash with get_fanout_with_deps() with semijoin + materialization +# +set @tmp_860300=@@optimizer_switch; +set optimizer_switch='semijoin=on,materialization=on,loosescan=off,firstmatch=off'; +CREATE TABLE t1 (f2 int); +INSERT INTO t1 VALUES (9),(6); +CREATE TABLE t3 (f4 int); +CREATE TABLE t4 (f6 varchar(1)); +SELECT * +FROM t3 +WHERE 'h' IN (SELECT f6 +FROM t4 +WHERE 5 IN (SELECT f2 FROM t1) +GROUP BY t4.f6); +f4 +DROP TABLE t1,t3,t4; +set optimizer_switch=@tmp_860300; +# +# BUG#860535: Assertion `keypart_map' failed in mi_rkey with semijoin +# +set @tmp_860535=@@optimizer_switch; +set optimizer_switch='semijoin=on,materialization=on,loosescan=off,firstmatch=off'; +CREATE TABLE t1 (f3 int) ; +INSERT INTO t1 VALUES (1),(7); +CREATE TABLE t2 (f3 int , f5 varchar(1), KEY (f3)) ; +INSERT INTO t2 VALUES (7,'b'); +CREATE TABLE t3 (f3 int , f4 varchar(1) , KEY(f3), KEY (f4,f3)) ; +INSERT INTO t3 VALUES (1,'t'),(7,'g'); +CREATE TABLE t4 +SELECT f3 +FROM t1 WHERE ( f3 ) NOT IN ( +SELECT f3 +FROM t2 +WHERE f5 IN ( +SELECT f4 +FROM t3 +WHERE t3.f3 < 3 +) +); +SELECT * FROM t4; +f3 +1 +7 +DROP TABLE t1, t2, t3, t4; +set optimizer_switch=@tmp_860535; +# +# BUG#860553: Crash in create_ref_for_key with semijoin + materialization +# +CREATE TABLE t1 (f1 int) ; +CREATE TABLE t2 (f5 varchar(52) NOT NULL) ; +CREATE TABLE t3 (f1 varchar(3), f4 varchar(52) , KEY (f4), PRIMARY KEY (f1)); +CREATE TABLE t4 (f3 int, KEY (f3)); +INSERT INTO t4 VALUES (17),(20); +CREATE TABLE t5 (f2 int); +INSERT INTO t5 VALUES (0),(0); +SELECT * +FROM t1 +JOIN t2 +ON ( t2.f5 ) IN ( +SELECT t3.f4 +FROM t3 +WHERE ( 1 ) IN ( +SELECT t4.f3 +FROM t4 , t5 +) +); +f1 f5 +DROP TABLE t1, t2, t3, t4, t5; +# +# BUG#868908: Crash in check_simple_equality() with semijoin + materialization + prepared statement +# +CREATE TABLE t1 ( a int ); +CREATE TABLE t3 ( b int, c int) ; +CREATE TABLE t2 ( a int ) ; +CREATE TABLE t4 ( a int , c int) ; +PREPARE st1 FROM " +SELECT STRAIGHT_JOIN * +FROM t1 +WHERE ( 3 ) IN ( + SELECT t3.b + FROM t3 + LEFT JOIN ( + t2 STRAIGHT_JOIN t4 ON ( t4.c = t2.a ) + ) ON ( t4.a = t3.c ) +); +"; +EXECUTE st1; +a +EXECUTE st1; +a +DROP TABLE t1,t2,t3,t4; +# +# BUG#901032: Wrong result for MIN/MAX on an indexed column with materialization and semijoin +# +CREATE TABLE t1 ( a INT, KEY(a) ); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (2); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (2); +SELECT MIN(a) FROM t1, t2 WHERE b IN (SELECT c FROM t3 GROUP BY c); +MIN(a) +1 +DROP TABLE t1,t2,t3; +# +# +# BUG#902632: Crash or invalid read at st_join_table::cleanup, st_table::disable_keyread +# +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1), (2); +CREATE TABLE t2 ( b INT ); +INSERT INTO t2 VALUES (3), (4); +CREATE TABLE t3 ( c INT ); +INSERT INTO t3 VALUES (5), (6); +SELECT * FROM t1 WHERE EXISTS ( +SELECT DISTINCT b FROM t2 +WHERE b <= a +AND b IN ( SELECT c FROM t3 GROUP BY c ) +); +a +DROP TABLE t1,t2,t3; +# +# BUG#901506: Crash in TABLE_LIST::print on EXPLAIN EXTENDED +# +CREATE TABLE t1 ( a INT, KEY(a) ); +INSERT INTO t1 VALUES (8); +EXPLAIN EXTENDED +SELECT * FROM t1 +WHERE a IN ( SELECT MIN(a) FROM t1 ); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t1 system a NULL NULL NULL 1 100.00 +1 PRIMARY <subquery2> system NULL NULL NULL NULL 1 100.00 +2 MATERIALIZED NULL NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +Warnings: +Note 1003 /* select#1 */ select 8 AS `a` from dual where 1 +DROP TABLE t1; +# +# BUG#904432: Wrong result with LEFT JOIN, constant table, semijoin=ON,materialization=ON +# +CREATE TABLE t1 ( a INT ) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4); +CREATE TABLE t2 ( b INT NOT NULL, c INT ); +INSERT INTO t2 VALUES (4,2),(4,2),(4,4),(1,1); +SELECT * FROM t1 LEFT JOIN t2 ON ( a = b ) +WHERE a IN ( SELECT c FROM t2 ); +a b c +4 4 2 +4 4 2 +4 4 4 +DROP TABLE t1,t2; +# +# BUG#922254: Assertion `0' failed at item_cmpfunc.cc:5899: Item* Item_equal::get_first(JOIN_TAB*, Item*) +# +CREATE TABLE t1 ( a VARCHAR(3) ); +CREATE TABLE t2 ( b VARCHAR(3), c VARCHAR(8), KEY(c) ); +INSERT INTO t2 VALUES ('USA','Abilene'),('USA','Akron'); +EXPLAIN +SELECT * FROM +( SELECT * FROM t1 ) AS alias1, +t2 AS alias2 +WHERE b = a AND a IN ( +SELECT alias3.c +FROM t2 AS alias3, t2 AS alias4 +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 +DROP TABLE t1,t2; +# +# BUG#928048: Query containing IN subquery with OR in the where clause returns a wrong result +# +create table t1 (a int, b int); +insert into t1 values (7,5), (3,3), (5,4), (9,3); +create table t2 (a int, b int, index i_a(a)); +insert into t2 values +(4,2), (7,9), (7,4), (3,1), (5,3), (3,1), (9,4), (8,1); +explain select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 4 +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 func 1 +2 MATERIALIZED t2 ALL i_a NULL NULL NULL 8 Using where +select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); +a b +7 5 +3 3 +drop table t1,t2; +# +# BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +SELECT STRAIGHT_JOIN MIN(a) FROM t1 +WHERE a IN ( +SELECT a FROM t1 +WHERE 'condition'='impossible' + ); +MIN(a) +NULL +DROP TABLE t1; +# +# BUG#938131: Subquery materialization is not used in CREATE TABLE SELECT +# +CREATE TABLE t1(a int); +INSERT INTO t1 values(1),(2); +CREATE TABLE t2(a int); +INSERT INTO t2 values(1),(2); +# Should use Materialization: +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 4 test.t1.a 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using temporary +flush status; +CREATE TABLE t3 SELECT * FROM t1 WHERE a IN (SELECT * FROM t2 GROUP BY a HAVING a > 1); +SHOW STATUS LIKE 'Created_tmp_tables'; +Variable_name Value +Created_tmp_tables 2 +DROP TABLE t1,t2,t3; +# +# BUG#939009: Crash with aggregate function in IN subquery +# +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch='materialization=on,semijoin=on'; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (7,1), (4,2), (7,7); +CREATE TABLE t2 ( c INT ); +INSERT INTO t2 VALUES (4), (7), (6); +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) +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`) join `test`.`t1` where `test`.`t1`.`b` = 7 and `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(`<subquery2>`.`MAX(c)` 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 `test`.`t1`.`a` = `<subquery2>`.`MAX(c)` and (<cache>(`<subquery2>`.`MAX(c)` is null) or `<subquery2>`.`MAX(c)` = 7) +SELECT * FROM t1 +WHERE a IN (SELECT MAX(c) FROM t2) AND b=7 AND (a IS NULL OR a=b); +a b +7 7 +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) +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); +a b +SET optimizer_switch=@save_optimizer_switch; +DROP TABLE t1,t2; +# +# BUG#946055: Crash with semijoin IN subquery when hash join is used +# +CREATE TABLE t1 (a int); +INSERT INTO t1 VALUES (7); +CREATE TABLE t2 (b int, c int, d varchar(1), e varchar(1), KEY (c), KEY (d, c)); +INSERT INTO t2 VALUES +(4,2,'v','v'), (6,1,'v','v'), (0,5,'x','x'), (7,1,'x','x'), +(7,3,'i','i'), (7,1,'e','e'), (1,4,'p','p'), (1,2,'j','j'); +SET @save_optimizer_switch=@@optimizer_switch; +SET @save_join_cache_level=@@join_cache_level; +SET join_cache_level=2; +EXPLAIN +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 index c c 5 NULL 8 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 ALL c NULL NULL NULL 8 Using where; Using join buffer (flat, BNL join) +3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +a c +7 1 +7 1 +7 1 +SET optimizer_switch='join_cache_hashed=on'; +SET join_cache_level=4; +EXPLAIN +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 system NULL NULL NULL NULL 1 +1 PRIMARY t2 index c c 5 NULL 8 Using index +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 func,func 1 +2 MATERIALIZED s2 ref d d 4 const 2 Using where; Using index +2 MATERIALIZED s1 hash_ALL c #hash#$hj 5 const 8 Using where; Using join buffer (flat, BNLH join) +3 SUBQUERY t2 ALL NULL NULL NULL NULL 8 +SELECT a, c FROM t1, t2 +WHERE (a, c) IN (SELECT s1.b, s1.c FROM t2 AS s1, t2 AS s2 +WHERE s2.d = s1.e AND s1.e = (SELECT MAX(e) FROM t2)); +a c +7 1 +7 1 +7 1 +SET optimizer_switch=@save_optimizer_switch; +SET join_cache_level=@save_join_cache_level; +DROP TABLE t1,t2; +# +# BUG#952297: Server crashes on 2nd execution of PS in Field::is_null with semijoin+materialization +# +CREATE TABLE t1 ( a VARCHAR(1) ); +INSERT INTO t1 VALUES ('y'),('z'); +CREATE TABLE t2 ( b VARCHAR(1), c VARCHAR(1) ); +INSERT INTO t2 VALUES ('v','v'),('v','v'); +CREATE VIEW v2 AS SELECT * FROM t2; +PREPARE ps FROM ' +SELECT a FROM t1, v2 +WHERE ( c, b ) IN ( SELECT b, b FROM t2 ) +GROUP BY a '; +EXECUTE ps; +a +y +z +EXECUTE ps; +a +y +z +DROP VIEW v2; +DROP TABLE t1, t2; +# +# BUG#1000269: Wrong result (extra rows) with semijoin+materialization, IN subqueries, join_cache_level>0 +# +CREATE TABLE t1 (a1 VARCHAR(1), a2 VARCHAR(1)) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('b','b'),('e','e'); +CREATE TABLE t2 (b1 VARCHAR(1), b2 VARCHAR(1), KEY(b1)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('v','v'),('s','s'),('l','l'), ('y','y'),('c','c'),('i','i'); +SELECT * FROM t1, t2 WHERE b1 IN ( SELECT b2 FROM t2 WHERE b1 > 'o' ) AND ( b1 < 'l' OR a1 IN ('b','c') ); +a1 a2 b1 b2 +b b v v +b b s s +b b y y +DROP TABLE t1,t2; +# +# MDEV-4465: Reproducible crash (mysqld got signal 11) in multi_delete::initialize_tables with semijoin+materialization +# +CREATE TABLE t1 ( +id int(11) NOT NULL +); +CREATE TABLE t2 ( +id int(11) NOT NULL, +a_id int(11) DEFAULT NULL +); +insert into t1 values (1), (2), (3); +insert into t2 values (1, 1), (2, 1), (3, 1), (4, 2), (5, 3), (6, 3), (7, 3); +delete t2 from t2 where a_id in (select * from (select t1.id from t1 limit 2) as x); +drop table t1,t2; +# This must be at the end: +set optimizer_switch=@subselect_sj_mat_tmp; +set join_cache_level=@save_join_cache_level; +# +# MDEV-4908: Assertion `((Item_cond *) cond)->functype() == +# ((Item_cond *) new_item)->functype()' fails on a query with +# IN and equal conditions, AND/OR, materialization+semijoin +# +SET @save_optimizer_switch=@@optimizer_switch; +SET optimizer_switch = 'materialization=on,semijoin=on'; +CREATE TABLE t1 (pk INT, a INT, b INT, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,3,5),(2,4,6); +SELECT * FROM t1 WHERE 8 IN ( SELECT MIN(pk) FROM t1 ) AND ( pk = a OR pk = b ); +pk a b +drop table t1; +SET optimizer_switch=@save_optimizer_switch; +# +# MDEV-5011: ERROR Plugin 'MEMORY' has ref_count=1 after shutdown for SJM queries +# +CREATE TABLE t1 (pk INT, a INT, b INT, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,3,5),(2,4,6); +SELECT * FROM t1 WHERE 8 IN (SELECT MIN(pk) FROM t1) AND (pk = a OR pk = b); +pk a b +DROP TABLE t1; +# +# MDEV-5368: Server crashes in Item_in_subselect::optimize on 2nd +# execution of PS with IN subqueries, materialization+semijoin +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +INSERT INTO t2 VALUES (8),(9); +PREPARE stmt FROM " +SELECT * FROM t1 WHERE 1 IN ( SELECT b FROM v2 WHERE 2 IN ( SELECT MAX(a) FROM t1 ) ) +"; +EXECUTE stmt; +a +EXECUTE stmt; +a +DROP TABLE t1, t2; +DROP VIEW v2; +# +# MDEV-5811: Server crashes in best_access_path with materialization+semijoin and big_tables=ON +# +SET @tmp_mdev5811= @@big_tables; +SET big_tables = ON; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (b INT); +INSERT INTO t2 VALUES (3),(4); +SELECT * FROM t1 AS t1_1, t1 AS t1_2 +WHERE ( t1_1.a, t1_2.a ) IN ( SELECT MAX(b), MIN(b) FROM t2 ); +a a +DROP TABLE t1,t2; +SET big_tables=@tmp_mdev5811; +# End of 5.3 tests +# +# MDEV-5056: Wrong result (extra rows) with materialization+semijoin, IN subqueries +# +set @tmp_mdev5056=@@join_cache_level; +SET join_cache_level = 2; +CREATE TABLE t1 ( c1 VARCHAR(2), c2 VARCHAR(2), INDEX(c1) ) ENGINE=MyISAM; +INSERT INTO t1 VALUES +('JP','OM'),('VA','JP'),('CA','ML'),('ML','EG'),('DK','CA'), +('DK','QA'),('YE','PL'),('TR','ZW'),('DK','SK'),('SK','DK'), +('RO','ML'),('ML','BG'),('BG','ZW'),('ZW','GE'),('GE','JP'), +('PL','EG'),('QA','YE'),('WF','DK'),('DK','JP'),('EG','OM'); +CREATE TABLE t2 ( c3 VARCHAR(2), c4 VARCHAR(2) ) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('CA','ML'),('IN','HU'),('HU','IN'); +SELECT * FROM t1 AS alias1, t1 AS alias2 +WHERE ( alias2.c2, alias1.c1 ) IN ( SELECT c4, c3 FROM t2 ) AND alias1.c1 IN ( SELECT c2 FROM t1 ); +c1 c2 c1 c2 +CA ML CA ML +CA ML RO ML +DROP TABLE t1,t2; +set join_cache_level=@tmp_mdev5056; +# +# MDEV-5368: Server crashes in Item_in_subselect::optimize on 2nd +# execution of PS with IN subqueries, materialization+semijoin +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1),(3); +CREATE TABLE t2 (b INT) ENGINE=MyISAM; +CREATE ALGORITHM=MERGE VIEW v2 AS SELECT * FROM t2; +INSERT INTO t2 VALUES (8),(9); +PREPARE stmt FROM " +SELECT * FROM t1 WHERE 1 IN ( SELECT b FROM v2 WHERE 2 IN ( SELECT MAX(a) FROM t1 ) ) +"; +EXECUTE stmt; +a +EXECUTE stmt; +a +DROP TABLE t1, t2; +DROP VIEW v2; +# +# MDEV-6289 : Unexpected results when querying information_schema +# +CREATE TABLE t1 ( +id int(11) unsigned NOT NULL AUTO_INCREMENT, +db varchar(254) NOT NULL DEFAULT '', +PRIMARY KEY (id), +UNIQUE KEY db (db) +) DEFAULT CHARSET=utf8; +INSERT INTO t1 (db) VALUES ('mysqltest1'),('mysqltest2'),('mysqltest3'),('mysqltest4'); +drop database if exists mysqltest1; +drop database if exists mysqltest2; +drop database if exists mysqltest3; +drop database if exists mysqltest4; +create database mysqltest1; +create database mysqltest2; +create database mysqltest3; +create database mysqltest4; +SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC; +db +mysqltest4 +mysqltest3 +mysqltest2 +mysqltest1 +EXPLAIN EXTENDED +SELECT db FROM t1 WHERE db IN (SELECT SCHEMA_NAME FROM information_schema.schemata) ORDER BY db DESC; +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 temporary; Using filesort +1 PRIMARY t1 eq_ref db db 764 information_schema.schemata.SCHEMA_NAME 1 100.00 Using where; Using index +2 MATERIALIZED schemata ALL NULL NULL NULL NULL NULL NULL +Warnings: +Note 1003 select `test`.`t1`.`db` AS `db` from `test`.`t1` semi join (`information_schema`.`schemata`) where `test`.`t1`.`db` = `information_schema`.`schemata`.`SCHEMA_NAME` order by `test`.`t1`.`db` desc +drop table t1; +drop database mysqltest1; +drop database mysqltest2; +drop database mysqltest3; +drop database mysqltest4; +# +# MDEV-7810 Wrong result on execution of a query as a PS +# (both 1st and further executions) +CREATE TABLE t1 (a INT NOT NULL) ENGINE=MyISAM; +INSERT INTO t1 VALUES (0),(8); +SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2)); +a +0 +PREPARE stmt FROM " +SELECT a FROM (SELECT DISTINCT * FROM t1) AS sq WHERE a IN (SELECT MIN(t2.a) FROM (t1 AS t2)) +"; +execute stmt; +a +0 +execute stmt; +a +0 +drop table t1; +# +# MDEV-12429: IN subquery used in WHERE of EXISTS subquery +# +CREATE TABLE t1 ( +pk INT, f1 INT NOT NULL, f2 VARCHAR(3), f3 INT NULL, PRIMARY KEY(pk)) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1,1,'foo',8), (2,5,'bar',7); +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +f2 +foo +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch='exists_to_in=off'; +EXPLAIN +SELECT sq1.f2 FROM t1 AS sq1 +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 +2 DEPENDENT SUBQUERY sq2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join) +3 MATERIALIZED t1 ALL NULL NULL NULL NULL 2 +# this checks the result set above +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT sq1.f2 FROM t1 AS sq1 +WHERE EXISTS ( SELECT * FROM t1 AS sq2 +WHERE sq1.`pk` IN ( SELECT f1 FROM t1 ) AND sq2.f1 = sq1.f1 ); +f2 +foo +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1; +# +# MDEV-12145: IN subquery used in WHERE of EXISTS subquery +# +CREATE TABLE t1 (f1 INT) ENGINE=MyISAM; +INSERT INTO t1 VALUES (4),(6); +CREATE TABLE t2 (i2 INT, KEY(i2)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (8),(7),(1); +CREATE TABLE t3 (f3 INT, i3 INT, KEY(i3)) ENGINE=MyISAM; +INSERT INTO t3 VALUES (8,0),(6,3),(2,8),(3,8),(1,6),(0,0),(1,0),(1,5); +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch='exists_to_in=off'; +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +f1 +6 +EXPLAIN EXTENDED +SELECT * FROM t1 +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +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`)) +# this checks the result set above +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT * FROM t1 +WHERE EXISTS ( SELECT * FROM t2, t3 +WHERE i3 = i2 AND f1 IN ( SELECT f3 FROM t3 ) ); +f1 +6 +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1,t2,t3; +# +# MDEV-9686: IN subquery used in WHERE of a subquery from select list +# +CREATE TABLE t1 (pk INT PRIMARY KEY, f1 INT); +INSERT INTO t1 VALUES (1, 4),(2, 3),(3, 3),(4, 6),(5, 3); +CREATE TABLE t2 (f2 INT); +INSERT INTO t2 VALUES (1),(2),(3),(4),(5); +# t1.pk is always IN ( SELECT f2 FROM t2 ), +# so the IN condition should be true for every row, +# and thus COUNT(*) should always return 5 +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +pk f1 sq +1 4 5 +2 3 5 +3 3 5 +4 6 5 +5 3 5 +EXPLAIN EXTENDED +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 <subquery3> eq_ref distinct_key distinct_key 4 func 1 100.00 +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using join buffer (flat, BNL join) +3 MATERIALIZED t2 ALL NULL NULL NULL NULL 5 100.00 +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` +# this checks the result set above +set @save_optimizer_switch= @@optimizer_switch; +set optimizer_switch= 'materialization=off,semijoin=off'; +SELECT pk, f1, ( SELECT COUNT(*) FROM t2 +WHERE t1.pk IN ( SELECT f2 FROM t2 ) ) AS sq FROM t1; +pk f1 sq +1 4 5 +2 3 5 +3 3 5 +4 6 5 +5 3 5 +set optimizer_switch= @save_optimizer_switch; +DROP TABLE t1,t2; +# +# mdev-12838: scan of materialized of semi-join subquery in join +# +set @save_optimizer_switch=@@optimizer_switch; +CREATE TABLE t1 ( +dispatch_group varchar(32), +assignment_group varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx1 (dispatch_group), +KEY idx2 (assignment_group) +) ENGINE=MyISAM; +CREATE TABLE t2 ( +ugroup varchar(32), +user varchar(32), +sys_id char(32), +PRIMARY KEY (sys_id), +KEY idx3 (ugroup), +KEY idx4 (user) +) ENGINE=MyISAM; +CREATE TABLE t3 ( +type mediumtext, +sys_id char(32), +PRIMARY KEY (sys_id) +) ENGINE=MyISAM; +set optimizer_switch='materialization=off'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +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 t2 ref idx3,idx4 idx4 35 const 2 Using index condition; Using where; Start temporary +1 PRIMARY t3_i eq_ref PRIMARY PRIMARY 32 test.t2.ugroup 1 Using index condition; Using where +1 PRIMARY t1 ref idx1,idx2 idx1 35 test.t3_i.sys_id 2 Using index condition; Using where; End temporary +1 PRIMARY t3 eq_ref PRIMARY PRIMARY 32 test.t1.assignment_group 1 Using where; Using index +SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +set optimizer_switch='materialization=on'; +explain SELECT t1.assignment_group +FROM t1, t3 +WHERE t1.assignment_group = t3.sys_id AND +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +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 t1 ref idx1,idx2 idx1 35 test.t2.ugroup 2 Using where +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 +t1.dispatch_group IN +(SELECT t2.ugroup +FROM t2, t3 t3_i +WHERE t2.ugroup = t3_i.sys_id AND +t3_i.type LIKE '59e22fb137032000158bbfc8bcbe5d52' AND +t2.user = '86826bf03710200044e0bfc8bcbe5d79'); +assignment_group +df50316637232000158bbfc8bcbe5d23 +e08fad2637232000158bbfc8bcbe5d39 +ec70316637232000158bbfc8bcbe5d60 +7b10fd2637232000158bbfc8bcbe5d30 +ebb4620037332000158bbfc8bcbe5d89 +DROP TABLE t1,t2,t3; +set optimizer_switch=@save_optimizer_switch; +# End of 5.5 tests +# +# MDEV-7220: Materialization strategy is not used for REPLACE ... SELECT +# +create table t0(a int); +insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t1 (a int, b int, c int); +insert into t1 +select A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100, A.a+B.a*10+C.a*100 +from t0 A, t0 B, t0 C; +create table t2 (a int, b int, c int); +insert into t2 select A.a, A.a, A.a from t1 A; +insert into t2 select * from t2; +insert into t2 select * from t2; +create table t3 as select * from t2 limit 1; +# The testcase only makes sense if the following uses Materialization: +explain +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 1000 Using where +1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 8 test.t1.a,test.t1.b 1 +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 4000 Using temporary +flush status; +replace into t3 +select * from t1 where (a,b) in (select max(a),b from t2 group by b); +# Sequential reads: +# 1K is read from t1 +# 4K is read from t2 +# 1K groups is read from the tmp. table +# +# Lookups: +# 4K lookups in group by table +# 1K lookups in temp.table +# +# Writes: +# 2x 1K writes to temporary tables (grouping table and subquery materialization table +# +# The point is that neither counter should be in the millions (this +# will happen if Materialization is not used +show status where Variable_name like 'Handler_read%' or Variable_name like 'Handler_%write%'; +Variable_name Value +Handler_read_first 0 +Handler_read_key 5000 +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 6003 +Handler_tmp_write 2000 +Handler_write 1000 +drop table t0,t1,t2,t3; +# +# MDEV-7971: Assertion `name != __null' failed in ACL_internal_schema_registry::lookup +# on 2nd execution os PS with multi-table update +# +CREATE TABLE t1 (f1 INT); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 (f2 INT); +INSERT INTO t2 VALUES (3),(4); +CREATE TABLE t3 (f3 INT); +INSERT INTO t3 VALUES (5),(6); +PREPARE stmt FROM ' + UPDATE t1, t2 + SET f1 = 5 + WHERE 8 IN ( SELECT MIN(f3) FROM t3 ) +'; +EXECUTE stmt; +EXECUTE stmt; +DROP TABLE t1,t2,t3; +# +# MDEV-10389: Query returns different results on a debug vs non-debug build of the same revision +# +CREATE TABLE t1 (i1 INT, i2 INT NOT NULL); +INSERT INTO t1 VALUES (1,4),(2,6); +SELECT * FROM t1 AS alias1 +WHERE alias1.i1 IN ( +SELECT i1 FROM t1 WHERE alias1.i2 IN ( SELECT i2 FROM t1 HAVING i2 <> 7 ) +); +i1 i2 +1 4 +2 6 +DROP TABLE t1; diff --cc sql/opt_subselect.cc index 3abf879,da9159d..def13ff --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@@ -5961,6 -6310,420 +6316,421 @@@ bool JOIN::choose_tableless_subquery_pl tmp_having= having; } } + exec_const_cond= conds; return FALSE; } + + + /* + Check if the item exists in the fields list of the left part of + the IN subquery predicate subq_pred and returns its corresponding + item from the select of the right part of subq_pred. + */ + Item *Item::get_corresponding_field_in_insubq(Item_in_subselect *subq_pred) + { + DBUG_ASSERT(type() == Item::FIELD_ITEM || + (type() == Item::REF_ITEM && + ((Item_ref *) this)->ref_type() == Item_ref::VIEW_REF)); + + List_iterator<Field_pair> it(subq_pred->corresponding_fields); + Field_pair *ret; + Item_field *field_item= (Item_field *) (real_item()); + while ((ret= it++)) + { + if (field_item->field == ret->field) + return ret->corresponding_item; + } + return NULL; + } + + + bool Item_field::excl_dep_on_in_subq_left_part(Item_in_subselect *subq_pred) + { + if (((Item *)this)->get_corresponding_field_in_insubq(subq_pred)) + return true; + if (item_equal) + { + Item_equal_fields_iterator it(*item_equal); + Item *equal_item; + while ((equal_item= it++)) + { + if (equal_item->const_item()) + continue; + if (equal_item->get_corresponding_field_in_insubq(subq_pred)) + return true; + } + } + return false; + } + + + bool Item_direct_view_ref::excl_dep_on_in_subq_left_part(Item_in_subselect *subq_pred) + { + if (item_equal) + { + DBUG_ASSERT(real_item()->type() == Item::FIELD_ITEM); + if (((Item *)this)->get_corresponding_field_in_insubq(subq_pred)) + return true; + } + return (*ref)->excl_dep_on_in_subq_left_part(subq_pred); + } + + + bool Item_equal::excl_dep_on_in_subq_left_part(Item_in_subselect *subq_pred) + { + Item *left_item = get_const(); + Item_equal_fields_iterator it(*this); + Item *item; + if (!left_item) + { + while ((item=it++)) + { + if (item->excl_dep_on_in_subq_left_part(subq_pred)) + { + left_item= item; + break; + } + } + } + if (!left_item) + return false; + while ((item=it++)) + { + if (item->excl_dep_on_in_subq_left_part(subq_pred)) + return true; + } + return false; + } + + + /** + @brief + Get corresponding item from the select of the right part of IN subquery + + @param thd the thread handle + @param item the item from the left part of subq_pred for which + corresponding item should be found + @param subq_pred the IN subquery predicate + + @details + This method looks through the fields of the select of the right part of + the IN subquery predicate subq_pred trying to find the corresponding + item 'new_item' for item. If item has equal items it looks through + the fields of the select of the right part of subq_pred for each equal + item trying to find the corresponding item. + The method assumes that the given item is either a field item or + a reference to a field item. + + @retval <item*> reference to the corresponding item + @retval NULL if item was not found + */ + + static + Item *get_corresponding_item(THD *thd, Item *item, + Item_in_subselect *subq_pred) + { + DBUG_ASSERT(item->type() == Item::FIELD_ITEM || + (item->type() == Item::REF_ITEM && + ((Item_ref *) item)->ref_type() == Item_ref::VIEW_REF)); + + Item *corresonding_item; + Item_equal *item_equal= item->get_item_equal(); + + if (item_equal) + { + Item_equal_fields_iterator it(*item_equal); + Item *equal_item; + while ((equal_item= it++)) + { + corresonding_item= + equal_item->get_corresponding_field_in_insubq(subq_pred); + if (corresonding_item) + return corresonding_item; + } + return NULL; + } + else + return item->get_corresponding_field_in_insubq(subq_pred); + } + + + Item *Item_field::in_subq_field_transformer_for_where(THD *thd, uchar *arg) + { + Item_in_subselect *subq_pred= (Item_in_subselect *)arg; + Item *producing_item= get_corresponding_item(thd, this, subq_pred); + if (producing_item) + return producing_item->build_clone(thd); + return this; + } + + + Item *Item_direct_view_ref::in_subq_field_transformer_for_where(THD *thd, + uchar *arg) + { + if (item_equal) + { + Item_in_subselect *subq_pred= (Item_in_subselect *)arg; + Item *producing_item= get_corresponding_item(thd, this, subq_pred); + DBUG_ASSERT (producing_item != NULL); + return producing_item->build_clone(thd); + } + return this; + } + + + /** + @brief + Transforms item so it can be pushed into the IN subquery HAVING clause + + @param thd the thread handle + @param in_item the item for which pushable item should be created + @param subq_pred the IN subquery predicate + + @details + This method finds for in_item that is a field from the left part of the + IN subquery predicate subq_pred its corresponding item from the right part + of subq_pred. + If corresponding item is found, a shell for this item is created. + This shell can be pushed into the HAVING part of subq_pred select. + + @retval <item*> reference to the created corresponding item shell for in_item + @retval NULL if mistake occurs + */ + + static Item* + get_corresponding_item_for_in_subq_having(THD *thd, Item *in_item, + Item_in_subselect *subq_pred) + { + Item *new_item= get_corresponding_item(thd, in_item, subq_pred); + + if (new_item) + { + Item_ref *ref= + new (thd->mem_root) Item_ref(thd, + &subq_pred->unit->first_select()->context, + NullS, NullS, + &new_item->name); + if (!ref) + DBUG_ASSERT(0); + return ref; + } + return new_item; + } + + + Item *Item_field::in_subq_field_transformer_for_having(THD *thd, uchar *arg) + { + return get_corresponding_item_for_in_subq_having(thd, this, + (Item_in_subselect *)arg); + } + + + Item *Item_direct_view_ref::in_subq_field_transformer_for_having(THD *thd, + uchar *arg) + { + if (!item_equal) + return this; + else + { + Item *new_item= get_corresponding_item_for_in_subq_having(thd, this, + (Item_in_subselect *)arg); + if (!new_item) + return this; + return new_item; + } + } + + + /** + @brief + Find fields that are used in the GROUP BY of the select + + @param thd the thread handle + @param sel the select of the IN subquery predicate + @param fields fields of the left part of the IN subquery predicate + @param grouping_list GROUP BY clause + + @details + This method traverses fields which are used in the GROUP BY of + sel and saves them with their corresponding items from fields. + */ + + bool grouping_fields_in_the_in_subq_left_part(THD *thd, + st_select_lex *sel, + List<Field_pair> *fields, + ORDER *grouping_list) + { + DBUG_ENTER("grouping_fields_in_the_in_subq_left_part"); + sel->grouping_tmp_fields.empty(); + List_iterator<Field_pair> it(*fields); + Field_pair *item; + while ((item= it++)) + { + for (ORDER *ord= grouping_list; ord; ord= ord->next) + { + if ((*ord->item)->eq(item->corresponding_item, 0)) + { + if (sel->grouping_tmp_fields.push_back(item, thd->mem_root)) + DBUG_RETURN(TRUE); + } + } + } + DBUG_RETURN(FALSE); + } + + + /** + @brief + Extract condition that can be pushed into select of this IN subquery + + @param thd the thread handle + @param cond current condition + + @details + This function builds the most restrictive condition depending only on + the list of fields of the left part of this IN subquery predicate + (directly or indirectly through equality) that can be extracted from the + given condition cond and pushes it into this IN subquery. + + Example of the transformation: + + SELECT * FROM t1 + WHERE a>3 AND b>10 AND + (a,b) IN (SELECT x,MAX(y) FROM t2 GROUP BY x); + + => + + SELECT * FROM t1 + WHERE a>3 AND b>10 AND + (a,b) IN (SELECT x,max(y) + FROM t2 + WHERE x>3 + GROUP BY x + HAVING MAX(y)>10); + + + In details: + 1. Check what pushable formula can be extracted from cond + 2. Build a clone PC of the formula that can be extracted + (the clone is built only if the extracted formula is a AND subformula + of cond or conjunction of such subformulas) + 3. If there is no HAVING clause prepare PC to be conjuncted with + WHERE clause of this subquery. Otherwise do 4-7. + 4. Check what formula PC_where can be extracted from PC to be pushed + into the WHERE clause of the subquery + 5. Build PC_where and if PC_where is a conjunct(s) of PC remove it from PC + getting PC_having + 6. Prepare PC_where to be conjuncted with the WHERE clause of + the IN subquery + 7. Prepare PC_having to be conjuncted with the HAVING clause of + the IN subquery + + @note + This method is similar to pushdown_cond_for_derived() + + @retval TRUE if an error occurs + @retval FALSE otherwise + */ + + bool Item_in_subselect::pushdown_cond_for_in_subquery(THD *thd, Item *cond) + { + DBUG_ENTER("Item_in_subselect::pushdown_cond_for_in_subquery"); + Item *remaining_cond= NULL; + + if (!cond) + DBUG_RETURN(FALSE); + + st_select_lex *sel = unit->first_select(); + + if (is_jtbm_const_tab) + DBUG_RETURN(FALSE); + + if (!sel->cond_pushdown_is_allowed()) + DBUG_RETURN(FALSE); + + /* + Create a list of Field_pair items for this IN subquery. + It consists of the pairs of fields from the left part of this IN subquery + predicate 'left_part' and the respective fields from the select of the + right part of the IN subquery 'sel' (the field from left_part with the + corresponding field from the sel projection list). + Attach this list to the IN subquery. + */ + corresponding_fields.empty(); + List_iterator_fast<Item> it(sel->join->fields_list); + Item *item; + for (uint i= 0; i < left_expr->cols(); i++) + { + item= it++; + Item *elem= left_expr->element_index(i); + + if (elem->real_item()->type() != Item::FIELD_ITEM) + continue; + + if (corresponding_fields.push_back( + new Field_pair(((Item_field *)(elem->real_item()))->field, + item))) + DBUG_RETURN(TRUE); + } + + /* 1. Check what pushable formula can be extracted from cond */ + Item *extracted_cond; + cond->check_pushable_cond(&Item::pushable_cond_checker_for_subquery, + (uchar *)this); + /* 2. Build a clone PC of the formula that can be extracted */ + extracted_cond= + cond->build_pushable_cond(thd, + &Item::pushable_equality_checker_for_subquery, + (uchar *)this); + /* Nothing to push */ + if (!extracted_cond) + { + DBUG_RETURN(FALSE); + } + + /* Collect fields that are used in the GROUP BY of sel */ + st_select_lex *save_curr_select= thd->lex->current_select; + if (sel->have_window_funcs()) + { + if (sel->group_list.first || sel->join->implicit_grouping) + goto exit; + ORDER *common_partition_fields= + sel->find_common_window_func_partition_fields(thd); + if (!common_partition_fields) + goto exit; + + if (grouping_fields_in_the_in_subq_left_part(thd, sel, &corresponding_fields, + common_partition_fields)) + DBUG_RETURN(TRUE); + } + else if (grouping_fields_in_the_in_subq_left_part(thd, sel, + &corresponding_fields, + sel->group_list.first)) + DBUG_RETURN(TRUE); + + /* Do 4-6 */ + sel->pushdown_cond_into_where_clause(thd, extracted_cond, + &remaining_cond, + &Item::in_subq_field_transformer_for_where, + (uchar *) this); + if (!remaining_cond) + goto exit; + /* + 7. Prepare PC_having to be conjuncted with the HAVING clause of + the IN subquery + */ + remaining_cond= + remaining_cond->transform(thd, + &Item::in_subq_field_transformer_for_having, + (uchar *)this); + if (!remaining_cond) + goto exit; + + remaining_cond->walk(&Item::cleanup_excluding_const_fields_processor, + 0, 0); + sel->cond_pushed_into_having= remaining_cond; + + exit: + thd->lex->current_select= save_curr_select; + DBUG_RETURN(FALSE); + } diff --cc sql/sql_lex.cc index 2c8c4f4,bea9fa0..8c7527e --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@@ -7787,169 -7497,126 +7786,294 @@@ bool SELECT_LEX::vers_push_field(THD *t } +Item *Lex_trim_st::make_item_func_trim_std(THD *thd) const +{ + if (m_remove) + { + switch (m_spec) { + case TRIM_BOTH: + return new (thd->mem_root) Item_func_trim(thd, m_source, m_remove); + case TRIM_LEADING: + return new (thd->mem_root) Item_func_ltrim(thd, m_source, m_remove); + case TRIM_TRAILING: + return new (thd->mem_root) Item_func_rtrim(thd, m_source, m_remove); + } + } + + switch (m_spec) { + case TRIM_BOTH: + return new (thd->mem_root) Item_func_trim(thd, m_source); + case TRIM_LEADING: + return new (thd->mem_root) Item_func_ltrim(thd, m_source); + case TRIM_TRAILING: + return new (thd->mem_root) Item_func_rtrim(thd, m_source); + } + DBUG_ASSERT(0); + return NULL; +} + + +Item *Lex_trim_st::make_item_func_trim_oracle(THD *thd) const +{ + if (m_remove) + { + switch (m_spec) { + case TRIM_BOTH: + return new (thd->mem_root) Item_func_trim_oracle(thd, m_source, m_remove); + case TRIM_LEADING: + return new (thd->mem_root) Item_func_ltrim_oracle(thd, m_source, m_remove); + case TRIM_TRAILING: + return new (thd->mem_root) Item_func_rtrim_oracle(thd, m_source, m_remove); + } + } + + switch (m_spec) { + case TRIM_BOTH: + return new (thd->mem_root) Item_func_trim_oracle(thd, m_source); + case TRIM_LEADING: + return new (thd->mem_root) Item_func_ltrim_oracle(thd, m_source); + case TRIM_TRAILING: + return new (thd->mem_root) Item_func_rtrim_oracle(thd, m_source); + } + DBUG_ASSERT(0); + return NULL; +} + + +Item *Lex_trim_st::make_item_func_trim(THD *thd) const +{ + return (thd->variables.sql_mode & MODE_ORACLE) ? + make_item_func_trim_oracle(thd) : + make_item_func_trim_std(thd); +} + + +Item *LEX::make_item_func_call_generic(THD *thd, Lex_ident_cli_st *cdb, + Lex_ident_cli_st *cname, List<Item> *args) +{ + Lex_ident_sys db(thd, cdb), name(thd, cname); + if (db.is_null() || name.is_null()) + return NULL; // EOM + /* + The following in practice calls: + <code>Create_sp_func::create()</code> + and builds a stored function. + + However, it's important to maintain the interface between the + parser and the implementation in item_create.cc clean, + since this will change with WL#2128 (SQL PATH): + - INFORMATION_SCHEMA.version() is the SQL 99 syntax for the native + function version(), + - MySQL.version() is the SQL 2003 syntax for the native function + version() (a vendor can specify any schema). + */ + + if (!name.str || check_db_name((LEX_STRING*) static_cast<LEX_CSTRING*>(&db))) + { + my_error(ER_WRONG_DB_NAME, MYF(0), db.str); + return NULL; + } + if (check_routine_name(&name)) + return NULL; + + Create_qfunc *builder= find_qualified_function_builder(thd); + DBUG_ASSERT(builder); + return builder->create_with_db(thd, &db, &name, true, args); +} + + +Item *LEX::create_item_qualified_asterisk(THD *thd, + const Lex_ident_sys_st *name) +{ + Item *item; + if (!(item= new (thd->mem_root) Item_field(thd, current_context(), + NullS, name->str, + &star_clex_str))) + return NULL; + current_select->with_wild++; + return item; +} + + +Item *LEX::create_item_qualified_asterisk(THD *thd, + const Lex_ident_sys_st *a, + const Lex_ident_sys_st *b) +{ + Item *item; + const char* schema= thd->client_capabilities & CLIENT_NO_SCHEMA ? + NullS : a->str; + if (!(item= new (thd->mem_root) Item_field(thd, current_context(), + schema, b->str, + &star_clex_str))) + return NULL; + current_select->with_wild++; + return item; +} + + +bool Lex_ident_sys_st::copy_ident_cli(THD *thd, const Lex_ident_cli_st *str) +{ + return thd->to_ident_sys_alloc(this, str); +} + +bool Lex_ident_sys_st::copy_keyword(THD *thd, const Lex_ident_cli_st *str) +{ + return thd->make_lex_string(static_cast<LEX_CSTRING*>(this), + str->str, str->length) == NULL; +} + +bool Lex_ident_sys_st::copy_or_convert(THD *thd, + const Lex_ident_cli_st *src, + CHARSET_INFO *cs) +{ + if (!src->is_8bit()) + return copy_keyword(thd, src); // 7bit string makes a wellformed identifier + return convert(thd, src, cs); +} + + +bool Lex_ident_sys_st::copy_sys(THD *thd, const LEX_CSTRING *src) +{ + if (thd->check_string_for_wellformedness(src->str, src->length, + system_charset_info)) + return true; + return thd->make_lex_string(this, src->str, src->length) == NULL; +} + + +bool Lex_ident_sys_st::convert(THD *thd, + const LEX_CSTRING *src, CHARSET_INFO *cs) +{ + LEX_STRING tmp; + if (thd->convert_with_error(system_charset_info, &tmp, cs, + src->str, src->length)) + return true; + str= tmp.str; + length= tmp.length; + return false; +} ++ ++ + /** + @brief + Extract from given item a condition pushable into WHERE clause + + @param thd the thread handle + @param cond the item to extract a condition to be pushed + into WHERE + @param remaining_cond the condition that will remain of cond after + the pushdown of its parts into the WHERE clause + @param transformer the transformer callback function to be + applied to the condition so it can be pushed + down into the WHERE clause of this select + @param arg parameter to be passed to the transformer + + @details + This method checks if cond entirely or its parts can be + pushed into the WHERE clause of this select and prepares it for pushing. + + First it checks wherever this select doesn't have any aggregation function + in its projection and GROUP BY clause. If so cond can be entirely + pushed into the WHERE clause of this select but before its fields should + be transformed with transformer_for_where to make it pushable. + + Otherwise the method checks wherever any condition depending only on + grouping fields can be extracted from cond. If there is any it prepares it + for pushing using grouping_field_transformer_for_where and if it happens to + be a conjunct of cond it removes it from cond. It saves the result of + removal in remaining_cond. + The extracted condition is saved in cond_pushed_into_where of this select. + + @note + When looking for pushable condition the method considers only the grouping + fields from the list grouping_tmp_fields whose elements are of the type + Field_pair. This list must be prepared before the call of the + function. + + @note + This method is called for pushdown conditions into materialized + derived tables/views optimization. + Item::derived_field_transformer_for_where is passed as the actual + callback function. + Also it is called for pushdown conditions into materialized IN subqueries. + Item::in_subq_field_transformer_for_where is passed as the actual + callback function. + */ + + void st_select_lex::pushdown_cond_into_where_clause(THD *thd, Item *cond, + Item **remaining_cond, + Item_transformer transformer, + uchar *arg) + { + if (!cond_pushdown_is_allowed()) + return; + thd->lex->current_select= this; + if (have_window_funcs()) + { + Item *cond_over_partition_fields; + check_cond_extraction_for_grouping_fields(cond); + cond_over_partition_fields= + build_cond_for_grouping_fields(thd, cond, true); + if (cond_over_partition_fields) + cond_over_partition_fields= cond_over_partition_fields->transform(thd, + &Item::grouping_field_transformer_for_where, + (uchar*) this); + if (cond_over_partition_fields) + { + cond_over_partition_fields->walk( + &Item::cleanup_excluding_const_fields_processor, 0, 0); + cond_pushed_into_where= cond_over_partition_fields; + } + + return; + } + + if (!join->group_list && !with_sum_func) + { + cond= + cond->transform(thd, transformer, arg); + if (cond) + { + cond->walk( + &Item::cleanup_excluding_const_fields_processor, 0, 0); + cond_pushed_into_where= cond; + } + + return; + } + + /* + Figure out what can be extracted from cond + that could be pushed into the WHERE clause of this select + */ + Item *cond_over_grouping_fields; + check_cond_extraction_for_grouping_fields(cond); + cond_over_grouping_fields= + build_cond_for_grouping_fields(thd, cond, true); + + /* + Transform the references to the columns from the cond + pushed into the WHERE clause of this select to make them usable in + the new context + */ + if (cond_over_grouping_fields) + cond_over_grouping_fields= cond_over_grouping_fields->transform(thd, + &Item::grouping_field_transformer_for_where, + (uchar*) this); + + if (cond_over_grouping_fields) + { + + /* + In cond remove top conjuncts that has been pushed into the WHERE + clause of this select + */ + cond= remove_pushed_top_conjuncts(thd, cond); + + cond_over_grouping_fields->walk( + &Item::cleanup_excluding_const_fields_processor, 0, 0); + cond_pushed_into_where= cond_over_grouping_fields; + } + + *remaining_cond= cond; + }
participants (1)
-
galina.shalyginaï¼ mariadb.com