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.

2396 lines
65 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
  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
  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. Warnings:
  683. Warning 1292 Truncated incorrect sort_buffer_size value: '8192'
  684. SELECT COUNT(*) FROM t1;
  685. COUNT(*)
  686. 3072
  687. EXPLAIN
  688. SELECT COUNT(*) FROM t1
  689. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  690. id select_type table type possible_keys key key_len ref rows Extra
  691. 1 SIMPLE t1 ALL idx_b,idx_c NULL NULL NULL # Using where
  692. SELECT COUNT(*) FROM t1
  693. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  694. COUNT(*)
  695. 3072
  696. EXPLAIN
  697. SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
  698. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  699. id select_type table type possible_keys key key_len ref rows Extra
  700. 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
  701. SELECT COUNT(*) FROM t1 FORCE INDEX(idx_b, idx_c)
  702. WHERE (c >= '2007-01-02' AND c <= '2007-01-03') OR b >= 1;
  703. COUNT(*)
  704. 3072
  705. set @@sort_buffer_size=default;
  706. DROP TABLE t1,t2;
  707. CREATE TABLE t1 (a int, b int);
  708. insert into t1 values (1,1),(1,2);
  709. CREATE TABLE t2 (primary key (a)) select * from t1;
  710. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  711. drop table if exists t2;
  712. Warnings:
  713. Note 1051 Unknown table 't2'
  714. CREATE TEMPORARY TABLE t2 (primary key (a)) select * from t1;
  715. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  716. drop table if exists t2;
  717. Warnings:
  718. Note 1051 Unknown table 't2'
  719. CREATE TABLE t2 (a int, b int, primary key (a));
  720. BEGIN;
  721. INSERT INTO t2 values(100,100);
  722. CREATE TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
  723. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  724. SELECT * from t2;
  725. a b
  726. 100 100
  727. ROLLBACK;
  728. SELECT * from t2;
  729. a b
  730. 100 100
  731. TRUNCATE table t2;
  732. INSERT INTO t2 select * from t1;
  733. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  734. SELECT * from t2;
  735. a b
  736. drop table t2;
  737. CREATE TEMPORARY TABLE t2 (a int, b int, primary key (a));
  738. BEGIN;
  739. INSERT INTO t2 values(100,100);
  740. CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
  741. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  742. SELECT * from t2;
  743. a b
  744. 100 100
  745. COMMIT;
  746. BEGIN;
  747. INSERT INTO t2 values(101,101);
  748. CREATE TEMPORARY TABLE IF NOT EXISTS t2 (primary key (a)) select * from t1;
  749. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  750. SELECT * from t2;
  751. a b
  752. 100 100
  753. 101 101
  754. ROLLBACK;
  755. SELECT * from t2;
  756. a b
  757. 100 100
  758. TRUNCATE table t2;
  759. INSERT INTO t2 select * from t1;
  760. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  761. SELECT * from t2;
  762. a b
  763. drop table t1,t2;
  764. create table t1(f1 varchar(800) binary not null, key(f1))
  765. character set utf8 collate utf8_general_ci;
  766. Warnings:
  767. Warning 1071 Specified key was too long; max key length is 767 bytes
  768. insert into t1 values('aaa');
  769. drop table t1;
  770. CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB;
  771. INSERT INTO t1 VALUES ( 1 , 1 , 1);
  772. INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1;
  773. INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1;
  774. INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1;
  775. INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1;
  776. INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1;
  777. INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1;
  778. INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1;
  779. EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b;
  780. id select_type table type possible_keys key key_len ref rows Extra
  781. 1 SIMPLE t1 index NULL b 5 NULL 128
  782. EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b;
  783. id select_type table type possible_keys key key_len ref rows Extra
  784. 1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort
  785. DROP TABLE t1;
  786. drop table if exists t1;
  787. show variables like 'innodb_rollback_on_timeout';
  788. Variable_name Value
  789. innodb_rollback_on_timeout OFF
  790. create table t1 (a int unsigned not null primary key) engine = innodb;
  791. insert into t1 values (1);
  792. commit;
  793. begin work;
  794. insert into t1 values (2);
  795. select * from t1;
  796. a
  797. 1
  798. 2
  799. begin work;
  800. insert into t1 values (5);
  801. select * from t1;
  802. a
  803. 1
  804. 5
  805. insert into t1 values (2);
  806. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  807. select * from t1;
  808. a
  809. 1
  810. 5
  811. commit;
  812. select * from t1;
  813. a
  814. 1
  815. 2
  816. commit;
  817. select * from t1;
  818. a
  819. 1
  820. 2
  821. 5
  822. drop table t1;
  823. drop table if exists t1;
  824. create table t1 (a int) engine=innodb;
  825. alter table t1 alter a set default 1;
  826. drop table t1;
  827. Bug#24918 drop table and lock / inconsistent between
  828. perm and temp tables
  829. Check transactional tables under LOCK TABLES
  830. drop table if exists t24918, t24918_tmp, t24918_trans, t24918_trans_tmp,
  831. t24918_access;
  832. create table t24918_access (id int);
  833. create table t24918 (id int) engine=myisam;
  834. create temporary table t24918_tmp (id int) engine=myisam;
  835. create table t24918_trans (id int) engine=innodb;
  836. create temporary table t24918_trans_tmp (id int) engine=innodb;
  837. lock table t24918 write, t24918_tmp write, t24918_trans write, t24918_trans_tmp write;
  838. drop table t24918;
  839. select * from t24918_access;
  840. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  841. drop table t24918_trans;
  842. select * from t24918_access;
  843. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  844. drop table t24918_trans_tmp;
  845. select * from t24918_access;
  846. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  847. drop table t24918_tmp;
  848. select * from t24918_access;
  849. ERROR HY000: Table 't24918_access' was not locked with LOCK TABLES
  850. unlock tables;
  851. drop table t24918_access;
  852. CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY bkey (b)) ENGINE=InnoDB;
  853. INSERT INTO t1 VALUES (1,2),(3,2),(2,2),(4,2),(5,2),(6,2),(7,2),(8,2);
  854. INSERT INTO t1 SELECT a + 8, 2 FROM t1;
  855. INSERT INTO t1 SELECT a + 16, 1 FROM t1;
  856. EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a;
  857. id 1
  858. select_type SIMPLE
  859. table t1
  860. type ref
  861. possible_keys bkey
  862. key bkey
  863. key_len 5
  864. ref const
  865. rows 16
  866. Extra Using where; Using index
  867. SELECT * FROM t1 WHERE b=2 ORDER BY a;
  868. a b
  869. 1 2
  870. 2 2
  871. 3 2
  872. 4 2
  873. 5 2
  874. 6 2
  875. 7 2
  876. 8 2
  877. 9 2
  878. 10 2
  879. 11 2
  880. 12 2
  881. 13 2
  882. 14 2
  883. 15 2
  884. 16 2
  885. EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
  886. id 1
  887. select_type SIMPLE
  888. table t1
  889. type range
  890. possible_keys bkey
  891. key bkey
  892. key_len 5
  893. ref NULL
  894. rows 16
  895. Extra Using where; Using index; Using filesort
  896. SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY a;
  897. a b
  898. 1 2
  899. 2 2
  900. 3 2
  901. 4 2
  902. 5 2
  903. 6 2
  904. 7 2
  905. 8 2
  906. 9 2
  907. 10 2
  908. 11 2
  909. 12 2
  910. 13 2
  911. 14 2
  912. 15 2
  913. 16 2
  914. 17 1
  915. 18 1
  916. 19 1
  917. 20 1
  918. 21 1
  919. 22 1
  920. 23 1
  921. 24 1
  922. 25 1
  923. 26 1
  924. 27 1
  925. 28 1
  926. 29 1
  927. 30 1
  928. 31 1
  929. 32 1
  930. EXPLAIN SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
  931. id 1
  932. select_type SIMPLE
  933. table t1
  934. type range
  935. possible_keys bkey
  936. key bkey
  937. key_len 5
  938. ref NULL
  939. rows 16
  940. Extra Using where; Using index
  941. SELECT * FROM t1 WHERE b BETWEEN 1 AND 2 ORDER BY b,a;
  942. a b
  943. 17 1
  944. 18 1
  945. 19 1
  946. 20 1
  947. 21 1
  948. 22 1
  949. 23 1
  950. 24 1
  951. 25 1
  952. 26 1
  953. 27 1
  954. 28 1
  955. 29 1
  956. 30 1
  957. 31 1
  958. 32 1
  959. 1 2
  960. 2 2
  961. 3 2
  962. 4 2
  963. 5 2
  964. 6 2
  965. 7 2
  966. 8 2
  967. 9 2
  968. 10 2
  969. 11 2
  970. 12 2
  971. 13 2
  972. 14 2
  973. 15 2
  974. 16 2
  975. CREATE TABLE t2 (a int, b int, c int, PRIMARY KEY (a), KEY bkey (b,c))
  976. ENGINE=InnoDB;
  977. INSERT INTO t2 VALUES (1,1,1),(3,1,1),(2,1,1),(4,1,1);
  978. INSERT INTO t2 SELECT a + 4, 1, 1 FROM t2;
  979. INSERT INTO t2 SELECT a + 8, 1, 1 FROM t2;
  980. EXPLAIN SELECT * FROM t2 WHERE b=1 ORDER BY a;
  981. id 1
  982. select_type SIMPLE
  983. table t2
  984. type ref
  985. possible_keys bkey
  986. key bkey
  987. key_len 5
  988. ref const
  989. rows 8
  990. Extra Using where; Using index; Using filesort
  991. SELECT * FROM t2 WHERE b=1 ORDER BY a;
  992. a b c
  993. 1 1 1
  994. 2 1 1
  995. 3 1 1
  996. 4 1 1
  997. 5 1 1
  998. 6 1 1
  999. 7 1 1
  1000. 8 1 1
  1001. 9 1 1
  1002. 10 1 1
  1003. 11 1 1
  1004. 12 1 1
  1005. 13 1 1
  1006. 14 1 1
  1007. 15 1 1
  1008. 16 1 1
  1009. EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
  1010. id 1
  1011. select_type SIMPLE
  1012. table t2
  1013. type ref
  1014. possible_keys bkey
  1015. key bkey
  1016. key_len 10
  1017. ref const,const
  1018. rows 8
  1019. Extra Using where; Using index
  1020. SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY a;
  1021. a b c
  1022. 1 1 1
  1023. 2 1 1
  1024. 3 1 1
  1025. 4 1 1
  1026. 5 1 1
  1027. 6 1 1
  1028. 7 1 1
  1029. 8 1 1
  1030. 9 1 1
  1031. 10 1 1
  1032. 11 1 1
  1033. 12 1 1
  1034. 13 1 1
  1035. 14 1 1
  1036. 15 1 1
  1037. 16 1 1
  1038. EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
  1039. id 1
  1040. select_type SIMPLE
  1041. table t2
  1042. type ref
  1043. possible_keys bkey
  1044. key bkey
  1045. key_len 10
  1046. ref const,const
  1047. rows 8
  1048. Extra Using where; Using index
  1049. SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY b,c,a;
  1050. a b c
  1051. 1 1 1
  1052. 2 1 1
  1053. 3 1 1
  1054. 4 1 1
  1055. 5 1 1
  1056. 6 1 1
  1057. 7 1 1
  1058. 8 1 1
  1059. 9 1 1
  1060. 10 1 1
  1061. 11 1 1
  1062. 12 1 1
  1063. 13 1 1
  1064. 14 1 1
  1065. 15 1 1
  1066. 16 1 1
  1067. EXPLAIN SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
  1068. id 1
  1069. select_type SIMPLE
  1070. table t2
  1071. type ref
  1072. possible_keys bkey
  1073. key bkey
  1074. key_len 10
  1075. ref const,const
  1076. rows 8
  1077. Extra Using where; Using index
  1078. SELECT * FROM t2 WHERE b=1 AND c=1 ORDER BY c,a;
  1079. a b c
  1080. 1 1 1
  1081. 2 1 1
  1082. 3 1 1
  1083. 4 1 1
  1084. 5 1 1
  1085. 6 1 1
  1086. 7 1 1
  1087. 8 1 1
  1088. 9 1 1
  1089. 10 1 1
  1090. 11 1 1
  1091. 12 1 1
  1092. 13 1 1
  1093. 14 1 1
  1094. 15 1 1
  1095. 16 1 1
  1096. DROP TABLE t1,t2;
  1097. CREATE TABLE t1 (a INT, PRIMARY KEY (a)) ENGINE=InnoDB;
  1098. INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8);
  1099. INSERT INTO t1 SELECT a + 8 FROM t1;
  1100. INSERT INTO t1 SELECT a + 16 FROM t1;
  1101. CREATE PROCEDURE p1 ()
  1102. BEGIN
  1103. DECLARE i INT DEFAULT 50;
  1104. DECLARE cnt INT;
  1105. START TRANSACTION;
  1106. ALTER TABLE t1 ENGINE=InnoDB;
  1107. COMMIT;
  1108. START TRANSACTION;
  1109. WHILE (i > 0) DO
  1110. SET i = i - 1;
  1111. SELECT COUNT(*) INTO cnt FROM t1 LOCK IN SHARE MODE;
  1112. END WHILE;
  1113. COMMIT;
  1114. END;|
  1115. CALL p1();
  1116. CALL p1();
  1117. CALL p1();
  1118. DROP PROCEDURE p1;
  1119. DROP TABLE t1;
  1120. create table t1(a text) engine=innodb default charset=utf8;
  1121. insert into t1 values('aaa');
  1122. alter table t1 add index(a(1024));
  1123. Warnings:
  1124. Warning 1071 Specified key was too long; max key length is 767 bytes
  1125. Warning 1071 Specified key was too long; max key length is 767 bytes
  1126. show create table t1;
  1127. Table Create Table
  1128. t1 CREATE TABLE `t1` (
  1129. `a` text,
  1130. KEY `a` (`a`(255))
  1131. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  1132. drop table t1;
  1133. CREATE TABLE t1 (
  1134. a INT,
  1135. b INT,
  1136. KEY (b)
  1137. ) ENGINE=InnoDB;
  1138. INSERT INTO t1 VALUES (1,10), (2,10), (2,20), (3,30);
  1139. START TRANSACTION;
  1140. SELECT * FROM t1 WHERE b=20 FOR UPDATE;
  1141. a b
  1142. 2 20
  1143. START TRANSACTION;
  1144. SELECT * FROM t1 WHERE b=10 ORDER BY A FOR UPDATE;
  1145. a b
  1146. 1 10
  1147. 2 10
  1148. ROLLBACK;
  1149. ROLLBACK;
  1150. DROP TABLE t1;
  1151. CREATE TABLE t1(
  1152. a INT,
  1153. b INT NOT NULL,
  1154. c INT NOT NULL,
  1155. d INT,
  1156. UNIQUE KEY (c,b)
  1157. ) engine=innodb;
  1158. INSERT INTO t1 VALUES (1,1,1,50), (1,2,3,40), (2,1,3,4);
  1159. EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d;
  1160. id select_type table type possible_keys key key_len ref rows Extra
  1161. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
  1162. SELECT c,b,d FROM t1 GROUP BY c,b,d;
  1163. c b d
  1164. 1 1 50
  1165. 3 1 4
  1166. 3 2 40
  1167. EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
  1168. id select_type table type possible_keys key key_len ref rows Extra
  1169. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3
  1170. SELECT c,b,d FROM t1 GROUP BY c,b,d ORDER BY NULL;
  1171. c b d
  1172. 1 1 50
  1173. 3 1 4
  1174. 3 2 40
  1175. EXPLAIN SELECT c,b,d FROM t1 ORDER BY c,b,d;
  1176. id select_type table type possible_keys key key_len ref rows Extra
  1177. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
  1178. SELECT c,b,d FROM t1 ORDER BY c,b,d;
  1179. c b d
  1180. 1 1 50
  1181. 3 1 4
  1182. 3 2 40
  1183. EXPLAIN SELECT c,b,d FROM t1 GROUP BY c,b;
  1184. id select_type table type possible_keys key key_len ref rows Extra
  1185. 1 SIMPLE t1 index NULL c 8 NULL 3
  1186. SELECT c,b,d FROM t1 GROUP BY c,b;
  1187. c b d
  1188. 1 1 50
  1189. 3 1 4
  1190. 3 2 40
  1191. EXPLAIN SELECT c,b FROM t1 GROUP BY c,b;
  1192. id select_type table type possible_keys key key_len ref rows Extra
  1193. 1 SIMPLE t1 index NULL c 8 NULL 3 Using index
  1194. SELECT c,b FROM t1 GROUP BY c,b;
  1195. c b
  1196. 1 1
  1197. 3 1
  1198. 3 2
  1199. DROP TABLE t1;
  1200. CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a), INDEX b (b)) ENGINE=InnoDB;
  1201. INSERT INTO t1(a,b) VALUES (1,1), (2,2), (3,2);
  1202. EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
  1203. id 1
  1204. select_type SIMPLE
  1205. table t1
  1206. type ref
  1207. possible_keys b
  1208. key b
  1209. key_len 5
  1210. ref const
  1211. rows 1
  1212. Extra Using where; Using index
  1213. SELECT * FROM t1 WHERE b=2 ORDER BY a ASC;
  1214. a b
  1215. 2 2
  1216. 3 2
  1217. EXPLAIN SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
  1218. id 1
  1219. select_type SIMPLE
  1220. table t1
  1221. type ref
  1222. possible_keys b
  1223. key b
  1224. key_len 5
  1225. ref const
  1226. rows 1
  1227. Extra Using where; Using index
  1228. SELECT * FROM t1 WHERE b=2 ORDER BY a DESC;
  1229. a b
  1230. 3 2
  1231. 2 2
  1232. EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a ASC;
  1233. id 1
  1234. select_type SIMPLE
  1235. table t1
  1236. type index
  1237. possible_keys NULL
  1238. key b
  1239. key_len 5
  1240. ref NULL
  1241. rows 3
  1242. Extra Using index
  1243. SELECT * FROM t1 ORDER BY b ASC, a ASC;
  1244. a b
  1245. 1 1
  1246. 2 2
  1247. 3 2
  1248. EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a DESC;
  1249. id 1
  1250. select_type SIMPLE
  1251. table t1
  1252. type index
  1253. possible_keys NULL
  1254. key b
  1255. key_len 5
  1256. ref NULL
  1257. rows 3
  1258. Extra Using index
  1259. SELECT * FROM t1 ORDER BY b DESC, a DESC;
  1260. a b
  1261. 3 2
  1262. 2 2
  1263. 1 1
  1264. EXPLAIN SELECT * FROM t1 ORDER BY b ASC, a DESC;
  1265. id 1
  1266. select_type SIMPLE
  1267. table t1
  1268. type index
  1269. possible_keys NULL
  1270. key b
  1271. key_len 5
  1272. ref NULL
  1273. rows 3
  1274. Extra Using index; Using filesort
  1275. SELECT * FROM t1 ORDER BY b ASC, a DESC;
  1276. a b
  1277. 1 1
  1278. 3 2
  1279. 2 2
  1280. EXPLAIN SELECT * FROM t1 ORDER BY b DESC, a ASC;
  1281. id 1
  1282. select_type SIMPLE
  1283. table t1
  1284. type index
  1285. possible_keys NULL
  1286. key b
  1287. key_len 5
  1288. ref NULL
  1289. rows 3
  1290. Extra Using index; Using filesort
  1291. SELECT * FROM t1 ORDER BY b DESC, a ASC;
  1292. a b
  1293. 2 2
  1294. 3 2
  1295. 1 1
  1296. DROP TABLE t1;
  1297. #
  1298. # Bug#27610: ALTER TABLE ROW_FORMAT=... does not rebuild the table.
  1299. #
  1300. # - prepare;
  1301. DROP TABLE IF EXISTS t1;
  1302. CREATE TABLE t1(c INT)
  1303. ENGINE = InnoDB
  1304. ROW_FORMAT = COMPACT;
  1305. # - initial check;
  1306. SELECT table_schema, table_name, row_format
  1307. FROM INFORMATION_SCHEMA.TABLES
  1308. WHERE table_schema = DATABASE() AND table_name = 't1';
  1309. table_schema table_name row_format
  1310. test t1 Compact
  1311. # - change ROW_FORMAT and check;
  1312. ALTER TABLE t1 ROW_FORMAT = REDUNDANT;
  1313. SELECT table_schema, table_name, row_format
  1314. FROM INFORMATION_SCHEMA.TABLES
  1315. WHERE table_schema = DATABASE() AND table_name = 't1';
  1316. table_schema table_name row_format
  1317. test t1 Redundant
  1318. # - that's it, cleanup.
  1319. DROP TABLE t1;
  1320. create table t1(a char(10) not null, unique key aa(a(1)),
  1321. b char(4) not null, unique key bb(b(4))) engine=innodb;
  1322. desc t1;
  1323. Field Type Null Key Default Extra
  1324. a char(10) NO UNI NULL
  1325. b char(4) NO PRI NULL
  1326. show create table t1;
  1327. Table Create Table
  1328. t1 CREATE TABLE `t1` (
  1329. `a` char(10) NOT NULL,
  1330. `b` char(4) NOT NULL,
  1331. UNIQUE KEY `bb` (`b`),
  1332. UNIQUE KEY `aa` (`a`(1))
  1333. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1334. drop table t1;
  1335. CREATE TABLE t1 (id int, type char(6), d int, INDEX idx(id,d)) ENGINE=InnoDB;
  1336. INSERT INTO t1 VALUES
  1337. (191, 'member', 1), (NULL, 'member', 3), (NULL, 'member', 4), (201, 'member', 2);
  1338. EXPLAIN SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
  1339. id select_type table type possible_keys key key_len ref rows Extra
  1340. 1 SIMPLE t1 ALL idx NULL NULL NULL 4 Using where; Using filesort
  1341. SELECT * FROM t1 WHERE id=191 OR id IS NULL ORDER BY d;
  1342. id type d
  1343. 191 member 1
  1344. NULL member 3
  1345. NULL member 4
  1346. DROP TABLE t1;
  1347. set @my_innodb_autoextend_increment=@@global.innodb_autoextend_increment;
  1348. set global innodb_autoextend_increment=8;
  1349. set global innodb_autoextend_increment=@my_innodb_autoextend_increment;
  1350. set @my_innodb_commit_concurrency=@@global.innodb_commit_concurrency;
  1351. set global innodb_commit_concurrency=0;
  1352. set global innodb_commit_concurrency=@my_innodb_commit_concurrency;
  1353. CREATE TABLE t1 (a int, b int, c int, PRIMARY KEY (a), KEY t1_b (b))
  1354. ENGINE=InnoDB;
  1355. INSERT INTO t1 (a,b,c) VALUES (1,1,1), (2,1,1), (3,1,1), (4,1,1);
  1356. INSERT INTO t1 (a,b,c) SELECT a+4,b,c FROM t1;
  1357. EXPLAIN SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
  1358. id select_type table type possible_keys key key_len ref rows Extra
  1359. 1 SIMPLE t1 index t1_b PRIMARY 4 NULL 8 Using where
  1360. SELECT a, b, c FROM t1 WHERE b = 1 ORDER BY a DESC LIMIT 5;
  1361. a b c
  1362. 8 1 1
  1363. 7 1 1
  1364. 6 1 1
  1365. 5 1 1
  1366. 4 1 1
  1367. DROP TABLE t1;
  1368. DROP TABLE IF EXISTS t1;
  1369. CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
  1370. CREATE INDEX i1 on t1 (a(3));
  1371. SELECT * FROM t1 WHERE a = 'abcde';
  1372. a
  1373. DROP TABLE t1;
  1374. #
  1375. # BUG #26288: savepoint are not deleted on comit, if the transaction
  1376. # was otherwise empty
  1377. #
  1378. BEGIN;
  1379. SAVEPOINT s1;
  1380. COMMIT;
  1381. RELEASE SAVEPOINT s1;
  1382. ERROR 42000: SAVEPOINT s1 does not exist
  1383. BEGIN;
  1384. SAVEPOINT s2;
  1385. COMMIT;
  1386. ROLLBACK TO SAVEPOINT s2;
  1387. ERROR 42000: SAVEPOINT s2 does not exist
  1388. BEGIN;
  1389. SAVEPOINT s3;
  1390. ROLLBACK;
  1391. RELEASE SAVEPOINT s3;
  1392. ERROR 42000: SAVEPOINT s3 does not exist
  1393. BEGIN;
  1394. SAVEPOINT s4;
  1395. ROLLBACK;
  1396. ROLLBACK TO SAVEPOINT s4;
  1397. ERROR 42000: SAVEPOINT s4 does not exist
  1398. 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;
  1399. SHOW CREATE TABLE t1;
  1400. Table Create Table
  1401. t1 CREATE TABLE `t1` (
  1402. `f1` int(11) NOT NULL COMMENT 'My ID#',
  1403. `f2` int(11) DEFAULT NULL,
  1404. `f3` char(10) DEFAULT 'My ID#',
  1405. PRIMARY KEY (`f1`),
  1406. KEY `f2_ref` (`f2`),
  1407. CONSTRAINT `f2_ref` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)
  1408. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1409. DROP TABLE t1;
  1410. #
  1411. # Bug #36995: valgrind error in remove_const during subquery executions
  1412. #
  1413. create table t1 (a bit(1) not null,b int) engine=myisam;
  1414. create table t2 (c int) engine=innodb;
  1415. set @save_optimizer_switch=@@optimizer_switch;
  1416. set @@optimizer_switch='partial_match_rowid_merge=off,partial_match_table_scan=off';
  1417. explain
  1418. select b from t1 where a not in (select b from t1,t2 group by a) group by a;
  1419. id select_type table type possible_keys key key_len ref rows Extra
  1420. 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  1421. 2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found
  1422. 2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1
  1423. set optimizer_switch=@save_optimizer_switch;
  1424. DROP TABLE t1,t2;
  1425. End of 5.0 tests
  1426. CREATE TABLE `t2` (
  1427. `k` int(11) NOT NULL auto_increment,
  1428. `a` int(11) default NULL,
  1429. `c` int(11) default NULL,
  1430. PRIMARY KEY (`k`),
  1431. UNIQUE KEY `idx_1` (`a`)
  1432. );
  1433. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1434. ifnull( c,
  1435. 0 ) + 1;
  1436. insert into t2 ( a ) values ( 7 ) on duplicate key update c =
  1437. ifnull( c,
  1438. 0 ) + 1;
  1439. select last_insert_id();
  1440. last_insert_id()
  1441. 2
  1442. select * from t2;
  1443. k a c
  1444. 1 6 NULL
  1445. 2 7 NULL
  1446. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1447. ifnull( c,
  1448. 0 ) + 1;
  1449. select last_insert_id();
  1450. last_insert_id()
  1451. 2
  1452. select last_insert_id(0);
  1453. last_insert_id(0)
  1454. 0
  1455. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1456. ifnull( c,
  1457. 0 ) + 1;
  1458. select last_insert_id();
  1459. last_insert_id()
  1460. 0
  1461. select * from t2;
  1462. k a c
  1463. 1 6 2
  1464. 2 7 NULL
  1465. insert ignore into t2 values (null,6,1),(10,8,1);
  1466. select last_insert_id();
  1467. last_insert_id()
  1468. 0
  1469. insert ignore into t2 values (null,6,1),(null,8,1),(null,15,1),(null,20,1);
  1470. select last_insert_id();
  1471. last_insert_id()
  1472. 11
  1473. select * from t2;
  1474. k a c
  1475. 1 6 2
  1476. 2 7 NULL
  1477. 10 8 1
  1478. 11 15 1
  1479. 12 20 1
  1480. insert into t2 ( a ) values ( 6 ) on duplicate key update c =
  1481. ifnull( c,
  1482. 0 ) + 1, k=last_insert_id(k);
  1483. select last_insert_id();
  1484. last_insert_id()
  1485. 1
  1486. select * from t2;
  1487. k a c
  1488. 1 6 3
  1489. 2 7 NULL
  1490. 10 8 1
  1491. 11 15 1
  1492. 12 20 1
  1493. drop table t2;
  1494. drop table if exists t1, t2;
  1495. create table t1 (i int);
  1496. alter table t1 modify i int default 1;
  1497. alter table t1 modify i int default 2, rename t2;
  1498. lock table t2 write;
  1499. alter table t2 modify i int default 3;
  1500. unlock tables;
  1501. lock table t2 write;
  1502. alter table t2 modify i int default 4, rename t1;
  1503. unlock tables;
  1504. drop table t1;
  1505. drop table if exists t1;
  1506. create table t1 (i int);
  1507. insert into t1 values ();
  1508. lock table t1 write;
  1509. alter table t1 modify i int default 1;
  1510. insert into t1 values ();
  1511. select * from t1;
  1512. i
  1513. NULL
  1514. 1
  1515. alter table t1 change i c char(10) default "Two";
  1516. insert into t1 values ();
  1517. select * from t1;
  1518. c
  1519. NULL
  1520. 1
  1521. Two
  1522. unlock tables;
  1523. select * from t1;
  1524. c
  1525. NULL
  1526. 1
  1527. Two
  1528. drop tables t1;
  1529. create table t1(f1 varchar(5) unique, f2 timestamp NOT NULL DEFAULT
  1530. CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP);
  1531. insert into t1(f1) values(1);
  1532. select @a:=f2 from t1;
  1533. @a:=f2
  1534. #
  1535. update t1 set f1=1;
  1536. select @b:=f2 from t1;
  1537. @b:=f2
  1538. #
  1539. select if(@a=@b,"ok","wrong");
  1540. if(@a=@b,"ok","wrong")
  1541. ok
  1542. insert into t1(f1) values (1) on duplicate key update f1="1";
  1543. select @b:=f2 from t1;
  1544. @b:=f2
  1545. #
  1546. select if(@a=@b,"ok","wrong");
  1547. if(@a=@b,"ok","wrong")
  1548. ok
  1549. insert into t1(f1) select f1 from t1 on duplicate key update f1="1";
  1550. select @b:=f2 from t1;
  1551. @b:=f2
  1552. #
  1553. select if(@a=@b,"ok","wrong");
  1554. if(@a=@b,"ok","wrong")
  1555. ok
  1556. drop table t1;
  1557. SET SESSION AUTOCOMMIT = 0;
  1558. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  1559. set binlog_format=mixed;
  1560. # Switch to connection con1
  1561. CREATE TABLE t1 (a INT PRIMARY KEY, b VARCHAR(256))
  1562. ENGINE = InnoDB;
  1563. INSERT INTO t1 VALUES (1,2);
  1564. # 1. test for locking:
  1565. BEGIN;
  1566. UPDATE t1 SET b = 12 WHERE a = 1;
  1567. affected rows: 1
  1568. info: Rows matched: 1 Changed: 1 Warnings: 0
  1569. SELECT * FROM t1;
  1570. a b
  1571. 1 12
  1572. # Switch to connection con2
  1573. UPDATE t1 SET b = 21 WHERE a = 1;
  1574. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  1575. # Switch to connection con1
  1576. SELECT * FROM t1;
  1577. a b
  1578. 1 12
  1579. ROLLBACK;
  1580. # 2. test for serialized update:
  1581. CREATE TABLE t2 (a INT);
  1582. TRUNCATE t1;
  1583. INSERT INTO t1 VALUES (1,'init');
  1584. CREATE PROCEDURE p1()
  1585. BEGIN
  1586. UPDATE t1 SET b = CONCAT(b, '+con2') WHERE a = 1;
  1587. INSERT INTO t2 VALUES ();
  1588. END|
  1589. BEGIN;
  1590. UPDATE t1 SET b = CONCAT(b, '+con1') WHERE a = 1;
  1591. affected rows: 1
  1592. info: Rows matched: 1 Changed: 1 Warnings: 0
  1593. SELECT * FROM t1;
  1594. a b
  1595. 1 init+con1
  1596. # Switch to connection con2
  1597. CALL p1;;
  1598. # Switch to connection con1
  1599. SELECT * FROM t1;
  1600. a b
  1601. 1 init+con1
  1602. COMMIT;
  1603. SELECT * FROM t1;
  1604. a b
  1605. 1 init+con1
  1606. # Switch to connection con2
  1607. SELECT * FROM t1;
  1608. a b
  1609. 1 init+con1+con2
  1610. # Switch to connection con1
  1611. # 3. test for updated key column:
  1612. TRUNCATE t1;
  1613. TRUNCATE t2;
  1614. INSERT INTO t1 VALUES (1,'init');
  1615. BEGIN;
  1616. UPDATE t1 SET a = 2, b = CONCAT(b, '+con1') WHERE a = 1;
  1617. affected rows: 1
  1618. info: Rows matched: 1 Changed: 1 Warnings: 0
  1619. SELECT * FROM t1;
  1620. a b
  1621. 2 init+con1
  1622. # Switch to connection con2
  1623. CALL p1;;
  1624. # Switch to connection con1
  1625. SELECT * FROM t1;
  1626. a b
  1627. 2 init+con1
  1628. COMMIT;
  1629. SELECT * FROM t1;
  1630. a b
  1631. 2 init+con1
  1632. # Switch to connection con2
  1633. SELECT * FROM t1;
  1634. a b
  1635. 2 init+con1
  1636. DROP PROCEDURE p1;
  1637. DROP TABLE t1, t2;
  1638. CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, PRIMARY KEY (a,b)) engine=innodb;
  1639. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1640. CONSTRAINT c2 FOREIGN KEY f2 (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
  1641. ERROR 42000: Incorrect foreign key definition for 'f2': Key reference and table reference don't match
  1642. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1643. CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a,b) ON UPDATE NO ACTION) engine=innodb;
  1644. ERROR 42000: Incorrect foreign key definition for 'c2': Key reference and table reference don't match
  1645. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1646. CONSTRAINT c1 FOREIGN KEY c2 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
  1647. CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
  1648. ALTER TABLE t2 DROP FOREIGN KEY c2;
  1649. DROP TABLE t2;
  1650. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1651. FOREIGN KEY (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
  1652. ERROR 42000: Incorrect foreign key definition for 'foreign key without name': 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. FOREIGN KEY f1 (c) REFERENCES t1 (a,k) ON UPDATE NO ACTION) engine=innodb;
  1655. ERROR 42000: Incorrect foreign key definition for 'f1': Key reference and table reference don't match
  1656. CREATE TABLE t2 (c INT NOT NULL, d INT NOT NULL, PRIMARY KEY (c,d),
  1657. CONSTRAINT c1 FOREIGN KEY f1 (c) REFERENCES t1 (a) ON DELETE NO ACTION,
  1658. CONSTRAINT c2 FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
  1659. FOREIGN KEY f3 (c) REFERENCES t1 (a) ON UPDATE NO ACTION,
  1660. FOREIGN KEY (c) REFERENCES t1 (a) ON UPDATE NO ACTION) engine=innodb;
  1661. SHOW CREATE TABLE t2;
  1662. Table Create Table
  1663. t2 CREATE TABLE `t2` (
  1664. `c` int(11) NOT NULL,
  1665. `d` int(11) NOT NULL,
  1666. PRIMARY KEY (`c`,`d`),
  1667. CONSTRAINT `c1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON DELETE NO ACTION,
  1668. CONSTRAINT `c2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
  1669. CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION,
  1670. CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION
  1671. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1672. DROP TABLE t2;
  1673. DROP TABLE t1;
  1674. create table t1 (a int auto_increment primary key) engine=innodb;
  1675. alter table t1 order by a;
  1676. Warnings:
  1677. Warning 1105 ORDER BY ignored as there is a user-defined clustered index in the table 't1'
  1678. drop table t1;
  1679. CREATE TABLE t1
  1680. (vid integer NOT NULL,
  1681. tid integer NOT NULL,
  1682. idx integer NOT NULL,
  1683. name varchar(128) NOT NULL,
  1684. type varchar(128) NULL,
  1685. PRIMARY KEY(idx, vid, tid),
  1686. UNIQUE(vid, tid, name)
  1687. ) ENGINE=InnoDB;
  1688. INSERT INTO t1 VALUES
  1689. (1,1,1,'pk',NULL),(2,1,1,'pk',NULL),(3,1,1,'pk',NULL),(4,1,1,'c1',NULL),
  1690. (5,1,1,'pk',NULL),(1,1,2,'c1',NULL),(2,1,2,'c1',NULL),(3,1,2,'c1',NULL),
  1691. (4,1,2,'c2',NULL),(5,1,2,'c1',NULL),(2,1,3,'c2',NULL),(3,1,3,'c2',NULL),
  1692. (4,1,3,'pk',NULL),(5,1,3,'c2',NULL),
  1693. (2,1,4,'c_extra',NULL),(3,1,4,'c_extra',NULL);
  1694. EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
  1695. id select_type table type possible_keys key key_len ref rows Extra
  1696. 1 SIMPLE t1 index NULL PRIMARY 12 NULL 16 Using where
  1697. SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE tid = 1 AND vid = 3 ORDER BY idx DESC;
  1698. vid tid idx name type
  1699. 3 1 4 c_extra NULL
  1700. 3 1 3 c2 NULL
  1701. 3 1 2 c1 NULL
  1702. 3 1 1 pk NULL
  1703. DROP TABLE t1;
  1704. #
  1705. # Bug #44290: explain crashes for subquery with distinct in
  1706. # SQL_SELECT::test_quick_select
  1707. # (reproduced only with InnoDB tables)
  1708. #
  1709. CREATE TABLE t1 (c1 INT, c2 INT, c3 INT, KEY (c3), KEY (c2, c3))
  1710. ENGINE=InnoDB;
  1711. INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
  1712. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1713. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1714. 1
  1715. 1
  1716. EXPLAIN
  1717. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1718. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1719. id select_type table type possible_keys key key_len ref rows Extra
  1720. 1 PRIMARY <derived2> system NULL NULL NULL NULL 1
  1721. 2 DERIVED t1 index c3,c2 c2 10 NULL 5
  1722. DROP TABLE t1;
  1723. CREATE TABLE t1 (c1 REAL, c2 REAL, c3 REAL, KEY (c3), KEY (c2, c3))
  1724. ENGINE=InnoDB;
  1725. INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
  1726. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1727. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1728. 1
  1729. 1
  1730. EXPLAIN
  1731. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1732. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1733. id select_type table type possible_keys key key_len ref rows Extra
  1734. 1 PRIMARY <derived2> system NULL NULL NULL NULL 1
  1735. 2 DERIVED t1 index c3,c2 c2 18 NULL 5
  1736. DROP TABLE t1;
  1737. CREATE TABLE t1 (c1 DECIMAL(12,2), c2 DECIMAL(12,2), c3 DECIMAL(12,2),
  1738. KEY (c3), KEY (c2, c3))
  1739. ENGINE=InnoDB;
  1740. INSERT INTO t1 VALUES (1,1,1), (1,1,1), (1,1,2), (1,1,1), (1,1,2);
  1741. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1742. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1743. 1
  1744. 1
  1745. EXPLAIN
  1746. SELECT 1 FROM (SELECT COUNT(DISTINCT c1)
  1747. FROM t1 WHERE c2 IN (1, 1) AND c3 = 2 GROUP BY c2) x;
  1748. id select_type table type possible_keys key key_len ref rows Extra
  1749. 1 PRIMARY <derived2> system NULL NULL NULL NULL 1
  1750. 2 DERIVED t1 index c3,c2 c2 14 NULL 5
  1751. DROP TABLE t1;
  1752. End of 5.1 tests
  1753. drop table if exists t1, t2, t3;
  1754. create table t1(a int);
  1755. insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
  1756. create table t2 (a int, b int, pk int, key(a,b), primary key(pk)) engine=innodb;
  1757. insert into t2 select @a:=A.a+10*(B.a + 10*C.a),@a, @a from t1 A, t1 B, t1 C;
  1758. this must use key 'a', not PRIMARY:
  1759. explain select a from t2 where a=b;
  1760. id select_type table type possible_keys key key_len ref rows Extra
  1761. 1 SIMPLE t2 index NULL a 10 NULL # Using where; Using index
  1762. drop table t1, t2;
  1763. SET SESSION BINLOG_FORMAT=STATEMENT;
  1764. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  1765. select @@session.sql_log_bin, @@session.binlog_format, @@session.tx_isolation;
  1766. @@session.sql_log_bin 1
  1767. @@session.binlog_format STATEMENT
  1768. @@session.tx_isolation READ-COMMITTED
  1769. CREATE TABLE t1 ( a INT ) ENGINE=InnoDB;
  1770. INSERT INTO t1 VALUES(1);
  1771. DROP TABLE t1;
  1772. DROP TABLE IF EXISTS t1;
  1773. CREATE TABLE t1 (a char(50)) ENGINE=InnoDB;
  1774. CREATE INDEX i1 on t1 (a(3));
  1775. SELECT * FROM t1 WHERE a = 'abcde';
  1776. a
  1777. DROP TABLE t1;
  1778. CREATE TABLE foo (a int, b int, c char(10),
  1779. PRIMARY KEY (c(3)),
  1780. KEY b (b)
  1781. ) engine=innodb;
  1782. CREATE TABLE foo2 (a int, b int, c char(10),
  1783. PRIMARY KEY (c),
  1784. KEY b (b)
  1785. ) engine=innodb;
  1786. CREATE TABLE bar (a int, b int, c char(10),
  1787. PRIMARY KEY (c(3)),
  1788. KEY b (b)
  1789. ) engine=myisam;
  1790. INSERT INTO foo VALUES
  1791. (1,2,'abcdefghij'), (2,3,''), (3,4,'klmnopqrst'),
  1792. (4,5,'uvwxyz'), (5,6,'meotnsyglt'), (4,5,'asfdewe');
  1793. INSERT INTO bar SELECT * FROM foo;
  1794. INSERT INTO foo2 SELECT * FROM foo;
  1795. EXPLAIN SELECT c FROM bar WHERE b>2;;
  1796. id 1
  1797. select_type SIMPLE
  1798. table bar
  1799. type ALL
  1800. possible_keys b
  1801. key NULL
  1802. key_len NULL
  1803. ref NULL
  1804. rows 6
  1805. Extra Using where
  1806. EXPLAIN SELECT c FROM foo WHERE b>2;;
  1807. id 1
  1808. select_type SIMPLE
  1809. table foo
  1810. type ALL
  1811. possible_keys b
  1812. key NULL
  1813. key_len NULL
  1814. ref NULL
  1815. rows 6
  1816. Extra Using where
  1817. EXPLAIN SELECT c FROM foo2 WHERE b>2;;
  1818. id 1
  1819. select_type SIMPLE
  1820. table foo2
  1821. type range
  1822. possible_keys b
  1823. key b
  1824. key_len 5
  1825. ref NULL
  1826. rows 3
  1827. Extra Using where; Using index
  1828. EXPLAIN SELECT c FROM bar WHERE c>2;;
  1829. id 1
  1830. select_type SIMPLE
  1831. table bar
  1832. type ALL
  1833. possible_keys PRIMARY
  1834. key NULL
  1835. key_len NULL
  1836. ref NULL
  1837. rows 6
  1838. Extra Using where
  1839. EXPLAIN SELECT c FROM foo WHERE c>2;;
  1840. id 1
  1841. select_type SIMPLE
  1842. table foo
  1843. type ALL
  1844. possible_keys PRIMARY
  1845. key NULL
  1846. key_len NULL
  1847. ref NULL
  1848. rows 6
  1849. Extra Using where
  1850. EXPLAIN SELECT c FROM foo2 WHERE c>2;;
  1851. id 1
  1852. select_type SIMPLE
  1853. table foo2
  1854. type index
  1855. possible_keys PRIMARY
  1856. key b
  1857. key_len 5
  1858. ref NULL
  1859. rows 6
  1860. Extra Using where; Using index
  1861. DROP TABLE foo, bar, foo2;
  1862. DROP TABLE IF EXISTS t1,t3,t2;
  1863. DROP FUNCTION IF EXISTS f1;
  1864. CREATE FUNCTION f1() RETURNS VARCHAR(250)
  1865. BEGIN
  1866. return 'hhhhhhh' ;
  1867. END|
  1868. CREATE TABLE t1 (a VARCHAR(20), b VARCHAR(20), c VARCHAR(20)) ENGINE=INNODB;
  1869. BEGIN WORK;
  1870. CREATE TEMPORARY TABLE t2 (a VARCHAR(20), b VARCHAR(20), c varchar(20)) ENGINE=INNODB;
  1871. CREATE TEMPORARY TABLE t3 LIKE t2;
  1872. INSERT INTO t1 VALUES ('a','b',NULL),('c','d',NULL),('e','f',NULL);
  1873. SET @stmt := CONCAT('INSERT INTO t2 SELECT tbl.a, tbl.b, f1()',' FROM t1 tbl');
  1874. PREPARE stmt1 FROM @stmt;
  1875. SET @stmt := CONCAT('INSERT INTO t3', ' SELECT * FROM t2');
  1876. PREPARE stmt3 FROM @stmt;
  1877. EXECUTE stmt1;
  1878. COMMIT;
  1879. DEALLOCATE PREPARE stmt1;
  1880. DEALLOCATE PREPARE stmt3;
  1881. DROP TABLE t1,t3,t2;
  1882. DROP FUNCTION f1;
  1883. DROP TABLE IF EXISTS t1,t2;
  1884. CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
  1885. CREATE TABLE t2 (id INT PRIMARY KEY,
  1886. t1_id INT, INDEX par_ind (t1_id),
  1887. FOREIGN KEY (t1_id) REFERENCES t1(id)) ENGINE=INNODB;
  1888. INSERT INTO t1 VALUES (1),(2);
  1889. INSERT INTO t2 VALUES (3,2);
  1890. SET AUTOCOMMIT = 0;
  1891. START TRANSACTION;
  1892. TRUNCATE TABLE t1;
  1893. 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`))
  1894. SELECT * FROM t1;
  1895. id
  1896. 1
  1897. 2
  1898. COMMIT;
  1899. SELECT * FROM t1;
  1900. id
  1901. 1
  1902. 2
  1903. START TRANSACTION;
  1904. TRUNCATE TABLE t1;
  1905. 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`))
  1906. SELECT * FROM t1;
  1907. id
  1908. 1
  1909. 2
  1910. ROLLBACK;
  1911. SELECT * FROM t1;
  1912. id
  1913. 1
  1914. 2
  1915. SET AUTOCOMMIT = 1;
  1916. START TRANSACTION;
  1917. SELECT * FROM t1;
  1918. id
  1919. 1
  1920. 2
  1921. COMMIT;
  1922. TRUNCATE TABLE t1;
  1923. 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`))
  1924. SELECT * FROM t1;
  1925. id
  1926. 1
  1927. 2
  1928. DELETE FROM t2 WHERE id = 3;
  1929. START TRANSACTION;
  1930. SELECT * FROM t1;
  1931. id
  1932. 1
  1933. 2
  1934. TRUNCATE TABLE t1;
  1935. ROLLBACK;
  1936. SELECT * FROM t1;
  1937. id
  1938. TRUNCATE TABLE t2;
  1939. DROP TABLE t2;
  1940. DROP TABLE t1;
  1941. #
  1942. # Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
  1943. #
  1944. CREATE TABLE t1 (
  1945. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  1946. PRIMARY KEY (id)
  1947. ) ENGINE=InnoDB;
  1948. CREATE TABLE t2 (
  1949. id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  1950. aid INT UNSIGNED NOT NULL,
  1951. PRIMARY KEY (id),
  1952. FOREIGN KEY (aid) REFERENCES t1 (id)
  1953. ) ENGINE=InnoDB;
  1954. CREATE TABLE t3 (
  1955. bid INT UNSIGNED NOT NULL,
  1956. FOREIGN KEY (bid) REFERENCES t2 (id)
  1957. ) ENGINE=InnoDB;
  1958. CREATE TABLE t4 (
  1959. a INT
  1960. ) ENGINE=InnoDB;
  1961. CREATE TABLE t5 (
  1962. a INT
  1963. ) ENGINE=InnoDB;
  1964. INSERT INTO t1 (id) VALUES (1);
  1965. INSERT INTO t2 (id, aid) VALUES (1, 1),(2,1),(3,1),(4,1);
  1966. INSERT INTO t3 (bid) VALUES (1);
  1967. INSERT INTO t4 VALUES (1),(2),(3),(4),(5);
  1968. INSERT INTO t5 VALUES (1);
  1969. DELETE t5 FROM t4 LEFT JOIN t5 ON t4.a= t5.a;
  1970. DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
  1971. 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`))
  1972. DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
  1973. 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`))
  1974. DELETE IGNORE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
  1975. DROP TABLE t3;
  1976. DROP TABLE t2;
  1977. DROP TABLE t1;
  1978. DROP TABLES t4,t5;
  1979. # Bug#40127 Multiple table DELETE IGNORE hangs on foreign key constraint violation on 5.0
  1980. # Testing for any side effects of IGNORE on AFTER DELETE triggers used with
  1981. # transactional tables.
  1982. #
  1983. CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
  1984. CREATE TABLE t2 (a VARCHAR(100)) ENGINE=InnoDB;
  1985. CREATE TABLE t3 (i INT NOT NULL PRIMARY KEY) ENGINE=InnoDB;
  1986. CREATE TABLE t4 (i INT NOT NULL PRIMARY KEY, t1i INT,
  1987. FOREIGN KEY (t1i) REFERENCES t1(i))
  1988. ENGINE=InnoDB;
  1989. CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
  1990. BEGIN
  1991. SET @b:='EXECUTED TRIGGER';
  1992. INSERT INTO t2 VALUES (@b);
  1993. SET @a:= error_happens_here;
  1994. END||
  1995. SET @b:="";
  1996. SET @a:="";
  1997. INSERT INTO t1 VALUES (1),(2),(3),(4);
  1998. INSERT INTO t3 SELECT * FROM t1;
  1999. ** An error in a trigger causes rollback of the statement.
  2000. DELETE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2001. ERROR 42S22: Unknown column 'error_happens_here' in 'field list'
  2002. SELECT @a,@b;
  2003. @a @b
  2004. EXECUTED TRIGGER
  2005. SELECT * FROM t2;
  2006. a
  2007. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2008. i i
  2009. 1 1
  2010. 2 2
  2011. 3 3
  2012. 4 4
  2013. ** Same happens with the IGNORE option
  2014. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2015. ERROR 42S22: Unknown column 'error_happens_here' in 'field list'
  2016. SELECT * FROM t2;
  2017. a
  2018. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2019. i i
  2020. 1 1
  2021. 2 2
  2022. 3 3
  2023. 4 4
  2024. **
  2025. ** The following is an attempt to demonstrate
  2026. ** error handling inside a row iteration.
  2027. **
  2028. DROP TRIGGER trg;
  2029. TRUNCATE TABLE t1;
  2030. TRUNCATE TABLE t2;
  2031. TRUNCATE TABLE t3;
  2032. INSERT INTO t1 VALUES (1),(2),(3),(4);
  2033. INSERT INTO t3 VALUES (1),(2),(3),(4);
  2034. INSERT INTO t4 VALUES (3,3),(4,4);
  2035. CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
  2036. BEGIN
  2037. SET @b:= CONCAT('EXECUTED TRIGGER FOR ROW ',CAST(OLD.i AS CHAR));
  2038. INSERT INTO t2 VALUES (@b);
  2039. END||
  2040. ** DELETE is prevented by foreign key constrains but errors are silenced.
  2041. ** The AFTER trigger isn't fired.
  2042. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2043. ** Tables are modified by best effort:
  2044. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2045. i i
  2046. 3 3
  2047. 4 4
  2048. ** The AFTER trigger was only executed on successful rows:
  2049. SELECT * FROM t2;
  2050. a
  2051. EXECUTED TRIGGER FOR ROW 1
  2052. EXECUTED TRIGGER FOR ROW 2
  2053. DROP TRIGGER trg;
  2054. **
  2055. ** Induce an error midway through an AFTER-trigger
  2056. **
  2057. TRUNCATE TABLE t4;
  2058. TRUNCATE TABLE t1;
  2059. TRUNCATE TABLE t3;
  2060. INSERT INTO t1 VALUES (1),(2),(3),(4);
  2061. INSERT INTO t3 VALUES (1),(2),(3),(4);
  2062. CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW
  2063. BEGIN
  2064. SET @a:= @a+1;
  2065. IF @a > 2 THEN
  2066. INSERT INTO t4 VALUES (5,5);
  2067. END IF;
  2068. END||
  2069. SET @a:=0;
  2070. ** Errors in the trigger causes the statement to abort.
  2071. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
  2072. 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`))
  2073. SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
  2074. i i
  2075. 1 1
  2076. 2 2
  2077. 3 3
  2078. 4 4
  2079. SELECT * FROM t4;
  2080. i t1i
  2081. DROP TRIGGER trg;
  2082. DROP TABLE t4;
  2083. DROP TABLE t1;
  2084. DROP TABLE t2;
  2085. DROP TABLE t3;
  2086. CREATE TABLE t1 (a INT, b INT, KEY (a)) ENGINE = INNODB;
  2087. CREATE TABLE t2 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
  2088. CREATE TABLE t3 (a INT, b INT KEY, KEY (a)) ENGINE = INNODB;
  2089. CREATE TABLE t4 (a INT KEY, b INT, KEY (b)) ENGINE = INNODB;
  2090. INSERT INTO t1 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6);
  2091. INSERT INTO t2 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
  2092. INSERT INTO t3 VALUES (1, 101), (2, 102), (3, 103), (4, 104), (5, 105), (6, 106);
  2093. INSERT INTO t4 VALUES (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
  2094. UPDATE t1, t2 SET t1.a = t1.a + 100, t2.b = t1.a + 10
  2095. WHERE t1.a BETWEEN 2 AND 4 AND t2.a = t1.b;
  2096. SELECT * FROM t2;
  2097. a b
  2098. 1 1
  2099. 2 12
  2100. 3 13
  2101. 4 14
  2102. 5 5
  2103. UPDATE t3, t4 SET t3.a = t3.a + 100, t4.b = t3.a + 10
  2104. WHERE t3.a BETWEEN 2 AND 4 AND t4.a = t3.b - 100;
  2105. SELECT * FROM t4;
  2106. a b
  2107. 1 1
  2108. 2 12
  2109. 3 13
  2110. 4 14
  2111. 5 5
  2112. DROP TABLE t1, t2, t3, t4;
  2113. #
  2114. # Bug#44886: SIGSEGV in test_if_skip_sort_order() -
  2115. # uninitialized variable used as subscript
  2116. #
  2117. CREATE TABLE t1 (a INT, b INT, c INT, d INT, PRIMARY KEY (b), KEY (a,c))
  2118. ENGINE=InnoDB;
  2119. INSERT INTO t1 VALUES (1,1,1,0);
  2120. CREATE TABLE t2 (a INT, b INT, e INT, KEY (e)) ENGINE=InnoDB;
  2121. INSERT INTO t2 VALUES (1,1,2);
  2122. CREATE TABLE t3 (a INT, b INT) ENGINE=MyISAM;
  2123. INSERT INTO t3 VALUES (1, 1);
  2124. SELECT * FROM t1, t2, t3
  2125. WHERE t1.a = t3.a AND (t1.b = t3.b OR t1.d) AND t2.b = t1.b AND t2.e = 2
  2126. GROUP BY t1.b;
  2127. a b c d a b e a b
  2128. 1 1 1 0 1 1 2 1 1
  2129. DROP TABLE t1, t2, t3;
  2130. #
  2131. # Bug #45828: Optimizer won't use partial primary key if another
  2132. # index can prevent filesort
  2133. #
  2134. CREATE TABLE `t1` (
  2135. c1 int NOT NULL,
  2136. c2 int NOT NULL,
  2137. c3 int NOT NULL,
  2138. PRIMARY KEY (c1,c2),
  2139. KEY (c3)
  2140. ) ENGINE=InnoDB;
  2141. INSERT INTO t1 VALUES (5,2,1246276747);
  2142. INSERT INTO t1 VALUES (2,1,1246281721);
  2143. INSERT INTO t1 VALUES (7,3,1246281756);
  2144. INSERT INTO t1 VALUES (4,2,1246282139);
  2145. INSERT INTO t1 VALUES (3,1,1246282230);
  2146. INSERT INTO t1 VALUES (1,0,1246282712);
  2147. INSERT INTO t1 VALUES (8,3,1246282765);
  2148. INSERT INTO t1 SELECT c1+10,c2+10,c3+10 FROM t1;
  2149. INSERT INTO t1 SELECT c1+100,c2+100,c3+100 from t1;
  2150. INSERT INTO t1 SELECT c1+1000,c2+1000,c3+1000 from t1;
  2151. INSERT INTO t1 SELECT c1+10000,c2+10000,c3+10000 from t1;
  2152. INSERT INTO t1 SELECT c1+100000,c2+100000,c3+100000 from t1;
  2153. INSERT INTO t1 SELECT c1+1000000,c2+1000000,c3+1000000 from t1;
  2154. SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2155. c1 c2 c3
  2156. EXPLAIN SELECT * FROM t1 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2157. id select_type table type possible_keys key key_len ref rows Extra
  2158. 1 SIMPLE t1 ref PRIMARY,c3 PRIMARY 4 const 1 Using where; Using filesort
  2159. EXPLAIN SELECT * FROM t1 FORCE INDEX (PRIMARY) WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2160. id select_type table type possible_keys key key_len ref rows Extra
  2161. 1 SIMPLE t1 ref PRIMARY PRIMARY 4 const 1 Using where; Using filesort
  2162. CREATE TABLE t2 (
  2163. c1 int NOT NULL,
  2164. c2 int NOT NULL,
  2165. c3 int NOT NULL,
  2166. KEY (c1,c2),
  2167. KEY (c3)
  2168. ) ENGINE=InnoDB;
  2169. explain SELECT * FROM t2 WHERE c1 = 99999999 AND c3 > 1 ORDER BY c3;
  2170. id select_type table type possible_keys key key_len ref rows Extra
  2171. 1 SIMPLE t2 ref c1,c3 c1 4 const 1 Using where; Using filesort
  2172. DROP TABLE t1,t2;
  2173. #
  2174. # 36259: Optimizing with ORDER BY
  2175. #
  2176. CREATE TABLE t1 (
  2177. a INT NOT NULL AUTO_INCREMENT,
  2178. b INT NOT NULL,
  2179. c INT NOT NULL,
  2180. d VARCHAR(5),
  2181. e INT NOT NULL,
  2182. PRIMARY KEY (a), KEY i2 (b,c,d)
  2183. ) ENGINE=InnoDB;
  2184. INSERT INTO t1 (b,c,d,e) VALUES (1,1,'a',1), (2,2,'b',2);
  2185. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2186. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2187. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2188. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2189. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2190. INSERT INTO t1 (b,c,d,e) SELECT RAND()*10000, RAND()*10000, d, e FROM t1;
  2191. EXPLAIN SELECT * FROM t1 WHERE b=1 AND c=1 ORDER BY a;
  2192. id select_type table type possible_keys key key_len ref rows Extra
  2193. 1 SIMPLE t1 ref i2 i2 8 const,const 1 Using where; Using filesort
  2194. EXPLAIN SELECT * FROM t1 FORCE INDEX(i2) WHERE b=1 and c=1 ORDER BY a;
  2195. id select_type table type possible_keys key key_len ref rows Extra
  2196. 1 SIMPLE t1 ref i2 i2 8 const,const 1 Using where; Using filesort
  2197. EXPLAIN SELECT * FROM t1 FORCE INDEX(PRIMARY) WHERE b=1 AND c=1 ORDER BY a;
  2198. id select_type table type possible_keys key key_len ref rows Extra
  2199. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 128 Using where
  2200. DROP TABLE t1;
  2201. #
  2202. # Bug #47963: Wrong results when index is used
  2203. #
  2204. CREATE TABLE t1(
  2205. a VARCHAR(5) NOT NULL,
  2206. b VARCHAR(5) NOT NULL,
  2207. c DATETIME NOT NULL,
  2208. KEY (c)
  2209. ) ENGINE=InnoDB;
  2210. INSERT INTO t1 VALUES('TEST', 'TEST', '2009-10-09 00:00:00');
  2211. SELECT * FROM t1 WHERE a = 'TEST' AND
  2212. c >= '2009-10-09 00:00:00' AND c <= '2009-10-09 00:00:00';
  2213. a b c
  2214. TEST TEST 2009-10-09 00:00:00
  2215. SELECT * FROM t1 WHERE a = 'TEST' AND
  2216. c >= '2009-10-09 00:00:00.0' AND c <= '2009-10-09 00:00:00.0';
  2217. a b c
  2218. TEST TEST 2009-10-09 00:00:00
  2219. SELECT * FROM t1 WHERE a = 'TEST' AND
  2220. c >= '2009-10-09 00:00:00.0' 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' 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.000' AND c <= '2009-10-09 00:00:00.000';
  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.00' AND c <= '2009-10-09 00:00:00.001';
  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.001' AND c <= '2009-10-09 00:00:00.00';
  2237. a b c
  2238. EXPLAIN SELECT * FROM t1 WHERE a = 'TEST' AND
  2239. c >= '2009-10-09 00:00:00.001' AND c <= '2009-10-09 00:00:00.00';
  2240. id select_type table type possible_keys key key_len ref rows Extra
  2241. 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
  2242. DROP TABLE t1;
  2243. #
  2244. # Bug #46175: NULL read_view and consistent read assertion
  2245. #
  2246. CREATE TABLE t1(a CHAR(13),KEY(a)) ENGINE=innodb;
  2247. CREATE TABLE t2(b DATETIME,KEY(b)) ENGINE=innodb;
  2248. INSERT INTO t1 VALUES (),();
  2249. INSERT INTO t2 VALUES (),();
  2250. CREATE OR REPLACE VIEW v1 AS SELECT 1 FROM t2
  2251. WHERE b =(SELECT a FROM t1 LIMIT 1);
  2252. CREATE PROCEDURE p1(num INT)
  2253. BEGIN
  2254. DECLARE i INT DEFAULT 0;
  2255. REPEAT
  2256. SHOW CREATE VIEW v1;
  2257. SET i:=i+1;
  2258. UNTIL i>num END REPEAT;
  2259. END|
  2260. # Should not crash
  2261. # Should not crash
  2262. DROP PROCEDURE p1;
  2263. DROP VIEW v1;
  2264. DROP TABLE t1,t2;
  2265. #
  2266. # Bug #49324: more valgrind errors in test_if_skip_sort_order
  2267. #
  2268. CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=innodb ;
  2269. #should not cause valgrind warnings
  2270. SELECT 1 FROM t1 JOIN t1 a USING(a) GROUP BY t1.a,t1.a;
  2271. 1
  2272. DROP TABLE t1;
  2273. #
  2274. # Bug#50843: Filesort used instead of clustered index led to
  2275. # performance degradation.
  2276. #
  2277. create table t1(f1 int not null primary key, f2 int) engine=innodb;
  2278. create table t2(f1 int not null, key (f1)) engine=innodb;
  2279. insert into t1 values (1,1),(2,2),(3,3);
  2280. insert into t2 values (1),(2),(3);
  2281. explain select t1.* from t1 left join t2 using(f1) group by t1.f1;
  2282. id select_type table type possible_keys key key_len ref rows Extra
  2283. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 3
  2284. 1 SIMPLE t2 ref f1 f1 4 test.t1.f1 1 Using index
  2285. drop table t1,t2;
  2286. #
  2287. #
  2288. # Bug #39653: find_shortest_key in sql_select.cc does not consider
  2289. # clustered primary keys
  2290. #
  2291. CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c INT, d INT, e INT, f INT,
  2292. KEY (b,c)) ENGINE=INNODB;
  2293. INSERT INTO t1 VALUES (1,1,1,1,1,1), (2,2,2,2,2,2), (3,3,3,3,3,3),
  2294. (4,4,4,4,4,4), (5,5,5,5,5,5), (6,6,6,6,6,6),
  2295. (7,7,7,7,7,7), (8,8,8,8,8,8), (9,9,9,9,9,9),
  2296. (11,11,11,11,11,11);
  2297. EXPLAIN SELECT COUNT(*) FROM t1;
  2298. id 1
  2299. select_type SIMPLE
  2300. table t1
  2301. type index
  2302. possible_keys NULL
  2303. key PRIMARY
  2304. key_len 4
  2305. ref NULL
  2306. rows 10
  2307. Extra Using index
  2308. DROP TABLE t1;
  2309. #
  2310. # Bug #49838: DROP INDEX and ADD UNIQUE INDEX for same index may
  2311. # corrupt definition at engine
  2312. #
  2313. CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, KEY k (a,b))
  2314. ENGINE=InnoDB;
  2315. ALTER TABLE t1 DROP INDEX k, ADD UNIQUE INDEX k (a,b);
  2316. SHOW INDEXES FROM t1;;
  2317. Table t1
  2318. Non_unique 0
  2319. Key_name k
  2320. Seq_in_index 1
  2321. Column_name a
  2322. Collation A
  2323. Cardinality 0
  2324. Sub_part NULL
  2325. Packed NULL
  2326. Null
  2327. Index_type BTREE
  2328. Comment
  2329. Table t1
  2330. Non_unique 0
  2331. Key_name k
  2332. Seq_in_index 2
  2333. Column_name b
  2334. Collation A
  2335. Cardinality 0
  2336. Sub_part NULL
  2337. Packed NULL
  2338. Null
  2339. Index_type BTREE
  2340. Comment
  2341. DROP TABLE t1;
  2342. #
  2343. # Bug #47453: InnoDB incorrectly changes TIMESTAMP columns when
  2344. # JOINed during an UPDATE
  2345. #
  2346. CREATE TABLE t1 (d INT) ENGINE=InnoDB;
  2347. CREATE TABLE t2 (a INT, b INT,
  2348. c TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
  2349. ON UPDATE CURRENT_TIMESTAMP) ENGINE=InnoDB;
  2350. set up our data elements
  2351. INSERT INTO t1 (d) VALUES (1);
  2352. INSERT INTO t2 (a,b) VALUES (1,1);
  2353. SELECT SECOND(c) INTO @bug47453 FROM t2;
  2354. SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
  2355. SECOND(c)-@bug47453
  2356. 0
  2357. UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
  2358. SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
  2359. SECOND(c)-@bug47453
  2360. 0
  2361. SELECT SLEEP(1);
  2362. SLEEP(1)
  2363. 0
  2364. UPDATE t1 JOIN t2 ON d=a SET b=1 WHERE a=1;
  2365. #should be 0
  2366. SELECT SECOND(c)-@bug47453 FROM t1 JOIN t2 ON d=a;
  2367. SECOND(c)-@bug47453
  2368. 0
  2369. DROP TABLE t1, t2;
  2370. #
  2371. # Bug#38999 valgrind warnings for update statement in function compare_record()
  2372. #
  2373. CREATE TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB;
  2374. CREATE TABLE t2 (a INT PRIMARY KEY) ENGINE=InnoDB;
  2375. INSERT INTO t1 values (1),(2),(3),(4),(5);
  2376. INSERT INTO t2 values (1);
  2377. SELECT * FROM t1 WHERE a = 2;
  2378. a
  2379. 2
  2380. UPDATE t1,t2 SET t1.a = t1.a + 100 WHERE t1.a = 1;
  2381. DROP TABLE t1,t2;
  2382. End of 5.1 tests