From 6bd13849b290ac490a7980c734030113123a8159 Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Sat, 7 Apr 2018 04:46:34 +0300 Subject: [PATCH] MCOL-1052 WIP Use SELECT fields referenced in HAVING items list. --- dbcon/mysql/ha_calpont_execplan.cpp | 22 ++++++++++++++++++++++ dbcon/mysql/ha_calpont_impl_if.h | 1 + 2 files changed, 23 insertions(+) diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index 78b65bd18..5663f2871 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -5289,6 +5289,8 @@ void gp_walk(const Item* item, void* arg) rc = buildReturnedColumnGr(col, *gwip, gwip->fatalParseError); } else*/ rc = buildReturnedColumn(col, *gwip, gwip->fatalParseError); + if ( col->type() == Item::FIELD_ITEM ) + gwip->fatalParseError = false; } SimpleColumn* sc = dynamic_cast(rc); @@ -5361,6 +5363,19 @@ void gp_walk(const Item* item, void* arg) Item_func* ifp = (Item_func*)col; gwip->ptWorkStack.push(buildParseTree(ifp, *gwip, gwip->fatalParseError)); } + else if (col->type() == Item::FIELD_ITEM && gwip->clauseType == HAVING) + { + // Найти item в списке groupByFields + Item_func_or_sum* isfp = reinterpret_cast(gwip->havingAggColsItems[0]); + if ( isfp->type() == Item::SUM_FUNC_ITEM ) + { + ReturnedColumn* rc = buildAggregateColumn(isfp, *gwip); + } + + if (rc) + gwip->rcWorkStack.push(rc); + break; + } else cando = false; @@ -8725,6 +8740,13 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro // add this agg col to returnedColumnList boost::shared_ptr spac(ac); gwi.returnedCols.push_back(spac); + // This item will be used in HAVING clause later. + Item_func_or_sum* isfp = reinterpret_cast(item); + if ( ! isfp->name_length ) + { + gwi.havingAggColsItems.push_back(item); + } + gwi.selectCols.push_back('`' + escapeBackTick(spac->alias().c_str()) + '`'); String str(256); item->print(&str, QT_INFINIDB_NO_QUOTE); diff --git a/dbcon/mysql/ha_calpont_impl_if.h b/dbcon/mysql/ha_calpont_impl_if.h index b74025d54..83f6aaf41 100644 --- a/dbcon/mysql/ha_calpont_impl_if.h +++ b/dbcon/mysql/ha_calpont_impl_if.h @@ -99,6 +99,7 @@ struct gp_walk_info execplan::CalpontSelectExecutionPlan::ReturnedColumnList groupByCols; execplan::CalpontSelectExecutionPlan::ReturnedColumnList subGroupByCols; execplan::CalpontSelectExecutionPlan::ReturnedColumnList orderByCols; + std::vector havingAggColsItems; execplan::CalpontSelectExecutionPlan::ColumnMap columnMap; // This vector temporarily hold the projection columns to be added // to the returnedCols vector for subquery processing. It will be appended