From 99de8cc02878ec8c20bffeaf17443e704d6edbf7 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Tue, 28 Jun 2022 15:51:05 +0530 Subject: [PATCH] MDEV-28919 Assertion `(((core_null) + 7) >> 3) == oindex.n_core_null_bytes || !not_redundant()' failed - In case of discarded tablespace, InnoDB can't read the root page to assign the n_core_null_bytes. Consecutive instant DDL fails because of non-matching n_core_null_bytes. --- .../innodb/r/instant_alter_import.result | 26 +++++++++++++++++++ .../suite/innodb/t/instant_alter_import.test | 24 +++++++++++++++++ storage/innobase/handler/handler0alter.cc | 9 +++++++ 3 files changed, 59 insertions(+) diff --git a/mysql-test/suite/innodb/r/instant_alter_import.result b/mysql-test/suite/innodb/r/instant_alter_import.result index fad2fd99685..9a20ed606bd 100644 --- a/mysql-test/suite/innodb/r/instant_alter_import.result +++ b/mysql-test/suite/innodb/r/instant_alter_import.result @@ -127,3 +127,29 @@ UNLOCK TABLES; ALTER TABLE t2 IMPORT TABLESPACE; ERROR HY000: Index for table 't2' is corrupt; try to repair it DROP TABLE t1, t2; +# +# MDEV-28919 Assertion `(((core_null) + 7) >> 3) == +# oindex.n_core_null_bytes || !not_redundant()' failed +# +call mtr.add_suppression(" InnoDB: Tablespace for table `test`.`t` is set as discarded"); +CREATE TABLE t (a INTEGER, b INTEGER as (a) VIRTUAL, +c INTEGER)engine=innodb; +ALTER TABLE t DISCARD TABLESPACE; +ALTER TABLE t DROP COLUMN b, algorithm=instant; +Warnings: +Warning 1814 Tablespace has been discarded for table `t` +ALTER TABLE t DROP COLUMN c, algorithm=instant; +Warnings: +Warning 1814 Tablespace has been discarded for table `t` +CREATE TABLE t1(a INTEGER)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1); +FLUSH TABLE t1 FOR EXPORT; +unlock tables; +ALTER TABLE t IMPORT tablespace; +check table t; +Table Op Msg_type Msg_text +test.t check status OK +select * from t; +a +1 +DROP TABLE t, t1; diff --git a/mysql-test/suite/innodb/t/instant_alter_import.test b/mysql-test/suite/innodb/t/instant_alter_import.test index fdf9f8e6cd9..7bd5645436c 100644 --- a/mysql-test/suite/innodb/t/instant_alter_import.test +++ b/mysql-test/suite/innodb/t/instant_alter_import.test @@ -203,3 +203,27 @@ UNLOCK TABLES; ALTER TABLE t2 IMPORT TABLESPACE; DROP TABLE t1, t2; + +--echo # +--echo # MDEV-28919 Assertion `(((core_null) + 7) >> 3) == +--echo # oindex.n_core_null_bytes || !not_redundant()' failed +--echo # +call mtr.add_suppression(" InnoDB: Tablespace for table `test`.`t` is set as discarded"); +CREATE TABLE t (a INTEGER, b INTEGER as (a) VIRTUAL, + c INTEGER)engine=innodb; +ALTER TABLE t DISCARD TABLESPACE; +# Table does reload +ALTER TABLE t DROP COLUMN b, algorithm=instant; +ALTER TABLE t DROP COLUMN c, algorithm=instant; + +CREATE TABLE t1(a INTEGER)ENGINE=InnoDB; +INSERT INTO t1 VALUES(1); +FLUSH TABLE t1 FOR EXPORT; +--let $MYSQLD_DATADIR= `select @@datadir` +--move_file $MYSQLD_DATADIR/test/t1.cfg $MYSQLD_DATADIR/test/t.cfg +--copy_file $MYSQLD_DATADIR/test/t1.ibd $MYSQLD_DATADIR/test/t.ibd +unlock tables; +ALTER TABLE t IMPORT tablespace; +check table t; +select * from t; +DROP TABLE t, t1; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 7b92ea85215..5492d6e7c4c 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -403,6 +403,15 @@ found_j: goto found_nullable; } } + + /* In case of discarded tablespace, InnoDB can't + read the root page. So assign the null bytes based + on nullabled fields */ + if (!oindex.table->space) { + oindex.n_core_null_bytes= UT_BITS_IN_BYTES( + unsigned(oindex.n_nullable)); + } + /* The n_core_null_bytes only matters for ROW_FORMAT=COMPACT and ROW_FORMAT=DYNAMIC tables. */ ut_ad(UT_BITS_IN_BYTES(core_null) == oindex.n_core_null_bytes