1152
1150
show create table t1;
1153
1151
Table Create Table
1154
1152
t1 CREATE TABLE `t1` (
1157
1155
UNIQUE KEY `id` (`id`,`id2`)
1158
) ENGINE=InnoDB COLLATE = utf8_general_ci
1159
1157
show create table t2;
1160
1158
Table Create Table
1161
1159
t2 CREATE TABLE `t2` (
1163
1161
KEY `t1_id_fk` (`id`),
1164
1162
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1165
) ENGINE=InnoDB COLLATE = utf8_general_ci
1166
1164
create index id on t2 (id);
1167
1165
show create table t2;
1168
1166
Table Create Table
1169
1167
t2 CREATE TABLE `t2` (
1171
1169
KEY `id` (`id`),
1172
1170
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1173
) ENGINE=InnoDB COLLATE = utf8_general_ci
1174
1172
create index id2 on t2 (id);
1175
1173
show create table t2;
1176
1174
Table Create Table
1177
1175
t2 CREATE TABLE `t2` (
1179
1177
KEY `id` (`id`),
1180
1178
KEY `id2` (`id`),
1181
1179
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1182
) ENGINE=InnoDB COLLATE = utf8_general_ci
1183
1181
drop index id2 on t2;
1184
1182
drop index id on t2;
1185
1183
Got one of the listed errors
1186
1184
show create table t2;
1187
1185
Table Create Table
1188
1186
t2 CREATE TABLE `t2` (
1190
1188
KEY `id` (`id`),
1191
1189
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1192
) ENGINE=InnoDB COLLATE = utf8_general_ci
1194
1192
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;
1195
1193
show create table t2;
1196
1194
Table Create Table
1197
1195
t2 CREATE TABLE `t2` (
1200
1198
KEY `t1_id_fk` (`id`,`id2`),
1201
1199
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1202
) ENGINE=InnoDB COLLATE = utf8_general_ci
1203
1201
create unique index id on t2 (id,id2);
1204
1202
show create table t2;
1205
1203
Table Create Table
1206
1204
t2 CREATE TABLE `t2` (
1209
1207
UNIQUE KEY `id` (`id`,`id2`),
1210
1208
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`, `id2`) REFERENCES `t1` (`id`, `id2`)
1211
) ENGINE=InnoDB COLLATE = utf8_general_ci
1213
1211
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;
1214
1212
show create table t2;
1215
1213
Table Create Table
1216
1214
t2 CREATE TABLE `t2` (
1219
1217
UNIQUE KEY `id` (`id`,`id2`),
1220
1218
KEY `t1_id_fk` (`id2`,`id`),
1221
1219
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1222
) ENGINE=InnoDB COLLATE = utf8_general_ci
1224
1222
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;
1225
1223
show create table t2;
1226
1224
Table Create Table
1227
1225
t2 CREATE TABLE `t2` (
1230
1228
UNIQUE KEY `id` (`id`,`id2`),
1231
1229
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1232
) ENGINE=InnoDB COLLATE = utf8_general_ci
1234
1232
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;
1235
1233
show create table t2;
1236
1234
Table Create Table
1237
1235
t2 CREATE TABLE `t2` (
1240
1238
UNIQUE KEY `id` (`id`,`id2`),
1241
1239
KEY `t1_id_fk` (`id2`,`id`),
1242
1240
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id2`, `id`) REFERENCES `t1` (`id`, `id2`)
1243
) ENGINE=InnoDB COLLATE = utf8_general_ci
1245
1243
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;
1246
1244
show create table t2;
1247
1245
Table Create Table
1248
1246
t2 CREATE TABLE `t2` (
1249
`id` INT NOT NULL AUTO_INCREMENT,
1247
`id` int NOT NULL AUTO_INCREMENT,
1251
1249
PRIMARY KEY (`id`),
1252
1250
KEY `id` (`id`,`id2`),
1253
1251
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1254
) ENGINE=InnoDB COLLATE = utf8_general_ci
1256
1254
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;
1257
1255
show create table t2;
1258
1256
Table Create Table
1259
1257
t2 CREATE TABLE `t2` (
1260
`id` INT NOT NULL AUTO_INCREMENT,
1258
`id` int NOT NULL AUTO_INCREMENT,
1262
1260
KEY `t1_id_fk` (`id`),
1263
1261
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1264
) ENGINE=InnoDB COLLATE = utf8_general_ci
1265
1263
alter table t2 add index id_test (id), add index id_test2 (id,id2);
1266
1264
show create table t2;
1267
1265
Table Create Table
1268
1266
t2 CREATE TABLE `t2` (
1269
`id` INT NOT NULL AUTO_INCREMENT,
1267
`id` int NOT NULL AUTO_INCREMENT,
1271
1269
KEY `id_test` (`id`),
1272
1270
KEY `id_test2` (`id`,`id2`),
1273
1271
CONSTRAINT `t1_id_fk` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)
1274
) ENGINE=InnoDB COLLATE = utf8_general_ci
1276
1274
create table t2 (id int not null, id2 int not null, constraint t1_id_fk foreign key (id2,id) references t1 (id)) engine = innodb;
1277
1275
ERROR 42000: Incorrect foreign key definition for 't1_id_fk': Key reference and table reference don't match
1279
1277
show create table t2;
1280
1278
Table Create Table
1281
1279
t2 CREATE TABLE `t2` (
1282
`a` INT NOT NULL AUTO_INCREMENT,
1283
`b` INT DEFAULT NULL,
1280
`a` int NOT NULL AUTO_INCREMENT,
1281
`b` int DEFAULT NULL,
1284
1282
PRIMARY KEY (`a`),
1285
1283
UNIQUE KEY `b_2` (`b`),
1287
1285
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1288
) ENGINE=InnoDB COLLATE = utf8_general_ci
1290
1288
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;
1291
1289
show create table t2;
1292
1290
Table Create Table
1293
1291
t2 CREATE TABLE `t2` (
1294
`a` INT NOT NULL AUTO_INCREMENT,
1295
`b` INT DEFAULT NULL,
1292
`a` int NOT NULL AUTO_INCREMENT,
1293
`b` int DEFAULT NULL,
1296
1294
PRIMARY KEY (`a`),
1297
1295
UNIQUE KEY `b` (`b`),
1298
1296
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
1299
1297
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
1300
) ENGINE=InnoDB COLLATE = utf8_general_ci
1301
1299
drop table t2, t1;
1302
1300
create table t1 (c char(10), index (c,c)) engine=innodb;
1303
1301
ERROR 42S21: Duplicate column name 'c'
1498
1496
insert into t1 values('+ ', '+ ', '+ ');
1499
1497
set @a=repeat(' ',20);
1500
1498
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1501
ERROR 22001: Data too long for column 'v' at row 1
1502
set @a=repeat(' ',10);
1503
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1504
ERROR 22001: Data too long for column 'v' at row 1
1505
set @a=repeat(' ',9);
1506
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
1500
Note 1265 Data truncated for column 'v' at row 1
1501
Note 1265 Data truncated for column 'c' at row 1
1507
1502
select concat('*',v,'*',c,'*',t,'*') from t1;
1508
1503
concat('*',v,'*',c,'*',t,'*')
1511
1506
show create table t1;
1512
1507
Table Create Table
1513
1508
t1 CREATE TABLE `t1` (
1514
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1515
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1516
`t` TEXT COLLATE utf8_general_ci
1517
) ENGINE=InnoDB COLLATE = utf8_general_ci
1509
`v` varchar(10) DEFAULT NULL,
1510
`c` varchar(10) DEFAULT NULL,
1518
1513
create table t2 like t1;
1519
1514
show create table t2;
1520
1515
Table Create Table
1521
1516
t2 CREATE TABLE `t2` (
1522
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1523
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1524
`t` TEXT COLLATE utf8_general_ci
1525
) ENGINE=InnoDB COLLATE = utf8_general_ci
1517
`v` varchar(10) DEFAULT NULL,
1518
`c` varchar(10) DEFAULT NULL,
1526
1521
create table t3 select * from t1;
1527
1522
show create table t3;
1528
1523
Table Create Table
1529
1524
t3 CREATE TABLE `t3` (
1530
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1531
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1532
`t` TEXT COLLATE utf8_general_ci
1533
) ENGINE=InnoDB COLLATE = utf8_general_ci
1525
`v` varchar(10) DEFAULT NULL,
1526
`c` varchar(10) DEFAULT NULL,
1534
1529
alter table t1 modify c varchar(10);
1535
1530
show create table t1;
1536
1531
Table Create Table
1537
1532
t1 CREATE TABLE `t1` (
1538
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1539
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1540
`t` TEXT COLLATE utf8_general_ci
1541
) ENGINE=InnoDB COLLATE = utf8_general_ci
1533
`v` varchar(10) DEFAULT NULL,
1534
`c` varchar(10) DEFAULT NULL,
1542
1537
alter table t1 modify v char(10);
1543
1538
show create table t1;
1544
1539
Table Create Table
1545
1540
t1 CREATE TABLE `t1` (
1546
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1547
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1548
`t` TEXT COLLATE utf8_general_ci
1549
) ENGINE=InnoDB COLLATE = utf8_general_ci
1541
`v` varchar(10) DEFAULT NULL,
1542
`c` varchar(10) DEFAULT NULL,
1550
1545
alter table t1 modify t varchar(10);
1547
Note 1265 Data truncated for column 't' at row 2
1551
1548
show create table t1;
1552
1549
Table Create Table
1553
1550
t1 CREATE TABLE `t1` (
1554
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1555
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1556
`t` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
1557
) ENGINE=InnoDB COLLATE = utf8_general_ci
1551
`v` varchar(10) DEFAULT NULL,
1552
`c` varchar(10) DEFAULT NULL,
1553
`t` varchar(10) DEFAULT NULL
1558
1555
select concat('*',v,'*',c,'*',t,'*') from t1;
1559
1556
concat('*',v,'*',c,'*',t,'*')
1782
1779
alter table t1 modify v varchar(300), drop key v, drop key v_2, add key v (v);
1784
Warning 1071 Specified key was too long; max key length is 1023 bytes
1781
Warning 1071 Specified key was too long; max key length is 767 bytes
1785
1782
show create table t1;
1786
1783
Table Create Table
1787
1784
t1 CREATE TABLE `t1` (
1788
`v` VARCHAR(300) COLLATE utf8_general_ci DEFAULT NULL,
1789
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1790
`t` TEXT COLLATE utf8_general_ci,
1785
`v` varchar(300) DEFAULT NULL,
1786
`c` varchar(10) DEFAULT NULL,
1792
1789
KEY `t` (`t`(10)),
1794
) ENGINE=InnoDB COLLATE = utf8_general_ci
1795
1792
select count(*) from t1 where v='a';
1813
1810
explain select count(*) from t1 where v='a ';
1814
1811
id select_type table type possible_keys key key_len ref rows Extra
1815
1 SIMPLE t1 ref v v 1023 const # Using where
1812
1 SIMPLE t1 ref v v 767 const # Using where
1816
1813
explain select count(*) from t1 where v like 'a%';
1817
1814
id select_type table type possible_keys key key_len ref rows Extra
1818
1 SIMPLE t1 range v v 1023 NULL # Using where
1815
1 SIMPLE t1 range v v 767 NULL # Using where
1819
1816
explain select count(*) from t1 where v between 'a' and 'a ';
1820
1817
id select_type table type possible_keys key key_len ref rows Extra
1821
1 SIMPLE t1 ref v v 1023 const # Using where
1818
1 SIMPLE t1 ref v v 767 const # Using where
1822
1819
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
1823
1820
id select_type table type possible_keys key key_len ref rows Extra
1824
1 SIMPLE t1 ref v v 1023 const # Using where
1821
1 SIMPLE t1 ref v v 767 const # Using where
1825
1822
explain select * from t1 where v='a';
1826
1823
id select_type table type possible_keys key key_len ref rows Extra
1827
1 SIMPLE t1 ref v v 1023 const # Using where
1824
1 SIMPLE t1 ref v v 767 const # Using where
1828
1825
select v,count(*) from t1 group by v limit 10;
1944
1941
alter table t1 modify v varchar(600), drop key v, add key v (v);
1946
Warning 1071 Specified key was too long; max key length is 1023 bytes
1943
Warning 1071 Specified key was too long; max key length is 767 bytes
1947
1944
show create table t1;
1948
1945
Table Create Table
1949
1946
t1 CREATE TABLE `t1` (
1950
`v` VARCHAR(600) COLLATE utf8_general_ci DEFAULT NULL,
1951
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
1952
`t` TEXT COLLATE utf8_general_ci,
1947
`v` varchar(600) DEFAULT NULL,
1948
`c` varchar(10) DEFAULT NULL,
1954
1951
KEY `t` (`t`(10)),
1956
) ENGINE=InnoDB COLLATE = utf8_general_ci
1957
1954
select v,count(*) from t1 group by v limit 10;
2025
2022
show create table t1;
2026
2023
Table Create Table
2027
2024
t1 CREATE TABLE `t1` (
2028
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2029
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2030
`t` TEXT COLLATE utf8_general_ci,
2025
`v` varchar(10) DEFAULT NULL,
2026
`c` varchar(10) DEFAULT NULL,
2031
2028
KEY `v` (`v`(5)),
2032
2029
KEY `c` (`c`(5)),
2033
2030
KEY `t` (`t`(5))
2034
) ENGINE=InnoDB COLLATE = utf8_general_ci
2036
2033
create table t1 (v char(10));
2037
2034
show create table t1;
2038
2035
Table Create Table
2039
2036
t1 CREATE TABLE `t1` (
2040
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
2041
) ENGINE=InnoDB COLLATE = utf8_general_ci
2037
`v` varchar(10) DEFAULT NULL
2043
2040
create table t1 (v varchar(10), c char(10));
2044
2041
show create table t1;
2045
2042
Table Create Table
2046
2043
t1 CREATE TABLE `t1` (
2047
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
2048
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL
2049
) ENGINE=InnoDB COLLATE = utf8_general_ci
2044
`v` varchar(10) DEFAULT NULL,
2045
`c` varchar(10) DEFAULT NULL
2050
2047
insert into t1 values('a','a'),('a ','a ');
2051
2048
select concat('*',v,'*',c,'*') from t1;
2052
2049
concat('*',v,'*',c,'*')
2065
2062
create table t1 (v varchar(16383), key(v));
2067
Warning 1071 Specified key was too long; max key length is 1023 bytes
2069
create table t1 (v varchar(16383));
2070
show create table t1;
2072
t1 CREATE TABLE `t1` (
2073
`v` VARCHAR(16383) COLLATE utf8_general_ci DEFAULT NULL
2074
) ENGINE=InnoDB COLLATE = utf8_general_ci
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
2064
Warning 1071 Specified key was too long; max key length is 767 bytes
2066
create table t1 (v varchar(16383));
2067
show create table t1;
2069
t1 CREATE TABLE `t1` (
2070
`v` varchar(16383) DEFAULT NULL
2073
create table t1 (v varchar(16383));
2074
show create table t1;
2076
t1 CREATE TABLE `t1` (
2077
`v` varchar(16383) DEFAULT NULL
2083
2080
set storage_engine=PBXT;
2084
2081
create table t1 (v varchar(16383)) engine=innodb;
2183
2191
create table t7 (col1 text, index(col1(767)))
2184
2192
engine = innodb;
2186
Warning 1071 Specified key was too long; max key length is 1023 bytes
2194
Warning 1071 Specified key was too long; max key length is 767 bytes
2187
2195
create table t8 (col1 blob, index(col1(767)))
2188
2196
engine = innodb;
2189
2197
create table t9 (col1 varchar(512), col2 varchar(512), index(col1, col2))
2190
2198
engine = innodb;
2192
Warning 1071 Specified key was too long; max key length is 1023 bytes
2193
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 767 bytes
2201
Warning 1071 Specified key was too long; max key length is 767 bytes
2194
2202
show create table t9;
2195
2203
Table Create Table
2196
2204
t9 CREATE TABLE `t9` (
2197
`col1` VARCHAR(512) COLLATE utf8_general_ci DEFAULT NULL,
2198
`col2` VARCHAR(512) COLLATE utf8_general_ci DEFAULT NULL,
2199
KEY `col1` (`col1`(255),`col2`(255))
2200
) ENGINE=InnoDB COLLATE = utf8_general_ci
2205
`col1` varchar(512) DEFAULT NULL,
2206
`col2` varchar(512) DEFAULT NULL,
2207
KEY `col1` (`col1`(191),`col2`(191))
2201
2209
drop table t1, t2, t4, t5, t6, t7, t8, t9;
2202
2210
create table t1 (col1 varchar(768), index(col1))
2203
2211
engine = innodb;
2205
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
2206
2214
create table t2 (col1 varbinary(768), index(col1))
2207
2215
engine = innodb;
2217
Warning 1071 Specified key was too long; max key length is 767 bytes
2208
2218
create table t3 (col1 text, index(col1(768)))
2209
2219
engine = innodb;
2211
Warning 1071 Specified key was too long; max key length is 1023 bytes
2221
Warning 1071 Specified key was too long; max key length is 767 bytes
2212
2222
create table t4 (col1 blob, index(col1(768)))
2213
2223
engine = innodb;
2225
Warning 1071 Specified key was too long; max key length is 767 bytes
2214
2226
show create table t1;
2215
2227
Table Create Table
2216
2228
t1 CREATE TABLE `t1` (
2217
`col1` VARCHAR(768) COLLATE utf8_general_ci DEFAULT NULL,
2218
KEY `col1` (`col1`(255))
2219
) ENGINE=InnoDB COLLATE = utf8_general_ci
2229
`col1` varchar(768) DEFAULT NULL,
2230
KEY `col1` (`col1`(191))
2220
2232
drop table t1, t2, t3, t4;
2221
2233
create table t1 (col1 varchar(768) primary key)
2222
2234
engine = innodb;
2223
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2224
create table t2 (col1 varbinary(1024) primary key)
2235
ERROR 42000: Specified key was too long; max key length is 767 bytes
2236
create table t2 (col1 varbinary(768) primary key)
2225
2237
engine = innodb;
2226
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2238
ERROR 42000: Specified key was too long; max key length is 767 bytes
2227
2239
create table t3 (col1 text, primary key(col1(768)))
2228
2240
engine = innodb;
2229
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2230
create table t4 (col1 blob, primary key(col1(1024)))
2241
ERROR 42000: Specified key was too long; max key length is 767 bytes
2242
create table t4 (col1 blob, primary key(col1(768)))
2231
2243
engine = innodb;
2232
ERROR 42000: Specified key was too long; max key length is 1023 bytes
2244
ERROR 42000: Specified key was too long; max key length is 767 bytes
2233
2245
CREATE TABLE t1
2235
2247
id INT PRIMARY KEY