Skip to content

Commit

Permalink
feat(tianmu): to adapt group by command to MySQL8.0.(#718)
Browse files Browse the repository at this point in the history
In 5.7, group by is sorted by asc by default, but in 8.0, it is not sorted by default
Init Query_result_create::table for CTAS to fix crash
  • Loading branch information
DandreChen committed Oct 14, 2022
1 parent c7c3b3d commit 26b4379
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions storage/tianmu/core/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,8 @@ Query_route_to Engine::Handle_Query(THD *thd, Query_expression *qe, Query_result
return Query_route_to::TO_MYSQL;
}

if (with_insert) result_output->create_table_for_query_block(thd); // used for CTAS

if (lock_tables(thd, thd->lex->query_tables, thd->lex->table_count, 0)) {
TIANMU_LOG(LogCtl_Level::ERROR, "Failed to lock tables for query '%s'", thd->query().str);
return Query_route_to::TO_TIANMU;
Expand Down
4 changes: 2 additions & 2 deletions storage/tianmu/core/engine.ic
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static int optimize_select(THD *thd, ulong select_options, Query_result *result,
}
} else { // it is a global_opton query block, such as limit, order by, etc.
if (!select_lex->master_query_expression()->is_prepared())
if (err = select_lex->prepare(thd, nullptr)) // stonedb8
if ((err = select_lex->prepare(thd, nullptr)))
{
return err;
}
Expand All @@ -67,7 +67,7 @@ static int optimize_select(THD *thd, ulong select_options, Query_result *result,
} else {
thd_proc_info(thd, "init");
if (!select_lex->master_query_expression()->is_prepared())
if (err = select_lex->prepare(thd, nullptr)) // stonedb8
if ((err = select_lex->prepare(thd, nullptr)))
{
return err;
}
Expand Down
4 changes: 2 additions & 2 deletions storage/tianmu/core/query_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,9 @@ Query_route_to Query::AddFields(mem_root_deque<Item *> &fields, TabID const &tmp

Query_route_to Query::AddGroupByFields(ORDER *group_by, const TabID &tmp_table) {
for (; group_by; group_by = group_by->next) {
if (group_by->direction != ORDER_ASC) {
if (group_by->direction != ORDER_NOT_RELEVANT) {
my_message(ER_SYNTAX_ERROR,
"Tianmu specific error: Using DESC after GROUP BY clause not "
"Tianmu specific error: Using ASC/DESC after GROUP BY clause not "
"allowed. Use "
"ORDER BY to order the result",
MYF(0));
Expand Down

0 comments on commit 26b4379

Please sign in to comment.