Skip to content

Commit edba047

Browse files
committed
MDEV-18218 Assertion `0' failed in btr_page_reorganize_low upon DROP COLUMN
dict_table_t::init_instant(): Correctly initialize the length of variable-length instantly dropped columns. row_ins_index_entry_set_vals(): For variable-length instantly dropped columns, write 0 bytes of data. For dropped fixed-length NOT NULL columns, write the fixed length of NUL bytes as data.
1 parent b13d356 commit edba047

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

mysql-test/suite/innodb/r/instant_alter.result

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,13 @@ INSERT INTO t1 SET a=1;
708708
ALTER TABLE t1 DROP c;
709709
ALTER TABLE t1 DROP b, ADD v INT AS (a);
710710
DROP TABLE t1;
711+
CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, b BLOB NOT NULL) ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
712+
INSERT INTO t1 VALUES (1,10,REPEAT('foobar',2000));
713+
ALTER TABLE t1 DROP COLUMN b;
714+
INSERT INTO t1 VALUES (2,20);
715+
ALTER TABLE t1 ADD COLUMN vpk INT AS (pk);
716+
ALTER TABLE t1 DROP COLUMN i;
717+
DROP TABLE t1;
711718
CREATE TABLE t1
712719
(id INT PRIMARY KEY, c2 INT UNIQUE,
713720
c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'),
@@ -1362,6 +1369,13 @@ INSERT INTO t1 SET a=1;
13621369
ALTER TABLE t1 DROP c;
13631370
ALTER TABLE t1 DROP b, ADD v INT AS (a);
13641371
DROP TABLE t1;
1372+
CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, b BLOB NOT NULL) ENGINE=InnoDB ROW_FORMAT=COMPACT;
1373+
INSERT INTO t1 VALUES (1,10,REPEAT('foobar',2000));
1374+
ALTER TABLE t1 DROP COLUMN b;
1375+
INSERT INTO t1 VALUES (2,20);
1376+
ALTER TABLE t1 ADD COLUMN vpk INT AS (pk);
1377+
ALTER TABLE t1 DROP COLUMN i;
1378+
DROP TABLE t1;
13651379
CREATE TABLE t1
13661380
(id INT PRIMARY KEY, c2 INT UNIQUE,
13671381
c3 POINT NOT NULL DEFAULT ST_GeomFromText('POINT(3 4)'),
@@ -2016,10 +2030,17 @@ INSERT INTO t1 SET a=1;
20162030
ALTER TABLE t1 DROP c;
20172031
ALTER TABLE t1 DROP b, ADD v INT AS (a);
20182032
DROP TABLE t1;
2033+
CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, b BLOB NOT NULL) ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
2034+
INSERT INTO t1 VALUES (1,10,REPEAT('foobar',2000));
2035+
ALTER TABLE t1 DROP COLUMN b;
2036+
INSERT INTO t1 VALUES (2,20);
2037+
ALTER TABLE t1 ADD COLUMN vpk INT AS (pk);
2038+
ALTER TABLE t1 DROP COLUMN i;
2039+
DROP TABLE t1;
20192040
disconnect analyze;
20202041
SELECT variable_value-@old_instant instants
20212042
FROM information_schema.global_status
20222043
WHERE variable_name = 'innodb_instant_alter_column';
20232044
instants
2024-
149
2045+
155
20252046
SET GLOBAL innodb_purge_rseg_truncate_frequency= @saved_frequency;

mysql-test/suite/innodb/t/instant_alter.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,17 @@ ALTER TABLE t1 DROP c;
599599
ALTER TABLE t1 DROP b, ADD v INT AS (a);
600600
DROP TABLE t1;
601601

602+
# MDEV-18218 Assertion `0' failed in btr_page_reorganize_low upon DROP COLUMN
603+
eval CREATE TABLE t1 (pk INT PRIMARY KEY, i INT, b BLOB NOT NULL) $engine;
604+
INSERT INTO t1 VALUES (1,10,REPEAT('foobar',2000));
605+
ALTER TABLE t1 DROP COLUMN b;
606+
INSERT INTO t1 VALUES (2,20);
607+
# this evicts and reloads the table definition until MDEV-17468 is fixed
608+
ALTER TABLE t1 ADD COLUMN vpk INT AS (pk);
609+
# this would load wrong metadata from the previous DROP COLUMN b, causing a crash
610+
ALTER TABLE t1 DROP COLUMN i;
611+
DROP TABLE t1;
612+
602613
dec $format;
603614
}
604615
disconnect analyze;

storage/innobase/handler/handler0alter.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ inline void dict_table_t::init_instant(const dict_table_t& table)
199199
}
200200
field_map_it->set_ind(fixed_len
201201
? uint16_t(fixed_len + 1)
202-
: f.col->len > 255);
202+
: DATA_BIG_COL(f.col));
203203
field_map_it++;
204204
ut_ad(f.col >= table.instant->dropped);
205205
ut_ad(f.col < table.instant->dropped

storage/innobase/row/row0ins.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3462,8 +3462,9 @@ row_ins_index_entry_set_vals(
34623462
field->type.prtype = DATA_BINARY_TYPE;
34633463
} else {
34643464
ut_ad(col->len <= sizeof field_ref_zero);
3465+
ut_ad(ind_field->fixed_len <= col->len);
34653466
dfield_set_data(field, field_ref_zero,
3466-
col->len);
3467+
ind_field->fixed_len);
34673468
field->type.prtype = DATA_NOT_NULL;
34683469
}
34693470

0 commit comments

Comments
 (0)