Commit 5c1add3e authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9709 Unexpected modification of value and warning about out of range value upon ALTER

MDEV-4102 Limitation on DOUBLE or REAL length is ignored with INSERT .. SELECT
parent 75d8544c
...@@ -638,3 +638,90 @@ DROP TABLE t1; ...@@ -638,3 +638,90 @@ DROP TABLE t1;
# #
# End of 10.1 tests # End of 10.1 tests
# #
#
# Start of 10.2 tests
#
#
# MDEV-4102 Limitation on DOUBLE or REAL length is ignored with INSERT .. SELECT
#
CREATE TABLE t1 (d1 DOUBLE(5,2), d2 DOUBLE(10,2));
INSERT INTO t1 VALUES (10000000.55, 10000000.55);
Warnings:
Warning 1264 Out of range value for column 'd1' at row 1
INSERT INTO t1 SELECT d2, d2 FROM t1;
Warnings:
Warning 1264 Out of range value for column 'd1' at row 1
SELECT * FROM t1;
d1 d2
999.99 10000000.55
999.99 10000000.55
DROP TABLE t1;
#
# MDEV-9709 Unexpected modification of value and warning about out of range value upon ALTER
#
CREATE TABLE t1 (
f FLOAT,
d10_10 DOUBLE PRECISION (10,10),
d53_10 DOUBLE(53,10)
);
INSERT INTO t1 (f,d10_10,d53_10) VALUES (
-9999999999999999999999999999999999999999999.9999999999,
-9999999999999999999999999999999999999999999.9999999999,
-9999999999999999999999999999999999999999999.9999999999
);
Warnings:
Warning 1264 Out of range value for column 'f' at row 1
Warning 1264 Out of range value for column 'd10_10' at row 1
SELECT * FROM t1;
f -3.40282e38
d10_10 -0.9999999999
d53_10 -10000000000000000000000000000000000000000000.0000000000
INSERT INTO t1 (f,d10_10,d53_10) SELECT d53_10, d53_10, d53_10 FROM t1;
Warnings:
Level Warning
Code 1264
Message Out of range value for column 'f' at row 1
Level Warning
Code 1264
Message Out of range value for column 'd10_10' at row 1
SELECT * FROM t1;
f -3.40282e38
d10_10 -0.9999999999
d53_10 -10000000000000000000000000000000000000000000.0000000000
f -3.40282e38
d10_10 -0.9999999999
d53_10 -10000000000000000000000000000000000000000000.0000000000
ALTER TABLE t1 ADD COLUMN i INT;
SELECT * FROM t1;
f -3.40282e38
d10_10 -0.9999999999
d53_10 -10000000000000000000000000000000000000000000.0000000000
i NULL
f -3.40282e38
d10_10 -0.9999999999
d53_10 -10000000000000000000000000000000000000000000.0000000000
i NULL
DROP TABLE t1;
CREATE TABLE t1 (d10_10 DOUBLE (10,10));
CREATE TABLE t2 (d53_10 DOUBLE (53,10));
INSERT INTO t2 VALUES (-9999999999999999999999999999999999999999999.9999999999);
INSERT INTO t1 (d10_10) SELECT d53_10 FROM t2;
Warnings:
Warning 1264 Out of range value for column 'd10_10' at row 1
SELECT * FROM t1;
d10_10
-0.9999999999
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 INTO t1 (d2_2) SELECT d4_2 FROM t2;
Warnings:
Warning 1264 Out of range value for column 'd2_2' at row 1
SELECT * FROM t1;
d2_2
0.99
DROP TABLE t1,t2;
#
# End of 10.2 tests
#
...@@ -458,3 +458,57 @@ DROP TABLE t1; ...@@ -458,3 +458,57 @@ DROP TABLE t1;
--echo # --echo #
--echo # End of 10.1 tests --echo # End of 10.1 tests
--echo # --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 INTO t1 VALUES (10000000.55, 10000000.55);
INSERT 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 INTO t1 (f,d10_10,d53_10) VALUES (
-9999999999999999999999999999999999999999999.9999999999,
-9999999999999999999999999999999999999999999.9999999999,
-9999999999999999999999999999999999999999999.9999999999
);
--vertical_results
SELECT * FROM t1;
INSERT 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 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 INTO t1 (d2_2) SELECT d4_2 FROM t2;
SELECT * FROM t1;
DROP TABLE t1,t2;
--echo #
--echo # End of 10.2 tests
--echo #
...@@ -1707,6 +1707,16 @@ class Field_real :public Field_num { ...@@ -1707,6 +1707,16 @@ class Field_real :public Field_num {
return do_field_real; return do_field_real;
} }
int save_in_field(Field *to) { return to->store(val_real()); } int save_in_field(Field *to) { return to->store(val_real()); }
bool memcpy_field_possible(const Field *from) const
{
/*
Cannot do memcpy from a longer field to a shorter field,
e.g. a DOUBLE(53,10) into a DOUBLE(10,10).
But it should be OK the other way around.
*/
return Field_num::memcpy_field_possible(from) &&
field_length >= from->field_length;
}
int store_decimal(const my_decimal *); int store_decimal(const my_decimal *);
int store_time_dec(MYSQL_TIME *ltime, uint dec); int store_time_dec(MYSQL_TIME *ltime, uint dec);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment