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.

1172 lines
33 KiB

branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense. Active transactions must not switch table or index definitions on the fly, for several reasons, including the following: * copied indexes do not carry any history or locking information; that is, rollbacks, read views, and record locking would be broken * huge potential for race conditions, inconsistent reads and writes, loss of data, and corruption Instead of trying to track down if the table was changed during a transaction, acquire appropriate locks that protect the creation and dropping of indexes. innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test that consistent reads work across dropped indexes. lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion. When inserting a record into an index, the table must be at least IX-locked. However, when an index is being created, an IS-lock on the table is sufficient. row_merge_lock_table(): Add the parameter enum lock_mode mode, which must be LOCK_X or LOCK_S. row_merge_drop_table(): Assert that n_mysql_handles_opened == 0. Unconditionally drop the table. ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate. After acquiring an X lock, assert that n_mysql_handles_opened == 1. Remove the comments about dropping tables in the background. ha_innobase::final_drop_index(): Acquire an X lock on the table. dict_table_t: Remove version_number, to_be_dropped, and prebuilts. ins_node_t: Remove table_version_number. enum lock_mode: Move the definition from lock0lock.h to lock0types.h. ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete(): Remove. row_prebuilt_t: Remove the declaration from row0types.h. row_drop_table_for_mysql_no_commit(): Always print a warning if a table was added to the background drop queue.
18 years ago
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense. Active transactions must not switch table or index definitions on the fly, for several reasons, including the following: * copied indexes do not carry any history or locking information; that is, rollbacks, read views, and record locking would be broken * huge potential for race conditions, inconsistent reads and writes, loss of data, and corruption Instead of trying to track down if the table was changed during a transaction, acquire appropriate locks that protect the creation and dropping of indexes. innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test that consistent reads work across dropped indexes. lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion. When inserting a record into an index, the table must be at least IX-locked. However, when an index is being created, an IS-lock on the table is sufficient. row_merge_lock_table(): Add the parameter enum lock_mode mode, which must be LOCK_X or LOCK_S. row_merge_drop_table(): Assert that n_mysql_handles_opened == 0. Unconditionally drop the table. ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate. After acquiring an X lock, assert that n_mysql_handles_opened == 1. Remove the comments about dropping tables in the background. ha_innobase::final_drop_index(): Acquire an X lock on the table. dict_table_t: Remove version_number, to_be_dropped, and prebuilts. ins_node_t: Remove table_version_number. enum lock_mode: Move the definition from lock0lock.h to lock0types.h. ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete(): Remove. row_prebuilt_t: Remove the declaration from row0types.h. row_drop_table_for_mysql_no_commit(): Always print a warning if a table was added to the background drop queue.
18 years ago
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense. Active transactions must not switch table or index definitions on the fly, for several reasons, including the following: * copied indexes do not carry any history or locking information; that is, rollbacks, read views, and record locking would be broken * huge potential for race conditions, inconsistent reads and writes, loss of data, and corruption Instead of trying to track down if the table was changed during a transaction, acquire appropriate locks that protect the creation and dropping of indexes. innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test that consistent reads work across dropped indexes. lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion. When inserting a record into an index, the table must be at least IX-locked. However, when an index is being created, an IS-lock on the table is sufficient. row_merge_lock_table(): Add the parameter enum lock_mode mode, which must be LOCK_X or LOCK_S. row_merge_drop_table(): Assert that n_mysql_handles_opened == 0. Unconditionally drop the table. ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate. After acquiring an X lock, assert that n_mysql_handles_opened == 1. Remove the comments about dropping tables in the background. ha_innobase::final_drop_index(): Acquire an X lock on the table. dict_table_t: Remove version_number, to_be_dropped, and prebuilts. ins_node_t: Remove table_version_number. enum lock_mode: Move the definition from lock0lock.h to lock0types.h. ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete(): Remove. row_prebuilt_t: Remove the declaration from row0types.h. row_drop_table_for_mysql_no_commit(): Always print a warning if a table was added to the background drop queue.
18 years ago
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense. Active transactions must not switch table or index definitions on the fly, for several reasons, including the following: * copied indexes do not carry any history or locking information; that is, rollbacks, read views, and record locking would be broken * huge potential for race conditions, inconsistent reads and writes, loss of data, and corruption Instead of trying to track down if the table was changed during a transaction, acquire appropriate locks that protect the creation and dropping of indexes. innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test that consistent reads work across dropped indexes. lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion. When inserting a record into an index, the table must be at least IX-locked. However, when an index is being created, an IS-lock on the table is sufficient. row_merge_lock_table(): Add the parameter enum lock_mode mode, which must be LOCK_X or LOCK_S. row_merge_drop_table(): Assert that n_mysql_handles_opened == 0. Unconditionally drop the table. ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate. After acquiring an X lock, assert that n_mysql_handles_opened == 1. Remove the comments about dropping tables in the background. ha_innobase::final_drop_index(): Acquire an X lock on the table. dict_table_t: Remove version_number, to_be_dropped, and prebuilts. ins_node_t: Remove table_version_number. enum lock_mode: Move the definition from lock0lock.h to lock0types.h. ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete(): Remove. row_prebuilt_t: Remove the declaration from row0types.h. row_drop_table_for_mysql_no_commit(): Always print a warning if a table was added to the background drop queue.
18 years ago
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense. Active transactions must not switch table or index definitions on the fly, for several reasons, including the following: * copied indexes do not carry any history or locking information; that is, rollbacks, read views, and record locking would be broken * huge potential for race conditions, inconsistent reads and writes, loss of data, and corruption Instead of trying to track down if the table was changed during a transaction, acquire appropriate locks that protect the creation and dropping of indexes. innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test that consistent reads work across dropped indexes. lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion. When inserting a record into an index, the table must be at least IX-locked. However, when an index is being created, an IS-lock on the table is sufficient. row_merge_lock_table(): Add the parameter enum lock_mode mode, which must be LOCK_X or LOCK_S. row_merge_drop_table(): Assert that n_mysql_handles_opened == 0. Unconditionally drop the table. ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate. After acquiring an X lock, assert that n_mysql_handles_opened == 1. Remove the comments about dropping tables in the background. ha_innobase::final_drop_index(): Acquire an X lock on the table. dict_table_t: Remove version_number, to_be_dropped, and prebuilts. ins_node_t: Remove table_version_number. enum lock_mode: Move the definition from lock0lock.h to lock0types.h. ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete(): Remove. row_prebuilt_t: Remove the declaration from row0types.h. row_drop_table_for_mysql_no_commit(): Always print a warning if a table was added to the background drop queue.
18 years ago
branches/zip: Fast index creation: Remove the ROW_PREBUILT_OBSOLETE nonsense. Active transactions must not switch table or index definitions on the fly, for several reasons, including the following: * copied indexes do not carry any history or locking information; that is, rollbacks, read views, and record locking would be broken * huge potential for race conditions, inconsistent reads and writes, loss of data, and corruption Instead of trying to track down if the table was changed during a transaction, acquire appropriate locks that protect the creation and dropping of indexes. innodb-index.test: Test the locking of CREATE INDEX and DROP INDEX. Test that consistent reads work across dropped indexes. lock_rec_insert_check_and_lock(): Relax the lock_table_has() assertion. When inserting a record into an index, the table must be at least IX-locked. However, when an index is being created, an IS-lock on the table is sufficient. row_merge_lock_table(): Add the parameter enum lock_mode mode, which must be LOCK_X or LOCK_S. row_merge_drop_table(): Assert that n_mysql_handles_opened == 0. Unconditionally drop the table. ha_innobase::add_index(): Acquire an X or S lock on the table, as appropriate. After acquiring an X lock, assert that n_mysql_handles_opened == 1. Remove the comments about dropping tables in the background. ha_innobase::final_drop_index(): Acquire an X lock on the table. dict_table_t: Remove version_number, to_be_dropped, and prebuilts. ins_node_t: Remove table_version_number. enum lock_mode: Move the definition from lock0lock.h to lock0types.h. ROW_PREBUILT_OBSOLETE, row_update_prebuilt(), row_prebuilt_table_obsolete(): Remove. row_prebuilt_t: Remove the declaration from row0types.h. row_drop_table_for_mysql_no_commit(): Always print a warning if a table was added to the background drop queue.
18 years ago
  1. create table t1(a int not null, b int, c char(10) not null, d varchar(20)) engine = innodb;
  2. insert into t1 values (5,5,'oo','oo'),(4,4,'tr','tr'),(3,4,'ad','ad'),(2,3,'ak','ak');
  3. commit;
  4. alter table t1 add index b (b), add index b (b);
  5. ERROR 42000: Duplicate key name 'b'
  6. alter table t1 add index (b,b);
  7. ERROR 42S21: Duplicate column name 'b'
  8. alter table t1 add index d2 (d);
  9. show create table t1;
  10. Table Create Table
  11. t1 CREATE TABLE `t1` (
  12. `a` int(11) NOT NULL,
  13. `b` int(11) DEFAULT NULL,
  14. `c` char(10) NOT NULL,
  15. `d` varchar(20) DEFAULT NULL,
  16. KEY `d2` (`d`)
  17. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  18. explain select * from t1 force index(d2) order by d;
  19. id select_type table type possible_keys key key_len ref rows Extra
  20. 1 SIMPLE t1 index NULL d2 23 NULL 4
  21. select * from t1 force index (d2) order by d;
  22. a b c d
  23. 3 4 ad ad
  24. 2 3 ak ak
  25. 5 5 oo oo
  26. 4 4 tr tr
  27. alter table t1 add unique index (b);
  28. ERROR 23000: Duplicate entry '4' for key 'b'
  29. show create table t1;
  30. Table Create Table
  31. t1 CREATE TABLE `t1` (
  32. `a` int(11) NOT NULL,
  33. `b` int(11) DEFAULT NULL,
  34. `c` char(10) NOT NULL,
  35. `d` varchar(20) DEFAULT NULL,
  36. KEY `d2` (`d`)
  37. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  38. alter table t1 add index (b);
  39. show create table t1;
  40. Table Create Table
  41. t1 CREATE TABLE `t1` (
  42. `a` int(11) NOT NULL,
  43. `b` int(11) DEFAULT NULL,
  44. `c` char(10) NOT NULL,
  45. `d` varchar(20) DEFAULT NULL,
  46. KEY `d2` (`d`),
  47. KEY `b` (`b`)
  48. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  49. CREATE TABLE `t1#1`(a INT PRIMARY KEY) ENGINE=InnoDB;
  50. alter table t1 add unique index (c), add index (d);
  51. ERROR HY000: Table 'test.t1#1' already exists
  52. rename table `t1#1` to `t1#2`;
  53. alter table t1 add unique index (c), add index (d);
  54. ERROR HY000: Table 'test.t1#2' already exists
  55. drop table `t1#2`;
  56. alter table t1 add unique index (c), add index (d);
  57. show create table t1;
  58. Table Create Table
  59. t1 CREATE TABLE `t1` (
  60. `a` int(11) NOT NULL,
  61. `b` int(11) DEFAULT NULL,
  62. `c` char(10) NOT NULL,
  63. `d` varchar(20) DEFAULT NULL,
  64. UNIQUE KEY `c` (`c`),
  65. KEY `d2` (`d`),
  66. KEY `b` (`b`),
  67. KEY `d` (`d`)
  68. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  69. explain select * from t1 force index(c) order by c;
  70. id select_type table type possible_keys key key_len ref rows Extra
  71. 1 SIMPLE t1 index NULL c 10 NULL 4
  72. alter table t1 add primary key (a), drop index c;
  73. show create table t1;
  74. Table Create Table
  75. t1 CREATE TABLE `t1` (
  76. `a` int(11) NOT NULL,
  77. `b` int(11) DEFAULT NULL,
  78. `c` char(10) NOT NULL,
  79. `d` varchar(20) DEFAULT NULL,
  80. PRIMARY KEY (`a`),
  81. KEY `d2` (`d`),
  82. KEY `b` (`b`),
  83. KEY `d` (`d`)
  84. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  85. alter table t1 add primary key (c);
  86. ERROR 42000: Multiple primary key defined
  87. alter table t1 drop primary key, add primary key (b);
  88. ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
  89. create unique index c on t1 (c);
  90. show create table t1;
  91. Table Create Table
  92. t1 CREATE TABLE `t1` (
  93. `a` int(11) NOT NULL,
  94. `b` int(11) DEFAULT NULL,
  95. `c` char(10) NOT NULL,
  96. `d` varchar(20) DEFAULT NULL,
  97. PRIMARY KEY (`a`),
  98. UNIQUE KEY `c` (`c`),
  99. KEY `d2` (`d`),
  100. KEY `b` (`b`),
  101. KEY `d` (`d`)
  102. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  103. explain select * from t1 force index(c) order by c;
  104. id select_type table type possible_keys key key_len ref rows Extra
  105. 1 SIMPLE t1 index NULL c 10 NULL 4
  106. select * from t1 force index(c) order by c;
  107. a b c d
  108. 3 4 ad ad
  109. 2 3 ak ak
  110. 5 5 oo oo
  111. 4 4 tr tr
  112. alter table t1 drop index b, add index (b);
  113. show create table t1;
  114. Table Create Table
  115. t1 CREATE TABLE `t1` (
  116. `a` int(11) NOT NULL,
  117. `b` int(11) DEFAULT NULL,
  118. `c` char(10) NOT NULL,
  119. `d` varchar(20) DEFAULT NULL,
  120. PRIMARY KEY (`a`),
  121. UNIQUE KEY `c` (`c`),
  122. KEY `d2` (`d`),
  123. KEY `d` (`d`),
  124. KEY `b` (`b`)
  125. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  126. insert into t1 values(6,1,'ggg','ggg');
  127. select * from t1;
  128. a b c d
  129. 2 3 ak ak
  130. 3 4 ad ad
  131. 4 4 tr tr
  132. 5 5 oo oo
  133. 6 1 ggg ggg
  134. select * from t1 force index(b) order by b;
  135. a b c d
  136. 6 1 ggg ggg
  137. 2 3 ak ak
  138. 3 4 ad ad
  139. 4 4 tr tr
  140. 5 5 oo oo
  141. select * from t1 force index(c) order by c;
  142. a b c d
  143. 3 4 ad ad
  144. 2 3 ak ak
  145. 6 1 ggg ggg
  146. 5 5 oo oo
  147. 4 4 tr tr
  148. select * from t1 force index(d) order by d;
  149. a b c d
  150. 3 4 ad ad
  151. 2 3 ak ak
  152. 6 1 ggg ggg
  153. 5 5 oo oo
  154. 4 4 tr tr
  155. explain select * from t1 force index(b) order by b;
  156. id select_type table type possible_keys key key_len ref rows Extra
  157. 1 SIMPLE t1 index NULL b 5 NULL 5
  158. explain select * from t1 force index(c) order by c;
  159. id select_type table type possible_keys key key_len ref rows Extra
  160. 1 SIMPLE t1 index NULL c 10 NULL 5
  161. explain select * from t1 force index(d) order by d;
  162. id select_type table type possible_keys key key_len ref rows Extra
  163. 1 SIMPLE t1 index NULL d 23 NULL 5
  164. show create table t1;
  165. Table Create Table
  166. t1 CREATE TABLE `t1` (
  167. `a` int(11) NOT NULL,
  168. `b` int(11) DEFAULT NULL,
  169. `c` char(10) NOT NULL,
  170. `d` varchar(20) DEFAULT NULL,
  171. PRIMARY KEY (`a`),
  172. UNIQUE KEY `c` (`c`),
  173. KEY `d2` (`d`),
  174. KEY `d` (`d`),
  175. KEY `b` (`b`)
  176. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  177. drop table t1;
  178. create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
  179. insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ad','ad'),(4,4,'afe','afe');
  180. commit;
  181. alter table t1 add index (c(2));
  182. show create table t1;
  183. Table Create Table
  184. t1 CREATE TABLE `t1` (
  185. `a` int(11) NOT NULL,
  186. `b` int(11) DEFAULT NULL,
  187. `c` char(10) DEFAULT NULL,
  188. `d` varchar(20) DEFAULT NULL,
  189. PRIMARY KEY (`a`),
  190. KEY `c` (`c`(2))
  191. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  192. alter table t1 add unique index (d(10));
  193. show create table t1;
  194. Table Create Table
  195. t1 CREATE TABLE `t1` (
  196. `a` int(11) NOT NULL,
  197. `b` int(11) DEFAULT NULL,
  198. `c` char(10) DEFAULT NULL,
  199. `d` varchar(20) DEFAULT NULL,
  200. PRIMARY KEY (`a`),
  201. UNIQUE KEY `d` (`d`(10)),
  202. KEY `c` (`c`(2))
  203. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  204. insert into t1 values(5,1,'ggg','ggg');
  205. select * from t1;
  206. a b c d
  207. 1 1 ab ab
  208. 2 2 ac ac
  209. 3 3 ad ad
  210. 4 4 afe afe
  211. 5 1 ggg ggg
  212. select * from t1 force index(c) order by c;
  213. a b c d
  214. 1 1 ab ab
  215. 2 2 ac ac
  216. 3 3 ad ad
  217. 4 4 afe afe
  218. 5 1 ggg ggg
  219. select * from t1 force index(d) order by d;
  220. a b c d
  221. 1 1 ab ab
  222. 2 2 ac ac
  223. 3 3 ad ad
  224. 4 4 afe afe
  225. 5 1 ggg ggg
  226. explain select * from t1 order by b;
  227. id select_type table type possible_keys key key_len ref rows Extra
  228. 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using filesort
  229. explain select * from t1 force index(c) order by c;
  230. id select_type table type possible_keys key key_len ref rows Extra
  231. 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using filesort
  232. explain select * from t1 force index(d) order by d;
  233. id select_type table type possible_keys key key_len ref rows Extra
  234. 1 SIMPLE t1 ALL NULL NULL NULL NULL 5 Using filesort
  235. show create table t1;
  236. Table Create Table
  237. t1 CREATE TABLE `t1` (
  238. `a` int(11) NOT NULL,
  239. `b` int(11) DEFAULT NULL,
  240. `c` char(10) DEFAULT NULL,
  241. `d` varchar(20) DEFAULT NULL,
  242. PRIMARY KEY (`a`),
  243. UNIQUE KEY `d` (`d`(10)),
  244. KEY `c` (`c`(2))
  245. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  246. alter table t1 drop index d;
  247. insert into t1 values(8,9,'fff','fff');
  248. select * from t1;
  249. a b c d
  250. 1 1 ab ab
  251. 2 2 ac ac
  252. 3 3 ad ad
  253. 4 4 afe afe
  254. 5 1 ggg ggg
  255. 8 9 fff fff
  256. select * from t1 force index(c) order by c;
  257. a b c d
  258. 1 1 ab ab
  259. 2 2 ac ac
  260. 3 3 ad ad
  261. 4 4 afe afe
  262. 8 9 fff fff
  263. 5 1 ggg ggg
  264. explain select * from t1 order by b;
  265. id select_type table type possible_keys key key_len ref rows Extra
  266. 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using filesort
  267. explain select * from t1 force index(c) order by c;
  268. id select_type table type possible_keys key key_len ref rows Extra
  269. 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using filesort
  270. explain select * from t1 order by d;
  271. id select_type table type possible_keys key key_len ref rows Extra
  272. 1 SIMPLE t1 ALL NULL NULL NULL NULL 6 Using filesort
  273. show create table t1;
  274. Table Create Table
  275. t1 CREATE TABLE `t1` (
  276. `a` int(11) NOT NULL,
  277. `b` int(11) DEFAULT NULL,
  278. `c` char(10) DEFAULT NULL,
  279. `d` varchar(20) DEFAULT NULL,
  280. PRIMARY KEY (`a`),
  281. KEY `c` (`c`(2))
  282. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  283. drop table t1;
  284. create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
  285. insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe');
  286. commit;
  287. alter table t1 add unique index (b,c);
  288. insert into t1 values(8,9,'fff','fff');
  289. select * from t1;
  290. a b c d
  291. 1 1 ab ab
  292. 2 2 ac ac
  293. 3 2 ad ad
  294. 4 4 afe afe
  295. 8 9 fff fff
  296. select * from t1 force index(b) order by b;
  297. a b c d
  298. 1 1 ab ab
  299. 2 2 ac ac
  300. 3 2 ad ad
  301. 4 4 afe afe
  302. 8 9 fff fff
  303. explain select * from t1 force index(b) order by b;
  304. id select_type table type possible_keys key key_len ref rows Extra
  305. 1 SIMPLE t1 index NULL b 16 NULL 5
  306. show create table t1;
  307. Table Create Table
  308. t1 CREATE TABLE `t1` (
  309. `a` int(11) NOT NULL,
  310. `b` int(11) DEFAULT NULL,
  311. `c` char(10) DEFAULT NULL,
  312. `d` varchar(20) DEFAULT NULL,
  313. PRIMARY KEY (`a`),
  314. UNIQUE KEY `b` (`b`,`c`)
  315. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  316. alter table t1 add index (b,c);
  317. insert into t1 values(11,11,'kkk','kkk');
  318. select * from t1;
  319. a b c d
  320. 1 1 ab ab
  321. 2 2 ac ac
  322. 3 2 ad ad
  323. 4 4 afe afe
  324. 8 9 fff fff
  325. 11 11 kkk kkk
  326. select * from t1 force index(b) order by b;
  327. a b c d
  328. 1 1 ab ab
  329. 2 2 ac ac
  330. 3 2 ad ad
  331. 4 4 afe afe
  332. 8 9 fff fff
  333. 11 11 kkk kkk
  334. explain select * from t1 force index(b) order by b;
  335. id select_type table type possible_keys key key_len ref rows Extra
  336. 1 SIMPLE t1 index NULL b 16 NULL 6
  337. show create table t1;
  338. Table Create Table
  339. t1 CREATE TABLE `t1` (
  340. `a` int(11) NOT NULL,
  341. `b` int(11) DEFAULT NULL,
  342. `c` char(10) DEFAULT NULL,
  343. `d` varchar(20) DEFAULT NULL,
  344. PRIMARY KEY (`a`),
  345. UNIQUE KEY `b` (`b`,`c`),
  346. KEY `b_2` (`b`,`c`)
  347. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  348. alter table t1 add unique index (c,d);
  349. insert into t1 values(13,13,'yyy','aaa');
  350. select * from t1;
  351. a b c d
  352. 1 1 ab ab
  353. 2 2 ac ac
  354. 3 2 ad ad
  355. 4 4 afe afe
  356. 8 9 fff fff
  357. 11 11 kkk kkk
  358. 13 13 yyy aaa
  359. select * from t1 force index(b) order by b;
  360. a b c d
  361. 1 1 ab ab
  362. 2 2 ac ac
  363. 3 2 ad ad
  364. 4 4 afe afe
  365. 8 9 fff fff
  366. 11 11 kkk kkk
  367. 13 13 yyy aaa
  368. select * from t1 force index(c) order by c;
  369. a b c d
  370. 1 1 ab ab
  371. 2 2 ac ac
  372. 3 2 ad ad
  373. 4 4 afe afe
  374. 8 9 fff fff
  375. 11 11 kkk kkk
  376. 13 13 yyy aaa
  377. explain select * from t1 force index(b) order by b;
  378. id select_type table type possible_keys key key_len ref rows Extra
  379. 1 SIMPLE t1 index NULL b 16 NULL 7
  380. explain select * from t1 force index(c) order by c;
  381. id select_type table type possible_keys key key_len ref rows Extra
  382. 1 SIMPLE t1 index NULL c 34 NULL 7
  383. show create table t1;
  384. Table Create Table
  385. t1 CREATE TABLE `t1` (
  386. `a` int(11) NOT NULL,
  387. `b` int(11) DEFAULT NULL,
  388. `c` char(10) DEFAULT NULL,
  389. `d` varchar(20) DEFAULT NULL,
  390. PRIMARY KEY (`a`),
  391. UNIQUE KEY `b` (`b`,`c`),
  392. UNIQUE KEY `c` (`c`,`d`),
  393. KEY `b_2` (`b`,`c`)
  394. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  395. drop table t1;
  396. create table t1(a int not null, b int not null, c int, primary key (a), key (b)) engine = innodb;
  397. create table t3(a int not null, c int not null, d int, primary key (a), key (c)) engine = innodb;
  398. create table t4(a int not null, d int not null, e int, primary key (a), key (d)) engine = innodb;
  399. create table t2(a int not null, b int not null, c int not null, d int not null, e int,
  400. foreign key (b) references t1(b) on delete cascade,
  401. foreign key (c) references t3(c), foreign key (d) references t4(d))
  402. engine = innodb;
  403. alter table t1 drop index b;
  404. ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
  405. alter table t3 drop index c;
  406. ERROR HY000: Cannot drop index 'c': needed in a foreign key constraint
  407. alter table t4 drop index d;
  408. ERROR HY000: Cannot drop index 'd': needed in a foreign key constraint
  409. alter table t2 drop index b;
  410. ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
  411. alter table t2 drop index b, drop index c, drop index d;
  412. ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
  413. create unique index dc on t2 (d,c);
  414. create index dc on t1 (b,c);
  415. alter table t2 add primary key (a);
  416. insert into t1 values (1,1,1);
  417. insert into t3 values (1,1,1);
  418. insert into t4 values (1,1,1);
  419. insert into t2 values (1,1,1,1,1);
  420. commit;
  421. alter table t4 add constraint dc foreign key (a) references t1(a);
  422. show create table t4;
  423. Table Create Table
  424. t4 CREATE TABLE `t4` (
  425. `a` int(11) NOT NULL,
  426. `d` int(11) NOT NULL,
  427. `e` int(11) DEFAULT NULL,
  428. PRIMARY KEY (`a`),
  429. KEY `d` (`d`),
  430. CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
  431. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  432. alter table t3 add constraint dc foreign key (a) references t1(a);
  433. ERROR HY000: Can't create table '#sql-temporary' (errno: 121)
  434. show create table t3;
  435. Table Create Table
  436. t3 CREATE TABLE `t3` (
  437. `a` int(11) NOT NULL,
  438. `c` int(11) NOT NULL,
  439. `d` int(11) DEFAULT NULL,
  440. PRIMARY KEY (`a`),
  441. KEY `c` (`c`)
  442. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  443. alter table t2 drop index b, add index (b);
  444. ERROR 42000: Incorrect index name 'b'
  445. show create table t2;
  446. Table Create Table
  447. t2 CREATE TABLE `t2` (
  448. `a` int(11) NOT NULL,
  449. `b` int(11) NOT NULL,
  450. `c` int(11) NOT NULL,
  451. `d` int(11) NOT NULL,
  452. `e` int(11) DEFAULT NULL,
  453. PRIMARY KEY (`a`),
  454. UNIQUE KEY `dc` (`d`,`c`),
  455. KEY `b` (`b`),
  456. KEY `c` (`c`),
  457. CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`) ON DELETE CASCADE,
  458. CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t3` (`c`),
  459. CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`d`) REFERENCES `t4` (`d`)
  460. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  461. delete from t1;
  462. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
  463. drop index dc on t4;
  464. ERROR 42000: Can't DROP 'dc'; check that column/key exists
  465. alter table t3 drop foreign key dc;
  466. ERROR HY000: Error on rename of './test/t3' to '#sql2-temporary' (errno: 152)
  467. alter table t4 drop foreign key dc;
  468. select * from t2;
  469. a b c d e
  470. 1 1 1 1 1
  471. delete from t1;
  472. select * from t2;
  473. a b c d e
  474. drop table t2,t4,t3,t1;
  475. create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb default charset=utf8;
  476. insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,2,'ad','ad'),(4,4,'afe','afe');
  477. commit;
  478. alter table t1 add unique index (b);
  479. ERROR 23000: Duplicate entry '2' for key 'b'
  480. insert into t1 values(8,9,'fff','fff');
  481. select * from t1;
  482. a b c d
  483. 1 1 ab ab
  484. 2 2 ac ac
  485. 3 2 ad ad
  486. 4 4 afe afe
  487. 8 9 fff fff
  488. show create table t1;
  489. Table Create Table
  490. t1 CREATE TABLE `t1` (
  491. `a` int(11) NOT NULL,
  492. `b` int(11) DEFAULT NULL,
  493. `c` char(10) DEFAULT NULL,
  494. `d` varchar(20) DEFAULT NULL,
  495. PRIMARY KEY (`a`)
  496. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  497. alter table t1 add index (b);
  498. insert into t1 values(10,10,'kkk','iii');
  499. select * from t1;
  500. a b c d
  501. 1 1 ab ab
  502. 2 2 ac ac
  503. 3 2 ad ad
  504. 4 4 afe afe
  505. 8 9 fff fff
  506. 10 10 kkk iii
  507. select * from t1 force index(b) order by b;
  508. a b c d
  509. 1 1 ab ab
  510. 2 2 ac ac
  511. 3 2 ad ad
  512. 4 4 afe afe
  513. 8 9 fff fff
  514. 10 10 kkk iii
  515. explain select * from t1 force index(b) order by b;
  516. id select_type table type possible_keys key key_len ref rows Extra
  517. 1 SIMPLE t1 index NULL b 5 NULL 6
  518. show create table t1;
  519. Table Create Table
  520. t1 CREATE TABLE `t1` (
  521. `a` int(11) NOT NULL,
  522. `b` int(11) DEFAULT NULL,
  523. `c` char(10) DEFAULT NULL,
  524. `d` varchar(20) DEFAULT NULL,
  525. PRIMARY KEY (`a`),
  526. KEY `b` (`b`)
  527. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  528. alter table t1 add unique index (c), add index (d);
  529. insert into t1 values(11,11,'aaa','mmm');
  530. select * from t1;
  531. a b c d
  532. 1 1 ab ab
  533. 2 2 ac ac
  534. 3 2 ad ad
  535. 4 4 afe afe
  536. 8 9 fff fff
  537. 10 10 kkk iii
  538. 11 11 aaa mmm
  539. select * from t1 force index(b) order by b;
  540. a b c d
  541. 1 1 ab ab
  542. 2 2 ac ac
  543. 3 2 ad ad
  544. 4 4 afe afe
  545. 8 9 fff fff
  546. 10 10 kkk iii
  547. 11 11 aaa mmm
  548. select * from t1 force index(c) order by c;
  549. a b c d
  550. 11 11 aaa mmm
  551. 1 1 ab ab
  552. 2 2 ac ac
  553. 3 2 ad ad
  554. 4 4 afe afe
  555. 8 9 fff fff
  556. 10 10 kkk iii
  557. select * from t1 force index(d) order by d;
  558. a b c d
  559. 1 1 ab ab
  560. 2 2 ac ac
  561. 3 2 ad ad
  562. 4 4 afe afe
  563. 8 9 fff fff
  564. 10 10 kkk iii
  565. 11 11 aaa mmm
  566. explain select * from t1 force index(b) order by b;
  567. id select_type table type possible_keys key key_len ref rows Extra
  568. 1 SIMPLE t1 index NULL b 5 NULL 7
  569. explain select * from t1 force index(c) order by c;
  570. id select_type table type possible_keys key key_len ref rows Extra
  571. 1 SIMPLE t1 index NULL c 31 NULL 7
  572. explain select * from t1 force index(d) order by d;
  573. id select_type table type possible_keys key key_len ref rows Extra
  574. 1 SIMPLE t1 index NULL d 63 NULL 7
  575. show create table t1;
  576. Table Create Table
  577. t1 CREATE TABLE `t1` (
  578. `a` int(11) NOT NULL,
  579. `b` int(11) DEFAULT NULL,
  580. `c` char(10) DEFAULT NULL,
  581. `d` varchar(20) DEFAULT NULL,
  582. PRIMARY KEY (`a`),
  583. UNIQUE KEY `c` (`c`),
  584. KEY `b` (`b`),
  585. KEY `d` (`d`)
  586. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  587. check table t1;
  588. Table Op Msg_type Msg_text
  589. test.t1 check status OK
  590. drop table t1;
  591. create table t1(a int not null, b int) engine = innodb;
  592. insert into t1 values (1,1),(1,1),(1,1),(1,1);
  593. alter table t1 add unique index (a);
  594. ERROR 23000: Duplicate entry '1' for key 'a'
  595. alter table t1 add unique index (b);
  596. ERROR 23000: Duplicate entry '1' for key 'b'
  597. alter table t1 add unique index (a), add unique index(b);
  598. ERROR 23000: Duplicate entry '1' for key 'a'
  599. show create table t1;
  600. Table Create Table
  601. t1 CREATE TABLE `t1` (
  602. `a` int(11) NOT NULL,
  603. `b` int(11) DEFAULT NULL
  604. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  605. drop table t1;
  606. create table t1(a int not null, c int not null,b int, primary key(a), unique key(c), key(b)) engine = innodb;
  607. alter table t1 drop index c, drop index b;
  608. show create table t1;
  609. Table Create Table
  610. t1 CREATE TABLE `t1` (
  611. `a` int(11) NOT NULL,
  612. `c` int(11) NOT NULL,
  613. `b` int(11) DEFAULT NULL,
  614. PRIMARY KEY (`a`)
  615. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  616. drop table t1;
  617. create table t1(a int not null, b int, primary key(a)) engine = innodb;
  618. alter table t1 add index (b);
  619. show create table t1;
  620. Table Create Table
  621. t1 CREATE TABLE `t1` (
  622. `a` int(11) NOT NULL,
  623. `b` int(11) DEFAULT NULL,
  624. PRIMARY KEY (`a`),
  625. KEY `b` (`b`)
  626. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  627. drop table t1;
  628. create table t1(a int not null, b int, c char(10), d varchar(20), primary key (a)) engine = innodb;
  629. insert into t1 values (1,1,'ab','ab'),(2,2,'ac','ac'),(3,3,'ac','ac'),(4,4,'afe','afe'),(5,4,'affe','affe');
  630. alter table t1 add unique index (b), add unique index (c), add unique index (d);
  631. ERROR 23000: Duplicate entry '4' for key 'b'
  632. alter table t1 add unique index (c), add unique index (b), add index (d);
  633. ERROR 23000: Duplicate entry 'ac' for key 'c'
  634. show create table t1;
  635. Table Create Table
  636. t1 CREATE TABLE `t1` (
  637. `a` int(11) NOT NULL,
  638. `b` int(11) DEFAULT NULL,
  639. `c` char(10) DEFAULT NULL,
  640. `d` varchar(20) DEFAULT NULL,
  641. PRIMARY KEY (`a`)
  642. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  643. drop table t1;
  644. create table t1(a int not null, b int not null, c int, primary key (a), key(c)) engine=innodb;
  645. insert into t1 values (5,1,5),(4,2,4),(3,3,3),(2,4,2),(1,5,1);
  646. alter table t1 add unique index (b);
  647. insert into t1 values (10,20,20),(11,19,19),(12,18,18),(13,17,17);
  648. show create table t1;
  649. Table Create Table
  650. t1 CREATE TABLE `t1` (
  651. `a` int(11) NOT NULL,
  652. `b` int(11) NOT NULL,
  653. `c` int(11) DEFAULT NULL,
  654. PRIMARY KEY (`a`),
  655. UNIQUE KEY `b` (`b`),
  656. KEY `c` (`c`)
  657. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  658. check table t1;
  659. Table Op Msg_type Msg_text
  660. test.t1 check status OK
  661. explain select * from t1 force index(c) order by c;
  662. id select_type table type possible_keys key key_len ref rows Extra
  663. 1 SIMPLE t1 index NULL c 5 NULL 9
  664. explain select * from t1 order by a;
  665. id select_type table type possible_keys key key_len ref rows Extra
  666. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 9
  667. explain select * from t1 force index(b) order by b;
  668. id select_type table type possible_keys key key_len ref rows Extra
  669. 1 SIMPLE t1 index NULL b 4 NULL 9
  670. select * from t1 order by a;
  671. a b c
  672. 1 5 1
  673. 2 4 2
  674. 3 3 3
  675. 4 2 4
  676. 5 1 5
  677. 10 20 20
  678. 11 19 19
  679. 12 18 18
  680. 13 17 17
  681. select * from t1 force index(b) order by b;
  682. a b c
  683. 5 1 5
  684. 4 2 4
  685. 3 3 3
  686. 2 4 2
  687. 1 5 1
  688. 13 17 17
  689. 12 18 18
  690. 11 19 19
  691. 10 20 20
  692. select * from t1 force index(c) order by c;
  693. a b c
  694. 1 5 1
  695. 2 4 2
  696. 3 3 3
  697. 4 2 4
  698. 5 1 5
  699. 13 17 17
  700. 12 18 18
  701. 11 19 19
  702. 10 20 20
  703. drop table t1;
  704. create table t1(a int not null, b int not null) engine=innodb;
  705. insert into t1 values (1,1);
  706. alter table t1 add primary key(b);
  707. insert into t1 values (2,2);
  708. show create table t1;
  709. Table Create Table
  710. t1 CREATE TABLE `t1` (
  711. `a` int(11) NOT NULL,
  712. `b` int(11) NOT NULL,
  713. PRIMARY KEY (`b`)
  714. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  715. check table t1;
  716. Table Op Msg_type Msg_text
  717. test.t1 check status OK
  718. select * from t1;
  719. a b
  720. 1 1
  721. 2 2
  722. explain select * from t1;
  723. id select_type table type possible_keys key key_len ref rows Extra
  724. 1 SIMPLE t1 ALL NULL NULL NULL NULL 2
  725. explain select * from t1 order by a;
  726. id select_type table type possible_keys key key_len ref rows Extra
  727. 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using filesort
  728. explain select * from t1 order by b;
  729. id select_type table type possible_keys key key_len ref rows Extra
  730. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 2
  731. checksum table t1;
  732. Table Checksum
  733. test.t1 582702641
  734. drop table t1;
  735. create table t1(a int not null) engine=innodb;
  736. insert into t1 values (1);
  737. alter table t1 add primary key(a);
  738. insert into t1 values (2);
  739. show create table t1;
  740. Table Create Table
  741. t1 CREATE TABLE `t1` (
  742. `a` int(11) NOT NULL,
  743. PRIMARY KEY (`a`)
  744. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  745. check table t1;
  746. Table Op Msg_type Msg_text
  747. test.t1 check status OK
  748. commit;
  749. select * from t1;
  750. a
  751. 1
  752. 2
  753. explain select * from t1;
  754. id select_type table type possible_keys key key_len ref rows Extra
  755. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
  756. explain select * from t1 order by a;
  757. id select_type table type possible_keys key key_len ref rows Extra
  758. 1 SIMPLE t1 index NULL PRIMARY 4 NULL 2 Using index
  759. drop table t1;
  760. create table t2(d varchar(17) primary key) engine=innodb default charset=utf8;
  761. create table t3(a int primary key) engine=innodb;
  762. insert into t3 values(22),(44),(33),(55),(66);
  763. insert into t2 values ('jejdkrun87'),('adfd72nh9k'),
  764. ('adfdpplkeock'),('adfdijnmnb78k'),('adfdijn0loKNHJik');
  765. create table t1(a int, b blob, c text, d text not null)
  766. engine=innodb default charset = utf8;
  767. insert into t1
  768. select a,left(repeat(d,100*a),65535),repeat(d,20*a),d from t2,t3;
  769. drop table t2, t3;
  770. select count(*) from t1 where a=44;
  771. count(*)
  772. 5
  773. select a,
  774. length(b),b=left(repeat(d,100*a),65535),length(c),c=repeat(d,20*a),d from t1;
  775. a length(b) b=left(repeat(d,100*a),65535) length(c) c=repeat(d,20*a) d
  776. 22 22000 1 4400 1 adfd72nh9k
  777. 22 35200 1 7040 1 adfdijn0loKNHJik
  778. 22 28600 1 5720 1 adfdijnmnb78k
  779. 22 26400 1 5280 1 adfdpplkeock
  780. 22 22000 1 4400 1 jejdkrun87
  781. 33 33000 1 6600 1 adfd72nh9k
  782. 33 52800 1 10560 1 adfdijn0loKNHJik
  783. 33 42900 1 8580 1 adfdijnmnb78k
  784. 33 39600 1 7920 1 adfdpplkeock
  785. 33 33000 1 6600 1 jejdkrun87
  786. 44 44000 1 8800 1 adfd72nh9k
  787. 44 65535 1 14080 1 adfdijn0loKNHJik
  788. 44 57200 1 11440 1 adfdijnmnb78k
  789. 44 52800 1 10560 1 adfdpplkeock
  790. 44 44000 1 8800 1 jejdkrun87
  791. 55 55000 1 11000 1 adfd72nh9k
  792. 55 65535 1 17600 1 adfdijn0loKNHJik
  793. 55 65535 1 14300 1 adfdijnmnb78k
  794. 55 65535 1 13200 1 adfdpplkeock
  795. 55 55000 1 11000 1 jejdkrun87
  796. 66 65535 1 13200 1 adfd72nh9k
  797. 66 65535 1 21120 1 adfdijn0loKNHJik
  798. 66 65535 1 17160 1 adfdijnmnb78k
  799. 66 65535 1 15840 1 adfdpplkeock
  800. 66 65535 1 13200 1 jejdkrun87
  801. alter table t1 add primary key (a), add key (b(20));
  802. ERROR 23000: Duplicate entry '22' for key 'PRIMARY'
  803. delete from t1 where a%2;
  804. check table t1;
  805. Table Op Msg_type Msg_text
  806. test.t1 check status OK
  807. alter table t1 add primary key (a,b(255),c(255)), add key (b(767));
  808. select count(*) from t1 where a=44;
  809. count(*)
  810. 5
  811. select a,
  812. length(b),b=left(repeat(d,100*a),65535),length(c),c=repeat(d,20*a),d from t1;
  813. a length(b) b=left(repeat(d,100*a),65535) length(c) c=repeat(d,20*a) d
  814. 22 22000 1 4400 1 adfd72nh9k
  815. 22 35200 1 7040 1 adfdijn0loKNHJik
  816. 22 28600 1 5720 1 adfdijnmnb78k
  817. 22 26400 1 5280 1 adfdpplkeock
  818. 22 22000 1 4400 1 jejdkrun87
  819. 44 44000 1 8800 1 adfd72nh9k
  820. 44 65535 1 14080 1 adfdijn0loKNHJik
  821. 44 57200 1 11440 1 adfdijnmnb78k
  822. 44 52800 1 10560 1 adfdpplkeock
  823. 44 44000 1 8800 1 jejdkrun87
  824. 66 65535 1 13200 1 adfd72nh9k
  825. 66 65535 1 21120 1 adfdijn0loKNHJik
  826. 66 65535 1 17160 1 adfdijnmnb78k
  827. 66 65535 1 15840 1 adfdpplkeock
  828. 66 65535 1 13200 1 jejdkrun87
  829. show create table t1;
  830. Table Create Table
  831. t1 CREATE TABLE `t1` (
  832. `a` int(11) NOT NULL DEFAULT '0',
  833. `b` blob NOT NULL,
  834. `c` text NOT NULL,
  835. `d` text NOT NULL,
  836. PRIMARY KEY (`a`,`b`(255),`c`(255)),
  837. KEY `b` (`b`(767))
  838. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  839. check table t1;
  840. Table Op Msg_type Msg_text
  841. test.t1 check status OK
  842. explain select * from t1 where b like 'adfd%';
  843. id select_type table type possible_keys key key_len ref rows Extra
  844. 1 SIMPLE t1 ALL b NULL NULL NULL 15 Using where
  845. create table t2(a int, b varchar(255), primary key(a,b)) engine=innodb;
  846. insert into t2 select a,left(b,255) from t1;
  847. drop table t1;
  848. rename table t2 to t1;
  849. set innodb_lock_wait_timeout=1;
  850. begin;
  851. select a from t1 limit 1 for update;
  852. a
  853. 22
  854. set innodb_lock_wait_timeout=1;
  855. create index t1ba on t1 (b,a);
  856. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  857. commit;
  858. begin;
  859. select a from t1 limit 1 lock in share mode;
  860. a
  861. 22
  862. create index t1ba on t1 (b,a);
  863. drop index t1ba on t1;
  864. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  865. commit;
  866. explain select a from t1 order by b;
  867. id select_type table type possible_keys key key_len ref rows Extra
  868. 1 SIMPLE t1 index NULL t1ba 261 NULL 15 Using index
  869. select a,sleep(2+a/100) from t1 order by b limit 3;
  870. select sleep(1);
  871. sleep(1)
  872. 0
  873. drop index t1ba on t1;
  874. a sleep(2+a/100)
  875. 22 0
  876. 44 0
  877. 66 0
  878. explain select a from t1 order by b;
  879. id select_type table type possible_keys key key_len ref rows Extra
  880. 1 SIMPLE t1 index NULL PRIMARY 261 NULL 15 Using index; Using filesort
  881. select a from t1 order by b limit 3;
  882. a
  883. 22
  884. 66
  885. 44
  886. commit;
  887. drop table t1;
  888. set global innodb_file_per_table=on;
  889. set global innodb_file_format='Barracuda';
  890. create table t1(a blob,b blob,c blob,d blob,e blob,f blob,g blob,h blob,
  891. i blob,j blob,k blob,l blob,m blob,n blob,o blob,p blob,
  892. q blob,r blob,s blob,t blob,u blob)
  893. engine=innodb row_format=dynamic;
  894. create index t1a on t1 (a(1));
  895. create index t1b on t1 (b(1));
  896. create index t1c on t1 (c(1));
  897. create index t1d on t1 (d(1));
  898. create index t1e on t1 (e(1));
  899. create index t1f on t1 (f(1));
  900. create index t1g on t1 (g(1));
  901. create index t1h on t1 (h(1));
  902. create index t1i on t1 (i(1));
  903. create index t1j on t1 (j(1));
  904. create index t1k on t1 (k(1));
  905. create index t1l on t1 (l(1));
  906. create index t1m on t1 (m(1));
  907. create index t1n on t1 (n(1));
  908. create index t1o on t1 (o(1));
  909. create index t1p on t1 (p(1));
  910. create index t1q on t1 (q(1));
  911. create index t1r on t1 (r(1));
  912. create index t1s on t1 (s(1));
  913. create index t1t on t1 (t(1));
  914. create index t1u on t1 (u(1));
  915. ERROR HY000: Too big row
  916. create index t1ut on t1 (u(1), t(1));
  917. ERROR HY000: Too big row
  918. create index t1st on t1 (s(1), t(1));
  919. show create table t1;
  920. Table Create Table
  921. t1 CREATE TABLE `t1` (
  922. `a` blob,
  923. `b` blob,
  924. `c` blob,
  925. `d` blob,
  926. `e` blob,
  927. `f` blob,
  928. `g` blob,
  929. `h` blob,
  930. `i` blob,
  931. `j` blob,
  932. `k` blob,
  933. `l` blob,
  934. `m` blob,
  935. `n` blob,
  936. `o` blob,
  937. `p` blob,
  938. `q` blob,
  939. `r` blob,
  940. `s` blob,
  941. `t` blob,
  942. `u` blob,
  943. KEY `t1a` (`a`(1)),
  944. KEY `t1b` (`b`(1)),
  945. KEY `t1c` (`c`(1)),
  946. KEY `t1d` (`d`(1)),
  947. KEY `t1e` (`e`(1)),
  948. KEY `t1f` (`f`(1)),
  949. KEY `t1g` (`g`(1)),
  950. KEY `t1h` (`h`(1)),
  951. KEY `t1i` (`i`(1)),
  952. KEY `t1j` (`j`(1)),
  953. KEY `t1k` (`k`(1)),
  954. KEY `t1l` (`l`(1)),
  955. KEY `t1m` (`m`(1)),
  956. KEY `t1n` (`n`(1)),
  957. KEY `t1o` (`o`(1)),
  958. KEY `t1p` (`p`(1)),
  959. KEY `t1q` (`q`(1)),
  960. KEY `t1r` (`r`(1)),
  961. KEY `t1s` (`s`(1)),
  962. KEY `t1t` (`t`(1)),
  963. KEY `t1st` (`s`(1),`t`(1))
  964. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC
  965. create index t1u on t1 (u(1));
  966. ERROR HY000: Too big row
  967. alter table t1 row_format=compact;
  968. create index t1u on t1 (u(1));
  969. drop table t1;
  970. set global innodb_file_per_table=0;
  971. set global innodb_file_format=Antelope;
  972. set global innodb_file_format_check=Antelope;
  973. SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
  974. SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
  975. CREATE TABLE t1(
  976. c1 BIGINT(12) NOT NULL,
  977. PRIMARY KEY (c1)
  978. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  979. CREATE TABLE t2(
  980. c1 BIGINT(16) NOT NULL,
  981. c2 BIGINT(12) NOT NULL,
  982. c3 BIGINT(12) NOT NULL,
  983. PRIMARY KEY (c1)
  984. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  985. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  986. FOREIGN KEY (c3) REFERENCES t1(c1);
  987. SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  988. SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  989. SHOW CREATE TABLE t2;
  990. Table Create Table
  991. t2 CREATE TABLE `t2` (
  992. `c1` bigint(16) NOT NULL,
  993. `c2` bigint(12) NOT NULL,
  994. `c3` bigint(12) NOT NULL,
  995. PRIMARY KEY (`c1`),
  996. KEY `fk_t2_ca` (`c3`),
  997. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`)
  998. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  999. CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
  1000. SHOW CREATE TABLE t2;
  1001. Table Create Table
  1002. t2 CREATE TABLE `t2` (
  1003. `c1` bigint(16) NOT NULL,
  1004. `c2` bigint(12) NOT NULL,
  1005. `c3` bigint(12) NOT NULL,
  1006. PRIMARY KEY (`c1`),
  1007. KEY `i_t2_c3_c2` (`c3`,`c2`),
  1008. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`)
  1009. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1010. SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
  1011. SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
  1012. INSERT INTO t2 VALUES(0,0,0);
  1013. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`))
  1014. INSERT INTO t1 VALUES(0);
  1015. INSERT INTO t2 VALUES(0,0,0);
  1016. DROP TABLE t2;
  1017. CREATE TABLE t2(
  1018. c1 BIGINT(16) NOT NULL,
  1019. c2 BIGINT(12) NOT NULL,
  1020. c3 BIGINT(12) NOT NULL,
  1021. PRIMARY KEY (c1,c2,c3)
  1022. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1023. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  1024. FOREIGN KEY (c3) REFERENCES t1(c1);
  1025. SHOW CREATE TABLE t2;
  1026. Table Create Table
  1027. t2 CREATE TABLE `t2` (
  1028. `c1` bigint(16) NOT NULL,
  1029. `c2` bigint(12) NOT NULL,
  1030. `c3` bigint(12) NOT NULL,
  1031. PRIMARY KEY (`c1`,`c2`,`c3`),
  1032. KEY `fk_t2_ca` (`c3`),
  1033. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`)
  1034. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1035. CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
  1036. SHOW CREATE TABLE t2;
  1037. Table Create Table
  1038. t2 CREATE TABLE `t2` (
  1039. `c1` bigint(16) NOT NULL,
  1040. `c2` bigint(12) NOT NULL,
  1041. `c3` bigint(12) NOT NULL,
  1042. PRIMARY KEY (`c1`,`c2`,`c3`),
  1043. KEY `i_t2_c3_c2` (`c3`,`c2`),
  1044. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`)
  1045. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1046. INSERT INTO t2 VALUES(0,0,1);
  1047. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`))
  1048. INSERT INTO t2 VALUES(0,0,0);
  1049. DELETE FROM t1;
  1050. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`) REFERENCES `t1` (`c1`))
  1051. DELETE FROM t2;
  1052. DROP TABLE t2;
  1053. DROP TABLE t1;
  1054. CREATE TABLE t1(
  1055. c1 BIGINT(12) NOT NULL,
  1056. c2 INT(4) NOT NULL,
  1057. PRIMARY KEY (c2,c1)
  1058. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1059. CREATE TABLE t2(
  1060. c1 BIGINT(16) NOT NULL,
  1061. c2 BIGINT(12) NOT NULL,
  1062. c3 BIGINT(12) NOT NULL,
  1063. PRIMARY KEY (c1)
  1064. ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1065. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  1066. FOREIGN KEY (c3,c2) REFERENCES t1(c1,c1);
  1067. ERROR HY000: Can't create table '#sql-temporary' (errno: 150)
  1068. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  1069. FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2);
  1070. ERROR HY000: Can't create table '#sql-temporary' (errno: 150)
  1071. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  1072. FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1);
  1073. ERROR HY000: Can't create table '#sql-temporary' (errno: 150)
  1074. ALTER TABLE t1 MODIFY COLUMN c2 BIGINT(12) NOT NULL;
  1075. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  1076. FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2);
  1077. ERROR HY000: Can't create table '#sql-temporary' (errno: 150)
  1078. ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
  1079. FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1);
  1080. SHOW CREATE TABLE t1;
  1081. Table Create Table
  1082. t1 CREATE TABLE `t1` (
  1083. `c1` bigint(12) NOT NULL,
  1084. `c2` bigint(12) NOT NULL,
  1085. PRIMARY KEY (`c2`,`c1`)
  1086. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1087. SHOW CREATE TABLE t2;
  1088. Table Create Table
  1089. t2 CREATE TABLE `t2` (
  1090. `c1` bigint(16) NOT NULL,
  1091. `c2` bigint(12) NOT NULL,
  1092. `c3` bigint(12) NOT NULL,
  1093. PRIMARY KEY (`c1`),
  1094. KEY `fk_t2_ca` (`c3`,`c2`),
  1095. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`, `c2`) REFERENCES `t1` (`c2`, `c1`)
  1096. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1097. CREATE INDEX i_t2_c2_c1 ON t2(c2, c1);
  1098. SHOW CREATE TABLE t2;
  1099. Table Create Table
  1100. t2 CREATE TABLE `t2` (
  1101. `c1` bigint(16) NOT NULL,
  1102. `c2` bigint(12) NOT NULL,
  1103. `c3` bigint(12) NOT NULL,
  1104. PRIMARY KEY (`c1`),
  1105. KEY `fk_t2_ca` (`c3`,`c2`),
  1106. KEY `i_t2_c2_c1` (`c2`,`c1`),
  1107. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`, `c2`) REFERENCES `t1` (`c2`, `c1`)
  1108. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1109. CREATE INDEX i_t2_c3_c1_c2 ON t2(c3, c1, c2);
  1110. SHOW CREATE TABLE t2;
  1111. Table Create Table
  1112. t2 CREATE TABLE `t2` (
  1113. `c1` bigint(16) NOT NULL,
  1114. `c2` bigint(12) NOT NULL,
  1115. `c3` bigint(12) NOT NULL,
  1116. PRIMARY KEY (`c1`),
  1117. KEY `fk_t2_ca` (`c3`,`c2`),
  1118. KEY `i_t2_c2_c1` (`c2`,`c1`),
  1119. KEY `i_t2_c3_c1_c2` (`c3`,`c1`,`c2`),
  1120. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`, `c2`) REFERENCES `t1` (`c2`, `c1`)
  1121. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1122. CREATE INDEX i_t2_c3_c2 ON t2(c3, c2);
  1123. SHOW CREATE TABLE t2;
  1124. Table Create Table
  1125. t2 CREATE TABLE `t2` (
  1126. `c1` bigint(16) NOT NULL,
  1127. `c2` bigint(12) NOT NULL,
  1128. `c3` bigint(12) NOT NULL,
  1129. PRIMARY KEY (`c1`),
  1130. KEY `i_t2_c2_c1` (`c2`,`c1`),
  1131. KEY `i_t2_c3_c1_c2` (`c3`,`c1`,`c2`),
  1132. KEY `i_t2_c3_c2` (`c3`,`c2`),
  1133. CONSTRAINT `fk_t2_ca` FOREIGN KEY (`c3`, `c2`) REFERENCES `t1` (`c2`, `c1`)
  1134. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1135. DROP TABLE t2;
  1136. DROP TABLE t1;
  1137. CREATE TABLE t1 (a INT, b CHAR(1)) ENGINE=InnoDB;
  1138. INSERT INTO t1 VALUES (3,'a'),(3,'b'),(1,'c'),(0,'d'),(1,'e');
  1139. BEGIN;
  1140. SELECT * FROM t1;
  1141. a b
  1142. 3 a
  1143. 3 b
  1144. 1 c
  1145. 0 d
  1146. 1 e
  1147. CREATE INDEX t1a ON t1(a);
  1148. SELECT * FROM t1;
  1149. a b
  1150. 3 a
  1151. 3 b
  1152. 1 c
  1153. 0 d
  1154. 1 e
  1155. SELECT * FROM t1 FORCE INDEX(t1a) ORDER BY a;
  1156. ERROR HY000: Table definition has changed, please retry transaction
  1157. SELECT * FROM t1;
  1158. a b
  1159. 3 a
  1160. 3 b
  1161. 1 c
  1162. 0 d
  1163. 1 e
  1164. COMMIT;
  1165. SELECT * FROM t1 FORCE INDEX(t1a) ORDER BY a;
  1166. a b
  1167. 0 d
  1168. 1 c
  1169. 1 e
  1170. 3 a
  1171. 3 b
  1172. DROP TABLE t1;