From e768a6c5ce555c730f3b45c0028bfdaa50299ed9 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 31 Jul 2019 15:03:12 -0500 Subject: [PATCH] MCOL-179 Don't round before divide for DIV. Mimic InnoDB behavior. --- utils/funcexp/func_div.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/funcexp/func_div.cpp b/utils/funcexp/func_div.cpp index 327f5e71e..b82cfaa4b 100644 --- a/utils/funcexp/func_div.cpp +++ b/utils/funcexp/func_div.cpp @@ -51,6 +51,16 @@ int64_t Func_div::getIntVal(rowgroup::Row& row, { double val1 = parm[0]->data()->getDoubleVal(row, isNull); double val2 = parm[1]->data()->getDoubleVal(row, isNull); + + if (val2 == 0 || val2 == NAN) + { + isNull = true; + return 0; + } + // MCOL-179 InnoDB doesn't round or convert to int before dividing. + return static_cast(val1 / val2); + +#if 0 int64_t int_val2 = (int64_t)(val2 > 0 ? val2 + 0.5 : val2 - 0.5); if (int_val2 == 0) @@ -69,6 +79,7 @@ int64_t Func_div::getIntVal(rowgroup::Row& row, } return int_val1 / int_val2; +#endif }