From b0fa30808622fe12d474a70af1838906e60b9897 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Sun, 2 Feb 2020 15:13:29 +0300 Subject: MDEV-21195 INSERT chooses wrong partition for RANGE partitioning by DECIMAL column Use FLOOR rounding for DECIMAL_RESULT item_expr in partition function. --- sql/sql_partition.cc | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'sql/sql_partition.cc') diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 00a78ce3199..febd88c4b9b 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -2840,14 +2840,34 @@ bool partition_key_modified(TABLE *table, const MY_BITMAP *fields) static inline int part_val_int(Item *item_expr, longlong *result) { - *result= item_expr->val_int(); + switch (item_expr->cmp_type()) + { + case DECIMAL_RESULT: + { + my_decimal buf; + my_decimal *val= item_expr->val_decimal(&buf); + if (val && my_decimal2int(E_DEC_FATAL_ERROR, val, item_expr->unsigned_flag, + result, FLOOR) != E_DEC_OK) + return true; + break; + } + case INT_RESULT: + *result= item_expr->val_int(); + break; + case STRING_RESULT: + case REAL_RESULT: + case ROW_RESULT: + case TIME_RESULT: + DBUG_ASSERT(0); + break; + } if (item_expr->null_value) { if (unlikely(current_thd->is_error())) - return TRUE; + return true; *result= LONGLONG_MIN; } - return FALSE; + return false; } -- cgit v1.2.1