From e7b8abfdb94e1988b93e1a3c8f783b77b0974170 Mon Sep 17 00:00:00 2001 From: David Hall Date: Mon, 17 Aug 2020 14:40:22 -0500 Subject: [PATCH] MCOL-3827 Optimize out sort on SubQuery in Select --- dbcon/joblist/jlf_subquery.cpp | 2 +- dbcon/mysql/ha_mcs_execplan.cpp | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/dbcon/joblist/jlf_subquery.cpp b/dbcon/joblist/jlf_subquery.cpp index ac2f4b950..ab1ff36cd 100644 --- a/dbcon/joblist/jlf_subquery.cpp +++ b/dbcon/joblist/jlf_subquery.cpp @@ -823,7 +823,7 @@ void addOrderByAndLimit(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo) if (sc == NULL) { const ReturnedColumn* rc = dynamic_cast(orderByCols[i].get()); - uint64_t eid = rc->expressionId(); + uint32_t eid = rc->expressionId(); CalpontSystemCatalog::ColType ct = rc->resultType(); tupleKey = getExpTupleKey(jobInfo, eid); jobInfo.orderByColVec.push_back(make_pair(tupleKey, orderByCols[i]->asc())); diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 8ae75b42d..5f7eea830 100755 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -7790,12 +7790,16 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, } } - if (ordercol->direction == ORDER::ORDER_ASC) - rc->asc(true); - else - rc->asc(false); + SimpleColumn* sc = dynamic_cast(rc); + if (!sc || sc->oid()) + { + if (ordercol->direction == ORDER::ORDER_ASC) + rc->asc(true); + else + rc->asc(false); - gwi.orderByCols.push_back(SRCP(rc)); + gwi.orderByCols.push_back(SRCP(rc)); + } } } // make sure columnmap, returnedcols and count(*) arg_list are not empty @@ -9582,12 +9586,16 @@ int getGroupPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, cal_gro } } - if (ordercol->direction == ORDER::ORDER_ASC) - rc->asc(true); - else - rc->asc(false); + SimpleColumn* sc = dynamic_cast(rc); + if (!sc || sc->oid()) + { + if (ordercol->direction == ORDER::ORDER_ASC) + rc->asc(true); + else + rc->asc(false); - gwi.orderByCols.push_back(SRCP(rc)); + gwi.orderByCols.push_back(SRCP(rc)); + } }