From e648ff111a1d3fe79b6bd4ff0a25e85d1b949fb2 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 7 Feb 2013 15:33:24 +0200 Subject: MDEV-537 Make multi-column non-top level subqueries to be executed via index (index/unique subquery) instead of single_select_engine This task changes the IN-EXISTS rewrite for multi-column subqueries "(a, b) IN (select b, c ...)" to work in the same way as for single-column subqueries "a IN (select b ...) with respect to the injection of NULL-rejecting predicates. More specifically, the method Item_in_subselect::create_row_in_to_exists_cond() adds Item_is_not_null_test and Item_func_trig_cond only if the left IN operand can be NULL. Not having these predicates when not necessary, makes it possible to rewrite the subquery into a "unique_subquery" or "index_subquery" when there is a suitable index on the only subquery table. --- sql/item_subselect.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'sql') diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 8b3ce257642..0bde4a7926f 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2306,7 +2306,7 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join, ref_pointer_array+i, (char *)"", (char *)"")); - if (!abort_on_null) + if (!abort_on_null && select_lex->ref_pointer_array[i]->maybe_null) { Item *having_col_item= new Item_is_not_null_test(this, @@ -2325,10 +2325,6 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join, (char *)"", (char *)"")); item= new Item_cond_or(item, item_isnull); - /* - TODO: why we create the above for cases where the right part - cant be NULL? - */ if (left_expr->element_index(i)->maybe_null) { if (!(item= new Item_func_trig_cond(item, get_cond_guard(i)))) @@ -2339,6 +2335,11 @@ Item_in_subselect::create_row_in_to_exists_cond(JOIN * join, } *having_item= and_items(*having_item, having_col_item); } + if (!abort_on_null && left_expr->element_index(i)->maybe_null) + { + if (!(item= new Item_func_trig_cond(item, get_cond_guard(i)))) + DBUG_RETURN(true); + } *where_item= and_items(*where_item, item); } } -- cgit v1.2.1