From 76fd8c1c2f46da3e06e365a104d6d9f43df8b0c2 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Mon, 9 May 2011 11:20:51 +0100 Subject: [PATCH] Change "disable semi-joins in presense of outer joins" check to actually check for outer joins (and not for any "t1 SOME_JOIN t2 ON cond" syntax). --- sql/opt_subselect.cc | 27 +++++++++++++++++++++++++++ sql/sql_select.h | 3 ++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index c89cfde763c..24727d2f656 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -601,6 +601,26 @@ bool make_in_exists_conversion(THD *thd, JOIN *join, Item_in_subselect *item) } +bool check_for_outer_joins(List *join_list) +{ + TABLE_LIST *table; + NESTED_JOIN *nested_join; + List_iterator li(*join_list); + while ((table= li++)) + { + if ((nested_join= table->nested_join)) + { + if (check_for_outer_joins(&nested_join->join_list)) + return TRUE; + } + + if (table->outer_join) + return TRUE; + } + return FALSE; +} + + /* Convert semi-join subquery predicates into semi-join join nests @@ -685,6 +705,7 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) // Temporary measure: disable semi-joins when they are together with outer // joins. + /* for (TABLE_LIST *tbl= join->select_lex->leaf_tables; tbl; tbl=tbl->next_leaf) { TABLE_LIST *embedding= tbl->embedding; @@ -695,6 +716,12 @@ bool convert_join_subqueries_to_semijoins(JOIN *join) arena= thd->activate_stmt_arena_if_needed(&backup); goto skip_conversion; } + }*/ + if (check_for_outer_joins(join->join_list)) + { + in_subq= join->sj_subselects.front(); + arena= thd->activate_stmt_arena_if_needed(&backup); + goto skip_conversion; } //dump_TABLE_LIST_struct(select_lex, select_lex->leaf_tables); diff --git a/sql/sql_select.h b/sql/sql_select.h index 9a5c0494d29..4fbb8121208 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -701,7 +701,8 @@ public: /* Tables removed by table elimination. Set to 0 before the elimination. */ table_map eliminated_tables; /* - Bitmap of all inner tables from outer joins + Bitmap of all inner tables from outer joins (set at start of + make_join_statistics) */ table_map outer_join; ha_rows send_records,found_records,examined_rows,row_limit, select_limit;