diff --git a/dbcon/joblist/jlf_subquery.cpp b/dbcon/joblist/jlf_subquery.cpp index ac2f4b950..d7452cb7b 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(); + 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 + // a singleton is a waste anyway. + if ((int32_t)eid == -1) + continue; CalpontSystemCatalog::ColType ct = rc->resultType(); tupleKey = getExpTupleKey(jobInfo, eid); jobInfo.orderByColVec.push_back(make_pair(tupleKey, orderByCols[i]->asc()));