Skip to content

Commit

Permalink
MDEV-21787 Alter table failure tries to access uninitialized column
Browse files Browse the repository at this point in the history
- Problem is that failure of inplace DDL tries to access the
uninitialized column. This is caused by MDEV-19606 (commit 0274ab1).
Fix is that InnoDB should use column while freeing the index when index
is completely initialized.
  • Loading branch information
Thirunarayanan committed May 26, 2020
1 parent 3ad1af9 commit fdb37d0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 13 deletions.
13 changes: 10 additions & 3 deletions mysql-test/suite/innodb/r/instant_alter_limit,32k.rdiff
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
--- instant_alter_limit.result
+++ instant_alter_limit.result
@@ -42,5 +42,5 @@
--- instant_alter_limit.result 2020-05-26 18:01:27.377946439 +0530
+++ instant_alter_limit,32k.reject 2020-05-26 19:59:19.743877366 +0530
@@ -43,5 +43,12 @@
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
instants
-502
+506
DROP TABLE t;
+#
+# MDEV-21787 Alter table failure tries to access uninitialized column
+#
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT GENERATED ALWAYS AS (SUBSTR(f4, 1, 400)), f3 VARCHAR(500), f4 TEXT)ENGINE=InnoDB ROW_FORMAT=Compact;
+ALTER TABLE t1 ADD UNIQUE KEY (f2(9));
+ALTER TABLE t1 ADD COLUMN f5 TEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
15 changes: 12 additions & 3 deletions mysql-test/suite/innodb/r/instant_alter_limit,4k.rdiff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- instant_alter_limit.result
+++ instant_alter_limit.result
--- instant_alter_limit.result 2020-05-26 18:01:27.377946439 +0530
+++ instant_alter_limit,4k.reject 2020-05-26 20:17:53.314736548 +0530
@@ -5,6 +5,276 @@
ENGINE=InnoDB;
INSERT INTO t VALUES(1,2,3,4,5);
Expand Down Expand Up @@ -295,10 +295,19 @@
ALTER TABLE t ADD COLUMN b INT NOT NULL, ALGORITHM=INSTANT;
ERROR 0A000: ALGORITHM=INSTANT is not supported for this operation. Try ALGORITHM=INPLACE
SELECT variable_value-@old_instant instants
@@ -43,5 +319,5 @@
@@ -43,5 +319,14 @@
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
instants
-502
+474
DROP TABLE t;
+#
+# MDEV-21787 Alter table failure tries to access uninitialized column
+#
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT GENERATED ALWAYS AS (SUBSTR(f4, 1, 400)), f3 VARCHAR(500), f4 TEXT)ENGINE=InnoDB ROW_FORMAT=Compact;
+ALTER TABLE t1 ADD UNIQUE KEY (f2(9));
+ALTER TABLE t1 ADD COLUMN f5 TEXT, ALGORITHM=INPLACE;
+Warnings:
+Warning 139 Row size too large (> 1982). Changing some columns to TEXT or BLOB or using ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED may help. In current row format, BLOB prefix of 768 bytes is stored inline.
+DROP TABLE t1;
13 changes: 10 additions & 3 deletions mysql-test/suite/innodb/r/instant_alter_limit,64k.rdiff
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
--- instant_alter_limit.result
+++ instant_alter_limit.result
@@ -42,5 +42,5 @@
--- instant_alter_limit.result 2020-05-26 18:01:27.377946439 +0530
+++ instant_alter_limit,64k.reject 2020-05-26 20:00:22.499711222 +0530
@@ -43,5 +43,12 @@
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
instants
-502
+506
DROP TABLE t;
+#
+# MDEV-21787 Alter table failure tries to access uninitialized column
+#
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT GENERATED ALWAYS AS (SUBSTR(f4, 1, 400)), f3 VARCHAR(500), f4 TEXT)ENGINE=InnoDB ROW_FORMAT=Compact;
+ALTER TABLE t1 ADD UNIQUE KEY (f2(9));
+ALTER TABLE t1 ADD COLUMN f5 TEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
13 changes: 10 additions & 3 deletions mysql-test/suite/innodb/r/instant_alter_limit,8k.rdiff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- instant_alter_limit.result
+++ instant_alter_limit.result
--- instant_alter_limit.result 2020-05-26 18:01:27.377946439 +0530
+++ instant_alter_limit,8k.reject 2020-05-26 20:19:50.881869095 +0530
@@ -5,6 +5,28 @@
ENGINE=InnoDB;
INSERT INTO t VALUES(1,2,3,4,5);
Expand Down Expand Up @@ -47,10 +47,17 @@
ALTER TABLE t ADD COLUMN b INT NOT NULL, ALGORITHM=INSTANT;
ERROR 0A000: ALGORITHM=INSTANT is not supported for this operation. Try ALGORITHM=INPLACE
SELECT variable_value-@old_instant instants
@@ -43,5 +71,5 @@
@@ -43,5 +71,12 @@
FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';
instants
-502
+492
DROP TABLE t;
+#
+# MDEV-21787 Alter table failure tries to access uninitialized column
+#
+CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT GENERATED ALWAYS AS (SUBSTR(f4, 1, 400)), f3 VARCHAR(500), f4 TEXT)ENGINE=InnoDB ROW_FORMAT=Compact;
+ALTER TABLE t1 ADD UNIQUE KEY (f2(9));
+ALTER TABLE t1 ADD COLUMN f5 TEXT, ALGORITHM=INPLACE;
+DROP TABLE t1;
14 changes: 14 additions & 0 deletions mysql-test/suite/innodb/t/instant_alter_limit.test
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ FROM information_schema.global_status
WHERE variable_name = 'innodb_instant_alter_column';

DROP TABLE t;

--echo #
--echo # MDEV-21787 Alter table failure tries to access uninitialized column
--echo #
CREATE TABLE t1(f1 INT PRIMARY KEY, f2 TEXT GENERATED ALWAYS AS (SUBSTR(f4, 1, 400)), f3 VARCHAR(500), f4 TEXT)ENGINE=InnoDB ROW_FORMAT=Compact;
ALTER TABLE t1 ADD UNIQUE KEY (f2(9));
let $error_code = 0;
let $innodb_page_size = `SELECT @@INNODB_PAGE_SIZE`;
if ($innodb_page_size == 4k) {
let $error_code= ER_TOO_BIG_ROWSIZE;
}
--error $error_code
ALTER TABLE t1 ADD COLUMN f5 TEXT, ALGORITHM=INPLACE;
DROP TABLE t1;
2 changes: 1 addition & 1 deletion storage/innobase/include/dict0mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ struct dict_index_t {
@param whether to reset fields[].col */
void detach_columns(bool clear= false)
{
if (!has_virtual())
if (!has_virtual() || !cached)
return;
for (unsigned i= 0; i < n_fields; i++)
{
Expand Down

0 comments on commit fdb37d0

Please sign in to comment.