diff --git a/sql/sql_optimizer.cc b/sql/sql_optimizer.cc index 2e670e6d3..6136e12f9 100644 --- a/sql/sql_optimizer.cc +++ b/sql/sql_optimizer.cc @@ -228,7 +228,7 @@ JOIN::optimize(OptimizePhase phase) if (phase == OptimizePhase::Before_LOJ_Transform) { if (tl->is_view_or_derived() && tl->optimize_derived_for_tianmu(thd)) - DBUG_RETURN(1); + DBUG_RETURN(0); } } } @@ -10126,7 +10126,7 @@ bool optimize_cond(THD *thd, Item **cond, COND_EQUAL **cond_equal, DBUG_EXECUTE("where",print_where(*cond,"after const change", QT_ORDINARY);); } } - if (*cond) + if ((*cond) && (!( (int64)(*cond) & 0x1))) { Opt_trace_object step_wrapper(trace); step_wrapper.add_alnum("transformation", "trivial_condition_removal"); diff --git a/storage/tianmu/core/engine_execute.cpp b/storage/tianmu/core/engine_execute.cpp index 2c6034b2d..33912629c 100644 --- a/storage/tianmu/core/engine_execute.cpp +++ b/storage/tianmu/core/engine_execute.cpp @@ -372,9 +372,10 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE return QueryRouteTo::kToMySQL; } - auto join_exec = ([&selects_list, &result_output] { + auto join_exec = ([&thd, &selects_list, &result_output] { selects_list->set_query_result(result_output); ASSERT(selects_list->join); + thd->lex->set_current_select(selects_list->join->select_lex); selects_list->join->exec(); return QueryRouteTo::kToTianmu; }); @@ -384,7 +385,7 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE List_iterator_fast li(selects_list->fields_list); for (Item *item = li++; item; item = li++) { if ((item->type() == Item::Type::FUNC_ITEM) && - (down_cast(item)->functype() == Item_func::Functype::FUNC_SP)) { + ((down_cast(item)->functype() == Item_func::Functype::FUNC_SP))) { return join_exec(); } } @@ -427,10 +428,25 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE } } - for (SELECT_LEX *sl = selects_list; sl; sl = sl->next_select()) { - if (sl->join->m_select_limit == 0) { - exec_direct = true; - break; + if (!exec_direct) { + for (SELECT_LEX *sl = selects_list; sl; sl = sl->next_select()) { + if (sl->join->m_select_limit == 0) { + exec_direct = true; + break; + } + } + } + + if (exec_direct) { + if ((!selects_list->table_list.elements) && (selects_list->fields_list.elements)) { + List_iterator_fast li(selects_list->fields_list); + for (Item *item = li++; item; item = li++) { + if ((item->type() == Item::Type::FUNC_ITEM) && + ((down_cast(item)->functype() == Item_func::Functype::SUSERVAR_FUNC))) { + exec_direct = false; + break; + } + } } }