Commit c55de8d4 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result

When altering from DECIMAL to *INT UNIGNED or to BIT, go through val_decimal(),
to avoid truncation to the biggest possible signed integer
(0x7FFFFFFFFFFFFFFF / 9223372036854775807).
parent ec4fdd57
...@@ -830,3 +830,22 @@ def COALESCE(val, 1) 246 2 1 Y 32896 0 63 ...@@ -830,3 +830,22 @@ def COALESCE(val, 1) 246 2 1 Y 32896 0 63
COALESCE(val, 1) COALESCE(val, 1)
0 0
DROP TABLE t1; DROP TABLE t1;
#
# End of 10.1 tests
#
#
# Start of 10.2 tests
#
#
# MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result
#
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
ALTER TABLE t1 MODIFY a BIT(64);
SELECT a+0 FROM t1;
a+0
18446744073709551615
DROP TABLE IF EXISTS t1;
#
# End of 10.2 tests
#
...@@ -91,5 +91,18 @@ a ...@@ -91,5 +91,18 @@ a
10 10
DROP TABLE t1; DROP TABLE t1;
# #
# MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result
#
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
SELECT * FROM t1;
a
18446744073709551615
ALTER TABLE t1 MODIFY a BIGINT UNSIGNED;
SELECT * FROM t1;
a
18446744073709551615
DROP TABLE t1;
#
# End of 10.2 tests # End of 10.2 tests
# #
...@@ -458,3 +458,28 @@ DROP TABLE t2; ...@@ -458,3 +458,28 @@ DROP TABLE t2;
SELECT COALESCE(val, 1) FROM t1; SELECT COALESCE(val, 1) FROM t1;
--disable_metadata --disable_metadata
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # End of 10.1 tests
--echo #
--echo #
--echo # Start of 10.2 tests
--echo #
--echo #
--echo # MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result
--echo #
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
ALTER TABLE t1 MODIFY a BIT(64);
SELECT a+0 FROM t1;
DROP TABLE IF EXISTS t1;
--echo #
--echo # End of 10.2 tests
--echo #
...@@ -73,6 +73,18 @@ ALTER TABLE t1 MODIFY a INT; ...@@ -73,6 +73,18 @@ ALTER TABLE t1 MODIFY a INT;
SELECT * FROM t1; SELECT * FROM t1;
DROP TABLE t1; DROP TABLE t1;
--echo #
--echo # MDEV-9334 ALTER from DECIMAL to BIGINT UNSIGNED returns a wrong result
--echo #
CREATE TABLE t1 (a DECIMAL(30,0));
INSERT INTO t1 VALUES (CAST(0xFFFFFFFFFFFFFFFF AS UNSIGNED));
SELECT * FROM t1;
ALTER TABLE t1 MODIFY a BIGINT UNSIGNED;
SELECT * FROM t1;
DROP TABLE t1;
--echo # --echo #
--echo # End of 10.2 tests --echo # End of 10.2 tests
--echo # --echo #
...@@ -1636,6 +1636,8 @@ class Field_num :public Field { ...@@ -1636,6 +1636,8 @@ class Field_num :public Field {
bool eq_def(const Field *field) const; bool eq_def(const Field *field) const;
Copy_func *get_copy_func(const Field *from) const Copy_func *get_copy_func(const Field *from) const
{ {
if (unsigned_flag && from->cmp_type() == DECIMAL_RESULT)
return do_field_decimal;
return do_field_int; return do_field_int;
} }
int save_in_field(Field *to) int save_in_field(Field *to)
...@@ -3661,6 +3663,8 @@ class Field_bit :public Field { ...@@ -3661,6 +3663,8 @@ class Field_bit :public Field {
} }
Copy_func *get_copy_func(const Field *from) const Copy_func *get_copy_func(const Field *from) const
{ {
if (from->cmp_type() == DECIMAL_RESULT)
return do_field_decimal;
return do_field_int; return do_field_int;
} }
int save_in_field(Field *to) { return to->store(val_int(), true); } int save_in_field(Field *to) { return to->store(val_int(), true); }
......
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