From 8e6e5acef1517ebf0c645a7e704bede8f7366b2d Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Fri, 5 Jun 2020 02:40:36 +1000 Subject: [PATCH] MDEV-22753 Server crashes upon INSERT into versioned partitioned table with WITHOUT OVERLAPS Add `append_system_key_parts` call inside `fast_alter_partition_table` during new partition creation. --- mysql-test/suite/period/r/overlaps.result | 24 +++++++++++++++++++++++ mysql-test/suite/period/t/overlaps.test | 15 ++++++++++++++ sql/sql_table.cc | 7 +++++++ 3 files changed, 46 insertions(+) diff --git a/mysql-test/suite/period/r/overlaps.result b/mysql-test/suite/period/r/overlaps.result index bf0ff977dcc..fcd54a0a942 100644 --- a/mysql-test/suite/period/r/overlaps.result +++ b/mysql-test/suite/period/r/overlaps.result @@ -296,4 +296,28 @@ a s e foo 2012-01-01 00:00:00 2015-12-31 00:00:00 bar 2012-01-01 00:00:00 2015-12-31 00:00:00 baz 2013-01-01 00:00:00 2014-01-01 00:00:00 +# MDEV-22753 Server crashes in handler::ha_check_overlaps or error 190 +# "Incompatible key or row definition" upon INSERT into versioned +# partitioned table with WITHOUT OVERLAPS +create or replace table t1 (f int, s date, e date, period for p(s,e), +unique(f, p without overlaps) +) engine=innodb with system versioning +partition by system_time limit 1000 +(partition p1 history, partition pn current); +alter table t1 add partition (partition p2 history); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f` int(11) DEFAULT NULL, + `s` date NOT NULL, + `e` date NOT NULL, + PERIOD FOR `p` (`s`, `e`), + UNIQUE KEY `f` (`f`,`p` WITHOUT OVERLAPS) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING + PARTITION BY SYSTEM_TIME LIMIT 1000 +(PARTITION `p1` HISTORY ENGINE = InnoDB, + PARTITION `p2` HISTORY ENGINE = InnoDB, + PARTITION `pn` CURRENT ENGINE = InnoDB) +insert into t1 values (1,'2013-01-12','2015-11-04'), +(2,'2016-03-15','2024-11-09'); drop table t, t1; diff --git a/mysql-test/suite/period/t/overlaps.test b/mysql-test/suite/period/t/overlaps.test index 8c5541c5bc8..30032f9898c 100644 --- a/mysql-test/suite/period/t/overlaps.test +++ b/mysql-test/suite/period/t/overlaps.test @@ -285,4 +285,19 @@ insert into t1 values ('bar', '2012-01-01', '2015-12-31'), ('baz', '2013-01-01', '2014-01-01'); select * from t1; +--echo # MDEV-22753 Server crashes in handler::ha_check_overlaps or error 190 +--echo # "Incompatible key or row definition" upon INSERT into versioned +--echo # partitioned table with WITHOUT OVERLAPS +create or replace table t1 (f int, s date, e date, period for p(s,e), + unique(f, p without overlaps) + ) engine=innodb with system versioning + partition by system_time limit 1000 + (partition p1 history, partition pn current); +alter table t1 add partition (partition p2 history); +show create table t1; +insert into t1 values (1,'2013-01-12','2015-11-04'), + (2,'2016-03-15','2024-11-09'); + + + drop table t, t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 6efd0210652..307aab99bf8 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -75,6 +75,9 @@ static int copy_data_between_tables(THD *, TABLE *,TABLE *, ha_rows *, ha_rows *, Alter_info::enum_enable_or_disable, Alter_table_ctx *); +static bool append_system_key_parts(THD *thd, HA_CREATE_INFO *create_info, + Alter_info *alter_info, KEY **key_info, + uint key_count); static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *, uint *, handler *, KEY **, uint *, int); static uint blob_length_by_type(enum_field_types type); @@ -1821,6 +1824,10 @@ bool mysql_write_frm(ALTER_PARTITION_PARAM_TYPE *lpt, uint flags) strxmov(shadow_frm_name, shadow_path, reg_ext, NullS); if (flags & WFRM_WRITE_SHADOW) { + if (append_system_key_parts(lpt->thd, lpt->create_info, lpt->alter_info, + &lpt->key_info_buffer, 0)) + DBUG_RETURN(true); + if (mysql_prepare_create_table(lpt->thd, lpt->create_info, lpt->alter_info, &lpt->db_options, lpt->table->file, &lpt->key_info_buffer, &lpt->key_count,