MDEV-24511 null field is created with CREATE..SELECT

When creating fields for UNION results, Field_null is not allowed.
Should create binary(0) instead.
This commit is contained in:
Sergei Golubchik 2021-07-27 23:45:30 +02:00 committed by Nikita Malyavin
commit 6152ab7b42
5 changed files with 68 additions and 5 deletions

View file

@ -5933,7 +5933,7 @@ void Type_handler_geometry::Item_param_set_param_func(Item_param *param,
/***************************************************************************/
bool Type_handler_string_result::union_element_finalize(const Item * item) const
bool Type_handler_string_result::union_element_finalize(Item_type_holder *item) const
{
if (item->collation.derivation == DERIVATION_NONE)
{
@ -5943,6 +5943,12 @@ bool Type_handler_string_result::union_element_finalize(const Item * item) const
return false;
}
bool Type_handler_null::union_element_finalize(Item_type_holder *item) const
{
item->set_handler(&type_handler_string);
return false;
}
/***************************************************************************/
bool Type_handler::Vers_history_point_resolve_unit(THD *thd,

View file

@ -62,6 +62,7 @@ class Item_func_minus;
class Item_func_mul;
class Item_func_div;
class Item_func_mod;
class Item_type_holder;
class cmp_item;
class in_vector;
class Type_handler_hybrid_field_type;
@ -1191,7 +1192,7 @@ public:
Performs the final data type validation for a UNION element,
after the regular "aggregation for result" was done.
*/
virtual bool union_element_finalize(const Item * item) const
virtual bool union_element_finalize(Item_type_holder *item) const
{
return false;
}
@ -2244,7 +2245,7 @@ public:
void sortlength(THD *thd,
const Type_std_attributes *item,
SORT_FIELD_ATTR *attr) const;
bool union_element_finalize(const Item * item) const;
bool union_element_finalize(Item_type_holder *item) const;
bool Column_definition_prepare_stage1(THD *thd,
MEM_ROOT *mem_root,
Column_definition *c,
@ -3118,6 +3119,7 @@ public:
bool Item_send(Item *item, Protocol *protocol, st_value *buf) const;
Field *make_conversion_table_field(TABLE *, uint metadata,
const Field *target) const;
bool union_element_finalize(Item_type_holder *item) const;
bool Column_definition_fix_attributes(Column_definition *c) const;
bool Column_definition_prepare_stage1(THD *thd,
MEM_ROOT *mem_root,

View file

@ -1154,7 +1154,8 @@ cont:
Test if the aggregated data type is OK for a UNION element.
E.g. in case of string data, DERIVATION_NONE is not allowed.
*/
if (type->type_handler()->union_element_finalize(type))
if (type->type() == Item::TYPE_HOLDER && type->type_handler()->
union_element_finalize(static_cast<Item_type_holder*>(type)))
goto err;
}