From 07561c43d7563f9f197d8973c8486d6425c9bfe6 Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Thu, 30 Aug 2018 17:03:14 +0300 Subject: [PATCH] MCOL-1052 LIMIT processing refactoring in getGroupPlan(). --- dbcon/execplan/calpontselectexecutionplan.h | 12 ++++++++++++ dbcon/joblist/joblistfactory.cpp | 5 +++-- dbcon/mysql/ha_calpont_execplan.cpp | 19 +++++++++++-------- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/dbcon/execplan/calpontselectexecutionplan.h b/dbcon/execplan/calpontselectexecutionplan.h index b3c6458f4..5d1f2fbb6 100644 --- a/dbcon/execplan/calpontselectexecutionplan.h +++ b/dbcon/execplan/calpontselectexecutionplan.h @@ -575,6 +575,15 @@ public: return fHasOrderBy; } + void specHandlerProcessed(const bool hand) + { + fSpecHandlerProcessed = hand; + } + const bool specHandlerProcessed() const + { + return fSpecHandlerProcessed; + } + void selectSubList(const SelectList& selectSubList) { fSelectSubList = selectSubList; @@ -871,6 +880,9 @@ private: uint32_t fPriority; uint32_t fStringTableThreshold; + + // for specific handlers processing, e.g. GROUP BY + bool fSpecHandlerProcessed; // Derived table involved in the query. For derived table optimization std::vector fSubSelectList; diff --git a/dbcon/joblist/joblistfactory.cpp b/dbcon/joblist/joblistfactory.cpp index 8c0615d83..04989e7b7 100644 --- a/dbcon/joblist/joblistfactory.cpp +++ b/dbcon/joblist/joblistfactory.cpp @@ -1846,12 +1846,13 @@ void makeVtableModeSteps(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo, if (csep->limitNum() != (uint64_t) - 1) { // special case for outer query order by limit -- return all - if (jobInfo.subId == 0 && csep->hasOrderBy()) + if (jobInfo.subId == 0 && csep->hasOrderBy() && !csep->specHandlerProcessed()) { jobInfo.limitCount = (uint64_t) - 1; } - // support order by and limit in sub-query/union + // support order by and limit in sub-query/union or + // GROUP BY handler processed outer query order else if (csep->orderByCols().size() > 0) { addOrderByAndLimit(csep, jobInfo); diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index da0fdbced..0af74c433 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -10164,25 +10164,28 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro } } - if (ord_cols.length() > 0) // has order by + if ( gwi.orderByCols.size() ) // has order by { gwi.thd->infinidb_vtable.has_order_by = true; csep->hasOrderBy(true); - ord_cols = " order by " + ord_cols; - select_query += ord_cols; + csep->specHandlerProcessed(true); } } // LIMIT and OFFSET are extracted from TABLE_LIST elements. // All of JOIN-ed tables contain relevant limit and offset. - if (gi.groupByTables->select_lex->select_limit) + uint64_t limit = (uint64_t)-1; + if (gi.groupByTables->select_lex->select_limit && + ( limit = static_cast(gi.groupByTables->select_lex->select_limit)->val_int() ) && + limit != (uint64_t)-1 ) { - csep->limitNum(((Item_int*)gi.groupByTables->select_lex->select_limit)->val_int()); + csep->limitNum(limit); } - else + else if (csep->hasOrderBy()) { - if (csep->hasOrderBy()) - csep->limitNum((uint64_t) - 2); + // We use LimitedOrderBy so set the limit to + // go through the check in addOrderByAndLimit + csep->limitNum((uint64_t) - 2); } if (gi.groupByTables->select_lex->offset_limit)