From 4045ead9db6f591bc4b971162d943ca2dc799d38 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Thu, 12 Oct 2023 14:49:27 +0530 Subject: [PATCH] MDEV-32337 Assertion `pos < table->n_def' failed in dict_table_get_nth_col While checking for altered column in foreign key constraints, InnoDB fails to ignore virtual columns. This issue caused by commit 5f09b53bdb4e973e7c7ec2c53a24c98321223f98(MDEV-31086). --- mysql-test/suite/innodb/r/fk_col_alter.result | 11 +++++++++++ mysql-test/suite/innodb/t/fk_col_alter.test | 13 +++++++++++++ storage/innobase/handler/handler0alter.cc | 13 +++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/innodb/r/fk_col_alter.result b/mysql-test/suite/innodb/r/fk_col_alter.result index a220402db94..21a8f5da334 100644 --- a/mysql-test/suite/innodb/r/fk_col_alter.result +++ b/mysql-test/suite/innodb/r/fk_col_alter.result @@ -94,4 +94,15 @@ ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b); ERROR 42S02: Table 'test.t2' doesn't exist DROP TABLE t2, t1; ERROR 42S02: Unknown table 'test.t2' +# +# MDEV-32337 Assertion `pos < table->n_def' failed +# in dict_table_get_nth_col +# +CREATE TABLE t (a INT, va INT AS (a), b INT, vb INT AS (b), +c INT, vc INT AS (c), vf VARCHAR(16) AS (f), +f VARCHAR(4)) ENGINE=InnoDB; +ALTER TABLE t MODIFY f VARCHAR(8); +ALTER TABLE t MODIFY vf VARCHAR(18); +ERROR HY000: This is not yet supported for generated columns +DROP TABLE t; # End of 10.4 tests diff --git a/mysql-test/suite/innodb/t/fk_col_alter.test b/mysql-test/suite/innodb/t/fk_col_alter.test index 87ccde5652a..afcea6093b4 100644 --- a/mysql-test/suite/innodb/t/fk_col_alter.test +++ b/mysql-test/suite/innodb/t/fk_col_alter.test @@ -126,4 +126,17 @@ SET SESSION FOREIGN_KEY_CHECKS = ON; ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b); --error ER_BAD_TABLE_ERROR DROP TABLE t2, t1; + +--echo # +--echo # MDEV-32337 Assertion `pos < table->n_def' failed +--echo # in dict_table_get_nth_col +--echo # +CREATE TABLE t (a INT, va INT AS (a), b INT, vb INT AS (b), + c INT, vc INT AS (c), vf VARCHAR(16) AS (f), + f VARCHAR(4)) ENGINE=InnoDB; +ALTER TABLE t MODIFY f VARCHAR(8); +# Altering the virtual column is not supported +--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN +ALTER TABLE t MODIFY vf VARCHAR(18); +DROP TABLE t; --echo # End of 10.4 tests diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index bde3c1fb05e..eb484281bf2 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -8333,8 +8333,17 @@ err_exit: if (ha_alter_info->handler_flags & ALTER_COLUMN_TYPE_CHANGE_BY_ENGINE) { - for (uint i= 0; i < table->s->fields; i++) { + for (uint i= 0, n_v_col= 0; i < table->s->fields; + i++) { Field* field = table->field[i]; + + /* Altering the virtual column is not + supported for inplace alter algorithm */ + if (field->vcol_info) { + n_v_col++; + continue; + } + for (const Create_field& new_field : ha_alter_info->alter_info->create_list) { if (new_field.field == field) { @@ -8349,7 +8358,7 @@ err_exit: field_changed: const char* col_name= field->field_name.str; dict_col_t *col= dict_table_get_nth_col( - m_prebuilt->table, i); + m_prebuilt->table, i - n_v_col); if (check_col_is_in_fk_indexes( m_prebuilt->table, col, col_name, span(