From db444dbb2ed6faf73c86bbe84849ae42b429c6f0 Mon Sep 17 00:00:00 2001 From: DandreChen Date: Fri, 14 Oct 2022 14:49:12 +0800 Subject: [PATCH] feat(tianmu): to adapt `group by` command to MySQL8.0.(#718) 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 --- storage/tianmu/core/engine.cpp | 1 + storage/tianmu/core/engine.ic | 4 ++-- storage/tianmu/core/query_compile.cpp | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/storage/tianmu/core/engine.cpp b/storage/tianmu/core/engine.cpp index 3c2bf3c369..c73bf2434d 100644 --- a/storage/tianmu/core/engine.cpp +++ b/storage/tianmu/core/engine.cpp @@ -2287,6 +2287,7 @@ Query_route_to Engine::Execute(THD *thd, LEX *lex, Query_result *result_output, Query query(current_txn_); CompiledQuery cqu; + result_output->create_table_for_query_block(thd); // used for CTAS if (result_output->start_execution(thd)) return Query_route_to::TO_MYSQL; current_txn_->ResetDisplay(); // switch display on diff --git a/storage/tianmu/core/engine.ic b/storage/tianmu/core/engine.ic index f6d46af606..1b27643832 100644 --- a/storage/tianmu/core/engine.ic +++ b/storage/tianmu/core/engine.ic @@ -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; } @@ -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; } diff --git a/storage/tianmu/core/query_compile.cpp b/storage/tianmu/core/query_compile.cpp index be05a365e8..3933b0d6d8 100644 --- a/storage/tianmu/core/query_compile.cpp +++ b/storage/tianmu/core/query_compile.cpp @@ -483,9 +483,9 @@ Query_route_to Query::AddFields(mem_root_deque &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));