summaryrefslogtreecommitdiff
path: root/mysql-test/t/func_math.test
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-03-18 13:38:29 +0300
committerAlexey Kopytov <Alexey.Kopytov@Sun.com>2010-03-18 13:38:29 +0300
commit2acfdc50929dda084cdad96e4208c1dd6f26e183 (patch)
treeb9789210c6251e842ccc7cee877d0f3ffa2b0887 /mysql-test/t/func_math.test
parentd1ad316a59b6bd48dec94433ffe982ddfc376e35 (diff)
downloadmariadb-git-2acfdc50929dda084cdad96e4208c1dd6f26e183.tar.gz
Bug #8433: Overflow must be an error
All numeric operators and functions on integer, floating point and DECIMAL values now throw an 'out of range' error rather than returning an incorrect value or NULL, when the result is out of supported range for the corresponding data type. Some test cases in the test suite had to be updated accordingly either because the test case itself relied on a value returned in case of a numeric overflow, or because a numeric overflow was the root cause of the corresponding bugs. The latter tests are no longer relevant, since the expressions used to trigger the corresponding bugs are not valid anymore. However, such test cases have been adjusted and kept "for the record". mysql-test/r/func_math.result: Added test cases for bug #8433. Updated results of the test case for bug #31236. mysql-test/r/func_misc.result: Streamlined test cases. mysql-test/r/func_test.result: Streamlined test cases. mysql-test/r/select.result: Streamlined test cases. mysql-test/r/sp.result: Streamlined test cases. mysql-test/r/strict.result: Streamlined test cases. mysql-test/r/type_newdecimal.result: Streamlined test cases. mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result: Streamlined test cases. mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test: Streamlined test cases. mysql-test/t/func_math.test: Added test cases for bug #8433. Updated results of the test case for bug #31236. mysql-test/t/func_misc.test: Streamlined test cases. mysql-test/t/func_test.test: Streamlined test cases. mysql-test/t/select.test: Streamlined test cases. mysql-test/t/sp.test: Streamlined test cases. mysql-test/t/strict.test: Streamlined test cases. mysql-test/t/type_newdecimal.test: Streamlined test cases. sql/item_create.cc: Changed Item_func_cot() to be defined as a standalone Item rather than a combination of "1 / TAN(x)". sql/item_func.cc: Throw an 'out of range' error rather than returning an incorrect value or NULL, when the result of a numeric operator or a function is out of supported range for the corresponding data type. sql/item_func.h: Added validation helpers as inline methods of Item_func. sql/share/errmsg-utf8.txt: New ER_DATA_OUT_OF_RANGE error.
Diffstat (limited to 'mysql-test/t/func_math.test')
-rw-r--r--mysql-test/t/func_math.test141
1 files changed, 139 insertions, 2 deletions
diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test
index b999b1e8c1b..44af2f5ad3f 100644
--- a/mysql-test/t/func_math.test
+++ b/mysql-test/t/func_math.test
@@ -283,12 +283,20 @@ DROP TABLE t1;
#
# Bug #31236: Inconsistent division by zero behavior for floating point numbers
#
+# After the fix for bug #8433 we throw an error in the below test cases
+# rather than just return a NULL value.
+--error ER_DATA_OUT_OF_RANGE
SELECT 1e308 + 1e308;
+--error ER_DATA_OUT_OF_RANGE
SELECT -1e308 - 1e308;
+--error ER_DATA_OUT_OF_RANGE
SELECT 1e300 * 1e300;
+--error ER_DATA_OUT_OF_RANGE
SELECT 1e300 / 1e-300;
+--error ER_DATA_OUT_OF_RANGE
SELECT EXP(750);
+--error ER_DATA_OUT_OF_RANGE
SELECT POW(10, 309);
--echo #
@@ -314,10 +322,139 @@ DROP TABLE t1;
# DIV returns incorrect result with large decimal value
# Bug #46606:Casting error for large numbers in 5.4 when 'div' is used
---error ER_WARN_DATA_OUT_OF_RANGE
+--error ER_DATA_OUT_OF_RANGE
select 123456789012345678901234567890.123456789012345678901234567890 div 1 as x;
---error ER_WARN_DATA_OUT_OF_RANGE
+--error ER_DATA_OUT_OF_RANGE
select "123456789012345678901234567890.123456789012345678901234567890" div 1 as x;
SHOW WARNINGS;
--echo End of 5.1 tests
+
+--echo #
+--echo # Bug #8433: Overflow must be an error
+--echo #
+
+# Floating point overflows
+# ========================
+--error ER_DATA_OUT_OF_RANGE
+SELECT 1e308 + 1e308;
+--error ER_DATA_OUT_OF_RANGE
+SELECT -1e308 - 1e308;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 1e300 * 1e300;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 1e300 / 1e-300;
+--error ER_DATA_OUT_OF_RANGE
+SELECT EXP(750);
+--error ER_DATA_OUT_OF_RANGE
+SELECT POW(10, 309);
+--error ER_DATA_OUT_OF_RANGE
+SELECT COT(0);
+--error ER_DATA_OUT_OF_RANGE
+SELECT DEGREES(1e307);
+
+# Integer overflows
+# =================
+
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775808 + 9223372036854775808;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 18446744073709551615 + 1;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 1 + 18446744073709551615;
+--error ER_DATA_OUT_OF_RANGE
+SELECT -2 + CAST(1 AS UNSIGNED);
+--error ER_DATA_OUT_OF_RANGE
+SELECT CAST(1 AS UNSIGNED) + -2;
+--error ER_DATA_OUT_OF_RANGE
+SELECT -9223372036854775808 + -9223372036854775808;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775807 + 9223372036854775807;
+
+--error ER_DATA_OUT_OF_RANGE
+SELECT CAST(0 AS UNSIGNED) - 9223372036854775809;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775808 - 9223372036854775809;
+--error ER_DATA_OUT_OF_RANGE
+SELECT CAST(1 AS UNSIGNED) - 2;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 18446744073709551615 - (-1);
+--error ER_DATA_OUT_OF_RANGE
+SELECT -1 - 9223372036854775808;
+--error ER_DATA_OUT_OF_RANGE
+SELECT -1 - CAST(1 AS UNSIGNED);
+--error ER_DATA_OUT_OF_RANGE
+SELECT -9223372036854775808 - 1;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775807 - -9223372036854775808;
+
+# To test SIGNED overflow when subtraction arguments are both UNSIGNED
+set SQL_MODE='NO_UNSIGNED_SUBTRACTION';
+--error ER_DATA_OUT_OF_RANGE
+SELECT 18446744073709551615 - 1;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 18446744073709551615 - CAST(1 AS UNSIGNED);
+--error ER_DATA_OUT_OF_RANGE
+SELECT 18446744073709551614 - (-1);
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775807 - -1;
+set SQL_MODE=default;
+
+--error ER_DATA_OUT_OF_RANGE
+SELECT 4294967296 * 4294967296;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775808 * 2;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775808 * 2;
+# The following one triggers condition #3 from the comments in
+# Item_func_mul::int_op()
+--error ER_DATA_OUT_OF_RANGE
+SELECT 7158278827 * 3221225472;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775807 * (-2);
+--error ER_DATA_OUT_OF_RANGE
+SELECT CAST(1 as UNSIGNED) * (-1);
+--error ER_DATA_OUT_OF_RANGE
+SELECT 9223372036854775807 * 2;
+
+--error ER_DATA_OUT_OF_RANGE
+SELECT ABS(-9223372036854775808);
+
+--error ER_DATA_OUT_OF_RANGE
+SELECT -9223372036854775808 DIV -1;
+--error ER_DATA_OUT_OF_RANGE
+SELECT 18446744073709551615 DIV -1;
+
+
+# Have to create a table because the negation op may convert literals to DECIMAL
+CREATE TABLE t1(a BIGINT, b BIGINT UNSIGNED);
+INSERT INTO t1 VALUES(-9223372036854775808, 9223372036854775809);
+
+--error ER_DATA_OUT_OF_RANGE
+SELECT -a FROM t1;
+--error ER_DATA_OUT_OF_RANGE
+SELECT -b FROM t1;
+
+DROP TABLE t1;
+
+# Decimal overflows
+# =================
+
+SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
+--error ER_DATA_OUT_OF_RANGE
+SELECT @a + @a;
+--error ER_DATA_OUT_OF_RANGE
+SELECT @a * @a;
+--error ER_DATA_OUT_OF_RANGE
+SELECT -@a - @a;
+--error ER_DATA_OUT_OF_RANGE
+SELECT @a / 0.5;
+
+# Non-overflow tests to improve code coverage
+# ===========================================
+SELECT COT(1/0);
+SELECT -1 + 9223372036854775808;
+SELECT 2 DIV -2;
+SELECT -(1 DIV 0);
+# Crashed the server with SIGFPE before the bugfix
+SELECT -9223372036854775808 MOD -1;