Commit baadbe96 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-9234 Add Type_handler::union_element_finalize()

parent a765b19e
...@@ -7890,6 +7890,19 @@ bool Type_handler_string_result::Item_eq_value(THD *thd, ...@@ -7890,6 +7890,19 @@ bool Type_handler_string_result::Item_eq_value(THD *thd,
} }
/***************************************************************************/
bool Type_handler_string_result::union_element_finalize(const Item * item) const
{
if (item->collation.derivation == DERIVATION_NONE)
{
my_error(ER_CANT_AGGREGATE_NCOLLATIONS, MYF(0), "UNION");
return true;
}
return false;
}
/***************************************************************************/ /***************************************************************************/
void Type_handler_var_string:: void Type_handler_var_string::
......
...@@ -3356,6 +3356,14 @@ class Type_handler ...@@ -3356,6 +3356,14 @@ class Type_handler
virtual Field *make_conversion_table_field(TABLE *TABLE, virtual Field *make_conversion_table_field(TABLE *TABLE,
uint metadata, uint metadata,
const Field *target) const= 0; const Field *target) const= 0;
/*
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
{
return false;
}
// Automatic upgrade, e.g. for ALTER TABLE t1 FORCE // Automatic upgrade, e.g. for ALTER TABLE t1 FORCE
virtual void Column_definition_implicit_upgrade(Column_definition *c) const virtual void Column_definition_implicit_upgrade(Column_definition *c) const
{ } { }
...@@ -4580,6 +4588,7 @@ class Type_handler_string_result: public Type_handler ...@@ -4580,6 +4588,7 @@ class Type_handler_string_result: public Type_handler
void sortlength(THD *thd, void sortlength(THD *thd,
const Type_std_attributes *item, const Type_std_attributes *item,
SORT_FIELD_ATTR *attr) const; SORT_FIELD_ATTR *attr) const;
bool union_element_finalize(const Item * item) const;
bool Column_definition_prepare_stage1(THD *thd, bool Column_definition_prepare_stage1(THD *thd,
MEM_ROOT *mem_root, MEM_ROOT *mem_root,
Column_definition *c, Column_definition *c,
......
...@@ -1085,12 +1085,12 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg, ...@@ -1085,12 +1085,12 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
while ((type= tp++)) while ((type= tp++))
{ {
if (type->cmp_type() == STRING_RESULT && /*
type->collation.derivation == DERIVATION_NONE) Test if the aggregated data type is OK for a UNION element.
{ E.g. in case of string data, DERIVATION_NONE is not allowed.
my_error(ER_CANT_AGGREGATE_NCOLLATIONS, MYF(0), "UNION"); */
if (type->type_handler()->union_element_finalize(type))
goto err; goto err;
}
} }
/* /*
......
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