summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2020-08-02 18:58:01 +0400
committerAlexander Barkov <bar@mariadb.com>2020-08-02 18:58:01 +0400
commit863d5b4f75b488412c237af8bed9632aabce690b (patch)
tree9660a6ffab193834d99599261e0fd44c22cbcd0c /sql/item_func.cc
parentda78e952fb327161311a590eb902c5c55da0f2fc (diff)
downloadmariadb-git-863d5b4f75b488412c237af8bed9632aabce690b.tar.gz
MDEV-23350 ROUND(bigint_22_or_longer) returns a wrong data type
The condition in Item_func_round::fix_arg_int() to decide whether: - we can preserve the data type of args[0] versus - the result can go outside of the args[0] data type was wrong. The data type of the first argument can be preserved in these cases: - TRUNCATE(x, n) - ROUND(x, n>=0) Fixing the condition accordingly.
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 6b19933fd48..dc30bad6fe3 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -2472,7 +2472,8 @@ void Item_func_round::fix_arg_int(const Type_handler *preferred,
Longlong_hybrid val1= args[1]->to_longlong_hybrid();
if (args[1]->null_value)
fix_length_and_dec_double(NOT_FIXED_DEC);
- else if ((!val1.to_uint(DECIMAL_MAX_SCALE) && truncate) ||
+ else if (truncate ||
+ !val1.neg() /* ROUND(x, n>=0) */ ||
args[0]->decimal_precision() < DECIMAL_LONGLONG_DIGITS)
{
// Here we can keep INT_RESULT