diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 42adc6fac12f61053aea6784a200685a217918ac..a50e2ad899aa7b317869daa946a3e8626631ad13 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -1484,6 +1484,17 @@ int32_t tsCompare(const void* p1, const void* p2) { } } +int32_t tsCompareDesc(const void* p1, const void* p2) { + TSKEY k = *(TSKEY*)p1; + SResPair* pair = (SResPair*)p2; + + if (k == pair->key) { + return 0; + } else { + return k > pair->key? -1:1; + } +} + static void stddev_dst_function(SQLFunctionCtx *pCtx) { SStddevdstInfo *pStd = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); @@ -1505,7 +1516,7 @@ static void stddev_dst_function(SQLFunctionCtx *pCtx) { SResPair* p = taosArrayGet(resList, 0); avg = p->avg; } else { // todo opt performance by using iterator since the timestamp lsit is matched with the output result - SResPair* p = bsearch(&pCtx->startTs, resList->pData, len, sizeof(SResPair), tsCompare); + SResPair* p = bsearch(&pCtx->startTs, resList->pData, len, sizeof(SResPair), pCtx->order == TSDB_ORDER_DESC ? tsCompareDesc : tsCompare); if (p == NULL) { return; } diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 48ca064d87357e8bd46c6164813979670ab5485e..d83620c78fe0cc87a1fff61b6c58dff9852ecbec 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -464,8 +464,8 @@ void taosFillSetInputDataBlock(SFillInfo* pFillInfo, const SSDataBlock* pInput) pFillInfo->interval.slidingUnit, pFillInfo->precision); numOfRes += 1; - if(numOfRes < numOfRows) { - // reset current Key + if(numOfRes < numOfRows || pFillInfo->currentKey < lastKey) { + // set currentKey max pFillInfo->currentKey = tsList[0]; } }