From 7599a9379eb2c11c74aaac925ff73470ad239276 Mon Sep 17 00:00:00 2001 From: Gagan Goel Date: Thu, 12 Sep 2019 11:11:46 -0400 Subject: [PATCH] Save and restore the group by list columns as the server optimizer can optimize out the constant columns in this list --- dbcon/mysql/ha_mcs_pushdown.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dbcon/mysql/ha_mcs_pushdown.cpp b/dbcon/mysql/ha_mcs_pushdown.cpp index 406d4ae43..d88e88738 100644 --- a/dbcon/mysql/ha_mcs_pushdown.cpp +++ b/dbcon/mysql/ha_mcs_pushdown.cpp @@ -718,6 +718,25 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex) return handler; } + // Save the original group_list as it can be mutated by the + // optimizer which calls the remove_const() function + Group_list_ptrs *group_list_ptrs = NULL; + if (select_lex->group_list.first) + { + void *mem = thd->stmt_arena->alloc(sizeof(Group_list_ptrs)); + + if (!mem || !(group_list_ptrs = new (mem) Group_list_ptrs(thd->stmt_arena->mem_root)) || + group_list_ptrs->reserve(select_lex->group_list.elements)) + { + return handler; + } + + for (ORDER *order = select_lex->group_list.first; order; order = order->next) + { + group_list_ptrs->push_back(order); + } + } + bool unsupported_feature = false; // Select_handler use the short-cut that effectively disables // INSERT..SELECT, LDI, SELECT..INTO OUTFILE @@ -749,6 +768,17 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex) } } + // Restore back the saved group_list + if (group_list_ptrs) + { + select_lex->group_list.empty(); + for (size_t i = 0; i < group_list_ptrs->size(); i++) + { + ORDER *order = (*group_list_ptrs)[i]; + select_lex->group_list.link_in_list(order, &order->next); + } + } + // Iterate and traverse through the item list and do not create SH // if the unsupported (set/get_user_var) functions are present. TABLE_LIST* table_ptr = select_lex->get_table_list();