From 67b4bb67f034d1870fb608a92b65d843c44c6e6f Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 27 Aug 2020 17:12:45 -0500 Subject: [PATCH 1/3] MCOL-3827 optimize out sort of singleton --- dbcon/joblist/jlf_subquery.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dbcon/joblist/jlf_subquery.cpp b/dbcon/joblist/jlf_subquery.cpp index ac2f4b950..ef40292ba 100644 --- a/dbcon/joblist/jlf_subquery.cpp +++ b/dbcon/joblist/jlf_subquery.cpp @@ -819,11 +819,17 @@ void addOrderByAndLimit(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo) { sc = dynamic_cast(jobInfo.deliveredCols[sc->orderPos()].get()); - // TODO Investigate why this could be NULL + // If sc is NULL it's most likely a scaler subquery if (sc == NULL) { const ReturnedColumn* rc = dynamic_cast(orderByCols[i].get()); uint64_t eid = rc->expressionId(); + // If eid is -1, then there's no corresponding + // entry in tupleKeyMap and it will assert down the line + // Don't add the order by. It won't work and ordering on + // a singleton is a waste anyway. + if ((int64_t)eid == -1) + continue; CalpontSystemCatalog::ColType ct = rc->resultType(); tupleKey = getExpTupleKey(jobInfo, eid); jobInfo.orderByColVec.push_back(make_pair(tupleKey, orderByCols[i]->asc())); From 94258d02617d42900c0ae4f95978d077932c2d1b Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 28 Aug 2020 13:43:54 -0500 Subject: [PATCH 2/3] MCOL-3827 need to cast to int32_t --- dbcon/joblist/jlf_subquery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbcon/joblist/jlf_subquery.cpp b/dbcon/joblist/jlf_subquery.cpp index ef40292ba..59398bd41 100644 --- a/dbcon/joblist/jlf_subquery.cpp +++ b/dbcon/joblist/jlf_subquery.cpp @@ -828,7 +828,7 @@ void addOrderByAndLimit(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo) // entry in tupleKeyMap and it will assert down the line // Don't add the order by. It won't work and ordering on // a singleton is a waste anyway. - if ((int64_t)eid == -1) + if ((int32_t)eid == -1) continue; CalpontSystemCatalog::ColType ct = rc->resultType(); tupleKey = getExpTupleKey(jobInfo, eid); From 9df66c4d3e37a0ebcf8e69cb3611323b464417d2 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 28 Aug 2020 13:55:34 -0500 Subject: [PATCH 3/3] MCOL-3827 eid is 4 bytes --- dbcon/joblist/jlf_subquery.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dbcon/joblist/jlf_subquery.cpp b/dbcon/joblist/jlf_subquery.cpp index 59398bd41..d7452cb7b 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(); // If eid is -1, then there's no corresponding // entry in tupleKeyMap and it will assert down the line // Don't add the order by. It won't work and ordering on