Skip to content

Commit

Permalink
fix(tianmu): fix MySQL server has gone away when exec query (#1641 #…
Browse files Browse the repository at this point in the history
  • Loading branch information
adofsauron authored and mergify[bot] committed Apr 28, 2023
1 parent 587d276 commit 4a35d96
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
4 changes: 2 additions & 2 deletions sql/sql_optimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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");
Expand Down
28 changes: 22 additions & 6 deletions storage/tianmu/core/engine_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand All @@ -384,7 +385,7 @@ QueryRouteTo Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, SE
List_iterator_fast<Item> li(selects_list->fields_list);
for (Item *item = li++; item; item = li++) {
if ((item->type() == Item::Type::FUNC_ITEM) &&
(down_cast<Item_func *>(item)->functype() == Item_func::Functype::FUNC_SP)) {
((down_cast<Item_func *>(item)->functype() == Item_func::Functype::FUNC_SP))) {
return join_exec();
}
}
Expand Down Expand Up @@ -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<Item> li(selects_list->fields_list);
for (Item *item = li++; item; item = li++) {
if ((item->type() == Item::Type::FUNC_ITEM) &&
((down_cast<Item_func *>(item)->functype() == Item_func::Functype::SUSERVAR_FUNC))) {
exec_direct = false;
break;
}
}
}
}

Expand Down

0 comments on commit 4a35d96

Please sign in to comment.