You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1289 lines
82 KiB

  1. set @@optimizer_switch='semijoin=off';
  2. set optimizer_switch='firstmatch=off';
  3. drop table if exists t1, t2, t3, t1i, t2i, t3i;
  4. drop view if exists v1, v2, v1m, v2m;
  5. create table t1 (a1 char(8), a2 char(8));
  6. create table t2 (b1 char(8), b2 char(8));
  7. create table t3 (c1 char(8), c2 char(8));
  8. insert into t1 values ('1 - 00', '2 - 00');
  9. insert into t1 values ('1 - 01', '2 - 01');
  10. insert into t1 values ('1 - 02', '2 - 02');
  11. insert into t2 values ('1 - 01', '2 - 01');
  12. insert into t2 values ('1 - 01', '2 - 01');
  13. insert into t2 values ('1 - 02', '2 - 02');
  14. insert into t2 values ('1 - 02', '2 - 02');
  15. insert into t2 values ('1 - 03', '2 - 03');
  16. insert into t3 values ('1 - 01', '2 - 01');
  17. insert into t3 values ('1 - 02', '2 - 02');
  18. insert into t3 values ('1 - 03', '2 - 03');
  19. insert into t3 values ('1 - 04', '2 - 04');
  20. create table t1i (a1 char(8), a2 char(8));
  21. create table t2i (b1 char(8), b2 char(8));
  22. create table t3i (c1 char(8), c2 char(8));
  23. create index it1i1 on t1i (a1);
  24. create index it1i2 on t1i (a2);
  25. create index it1i3 on t1i (a1, a2);
  26. create index it2i1 on t2i (b1);
  27. create index it2i2 on t2i (b2);
  28. create index it2i3 on t2i (b1, b2);
  29. create index it3i1 on t3i (c1);
  30. create index it3i2 on t3i (c2);
  31. create index it3i3 on t3i (c1, c2);
  32. insert into t1i select * from t1;
  33. insert into t2i select * from t2;
  34. insert into t3i select * from t3;
  35. /******************************************************************************
  36. * Simple tests.
  37. ******************************************************************************/
  38. # non-indexed nullable fields
  39. explain extended
  40. select * from t1 where a1 in (select b1 from t2 where b1 > '0');
  41. id select_type table type possible_keys key key_len ref rows filtered Extra
  42. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  43. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  44. Warnings:
  45. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` AS `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`)))))
  46. select * from t1 where a1 in (select b1 from t2 where b1 > '0');
  47. a1 a2
  48. 1 - 01 2 - 01
  49. 1 - 02 2 - 02
  50. explain extended
  51. select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
  52. id select_type table type possible_keys key key_len ref rows filtered Extra
  53. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  54. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary; Using filesort
  55. Warnings:
  56. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` AS `b1` 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`)))))
  57. select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
  58. a1 a2
  59. 1 - 01 2 - 01
  60. 1 - 02 2 - 02
  61. explain extended
  62. select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
  63. id select_type table type possible_keys key key_len ref rows filtered Extra
  64. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  65. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary; Using filesort
  66. Warnings:
  67. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group 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`)))))
  68. select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
  69. a1 a2
  70. 1 - 01 2 - 01
  71. 1 - 02 2 - 02
  72. explain extended
  73. select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
  74. id select_type table type possible_keys key key_len ref rows filtered Extra
  75. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  76. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using temporary; Using filesort
  77. Warnings:
  78. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,min(`test`.`t2`.`b2`) AS `min(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)`)))))
  79. select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
  80. a1 a2
  81. 1 - 01 2 - 01
  82. 1 - 02 2 - 02
  83. explain extended
  84. select * from t1i where a1 in (select b1 from t2i where b1 > '0');
  85. id select_type table type possible_keys key key_len ref rows filtered Extra
  86. 1 PRIMARY t1i index NULL it1i3 18 NULL 3 100.00 Using where; Using index
  87. 2 SUBQUERY t2i index it2i1,it2i3 it2i1 9 NULL 5 100.00 Using where; Using index
  88. Warnings:
  89. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` AS `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`)))))
  90. select * from t1i where a1 in (select b1 from t2i where b1 > '0');
  91. a1 a2
  92. 1 - 01 2 - 01
  93. 1 - 02 2 - 02
  94. explain extended
  95. select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
  96. id select_type table type possible_keys key key_len ref rows filtered Extra
  97. 1 PRIMARY t1i index NULL # 18 # 3 100.00 #
  98. 2 SUBQUERY t2i range it2i1,it2i3 # 9 # 3 100.00 #
  99. Warnings:
  100. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` AS `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>`.`b1`)))))
  101. select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
  102. a1 a2
  103. 1 - 01 2 - 01
  104. 1 - 02 2 - 02
  105. explain extended
  106. select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
  107. id select_type table type possible_keys key key_len ref rows filtered Extra
  108. 1 PRIMARY t1i index NULL it1i3 18 NULL 3 100.00 Using where; Using index
  109. 2 SUBQUERY t2i index it2i1,it2i3 it2i3 18 NULL 5 100.00 Using where; Using index
  110. Warnings:
  111. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`)))))
  112. select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
  113. a1 a2
  114. 1 - 01 2 - 01
  115. 1 - 02 2 - 02
  116. explain extended
  117. select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
  118. id select_type table type possible_keys key key_len ref rows filtered Extra
  119. 1 PRIMARY t1i index NULL # # # 3 100.00 #
  120. 2 SUBQUERY t2i range it2i1,it2i3 # # # 3 100.00 #
  121. Warnings:
  122. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group 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`)))))
  123. select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
  124. a1 a2
  125. 1 - 01 2 - 01
  126. 1 - 02 2 - 02
  127. explain extended
  128. select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
  129. id select_type table type possible_keys key key_len ref rows filtered Extra
  130. 1 PRIMARY t1i index NULL # # # 3 100.00 #
  131. 2 SUBQUERY t2i range it2i1,it2i3 # # # 3 100.00 #
  132. Warnings:
  133. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,min(`test`.`t2i`.`b2`) AS `min(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)`)))))
  134. select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
  135. a1 a2
  136. 1 - 01 2 - 01
  137. 1 - 02 2 - 02
  138. explain extended
  139. select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1);
  140. id select_type table type possible_keys key key_len ref rows filtered Extra
  141. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  142. 2 SUBQUERY t2i range NULL it2i3 9 NULL 3 100.00 Using index for group-by
  143. Warnings:
  144. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,max(`test`.`t2i`.`b2`) AS `max(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)`)))))
  145. select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1);
  146. a1 a2
  147. 1 - 01 2 - 01
  148. 1 - 02 2 - 02
  149. prepare st1 from "explain select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)";
  150. execute st1;
  151. id select_type table type possible_keys key key_len ref rows Extra
  152. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
  153. 2 SUBQUERY t2i range NULL it2i3 9 NULL 3 Using index for group-by
  154. execute st1;
  155. id select_type table type possible_keys key key_len ref rows Extra
  156. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
  157. 2 SUBQUERY t2i range NULL it2i3 9 NULL 3 Using index for group-by
  158. prepare st2 from "select * from t1 where (a1, a2) in (select b1, max(b2) from t2i group by b1)";
  159. execute st2;
  160. a1 a2
  161. 1 - 01 2 - 01
  162. 1 - 02 2 - 02
  163. execute st2;
  164. a1 a2
  165. 1 - 01 2 - 01
  166. 1 - 02 2 - 02
  167. explain extended
  168. select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
  169. id select_type table type possible_keys key key_len ref rows filtered Extra
  170. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  171. 2 SUBQUERY t2i range it2i1,it2i3 it2i3 18 NULL 3 100.00 Using where; Using index for group-by
  172. Warnings:
  173. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,min(`test`.`t2i`.`b2`) AS `min(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)`)))))
  174. select * from t1 where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
  175. a1 a2
  176. 1 - 01 2 - 01
  177. 1 - 02 2 - 02
  178. select * from t1 where (a1, a2) in (select b1, min(b2) from t2i limit 1,1);
  179. ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
  180. set @save_optimizer_switch=@@optimizer_switch;
  181. set @@optimizer_switch='default,semijoin=off';
  182. prepare st1 from
  183. "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
  184. set @@optimizer_switch='default,materialization=off';
  185. execute st1;
  186. a1 a2
  187. 1 - 01 2 - 01
  188. 1 - 02 2 - 02
  189. set @@optimizer_switch='default,semijoin=off';
  190. execute st1;
  191. a1 a2
  192. 1 - 01 2 - 01
  193. 1 - 02 2 - 02
  194. set @@optimizer_switch='default,materialization=off';
  195. prepare st1 from
  196. "select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1)";
  197. set @@optimizer_switch='default,semijoin=off';
  198. execute st1;
  199. a1 a2
  200. 1 - 01 2 - 01
  201. 1 - 02 2 - 02
  202. set @@optimizer_switch='default,materialization=off';
  203. execute st1;
  204. a1 a2
  205. 1 - 01 2 - 01
  206. 1 - 02 2 - 02
  207. set @@optimizer_switch=@save_optimizer_switch;
  208. explain extended
  209. select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
  210. id select_type table type possible_keys key key_len ref rows filtered Extra
  211. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  212. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00
  213. Warnings:
  214. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `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`)))))
  215. select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
  216. a1 a2
  217. 1 - 01 2 - 01
  218. 1 - 02 2 - 02
  219. explain extended
  220. select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
  221. id select_type table type possible_keys key key_len ref rows filtered Extra
  222. 1 PRIMARY t1i index NULL it1i3 18 NULL 3 100.00 Using where; Using index
  223. 2 SUBQUERY t2i index NULL it2i3 18 NULL 5 100.00 Using index
  224. Warnings:
  225. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`)))))
  226. select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
  227. a1 a2
  228. 1 - 01 2 - 01
  229. 1 - 02 2 - 02
  230. /******************************************************************************
  231. * Views, UNIONs, several levels of nesting.
  232. ******************************************************************************/
  233. # materialize the result of subquery over temp-table view
  234. create algorithm=merge view v1 as
  235. select b1, c2 from t2, t3 where b2 > c2;
  236. create algorithm=merge view v2 as
  237. select b1, c2 from t2, t3 group by b2, c2;
  238. Warnings:
  239. Warning 1354 View merge algorithm can't be used here for now (assumed undefined algorithm)
  240. create algorithm=temptable view v1m as
  241. select b1, c2 from t2, t3 where b2 > c2;
  242. create algorithm=temptable view v2m as
  243. select b1, c2 from t2, t3 group by b2, c2;
  244. select * from v1 where (c2, b1) in (select c2, b1 from v2 where b1 is not null);
  245. b1 c2
  246. 1 - 02 2 - 01
  247. 1 - 02 2 - 01
  248. 1 - 03 2 - 01
  249. 1 - 03 2 - 02
  250. select * from v1 where (c2, b1) in (select distinct c2, b1 from v2 where b1 is not null);
  251. b1 c2
  252. 1 - 02 2 - 01
  253. 1 - 02 2 - 01
  254. 1 - 03 2 - 01
  255. 1 - 03 2 - 02
  256. select * from v1m where (c2, b1) in (select c2, b1 from v2m where b1 is not null);
  257. b1 c2
  258. 1 - 02 2 - 01
  259. 1 - 02 2 - 01
  260. 1 - 03 2 - 01
  261. 1 - 03 2 - 02
  262. select * from v1m where (c2, b1) in (select distinct c2, b1 from v2m where b1 is not null);
  263. b1 c2
  264. 1 - 02 2 - 01
  265. 1 - 02 2 - 01
  266. 1 - 03 2 - 01
  267. 1 - 03 2 - 02
  268. drop view v1, v2, v1m, v2m;
  269. explain extended
  270. select * from t1
  271. where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
  272. (a1, a2) in (select c1, c2 from t3
  273. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  274. id select_type table type possible_keys key key_len ref rows filtered Extra
  275. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  276. 3 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  277. 4 SUBQUERY t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index
  278. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  279. Warnings:
  280. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `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 <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`))))))
  281. select * from t1
  282. where (a1, a2) in (select b1, b2 from t2 where b1 > '0') and
  283. (a1, a2) in (select c1, c2 from t3
  284. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  285. a1 a2
  286. 1 - 01 2 - 01
  287. 1 - 02 2 - 02
  288. explain extended
  289. select * from t1i
  290. where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
  291. (a1, a2) in (select c1, c2 from t3i
  292. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  293. id select_type table type possible_keys key key_len ref rows filtered Extra
  294. 1 PRIMARY t1i index NULL # # # 3 100.00 #
  295. 3 SUBQUERY t3i index NULL # # # 4 100.00 #
  296. 4 SUBQUERY t2i index it2i2 # # # 5 100.00 #
  297. 2 SUBQUERY t2i index it2i1,it2i3 # # # 5 100.00 #
  298. Warnings:
  299. Note 1003 select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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 <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1` AS `c1`,`test`.`t3i`.`c2` AS `c2` from `test`.`t3i` where <in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`))))))
  300. select * from t1i
  301. where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
  302. (a1, a2) in (select c1, c2 from t3i
  303. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  304. a1 a2
  305. 1 - 01 2 - 01
  306. 1 - 02 2 - 02
  307. explain extended
  308. select * from t1
  309. where (a1, a2) in (select b1, b2 from t2
  310. where b2 in (select c2 from t3 where c2 LIKE '%02') or
  311. b2 in (select c2 from t3 where c2 LIKE '%03')) and
  312. (a1, a2) in (select c1, c2 from t3
  313. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  314. id select_type table type possible_keys key key_len ref rows filtered Extra
  315. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  316. 5 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  317. 6 SUBQUERY t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index
  318. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  319. 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  320. 3 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  321. Warnings:
  322. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `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 <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key where ((`test`.`t2`.`b2` = `<subquery4>`.`c2`)))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery2>`.`b1`) and (`test`.`t1`.`a2` = `<subquery2>`.`b2`))))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`))))))
  323. select * from t1
  324. where (a1, a2) in (select b1, b2 from t2
  325. where b2 in (select c2 from t3 where c2 LIKE '%02') or
  326. b2 in (select c2 from t3 where c2 LIKE '%03')) and
  327. (a1, a2) in (select c1, c2 from t3
  328. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  329. a1 a2
  330. 1 - 02 2 - 02
  331. explain extended
  332. select * from t1
  333. where (a1, a2) in (select b1, b2 from t2
  334. where b2 in (select c2 from t3 t3a where c1 = a1) or
  335. b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
  336. (a1, a2) in (select c1, c2 from t3 t3c
  337. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  338. id select_type table type possible_keys key key_len ref rows filtered Extra
  339. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  340. 5 SUBQUERY t3c ALL NULL NULL NULL NULL 4 100.00 Using where
  341. 6 SUBQUERY t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index
  342. 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  343. 4 SUBQUERY t3b ALL NULL NULL NULL NULL 4 100.00 Using where
  344. 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where
  345. Warnings:
  346. Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
  347. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where ((<in_optimizer>(`test`.`t2`.`b2`,<exists>(select 1 AS `Not_used` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` AS `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 <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3c`.`c1` AS `c1`,`test`.`t3c`.`c2` AS `c2` from `test`.`t3` `t3c` where <in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),(`test`.`t3c`.`c1`,`test`.`t3c`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`))))))
  348. select * from t1
  349. where (a1, a2) in (select b1, b2 from t2
  350. where b2 in (select c2 from t3 t3a where c1 = a1) or
  351. b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
  352. (a1, a2) in (select c1, c2 from t3 t3c
  353. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  354. a1 a2
  355. 1 - 01 2 - 01
  356. 1 - 02 2 - 02
  357. explain extended
  358. (select * from t1
  359. where (a1, a2) in (select b1, b2 from t2
  360. where b2 in (select c2 from t3 where c2 LIKE '%02') or
  361. b2 in (select c2 from t3 where c2 LIKE '%03')
  362. group by b1, b2) and
  363. (a1, a2) in (select c1, c2 from t3
  364. where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
  365. UNION
  366. (select * from t1i
  367. where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
  368. (a1, a2) in (select c1, c2 from t3i
  369. where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
  370. id select_type table type possible_keys key key_len ref rows filtered Extra
  371. 1 PRIMARY t1 ALL NULL # # # 3 100.00 #
  372. 5 SUBQUERY t3 ALL NULL # # # 4 100.00 #
  373. 6 SUBQUERY t2i index it2i2 # # # 5 100.00 #
  374. 2 SUBQUERY t2 ALL NULL # # # 5 100.00 #
  375. 4 SUBQUERY t3 ALL NULL # # # 4 100.00 #
  376. 3 SUBQUERY t3 ALL NULL # # # 4 100.00 #
  377. 7 UNION t1i index NULL # # # 3 100.00 #
  378. 9 SUBQUERY t3i index NULL # # # 4 100.00 #
  379. 10 SUBQUERY t2i index it2i2 # # # 5 100.00 #
  380. 8 SUBQUERY t2i index it2i1,it2i3 # # # 5 100.00 #
  381. NULL UNION RESULT <union1,7> ALL NULL # # # NULL NULL #
  382. Warnings:
  383. Note 1003 (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `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 <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `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`)))))) group 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`))))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key where ((`test`.`t3`.`c1` = `<subquery6>`.`b1`) and (`test`.`t3`.`c2` = `<subquery6>`.`b2`))))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key where ((`test`.`t1`.`a1` = `<subquery5>`.`c1`) and (`test`.`t1`.`a2` = `<subquery5>`.`c2`))))))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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 <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1` AS `c1`,`test`.`t3i`.`c2` AS `c2` from `test`.`t3i` where <in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`)))))))
  384. (select * from t1
  385. where (a1, a2) in (select b1, b2 from t2
  386. where b2 in (select c2 from t3 where c2 LIKE '%02') or
  387. b2 in (select c2 from t3 where c2 LIKE '%03')
  388. group by b1, b2) and
  389. (a1, a2) in (select c1, c2 from t3
  390. where (c1, c2) in (select b1, b2 from t2i where b2 > '0')))
  391. UNION
  392. (select * from t1i
  393. where (a1, a2) in (select b1, b2 from t2i where b1 > '0') and
  394. (a1, a2) in (select c1, c2 from t3i
  395. where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
  396. a1 a2
  397. 1 - 02 2 - 02
  398. 1 - 01 2 - 01
  399. explain extended
  400. select * from t1
  401. where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
  402. (a1, a2) in (select c1, c2 from t3
  403. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  404. id select_type table type possible_keys key key_len ref rows filtered Extra
  405. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  406. 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  407. 5 SUBQUERY t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index
  408. 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  409. 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  410. NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
  411. Warnings:
  412. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `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 `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `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 <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`))))))
  413. select * from t1
  414. where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
  415. (a1, a2) in (select c1, c2 from t3
  416. where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
  417. a1 a2
  418. 1 - 01 2 - 01
  419. 1 - 02 2 - 02
  420. explain extended
  421. select * from t1, t3
  422. where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
  423. (c1, c2) in (select c1, c2 from t3
  424. where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
  425. a1 = c1;
  426. id select_type table type possible_keys key key_len ref rows filtered Extra
  427. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  428. 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer
  429. 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  430. 5 SUBQUERY t2i index it2i2 it2i3 18 NULL 5 100.00 Using where; Using index
  431. 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  432. 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  433. NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
  434. Warnings:
  435. Note 1003 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 <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `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 `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `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 <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `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`))))))
  436. select * from t1, t3
  437. where (a1, a2) in (select * from t1 where a1 > '0' UNION select * from t2 where b1 < '9') and
  438. (c1, c2) in (select c1, c2 from t3
  439. where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
  440. a1 = c1;
  441. a1 a2 c1 c2
  442. 1 - 01 2 - 01 1 - 01 2 - 01
  443. 1 - 02 2 - 02 1 - 02 2 - 02
  444. /******************************************************************************
  445. * Negative tests, where materialization should not be applied.
  446. ******************************************************************************/
  447. # UNION in a subquery
  448. explain extended
  449. select * from t3
  450. where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
  451. id select_type table type possible_keys key key_len ref rows filtered Extra
  452. 1 PRIMARY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  453. 2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  454. 3 DEPENDENT UNION t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  455. NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL NULL
  456. Warnings:
  457. Note 1003 select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`c1`,<exists>(select 1 AS `Not_used` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1`)) union select 1 AS `Not_used` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))))
  458. select * from t3
  459. where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
  460. c1 c2
  461. 1 - 01 2 - 01
  462. 1 - 02 2 - 02
  463. 1 - 03 2 - 03
  464. explain extended
  465. select * from t1
  466. where (a1, a2) in (select b1, b2 from t2
  467. where b2 in (select c2 from t3 t3a where c1 = a1) or
  468. b2 in (select c2 from t3 t3b where c2 LIKE '%03')) and
  469. (a1, a2) in (select c1, c2 from t3 t3c
  470. where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2));
  471. id select_type table type possible_keys key key_len ref rows filtered Extra
  472. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  473. 5 DEPENDENT SUBQUERY t3c ALL NULL NULL NULL NULL 4 100.00 Using where
  474. 6 DEPENDENT SUBQUERY t2i index_subquery it2i1,it2i2,it2i3 it2i3 18 func,func 2 100.00 Using index; Using where
  475. 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where
  476. 4 SUBQUERY t3b ALL NULL NULL NULL NULL 4 100.00 Using where
  477. 3 DEPENDENT SUBQUERY t3a ALL NULL NULL NULL NULL 4 100.00 Using where
  478. Warnings:
  479. Note 1276 Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
  480. Note 1276 Field or reference 'test.t1.a2' of SELECT #6 was resolved in SELECT #1
  481. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where ((<in_optimizer>(`test`.`t2`.`b2`,<exists>(select 1 AS `Not_used` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` AS `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 <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t3c`.`c1` AS `c1`,`test`.`t3c`.`c2` AS `c2` from `test`.`t3` `t3c` where (<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`)))))
  482. explain extended
  483. select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
  484. id select_type table type possible_keys key key_len ref rows filtered Extra
  485. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  486. 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
  487. Warnings:
  488. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01' AS `1 - 01`,'2 - 01' AS `2 - 01` having ((<cache>(`test`.`t1`.`a1`) = '1 - 01') and (<cache>(`test`.`t1`.`a2`) = '2 - 01'))))
  489. select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
  490. a1 a2
  491. 1 - 01 2 - 01
  492. explain extended
  493. select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual);
  494. id select_type table type possible_keys key key_len ref rows filtered Extra
  495. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  496. 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL NULL No tables used
  497. Warnings:
  498. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01' AS `1 - 01`,'2 - 01' AS `2 - 01` having ((<cache>(`test`.`t1`.`a1`) = '1 - 01') and (<cache>(`test`.`t1`.`a2`) = '2 - 01'))))
  499. select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01' from dual);
  500. a1 a2
  501. 1 - 01 2 - 01
  502. /******************************************************************************
  503. * Subqueries in other uncovered clauses.
  504. ******************************************************************************/
  505. /* SELECT clause */
  506. select ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL from t1;
  507. ((a1,a2) IN (select * from t2 where b2 > '0')) IS NULL
  508. 0
  509. 0
  510. 0
  511. /* GROUP BY clause */
  512. create table columns (col int key);
  513. insert into columns values (1), (2);
  514. explain extended
  515. select * from t1 group by (select col from columns limit 1);
  516. id select_type table type possible_keys key key_len ref rows filtered Extra
  517. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
  518. 2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index
  519. Warnings:
  520. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by (select `test`.`columns`.`col` AS `col` from `test`.`columns` limit 1)
  521. select * from t1 group by (select col from columns limit 1);
  522. a1 a2
  523. 1 - 00 2 - 00
  524. explain extended
  525. select * from t1 group by (a1 in (select col from columns));
  526. id select_type table type possible_keys key key_len ref rows filtered Extra
  527. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using temporary; Using filesort
  528. 2 DEPENDENT SUBQUERY columns unique_subquery PRIMARY PRIMARY 4 func 1 100.00 Using index; Using where; Full scan on NULL key
  529. Warnings:
  530. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <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`)))))
  531. select * from t1 group by (a1 in (select col from columns));
  532. a1 a2
  533. 1 - 00 2 - 00
  534. /* ORDER BY clause */
  535. explain extended
  536. select * from t1 order by (select col from columns limit 1);
  537. id select_type table type possible_keys key key_len ref rows filtered Extra
  538. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
  539. 2 SUBQUERY columns index NULL PRIMARY 4 NULL 2 100.00 Using index
  540. Warnings:
  541. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` order by (select `test`.`columns`.`col` AS `col` from `test`.`columns` limit 1)
  542. select * from t1 order by (select col from columns limit 1);
  543. a1 a2
  544. 1 - 00 2 - 00
  545. 1 - 01 2 - 01
  546. 1 - 02 2 - 02
  547. /******************************************************************************
  548. * Column types/sizes that affect materialization.
  549. ******************************************************************************/
  550. /*
  551. Test that BLOBs are not materialized (except when arguments of some functions).
  552. */
  553. # force materialization to be always considered
  554. set @prefix_len = 6;
  555. set @blob_len = 16;
  556. set @suffix_len = @blob_len - @prefix_len;
  557. create table t1_16 (a1 blob(16), a2 blob(16));
  558. create table t2_16 (b1 blob(16), b2 blob(16));
  559. create table t3_16 (c1 blob(16), c2 blob(16));
  560. insert into t1_16 values
  561. (concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
  562. insert into t1_16 values
  563. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  564. insert into t1_16 values
  565. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  566. insert into t2_16 values
  567. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  568. insert into t2_16 values
  569. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  570. insert into t2_16 values
  571. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  572. insert into t3_16 values
  573. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  574. insert into t3_16 values
  575. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  576. insert into t3_16 values
  577. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  578. insert into t3_16 values
  579. (concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
  580. explain extended select left(a1,7), left(a2,7)
  581. from t1_16
  582. where a1 in (select b1 from t2_16 where b1 > '0');
  583. id select_type table type possible_keys key key_len ref rows filtered Extra
  584. 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  585. 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  586. Warnings:
  587. 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` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select 1 AS `Not_used` from `test`.`t2_16` where ((`test`.`t2_16`.`b1` > '0') and (<cache>(`test`.`t1_16`.`a1`) = `test`.`t2_16`.`b1`))))
  588. select left(a1,7), left(a2,7)
  589. from t1_16
  590. where a1 in (select b1 from t2_16 where b1 > '0');
  591. left(a1,7) left(a2,7)
  592. 1 - 01x 2 - 01x
  593. 1 - 02x 2 - 02x
  594. explain extended select left(a1,7), left(a2,7)
  595. from t1_16
  596. where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
  597. id select_type table type possible_keys key key_len ref rows filtered Extra
  598. 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  599. 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  600. Warnings:
  601. 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` where <in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(select `test`.`t2_16`.`b1` AS `b1`,`test`.`t2_16`.`b2` AS `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`))))
  602. select left(a1,7), left(a2,7)
  603. from t1_16
  604. where (a1,a2) in (select b1, b2 from t2_16 where b1 > '0');
  605. left(a1,7) left(a2,7)
  606. 1 - 01x 2 - 01x
  607. 1 - 02x 2 - 02x
  608. explain extended select left(a1,7), left(a2,7)
  609. from t1_16
  610. where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
  611. id select_type table type possible_keys key key_len ref rows filtered Extra
  612. 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  613. 2 SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  614. Warnings:
  615. 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` where <in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (select substr(`test`.`t2_16`.`b1`,1,16) AS `substring(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)`)))))
  616. select left(a1,7), left(a2,7)
  617. from t1_16
  618. where a1 in (select substring(b1,1,16) from t2_16 where b1 > '0');
  619. left(a1,7) left(a2,7)
  620. 1 - 01x 2 - 01x
  621. 1 - 02x 2 - 02x
  622. explain extended select left(a1,7), left(a2,7)
  623. from t1_16
  624. where a1 in (select group_concat(b1) from t2_16 group by b2);
  625. id select_type table type possible_keys key key_len ref rows filtered Extra
  626. 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  627. 2 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  628. Warnings:
  629. 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` where <in_optimizer>(`test`.`t1_16`.`a1`,<exists>(select group_concat(`test`.`t2_16`.`b1` separator ',') AS `group_concat(b1)` 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 ',')))))
  630. select left(a1,7), left(a2,7)
  631. from t1_16
  632. where a1 in (select group_concat(b1) from t2_16 group by b2);
  633. left(a1,7) left(a2,7)
  634. 1 - 01x 2 - 01x
  635. 1 - 02x 2 - 02x
  636. set @@group_concat_max_len = 256;
  637. explain extended select left(a1,7), left(a2,7)
  638. from t1_16
  639. where a1 in (select group_concat(b1) from t2_16 group by b2);
  640. id select_type table type possible_keys key key_len ref rows filtered Extra
  641. 1 PRIMARY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  642. 2 SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  643. Warnings:
  644. 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` where <in_optimizer>(`test`.`t1_16`.`a1`,`test`.`t1_16`.`a1` in ( <materialize> (select group_concat(`test`.`t2_16`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  645. select left(a1,7), left(a2,7)
  646. from t1_16
  647. where a1 in (select group_concat(b1) from t2_16 group by b2);
  648. left(a1,7) left(a2,7)
  649. 1 - 01x 2 - 01x
  650. 1 - 02x 2 - 02x
  651. explain extended
  652. select * from t1
  653. where concat(a1,'x') IN
  654. (select left(a1,8) from t1_16
  655. where (a1, a2) IN
  656. (select t2_16.b1, t2_16.b2 from t2_16, t2
  657. where t2.b2 = substring(t2_16.b2,1,6) and
  658. t2.b1 IN (select c1 from t3 where c2 > '0')));
  659. id select_type table type possible_keys key key_len ref rows filtered Extra
  660. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
  661. 2 DEPENDENT SUBQUERY t1_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  662. 3 DEPENDENT SUBQUERY t2_16 ALL NULL NULL NULL NULL 3 100.00 Using where
  663. 3 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 5 100.00 Using where; Using join buffer
  664. 4 SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  665. Warnings:
  666. Note 1003 select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(concat(`test`.`t1`.`a1`,'x'),<exists>(select 1 AS `Not_used` from `test`.`t1_16` where (<in_optimizer>((`test`.`t1_16`.`a1`,`test`.`t1_16`.`a2`),<exists>(select `test`.`t2_16`.`b1` AS `b1`,`test`.`t2_16`.`b2` AS `b2` from `test`.`t2_16` join `test`.`t2` where ((`test`.`t2`.`b2` = substr(`test`.`t2_16`.`b2`,1,6)) and <in_optimizer>(`test`.`t2`.`b1`,`test`.`t2`.`b1` in ( <materialize> (select `test`.`t3`.`c1` AS `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>(concat(`test`.`t1`.`a1`,'x')) = left(`test`.`t1_16`.`a1`,8)))))
  667. drop table t1_16, t2_16, t3_16;
  668. set @blob_len = 512;
  669. set @suffix_len = @blob_len - @prefix_len;
  670. create table t1_512 (a1 blob(512), a2 blob(512));
  671. create table t2_512 (b1 blob(512), b2 blob(512));
  672. create table t3_512 (c1 blob(512), c2 blob(512));
  673. insert into t1_512 values
  674. (concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
  675. insert into t1_512 values
  676. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  677. insert into t1_512 values
  678. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  679. insert into t2_512 values
  680. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  681. insert into t2_512 values
  682. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  683. insert into t2_512 values
  684. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  685. insert into t3_512 values
  686. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  687. insert into t3_512 values
  688. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  689. insert into t3_512 values
  690. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  691. insert into t3_512 values
  692. (concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
  693. explain extended select left(a1,7), left(a2,7)
  694. from t1_512
  695. where a1 in (select b1 from t2_512 where b1 > '0');
  696. id select_type table type possible_keys key key_len ref rows filtered Extra
  697. 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  698. 2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  699. Warnings:
  700. 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` where <in_optimizer>(`test`.`t1_512`.`a1`,<exists>(select 1 AS `Not_used` from `test`.`t2_512` where ((`test`.`t2_512`.`b1` > '0') and (<cache>(`test`.`t1_512`.`a1`) = `test`.`t2_512`.`b1`))))
  701. select left(a1,7), left(a2,7)
  702. from t1_512
  703. where a1 in (select b1 from t2_512 where b1 > '0');
  704. left(a1,7) left(a2,7)
  705. 1 - 01x 2 - 01x
  706. 1 - 02x 2 - 02x
  707. explain extended select left(a1,7), left(a2,7)
  708. from t1_512
  709. where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
  710. id select_type table type possible_keys key key_len ref rows filtered Extra
  711. 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  712. 2 DEPENDENT SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  713. Warnings:
  714. 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` where <in_optimizer>((`test`.`t1_512`.`a1`,`test`.`t1_512`.`a2`),<exists>(select `test`.`t2_512`.`b1` AS `b1`,`test`.`t2_512`.`b2` AS `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`))))
  715. select left(a1,7), left(a2,7)
  716. from t1_512
  717. where (a1,a2) in (select b1, b2 from t2_512 where b1 > '0');
  718. left(a1,7) left(a2,7)
  719. 1 - 01x 2 - 01x
  720. 1 - 02x 2 - 02x
  721. explain extended select left(a1,7), left(a2,7)
  722. from t1_512
  723. where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
  724. id select_type table type possible_keys key key_len ref rows filtered Extra
  725. 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  726. 2 SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  727. Warnings:
  728. 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` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select substr(`test`.`t2_512`.`b1`,1,512) AS `substring(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)`)))))
  729. select left(a1,7), left(a2,7)
  730. from t1_512
  731. where a1 in (select substring(b1,1,512) from t2_512 where b1 > '0');
  732. left(a1,7) left(a2,7)
  733. 1 - 01x 2 - 01x
  734. 1 - 02x 2 - 02x
  735. explain extended select left(a1,7), left(a2,7)
  736. from t1_512
  737. where a1 in (select group_concat(b1) from t2_512 group by b2);
  738. id select_type table type possible_keys key key_len ref rows filtered Extra
  739. 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  740. 2 SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  741. Warnings:
  742. 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` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select group_concat(`test`.`t2_512`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  743. select left(a1,7), left(a2,7)
  744. from t1_512
  745. where a1 in (select group_concat(b1) from t2_512 group by b2);
  746. left(a1,7) left(a2,7)
  747. set @@group_concat_max_len = 256;
  748. explain extended select left(a1,7), left(a2,7)
  749. from t1_512
  750. where a1 in (select group_concat(b1) from t2_512 group by b2);
  751. id select_type table type possible_keys key key_len ref rows filtered Extra
  752. 1 PRIMARY t1_512 ALL NULL NULL NULL NULL 3 100.00 Using where
  753. 2 SUBQUERY t2_512 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  754. Warnings:
  755. 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` where <in_optimizer>(`test`.`t1_512`.`a1`,`test`.`t1_512`.`a1` in ( <materialize> (select group_concat(`test`.`t2_512`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  756. select left(a1,7), left(a2,7)
  757. from t1_512
  758. where a1 in (select group_concat(b1) from t2_512 group by b2);
  759. left(a1,7) left(a2,7)
  760. drop table t1_512, t2_512, t3_512;
  761. set @blob_len = 1024;
  762. set @suffix_len = @blob_len - @prefix_len;
  763. create table t1_1024 (a1 blob(1024), a2 blob(1024));
  764. create table t2_1024 (b1 blob(1024), b2 blob(1024));
  765. create table t3_1024 (c1 blob(1024), c2 blob(1024));
  766. insert into t1_1024 values
  767. (concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
  768. insert into t1_1024 values
  769. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  770. insert into t1_1024 values
  771. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  772. insert into t2_1024 values
  773. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  774. insert into t2_1024 values
  775. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  776. insert into t2_1024 values
  777. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  778. insert into t3_1024 values
  779. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  780. insert into t3_1024 values
  781. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  782. insert into t3_1024 values
  783. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  784. insert into t3_1024 values
  785. (concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
  786. explain extended select left(a1,7), left(a2,7)
  787. from t1_1024
  788. where a1 in (select b1 from t2_1024 where b1 > '0');
  789. id select_type table type possible_keys key key_len ref rows filtered Extra
  790. 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  791. 2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  792. Warnings:
  793. 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` where <in_optimizer>(`test`.`t1_1024`.`a1`,<exists>(select 1 AS `Not_used` from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = `test`.`t2_1024`.`b1`))))
  794. select left(a1,7), left(a2,7)
  795. from t1_1024
  796. where a1 in (select b1 from t2_1024 where b1 > '0');
  797. left(a1,7) left(a2,7)
  798. 1 - 01x 2 - 01x
  799. 1 - 02x 2 - 02x
  800. explain extended select left(a1,7), left(a2,7)
  801. from t1_1024
  802. where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
  803. id select_type table type possible_keys key key_len ref rows filtered Extra
  804. 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  805. 2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  806. Warnings:
  807. 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` where <in_optimizer>((`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a2`),<exists>(select `test`.`t2_1024`.`b1` AS `b1`,`test`.`t2_1024`.`b2` AS `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`))))
  808. select left(a1,7), left(a2,7)
  809. from t1_1024
  810. where (a1,a2) in (select b1, b2 from t2_1024 where b1 > '0');
  811. left(a1,7) left(a2,7)
  812. 1 - 01x 2 - 01x
  813. 1 - 02x 2 - 02x
  814. explain extended select left(a1,7), left(a2,7)
  815. from t1_1024
  816. where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
  817. id select_type table type possible_keys key key_len ref rows filtered Extra
  818. 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  819. 2 DEPENDENT SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  820. Warnings:
  821. 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` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in (select 1 AS `Not_used` from `test`.`t2_1024` where ((`test`.`t2_1024`.`b1` > '0') and (<cache>(`test`.`t1_1024`.`a1`) = substr(`test`.`t2_1024`.`b1`,1,1024)))))
  822. select left(a1,7), left(a2,7)
  823. from t1_1024
  824. where a1 in (select substring(b1,1,1024) from t2_1024 where b1 > '0');
  825. left(a1,7) left(a2,7)
  826. 1 - 01x 2 - 01x
  827. 1 - 02x 2 - 02x
  828. explain extended select left(a1,7), left(a2,7)
  829. from t1_1024
  830. where a1 in (select group_concat(b1) from t2_1024 group by b2);
  831. id select_type table type possible_keys key key_len ref rows filtered Extra
  832. 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  833. 2 SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  834. Warnings:
  835. 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` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1024`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  836. select left(a1,7), left(a2,7)
  837. from t1_1024
  838. where a1 in (select group_concat(b1) from t2_1024 group by b2);
  839. left(a1,7) left(a2,7)
  840. set @@group_concat_max_len = 256;
  841. explain extended select left(a1,7), left(a2,7)
  842. from t1_1024
  843. where a1 in (select group_concat(b1) from t2_1024 group by b2);
  844. id select_type table type possible_keys key key_len ref rows filtered Extra
  845. 1 PRIMARY t1_1024 ALL NULL NULL NULL NULL 3 100.00 Using where
  846. 2 SUBQUERY t2_1024 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  847. Warnings:
  848. 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` where <in_optimizer>(`test`.`t1_1024`.`a1`,`test`.`t1_1024`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1024`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  849. select left(a1,7), left(a2,7)
  850. from t1_1024
  851. where a1 in (select group_concat(b1) from t2_1024 group by b2);
  852. left(a1,7) left(a2,7)
  853. drop table t1_1024, t2_1024, t3_1024;
  854. set @blob_len = 1025;
  855. set @suffix_len = @blob_len - @prefix_len;
  856. create table t1_1025 (a1 blob(1025), a2 blob(1025));
  857. create table t2_1025 (b1 blob(1025), b2 blob(1025));
  858. create table t3_1025 (c1 blob(1025), c2 blob(1025));
  859. insert into t1_1025 values
  860. (concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
  861. insert into t1_1025 values
  862. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  863. insert into t1_1025 values
  864. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  865. insert into t2_1025 values
  866. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  867. insert into t2_1025 values
  868. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  869. insert into t2_1025 values
  870. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  871. insert into t3_1025 values
  872. (concat('1 - 01', repeat('x', @suffix_len)), concat('2 - 01', repeat('x', @suffix_len)));
  873. insert into t3_1025 values
  874. (concat('1 - 02', repeat('x', @suffix_len)), concat('2 - 02', repeat('x', @suffix_len)));
  875. insert into t3_1025 values
  876. (concat('1 - 03', repeat('x', @suffix_len)), concat('2 - 03', repeat('x', @suffix_len)));
  877. insert into t3_1025 values
  878. (concat('1 - 04', repeat('x', @suffix_len)), concat('2 - 04', repeat('x', @suffix_len)));
  879. explain extended select left(a1,7), left(a2,7)
  880. from t1_1025
  881. where a1 in (select b1 from t2_1025 where b1 > '0');
  882. id select_type table type possible_keys key key_len ref rows filtered Extra
  883. 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  884. 2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  885. Warnings:
  886. 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` where <in_optimizer>(`test`.`t1_1025`.`a1`,<exists>(select 1 AS `Not_used` from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = `test`.`t2_1025`.`b1`))))
  887. select left(a1,7), left(a2,7)
  888. from t1_1025
  889. where a1 in (select b1 from t2_1025 where b1 > '0');
  890. left(a1,7) left(a2,7)
  891. 1 - 01x 2 - 01x
  892. 1 - 02x 2 - 02x
  893. explain extended select left(a1,7), left(a2,7)
  894. from t1_1025
  895. where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
  896. id select_type table type possible_keys key key_len ref rows filtered Extra
  897. 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  898. 2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  899. Warnings:
  900. 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` where <in_optimizer>((`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a2`),<exists>(select `test`.`t2_1025`.`b1` AS `b1`,`test`.`t2_1025`.`b2` AS `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`))))
  901. select left(a1,7), left(a2,7)
  902. from t1_1025
  903. where (a1,a2) in (select b1, b2 from t2_1025 where b1 > '0');
  904. left(a1,7) left(a2,7)
  905. 1 - 01x 2 - 01x
  906. 1 - 02x 2 - 02x
  907. explain extended select left(a1,7), left(a2,7)
  908. from t1_1025
  909. where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
  910. id select_type table type possible_keys key key_len ref rows filtered Extra
  911. 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  912. 2 DEPENDENT SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  913. Warnings:
  914. 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` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in (select 1 AS `Not_used` from `test`.`t2_1025` where ((`test`.`t2_1025`.`b1` > '0') and (<cache>(`test`.`t1_1025`.`a1`) = substr(`test`.`t2_1025`.`b1`,1,1025)))))
  915. select left(a1,7), left(a2,7)
  916. from t1_1025
  917. where a1 in (select substring(b1,1,1025) from t2_1025 where b1 > '0');
  918. left(a1,7) left(a2,7)
  919. 1 - 01x 2 - 01x
  920. 1 - 02x 2 - 02x
  921. explain extended select left(a1,7), left(a2,7)
  922. from t1_1025
  923. where a1 in (select group_concat(b1) from t2_1025 group by b2);
  924. id select_type table type possible_keys key key_len ref rows filtered Extra
  925. 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  926. 2 SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  927. Warnings:
  928. 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` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1025`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  929. select left(a1,7), left(a2,7)
  930. from t1_1025
  931. where a1 in (select group_concat(b1) from t2_1025 group by b2);
  932. left(a1,7) left(a2,7)
  933. set @@group_concat_max_len = 256;
  934. explain extended select left(a1,7), left(a2,7)
  935. from t1_1025
  936. where a1 in (select group_concat(b1) from t2_1025 group by b2);
  937. id select_type table type possible_keys key key_len ref rows filtered Extra
  938. 1 PRIMARY t1_1025 ALL NULL NULL NULL NULL 3 100.00 Using where
  939. 2 SUBQUERY t2_1025 ALL NULL NULL NULL NULL 3 100.00 Using filesort
  940. Warnings:
  941. 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` where <in_optimizer>(`test`.`t1_1025`.`a1`,`test`.`t1_1025`.`a1` in ( <materialize> (select group_concat(`test`.`t2_1025`.`b1` separator ',') AS `group_concat(b1)` 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)`)))))
  942. select left(a1,7), left(a2,7)
  943. from t1_1025
  944. where a1 in (select group_concat(b1) from t2_1025 group by b2);
  945. left(a1,7) left(a2,7)
  946. drop table t1_1025, t2_1025, t3_1025;
  947. create table t1bit (a1 bit(3), a2 bit(3));
  948. create table t2bit (b1 bit(3), b2 bit(3));
  949. insert into t1bit values (b'000', b'100');
  950. insert into t1bit values (b'001', b'101');
  951. insert into t1bit values (b'010', b'110');
  952. insert into t2bit values (b'001', b'101');
  953. insert into t2bit values (b'010', b'110');
  954. insert into t2bit values (b'110', b'111');
  955. explain extended select bin(a1), bin(a2)
  956. from t1bit
  957. where (a1, a2) in (select b1, b2 from t2bit);
  958. id select_type table type possible_keys key key_len ref rows filtered Extra
  959. 1 PRIMARY t1bit ALL NULL NULL NULL NULL 3 100.00 Using where
  960. 2 SUBQUERY t2bit ALL NULL NULL NULL NULL 3 100.00
  961. Warnings:
  962. Note 1003 select conv(`test`.`t1bit`.`a1`,10,2) AS `bin(a1)`,conv(`test`.`t1bit`.`a2`,10,2) AS `bin(a2)` from `test`.`t1bit` where <in_optimizer>((`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`),(`test`.`t1bit`.`a1`,`test`.`t1bit`.`a2`) in ( <materialize> (select `test`.`t2bit`.`b1` AS `b1`,`test`.`t2bit`.`b2` AS `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`)))))
  963. select bin(a1), bin(a2)
  964. from t1bit
  965. where (a1, a2) in (select b1, b2 from t2bit);
  966. bin(a1) bin(a2)
  967. 1 101
  968. 10 110
  969. drop table t1bit, t2bit;
  970. create table t1bb (a1 bit(3), a2 blob(3));
  971. create table t2bb (b1 bit(3), b2 blob(3));
  972. insert into t1bb values (b'000', '100');
  973. insert into t1bb values (b'001', '101');
  974. insert into t1bb values (b'010', '110');
  975. insert into t2bb values (b'001', '101');
  976. insert into t2bb values (b'010', '110');
  977. insert into t2bb values (b'110', '111');
  978. explain extended select bin(a1), a2
  979. from t1bb
  980. where (a1, a2) in (select b1, b2 from t2bb);
  981. id select_type table type possible_keys key key_len ref rows filtered Extra
  982. 1 PRIMARY t1bb ALL NULL NULL NULL NULL 3 100.00 Using where
  983. 2 DEPENDENT SUBQUERY t2bb ALL NULL NULL NULL NULL 3 100.00 Using where
  984. Warnings:
  985. Note 1003 select conv(`test`.`t1bb`.`a1`,10,2) AS `bin(a1)`,`test`.`t1bb`.`a2` AS `a2` from `test`.`t1bb` where <in_optimizer>((`test`.`t1bb`.`a1`,`test`.`t1bb`.`a2`),<exists>(select `test`.`t2bb`.`b1` AS `b1`,`test`.`t2bb`.`b2` AS `b2` from `test`.`t2bb` where ((<cache>(`test`.`t1bb`.`a1`) = `test`.`t2bb`.`b1`) and (<cache>(`test`.`t1bb`.`a2`) = `test`.`t2bb`.`b2`))))
  986. select bin(a1), a2
  987. from t1bb
  988. where (a1, a2) in (select b1, b2 from t2bb);
  989. bin(a1) a2
  990. 1 101
  991. 10 110
  992. drop table t1bb, t2bb;
  993. drop table t1, t2, t3, t1i, t2i, t3i, columns;
  994. /******************************************************************************
  995. * Test the cache of the left operand of IN.
  996. ******************************************************************************/
  997. # Test that default values of Cached_item are not used for comparison
  998. create table t1 (s1 int);
  999. create table t2 (s2 int);
  1000. insert into t1 values (5),(1),(0);
  1001. insert into t2 values (0), (1);
  1002. select s2 from t2 where s2 in (select s1 from t1);
  1003. s2
  1004. 0
  1005. 1
  1006. drop table t1, t2;
  1007. create table t1 (a int not null, b int not null);
  1008. create table t2 (c int not null, d int not null);
  1009. create table t3 (e int not null);
  1010. insert into t1 values (1,10);
  1011. insert into t1 values (1,20);
  1012. insert into t1 values (2,10);
  1013. insert into t1 values (2,20);
  1014. insert into t1 values (2,30);
  1015. insert into t1 values (3,20);
  1016. insert into t1 values (4,40);
  1017. insert into t2 values (2,10);
  1018. insert into t2 values (2,20);
  1019. insert into t2 values (2,40);
  1020. insert into t2 values (3,20);
  1021. insert into t2 values (4,10);
  1022. insert into t2 values (5,10);
  1023. insert into t3 values (10);
  1024. insert into t3 values (10);
  1025. insert into t3 values (20);
  1026. insert into t3 values (30);
  1027. explain extended
  1028. select a from t1 where a in (select c from t2 where d >= 20);
  1029. id select_type table type possible_keys key key_len ref rows filtered Extra
  1030. 1 PRIMARY t1 ALL NULL NULL NULL NULL 7 100.00 Using where
  1031. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
  1032. Warnings:
  1033. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` AS `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`)))))
  1034. select a from t1 where a in (select c from t2 where d >= 20);
  1035. a
  1036. 2
  1037. 2
  1038. 2
  1039. 3
  1040. create index it1a on t1(a);
  1041. explain extended
  1042. select a from t1 where a in (select c from t2 where d >= 20);
  1043. id select_type table type possible_keys key key_len ref rows filtered Extra
  1044. 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index
  1045. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 6 100.00 Using where
  1046. Warnings:
  1047. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` AS `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`)))))
  1048. select a from t1 where a in (select c from t2 where d >= 20);
  1049. a
  1050. 2
  1051. 2
  1052. 2
  1053. 3
  1054. insert into t2 values (1,10);
  1055. explain extended
  1056. select a from t1 where a in (select c from t2 where d >= 20);
  1057. id select_type table type possible_keys key key_len ref rows filtered Extra
  1058. 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using where; Using index
  1059. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
  1060. Warnings:
  1061. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` AS `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`)))))
  1062. select a from t1 where a in (select c from t2 where d >= 20);
  1063. a
  1064. 2
  1065. 2
  1066. 2
  1067. 3
  1068. explain extended
  1069. select a from t1 group by a having a in (select c from t2 where d >= 20);
  1070. id select_type table type possible_keys key key_len ref rows filtered Extra
  1071. 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
  1072. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
  1073. Warnings:
  1074. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` AS `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`)))))
  1075. select a from t1 group by a having a in (select c from t2 where d >= 20);
  1076. a
  1077. 2
  1078. 3
  1079. create index iab on t1(a, b);
  1080. explain extended
  1081. select a from t1 group by a having a in (select c from t2 where d >= 20);
  1082. id select_type table type possible_keys key key_len ref rows filtered Extra
  1083. 1 PRIMARY t1 index NULL it1a 4 NULL 7 100.00 Using index
  1084. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
  1085. Warnings:
  1086. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t2`.`c` AS `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`)))))
  1087. select a from t1 group by a having a in (select c from t2 where d >= 20);
  1088. a
  1089. 2
  1090. 3
  1091. explain extended
  1092. select a from t1 group by a
  1093. having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
  1094. id select_type table type possible_keys key key_len ref rows filtered Extra
  1095. 1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using index
  1096. 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
  1097. 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  1098. Warnings:
  1099. Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
  1100. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` where (<nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select `test`.`t3`.`e` AS `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`))))
  1101. select a from t1 group by a
  1102. having a in (select c from t2 where d >= some(select e from t3 where max(b)=e));
  1103. a
  1104. 2
  1105. 3
  1106. explain extended
  1107. select a from t1
  1108. where a in (select c from t2 where d >= some(select e from t3 where b=e));
  1109. id select_type table type possible_keys key key_len ref rows filtered Extra
  1110. 1 PRIMARY t1 index NULL iab 8 NULL 7 100.00 Using where; Using index
  1111. 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 7 100.00 Using where
  1112. 3 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 4 100.00 Using where
  1113. Warnings:
  1114. Note 1276 Field or reference 'test.t1.b' of SELECT #3 was resolved in SELECT #1
  1115. Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,<exists>(select 1 AS `Not_used` from `test`.`t2` where (<nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select 1 AS `Not_used` 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`))))
  1116. select a from t1
  1117. where a in (select c from t2 where d >= some(select e from t3 where b=e));
  1118. a
  1119. 1
  1120. 2
  1121. 2
  1122. 2
  1123. 3
  1124. drop table t1, t2, t3;
  1125. create table t2 (a int, b int, key(a), key(b));
  1126. insert into t2 values (3,3),(3,3),(3,3);
  1127. select 1 from t2 where
  1128. t2.a > 1
  1129. or
  1130. t2.a = 3 and not t2.a not in (select t2.b from t2);
  1131. 1
  1132. 1
  1133. 1
  1134. 1
  1135. drop table t2;
  1136. create table t1 (a1 int key);
  1137. create table t2 (b1 int);
  1138. insert into t1 values (5);
  1139. explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
  1140. id select_type table type possible_keys key key_len ref rows Extra
  1141. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
  1142. 2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found
  1143. select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
  1144. min(a1)
  1145. set @save_optimizer_switch=@@optimizer_switch;
  1146. set @@optimizer_switch='default,materialization=off';
  1147. explain select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
  1148. id select_type table type possible_keys key key_len ref rows Extra
  1149. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
  1150. 2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found
  1151. select min(a1) from t1 where 7 in (select b1 from t2 group by b1);
  1152. min(a1)
  1153. set @@optimizer_switch='default,semijoin=off';
  1154. explain select min(a1) from t1 where 7 in (select b1 from t2);
  1155. id select_type table type possible_keys key key_len ref rows Extra
  1156. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
  1157. 2 SUBQUERY t2 system NULL NULL NULL NULL 0 const row not found
  1158. select min(a1) from t1 where 7 in (select b1 from t2);
  1159. min(a1)
  1160. set @@optimizer_switch='default,materialization=off';
  1161. # with MariaDB and MWL#90, this particular case is solved:
  1162. explain select min(a1) from t1 where 7 in (select b1 from t2);
  1163. id select_type table type possible_keys key key_len ref rows Extra
  1164. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  1165. select min(a1) from t1 where 7 in (select b1 from t2);
  1166. min(a1)
  1167. NULL
  1168. # but when we go around MWL#90 code, the problem still shows up:
  1169. explain select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
  1170. id select_type table type possible_keys key key_len ref rows Extra
  1171. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
  1172. 2 DEPENDENT SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  1173. select min(a1) from t1 where 7 in (select b1 from t2) or 2> 4;
  1174. min(a1)
  1175. set @@optimizer_switch= @save_optimizer_switch;
  1176. drop table t1,t2;
  1177. create table t1 (a char(2), b varchar(10));
  1178. insert into t1 values ('a', 'aaa');
  1179. insert into t1 values ('aa', 'aaaa');
  1180. explain select a,b from t1 where b in (select a from t1);
  1181. id select_type table type possible_keys key key_len ref rows Extra
  1182. 1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where
  1183. 2 SUBQUERY t1 ALL NULL NULL NULL NULL 2
  1184. select a,b from t1 where b in (select a from t1);
  1185. a b
  1186. prepare st1 from "select a,b from t1 where b in (select a from t1)";
  1187. execute st1;
  1188. a b
  1189. execute st1;
  1190. a b
  1191. drop table t1;
  1192. CREATE TABLE t1 (f1 INT, f2 DECIMAL(5,3)) ENGINE=MyISAM;
  1193. INSERT INTO t1 (f1, f2) VALUES (1, 1.789);
  1194. INSERT INTO t1 (f1, f2) VALUES (13, 1.454);
  1195. INSERT INTO t1 (f1, f2) VALUES (10, 1.668);
  1196. CREATE TABLE t2 LIKE t1;
  1197. INSERT INTO t2 VALUES (1, 1.789);
  1198. INSERT INTO t2 VALUES (13, 1.454);
  1199. set @save_optimizer_switch=@@optimizer_switch;
  1200. SET @@optimizer_switch='default,semijoin=on,materialization=on';
  1201. EXPLAIN SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
  1202. id select_type table type possible_keys key key_len ref rows Extra
  1203. 1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 2
  1204. 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where; Using join buffer
  1205. 2 SUBQUERY t2 ALL NULL NULL NULL NULL 2
  1206. SELECT COUNT(*) FROM t1 WHERE (f1,f2) IN (SELECT f1,f2 FROM t2);
  1207. COUNT(*)
  1208. 2
  1209. set @@optimizer_switch= @save_optimizer_switch;
  1210. DROP TABLE t1, t2;
  1211. CREATE TABLE t1 (
  1212. pk int,
  1213. a varchar(1),
  1214. b varchar(4),
  1215. c varchar(4),
  1216. d varchar(4),
  1217. PRIMARY KEY (pk)
  1218. );
  1219. INSERT INTO t1 VALUES (1,'o','ffff','ffff','ffoo'),(2,'f','ffff','ffff','ffff');
  1220. CREATE TABLE t2 LIKE t1;
  1221. INSERT INTO t2 VALUES (1,'i','iiii','iiii','iiii'),(2,'f','ffff','ffff','ffff');
  1222. set @save_optimizer_switch=@@optimizer_switch;
  1223. SET @@optimizer_switch='default,semijoin=on,materialization=on';
  1224. EXPLAIN SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
  1225. id select_type table type possible_keys key key_len ref rows Extra
  1226. 1 PRIMARY t1 ALL NULL NULL NULL NULL 2
  1227. 1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 5 func 1
  1228. 2 SUBQUERY t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using MRR
  1229. SELECT pk FROM t1 WHERE (a) IN (SELECT a FROM t2 WHERE pk > 0);
  1230. pk
  1231. 2
  1232. SELECT pk FROM t1 WHERE (b,c,d) IN (SELECT b,c,d FROM t2 WHERE pk > 0);
  1233. pk
  1234. 2
  1235. DROP TABLE t1, t2;
  1236. set optimizer_switch=@save_optimizer_switch;
  1237. #
  1238. # BUG#50019: Wrong result for IN-subquery with materialization
  1239. #
  1240. create table t1(i int);
  1241. insert into t1 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
  1242. create table t2(i int);
  1243. insert into t2 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
  1244. create table t3(i int);
  1245. insert into t3 values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
  1246. select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5);
  1247. i
  1248. 1
  1249. 2
  1250. 3
  1251. 4
  1252. set @save_optimizer_switch=@@optimizer_switch;
  1253. set session optimizer_switch='materialization=off';
  1254. select * from t1 where t1.i in (select t2.i from t2 join t3 where t2.i + t3.i = 5);
  1255. i
  1256. 1
  1257. 2
  1258. 3
  1259. 4
  1260. set session optimizer_switch=@save_optimizer_switch;
  1261. drop table t1, t2, t3;
  1262. create table t0 (a int);
  1263. insert into t0 values (0),(1),(2);
  1264. create table t1 (a int);
  1265. insert into t1 values (0),(1),(2);
  1266. explain select a, a in (select a from t1) from t0;
  1267. id select_type table type possible_keys key key_len ref rows Extra
  1268. 1 PRIMARY t0 ALL NULL NULL NULL NULL 3
  1269. 2 SUBQUERY t1 ALL NULL NULL NULL NULL 3
  1270. select a, a in (select a from t1) from t0;
  1271. a a in (select a from t1)
  1272. 0 1
  1273. 1 1
  1274. 2 1
  1275. prepare s from 'select a, a in (select a from t1) from t0';
  1276. execute s;
  1277. a a in (select a from t1)
  1278. 0 1
  1279. 1 1
  1280. 2 1
  1281. update t1 set a=123;
  1282. execute s;
  1283. a a in (select a from t1)
  1284. 0 0
  1285. 1 0
  1286. 2 0
  1287. drop table t0, t1;
  1288. set optimizer_switch='firstmatch=on';
  1289. set @@optimizer_switch=default;