From 18ad3bdc2fa3bbe1bfd7e433adb0bc6b3dbce8c8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 5 Sep 2010 18:43:47 +0300 Subject: MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation Fixes for multiple problems/bugs/test failures that resulted from moving subquery optimization from the execution phase to the optimization phase. --- sql/sql_union.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'sql/sql_union.cc') diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 374e92c6a52..d91bdc069e8 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -186,6 +186,8 @@ st_select_lex_unit::init_prepare_fake_select_lex(THD *thd_arg) { (*order->item)->walk(&Item::change_context_processor, 0, (uchar*) &fake_select_lex->context); + (*order->item)->walk(&Item::set_fake_select_as_master_processor, 0, + (uchar*) fake_select_lex); } } @@ -271,6 +273,18 @@ bool st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result, can_skip_order_by= is_union_select && !(sl->braces && sl->explicit_limit); + /* + Remove all references from the select_lex_units to the subqueries that + are inside the ORDER BY clause. + */ + if (can_skip_order_by) + { + for (ORDER *ord= (ORDER *)sl->order_list.first; ord; ord= ord->next) + { + (*ord->item)->walk(&Item::eliminate_subselect_processor, FALSE, NULL); + } + } + saved_error= join->prepare(&sl->ref_pointer_array, (TABLE_LIST*) sl->table_list.first, sl->with_wild, -- cgit v1.2.1