enh:[TD-32158] Free memory only when function need cleanup.
This commit is contained in:
parent
122b707ac8
commit
ad7b2ddc1b
|
@ -258,6 +258,7 @@ typedef struct SqlFunctionCtx {
|
||||||
SFuncInputRowIter rowIter;
|
SFuncInputRowIter rowIter;
|
||||||
bool bInputFinished;
|
bool bInputFinished;
|
||||||
bool hasWindowOrGroup; // denote that the function is used with time window or group
|
bool hasWindowOrGroup; // denote that the function is used with time window or group
|
||||||
|
bool needCleanup; // denote that the function need to be cleaned up
|
||||||
} SqlFunctionCtx;
|
} SqlFunctionCtx;
|
||||||
|
|
||||||
typedef struct tExprNode {
|
typedef struct tExprNode {
|
||||||
|
|
|
@ -592,9 +592,16 @@ void cleanupResultInfoInStream(SExecTaskInfo* pTaskInfo, void* pState, SExprSupp
|
||||||
int32_t numOfExprs = pSup->numOfExprs;
|
int32_t numOfExprs = pSup->numOfExprs;
|
||||||
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
||||||
SqlFunctionCtx* pCtx = pSup->pCtx;
|
SqlFunctionCtx* pCtx = pSup->pCtx;
|
||||||
|
int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
|
||||||
|
bool needCleanup = false;
|
||||||
|
|
||||||
int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
|
for (int32_t j = 0; j < numOfExprs; ++j) {
|
||||||
|
needCleanup |= pCtx[j].needCleanup;
|
||||||
|
}
|
||||||
|
if (!needCleanup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
|
for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) {
|
||||||
SResultWindowInfo* pWinInfo = taosArrayGet(pGroupResInfo->pRows, i);
|
SResultWindowInfo* pWinInfo = taosArrayGet(pGroupResInfo->pRows, i);
|
||||||
SRowBuffPos* pPos = pWinInfo->pStatePos;
|
SRowBuffPos* pPos = pWinInfo->pStatePos;
|
||||||
|
@ -620,6 +627,13 @@ void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf*
|
||||||
int32_t numOfExprs = pSup->numOfExprs;
|
int32_t numOfExprs = pSup->numOfExprs;
|
||||||
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
int32_t* rowEntryOffset = pSup->rowEntryInfoOffset;
|
||||||
SqlFunctionCtx* pCtx = pSup->pCtx;
|
SqlFunctionCtx* pCtx = pSup->pCtx;
|
||||||
|
bool needCleanup = false;
|
||||||
|
for (int32_t j = 0; j < numOfExprs; ++j) {
|
||||||
|
needCleanup |= pCtx[j].needCleanup;
|
||||||
|
}
|
||||||
|
if (!needCleanup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// begin from last iter
|
// begin from last iter
|
||||||
void* pData = pGroupResInfo->dataPos;
|
void* pData = pGroupResInfo->dataPos;
|
||||||
|
|
|
@ -2111,6 +2111,7 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput,
|
||||||
pCtx->saveHandle.currentPage = -1;
|
pCtx->saveHandle.currentPage = -1;
|
||||||
pCtx->pStore = pStore;
|
pCtx->pStore = pStore;
|
||||||
pCtx->hasWindowOrGroup = false;
|
pCtx->hasWindowOrGroup = false;
|
||||||
|
pCtx->needCleanup = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 1; i < numOfOutput; ++i) {
|
for (int32_t i = 1; i < numOfOutput; ++i) {
|
||||||
|
|
|
@ -2114,6 +2114,7 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) {
|
||||||
SET_VAL(pResInfo, numOfElems, 1);
|
SET_VAL(pResInfo, numOfElems, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pCtx->needCleanup = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6078,6 +6079,7 @@ int32_t modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
|
||||||
pInfo->pHash = NULL;
|
pInfo->pHash = NULL;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
pCtx->needCleanup = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue