diff --git a/dbcon/joblist/limitedorderby.cpp b/dbcon/joblist/limitedorderby.cpp index 82d6041a8..4f3366cc6 100644 --- a/dbcon/joblist/limitedorderby.cpp +++ b/dbcon/joblist/limitedorderby.cpp @@ -77,14 +77,9 @@ void LimitedOrderBy::initialize(const RowGroup& rg, const JobInfo& jobInfo) map::iterator j = keyToIndexMap.find(i->first); idbassert(j != keyToIndexMap.end()); - // MCOL-1052 Ordering direction in CSEP differs from - // internal direction representation. - if (i->second) - fOrderByCond.push_back(IdbSortSpec(j->second, false)); - else - fOrderByCond.push_back(IdbSortSpec(j->second, true)); - - //fOrderByCond.push_back(IdbSortSpec(j->second, i->second)); + // TODO Ordering direction in CSEP differs from + // internal direction representation. This behavior should be fixed + fOrderByCond.push_back(IdbSortSpec(j->second, i->second)); } // limit row count info @@ -182,8 +177,8 @@ void LimitedOrderBy::finalize() if (fRowGroup.getRowCount() > 0) fDataQueue.push(fData); - // MCOL-1052 The removed check effectivly disables sorting to happen, - // since fStart = 0; + // MCOL-1052 The removed check effectively disables sorting, + // since fStart = 0 if there is no OFFSET; if (true) { uint64_t newSize = fRowsPerRG * fRowGroup.getRowSize(); diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index fac0cd032..14a7786a1 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -8009,6 +8009,10 @@ int cp_get_group_plan(THD* thd, SCSEP& csep, cal_impl_if::cal_group_info& gi) gwi.thd = thd; int status = getGroupPlan(gwi, select_lex, csep, gi); + cerr << "---------------- cp_get_group_plan EXECUTION PLAN ----------------" << endl; + cerr << *csep << endl ; + cerr << "-------------- EXECUTION PLAN END --------------\n" << endl; + if (status > 0) return ER_INTERNAL_ERROR; else if (status < 0) @@ -9877,6 +9881,31 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro select_query += ord_cols; } } + // 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) + { + csep->limitNum(((Item_int*)gi.groupByTables->select_lex->select_limit)->val_int()); + } + + if (gi.groupByTables->select_lex->offset_limit) + { + csep->limitStart(((Item_int*)gi.groupByTables->select_lex->offset_limit)->val_int()); + } + + //gwi.thd->infinidb_vtable.select_vtable_query.free(); + //gwi.thd->infinidb_vtable.select_vtable_query.append(select_query.c_str(), select_query.length()); + + // We don't currently support limit with correlated subquery + if (csep->limitNum() != (uint64_t) - 1 && + gwi.subQuery && !gwi.correlatedTbNameVec.empty()) + { + gwi.fatalParseError = true; + gwi.parseErrorText = IDBErrorInfo::instance()->errorMsg(ERR_NON_SUPPORT_LIMIT_SUB); + setError(gwi.thd, ER_INTERNAL_ERROR, gwi.parseErrorText, gwi); + return ER_CHECK_NOT_IMPLEMENTED; + } + } // ORDER BY processing ends here if ( gi.groupByDistinct ) diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index 5ca94562b..49df3bde3 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -5581,14 +5581,19 @@ internal_error: */ /*********************************************************** * DESCRIPTION: - * Return a result record for each group_by_handler::next_row() call. + * Return a result record for each + * group_by_handler::next_row() call. * PARAMETERS: - * group_hand - group by handler, that preserves initial table and items lists. . - * table - TABLE pointer The table to save the result set in. + * group_hand - group by handler, that preserves initial + * table and items lists. . + * table - TABLE pointer The table to save the result + * set in. * RETURN: * 0 if success - * HA_ERR_END_OF_FILE if the record set has come to an end - * others if something went wrong whilst getting the result set + * HA_ERR_END_OF_FILE if the record set has come to + * an end + * others if something went wrong whilst getting the + * result set ***********************************************************/ int ha_calpont_impl_group_by_next(ha_calpont_group_by_handler* group_hand, TABLE* table) { diff --git a/utils/windowfunction/idborderby.h b/utils/windowfunction/idborderby.h index 91db95366..38b31deb9 100644 --- a/utils/windowfunction/idborderby.h +++ b/utils/windowfunction/idborderby.h @@ -59,7 +59,8 @@ class IdbCompare; struct IdbSortSpec { int fIndex; - int fAsc; // ::= ASC | DESC + // TODO There are three ordering specs since 10.2 + int fAsc; // ::= ASC | DESC int fNf; // ::= NULLS FIRST | NULLS LAST IdbSortSpec() : fIndex(-1), fAsc(1), fNf(1) {}