diff --git a/src/client/src/tscGlobalmerge.c b/src/client/src/tscGlobalmerge.c index 1db6017add976463761f08bd81ab4fb66bb0c710..b216f9d29ac30a93b7ad0e40cfdbe5a8283c1dcc 100644 --- a/src/client/src/tscGlobalmerge.c +++ b/src/client/src/tscGlobalmerge.c @@ -965,7 +965,7 @@ SSDataBlock* doGlobalAggregate(void* param, bool* newgroup) { w->skey = *(int64_t*)pInfoData->pData; w->ekey = *(int64_t*)(((char*)pInfoData->pData) + TSDB_KEYSIZE * (pRes->info.rows - 1)); - if (pOperator->pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_DESC) { + if (pOperator->pRuntimeEnv->pQueryAttr->order.order == TSDB_ORDER_DESC && w->skey < w->ekey) { SWAP(w->skey, w->ekey, TSKEY); assert(w->skey >= w->ekey); }