mirror of
https://github.com/MariaDB/server.git
synced 2025-09-02 09:41:40 +03:00
ALTER TABLE IMPORT doesn't properly handle instant alter metadata.
This patch makes IMPORT read, parse and apply instant alter metadata at the
very beginning of operation. So, cases when source table has some metadata
and destination table doesn't have it now works fine.
DISCARD already removes instant metadata so importing normal table into
instant table worked fine before this patch.
decrypt_decompress(): decrypts and decompresses page if needed
handle_instant_metadata(): this should be the first thing to read source
table. Basically, it applies instant metadata to a destination
dict_table_t object. This is the first thing to read FSP flags so
all possible checks of it were moved to this function.
PageConverter::update_index_page(): it doesn't now read instant metadata.
This logic were moved into handle_instant_metadata()
row_import::match_flags(): this is a first part row_import::match_schema().
As a separate function it's used by handle_instant_metadata().
fil_space_t::is_full_crc32_compressed(): added convenient function
ha_innobase::discard_or_import_tablespace(): do not reload table definition
to read instant metadata because handle_instant_metadata() does it better.
The reverted code was originally added in
4e7ee166a9
ANONYMOUS_VAR: this is a handy thing to use along with make_scope_exit()
full_crc32_import.test shows different results, because no
dict_table_close() and dict_table_open_on_id() happens.
Thus, SHOW CREATE TABLE shows a little bit older table definition.
121 lines
3.2 KiB
Plaintext
121 lines
3.2 KiB
Plaintext
set default_storage_engine=innodb;
|
|
#
|
|
# MDEV-18295 IMPORT TABLESPACE fails with instant-altered tables
|
|
#
|
|
create table t2 (x int, z int default 41);
|
|
alter table t2 discard tablespace;
|
|
create table t1 (x int);
|
|
insert into t1 values (1);
|
|
alter table t1 add z int default 42, algorithm instant;
|
|
select * from t1;
|
|
x z
|
|
1 42
|
|
flush tables t1 for export;
|
|
unlock tables;
|
|
# The metadata has to be updated to instant ADD COLUMN.
|
|
alter table t2 import tablespace;
|
|
select * from t2;
|
|
x z
|
|
1 42
|
|
insert into t2 set x=2;
|
|
select * from t2;
|
|
x z
|
|
1 42
|
|
2 41
|
|
alter table t1 discard tablespace;
|
|
flush tables t2 for export;
|
|
unlock tables;
|
|
# Both the metadata and the data file used instant ADD COLUMN.
|
|
alter table t1 import tablespace;
|
|
select * from t1;
|
|
x z
|
|
1 42
|
|
2 41
|
|
drop table t2;
|
|
create table t2 select * from t1;
|
|
alter table t1 discard tablespace;
|
|
flush tables t2 for export;
|
|
unlock tables;
|
|
# The instant ADD COLUMN has to be removed from the metadata.
|
|
alter table t1 import tablespace;
|
|
select * from t1;
|
|
x z
|
|
1 42
|
|
2 41
|
|
# Remove metadata for instant DROP COLUMN, then import
|
|
alter table t1 drop x, add column x int first, algorithm instant;
|
|
select * from t1;
|
|
x z
|
|
NULL 42
|
|
NULL 41
|
|
alter table t1 discard tablespace;
|
|
alter table t1 import tablespace;
|
|
select * from t1;
|
|
x z
|
|
1 42
|
|
2 41
|
|
# Import a data file that contains instant DROP COLUMN metadata
|
|
alter table t2 drop x;
|
|
alter table t1 drop x, force;
|
|
alter table t1 discard tablespace;
|
|
flush tables t2 for export;
|
|
unlock tables;
|
|
alter table t1 import tablespace;
|
|
select * from t1;
|
|
z
|
|
42
|
|
41
|
|
drop table t2;
|
|
drop table t1;
|
|
CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT) ENGINE=INNODB;
|
|
CREATE TABLE t2 (id INT PRIMARY KEY AUTO_INCREMENT, i1 INT, i2 INT) ENGINE=INNODB;
|
|
ALTER TABLE t2 DROP COLUMN i2, ALGORITHM=INSTANT;
|
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
ALTER TABLE t2 IMPORT TABLESPACE;
|
|
DROP TABLE t2, t1;
|
|
CREATE TABLE t1 (id INT PRIMARY KEY, i2 INT, i1 INT) ENGINE=INNODB;
|
|
INSERT INTO t1 VALUES (1, 1, 1);
|
|
ALTER TABLE t1 MODIFY COLUMN i2 INT AFTER i1, ALGORITHM=INSTANT;
|
|
CREATE TABLE t2 LIKE t1;
|
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
ALTER TABLE t2 IMPORT TABLESPACE;
|
|
SELECT * FROM t2;
|
|
id i1 i2
|
|
1 1 1
|
|
DROP TABLE t2, t1;
|
|
CREATE TABLE t1 (id INT PRIMARY KEY, i2 INT, i1 INT) ENGINE=INNODB;
|
|
INSERT INTO t1 VALUES (1, 1, 1);
|
|
ALTER TABLE t1 DROP COLUMN i2, ALGORITHM=INSTANT;
|
|
CREATE TABLE t2 LIKE t1;
|
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
ALTER TABLE t2 IMPORT TABLESPACE;
|
|
SELECT * FROM t2;
|
|
id i1
|
|
1 1
|
|
DROP TABLE t2, t1;
|
|
CREATE TABLE t1 (id INT PRIMARY KEY, i2 INT, i1 INT)
|
|
ENGINE=INNODB PAGE_COMPRESSED=1;
|
|
INSERT INTO t1 VALUES (1, 1, 1);
|
|
ALTER TABLE t1 DROP COLUMN i2, ALGORITHM=INSTANT;
|
|
CREATE TABLE t2 LIKE t1;
|
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
ALTER TABLE t2 IMPORT TABLESPACE;
|
|
DROP TABLE t2, t1;
|
|
CREATE TABLE t1 (id INT PRIMARY KEY AUTO_INCREMENT, i2 INT, i1 INT) ENGINE=INNODB;
|
|
INSERT INTO t1 (i2) SELECT 4 FROM seq_1_to_1024;
|
|
ALTER TABLE t1 DROP COLUMN i2, ALGORITHM=INSTANT;
|
|
CREATE TABLE t2 LIKE t1;
|
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
|
FLUSH TABLE t1 FOR EXPORT;
|
|
UNLOCK TABLES;
|
|
ALTER TABLE t2 IMPORT TABLESPACE;
|
|
DROP TABLE t2, t1;
|