summaryrefslogtreecommitdiff
path: root/mysql-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
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')
-rw-r--r--mysql-test/r/func_math.result136
-rw-r--r--mysql-test/r/func_misc.result6
-rw-r--r--mysql-test/r/func_test.result4
-rw-r--r--mysql-test/r/select.result15
-rw-r--r--mysql-test/r/sp.result32
-rw-r--r--mysql-test/r/strict.result5
-rw-r--r--mysql-test/r/type_newdecimal.result7
-rw-r--r--mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result4
-rw-r--r--mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test2
-rw-r--r--mysql-test/t/func_math.test141
-rw-r--r--mysql-test/t/func_misc.test2
-rw-r--r--mysql-test/t/func_test.test2
-rw-r--r--mysql-test/t/select.test4
-rw-r--r--mysql-test/t/sp.test9
-rw-r--r--mysql-test/t/strict.test1
-rw-r--r--mysql-test/t/type_newdecimal.test1
16 files changed, 301 insertions, 70 deletions
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result
index 537b1db9781..449c05c65a9 100644
--- a/mysql-test/r/func_math.result
+++ b/mysql-test/r/func_math.result
@@ -98,7 +98,7 @@ explain extended select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
+Note 1003 select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format(cot(1),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
select degrees(pi()),radians(360);
degrees(pi()) radians(360)
180 6.283185307179586
@@ -451,23 +451,17 @@ SELECT 1 FROM (SELECT ROUND(f1, f1) AS a FROM t1) AS s WHERE a LIKE 'a';
DROP TABLE t1;
End of 5.0 tests
SELECT 1e308 + 1e308;
-1e308 + 1e308
-NULL
+ERROR 22003: DOUBLE value is out of range in '(1e308 + 1e308)'
SELECT -1e308 - 1e308;
--1e308 - 1e308
-NULL
+ERROR 22003: DOUBLE value is out of range in '(-(1e308) - 1e308)'
SELECT 1e300 * 1e300;
-1e300 * 1e300
-NULL
+ERROR 22003: DOUBLE value is out of range in '(1e300 * 1e300)'
SELECT 1e300 / 1e-300;
-1e300 / 1e-300
-NULL
+ERROR 22003: DOUBLE value is out of range in '(1e300 / 1e-300)'
SELECT EXP(750);
-EXP(750)
-NULL
+ERROR 22003: DOUBLE value is out of range in 'exp(750)'
SELECT POW(10, 309);
-POW(10, 309)
-NULL
+ERROR 22003: DOUBLE value is out of range in 'pow(10,309)'
#
# Bug #44768: SIGFPE crash when selecting rand from a view
# containing null
@@ -488,11 +482,121 @@ RAND(i)
DROP TABLE t1;
#
select 123456789012345678901234567890.123456789012345678901234567890 div 1 as x;
-ERROR 22003: Out of range value for column 'x' at row 1
+ERROR 22003: BIGINT value is out of range in '(123456789012345678901234567890.123456789012345678901234567890 DIV 1)'
select "123456789012345678901234567890.123456789012345678901234567890" div 1 as x;
-ERROR 22003: Out of range value for column 'x' at row 1
+ERROR 22003: BIGINT value is out of range in '('123456789012345678901234567890.123456789012345678901234567890' DIV 1)'
SHOW WARNINGS;
Level Code Message
Warning 1292 Truncated incorrect DECIMAL value: ''
-Error 1264 Out of range value for column 'x' at row 1
+Error 1689 BIGINT value is out of range in '('123456789012345678901234567890.123456789012345678901234567890' DIV 1)'
End of 5.1 tests
+#
+# Bug #8433: Overflow must be an error
+#
+SELECT 1e308 + 1e308;
+ERROR 22003: DOUBLE value is out of range in '(1e308 + 1e308)'
+SELECT -1e308 - 1e308;
+ERROR 22003: DOUBLE value is out of range in '(-(1e308) - 1e308)'
+SELECT 1e300 * 1e300;
+ERROR 22003: DOUBLE value is out of range in '(1e300 * 1e300)'
+SELECT 1e300 / 1e-300;
+ERROR 22003: DOUBLE value is out of range in '(1e300 / 1e-300)'
+SELECT EXP(750);
+ERROR 22003: DOUBLE value is out of range in 'exp(750)'
+SELECT POW(10, 309);
+ERROR 22003: DOUBLE value is out of range in 'pow(10,309)'
+SELECT COT(0);
+ERROR 22003: DOUBLE value is out of range in 'cot(0)'
+SELECT DEGREES(1e307);
+ERROR 22003: DOUBLE value is out of range in 'degrees(1e307)'
+SELECT 9223372036854775808 + 9223372036854775808;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 + 9223372036854775808)'
+SELECT 18446744073709551615 + 1;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 + 1)'
+SELECT 1 + 18446744073709551615;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(1 + 18446744073709551615)'
+SELECT -2 + CAST(1 AS UNSIGNED);
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(2) + cast(1 as unsigned))'
+SELECT CAST(1 AS UNSIGNED) + -2;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) + -(2))'
+SELECT -9223372036854775808 + -9223372036854775808;
+ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) + -(9223372036854775808))'
+SELECT 9223372036854775807 + 9223372036854775807;
+ERROR 22003: BIGINT value is out of range in '(9223372036854775807 + 9223372036854775807)'
+SELECT CAST(0 AS UNSIGNED) - 9223372036854775809;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(0 as unsigned) - 9223372036854775809)'
+SELECT 9223372036854775808 - 9223372036854775809;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 - 9223372036854775809)'
+SELECT CAST(1 AS UNSIGNED) - 2;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) - 2)'
+SELECT 18446744073709551615 - (-1);
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 - -(1))'
+SELECT -1 - 9223372036854775808;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(1) - 9223372036854775808)'
+SELECT -1 - CAST(1 AS UNSIGNED);
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(-(1) - cast(1 as unsigned))'
+SELECT -9223372036854775808 - 1;
+ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) - 1)'
+SELECT 9223372036854775807 - -9223372036854775808;
+ERROR 22003: BIGINT value is out of range in '(9223372036854775807 - -(9223372036854775808))'
+set SQL_MODE='NO_UNSIGNED_SUBTRACTION';
+SELECT 18446744073709551615 - 1;
+ERROR 22003: BIGINT value is out of range in '(18446744073709551615 - 1)'
+SELECT 18446744073709551615 - CAST(1 AS UNSIGNED);
+ERROR 22003: BIGINT value is out of range in '(18446744073709551615 - cast(1 as unsigned))'
+SELECT 18446744073709551614 - (-1);
+ERROR 22003: BIGINT value is out of range in '(18446744073709551614 - -(1))'
+SELECT 9223372036854775807 - -1;
+ERROR 22003: BIGINT value is out of range in '(9223372036854775807 - -(1))'
+set SQL_MODE=default;
+SELECT 4294967296 * 4294967296;
+ERROR 22003: BIGINT value is out of range in '(4294967296 * 4294967296)'
+SELECT 9223372036854775808 * 2;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 * 2)'
+SELECT 9223372036854775808 * 2;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(9223372036854775808 * 2)'
+SELECT 7158278827 * 3221225472;
+ERROR 22003: BIGINT value is out of range in '(7158278827 * 3221225472)'
+SELECT 9223372036854775807 * (-2);
+ERROR 22003: BIGINT value is out of range in '(9223372036854775807 * -(2))'
+SELECT CAST(1 as UNSIGNED) * (-1);
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(cast(1 as unsigned) * -(1))'
+SELECT 9223372036854775807 * 2;
+ERROR 22003: BIGINT value is out of range in '(9223372036854775807 * 2)'
+SELECT ABS(-9223372036854775808);
+ERROR 22003: BIGINT value is out of range in 'abs(-(9223372036854775808))'
+SELECT -9223372036854775808 DIV -1;
+ERROR 22003: BIGINT value is out of range in '(-(9223372036854775808) DIV -(1))'
+SELECT 18446744073709551615 DIV -1;
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(18446744073709551615 DIV -(1))'
+CREATE TABLE t1(a BIGINT, b BIGINT UNSIGNED);
+INSERT INTO t1 VALUES(-9223372036854775808, 9223372036854775809);
+SELECT -a FROM t1;
+ERROR 22003: BIGINT value is out of range in '-('-9223372036854775808')'
+SELECT -b FROM t1;
+ERROR 22003: BIGINT value is out of range in '-('9223372036854775809')'
+DROP TABLE t1;
+SET @a:=999999999999999999999999999999999999999999999999999999999999999999999999999999999;
+SELECT @a + @a;
+ERROR 22003: DECIMAL value is out of range in '((@a) + (@a))'
+SELECT @a * @a;
+ERROR 22003: DECIMAL value is out of range in '((@a) * (@a))'
+SELECT -@a - @a;
+ERROR 22003: DECIMAL value is out of range in '(-((@a)) - (@a))'
+SELECT @a / 0.5;
+ERROR 22003: DECIMAL value is out of range in '((@a) / 0.5)'
+SELECT COT(1/0);
+COT(1/0)
+NULL
+SELECT -1 + 9223372036854775808;
+-1 + 9223372036854775808
+9223372036854775807
+SELECT 2 DIV -2;
+2 DIV -2
+-1
+SELECT -(1 DIV 0);
+-(1 DIV 0)
+NULL
+SELECT -9223372036854775808 MOD -1;
+-9223372036854775808 MOD -1
+0
diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result
index 81dddd0f648..d4c1aef4054 100644
--- a/mysql-test/r/func_misc.result
+++ b/mysql-test/r/func_misc.result
@@ -25,9 +25,9 @@ length(uuid()) charset(uuid()) length(unhex(replace(uuid(),_utf8'-',_utf8'')))
36 utf8 16
set @a= uuid_short();
set @b= uuid_short();
-select cast(@a - @b as signed);
-cast(@a - @b as signed)
--1
+select @b - @a;
+@b - @a
+1
select length(format('nan', 2)) > 0;
length(format('nan', 2)) > 0
1
diff --git a/mysql-test/r/func_test.result b/mysql-test/r/func_test.result
index 96a7bafccfc..bd111a3c310 100644
--- a/mysql-test/r/func_test.result
+++ b/mysql-test/r/func_test.result
@@ -63,8 +63,8 @@ id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select (10 % 7) AS `10 % 7`,(10 % 7) AS `10 mod 7`,(10 DIV 3) AS `10 div 3`
-select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2;
-(1 << 64)-1 ((1 << 64)-1) DIV 1 ((1 << 64)-1) DIV 2
+select 18446744073709551615, 18446744073709551615 DIV 1, 18446744073709551615 DIV 2;
+18446744073709551615 18446744073709551615 DIV 1 18446744073709551615 DIV 2
18446744073709551615 18446744073709551615 9223372036854775807
explain extended select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2;
id select_type table type possible_keys key key_len ref rows filtered Extra
diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result
index cc752c03a36..305a74ee086 100644
--- a/mysql-test/r/select.result
+++ b/mysql-test/r/select.result
@@ -2426,27 +2426,28 @@ city
London
DROP TABLE t1;
create table t1 (a int(11) unsigned, b int(11) unsigned);
-insert into t1 values (1,0), (1,1), (1,2);
+insert into t1 values (1,0), (1,1), (18446744073709551615,0);
+Warnings:
+Warning 1264 Out of range value for column 'a' at row 3
select a-b from t1 order by 1;
a-b
0
1
-18446744073709551615
+4294967295
select a-b , (a-b < 0) from t1 order by 1;
a-b (a-b < 0)
0 0
1 0
-18446744073709551615 0
+4294967295 0
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
d (a-b >= 0) b
1 1 0
0 1 1
-18446744073709551615 1 2
select cast((a - b) as unsigned) from t1 order by 1;
cast((a - b) as unsigned)
0
1
-18446744073709551615
+4294967295
drop table t1;
create table t1 (a int(11));
select all all * from t1;
@@ -3419,6 +3420,7 @@ id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t2 const PRIMARY PRIMARY 4 const 1
1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where
DROP TABLE t1,t2;
+SET SQL_MODE='NO_UNSIGNED_SUBTRACTION';
CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL);
INSERT t1 SET i = 0;
UPDATE t1 SET i = -1;
@@ -3438,8 +3440,9 @@ Warnings:
Warning 1264 Out of range value for column 'i' at row 1
SELECT * FROM t1;
i
-255
+0
DROP TABLE t1;
+SET SQL_MODE=default;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, c int, e int, primary key(a,b,c));
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index b656680326b..62981a2a8d5 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -6022,16 +6022,12 @@ select bug20777(9223372036854775810) as '9223372036854775810 2**63+2';
9223372036854775810 2**63+2
9223372036854775810
select bug20777(-9223372036854775808) as 'lower bounds signed bigint';
-lower bounds signed bigint
-0
-Warnings:
-Warning 1264 Out of range value for column 'f1' at row 1
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(f1@0 - 10)'
select bug20777(9223372036854775807) as 'upper bounds signed bigint';
upper bounds signed bigint
9223372036854775807
select bug20777(0) as 'lower bounds unsigned bigint';
-lower bounds unsigned bigint
-0
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(f1@0 - 10)'
select bug20777(18446744073709551615) as 'upper bounds unsigned bigint';
upper bounds unsigned bigint
18446744073709551615
@@ -6041,10 +6037,7 @@ upper bounds unsigned bigint + 1
Warnings:
Warning 1264 Out of range value for column 'f1' at row 1
select bug20777(-1) as 'lower bounds unsigned bigint - 1';
-lower bounds unsigned bigint - 1
-0
-Warnings:
-Warning 1264 Out of range value for column 'f1' at row 1
+ERROR 22003: BIGINT UNSIGNED value is out of range in '(f1@0 - 10)'
create table examplebug20777 as select
0 as 'i',
bug20777(9223372036854775806) as '2**63-2',
@@ -6053,15 +6046,10 @@ bug20777(9223372036854775808) as '2**63',
bug20777(9223372036854775809) as '2**63+1',
bug20777(18446744073709551614) as '2**64-2',
bug20777(18446744073709551615) as '2**64-1',
-bug20777(18446744073709551616) as '2**64',
-bug20777(0) as '0',
-bug20777(-1) as '-1';
+bug20777(18446744073709551616) as '2**64';
Warnings:
Warning 1264 Out of range value for column 'f1' at row 1
-Warning 1264 Out of range value for column 'f1' at row 1
-insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616, 0, -1);
-Warnings:
-Warning 1264 Out of range value for column '-1' at row 1
+insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616);
show create table examplebug20777;
Table Create Table
examplebug20777 CREATE TABLE `examplebug20777` (
@@ -6072,14 +6060,12 @@ examplebug20777 CREATE TABLE `examplebug20777` (
`2**63+1` bigint(20) unsigned DEFAULT NULL,
`2**64-2` bigint(20) unsigned DEFAULT NULL,
`2**64-1` bigint(20) unsigned DEFAULT NULL,
- `2**64` bigint(20) unsigned DEFAULT NULL,
- `0` bigint(20) unsigned DEFAULT NULL,
- `-1` bigint(20) unsigned DEFAULT NULL
+ `2**64` bigint(20) unsigned DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
select * from examplebug20777 order by i;
-i 2**63-2 2**63-1 2**63 2**63+1 2**64-2 2**64-1 2**64 0 -1
-0 9223372036854775806 9223372036854775807 9223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 18446744073709551615 0 0
-1 9223372036854775806 9223372036854775807 223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 8446744073709551616 0 0
+i 2**63-2 2**63-1 2**63 2**63+1 2**64-2 2**64-1 2**64
+0 9223372036854775806 9223372036854775807 9223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 18446744073709551615
+1 9223372036854775806 9223372036854775807 223372036854775808 9223372036854775809 18446744073709551614 18446744073709551615 8446744073709551616
drop table examplebug20777;
select bug20777(18446744073709551613)+1;
bug20777(18446744073709551613)+1
diff --git a/mysql-test/r/strict.result b/mysql-test/r/strict.result
index fa4096cb424..769e797d2f6 100644
--- a/mysql-test/r/strict.result
+++ b/mysql-test/r/strict.result
@@ -895,6 +895,7 @@ ERROR 22003: Out of range value for column 'col1' at row 1
INSERT INTO t1 (col2) VALUES ('-1.2E-3');
ERROR 22003: Out of range value for column 'col2' at row 1
UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
+ERROR 22003: DOUBLE value is out of range in '("test"."t1"."col1" * 5000)'
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
ERROR 22012: Division by 0
UPDATE t1 SET col2= MOD(col2,0) WHERE col2 > 0;
@@ -922,10 +923,10 @@ SELECT * FROM t1;
col1 col2
-2.2e-307 0
1e-303 0
-NULL 1.7e308
+1.7e308 1.7e308
-2.2e-307 0
-2e-307 0
-NULL 1.7e308
+1.7e308 1.7e308
0 NULL
2 NULL
NULL NULL
diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result
index 00526597a32..e5fbf158a8b 100644
--- a/mysql-test/r/type_newdecimal.result
+++ b/mysql-test/r/type_newdecimal.result
@@ -1385,11 +1385,7 @@ Warning 1264 Out of range value for column 'c1' at row 1
insert into t1 values(
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 *
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999);
-Warnings:
-Warning 1292 Truncated incorrect DECIMAL value: ''
-Warning 1292 Truncated incorrect DECIMAL value: ''
-Warning 1292 Truncated incorrect DECIMAL value: ''
-Warning 1264 Out of range value for column 'c1' at row 1
+ERROR 22003: DECIMAL value is out of range in '(99999999999999999999999999999999999999999999999999999999999999999 * 99999999999999999999999999999999999999999999999999999999999999999)'
insert into t1 values(1e100);
Warnings:
Warning 1264 Out of range value for column 'c1' at row 1
@@ -1397,7 +1393,6 @@ select * from t1;
c1
9999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999
-9999999999999999999999999999999999999999999999999999999999999999
drop table t1;
create table t1(a decimal(7,2));
insert into t1 values(123.12);
diff --git a/mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result b/mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result
index 2d709c486dd..e6d9aff7141 100644
--- a/mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result
+++ b/mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result
@@ -14,9 +14,9 @@ SET @@global.sql_slave_skip_counter = 2147483648*2;
Warnings:
Warning 1292 Truncated incorrect sql_slave_skip_counter value: '4294967296'
SET @@global.sql_slave_skip_counter = 2147483648*2-1;
-SET @@global.sql_slave_skip_counter = 4294967295*4294967295;
+SET @@global.sql_slave_skip_counter = 18446744065119617025;
Warnings:
-Warning 1292 Truncated incorrect sql_slave_skip_counter value: '-8589934591'
+Warning 1292 Truncated incorrect sql_slave_skip_counter value: '18446744065119617025'
'#--------------------FN_DYNVARS_165_03-------------------------#'
SET @@global.sql_slave_skip_counter = '5';
ERROR 42000: Incorrect argument type to variable 'sql_slave_skip_counter'
diff --git a/mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test b/mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test
index 86cb3824d07..10ca47133b7 100644
--- a/mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test
+++ b/mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test
@@ -56,7 +56,7 @@ SET @@global.sql_slave_skip_counter = 1024;
SET @@global.sql_slave_skip_counter = 2147483648;
SET @@global.sql_slave_skip_counter = 2147483648*2;
SET @@global.sql_slave_skip_counter = 2147483648*2-1;
-SET @@global.sql_slave_skip_counter = 4294967295*4294967295;
+SET @@global.sql_slave_skip_counter = 18446744065119617025;
--echo '#--------------------FN_DYNVARS_165_03-------------------------#'
###################################################################
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;
diff --git a/mysql-test/t/func_misc.test b/mysql-test/t/func_misc.test
index 6590b43f2dc..43cc6de6649 100644
--- a/mysql-test/t/func_misc.test
+++ b/mysql-test/t/func_misc.test
@@ -22,7 +22,7 @@ select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_ut
# between two calls should be -1
set @a= uuid_short();
set @b= uuid_short();
-select cast(@a - @b as signed);
+select @b - @a;
#
# Test for core dump with nan
diff --git a/mysql-test/t/func_test.test b/mysql-test/t/func_test.test
index 77bf3be5e72..f697e0b477a 100644
--- a/mysql-test/t/func_test.test
+++ b/mysql-test/t/func_test.test
@@ -24,7 +24,7 @@ select 1 XOR 1, 1 XOR 0, 0 XOR 1, 0 XOR 0, NULL XOR 1, 1 XOR NULL, 0 XOR NULL;
select 1 like 2 xor 2 like 1;
select 10 % 7, 10 mod 7, 10 div 3;
explain extended select 10 % 7, 10 mod 7, 10 div 3;
-select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2;
+select 18446744073709551615, 18446744073709551615 DIV 1, 18446744073709551615 DIV 2;
explain extended select (1 << 64)-1, ((1 << 64)-1) DIV 1, ((1 << 64)-1) DIV 2;
create table t1 (a int);
diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test
index 80a714882be..1e53461f665 100644
--- a/mysql-test/t/select.test
+++ b/mysql-test/t/select.test
@@ -1989,7 +1989,7 @@ DROP TABLE t1;
#
create table t1 (a int(11) unsigned, b int(11) unsigned);
-insert into t1 values (1,0), (1,1), (1,2);
+insert into t1 values (1,0), (1,1), (18446744073709551615,0);
select a-b from t1 order by 1;
select a-b , (a-b < 0) from t1 order by 1;
select a-b as d, (a-b >= 0), b from t1 group by b having d >= 0;
@@ -2910,6 +2910,7 @@ DROP TABLE t1,t2;
# cases to prevent fixing this accidently. It is intended behaviour)
#
+SET SQL_MODE='NO_UNSIGNED_SUBTRACTION';
CREATE TABLE t1 (i TINYINT UNSIGNED NOT NULL);
INSERT t1 SET i = 0;
UPDATE t1 SET i = -1;
@@ -2919,6 +2920,7 @@ SELECT * FROM t1;
UPDATE t1 SET i = i - 1;
SELECT * FROM t1;
DROP TABLE t1;
+SET SQL_MODE=default;
# BUG#17379
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index b4727ad3df7..310803531d9 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -7076,11 +7076,14 @@ select bug20777(9223372036854775807) as '9223372036854775807 2**63-1';
select bug20777(9223372036854775808) as '9223372036854775808 2**63+0';
select bug20777(9223372036854775809) as '9223372036854775809 2**63+1';
select bug20777(9223372036854775810) as '9223372036854775810 2**63+2';
+--error ER_DATA_OUT_OF_RANGE
select bug20777(-9223372036854775808) as 'lower bounds signed bigint';
select bug20777(9223372036854775807) as 'upper bounds signed bigint';
+--error ER_DATA_OUT_OF_RANGE
select bug20777(0) as 'lower bounds unsigned bigint';
select bug20777(18446744073709551615) as 'upper bounds unsigned bigint';
select bug20777(18446744073709551616) as 'upper bounds unsigned bigint + 1';
+--error ER_DATA_OUT_OF_RANGE
select bug20777(-1) as 'lower bounds unsigned bigint - 1';
create table examplebug20777 as select
@@ -7091,10 +7094,8 @@ create table examplebug20777 as select
bug20777(9223372036854775809) as '2**63+1',
bug20777(18446744073709551614) as '2**64-2',
bug20777(18446744073709551615) as '2**64-1',
- bug20777(18446744073709551616) as '2**64',
- bug20777(0) as '0',
- bug20777(-1) as '-1';
-insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616, 0, -1);
+ bug20777(18446744073709551616) as '2**64';
+insert into examplebug20777 values (1, 9223372036854775806, 9223372036854775807, 223372036854775808, 9223372036854775809, 18446744073709551614, 18446744073709551615, 8446744073709551616);
show create table examplebug20777;
select * from examplebug20777 order by i;
diff --git a/mysql-test/t/strict.test b/mysql-test/t/strict.test
index d1e136bf5fa..0dd324d5df2 100644
--- a/mysql-test/t/strict.test
+++ b/mysql-test/t/strict.test
@@ -822,6 +822,7 @@ INSERT INTO t1 (col2) VALUES (-1.1E-3);
INSERT INTO t1 (col1) VALUES ('+1.8E+309');
--error 1264
INSERT INTO t1 (col2) VALUES ('-1.2E-3');
+--error ER_DATA_OUT_OF_RANGE
UPDATE t1 SET col1 =col1 * 5000 WHERE col1 > 0;
--error 1365
UPDATE t1 SET col2 =col2 / 0 WHERE col2 > 0;
diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test
index 8af9d4c263e..3f418a339cc 100644
--- a/mysql-test/t/type_newdecimal.test
+++ b/mysql-test/t/type_newdecimal.test
@@ -1090,6 +1090,7 @@ create table t1 (c1 decimal(64));
--disable_ps_protocol
insert into t1 values(
89000000000000000000000000000000000000000000000000000000000000000000000000000000000000000);
+--error ER_DATA_OUT_OF_RANGE
insert into t1 values(
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 *
99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999);