Skip to content

Commit 4045ead

Browse files
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 5f09b53(MDEV-31086).
1 parent a2312b6 commit 4045ead

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,15 @@ ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b);
9494
ERROR 42S02: Table 'test.t2' doesn't exist
9595
DROP TABLE t2, t1;
9696
ERROR 42S02: Unknown table 'test.t2'
97+
#
98+
# MDEV-32337 Assertion `pos < table->n_def' failed
99+
# in dict_table_get_nth_col
100+
#
101+
CREATE TABLE t (a INT, va INT AS (a), b INT, vb INT AS (b),
102+
c INT, vc INT AS (c), vf VARCHAR(16) AS (f),
103+
f VARCHAR(4)) ENGINE=InnoDB;
104+
ALTER TABLE t MODIFY f VARCHAR(8);
105+
ALTER TABLE t MODIFY vf VARCHAR(18);
106+
ERROR HY000: This is not yet supported for generated columns
107+
DROP TABLE t;
97108
# End of 10.4 tests

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,17 @@ SET SESSION FOREIGN_KEY_CHECKS = ON;
126126
ALTER TABLE t2 MODIFY b VARCHAR(16), ADD KEY(b);
127127
--error ER_BAD_TABLE_ERROR
128128
DROP TABLE t2, t1;
129+
130+
--echo #
131+
--echo # MDEV-32337 Assertion `pos < table->n_def' failed
132+
--echo # in dict_table_get_nth_col
133+
--echo #
134+
CREATE TABLE t (a INT, va INT AS (a), b INT, vb INT AS (b),
135+
c INT, vc INT AS (c), vf VARCHAR(16) AS (f),
136+
f VARCHAR(4)) ENGINE=InnoDB;
137+
ALTER TABLE t MODIFY f VARCHAR(8);
138+
# Altering the virtual column is not supported
139+
--error ER_UNSUPPORTED_ACTION_ON_GENERATED_COLUMN
140+
ALTER TABLE t MODIFY vf VARCHAR(18);
141+
DROP TABLE t;
129142
--echo # End of 10.4 tests

storage/innobase/handler/handler0alter.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8333,8 +8333,17 @@ ha_innobase::prepare_inplace_alter_table(
83338333
if (ha_alter_info->handler_flags
83348334
& ALTER_COLUMN_TYPE_CHANGE_BY_ENGINE) {
83358335

8336-
for (uint i= 0; i < table->s->fields; i++) {
8336+
for (uint i= 0, n_v_col= 0; i < table->s->fields;
8337+
i++) {
83378338
Field* field = table->field[i];
8339+
8340+
/* Altering the virtual column is not
8341+
supported for inplace alter algorithm */
8342+
if (field->vcol_info) {
8343+
n_v_col++;
8344+
continue;
8345+
}
8346+
83388347
for (const Create_field& new_field :
83398348
ha_alter_info->alter_info->create_list) {
83408349
if (new_field.field == field) {
@@ -8349,7 +8358,7 @@ ha_innobase::prepare_inplace_alter_table(
83498358
field_changed:
83508359
const char* col_name= field->field_name.str;
83518360
dict_col_t *col= dict_table_get_nth_col(
8352-
m_prebuilt->table, i);
8361+
m_prebuilt->table, i - n_v_col);
83538362
if (check_col_is_in_fk_indexes(
83548363
m_prebuilt->table, col, col_name,
83558364
span<const dict_foreign_t*>(

0 commit comments

Comments
 (0)