From 4b0cedf82d8d8ba582648dcb4a2620c146862a43 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 27 Jun 2018 16:07:21 +0400 Subject: MDEV-16454 Bad results for IN with ROW Consider an IN predicate with ROW-type arguments: predicant IN (value1, ..., valueM) where predicant and all values consist of N elements. When performing IN for these arguments, at every position i (1..N) only data type of i-th element of predicant was taken into account, while data types on i-th elements of value1..valueM were not taken. These led to bad comparison data type detection, e.g. when mixing unsigned and signed integer values. After this change all element data types are taken into account. So, for example, a mixture of unsigned and signed values is now calculated using decimal and does not overflow any more. Detailed changes: 1. All comparators for ROW elements are now created recursively at fix_fields() time, inside cmp_item_row::prepare_comparators(). Previously prepare_comparators() installed comparators only for temporal data types, while comparators for other types were installed at execution time, in cmp_item_row::store_value(). 2. Removing comparator creating code from cmp_item_row::store_value(). It was responsible for non-temporal data types. 3. Removing find_date_time_item(). It's not needed any more. All ROW-element data types are now covered by cmp_item_row::prepare_comparators(). 4. Adding a helper method Item_args::alloc_and_extract_row_elements() to extract elements from an array of ROW-type Items, from the given position. Using this method to collect elements from the i-th position and further pass them to Type_handler_hybrid_field_type::aggregate_for_comparison(). 5. Moving the call for alloc_comparators() inside cmp_item_row::prepare_comparators(). This helps to call prepare_comparators() for ROW elements recursively (if elements appear to be ROWs again). Moving alloc_comparators() from "public" to "private". --- mysql-test/main/func_debug.test | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'mysql-test/main/func_debug.test') diff --git a/mysql-test/main/func_debug.test b/mysql-test/main/func_debug.test index 9237561500d..f3ae0c67181 100644 --- a/mysql-test/main/func_debug.test +++ b/mysql-test/main/func_debug.test @@ -555,3 +555,25 @@ EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a BETWEEN ''a'' AND ?' USING 0x61; DROP TABLE t1; SET SESSION debug_dbug="-d,Item_basic_value"; + + +--echo # +--echo # MDEV-16454 Bad results for IN with ROW +--echo # + +SET SESSION debug_dbug="+d,cmp_item"; +SET SESSION debug_dbug="+d,Item_func_in"; +SET SESSION debug_dbug="+d,Predicant_to_list_comparator"; + +SELECT (18446744073709551615,0) IN ((18446744073709551614,0),(-1,0)); +SELECT (1,(0,0)) IN ((1,(1,0)),(0,(0,0))); +SELECT (1,(0,0),3) IN ((1,(1,0),3),(0,(0,0),3)); + +SELECT '0x' IN (0); +SELECT '0x' IN (0,1); +SELECT ('0x',1) IN ((0,1)); +SELECT ('0x',1) IN ((0,1),(1,1)); + +SET SESSION debug_dbug="-d,Predicant_to_list_comparator"; +SET SESSION debug_dbug="-d,Item_func_in"; +SET SESSION debug_dbug="-d,cmp_item"; -- cgit v1.2.1