1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
|
# Pre-create some tables, so that DDTableBuffer is not empty
set global innodb_flush_log_at_trx_commit=1;
CREATE TABLE t1(a TINYINT AUTO_INCREMENT KEY) ENGINE = InnoDB;
INSERT INTO t1 VALUES(0), (0), (0), (0), (-1), (-10), (0),
(20), (30), (31);
SELECT * FROM t1;
a
-10
-1
1
2
3
4
5
20
30
31
CREATE TABLE t2(a TINYINT UNSIGNED AUTO_INCREMENT KEY) ENGINE = InnoDB;
INSERT INTO t2 VALUES(-5);
ERROR 22003: Out of range value for column 'a' at row 1
INSERT INTO t2 VALUES(0), (0), (0), (0), (8), (10), (0),
(20), (30), (31);
SELECT * FROM t2;
a
1
2
3
4
8
10
11
20
30
31
CREATE TABLE t3(a SMALLINT AUTO_INCREMENT KEY) ENGINE = InnoDB;
INSERT INTO t3 VALUES(0), (0), (0), (0), (-1), (-10), (0),
(20), (30), (31), (1024), (4096);
SELECT * FROM t3;
a
-10
-1
1
2
3
4
5
20
30
31
1024
4096
# restart
set global innodb_flush_log_at_trx_commit=1;
# Scenario 1: Create two new tables, with simple DMLs on them,
# and force a checkpoint, then some other DMLs on them
CREATE TABLE t4(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT, KEY b(b)) ENGINE = InnoDB;
CREATE TABLE t5(a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT, KEY b(b)) ENGINE = InnoDB;
SET @start_global_value = @@global.innodb_log_checkpoint_now;
SELECT @start_global_value;
@start_global_value
0
# Invoke a checkpoint, which would persist the autoinc counters
# of t4 and t5 into DD Table Buffer
set global innodb_log_checkpoint_now=ON;
INSERT INTO t4 VALUES(0, 1), (0, 2), (10, 3), (12, 4), (0, 5);
SELECT * FROM t4;
a b
1 1
2 2
10 3
12 4
13 5
SHOW CREATE TABLE t4;
Table Create Table
t4 CREATE TABLE `t4` (
`a` int NOT NULL AUTO_INCREMENT,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
INSERT INTO t5 VALUES(0, 1), (100, 2), (50, 3);
INSERT INTO t5 VALUES(0, 4), (109, 5), (0, 6);
SELECT * FROM t5;
a b
1 1
100 2
50 3
101 4
109 5
110 6
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TABLE `t5` (
`a` int NOT NULL AUTO_INCREMENT,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB AUTO_INCREMENT=111 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
set global innodb_log_checkpoint_now=ON;
SELECT @start_global_value;
@start_global_value
0
SET @@global.innodb_log_checkpoint_now = @start_global_value;
SELECT @@global.innodb_log_checkpoint_now;
@@global.innodb_log_checkpoint_now
0
START TRANSACTION;
# This should insert 14, 15
INSERT INTO t4 VALUES(0, 10), (0, 20);
# This should insert 111, 112
INSERT INTO t5 VALUES(0, 10), (0, 20);
COMMIT;
START TRANSACTION;
# This should insert 16, 17
INSERT INTO t4 VALUES(0, 10), (0, 20);
# This should insert 113, 114
INSERT INTO t5 VALUES(0, 10), (0, 20);
# This will not rollback the counter
ROLLBACK;
# Kill and restart
SET GLOBAL innodb_flush_log_at_trx_commit=1;
SELECT MAX(a) AS `Expect 15` FROM t4;
Expect 15
15
SELECT MAX(a) AS `Expect 112` FROM t5;
Expect 112
112
SHOW CREATE TABLE t4;
Table Create Table
t4 CREATE TABLE `t4` (
`a` int NOT NULL AUTO_INCREMENT,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
SHOW CREATE TABLE t5;
Table Create Table
t5 CREATE TABLE `t5` (
`a` int NOT NULL AUTO_INCREMENT,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB AUTO_INCREMENT=115 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Scenario 2: Mix the persisted autoinc counter and corrupted bits
TRUNCATE TABLE t1;
TRUNCATE TABLE t2;
TRUNCATE TABLE t3;
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t4;
Table Op Msg_type Msg_text
test.t4 check Warning InnoDB: The B-tree of index b is corrupted.
test.t4 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT b FROM t4 WHERE b > 3;
ERROR HY000: Index b is corrupted
# This should insert 18, 19
INSERT INTO t4 VALUES(0, 6), (0, 7);
SELECT MAX(a) AS `Expect 19` FROM t4;
Expect 19
19
INSERT INTO t1 VALUES(0), (0);
INSERT INTO t2 VALUES(0), (0);
INSERT INTO t3 VALUES(0), (0);
# This should insert 115, 116
INSERT INTO t5 VALUES(0, 10), (0, 11);
# Kill and restart
set global innodb_flush_log_at_trx_commit=1;
CHECK TABLE t4;
Table Op Msg_type Msg_text
test.t4 check Warning InnoDB: Index b is marked as corrupted
test.t4 check error Corrupt
SELECT b FROM t4 WHERE b > 3;
ERROR HY000: Index b is corrupted
# This should fix the corrupted index
DROP INDEX b ON t4;
CREATE INDEX b ON t4(b);
CHECK TABLE t4;
Table Op Msg_type Msg_text
test.t4 check status OK
INSERT INTO t4 VALUES(0, 8), (0, 9), (30, 10);
SET @start_global_value = @@global.innodb_log_checkpoint_now;
SELECT @start_global_value;
@start_global_value
0
set global innodb_log_checkpoint_now=ON;
SELECT MAX(a) AS `Expect 116` FROM t5;
Expect 116
116
DELETE FROM t5;
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t5;
Table Op Msg_type Msg_text
test.t5 check Warning InnoDB: The B-tree of index b is corrupted.
test.t5 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT @start_global_value;
@start_global_value
0
SET @@global.innodb_log_checkpoint_now = @start_global_value;
SELECT @@global.innodb_log_checkpoint_now;
@@global.innodb_log_checkpoint_now
0
# This should insert 117, 118
INSERT INTO t5 VALUES(0, 10), (0, 20);
# Kill and restart
set global innodb_flush_log_at_trx_commit=1;
SELECT b FROM t5 WHERE b > 3;
ERROR HY000: Index b is corrupted
# This should fix the corrupted index
DROP INDEX b ON t5;
CREATE INDEX b ON t5(b);
CHECK TABLE t5;
Table Op Msg_type Msg_text
test.t5 check status OK
# This should insert 31, 32
INSERT INTO t4 VALUES(0, 11), (0, 12);
SELECT MAX(a) AS `Expect 32` FROM t4;
Expect 32
32
# restart
set global innodb_flush_log_at_trx_commit=1;
# This should insert 119, 120
INSERT INTO t5 VALUES(0, 12), (0, 13);
SELECT MAX(a) AS `Expect 120` FROM t5;
Expect 120
120
CREATE TABLE t6 (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100)
) ENGINE=InnoDB AUTO_INCREMENT=99;
SET GLOBAL debug="+d,innodb_evict_autoinc_table";
# Evict table from dictionary cache
SET GLOBAL innodb_ft_aux_table="test/t6";
ERROR 42000: Variable 'innodb_ft_aux_table' can't be set to the value of 'test/t6'
SET GLOBAL debug="-d,innodb_evict_autoinc_table";
INSERT INTO t6(name) VALUES('mysql');
SELECT * FROM t6;
id name
99 mysql
DROP TABLE t1, t2, t3, t4, t5, t6;
#
# Scenario 4: Test ALTER TABLE .. AUTO_INCREMENT to a smaller value
# and maybe crash
#
CREATE TABLE t1(a TINYINT AUTO_INCREMENT KEY) ENGINE = InnoDB;
INSERT INTO t1 VALUES(0), (0), (10), (20), (30), (31), (32);
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 35` FROM t1;
Expect 35
35
DELETE FROM t1 WHERE a >= 30;
ALTER TABLE t1 AUTO_INCREMENT = 21;
# restart
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` tinyint NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 23` FROM t1;
Expect 23
23
DROP TABLE t1;
CREATE TABLE t1(a TINYINT AUTO_INCREMENT KEY) ENGINE = InnoDB;
INSERT INTO t1 VALUES(0), (0), (10), (20), (30), (31), (32);
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 35` FROM t1;
Expect 35
35
DELETE FROM t1 WHERE a >= 30;
SET SESSION debug="+d, ib_ddl_crash_before_update_stats";
# Write file to make mysql-test-run.pl expect crash
ALTER TABLE t1 AUTO_INCREMENT = 21;
ERROR HY000: Lost connection to MySQL server during query
# Restart mysqld after the crash and reconnect.
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` tinyint NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 38` FROM t1;
Expect 38
38
DROP TABLE t1;
CREATE TABLE t1 (a INT AUTO_INCREMENT NOT NULL, KEY(a))
PARTITION BY RANGE (a)
( PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN (50));
INSERT INTO t1 VALUES(0), (0), (10), (20), (30), (31), (32);
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 35` FROM t1;
Expect 35
35
DELETE FROM t1 WHERE a >= 30;
ALTER TABLE t1 AUTO_INCREMENT = 21;
# restart
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL AUTO_INCREMENT,
KEY `a` (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
/*!50100 PARTITION BY RANGE (`a`)
(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (50) ENGINE = InnoDB) */
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 23` FROM t1;
Expect 23
23
DROP TABLE t1;
CREATE TABLE t1 (a INT AUTO_INCREMENT NOT NULL, KEY(a))
PARTITION BY RANGE (a)
( PARTITION p0 VALUES LESS THAN (10),
PARTITION p1 VALUES LESS THAN (20),
PARTITION p2 VALUES LESS THAN (50));
INSERT INTO t1 VALUES(0), (0), (10), (20), (30), (31), (32);
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 35` FROM t1;
Expect 35
35
DELETE FROM t1 WHERE a >= 30;
SET SESSION debug="+d, ib_ddl_crash_before_update_stats";
# Write file to make mysql-test-run.pl expect crash
ALTER TABLE t1 AUTO_INCREMENT = 21;
ERROR HY000: Lost connection to MySQL server during query
# Restart mysqld after the crash and reconnect.
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL AUTO_INCREMENT,
KEY `a` (`a`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
/*!50100 PARTITION BY RANGE (`a`)
(PARTITION p0 VALUES LESS THAN (10) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (20) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (50) ENGINE = InnoDB) */
INSERT INTO t1 VALUES(0), (0), (0);
SELECT MAX(a) `Expect 38` FROM t1;
Expect 38
38
DROP TABLE t1;
#
# BUG#31763837: DEBUG ASSERT IS HIT IN DD DURING TABLE TRUNCATE
#
CREATE TABLE t1(col1 INT AUTO_INCREMENT PRIMARY KEY);
INSERT INTO t1 VALUES (DEFAULT), (DEFAULT), (DEFAULT);
SELECT * FROM t1 ORDER BY col1;
col1
1
2
3
# Stop mysqld and trigger failure during boot.
# Kill the server
# Start server normally.
# restart:
SELECT * FROM t1 ORDER BY col1;
col1
1
2
3
INSERT INTO t1 VALUES (DEFAULT);
SELECT * FROM t1 ORDER BY col1;
col1
1
2
3
4
ALTER TABLE t1 AUTO_INCREMENT = 4;
INSERT INTO t1 VALUES (DEFAULT);
SELECT * FROM t1 ORDER BY col1;
col1
1
2
3
4
5
TRUNCATE TABLE t1;
DROP TABLE t1;
|