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 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
|
#
# Bug#30128418: IMPORT TABLESPACE MUST CHECK DESCENDING INDEX DEFINITION
#
###
### EXPORT #1: Backup Ascending key IBD and v3 CFG
###
# Create a table with a normal ascending secondary key and export it.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b));
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t1 VALUES (2, 2);
SELECT * FROM t1;
a b
1 1
2 2
SELECT * FROM t1 order by a;
a b
1 1
2 2
SELECT * FROM t1 order by b;
a b
1 1
2 2
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Export the table using IB_EXPORT_CFG_VERSION_V3,
# which does not export the DESC flag.
SET GLOBAL DEBUG='+d,ib_export_use_cfg_version_3';
FLUSH TABLES t1 FOR EXPORT;
SET GLOBAL DEBUG='-d,ib_export_use_cfg_version_3';
# Back-up the IBD and the v3 CFG file
# Unlock the table, which deletes the CFG file.
UNLOCK TABLES;
###
### EXPORT #2: Backup v4 CFG for Ascending key IBD
###
# Export the table using IB_EXPORT_CFG_VERSION_V4,
# which will export the DESC flag on the secondary index.
FLUSH TABLES t1 FOR EXPORT;
# Back-up the v4 CFG file
UNLOCK TABLES;
DROP TABLE t1;
###
### EXPORT #3: Backup Descending key IBD and v3 CFG
###
# Create a table with a descending secondary key and export it.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b DESC));
INSERT INTO t1 VALUES (1, 1);
INSERT INTO t1 VALUES (2, 2);
SELECT * FROM t1;
a b
1 1
2 2
SELECT * FROM t1 order by a;
a b
1 1
2 2
SELECT * FROM t1 order by b;
a b
1 1
2 2
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Export the table using IB_EXPORT_CFG_VERSION_V3,
# which does not export the DESC flag.
SET GLOBAL DEBUG='+d,ib_export_use_cfg_version_3';
FLUSH TABLES t1 FOR EXPORT;
SET GLOBAL DEBUG='-d,ib_export_use_cfg_version_3';
# Back-up the IBD and the v3 CFG file
# Unlock the table, which deletes the CFG file.
UNLOCK TABLES;
###
### EXPORT #4: Backup v4 CFG for Descending key IBD
###
# Export the table using IB_EXPORT_CFG_VERSION_V4,
# which will export the DESC flag on the secondary index.
FLUSH TABLES t1 FOR EXPORT;
# Back-up the v4 CFG with the descending key.
# Unlock the table, which deletes the cfg file.
UNLOCK TABLES;
###
### EXPORT #5: Backup with a future version 99 CFG
###
# Export the table using a future version IB_EXPORT_CFG_VERSION_V99,
SET GLOBAL DEBUG='+d,ib_export_use_cfg_version_99';
FLUSH TABLES t1 FOR EXPORT;
SET GLOBAL DEBUG='-d,ib_export_use_cfg_version_99';
# Back-up the v99 CFG with the descending key.
# Unlock the table, which deletes the cfg file.
UNLOCK TABLES;
###
### IMPORT TEST #1: Ascending key IBD and v3 CFG to Discarded Ascending Key IBD
###
# Recreate the table without the DESC attribute on the secondary key.
DROP TABLE t1;
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the ascending key IBD and the v3 version of the CFG.
# Import the table. Since both the discarded IBD and the imported
# IBD match, the import succeeds.
ALTER TABLE t1 IMPORT TABLESPACE;
# Show that column b is sorted correctly.
SELECT * FROM t1;
a b
1 1
2 2
SELECT * FROM t1 order by a;
a b
1 1
2 2
SELECT * FROM t1 order by b;
a b
1 1
2 2
INSERT INTO t1 VALUES (3, 3);
INSERT INTO t1 VALUES (4, 4);
SELECT * FROM t1;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by a;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by b;
a b
1 1
2 2
3 3
4 4
DROP TABLE t1;
###
### IMPORT TEST #2: Ascending key IBD and v4 CFG to Discarded Ascending Key IBD
###
# Recreate the table without the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the ascending key IBD and the v4 version of the CFG.
# Import the table. Since both the discarded IBD and the imported
# IBD match, the import succeeds.
ALTER TABLE t1 IMPORT TABLESPACE;
# Show that column b is sorted correctly.
SELECT * FROM t1;
a b
1 1
2 2
SELECT * FROM t1 order by a;
a b
1 1
2 2
SELECT * FROM t1 order by b;
a b
1 1
2 2
INSERT INTO t1 VALUES (3, 3);
INSERT INTO t1 VALUES (4, 4);
SELECT * FROM t1;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by a;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by b;
a b
1 1
2 2
3 3
4 4
DROP TABLE t1;
###
### IMPORT TEST #3: Ascending key IBD and v3 CFG to Discarded Descending Key IBD
###
# Recreate the table with the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b DESC));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the ascending key IBD and the v3 version of the CFG.
# Attempt to import the table. Since the DESC flag is not available in the
# CFG file, we assume it is ascending, which is different from the exported
# table. The error message will complain about Index b field b.
# The import will abort and delete the cfg file.
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Index b field b is descending which does not match metadata file which is ascending)
DROP TABLE t1;
###
### IMPORT TEST #4 Ascending key IBD and v4 CFG to Discarded Descending Key IBD
###
# Recreate the table with the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b DESC));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the ascending key IBD and the v4 version of the CFG.
# Attempt to import the table. Since the DESC flag if the discarded table
# is different from the exported table, the error message will complain about
# Index b field b. The import will abort and delete the cfg file.
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Index b field b is descending which does not match metadata file which is ascending)
DROP TABLE t1;
###
### IMPORT TEST #5: Descending key IBD and v3 CFG to Discarded Ascending Key IBD
###
# Recreate the table without the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the descending key IBD and the v3 version of the CFG.
# Attempt to import the table. Since the DESC flag is not available in the
# CFG file, we assume it is ascending, which matches the exported table.
# So the import succeeds, but the sort order of the keys in the imported
# file is descending and all new keys will be ascending.
ALTER TABLE t1 IMPORT TABLESPACE;
Warnings:
Warning 1817 InnoDB: Index corrupt: Index 'b' is found to be corrupt and should be recreated.
# Show that the index is corrupt
SHOW WARNINGS;
Level Code Message
Warning 1817 InnoDB: Index corrupt: Index 'b' is found to be corrupt and should be recreated.
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
test.t1 check Warning InnoDB: Index b is marked as corrupted
test.t1 check error Corrupt
# Fix the corruption
OPTIMIZE TABLE t1;
Table Op Msg_type Msg_text
test.t1 optimize note Table does not support optimize, doing recreate + analyze instead
test.t1 optimize status OK
# Show that the index is no longer corrupt
CHECK TABLE t1 EXTENDED;
Table Op Msg_type Msg_text
test.t1 check status OK
# Show that column b is sorted consistently.
SELECT * FROM t1;
a b
1 1
2 2
SELECT * FROM t1 order by a;
a b
1 1
2 2
SELECT * FROM t1 order by b;
a b
1 1
2 2
INSERT INTO t1 VALUES (3, 3);
INSERT INTO t1 VALUES (4, 4);
SELECT * FROM t1;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by a;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by b;
a b
1 1
2 2
3 3
4 4
DROP TABLE t1;
###
### IMPORT TEST #6: Descending key IBD and v4 CFG to Discarded Ascending Key IBD
###
# Recreate the table without the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the descending key IBD and the v4 version of the CFG.
# Attempt to import the table. Since the DESC flag if the discarded table
# is different from the exported table, the error message will complain about
# column b in index b. The import will abort and delete the cfg file.
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Index b field b is ascending which does not match metadata file which is descending)
DROP TABLE t1;
###
### IMPORT TEST #7: Descending key IBD and v3 CFG to Discarded Descending Key IBD
###
# Recreate the table with the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b DESC));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the descending key IBD and the v3 version of the CFG.
# Attempt to import the table. Since the DESC flag is not available in the
# CFG file, we wrongly assume it is ascending. Since this is different from
# the exported table, the error message will complain about column b in index b.
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Index b field b is descending which does not match metadata file which is ascending)
DROP TABLE t1;
###
### IMPORT TEST #8: Descending key IBD and v4 CFG to Discarded Descending Key IBD
###
# Recreate the table with the DESC attribute on the secondary key.
CREATE TABLE t1 (a int, b int, PRIMARY KEY (a), KEY (b DESC));
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int NOT NULL,
`b` int DEFAULT NULL,
PRIMARY KEY (`a`),
KEY `b` (`b` DESC)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the descending key IBD and the v4 version of the CFG.
# Import the table successfuly.
ALTER TABLE t1 IMPORT TABLESPACE;
# Show that column b is descending.
SELECT * FROM t1;
a b
1 1
2 2
SELECT * FROM t1 order by a;
a b
1 1
2 2
SELECT * FROM t1 order by b;
a b
1 1
2 2
INSERT INTO t1 VALUES (3, 3);
INSERT INTO t1 VALUES (4, 4);
SELECT * FROM t1;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by a;
a b
1 1
2 2
3 3
4 4
SELECT * FROM t1 order by b;
a b
1 1
2 2
3 3
4 4
###
### IMPORT TEST #9: Any unknown version will be rejected with a clear error message.
###
# Discard the table which deletes the IBD file.
ALTER TABLE t1 DISCARD TABLESPACE;
# Restore the descending key IBD and the v99 version of the CFG.
# Attempt to import the table.
ALTER TABLE t1 IMPORT TABLESPACE;
ERROR HY000: Failed to import test/t1 because the CFG file version (99) is not compatible with the current version (5)
SHOW WARNINGS;
Level Code Message
Error 3949 Failed to import test/t1 because the CFG file version (99) is not compatible with the current version (5)
Warning 1816 InnoDB: ALTER TABLE `test`.`t1` IMPORT TABLESPACE failed with error 48 : 'Unsupported'
Error 1112 Table 't1' uses an extension that doesn't exist in this MySQL version
# Cleanup
DROP TABLE t1;
#
# Bug#30191523 : FLUSH TABLE T FOR EXPORT OR ALTER TABLE T2 IMPORT
# TABLESPACE BROKEN IN 8.0.17.
#
# ---------------------- Test 1 ----------------------------------
# Source table has INSTANT columns but target table doesn't
# ----------------------------------------------------------------
# Create source table t1 and add a column INSTANTly
CREATE TABLE t1(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY);
ALTER TABLE t1 ADD COLUMN v1 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t1 ADD COLUMN v2 VARCHAR(255), ALGORITHM=INSTANT;
# Insert some data into t1
SELECT * from t1 limit 10;
id v1 v2
1 aaaaaaaaaaaaa bbbbbbbbbbbbbb
2 aaaaaaaaaaaaa bbbbbbbbbbbbbb
3 aaaaaaaaaaaaa bbbbbbbbbbbbbb
4 aaaaaaaaaaaaa bbbbbbbbbbbbbb
5 aaaaaaaaaaaaa bbbbbbbbbbbbbb
6 aaaaaaaaaaaaa bbbbbbbbbbbbbb
7 aaaaaaaaaaaaa bbbbbbbbbbbbbb
8 aaaaaaaaaaaaa bbbbbbbbbbbbbb
9 aaaaaaaaaaaaa bbbbbbbbbbbbbb
10 aaaaaaaaaaaaa bbbbbbbbbbbbbb
SELECT COUNT(*) from t1;
COUNT(*)
1000
SELECT NAME, N_COLS, INSTANT_COLS FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME="test/t1";
NAME N_COLS INSTANT_COLS
test/t1 6 0
SELECT NAME, POS, HAS_DEFAULT from information_Schema.innodb_columns WHERE NAME='v1' OR NAME='v2';
NAME POS HAS_DEFAULT
v1 1 1
v2 2 1
# Flush the table and store CFG/IBD files to temp
FLUSH TABLE t1 FOR EXPORT;
UNLOCK TABLES;
# Create table t2 without INSTANTly added columns
CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 DISCARD TABLESPACE;
# Copy CFG/IBD file from temp
# IMPORT should succeed. Target table metadata should have been updated.
ALTER TABLE t2 IMPORT TABLESPACE;
SELECT * from t2 limit 10;
id v1 v2
1 aaaaaaaaaaaaa bbbbbbbbbbbbbb
2 aaaaaaaaaaaaa bbbbbbbbbbbbbb
3 aaaaaaaaaaaaa bbbbbbbbbbbbbb
4 aaaaaaaaaaaaa bbbbbbbbbbbbbb
5 aaaaaaaaaaaaa bbbbbbbbbbbbbb
6 aaaaaaaaaaaaa bbbbbbbbbbbbbb
7 aaaaaaaaaaaaa bbbbbbbbbbbbbb
8 aaaaaaaaaaaaa bbbbbbbbbbbbbb
9 aaaaaaaaaaaaa bbbbbbbbbbbbbb
10 aaaaaaaaaaaaa bbbbbbbbbbbbbb
SELECT COUNT(*) from t2;
COUNT(*)
1000
SELECT NAME, N_COLS, INSTANT_COLS FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME="test/t1" OR NAME="test/t2";
NAME N_COLS INSTANT_COLS
test/t1 6 0
test/t2 6 0
SELECT NAME, POS, HAS_DEFAULT from information_Schema.innodb_columns WHERE NAME='v1' OR NAME='v2';
NAME POS HAS_DEFAULT
v1 1 1
v2 2 1
v1 1 1
v2 2 1
DROP TABLE t2;
# Create table t2 with one column added INSTANTly
CREATE TABLE t2(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, v1 VARCHAR(255));
ALTER TABLE t2 ADD COLUMN v2 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t2 DISCARD TABLESPACE;
# Copy CFG/IBD file from temp
# IMPORT should fail as INSTANT METADATA doesn't match.
ALTER TABLE t2 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (Table has instant column but current row version didn't match.)
DROP TABLE t2;
# Create table t2 with two column added INSTANTly
CREATE TABLE t2(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY);
ALTER TABLE t2 ADD COLUMN v1 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t2 ADD COLUMN v2 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t2 DISCARD TABLESPACE;
# Copy CFG/IBD file from temp
# IMPORT should succeed.
ALTER TABLE t2 IMPORT TABLESPACE;
SELECT * from t2 limit 10;
id v1 v2
1 aaaaaaaaaaaaa bbbbbbbbbbbbbb
2 aaaaaaaaaaaaa bbbbbbbbbbbbbb
3 aaaaaaaaaaaaa bbbbbbbbbbbbbb
4 aaaaaaaaaaaaa bbbbbbbbbbbbbb
5 aaaaaaaaaaaaa bbbbbbbbbbbbbb
6 aaaaaaaaaaaaa bbbbbbbbbbbbbb
7 aaaaaaaaaaaaa bbbbbbbbbbbbbb
8 aaaaaaaaaaaaa bbbbbbbbbbbbbb
9 aaaaaaaaaaaaa bbbbbbbbbbbbbb
10 aaaaaaaaaaaaa bbbbbbbbbbbbbb
SELECT COUNT(*) from t2;
COUNT(*)
1000
SELECT NAME, N_COLS, INSTANT_COLS FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME="test/t1" OR NAME="test/t2";
NAME N_COLS INSTANT_COLS
test/t1 6 0
test/t2 6 0
SELECT NAME, POS, HAS_DEFAULT from information_Schema.innodb_columns WHERE NAME='v1' OR NAME='v2';
NAME POS HAS_DEFAULT
v1 1 1
v2 2 1
v1 1 1
v2 2 1
DROP TABLE t2;
DROP TABLE t1;
# ---------------------- Test 2 ----------------------------------
# Source table doesn't have INSTANT columns but target table does
# ----------------------------------------------------------------
# Create source table t1 and add a column INSTANTly
CREATE TABLE t1(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, v1 VARCHAR(255), v2 VARCHAR(255));
# Insert some data into t1
SELECT * from t1 limit 10;
id v1 v2
1 aaaaaaaaaaaaa bbbbbbbbbbbbbb
2 aaaaaaaaaaaaa bbbbbbbbbbbbbb
3 aaaaaaaaaaaaa bbbbbbbbbbbbbb
4 aaaaaaaaaaaaa bbbbbbbbbbbbbb
5 aaaaaaaaaaaaa bbbbbbbbbbbbbb
6 aaaaaaaaaaaaa bbbbbbbbbbbbbb
7 aaaaaaaaaaaaa bbbbbbbbbbbbbb
8 aaaaaaaaaaaaa bbbbbbbbbbbbbb
9 aaaaaaaaaaaaa bbbbbbbbbbbbbb
10 aaaaaaaaaaaaa bbbbbbbbbbbbbb
SELECT COUNT(*) from t1;
COUNT(*)
1000
SELECT NAME, N_COLS, INSTANT_COLS FROM INFORMATION_SCHEMA.INNODB_TABLES WHERE NAME="test/t1";
NAME N_COLS INSTANT_COLS
test/t1 6 0
SELECT NAME, POS, HAS_DEFAULT from information_Schema.innodb_columns WHERE NAME='v1' OR NAME='v2';
NAME POS HAS_DEFAULT
v1 1 0
v2 2 0
# Flush the table and store CFG/IBD files to temp
FLUSH TABLE t1 FOR EXPORT;
UNLOCK TABLES;
# Create table t2 with no INSTANTly added columns
CREATE TABLE t2(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, v1 VARCHAR(255), v2 VARCHAR(255));
ALTER TABLE t2 DISCARD TABLESPACE;
# Copy CFG/IBD file from temp
# IMPORT should succeed.
ALTER TABLE t2 IMPORT TABLESPACE;
DROP TABLE t2;
# Create table t2 with 1 INSTANTly added columns
CREATE TABLE t2(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, v1 VARCHAR(255));
ALTER TABLE t2 ADD COLUMN v2 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t2 DISCARD TABLESPACE;
# Copy CFG/IBD file from temp
# IMPORT should fail.
ALTER TABLE t2 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (The .cfg file indicates no INSTANT column in the source table whereas the metadata in data dictionary says there are instant columns in the target table)
DROP TABLE t2;
# Create table t2 with 2 INSTANTly added columns
CREATE TABLE t2(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY);
ALTER TABLE t2 ADD COLUMN v1 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t2 ADD COLUMN v2 VARCHAR(255), ALGORITHM=INSTANT;
ALTER TABLE t2 DISCARD TABLESPACE;
# Copy CFG/IBD file from temp
# IMPORT should fail.
ALTER TABLE t2 IMPORT TABLESPACE;
ERROR HY000: Schema mismatch (The .cfg file indicates no INSTANT column in the source table whereas the metadata in data dictionary says there are instant columns in the target table)
DROP TABLE t2;
# Cleanup
DROP TABLE t1;
|