-
Alexander Barkov authored
This patch fixes a number of data type aggregation problems in IN and CASE: - MDEV-11497 Wrong result for (int_expr IN (mixture of signed and unsigned expressions)) - MDEV-11514 IN with a mixture of TIME and DATETIME returns a wrong result - MDEV-11554 Wrong result for CASE on a mixture of signed and unsigned expressions - MDEV-11555 CASE with a mixture of TIME and DATETIME returns a wrong result 1. The problem reported in MDEV-11514 and MDEV-11555 was in the wrong assumption that items having the same cmp_type() can reuse the same cmp_item instance. So Item_func_case and Item_func_in used a static array of cmp_item*, one element per one XXX_RESULT. TIME and DATETIME cannot reuse the same cmp_item, because arguments of these types are compared very differently. TIME and DATETIME must have different instances in the cmp_item array. Reusing the same cmp_item for TIME and DATETIME leads to unexpected result and unexpected warnings. Note, after adding more data types soon (e.g. INET6), the problem would become more serious, as INET6 will most likely have STRING_RESULT, but it won't be able to reuse the same cmp_item with VARCHAR/TEXT. This patch introduces a new class Predicant_to_list_comparator, which maintains an array of cmp_items, one element per distinct Type_handler rather than one element per XXX_RESULT. 2. The problem reported in MDEV-11497 and MDEV-11554 happened because Item_func_in and Item_func_case did not take into account the fact that UNSIGNED and SIGNED values must be compared as DECIMAL rather than INT, because they used item_cmp_type() to aggregate the arguments. The relevant code now resides in Predicant_to_list_comparator::add_value() and uses Type_handler_hybrid_field_type::aggregate_for_comparison(), like Item_func_between does.
74891ed2