Skip to content

Commit

Permalink
MDEV-33214 Table is getting rebuild with ALTER TABLE ADD COLUMN
Browse files Browse the repository at this point in the history
Problem:
======
- InnoDB fail to do instant operation while adding the variable
length column. Problem is that InnoDB wrongly assumes that
variable character length can never part of externally stored
page.

Solution:
========
instant_alter_column_possible(): Variable length
character field can be stored as externally stored page.
  • Loading branch information
Thirunarayanan committed Mar 15, 2024
1 parent ef7abc8 commit f5df448
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
Binary file modified mysql-test/suite/innodb/r/instant_alter_extend.result
Binary file not shown.
13 changes: 13 additions & 0 deletions mysql-test/suite/innodb/t/instant_alter_extend.test
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,16 @@ select * from t1;
check table t1;

drop database best;

--echo #
--echo # MDEV-33214 Table is getting rebuild with
--echo # ALTER TABLE ADD COLUMN
--echo #
use test;
CREATE TABLE t1(f1 INT, f2 VARCHAR(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
INSERT INTO t1 VALUES(1,'abc'),(2,'def');
ALTER TABLE t1 ADD (f3 VARCHAR(5000), f4 VARCHAR(20)), ALGORITHM=instant;
ALTER TABLE t1 ADD f5 TEXT, ALGORITHM=INSTANT;
DROP TABLE t1;

--echo # End of 10.4 tests
6 changes: 1 addition & 5 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1581,11 +1581,9 @@ instant_alter_column_possible(
ut_ad(!is_null || nullable);
n_nullable += nullable;
n_add++;
uint l;
uint l = (*af)->pack_length();
switch ((*af)->type()) {
case MYSQL_TYPE_VARCHAR:
l = reinterpret_cast<const Field_varstring*>
(*af)->get_length();
variable_length:
if (l >= min_local_len) {
max_size += blob_prefix
Expand All @@ -1599,7 +1597,6 @@ instant_alter_column_possible(
if (!is_null) {
min_size += l;
}
l = (*af)->pack_length();
max_size += l;
lenlen += l > 255 ? 2 : 1;
}
Expand All @@ -1613,7 +1610,6 @@ instant_alter_column_possible(
((*af))->get_length();
goto variable_length;
default:
l = (*af)->pack_length();
if (l > 255 && ib_table.not_redundant()) {
goto variable_length;
}
Expand Down

0 comments on commit f5df448

Please sign in to comment.