Item_func_min_max::fix_length_and_dec() is hard-coded for the built-in data types. To allow pluggable data type determine behavior of the functions LEAST and GREATEST, we'll move the code to Type_handler as follows:
1. Add a new method in Type_handler_hybrid_field_type:
This method will decide which data type handler should be used for the result of LEAST/GREATEST.
2. Add a new virtual method in Type_handler:
This method will calculate the data type attributes. See Type_std_attributes.
Note, implementations for the particular Type_handler_xxx classes should reuse the code from Item_hybrid_func_fix_attributes as much as possible, because the current implementation of Item_func_min_max::fix_length_and_dec() is quite buggy:
MDEV-12497Wrong data type for LEAST(latin1_expr, utf8_expr) MDEV-12504Wrong data type for LEAST(date_expr,time_expr) MDEV-12505Wrong data type for GREATEST(bit_column, int_column)
Sharing the code with Item_hybrid_func should fix these problems.
3. Remove the current implementation of Item_func_min_max::fix_length_and_dec() and replace it to the new methods.
Under terms of this task we'll also disallow LEAST and GREATEST to have arguments of the GEOMETRY data type mixed with numeric and temporal arguments, as this has no sense.