1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Backport of the patch for bug #8457 "Precision math: DIV

returns incorrect result with large decimal value" 
 
For the DIV operator, neither operands nor result were checked 
for integer overflows. 
 
This patch changes the DIV behavior for non-integer operands as 
follows: if either of the operands has a non-integer type, 
convert both operands to the DECIMAL type, then calculate the 
division using DECIMAL arithmetics. Convert the resulting 
DECIMAL value into BIGINT [UNSIGNED] if it fits into the 
corresponding range, or throw an 'out of range' error 
otherwise. 

mysql-test/r/func_math.result:
  Added a test case for bug #8457.
  Fixed results for a test case depending on the wrong behavior.
mysql-test/r/type_varchar.result:
  Fixed results for a test case depending on the wrong behavior.
mysql-test/t/func_math.test:
  Added a test case for bug #8457.
sql/item_func.cc:
  If either of the operands has a non-integer type, convert both 
  operands to the DECIMAL type, then calculate the division using 
  DECIMAL arithmetics. Convert the resulting DECIMAL value into 
  BIGINT [UNSIGNED] if it fits into the corresponding range, or 
  throw an 'out of range' error otherwise.
This commit is contained in:
Alexey Kopytov
2009-10-13 12:31:42 +04:00
parent 4337c3808f
commit 7e3b4d21c0
4 changed files with 57 additions and 2 deletions

View File

@ -382,6 +382,9 @@ y
SELECT b DIV 900 y FROM t1 GROUP BY y;
y
0
Warnings:
Warning 1366 Incorrect decimal value: '' for column '' at row -1
Warning 1366 Incorrect decimal value: '' for column '' at row -1
SELECT c DIV 900 y FROM t1 GROUP BY y;
y
0
@ -482,4 +485,12 @@ RAND(i)
0.155220427694936
DROP TABLE t1;
#
select 123456789012345678901234567890.123456789012345678901234567890 div 1 as x;
ERROR 22003: Out of range value for column 'x' at row 1
select "123456789012345678901234567890.123456789012345678901234567890" div 1 as x;
ERROR 22003: Out of range value for column 'x' at row 1
SHOW WARNINGS;
Level Code Message
Warning 1292 Truncated incorrect DECIMAL value: ''
Error 1264 Out of range value for column 'x' at row 1
End of 5.1 tests