Skip to content

Commit

Permalink
MDEV-28127 EXCHANGE PARTITION with non-matching vcol expression segfault
Browse files Browse the repository at this point in the history
mysql_compare_tables() treated all columns non-virtual. Now it
properly checks if the columns are virtual and matches expressions.
  • Loading branch information
midenok committed Nov 10, 2023
1 parent ebb6f57 commit 56e4791
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
22 changes: 22 additions & 0 deletions mysql-test/suite/vcol/r/partition.result
Expand Up @@ -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;
21 changes: 21 additions & 0 deletions mysql-test/suite/vcol/t/partition.test
Expand Up @@ -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;
8 changes: 8 additions & 0 deletions sql/sql_table.cc
Expand Up @@ -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
Expand Down

0 comments on commit 56e4791

Please sign in to comment.