[td-3662] <fix>: fix invalid write caused by top/bottom query.
This commit is contained in:
parent
49b78ead9e
commit
272494d1c5
|
@ -129,6 +129,8 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
|
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
|
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
|
||||||
bool tscGroupbyColumn(SQueryInfo* pQueryInfo);
|
bool tscGroupbyColumn(SQueryInfo* pQueryInfo);
|
||||||
|
bool tscIsTopbotQuery(SQueryInfo* pQueryInfo);
|
||||||
|
int32_t tscGetTopbotQueryParam(SQueryInfo* pQueryInfo);
|
||||||
|
|
||||||
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
|
||||||
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
|
||||||
|
|
|
@ -338,12 +338,19 @@ void tscCreateLocalMerger(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrde
|
||||||
pReducer->resColModel->capacity = pReducer->nResultBufSize;
|
pReducer->resColModel->capacity = pReducer->nResultBufSize;
|
||||||
pReducer->finalModel = pFFModel;
|
pReducer->finalModel = pFFModel;
|
||||||
|
|
||||||
|
int32_t expandFactor = 1;
|
||||||
if (finalmodel->rowSize > 0) {
|
if (finalmodel->rowSize > 0) {
|
||||||
pReducer->resColModel->capacity /= finalmodel->rowSize;
|
bool topBotQuery = tscIsTopbotQuery(pQueryInfo);
|
||||||
|
if (topBotQuery) {
|
||||||
|
expandFactor = tscGetTopbotQueryParam(pQueryInfo);
|
||||||
|
pReducer->resColModel->capacity /= (finalmodel->rowSize * expandFactor);
|
||||||
|
} else {
|
||||||
|
pReducer->resColModel->capacity /= finalmodel->rowSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(finalmodel->rowSize > 0 && finalmodel->rowSize <= pReducer->rowSize);
|
assert(finalmodel->rowSize > 0 && finalmodel->rowSize <= pReducer->rowSize);
|
||||||
pReducer->pFinalRes = calloc(1, pReducer->rowSize * pReducer->resColModel->capacity);
|
pReducer->pFinalRes = calloc(1, pReducer->rowSize * pReducer->resColModel->capacity * expandFactor);
|
||||||
|
|
||||||
if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL ||
|
if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL ||
|
||||||
pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) {
|
pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) {
|
||||||
|
|
|
@ -271,6 +271,41 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tscIsTopbotQuery(SQueryInfo* pQueryInfo) {
|
||||||
|
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
|
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||||
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
if (pExpr == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t functionId = pExpr->functionId;
|
||||||
|
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tscGetTopbotQueryParam(SQueryInfo* pQueryInfo) {
|
||||||
|
size_t numOfExprs = tscSqlExprNumOfExprs(pQueryInfo);
|
||||||
|
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||||
|
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||||
|
if (pExpr == NULL) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t functionId = pExpr->functionId;
|
||||||
|
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM) {
|
||||||
|
return pExpr->param[0].i64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void tscClearInterpInfo(SQueryInfo* pQueryInfo) {
|
void tscClearInterpInfo(SQueryInfo* pQueryInfo) {
|
||||||
if (!tscIsPointInterpQuery(pQueryInfo)) {
|
if (!tscIsPointInterpQuery(pQueryInfo)) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue