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.

266 lines
7.2 KiB

Fix for lp:711565 "Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time" - In Maria/MyISAM: Release/re-acquire locks to give queries that wait on them a chance to make progress - In Maria/MyISAM: Change from numeric constants to ICP_RES values. - In Maria: Do check index condition in maria_rprev() (was lost in the merge/backport?) - In Maria/MyISAM/XtraDB: Check if the query was killed, and return immediately if it was. Added new storage engine error: HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted Authors: Sergey Petrunia & Monty include/my_base.h: Added HA_ERR_ABORTED_BY_USER, for handler to signal that it detected a kill of the query and aborted include/my_handler.h: Added comment mysql-test/r/myisam_icp.result: Updated test mysql-test/t/myisam_icp.test: Drop used tables at start of test Added test case that can help with manual testing of killing index condition pushdown query. mysys/my_handler_errors.h: Text for new storage engine error sql/handler.cc: If engine got HA_ERR_ABORTED_BY_USER, send kill message. sql/multi_range_read.cc: Return error code storage/maria/ha_maria.cc: Added ma_killed_in_mariadb() to detect kill. Ensure that file->external_ref points to TABLE object. storage/maria/ma_extra.c: Dummy test-if-killed for standalone storage/maria/ma_key.c: If ma_check_index_cond() fails, set my_errno and info->cur_row.lastpos storage/maria/ma_rkey.c: Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was storage/maria/ma_rnext.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) storage/maria/ma_rprev.c: Check if the query was killed, and return immediately if it was Added missing fast_ma_writeinfo(info) and ma_check_index_cond() storage/maria/ma_search.c: Give error message if we find a wrong key storage/maria/ma_static.c: Added pointer to test-if-killed function storage/maria/maria_def.h: New prototypes storage/myisam/ha_myisam.cc: Added mi_killed_in_mariadb() Ensure that file->external_ref points to TABLE object. storage/myisam/mi_extra.c: Dummy test-if-killed for standalone storage/myisam/mi_key.c: If ma_check_index_cond() fails, set my_errno and info->lastpos storage/myisam/mi_rkey.c: Ensure that info->lastpos= HA_OFFSET_ERROR in case of error Release/re-acquire locks to give queries that wait on them a chance to make progress Check if the query was killed, and return immediately if it was Reorder code to do less things in case of error. Added missing fast_mi_writeinfo() storage/myisam/mi_rnext.c: Check if the query was killed, and return immediately if it was Simplify old ICP code Added missing fast_ma_writeinfo(info) storage/myisam/mi_rnext_same.c: Check if the query was killed, and return immediately if it was Added missing fast_mi_writeinfo(info) storage/myisam/mi_rprev.c: Check if the query was killed, and return immediately if it was Simplify error handling of ICP Added missing fast_mi_writeinfo(info) storage/myisam/mi_search.c: Give error message if we find a wrong key storage/myisam/mi_static.c: Added pointer to test-if-killed function storage/myisam/myisamdef.h: New prototypes storage/xtradb/handler/ha_innodb.cc: Added DB_SEARCH_ABORTED_BY_USER and ha_innobase::is_thd_killed() Check if the query was killed, and return immediately if it was storage/xtradb/handler/ha_innodb.h: Added prototype storage/xtradb/include/db0err.h: Added DB_SEARCH_ABORTED_BY_USER storage/xtradb/include/row0mysql.h: Added possible ICP errors storage/xtradb/row/row0sel.c: Use ICP errors instead of constants. Detect if killed and return B_SEARCH_ABORTED_BY_USER
15 years ago
  1. #
  2. # ICP/MyISAM tests (Index Condition Pushdown)
  3. #
  4. set @myisam_icp_tmp=@@optimizer_switch;
  5. set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on';
  6. --source include/icp_tests.inc
  7. --disable_warnings
  8. drop table if exists t0, t1, t1i, t1m;
  9. --enable_warnings
  10. #
  11. # BUG#711565 Index Condition Pushdown can make a thread hold MyISAM locks as well as be unKILLable for long time
  12. # This is not a ready mysqltest testcase but rather a set of queries that
  13. # allow to check the bug[fix] manually. Making this testcase automatic is
  14. # difficult because
  15. # - big tables are involved
  16. # - it's difficult to have automatic checks of whether the query could be
  17. # KILLed that would reliably work on fast/slow buildslaves, etc.
  18. --disable_parsing
  19. create table t0 (a int);
  20. insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
  21. create table t1 (
  22. kp1 int, kp2 int,
  23. filler char(100),
  24. col int,
  25. key(kp1, kp2)
  26. );
  27. set myisam_sort_buffer_size=32*1000*1000;
  28. insert into t1
  29. select
  30. 1000 + A.a + 10*B.a + 100*C.a + 1000*D.a + 10000 * F.a,
  31. 1,
  32. 'filler-data filler-data filler-data filler-data filler-data',
  33. 1
  34. from
  35. t0 A, t0 B, t0 C, t0 D, t0 E, t0 F, t0 G
  36. ;
  37. insert into t1 values (990, 100, 'a record to test index_next checks',100);
  38. update t1 set kp2=10 where kp1 between 20000+100 and 28000;
  39. update t1 set kp1=20000 where kp1 between 20000 and 28000;
  40. insert into t1 values (20000, 100, 'last-20K-record',1);
  41. create table t1i like t1;
  42. alter table t1i engine=innodb;
  43. insert into t1i select * from t1;
  44. create table t1m like t1;
  45. alter table t1m engine=maria;
  46. insert into t1m select * from t1;
  47. #
  48. # XtraDB has one check for all kinds of ranges.
  49. #
  50. explain
  51. select * from t1i
  52. where
  53. kp1 < 8000 and
  54. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  55. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  56. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  57. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  58. kp2 +1 > 10;
  59. #
  60. # MyISAM, check range access + mi_rnext():
  61. # (will return HA_ERR_END_OF_FILE)
  62. explain
  63. select * from t1
  64. where
  65. kp1 < 10000 and
  66. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  67. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  68. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  69. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  70. kp2 +1 > 10;
  71. #
  72. # MyISAM, check range access + mi_rkey():
  73. # (will return HA_ERR_END_OF_FILE)
  74. explain
  75. select * from t1
  76. where
  77. kp1 >= 999 and kp1 < 10000 and
  78. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  79. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  80. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  81. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  82. kp2 +1 > 10;
  83. #
  84. # MyISAM, check mi_rnext_same:
  85. #
  86. explain
  87. select * from t1
  88. where
  89. kp1 = 20000 and
  90. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  91. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  92. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  93. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  94. kp2 +1 < 10;
  95. #
  96. # MyISAM, check mi_rprev:
  97. #
  98. explain
  99. select * from t1
  100. where
  101. kp1 = 20000 and
  102. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  103. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  104. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  105. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  106. kp2 +1 > 20
  107. order by kp1, kp2 desc;
  108. #
  109. # Maria, check range access + maria_rkey():
  110. #
  111. explain
  112. select * from t1m
  113. where
  114. kp1 >= 999 and kp1 < 10000 and
  115. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  116. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  117. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  118. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  119. kp2 +1 > 10;
  120. #
  121. # Maria, check range access + maria_rnext():
  122. #
  123. explain
  124. select * from t1m
  125. where
  126. kp1 < 10000 and
  127. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  128. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  129. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  130. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  131. kp2 +1 > 10;
  132. #
  133. # Maria, check maria_rnext_same:
  134. #
  135. explain
  136. select * from t1m
  137. where
  138. kp1 = 20000 and
  139. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  140. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  141. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  142. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  143. kp2 +1 > 100;
  144. #
  145. # Maria, check maria_rprev:
  146. #
  147. explain
  148. select * from t1m
  149. where
  150. kp1 = 20000 and
  151. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  152. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  153. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  154. concat(repeat('foo-bar-', 100000), kp2) like '%bar-1%' and
  155. kp2 +1 > 20
  156. order by kp1, kp2 desc;
  157. drop table t0, t1, t1i, t1m;
  158. --enable_parsing
  159. --echo #
  160. --echo # BUG#826935 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
  161. --echo #
  162. CREATE TABLE t1 ( a int, b varchar(1024), c int, KEY (c), KEY (c,a)) ;
  163. INSERT INTO t1 VALUES
  164. (NULL,'x','-678428672'),
  165. (NULL,'ok',NULL),
  166. (796262400,'byluovkgwoukfxedyeffsedajyqkyhpaqqpozn', NULL),
  167. (7,'STQUF',146014208),
  168. (955711488,'WWVOR','-1515388928');
  169. SELECT b FROM t1 WHERE a != 1 AND c IS NULL ORDER BY 1;
  170. DROP TABLE t1;
  171. --echo #
  172. --echo # Bug#870046: ICP for a GROUP BY query
  173. --echo #
  174. CREATE TABLE t1 (a int, b varchar(1), c varchar(1), INDEX idx(b));
  175. INSERT INTO t1 VALUES (2,'x','x'), (5,'x','y');
  176. SET SESSION optimizer_switch='index_condition_pushdown=off';
  177. EXPLAIN
  178. SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
  179. SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
  180. SET SESSION optimizer_switch='index_condition_pushdown=on';
  181. EXPLAIN
  182. SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
  183. SELECT a, MIN(c) FROM t1 WHERE b = 'x' AND c > 'x' GROUP BY a;
  184. DROP TABLE t1;
  185. --echo #
  186. --echo # BUG#887026: Wrong result with ICP, outer join, subquery in maria-5.3-icp
  187. --echo #
  188. CREATE TABLE t1 (c varchar(1));
  189. INSERT INTO t1 VALUES ('c'), ('c');
  190. CREATE TABLE t2 (c varchar(1), b int);
  191. INSERT INTO t2 VALUES ('d', NULL),('d', NULL);
  192. CREATE TABLE t3 (c varchar(1));
  193. INSERT INTO t3 VALUES ('c');
  194. INSERT INTO t3 VALUES ('c');
  195. CREATE TABLE t4 ( b int, c varchar(1), KEY (b));
  196. INSERT INTO t4 VALUES (7,'c');
  197. INSERT INTO t4 VALUES (7,'c');
  198. SET @save_optimizer_switch=@@optimizer_switch;
  199. SET optimizer_switch='outer_join_with_cache=off';
  200. --echo # Must be t1,t2,t3,t4, with t4 having Full-scan-on-NULL but not Using index condition
  201. explain
  202. SELECT * FROM t1 LEFT JOIN t2 ON t1.c=t2.b
  203. WHERE
  204. t2.b NOT IN (SELECT t4.b FROM t3 STRAIGHT_JOIN t4 WHERE t4.b <= 2 AND t4.c = t3.c);
  205. SELECT * FROM t1 LEFT JOIN t2 ON t1.c=t2.b
  206. WHERE
  207. t2.b NOT IN (SELECT t4.b FROM t3 STRAIGHT_JOIN t4 WHERE t4.b <= 2 AND t4.c = t3.c);
  208. SET optimizer_switch=@save_optimizer_switch;
  209. DROP TABLE t1,t2,t3,t4;
  210. set optimizer_switch=@myisam_icp_tmp;