Commit 7f3e2dc4 authored by hf@deer.(none)'s avatar hf@deer.(none)

Fix for bug #13372 (decimal union)

parent a5feed98
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2, t3;
SET SQL_WARNINGS=1; SET SQL_WARNINGS=1;
CREATE TABLE t1 ( CREATE TABLE t1 (
id int(11) NOT NULL auto_increment, id int(11) NOT NULL auto_increment,
...@@ -655,3 +655,18 @@ select * from t1; ...@@ -655,3 +655,18 @@ select * from t1;
a b a b
123.12345 123.1 123.12345 123.1
drop table t1; drop table t1;
create table t1 (d decimal(10,1));
create table t2 (d decimal(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;
d
1.234567800
100000000.000000000
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`d` decimal(18,9) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3;
...@@ -235,3 +235,18 @@ select * from t1 where reckey=1.09E2; ...@@ -235,3 +235,18 @@ select * from t1 where reckey=1.09E2;
reckey recdesc reckey recdesc
109 Has 109 as key 109 Has 109 as key
drop table t1; drop table t1;
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;
d
1.234567800
100000000.000000000
show create table t3;
Table Create Table
t3 CREATE TABLE `t3` (
`d` double(61,9) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1, t2, t3;
# bug in decimal() with negative numbers by kaido@tradenet.ee # bug in decimal() with negative numbers by kaido@tradenet.ee
--disable_warnings --disable_warnings
DROP TABLE IF EXISTS t1; DROP TABLE IF EXISTS t1, t2, t3;
--enable_warnings --enable_warnings
SET SQL_WARNINGS=1; SET SQL_WARNINGS=1;
...@@ -276,4 +276,16 @@ update t1 set b=a; ...@@ -276,4 +276,16 @@ update t1 set b=a;
select * from t1; select * from t1;
drop table t1; drop table t1;
#
# Bug #13372 (decimal union)
#
create table t1 (d decimal(10,1));
create table t2 (d decimal(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;
# End of 4.1 tests # End of 4.1 tests
...@@ -149,4 +149,17 @@ select * from t1 where reckey=109; ...@@ -149,4 +149,17 @@ select * from t1 where reckey=109;
select * from t1 where reckey=1.09E2; select * from t1 where reckey=1.09E2;
drop table t1; 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;
# End of 4.1 tests # End of 4.1 tests
...@@ -3205,9 +3205,14 @@ enum_field_types Item_type_holder::get_real_type(Item *item) ...@@ -3205,9 +3205,14 @@ enum_field_types Item_type_holder::get_real_type(Item *item)
bool Item_type_holder::join_types(THD *thd, Item *item) bool Item_type_holder::join_types(THD *thd, Item *item)
{ {
uint max_length_orig= max_length;
uint decimals_orig= decimals;
max_length= max(max_length, display_length(item)); max_length= max(max_length, display_length(item));
decimals= max(decimals, item->decimals);
fld_type= Field::field_type_merge(fld_type, get_real_type(item)); fld_type= Field::field_type_merge(fld_type, get_real_type(item));
if (Field::result_merge_type(fld_type) == STRING_RESULT) switch (Field::result_merge_type(fld_type))
{
case STRING_RESULT:
{ {
const char *old_cs, *old_derivation; const char *old_cs, *old_derivation;
old_cs= collation.collation->name; old_cs= collation.collation->name;
...@@ -3221,8 +3226,23 @@ bool Item_type_holder::join_types(THD *thd, Item *item) ...@@ -3221,8 +3226,23 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
"UNION"); "UNION");
return TRUE; return TRUE;
} }
break;
} }
decimals= max(decimals, item->decimals); case REAL_RESULT:
{
decimals= max(decimals, item->decimals);
if (decimals != NOT_FIXED_DEC)
{
int delta1= max_length_orig - decimals_orig;
int delta2= item->max_length - item->decimals;
max_length= max(delta1, delta2) + decimals;
}
else
max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
break;
}
default:;
};
maybe_null|= item->maybe_null; maybe_null|= item->maybe_null;
get_full_info(item); get_full_info(item);
return FALSE; return FALSE;
......
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