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.

3482 lines
108 KiB

20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
20 years ago
  1. drop table if exists t1,t2,t3,t4;
  2. drop database if exists mysqltest;
  3. create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
  4. insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David'), (2, 'Erik'), (3, 'Sasha'), (3, 'Jeremy'), (4, 'Matt');
  5. select id, code, name from t1 order by id;
  6. id code name
  7. 1 1 Tim
  8. 2 1 Monty
  9. 3 2 David
  10. 4 2 Erik
  11. 5 3 Sasha
  12. 6 3 Jeremy
  13. 7 4 Matt
  14. update ignore t1 set id = 8, name = 'Sinisa' where id < 3;
  15. select id, code, name from t1 order by id;
  16. id code name
  17. 2 1 Monty
  18. 3 2 David
  19. 4 2 Erik
  20. 5 3 Sasha
  21. 6 3 Jeremy
  22. 7 4 Matt
  23. 8 1 Sinisa
  24. update ignore t1 set id = id + 10, name = 'Ralph' where id < 4;
  25. select id, code, name from t1 order by id;
  26. id code name
  27. 3 2 David
  28. 4 2 Erik
  29. 5 3 Sasha
  30. 6 3 Jeremy
  31. 7 4 Matt
  32. 8 1 Sinisa
  33. 12 1 Ralph
  34. drop table t1;
  35. CREATE TABLE t1 (
  36. id int(11) NOT NULL auto_increment,
  37. parent_id int(11) DEFAULT '0' NOT NULL,
  38. level tinyint(4) DEFAULT '0' NOT NULL,
  39. PRIMARY KEY (id),
  40. KEY parent_id (parent_id),
  41. KEY level (level)
  42. ) engine=innodb;
  43. INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1),(179,5,2);
  44. update t1 set parent_id=parent_id+100;
  45. select * from t1 where parent_id=102;
  46. id parent_id level
  47. 8 102 2
  48. 9 102 2
  49. 15 102 2
  50. update t1 set id=id+1000;
  51. update t1 set id=1024 where id=1009;
  52. Got one of the listed errors
  53. select * from t1;
  54. id parent_id level
  55. 1001 100 0
  56. 1002 101 1
  57. 1003 101 1
  58. 1004 101 1
  59. 1005 101 1
  60. 1006 101 1
  61. 1007 101 1
  62. 1008 102 2
  63. 1009 102 2
  64. 1015 102 2
  65. 1016 103 2
  66. 1017 103 2
  67. 1018 103 2
  68. 1019 103 2
  69. 1020 103 2
  70. 1021 104 2
  71. 1022 104 2
  72. 1024 104 2
  73. 1025 105 2
  74. 1026 105 2
  75. 1027 105 2
  76. 1028 105 2
  77. 1029 105 2
  78. 1030 105 2
  79. 1031 106 2
  80. 1032 106 2
  81. 1033 106 2
  82. 1034 106 2
  83. 1035 106 2
  84. 1036 107 2
  85. 1037 107 2
  86. 1038 107 2
  87. 1040 107 2
  88. 1157 100 0
  89. 1179 105 2
  90. 1183 104 2
  91. 1193 105 2
  92. 1202 107 2
  93. 1203 107 2
  94. update ignore t1 set id=id+1;
  95. select * from t1;
  96. id parent_id level
  97. 1001 100 0
  98. 1002 101 1
  99. 1003 101 1
  100. 1004 101 1
  101. 1005 101 1
  102. 1006 101 1
  103. 1007 101 1
  104. 1008 102 2
  105. 1010 102 2
  106. 1015 102 2
  107. 1016 103 2
  108. 1017 103 2
  109. 1018 103 2
  110. 1019 103 2
  111. 1020 103 2
  112. 1021 104 2
  113. 1023 104 2
  114. 1024 104 2
  115. 1025 105 2
  116. 1026 105 2
  117. 1027 105 2
  118. 1028 105 2
  119. 1029 105 2
  120. 1030 105 2
  121. 1031 106 2
  122. 1032 106 2
  123. 1033 106 2
  124. 1034 106 2
  125. 1035 106 2
  126. 1036 107 2
  127. 1037 107 2
  128. 1039 107 2
  129. 1041 107 2
  130. 1158 100 0
  131. 1180 105 2
  132. 1184 104 2
  133. 1194 105 2
  134. 1202 107 2
  135. 1204 107 2
  136. update ignore t1 set id=1023 where id=1010;
  137. select * from t1 where parent_id=102;
  138. id parent_id level
  139. 1008 102 2
  140. 1010 102 2
  141. 1015 102 2
  142. explain select level from t1 where level=1;
  143. id select_type table type possible_keys key key_len ref rows Extra
  144. 1 SIMPLE t1 ref level level 1 const # Using index
  145. explain select level,id from t1 where level=1;
  146. id select_type table type possible_keys key key_len ref rows Extra
  147. 1 SIMPLE t1 ref level level 1 const # Using index
  148. explain select level,id,parent_id from t1 where level=1;
  149. id select_type table type possible_keys key key_len ref rows Extra
  150. 1 SIMPLE t1 ref level level 1 const #
  151. select level,id from t1 where level=1;
  152. level id
  153. 1 1002
  154. 1 1003
  155. 1 1004
  156. 1 1005
  157. 1 1006
  158. 1 1007
  159. select level,id,parent_id from t1 where level=1;
  160. level id parent_id
  161. 1 1002 101
  162. 1 1003 101
  163. 1 1004 101
  164. 1 1005 101
  165. 1 1006 101
  166. 1 1007 101
  167. optimize table t1;
  168. Table Op Msg_type Msg_text
  169. test.t1 optimize status OK
  170. show keys from t1;
  171. Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
  172. t1 0 PRIMARY 1 id A # NULL NULL BTREE
  173. t1 1 parent_id 1 parent_id A # NULL NULL BTREE
  174. t1 1 level 1 level A # NULL NULL BTREE
  175. drop table t1;
  176. CREATE TABLE t1 (
  177. gesuchnr int(11) DEFAULT '0' NOT NULL,
  178. benutzer_id int(11) DEFAULT '0' NOT NULL,
  179. PRIMARY KEY (gesuchnr,benutzer_id)
  180. ) engine=innodb;
  181. replace into t1 (gesuchnr,benutzer_id) values (2,1);
  182. replace into t1 (gesuchnr,benutzer_id) values (1,1);
  183. replace into t1 (gesuchnr,benutzer_id) values (1,1);
  184. select * from t1;
  185. gesuchnr benutzer_id
  186. 1 1
  187. 2 1
  188. drop table t1;
  189. create table t1 (a int) engine=innodb;
  190. insert into t1 values (1), (2);
  191. optimize table t1;
  192. Table Op Msg_type Msg_text
  193. test.t1 optimize status OK
  194. delete from t1 where a = 1;
  195. select * from t1;
  196. a
  197. 2
  198. check table t1;
  199. Table Op Msg_type Msg_text
  200. test.t1 check status OK
  201. drop table t1;
  202. create table t1 (a int,b varchar(20)) engine=innodb;
  203. insert into t1 values (1,""), (2,"testing");
  204. delete from t1 where a = 1;
  205. select * from t1;
  206. a b
  207. 2 testing
  208. create index skr on t1 (a);
  209. insert into t1 values (3,""), (4,"testing");
  210. analyze table t1;
  211. Table Op Msg_type Msg_text
  212. test.t1 analyze status OK
  213. show keys from t1;
  214. Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
  215. t1 1 skr 1 a A # NULL NULL YES BTREE
  216. drop table t1;
  217. create table t1 (a int,b varchar(20),key(a)) engine=innodb;
  218. insert into t1 values (1,""), (2,"testing");
  219. select * from t1 where a = 1;
  220. a b
  221. 1
  222. drop table t1;
  223. create table t1 (n int not null primary key) engine=innodb;
  224. set autocommit=0;
  225. insert into t1 values (4);
  226. rollback;
  227. select n, "after rollback" from t1;
  228. n after rollback
  229. insert into t1 values (4);
  230. commit;
  231. select n, "after commit" from t1;
  232. n after commit
  233. 4 after commit
  234. commit;
  235. insert into t1 values (5);
  236. insert into t1 values (4);
  237. ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
  238. commit;
  239. select n, "after commit" from t1;
  240. n after commit
  241. 4 after commit
  242. 5 after commit
  243. set autocommit=1;
  244. insert into t1 values (6);
  245. insert into t1 values (4);
  246. ERROR 23000: Duplicate entry '4' for key 'PRIMARY'
  247. select n from t1;
  248. n
  249. 4
  250. 5
  251. 6
  252. set autocommit=0;
  253. begin;
  254. savepoint `my_savepoint`;
  255. insert into t1 values (7);
  256. savepoint `savept2`;
  257. insert into t1 values (3);
  258. select n from t1;
  259. n
  260. 3
  261. 4
  262. 5
  263. 6
  264. 7
  265. savepoint savept3;
  266. rollback to savepoint savept2;
  267. rollback to savepoint savept3;
  268. ERROR 42000: SAVEPOINT savept3 does not exist
  269. rollback to savepoint savept2;
  270. release savepoint `my_savepoint`;
  271. select n from t1;
  272. n
  273. 4
  274. 5
  275. 6
  276. 7
  277. rollback to savepoint `my_savepoint`;
  278. ERROR 42000: SAVEPOINT my_savepoint does not exist
  279. rollback to savepoint savept2;
  280. ERROR 42000: SAVEPOINT savept2 does not exist
  281. insert into t1 values (8);
  282. savepoint sv;
  283. commit;
  284. savepoint sv;
  285. set autocommit=1;
  286. rollback;
  287. drop table t1;
  288. create table t1 (n int not null primary key) engine=innodb;
  289. start transaction;
  290. insert into t1 values (4);
  291. flush tables with read lock;
  292. commit;
  293. unlock tables;
  294. commit;
  295. select * from t1;
  296. n
  297. 4
  298. drop table t1;
  299. create table t1 ( id int NOT NULL PRIMARY KEY, nom varchar(64)) engine=innodb;
  300. begin;
  301. insert into t1 values(1,'hamdouni');
  302. select id as afterbegin_id,nom as afterbegin_nom from t1;
  303. afterbegin_id afterbegin_nom
  304. 1 hamdouni
  305. rollback;
  306. select id as afterrollback_id,nom as afterrollback_nom from t1;
  307. afterrollback_id afterrollback_nom
  308. set autocommit=0;
  309. insert into t1 values(2,'mysql');
  310. select id as afterautocommit0_id,nom as afterautocommit0_nom from t1;
  311. afterautocommit0_id afterautocommit0_nom
  312. 2 mysql
  313. rollback;
  314. select id as afterrollback_id,nom as afterrollback_nom from t1;
  315. afterrollback_id afterrollback_nom
  316. set autocommit=1;
  317. drop table t1;
  318. CREATE TABLE t1 (id char(8) not null primary key, val int not null) engine=innodb;
  319. insert into t1 values ('pippo', 12);
  320. insert into t1 values ('pippo', 12);
  321. ERROR 23000: Duplicate entry 'pippo' for key 'PRIMARY'
  322. delete from t1;
  323. delete from t1 where id = 'pippo';
  324. select * from t1;
  325. id val
  326. insert into t1 values ('pippo', 12);
  327. set autocommit=0;
  328. delete from t1;
  329. rollback;
  330. select * from t1;
  331. id val
  332. pippo 12
  333. delete from t1;
  334. commit;
  335. select * from t1;
  336. id val
  337. drop table t1;
  338. create table t1 (a integer) engine=innodb;
  339. start transaction;
  340. rename table t1 to t2;
  341. create table t1 (b integer) engine=innodb;
  342. insert into t1 values (1);
  343. rollback;
  344. drop table t1;
  345. rename table t2 to t1;
  346. drop table t1;
  347. set autocommit=1;
  348. CREATE TABLE t1 (ID INTEGER NOT NULL PRIMARY KEY, NAME VARCHAR(64)) ENGINE=innodb;
  349. INSERT INTO t1 VALUES (1, 'Jochen');
  350. select * from t1;
  351. ID NAME
  352. 1 Jochen
  353. drop table t1;
  354. CREATE TABLE t1 ( _userid VARCHAR(60) NOT NULL PRIMARY KEY) ENGINE=innodb;
  355. set autocommit=0;
  356. INSERT INTO t1 SET _userid='marc@anyware.co.uk';
  357. COMMIT;
  358. SELECT * FROM t1;
  359. _userid
  360. marc@anyware.co.uk
  361. SELECT _userid FROM t1 WHERE _userid='marc@anyware.co.uk';
  362. _userid
  363. marc@anyware.co.uk
  364. drop table t1;
  365. set autocommit=1;
  366. CREATE TABLE t1 (
  367. user_id int(10) DEFAULT '0' NOT NULL,
  368. name varchar(100),
  369. phone varchar(100),
  370. ref_email varchar(100) DEFAULT '' NOT NULL,
  371. detail varchar(200),
  372. PRIMARY KEY (user_id,ref_email)
  373. )engine=innodb;
  374. INSERT INTO t1 VALUES (10292,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10292,'shirish','2333604','shirish@yahoo.com','ddsds'),(10292,'sonali','323232','sonali@bolly.com','filmstar');
  375. select * from t1 where user_id=10292;
  376. user_id name phone ref_email detail
  377. 10292 sanjeev 29153373 sansh777@hotmail.com xxx
  378. 10292 shirish 2333604 shirish@yahoo.com ddsds
  379. 10292 sonali 323232 sonali@bolly.com filmstar
  380. INSERT INTO t1 VALUES (10291,'sanjeev','29153373','sansh777@hotmail.com','xxx'),(10293,'shirish','2333604','shirish@yahoo.com','ddsds');
  381. select * from t1 where user_id=10292;
  382. user_id name phone ref_email detail
  383. 10292 sanjeev 29153373 sansh777@hotmail.com xxx
  384. 10292 shirish 2333604 shirish@yahoo.com ddsds
  385. 10292 sonali 323232 sonali@bolly.com filmstar
  386. select * from t1 where user_id>=10292;
  387. user_id name phone ref_email detail
  388. 10292 sanjeev 29153373 sansh777@hotmail.com xxx
  389. 10292 shirish 2333604 shirish@yahoo.com ddsds
  390. 10292 sonali 323232 sonali@bolly.com filmstar
  391. 10293 shirish 2333604 shirish@yahoo.com ddsds
  392. select * from t1 where user_id>10292;
  393. user_id name phone ref_email detail
  394. 10293 shirish 2333604 shirish@yahoo.com ddsds
  395. select * from t1 where user_id<10292;
  396. user_id name phone ref_email detail
  397. 10291 sanjeev 29153373 sansh777@hotmail.com xxx
  398. drop table t1;
  399. CREATE TABLE t1 (a int not null, b int not null,c int not null,
  400. key(a),primary key(a,b), unique(c),key(a),unique(b));
  401. show index from t1;
  402. Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
  403. t1 0 PRIMARY 1 a A # NULL NULL BTREE
  404. t1 0 PRIMARY 2 b A # NULL NULL BTREE
  405. t1 0 c 1 c A # NULL NULL BTREE
  406. t1 0 b 1 b A # NULL NULL BTREE
  407. t1 1 a 1 a A # NULL NULL BTREE
  408. t1 1 a_2 1 a A # NULL NULL BTREE
  409. drop table t1;
  410. create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
  411. alter table t1 engine=innodb;
  412. insert into t1 values ('1','1'),('5','2'),('2','3'),('3','4'),('4','4');
  413. select * from t1;
  414. col1 col2
  415. 1 1
  416. 2 3
  417. 3 4
  418. 4 4
  419. 5 2
  420. update t1 set col2='7' where col1='4';
  421. select * from t1;
  422. col1 col2
  423. 1 1
  424. 2 3
  425. 3 4
  426. 4 7
  427. 5 2
  428. alter table t1 add co3 int not null;
  429. select * from t1;
  430. col1 col2 co3
  431. 1 1 0
  432. 2 3 0
  433. 3 4 0
  434. 4 7 0
  435. 5 2 0
  436. update t1 set col2='9' where col1='2';
  437. select * from t1;
  438. col1 col2 co3
  439. 1 1 0
  440. 2 9 0
  441. 3 4 0
  442. 4 7 0
  443. 5 2 0
  444. drop table t1;
  445. create table t1 (a int not null , b int, primary key (a)) engine = innodb;
  446. create table t2 (a int not null , b int, primary key (a)) engine = myisam;
  447. insert into t1 VALUES (1,3) , (2,3), (3,3);
  448. select * from t1;
  449. a b
  450. 1 3
  451. 2 3
  452. 3 3
  453. insert into t2 select * from t1;
  454. select * from t2;
  455. a b
  456. 1 3
  457. 2 3
  458. 3 3
  459. delete from t1 where b = 3;
  460. select * from t1;
  461. a b
  462. insert into t1 select * from t2;
  463. select * from t1;
  464. a b
  465. 1 3
  466. 2 3
  467. 3 3
  468. select * from t2;
  469. a b
  470. 1 3
  471. 2 3
  472. 3 3
  473. drop table t1,t2;
  474. CREATE TABLE t1 (
  475. id int(11) NOT NULL auto_increment,
  476. ggid varchar(32) binary DEFAULT '' NOT NULL,
  477. email varchar(64) DEFAULT '' NOT NULL,
  478. passwd varchar(32) binary DEFAULT '' NOT NULL,
  479. PRIMARY KEY (id),
  480. UNIQUE ggid (ggid)
  481. ) ENGINE=innodb;
  482. insert into t1 (ggid,passwd) values ('test1','xxx');
  483. insert into t1 (ggid,passwd) values ('test2','yyy');
  484. insert into t1 (ggid,passwd) values ('test2','this will fail');
  485. ERROR 23000: Duplicate entry 'test2' for key 'ggid'
  486. insert into t1 (ggid,id) values ('this will fail',1);
  487. ERROR 23000: Duplicate entry '1' for key 'PRIMARY'
  488. select * from t1 where ggid='test1';
  489. id ggid email passwd
  490. 1 test1 xxx
  491. select * from t1 where passwd='xxx';
  492. id ggid email passwd
  493. 1 test1 xxx
  494. select * from t1 where id=2;
  495. id ggid email passwd
  496. 2 test2 yyy
  497. replace into t1 (ggid,id) values ('this will work',1);
  498. replace into t1 (ggid,passwd) values ('test2','this will work');
  499. update t1 set id=100,ggid='test2' where id=1;
  500. ERROR 23000: Duplicate entry 'test2' for key 'ggid'
  501. select * from t1;
  502. id ggid email passwd
  503. 1 this will work
  504. 3 test2 this will work
  505. select * from t1 where id=1;
  506. id ggid email passwd
  507. 1 this will work
  508. select * from t1 where id=999;
  509. id ggid email passwd
  510. drop table t1;
  511. CREATE TABLE t1 (
  512. user_name varchar(12),
  513. password text,
  514. subscribed char(1),
  515. user_id int(11) DEFAULT '0' NOT NULL,
  516. quota bigint(20),
  517. weight double,
  518. access_date date,
  519. access_time time,
  520. approved datetime,
  521. dummy_primary_key int(11) NOT NULL auto_increment,
  522. PRIMARY KEY (dummy_primary_key)
  523. ) ENGINE=innodb;
  524. INSERT INTO t1 VALUES ('user_0','somepassword','N',0,0,0,'2000-09-07','23:06:59','2000-09-07 23:06:59',1);
  525. INSERT INTO t1 VALUES ('user_1','somepassword','Y',1,1,1,'2000-09-07','23:06:59','2000-09-07 23:06:59',2);
  526. INSERT INTO t1 VALUES ('user_2','somepassword','N',2,2,1.4142135623731,'2000-09-07','23:06:59','2000-09-07 23:06:59',3);
  527. INSERT INTO t1 VALUES ('user_3','somepassword','Y',3,3,1.7320508075689,'2000-09-07','23:06:59','2000-09-07 23:06:59',4);
  528. INSERT INTO t1 VALUES ('user_4','somepassword','N',4,4,2,'2000-09-07','23:06:59','2000-09-07 23:06:59',5);
  529. select user_name, password , subscribed, user_id, quota, weight, access_date, access_time, approved, dummy_primary_key from t1 order by user_name;
  530. user_name password subscribed user_id quota weight access_date access_time approved dummy_primary_key
  531. user_0 somepassword N 0 0 0 2000-09-07 23:06:59 2000-09-07 23:06:59 1
  532. user_1 somepassword Y 1 1 1 2000-09-07 23:06:59 2000-09-07 23:06:59 2
  533. user_2 somepassword N 2 2 1.4142135623731 2000-09-07 23:06:59 2000-09-07 23:06:59 3
  534. user_3 somepassword Y 3 3 1.7320508075689 2000-09-07 23:06:59 2000-09-07 23:06:59 4
  535. user_4 somepassword N 4 4 2 2000-09-07 23:06:59 2000-09-07 23:06:59 5
  536. drop table t1;
  537. CREATE TABLE t1 (
  538. id int(11) NOT NULL auto_increment,
  539. parent_id int(11) DEFAULT '0' NOT NULL,
  540. level tinyint(4) DEFAULT '0' NOT NULL,
  541. KEY (id),
  542. KEY parent_id (parent_id),
  543. KEY level (level)
  544. ) engine=innodb;
  545. INSERT INTO t1 VALUES (1,0,0),(3,1,1),(4,1,1),(8,2,2),(9,2,2),(17,3,2),(22,4,2),(24,4,2),(28,5,2),(29,5,2),(30,5,2),(31,6,2),(32,6,2),(33,6,2),(203,7,2),(202,7,2),(20,3,2),(157,0,0),(193,5,2),(40,7,2),(2,1,1),(15,2,2),(6,1,1),(34,6,2),(35,6,2),(16,3,2),(7,1,1),(36,7,2),(18,3,2),(26,5,2),(27,5,2),(183,4,2),(38,7,2),(25,5,2),(37,7,2),(21,4,2),(19,3,2),(5,1,1);
  546. INSERT INTO t1 values (179,5,2);
  547. update t1 set parent_id=parent_id+100;
  548. select * from t1 where parent_id=102;
  549. id parent_id level
  550. 8 102 2
  551. 9 102 2
  552. 15 102 2
  553. update t1 set id=id+1000;
  554. update t1 set id=1024 where id=1009;
  555. select * from t1;
  556. id parent_id level
  557. 1001 100 0
  558. 1003 101 1
  559. 1004 101 1
  560. 1008 102 2
  561. 1024 102 2
  562. 1017 103 2
  563. 1022 104 2
  564. 1024 104 2
  565. 1028 105 2
  566. 1029 105 2
  567. 1030 105 2
  568. 1031 106 2
  569. 1032 106 2
  570. 1033 106 2
  571. 1203 107 2
  572. 1202 107 2
  573. 1020 103 2
  574. 1157 100 0
  575. 1193 105 2
  576. 1040 107 2
  577. 1002 101 1
  578. 1015 102 2
  579. 1006 101 1
  580. 1034 106 2
  581. 1035 106 2
  582. 1016 103 2
  583. 1007 101 1
  584. 1036 107 2
  585. 1018 103 2
  586. 1026 105 2
  587. 1027 105 2
  588. 1183 104 2
  589. 1038 107 2
  590. 1025 105 2
  591. 1037 107 2
  592. 1021 104 2
  593. 1019 103 2
  594. 1005 101 1
  595. 1179 105 2
  596. update ignore t1 set id=id+1;
  597. select * from t1;
  598. id parent_id level
  599. 1002 100 0
  600. 1004 101 1
  601. 1005 101 1
  602. 1009 102 2
  603. 1025 102 2
  604. 1018 103 2
  605. 1023 104 2
  606. 1025 104 2
  607. 1029 105 2
  608. 1030 105 2
  609. 1031 105 2
  610. 1032 106 2
  611. 1033 106 2
  612. 1034 106 2
  613. 1204 107 2
  614. 1203 107 2
  615. 1021 103 2
  616. 1158 100 0
  617. 1194 105 2
  618. 1041 107 2
  619. 1003 101 1
  620. 1016 102 2
  621. 1007 101 1
  622. 1035 106 2
  623. 1036 106 2
  624. 1017 103 2
  625. 1008 101 1
  626. 1037 107 2
  627. 1019 103 2
  628. 1027 105 2
  629. 1028 105 2
  630. 1184 104 2
  631. 1039 107 2
  632. 1026 105 2
  633. 1038 107 2
  634. 1022 104 2
  635. 1020 103 2
  636. 1006 101 1
  637. 1180 105 2
  638. update ignore t1 set id=1023 where id=1010;
  639. select * from t1 where parent_id=102;
  640. id parent_id level
  641. 1009 102 2
  642. 1025 102 2
  643. 1016 102 2
  644. explain select level from t1 where level=1;
  645. id select_type table type possible_keys key key_len ref rows Extra
  646. 1 SIMPLE t1 ref level level 1 const # Using index
  647. select level,id from t1 where level=1;
  648. level id
  649. 1 1004
  650. 1 1005
  651. 1 1003
  652. 1 1007
  653. 1 1008
  654. 1 1006
  655. select level,id,parent_id from t1 where level=1;
  656. level id parent_id
  657. 1 1004 101
  658. 1 1005 101
  659. 1 1003 101
  660. 1 1007 101
  661. 1 1008 101
  662. 1 1006 101
  663. select level,id from t1 where level=1 order by id;
  664. level id
  665. 1 1003
  666. 1 1004
  667. 1 1005
  668. 1 1006
  669. 1 1007
  670. 1 1008
  671. delete from t1 where level=1;
  672. select * from t1;
  673. id parent_id level
  674. 1002 100 0
  675. 1009 102 2
  676. 1025 102 2
  677. 1018 103 2
  678. 1023 104 2
  679. 1025 104 2
  680. 1029 105 2
  681. 1030 105 2
  682. 1031 105 2
  683. 1032 106 2
  684. 1033 106 2
  685. 1034 106 2
  686. 1204 107 2
  687. 1203 107 2
  688. 1021 103 2
  689. 1158 100 0
  690. 1194 105 2
  691. 1041 107 2
  692. 1016 102 2
  693. 1035 106 2
  694. 1036 106 2
  695. 1017 103 2
  696. 1037 107 2
  697. 1019 103 2
  698. 1027 105 2
  699. 1028 105 2
  700. 1184 104 2
  701. 1039 107 2
  702. 1026 105 2
  703. 1038 107 2
  704. 1022 104 2
  705. 1020 103 2
  706. 1180 105 2
  707. drop table t1;
  708. CREATE TABLE t1 (
  709. sca_code char(6) NOT NULL,
  710. cat_code char(6) NOT NULL,
  711. sca_desc varchar(50),
  712. lan_code char(2) NOT NULL,
  713. sca_pic varchar(100),
  714. sca_sdesc varchar(50),
  715. sca_sch_desc varchar(16),
  716. PRIMARY KEY (sca_code, cat_code, lan_code),
  717. INDEX sca_pic (sca_pic)
  718. ) engine = innodb ;
  719. INSERT INTO t1 ( sca_code, cat_code, sca_desc, lan_code, sca_pic, sca_sdesc, sca_sch_desc) VALUES ( 'PD', 'J', 'PENDANT', 'EN', NULL, NULL, 'PENDANT'),( 'RI', 'J', 'RING', 'EN', NULL, NULL, 'RING'),( 'QQ', 'N', 'RING', 'EN', 'not null', NULL, 'RING');
  720. select count(*) from t1 where sca_code = 'PD';
  721. count(*)
  722. 1
  723. select count(*) from t1 where sca_code <= 'PD';
  724. count(*)
  725. 1
  726. select count(*) from t1 where sca_pic is null;
  727. count(*)
  728. 2
  729. alter table t1 drop index sca_pic, add index sca_pic (cat_code, sca_pic);
  730. select count(*) from t1 where sca_code='PD' and sca_pic is null;
  731. count(*)
  732. 1
  733. select count(*) from t1 where cat_code='E';
  734. count(*)
  735. 0
  736. alter table t1 drop index sca_pic, add index (sca_pic, cat_code);
  737. select count(*) from t1 where sca_code='PD' and sca_pic is null;
  738. count(*)
  739. 1
  740. select count(*) from t1 where sca_pic >= 'n';
  741. count(*)
  742. 1
  743. select sca_pic from t1 where sca_pic is null;
  744. sca_pic
  745. NULL
  746. NULL
  747. update t1 set sca_pic="test" where sca_pic is null;
  748. delete from t1 where sca_code='pd';
  749. drop table t1;
  750. set @a:=now();
  751. CREATE TABLE t1 (a int not null, b timestamp not null, primary key (a)) engine=innodb;
  752. insert into t1 (a) values(1),(2),(3);
  753. select t1.a from t1 natural join t1 as t2 where t1.b >= @a order by t1.a;
  754. a
  755. 1
  756. 2
  757. 3
  758. select a from t1 natural join t1 as t2 where b >= @a order by a;
  759. a
  760. 1
  761. 2
  762. 3
  763. update t1 set a=5 where a=1;
  764. select a from t1;
  765. a
  766. 2
  767. 3
  768. 5
  769. drop table t1;
  770. create table t1 (a varchar(100) not null, primary key(a), b int not null) engine=innodb;
  771. insert into t1 values("hello",1),("world",2);
  772. select * from t1 order by b desc;
  773. a b
  774. world 2
  775. hello 1
  776. optimize table t1;
  777. Table Op Msg_type Msg_text
  778. test.t1 optimize status OK
  779. show keys from t1;
  780. Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
  781. t1 0 PRIMARY 1 a A # NULL NULL BTREE
  782. drop table t1;
  783. create table t1 (i int, j int ) ENGINE=innodb;
  784. insert into t1 values (1,2);
  785. select * from t1 where i=1 and j=2;
  786. i j
  787. 1 2
  788. create index ax1 on t1 (i,j);
  789. select * from t1 where i=1 and j=2;
  790. i j
  791. 1 2
  792. drop table t1;
  793. CREATE TABLE t1 (
  794. a int3 unsigned NOT NULL,
  795. b int1 unsigned NOT NULL,
  796. UNIQUE (a, b)
  797. ) ENGINE = innodb;
  798. INSERT INTO t1 VALUES (1, 1);
  799. SELECT MIN(B),MAX(b) FROM t1 WHERE t1.a = 1;
  800. MIN(B) MAX(b)
  801. 1 1
  802. drop table t1;
  803. CREATE TABLE t1 (a int unsigned NOT NULL) engine=innodb;
  804. INSERT INTO t1 VALUES (1);
  805. SELECT * FROM t1;
  806. a
  807. 1
  808. DROP TABLE t1;
  809. create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, a1 int, a2 int, a3 int, a4 int, a5 int, a6 int, a7 int, a8 int, a9 int, b1 int, b2 int, b3 int, b4 int, b5 int, b6 int) engine = innodb;
  810. insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);
  811. explain select * from t1 where a > 0 and a < 50;
  812. id select_type table type possible_keys key key_len ref rows Extra
  813. 1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where
  814. drop table t1;
  815. create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
  816. insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
  817. LOCK TABLES t1 WRITE;
  818. insert into t1 values (99,1,2,'D'),(1,1,2,'D');
  819. ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
  820. select id from t1;
  821. id
  822. 0
  823. 1
  824. 2
  825. select id from t1;
  826. id
  827. 0
  828. 1
  829. 2
  830. UNLOCK TABLES;
  831. DROP TABLE t1;
  832. create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb;
  833. insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL');
  834. LOCK TABLES t1 WRITE;
  835. begin;
  836. insert into t1 values (99,1,2,'D'),(1,1,2,'D');
  837. ERROR 23000: Duplicate entry '1-1' for key 'PRIMARY'
  838. select id from t1;
  839. id
  840. 0
  841. 1
  842. 2
  843. insert ignore into t1 values (100,1,2,'D'),(1,1,99,'D');
  844. commit;
  845. select id,id3 from t1;
  846. id id3
  847. 0 0
  848. 1 1
  849. 2 2
  850. 100 2
  851. UNLOCK TABLES;
  852. DROP TABLE t1;
  853. create table t1 (a char(20), unique (a(5))) engine=innodb;
  854. drop table t1;
  855. create table t1 (a char(20), index (a(5))) engine=innodb;
  856. show create table t1;
  857. Table Create Table
  858. t1 CREATE TABLE `t1` (
  859. `a` char(20) DEFAULT NULL,
  860. KEY `a` (`a`(5))
  861. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  862. drop table t1;
  863. create temporary table t1 (a int not null auto_increment, primary key(a)) engine=innodb;
  864. insert into t1 values (NULL),(NULL),(NULL);
  865. delete from t1 where a=3;
  866. insert into t1 values (NULL);
  867. select * from t1;
  868. a
  869. 1
  870. 2
  871. 4
  872. alter table t1 add b int;
  873. select * from t1;
  874. a b
  875. 1 NULL
  876. 2 NULL
  877. 4 NULL
  878. drop table t1;
  879. create table t1
  880. (
  881. id int auto_increment primary key,
  882. name varchar(32) not null,
  883. value text not null,
  884. uid int not null,
  885. unique key(name,uid)
  886. ) engine=innodb;
  887. insert into t1 values (1,'one','one value',101),
  888. (2,'two','two value',102),(3,'three','three value',103);
  889. set insert_id=5;
  890. replace into t1 (value,name,uid) values ('other value','two',102);
  891. delete from t1 where uid=102;
  892. set insert_id=5;
  893. replace into t1 (value,name,uid) values ('other value','two',102);
  894. set insert_id=6;
  895. replace into t1 (value,name,uid) values ('other value','two',102);
  896. select * from t1;
  897. id name value uid
  898. 1 one one value 101
  899. 3 three three value 103
  900. 6 two other value 102
  901. drop table t1;
  902. create database mysqltest;
  903. create table mysqltest.t1 (a int not null) engine= innodb;
  904. insert into mysqltest.t1 values(1);
  905. create table mysqltest.t2 (a int not null) engine= myisam;
  906. insert into mysqltest.t2 values(1);
  907. create table mysqltest.t3 (a int not null) engine= heap;
  908. insert into mysqltest.t3 values(1);
  909. commit;
  910. drop database mysqltest;
  911. show tables from mysqltest;
  912. ERROR 42000: Unknown database 'mysqltest'
  913. set autocommit=0;
  914. create table t1 (a int not null) engine= innodb;
  915. insert into t1 values(1),(2);
  916. truncate table t1;
  917. commit;
  918. truncate table t1;
  919. truncate table t1;
  920. select * from t1;
  921. a
  922. insert into t1 values(1),(2);
  923. delete from t1;
  924. select * from t1;
  925. a
  926. commit;
  927. drop table t1;
  928. set autocommit=1;
  929. create table t1 (a int not null) engine= innodb;
  930. insert into t1 values(1),(2);
  931. truncate table t1;
  932. insert into t1 values(1),(2);
  933. select * from t1;
  934. a
  935. 1
  936. 2
  937. truncate table t1;
  938. insert into t1 values(1),(2);
  939. delete from t1;
  940. select * from t1;
  941. a
  942. drop table t1;
  943. create table t1 (a int not null, b int not null, c int not null, primary key (a),key(b)) engine=innodb;
  944. insert into t1 values (3,3,3),(1,1,1),(2,2,2),(4,4,4);
  945. explain select * from t1 order by a;
  946. id select_type table type possible_keys key key_len ref rows Extra
  947. 1 SIMPLE t1 index NULL PRIMARY 4 NULL #
  948. explain select * from t1 order by b;
  949. id select_type table type possible_keys key key_len ref rows Extra
  950. 1 SIMPLE t1 index NULL b 4 NULL #
  951. explain select * from t1 order by c;
  952. id select_type table type possible_keys key key_len ref rows Extra
  953. 1 SIMPLE t1 ALL NULL NULL NULL NULL # Using filesort
  954. explain select a from t1 order by a;
  955. id select_type table type possible_keys key key_len ref rows Extra
  956. 1 SIMPLE t1 index NULL PRIMARY 4 NULL # Using index
  957. explain select b from t1 order by b;
  958. id select_type table type possible_keys key key_len ref rows Extra
  959. 1 SIMPLE t1 index NULL b 4 NULL # Using index
  960. explain select a,b from t1 order by b;
  961. id select_type table type possible_keys key key_len ref rows Extra
  962. 1 SIMPLE t1 index NULL b 4 NULL # Using index
  963. explain select a,b from t1;
  964. id select_type table type possible_keys key key_len ref rows Extra
  965. 1 SIMPLE t1 index NULL b 4 NULL # Using index
  966. explain select a,b,c from t1;
  967. id select_type table type possible_keys key key_len ref rows Extra
  968. 1 SIMPLE t1 ALL NULL NULL NULL NULL #
  969. drop table t1;
  970. create table t1 (t int not null default 1, key (t)) engine=innodb;
  971. desc t1;
  972. Field Type Null Key Default Extra
  973. t int(11) NO MUL 1
  974. drop table t1;
  975. CREATE TABLE t1 (
  976. number bigint(20) NOT NULL default '0',
  977. cname char(15) NOT NULL default '',
  978. carrier_id smallint(6) NOT NULL default '0',
  979. privacy tinyint(4) NOT NULL default '0',
  980. last_mod_date timestamp NOT NULL,
  981. last_mod_id smallint(6) NOT NULL default '0',
  982. last_app_date timestamp NOT NULL,
  983. last_app_id smallint(6) default '-1',
  984. version smallint(6) NOT NULL default '0',
  985. assigned_scps int(11) default '0',
  986. status tinyint(4) default '0'
  987. ) ENGINE=InnoDB;
  988. INSERT INTO t1 VALUES (4077711111,'SeanWheeler',90,2,20020111112846,500,00000000000000,-1,2,3,1);
  989. INSERT INTO t1 VALUES (9197722223,'berry',90,3,20020111112809,500,20020102114532,501,4,10,0);
  990. INSERT INTO t1 VALUES (650,'San Francisco',0,0,20011227111336,342,00000000000000,-1,1,24,1);
  991. INSERT INTO t1 VALUES (302467,'Sue\'s Subshop',90,3,20020109113241,500,20020102115111,501,7,24,0);
  992. INSERT INTO t1 VALUES (6014911113,'SudzCarwash',520,1,20020102115234,500,20020102115259,501,33,32768,0);
  993. INSERT INTO t1 VALUES (333,'tubs',99,2,20020109113440,501,20020109113440,500,3,10,0);
  994. CREATE TABLE t2 (
  995. number bigint(20) NOT NULL default '0',
  996. cname char(15) NOT NULL default '',
  997. carrier_id smallint(6) NOT NULL default '0',
  998. privacy tinyint(4) NOT NULL default '0',
  999. last_mod_date timestamp NOT NULL,
  1000. last_mod_id smallint(6) NOT NULL default '0',
  1001. last_app_date timestamp NOT NULL,
  1002. last_app_id smallint(6) default '-1',
  1003. version smallint(6) NOT NULL default '0',
  1004. assigned_scps int(11) default '0',
  1005. status tinyint(4) default '0'
  1006. ) ENGINE=InnoDB;
  1007. INSERT INTO t2 VALUES (4077711111,'SeanWheeler',0,2,20020111112853,500,00000000000000,-1,2,3,1);
  1008. INSERT INTO t2 VALUES (9197722223,'berry',90,3,20020111112818,500,20020102114532,501,4,10,0);
  1009. INSERT INTO t2 VALUES (650,'San Francisco',90,0,20020109113158,342,00000000000000,-1,1,24,1);
  1010. INSERT INTO t2 VALUES (333,'tubs',99,2,20020109113453,501,20020109113453,500,3,10,0);
  1011. select * from t1;
  1012. number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
  1013. 4077711111 SeanWheeler 90 2 2002-01-11 11:28:46 500 0000-00-00 00:00:00 -1 2 3 1
  1014. 9197722223 berry 90 3 2002-01-11 11:28:09 500 2002-01-02 11:45:32 501 4 10 0
  1015. 650 San Francisco 0 0 2001-12-27 11:13:36 342 0000-00-00 00:00:00 -1 1 24 1
  1016. 302467 Sue's Subshop 90 3 2002-01-09 11:32:41 500 2002-01-02 11:51:11 501 7 24 0
  1017. 6014911113 SudzCarwash 520 1 2002-01-02 11:52:34 500 2002-01-02 11:52:59 501 33 32768 0
  1018. 333 tubs 99 2 2002-01-09 11:34:40 501 2002-01-09 11:34:40 500 3 10 0
  1019. select * from t2;
  1020. number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
  1021. 4077711111 SeanWheeler 0 2 2002-01-11 11:28:53 500 0000-00-00 00:00:00 -1 2 3 1
  1022. 9197722223 berry 90 3 2002-01-11 11:28:18 500 2002-01-02 11:45:32 501 4 10 0
  1023. 650 San Francisco 90 0 2002-01-09 11:31:58 342 0000-00-00 00:00:00 -1 1 24 1
  1024. 333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
  1025. delete t1, t2 from t1 left join t2 on t1.number=t2.number where (t1.carrier_id=90 and t1.number=t2.number) or (t2.carrier_id=90 and t1.number=t2.number) or (t1.carrier_id=90 and t2.number is null);
  1026. select * from t1;
  1027. number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
  1028. 6014911113 SudzCarwash 520 1 2002-01-02 11:52:34 500 2002-01-02 11:52:59 501 33 32768 0
  1029. 333 tubs 99 2 2002-01-09 11:34:40 501 2002-01-09 11:34:40 500 3 10 0
  1030. select * from t2;
  1031. number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
  1032. 333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
  1033. select * from t2;
  1034. number cname carrier_id privacy last_mod_date last_mod_id last_app_date last_app_id version assigned_scps status
  1035. 333 tubs 99 2 2002-01-09 11:34:53 501 2002-01-09 11:34:53 500 3 10 0
  1036. drop table t1,t2;
  1037. create table t1 (id int unsigned not null auto_increment, code tinyint unsigned not null, name char(20) not null, primary key (id), key (code), unique (name)) engine=innodb;
  1038. BEGIN;
  1039. SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  1040. SELECT @@tx_isolation,@@global.tx_isolation;
  1041. @@tx_isolation @@global.tx_isolation
  1042. SERIALIZABLE REPEATABLE-READ
  1043. insert into t1 (code, name) values (1, 'Tim'), (1, 'Monty'), (2, 'David');
  1044. select id, code, name from t1 order by id;
  1045. id code name
  1046. 1 1 Tim
  1047. 2 1 Monty
  1048. 3 2 David
  1049. COMMIT;
  1050. BEGIN;
  1051. SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
  1052. insert into t1 (code, name) values (2, 'Erik'), (3, 'Sasha');
  1053. select id, code, name from t1 order by id;
  1054. id code name
  1055. 1 1 Tim
  1056. 2 1 Monty
  1057. 3 2 David
  1058. 4 2 Erik
  1059. 5 3 Sasha
  1060. COMMIT;
  1061. BEGIN;
  1062. SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
  1063. insert into t1 (code, name) values (3, 'Jeremy'), (4, 'Matt');
  1064. select id, code, name from t1 order by id;
  1065. id code name
  1066. 1 1 Tim
  1067. 2 1 Monty
  1068. 3 2 David
  1069. 4 2 Erik
  1070. 5 3 Sasha
  1071. 6 3 Jeremy
  1072. 7 4 Matt
  1073. COMMIT;
  1074. DROP TABLE t1;
  1075. create table t1 (n int(10), d int(10)) engine=innodb;
  1076. create table t2 (n int(10), d int(10)) engine=innodb;
  1077. insert into t1 values(1,1),(1,2);
  1078. insert into t2 values(1,10),(2,20);
  1079. UPDATE t1,t2 SET t1.d=t2.d,t2.d=30 WHERE t1.n=t2.n;
  1080. select * from t1;
  1081. n d
  1082. 1 10
  1083. 1 10
  1084. select * from t2;
  1085. n d
  1086. 1 30
  1087. 2 20
  1088. drop table t1,t2;
  1089. create table t1 (a int, b int) engine=innodb;
  1090. insert into t1 values(20,null);
  1091. select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
  1092. t2.b=t3.a;
  1093. b ifnull(t2.b,"this is null")
  1094. NULL this is null
  1095. select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
  1096. t2.b=t3.a order by 1;
  1097. b ifnull(t2.b,"this is null")
  1098. NULL this is null
  1099. insert into t1 values(10,null);
  1100. select t2.b, ifnull(t2.b,"this is null") from t1 as t2 left join t1 as t3 on
  1101. t2.b=t3.a order by 1;
  1102. b ifnull(t2.b,"this is null")
  1103. NULL this is null
  1104. NULL this is null
  1105. drop table t1;
  1106. create table t1 (a varchar(10) not null) engine=myisam;
  1107. create table t2 (b varchar(10) not null unique) engine=innodb;
  1108. select t1.a from t1,t2 where t1.a=t2.b;
  1109. a
  1110. drop table t1,t2;
  1111. create table t1 (a int not null, b int, primary key (a)) engine = innodb;
  1112. create table t2 (a int not null, b int, primary key (a)) engine = innodb;
  1113. insert into t1 values (10, 20);
  1114. insert into t2 values (10, 20);
  1115. update t1, t2 set t1.b = 150, t2.b = t1.b where t2.a = t1.a and t1.a = 10;
  1116. drop table t1,t2;
  1117. CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
  1118. CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE ) ENGINE=INNODB;
  1119. insert into t1 set id=1;
  1120. insert into t2 set id=1, t1_id=1;
  1121. delete t1,t2 from t1,t2 where t1.id=t2.t1_id;
  1122. select * from t1;
  1123. id
  1124. select * from t2;
  1125. id t1_id
  1126. drop table t2,t1;
  1127. CREATE TABLE t1(id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
  1128. CREATE TABLE t2(id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id) ) ENGINE=INNODB;
  1129. INSERT INTO t1 VALUES(1);
  1130. INSERT INTO t2 VALUES(1, 1);
  1131. SELECT * from t1;
  1132. id
  1133. 1
  1134. UPDATE t1,t2 SET t1.id=t1.id+1, t2.t1_id=t1.id+1;
  1135. SELECT * from t1;
  1136. id
  1137. 2
  1138. UPDATE t1,t2 SET t1.id=t1.id+1 where t1.id!=t2.id;
  1139. SELECT * from t1;
  1140. id
  1141. 3
  1142. DROP TABLE t1,t2;
  1143. set autocommit=0;
  1144. CREATE TABLE t1 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
  1145. CREATE TABLE t2 (id CHAR(15) NOT NULL, value CHAR(40) NOT NULL, PRIMARY KEY(id)) ENGINE=InnoDB;
  1146. CREATE TABLE t3 (id1 CHAR(15) NOT NULL, id2 CHAR(15) NOT NULL, PRIMARY KEY(id1, id2)) ENGINE=InnoDB;
  1147. INSERT INTO t3 VALUES("my-test-1", "my-test-2");
  1148. COMMIT;
  1149. INSERT INTO t1 VALUES("this-key", "will disappear");
  1150. INSERT INTO t2 VALUES("this-key", "will also disappear");
  1151. DELETE FROM t3 WHERE id1="my-test-1";
  1152. SELECT * FROM t1;
  1153. id value
  1154. this-key will disappear
  1155. SELECT * FROM t2;
  1156. id value
  1157. this-key will also disappear
  1158. SELECT * FROM t3;
  1159. id1 id2
  1160. ROLLBACK;
  1161. SELECT * FROM t1;
  1162. id value
  1163. SELECT * FROM t2;
  1164. id value
  1165. SELECT * FROM t3;
  1166. id1 id2
  1167. my-test-1 my-test-2
  1168. SELECT * FROM t3 WHERE id1="my-test-1" LOCK IN SHARE MODE;
  1169. id1 id2
  1170. my-test-1 my-test-2
  1171. COMMIT;
  1172. set autocommit=1;
  1173. DROP TABLE t1,t2,t3;
  1174. CREATE TABLE t1 (a int not null primary key, b int not null, unique (b)) engine=innodb;
  1175. INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
  1176. UPDATE t1 set a=a+100 where b between 2 and 3 and a < 1000;
  1177. SELECT * from t1;
  1178. a b
  1179. 1 1
  1180. 102 2
  1181. 103 3
  1182. 4 4
  1183. 5 5
  1184. 6 6
  1185. 7 7
  1186. 8 8
  1187. 9 9
  1188. drop table t1;
  1189. CREATE TABLE t1 (a int not null primary key, b int not null, key (b)) engine=innodb;
  1190. CREATE TABLE t2 (a int not null primary key, b int not null, key (b)) engine=innodb;
  1191. INSERT INTO t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12);
  1192. INSERT INTO t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
  1193. update t1,t2 set t1.a=t1.a+100;
  1194. select * from t1;
  1195. a b
  1196. 101 1
  1197. 102 2
  1198. 103 3
  1199. 104 4
  1200. 105 5
  1201. 106 6
  1202. 107 7
  1203. 108 8
  1204. 109 9
  1205. 110 10
  1206. 111 11
  1207. 112 12
  1208. update t1,t2 set t1.a=t1.a+100 where t1.a=101;
  1209. select * from t1;
  1210. a b
  1211. 201 1
  1212. 102 2
  1213. 103 3
  1214. 104 4
  1215. 105 5
  1216. 106 6
  1217. 107 7
  1218. 108 8
  1219. 109 9
  1220. 110 10
  1221. 111 11
  1222. 112 12
  1223. update t1,t2 set t1.b=t1.b+10 where t1.b=2;
  1224. select * from t1;
  1225. a b
  1226. 201 1
  1227. 103 3
  1228. 104 4
  1229. 105 5
  1230. 106 6
  1231. 107 7
  1232. 108 8
  1233. 109 9
  1234. 110 10
  1235. 111 11
  1236. 102 12
  1237. 112 12
  1238. update t1,t2 set t1.b=t1.b+2,t2.b=t1.b+10 where t1.b between 3 and 5 and t1.a=t2.a+100;
  1239. select * from t1;
  1240. a b
  1241. 201 1
  1242. 103 5
  1243. 104 6
  1244. 106 6
  1245. 105 7
  1246. 107 7
  1247. 108 8
  1248. 109 9
  1249. 110 10
  1250. 111 11
  1251. 102 12
  1252. 112 12
  1253. select * from t2;
  1254. a b
  1255. 1 1
  1256. 2 2
  1257. 6 6
  1258. 7 7
  1259. 8 8
  1260. 9 9
  1261. 3 13
  1262. 4 14
  1263. 5 15
  1264. drop table t1,t2;
  1265. CREATE TABLE t2 ( NEXT_T BIGINT NOT NULL PRIMARY KEY) ENGINE=MyISAM;
  1266. CREATE TABLE t1 ( B_ID INTEGER NOT NULL PRIMARY KEY) ENGINE=InnoDB;
  1267. SET AUTOCOMMIT=0;
  1268. INSERT INTO t1 ( B_ID ) VALUES ( 1 );
  1269. INSERT INTO t2 ( NEXT_T ) VALUES ( 1 );
  1270. ROLLBACK;
  1271. Warnings:
  1272. Warning 1196 Some non-transactional changed tables couldn't be rolled back
  1273. SELECT * FROM t1;
  1274. B_ID
  1275. drop table t1,t2;
  1276. create table t1 ( pk int primary key, parent int not null, child int not null, index (parent) ) engine = innodb;
  1277. insert into t1 values (1,0,4), (2,1,3), (3,2,1), (4,1,2);
  1278. select distinct parent,child from t1 order by parent;
  1279. parent child
  1280. 0 4
  1281. 1 2
  1282. 1 3
  1283. 2 1
  1284. drop table t1;
  1285. create table t1 (a int not null auto_increment primary key, b int, c int, key(c)) engine=innodb;
  1286. create table t2 (a int not null auto_increment primary key, b int);
  1287. insert into t1 (b) values (null),(null),(null),(null),(null),(null),(null);
  1288. insert into t2 (a) select b from t1;
  1289. insert into t1 (b) select b from t2;
  1290. insert into t2 (a) select b from t1;
  1291. insert into t1 (a) select b from t2;
  1292. insert into t2 (a) select b from t1;
  1293. insert into t1 (a) select b from t2;
  1294. insert into t2 (a) select b from t1;
  1295. insert into t1 (a) select b from t2;
  1296. insert into t2 (a) select b from t1;
  1297. insert into t1 (a) select b from t2;
  1298. select count(*) from t1;
  1299. count(*)
  1300. 623
  1301. explain select * from t1 where c between 1 and 2500;
  1302. id select_type table type possible_keys key key_len ref rows Extra
  1303. 1 SIMPLE t1 range c c 5 NULL # Using where
  1304. update t1 set c=a;
  1305. explain select * from t1 where c between 1 and 2500;
  1306. id select_type table type possible_keys key key_len ref rows Extra
  1307. 1 SIMPLE t1 ALL c NULL NULL NULL # Using where
  1308. drop table t1,t2;
  1309. create table t1 (id int primary key auto_increment, fk int, index index_fk (fk)) engine=innodb;
  1310. insert into t1 (id) values (null),(null),(null),(null),(null);
  1311. update t1 set fk=69 where fk is null order by id limit 1;
  1312. SELECT * from t1;
  1313. id fk
  1314. 2 NULL
  1315. 3 NULL
  1316. 4 NULL
  1317. 5 NULL
  1318. 1 69
  1319. drop table t1;
  1320. create table t1 (a int not null, b int not null, key (a));
  1321. insert into t1 values (1,1),(1,2),(1,3),(3,1),(3,2),(3,3),(3,1),(3,2),(3,3),(2,1),(2,2),(2,3);
  1322. SET @tmp=0;
  1323. update t1 set b=(@tmp:=@tmp+1) order by a;
  1324. update t1 set b=99 where a=1 order by b asc limit 1;
  1325. update t1 set b=100 where a=1 order by b desc limit 2;
  1326. update t1 set a=a+10+b where a=1 order by b;
  1327. select * from t1 order by a,b;
  1328. a b
  1329. 2 4
  1330. 2 5
  1331. 2 6
  1332. 3 7
  1333. 3 8
  1334. 3 9
  1335. 3 10
  1336. 3 11
  1337. 3 12
  1338. 13 2
  1339. 111 100
  1340. 111 100
  1341. drop table t1;
  1342. create table t1 ( c char(8) not null ) engine=innodb;
  1343. insert into t1 values ('0'),('1'),('2'),('3'),('4'),('5'),('6'),('7'),('8'),('9');
  1344. insert into t1 values ('A'),('B'),('C'),('D'),('E'),('F');
  1345. alter table t1 add b char(8) not null;
  1346. alter table t1 add a char(8) not null;
  1347. alter table t1 add primary key (a,b,c);
  1348. update t1 set a=c, b=c;
  1349. create table t2 (c char(8) not null, b char(8) not null, a char(8) not null, primary key(a,b,c)) engine=innodb;
  1350. insert into t2 select * from t1;
  1351. delete t1,t2 from t2,t1 where t1.a<'B' and t2.b=t1.b;
  1352. drop table t1,t2;
  1353. SET AUTOCOMMIT=1;
  1354. create table t1 (a integer auto_increment primary key) engine=innodb;
  1355. insert into t1 (a) values (NULL),(NULL);
  1356. truncate table t1;
  1357. insert into t1 (a) values (NULL),(NULL);
  1358. SELECT * from t1;
  1359. a
  1360. 1
  1361. 2
  1362. drop table t1;
  1363. CREATE TABLE t1 (`id 1` INT NOT NULL, PRIMARY KEY (`id 1`)) ENGINE=INNODB;
  1364. CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id), FOREIGN KEY (`t1_id`) REFERENCES `t1`(`id 1`) ON DELETE CASCADE ) ENGINE=INNODB;
  1365. drop table t2,t1;
  1366. create table `t1` (`id` int( 11 ) not null ,primary key ( `id` )) engine = innodb;
  1367. insert into `t1`values ( 1 ) ;
  1368. create table `t2` (`id` int( 11 ) not null default '0',unique key `id` ( `id` ) ,constraint `t1_id_fk` foreign key ( `id` ) references `t1` (`id` )) engine = innodb;
  1369. insert into `t2`values ( 1 ) ;
  1370. create table `t3` (`id` int( 11 ) not null default '0',key `id` ( `id` ) ,constraint `t2_id_fk` foreign key ( `id` ) references `t2` (`id` )) engine = innodb;
  1371. insert into `t3`values ( 1 ) ;
  1372. delete t3,t2,t1 from t1,t2,t3 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
  1373. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))
  1374. update t1,t2,t3 set t3.id=5, t2.id=6, t1.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
  1375. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`))
  1376. update t3 set t3.id=7 where t1.id =1 and t2.id = t1.id and t3.id = t2.id;
  1377. ERROR 42S22: Unknown column 't1.id' in 'where clause'
  1378. drop table t3,t2,t1;
  1379. create table t1(
  1380. id int primary key,
  1381. pid int,
  1382. index(pid),
  1383. foreign key(pid) references t1(id) on delete cascade) engine=innodb;
  1384. insert into t1 values(0,0),(1,0),(2,1),(3,2),(4,3),(5,4),(6,5),(7,6),
  1385. (8,7),(9,8),(10,9),(11,10),(12,11),(13,12),(14,13),(15,14);
  1386. delete from t1 where id=0;
  1387. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `t1` (`id`) ON DELETE CASCADE)
  1388. delete from t1 where id=15;
  1389. delete from t1 where id=0;
  1390. drop table t1;
  1391. CREATE TABLE t1 (col1 int(1))ENGINE=InnoDB;
  1392. CREATE TABLE t2 (col1 int(1),stamp TIMESTAMP,INDEX stamp_idx
  1393. (stamp))ENGINE=InnoDB;
  1394. insert into t1 values (1),(2),(3);
  1395. insert into t2 values (1, 20020204130000),(2, 20020204130000),(4,20020204310000 ),(5,20020204230000);
  1396. Warnings:
  1397. Warning 1265 Data truncated for column 'stamp' at row 3
  1398. SELECT col1 FROM t1 UNION SELECT col1 FROM t2 WHERE stamp <
  1399. '20020204120000' GROUP BY col1;
  1400. col1
  1401. 1
  1402. 2
  1403. 3
  1404. 4
  1405. drop table t1,t2;
  1406. CREATE TABLE t1 (
  1407. `id` int(10) unsigned NOT NULL auto_increment,
  1408. `id_object` int(10) unsigned default '0',
  1409. `id_version` int(10) unsigned NOT NULL default '1',
  1410. `label` varchar(100) NOT NULL default '',
  1411. `description` text,
  1412. PRIMARY KEY (`id`),
  1413. KEY `id_object` (`id_object`),
  1414. KEY `id_version` (`id_version`)
  1415. ) ENGINE=InnoDB;
  1416. INSERT INTO t1 VALUES("6", "3382", "9", "Test", NULL), ("7", "102", "5", "Le Pekin (Test)", NULL),("584", "1794", "4", "Test de resto", NULL),("837", "1822", "6", "Test 3", NULL),("1119", "3524", "1", "Societe Test", NULL),("1122", "3525", "1", "Fournisseur Test", NULL);
  1417. CREATE TABLE t2 (
  1418. `id` int(10) unsigned NOT NULL auto_increment,
  1419. `id_version` int(10) unsigned NOT NULL default '1',
  1420. PRIMARY KEY (`id`),
  1421. KEY `id_version` (`id_version`)
  1422. ) ENGINE=InnoDB;
  1423. INSERT INTO t2 VALUES("3524", "1"),("3525", "1"),("1794", "4"),("102", "5"),("1822", "6"),("3382", "9");
  1424. SELECT t2.id, t1.`label` FROM t2 INNER JOIN
  1425. (SELECT t1.id_object as id_object FROM t1 WHERE t1.`label` LIKE '%test%') AS lbl
  1426. ON (t2.id = lbl.id_object) INNER JOIN t1 ON (t2.id = t1.id_object);
  1427. id label
  1428. 3382 Test
  1429. 102 Le Pekin (Test)
  1430. 1794 Test de resto
  1431. 1822 Test 3
  1432. 3524 Societe Test
  1433. 3525 Fournisseur Test
  1434. drop table t1,t2;
  1435. create table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
  1436. create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
  1437. create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
  1438. insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
  1439. insert t2 select * from t1;
  1440. insert t3 select * from t1;
  1441. checksum table t1, t2, t3, t4 quick;
  1442. Table Checksum
  1443. test.t1 2948697075
  1444. test.t2 NULL
  1445. test.t3 NULL
  1446. test.t4 NULL
  1447. Warnings:
  1448. Error 1146 Table 'test.t4' doesn't exist
  1449. checksum table t1, t2, t3, t4;
  1450. Table Checksum
  1451. test.t1 2948697075
  1452. test.t2 2948697075
  1453. test.t3 2948697075
  1454. test.t4 NULL
  1455. Warnings:
  1456. Error 1146 Table 'test.t4' doesn't exist
  1457. checksum table t1, t2, t3, t4 extended;
  1458. Table Checksum
  1459. test.t1 2948697075
  1460. test.t2 2948697075
  1461. test.t3 2948697075
  1462. test.t4 NULL
  1463. Warnings:
  1464. Error 1146 Table 'test.t4' doesn't exist
  1465. drop table t1,t2,t3;
  1466. create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
  1467. insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
  1468. select trim(name2) from t1 union all select trim(name) from t1 union all select trim(id) from t1;
  1469. trim(name2)
  1470. fff
  1471. sss
  1472. ttt
  1473. first
  1474. second
  1475. third
  1476. 1
  1477. 2
  1478. 3
  1479. drop table t1;
  1480. create table t1 (a int) engine=innodb;
  1481. create table t2 like t1;
  1482. drop table t1,t2;
  1483. create table t1 (id int(11) not null, id2 int(11) not null, unique (id,id2)) engine=innodb;
  1484. create table t2 (id int(11) not null, constraint t1_id_fk foreign key ( id ) references t1 (id)) engine = innodb;
  1485. show create table t1;
  1486. Table Create Table
  1487. t1 CREATE TABLE `t1` (
  1488. `id` int(11) NOT NULL,
  1489. `id2` int(11) NOT NULL,
  1490. UNIQUE KEY `id` (`id`,`id2`)
  1491. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1492. show create table t2;
  1493. Table Create Table
  1494. t2 CREATE TABLE `t2` (
  1495. `id` int(11) NOT NULL,
  1496. KEY `t1_id_fk` (`id`),
  1497. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1498. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1499. create index id on t2 (id);
  1500. show create table t2;
  1501. Table Create Table
  1502. t2 CREATE TABLE `t2` (
  1503. `id` int(11) NOT NULL,
  1504. KEY `id` (`id`),
  1505. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1506. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1507. create index id2 on t2 (id);
  1508. show create table t2;
  1509. Table Create Table
  1510. t2 CREATE TABLE `t2` (
  1511. `id` int(11) NOT NULL,
  1512. KEY `id` (`id`),
  1513. KEY `id2` (`id`),
  1514. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1515. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1516. drop index id2 on t2;
  1517. drop index id on t2;
  1518. Got one of the listed errors
  1519. show create table t2;
  1520. Table Create Table
  1521. t2 CREATE TABLE `t2` (
  1522. `id` int(11) NOT NULL,
  1523. KEY `id` (`id`),
  1524. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1525. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1526. drop table t2;
  1527. create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
  1528. show create table t2;
  1529. Table Create Table
  1530. t2 CREATE TABLE `t2` (
  1531. `id` int(11) NOT NULL,
  1532. `id2` int(11) NOT NULL,
  1533. KEY `t1_id_fk` (`id`,`id2`),
  1534. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
  1535. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1536. create unique index id on t2 (id,id2);
  1537. show create table t2;
  1538. Table Create Table
  1539. t2 CREATE TABLE `t2` (
  1540. `id` int(11) NOT NULL,
  1541. `id2` int(11) NOT NULL,
  1542. UNIQUE KEY `id` (`id`,`id2`),
  1543. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
  1544. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1545. drop table t2;
  1546. create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
  1547. show create table t2;
  1548. Table Create Table
  1549. t2 CREATE TABLE `t2` (
  1550. `id` int(11) NOT NULL,
  1551. `id2` int(11) NOT NULL,
  1552. UNIQUE KEY `id` (`id`,`id2`),
  1553. KEY `t1_id_fk` (`id2`,`id`),
  1554. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
  1555. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1556. drop table t2;
  1557. create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
  1558. show create table t2;
  1559. Table Create Table
  1560. t2 CREATE TABLE `t2` (
  1561. `id` int(11) NOT NULL,
  1562. `id2` int(11) NOT NULL,
  1563. UNIQUE KEY `id` (`id`,`id2`),
  1564. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1565. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1566. drop table t2;
  1567. create table t2 (id int(11) not null, id2 int(11) not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
  1568. show create table t2;
  1569. Table Create Table
  1570. t2 CREATE TABLE `t2` (
  1571. `id` int(11) NOT NULL,
  1572. `id2` int(11) NOT NULL,
  1573. UNIQUE KEY `id` (`id`,`id2`),
  1574. KEY `t1_id_fk` (`id2`,`id`),
  1575. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
  1576. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1577. drop table t2;
  1578. create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
  1579. show create table t2;
  1580. Table Create Table
  1581. t2 CREATE TABLE `t2` (
  1582. `id` int(11) NOT NULL AUTO_INCREMENT,
  1583. `id2` int(11) NOT NULL,
  1584. PRIMARY KEY (`id`),
  1585. KEY `id` (`id`,`id2`),
  1586. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1587. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1588. drop table t2;
  1589. create table t2 (id int(11) not null auto_increment, id2 int(11) not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
  1590. show create table t2;
  1591. Table Create Table
  1592. t2 CREATE TABLE `t2` (
  1593. `id` int(11) NOT NULL AUTO_INCREMENT,
  1594. `id2` int(11) NOT NULL,
  1595. KEY `t1_id_fk` (`id`),
  1596. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1597. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1598. alter table t2 add index id_test (id), add index id_test2 (id,id2);
  1599. show create table t2;
  1600. Table Create Table
  1601. t2 CREATE TABLE `t2` (
  1602. `id` int(11) NOT NULL AUTO_INCREMENT,
  1603. `id2` int(11) NOT NULL,
  1604. KEY `id_test` (`id`),
  1605. KEY `id_test2` (`id`,`id2`),
  1606. CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
  1607. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1608. drop table t2;
  1609. create table t2 (id int(11) not null, id2 int(11) not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
  1610. ERROR HY000: Can't create table 'test.t2' (errno: 150)
  1611. create table t2 (a int auto_increment primary key, b int, index(b), foreign key (b) references t1(id), unique(b)) engine=innodb;
  1612. show create table t2;
  1613. Table Create Table
  1614. t2 CREATE TABLE `t2` (
  1615. `a` int(11) NOT NULL AUTO_INCREMENT,
  1616. `b` int(11) DEFAULT NULL,
  1617. PRIMARY KEY (`a`),
  1618. UNIQUE KEY `b_2` (`b`),
  1619. KEY `b` (`b`),
  1620. CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
  1621. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1622. drop table t2;
  1623. create table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=innodb;
  1624. show create table t2;
  1625. Table Create Table
  1626. t2 CREATE TABLE `t2` (
  1627. `a` int(11) NOT NULL AUTO_INCREMENT,
  1628. `b` int(11) DEFAULT NULL,
  1629. PRIMARY KEY (`a`),
  1630. UNIQUE KEY `b` (`b`),
  1631. CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
  1632. CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
  1633. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1634. drop table t2, t1;
  1635. flush status;
  1636. show status like "binlog_cache_use";
  1637. Variable_name Value
  1638. Binlog_cache_use 0
  1639. show status like "binlog_cache_disk_use";
  1640. Variable_name Value
  1641. Binlog_cache_disk_use 0
  1642. create table t1 (a int) engine=innodb;
  1643. show status like "binlog_cache_use";
  1644. Variable_name Value
  1645. Binlog_cache_use 1
  1646. show status like "binlog_cache_disk_use";
  1647. Variable_name Value
  1648. Binlog_cache_disk_use 1
  1649. begin;
  1650. delete from t1;
  1651. commit;
  1652. show status like "binlog_cache_use";
  1653. Variable_name Value
  1654. Binlog_cache_use 2
  1655. show status like "binlog_cache_disk_use";
  1656. Variable_name Value
  1657. Binlog_cache_disk_use 1
  1658. drop table t1;
  1659. create table t1 (c char(10), index (c,c)) engine=innodb;
  1660. ERROR 42S21: Duplicate column name 'c'
  1661. create table t1 (c1 char(10), c2 char(10), index (c1,c2,c1)) engine=innodb;
  1662. ERROR 42S21: Duplicate column name 'c1'
  1663. create table t1 (c1 char(10), c2 char(10), index (c1,c1,c2)) engine=innodb;
  1664. ERROR 42S21: Duplicate column name 'c1'
  1665. create table t1 (c1 char(10), c2 char(10), index (c2,c1,c1)) engine=innodb;
  1666. ERROR 42S21: Duplicate column name 'c1'
  1667. create table t1 (c1 char(10), c2 char(10)) engine=innodb;
  1668. alter table t1 add key (c1,c1);
  1669. ERROR 42S21: Duplicate column name 'c1'
  1670. alter table t1 add key (c2,c1,c1);
  1671. ERROR 42S21: Duplicate column name 'c1'
  1672. alter table t1 add key (c1,c2,c1);
  1673. ERROR 42S21: Duplicate column name 'c1'
  1674. alter table t1 add key (c1,c1,c2);
  1675. ERROR 42S21: Duplicate column name 'c1'
  1676. drop table t1;
  1677. create table t1(a int(1) , b int(1)) engine=innodb;
  1678. insert into t1 values ('1111', '3333');
  1679. select distinct concat(a, b) from t1;
  1680. concat(a, b)
  1681. 11113333
  1682. drop table t1;
  1683. CREATE TABLE t1 ( a char(10) ) ENGINE=InnoDB;
  1684. SELECT a FROM t1 WHERE MATCH (a) AGAINST ('test' IN BOOLEAN MODE);
  1685. ERROR HY000: The used table type doesn't support FULLTEXT indexes
  1686. DROP TABLE t1;
  1687. CREATE TABLE t1 (a_id tinyint(4) NOT NULL default '0', PRIMARY KEY (a_id)) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1688. INSERT INTO t1 VALUES (1),(2),(3);
  1689. CREATE TABLE t2 (b_id tinyint(4) NOT NULL default '0',b_a tinyint(4) NOT NULL default '0', PRIMARY KEY (b_id), KEY (b_a),
  1690. CONSTRAINT fk_b_a FOREIGN KEY (b_a) REFERENCES t1 (a_id) ON DELETE CASCADE ON UPDATE NO ACTION) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  1691. INSERT INTO t2 VALUES (1,1),(2,1),(3,1),(4,2),(5,2);
  1692. SELECT * FROM (SELECT t1.*,GROUP_CONCAT(t2.b_id SEPARATOR ',') as b_list FROM (t1 LEFT JOIN (t2) on t1.a_id = t2.b_a) GROUP BY t1.a_id ) AS xyz;
  1693. a_id b_list
  1694. 1 1,2,3
  1695. 2 4,5
  1696. 3 NULL
  1697. DROP TABLE t2;
  1698. DROP TABLE t1;
  1699. create temporary table t1 (a int) engine=innodb;
  1700. insert into t1 values (4711);
  1701. truncate t1;
  1702. insert into t1 values (42);
  1703. select * from t1;
  1704. a
  1705. 42
  1706. drop table t1;
  1707. create table t1 (a int) engine=innodb;
  1708. insert into t1 values (4711);
  1709. truncate t1;
  1710. insert into t1 values (42);
  1711. select * from t1;
  1712. a
  1713. 42
  1714. drop table t1;
  1715. create table t1 (a int not null, b int not null, c blob not null, d int not null, e int, primary key (a,b,c(255),d)) engine=innodb;
  1716. insert into t1 values (2,2,"b",2,2),(1,1,"a",1,1),(3,3,"ab",3,3);
  1717. select * from t1 order by a,b,c,d;
  1718. a b c d e
  1719. 1 1 a 1 1
  1720. 2 2 b 2 2
  1721. 3 3 ab 3 3
  1722. explain select * from t1 order by a,b,c,d;
  1723. id select_type table type possible_keys key key_len ref rows Extra
  1724. 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using filesort
  1725. drop table t1;
  1726. create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
  1727. insert into t1 values ('8', '6'), ('4', '7');
  1728. select min(a) from t1;
  1729. min(a)
  1730. 4
  1731. select min(b) from t1 where a='8';
  1732. min(b)
  1733. 6
  1734. drop table t1;
  1735. create table t1 (x bigint unsigned not null primary key) engine=innodb;
  1736. insert into t1(x) values (0xfffffffffffffff0),(0xfffffffffffffff1);
  1737. select * from t1;
  1738. x
  1739. 18446744073709551600
  1740. 18446744073709551601
  1741. select count(*) from t1 where x>0;
  1742. count(*)
  1743. 2
  1744. select count(*) from t1 where x=0;
  1745. count(*)
  1746. 0
  1747. select count(*) from t1 where x<0;
  1748. count(*)
  1749. 0
  1750. select count(*) from t1 where x < -16;
  1751. count(*)
  1752. 0
  1753. select count(*) from t1 where x = -16;
  1754. count(*)
  1755. 0
  1756. explain select count(*) from t1 where x > -16;
  1757. id select_type table type possible_keys key key_len ref rows Extra
  1758. 1 SIMPLE t1 index PRIMARY PRIMARY 8 NULL 2 Using where; Using index
  1759. select count(*) from t1 where x > -16;
  1760. count(*)
  1761. 2
  1762. select * from t1 where x > -16;
  1763. x
  1764. 18446744073709551600
  1765. 18446744073709551601
  1766. select count(*) from t1 where x = 18446744073709551601;
  1767. count(*)
  1768. 1
  1769. drop table t1;
  1770. show status like "Innodb_buffer_pool_pages_total";
  1771. Variable_name Value
  1772. Innodb_buffer_pool_pages_total 512
  1773. show status like "Innodb_page_size";
  1774. Variable_name Value
  1775. Innodb_page_size 16384
  1776. show status like "Innodb_rows_deleted";
  1777. Variable_name Value
  1778. Innodb_rows_deleted 2070
  1779. show status like "Innodb_rows_inserted";
  1780. Variable_name Value
  1781. Innodb_rows_inserted 3083
  1782. show status like "Innodb_rows_updated";
  1783. Variable_name Value
  1784. Innodb_rows_updated 886
  1785. show status like "Innodb_row_lock_waits";
  1786. Variable_name Value
  1787. Innodb_row_lock_waits 0
  1788. show status like "Innodb_row_lock_current_waits";
  1789. Variable_name Value
  1790. Innodb_row_lock_current_waits 0
  1791. show status like "Innodb_row_lock_time";
  1792. Variable_name Value
  1793. Innodb_row_lock_time 0
  1794. show status like "Innodb_row_lock_time_max";
  1795. Variable_name Value
  1796. Innodb_row_lock_time_max 0
  1797. show status like "Innodb_row_lock_time_avg";
  1798. Variable_name Value
  1799. Innodb_row_lock_time_avg 0
  1800. show variables like "innodb_sync_spin_loops";
  1801. Variable_name Value
  1802. innodb_sync_spin_loops 20
  1803. set global innodb_sync_spin_loops=1000;
  1804. show variables like "innodb_sync_spin_loops";
  1805. Variable_name Value
  1806. innodb_sync_spin_loops 1000
  1807. set global innodb_sync_spin_loops=0;
  1808. show variables like "innodb_sync_spin_loops";
  1809. Variable_name Value
  1810. innodb_sync_spin_loops 0
  1811. set global innodb_sync_spin_loops=20;
  1812. show variables like "innodb_sync_spin_loops";
  1813. Variable_name Value
  1814. innodb_sync_spin_loops 20
  1815. show variables like "innodb_thread_concurrency";
  1816. Variable_name Value
  1817. innodb_thread_concurrency 8
  1818. set global innodb_thread_concurrency=1001;
  1819. show variables like "innodb_thread_concurrency";
  1820. Variable_name Value
  1821. innodb_thread_concurrency 1000
  1822. set global innodb_thread_concurrency=0;
  1823. show variables like "innodb_thread_concurrency";
  1824. Variable_name Value
  1825. innodb_thread_concurrency 0
  1826. set global innodb_thread_concurrency=16;
  1827. show variables like "innodb_thread_concurrency";
  1828. Variable_name Value
  1829. innodb_thread_concurrency 16
  1830. show variables like "innodb_concurrency_tickets";
  1831. Variable_name Value
  1832. innodb_concurrency_tickets 500
  1833. set global innodb_concurrency_tickets=1000;
  1834. show variables like "innodb_concurrency_tickets";
  1835. Variable_name Value
  1836. innodb_concurrency_tickets 1000
  1837. set global innodb_concurrency_tickets=0;
  1838. show variables like "innodb_concurrency_tickets";
  1839. Variable_name Value
  1840. innodb_concurrency_tickets 1
  1841. set global innodb_concurrency_tickets=500;
  1842. show variables like "innodb_concurrency_tickets";
  1843. Variable_name Value
  1844. innodb_concurrency_tickets 500
  1845. show variables like "innodb_thread_sleep_delay";
  1846. Variable_name Value
  1847. innodb_thread_sleep_delay 10000
  1848. set global innodb_thread_sleep_delay=100000;
  1849. show variables like "innodb_thread_sleep_delay";
  1850. Variable_name Value
  1851. innodb_thread_sleep_delay 100000
  1852. set global innodb_thread_sleep_delay=0;
  1853. show variables like "innodb_thread_sleep_delay";
  1854. Variable_name Value
  1855. innodb_thread_sleep_delay 0
  1856. set global innodb_thread_sleep_delay=10000;
  1857. show variables like "innodb_thread_sleep_delay";
  1858. Variable_name Value
  1859. innodb_thread_sleep_delay 10000
  1860. set storage_engine=INNODB;
  1861. drop table if exists t1,t2,t3;
  1862. --- Testing varchar ---
  1863. --- Testing varchar ---
  1864. create table t1 (v varchar(10), c char(10), t text);
  1865. insert into t1 values('+ ', '+ ', '+ ');
  1866. set @a=repeat(' ',20);
  1867. insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
  1868. Warnings:
  1869. Note 1265 Data truncated for column 'v' at row 1
  1870. select concat('*',v,'*',c,'*',t,'*') from t1;
  1871. concat('*',v,'*',c,'*',t,'*')
  1872. *+ *+*+ *
  1873. *+ *+*+ *
  1874. show create table t1;
  1875. Table Create Table
  1876. t1 CREATE TABLE `t1` (
  1877. `v` varchar(10) DEFAULT NULL,
  1878. `c` char(10) DEFAULT NULL,
  1879. `t` text
  1880. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1881. create table t2 like t1;
  1882. show create table t2;
  1883. Table Create Table
  1884. t2 CREATE TABLE `t2` (
  1885. `v` varchar(10) DEFAULT NULL,
  1886. `c` char(10) DEFAULT NULL,
  1887. `t` text
  1888. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1889. create table t3 select * from t1;
  1890. show create table t3;
  1891. Table Create Table
  1892. t3 CREATE TABLE `t3` (
  1893. `v` varchar(10) DEFAULT NULL,
  1894. `c` char(10) DEFAULT NULL,
  1895. `t` text
  1896. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1897. alter table t1 modify c varchar(10);
  1898. show create table t1;
  1899. Table Create Table
  1900. t1 CREATE TABLE `t1` (
  1901. `v` varchar(10) DEFAULT NULL,
  1902. `c` varchar(10) DEFAULT NULL,
  1903. `t` text
  1904. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1905. alter table t1 modify v char(10);
  1906. show create table t1;
  1907. Table Create Table
  1908. t1 CREATE TABLE `t1` (
  1909. `v` char(10) DEFAULT NULL,
  1910. `c` varchar(10) DEFAULT NULL,
  1911. `t` text
  1912. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1913. alter table t1 modify t varchar(10);
  1914. Warnings:
  1915. Note 1265 Data truncated for column 't' at row 2
  1916. show create table t1;
  1917. Table Create Table
  1918. t1 CREATE TABLE `t1` (
  1919. `v` char(10) DEFAULT NULL,
  1920. `c` varchar(10) DEFAULT NULL,
  1921. `t` varchar(10) DEFAULT NULL
  1922. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1923. select concat('*',v,'*',c,'*',t,'*') from t1;
  1924. concat('*',v,'*',c,'*',t,'*')
  1925. *+*+*+ *
  1926. *+*+*+ *
  1927. drop table t1,t2,t3;
  1928. create table t1 (v varchar(10), c char(10), t text, key(v), key(c), key(t(10)));
  1929. show create table t1;
  1930. Table Create Table
  1931. t1 CREATE TABLE `t1` (
  1932. `v` varchar(10) DEFAULT NULL,
  1933. `c` char(10) DEFAULT NULL,
  1934. `t` text,
  1935. KEY `v` (`v`),
  1936. KEY `c` (`c`),
  1937. KEY `t` (`t`(10))
  1938. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  1939. select count(*) from t1;
  1940. count(*)
  1941. 270
  1942. insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
  1943. select count(*) from t1 where v='a';
  1944. count(*)
  1945. 10
  1946. select count(*) from t1 where c='a';
  1947. count(*)
  1948. 10
  1949. select count(*) from t1 where t='a';
  1950. count(*)
  1951. 10
  1952. select count(*) from t1 where v='a ';
  1953. count(*)
  1954. 10
  1955. select count(*) from t1 where c='a ';
  1956. count(*)
  1957. 10
  1958. select count(*) from t1 where t='a ';
  1959. count(*)
  1960. 10
  1961. select count(*) from t1 where v between 'a' and 'a ';
  1962. count(*)
  1963. 10
  1964. select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
  1965. count(*)
  1966. 10
  1967. select count(*) from t1 where v like 'a%';
  1968. count(*)
  1969. 11
  1970. select count(*) from t1 where c like 'a%';
  1971. count(*)
  1972. 11
  1973. select count(*) from t1 where t like 'a%';
  1974. count(*)
  1975. 11
  1976. select count(*) from t1 where v like 'a %';
  1977. count(*)
  1978. 9
  1979. explain select count(*) from t1 where v='a ';
  1980. id select_type table type possible_keys key key_len ref rows Extra
  1981. 1 SIMPLE t1 ref v v 13 const # Using where; Using index
  1982. explain select count(*) from t1 where c='a ';
  1983. id select_type table type possible_keys key key_len ref rows Extra
  1984. 1 SIMPLE t1 ref c c 11 const # Using where; Using index
  1985. explain select count(*) from t1 where t='a ';
  1986. id select_type table type possible_keys key key_len ref rows Extra
  1987. 1 SIMPLE t1 range t t 13 NULL # Using where
  1988. explain select count(*) from t1 where v like 'a%';
  1989. id select_type table type possible_keys key key_len ref rows Extra
  1990. 1 SIMPLE t1 range v v 13 NULL # Using where; Using index
  1991. explain select count(*) from t1 where v between 'a' and 'a ';
  1992. id select_type table type possible_keys key key_len ref rows Extra
  1993. 1 SIMPLE t1 ref v v 13 const # Using where; Using index
  1994. explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
  1995. id select_type table type possible_keys key key_len ref rows Extra
  1996. 1 SIMPLE t1 ref v v 13 const # Using where; Using index
  1997. alter table t1 add unique(v);
  1998. ERROR 23000: Duplicate entry '{ ' for key 'v_2'
  1999. alter table t1 add key(v);
  2000. select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a';
  2001. qq
  2002. *a*a*a*
  2003. *a *a*a *
  2004. *a *a*a *
  2005. *a *a*a *
  2006. *a *a*a *
  2007. *a *a*a *
  2008. *a *a*a *
  2009. *a *a*a *
  2010. *a *a*a *
  2011. *a *a*a *
  2012. explain select * from t1 where v='a';
  2013. id select_type table type possible_keys key key_len ref rows Extra
  2014. 1 SIMPLE t1 ref v,v_2 # 13 const # Using where
  2015. select v,count(*) from t1 group by v limit 10;
  2016. v count(*)
  2017. a 1
  2018. a 10
  2019. b 10
  2020. c 10
  2021. d 10
  2022. e 10
  2023. f 10
  2024. g 10
  2025. h 10
  2026. i 10
  2027. select v,count(t) from t1 group by v limit 10;
  2028. v count(t)
  2029. a 1
  2030. a 10
  2031. b 10
  2032. c 10
  2033. d 10
  2034. e 10
  2035. f 10
  2036. g 10
  2037. h 10
  2038. i 10
  2039. select v,count(c) from t1 group by v limit 10;
  2040. v count(c)
  2041. a 1
  2042. a 10
  2043. b 10
  2044. c 10
  2045. d 10
  2046. e 10
  2047. f 10
  2048. g 10
  2049. h 10
  2050. i 10
  2051. select sql_big_result v,count(t) from t1 group by v limit 10;
  2052. v count(t)
  2053. a 1
  2054. a 10
  2055. b 10
  2056. c 10
  2057. d 10
  2058. e 10
  2059. f 10
  2060. g 10
  2061. h 10
  2062. i 10
  2063. select sql_big_result v,count(c) from t1 group by v limit 10;
  2064. v count(c)
  2065. a 1
  2066. a 10
  2067. b 10
  2068. c 10
  2069. d 10
  2070. e 10
  2071. f 10
  2072. g 10
  2073. h 10
  2074. i 10
  2075. select c,count(*) from t1 group by c limit 10;
  2076. c count(*)
  2077. a 1
  2078. a 10
  2079. b 10
  2080. c 10
  2081. d 10
  2082. e 10
  2083. f 10
  2084. g 10
  2085. h 10
  2086. i 10
  2087. select c,count(t) from t1 group by c limit 10;
  2088. c count(t)
  2089. a 1
  2090. a 10
  2091. b 10
  2092. c 10
  2093. d 10
  2094. e 10
  2095. f 10
  2096. g 10
  2097. h 10
  2098. i 10
  2099. select sql_big_result c,count(t) from t1 group by c limit 10;
  2100. c count(t)
  2101. a 1
  2102. a 10
  2103. b 10
  2104. c 10
  2105. d 10
  2106. e 10
  2107. f 10
  2108. g 10
  2109. h 10
  2110. i 10
  2111. select t,count(*) from t1 group by t limit 10;
  2112. t count(*)
  2113. a 1
  2114. a 10
  2115. b 10
  2116. c 10
  2117. d 10
  2118. e 10
  2119. f 10
  2120. g 10
  2121. h 10
  2122. i 10
  2123. select t,count(t) from t1 group by t limit 10;
  2124. t count(t)
  2125. a 1
  2126. a 10
  2127. b 10
  2128. c 10
  2129. d 10
  2130. e 10
  2131. f 10
  2132. g 10
  2133. h 10
  2134. i 10
  2135. select sql_big_result t,count(t) from t1 group by t limit 10;
  2136. t count(t)
  2137. a 1
  2138. a 10
  2139. b 10
  2140. c 10
  2141. d 10
  2142. e 10
  2143. f 10
  2144. g 10
  2145. h 10
  2146. i 10
  2147. alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
  2148. show create table t1;
  2149. Table Create Table
  2150. t1 CREATE TABLE `t1` (
  2151. `v` varchar(300) DEFAULT NULL,
  2152. `c` char(10) DEFAULT NULL,
  2153. `t` text,
  2154. KEY `c` (`c`),
  2155. KEY `t` (`t`(10)),
  2156. KEY `v` (`v`)
  2157. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2158. select count(*) from t1 where v='a';
  2159. count(*)
  2160. 10
  2161. select count(*) from t1 where v='a ';
  2162. count(*)
  2163. 10
  2164. select count(*) from t1 where v between 'a' and 'a ';
  2165. count(*)
  2166. 10
  2167. select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
  2168. count(*)
  2169. 10
  2170. select count(*) from t1 where v like 'a%';
  2171. count(*)
  2172. 11
  2173. select count(*) from t1 where v like 'a %';
  2174. count(*)
  2175. 9
  2176. explain select count(*) from t1 where v='a ';
  2177. id select_type table type possible_keys key key_len ref rows Extra
  2178. 1 SIMPLE t1 ref v v 303 const # Using where; Using index
  2179. explain select count(*) from t1 where v like 'a%';
  2180. id select_type table type possible_keys key key_len ref rows Extra
  2181. 1 SIMPLE t1 range v v 303 NULL # Using where; Using index
  2182. explain select count(*) from t1 where v between 'a' and 'a ';
  2183. id select_type table type possible_keys key key_len ref rows Extra
  2184. 1 SIMPLE t1 ref v v 303 const # Using where; Using index
  2185. explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
  2186. id select_type table type possible_keys key key_len ref rows Extra
  2187. 1 SIMPLE t1 ref v v 303 const # Using where; Using index
  2188. explain select * from t1 where v='a';
  2189. id select_type table type possible_keys key key_len ref rows Extra
  2190. 1 SIMPLE t1 ref v v 303 const # Using where
  2191. select v,count(*) from t1 group by v limit 10;
  2192. v count(*)
  2193. a 1
  2194. a 10
  2195. b 10
  2196. c 10
  2197. d 10
  2198. e 10
  2199. f 10
  2200. g 10
  2201. h 10
  2202. i 10
  2203. select v,count(t) from t1 group by v limit 10;
  2204. v count(t)
  2205. a 1
  2206. a 10
  2207. b 10
  2208. c 10
  2209. d 10
  2210. e 10
  2211. f 10
  2212. g 10
  2213. h 10
  2214. i 10
  2215. select sql_big_result v,count(t) from t1 group by v limit 10;
  2216. v count(t)
  2217. a 1
  2218. a 10
  2219. b 10
  2220. c 10
  2221. d 10
  2222. e 10
  2223. f 10
  2224. g 10
  2225. h 10
  2226. i 10
  2227. alter table t1 drop key v, add key v (v(30));
  2228. show create table t1;
  2229. Table Create Table
  2230. t1 CREATE TABLE `t1` (
  2231. `v` varchar(300) DEFAULT NULL,
  2232. `c` char(10) DEFAULT NULL,
  2233. `t` text,
  2234. KEY `c` (`c`),
  2235. KEY `t` (`t`(10)),
  2236. KEY `v` (`v`(30))
  2237. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2238. select count(*) from t1 where v='a';
  2239. count(*)
  2240. 10
  2241. select count(*) from t1 where v='a ';
  2242. count(*)
  2243. 10
  2244. select count(*) from t1 where v between 'a' and 'a ';
  2245. count(*)
  2246. 10
  2247. select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
  2248. count(*)
  2249. 10
  2250. select count(*) from t1 where v like 'a%';
  2251. count(*)
  2252. 11
  2253. select count(*) from t1 where v like 'a %';
  2254. count(*)
  2255. 9
  2256. explain select count(*) from t1 where v='a ';
  2257. id select_type table type possible_keys key key_len ref rows Extra
  2258. 1 SIMPLE t1 ref v v 33 const # Using where
  2259. explain select count(*) from t1 where v like 'a%';
  2260. id select_type table type possible_keys key key_len ref rows Extra
  2261. 1 SIMPLE t1 range v v 33 NULL # Using where
  2262. explain select count(*) from t1 where v between 'a' and 'a ';
  2263. id select_type table type possible_keys key key_len ref rows Extra
  2264. 1 SIMPLE t1 ref v v 33 const # Using where
  2265. explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
  2266. id select_type table type possible_keys key key_len ref rows Extra
  2267. 1 SIMPLE t1 ref v v 33 const # Using where
  2268. explain select * from t1 where v='a';
  2269. id select_type table type possible_keys key key_len ref rows Extra
  2270. 1 SIMPLE t1 ref v v 33 const # Using where
  2271. select v,count(*) from t1 group by v limit 10;
  2272. v count(*)
  2273. a 1
  2274. a 10
  2275. b 10
  2276. c 10
  2277. d 10
  2278. e 10
  2279. f 10
  2280. g 10
  2281. h 10
  2282. i 10
  2283. select v,count(t) from t1 group by v limit 10;
  2284. v count(t)
  2285. a 1
  2286. a 10
  2287. b 10
  2288. c 10
  2289. d 10
  2290. e 10
  2291. f 10
  2292. g 10
  2293. h 10
  2294. i 10
  2295. select sql_big_result v,count(t) from t1 group by v limit 10;
  2296. v count(t)
  2297. a 1
  2298. a 10
  2299. b 10
  2300. c 10
  2301. d 10
  2302. e 10
  2303. f 10
  2304. g 10
  2305. h 10
  2306. i 10
  2307. alter table t1 modify v varchar(600), drop key v, add key v (v);
  2308. show create table t1;
  2309. Table Create Table
  2310. t1 CREATE TABLE `t1` (
  2311. `v` varchar(600) DEFAULT NULL,
  2312. `c` char(10) DEFAULT NULL,
  2313. `t` text,
  2314. KEY `c` (`c`),
  2315. KEY `t` (`t`(10)),
  2316. KEY `v` (`v`)
  2317. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2318. select v,count(*) from t1 group by v limit 10;
  2319. v count(*)
  2320. a 1
  2321. a 10
  2322. b 10
  2323. c 10
  2324. d 10
  2325. e 10
  2326. f 10
  2327. g 10
  2328. h 10
  2329. i 10
  2330. select v,count(t) from t1 group by v limit 10;
  2331. v count(t)
  2332. a 1
  2333. a 10
  2334. b 10
  2335. c 10
  2336. d 10
  2337. e 10
  2338. f 10
  2339. g 10
  2340. h 10
  2341. i 10
  2342. select sql_big_result v,count(t) from t1 group by v limit 10;
  2343. v count(t)
  2344. a 1
  2345. a 10
  2346. b 10
  2347. c 10
  2348. d 10
  2349. e 10
  2350. f 10
  2351. g 10
  2352. h 10
  2353. i 10
  2354. drop table t1;
  2355. create table t1 (a char(10), unique (a));
  2356. insert into t1 values ('a ');
  2357. insert into t1 values ('a ');
  2358. ERROR 23000: Duplicate entry 'a' for key 'a'
  2359. alter table t1 modify a varchar(10);
  2360. insert into t1 values ('a '),('a '),('a '),('a ');
  2361. ERROR 23000: Duplicate entry 'a ' for key 'a'
  2362. insert into t1 values ('a ');
  2363. ERROR 23000: Duplicate entry 'a ' for key 'a'
  2364. insert into t1 values ('a ');
  2365. ERROR 23000: Duplicate entry 'a ' for key 'a'
  2366. insert into t1 values ('a ');
  2367. ERROR 23000: Duplicate entry 'a ' for key 'a'
  2368. update t1 set a='a ' where a like 'a%';
  2369. select concat(a,'.') from t1;
  2370. concat(a,'.')
  2371. a .
  2372. update t1 set a='abc ' where a like 'a ';
  2373. select concat(a,'.') from t1;
  2374. concat(a,'.')
  2375. a .
  2376. update t1 set a='a ' where a like 'a %';
  2377. select concat(a,'.') from t1;
  2378. concat(a,'.')
  2379. a .
  2380. update t1 set a='a ' where a like 'a ';
  2381. select concat(a,'.') from t1;
  2382. concat(a,'.')
  2383. a .
  2384. drop table t1;
  2385. create table t1 (v varchar(10), c char(10), t text, key(v(5)), key(c(5)), key(t(5)));
  2386. show create table t1;
  2387. Table Create Table
  2388. t1 CREATE TABLE `t1` (
  2389. `v` varchar(10) DEFAULT NULL,
  2390. `c` char(10) DEFAULT NULL,
  2391. `t` text,
  2392. KEY `v` (`v`(5)),
  2393. KEY `c` (`c`(5)),
  2394. KEY `t` (`t`(5))
  2395. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2396. drop table t1;
  2397. create table t1 (v char(10) character set utf8);
  2398. show create table t1;
  2399. Table Create Table
  2400. t1 CREATE TABLE `t1` (
  2401. `v` char(10) CHARACTER SET utf8 DEFAULT NULL
  2402. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2403. drop table t1;
  2404. create table t1 (v varchar(10), c char(10)) row_format=fixed;
  2405. show create table t1;
  2406. Table Create Table
  2407. t1 CREATE TABLE `t1` (
  2408. `v` varchar(10) DEFAULT NULL,
  2409. `c` char(10) DEFAULT NULL
  2410. ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=FIXED
  2411. insert into t1 values('a','a'),('a ','a ');
  2412. select concat('*',v,'*',c,'*') from t1;
  2413. concat('*',v,'*',c,'*')
  2414. *a*a*
  2415. *a *a*
  2416. drop table t1;
  2417. create table t1 (v varchar(65530), key(v(10)));
  2418. insert into t1 values(repeat('a',65530));
  2419. select length(v) from t1 where v=repeat('a',65530);
  2420. length(v)
  2421. 65530
  2422. drop table t1;
  2423. create table t1(a int, b varchar(12), key ba(b, a));
  2424. insert into t1 values (1, 'A'), (20, NULL);
  2425. explain select * from t1 where a=20 and b is null;
  2426. id select_type table type possible_keys key key_len ref rows Extra
  2427. 1 SIMPLE t1 ref ba ba 20 const,const 1 Using where; Using index
  2428. select * from t1 where a=20 and b is null;
  2429. a b
  2430. 20 NULL
  2431. drop table t1;
  2432. create table t1 (v varchar(65530), key(v));
  2433. Warnings:
  2434. Warning 1071 Specified key was too long; max key length is 767 bytes
  2435. drop table t1;
  2436. create table t1 (v varchar(65536));
  2437. Warnings:
  2438. Note 1246 Converting column 'v' from VARCHAR to TEXT
  2439. show create table t1;
  2440. Table Create Table
  2441. t1 CREATE TABLE `t1` (
  2442. `v` mediumtext
  2443. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2444. drop table t1;
  2445. create table t1 (v varchar(65530) character set utf8);
  2446. Warnings:
  2447. Note 1246 Converting column 'v' from VARCHAR to TEXT
  2448. show create table t1;
  2449. Table Create Table
  2450. t1 CREATE TABLE `t1` (
  2451. `v` mediumtext CHARACTER SET utf8
  2452. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2453. drop table t1;
  2454. set storage_engine=MyISAM;
  2455. create table t1 (v varchar(16384)) engine=innodb;
  2456. drop table t1;
  2457. create table t1 (a char(1), b char(1), key(a, b)) engine=innodb;
  2458. insert into t1 values ('8', '6'), ('4', '7');
  2459. select min(a) from t1;
  2460. min(a)
  2461. 4
  2462. select min(b) from t1 where a='8';
  2463. min(b)
  2464. 6
  2465. drop table t1;
  2466. CREATE TABLE t1 ( `a` int(11) NOT NULL auto_increment, `b` int(11) default NULL,PRIMARY KEY (`a`),UNIQUE KEY `b` (`b`)) ENGINE=innodb;
  2467. insert into t1 (b) values (1);
  2468. replace into t1 (b) values (2), (1), (3);
  2469. select * from t1;
  2470. a b
  2471. 3 1
  2472. 2 2
  2473. 4 3
  2474. truncate table t1;
  2475. insert into t1 (b) values (1);
  2476. replace into t1 (b) values (2);
  2477. replace into t1 (b) values (1);
  2478. replace into t1 (b) values (3);
  2479. select * from t1;
  2480. a b
  2481. 3 1
  2482. 2 2
  2483. 4 3
  2484. drop table t1;
  2485. create table t1 (rowid int not null auto_increment, val int not null,primary
  2486. key (rowid), unique(val)) engine=innodb;
  2487. replace into t1 (val) values ('1'),('2');
  2488. replace into t1 (val) values ('1'),('2');
  2489. insert into t1 (val) values ('1'),('2');
  2490. ERROR 23000: Duplicate entry '1' for key 'val'
  2491. select * from t1;
  2492. rowid val
  2493. 3 1
  2494. 4 2
  2495. drop table t1;
  2496. create table t1 (a int not null auto_increment primary key, val int) engine=InnoDB;
  2497. insert into t1 (val) values (1);
  2498. update t1 set a=2 where a=1;
  2499. insert into t1 (val) values (1);
  2500. ERROR 23000: Duplicate entry '2' for key 'PRIMARY'
  2501. select * from t1;
  2502. a val
  2503. 2 1
  2504. drop table t1;
  2505. CREATE TABLE t1 (GRADE DECIMAL(4) NOT NULL, PRIMARY KEY (GRADE)) ENGINE=INNODB;
  2506. INSERT INTO t1 (GRADE) VALUES (151),(252),(343);
  2507. SELECT GRADE FROM t1 WHERE GRADE > 160 AND GRADE < 300;
  2508. GRADE
  2509. 252
  2510. SELECT GRADE FROM t1 WHERE GRADE= 151;
  2511. GRADE
  2512. 151
  2513. DROP TABLE t1;
  2514. create table t1 (f1 varchar(10), f2 varchar(10), primary key (f1,f2)) engine=innodb;
  2515. create table t2 (f3 varchar(10), f4 varchar(10), key (f4)) engine=innodb;
  2516. insert into t2 values ('aa','cc');
  2517. insert into t1 values ('aa','bb'),('aa','cc');
  2518. delete t1 from t1,t2 where f1=f3 and f4='cc';
  2519. select * from t1;
  2520. f1 f2
  2521. drop table t1,t2;
  2522. CREATE TABLE t1 (
  2523. id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)
  2524. ) ENGINE=InnoDB;
  2525. CREATE TABLE t2 (
  2526. id INTEGER NOT NULL,
  2527. FOREIGN KEY (id) REFERENCES t1 (id)
  2528. ) ENGINE=InnoDB;
  2529. INSERT INTO t1 (id) VALUES (NULL);
  2530. SELECT * FROM t1;
  2531. id
  2532. 1
  2533. TRUNCATE t1;
  2534. INSERT INTO t1 (id) VALUES (NULL);
  2535. SELECT * FROM t1;
  2536. id
  2537. 1
  2538. DELETE FROM t1;
  2539. TRUNCATE t1;
  2540. INSERT INTO t1 (id) VALUES (NULL);
  2541. SELECT * FROM t1;
  2542. id
  2543. 1
  2544. DROP TABLE t2, t1;
  2545. CREATE TABLE t1
  2546. (
  2547. id INT PRIMARY KEY
  2548. ) ENGINE=InnoDB;
  2549. CREATE TEMPORARY TABLE t2
  2550. (
  2551. id INT NOT NULL PRIMARY KEY,
  2552. b INT,
  2553. FOREIGN KEY (b) REFERENCES test.t1(id)
  2554. ) ENGINE=InnoDB;
  2555. Got one of the listed errors
  2556. DROP TABLE t1;
  2557. create table t1 (col1 varchar(2000), index (col1(767)))
  2558. character set = latin1 engine = innodb;
  2559. create table t2 (col1 char(255), index (col1))
  2560. character set = latin1 engine = innodb;
  2561. create table t3 (col1 binary(255), index (col1))
  2562. character set = latin1 engine = innodb;
  2563. create table t4 (col1 varchar(767), index (col1))
  2564. character set = latin1 engine = innodb;
  2565. create table t5 (col1 varchar(767) primary key)
  2566. character set = latin1 engine = innodb;
  2567. create table t6 (col1 varbinary(767) primary key)
  2568. character set = latin1 engine = innodb;
  2569. create table t7 (col1 text, index(col1(767)))
  2570. character set = latin1 engine = innodb;
  2571. create table t8 (col1 blob, index(col1(767)))
  2572. character set = latin1 engine = innodb;
  2573. create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
  2574. character set = latin1 engine = innodb;
  2575. show create table t9;
  2576. Table Create Table
  2577. t9 CREATE TABLE `t9` (
  2578. `col1` varchar(512) DEFAULT NULL,
  2579. `col2` varchar(512) DEFAULT NULL,
  2580. KEY `col1` (`col1`,`col2`)
  2581. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2582. drop table t1, t2, t3, t4, t5, t6, t7, t8, t9;
  2583. create table t1 (col1 varchar(768), index(col1))
  2584. character set = latin1 engine = innodb;
  2585. Warnings:
  2586. Warning 1071 Specified key was too long; max key length is 767 bytes
  2587. create table t2 (col1 varbinary(768), index(col1))
  2588. character set = latin1 engine = innodb;
  2589. Warnings:
  2590. Warning 1071 Specified key was too long; max key length is 767 bytes
  2591. create table t3 (col1 text, index(col1(768)))
  2592. character set = latin1 engine = innodb;
  2593. Warnings:
  2594. Warning 1071 Specified key was too long; max key length is 767 bytes
  2595. create table t4 (col1 blob, index(col1(768)))
  2596. character set = latin1 engine = innodb;
  2597. Warnings:
  2598. Warning 1071 Specified key was too long; max key length is 767 bytes
  2599. show create table t1;
  2600. Table Create Table
  2601. t1 CREATE TABLE `t1` (
  2602. `col1` varchar(768) DEFAULT NULL,
  2603. KEY `col1` (`col1`(767))
  2604. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  2605. drop table t1, t2, t3, t4;
  2606. create table t1 (col1 varchar(768) primary key)
  2607. character set = latin1 engine = innodb;
  2608. ERROR 42000: Specified key was too long; max key length is 767 bytes
  2609. create table t2 (col1 varbinary(768) primary key)
  2610. character set = latin1 engine = innodb;
  2611. ERROR 42000: Specified key was too long; max key length is 767 bytes
  2612. create table t3 (col1 text, primary key(col1(768)))
  2613. character set = latin1 engine = innodb;
  2614. ERROR 42000: Specified key was too long; max key length is 767 bytes
  2615. create table t4 (col1 blob, primary key(col1(768)))
  2616. character set = latin1 engine = innodb;
  2617. ERROR 42000: Specified key was too long; max key length is 767 bytes
  2618. CREATE TABLE t1
  2619. (
  2620. id INT PRIMARY KEY
  2621. ) ENGINE=InnoDB;
  2622. CREATE TABLE t2
  2623. (
  2624. v INT,
  2625. CONSTRAINT c1 FOREIGN KEY (v) REFERENCES t1(id)
  2626. ) ENGINE=InnoDB;
  2627. INSERT INTO t2 VALUES(2);
  2628. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
  2629. INSERT INTO t1 VALUES(1);
  2630. INSERT INTO t2 VALUES(1);
  2631. DELETE FROM t1 WHERE id = 1;
  2632. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
  2633. DROP TABLE t1;
  2634. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
  2635. SET FOREIGN_KEY_CHECKS=0;
  2636. DROP TABLE t1;
  2637. SET FOREIGN_KEY_CHECKS=1;
  2638. INSERT INTO t2 VALUES(3);
  2639. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
  2640. DROP TABLE t2;
  2641. create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
  2642. insert into t1 values (1),(2);
  2643. set autocommit=0;
  2644. checksum table t1;
  2645. Table Checksum
  2646. test.t1 1531596814
  2647. insert into t1 values(3);
  2648. checksum table t1;
  2649. Table Checksum
  2650. test.t1 1531596814
  2651. commit;
  2652. checksum table t1;
  2653. Table Checksum
  2654. test.t1 2050879373
  2655. commit;
  2656. drop table t1;
  2657. create table t1(a int not null) engine=innodb DEFAULT CHARSET=latin1;
  2658. insert into t1 values (1),(2);
  2659. set autocommit=1;
  2660. checksum table t1;
  2661. Table Checksum
  2662. test.t1 1531596814
  2663. set autocommit=1;
  2664. insert into t1 values(3);
  2665. checksum table t1;
  2666. Table Checksum
  2667. test.t1 2050879373
  2668. drop table t1;
  2669. create table t1 (
  2670. a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2))
  2671. ) character set utf8 engine = innodb;
  2672. create table t2 (
  2673. a int, b char(10), c char(10), filler char(10), primary key(a, b(2)), unique key (a, c(2))
  2674. ) character set ucs2 engine = innodb;
  2675. insert into t1 values (1,'abcdefg','abcdefg','one');
  2676. insert into t1 values (2,'ijkilmn','ijkilmn','two');
  2677. insert into t1 values (3,'qrstuvw','qrstuvw','three');
  2678. insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
  2679. insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
  2680. insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
  2681. insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
  2682. insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
  2683. insert into t2 values (1,'abcdefg','abcdefg','one');
  2684. insert into t2 values (2,'ijkilmn','ijkilmn','two');
  2685. insert into t2 values (3,'qrstuvw','qrstuvw','three');
  2686. insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
  2687. insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
  2688. insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
  2689. insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
  2690. insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
  2691. insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
  2692. insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
  2693. insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
  2694. insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
  2695. update t1 set filler = 'boo' where a = 1;
  2696. update t2 set filler ='email' where a = 4;
  2697. select a,hex(b),hex(c),filler from t1 order by filler;
  2698. a hex(b) hex(c) filler
  2699. 1 61626364656667 61626364656667 boo
  2700. 4 D0B1 D0B1 eight
  2701. 4 5B 5B five
  2702. 4 E880BD E880BD four
  2703. 4 E880BDD0B1E880BD E880BDD0B1E880BD seven
  2704. 4 E880BDE880BD E880BDE880BD six
  2705. 3 71727374757677 71727374757677 three
  2706. 2 696A6B696C6D6E 696A6B696C6D6E two
  2707. select a,hex(b),hex(c),filler from t2 order by filler;
  2708. a hex(b) hex(c) filler
  2709. 4 05630563 05630563 email
  2710. 4 0563 0563 email
  2711. 4 05612020 05612020 email
  2712. 4 01FC 01FC email
  2713. 4 0120 0120 email
  2714. 4 00640065 00640065 email
  2715. 4 00E400E50068 00E400E50068 email
  2716. 4 0000E400 0000E400 email
  2717. 4 0000563001FC0563 0000563001FC0563 email
  2718. 1 0061006200630064006500660067 0061006200630064006500660067 one
  2719. 3 0071007200730074007500760077 0071007200730074007500760077 three
  2720. 2 0069006A006B0069006C006D006E 0069006A006B0069006C006D006E two
  2721. drop table t1;
  2722. drop table t2;
  2723. create table t1 (
  2724. a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2))
  2725. ) character set utf8 engine = innodb;
  2726. create table t2 (
  2727. a int, b varchar(10), c varchar(10), filler varchar(10), primary key(a, b(2)), unique key (a, c(2))
  2728. ) character set ucs2 engine = innodb;
  2729. insert into t1 values (1,'abcdefg','abcdefg','one');
  2730. insert into t1 values (2,'ijkilmn','ijkilmn','two');
  2731. insert into t1 values (3,'qrstuvw','qrstuvw','three');
  2732. insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
  2733. insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
  2734. insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
  2735. insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
  2736. insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
  2737. insert into t2 values (1,'abcdefg','abcdefg','one');
  2738. insert into t2 values (2,'ijkilmn','ijkilmn','two');
  2739. insert into t2 values (3,'qrstuvw','qrstuvw','three');
  2740. insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
  2741. insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
  2742. insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
  2743. insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
  2744. insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
  2745. insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
  2746. insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
  2747. insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
  2748. insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
  2749. update t1 set filler = 'boo' where a = 1;
  2750. update t2 set filler ='email' where a = 4;
  2751. select a,hex(b),hex(c),filler from t1 order by filler;
  2752. a hex(b) hex(c) filler
  2753. 1 61626364656667 61626364656667 boo
  2754. 4 D0B1 D0B1 eight
  2755. 4 5B 5B five
  2756. 4 E880BD E880BD four
  2757. 4 E880BDD0B1E880BD E880BDD0B1E880BD seven
  2758. 4 E880BDE880BD E880BDE880BD six
  2759. 3 71727374757677 71727374757677 three
  2760. 2 696A6B696C6D6E 696A6B696C6D6E two
  2761. select a,hex(b),hex(c),filler from t2 order by filler;
  2762. a hex(b) hex(c) filler
  2763. 4 05630563 05630563 email
  2764. 4 0563 0563 email
  2765. 4 05612020 05612020 email
  2766. 4 01FC 01FC email
  2767. 4 0120 0120 email
  2768. 4 00640065 00640065 email
  2769. 4 00E400E50068 00E400E50068 email
  2770. 4 0000E400 0000E400 email
  2771. 4 0000563001FC0563 0000563001FC0563 email
  2772. 1 0061006200630064006500660067 0061006200630064006500660067 one
  2773. 3 0071007200730074007500760077 0071007200730074007500760077 three
  2774. 2 0069006A006B0069006C006D006E 0069006A006B0069006C006D006E two
  2775. drop table t1;
  2776. drop table t2;
  2777. create table t1 (
  2778. a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2))
  2779. ) character set utf8 engine = innodb;
  2780. create table t2 (
  2781. a int, b text(10), c text(10), filler text(10), primary key(a, b(2)), unique key (a, c(2))
  2782. ) character set ucs2 engine = innodb;
  2783. insert into t1 values (1,'abcdefg','abcdefg','one');
  2784. insert into t1 values (2,'ijkilmn','ijkilmn','two');
  2785. insert into t1 values (3,'qrstuvw','qrstuvw','three');
  2786. insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
  2787. insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
  2788. insert into t1 values (4,_utf8 0xe880bde880bd,_utf8 0xe880bde880bd,'six');
  2789. insert into t1 values (4,_utf8 0xe880bdD0B1e880bd,_utf8 0xe880bdD0B1e880bd,'seven');
  2790. insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
  2791. insert into t2 values (1,'abcdefg','abcdefg','one');
  2792. insert into t2 values (2,'ijkilmn','ijkilmn','two');
  2793. insert into t2 values (3,'qrstuvw','qrstuvw','three');
  2794. insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
  2795. insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
  2796. insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
  2797. insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
  2798. insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
  2799. insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
  2800. insert into t2 values (4,_ucs2 0x05630563,_ucs2 0x05630563,'eleven');
  2801. insert into t2 values (4,_ucs2 0x0563001fc0563,_ucs2 0x0563001fc0563,'point');
  2802. insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
  2803. update t1 set filler = 'boo' where a = 1;
  2804. update t2 set filler ='email' where a = 4;
  2805. select a,hex(b),hex(c),filler from t1 order by filler;
  2806. a hex(b) hex(c) filler
  2807. 1 61626364656667 61626364656667 boo
  2808. 4 D0B1 D0B1 eight
  2809. 4 5B 5B five
  2810. 4 E880BD E880BD four
  2811. 4 E880BDD0B1E880BD E880BDD0B1E880BD seven
  2812. 4 E880BDE880BD E880BDE880BD six
  2813. 3 71727374757677 71727374757677 three
  2814. 2 696A6B696C6D6E 696A6B696C6D6E two
  2815. select a,hex(b),hex(c),filler from t2 order by filler;
  2816. a hex(b) hex(c) filler
  2817. 4 0120 0120 email
  2818. 4 01FC 01FC email
  2819. 4 0563 0563 email
  2820. 4 0000563001FC0563 0000563001FC0563 email
  2821. 4 0000E400 0000E400 email
  2822. 4 00640065 00640065 email
  2823. 4 00E400E50068 00E400E50068 email
  2824. 4 05612020 05612020 email
  2825. 4 05630563 05630563 email
  2826. 1 0061006200630064006500660067 0061006200630064006500660067 one
  2827. 3 0071007200730074007500760077 0071007200730074007500760077 three
  2828. 2 0069006A006B0069006C006D006E 0069006A006B0069006C006D006E two
  2829. drop table t1;
  2830. drop table t2;
  2831. create table t1 (
  2832. a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2))
  2833. ) character set utf8 engine = innodb;
  2834. create table t2 (
  2835. a int, b blob(10), c blob(10), filler blob(10), primary key(a, b(2)), unique key (a, c(2))
  2836. ) character set ucs2 engine = innodb;
  2837. insert into t1 values (1,'abcdefg','abcdefg','one');
  2838. insert into t1 values (2,'ijkilmn','ijkilmn','two');
  2839. insert into t1 values (3,'qrstuvw','qrstuvw','three');
  2840. insert into t1 values (4,_utf8 0xe880bd,_utf8 0xe880bd,'four');
  2841. insert into t1 values (4,_utf8 0x5b,_utf8 0x5b,'five');
  2842. insert into t1 values (4,_utf8 0xD0B1,_utf8 0xD0B1,'eight');
  2843. insert into t2 values (1,'abcdefg','abcdefg','one');
  2844. insert into t2 values (2,'ijkilmn','ijkilmn','two');
  2845. insert into t2 values (3,'qrstuvw','qrstuvw','three');
  2846. insert into t2 values (4,_ucs2 0x00e400,_ucs2 0x00e400,'four');
  2847. insert into t2 values (4,_ucs2 0x00640065,_ucs2 0x00640065,'five');
  2848. insert into t2 values (4,_ucs2 0x00e400e50068,_ucs2 0x00e400e50068,'six');
  2849. insert into t2 values (4,_ucs2 0x01fc,_ucs2 0x01fc,'seven');
  2850. insert into t2 values (4,_ucs2 0x0120,_ucs2 0x0120,'eight');
  2851. insert into t2 values (4,_ucs2 0x0563,_ucs2 0x0563,'ten');
  2852. insert into t2 values (4,_ucs2 0x05612020,_ucs2 0x05612020,'taken');
  2853. update t1 set filler = 'boo' where a = 1;
  2854. update t2 set filler ='email' where a = 4;
  2855. select a,hex(b),hex(c),filler from t1 order by filler;
  2856. a hex(b) hex(c) filler
  2857. 1 61626364656667 61626364656667 boo
  2858. 4 D0B1 D0B1 eight
  2859. 4 5B 5B five
  2860. 4 E880BD E880BD four
  2861. 3 71727374757677 71727374757677 three
  2862. 2 696A6B696C6D6E 696A6B696C6D6E two
  2863. select a,hex(b),hex(c),filler from t2 order by filler;
  2864. a hex(b) hex(c) filler
  2865. 4 0000E400 0000E400 email
  2866. 4 00640065 00640065 email
  2867. 4 00E400E50068 00E400E50068 email
  2868. 4 0120 0120 email
  2869. 4 01FC 01FC email
  2870. 4 05612020 05612020 email
  2871. 4 0563 0563 email
  2872. 1 61626364656667 61626364656667 one
  2873. 3 71727374757677 71727374757677 three
  2874. 2 696A6B696C6D6E 696A6B696C6D6E two
  2875. drop table t1;
  2876. drop table t2;
  2877. commit;
  2878. set foreign_key_checks=0;
  2879. create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
  2880. create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
  2881. ERROR HY000: Can't create table 'test.t1' (errno: 150)
  2882. set foreign_key_checks=1;
  2883. drop table t2;
  2884. set foreign_key_checks=0;
  2885. create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
  2886. create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=utf8;
  2887. ERROR HY000: Can't create table 'test.t2' (errno: 150)
  2888. set foreign_key_checks=1;
  2889. drop table t1;
  2890. set foreign_key_checks=0;
  2891. create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
  2892. create table t1(a varchar(10) primary key) engine = innodb;
  2893. alter table t1 modify column a int;
  2894. Got one of the listed errors
  2895. set foreign_key_checks=1;
  2896. drop table t2,t1;
  2897. set foreign_key_checks=0;
  2898. create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
  2899. create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
  2900. alter table t1 convert to character set utf8;
  2901. set foreign_key_checks=1;
  2902. drop table t2,t1;
  2903. set foreign_key_checks=0;
  2904. create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
  2905. create table t3(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=utf8;
  2906. rename table t3 to t1;
  2907. ERROR HY000: Error on rename of './test/t3' to './test/t1' (errno: 150)
  2908. set foreign_key_checks=1;
  2909. drop table t2,t3;
  2910. create table t1(a int primary key) row_format=redundant engine=innodb;
  2911. create table t2(a int primary key,constraint foreign key(a)references t1(a)) row_format=compact engine=innodb;
  2912. create table t3(a int primary key) row_format=compact engine=innodb;
  2913. create table t4(a int primary key,constraint foreign key(a)references t3(a)) row_format=redundant engine=innodb;
  2914. insert into t1 values(1);
  2915. insert into t3 values(1);
  2916. insert into t2 values(2);
  2917. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
  2918. insert into t4 values(2);
  2919. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
  2920. insert into t2 values(1);
  2921. insert into t4 values(1);
  2922. update t1 set a=2;
  2923. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
  2924. update t2 set a=2;
  2925. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
  2926. update t3 set a=2;
  2927. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
  2928. update t4 set a=2;
  2929. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
  2930. truncate t1;
  2931. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`))
  2932. truncate t3;
  2933. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`))
  2934. truncate t2;
  2935. truncate t4;
  2936. truncate t1;
  2937. truncate t3;
  2938. drop table t4,t3,t2,t1;
  2939. create table t1 (a varchar(255) character set utf8,
  2940. b varchar(255) character set utf8,
  2941. c varchar(255) character set utf8,
  2942. d varchar(255) character set utf8,
  2943. key (a,b,c,d)) engine=innodb;
  2944. drop table t1;
  2945. create table t1 (a varchar(255) character set utf8,
  2946. b varchar(255) character set utf8,
  2947. c varchar(255) character set utf8,
  2948. d varchar(255) character set utf8,
  2949. e varchar(255) character set utf8,
  2950. key (a,b,c,d,e)) engine=innodb;
  2951. ERROR 42000: Specified key was too long; max key length is 3072 bytes
  2952. create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
  2953. create table t2 (s1 binary(2),primary key (s1)) engine=innodb;
  2954. create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
  2955. create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
  2956. insert into t1 values (0x41),(0x4120),(0x4100);
  2957. insert into t2 values (0x41),(0x4120),(0x4100);
  2958. ERROR 23000: Duplicate entry 'A' for key 'PRIMARY'
  2959. insert into t2 values (0x41),(0x4120);
  2960. insert into t3 values (0x41),(0x4120),(0x4100);
  2961. ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
  2962. insert into t3 values (0x41),(0x4100);
  2963. insert into t4 values (0x41),(0x4120),(0x4100);
  2964. ERROR 23000: Duplicate entry 'A' for key 'PRIMARY'
  2965. insert into t4 values (0x41),(0x4100);
  2966. select hex(s1) from t1;
  2967. hex(s1)
  2968. 41
  2969. 4100
  2970. 4120
  2971. select hex(s1) from t2;
  2972. hex(s1)
  2973. 4100
  2974. 4120
  2975. select hex(s1) from t3;
  2976. hex(s1)
  2977. 4100
  2978. 41
  2979. select hex(s1) from t4;
  2980. hex(s1)
  2981. 4100
  2982. 41
  2983. drop table t1,t2,t3,t4;
  2984. create table t1 (a int primary key,s1 varbinary(3) not null unique) engine=innodb;
  2985. create table t2 (s1 binary(2) not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
  2986. insert into t1 values(1,0x4100),(2,0x41),(3,0x4120),(4,0x42);
  2987. insert into t2 values(0x42);
  2988. ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  2989. insert into t2 values(0x41);
  2990. select hex(s1) from t2;
  2991. hex(s1)
  2992. 4100
  2993. update t1 set s1=0x123456 where a=2;
  2994. select hex(s1) from t2;
  2995. hex(s1)
  2996. 4100
  2997. update t1 set s1=0x12 where a=1;
  2998. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  2999. update t1 set s1=0x12345678 where a=1;
  3000. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  3001. update t1 set s1=0x123457 where a=1;
  3002. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  3003. update t1 set s1=0x1220 where a=1;
  3004. select hex(s1) from t2;
  3005. hex(s1)
  3006. 1220
  3007. update t1 set s1=0x1200 where a=1;
  3008. select hex(s1) from t2;
  3009. hex(s1)
  3010. 1200
  3011. update t1 set s1=0x4200 where a=1;
  3012. select hex(s1) from t2;
  3013. hex(s1)
  3014. 4200
  3015. delete from t1 where a=1;
  3016. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  3017. delete from t1 where a=2;
  3018. update t2 set s1=0x4120;
  3019. delete from t1;
  3020. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  3021. delete from t1 where a!=3;
  3022. select a,hex(s1) from t1;
  3023. a hex(s1)
  3024. 3 4120
  3025. select hex(s1) from t2;
  3026. hex(s1)
  3027. 4120
  3028. drop table t2,t1;
  3029. create table t1 (a int primary key,s1 varchar(2) binary not null unique) engine=innodb;
  3030. create table t2 (s1 char(2) binary not null, constraint c foreign key(s1) references t1(s1) on update cascade) engine=innodb;
  3031. insert into t1 values(1,0x4100),(2,0x41);
  3032. insert into t2 values(0x41);
  3033. select hex(s1) from t2;
  3034. hex(s1)
  3035. 41
  3036. update t1 set s1=0x1234 where a=1;
  3037. select hex(s1) from t2;
  3038. hex(s1)
  3039. 41
  3040. update t1 set s1=0x12 where a=2;
  3041. select hex(s1) from t2;
  3042. hex(s1)
  3043. 12
  3044. delete from t1 where a=1;
  3045. delete from t1 where a=2;
  3046. ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c` FOREIGN KEY (`s1`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE)
  3047. select a,hex(s1) from t1;
  3048. a hex(s1)
  3049. 2 12
  3050. select hex(s1) from t2;
  3051. hex(s1)
  3052. 12
  3053. drop table t2,t1;
  3054. CREATE TABLE t1 (
  3055. ind enum('0','1','2') NOT NULL default '0',
  3056. string1 varchar(250) NOT NULL,
  3057. PRIMARY KEY (ind)
  3058. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  3059. CREATE TABLE t2 (
  3060. ind enum('0','1','2') NOT NULL default '0',
  3061. string1 varchar(250) NOT NULL,
  3062. PRIMARY KEY (ind)
  3063. ) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
  3064. INSERT INTO t1 VALUES ('1', ''),('2', '');
  3065. INSERT INTO t2 VALUES ('1', ''),('2', '');
  3066. SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
  3067. hex(ind) hex(string1)
  3068. 31
  3069. 32
  3070. SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
  3071. hex(ind) hex(string1)
  3072. 0031
  3073. 0032
  3074. drop table t1,t2;
  3075. CREATE TABLE t1 (
  3076. ind set('0','1','2') NOT NULL default '0',
  3077. string1 varchar(250) NOT NULL,
  3078. PRIMARY KEY (ind)
  3079. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  3080. CREATE TABLE t2 (
  3081. ind set('0','1','2') NOT NULL default '0',
  3082. string1 varchar(250) NOT NULL,
  3083. PRIMARY KEY (ind)
  3084. ) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
  3085. INSERT INTO t1 VALUES ('1', ''),('2', '');
  3086. INSERT INTO t2 VALUES ('1', ''),('2', '');
  3087. SELECT hex(ind),hex(string1) FROM t1 ORDER BY string1;
  3088. hex(ind) hex(string1)
  3089. 31
  3090. 32
  3091. SELECT hex(ind),hex(string1) FROM t2 ORDER BY string1;
  3092. hex(ind) hex(string1)
  3093. 0031
  3094. 0032
  3095. drop table t1,t2;
  3096. CREATE TABLE t1 (
  3097. ind bit not null,
  3098. string1 varchar(250) NOT NULL,
  3099. PRIMARY KEY (ind)
  3100. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  3101. CREATE TABLE t2 (
  3102. ind bit not null,
  3103. string1 varchar(250) NOT NULL,
  3104. PRIMARY KEY (ind)
  3105. ) ENGINE=InnoDB DEFAULT CHARSET=ucs2;
  3106. insert into t1 values(0,''),(1,'');
  3107. insert into t2 values(0,''),(1,'');
  3108. select hex(ind),hex(string1) from t1 order by string1;
  3109. hex(ind) hex(string1)
  3110. 0
  3111. 1
  3112. select hex(ind),hex(string1) from t2 order by string1;
  3113. hex(ind) hex(string1)
  3114. 0
  3115. 1
  3116. drop table t1,t2;
  3117. create table t2 (
  3118. a int, b char(10), filler char(10), primary key(a, b(2))
  3119. ) character set utf8 engine = innodb;
  3120. insert into t2 values (1,'abcdefg','one');
  3121. insert into t2 values (2,'ijkilmn','two');
  3122. insert into t2 values (3, 'qrstuvw','three');
  3123. update t2 set a=5, filler='booo' where a=1;
  3124. drop table t2;
  3125. create table t2 (
  3126. a int, b char(10), filler char(10), primary key(a, b(2))
  3127. ) character set ucs2 engine = innodb;
  3128. insert into t2 values (1,'abcdefg','one');
  3129. insert into t2 values (2,'ijkilmn','two');
  3130. insert into t2 values (3, 'qrstuvw','three');
  3131. update t2 set a=5, filler='booo' where a=1;
  3132. drop table t2;
  3133. create table t1(a int not null, b char(110),primary key(a,b(100))) engine=innodb default charset=utf8;
  3134. insert into t1 values(1,'abcdefg'),(2,'defghijk');
  3135. insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
  3136. insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
  3137. select a,hex(b) from t1 order by b;
  3138. a hex(b)
  3139. 1 61626364656667
  3140. 2 6465666768696A6B
  3141. 6 D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1
  3142. 7 D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2
  3143. update t1 set b = 'three' where a = 6;
  3144. drop table t1;
  3145. create table t1(a int not null, b text(110),primary key(a,b(100))) engine=innodb default charset=utf8;
  3146. insert into t1 values(1,'abcdefg'),(2,'defghijk');
  3147. insert into t1 values(6,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1);
  3148. insert into t1 values(7,_utf8 0xD0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2);
  3149. select a,hex(b) from t1 order by b;
  3150. a hex(b)
  3151. 1 61626364656667
  3152. 2 6465666768696A6B
  3153. 6 D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1
  3154. 7 D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B1D0B2
  3155. update t1 set b = 'three' where a = 6;
  3156. drop table t1;
  3157. CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
  3158. CREATE TABLE t2(a INT) ENGINE=InnoDB;
  3159. ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
  3160. ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
  3161. ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
  3162. ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
  3163. SHOW CREATE TABLE t2;
  3164. Table Create Table
  3165. t2 CREATE TABLE `t2` (
  3166. `a` int(11) DEFAULT NULL,
  3167. KEY `t2_ibfk_0` (`a`)
  3168. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  3169. DROP TABLE t2,t1;
  3170. create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
  3171. insert into t1(a) values (1),(2),(3);
  3172. commit;
  3173. set autocommit = 0;
  3174. update t1 set b = 5 where a = 2;
  3175. create trigger t1t before insert on t1 for each row begin set NEW.b = NEW.a * 10 + 5, NEW.c = NEW.a / 10; end |
  3176. set autocommit = 0;
  3177. insert into t1(a) values (10),(20),(30),(40),(50),(60),(70),(80),(90),(100),
  3178. (11),(21),(31),(41),(51),(61),(71),(81),(91),(101),
  3179. (12),(22),(32),(42),(52),(62),(72),(82),(92),(102),
  3180. (13),(23),(33),(43),(53),(63),(73),(83),(93),(103),
  3181. (14),(24),(34),(44),(54),(64),(74),(84),(94),(104);
  3182. commit;
  3183. commit;
  3184. drop trigger t1t;
  3185. drop table t1;
  3186. create table t1(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
  3187. create table t2(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
  3188. create table t3(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
  3189. create table t4(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
  3190. create table t5(a int not null, b int, c int, d int, primary key(a)) engine=innodb;
  3191. insert into t1(a) values (1),(2),(3);
  3192. insert into t2(a) values (1),(2),(3);
  3193. insert into t3(a) values (1),(2),(3);
  3194. insert into t4(a) values (1),(2),(3);
  3195. insert into t3(a) values (5),(7),(8);
  3196. insert into t4(a) values (5),(7),(8);
  3197. insert into t5(a) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12);
  3198. create trigger t1t before insert on t1 for each row begin
  3199. INSERT INTO t2 SET a = NEW.a;
  3200. end |
  3201. create trigger t2t before insert on t2 for each row begin
  3202. DELETE FROM t3 WHERE a = NEW.a;
  3203. end |
  3204. create trigger t3t before delete on t3 for each row begin
  3205. UPDATE t4 SET b = b + 1 WHERE a = OLD.a;
  3206. end |
  3207. create trigger t4t before update on t4 for each row begin
  3208. UPDATE t5 SET b = b + 1 where a = NEW.a;
  3209. end |
  3210. commit;
  3211. set autocommit = 0;
  3212. update t1 set b = b + 5 where a = 1;
  3213. update t2 set b = b + 5 where a = 1;
  3214. update t3 set b = b + 5 where a = 1;
  3215. update t4 set b = b + 5 where a = 1;
  3216. insert into t5(a) values(20);
  3217. set autocommit = 0;
  3218. insert into t1(a) values(7);
  3219. insert into t2(a) values(8);
  3220. delete from t2 where a = 3;
  3221. update t4 set b = b + 1 where a = 3;
  3222. commit;
  3223. drop trigger t1t;
  3224. drop trigger t2t;
  3225. drop trigger t3t;
  3226. drop trigger t4t;
  3227. drop table t1, t2, t3, t4, t5;
  3228. CREATE TABLE t1 (
  3229. field1 varchar(8) NOT NULL DEFAULT '',
  3230. field2 varchar(8) NOT NULL DEFAULT '',
  3231. PRIMARY KEY (field1, field2)
  3232. ) ENGINE=InnoDB;
  3233. CREATE TABLE t2 (
  3234. field1 varchar(8) NOT NULL DEFAULT '' PRIMARY KEY,
  3235. FOREIGN KEY (field1) REFERENCES t1 (field1)
  3236. ON DELETE CASCADE ON UPDATE CASCADE
  3237. ) ENGINE=InnoDB;
  3238. INSERT INTO t1 VALUES ('old', 'somevalu');
  3239. INSERT INTO t1 VALUES ('other', 'anyvalue');
  3240. INSERT INTO t2 VALUES ('old');
  3241. INSERT INTO t2 VALUES ('other');
  3242. UPDATE t1 SET field1 = 'other' WHERE field2 = 'somevalu';
  3243. ERROR 23000: Upholding foreign key constraints for table 't1', entry 'other-somevalu', key 1 would lead to a duplicate entry
  3244. DROP TABLE t2;
  3245. DROP TABLE t1;
  3246. create table t1 (
  3247. c1 bigint not null,
  3248. c2 bigint not null,
  3249. primary key (c1),
  3250. unique key (c2)
  3251. ) engine=innodb;
  3252. create table t2 (
  3253. c1 bigint not null,
  3254. primary key (c1)
  3255. ) engine=innodb;
  3256. alter table t1 add constraint c2_fk foreign key (c2)
  3257. references t2(c1) on delete cascade;
  3258. show create table t1;
  3259. Table Create Table
  3260. t1 CREATE TABLE `t1` (
  3261. `c1` bigint(20) NOT NULL,
  3262. `c2` bigint(20) NOT NULL,
  3263. PRIMARY KEY (`c1`),
  3264. UNIQUE KEY `c2` (`c2`),
  3265. CONSTRAINT `c2_fk` FOREIGN KEY (`c2`) REFERENCES `t2` (`c1`) ON DELETE CASCADE
  3266. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  3267. alter table t1 drop foreign key c2_fk;
  3268. show create table t1;
  3269. Table Create Table
  3270. t1 CREATE TABLE `t1` (
  3271. `c1` bigint(20) NOT NULL,
  3272. `c2` bigint(20) NOT NULL,
  3273. PRIMARY KEY (`c1`),
  3274. UNIQUE KEY `c2` (`c2`)
  3275. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  3276. drop table t1, t2;
  3277. create table t1(a date) engine=innodb;
  3278. create table t2(a date, key(a)) engine=innodb;
  3279. insert into t1 values('2005-10-01');
  3280. insert into t2 values('2005-10-01');
  3281. select * from t1, t2
  3282. where t2.a between t1.a - interval 2 day and t1.a + interval 2 day;
  3283. a a
  3284. 2005-10-01 2005-10-01
  3285. drop table t1, t2;
  3286. create table t1 (id int not null, f_id int not null, f int not null,
  3287. primary key(f_id, id)) engine=innodb;
  3288. create table t2 (id int not null,s_id int not null,s varchar(200),
  3289. primary key(id)) engine=innodb;
  3290. INSERT INTO t1 VALUES (8, 1, 3);
  3291. INSERT INTO t1 VALUES (1, 2, 1);
  3292. INSERT INTO t2 VALUES (1, 0, '');
  3293. INSERT INTO t2 VALUES (8, 1, '');
  3294. commit;
  3295. DELETE ml.* FROM t1 AS ml LEFT JOIN t2 AS mm ON (mm.id=ml.id)
  3296. WHERE mm.id IS NULL;
  3297. select ml.* from t1 as ml left join t2 as mm on (mm.id=ml.id)
  3298. where mm.id is null lock in share mode;
  3299. id f_id f
  3300. drop table t1,t2;
  3301. create table t1(a int not null, b int, primary key(a)) engine=innodb;
  3302. insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2),(7,3);
  3303. commit;
  3304. set autocommit = 0;
  3305. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3306. update t1 set b = 5 where b = 1;
  3307. set autocommit = 0;
  3308. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3309. select * from t1 where a = 7 and b = 3 for update;
  3310. a b
  3311. 7 3
  3312. commit;
  3313. commit;
  3314. drop table t1;
  3315. create table t1(a int not null, b int, primary key(a)) engine=innodb;
  3316. insert into t1 values(1,1),(2,2),(3,1),(4,2),(5,1),(6,2);
  3317. commit;
  3318. set autocommit = 0;
  3319. select * from t1 lock in share mode;
  3320. a b
  3321. 1 1
  3322. 2 2
  3323. 3 1
  3324. 4 2
  3325. 5 1
  3326. 6 2
  3327. update t1 set b = 5 where b = 1;
  3328. set autocommit = 0;
  3329. select * from t1 where a = 2 and b = 2 for update;
  3330. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3331. commit;
  3332. commit;
  3333. drop table t1;
  3334. create table t1(a int not null, b int, primary key(a)) engine=innodb;
  3335. insert into t1 values (1,2),(5,3),(4,2);
  3336. create table t2(d int not null, e int, primary key(d)) engine=innodb;
  3337. insert into t2 values (8,6),(12,1),(3,1);
  3338. commit;
  3339. set autocommit = 0;
  3340. select * from t2 for update;
  3341. d e
  3342. 3 1
  3343. 8 6
  3344. 12 1
  3345. set autocommit = 0;
  3346. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3347. insert into t1 select * from t2;
  3348. update t1 set b = (select e from t2 where a = d);
  3349. create table t3(d int not null, e int, primary key(d)) engine=innodb
  3350. select * from t2;
  3351. commit;
  3352. commit;
  3353. drop table t1, t2, t3;
  3354. create table t1(a int not null, b int, primary key(a)) engine=innodb;
  3355. insert into t1 values (1,2),(5,3),(4,2);
  3356. create table t2(a int not null, b int, primary key(a)) engine=innodb;
  3357. insert into t2 values (8,6),(12,1),(3,1);
  3358. create table t3(d int not null, b int, primary key(d)) engine=innodb;
  3359. insert into t3 values (8,6),(12,1),(3,1);
  3360. create table t5(a int not null, b int, primary key(a)) engine=innodb;
  3361. insert into t5 values (1,2),(5,3),(4,2);
  3362. create table t6(d int not null, e int, primary key(d)) engine=innodb;
  3363. insert into t6 values (8,6),(12,1),(3,1);
  3364. create table t8(a int not null, b int, primary key(a)) engine=innodb;
  3365. insert into t8 values (1,2),(5,3),(4,2);
  3366. create table t9(d int not null, e int, primary key(d)) engine=innodb;
  3367. insert into t9 values (8,6),(12,1),(3,1);
  3368. commit;
  3369. set autocommit = 0;
  3370. select * from t2 for update;
  3371. a b
  3372. 3 1
  3373. 8 6
  3374. 12 1
  3375. set autocommit = 0;
  3376. SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3377. insert into t1 select * from t2;
  3378. set autocommit = 0;
  3379. SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3380. update t3 set b = (select b from t2 where a = d);
  3381. set autocommit = 0;
  3382. SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE;
  3383. create table t4(a int not null, b int, primary key(a)) engine=innodb select * from t2;
  3384. set autocommit = 0;
  3385. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3386. insert into t5 (select * from t2 lock in share mode);
  3387. set autocommit = 0;
  3388. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3389. update t6 set e = (select b from t2 where a = d lock in share mode);
  3390. set autocommit = 0;
  3391. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3392. create table t7(a int not null, b int, primary key(a)) engine=innodb select * from t2 lock in share mode;
  3393. set autocommit = 0;
  3394. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3395. insert into t8 (select * from t2 for update);
  3396. set autocommit = 0;
  3397. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3398. update t9 set e = (select b from t2 where a = d for update);
  3399. set autocommit = 0;
  3400. SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;
  3401. create table t10(a int not null, b int, primary key(a)) engine=innodb select * from t2 for update;
  3402. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3403. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3404. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3405. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3406. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3407. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3408. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3409. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3410. ERROR HY000: Lock wait timeout exceeded; try restarting transaction
  3411. commit;
  3412. drop table t1, t2, t3, t5, t6, t8, t9;
  3413. CREATE TABLE t1 (DB_ROW_ID int) engine=innodb;
  3414. ERROR HY000: Can't create table 'test.t1' (errno: -1)
  3415. CREATE TABLE t1 (
  3416. a BIGINT(20) NOT NULL,
  3417. PRIMARY KEY (a)
  3418. ) ENGINE=INNODB DEFAULT CHARSET=UTF8;
  3419. CREATE TABLE t2 (
  3420. a BIGINT(20) NOT NULL,
  3421. b VARCHAR(128) NOT NULL,
  3422. c TEXT NOT NULL,
  3423. PRIMARY KEY (a,b),
  3424. KEY idx_t2_b_c (b,c(200)),
  3425. CONSTRAINT t_fk FOREIGN KEY (a) REFERENCES t1 (a)
  3426. ON DELETE CASCADE
  3427. ) ENGINE=INNODB DEFAULT CHARSET=UTF8;
  3428. INSERT INTO t1 VALUES (1);
  3429. INSERT INTO t2 VALUES (1, 'bar', 'vbar');
  3430. INSERT INTO t2 VALUES (1, 'BAR2', 'VBAR');
  3431. INSERT INTO t2 VALUES (1, 'bar_bar', 'bibi');
  3432. INSERT INTO t2 VALUES (1, 'customer_over', '1');
  3433. SELECT * FROM t2 WHERE b = 'customer_over';
  3434. a b c
  3435. 1 customer_over 1
  3436. SELECT * FROM t2 WHERE BINARY b = 'customer_over';
  3437. a b c
  3438. 1 customer_over 1
  3439. SELECT DISTINCT p0.a FROM t2 p0 WHERE p0.b = 'customer_over';
  3440. a
  3441. 1
  3442. /* Bang: Empty result set, above was expected: */
  3443. SELECT DISTINCT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
  3444. a
  3445. 1
  3446. SELECT p0.a FROM t2 p0 WHERE BINARY p0.b = 'customer_over';
  3447. a
  3448. 1
  3449. drop table t2, t1;
  3450. CREATE TABLE t1 ( a int ) ENGINE=innodb;
  3451. BEGIN;
  3452. INSERT INTO t1 VALUES (1);
  3453. OPTIMIZE TABLE t1;
  3454. Table Op Msg_type Msg_text
  3455. test.t1 optimize status OK
  3456. DROP TABLE t1;
  3457. CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
  3458. CREATE TABLE t2 (id int PRIMARY KEY, f INT NOT NULL,
  3459. CONSTRAINT t2_t1 FOREIGN KEY (id) REFERENCES t1 (id)
  3460. ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB;
  3461. ALTER TABLE t2 ADD FOREIGN KEY (f) REFERENCES t1 (f) ON
  3462. DELETE CASCADE ON UPDATE CASCADE;
  3463. SHOW CREATE TABLE t2;
  3464. Table Create Table
  3465. t2 CREATE TABLE `t2` (
  3466. `id` int(11) NOT NULL,
  3467. `f` int(11) NOT NULL,
  3468. PRIMARY KEY (`id`),
  3469. KEY `f` (`f`),
  3470. CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE,
  3471. CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
  3472. ) ENGINE=InnoDB DEFAULT CHARSET=latin1
  3473. DROP TABLE t2, t1;
  3474. CREATE TABLE t1 (a INT, INDEX(a)) ENGINE=InnoDB;
  3475. CREATE TABLE t2 (a INT, INDEX(a)) ENGINE=InnoDB;
  3476. INSERT INTO t1 VALUES (1);
  3477. INSERT INTO t2 VALUES (1);
  3478. ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL;
  3479. ALTER TABLE t2 MODIFY a INT NOT NULL;
  3480. ERROR HY000: Error on rename of '#sql-temporary' to './test/t2' (errno: 150)
  3481. DELETE FROM t1;
  3482. DROP TABLE t2,t1;