398
399
CREATE TABLE t1 (a int not null, b int not null,c int not null,
399
400
key(a),primary key(a,b), unique(c),key(a),unique(b));
400
401
show index from t1;
401
Table Unique Key_name Seq_in_index Column_name
402
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_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
410
create table t1 (col1 int not null, col2 char(4) not null, primary key(col1));
410
411
alter table t1 engine=innodb;
1126
1128
3524 Societe Test
1127
1129
3525 Fournisseur Test
1128
1130
drop table t1,t2;
1129
create TEMPORARY table t1 (a int, b varchar(200), c text not null) engine=myisam;
1130
create table t2 (a int, b varchar(200), c text not null) engine=innodb;
1131
create table t3 (a int, b varchar(200), c text not null) engine=innodb;
1131
create TEMPORARY table t1 (a int, b varchar(200), c text not null) checksum=1 engine=myisam;
1132
create table t2 (a int, b varchar(200), c text not null) checksum=0 engine=innodb;
1133
create table t3 (a int, b varchar(200), c text not null) checksum=1 engine=innodb;
1132
1134
insert t1 values (1, "aaa", "bbb"), (NULL, "", "ccccc"), (0, NULL, "");
1133
1135
insert t2 select * from t1;
1134
1136
insert t3 select * from t1;
1137
checksum table t1, t2, t3, t4 quick;
1144
Error 1146 Table 'test.t4' doesn't exist
1145
checksum table t1, t2, t3, t4;
1152
Error 1146 Table 'test.t4' doesn't exist
1153
checksum table t1, t2, t3, t4 extended;
1160
Error 1146 Table 'test.t4' doesn't exist
1135
1161
drop table t1,t2,t3;
1136
1162
create table t1 (id int, name char(10) not null, name2 char(10) not null) engine=innodb;
1137
1163
insert into t1 values(1,'first','fff'),(2,'second','sss'),(3,'third','ttt');
1155
1181
show create table t1;
1156
1182
Table Create Table
1157
1183
t1 CREATE TABLE `t1` (
1160
1186
UNIQUE KEY `id` (`id`,`id2`)
1161
) ENGINE=InnoDB COLLATE = utf8_general_ci
1162
1188
show create table t2;
1163
1189
Table Create Table
1164
1190
t2 CREATE TABLE `t2` (
1166
1192
KEY `t1_id_fk` (`id`),
1167
1193
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1168
) ENGINE=InnoDB COLLATE = utf8_general_ci
1169
1195
create index id on t2 (id);
1170
1196
show create table t2;
1171
1197
Table Create Table
1172
1198
t2 CREATE TABLE `t2` (
1174
1200
KEY `id` (`id`),
1175
1201
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1176
) ENGINE=InnoDB COLLATE = utf8_general_ci
1177
1203
create index id2 on t2 (id);
1178
1204
show create table t2;
1179
1205
Table Create Table
1180
1206
t2 CREATE TABLE `t2` (
1182
1208
KEY `id` (`id`),
1183
1209
KEY `id2` (`id`),
1184
1210
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1185
) ENGINE=InnoDB COLLATE = utf8_general_ci
1186
1212
drop index id2 on t2;
1187
1213
drop index id on t2;
1188
1214
Got one of the listed errors
1189
1215
show create table t2;
1190
1216
Table Create Table
1191
1217
t2 CREATE TABLE `t2` (
1193
1219
KEY `id` (`id`),
1194
1220
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1195
) ENGINE=InnoDB COLLATE = utf8_general_ci
1197
1223
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id,id2) references t1 (id,id2)) engine = innodb;
1198
1224
show create table t2;
1199
1225
Table Create Table
1200
1226
t2 CREATE TABLE `t2` (
1203
1229
KEY `t1_id_fk` (`id`,`id2`),
1204
1230
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1205
) ENGINE=InnoDB COLLATE = utf8_general_ci
1206
1232
create unique index id on t2 (id,id2);
1207
1233
show create table t2;
1208
1234
Table Create Table
1209
1235
t2 CREATE TABLE `t2` (
1212
1238
UNIQUE KEY `id` (`id`,`id2`),
1213
1239
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1214
) ENGINE=InnoDB COLLATE = utf8_general_ci
1216
1242
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
1217
1243
show create table t2;
1218
1244
Table Create Table
1219
1245
t2 CREATE TABLE `t2` (
1222
1248
UNIQUE KEY `id` (`id`,`id2`),
1223
1249
KEY `t1_id_fk` (`id2`,`id`),
1224
1250
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1225
) ENGINE=InnoDB COLLATE = utf8_general_ci
1227
1253
create table t2 (id int not null, id2 int not null, unique (id,id2), constraint t1_id_fk foreign key (id) references t1 (id)) engine = innodb;
1228
1254
show create table t2;
1229
1255
Table Create Table
1230
1256
t2 CREATE TABLE `t2` (
1233
1259
UNIQUE KEY `id` (`id`,`id2`),
1234
1260
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1235
) ENGINE=InnoDB COLLATE = utf8_general_ci
1237
1263
create table t2 (id int not null, id2 int not null, unique (id,id2),constraint t1_id_fk foreign key (id2,id) references t1 (id,id2)) engine = innodb;
1238
1264
show create table t2;
1239
1265
Table Create Table
1240
1266
t2 CREATE TABLE `t2` (
1243
1269
UNIQUE KEY `id` (`id`,`id2`),
1244
1270
KEY `t1_id_fk` (`id2`,`id`),
1245
1271
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1246
) ENGINE=InnoDB COLLATE = utf8_general_ci
1248
1274
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id), primary key (id), index (id,id2)) engine = innodb;
1249
1275
show create table t2;
1250
1276
Table Create Table
1251
1277
t2 CREATE TABLE `t2` (
1252
`id` INT NOT NULL AUTO_INCREMENT,
1278
`id` int NOT NULL AUTO_INCREMENT,
1254
1280
PRIMARY KEY (`id`),
1255
1281
KEY `id` (`id`,`id2`),
1256
1282
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1257
) ENGINE=InnoDB COLLATE = utf8_general_ci
1259
1285
create table t2 (id int not null auto_increment, id2 int not null, constraint t1_id_fk foreign key (id) references t1 (id)) engine= innodb;
1260
1286
show create table t2;
1261
1287
Table Create Table
1262
1288
t2 CREATE TABLE `t2` (
1263
`id` INT NOT NULL AUTO_INCREMENT,
1289
`id` int NOT NULL AUTO_INCREMENT,
1265
1291
KEY `t1_id_fk` (`id`),
1266
1292
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1267
) ENGINE=InnoDB COLLATE = utf8_general_ci
1268
1294
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1269
1295
show create table t2;
1270
1296
Table Create Table
1271
1297
t2 CREATE TABLE `t2` (
1272
`id` INT NOT NULL AUTO_INCREMENT,
1298
`id` int NOT NULL AUTO_INCREMENT,
1274
1300
KEY `id_test` (`id`),
1275
1301
KEY `id_test2` (`id`,`id2`),
1276
1302
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1277
) ENGINE=InnoDB COLLATE = utf8_general_ci
1279
1305
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1280
1306
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
1282
1308
show create table t2;
1283
1309
Table Create Table
1284
1310
t2 CREATE TABLE `t2` (
1285
`a` INT NOT NULL AUTO_INCREMENT,
1286
`b` INT DEFAULT NULL,
1311
`a` int NOT NULL AUTO_INCREMENT,
1312
`b` int DEFAULT NULL,
1287
1313
PRIMARY KEY (`a`),
1288
1314
UNIQUE KEY `b_2` (`b`),
1290
1316
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1291
) ENGINE=InnoDB COLLATE = utf8_general_ci
1293
1319
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;
1294
1320
show create table t2;
1295
1321
Table Create Table
1296
1322
t2 CREATE TABLE `t2` (
1297
`a` INT NOT NULL AUTO_INCREMENT,
1298
`b` INT DEFAULT NULL,
1323
`a` int NOT NULL AUTO_INCREMENT,
1324
`b` int DEFAULT NULL,
1299
1325
PRIMARY KEY (`a`),
1300
1326
UNIQUE KEY `b` (`b`),
1301
1327
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
1302
1328
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1303
) ENGINE=InnoDB COLLATE = utf8_general_ci
1304
1330
drop table t2, t1;
1305
1331
create table t1 (c char(10), index (c,c)) engine=innodb;
1306
1332
ERROR 42S21: Duplicate column name 'c'
1412
show status like "Innodb_buffer_pool_pages_total";
1414
show status like "Innodb_page_size";
1416
show status like "Innodb_rows_deleted";
1418
show status like "Innodb_rows_inserted";
1420
show status like "Innodb_rows_updated";
1422
show status like "Innodb_row_lock_waits";
1424
show status like "Innodb_row_lock_current_waits";
1426
show status like "Innodb_row_lock_time";
1428
show status like "Innodb_row_lock_time_max";
1430
show status like "Innodb_row_lock_time_avg";
1432
set @my_innodb_sync_spin_loops = @@global.innodb_sync_spin_loops;
1433
1438
show variables like "innodb_sync_spin_loops";
1434
1439
Variable_name Value
1435
innodb_sync_spin_loops 30
1440
innodb_sync_spin_loops 20
1436
1441
set global innodb_sync_spin_loops=1000;
1437
1442
show variables like "innodb_sync_spin_loops";
1438
1443
Variable_name Value
1445
1450
show variables like "innodb_sync_spin_loops";
1446
1451
Variable_name Value
1447
1452
innodb_sync_spin_loops 20
1448
set @@global.innodb_sync_spin_loops = @my_innodb_sync_spin_loops;
1449
set @my_innodb_thread_concurrency = @@global.innodb_thread_concurrency;
1450
1453
show variables like "innodb_thread_concurrency";
1451
1454
Variable_name Value
1452
1455
innodb_thread_concurrency 0
1453
1456
set global innodb_thread_concurrency=1001;
1455
Error 1524 Error setting innodb_thread_concurrency. Given value 1001 (> 1000)
1458
Error 1292 Truncated incorrect thread_concurrency value: '1001'
1456
1459
show variables like "innodb_thread_concurrency";
1457
1460
Variable_name Value
1458
innodb_thread_concurrency 0
1461
innodb_thread_concurrency 1000
1459
1462
set global innodb_thread_concurrency=0;
1460
1463
show variables like "innodb_thread_concurrency";
1461
1464
Variable_name Value
1505
1507
insert into t1 values('+ ', '+ ', '+ ');
1506
1508
set @a=repeat(' ',20);
1507
1509
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1508
ERROR 22001: Data too long for column 'v' at row 1
1509
set @a=repeat(' ',10);
1510
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1511
ERROR 22001: Data too long for column 'v' at row 1
1512
set @a=repeat(' ',9);
1513
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1511
Note 1265 Data truncated for column 'v' at row 1
1512
Note 1265 Data truncated for column 'c' at row 1
1514
1513
select concat('*',v,'*',c,'*',t,'*') from t1;
1515
1514
concat('*',v,'*',c,'*',t,'*')
1518
1517
show create table t1;
1519
1518
Table Create Table
1520
1519
t1 CREATE TABLE `t1` (
1521
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1522
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1523
`t` TEXT COLLATE utf8_general_ci
1524
) ENGINE=InnoDB COLLATE = utf8_general_ci
1520
`v` varchar(10) DEFAULT NULL,
1521
`c` varchar(10) DEFAULT NULL,
1525
1524
create table t2 like t1;
1526
1525
show create table t2;
1527
1526
Table Create Table
1528
1527
t2 CREATE TABLE `t2` (
1529
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1530
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1531
`t` TEXT COLLATE utf8_general_ci
1532
) ENGINE=InnoDB COLLATE = utf8_general_ci
1528
`v` varchar(10) DEFAULT NULL,
1529
`c` varchar(10) DEFAULT NULL,
1533
1532
create table t3 select * from t1;
1534
1533
show create table t3;
1535
1534
Table Create Table
1536
1535
t3 CREATE TABLE `t3` (
1537
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1538
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1539
`t` TEXT COLLATE utf8_general_ci
1540
) ENGINE=InnoDB COLLATE = utf8_general_ci
1536
`v` varchar(10) DEFAULT NULL,
1537
`c` varchar(10) DEFAULT NULL,
1541
1540
alter table t1 modify c varchar(10);
1542
1541
show create table t1;
1543
1542
Table Create Table
1544
1543
t1 CREATE TABLE `t1` (
1545
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1546
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1547
`t` TEXT COLLATE utf8_general_ci
1548
) ENGINE=InnoDB COLLATE = utf8_general_ci
1544
`v` varchar(10) DEFAULT NULL,
1545
`c` varchar(10) DEFAULT NULL,
1549
1548
alter table t1 modify v char(10);
1550
1549
show create table t1;
1551
1550
Table Create Table
1552
1551
t1 CREATE TABLE `t1` (
1553
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1554
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1555
`t` TEXT COLLATE utf8_general_ci
1556
) ENGINE=InnoDB COLLATE = utf8_general_ci
1552
`v` varchar(10) DEFAULT NULL,
1553
`c` varchar(10) DEFAULT NULL,
1557
1556
alter table t1 modify t varchar(10);
1558
Note 1265 Data truncated for column 't' at row 2
1558
1559
show create table t1;
1559
1560
Table Create Table
1560
1561
t1 CREATE TABLE `t1` (
1561
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1562
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1563
`t` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
1564
) ENGINE=InnoDB COLLATE = utf8_general_ci
1562
`v` varchar(10) DEFAULT NULL,
1563
`c` varchar(10) DEFAULT NULL,
1564
`t` varchar(10) DEFAULT NULL
1565
1566
select concat('*',v,'*',c,'*',t,'*') from t1;
1566
1567
concat('*',v,'*',c,'*',t,'*')
1789
1790
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
1791
Warning 1071 Specified key was too long; max key length is 1023 bytes
1792
Warning 1071 Specified key was too long; max key length is 767 bytes
1792
1793
show create table t1;
1793
1794
Table Create Table
1794
1795
t1 CREATE TABLE `t1` (
1795
`v` VARCHAR(300) COLLATE utf8_general_ci DEFAULT NULL,
1796
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1797
`t` TEXT COLLATE utf8_general_ci,
1796
`v` varchar(300) DEFAULT NULL,
1797
`c` varchar(10) DEFAULT NULL,
1799
1800
KEY `t` (`t`(10)),
1801
) ENGINE=InnoDB COLLATE = utf8_general_ci
1802
1803
select count(*) from t1 where v='a';
1820
1821
explain select count(*) from t1 where v='a ';
1821
1822
id select_type table type possible_keys key key_len ref rows Extra
1822
1 SIMPLE t1 ref v v 1023 const # Using where
1823
1 SIMPLE t1 ref v v 767 const # Using where
1823
1824
explain select count(*) from t1 where v like 'a%';
1824
1825
id select_type table type possible_keys key key_len ref rows Extra
1825
1 SIMPLE t1 range v v 1023 NULL # Using where
1826
1 SIMPLE t1 range v v 767 NULL # Using where
1826
1827
explain select count(*) from t1 where v between 'a' and 'a ';
1827
1828
id select_type table type possible_keys key key_len ref rows Extra
1828
1 SIMPLE t1 ref v v 1023 const # Using where
1829
1 SIMPLE t1 ref v v 767 const # Using where
1829
1830
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1830
1831
id select_type table type possible_keys key key_len ref rows Extra
1831
1 SIMPLE t1 ref v v 1023 const # Using where
1832
1 SIMPLE t1 ref v v 767 const # Using where
1832
1833
explain select * from t1 where v='a';
1833
1834
id select_type table type possible_keys key key_len ref rows Extra
1834
1 SIMPLE t1 ref v v 1023 const # Using where
1835
1 SIMPLE t1 ref v v 767 const # Using where
1835
1836
select v,count(*) from t1 group by v limit 10;
1951
1952
alter table t1 modify v varchar(600), drop key v, add key v (v);
1953
Warning 1071 Specified key was too long; max key length is 1023 bytes
1954
Warning 1071 Specified key was too long; max key length is 767 bytes
1954
1955
show create table t1;
1955
1956
Table Create Table
1956
1957
t1 CREATE TABLE `t1` (
1957
`v` VARCHAR(600) COLLATE utf8_general_ci DEFAULT NULL,
1958
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1959
`t` TEXT COLLATE utf8_general_ci,
1958
`v` varchar(600) DEFAULT NULL,
1959
`c` varchar(10) DEFAULT NULL,
1961
1962
KEY `t` (`t`(10)),
1963
) ENGINE=InnoDB COLLATE = utf8_general_ci
1964
1965
select v,count(*) from t1 group by v limit 10;
2032
2033
show create table t1;
2033
2034
Table Create Table
2034
2035
t1 CREATE TABLE `t1` (
2035
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2036
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2037
`t` TEXT COLLATE utf8_general_ci,
2036
`v` varchar(10) DEFAULT NULL,
2037
`c` varchar(10) DEFAULT NULL,
2038
2039
KEY `v` (`v`(5)),
2039
2040
KEY `c` (`c`(5)),
2040
2041
KEY `t` (`t`(5))
2041
) ENGINE=InnoDB COLLATE = utf8_general_ci
2043
2044
create table t1 (v char(10));
2044
2045
show create table t1;
2045
2046
Table Create Table
2046
2047
t1 CREATE TABLE `t1` (
2047
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
2048
) ENGINE=InnoDB COLLATE = utf8_general_ci
2048
`v` varchar(10) DEFAULT NULL
2050
create table t1 (v varchar(10), c char(10));
2051
create table t1 (v varchar(10), c char(10)) row_format=fixed;
2053
Warning 1478 InnoDB: assuming ROW_FORMAT=COMPACT.
2051
2054
show create table t1;
2052
2055
Table Create Table
2053
2056
t1 CREATE TABLE `t1` (
2054
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2055
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
2056
) ENGINE=InnoDB COLLATE = utf8_general_ci
2057
`v` varchar(10) DEFAULT NULL,
2058
`c` varchar(10) DEFAULT NULL
2059
) ENGINE=InnoDB ROW_FORMAT=FIXED
2057
2060
insert into t1 values('a','a'),('a ','a ');
2058
2061
select concat('*',v,'*',c,'*') from t1;
2059
2062
concat('*',v,'*',c,'*')
2072
2075
create table t1 (v varchar(16383), key(v));
2074
Warning 1071 Specified key was too long; max key length is 1023 bytes
2076
create table t1 (v varchar(16383));
2077
show create table t1;
2079
t1 CREATE TABLE `t1` (
2080
`v` VARCHAR(16383) COLLATE utf8_general_ci DEFAULT NULL
2081
) ENGINE=InnoDB COLLATE = utf8_general_ci
2083
create table t1 (v varchar(16383));
2084
show create table t1;
2086
t1 CREATE TABLE `t1` (
2087
`v` VARCHAR(16383) COLLATE utf8_general_ci DEFAULT NULL
2088
) ENGINE=InnoDB COLLATE = utf8_general_ci
2077
Warning 1071 Specified key was too long; max key length is 767 bytes
2079
create table t1 (v varchar(16383));
2080
show create table t1;
2082
t1 CREATE TABLE `t1` (
2083
`v` varchar(16383) DEFAULT NULL
2086
create table t1 (v varchar(16383));
2087
show create table t1;
2089
t1 CREATE TABLE `t1` (
2090
`v` varchar(16383) DEFAULT NULL
2090
2093
set storage_engine=InnoDB;
2091
2094
create table t1 (v varchar(16383)) engine=innodb;
2190
2204
create table t7 (col1 text, index(col1(767)))
2191
2205
engine = innodb;
2193
Warning 1071 Specified key was too long; max key length is 1023 bytes
2207
Warning 1071 Specified key was too long; max key length is 767 bytes
2194
2208
create table t8 (col1 blob, index(col1(767)))
2195
2209
engine = innodb;
2196
2210
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
2197
2211
engine = innodb;
2199
Warning 1071 Specified key was too long; max key length is 1023 bytes
2200
Warning 1071 Specified key was too long; max key length is 1023 bytes
2213
Warning 1071 Specified key was too long; max key length is 767 bytes
2214
Warning 1071 Specified key was too long; max key length is 767 bytes
2201
2215
show create table t9;
2202
2216
Table Create Table
2203
2217
t9 CREATE TABLE `t9` (
2204
`col1` VARCHAR(512) COLLATE utf8_general_ci DEFAULT NULL,
2205
`col2` VARCHAR(512) COLLATE utf8_general_ci DEFAULT NULL,
2206
KEY `col1` (`col1`(255),`col2`(255))
2207
) ENGINE=InnoDB COLLATE = utf8_general_ci
2218
`col1` varchar(512) DEFAULT NULL,
2219
`col2` varchar(512) DEFAULT NULL,
2220
KEY `col1` (`col1`(191),`col2`(191))
2208
2222
drop table t1, t2, t4, t5, t6, t7, t8, t9;
2209
2223
create table t1 (col1 varchar(768), index(col1))
2210
2224
engine = innodb;
2212
Warning 1071 Specified key was too long; max key length is 1023 bytes
2226
Warning 1071 Specified key was too long; max key length is 767 bytes
2213
2227
create table t2 (col1 varbinary(768), index(col1))
2214
2228
engine = innodb;
2230
Warning 1071 Specified key was too long; max key length is 767 bytes
2215
2231
create table t3 (col1 text, index(col1(768)))
2216
2232
engine = innodb;
2218
Warning 1071 Specified key was too long; max key length is 1023 bytes
2234
Warning 1071 Specified key was too long; max key length is 767 bytes
2219
2235
create table t4 (col1 blob, index(col1(768)))
2220
2236
engine = innodb;
2238
Warning 1071 Specified key was too long; max key length is 767 bytes
2221
2239
show create table t1;
2222
2240
Table Create Table
2223
2241
t1 CREATE TABLE `t1` (
2224
`col1` VARCHAR(768) COLLATE utf8_general_ci DEFAULT NULL,
2225
KEY `col1` (`col1`(255))
2226
) ENGINE=InnoDB COLLATE = utf8_general_ci
2242
`col1` varchar(768) DEFAULT NULL,
2243
KEY `col1` (`col1`(191))
2227
2245
drop table t1, t2, t3, t4;
2228
2246
create table t1 (col1 varchar(768) primary key)
2229
2247
engine = innodb;
2230
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2231
create table t2 (col1 varbinary(1024) primary key)
2248
ERROR 42000: Specified key was too long; max key length is 767 bytes
2249
create table t2 (col1 varbinary(768) primary key)
2232
2250
engine = innodb;
2233
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2251
ERROR 42000: Specified key was too long; max key length is 767 bytes
2234
2252
create table t3 (col1 text, primary key(col1(768)))
2235
2253
engine = innodb;
2236
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2237
create table t4 (col1 blob, primary key(col1(1024)))
2254
ERROR 42000: Specified key was too long; max key length is 767 bytes
2255
create table t4 (col1 blob, primary key(col1(768)))
2238
2256
engine = innodb;
2239
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2257
ERROR 42000: Specified key was too long; max key length is 767 bytes
2240
2258
CREATE TABLE t1
2242
2260
id INT PRIMARY KEY
2260
2278
INSERT INTO t2 VALUES(3);
2261
2279
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `c1` FOREIGN KEY (`v`) REFERENCES `t1` (`id`))
2281
create table t1(a int not null) engine=innodb;
2282
insert into t1 values (1),(2);
2287
insert into t1 values(3);
2297
create table t1(a int not null) engine=innodb;
2298
insert into t1 values (1),(2);
2304
insert into t1 values(3);
2263
2309
set foreign_key_checks=0;
2264
2310
create table t2 (a int primary key, b int, foreign key (b) references t1(a)) engine = innodb;
2265
2311
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
2316
2367
key (a,b,c,d,e)) engine=innodb;
2317
2368
ERROR 42000: Specified key was too long; max key length is 3500 bytes
2318
2369
create table t1 (s1 varbinary(2),primary key (s1)) engine=innodb;
2319
create table t3 (s1 varchar(2) ,primary key (s1)) engine=innodb;
2320
create table t4 (s1 char(2) ,primary key (s1)) engine=innodb;
2370
create table t3 (s1 varchar(2) binary,primary key (s1)) engine=innodb;
2371
create table t4 (s1 char(2) binary,primary key (s1)) engine=innodb;
2321
2372
insert into t1 values (0x41),(0x4120),(0x4100);
2322
2373
insert into t3 values (0x41),(0x4120),(0x4100);
2323
2374
ERROR 23000: Duplicate entry 'A ' for key 'PRIMARY'
2697
2750
SHOW CREATE TABLE t1;
2698
2751
Table Create Table
2699
2752
t1 CREATE TABLE `t1` (
2700
`id` INT NOT NULL AUTO_INCREMENT,
2753
`id` int NOT NULL AUTO_INCREMENT,
2701
2754
PRIMARY KEY (`id`)
2702
) ENGINE=InnoDB COLLATE = utf8_general_ci AUTO_INCREMENT=42
2755
) ENGINE=InnoDB AUTO_INCREMENT=349
2703
2756
CREATE TABLE t2 (id int PRIMARY KEY) ENGINE=InnoDB;
2704
2757
INSERT INTO t2 VALUES(42),(347),(348);
2705
2758
ALTER TABLE t1 ADD CONSTRAINT t1_t2 FOREIGN KEY (id) REFERENCES t2(id);
2706
2759
SHOW CREATE TABLE t1;
2707
2760
Table Create Table
2708
2761
t1 CREATE TABLE `t1` (
2709
`id` INT NOT NULL AUTO_INCREMENT,
2762
`id` int NOT NULL AUTO_INCREMENT,
2710
2763
PRIMARY KEY (`id`),
2711
2764
CONSTRAINT `t1_t2` FOREIGN KEY (`id`) REFERENCES `t2` (`id`)
2712
) ENGINE=InnoDB COLLATE = utf8_general_ci
2765
) ENGINE=InnoDB AUTO_INCREMENT=349
2713
2766
DROP TABLE t1,t2;
2714
2767
DROP TABLE IF EXISTS t1;