From dac290b755af88ba73815190bb718551322c4bf2 Mon Sep 17 00:00:00 2001 From: Gagan Goel Date: Wed, 25 Sep 2019 10:42:39 -0400 Subject: [PATCH] Build an aggregate column from the extended select list in the group by handler. --- dbcon/mysql/ha_calpont_execplan.cpp | 11 +++++++++-- dbcon/mysql/ha_calpont_impl_if.h | 7 +++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index 325caee48..684e0535a 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -3112,7 +3112,7 @@ CalpontSystemCatalog::ColType colType_MysqlToIDB (const Item* item) return ct; } -ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand) +ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand, bool isRefItem) { ReturnedColumn* rc = NULL; @@ -3132,6 +3132,12 @@ ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupp case Item::FIELD_ITEM: { Item_field* ifp = (Item_field*)item; + + if (isRefItem && gwi.isGroupByHandler && !gwi.extSelAggColsItems.empty()) + { + return buildAggFrmTempField(ifp, gwi); + } + return buildSimpleColumn(ifp, gwi); } case Item::CONST_ITEM: @@ -5606,7 +5612,7 @@ void gp_walk(const Item* item, void* arg) if (col->type() != Item::COND_ITEM) { - rc = buildReturnedColumn(col, *gwip, gwip->fatalParseError); + rc = buildReturnedColumn(col, *gwip, gwip->fatalParseError, false, true); if ( col->type() == Item::FIELD_ITEM ) gwip->fatalParseError = false; @@ -8112,6 +8118,7 @@ int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi) SELECT_LEX *select_lex = gi.groupByTables->select_lex; gp_walk_info gwi; gwi.thd = thd; + gwi.isGroupByHandler = true; int status = getGroupPlan(gwi, *select_lex, csep, gi); #ifdef DEBUG_WALK_COND diff --git a/dbcon/mysql/ha_calpont_impl_if.h b/dbcon/mysql/ha_calpont_impl_if.h index 3bf4b9bf6..f59ad0831 100644 --- a/dbcon/mysql/ha_calpont_impl_if.h +++ b/dbcon/mysql/ha_calpont_impl_if.h @@ -157,6 +157,8 @@ struct gp_walk_info bool cs_vtable_is_update_with_derive; bool cs_vtable_impossible_where_on_union; + bool isGroupByHandler; + gp_walk_info() : sessionid(0), fatalParseError(false), condPush(false), @@ -175,7 +177,8 @@ struct gp_walk_info recursionHWM(0), inCaseStmt(false), cs_vtable_is_update_with_derive(false), - cs_vtable_impossible_where_on_union(false) + cs_vtable_impossible_where_on_union(false), + isGroupByHandler(false) {} ~gp_walk_info() {} @@ -358,7 +361,7 @@ const std::string bestTableName(const Item_field* ifp); bool isMCSTable(TABLE* table_ptr); // execution plan util functions prototypes -execplan::ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand = false); +execplan::ReturnedColumn* buildReturnedColumn(Item* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand = false, bool isRefItem = false); execplan::ReturnedColumn* buildFunctionColumn(Item_func* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand = false, bool selectBetweenIn = false); execplan::ArithmeticColumn* buildArithmeticColumn(Item_func* item, gp_walk_info& gwi, bool& nonSupport, bool pushdownHand = false); execplan::ConstantColumn* buildDecimalColumn(Item* item, gp_walk_info& gwi);