summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2020-02-02 15:13:29 +0300
committerAleksey Midenkov <midenok@gmail.com>2020-02-02 15:13:29 +0300
commitb0fa30808622fe12d474a70af1838906e60b9897 (patch)
treed3a9096d3f7bfcf51411b8a6892733a9c31e6e7c /sql
parent74deeaee342c901c92b91d12033771716a373d8e (diff)
downloadmariadb-git-b0fa30808622fe12d474a70af1838906e60b9897.tar.gz
MDEV-21195 INSERT chooses wrong partition for RANGE partitioning by DECIMAL column
Use FLOOR rounding for DECIMAL_RESULT item_expr in partition function.
Diffstat (limited to 'sql')
-rw-r--r--sql/my_decimal.cc4
-rw-r--r--sql/my_decimal.h2
-rw-r--r--sql/sql_partition.cc26
3 files changed, 26 insertions, 6 deletions
diff --git a/sql/my_decimal.cc b/sql/my_decimal.cc
index 01fad3dde37..8acb46b9ef2 100644
--- a/sql/my_decimal.cc
+++ b/sql/my_decimal.cc
@@ -345,12 +345,12 @@ void my_decimal_trim(ulonglong *precision, uint *scale)
*/
int my_decimal2int(uint mask, const decimal_t *d, bool unsigned_flag,
- longlong *l)
+ longlong *l, decimal_round_mode round_type)
{
int res;
my_decimal rounded;
/* decimal_round can return only E_DEC_TRUNCATED */
- decimal_round(d, &rounded, 0, HALF_UP);
+ decimal_round(d, &rounded, 0, round_type);
res= (unsigned_flag ?
decimal2ulonglong(&rounded, (ulonglong *) l) :
decimal2longlong(&rounded, l));
diff --git a/sql/my_decimal.h b/sql/my_decimal.h
index 6d6bb258293..b409a87bdd4 100644
--- a/sql/my_decimal.h
+++ b/sql/my_decimal.h
@@ -348,7 +348,7 @@ my_decimal *seconds2my_decimal(bool sign, ulonglong sec, ulong microsec,
(TIME)->second_part, (DECIMAL))
int my_decimal2int(uint mask, const decimal_t *d, bool unsigned_flag,
- longlong *l);
+ longlong *l, decimal_round_mode round_type= HALF_UP);
inline
int my_decimal2double(uint, const decimal_t *d, double *result)
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;
}