diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 505057ef3341ae9046c6a35d56884432b56d7d3e..f312b4ab645b5609aa47cecc4e360f8db542a467 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -2615,6 +2615,10 @@ static void top_function_f(SQLFunctionCtx *pCtx, int32_t index) { STopBotInfo *pRes = getTopBotOutputInfo(pCtx); assert(pRes->num >= 0); + + if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotInfo) + POINTER_BYTES * pCtx->param[0].i64)) { + buildTopBotStruct(pRes, pCtx); + } SET_VAL(pCtx, 1, 1); TSKEY ts = GET_TS_DATA(pCtx, index);