summaryrefslogtreecommitdiff
path: root/mysql-test/main/type_float.test
diff options
context:
space:
mode:
authorMichael Widenius <monty@mariadb.org>2018-03-09 14:05:35 +0200
committerMonty <monty@mariadb.org>2018-03-29 13:59:44 +0300
commita7abddeffa6a760ce948c2dfb007cdf3f1a369d5 (patch)
tree70eb743fa965a17380bbc0ac88ae79ca1075b896 /mysql-test/main/type_float.test
parentab1941266c59a19703a74b5593cf3f508a5752d7 (diff)
downloadmariadb-git-a7abddeffa6a760ce948c2dfb007cdf3f1a369d5.tar.gz
Create 'main' test directory and move 't' and 'r' there
Diffstat (limited to 'mysql-test/main/type_float.test')
-rw-r--r--mysql-test/main/type_float.test553
1 files changed, 553 insertions, 0 deletions
diff --git a/mysql-test/main/type_float.test b/mysql-test/main/type_float.test
new file mode 100644
index 00000000000..2d7c4428507
--- /dev/null
+++ b/mysql-test/main/type_float.test
@@ -0,0 +1,553 @@
+# Description
+# -----------
+# Numeric floating point.
+
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+
+SELECT 10,10.0,10.,.1e+2,100.0e-1;
+SELECT 6e-16, -6e-16, --6e-16, -6e-16+1.000000;
+SELECT 1e1,1.e1,1.0e1,1e+1,1.e+1,1.0e+1,1e-1,1.e-1,1.0e-1;
+SELECT 0.001e+1,0.001e-1, -0.001e+01,-0.001e-01;
+SELECT 123.23E+02,-123.23E-02,"123.23E+02"+0.0,"-123.23E-02"+0.0;
+SELECT 2147483647E+02,21474836.47E+06;
+
+create table t1 (f1 float(24),f2 float(52));
+# We mask out Privileges column because it differs for embedded server
+--replace_column 8 #
+show full columns from t1;
+insert into t1 values(10,10),(1e+5,1e+5),(1234567890,1234567890),(1e+10,1e+10),(1e+15,1e+15),(1e+20,1e+20),(1e+50,1e+50),(1e+150,1e+150);
+insert into t1 values(-10,-10),(1e-5,1e-5),(1e-10,1e-10),(1e-15,1e-15),(1e-20,1e-20),(1e-50,1e-50),(1e-150,1e-150);
+select * from t1;
+drop table t1;
+
+create table t1 (datum double);
+insert into t1 values (0.5),(1.0),(1.5),(2.0),(2.5);
+select * from t1;
+select * from t1 where datum < 1.5;
+select * from t1 where datum > 1.5;
+select * from t1 where datum = 1.5;
+drop table t1;
+
+create table t1 (a decimal(7,3) not null, key (a));
+insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1");
+select a from t1 order by a;
+select min(a) from t1;
+drop table t1;
+
+#
+# BUG#3612, BUG#4393, BUG#4356, BUG#4394
+#
+
+create table t1 (c1 double, c2 varchar(20));
+insert t1 values (121,"16");
+select c1 + c1 * (c2 / 100) as col from t1;
+create table t2 select c1 + c1 * (c2 / 100) as col1, round(c1, 5) as col2, round(c1, 35) as col3, sqrt(c1*1e-15) col4 from t1;
+# Floats are a bit different in PS
+--disable_ps_protocol
+select * from t2;
+--enable_ps_protocol
+show create table t2;
+drop table t1,t2;
+
+# Bug #1022: When a table contains a 'float' field,
+# and one of the functions MAX, MIN, or AVG is used on that field,
+# the system crashes.
+
+create table t1 (a float);
+insert into t1 values (1);
+select max(a),min(a),avg(a) from t1;
+drop table t1;
+
+#
+# FLOAT/DOUBLE/DECIMAL handling
+#
+
+create table t1 (f float, f2 float(24), f3 float(6,2), d double, d2 float(53), d3 double(10,3), de decimal, de2 decimal(6), de3 decimal(5,2), n numeric, n2 numeric(8), n3 numeric(7,6));
+# We mask out Privileges column because it differs for embedded server
+--replace_column 8 #
+show full columns from t1;
+drop table t1;
+
+create table t1 (a decimal(7,3) not null, key (a));
+insert into t1 values ("0"),("-0.00"),("-0.01"),("-0.002"),("1");
+select a from t1 order by a;
+select min(a) from t1;
+drop table t1;
+
+--error 1425
+create table t1 (a float(200,100), b double(200,100));
+
+#
+# float in a char(1) field
+#
+create table t1 (c20 char);
+insert ignore into t1 values (5000.0);
+insert ignore into t1 values (0.5e4);
+drop table t1;
+
+# Errors
+
+--error 1063
+create table t1 (f float(54)); # Should give an error
+--disable_warnings
+drop table if exists t1;
+--enable_warnings
+
+# Don't allow 'double unsigned' to be set to a negative value (Bug #7700)
+create table t1 (d1 double, d2 double unsigned);
+insert into t1 set d1 = -1.0;
+update ignore t1 set d2 = d1;
+select * from t1;
+drop table t1;
+
+# Ensure that maximum values as the result of number of decimals
+# being specified in table schema are enforced (Bug #7361)
+create table t1 (f float(4,3));
+insert ignore into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11");
+select * from t1;
+drop table if exists t1;
+create table t1 (f double(4,3));
+insert ignore into t1 values (-11.0),(-11),("-11"),(11.0),(11),("11");
+select * from t1;
+drop table if exists t1;
+
+# Check conversion of floats to character field (Bug #7774)
+create table t1 (c char(20));
+insert into t1 values (5e-28);
+select * from t1;
+drop table t1;
+create table t1 (c char(6));
+insert into t1 values (2e5),(2e6),(2e-4),(2e-5);
+select * from t1;
+drop table t1;
+
+#
+# Test of comparison of integer with float-in-range (Bug #7840)
+# This is needed because some ODBC applications (like Foxpro) uses
+# floats for everything.
+#
+
+CREATE TABLE t1 (
+ reckey int unsigned NOT NULL,
+ recdesc varchar(50) NOT NULL,
+ PRIMARY KEY (reckey)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+
+INSERT INTO t1 VALUES (108, 'Has 108 as key');
+INSERT INTO t1 VALUES (109, 'Has 109 as key');
+select * from t1 where reckey=108;
+select * from t1 where reckey=1.08E2;
+select * from t1 where reckey=109;
+select * from t1 where reckey=1.09E2;
+drop table t1;
+
+#
+# Bug #13372 (decimal union)
+#
+create table t1 (d double(10,1));
+create table t2 (d double(10,9));
+insert into t1 values ("100000000.0");
+insert into t2 values ("1.23456780");
+create table t3 select * from t2 union select * from t1;
+select * from t3;
+show create table t3;
+drop table t1, t2, t3;
+
+
+#
+# Bug #9855 (inconsistent column type for create select
+#
+create table t1 select 105213674794682365.00 + 0.0 x;
+show warnings;
+desc t1;
+drop table t1;
+
+create table t1 select 0.0 x;
+desc t1;
+create table t2 select 105213674794682365.00 y;
+desc t2;
+create table t3 select x+y a from t1,t2;
+show warnings;
+desc t3;
+drop table t1,t2,t3;
+
+#
+# Bug #22129: A small double precision number becomes zero
+#
+# check if underflows are detected correctly
+select 1e-308, 1.00000001e-300, 100000000e-300;
+
+# check if overflows are detected correctly
+select 10e307;
+
+#
+# Bug #19690: ORDER BY eliminates rows from the result
+#
+create table t1(a int, b double(8, 2));
+insert into t1 values
+(1, 28.50), (1, 121.85), (1, 157.23), (1, 1351.00), (1, -1965.35), (1, 81.75),
+(1, 217.08), (1, 7.94), (4, 96.07), (4, 6404.65), (4, -6500.72), (2, 100.00),
+(5, 5.00), (5, -2104.80), (5, 2033.80), (5, 0.07), (5, 65.93),
+(3, -4986.24), (3, 5.00), (3, 4857.34), (3, 123.74), (3, 0.16),
+(6, -1695.31), (6, 1003.77), (6, 499.72), (6, 191.82);
+explain select sum(b) s from t1 group by a;
+select sum(b) s from t1 group by a;
+select sum(b) s from t1 group by a having s <> 0;
+select sum(b) s from t1 group by a having s <> 0 order by s;
+select sum(b) s from t1 group by a having s <=> 0;
+select sum(b) s from t1 group by a having s <=> 0 order by s;
+alter table t1 add key (a, b);
+explain select sum(b) s from t1 group by a;
+select sum(b) s from t1 group by a;
+select sum(b) s from t1 group by a having s <> 0;
+select sum(b) s from t1 group by a having s <> 0 order by s;
+select sum(b) s from t1 group by a having s <=> 0;
+select sum(b) s from t1 group by a having s <=> 0 order by s;
+drop table t1;
+
+--echo End of 4.1 tests
+
+#
+# bug #12694 (float(m,d) specifications)
+#
+
+--error 1427
+create table t1 (s1 float(0,2));
+--error 1427
+create table t1 (s1 float(1,2));
+
+#
+# MySQL Bugs: #11589: mysqltest --ps-protocol, strange output, float/double/real with zerofill
+#
+
+CREATE TABLE t1 (
+ f1 real zerofill,
+ f2 double zerofill,
+ f3 float zerofill);
+INSERT INTO t1 VALUES ( 0.314152e+1, 0.314152e+1, 0.314152e+1);
+
+let $my_stmt= select f1, f2, f3 FROM t1;
+eval PREPARE stmt1 FROM '$my_stmt';
+select f1, f2, f3 FROM t1;
+eval $my_stmt;
+EXECUTE stmt1;
+
+DROP TABLE t1;
+# Bug #28121 "INSERT or UPDATE into DOUBLE(200,0) field being truncated to 31 digits"
+#
+
+create table t1 (f1 double(200, 0));
+insert into t1 values (1e199), (-1e199);
+insert into t1 values (1e200), (-1e200);
+insert ignore into t1 values (2e200), (-2e200);
+select f1 + 0e0 from t1;
+drop table t1;
+
+create table t1 (f1 float(30, 0));
+insert into t1 values (1e29), (-1e29);
+insert into t1 values (1e30), (-1e30);
+insert ignore into t1 values (2e30), (-2e30);
+select f1 + 0e0 from t1;
+drop table t1;
+
+#
+# Bug #12860 "Difference in zero padding of exponent between Unix and Windows"
+#
+
+create table t1 (c char(6));
+insert into t1 values (2e6),(2e-5);
+select * from t1;
+drop table t1;
+
+#
+# Bug #21497 "DOUBLE truncated to unusable value"
+#
+
+CREATE TABLE d1 (d DOUBLE);
+INSERT INTO d1 VALUES (1.7976931348623157E+308);
+SELECT * FROM d1;
+--error ER_ILLEGAL_VALUE_FOR_TYPE
+INSERT INTO d1 VALUES (1.79769313486232e+308);
+SELECT * FROM d1;
+DROP TABLE d1;
+
+#
+# Bug #26788 "mysqld (debug) aborts when inserting specific numbers into char
+# fields"
+#
+
+create table t1 (a char(20));
+insert into t1 values (1.225e-05);
+select a+0 from t1;
+drop table t1;
+
+#
+# Bug #27483: Casting 'scientific notation type' to 'unsigned bigint' fails on
+# windows.
+#
+
+create table t1(d double, u bigint unsigned);
+
+insert into t1(d) values (9.22337203685479e18),
+ (1.84e19);
+
+update t1 set u = d;
+select u from t1;
+
+drop table t1;
+
+#
+# Bug #21205: Different number of digits for float/doble/real in --ps-protocol
+#
+
+CREATE TABLE t1 (f1 DOUBLE);
+INSERT INTO t1 VALUES(-1.79769313486231e+308);
+SELECT f1 FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # Bug#12406055 BUFFER OVERFLOW OF VARIABLE 'BUFF' IN STRING::SET_REAL
+--echo #
+
+--echo # Ignoring output from misc. float operations
+--disable_result_log
+
+let $nine_65=
+99999999999999999999999999999999999999999999999999999999999999999;
+
+select format(-1.7976931348623157E+307,256) as foo;
+select least(-1.1111111111111111111111111,
+ - group_concat(1.7976931348623157E+308)) as foo;
+eval select concat((truncate((-1.7976931348623157E+307),(0x1e))),
+ ($nine_65)) into @a;
+--enable_result_log
+
+--echo End of 5.0 tests
+
+--echo #
+--echo # Bug#12368853 FORMAT() CRASHES WITH LARGE NUMBERS AFTER TRUNCATE...
+--echo #
+
+select format(truncate('1.7976931348623157E+308',-12),1,'fr_BE') as foo;
+
+--echo #
+--echo # Bug #13500371 63704: CONVERSION OF '1.' TO A NUMBER GIVES ERROR 1265
+--echo # (WARN_DATA_TRUNCATED)
+--echo #
+
+CREATE TABLE t1 (f FLOAT);
+INSERT INTO t1 VALUES ('1.');
+INSERT IGNORE INTO t1 VALUES ('2.0.');
+INSERT IGNORE INTO t1 VALUES ('.');
+SELECT * FROM t1 ORDER BY f;
+DROP TABLE t1;
+
+
+--echo #
+--echo # Start of 10.0 tests
+--echo #
+
+--echo #
+--echo # MDEV-6950 Bad results with joins comparing DATE/DATETIME and INT/DECIMAL/DOUBLE/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 DOUBLE);
+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 DOUBLE);
+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 elimitated
+EXPLAIN SELECT t1.* FROM t1 LEFT JOIN t2 USING(a);
+DROP TABLE t1,t2;
+
+--echo #
+--echo # End of 10.0 tests
+--echo #
+
+
+--echo #
+--echo # MDEV-8704 Wrong result for SELECT..WHERE LENGTH(double_column)!=6 AND double_column=100e0
+--echo #
+
+# The original test case from the bug report
+CREATE TABLE t1 (a DOUBLE(9,2));
+INSERT INTO t1 VALUES (100),(110);
+SELECT * FROM t1 WHERE LENGTH(a)!=6;
+SELECT * FROM t1 WHERE LENGTH(a)!=6 AND a=100e0;
+DROP TABLE t1;
+
+# DOUBLE with no specific precision
+CREATE TABLE t1 (a DOUBLE);
+INSERT INTO t1 VALUES (100),(110);
+SELECT * FROM t1 WHERE LENGTH(a)!=6;
+SELECT * FROM t1 WHERE LENGTH(a)!=6 AND a=100e0;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE LENGTH(a)!=6 AND a=100e0;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE LENGTH(a)!=RAND() AND a=100e0;
+DROP TABLE t1;
+
+# The constant scale is bigger than the field scale
+CREATE TABLE t1 (a DOUBLE(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.10e0;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE LENGTH(a)!=3 AND a=1.10e0;
+--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.10e0;
+DROP TABLE t1;
+
+# The constant scale is equal to the field scale
+CREATE TABLE t1 (a DOUBLE(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.10e0;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE LENGTH(a)!=4 AND a=1.10e0;
+--echo # Notice 1.10 in the final WHERE condition
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE LENGTH(a)!=RAND() AND a=1.10e0;
+DROP TABLE t1;
+
+# The constant scale is smaller than the field scale
+CREATE TABLE t1 (a DOUBLE(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.10e0;
+EXPLAIN EXTENDED
+SELECT * FROM t1 WHERE LENGTH(a)!=5 AND a=1.10e0;
+--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.10e0;
+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 DOUBLE ZEROFILL);
+INSERT INTO t1 VALUES (2010),(2020);
+EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=2010e0 AND a>=2010e0;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.1 tests
+--echo #
+
+--echo #
+--echo # Start of 10.2 tests
+--echo #
+
+--echo #
+--echo # MDEV-4102 Limitation on DOUBLE or REAL length is ignored with INSERT .. SELECT
+--echo #
+CREATE TABLE t1 (d1 DOUBLE(5,2), d2 DOUBLE(10,2));
+INSERT IGNORE INTO t1 VALUES (10000000.55, 10000000.55);
+INSERT IGNORE INTO t1 SELECT d2, d2 FROM t1;
+SELECT * FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # MDEV-9709 Unexpected modification of value and warning about out of range value upon ALTER
+--echo #
+
+CREATE TABLE t1 (
+ f FLOAT,
+ d10_10 DOUBLE PRECISION (10,10),
+ d53_10 DOUBLE(53,10)
+);
+INSERT IGNORE INTO t1 (f,d10_10,d53_10) VALUES (
+ -9999999999999999999999999999999999999999999.9999999999,
+ -9999999999999999999999999999999999999999999.9999999999,
+ -9999999999999999999999999999999999999999999.9999999999
+);
+--vertical_results
+SELECT * FROM t1;
+INSERT IGNORE INTO t1 (f,d10_10,d53_10) SELECT d53_10, d53_10, d53_10 FROM t1;
+SELECT * FROM t1;
+ALTER TABLE t1 ADD COLUMN i INT;
+SELECT * FROM t1;
+DROP TABLE t1;
+--horizontal_results
+
+CREATE TABLE t1 (d10_10 DOUBLE (10,10));
+CREATE TABLE t2 (d53_10 DOUBLE (53,10));
+INSERT INTO t2 VALUES (-9999999999999999999999999999999999999999999.9999999999);
+INSERT IGNORE INTO t1 (d10_10) SELECT d53_10 FROM t2;
+SELECT * FROM t1;
+DROP TABLE t1,t2;
+
+CREATE TABLE t1 (d2_2 FLOAT (2,2));
+CREATE TABLE t2 (d4_2 FLOAT (4,2));
+INSERT INTO t2 VALUES (99.99);
+INSERT IGNORE INTO t1 (d2_2) SELECT d4_2 FROM t2;
+SELECT * FROM t1;
+DROP TABLE t1,t2;
+
+--echo #
+--echo # Test of using wrong scale
+--echo #
+
+create or replace table t1 (a double(40,30));
+--error ER_TOO_BIG_SCALE 1425
+create or replace table t1 (a double(40,31));
+create or replace table t1 as select 1.01e1;
+show create table t1;
+create or replace table t1 as select truncate(10.000000000001e1, 30) as t;
+show create table t1;
+create or replace table t1 as select truncate(10.000000000001e1, 31) as t;
+show create table t1;
+create or replace table t1 as select truncate(10.000000000001e1, 39) as t;
+show create table t1;
+create or replace table t1 as select truncate(10.000000000001e1, 51) as t;
+show create table t1;
+create or replace table t1 as select truncate(10.000000000001e1, 20)/2 as t;
+show create table t1;
+create or replace table t1 as select truncate(10.000000000001e1, 28)/2 as t;
+show create table t1;
+
+drop table if exists t1;
+
+--echo #
+--echo # MDEV-11586 UNION of FLOAT type results in erroneous precision
+--echo #
+
+CREATE TABLE t1 (f FLOAT);
+INSERT INTO t1 VALUES (1.1);
+SELECT f FROM t1 UNION SELECT 1;
+SELECT 1 UNION SELECT f FROM t1;
+SELECT f FROM t1 UNION SELECT 2147483647;
+SELECT 2147483647 UNION SELECT f FROM t1;
+SELECT CASE WHEN 0 THEN (SELECT f FROM t1) ELSE 2147483647 END AS c1,
+ CASE WHEN 1 THEN 2147483647 ELSE (SELECT f FROM t1) END AS c2;
+DROP TABLE t1;
+
+
+--echo #
+--echo # End of 10.2 tests
+--echo #