diff --git a/mysql-test/suite/vcol/r/partition.result b/mysql-test/suite/vcol/r/partition.result index d7c5052b72a30..74c1e3bfee07e 100644 --- a/mysql-test/suite/vcol/r/partition.result +++ b/mysql-test/suite/vcol/r/partition.result @@ -101,3 +101,25 @@ partition pn values less than (maxvalue)); insert into t1 (x, b) values (1, ''), (2, ''), (3, 'a'), (4, 'b'); update t1 set b= 'bar' where x > 0 order by v limit 2; drop table t1; +# +# MDEV-28127 EXCHANGE PARTITION with non-matching vcol expression segfault +# +set @old_mode= @@sql_mode; +set sql_mode=''; +create table t1 (a int, key(a)) partition by range (a) (partition p values less than (1)); +create table t (a int generated always as (1) virtual, key(a)); +alter table t1 exchange partition p with table t; +ERROR HY000: Tables have different definitions +create or replace table t (a int, key(a)); +alter table t1 exchange partition p with table t; +create or replace table t1 (a int generated always as (1) virtual, key(a)) partition by range (a) (partition p values less than (1)); +create or replace table t (a int generated always as (1) virtual, key(a)); +alter table t1 exchange partition p with table t; +create or replace table t (a int generated always as (1) stored, key(a)); +alter table t1 exchange partition p with table t; +ERROR HY000: Tables have different definitions +insert into t values (1); +Warnings: +Warning 1906 The value specified for generated column 'a' in table 't' has been ignored +drop tables t1, t; +set sql_mode= @old_mode; diff --git a/mysql-test/suite/vcol/t/partition.test b/mysql-test/suite/vcol/t/partition.test index 408990b20a6d8..019618b00b128 100644 --- a/mysql-test/suite/vcol/t/partition.test +++ b/mysql-test/suite/vcol/t/partition.test @@ -78,3 +78,24 @@ partition by range columns (x) ( insert into t1 (x, b) values (1, ''), (2, ''), (3, 'a'), (4, 'b'); update t1 set b= 'bar' where x > 0 order by v limit 2; drop table t1; + +--echo # +--echo # MDEV-28127 EXCHANGE PARTITION with non-matching vcol expression segfault +--echo # +set @old_mode= @@sql_mode; +set sql_mode=''; +create table t1 (a int, key(a)) partition by range (a) (partition p values less than (1)); +create table t (a int generated always as (1) virtual, key(a)); +--error ER_TABLES_DIFFERENT_METADATA +alter table t1 exchange partition p with table t; +create or replace table t (a int, key(a)); +alter table t1 exchange partition p with table t; +create or replace table t1 (a int generated always as (1) virtual, key(a)) partition by range (a) (partition p values less than (1)); +create or replace table t (a int generated always as (1) virtual, key(a)); +alter table t1 exchange partition p with table t; +create or replace table t (a int generated always as (1) stored, key(a)); +--error ER_TABLES_DIFFERENT_METADATA +alter table t1 exchange partition p with table t; +insert into t values (1); +drop tables t1, t; +set sql_mode= @old_mode; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 84ef23bf82860..1a239b7d105bb 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7538,6 +7538,14 @@ bool mysql_compare_tables(TABLE *table, (uint) (field->flags & NOT_NULL_FLAG)) DBUG_RETURN(false); + if (field->vcol_info) + { + if (!tmp_new_field->field->vcol_info) + DBUG_RETURN(false); + if (!field->vcol_info->is_equal(tmp_new_field->field->vcol_info)) + DBUG_RETURN(false); + } + /* mysql_prepare_alter_table() clears HA_OPTION_PACK_RECORD bit when preparing description of existing table. In ALTER TABLE it is later