diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index c4228c67ad9890f4902241fa04656744d8bca286..66ec044cc03bec6d661e8deb8698dd5dfec8ed2e 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -3682,6 +3682,37 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i initCtxOutputBuffer(pCtx, pDataBlock->info.numOfCols); } +bool extendColCapacity(SColumnInfoData* pColInfo, int32_t newSize, SQLFunctionCtx* pCtx, int32_t *bufCapacity, bool extendLarge) { + char* p = NULL; + int32_t newCapacity = 0; + if (extendLarge) { + // doulbe newSize + newCapacity = newSize * 2; + p = realloc(pColInfo->pData, (size_t)newCapacity * pColInfo->info.bytes); + } + + if (p == NULL) { + // failed then newSize + newCapacity = newSize; + p = realloc(pColInfo->pData, (size_t)newCapacity * pColInfo->info.bytes); + if(p == NULL) { + taosMsleep(1000); + p = realloc(pColInfo->pData, (size_t)newCapacity * pColInfo->info.bytes); + qInfo("MEM realloc memory size %d failed, sleep 1s to try, p=%p", newSize * pColInfo->info.bytes, p); + } + } + + if (p != NULL) { + // save new pointer + pColInfo->pData = p; + pCtx->pOutput = p; + (*bufCapacity) = newCapacity; + return true; + } + + return false; +} + void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOfInputRows, SQueryRuntimeEnv* runtimeEnv, bool extendLarge) { SSDataBlock* pDataBlock = pBInfo->pRes;