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.

2451 lines
67 KiB

Fixes to allow one to compile and test innodb_plugin If one compiles innodb_plugin, then the tests in suite/innodb_plugin will use the plugin. If not and xtradb is used, the tests will use xtradb. mysql-test/include/have_innodb_plugin.inc: Test both for innodb_plugin and xtradb mysql-test/include/have_real_innodb_plugin.inc: Test if we are using innodb_plugin (but not xtradb) mysql-test/include/have_xtradb.inc: Test if xtradb is used mysql-test/lib/mtr_cases.pm: Enable easy testing of innodb_plugin mysql-test/mysql-test-run.pl: Added supression for difference between xtradb & innodb_plugin mysql-test/suite/innodb_plugin/r/innodb-index-ip.result: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/r/innodb-index-xb.result: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/r/innodb-index.result: Move tests away that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/r/innodb-ip.result: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/r/innodb-xb.result: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/r/innodb.result: Move tests away that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/r/innodb_bug21704-xb.result: Test result differ for xtradb mysql-test/suite/innodb_plugin/r/innodb_bug46000.result: Remove (not needed) error message not given by MariaDB mysql-test/suite/innodb_plugin/r/innodb_bug49164-xb.result: Test result differs for xtradb mysql-test/suite/innodb_plugin/r/innodb_bug49164.result: Update results mysql-test/suite/innodb_plugin/r/innodb_bug53591.result: Remove (not needed) error message not given by MariaDB mysql-test/suite/innodb_plugin/r/innodb_bug54679.result: Updated result file mysql-test/suite/innodb_plugin/r/innodb_mysql.result: Updated result file mysql-test/suite/innodb_plugin/t/disabled.def: Disable some tests that depends on newer version of XtraDB mysql-test/suite/innodb_plugin/t/innodb-index-ip.test: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/t/innodb-index-xb.test: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/t/innodb-index.test: Move tests away that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/t/innodb-ip.test: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/t/innodb-xb.test: Tests from innodb-index that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/t/innodb.test: Move tests away that gave different results for innodb_plugin and xtradb mysql-test/suite/innodb_plugin/t/innodb_bug21704-xb.test: Test result differ for xtradb mysql-test/suite/innodb_plugin/t/innodb_bug21704.test: Test result differ for xtradb mysql-test/suite/innodb_plugin/t/innodb_bug53591.test: Test results only makes sence for innodb_plugin (things works ok for xtradb) sql/sql_table.cc: Don't set HA_CREATE_USED_ROW_FORMAT for create table (only for update_create_info) if ROW_FORMAT is not used. storage/innodb_plugin/handler/ha_innodb.cc: Fixed wrong error message from innodb. This is needed as MariaDB properly handles errors from ha_index_init() storage/xtradb/handler/ha_innodb.cc: Update base information for XtraDB so that one can use informationschema.plugins to check if one is using XtraDB
16 years ago
  1. set global innodb_support_xa=default;
  2. set session innodb_support_xa=default;
  3. SET SESSION STORAGE_ENGINE = InnoDB;
  4. drop table if exists t1,t2,t3,t1m,t1i,t2m,t2i,t4;
  5. drop procedure if exists p1;
  6. create table t1 (
  7. c_id int(11) not null default '0',
  8. org_id int(11) default null,
  9. unique key contacts$c_id (c_id),
  10. key contacts$org_id (org_id)
  11. );
  12. insert into t1 values
  13. (2,null),(120,null),(141,null),(218,7), (128,1),
  14. (151,2),(234,2),(236,2),(243,2),(255,2),(259,2),(232,3),(235,3),(238,3),
  15. (246,3),(253,3),(269,3),(285,3),(291,3),(293,3),(131,4),(230,4),(231,4);
  16. create table t2 (
  17. slai_id int(11) not null default '0',
  18. owner_tbl int(11) default null,
  19. owner_id int(11) default null,
  20. sla_id int(11) default null,
  21. inc_web int(11) default null,
  22. inc_email int(11) default null,
  23. inc_chat int(11) default null,
  24. inc_csr int(11) default null,
  25. inc_total int(11) default null,
  26. time_billed int(11) default null,
  27. activedate timestamp null default null,
  28. expiredate timestamp null default null,
  29. state int(11) default null,
  30. sla_set int(11) default null,
  31. unique key t2$slai_id (slai_id),
  32. key t2$owner_id (owner_id),
  33. key t2$sla_id (sla_id)
  34. );
  35. insert into t2(slai_id, owner_tbl, owner_id, sla_id) values
  36. (1,3,1,1), (3,3,10,2), (4,3,3,6), (5,3,2,5), (6,3,8,3), (7,3,9,7),
  37. (8,3,6,8), (9,3,4,9), (10,3,5,10), (11,3,11,11), (12,3,7,12);
  38. flush tables;
  39. select si.slai_id
  40. from t1 c join t2 si on
  41. ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
  42. ( si.owner_tbl = 2 and si.owner_id = c.c_id))
  43. where
  44. c.c_id = 218 and expiredate is null;
  45. slai_id
  46. 12
  47. select * from t1 where org_id is null;
  48. c_id org_id
  49. 2 NULL
  50. 120 NULL
  51. 141 NULL
  52. select si.slai_id
  53. from t1 c join t2 si on
  54. ((si.owner_tbl = 3 and si.owner_id = c.org_id) or
  55. ( si.owner_tbl = 2 and si.owner_id = c.c_id))
  56. where
  57. c.c_id = 218 and expiredate is null;
  58. slai_id
  59. 12
  60. drop table t1, t2;
  61. CREATE TABLE t1 (a int, b int, KEY b (b));
  62. CREATE TABLE t2 (a int, b int, PRIMARY KEY (a,b));
  63. CREATE TABLE t3 (a int, b int, c int, PRIMARY KEY (a),
  64. UNIQUE KEY b (b,c), KEY a (a,b,c));
  65. INSERT INTO t1 VALUES (1, 1);
  66. INSERT INTO t1 SELECT a + 1, b + 1 FROM t1;
  67. INSERT INTO t1 SELECT a + 2, b + 2 FROM t1;
  68. INSERT INTO t2 VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(1,7),(1,8);
  69. INSERT INTO t2 SELECT a + 1, b FROM t2;
  70. DELETE FROM t2 WHERE a = 1 AND b < 2;
  71. INSERT INTO t3 VALUES (1,1,1),(2,1,2);
  72. INSERT INTO t3 SELECT a + 2, a + 2, 3 FROM t3;
  73. INSERT INTO t3 SELECT a + 4, a + 4, 3 FROM t3;
  74. SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
  75. t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
  76. ORDER BY t1.b LIMIT 2;
  77. b a
  78. 1 1
  79. 2 2
  80. SELECT STRAIGHT_JOIN SQL_NO_CACHE t1.b, t1.a FROM t1, t3, t2 WHERE
  81. t3.a = t2.a AND t2.b = t1.a AND t3.b = 1 AND t3.c IN (1, 2)
  82. ORDER BY t1.b LIMIT 5;
  83. b a
  84. 1 1
  85. 2 2
  86. 2 2
  87. 3 3
  88. 3 3
  89. DROP TABLE t1, t2, t3;
  90. CREATE TABLE `t1` (`id1` INT) ;
  91. INSERT INTO `t1` (`id1`) VALUES (1),(5),(2);
  92. CREATE TABLE `t2` (
  93. `id1` INT,
  94. `id2` INT NOT NULL,
  95. `id3` INT,
  96. `id4` INT NOT NULL,
  97. UNIQUE (`id2`,`id4`),
  98. KEY (`id1`)
  99. );
  100. INSERT INTO `t2`(`id1`,`id2`,`id3`,`id4`) VALUES
  101. (1,1,1,0),
  102. (1,1,2,1),
  103. (5,1,2,2),
  104. (6,1,2,3),
  105. (1,2,2,2),
  106. (1,2,1,1);
  107. SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = 1 AND `id3` = 2);
  108. id1
  109. 2
  110. DROP TABLE t1, t2;
  111. create table t1 (c1 int) engine=innodb;
  112. handler t1 open;
  113. handler t1 read first;
  114. c1
  115. Before and after comparison
  116. 0
  117. drop table t1;
  118. CREATE TABLE t1(c1 TEXT, UNIQUE (c1(1)), cnt INT DEFAULT 1)
  119. ENGINE=INNODB CHARACTER SET UTF8;
  120. INSERT INTO t1 (c1) VALUES ('1a');
  121. SELECT * FROM t1;
  122. c1 cnt
  123. 1a 1
  124. INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
  125. SELECT * FROM t1;
  126. c1 cnt
  127. 1a 2
  128. DROP TABLE t1;
  129. CREATE TABLE t1(c1 VARCHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
  130. ENGINE=INNODB CHARACTER SET UTF8;
  131. INSERT INTO t1 (c1) VALUES ('1a');
  132. SELECT * FROM t1;
  133. c1 cnt
  134. 1a 1
  135. INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
  136. SELECT * FROM t1;
  137. c1 cnt
  138. 1a 2
  139. DROP TABLE t1;
  140. CREATE TABLE t1(c1 CHAR(2), UNIQUE (c1(1)), cnt INT DEFAULT 1)
  141. ENGINE=INNODB CHARACTER SET UTF8;
  142. INSERT INTO t1 (c1) VALUES ('1a');
  143. SELECT * FROM t1;
  144. c1 cnt
  145. 1a 1
  146. INSERT INTO t1 (c1) VALUES ('1b') ON DUPLICATE KEY UPDATE cnt=cnt+1;
  147. SELECT * FROM t1;
  148. c1 cnt
  149. 1a 2
  150. DROP TABLE t1;
  151. CREATE TABLE t1 (
  152. a1 decimal(10,0) DEFAULT NULL,
  153. a2 blob,
  154. a3 time DEFAULT NULL,
  155. a4 blob,
  156. a5 char(175) DEFAULT NULL,
  157. a6 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  158. a7 tinyblob,
  159. INDEX idx (a6,a7(239),a5)
  160. ) ENGINE=InnoDB;
  161. EXPLAIN SELECT a4 FROM t1 WHERE
  162. a6=NULL AND
  163. a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
  164. id select_type table type possible_keys key key_len ref rows Extra
  165. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  166. EXPLAIN SELECT t1.a4 FROM t1, t1 t WHERE
  167. t.a6=t.a6 AND t1.a6=NULL AND
  168. t1.a4='UNcT5pIde4I6c2SheTo4gt92OV1jgJCVkXmzyf325R1DwLURkbYHwhydANIZMbKTgdcR5xS';
  169. id select_type table type possible_keys key key_len ref rows Extra
  170. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  171. DROP TABLE t1;
  172. create table t1m (a int) engine = MEMORY;
  173. create table t1i (a int);
  174. create table t2m (a int) engine = MEMORY;
  175. create table t2i (a int);
  176. insert into t2m values (5);
  177. insert into t2i values (5);
  178. select min(a) from t1i;
  179. min(a)
  180. NULL
  181. select min(7) from t1i;
  182. min(7)
  183. NULL
  184. select min(7) from DUAL;
  185. min(7)
  186. 7
  187. explain select min(7) from t2i join t1i;
  188. id select_type table type possible_keys key key_len ref rows Extra
  189. 1 SIMPLE t2i ALL NULL NULL NULL NULL 1
  190. 1 SIMPLE t1i ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
  191. select min(7) from t2i join t1i;
  192. min(7)
  193. NULL
  194. select max(a) from t1i;
  195. max(a)
  196. NULL
  197. select max(7) from t1i;
  198. max(7)
  199. NULL
  200. select max(7) from DUAL;
  201. max(7)
  202. 7
  203. explain select max(7) from t2i join t1i;
  204. id select_type table type possible_keys key key_len ref rows Extra
  205. 1 SIMPLE t2i ALL NULL NULL NULL NULL 1
  206. 1 SIMPLE t1i ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
  207. select max(7) from t2i join t1i;
  208. max(7)
  209. NULL
  210. select 1, min(a) from t1i where a=99;
  211. 1 min(a)
  212. 1 NULL
  213. select 1, min(a) from t1i where 1=99;
  214. 1 min(a)
  215. 1 NULL
  216. select 1, min(1) from t1i where a=99;
  217. 1 min(1)
  218. 1 NULL
  219. select 1, min(1) from t1i where 1=99;
  220. 1 min(1)
  221. 1 NULL
  222. select 1, max(a) from t1i where a=99;
  223. 1 max(a)
  224. 1 NULL
  225. select 1, max(a) from t1i where 1=99;
  226. 1 max(a)
  227. 1 NULL
  228. select 1, max(1) from t1i where a=99;
  229. 1 max(1)
  230. 1 NULL
  231. select 1, max(1) from t1i where 1=99;
  232. 1 max(1)
  233. 1 NULL
  234. explain select count(*), min(7), max(7) from t1m, t1i;
  235. id select_type table type possible_keys key key_len ref rows Extra
  236. 1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found
  237. 1 SIMPLE t1i ALL NULL NULL NULL NULL 1
  238. select count(*), min(7), max(7) from t1m, t1i;
  239. count(*) min(7) max(7)
  240. 0 NULL NULL
  241. explain select count(*), min(7), max(7) from t1m, t2i;
  242. id select_type table type possible_keys key key_len ref rows Extra
  243. 1 SIMPLE t1m system NULL NULL NULL NULL 0 const row not found
  244. 1 SIMPLE t2i ALL NULL NULL NULL NULL 1
  245. select count(*), min(7), max(7) from t1m, t2i;
  246. count(*) min(7) max(7)
  247. 0 NULL NULL
  248. explain select count(*), min(7), max(7) from t2m, t1i;
  249. id select_type table type possible_keys key key_len ref rows Extra
  250. 1 SIMPLE t2m system NULL NULL NULL NULL 1
  251. 1 SIMPLE t1i ALL NULL NULL NULL NULL 1
  252. select count(*), min(7), max(7) from t2m, t1i;
  253. count(*) min(7) max(7)
  254. 0 NULL NULL
  255. drop table t1m, t1i, t2m, t2i;
  256. create table t1 (
  257. a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
  258. ) ENGINE = MEMORY;
  259. insert into t1 (a1, a2, b, c, d) values
  260. ('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
  261. ('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
  262. ('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
  263. ('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
  264. ('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
  265. ('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
  266. ('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
  267. ('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
  268. ('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
  269. ('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
  270. ('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
  271. ('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
  272. ('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
  273. ('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
  274. ('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
  275. ('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4'),
  276. ('a','a','a','a111','xy1'),('a','a','a','b111','xy2'),('a','a','a','c111','xy3'),('a','a','a','d111','xy4'),
  277. ('a','a','b','e112','xy1'),('a','a','b','f112','xy2'),('a','a','b','g112','xy3'),('a','a','b','h112','xy4'),
  278. ('a','b','a','i121','xy1'),('a','b','a','j121','xy2'),('a','b','a','k121','xy3'),('a','b','a','l121','xy4'),
  279. ('a','b','b','m122','xy1'),('a','b','b','n122','xy2'),('a','b','b','o122','xy3'),('a','b','b','p122','xy4'),
  280. ('b','a','a','a211','xy1'),('b','a','a','b211','xy2'),('b','a','a','c211','xy3'),('b','a','a','d211','xy4'),
  281. ('b','a','b','e212','xy1'),('b','a','b','f212','xy2'),('b','a','b','g212','xy3'),('b','a','b','h212','xy4'),
  282. ('b','b','a','i221','xy1'),('b','b','a','j221','xy2'),('b','b','a','k221','xy3'),('b','b','a','l221','xy4'),
  283. ('b','b','b','m222','xy1'),('b','b','b','n222','xy2'),('b','b','b','o222','xy3'),('b','b','b','p222','xy4'),
  284. ('c','a','a','a311','xy1'),('c','a','a','b311','xy2'),('c','a','a','c311','xy3'),('c','a','a','d311','xy4'),
  285. ('c','a','b','e312','xy1'),('c','a','b','f312','xy2'),('c','a','b','g312','xy3'),('c','a','b','h312','xy4'),
  286. ('c','b','a','i321','xy1'),('c','b','a','j321','xy2'),('c','b','a','k321','xy3'),('c','b','a','l321','xy4'),
  287. ('c','b','b','m322','xy1'),('c','b','b','n322','xy2'),('c','b','b','o322','xy3'),('c','b','b','p322','xy4'),
  288. ('d','a','a','a411','xy1'),('d','a','a','b411','xy2'),('d','a','a','c411','xy3'),('d','a','a','d411','xy4'),
  289. ('d','a','b','e412','xy1'),('d','a','b','f412','xy2'),('d','a','b','g412','xy3'),('d','a','b','h412','xy4'),
  290. ('d','b','a','i421','xy1'),('d','b','a','j421','xy2'),('d','b','a','k421','xy3'),('d','b','a','l421','xy4'),
  291. ('d','b','b','m422','xy1'),('d','b','b','n422','xy2'),('d','b','b','o422','xy3'),('d','b','b','p422','xy4');
  292. create table t4 (
  293. pk_col int auto_increment primary key, a1 char(64), a2 char(64), b char(16), c char(16) not null, d char(16), dummy char(64) default ' '
  294. );
  295. insert into t4 (a1, a2, b, c, d, dummy) select * from t1;
  296. create index idx12672_0 on t4 (a1);
  297. create index idx12672_1 on t4 (a1,a2,b,c);
  298. create index idx12672_2 on t4 (a1,a2,b);
  299. analyze table t4;
  300. Table Op Msg_type Msg_text
  301. test.t4 analyze status OK
  302. select distinct a1 from t4 where pk_col not in (1,2,3,4);
  303. a1
  304. a
  305. b
  306. c
  307. d
  308. drop table t1,t4;
  309. DROP TABLE IF EXISTS t2, t1;
  310. CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB;
  311. CREATE TABLE t2 (
  312. i INT NOT NULL,
  313. FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION
  314. ) ENGINE= InnoDB;
  315. INSERT INTO t1 VALUES (1);
  316. INSERT INTO t2 VALUES (1);
  317. DELETE IGNORE FROM t1 WHERE i = 1;
  318. Warnings:
  319. Error 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`i`) REFERENCES `t1` (`i`) ON DELETE NO ACTION)
  320. SELECT * FROM t1, t2;
  321. i i
  322. 1 1
  323. DROP TABLE t2, t1;
  324. End of 4.1 tests.
  325. create table t1 (
  326. a varchar(30), b varchar(30), primary key(a), key(b)
  327. );
  328. select distinct a from t1;
  329. a
  330. drop table t1;
  331. create table t1(a int, key(a));
  332. insert into t1 values(1);
  333. select a, count(a) from t1 group by a with rollup;
  334. a count(a)
  335. 1 1
  336. NULL 1
  337. drop table t1;
  338. create table t1 (f1 int, f2 char(1), primary key(f1,f2));
  339. insert into t1 values ( 1,"e"),(2,"a"),( 3,"c"),(4,"d");
  340. alter table t1 drop primary key, add primary key (f2, f1);
  341. explain select distinct f1 a, f1 b from t1;
  342. id select_type table type possible_keys key key_len ref rows Extra
  343. 1 SIMPLE t1 index NULL PRIMARY 5 NULL 4 Using index; Using temporary
  344. explain select distinct f1, f2 from t1;
  345. id select_type table type possible_keys key key_len ref rows Extra
  346. 1 SIMPLE t1 range NULL PRIMARY 5 NULL 3 Using index for group-by; Using temporary
  347. drop table t1;
  348. CREATE TABLE t1 (id int(11) NOT NULL PRIMARY KEY, name varchar(20),
  349. INDEX (name));
  350. CREATE TABLE t2 (id int(11) NOT NULL PRIMARY KEY, fkey int(11));
  351. ALTER TABLE t2 ADD FOREIGN KEY (fkey) REFERENCES t2(id);
  352. INSERT INTO t1 VALUES (1,'A1'),(2,'A2'),(3,'B');
  353. INSERT INTO t2 VALUES (1,1),(2,2),(3,2),(4,3),(5,3);
  354. EXPLAIN
  355. SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
  356. WHERE t1.name LIKE 'A%';
  357. id select_type table type possible_keys key key_len ref rows Extra
  358. 1 SIMPLE t1 index PRIMARY,name name 23 NULL 3 Using where; Using index
  359. 1 SIMPLE t2 ref fkey fkey 5 test.t1.id 1 Using index
  360. EXPLAIN
  361. SELECT COUNT(*) FROM t2 LEFT JOIN t1 ON t2.fkey = t1.id
  362. WHERE t1.name LIKE 'A%' OR FALSE;
  363. id select_type table type possible_keys key key_len ref rows Extra
  364. 1 SIMPLE t2 index NULL fkey 5 NULL 5 Using index
  365. 1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.fkey 1 Using where
  366. DROP TABLE t1,t2;
  367. CREATE TABLE t1 (
  368. id int NOT NULL,
  369. name varchar(20) NOT NULL,
  370. dept varchar(20) NOT NULL,
  371. age tinyint(3) unsigned NOT NULL,
  372. PRIMARY KEY (id),
  373. INDEX (name,dept)
  374. ) ENGINE=InnoDB;
  375. INSERT INTO t1(id, dept, age, name) VALUES
  376. (3987, 'cs1', 10, 'rs1'), (3988, 'cs2', 20, 'rs1'), (3995, 'cs3', 10, 'rs2'),
  377. (3996, 'cs4', 20, 'rs2'), (4003, 'cs5', 10, 'rs3'), (4004, 'cs6', 20, 'rs3'),
  378. (4011, 'cs7', 10, 'rs4'), (4012, 'cs8', 20, 'rs4'), (4019, 'cs9', 10, 'rs5'),
  379. (4020, 'cs10', 20, 'rs5'),(4027, 'cs11', 10, 'rs6'),(4028, 'cs12', 20, 'rs6');
  380. EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
  381. id select_type table type possible_keys key key_len ref rows Extra
  382. 1 SIMPLE t1 range name name 44 NULL 2 Using where; Using index for group-by
  383. SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
  384. name dept
  385. rs5 cs10
  386. rs5 cs9
  387. DELETE FROM t1;
  388. # Masking (#) number in "rows" column of the following EXPLAIN output, as it may vary (bug#47746).
  389. EXPLAIN SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
  390. id select_type table type possible_keys key key_len ref rows Extra
  391. 1 SIMPLE t1 range name name 44 NULL # Using where; Using index for group-by
  392. SELECT DISTINCT t1.name, t1.dept FROM t1 WHERE t1.name='rs5';
  393. name dept
  394. DROP TABLE t1;
  395. drop table if exists t1;
  396. show variables like 'innodb_rollback_on_timeout';
  397. Variable_name Value
  398. innodb_rollback_on_timeout OFF
  399. create table t1 (a int unsigned not null primary key) engine = innodb;
  400. insert into t1 values (1);
  401. commit;
  402. begin work;
  403. insert into t1 values (2);
  404. select * from t1;
  405. a
  406. 1
  407. 2
  408. begin work;
  409. insert into t1 values (5);
  410. select * from t1;
  411. a
  412. 1
  413. 5
  414. insert into t1 values (2);
  415. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  416. select * from t1;
  417. a
  418. 1
  419. 5
  420. commit;
  421. select * from t1;
  422. a
  423. 1
  424. 2
  425. commit;
  426. select * from t1;
  427. a
  428. 1
  429. 2
  430. 5
  431. drop table t1;
  432. set @save_qcache_size=@@global.query_cache_size;
  433. set @save_qcache_type=@@global.query_cache_type;
  434. set global query_cache_size=10*1024*1024;
  435. set global query_cache_type=1;
  436. drop table if exists `test`;
  437. Warnings:
  438. Note 1051 Unknown table 'test'
  439. CREATE TABLE `test` (`test1` varchar(3) NOT NULL,
  440. `test2` varchar(4) NOT NULL,PRIMARY KEY (`test1`))
  441. ENGINE=InnoDB DEFAULT CHARSET=latin1;
  442. INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '5678');
  443. select * from test;
  444. test1 test2
  445. tes 5678
  446. INSERT INTO `test` (`test1`, `test2`) VALUES ('tes', '1234')
  447. ON DUPLICATE KEY UPDATE `test2` = '1234';
  448. select * from test;
  449. test1 test2
  450. tes 1234
  451. flush tables;
  452. select * from test;
  453. test1 test2
  454. tes 1234
  455. drop table test;
  456. set global query_cache_type=@save_qcache_type;
  457. set global query_cache_size=@save_qcache_size;
  458. drop table if exists t1;
  459. show variables like 'innodb_rollback_on_timeout';
  460. Variable_name Value
  461. innodb_rollback_on_timeout OFF
  462. create table t1 (a int unsigned not null primary key) engine = innodb;
  463. insert into t1 values (1);
  464. commit;
  465. begin work;
  466. insert into t1 values (2);
  467. select * from t1;
  468. a
  469. 1
  470. 2
  471. begin work;
  472. insert into t1 values (5);
  473. select * from t1;
  474. a
  475. 1
  476. 5
  477. insert into t1 values (2);
  478. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  479. select * from t1;
  480. a
  481. 1
  482. 5
  483. commit;
  484. select * from t1;
  485. a
  486. 1
  487. 2
  488. commit;
  489. select * from t1;
  490. a
  491. 1
  492. 2
  493. 5
  494. drop table t1;
  495. create table t1(
  496. id int auto_increment,
  497. c char(1) not null,
  498. counter int not null default 1,
  499. primary key (id),
  500. unique key (c)
  501. ) engine=innodb;
  502. insert into t1 (id, c) values
  503. (NULL, 'a'),
  504. (NULL, 'a')
  505. on duplicate key update id = values(id), counter = counter + 1;
  506. select * from t1;
  507. id c counter
  508. 2 a 2
  509. insert into t1 (id, c) values
  510. (NULL, 'b')
  511. on duplicate key update id = values(id), counter = counter + 1;
  512. select * from t1;
  513. id c counter
  514. 2 a 2
  515. 3 b 1
  516. truncate table t1;
  517. insert into t1 (id, c) values (NULL, 'a');
  518. select * from t1;
  519. id c counter
  520. 1 a 1
  521. insert into t1 (id, c) values (NULL, 'b'), (NULL, 'b')
  522. on duplicate key update id = values(id), c = values(c), counter = counter + 1;
  523. select * from t1;
  524. id c counter
  525. 1 a 1
  526. 3 b 2
  527. insert into t1 (id, c) values (NULL, 'a')
  528. on duplicate key update id = values(id), c = values(c), counter = counter + 1;
  529. select * from t1;
  530. id c counter
  531. 3 b 2
  532. 4 a 2
  533. drop table t1;
  534. CREATE TABLE t1(
  535. id int AUTO_INCREMENT PRIMARY KEY,
  536. stat_id int NOT NULL,
  537. acct_id int DEFAULT NULL,
  538. INDEX idx1 (stat_id, acct_id),
  539. INDEX idx2 (acct_id)
  540. ) ENGINE=MyISAM;
  541. CREATE TABLE t2(
  542. id int AUTO_INCREMENT PRIMARY KEY,
  543. stat_id int NOT NULL,
  544. acct_id int DEFAULT NULL,
  545. INDEX idx1 (stat_id, acct_id),
  546. INDEX idx2 (acct_id)
  547. ) ENGINE=InnoDB;
  548. INSERT INTO t1(stat_id,acct_id) VALUES
  549. (1,759), (2,831), (3,785), (4,854), (1,921),
  550. (1,553), (2,589), (3,743), (2,827), (2,545),
  551. (4,779), (4,783), (1,597), (1,785), (4,832),
  552. (1,741), (1,833), (3,788), (2,973), (1,907);
  553. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  554. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  555. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  556. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  557. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  558. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  559. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  560. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  561. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  562. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  563. INSERT INTO t1(stat_id,acct_id) SELECT stat_id, mod(id+100000, acct_id) FROM t1;
  564. UPDATE t1 SET acct_id=785
  565. WHERE MOD(stat_id,2)=0 AND MOD(id,stat_id)=MOD(acct_id,stat_id);
  566. OPTIMIZE TABLE t1;
  567. Table Op Msg_type Msg_text
  568. test.t1 optimize status OK
  569. SELECT COUNT(*) FROM t1;
  570. COUNT(*)
  571. 40960
  572. SELECT COUNT(*) FROM t1 WHERE acct_id=785;
  573. COUNT(*)
  574. 8702
  575. EXPLAIN SELECT COUNT(*) FROM t1 WHERE stat_id IN (1,3) AND acct_id=785;
  576. id select_type table type possible_keys key key_len ref rows Extra
  577. 1 SIMPLE t1 range idx1,idx2 idx1 9 NULL 2 Using where; Using index
  578. INSERT INTO t2 SELECT * FROM t1;
  579. OPTIMIZE TABLE t2;
  580. Table Op Msg_type Msg_text
  581. test.t2 optimize note Table does not support optimize, doing recreate + analyze instead
  582. test.t2 optimize status OK
  583. EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
  584. id select_type table type possible_keys key key_len ref rows Extra
  585. 1 SIMPLE t2 range idx1,idx2 idx1 9 NULL 2 Using where; Using index
  586. DROP TABLE t1,t2;
  587. create table t1(a int) engine=innodb;
  588. alter table t1 comment '123';
  589. show create table t1;
  590. Table Create Table
  591. t1 CREATE TABLE `t1` (
  592. `a` int(11) DEFAULT NULL
  593. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='123'
  594. drop table t1;
  595. CREATE TABLE t1 (a CHAR(2), KEY (a)) ENGINE = InnoDB DEFAULT CHARSET=UTF8;
  596. INSERT INTO t1 VALUES ('uk'),('bg');
  597. SELECT * FROM t1 WHERE a = 'uk';
  598. a
  599. uk
  600. DELETE FROM t1 WHERE a = 'uk';
  601. SELECT * FROM t1 WHERE a = 'uk';
  602. a
  603. UPDATE t1 SET a = 'us' WHERE a = 'uk';
  604. SELECT * FROM t1 WHERE a = 'uk';
  605. a
  606. CREATE TABLE t2 (a CHAR(2), KEY (a)) ENGINE = InnoDB;
  607. INSERT INTO t2 VALUES ('uk'),('bg');
  608. SELECT * FROM t2 WHERE a = 'uk';
  609. a
  610. uk
  611. DELETE FROM t2 WHERE a = 'uk';
  612. SELECT * FROM t2 WHERE a = 'uk';
  613. a
  614. INSERT INTO t2 VALUES ('uk');
  615. UPDATE t2 SET a = 'us' WHERE a = 'uk';
  616. SELECT * FROM t2 WHERE a = 'uk';
  617. a
  618. CREATE TABLE t3 (a CHAR(2), KEY (a)) ENGINE = MyISAM;
  619. INSERT INTO t3 VALUES ('uk'),('bg');
  620. SELECT * FROM t3 WHERE a = 'uk';
  621. a
  622. uk
  623. DELETE FROM t3 WHERE a = 'uk';
  624. SELECT * FROM t3 WHERE a = 'uk';
  625. a
  626. INSERT INTO t3 VALUES ('uk');
  627. UPDATE t3 SET a = 'us' WHERE a = 'uk';
  628. SELECT * FROM t3 WHERE a = 'uk';
  629. a
  630. DROP TABLE t1,t2,t3;
  631. create table t1 (a int) engine=innodb;
  632. select * from bug29807;
  633. ERROR 42S02: Table 'test.bug29807' doesn't exist
  634. drop table t1;
  635. drop table bug29807;
  636. ERROR 42S02: Unknown table 'bug29807'
  637. create table bug29807 (a int);
  638. drop table bug29807;
  639. CREATE TABLE t1 (a INT) ENGINE=InnoDB;
  640. CREATE TABLE t2 (a INT) ENGINE=InnoDB;
  641. switch to connection c1
  642. SET AUTOCOMMIT=0;
  643. INSERT INTO t2 VALUES (1);
  644. switch to connection c2
  645. SET AUTOCOMMIT=0;
  646. LOCK TABLES t1 READ, t2 READ;
  647. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  648. switch to connection c1
  649. COMMIT;
  650. INSERT INTO t1 VALUES (1);
  651. switch to connection default
  652. SET AUTOCOMMIT=default;
  653. DROP TABLE t1,t2;
  654. CREATE TABLE t1 (
  655. id int NOT NULL auto_increment PRIMARY KEY,
  656. b int NOT NULL,
  657. c datetime NOT NULL,
  658. INDEX idx_b(b),
  659. INDEX idx_c(c)
  660. ) ENGINE=InnoDB;
  661. CREATE TABLE t2 (
  662. b int NOT NULL auto_increment PRIMARY KEY,
  663. c datetime NOT NULL
  664. ) ENGINE= MyISAM;
  665. INSERT INTO t2(c) VALUES ('2007-01-01');
  666. INSERT INTO t2(c) SELECT c FROM t2;
  667. INSERT INTO t2(c) SELECT c FROM t2;
  668. INSERT INTO t2(c) SELECT c FROM t2;
  669. INSERT INTO t2(c) SELECT c FROM t2;
  670. INSERT INTO t2(c) SELECT c FROM t2;
  671. INSERT INTO t2(c) SELECT c FROM t2;
  672. INSERT INTO t2(c) SELECT c FROM t2;
  673. INSERT INTO t2(c) SELECT c FROM t2;
  674. INSERT INTO t2(c) SELECT c FROM t2;
  675. INSERT INTO t2(c) SELECT c FROM t2;
  676. INSERT INTO t1(b,c) SELECT b,c FROM t2;
  677. UPDATE t2 SET c='2007-01-02';
  678. INSERT INTO t1(b,c) SELECT b,c FROM t2;
  679. UPDATE t2 SET c='2007-01-03';
  680. INSERT INTO t1(b,c) SELECT b,c FROM t2;
  681. set @@sort_buffer_size=8192;
  682. SELECT COUNT(*) FROM t1;
  683. COUNT(*)
  684. 3072
  685. EXPLAIN
  686. SELECT COUNT(*) FROM t1
  687. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  688. id select_type table type possible_keys key key_len ref rows Extra
  689. 1 SIMPLE t1 ALL idx_b,idx_c NULL NULL NULL # Using where
  690. SELECT COUNT(*) FROM t1
  691. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  692. COUNT(*)
  693. 3072
  694. EXPLAIN
  695. SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
  696. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  697. id select_type table type possible_keys key key_len ref rows Extra
  698. 1 SIMPLE t1 index_merge idx_b,idx_c idx_c,idx_b 8,4 NULL # Using sort_union(idx_c,idx_b); Using where
  699. SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
  700. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  701. COUNT(*)
  702. 3072
  703. set @@sort_buffer_size=default;
  704. DROP TABLE t1,t2;
  705. CREATE TABLE t1 (a int, b int);
  706. insert into t1 values (1,1),(1,2);
  707. CREATE TABLE t2 (primary key (a)) select * from t1;
  708. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  709. drop table if exists t2;
  710. Warnings:
  711. Note 1051 Unknown table 't2'
  712. CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
  713. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  714. drop table if exists t2;
  715. Warnings:
  716. Note 1051 Unknown table 't2'
  717. CREATE TABLE t2 (a int, b int, primary key (a));
  718. BEGIN;
  719. INSERT INTO t2 values(100,100);
  720. CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
  721. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  722. SELECT * from t2;
  723. a b
  724. 100 100
  725. ROLLBACK;
  726. SELECT * from t2;
  727. a b
  728. 100 100
  729. TRUNCATE table t2;
  730. INSERT INTO t2 select * from t1;
  731. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  732. SELECT * from t2;
  733. a b
  734. drop table t2;
  735. CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
  736. BEGIN;
  737. INSERT INTO t2 values(100,100);
  738. CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
  739. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  740. SELECT * from t2;
  741. a b
  742. 100 100
  743. COMMIT;
  744. BEGIN;
  745. INSERT INTO t2 values(101,101);
  746. CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
  747. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  748. SELECT * from t2;
  749. a b
  750. 100 100
  751. 101 101
  752. ROLLBACK;
  753. SELECT * from t2;
  754. a b
  755. 100 100
  756. TRUNCATE table t2;
  757. INSERT INTO t2 select * from t1;
  758. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  759. SELECT * from t2;
  760. a b
  761. drop table t1,t2;
  762. create table t1(f1 varchar(800) binary not null, key(f1))
  763. character set utf8 collate utf8_general_ci;
  764. Warnings:
  765. Warning 1071 Specified key was too long; max key length is 767 bytes
  766. insert into t1 values('aaa');
  767. drop table t1;
  768. CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
  769. INSERT INTO t1 VALUES ( 1 , 1 , 1);
  770. INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
  771. INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
  772. INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
  773. INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
  774. INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
  775. INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
  776. INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
  777. EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
  778. id select_type table type possible_keys key key_len ref rows Extra
  779. 1 SIMPLE t1 index NULL b 5 NULL 128
  780. EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
  781. id select_type table type possible_keys key key_len ref rows Extra
  782. 1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort
  783. DROP TABLE t1;
  784. drop table if exists t1;
  785. show variables like 'innodb_rollback_on_timeout';
  786. Variable_name Value
  787. innodb_rollback_on_timeout OFF
  788. create table t1 (a int unsigned not null primary key) engine = innodb;
  789. insert into t1 values (1);
  790. commit;
  791. begin work;
  792. insert into t1 values (2);
  793. select * from t1;
  794. a
  795. 1
  796. 2
  797. begin work;
  798. insert into t1 values (5);
  799. select * from t1;
  800. a
  801. 1
  802. 5
  803. insert into t1 values (2);
  804. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  805. select * from t1;
  806. a
  807. 1
  808. 5
  809. commit;
  810. select * from t1;
  811. a
  812. 1
  813. 2
  814. commit;
  815. select * from t1;
  816. a
  817. 1
  818. 2
  819. 5
  820. drop table t1;
  821. drop table if exists t1;
  822. create table t1 (a int) engine=innodb;
  823. alter table t1 alter a set default 1;
  824. drop table t1;
  825. Bug#24918 drop table and lock / inconsistent between
  826. perm and temp tables
  827. Check transactional tables under LOCK TABLES
  828. drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp,
  829. t24918_access;
  830. create table t24918_access (id int);
  831. create table t24918 (id int) engine=myisam;
  832. create temporary table t24918_tmp (id int) engine=myisam;
  833. create table t24918_trans (id int) engine=innodb;
  834. create temporary table t24918_trans_tmp (id int) engine=innodb;
  835. lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
  836. drop table t24918;
  837. select * from t24918_access;
  838. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  839. drop table t24918_trans;
  840. select * from t24918_access;
  841. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  842. drop table t24918_trans_tmp;
  843. select * from t24918_access;
  844. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  845. drop table t24918_tmp;
  846. select * from t24918_access;
  847. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  848. unlock tables;
  849. drop table t24918_access;
  850. CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
  851. INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
  852. INSERT INTO t1 SELECT a + 8, 2 FROM t1;
  853. INSERT INTO t1 SELECT a + 16, 1 FROM t1;
  854. EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
  855. id 1
  856. select_type SIMPLE
  857. table t1
  858. type ref
  859. possible_keys bkey
  860. key bkey
  861. key_len 5
  862. ref const
  863. rows 16
  864. Extra Using where; Using index
  865. SELECT * FROM t1 WHERE b=2 ORDER BY a;
  866. a b
  867. 1 2
  868. 2 2
  869. 3 2
  870. 4 2
  871. 5 2
  872. 6 2
  873. 7 2
  874. 8 2
  875. 9 2
  876. 10 2
  877. 11 2
  878. 12 2
  879. 13 2
  880. 14 2
  881. 15 2
  882. 16 2
  883. EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
  884. id 1
  885. select_type SIMPLE
  886. table t1
  887. type range
  888. possible_keys bkey
  889. key bkey
  890. key_len 5
  891. ref NULL
  892. rows 16
  893. Extra Using where; Using index; Using filesort
  894. SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
  895. a b
  896. 1 2
  897. 2 2
  898. 3 2
  899. 4 2
  900. 5 2
  901. 6 2
  902. 7 2
  903. 8 2
  904. 9 2
  905. 10 2
  906. 11 2
  907. 12 2
  908. 13 2
  909. 14 2
  910. 15 2
  911. 16 2
  912. 17 1
  913. 18 1
  914. 19 1
  915. 20 1
  916. 21 1
  917. 22 1
  918. 23 1
  919. 24 1
  920. 25 1
  921. 26 1
  922. 27 1
  923. 28 1
  924. 29 1
  925. 30 1
  926. 31 1
  927. 32 1
  928. EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
  929. id 1
  930. select_type SIMPLE
  931. table t1
  932. type range
  933. possible_keys bkey
  934. key bkey
  935. key_len 5
  936. ref NULL
  937. rows 16
  938. Extra Using where; Using index
  939. SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
  940. a b
  941. 17 1
  942. 18 1
  943. 19 1
  944. 20 1
  945. 21 1
  946. 22 1
  947. 23 1
  948. 24 1
  949. 25 1
  950. 26 1
  951. 27 1
  952. 28 1
  953. 29 1
  954. 30 1
  955. 31 1
  956. 32 1
  957. 1 2
  958. 2 2
  959. 3 2
  960. 4 2
  961. 5 2
  962. 6 2
  963. 7 2
  964. 8 2
  965. 9 2
  966. 10 2
  967. 11 2
  968. 12 2
  969. 13 2
  970. 14 2
  971. 15 2
  972. 16 2
  973. CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
  974. ENGINE=InnoDB;
  975. INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
  976. INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
  977. INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
  978. EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
  979. id 1
  980. select_type SIMPLE
  981. table t2
  982. type ref
  983. possible_keys bkey
  984. key bkey
  985. key_len 5
  986. ref const
  987. rows 8
  988. Extra Using where; Using index; Using filesort
  989. SELECT * FROM t2 WHERE b=1 ORDER BY a;
  990. a b c
  991. 1 1 1
  992. 2 1 1
  993. 3 1 1
  994. 4 1 1
  995. 5 1 1
  996. 6 1 1
  997. 7 1 1
  998. 8 1 1
  999. 9 1 1
  1000. 10 1 1
  1001. 11 1 1
  1002. 12 1 1
  1003. 13 1 1
  1004. 14 1 1
  1005. 15 1 1
  1006. 16 1 1
  1007. EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
  1008. id 1
  1009. select_type SIMPLE
  1010. table t2
  1011. type ref
  1012. possible_keys bkey
  1013. key bkey
  1014. key_len 10
  1015. ref const,const
  1016. rows 8
  1017. Extra Using where; Using index
  1018. SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
  1019. a b c
  1020. 1 1 1
  1021. 2 1 1
  1022. 3 1 1
  1023. 4 1 1
  1024. 5 1 1
  1025. 6 1 1
  1026. 7 1 1
  1027. 8 1 1
  1028. 9 1 1
  1029. 10 1 1
  1030. 11 1 1
  1031. 12 1 1
  1032. 13 1 1
  1033. 14 1 1
  1034. 15 1 1
  1035. 16 1 1
  1036. EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
  1037. id 1
  1038. select_type SIMPLE
  1039. table t2
  1040. type ref
  1041. possible_keys bkey
  1042. key bkey
  1043. key_len 10
  1044. ref const,const
  1045. rows 8
  1046. Extra Using where; Using index
  1047. SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
  1048. a b c
  1049. 1 1 1
  1050. 2 1 1
  1051. 3 1 1
  1052. 4 1 1
  1053. 5 1 1
  1054. 6 1 1
  1055. 7 1 1
  1056. 8 1 1
  1057. 9 1 1
  1058. 10 1 1
  1059. 11 1 1
  1060. 12 1 1
  1061. 13 1 1
  1062. 14 1 1
  1063. 15 1 1
  1064. 16 1 1
  1065. EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
  1066. id 1
  1067. select_type SIMPLE
  1068. table t2
  1069. type ref
  1070. possible_keys bkey
  1071. key bkey
  1072. key_len 10
  1073. ref const,const
  1074. rows 8
  1075. Extra Using where; Using index
  1076. SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
  1077. a b c
  1078. 1 1 1
  1079. 2 1 1
  1080. 3 1 1
  1081. 4 1 1
  1082. 5 1 1
  1083. 6 1 1
  1084. 7 1 1
  1085. 8 1 1
  1086. 9 1 1
  1087. 10 1 1
  1088. 11 1 1
  1089. 12 1 1
  1090. 13 1 1
  1091. 14 1 1
  1092. 15 1 1
  1093. 16 1 1
  1094. DROP TABLE t1,t2;
  1095. CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
  1096. INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
  1097. INSERT INTO t1 SELECT a + 8 FROM t1;
  1098. INSERT INTO t1 SELECT a + 16 FROM t1;
  1099. CREATE PROCEDURE p1 ()
  1100. BEGIN
  1101. DECLARE i INT DEFAULT 50;
  1102. DECLARE cnt INT;
  1103. START TRANSACTION;
  1104. ALTER TABLE t1 ENGINE=InnoDB;
  1105. COMMIT;
  1106. START TRANSACTION;
  1107. WHILE (i > 0) DO
  1108. SET i = i - 1;
  1109. SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
  1110. END WHILE;
  1111. COMMIT;
  1112. END;|
  1113. CALL p1();
  1114. CALL p1();
  1115. CALL p1();
  1116. DROP PROCEDURE p1;
  1117. DROP TABLE t1;
  1118. create table t1(a text) engine=innodb default charset=utf8;
  1119. insert into t1 values('aaa');
  1120. alter table t1 add index(a(1024));
  1121. Warnings:
  1122. Warning 1071 Specified key was too long; max key length is 767 bytes
  1123. Warning 1071 Specified key was too long; max key length is 767 bytes
  1124. show create table t1;
  1125. Table Create Table
  1126. t1 CREATE TABLE `t1` (
  1127. `a` text,
  1128. KEY `a` (`a`(255))
  1129. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  1130. drop table t1;
  1131. CREATE TABLE t1 (
  1132. a INT,
  1133. b INT,
  1134. KEY (b)
  1135. ) ENGINE=InnoDB;
  1136. INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
  1137. START TRANSACTION;
  1138. SELECT * FROM t1 WHERE b=20 FOR UPDATE;
  1139. a b
  1140. 2 20
  1141. START TRANSACTION;
  1142. SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
  1143. a b
  1144. 1 10
  1145. 2 10
  1146. ROLLBACK;
  1147. ROLLBACK;
  1148. DROP TABLE t1;
  1149. CREATE TABLE t1(
  1150. a INT,
  1151. b INT NOT NULL,
  1152. c INT NOT NULL,
  1153. d INT,
  1154. UNIQUE KEY (c,b)
  1155. ) engine=innodb;
  1156. INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
  1157. EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
  1158. id select_type table type possible_keys key key_len ref rows Extra
  1159. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
  1160. SELECT c,b,d FROM t1 GROUP BY c,b,d;
  1161. c b d
  1162. 1 1 50
  1163. 3 1 4
  1164. 3 2 40
  1165. EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
  1166. id select_type table type possible_keys key key_len ref rows Extra
  1167. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
  1168. SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
  1169. c b d
  1170. 1 1 50
  1171. 3 1 4
  1172. 3 2 40
  1173. EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
  1174. id select_type table type possible_keys key key_len ref rows Extra
  1175. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
  1176. SELECT c,b,d FROM t1 ORDER BY c,b,d;
  1177. c b d
  1178. 1 1 50
  1179. 3 1 4
  1180. 3 2 40
  1181. EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
  1182. id select_type table type possible_keys key key_len ref rows Extra
  1183. 1 SIMPLE t1 index NULL c 8 NULL 3
  1184. SELECT c,b,d FROM t1 GROUP BY c,b;
  1185. c b d
  1186. 1 1 50
  1187. 3 1 4
  1188. 3 2 40
  1189. EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
  1190. id select_type table type possible_keys key key_len ref rows Extra
  1191. 1 SIMPLE t1 index NULL c 8 NULL 3 Using index
  1192. SELECT c,b FROM t1 GROUP BY c,b;
  1193. c b
  1194. 1 1
  1195. 3 1
  1196. 3 2
  1197. DROP TABLE t1;
  1198. CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
  1199. INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
  1200. EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
  1201. id 1
  1202. select_type SIMPLE
  1203. table t1
  1204. type ref
  1205. possible_keys b
  1206. key b
  1207. key_len 5
  1208. ref const
  1209. rows 1
  1210. Extra Using where; Using index
  1211. SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
  1212. a b
  1213. 2 2
  1214. 3 2
  1215. EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
  1216. id 1
  1217. select_type SIMPLE
  1218. table t1
  1219. type ref
  1220. possible_keys b
  1221. key b
  1222. key_len 5
  1223. ref const
  1224. rows 1
  1225. Extra Using where; Using index
  1226. SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
  1227. a b
  1228. 3 2
  1229. 2 2
  1230. EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
  1231. id 1
  1232. select_type SIMPLE
  1233. table t1
  1234. type index
  1235. possible_keys NULL
  1236. key b
  1237. key_len 5
  1238. ref NULL
  1239. rows 3
  1240. Extra Using index
  1241. SELECT * FROM t1 ORDER BY b ASC, a ASC;
  1242. a b
  1243. 1 1
  1244. 2 2
  1245. 3 2
  1246. EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
  1247. id 1
  1248. select_type SIMPLE
  1249. table t1
  1250. type index
  1251. possible_keys NULL
  1252. key b
  1253. key_len 5
  1254. ref NULL
  1255. rows 3
  1256. Extra Using index
  1257. SELECT * FROM t1 ORDER BY b DESC, a DESC;
  1258. a b
  1259. 3 2
  1260. 2 2
  1261. 1 1
  1262. EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
  1263. id 1
  1264. select_type SIMPLE
  1265. table t1
  1266. type index
  1267. possible_keys NULL
  1268. key b
  1269. key_len 5
  1270. ref NULL
  1271. rows 3
  1272. Extra Using index; Using filesort
  1273. SELECT * FROM t1 ORDER BY b ASC, a DESC;
  1274. a b
  1275. 1 1
  1276. 3 2
  1277. 2 2
  1278. EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
  1279. id 1
  1280. select_type SIMPLE
  1281. table t1
  1282. type index
  1283. possible_keys NULL
  1284. key b
  1285. key_len 5
  1286. ref NULL
  1287. rows 3
  1288. Extra Using index; Using filesort
  1289. SELECT * FROM t1 ORDER BY b DESC, a ASC;
  1290. a b
  1291. 2 2
  1292. 3 2
  1293. 1 1
  1294. DROP TABLE t1;
  1295. #
  1296. # Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
  1297. #
  1298. # - prepare;
  1299. DROP TABLE IF EXISTS t1;
  1300. CREATE TABLE t1(c INT)
  1301. ENGINE = InnoDB
  1302. ROW_FORMAT = COMPACT;
  1303. # - initial check;
  1304. SELECT table_schema, table_name, row_format
  1305. FROM INFORMATION_SCHEMA.TABLES
  1306. WHERE table_schema = DATABASE() AND table_name = 't1';
  1307. table_schema table_name row_format
  1308. test t1 Compact
  1309. # - change ROW_FORMAT and check;
  1310. ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
  1311. SELECT table_schema, table_name, row_format
  1312. FROM INFORMATION_SCHEMA.TABLES
  1313. WHERE table_schema = DATABASE() AND table_name = 't1';
  1314. table_schema table_name row_format
  1315. test t1 Redundant
  1316. # - that's it, cleanup.
  1317. DROP TABLE t1;
  1318. create table t1(a char(10) not null, unique key aa(a(1)),
  1319. b char(4) not null, unique key bb(b(4))) engine=innodb;
  1320. desc t1;
  1321. Field Type Null Key Default Extra
  1322. a char(10) NO UNI NULL
  1323. b char(4) NO PRI NULL
  1324. show create table t1;
  1325. Table Create Table
  1326. t1 CREATE TABLE `t1` (
  1327. `a` char(10) NOT NULL,
  1328. `b` char(4) NOT NULL,
  1329. UNIQUE KEY `bb` (`b`),
  1330. UNIQUE KEY `aa` (`a`(1))
  1331. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1332. drop table t1;
  1333. CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
  1334. INSERT INTO t1 VALUES
  1335. (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
  1336. EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
  1337. id select_type table type possible_keys key key_len ref rows Extra
  1338. 1 SIMPLE t1 ALL idx NULL NULL NULL 4 Using where; Using filesort
  1339. SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
  1340. id type d
  1341. 191 member 1
  1342. NULL member 3
  1343. NULL member 4
  1344. DROP TABLE t1;
  1345. set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
  1346. set global innodb_autoextend_increment=8;
  1347. set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
  1348. set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
  1349. set global innodb_commit_concurrency=0;
  1350. set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
  1351. CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
  1352. ENGINE=InnoDB;
  1353. INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
  1354. INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
  1355. EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
  1356. id select_type table type possible_keys key key_len ref rows Extra
  1357. 1 SIMPLE t1 index t1_b PRIMARY 4 NULL 8 Using where
  1358. SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
  1359. a b c
  1360. 8 1 1
  1361. 7 1 1
  1362. 6 1 1
  1363. 5 1 1
  1364. 4 1 1
  1365. DROP TABLE t1;
  1366. DROP TABLE IF EXISTS t1;
  1367. CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
  1368. CREATE INDEX i1 on t1 (a(3));
  1369. SELECT * FROM t1 WHERE a = 'abcde';
  1370. a
  1371. DROP TABLE t1;
  1372. #
  1373. # BUG #26288: savepoint are not deleted on comit, if the transaction
  1374. # was otherwise empty
  1375. #
  1376. BEGIN;
  1377. SAVEPOINT s1;
  1378. COMMIT;
  1379. RELEASE SAVEPOINT s1;
  1380. ERROR 42000: SAVEPOINT s1 does not exist
  1381. BEGIN;
  1382. SAVEPOINT s2;
  1383. COMMIT;
  1384. ROLLBACK TO SAVEPOINT s2;
  1385. ERROR 42000: SAVEPOINT s2 does not exist
  1386. BEGIN;
  1387. SAVEPOINT s3;
  1388. ROLLBACK;
  1389. RELEASE SAVEPOINT s3;
  1390. ERROR 42000: SAVEPOINT s3 does not exist
  1391. BEGIN;
  1392. SAVEPOINT s4;
  1393. ROLLBACK;
  1394. ROLLBACK TO SAVEPOINT s4;
  1395. ERROR 42000: SAVEPOINT s4 does not exist
  1396. CREATE TABLE t1 (f1 INTEGER PRIMARY KEY COMMENT 'My ID#', f2 INTEGER DEFAULT NULL, f3 CHAR(10) DEFAULT 'My ID#', CONSTRAINT f2_ref FOREIGN KEY (f2) REFERENCES t1 (f1)) ENGINE=INNODB;
  1397. SHOW CREATE TABLE t1;
  1398. Table Create Table
  1399. t1 CREATE TABLE `t1` (
  1400. `f1` int(11) NOT NULL COMMENT 'My ID#',
  1401. `f2` int(11) DEFAULT NULL,
  1402. `f3` char(10) DEFAULT 'My ID#',
  1403. PRIMARY KEY (`f1`),
  1404. KEY `f2_ref` (`f2`),
  1405. CONSTRAINT `f2_ref` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
  1406. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1407. DROP TABLE t1;
  1408. #
  1409. # Bug #36995: valgrind error in remove_const during subquery executions
  1410. #
  1411. create table t1 (a bit(1) not null,b int) engine=myisam;
  1412. create table t2 (c int) engine=innodb;
  1413. set @save_optimizer_switch=@@optimizer_switch;
  1414. set @@optimizer_switch='partial_match_rowid_merge=off,partial_match_table_scan=off';
  1415. explain
  1416. select b from t1 where a not in (select b from t1,t2 group by a) group by a;
  1417. id select_type table type possible_keys key key_len ref rows Extra
  1418. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  1419. 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found
  1420. 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1
  1421. set optimizer_switch=@save_optimizer_switch;
  1422. DROP TABLE t1,t2;
  1423. End of 5.0 tests
  1424. CREATE TABLE `t2` (
  1425. `k` int(11) NOT NULL auto_increment,
  1426. `a` int(11) default NULL,
  1427. `c` int(11) default NULL,
  1428. PRIMARY KEY (`k`),
  1429. UNIQUE KEY `idx_1` (`a`)
  1430. );
  1431. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1432. ifnull( c,
  1433. 0 ) + 1;
  1434. insert into t2 ( a ) values ( 7 ) on duplicate key update c =
  1435. ifnull( c,
  1436. 0 ) + 1;
  1437. select last_insert_id();
  1438. last_insert_id()
  1439. 2
  1440. select * from t2;
  1441. k a c
  1442. 1 6 NULL
  1443. 2 7 NULL
  1444. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1445. ifnull( c,
  1446. 0 ) + 1;
  1447. select last_insert_id();
  1448. last_insert_id()
  1449. 2
  1450. select last_insert_id(0);
  1451. last_insert_id(0)
  1452. 0
  1453. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1454. ifnull( c,
  1455. 0 ) + 1;
  1456. select last_insert_id();
  1457. last_insert_id()
  1458. 0
  1459. select * from t2;
  1460. k a c
  1461. 1 6 2
  1462. 2 7 NULL
  1463. insert ignore into t2 values (null,6,1),(10,8,1);
  1464. select last_insert_id();
  1465. last_insert_id()
  1466. 0
  1467. insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
  1468. select last_insert_id();
  1469. last_insert_id()
  1470. 11
  1471. select * from t2;
  1472. k a c
  1473. 1 6 2
  1474. 2 7 NULL
  1475. 10 8 1
  1476. 11 15 1
  1477. 12 20 1
  1478. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1479. ifnull( c,
  1480. 0 ) + 1, k=last_insert_id(k);
  1481. select last_insert_id();
  1482. last_insert_id()
  1483. 1
  1484. select * from t2;
  1485. k a c
  1486. 1 6 3
  1487. 2 7 NULL
  1488. 10 8 1
  1489. 11 15 1
  1490. 12 20 1
  1491. drop table t2;
  1492. drop table if exists t1, t2;
  1493. create table t1 (i int);
  1494. alter table t1 modify i int default 1;
  1495. alter table t1 modify i int default 2, rename t2;
  1496. lock table t2 write;
  1497. alter table t2 modify i int default 3;
  1498. unlock tables;
  1499. lock table t2 write;
  1500. alter table t2 modify i int default 4, rename t1;
  1501. unlock tables;
  1502. drop table t1;
  1503. drop table if exists t1;
  1504. create table t1 (i int);
  1505. insert into t1 values ();
  1506. lock table t1 write;
  1507. alter table t1 modify i int default 1;
  1508. insert into t1 values ();
  1509. select * from t1;
  1510. i
  1511. NULL
  1512. 1
  1513. alter table t1 change i c char(10) default "Two";
  1514. insert into t1 values ();
  1515. select * from t1;
  1516. c
  1517. NULL
  1518. 1
  1519. Two
  1520. unlock tables;
  1521. select * from t1;
  1522. c
  1523. NULL
  1524. 1
  1525. Two
  1526. drop tables t1;
  1527. create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
  1528. CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
  1529. insert into t1(f1) values(1);
  1530. select @a:=f2 from t1;
  1531. @a:=f2
  1532. #
  1533. update t1 set f1=1;
  1534. select @b:=f2 from t1;
  1535. @b:=f2
  1536. #
  1537. select if(@a=@b,"ok","wrong");
  1538. if(@a=@b,"ok","wrong")
  1539. ok
  1540. insert into t1(f1) values (1) on duplicate key update f1="1";
  1541. select @b:=f2 from t1;
  1542. @b:=f2
  1543. #
  1544. select if(@a=@b,"ok","wrong");
  1545. if(@a=@b,"ok","wrong")
  1546. ok
  1547. insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
  1548. select @b:=f2 from t1;
  1549. @b:=f2
  1550. #
  1551. select if(@a=@b,"ok","wrong");
  1552. if(@a=@b,"ok","wrong")
  1553. ok
  1554. drop table t1;
  1555. SET SESSION AUTOCOMMIT = 0;
  1556. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  1557. set binlog_format=mixed;
  1558. # Switch to connection con1
  1559. CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
  1560. ENGINE = InnoDB;
  1561. INSERT INTO t1 VALUES (1,2);
  1562. # 1. test for locking:
  1563. BEGIN;
  1564. UPDATE t1 SET b = 12 WHERE a = 1;
  1565. affected rows: 1
  1566. info: Rows matched: 1 Changed: 1 Warnings: 0
  1567. SELECT * FROM t1;
  1568. a b
  1569. 1 12
  1570. # Switch to connection con2
  1571. UPDATE t1 SET b = 21 WHERE a = 1;
  1572. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  1573. # Switch to connection con1
  1574. SELECT * FROM t1;
  1575. a b
  1576. 1 12
  1577. ROLLBACK;
  1578. # 2. test for serialized update:
  1579. CREATE TABLE t2 (a INT);
  1580. TRUNCATE t1;
  1581. INSERT INTO t1 VALUES (1,'init');
  1582. CREATE PROCEDURE p1()
  1583. BEGIN
  1584. # retry the UPDATE in case it times out the lock before con1 has time
  1585. # to COMMIT.
  1586. DECLARE do_retry INT DEFAULT 0;
  1587. DECLARE CONTINUE HANDLER FOR SQLEXCEPTION SET do_retry = 1;
  1588. retry_loop:LOOP
  1589. UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
  1590. IF do_retry = 0 THEN
  1591. LEAVE retry_loop;
  1592. END IF;
  1593. SET do_retry = 0;
  1594. END LOOP;
  1595. INSERT INTO t2 VALUES ();
  1596. END|
  1597. BEGIN;
  1598. UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
  1599. affected rows: 1
  1600. info: Rows matched: 1 Changed: 1 Warnings: 0
  1601. SELECT * FROM t1;
  1602. a b
  1603. 1 init+con1
  1604. # Switch to connection con2
  1605. CALL p1;;
  1606. # Switch to connection con1
  1607. SELECT * FROM t1;
  1608. a b
  1609. 1 init+con1
  1610. COMMIT;
  1611. SELECT * FROM t1;
  1612. a b
  1613. 1 init+con1
  1614. # Switch to connection con2
  1615. SELECT * FROM t1;
  1616. a b
  1617. 1 init+con1+con2
  1618. # Switch to connection con1
  1619. # 3. test for updated key column:
  1620. TRUNCATE t1;
  1621. TRUNCATE t2;
  1622. INSERT INTO t1 VALUES (1,'init');
  1623. BEGIN;
  1624. UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
  1625. affected rows: 1
  1626. info: Rows matched: 1 Changed: 1 Warnings: 0
  1627. SELECT * FROM t1;
  1628. a b
  1629. 2 init+con1
  1630. # Switch to connection con2
  1631. CALL p1;;
  1632. # Switch to connection con1
  1633. SELECT * FROM t1;
  1634. a b
  1635. 2 init+con1
  1636. COMMIT;
  1637. SELECT * FROM t1;
  1638. a b
  1639. 2 init+con1
  1640. # Switch to connection con2
  1641. SELECT * FROM t1;
  1642. a b
  1643. 2 init+con1
  1644. DROP PROCEDURE p1;
  1645. DROP TABLE t1, t2;
  1646. CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
  1647. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1648. CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
  1649. ERROR 42000: Incorrect foreign key definition for 'f2': Key reference and table reference don't match
  1650. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1651. CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
  1652. ERROR 42000: Incorrect foreign key definition for 'c2': Key reference and table reference don't match
  1653. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1654. CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
  1655. CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
  1656. ALTER TABLE t2 DROP FOREIGN KEY c2;
  1657. DROP TABLE t2;
  1658. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1659. FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
  1660. ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
  1661. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1662. FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
  1663. ERROR 42000: Incorrect foreign key definition for 'f1': Key reference and table reference don't match
  1664. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1665. CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
  1666. CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
  1667. FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
  1668. FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
  1669. SHOW CREATE TABLE t2;
  1670. Table Create Table
  1671. t2 CREATE TABLE `t2` (
  1672. `c` int(11) NOT NULL,
  1673. `d` int(11) NOT NULL,
  1674. PRIMARY KEY (`c`,`d`),
  1675. CONSTRAINT `c1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON DELETE NO ACTION,
  1676. CONSTRAINT `c2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
  1677. CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
  1678. CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION
  1679. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1680. DROP TABLE t2;
  1681. DROP TABLE t1;
  1682. create table t1 (a int auto_increment primary key) engine=innodb;
  1683. alter table t1 order by a;
  1684. Warnings:
  1685. Warning 1105 ORDER BY ignored as there is a user-defined clustered index in the table 't1'
  1686. drop table t1;
  1687. CREATE TABLE t1
  1688. (vid integer NOT NULL,
  1689. tid integer NOT NULL,
  1690. idx integer NOT NULL,
  1691. name varchar(128) NOT NULL,
  1692. type varchar(128) NULL,
  1693. PRIMARY KEY(idx, vid, tid),
  1694. UNIQUE(vid, tid, name)
  1695. ) ENGINE=InnoDB;
  1696. INSERT INTO t1 VALUES
  1697. (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
  1698. (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
  1699. (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
  1700. (4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
  1701. (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
  1702. EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
  1703. id select_type table type possible_keys key key_len ref rows Extra
  1704. 1 SIMPLE t1 index NULL PRIMARY 12 NULL 16 Using where
  1705. SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
  1706. vid tid idx name type
  1707. 3 1 4 c_extra NULL
  1708. 3 1 3 c2 NULL
  1709. 3 1 2 c1 NULL
  1710. 3 1 1 pk NULL
  1711. DROP TABLE t1;
  1712. #
  1713. # Bug #44290: explain crashes for subquery with distinct in
  1714. # SQL_SELECT::test_quick_select
  1715. # (reproduced only with InnoDB tables)
  1716. #
  1717. CREATE TABLE t1 (c1 INT, c2 INT, c3 INT, KEY (c3), KEY (c2, c3))
  1718. ENGINE=InnoDB;
  1719. INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
  1720. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1721. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1722. 1
  1723. 1
  1724. EXPLAIN
  1725. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1726. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1727. id select_type table type possible_keys key key_len ref rows Extra
  1728. 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
  1729. 2 DERIVED t1 index_merge c3,c2 c3,c2 5,10 NULL 1 Using intersect(c3,c2); Using where; Using filesort
  1730. DROP TABLE t1;
  1731. CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
  1732. ENGINE=InnoDB;
  1733. INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
  1734. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1735. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1736. 1
  1737. 1
  1738. EXPLAIN
  1739. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1740. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1741. id select_type table type possible_keys key key_len ref rows Extra
  1742. 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
  1743. 2 DERIVED t1 index_merge c3,c2 c3,c2 9,18 NULL 1 Using intersect(c3,c2); Using where; Using filesort
  1744. DROP TABLE t1;
  1745. CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2),
  1746. KEY (c3), KEY (c2, c3))
  1747. ENGINE=InnoDB;
  1748. INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
  1749. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1750. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1751. 1
  1752. 1
  1753. EXPLAIN
  1754. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1755. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1756. id select_type table type possible_keys key key_len ref rows Extra
  1757. 1 PRIMARY <derived2> ALL NULL NULL NULL NULL 2
  1758. 2 DERIVED t1 index_merge c3,c2 c3,c2 7,14 NULL 1 Using intersect(c3,c2); Using where; Using filesort
  1759. DROP TABLE t1;
  1760. End of 5.1 tests
  1761. drop table if exists t1, t2, t3;
  1762. create table t1(a int);
  1763. insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
  1764. create table t2 (a int, b int, pk int, key(a,b), primary key(pk)) engine=innodb;
  1765. insert into t2 select @a:=A.a+10*(B.a + 10*C.a),@a, @a from t1 A, t1 B, t1 C;
  1766. this must use key 'a', not PRIMARY:
  1767. explain select a from t2 where a=b;
  1768. id select_type table type possible_keys key key_len ref rows Extra
  1769. 1 SIMPLE t2 index NULL a 10 NULL # Using where; Using index
  1770. drop table t1, t2;
  1771. SET SESSION BINLOG_FORMAT=STATEMENT;
  1772. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  1773. select @@session.sql_log_bin, @@session.binlog_format, @@session.tx_isolation;
  1774. @@session.sql_log_bin 1
  1775. @@session.binlog_format STATEMENT
  1776. @@session.tx_isolation READ-COMMITTED
  1777. CREATE TABLE t1 ( a INT ) ENGINE=InnoDB;
  1778. INSERT INTO t1 VALUES(1);
  1779. DROP TABLE t1;
  1780. DROP TABLE IF EXISTS t1;
  1781. CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
  1782. CREATE INDEX i1 on t1 (a(3));
  1783. SELECT * FROM t1 WHERE a = 'abcde';
  1784. a
  1785. DROP TABLE t1;
  1786. CREATE TABLE foo (a int, b int, c char(10),
  1787. PRIMARY KEY (c(3)),
  1788. KEY b (b)
  1789. ) engine=innodb;
  1790. CREATE TABLE foo2 (a int, b int, c char(10),
  1791. PRIMARY KEY (c),
  1792. KEY b (b)
  1793. ) engine=innodb;
  1794. CREATE TABLE bar (a int, b int, c char(10),
  1795. PRIMARY KEY (c(3)),
  1796. KEY b (b)
  1797. ) engine=myisam;
  1798. INSERT INTO foo VALUES
  1799. (1,2,'abcdefghij'), (2,3,''), (3,4,'klmnopqrst'),
  1800. (4,5,'uvwxyz'), (5,6,'meotnsyglt'), (4,5,'asfdewe');
  1801. INSERT INTO bar SELECT * FROM foo;
  1802. INSERT INTO foo2 SELECT * FROM foo;
  1803. EXPLAIN SELECT c FROM bar WHERE b>2;;
  1804. id 1
  1805. select_type SIMPLE
  1806. table bar
  1807. type ALL
  1808. possible_keys b
  1809. key NULL
  1810. key_len NULL
  1811. ref NULL
  1812. rows 6
  1813. Extra Using where
  1814. EXPLAIN SELECT c FROM foo WHERE b>2;;
  1815. id 1
  1816. select_type SIMPLE
  1817. table foo
  1818. type ALL
  1819. possible_keys b
  1820. key NULL
  1821. key_len NULL
  1822. ref NULL
  1823. rows 6
  1824. Extra Using where
  1825. EXPLAIN SELECT c FROM foo2 WHERE b>2;;
  1826. id 1
  1827. select_type SIMPLE
  1828. table foo2
  1829. type range
  1830. possible_keys b
  1831. key b
  1832. key_len 5
  1833. ref NULL
  1834. rows 3
  1835. Extra Using where; Using index
  1836. EXPLAIN SELECT c FROM bar WHERE c>2;;
  1837. id 1
  1838. select_type SIMPLE
  1839. table bar
  1840. type ALL
  1841. possible_keys PRIMARY
  1842. key NULL
  1843. key_len NULL
  1844. ref NULL
  1845. rows 6
  1846. Extra Using where
  1847. EXPLAIN SELECT c FROM foo WHERE c>2;;
  1848. id 1
  1849. select_type SIMPLE
  1850. table foo
  1851. type ALL
  1852. possible_keys PRIMARY
  1853. key NULL
  1854. key_len NULL
  1855. ref NULL
  1856. rows 6
  1857. Extra Using where
  1858. EXPLAIN SELECT c FROM foo2 WHERE c>2;;
  1859. id 1
  1860. select_type SIMPLE
  1861. table foo2
  1862. type index
  1863. possible_keys PRIMARY
  1864. key b
  1865. key_len 5
  1866. ref NULL
  1867. rows 6
  1868. Extra Using where; Using index
  1869. DROP TABLE foo, bar, foo2;
  1870. DROP TABLE IF EXISTS t1,t3,t2;
  1871. DROP FUNCTION IF EXISTS f1;
  1872. CREATE FUNCTION f1() RETURNS VARCHAR(250)
  1873. BEGIN
  1874. return 'hhhhhhh' ;
  1875. END|
  1876. CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20), c VARCHAR(20)) ENGINE=INNODB;
  1877. BEGIN WORK;
  1878. CREATE TEMPORARY TABLE t2 (a VARCHAR(20), b VARCHAR(20), c varchar(20)) ENGINE=INNODB;
  1879. CREATE TEMPORARY TABLE t3 LIKE t2;
  1880. INSERT INTO t1 VALUES ('a','b',NULL),('c','d',NULL),('e','f',NULL);
  1881. SET @stmt := CONCAT('INSERT INTO t2 SELECT tbl.a, tbl.b, f1()',' FROM t1 tbl');
  1882. PREPARE stmt1 FROM @stmt;
  1883. SET @stmt := CONCAT('INSERT INTO t3', ' SELECT * FROM t2');
  1884. PREPARE stmt3 FROM @stmt;
  1885. EXECUTE stmt1;
  1886. COMMIT;
  1887. DEALLOCATE PREPARE stmt1;
  1888. DEALLOCATE PREPARE stmt3;
  1889. DROP TABLE t1,t3,t2;
  1890. DROP FUNCTION f1;
  1891. DROP TABLE IF EXISTS t1,t2;
  1892. CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
  1893. CREATE TABLE t2 (id INT PRIMARY KEY,
  1894. t1_id INT, INDEX par_ind (t1_id),
  1895. FOREIGN KEY (t1_id) REFERENCES t1(id)) ENGINE=INNODB;
  1896. INSERT INTO t1 VALUES (1),(2);
  1897. INSERT INTO t2 VALUES (3,2);
  1898. SET AUTOCOMMIT = 0;
  1899. START TRANSACTION;
  1900. TRUNCATE TABLE t1;
  1901. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
  1902. SELECT * FROM t1;
  1903. id
  1904. 1
  1905. 2
  1906. COMMIT;
  1907. SELECT * FROM t1;
  1908. id
  1909. 1
  1910. 2
  1911. START TRANSACTION;
  1912. TRUNCATE TABLE t1;
  1913. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
  1914. SELECT * FROM t1;
  1915. id
  1916. 1
  1917. 2
  1918. ROLLBACK;
  1919. SELECT * FROM t1;
  1920. id
  1921. 1
  1922. 2
  1923. SET AUTOCOMMIT = 1;
  1924. START TRANSACTION;
  1925. SELECT * FROM t1;
  1926. id
  1927. 1
  1928. 2
  1929. COMMIT;
  1930. TRUNCATE TABLE t1;
  1931. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`))
  1932. SELECT * FROM t1;
  1933. id
  1934. 1
  1935. 2
  1936. DELETE FROM t2 WHERE id = 3;
  1937. START TRANSACTION;
  1938. SELECT * FROM t1;
  1939. id
  1940. 1
  1941. 2
  1942. TRUNCATE TABLE t1;
  1943. ROLLBACK;
  1944. SELECT * FROM t1;
  1945. id
  1946. TRUNCATE TABLE t2;
  1947. DROP TABLE t2;
  1948. DROP TABLE t1;
  1949. #
  1950. # Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
  1951. #
  1952. CREATE TABLE t1 (
  1953. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  1954. PRIMARY KEY (id)
  1955. ) ENGINE=InnoDB;
  1956. CREATE TABLE t2 (
  1957. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  1958. aid INT UNSIGNED NOT NULL,
  1959. PRIMARY KEY (id),
  1960. FOREIGN KEY (aid) REFERENCES t1 (id)
  1961. ) ENGINE=InnoDB;
  1962. CREATE TABLE t3 (
  1963. bid INT UNSIGNED NOT NULL,
  1964. FOREIGN KEY (bid) REFERENCES t2 (id)
  1965. ) ENGINE=InnoDB;
  1966. CREATE TABLE t4 (
  1967. a INT
  1968. ) ENGINE=InnoDB;
  1969. CREATE TABLE t5 (
  1970. a INT
  1971. ) ENGINE=InnoDB;
  1972. INSERT INTO t1 (id) VALUES (1);
  1973. INSERT INTO t2 (id, aid) VALUES (1, 1),(2,1),(3,1),(4,1);
  1974. INSERT INTO t3 (bid) VALUES (1);
  1975. INSERT INTO t4 VALUES (1),(2),(3),(4),(5);
  1976. INSERT INTO t5 VALUES (1);
  1977. DELETE t5 FROM t4 LEFT JOIN t5 ON t4.a= t5.a;
  1978. DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
  1979. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`))
  1980. DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
  1981. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`))
  1982. DELETE IGNORE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
  1983. DROP TABLE t3;
  1984. DROP TABLE t2;
  1985. DROP TABLE t1;
  1986. DROP TABLES t4,t5;
  1987. # Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
  1988. # Testing for any side effects of IGNORE on AFTER DELETE triggers used with
  1989. # transactional tables.
  1990. #
  1991. CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
  1992. CREATE TABLE t2 (a VARCHAR(100)) ENGINE=InnoDB;
  1993. CREATE TABLE t3 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
  1994. CREATE TABLE t4 (i INT NOT NULL PRIMARY KEY, t1i INT,
  1995. FOREIGN KEY (t1i) REFERENCES t1(i))
  1996. ENGINE=InnoDB;
  1997. CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
  1998. BEGIN
  1999. SET @b:='EXECUTED TRIGGER';
  2000. INSERT INTO t2 VALUES (@b);
  2001. SET @a:= error_happens_here;
  2002. END||
  2003. SET @b:="";
  2004. SET @a:="";
  2005. INSERT INTO t1 VALUES (1),(2),(3),(4);
  2006. INSERT INTO t3 SELECT * FROM t1;
  2007. ** An error in a trigger causes rollback of the statement.
  2008. DELETE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2009. ERROR 42S22: Unknown column 'error_happens_here' in 'field list'
  2010. SELECT @a,@b;
  2011. @a @b
  2012. EXECUTED TRIGGER
  2013. SELECT * FROM t2;
  2014. a
  2015. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2016. i i
  2017. 1 1
  2018. 2 2
  2019. 3 3
  2020. 4 4
  2021. ** Same happens with the IGNORE option
  2022. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2023. ERROR 42S22: Unknown column 'error_happens_here' in 'field list'
  2024. SELECT * FROM t2;
  2025. a
  2026. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2027. i i
  2028. 1 1
  2029. 2 2
  2030. 3 3
  2031. 4 4
  2032. **
  2033. ** The following is an attempt to demonstrate
  2034. ** error handling inside a row iteration.
  2035. **
  2036. DROP TRIGGER trg;
  2037. TRUNCATE TABLE t1;
  2038. TRUNCATE TABLE t2;
  2039. TRUNCATE TABLE t3;
  2040. INSERT INTO t1 VALUES (1),(2),(3),(4);
  2041. INSERT INTO t3 VALUES (1),(2),(3),(4);
  2042. INSERT INTO t4 VALUES (3,3),(4,4);
  2043. CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
  2044. BEGIN
  2045. SET @b:= CONCAT('EXECUTED TRIGGER FOR ROW ',CAST(OLD.i AS CHAR));
  2046. INSERT INTO t2 VALUES (@b);
  2047. END||
  2048. ** DELETE is prevented by foreign key constrains but errors are silenced.
  2049. ** The AFTER trigger isn't fired.
  2050. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2051. ** Tables are modified by best effort:
  2052. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2053. i i
  2054. 3 3
  2055. 4 4
  2056. ** The AFTER trigger was only executed on successful rows:
  2057. SELECT * FROM t2;
  2058. a
  2059. EXECUTED TRIGGER FOR ROW 1
  2060. EXECUTED TRIGGER FOR ROW 2
  2061. DROP TRIGGER trg;
  2062. **
  2063. ** Induce an error midway through an AFTER-trigger
  2064. **
  2065. TRUNCATE TABLE t4;
  2066. TRUNCATE TABLE t1;
  2067. TRUNCATE TABLE t3;
  2068. INSERT INTO t1 VALUES (1),(2),(3),(4);
  2069. INSERT INTO t3 VALUES (1),(2),(3),(4);
  2070. CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
  2071. BEGIN
  2072. SET @a:= @a+1;
  2073. IF @a > 2 THEN
  2074. INSERT INTO t4 VALUES (5,5);
  2075. END IF;
  2076. END||
  2077. SET @a:=0;
  2078. ** Errors in the trigger causes the statement to abort.
  2079. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2080. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`t1i`) REFERENCES `t1` (`i`))
  2081. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2082. i i
  2083. 1 1
  2084. 2 2
  2085. 3 3
  2086. 4 4
  2087. SELECT * FROM t4;
  2088. i t1i
  2089. DROP TRIGGER trg;
  2090. DROP TABLE t4;
  2091. DROP TABLE t1;
  2092. DROP TABLE t2;
  2093. DROP TABLE t3;
  2094. CREATE TABLE t1 (a INT, b INT, KEY (a)) ENGINE = INNODB;
  2095. CREATE TABLE t2 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
  2096. CREATE TABLE t3 (a INT, b INT KEY, KEY (a)) ENGINE = INNODB;
  2097. CREATE TABLE t4 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
  2098. INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
  2099. INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
  2100. INSERT INTO t3 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105), (6, 106);
  2101. INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
  2102. UPDATE t1, t2 SET t1.a = t1.a + 100, t2.b = t1.a + 10
  2103. WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b;
  2104. SELECT * FROM t2;
  2105. a b
  2106. 1 1
  2107. 2 12
  2108. 3 13
  2109. 4 14
  2110. 5 5
  2111. UPDATE t3, t4 SET t3.a = t3.a + 100, t4.b = t3.a + 10
  2112. WHERE t3.a BETWEEN 2 AND 4 AND t4.a = t3.b - 100;
  2113. SELECT * FROM t4;
  2114. a b
  2115. 1 1
  2116. 2 12
  2117. 3 13
  2118. 4 14
  2119. 5 5
  2120. DROP TABLE t1, t2, t3, t4;
  2121. #
  2122. # Bug#44886: SIGSEGV in test_if_skip_sort_order() -
  2123. # uninitialized variable used as subscript
  2124. #
  2125. CREATE TABLE t1 (a INT, b INT, c INT, d INT, PRIMARY KEY (b), KEY (a,c))
  2126. ENGINE=InnoDB;
  2127. INSERT INTO t1 VALUES (1,1,1,0);
  2128. CREATE TABLE t2 (a INT, b INT, e INT, KEY (e)) ENGINE=InnoDB;
  2129. INSERT INTO t2 VALUES (1,1,2);
  2130. CREATE TABLE t3 (a INT, b INT) ENGINE=MyISAM;
  2131. INSERT INTO t3 VALUES (1, 1);
  2132. SELECT * FROM t1, t2, t3
  2133. WHERE t1.a = t3.a AND (t1.b = t3.b OR t1.d) AND t2.b = t1.b AND t2.e = 2
  2134. GROUP BY t1.b;
  2135. a b c d a b e a b
  2136. 1 1 1 0 1 1 2 1 1
  2137. DROP TABLE t1, t2, t3;
  2138. #
  2139. # Bug #45828: Optimizer won't use partial primary key if another
  2140. # index can prevent filesort
  2141. #
  2142. CREATE TABLE `t1` (
  2143. c1 int NOT NULL,
  2144. c2 int NOT NULL,
  2145. c3 int NOT NULL,
  2146. PRIMARY KEY (c1,c2),
  2147. KEY (c3)
  2148. ) ENGINE=InnoDB;
  2149. INSERT INTO t1 VALUES (5,2,1246276747);
  2150. INSERT INTO t1 VALUES (2,1,1246281721);
  2151. INSERT INTO t1 VALUES (7,3,1246281756);
  2152. INSERT INTO t1 VALUES (4,2,1246282139);
  2153. INSERT INTO t1 VALUES (3,1,1246282230);
  2154. INSERT INTO t1 VALUES (1,0,1246282712);
  2155. INSERT INTO t1 VALUES (8,3,1246282765);
  2156. INSERT INTO t1 SELECT c1+10,c2+10,c3+10 FROM t1;
  2157. INSERT INTO t1 SELECT c1+100,c2+100,c3+100 from t1;
  2158. INSERT INTO t1 SELECT c1+1000,c2+1000,c3+1000 from t1;
  2159. INSERT INTO t1 SELECT c1+10000,c2+10000,c3+10000 from t1;
  2160. INSERT INTO t1 SELECT c1+100000,c2+100000,c3+100000 from t1;
  2161. INSERT INTO t1 SELECT c1+1000000,c2+1000000,c3+1000000 from t1;
  2162. SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2163. c1 c2 c3
  2164. EXPLAIN SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2165. id select_type table type possible_keys key key_len ref rows Extra
  2166. 1 SIMPLE t1 ref PRIMARY,c3 PRIMARY 4 const 1 Using where; Using filesort
  2167. EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2168. id select_type table type possible_keys key key_len ref rows Extra
  2169. 1 SIMPLE t1 ref PRIMARY PRIMARY 4 const 1 Using where; Using filesort
  2170. CREATE TABLE t2 (
  2171. c1 int NOT NULL,
  2172. c2 int NOT NULL,
  2173. c3 int NOT NULL,
  2174. KEY (c1,c2),
  2175. KEY (c3)
  2176. ) ENGINE=InnoDB;
  2177. explain SELECT * FROM t2 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2178. id select_type table type possible_keys key key_len ref rows Extra
  2179. 1 SIMPLE t2 ref c1,c3 c1 4 const 1 Using where; Using filesort
  2180. DROP TABLE t1,t2;
  2181. #
  2182. # 36259: Optimizing with ORDER BY
  2183. #
  2184. CREATE TABLE t1 (
  2185. a INT NOT NULL AUTO_INCREMENT,
  2186. b INT NOT NULL,
  2187. c INT NOT NULL,
  2188. d VARCHAR(5),
  2189. e INT NOT NULL,
  2190. PRIMARY KEY (a), KEY i2 (b,c,d)
  2191. ) ENGINE=InnoDB;
  2192. INSERT INTO t1 (b,c,d,e) VALUES (1,1,'a',1), (2,2,'b',2);
  2193. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2194. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2195. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2196. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2197. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2198. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2199. EXPLAIN SELECT * FROM t1 WHERE b=1 AND c=1 ORDER BY a;
  2200. id select_type table type possible_keys key key_len ref rows Extra
  2201. 1 SIMPLE t1 ref i2 i2 8 const,const 1 Using where; Using filesort
  2202. EXPLAIN SELECT * FROM t1 FORCE INDEX(i2) WHERE b=1 and c=1 ORDER BY a;
  2203. id select_type table type possible_keys key key_len ref rows Extra
  2204. 1 SIMPLE t1 ref i2 i2 8 const,const 1 Using where; Using filesort
  2205. EXPLAIN SELECT * FROM t1 FORCE INDEX(PRIMARY) WHERE b=1 AND c=1 ORDER BY a;
  2206. id select_type table type possible_keys key key_len ref rows Extra
  2207. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 128 Using where
  2208. DROP TABLE t1;
  2209. #
  2210. # Bug #47963: Wrong results when index is used
  2211. #
  2212. CREATE TABLE t1(
  2213. a VARCHAR(5) NOT NULL,
  2214. b VARCHAR(5) NOT NULL,
  2215. c DATETIME NOT NULL,
  2216. KEY (c)
  2217. ) ENGINE=InnoDB;
  2218. INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
  2219. SELECT * FROM t1 WHERE a = 'TEST' AND
  2220. c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
  2221. a b c
  2222. TEST TEST 2009-10-09 00:00:00
  2223. SELECT * FROM t1 WHERE a = 'TEST' AND
  2224. c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00.0';
  2225. a b c
  2226. TEST TEST 2009-10-09 00:00:00
  2227. SELECT * FROM t1 WHERE a = 'TEST' AND
  2228. c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00';
  2229. a b c
  2230. TEST TEST 2009-10-09 00:00:00
  2231. SELECT * FROM t1 WHERE a = 'TEST' AND
  2232. c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00.0';
  2233. a b c
  2234. TEST TEST 2009-10-09 00:00:00
  2235. SELECT * FROM t1 WHERE a = 'TEST' AND
  2236. c >= '2009-10-09 00:00:00.000' AND c <= '2009-10-09 00:00:00.000';
  2237. a b c
  2238. TEST TEST 2009-10-09 00:00:00
  2239. SELECT * FROM t1 WHERE a = 'TEST' AND
  2240. c >= '2009-10-09 00:00:00.00' AND c <= '2009-10-09 00:00:00.001';
  2241. a b c
  2242. TEST TEST 2009-10-09 00:00:00
  2243. SELECT * FROM t1 WHERE a = 'TEST' AND
  2244. c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
  2245. a b c
  2246. EXPLAIN SELECT * FROM t1 WHERE a = 'TEST' AND
  2247. c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
  2248. id select_type table type possible_keys key key_len ref rows Extra
  2249. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  2250. DROP TABLE t1;
  2251. #
  2252. # Bug #46175: NULL read_view and consistent read assertion
  2253. #
  2254. CREATE TABLE t1(a CHAR(13),KEY(a)) ENGINE=innodb;
  2255. CREATE TABLE t2(b DATETIME,KEY(b)) ENGINE=innodb;
  2256. INSERT INTO t1 VALUES (),();
  2257. INSERT INTO t2 VALUES (),();
  2258. CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t2
  2259. WHERE b =(SELECT a FROM t1 LIMIT 1);
  2260. CREATE PROCEDURE p1(num INT)
  2261. BEGIN
  2262. DECLARE i INT DEFAULT 0;
  2263. REPEAT
  2264. SHOW CREATE VIEW v1;
  2265. SET i:=i+1;
  2266. UNTIL i>num END REPEAT;
  2267. END|
  2268. # Should not crash
  2269. # Should not crash
  2270. DROP PROCEDURE p1;
  2271. DROP VIEW v1;
  2272. DROP TABLE t1,t2;
  2273. #
  2274. # Bug #49324: more valgrind errors in test_if_skip_sort_order
  2275. #
  2276. CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb ;
  2277. #should not cause valgrind warnings
  2278. SELECT 1 FROM t1 JOIN t1 a USING(a) GROUP BY t1.a,t1.a;
  2279. 1
  2280. DROP TABLE t1;
  2281. #
  2282. # Bug#50843: Filesort used instead of clustered index led to
  2283. # performance degradation.
  2284. #
  2285. create table t1(f1 int not null primary key, f2 int) engine=innodb;
  2286. create table t2(f1 int not null, key (f1)) engine=innodb;
  2287. insert into t1 values (1,1),(2,2),(3,3);
  2288. insert into t2 values (1),(2),(3);
  2289. explain select t1.* from t1 left join t2 using(f1) group by t1.f1;
  2290. id select_type table type possible_keys key key_len ref rows Extra
  2291. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 3
  2292. 1 SIMPLE t2 ref f1 f1 4 test.t1.f1 1 Using index
  2293. drop table t1,t2;
  2294. #
  2295. #
  2296. # Bug #39653: find_shortest_key in sql_select.cc does not consider
  2297. # clustered primary keys
  2298. #
  2299. CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT, f INT,
  2300. KEY (b,c)) ENGINE=INNODB;
  2301. INSERT INTO t1 VALUES (1,1,1,1,1,1), (2,2,2,2,2,2), (3,3,3,3,3,3),
  2302. (4,4,4,4,4,4), (5,5,5,5,5,5), (6,6,6,6,6,6),
  2303. (7,7,7,7,7,7), (8,8,8,8,8,8), (9,9,9,9,9,9),
  2304. (11,11,11,11,11,11);
  2305. EXPLAIN SELECT COUNT(*) FROM t1;
  2306. id 1
  2307. select_type SIMPLE
  2308. table t1
  2309. type index
  2310. possible_keys NULL
  2311. key PRIMARY
  2312. key_len 4
  2313. ref NULL
  2314. rows 10
  2315. Extra Using index
  2316. DROP TABLE t1;
  2317. #
  2318. # Bug #49838: DROP INDEX and ADD UNIQUE INDEX for same index may
  2319. # corrupt definition at engine
  2320. #
  2321. CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, KEY k (a,b))
  2322. ENGINE=InnoDB;
  2323. ALTER TABLE t1 DROP INDEX k, ADD UNIQUE INDEX k (a,b);
  2324. SHOW INDEXES FROM t1;;
  2325. Table t1
  2326. Non_unique 0
  2327. Key_name k
  2328. Seq_in_index 1
  2329. Column_name a
  2330. Collation A
  2331. Cardinality 0
  2332. Sub_part NULL
  2333. Packed NULL
  2334. Null
  2335. Index_type BTREE
  2336. Comment
  2337. Table t1
  2338. Non_unique 0
  2339. Key_name k
  2340. Seq_in_index 2
  2341. Column_name b
  2342. Collation A
  2343. Cardinality 0
  2344. Sub_part NULL
  2345. Packed NULL
  2346. Null
  2347. Index_type BTREE
  2348. Comment
  2349. DROP TABLE t1;
  2350. #
  2351. # Bug #47453: InnoDB incorrectly changes TIMESTAMP columns when
  2352. # JOINed during an UPDATE
  2353. #
  2354. CREATE TABLE t1 (d INT) ENGINE=InnoDB;
  2355. CREATE TABLE t2 (a INT, b INT,
  2356. c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
  2357. ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB;
  2358. set up our data elements
  2359. INSERT INTO t1 (d) VALUES (1);
  2360. INSERT INTO t2 (a,b) VALUES (1,1);
  2361. SELECT SECOND(c) INTO @bug47453 FROM t2;
  2362. SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
  2363. SECOND(c)-@bug47453
  2364. 0
  2365. UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
  2366. SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
  2367. SECOND(c)-@bug47453
  2368. 0
  2369. SELECT SLEEP(1);
  2370. SLEEP(1)
  2371. 0
  2372. UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
  2373. #should be 0
  2374. SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
  2375. SECOND(c)-@bug47453
  2376. 0
  2377. DROP TABLE t1, t2;
  2378. #
  2379. # Bug#38999 valgrind warnings for update statement in function compare_record()
  2380. #
  2381. CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
  2382. CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
  2383. INSERT INTO t1 values (1),(2),(3),(4),(5);
  2384. INSERT INTO t2 values (1);
  2385. SELECT * FROM t1 WHERE a = 2;
  2386. a
  2387. 2
  2388. UPDATE t1,t2 SET t1.a = t1.a + 100 WHERE t1.a = 1;
  2389. DROP TABLE t1,t2;
  2390. #
  2391. # Bug#54606 innodb fast alter table + pack_keys=0
  2392. # prevents adding new indexes
  2393. #
  2394. CREATE TABLE t1 (a INT, b CHAR(9), c INT, key(b))
  2395. ENGINE=InnoDB
  2396. PACK_KEYS=0;
  2397. CREATE INDEX a ON t1 (a);
  2398. CREATE INDEX c on t1 (c);
  2399. DROP TABLE t1;
  2400. CREATE TABLE t1 (
  2401. pk int NOT NULL AUTO_INCREMENT PRIMARY KEY,
  2402. a int,
  2403. b int,
  2404. INDEX idx(a))
  2405. ENGINE=INNODB;
  2406. INSERT INTO t1(a,b) VALUES
  2407. (11, 1100), (2, 200), (1, 100), (14, 1400), (5, 500),
  2408. (3, 300), (17, 1700), (4, 400), (12, 1200), (8, 800),
  2409. (6, 600), (18, 1800), (9, 900), (10, 1000), (7, 700),
  2410. (13, 1300), (15, 1500), (19, 1900), (16, 1600), (20, 2000);
  2411. INSERT INTO t1(a,b) SELECT a+20, b+2000 FROM t1;
  2412. INSERT INTO t1(a,b) SELECT a+40, b+4000 FROM t1;
  2413. INSERT INTO t1(a,b) SELECT a+80, b+8000 FROM t1;
  2414. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2415. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2416. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2417. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2418. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2419. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2420. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2421. INSERT INTO t1(a,b) SELECT a,b FROM t1;
  2422. INSERT INTO t1 VALUES (1000000, 0, 0);
  2423. SET SESSION sort_buffer_size = 1024*36;
  2424. EXPLAIN
  2425. SELECT COUNT(*) FROM
  2426. (SELECT * FROM t1 FORCE INDEX (idx,PRIMARY)
  2427. WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
  2428. id select_type table type possible_keys key key_len ref rows Extra
  2429. 1 SIMPLE t1 index_merge PRIMARY,idx idx,PRIMARY 5,4 NULL 3537 Using sort_union(idx,PRIMARY); Using where
  2430. SELECT COUNT(*) FROM
  2431. (SELECT * FROM t1 FORCE INDEX (idx,PRIMARY)
  2432. WHERE a BETWEEN 2 AND 7 OR pk=1000000) AS t;
  2433. COUNT(*)
  2434. 1537
  2435. SET SESSION sort_buffer_size = DEFAULT;
  2436. DROP TABLE t1;
  2437. End of 5.1 tests