Do not try use fields examples is expression and fiend used or SET/ENUM field used in types merging procedure (BUG#5618)
mysql-test/r/union.result: merging ENUM and SET fields in one UNION mysql-test/t/union.test: merging ENUM and SET fields in one UNION
This commit is contained in:
parent
ca65afeb72
commit
f177c76fb2
@ -996,3 +996,40 @@ PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
|
|||||||
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1);
|
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1);
|
||||||
ID1 ID2 DATA1 DATA2 DATA3 ID DATA1
|
ID1 ID2 DATA1 DATA2 DATA3 ID DATA1
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
create table t1 (a ENUM('Yes', 'No') NOT NULL);
|
||||||
|
create table t2 (a ENUM('aaa', 'bbb') NOT NULL);
|
||||||
|
insert into t1 values ('No');
|
||||||
|
insert into t2 values ('bbb');
|
||||||
|
create table t3 (a SET('Yes', 'No') NOT NULL);
|
||||||
|
create table t4 (a SET('aaa', 'bbb') NOT NULL);
|
||||||
|
insert into t3 values (1);
|
||||||
|
insert into t4 values (3);
|
||||||
|
select "1" as a union select a from t1;
|
||||||
|
a
|
||||||
|
1
|
||||||
|
No
|
||||||
|
select a as a from t1 union select "1";
|
||||||
|
a
|
||||||
|
No
|
||||||
|
1
|
||||||
|
select a as a from t2 union select a from t1;
|
||||||
|
a
|
||||||
|
bbb
|
||||||
|
No
|
||||||
|
select "1" as a union select a from t3;
|
||||||
|
a
|
||||||
|
1
|
||||||
|
Yes
|
||||||
|
select a as a from t3 union select "1";
|
||||||
|
a
|
||||||
|
Yes
|
||||||
|
1
|
||||||
|
select a as a from t4 union select a from t3;
|
||||||
|
a
|
||||||
|
aaa,bbb
|
||||||
|
Yes
|
||||||
|
select a as a from t1 union select a from t4;
|
||||||
|
a
|
||||||
|
No
|
||||||
|
aaa,bbb
|
||||||
|
drop table t1,t2,t3,t4;
|
||||||
|
@ -575,3 +575,23 @@ PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1) UNION
|
|||||||
(SELECT * FROM t1 AS PARTITIONED, t2 AS
|
(SELECT * FROM t1 AS PARTITIONED, t2 AS
|
||||||
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1);
|
PARTITIONED_B WHERE PARTITIONED_B.ID=PARTITIONED.ID1);
|
||||||
drop table t1,t2;
|
drop table t1,t2;
|
||||||
|
|
||||||
|
#
|
||||||
|
# merging ENUM and SET fields in one UNION
|
||||||
|
#
|
||||||
|
create table t1 (a ENUM('Yes', 'No') NOT NULL);
|
||||||
|
create table t2 (a ENUM('aaa', 'bbb') NOT NULL);
|
||||||
|
insert into t1 values ('No');
|
||||||
|
insert into t2 values ('bbb');
|
||||||
|
create table t3 (a SET('Yes', 'No') NOT NULL);
|
||||||
|
create table t4 (a SET('aaa', 'bbb') NOT NULL);
|
||||||
|
insert into t3 values (1);
|
||||||
|
insert into t4 values (3);
|
||||||
|
select "1" as a union select a from t1;
|
||||||
|
select a as a from t1 union select "1";
|
||||||
|
select a as a from t2 union select a from t1;
|
||||||
|
select "1" as a union select a from t3;
|
||||||
|
select a as a from t3 union select "1";
|
||||||
|
select a as a from t4 union select a from t3;
|
||||||
|
select a as a from t1 union select a from t4;
|
||||||
|
drop table t1,t2,t3,t4;
|
||||||
|
34
sql/item.cc
34
sql/item.cc
@ -2509,27 +2509,41 @@ bool Item_type_holder::join_types(THD *thd, Item *item)
|
|||||||
bool change_field= 0, skip_store_field= 0;
|
bool change_field= 0, skip_store_field= 0;
|
||||||
Item_result new_type= type_convertor[item_type][item->result_type()];
|
Item_result new_type= type_convertor[item_type][item->result_type()];
|
||||||
|
|
||||||
// we have both fields
|
/*
|
||||||
|
we have both fields and field is not enum or set(different enums(sets)
|
||||||
|
can't be joinned in one enum(set) field)
|
||||||
|
*/
|
||||||
if (field_example && item->type() == Item::FIELD_ITEM)
|
if (field_example && item->type() == Item::FIELD_ITEM)
|
||||||
{
|
{
|
||||||
Field *field= ((Item_field *)item)->field;
|
Field *field= ((Item_field *)item)->field;
|
||||||
if (field_example->field_cast_type() != field->field_cast_type())
|
Field::field_cast_enum field_type= field->field_cast_type();
|
||||||
|
|
||||||
|
if (field_type != Field::FIELD_CAST_ENUM &&
|
||||||
|
field_type != Field::FIELD_CAST_SET)
|
||||||
{
|
{
|
||||||
if (!(change_field=
|
if (field_example->field_cast_type() != field_type)
|
||||||
field_example->field_cast_compatible(field->field_cast_type())))
|
|
||||||
{
|
{
|
||||||
/*
|
if (!(change_field=
|
||||||
if old field can't store value of 'worse' new field we will make
|
field_example->field_cast_compatible(field->field_cast_type())))
|
||||||
decision about result field type based only on Item result type
|
{
|
||||||
*/
|
/*
|
||||||
if (!field->field_cast_compatible(field_example->field_cast_type()))
|
if old field can't store value of 'worse' new field we will make
|
||||||
skip_store_field= 1;
|
decision about result field type based only on Item result type
|
||||||
|
*/
|
||||||
|
if (!field->field_cast_compatible(field_example->field_cast_type()))
|
||||||
|
skip_store_field= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
skip_store_field= 1;
|
||||||
}
|
}
|
||||||
|
else if (field_example || item->type() == Item::FIELD_ITEM)
|
||||||
|
skip_store_field= 1;
|
||||||
|
|
||||||
// size/type should be changed
|
// size/type should be changed
|
||||||
if (change_field ||
|
if (change_field ||
|
||||||
|
skip_store_field ||
|
||||||
(new_type != item_type) ||
|
(new_type != item_type) ||
|
||||||
(max_length < new_length) ||
|
(max_length < new_length) ||
|
||||||
((new_type == INT_RESULT) &&
|
((new_type == INT_RESULT) &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user