diff options
Diffstat (limited to 'sql/item.cc')
-rw-r--r-- | sql/item.cc | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/sql/item.cc b/sql/item.cc index 14136435a50..4226f58e9a6 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2486,6 +2486,7 @@ Item_type_holder::Item_type_holder(THD *thd, Item *item) else field_example= 0; max_length= real_length(item); + maybe_null= item->maybe_null; collation.set(item->collation); } @@ -2509,31 +2510,36 @@ bool Item_type_holder::join_types(THD *thd, Item *item) bool change_field= 0, skip_store_field= 0; 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) { Field *field= ((Item_field *)item)->field; - if (field_example->field_cast_type() != field->field_cast_type()) + /* Can old example field store new data? */ + if ((change_field= + !field->field_cast_compatible(field_example->field_cast_type()))) { - if (!(change_field= - field_example->field_cast_compatible(field->field_cast_type()))) - { - /* - if old field can't store value of 'worse' new field we will make - 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; - } + /* + if old field can't store value of 'worse' new field we will make + decision about result field type based only on Item result type + */ + if (!field_example->field_cast_compatible(field->field_cast_type())) + skip_store_field= 1; } } + else if (field_example || item->type() == Item::FIELD_ITEM) + { + /* expression can't be mixed with field */ + skip_store_field= 1; + } // size/type should be changed if (change_field || + skip_store_field || (new_type != item_type) || (max_length < new_length) || - ((new_type == INT_RESULT) && - (decimals < item->decimals)) || (!maybe_null && item->maybe_null) || (item_type == STRING_RESULT && new_type == STRING_RESULT && !my_charset_same(collation.collation, item->collation.collation))) @@ -2541,8 +2547,6 @@ bool Item_type_holder::join_types(THD *thd, Item *item) // new field has some parameters worse then current skip_store_field|= (change_field && (max_length > new_length) || - ((new_type == INT_RESULT) && - (decimals > item->decimals)) || (maybe_null && !item->maybe_null) || (item_type == STRING_RESULT && new_type == STRING_RESULT && |