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 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
set names utf8;
Warnings:
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
CREATE TABLE corrupt_bit_test_ā(
a INT AUTO_INCREMENT PRIMARY KEY,
b CHAR(100),
c INT,
z INT,
INDEX idx(b))
ENGINE=InnoDB STATS_PERSISTENT=0;
INSERT INTO corrupt_bit_test_ā VALUES(0,'x',1, 1);
CREATE UNIQUE INDEX idxā ON corrupt_bit_test_ā(c, b);
CREATE UNIQUE INDEX idxē ON corrupt_bit_test_ā(z, b);
SELECT * FROM corrupt_bit_test_ā;
a b c z
1 x 1 1
INSERT INTO corrupt_bit_test_ā SELECT 0,b,c+1,z+1 FROM corrupt_bit_test_ā;
select count(*) from corrupt_bit_test_ā;
count(*)
2
SET SESSION debug="+d,dict_set_index_corrupted";
check table corrupt_bit_test_ā;
Table Op Msg_type Msg_text
test.corrupt_bit_test_ā check Warning InnoDB: The B-tree of index idx is corrupted.
test.corrupt_bit_test_ā check Warning InnoDB: The B-tree of index idxā is corrupted.
test.corrupt_bit_test_ā check Warning InnoDB: The B-tree of index idxē is corrupted.
test.corrupt_bit_test_ā check error Corrupt
SET SESSION debug="-d,dict_set_index_corrupted";
CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
ERROR 42000: Can't open table
CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
ERROR 42000: Can't open table
select c from corrupt_bit_test_ā;
ERROR HY000: Index idxā is corrupted
select z from corrupt_bit_test_ā;
ERROR HY000: Index idxē is corrupted
show warnings;
Level Code Message
Warning 180 InnoDB: Index idxē for table `test`.`corrupt_bit_test_ā` is marked as corrupted
Error 1712 Index idxē is corrupted
Error 1712 Index corrupt_bit_test_ā is corrupted
insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
select * from corrupt_bit_test_ā use index(primary) where a = 10001;
a b c z
10001 a 20001 20001
begin;
insert into corrupt_bit_test_ā values (10002, "a", 20002, 20002);
delete from corrupt_bit_test_ā where a = 10001;
insert into corrupt_bit_test_ā values (10001, "a", 20001, 20001);
rollback;
drop index idxā on corrupt_bit_test_ā;
check table corrupt_bit_test_ā;
Table Op Msg_type Msg_text
test.corrupt_bit_test_ā check Warning InnoDB: Index idx is marked as corrupted
test.corrupt_bit_test_ā check Warning InnoDB: Index idxē is marked as corrupted
test.corrupt_bit_test_ā check error Corrupt
set names utf8;
Warnings:
Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.
select z from corrupt_bit_test_ā;
ERROR HY000: Index idxē is corrupted
drop index idxē on corrupt_bit_test_ā;
CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
ERROR 42000: Can't open table
CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
ERROR 42000: Can't open table
drop index idx on corrupt_bit_test_ā;
CREATE INDEX idx3 ON corrupt_bit_test_ā(b, c);
CREATE INDEX idx4 ON corrupt_bit_test_ā(b, z);
select z from corrupt_bit_test_ā limit 10;
z
20001
1
2
drop table corrupt_bit_test_ā;
CREATE DATABASE corrupted;
use corrupted;
CREATE TABLE t1 (
a INT NOT NULL PRIMARY KEY,
b INT,
c CHAR(10),
v VARCHAR(100),
t TEXT,
p POINT NOT NULL);
CREATE TABLE t2 LIKE t1;
CREATE TEMPORARY TABLE t3 LIKE t2;
CREATE FULLTEXT INDEX ft ON t2(t);
Warnings:
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
CREATE INDEX idx_c ON t3(c);
INSERT INTO t1 VALUES (1, 2, 'aaa', 'abcdefghij', 'This is a', st_pointfromtext('POINT(0 0)')),
(2, 4, 'bb', 'qwerty', 'test case', st_pointfromtext('POINT(1 1)')),
(3, 6, 'ccccc', 'poiuy', 'for corrupted index', st_pointfromtext('POINT(2 2)'));
INSERT INTO t2 SELECT * FROM t1;
INSERT INTO t3 SELECT * FROM t1;
SELECT count(*) FROM t1;
count(*)
3
SELECT count(*) FROM t2;
count(*)
3
SELECT count(*) FROM t3;
count(*)
3
# Marking clustered index as corrupted results in ER_NO_SUCH_TABLE
set debug = "+d, dict_set_clust_index_corrupted";
CHECK TABLE t1;
Table Op Msg_type Msg_text
corrupted.t1 check Warning InnoDB: The B-tree of index PRIMARY is corrupted.
corrupted.t1 check error Corrupt
set debug = "-d, dict_set_clust_index_corrupted";
CREATE INDEX b ON t1(b);
ERROR 42S02: Table 'corrupted.t1' doesn't exist
# Mark the secondary index as corrupted
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t2;
Table Op Msg_type Msg_text
corrupted.t2 check Warning InnoDB: The B-tree of index ft is corrupted.
corrupted.t2 check Warning InnoDB: The B-tree of index FTS_DOC_ID_INDEX is corrupted.
corrupted.t2 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT * FROM t2 WHERE MATCH(t) AGAINST('corrupted');
ERROR HY000: The table does not have FULLTEXT index to support this query
SELECT a, b, c FROM t2 WHERE ST_Equals(p, st_pointfromtext('POINT(2 2)'));
a b c
3 6 ccccc
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t3;
Table Op Msg_type Msg_text
corrupted.t3 check Warning InnoDB: The B-tree of index idx_c is corrupted.
corrupted.t3 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT c FROM t3 WHERE c = 'bb';
ERROR HY000: Index idx_c is corrupted
# restart
# Make sure the corrupted indexes are still corrupted
use corrupted;
SHOW TABLES;
Tables_in_corrupted
t1
t2
CREATE INDEX b ON t1(b);
ERROR 42000: Can't open table
SELECT t FROM t2 WHERE MATCH(t) AGAINST('corrupted');
ERROR HY000: The table does not have FULLTEXT index to support this query
DROP INDEX ft ON t2;
ALTER TABLE t2 ADD FULLTEXT INDEX(t);
ERROR 42000: Can't open table
# Have to use ALTER TABLE ... COPY, in case 'Incorrect key file for table...'
# would be reported
ALTER TABLE t2 ADD FULLTEXT INDEX(t), ALGORITHM=COPY;
# This should be fine
SELECT t FROM t2 WHERE MATCH(t) AGAINST('corrupted');
t
for corrupted index
CHECK TABLE t1;
Table Op Msg_type Msg_text
corrupted.t1 check error Corrupt
CHECK TABLE t2;
Table Op Msg_type Msg_text
corrupted.t2 check status OK
# We can drop the corrupted table t1 directly here
DROP TABLE t1, t2;
use corrupted;
CREATE TABLE t3 (
a INT NOT NULL PRIMARY KEY,
b INT,
c CHAR(10),
v VARCHAR(100),
t TEXT,
p POINT NOT NULL SRID 0);
CREATE INDEX idx_b ON t3(b);
INSERT INTO t3 VALUES (1, 2, 'aaa', 'abcdefghij', 'This is a', st_pointfromtext('POINT(0 0)')),
(2, 4, 'bb', 'qwerty', 'test case', st_pointfromtext('POINT(1 1)')),
(3, 6, 'ccccc', 'poiuy', 'for corrupted index', st_pointfromtext('POINT(2 2)'));
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t3;
Table Op Msg_type Msg_text
corrupted.t3 check Warning InnoDB: The B-tree of index idx_b is corrupted.
corrupted.t3 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT b FROM t3 WHERE b > 2;
ERROR HY000: Index idx_b is corrupted
CREATE TABLE t4 LIKE t3;
CREATE INDEX idx_c ON t4(c);
CREATE INDEX idx_v ON t4(v);
INSERT INTO t4 SELECT * FROM t3;
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t4;
Table Op Msg_type Msg_text
corrupted.t4 check Warning InnoDB: The B-tree of index idx_b is corrupted.
corrupted.t4 check Warning InnoDB: The B-tree of index idx_c is corrupted.
corrupted.t4 check Warning InnoDB: The B-tree of index idx_v is corrupted.
corrupted.t4 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT b FROM t4 WHERE b > 3;
ERROR HY000: Index idx_b is corrupted
show warnings;
Level Code Message
Warning 180 InnoDB: Index idx_b for table `corrupted`.`t4` is marked as corrupted
Error 1712 Index idx_b is corrupted
Error 1712 Index t4 is corrupted
SELECT c FROM t4 WHERE c = 'bb';
ERROR HY000: Index idx_c is corrupted
SELECT v FROM t4 WHERE v = 'abcdefg';
ERROR HY000: Index idx_v is corrupted
CREATE TABLE t5 LIKE t3;
CREATE SPATIAL INDEX idx_p ON t5(p);
INSERT INTO t5 SELECT * FROM t3;
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check Warning InnoDB: The B-tree of index idx_b is corrupted.
corrupted.t5 check Warning InnoDB: The B-tree of index idx_p is corrupted.
corrupted.t5 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SELECT b FROM t5 WHERE b > 5;
ERROR HY000: Index idx_b is corrupted
# Kill and restart
use corrupted;
# Check that all corrupted indexes are still marked as corrupted,
# and non-corrupted indexes are still good.
CHECK TABLE t3;
Table Op Msg_type Msg_text
corrupted.t3 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t3 check error Corrupt
SELECT b FROM t3 WHERE b > 2;
ERROR HY000: Index idx_b is corrupted
CHECK TABLE t4;
Table Op Msg_type Msg_text
corrupted.t4 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t4 check Warning InnoDB: Index idx_c is marked as corrupted
corrupted.t4 check Warning InnoDB: Index idx_v is marked as corrupted
corrupted.t4 check error Corrupt
SELECT b FROM t4 WHERE b > 3;
ERROR HY000: Index idx_b is corrupted
SELECT c FROM t4 WHERE c = 'bb';
ERROR HY000: Index idx_c is corrupted
SELECT v FROM t4 WHERE v = 'abcdefg';
ERROR HY000: Index idx_v is corrupted
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t5 check Warning InnoDB: Index idx_p is marked as corrupted
corrupted.t5 check error Corrupt
SELECT b FROM t5 WHERE b > 5;
ERROR HY000: Index idx_b is corrupted
# Let's just fix corrupted index for t5
DROP INDEX idx_b ON t5;
DROP INDEX idx_p ON t5;
CREATE INDEX idx_b ON t5(b);
# restart
use corrupted;
CHECK TABLE t3;
Table Op Msg_type Msg_text
corrupted.t3 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t3 check error Corrupt
SELECT b FROM t3 WHERE b > 2;
ERROR HY000: Index idx_b is corrupted
CHECK TABLE t4;
Table Op Msg_type Msg_text
corrupted.t4 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t4 check Warning InnoDB: Index idx_c is marked as corrupted
corrupted.t4 check Warning InnoDB: Index idx_v is marked as corrupted
corrupted.t4 check error Corrupt
SELECT b FROM t4 WHERE b > 3;
ERROR HY000: Index idx_b is corrupted
SELECT c FROM t4 WHERE c = 'bb';
ERROR HY000: Index idx_c is corrupted
SELECT v FROM t4 WHERE v = 'abcdefg';
ERROR HY000: Index idx_v is corrupted
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check status OK
SELECT b FROM t5 WHERE b > 5;
b
6
# Based on these tables, let's test more on checkpoint
CREATE TABLE t6 LIKE t3;
CREATE INDEX idx_c ON t6(c);
INSERT INTO t6 SELECT * FROM t3;
# Corrupt new table indexes
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check Warning InnoDB: The B-tree of index idx_b is corrupted.
corrupted.t6 check Warning InnoDB: The B-tree of index idx_c is corrupted.
corrupted.t6 check error Corrupt
set debug = "-d, dict_set_index_corrupted";
SET @start_global_value = @@global.innodb_log_checkpoint_now;
SELECT @start_global_value;
@start_global_value
0
# Invoke a checkpoint, which would persist the corrupted bits
# of t6 into DD Table Buffer
set global innodb_log_checkpoint_now=ON;
# Then mark the clustered index as corrupted, make sure that new
# corruption bits would take effect as well
set debug = "+d, dict_set_clust_index_corrupted";
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check Warning InnoDB: The B-tree of index PRIMARY is corrupted.
corrupted.t6 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t6 check Warning InnoDB: Index idx_c is marked as corrupted
corrupted.t6 check error Corrupt
set debug = "-d, dict_set_clust_index_corrupted";
# Corrupt old table indexes
set debug = "+d, dict_set_index_corrupted";
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check Warning InnoDB: The B-tree of index idx_b is corrupted.
corrupted.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 crash would leave latest corruption bits un-persisted
# Kill and restart
use corrupted;
CHECK TABLE t3;
Table Op Msg_type Msg_text
corrupted.t3 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t3 check error Corrupt
CHECK TABLE t4;
Table Op Msg_type Msg_text
corrupted.t4 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t4 check Warning InnoDB: Index idx_c is marked as corrupted
corrupted.t4 check Warning InnoDB: Index idx_v is marked as corrupted
corrupted.t4 check error Corrupt
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t5 check error Corrupt
SELECT b FROM t5 WHERE b > 5;
ERROR HY000: Index idx_b is corrupted
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check error Corrupt
CREATE INDEX idx_v ON t6(v);
ERROR 42S02: Table 'corrupted.t6' doesn't exist
# Invoke checkpoint to persist the latest corruption bits again
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 @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
# restart
use corrupted;
# After a shutdown and restart, the corrupted bits should be persisted
# to DD Table Buffer, and we can get them correctly.
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t5 check error Corrupt
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check error Corrupt
# An IN-PLACE 'ALTER TABLE' would not recover the table
ALTER TABLE t5 CHANGE c c1 CHAR(10), ALGORITHM = INPLACE;
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check Warning InnoDB: Index idx_b is marked as corrupted
corrupted.t5 check error Corrupt
# An 'ALTER TABLE' requiring rebuild would recover the table
ALTER TABLE t5 ADD COLUMN d INT NOT NULL, ALGORITHM=INPLACE;
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check status OK
SELECT a, b, c1, v, t, st_astext(p) FROM t5 WHERE b > 2;
a b c1 v t st_astext(p)
2 4 bb qwerty test case POINT(1 1)
3 6 ccccc poiuy for corrupted index POINT(2 2)
# Re-create the table should recover the table
DROP TABLE t6;
CREATE TABLE t6 LIKE t3;
INSERT INTO t6 SELECT * FROM t3;
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check status OK
# Kill and restart
use corrupted;
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check status OK
SELECT a, b, c1, v, t, st_astext(p) FROM t5 WHERE b > 2;
a b c1 v t st_astext(p)
2 4 bb qwerty test case POINT(1 1)
3 6 ccccc poiuy for corrupted index POINT(2 2)
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check status OK
# restart
use corrupted;
CHECK TABLE t5;
Table Op Msg_type Msg_text
corrupted.t5 check status OK
CHECK TABLE t6;
Table Op Msg_type Msg_text
corrupted.t6 check status OK
DROP TABLE t3, t4, t5, t6;
DROP DATABASE corrupted;
|