--disable_warnings drop table if exists t1; --enable_warnings # # constant IN function test # select 1.1 IN (1.0, 1.2); select 1.1 IN (1.0, 1.2, 1.1, 1.4, 0.5); select 1.1 IN (1.0, 1.2, NULL, 1.4, 0.5); select 0.5 IN (1.0, 1.2, NULL, 1.4, 0.5); select 1 IN (1.11, 1.2, 1.1, 1.4, 1, 0.5); select 1 IN (1.11, 1.2, 1.1, 1.4, NULL, 0.5); # # case function test # select case 1.0 when 0.1 then "a" when 1.0 then "b" else "c" END; select case 0.1 when 0.1 then "a" when 1.0 then "b" else "c" END; select case 1 when 0.1 then "a" when 1.0 then "b" else "c" END; select case 1.0 when 0.1 then "a" when 1 then "b" else "c" END; select case 1.001 when 0.1 then "a" when 1 then "b" else "c" END; # # non constant IN test # create table t1 (a decimal(6,3)); insert into t1 values (1.0), (NULL), (0.1); select * from t1; select 0.1 in (1.0, 1.2, 1.1, a, 1.4, 0.5) from t1; drop table t1; # # if function test # create table t1 select if(1, 1.1, 1.2), if(0, 1.1, 1.2), if(0.1, 1.1, 1.2), if(0, 1, 1.1), if(0, NULL, 1.2), if(1, 0.22e1, 1.1), if(1E0, 1.1, 1.2); select * from t1; show create table t1; drop table t1; # # NULLIF # create table t1 select nullif(1.1, 1.1), nullif(1.1, 1.2), nullif(1.1, 0.11e1), nullif(1.0, 1), nullif(1, 1.0), nullif(1, 1.1); select * from t1; show create table t1; drop table t1; # # saving in decimal field with overflow # create table t1 (a decimal(4,2)); insert ignore into t1 value (10000), (1.1e10), ("11111"), (100000.1); insert ignore into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1); select a from t1; drop table t1; create table t1 (a decimal(4,2) unsigned); insert ignore into t1 value (10000), (1.1e10), ("11111"), (100000.1); insert ignore into t1 value (-10000), (-1.1e10), ("-11111"), (-100000.1); select a from t1; drop table t1; # # saving in field with overflow from decimal # create table t1 (a bigint); insert ignore into t1 values (18446744073709551615.0); insert ignore into t1 values (9223372036854775808.0); insert ignore into t1 values (-18446744073709551615.0); select * from t1; drop table t1; create table t1 (a bigint unsigned); insert into t1 values (18446744073709551615.0); insert into t1 values (9223372036854775808.0); insert ignore into t1 values (9999999999999999999999999.000); insert ignore into t1 values (-1.0); select * from t1; drop table t1; create table t1 (a tinyint); insert ignore into t1 values (18446744073709551615.0); insert ignore into t1 values (9223372036854775808.0); select * from t1; drop table t1; # # test that functions create decimal fields # create table t1 select round(15.4,-1), truncate(-5678.123451,-3), abs(-1.1), -(-1.1); show create table t1; drop table t1; # # Trydy's tests # set session sql_mode='traditional'; select 1e10/0e0; create table wl1612 (col1 int, col2 decimal(38,10), col3 numeric(38,10)); insert into wl1612 values(1,12345678901234567890.1234567890,12345678901234567890.1234567890); select * from wl1612; insert into wl1612 values(2,01234567890123456789.0123456789,01234567890123456789.0123456789); select * from wl1612 where col1=2; insert into wl1612 values(3,1234567890123456789012345678.0123456789,1234567890123456789012345678.0123456789); select * from wl1612 where col1=3; select col1/0 from wl1612; select col2/0 from wl1612; select col3/0 from wl1612; insert into wl1612 values(5,5000.0005,5000.0005); insert into wl1612 values(6,5000.0005,5000.0005); select sum(col2),sum(col3) from wl1612; #select avg(col2),avg(col3) from wl1612; insert into wl1612 values(7,500000.000005,500000.000005); insert into wl1612 values(8,500000.000005,500000.000005); select sum(col2),sum(col3) from wl1612 where col1>4; #select avg(col2),avg(col3) from wl1612 where col1>4; #insert into wl1612 (col1,col2) values(9,123456789012345678901234567890); #insert into wl1612 (col1,col3) values(9,123456789012345678901234567890); insert into wl1612 (col1, col2) values(9,1.01234567891); insert into wl1612 (col1, col2) values(10,1.01234567894); insert into wl1612 (col1, col2) values(11,1.01234567895); insert into wl1612 (col1, col2) values(12,1.01234567896); select col1,col2 from wl1612 where col1>8; insert into wl1612 (col1, col3) values(13,1.01234567891); insert into wl1612 (col1, col3) values(14,1.01234567894); insert into wl1612 (col1, col3) values(15,1.01234567895); insert into wl1612 (col1, col3) values(16,1.01234567896); select col1,col3 from wl1612 where col1>12; select col1 from wl1612 where col1>4 and col2=1.01234567891; #-- should return 0 rows # select col1 from wl1612 where col1>4 and col2=1.0123456789; #-- should return col1 values 9 & 10 # select col1 from wl1612 where col1>4 and col2<>1.0123456789; #-- should return col1 values 5,6,7,8,11,12 # select col1 from wl1612 where col1>4 and col2<1.0123456789; #-- should return 0 rows # select col1 from wl1612 where col1>4 and col2<=1.0123456789; #-- should return col1 values 9 & 10 # select col1 from wl1612 where col1>4 and col2>1.0123456789; #-- should return col1 values 5,6,7,8,11,12 # select col1 from wl1612 where col1>4 and col2>=1.0123456789; #-- should return col1 values 5,6,7,8,910,11,12 # #select col1, col2 from wl1612 where col1=11 or col1=12; select col1 from wl1612 where col1>4 and col2=1.012345679; #-- should return col1 values 11,12 # select col1 from wl1612 where col1>4 and col2<>1.012345679; #-- should return col1 values 5,6,7,8,9,10 # select col1 from wl1612 where col1>4 and col3=1.01234567891; #-- should return 0 rows # select col1 from wl1612 where col1>4 and col3=1.0123456789; #-- should return col1 values 13,14 # select col1 from wl1612 where col1>4 and col3<>1.0123456789; #-- should return col1 values 5,6,7,8,15,16 # select col1 from wl1612 where col1>4 and col3<1.0123456789; #-- should return 0 rows # select col1 from wl1612 where col1>4 and col3<=1.0123456789; #-- should return col1 values 13,14 # select col1 from wl1612 where col1>4 and col3>1.0123456789; #-- should return col1 values 5,6,7,8,15,16 # select col1 from wl1612 where col1>4 and col3>=1.0123456789; #-- should return col1 values 5,6,7,8,13,14,15,16 # select col1 from wl1612 where col1>4 and col3=1.012345679; #-- should return col1 values 15,16 # select col1 from wl1612 where col1>4 and col3<>1.012345679; #-- should return col1 values 5,6,7,8,13,14 # drop table wl1612; # select 1/3; # select 0.8=0.7+0.1; #-- should return 1 (true) # select 0.7+0.1; # create table wl1612_1 (col1 int); insert into wl1612_1 values(10); # select * from wl1612_1 where 0.8=0.7+0.1; #--should return 1 row (col1=10) # select 0.07+0.07 from wl1612_1; # select 0.07-0.07 from wl1612_1; # select 0.07*0.07 from wl1612_1; # select 0.07/0.07 from wl1612_1; # drop table wl1612_1; # create table wl1612_2 (col1 decimal(10,2), col2 numeric(10,2)); insert into wl1612_2 values(1,1); insert into wl1612_2 values(+1,+1); insert into wl1612_2 values(+01,+01); insert into wl1612_2 values(+001,+001); # select col1,count(*) from wl1612_2 group by col1; # select col2,count(*) from wl1612_2 group by col2; # drop table wl1612_2; # create table wl1612_3 (col1 decimal(10,2), col2 numeric(10,2)); insert into wl1612_3 values('1','1'); insert into wl1612_3 values('+1','+1'); # insert into wl1612_3 values('+01','+01'); insert into wl1612_3 values('+001','+001'); # select col1,count(*) from wl1612_3 group by col1; # select col2,count(*) from wl1612_3 group by col2; # drop table wl1612_3; # select mod(234,10) ; #-- should return 4 # select mod(234.567,10.555); #-- should return 2.357 # select mod(-234.567,10.555); #-- should return -2.357 # select mod(234.567,-10.555); #-- should return 2.357 # select round(15.1); #-- should return 15 # select round(15.4); #-- should return 15 # select round(15.5); #-- should return 16 # select round(15.6); #-- should return 16 # select round(15.9); #-- should return 16 # select round(-15.1); #-- should return -15 # select round(-15.4); #-- should return -15 # select round(-15.5); #-- should return -16 # select round(-15.6); #-- should return -16 # select round(-15.9); #-- should return -16 # select round(15.1,1); #-- should return 15.1 # select round(15.4,1); #-- should return 15.4 # select round(15.5,1); #-- should return 15.5 # select round(15.6,1); #-- should return 15.6 # select round(15.9,1); #-- should return 15.9 # select round(-15.1,1); #-- should return -15.1 # select round(-15.4,1); #-- should return -15.4 # select round(-15.5,1); #-- should return -15.5 # select round(-15.6,1); #-- should return -15.6 # select round(-15.9,1); #-- should return -15.9 # select round(15.1,0); #-- should return 15 # select round(15.4,0); #-- should return 15 # select round(15.5,0); #-- should return 16 # select round(15.6,0); #-- should return 16 # select round(15.9,0); #-- should return 16 # select round(-15.1,0); #-- should return -15 # select round(-15.4,0); #-- should return -15 # select round(-15.5,0); #-- should return -16 # select round(-15.6,0); #-- should return -16 # select round(-15.9,0); #-- should return -16 # select round(15.1,-1); #-- should return 20 # select round(15.4,-1); #-- should return 20 # select round(15.5,-1); #-- should return 20 # select round(15.6,-1); #-- should return 20 # select round(15.9,-1); #-- should return 20 # select round(-15.1,-1); #-- should return -20 # select round(-15.4,-1); #-- should return -20 # select round(-15.5,-1); #-- should return -20 # select round(-15.6,-1); #-- should return -20 # select round(-15.91,-1); #-- should return -20 # select truncate(5678.123451,0); #-- should return 5678 # select truncate(5678.123451,1); #-- should return 5678.1 # select truncate(5678.123451,2); #-- should return 5678.12 # select truncate(5678.123451,3); #-- should return 5678.123 # select truncate(5678.123451,4); #-- should return 5678.1234 # select truncate(5678.123451,5); #-- should return 5678.12345 # select truncate(5678.123451,6); #-- should return 5678.123451 # select truncate(5678.123451,-1); #-- should return 5670 # select truncate(5678.123451,-2); #-- should return 5600 # select truncate(5678.123451,-3); #-- should return 5000 # select truncate(5678.123451,-4); #-- should return 0 # select truncate(-5678.123451,0); #-- should return -5678 # select truncate(-5678.123451,1); #-- should return -5678.1 # select truncate(-5678.123451,2); #-- should return -5678.12 # select truncate(-5678.123451,3); #-- should return -5678.123 # select truncate(-5678.123451,4); #-- should return -5678.1234 # select truncate(-5678.123451,5); #-- should return -5678.12345 # select truncate(-5678.123451,6); #-- should return -5678.123451 # select truncate(-5678.123451,-1); #-- should return -5670 # select truncate(-5678.123451,-2); #-- should return -5600 # select truncate(-5678.123451,-3); #-- should return -5000 # select truncate(-5678.123451,-4); #-- should return 0 # #drop table if exists wl1612_4; create table wl1612_4 (col1 int, col2 decimal(30,25), col3 numeric(30,25)); # insert into wl1612_4 values(1,0.0123456789012345678912345,0.0123456789012345678912345); # select col2/9999999999 from wl1612_4 where col1=1; # select col3/9999999999 from wl1612_4 where col1=1; # select 9999999999/col2 from wl1612_4 where col1=1; # select 9999999999/col3 from wl1612_4 where col1=1; # select col2*9999999999 from wl1612_4 where col1=1; # select col3*9999999999 from wl1612_4 where col1=1; # insert into wl1612_4 values(2,55555.0123456789012345678912345,55555.0123456789012345678912345); # select col2/9999999999 from wl1612_4 where col1=2; # select col3/9999999999 from wl1612_4 where col1=2; # select 9999999999/col2 from wl1612_4 where col1=2; # select 9999999999/col3 from wl1612_4 where col1=2; # select col2*9999999999 from wl1612_4 where col1=2; # select col3*9999999999 from wl1612_4 where col1=2; # drop table wl1612_4; # # # # #-- Additional tests for WL#1612 Precision math # #-- Comparisons should show that a number is #-- exactly equal to its value as displayed. # set sql_mode=''; # select 23.4 + (-41.7), 23.4 - (41.7) = -18.3; # select -18.3=-18.3; # select 18.3=18.3; # select -18.3=18.3; # select 0.8 = 0.7 + 0.1; # #-- It should be possible to define a column #-- with up to 38 digits precision either before #-- or after the decimal point. Any number which #-- is inserted, if it's within the range, should #-- be exactly the same as the number that gets #-- selected. # drop table if exists t1; # create table t1 (col1 decimal(38)); # insert into t1 values (12345678901234567890123456789012345678); # select * from t1; #-- should return: #+----------------------------------------+ #| col1 | #+----------------------------------------+ #| 12345678901234567890123456789012345678 | #+----------------------------------------+ # #drop table t1; # #create table t1 (col1 decimal(38,38)); # #insert into t1 values (.12345678901234567890123456789012345678); # #select * from t1; #-- should return: #+------------------------------------------+ #| col1 | #+------------------------------------------+ #| 0.12345678901234567890123456789012345678 | #+------------------------------------------+ # drop table t1; # create table t1 (col1 decimal(31,30)); # insert into t1 values (0.00000000001); # select * from t1; #-- should return: #+---------------+ #|col1 | #+---------------+ #| 0.00000000001 | #+---------------+ # drop table t1; # #-- The usual arithmetic operators / * + - should work. # #select 77777777777777777777777777777777777777 / 7777777777777777777777777777777777777 = 10; #-- should return 0 (false). # select 7777777777777777777777777777777777777 * 10; #-- should return 77777777777777777777777777777777777770 # select .7777777777777777777777777777777777777 * 1000000000000000000; #-- should return 777777777777777777.7777777777777777777 # select .7777777777777777777777777777777777777 - 0.1; #-- should return .6777777777777777777777777777777777777 # select .343434343434343434 + .343434343434343434; #-- should return .686868686868686868 # #-- 5. All arithmetic functions mentioned in the #MySQL Reference Manual should work. # select abs(9999999999999999999999); #-- should return 9999999999999999999999 # select abs(-9999999999999999999999); #-- should return 9999999999999999999999 # select ceiling(999999999999999999); select ceiling(99999999999999999999); #-- should return 99999999999999999999 # select ceiling(9.9999999999999999999); #-- should return 10 # select ceiling(-9.9999999999999999999); #-- should return 9 # select floor(999999999999999999); select floor(9999999999999999999999); #-- should return 9999999999999999999999 # select floor(9.999999999999999999999); #-- should return 9 # select floor(-9.999999999999999999999); #-- should return -10 # #enable_view_protocol in 10.4 --disable_view_protocol select floor(-999999999999999999999.999); select ceiling(999999999999999999999.999); --enable_view_protocol # # select 99999999999999999999999999999999999999 mod 3; #-- should return 0 # select round(99999999999999999.999); #-- should return 100000000000000000 # select round(-99999999999999999.999); #-- should return -100000000000000000 # select round(99999999999999999.999,3); #-- should return 100000000000000000.000 # select round(-99999999999999999.999,3); #-- should return -100000000000000000.000 # #enable after fix MDEV-28660 --disable_view_protocol select truncate(99999999999999999999999999999999999999,49); #-- should return 99999999999999999999999999999999999999.000 # --enable_view_protocol select truncate(99.999999999999999999999999999999999999,49); #-- should return 99.9999999999999999999999999999999 # select truncate(99999999999999999999999999999999999999,-31); # should return 99999990000000000000000000000000000000 # #-- 6. Set functions (AVG, SUM, COUNT) should work. # #drop table if exists t1; # #delimiter // # #create procedure p1 () begin # declare v1 int default 1; declare v2 decimal(0,38) default 0; # create table t1 (col1 decimal(0,38)); # while v1 <= 10000 do # insert into t1 values (-v2); # set v2 = v2 + 0.00000000000000000000000000000000000001; # set v1 = v1 + 1; # end while; # select avg(col1),sum(col1),count(col1) from t1; end;// # #call p1()// #-- should return # -- avg(col1)=0.00000000000000000000000000000000000001 added 10,000 times, then divided by 10,000 # -- sum(col1)=0.00000000000000000000000000000000000001 added 10,000 times # # -- count(col1)=10000 # #delimiter ;// # #drop procedure p1; #drop table t1; # #-- When I say DECIMAL(x) I should be able to store x digits. #-- If I can't, there should be an error at CREATE time. # #drop table if exists t1; # #create table t1 (col1 decimal(254)); #-- should return SQLSTATE 22003 numeric value out of range # #-- When I say DECIMAL(x,y) there should be no silent change of precision or #-- scale. # #drop table if exists t1; # #create table t1 (col1 decimal(0,38)); # #show create table t1; #-- should return: #+-------+--------------------------------+ #| Table | Create Table | #+-------+--------------------------------+ #| t9 | CREATE TABLE `t1` ( | #|`s1` decimal(0,38) default NULL | #| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | #+-------+--------------------------------+ # #drop table t1; # #-- From WL#1612 "The future" point 2.: #-- The standard requires that we treat numbers like "0.5" as #-- DECIMAL or NUMERIC, not as floating-point. # #drop table if exists t1; # # create table t1 as select 0.5; # show create table t1; #-- should return: #+-------+-----------------------------------+ #| Table | Create Table | #+-------+-----------------------------------+ #| t7 | CREATE TABLE `t1` ( | #| `0.5` decimal(3,1) NOT NULL default '0.0' | #| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | #+-------+-----------------------------------+ # drop table t1; # #-- From WL#1612, "The future", point 3.: We have to start rounding correctly. # select round(1.5),round(2.5); #-- should return: #+------------+------------+ #| round(1.5) | round(2.5) | #+------------+------------+ #| 2 | 3 | #+------------+------------+ # #-- From WL#1612, "The future", point 4.: "select 0.07 * 0.07;" should return 0.0049, not 0.00. #-- If operand#1 has scale X and operand#2 has scale Y, then result should have scale (X+Y). # select 0.07 * 0.07; #-- should return 0.0049 # #-- From WL#1612, "The future", point 5.: Division by zero is an error. # set sql_mode='traditional'; # select 1E-500 = 0; #-- should return 1 (true). # select 1 / 1E-500; # #-- should return SQLSTATE 22012 division by zero. # select 1 / 0; #-- should return SQLSTATE 22012 division by zero. # #+-------+ #| 1 / 0 | #+-------+ #| NULL | #+-------+ #1 row in set, 1 warning (0.00 sec) # #-- From WL#1612 "The future" point 6.: Overflow is an error. # #set sql_mode=''; # #select 1E300 * 1E300; #-- should return SQLSTATE 22003 numeric value out of range # #select 18446744073709551615 + 1; #-- should return SQLSTATE 22003 numeric value out of range # #-- 14. From WL#1612 "The future" point 7.: #-- If s1 is INTEGER and s2 is DECIMAL, then #-- "create table tk7 as select avg(s1),avg(s2) from tk;" #-- should not create a table with "double(17,4)" data types. #-- The result of AVG must still be exact numeric, with a #-- scale the same or greater than the operand's scale. #-- The result of SUM must still be exact numeric, with #-- a scale the same as the operand's scale. # #drop table if exists t1; #drop table if exists t2; # #create table t1 (col1 int, col2 decimal(5)); # #create table t2 as select avg(col1),avg(col2) from t1; # # #show create table t2; #-- should return: #+-------+---------------------------------+ #| Table | Create Table | #+-------+---------------------------------+ #| t2 | CREATE TABLE `t2` ( | #| `avg(col1)` decimal(17,4) default NULL, | #| `avg(col2)` decimal(17,5) default NULL | #| ) ENGINE=MyISAM DEFAULT CHARSET=latin1 | #+-------+---------------------------------+ # #drop table t2; #drop table t1; # #-- From WL#1612 "The future" point 8.: Stop storing leading "+" signs and # leading "0"s. # #drop table if exists t1; # #create table t1 (col1 decimal(5,2),col2 decimal(5) zerofill, col3 decimal(3,1)); # #insert into t1 values (1,1,1); # #select col1 from t1 union select col2 from t1 union select col3 from t1; # #drop table t1; # #-- From WL#1612, The future" point 9.: #-- Accept the data type and precision and scale as the user #-- asks, or return an error, but don't change to something else. # #drop table if exists t1; # #create table t1 (col1 numeric(4,2)); # #show create table t1; # #drop table t1; # #-- The scripts in the following bugs should work: # #BUG#559 Maximum precision for DECIMAL column ... #BUG#1499 INSERT/UPDATE into decimal field rounding problem #BUG#1845 Not correctly recognising value for decimal field #BUG#2493 Round function doesn't work correctly #BUG#2649 round(0.5) gives 0 (should be 1) #BUG#3612 impicite rounding of VARCHARS during aritchmetic operations... #BUG#3722 SELECT fails for certain values in Double(255,10) column. #BUG#4485 Floating point conversions are inconsistent #BUG#4891 MATH #BUG#5931 Out-of-range values are accepted #BUG#6048 Stored procedure causes operating system reboot #BUG#6053 DOUBLE PRECISION literal # Tests from 'traditional' mode tests # set sql_mode='ansi,traditional'; # CREATE TABLE Sow6_2f (col1 NUMERIC(4,2)); #-- should return OK INSERT INTO Sow6_2f VALUES (10.55); #-- should return OK INSERT INTO Sow6_2f VALUES (10.5555); #-- should return OK INSERT INTO Sow6_2f VALUES (-10.55); #-- should return OK INSERT INTO Sow6_2f VALUES (-10.5555); #-- should return OK INSERT INTO Sow6_2f VALUES (11); #-- should return OK -- error 1264 INSERT INTO Sow6_2f VALUES (101.55); #-- should return SQLSTATE 22003 numeric value out of range -- error 1264 UPDATE Sow6_2f SET col1 = col1 * 50 WHERE col1 = 11; #-- should return SQLSTATE 22003 numeric value out of range -- error 1365 UPDATE Sow6_2f SET col1 = col1 / 0 WHERE col1 > 0; #-- should return SQLSTATE 22012 division by zero SELECT MOD(col1,0) FROM Sow6_2f; #-- should return SQLSTATE 22012 division by zero --replace_result sow Sow -- error 1366 INSERT INTO Sow6_2f VALUES ('a59b'); #-- should return SQLSTATE 22018 invalid character value for cast drop table Sow6_2f; # # bug#9501 # select 10.3330000000000/12.34500000; # # Bug #10404 # set sql_mode=''; select 0/0; # # bug #9546 # --disable_ps_protocol select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 as x; #enableview protocol after fix MDEV-28659 --disable_view_protocol select 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 + 1 as x; --enable_view_protocol --enable_ps_protocol # # Bug #10004 # select 0.190287977636363637 + 0.040372670 * 0 - 0; # # Bug #9527 # select -0.123 * 0; # # Bug #10232 # CREATE TABLE t1 (f1 DECIMAL (12,9), f2 DECIMAL(2,2)); INSERT INTO t1 VALUES (10.5, 0); UPDATE t1 SET f1 = 4.5; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 (f1 DECIMAL (64,20), f2 DECIMAL(2,2)); INSERT INTO t1 VALUES (9999999999999999999999999999999999, 0); SELECT * FROM t1; DROP TABLE t1; # # Bug #10599: problem with NULL # select abs(10/0); select abs(NULL); # # Bug #9894 (negative to unsigned column) # set @@sql_mode='traditional'; create table t1( d1 decimal(18) unsigned, d2 decimal(20) unsigned, d3 decimal (22) unsigned); --error 1264 insert into t1 values(1,-1,-1); drop table t1; create table t1 (col1 decimal(5,2), col2 numeric(5,2)); --error 1264 insert into t1 values (999.999,999.999); --error 1264 insert into t1 values (-999.999,-999.999); select * from t1; drop table t1; set sql_mode=''; # # Bug #8425 (insufficient precision of the division) # set @sav_dpi= @@div_precision_increment; set @@div_precision_increment=15; create table t1 (col1 int, col2 decimal(30,25), col3 numeric(30,25)); insert into t1 values (1,0.0123456789012345678912345,0.0123456789012345678912345); select col2/9999999999 from t1 where col1=1; select 9999999999/col2 from t1 where col1=1; select 77777777/7777777; drop table t1; set div_precision_increment= @sav_dpi; # # Bug #10896 (0.00 > -0.00) # create table t1 (a decimal(4,2)); insert into t1 values (0.00); select * from t1 where a > -0.00; select * from t1 where a = -0.00; drop table t1; # # Bug #11215: a problem with LONGLONG_MIN # create table t1 (col1 bigint default -9223372036854775808); insert into t1 values (default); select * from t1; drop table t1; # # Bug #10891 (converting to decimal crashes server) # #enable after fix MDEV-27871 --disable_view_protocol select cast('1.00000001335143196001808973960578441619873046875E-10' as decimal(30,15)); --enable_view_protocol # # Bug #11708 (conversion to decimal fails in decimal part) # select ln(14000) c1, convert(ln(14000),decimal(5,3)) c2, cast(ln(14000) as decimal(5,3)) c3; --error 1427 select convert(ln(14000),decimal(2,3)) c1; --error 1427 select cast(ln(14000) as decimal(2,3)) c1; # # Bug #8449 (Silent column changes) # --error 1426 create table t1 (sl decimal(70,30)); --error 1425 create table t1 (sl decimal(32,39)); --error 1426 create table t1 (sl decimal(67,38)); --error 1425 create table t1 (sl decimal(0,50)); --error 1427 create table t1 (sl decimal(0,30)); create table t1 (sl decimal(5, 5)); show create table t1; drop table t1; # Test limits create table t1 (sl decimal(65, 38)); show create table t1; drop table t1; # # Bug 11557 (DEFAULT values rounded improperly # create table t1 ( f1 decimal unsigned not null default 17.49, f2 decimal unsigned not null default 17.68, f3 decimal unsigned not null default 99.2, f4 decimal unsigned not null default 99.7, f5 decimal unsigned not null default 104.49, f6 decimal unsigned not null default 199.91, f7 decimal unsigned not null default 999.9, f8 decimal unsigned not null default 9999.99); insert into t1 (f1) values (1); select * from t1; drop table t1; # # Bug 12173 (show create table fails) # create table t1 ( f0 decimal (30,30) zerofill not null DEFAULT 0, f1 decimal (0,0) zerofill not null default 0); show create table t1; drop table t1; # # Bug 12938 (arithmetic loop's zero) # --disable_warnings drop procedure if exists wg2; --enable_warnings delimiter //; create procedure wg2() begin declare v int default 1; declare tdec decimal(5) default 0; while v <= 9 do set tdec =tdec * 10; select v, tdec; set v = v + 1; end while; end// call wg2()// delimiter ;// drop procedure wg2; # # Bug #12979 Stored procedures: crash if inout decimal parameter # (not a SP bug in fact) # select cast(@non_existing_user_var/2 as DECIMAL); # # Bug #13667 (Inconsistency for decimal(m,d) specification # --error 1427 create table t (d decimal(0,10)); # # Bug #14268 (bad FLOAT->DECIMAL conversion) # CREATE TABLE t1 ( my_float FLOAT, my_double DOUBLE, my_varchar VARCHAR(50), my_decimal DECIMAL(65,30) ); SHOW CREATE TABLE t1; let $max_power= 32; while ($max_power) { eval INSERT INTO t1 SET my_float = 1.175494345e-$max_power, my_double = 1.175494345e-$max_power, my_varchar = '1.175494345e-$max_power'; dec $max_power; } SELECT my_float, my_double, my_varchar FROM t1; # The following statement produces results with garbage past # the significant digits. Improving it is a part of the WL#3977. SELECT CAST(my_float AS DECIMAL(65,30)), my_float FROM t1; SELECT CAST(my_double AS DECIMAL(65,30)), my_double FROM t1; SELECT CAST(my_varchar AS DECIMAL(65,30)), my_varchar FROM t1; # We have to disable warnings here as the test in # Field_new_decimal::store(double): # if (nr2 != nr) # fails randomly depending on compiler options --disable_warnings UPDATE t1 SET my_decimal = my_float; # Expected result 0.000000000011754943372854760000 # On windows we get 0.000000000011754943372854770000 # use replace_result to correct it --replace_result 0.000000000011754943372854770000 0.000000000011754943372854760000 SELECT my_decimal, my_float FROM t1; UPDATE t1 SET my_decimal = my_double; SELECT my_decimal, my_double FROM t1; --enable_warnings UPDATE t1 SET my_decimal = my_varchar; SELECT my_decimal, my_varchar FROM t1; DROP TABLE t1; # # Bug #13573 (Wrong data inserted for too big values) # 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); --enable_ps_protocol insert into t1 values(1e100); select * from t1; drop table t1; # # Bug #18014: problem with 'alter table' # create table t1(a decimal(7,2)); insert into t1 values(123.12); select * from t1; alter table t1 modify a decimal(10,2); select * from t1; drop table t1; # # Bug#19667 group by a decimal expression yields wrong result # create table t1 (i int, j int); insert into t1 values (1,1), (1,2), (2,3), (2,4); select i, count(distinct j) from t1 group by i; select i+0.0 as i2, count(distinct j) from t1 group by i2; drop table t1; create table t1(f1 decimal(20,6)); insert into t1 values (CAST('10:11:12' AS date) + interval 14 microsecond); insert into t1 values (CAST('10:11:12' AS time)); select * from t1; drop table t1; # # Bug #8663 (cant use bigint as input to CAST) # select cast(19999999999999999999 as unsigned); # # Bug #24558: Increasing decimal column length causes data loss # create table t1(a decimal(18)); insert into t1 values(123456789012345678); alter table t1 modify column a decimal(19); select * from t1; drop table t1; # # Bug #27957 cast as decimal does not check overflow, also inconsistent with group, subselect # select cast(11.1234 as DECIMAL(3,2)); select * from (select cast(11.1234 as DECIMAL(3,2))) t; select cast(a as DECIMAL(3,2)) from (select 11.1233 as a UNION select 11.1234 UNION select 12.1234 ) t; select cast(a as DECIMAL(3,2)), count(*) from (select 11.1233 as a UNION select 11.1234 UNION select 12.1234 ) t group by 1; # # Bug #28361 Buffer overflow in DECIMAL code on Windows # create table t1 (s varchar(100)); insert into t1 values (0.00000000010000000000000000364321973154977415791655470655996396089904010295867919921875); drop table t1; # # Bug #27984 Long Decimal Maths produces truncated results # SELECT 1.000000000000 * 99.999999999998 / 100 a,1.000000000000 * (99.999999999998 / 100) b; # # Bug #29415: CAST AS DECIMAL(P,S) with too big precision/scale # SELECT CAST(1 AS decimal(65,10)); --error ER_TOO_BIG_PRECISION SELECT CAST(1 AS decimal(66,10)); SELECT CAST(1 AS decimal(65,38)); --error ER_TOO_BIG_SCALE SELECT CAST(1 AS decimal(65,39)); CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL); INSERT INTO t1 VALUES (3,30), (1,10), (2,10); SELECT a+CAST(1 AS decimal(65,30)) AS aa, SUM(b) FROM t1 GROUP BY aa; --error ER_TOO_BIG_SCALE SELECT a+CAST(1 AS decimal(65,49)) AS aa, SUM(b) FROM t1 GROUP BY aa; DROP TABLE t1; # # Bug #29417: assertion abort for a grouping query with decimal user variable # CREATE TABLE t1 (a int DEFAULT NULL, b int DEFAULT NULL); INSERT INTO t1 VALUES (3,30), (1,10), (2,10); SET @a= CAST(1 AS decimal); SELECT 1 FROM t1 GROUP BY @b := @a, @b; DROP TABLE t1; # # Bug #24907: unpredictable (display) precission, if input precission # increases # # As per 10.1.1. Overview of Numeric Types, type (new) DECIMAL has a # maxmimum precision of 30 places after the decimal point. Show that # temp field creation beyond that works and throws a truncation warning. # DECIMAL(37,36) should be adjusted to DECIMAL(31,30). CREATE TABLE t1 SELECT 0.1234567890123456789012345678901234567890123456789 AS f1; DESC t1; SELECT f1 FROM t1; DROP TABLE t1; # too many decimal places, AND too many digits altogether (90 = 45+45). # should preserve integers (65 = 45+20) CREATE TABLE t1 SELECT 123451234512345123451234512345123451234512345.678906789067890678906789067890678906789067890 AS f1; DESC t1; SELECT f1 FROM t1; DROP TABLE t1; # # Bug #36270: incorrect calculation result - works in 4.1 but not in 5.0 or 5.1 # #enable after fix MDEV-27871 --disable_view_protocol # show that if we need to truncate the scale of an operand, we pick the # right one (that is, we discard the least significant decimal places) select (1.20396873 * 0.89550000 * 0.68000000 * 1.08721696 * 0.99500000 * 1.01500000 * 1.01500000 * 0.99500000); --enable_view_protocol # # Bug #31616 div_precision_increment description looks wrong # create table t1 as select 5.05 / 0.014; show warnings; show create table t1; select * from t1; DROP TABLE t1; --echo # --echo # Bug#12563865 --echo # ROUNDED,TMP_BUF,DECIMAL_VALUE STACK CORRUPTION IN ALL VERSIONS >=5.0 --echo # let $nine_81= 999999999999999999999999999999999999999999999999999999999999999999999999999999999; #view protocol generates additional warning --disable_view_protocol eval SELECT substring(('M') FROM ($nine_81)) AS foo; --enable_view_protocol #enable after fix MDEV-28661 --disable_view_protocol eval SELECT min($nine_81) AS foo; eval SELECT multipolygonfromtext(('4294967294.1'),($nine_81)) AS foo; eval SELECT convert(($nine_81), decimal(30,30)) AS foo; eval SELECT bit_xor($nine_81) AS foo; eval SELECT -($nine_81) AS foo; eval SELECT date_sub(($nine_81), interval ((SELECT date_add((0x77500000), interval ('Oml') second))) day_minute) AS foo; eval SELECT truncate($nine_81, 28) AS foo; --enable_view_protocol --echo End of 5.0 tests # # Bug#16172 DECIMAL data type processed incorrectly # select cast(143.481 as decimal(4,1)); select cast(143.481 as decimal(4,0)); select cast(143.481 as decimal(2,1)); select cast(-3.4 as decimal(2,1)); select cast(99.6 as decimal(2,0)); select cast(-13.4 as decimal(2,1)); select cast(98.6 as decimal(2,0)); --echo # --echo # Bug #45262: Bad effects with CREATE TABLE and DECIMAL --echo # CREATE TABLE t1 SELECT .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS my_col; DESCRIBE t1; SELECT my_col FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT 1 + .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS my_col; DESCRIBE t1; SELECT my_col FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT 1 * .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS my_col; DESCRIBE t1; SELECT my_col FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT 1 / .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS my_col; DESCRIBE t1; SELECT my_col FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT 1 % .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS my_col; DESCRIBE t1; SELECT my_col FROM t1; DROP TABLE t1; --echo # --echo # Bug#45261: Crash, stored procedure + decimal --echo # --disable_warnings DROP TABLE IF EXISTS t1; --enable_warnings CREATE TABLE t1 SELECT /* 81 */ 100000000000000000000000000000000000000000000000000000000000000000000000000000001 AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 81 */ 100000000000000000000000000000000000000000000000000000000000000000000000000000001. AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 81 */ 100000000000000000000000000000000000000000000000000000000000000000000000000000001.1 /* 1 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; --enable_prepare_warnings CREATE TABLE t1 SELECT /* 82 */ 1000000000000000000000000000000000000000000000000000000000000000000000000000000001 AS c1; --disable_prepare_warnings DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 40 */ 1000000000000000000000000000000000000001.1000000000000000000000000000000000000001 /* 40 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 1 */ 1.10000000000000000000000000000000000000000000000000000000000000000000000000000001 /* 80 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 1 */ 1.100000000000000000000000000000000000000000000000000000000000000000000000000000001 /* 81 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT .100000000000000000000000000000000000000000000000000000000000000000000000000000001 /* 81 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 45 */ 123456789012345678901234567890123456789012345.123456789012345678901234567890123456789012345 /* 45 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 65 */ 12345678901234567890123456789012345678901234567890123456789012345.1 /* 1 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT /* 66 */ 123456789012345678901234567890123456789012345678901234567890123456.1 /* 1 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT .123456789012345678901234567890123456789012345678901234567890123456 /* 66 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 AS SELECT 123.1234567890123456789012345678901 /* 31 */ AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 SELECT 1.1 + CAST(1 AS DECIMAL(65,30)) AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; --echo # --echo # Test that the integer and decimal parts are properly calculated. --echo # CREATE TABLE t1 (a DECIMAL(30,30)); INSERT INTO t1 VALUES (0.1),(0.2),(0.3); CREATE TABLE t2 SELECT MIN(a + 0.0000000000000000000000000000001) AS c1 FROM t1; DESC t2; DROP TABLE t1,t2; CREATE TABLE t1 (a DECIMAL(30,30)); INSERT INTO t1 VALUES (0.1),(0.2),(0.3); CREATE TABLE t2 SELECT IFNULL(a + 0.00000000000000000000000000000000000000000000000001, NULL) AS c1 FROM t1; DESC t2; DROP TABLE t1,t2; CREATE TABLE t1 (a DECIMAL(30,30)); INSERT INTO t1 VALUES (0.1),(0.2),(0.3); CREATE TABLE t2 SELECT CASE a WHEN 0.1 THEN 0.0000000000000000000000000000000000000000000000000000000000000000001 END AS c1 FROM t1; DESC t2; DROP TABLE t1,t2; --echo # --echo # Test that variables get maximum precision. --echo # SET @decimal= 1.1; CREATE TABLE t1 SELECT @decimal AS c1; DESC t1; SELECT * FROM t1; DROP TABLE t1; --echo # --echo # Bug #45261 : Crash, stored procedure + decimal --echo # Original test by the reporter. --echo # --echo # should not crash CREATE TABLE t1 SELECT .123456789012345678901234567890123456789012345678901234567890123456 AS a; DROP TABLE t1; delimiter |; CREATE PROCEDURE test_proc() BEGIN # The las non critical CUSER definition is: # DECLARE mycursor CURSOR FOR SELECT 1 % # .12345678912345678912345678912345678912345678912345678912345678912 AS my_col; DECLARE mycursor CURSOR FOR SELECT 1 % .123456789123456789123456789123456789123456789123456789123456789123456789123456789 AS my_col; OPEN mycursor; CLOSE mycursor; END| delimiter ;| --echo # should not crash CALL test_proc(); DROP PROCEDURE test_proc; --echo # --echo # Bug #48370 Absolutely wrong calculations with GROUP BY and --echo # decimal fields when using IF --echo # CREATE TABLE currencies (id int, rate decimal(16,4), PRIMARY KEY (id), KEY (rate)); INSERT INTO currencies VALUES (11,0.7028); INSERT INTO currencies VALUES (1,1); CREATE TABLE payments ( id int, supplier_id int, status int, currency_id int, vat decimal(7,4), PRIMARY KEY (id), KEY currency_id (currency_id), KEY supplier_id (supplier_id) ); INSERT INTO payments (id,status,vat,supplier_id,currency_id) VALUES (3001,2,0.0000,344,11), (1,2,0.0000,1,1); CREATE TABLE sub_tasks ( id int, currency_id int, price decimal(16,4), discount decimal(10,4), payment_id int, PRIMARY KEY (id), KEY currency_id (currency_id), KEY payment_id (payment_id) ) ; INSERT INTO sub_tasks (id, price, discount, payment_id, currency_id) VALUES (52, 12.60, 0, 3001, 11), (56, 14.58, 0, 3001, 11); --echo # should return 1 and the same values in col 2 and 3 select STRAIGHT_JOIN (1 + PAY.vat) AS mult, SUM(ROUND((SUB.price - ROUND(ROUND(SUB.price, 2) * SUB.discount, 2)) * CUR.rate / CUR.rate, 2) ) v_net_with_discount, SUM(ROUND((SUB.price - ROUND(ROUND(SUB.price, 2) * SUB.discount, 1)) * CUR.rate / CUR.rate , 2) * (1 + PAY.vat) ) v_total from currencies CUR, payments PAY, sub_tasks SUB where SUB.payment_id = PAY.id and PAY.currency_id = CUR.id and PAY.id > 2 group by PAY.id + 1; DROP TABLE currencies, payments, sub_tasks; --echo # --echo # BUG#52171: distinct aggregates on unsigned decimal fields trigger assertions --echo # CREATE TABLE t1 (a DECIMAL(4,4) UNSIGNED); INSERT INTO t1 VALUES (0); SELECT AVG(DISTINCT a) FROM t1; SELECT SUM(DISTINCT a) FROM t1; DROP TABLE t1; --echo # --echo # Bug#55436: buffer overflow in debug binary of dbug_buff in --echo # Field_new_decimal::store_value --echo # # this threw memory warnings on Windows. Also make sure future changes # don't change these results, as per usual. SET SQL_MODE=''; CREATE TABLE t1(f1 DECIMAL(44,24)) ENGINE=MYISAM; INSERT INTO t1 SET f1 = -64878E-85; SELECT f1 FROM t1; DROP TABLE IF EXISTS t1; --echo End of 5.1 tests --echo # --echo # BUG#12911710 - VALGRIND FAILURE IN --echo # ROW-DEBUG:PERFSCHEMA.SOCKET_SUMMARY_BY_INSTANCE_FUNC --echo # CREATE TABLE t1(d1 DECIMAL(60,0) NOT NULL, d2 DECIMAL(60,0) NOT NULL); INSERT INTO t1 (d1, d2) VALUES(0.0, 0.0); SELECT d1 * d2 FROM t1; DROP TABLE t1; # # Test for Bug#18469276: MOD FOR SMALL DECIMALS FAILS # select 0.000000000000000000000000000000000000000000000000001 mod 1; # # incorrect result # select 0.0000000001 mod 1; select 0.01 mod 1; # # MDEV-17256 Decimal field multiplication bug # CREATE TABLE t1 ( `FLD1` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD2` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD3` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD4` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD5` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD6` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD7` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD8` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD9` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD10` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD11` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD12` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD13` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD14` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD15` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD16` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD17` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD18` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD19` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD20` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD21` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD22` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000, `FLD23` decimal(7,4) unsigned zerofill NOT NULL DEFAULT 001.0000 ); INSERT INTO t1 VALUES (001.0760,000.9500,001.0000,001.0000,001.0000, 001.0000,001.0000,001.0000,001.0000,001.0000,001.0000,000.5949,001.0194, 001.0000,001.0000,001.0000,001.0000,001.0000,001.0000,000.9220,001.1890,001.2130,327.2690); select FLD1*FLD2*FLD3*FLD4*FLD5*FLD6*FLD7*FLD8*FLD9*FLD10*FLD11*FLD12*FLD13*FLD14*FLD15*FLD16*FLD17*FLD18*FLD19*FLD20*FLD21*FLD22*FLD23 as calc1 from t1; select FLD23*FLD2*FLD1*FLD4*FLD5*FLD11*FLD12*FLD13*FLD3*FLD15*FLD16*FLD17*FLD18*FLD19*FLD20*FLD21*FLD22*FLD14*FLD6*FLD7*FLD8*FLD9*FLD10 as calc2 from t1; DROP TABLE t1; CREATE TABLE t1 AS SELECT 1.0 * 2.000; SHOW CREATE TABLE t1; DROP TABLE t1; --echo # --echo # MDEV-20495 Assertion `precision > 0' failed in decimal_bin_size upon CREATE .. SELECT with zerofilled decimal --echo # CREATE TABLE t1 (d DECIMAL(1,0) ZEROFILL); CREATE TABLE t2 AS SELECT 0 MOD d AS f FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1, t2; CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED); CREATE TABLE t2 AS SELECT 0 MOD d AS f FROM t1; SHOW CREATE TABLE t2; DROP TABLE IF EXISTS t1,t2; CREATE TABLE t1 (d DECIMAL(1,0) ZEROFILL); CREATE TABLE t2 AS SELECT CAST(0 AS UNSIGNED) MOD d AS f FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1, t2; CREATE TABLE t1 (d DECIMAL(1,0) UNSIGNED); CREATE TABLE t2 AS SELECT CAST(0 AS UNSIGNED) MOD d AS f FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1,t2; --echo # --echo # MDEV-20560 Assertion `precision > 0' failed in decimal_bin_size upon SELECT with MOD short unsigned decimal --echo # CREATE TABLE t1 (a DECIMAL(1,0) UNSIGNED); INSERT INTO t1 VALUES (1.0),(2.0); SELECT DISTINCT 1 MOD a FROM t1; CREATE TABLE t2 AS SELECT DISTINCT 1 MOD a AS f FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1, t2; CREATE TABLE t1 (a DECIMAL(1,0) UNSIGNED); INSERT INTO t1 VALUES (1.0),(2.0); SELECT DISTINCT 1 MOD a FROM t1; CREATE TABLE t2 AS SELECT DISTINCT CAST(1 AS UNSIGNED) MOD a AS f FROM t1; SHOW CREATE TABLE t2; DROP TABLE t1, t2; --echo # --echo # End of 5.5 tests --echo # --echo # --echo # MDEV-6950 Bad results with joins comparing DATE and INT/ENUM/VARCHAR columns --echo # CREATE TABLE t1 (a DATETIME PRIMARY KEY); INSERT INTO t1 VALUES ('1999-01-01 00:00:00'); CREATE TABLE t2 (a DECIMAL(30,1)); INSERT INTO t2 VALUES (19990101000000); INSERT INTO t2 VALUES (990101000000); SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a; SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a; ALTER TABLE t2 ADD PRIMARY KEY(a); SELECT t1.* FROM t1,t2 WHERE t1.a=t2.a; SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a; --echo # t2 should NOT be eliminated EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 ON t1.a=t2.a; DROP TABLE t1,t2; --echo # --echo # MDEV-6971 Bad results with joins comparing TIME and DOUBLE/DECIMAL columns --echo # CREATE TABLE t1 (a TIME(6) PRIMARY KEY); INSERT INTO t1 VALUES ('10:20:30'); CREATE TABLE t2 (a DECIMAL(30,10)); INSERT INTO t2 VALUES (102030),(102030.000000001); SELECT t1.* FROM t1 JOIN t2 USING(a); SELECT t1.* FROM t1 LEFT JOIN t2 USING(a); ALTER TABLE t2 ADD PRIMARY KEY(a); SELECT t1.* FROM t1 JOIN t2 USING(a); SELECT t1.* FROM t1 LEFT JOIN t2 USING(a); --echo # t2 should NOT be eliminated EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a); DROP TABLE t1,t2; --echo # --echo # End of 10.0 tests --echo # --echo # --echo # Start of 10.1 tests --echo # --echo # --echo # MDEV-8703 Wrong result for SELECT..WHERE LENGTH(decimal_10_1_column)!=3 AND decimal_10_1_column=1.10 --echo # # The constant scale is bigger than the field scale CREATE TABLE t1 (a DECIMAL(10,1)); INSERT INTO t1 VALUES (1.1),(1.2),(1.3); SELECT * FROM t1 WHERE LENGTH(a)!=3; SELECT * FROM t1 WHERE LENGTH(a)!=3 AND a=1.10; EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)!=3 AND a=1.10; --echo # Notice 1.1 instead of 1.10 in the final WHERE condition EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)!=rand() AND a=1.10; DROP TABLE t1; # The constant scale is equal to the field scale CREATE TABLE t1 (a DECIMAL(10,2)); INSERT INTO t1 VALUES (1.1),(1.2),(1.3); SELECT * FROM t1 WHERE LENGTH(a)!=4; SELECT * FROM t1 WHERE LENGTH(a)!=4 AND a=1.10; EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)!=4 AND a=1.10; --echo # Notice 1.10 in the final WHERE condition EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)!=rand() AND a=1.10; DROP TABLE t1; # The constant scale is smaller than the field scale CREATE TABLE t1 (a DECIMAL(10,3)); INSERT INTO t1 VALUES (1.1),(1.2),(1.3); SELECT * FROM t1 WHERE LENGTH(a)!=5; SELECT * FROM t1 WHERE LENGTH(a)!=5 AND a=1.10; EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)!=5 AND a=1.10; --echo # Notice 1.100 rather than 1.10 in the final WHERE condition EXPLAIN EXTENDED SELECT * FROM t1 WHERE LENGTH(a)!=rand() AND a=1.10; DROP TABLE t1; --echo # --echo # MDEV-8741 Equal field propagation leaves some remainders after simplifying WHERE zerofill_column=2010 AND zerofill_column>=2010 --echo # CREATE TABLE t1 (a DECIMAL(10,1) ZEROFILL); INSERT INTO t1 VALUES (2010),(2020); EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010.0 AND a>=2010.0; DROP TABLE t1; --echo # --echo # MDEV-8635 Redundant warnings on WHERE decimal_column='ax' --echo # CREATE TABLE t1 (a DECIMAL, KEY(a)) ENGINE=MyISAM; INSERT INTO t1 VALUES (1),(2),(3),(4),(5); # Make sure this does not produce any warnings EXPLAIN SELECT * FROM t1 WHERE a='ax' ORDER BY a; DROP TABLE t1; --echo # --echo # MDEV-8502 DECIMAL accepts out of range DEFAULT values --echo # --error ER_INVALID_DEFAULT CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT 10000); --error ER_INVALID_DEFAULT CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT 10000.0); --error ER_INVALID_DEFAULT CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT 10000e0); --error ER_INVALID_DEFAULT CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT '10000.0'); --error ER_INVALID_DEFAULT CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT '10000.1'); --echo # --echo # MDEV-10277 Redundant NOTE when inserting '0.00001 ' into a DECIMAL(2,1) column --echo # CREATE TABLE t1 (a DECIMAL(2,1)); INSERT INTO t1 VALUES ('0.00001 '); INSERT INTO t1 VALUES ('1e-10000 '); INSERT INTO t1 VALUES ('0.1 '); INSERT INTO t1 VALUES ('0.111 '); SELECT * FROM t1; DROP TABLE t1; CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT '1e-10000'); SHOW CREATE TABLE t1; DROP TABLE t1; CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT '0.1 '); SHOW CREATE TABLE t1; DROP TABLE t1; CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT '0.10001 '); SHOW CREATE TABLE t1; DROP TABLE t1; CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT '0.10001'); SHOW CREATE TABLE t1; DROP TABLE t1; CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT 0.10001); SHOW CREATE TABLE t1; DROP TABLE t1; CREATE TABLE t1 (a DECIMAL(2,1) DEFAULT 0.10001e0); SHOW CREATE TABLE t1; DROP TABLE t1; --echo # --echo # MDEV-23105 Cast number string with many leading zeros to decimal gives unexpected result --echo # SELECT CAST(0000000000000000000000000000000000000000000000000000000000000000000000000000000020.01 AS DECIMAL(15,2)) as val; SET sql_mode=''; CREATE TABLE t1 (a TEXT); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1)); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1,'.0')); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1,'.9')); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1,'.99')); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1,'.994')); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1,'.995')); INSERT INTO t1 VALUES (CONCAT(REPEAT('0',100),1,'.999')); CREATE TABLE t2 (a TEXT, d DECIMAL(15,2)); INSERT IGNORE INTO t2 (a,d) SELECT a, a FROM t1; INSERT IGNORE INTO t2 (a,d) SELECT CONCAT('-',a), CONCAT('-',a) FROM t1; SELECT d, a FROM t2 ORDER BY d,a; DROP TABLE t1, t2; SET sql_mode=DEFAULT; --echo # --echo # End of 10.1 tests --echo # --echo # --echo # Bug#18408499 UNSIGNED BIGINT HIGH VALUES --echo # WRONG NUMERICAL COMPARISON RESULTS --echo # CREATE TABLE t1(value DECIMAL(24,0) NOT NULL); INSERT INTO t1(value) VALUES('100000000000000000000001'), ('100000000000000000000002'), ('100000000000000000000003'); SELECT * FROM t1 WHERE value = '100000000000000000000002'; SELECT * FROM t1 WHERE '100000000000000000000002' = value; SELECT * FROM t1 WHERE value + 0 = '100000000000000000000002'; SELECT * FROM t1 WHERE value = 100000000000000000000002; SELECT * FROM t1 WHERE value + 0 = 100000000000000000000002; PREPARE stmt FROM 'SELECT * FROM t1 WHERE value = ?'; set @a="100000000000000000000002"; EXECUTE stmt using @a; set @a=100000000000000000000002; EXECUTE stmt using @a; DEALLOCATE PREPARE stmt; ALTER TABLE t1 ADD INDEX value (value); SELECT * FROM t1 WHERE value = '100000000000000000000002'; DROP TABLE t1; --echo # --echo # End of 10.1 tests --echo # --echo # --echo # Test CREATE .. SELECT --echo # create or replace table t1 as select 1.000000000000000000000000000000000 as a; show create table t1; create or replace table t1 as select 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 as a; show create table t1; create or replace table t1 as select 1.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 as a; show create table t1; drop table t1; --echo # --echo # MDEV-25317 Assertion `scale <= precision' failed in --echo # decimal_bin_size And Assertion `scale >= 0 && precision > 0 && scale <= precision' --echo # failed in decimal_bin_size_inline/decimal_bin_size. --echo # #enable after fix MDEV-27871 --disable_view_protocol SELECT AVG(DISTINCT 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001); --enable_view_protocol CREATE TABLE t1 AS SELECT NULL AS v1; SELECT 1 FROM t1 GROUP BY v1 ORDER BY AVG ( from_unixtime ( '' ) ) ; DROP TABLE t1; SELECT SUM(DISTINCT 0.000000000000000000000000000000000000001); CREATE TABLE t1 AS SELECT 1.000000000000000000000000000000000 AS a; ALTER TABLE t1 ADD COLUMN b INT; SELECT ROUND (a,b) AS c FROM t1 ORDER BY c; DROP TABLE t1; --echo # --echo # End of 10.2 tests --echo # --echo # --echo # Start of 10.4 tests --echo # --echo # --echo # MDEV-23032 FLOOR()/CEIL() incorrectly calculate the precision of a DECIMAL(M,D) column. --echo # DELIMITER $$; CREATE PROCEDURE p1(prec INT, scale INT, suffix VARCHAR(32)) BEGIN EXECUTE IMMEDIATE CONCAT('CREATE TABLE t1 (a decimal(',prec,',',scale,')',suffix,')'); INSERT IGNORE INTO t1 VALUES (-1e100), (+1e100); CREATE TABLE t2 AS SELECT a, FLOOR(a) AS fa, CEILING(a) AS ca, LENGTH(FLOOR(a)), LENGTH(CEILING(a)) FROM t1 ORDER BY a; SHOW CREATE TABLE t2; SELECT * FROM t2; DROP TABLE t2, t1; END; $$ DELIMITER ;$$ --vertical_results CALL p1(38,10,''); CALL p1(28,10,''); CALL p1(27,10,''); CALL p1(20,10,''); CALL p1(19,10,''); CALL p1(18,10,''); CALL p1(10,10,''); CALL p1(38,10,' UNSIGNED'); CALL p1(28,10,' UNSIGNED'); CALL p1(27,10,' UNSIGNED'); CALL p1(20,10,' UNSIGNED'); CALL p1(19,10,' UNSIGNED'); CALL p1(18,10,' UNSIGNED'); CALL p1(10,10,' UNSIGNED'); --horizontal_results DROP PROCEDURE p1; --echo # --echo # MDEV-23118 FORMAT(d1,dec) where dec=0/38 and d1 is DECIMAL(38,38) gives incorrect results --echo # --vertical_results CREATE OR REPLACE TABLE t1 (a DECIMAL(38,38)); INSERT INTO t1 VALUES (-0.9999999999999999999999999999999999999), (0.9999999999999999999999999999999999999); SELECT a, FORMAT(a,0), FORMAT(a,38) FROM t1; CREATE OR REPLACE TABLE t2 AS SELECT a, FORMAT(a,0), FORMAT(a,38) FROM t1; SELECT * FROM t2; SHOW CREATE TABLE t2; DROP TABLE t2,t1; --horizontal_results --echo # --echo # End of 10.4 tests --echo #