diff --git a/mysql-test/suite/versioning/r/partition.result b/mysql-test/suite/versioning/r/partition.result index 78d09c5c019..2b275538fb9 100644 --- a/mysql-test/suite/versioning/r/partition.result +++ b/mysql-test/suite/versioning/r/partition.result @@ -407,6 +407,14 @@ Warning 4112 Versioned table `test`.`t1`: partition `p2` is full, add more HISTO delete from t1 where x = 2; Warnings: Warning 4112 Versioned table `test`.`t1`: partition `p2` is full, add more HISTORY partitions +# MDEV-14923 Assertion upon INSERT into locked versioned partitioned table +create or replace table t1 (x int) with system versioning +partition by system_time (partition p1 history, partition pn current); +lock table t1 write; +alter table t1 add partition (partition p1 history); +ERROR HY000: Duplicate partition name p1 +insert into t1 values (1); +unlock tables; # Test cleanup drop database test; create database test; diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index 9422d5d336d..167a5b2f7a4 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -351,6 +351,15 @@ alter table t1 partition by system_time limit 1 ( delete from t1 where x = 1; delete from t1 where x = 2; +--echo # MDEV-14923 Assertion upon INSERT into locked versioned partitioned table +create or replace table t1 (x int) with system versioning +partition by system_time (partition p1 history, partition pn current); +lock table t1 write; +--error ER_SAME_NAME_PARTITION +alter table t1 add partition (partition p1 history); +insert into t1 values (1); +unlock tables; + --echo # Test cleanup drop database test; create database test; diff --git a/sql/partition_info.cc b/sql/partition_info.cc index 8133f15012c..65df87bee04 100644 --- a/sql/partition_info.cc +++ b/sql/partition_info.cc @@ -1940,7 +1940,7 @@ static void warn_if_dir_in_part_elem(THD *thd, partition_element *part_elem) bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, handler *file, HA_CREATE_INFO *info, - bool add_or_reorg_part) + partition_info *add_or_reorg_part) { handlerton *table_engine= default_engine_type; uint i, tot_partitions; @@ -2174,6 +2174,24 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, goto end; } + if (hist_parts > 1) + { + if (unlikely(vers_info->limit == 0 && vers_info->interval == 0)) + { + push_warning_printf(thd, + Sql_condition::WARN_LEVEL_WARN, + WARN_VERS_PARAMETERS, + ER_THD(thd, WARN_VERS_PARAMETERS), + "no rotation condition for multiple HISTORY partitions."); + } + } + if (unlikely(now_parts > 1)) + { + my_error(ER_VERS_WRONG_PARTS, MYF(0), info->alias); + goto end; + } + + DBUG_ASSERT(table_engine != partition_hton && default_engine_type == table_engine); if (eng_type) @@ -2188,6 +2206,9 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, if (add_or_reorg_part) { + if (unlikely(part_type == VERSIONING_PARTITION && + vers_setup_expression(thd, add_or_reorg_part->partitions.elements))) + goto end; if (unlikely(((part_type == RANGE_PARTITION || part_type == VERSIONING_PARTITION) && check_range_constants(thd)) || (part_type == LIST_PARTITION && @@ -2195,22 +2216,6 @@ bool partition_info::check_partition_info(THD *thd, handlerton **eng_type, goto end; } - if (hist_parts > 1) - { - if (vers_info->limit == 0 && vers_info->interval == 0) - { - push_warning_printf(thd, - Sql_condition::WARN_LEVEL_WARN, - WARN_VERS_PARAMETERS, - ER_THD(thd, WARN_VERS_PARAMETERS), - "no rotation condition for multiple HISTORY partitions."); - } - } - if (now_parts > 1) - { - my_error(ER_VERS_WRONG_PARTS, MYF(0), info->alias); - goto end; - } result= FALSE; end: DBUG_RETURN(result); diff --git a/sql/partition_info.h b/sql/partition_info.h index 6f1414efb02..23e94661e68 100644 --- a/sql/partition_info.h +++ b/sql/partition_info.h @@ -348,7 +348,7 @@ public: bool check_list_constants(THD *thd); bool check_partition_info(THD *thd, handlerton **eng_type, handler *file, HA_CREATE_INFO *info, - bool check_partition_function); + partition_info *add_or_reorg_part= NULL); void print_no_partition_found(TABLE *table, myf errflag); void print_debug(const char *str, uint*); Item* get_column_item(Item *item, Field *field); diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index d1da9823aa4..0249fa1694e 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -5436,13 +5436,8 @@ the generated partition syntax in a correct manner. tab_part_info->use_default_num_subpartitions= FALSE; } - if (alter_info->flags & Alter_info::ALTER_ADD_PARTITION && - tab_part_info->part_type == VERSIONING_PARTITION && - tab_part_info->vers_setup_expression(thd, alt_part_info->partitions.elements)) - goto err; - if (tab_part_info->check_partition_info(thd, (handlerton**)NULL, - table->file, 0, TRUE)) + table->file, 0, alt_part_info)) { goto err; }