fix(query): fix coverity issues.
This commit is contained in:
parent
00e56d678b
commit
70adc0ea33
|
@ -194,7 +194,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
||||||
}
|
}
|
||||||
} else if ((pr->type & CACHESCAN_RETRIEVE_TYPE_ALL) == CACHESCAN_RETRIEVE_TYPE_ALL) {
|
} else if ((pr->type & CACHESCAN_RETRIEVE_TYPE_ALL) == CACHESCAN_RETRIEVE_TYPE_ALL) {
|
||||||
for (int32_t i = pr->tableIndex; i < numOfTables; ++i) {
|
for (int32_t i = pr->tableIndex; i < numOfTables; ++i) {
|
||||||
STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i);
|
STableKeyInfo* pKeyInfo = (STableKeyInfo*) taosArrayGet(pr->pTableList, i);
|
||||||
code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h);
|
code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -120,8 +120,12 @@ static SBlockData *loadLastBlock(SLDataIter *pIter, const char *idStr) {
|
||||||
return &pInfo->blockData[1];
|
return &pInfo->blockData[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pIter->pSttBlk == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// current block not loaded yet
|
||||||
pInfo->currentLoadBlockIndex ^= 1;
|
pInfo->currentLoadBlockIndex ^= 1;
|
||||||
if (pIter->pSttBlk != NULL) { // current block not loaded yet
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
|
|
||||||
SBlockData *pBlock = &pInfo->blockData[pInfo->currentLoadBlockIndex];
|
SBlockData *pBlock = &pInfo->blockData[pInfo->currentLoadBlockIndex];
|
||||||
|
@ -156,8 +160,6 @@ static SBlockData *loadLastBlock(SLDataIter *pIter, const char *idStr) {
|
||||||
tsdbDebug("last block index list:%d, %d, %s", pInfo->blockIndex[0], pInfo->blockIndex[1], idStr);
|
tsdbDebug("last block index list:%d, %d, %s", pInfo->blockIndex[0], pInfo->blockIndex[1], idStr);
|
||||||
|
|
||||||
pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1;
|
pIter->iRow = (pIter->backward) ? pInfo->blockData[pInfo->currentLoadBlockIndex].nRow : -1;
|
||||||
}
|
|
||||||
|
|
||||||
return &pInfo->blockData[pInfo->currentLoadBlockIndex];
|
return &pInfo->blockData[pInfo->currentLoadBlockIndex];
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -259,7 +261,8 @@ static int32_t binarySearchForStartRowIndex(uint64_t *uidList, int32_t num, uint
|
||||||
int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
|
int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t iStt, int8_t backward, uint64_t suid,
|
||||||
uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo *pBlockLoadInfo,
|
uint64_t uid, STimeWindow *pTimeWindow, SVersionRange *pRange, SSttBlockLoadInfo *pBlockLoadInfo,
|
||||||
const char *idStr) {
|
const char *idStr) {
|
||||||
int32_t code = 0;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
*pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
|
*pIter = taosMemoryCalloc(1, sizeof(SLDataIter));
|
||||||
if (*pIter == NULL) {
|
if (*pIter == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -336,7 +339,10 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t
|
||||||
(*pIter)->iRow = ((*pIter)->backward) ? (*pIter)->pSttBlk->nRow : -1;
|
(*pIter)->iRow = ((*pIter)->backward) ? (*pIter)->pSttBlk->nRow : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
taosMemoryFree(*pIter);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +479,7 @@ bool tLDataIterNextRow(SLDataIter *pIter, const char *idStr) {
|
||||||
|
|
||||||
int32_t iBlockL = pIter->iSttBlk;
|
int32_t iBlockL = pIter->iSttBlk;
|
||||||
SBlockData *pBlockData = loadLastBlock(pIter, idStr);
|
SBlockData *pBlockData = loadLastBlock(pIter, idStr);
|
||||||
if (pBlockData == NULL && terrno != TSDB_CODE_SUCCESS) {
|
if (pBlockData == NULL || terrno != TSDB_CODE_SUCCESS) {
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1047,10 +1047,15 @@ static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, v
|
||||||
return pLeftBlock->offset > pRightBlock->offset ? 1 : -1;
|
return pLeftBlock->offset > pRightBlock->offset ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter) {
|
static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr) {
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter);
|
||||||
if (pBlockInfo != NULL) {
|
if (pBlockInfo != NULL) {
|
||||||
STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
|
if (pScanInfo == NULL) {
|
||||||
|
tsdbError("failed to locate the uid:%"PRIu64" in query table uid list, %s", pBlockInfo->uid, idStr);
|
||||||
|
return TSDB_CODE_INVALID_PARA;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t* mapDataIndex = taosArrayGet(pScanInfo->pBlockList, pBlockInfo->tbBlockIdx);
|
int32_t* mapDataIndex = taosArrayGet(pScanInfo->pBlockList, pBlockInfo->tbBlockIdx);
|
||||||
tMapDataGetItemByIdx(&pScanInfo->mapData, *mapDataIndex, &pBlockIter->block, tGetDataBlk);
|
tMapDataGetItemByIdx(&pScanInfo->mapData, *mapDataIndex, &pBlockIter->block, tGetDataBlk);
|
||||||
}
|
}
|
||||||
|
@ -1135,7 +1140,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
||||||
|
|
||||||
pBlockIter->index = asc ? 0 : (numOfBlocks - 1);
|
pBlockIter->index = asc ? 0 : (numOfBlocks - 1);
|
||||||
cleanupBlockOrderSupporter(&sup);
|
cleanupBlockOrderSupporter(&sup);
|
||||||
doSetCurrentBlock(pBlockIter);
|
doSetCurrentBlock(pBlockIter, pReader->idStr);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1175,12 +1180,12 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte
|
||||||
taosMemoryFree(pTree);
|
taosMemoryFree(pTree);
|
||||||
|
|
||||||
pBlockIter->index = asc ? 0 : (numOfBlocks - 1);
|
pBlockIter->index = asc ? 0 : (numOfBlocks - 1);
|
||||||
doSetCurrentBlock(pBlockIter);
|
doSetCurrentBlock(pBlockIter, pReader->idStr);
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool blockIteratorNext(SDataBlockIter* pBlockIter) {
|
static bool blockIteratorNext(SDataBlockIter* pBlockIter, const char* idStr) {
|
||||||
bool asc = ASCENDING_TRAVERSE(pBlockIter->order);
|
bool asc = ASCENDING_TRAVERSE(pBlockIter->order);
|
||||||
|
|
||||||
int32_t step = asc ? 1 : -1;
|
int32_t step = asc ? 1 : -1;
|
||||||
|
@ -1189,7 +1194,7 @@ static bool blockIteratorNext(SDataBlockIter* pBlockIter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlockIter->index += step;
|
pBlockIter->index += step;
|
||||||
doSetCurrentBlock(pBlockIter);
|
doSetCurrentBlock(pBlockIter, idStr);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1260,7 +1265,7 @@ static int32_t setFileBlockActiveInBlockIter(SDataBlockIter* pBlockIter, int32_t
|
||||||
ASSERT(pBlockInfo->uid == fblock.uid && pBlockInfo->tbBlockIdx == fblock.tbBlockIdx);
|
ASSERT(pBlockInfo->uid == fblock.uid && pBlockInfo->tbBlockIdx == fblock.tbBlockIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
doSetCurrentBlock(pBlockIter);
|
doSetCurrentBlock(pBlockIter, "");
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2190,6 +2195,8 @@ static int32_t buildComposedDataBlockImpl(STsdbReader* pReader, STableBlockScanI
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
SSDataBlock* pResBlock = pReader->pResBlock;
|
SSDataBlock* pResBlock = pReader->pResBlock;
|
||||||
|
|
||||||
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter);
|
||||||
|
@ -2200,6 +2207,13 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) {
|
||||||
STableBlockScanInfo* pBlockScanInfo = NULL;
|
STableBlockScanInfo* pBlockScanInfo = NULL;
|
||||||
if (pBlockInfo != NULL) {
|
if (pBlockInfo != NULL) {
|
||||||
pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
|
if (pBlockScanInfo == NULL) {
|
||||||
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
|
tsdbError("failed to locate the uid:%"PRIu64" in query table uid list, total tables:%d, %s",
|
||||||
|
pBlockInfo->uid, taosHashGetSize(pReader->status.pTableMap), pReader->idStr);
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
|
||||||
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
|
SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter);
|
||||||
TSDBKEY keyInBuf = getCurrentKeyInBuf(pBlockScanInfo, pReader);
|
TSDBKEY keyInBuf = getCurrentKeyInBuf(pBlockScanInfo, pReader);
|
||||||
|
|
||||||
|
@ -2276,7 +2290,7 @@ _end:
|
||||||
pResBlock->info.rows, el, pReader->idStr);
|
pResBlock->info.rows, el, pReader->idStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setComposedBlockFlag(STsdbReader* pReader, bool composed) { pReader->status.composedDataBlock = composed; }
|
void setComposedBlockFlag(STsdbReader* pReader, bool composed) { pReader->status.composedDataBlock = composed; }
|
||||||
|
@ -2732,7 +2746,7 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) {
|
||||||
// current block are exhausted, try the next file block
|
// current block are exhausted, try the next file block
|
||||||
if (pDumpInfo->allDumped) {
|
if (pDumpInfo->allDumped) {
|
||||||
// try next data block in current file
|
// try next data block in current file
|
||||||
bool hasNext = blockIteratorNext(&pReader->status.blockIter);
|
bool hasNext = blockIteratorNext(&pReader->status.blockIter, pReader->idStr);
|
||||||
if (hasNext) { // check for the next block in the block accessed order list
|
if (hasNext) { // check for the next block in the block accessed order list
|
||||||
initBlockDumpInfo(pReader, pBlockIter);
|
initBlockDumpInfo(pReader, pBlockIter);
|
||||||
} else {
|
} else {
|
||||||
|
@ -3849,8 +3863,14 @@ static SArray* doRetrieveDataBlock(STsdbReader* pReader) {
|
||||||
return pReader->pResBlock->pDataBlock;
|
return pReader->pResBlock->pDataBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pStatus->blockIter);
|
SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter);
|
||||||
STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pFBlock->uid, sizeof(pFBlock->uid));
|
STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid));
|
||||||
|
if (pBlockScanInfo == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid,
|
||||||
|
taosHashGetSize(pReader->status.pTableMap), pReader->idStr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t code = doLoadFileBlockData(pReader, &pStatus->blockIter, &pStatus->fileBlockData, pBlockScanInfo->uid);
|
int32_t code = doLoadFileBlockData(pReader, &pStatus->blockIter, &pStatus->fileBlockData, pBlockScanInfo->uid);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
@ -3979,7 +3999,7 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa
|
||||||
int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows);
|
int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows);
|
||||||
pTableBlockInfo->blockRowsHisto[bucketIndex]++;
|
pTableBlockInfo->blockRowsHisto[bucketIndex]++;
|
||||||
|
|
||||||
hasNext = blockIteratorNext(&pStatus->blockIter);
|
hasNext = blockIteratorNext(&pStatus->blockIter, pReader->idStr);
|
||||||
} else {
|
} else {
|
||||||
code = initForFirstBlockInFile(pReader, pBlockIter);
|
code = initForFirstBlockInFile(pReader, pBlockIter);
|
||||||
if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) {
|
if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) {
|
||||||
|
|
|
@ -955,9 +955,7 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi
|
||||||
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode,
|
SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScanPhysiNode* pScanPhyNode,
|
||||||
const char* pUser, SExecTaskInfo* pTaskInfo);
|
const char* pUser, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pNode, SExecTaskInfo* pTaskInfo);
|
||||||
SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo,
|
|
||||||
int32_t numOfScalarExpr, bool mergeResult, SExecTaskInfo* pTaskInfo);
|
|
||||||
|
|
||||||
SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode,
|
SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pNode,
|
||||||
SExecTaskInfo* pTaskInfo);
|
SExecTaskInfo* pTaskInfo);
|
||||||
|
@ -981,9 +979,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream,
|
||||||
SExecTaskInfo* pTaskInfo, int32_t numOfChild);
|
SExecTaskInfo* pTaskInfo, int32_t numOfChild);
|
||||||
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode,
|
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode,
|
||||||
SExecTaskInfo* pTaskInfo);
|
SExecTaskInfo* pTaskInfo);
|
||||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode *pAggNode, SExecTaskInfo* pTaskInfo);
|
||||||
SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition,
|
|
||||||
SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo);
|
|
||||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid,
|
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid,
|
||||||
SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo);
|
SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo);
|
||||||
|
|
||||||
|
|
|
@ -162,7 +162,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
if (pTableList->map != NULL) {
|
if (pTableList->map != NULL) {
|
||||||
int64_t* groupId = taosHashGet(pTableList->map, &pInfo->pRes->info.uid, sizeof(int64_t));
|
int64_t* groupId = taosHashGet(pTableList->map, &pInfo->pRes->info.uid, sizeof(int64_t));
|
||||||
|
if (groupId != NULL) {
|
||||||
pInfo->pRes->info.groupId = *groupId;
|
pInfo->pRes->info.groupId = *groupId;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ASSERT(taosArrayGetSize(pTableList->pTableList) == 1);
|
ASSERT(taosArrayGetSize(pTableList->pTableList) == 1);
|
||||||
STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, 0);
|
STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, 0);
|
||||||
|
|
|
@ -227,9 +227,12 @@ static int32_t destroyDataSinker(SDataSinkHandle* pHandle) {
|
||||||
while (!taosQueueEmpty(pDeleter->pDataBlocks)) {
|
while (!taosQueueEmpty(pDeleter->pDataBlocks)) {
|
||||||
SDataDeleterBuf* pBuf = NULL;
|
SDataDeleterBuf* pBuf = NULL;
|
||||||
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
taosReadQitem(pDeleter->pDataBlocks, (void**)&pBuf);
|
||||||
|
|
||||||
|
if (pBuf != NULL) {
|
||||||
taosMemoryFreeClear(pBuf->pData);
|
taosMemoryFreeClear(pBuf->pData);
|
||||||
taosFreeQitem(pBuf);
|
taosFreeQitem(pBuf);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
taosCloseQueue(pDeleter->pDataBlocks);
|
taosCloseQueue(pDeleter->pDataBlocks);
|
||||||
taosThreadMutexDestroy(&pDeleter->mutex);
|
taosThreadMutexDestroy(&pDeleter->mutex);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -358,15 +358,15 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId,
|
||||||
SDataSinkMgtCfg cfg = {.maxDataBlockNum = 10000, .maxDataBlockNumPerQuery = 5000};
|
SDataSinkMgtCfg cfg = {.maxDataBlockNum = 10000, .maxDataBlockNumPerQuery = 5000};
|
||||||
code = dsDataSinkMgtInit(&cfg);
|
code = dsDataSinkMgtInit(&cfg);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
qError("failed to dsDataSinkMgtInit, code: %s", tstrerror(code));
|
qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handle) {
|
if (handle) {
|
||||||
void* pSinkParam = NULL;
|
void* pSinkParam = NULL;
|
||||||
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo, readHandle);
|
code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo, readHandle);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS || pSinkParam == NULL) {
|
||||||
qError("failed to createDataSinkParam, code: %s", tstrerror(code));
|
qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str);
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3047,32 +3047,40 @@ void cleanupExprSupp(SExprSupp* pSupp) {
|
||||||
taosMemoryFree(pSupp->rowEntryInfoOffset);
|
taosMemoryFree(pSupp->rowEntryInfoOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode,SExecTaskInfo* pTaskInfo) {
|
||||||
SSDataBlock* pResultBlock, SNode* pCondition, SExprInfo* pScalarExprInfo,
|
|
||||||
int32_t numOfScalarExpr, bool mergeResult, SExecTaskInfo* pTaskInfo) {
|
|
||||||
SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
|
SAggOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SAggOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
SSDataBlock* pResBlock = createResDataBlock(pAggNode->node.pOutputDataBlockDesc);
|
||||||
|
initBasicInfo(&pInfo->binfo, pResBlock);
|
||||||
|
|
||||||
|
int32_t numOfScalarExpr = 0;
|
||||||
|
SExprInfo* pScalarExprInfo = NULL;
|
||||||
|
if (pAggNode->pExprs != NULL) {
|
||||||
|
pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES;
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, keyBufSize, pTaskInfo->id.str);
|
|
||||||
|
int32_t num = 0;
|
||||||
|
SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num);
|
||||||
|
int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
initBasicInfo(&pInfo->binfo, pResultBlock);
|
|
||||||
code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr);
|
code = initExprSupp(&pInfo->scalarExprSup, pScalarExprInfo, numOfScalarExpr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->binfo.mergeResultBlock = mergeResult;
|
pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock;
|
||||||
pInfo->groupId = UINT64_MAX;
|
pInfo->groupId = UINT64_MAX;
|
||||||
pInfo->pCondition = pCondition;
|
pInfo->pCondition = pAggNode->node.pConditions;
|
||||||
pOperator->name = "TableAggregate";
|
pOperator->name = "TableAggregate";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG;
|
||||||
pOperator->blocking = true;
|
pOperator->blocking = true;
|
||||||
|
@ -3331,8 +3339,6 @@ static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPT
|
||||||
return pTaskInfo;
|
return pTaskInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
|
||||||
|
|
||||||
SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode);
|
SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode);
|
||||||
|
|
||||||
int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, SExecTaskInfo* pTaskInfo) {
|
int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, SExecTaskInfo* pTaskInfo) {
|
||||||
|
@ -3709,22 +3715,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
pOptr = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo);
|
pOptr = createProjectOperatorInfo(ops[0], (SProjectPhysiNode*)pPhyNode, pTaskInfo);
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_HASH_AGG == type) {
|
||||||
SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode;
|
SAggPhysiNode* pAggNode = (SAggPhysiNode*)pPhyNode;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num);
|
|
||||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
|
||||||
|
|
||||||
int32_t numOfScalarExpr = 0;
|
|
||||||
SExprInfo* pScalarExprInfo = NULL;
|
|
||||||
if (pAggNode->pExprs != NULL) {
|
|
||||||
pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pAggNode->pGroupKeys != NULL) {
|
if (pAggNode->pGroupKeys != NULL) {
|
||||||
SArray* pColList = extractColumnInfo(pAggNode->pGroupKeys);
|
pOptr = createGroupOperatorInfo(ops[0], pAggNode, pTaskInfo);
|
||||||
pOptr = createGroupOperatorInfo(ops[0], pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions,
|
|
||||||
pScalarExprInfo, numOfScalarExpr, pTaskInfo);
|
|
||||||
} else {
|
} else {
|
||||||
pOptr = createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pAggNode->node.pConditions,
|
pOptr = createAggregateOperatorInfo(ops[0], pAggNode, pTaskInfo);
|
||||||
pScalarExprInfo, numOfScalarExpr, pAggNode->mergeDataBlock, pTaskInfo);
|
|
||||||
}
|
}
|
||||||
} else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
|
} else if (QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL == type) {
|
||||||
SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
|
SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
|
||||||
|
@ -3814,39 +3808,6 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
||||||
return pOptr;
|
return pOptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* extractColumnInfo(SNodeList* pNodeList) {
|
|
||||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
|
||||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
|
||||||
if (pList == NULL) {
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
|
||||||
STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i);
|
|
||||||
|
|
||||||
if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN) {
|
|
||||||
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
|
||||||
|
|
||||||
SColumn c = extractColumnFromColumnNode(pColNode);
|
|
||||||
taosArrayPush(pList, &c);
|
|
||||||
} else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) {
|
|
||||||
SValueNode* pValNode = (SValueNode*)pNode->pExpr;
|
|
||||||
SColumn c = {0};
|
|
||||||
c.slotId = pNode->slotId;
|
|
||||||
c.colId = pNode->slotId;
|
|
||||||
c.type = pValNode->node.type;
|
|
||||||
c.bytes = pValNode->node.resType.bytes;
|
|
||||||
c.scale = pValNode->node.resType.scale;
|
|
||||||
c.precision = pValNode->node.resType.precision;
|
|
||||||
|
|
||||||
taosArrayPush(pList, &c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pList;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t extractTbscanInStreamOpTree(SOperatorInfo* pOperator, STableScanInfo** ppInfo) {
|
static int32_t extractTbscanInStreamOpTree(SOperatorInfo* pOperator, STableScanInfo** ppInfo) {
|
||||||
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
|
||||||
if (pOperator->numOfDownstream == 0) {
|
if (pOperator->numOfDownstream == 0) {
|
||||||
|
@ -4070,6 +4031,7 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead
|
||||||
|
|
||||||
(*pTaskInfo)->sql = sql;
|
(*pTaskInfo)->sql = sql;
|
||||||
sql = NULL;
|
sql = NULL;
|
||||||
|
|
||||||
(*pTaskInfo)->pSubplan = pPlan;
|
(*pTaskInfo)->pSubplan = pPlan;
|
||||||
(*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList,
|
(*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList,
|
||||||
pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user);
|
||||||
|
|
|
@ -30,6 +30,7 @@ static void* getCurrentDataGroupInfo(const SPartitionOperatorInfo* pInfo, SDa
|
||||||
static int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity);
|
static int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity);
|
||||||
static int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo, int32_t numOfCols, char* pData,
|
static int32_t setGroupResultOutputBuf(SOperatorInfo* pOperator, SOptrBasicInfo* binfo, int32_t numOfCols, char* pData,
|
||||||
int16_t bytes, uint64_t groupId, SDiskbasedBuf* pBuf, SAggSupporter* pAggSup);
|
int16_t bytes, uint64_t groupId, SDiskbasedBuf* pBuf, SAggSupporter* pAggSup);
|
||||||
|
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||||
|
|
||||||
static void freeGroupKey(void* param) {
|
static void freeGroupKey(void* param) {
|
||||||
SGroupKeys* pKey = (SGroupKeys*)param;
|
SGroupKeys* pKey = (SGroupKeys*)param;
|
||||||
|
@ -61,7 +62,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char**
|
||||||
|
|
||||||
int32_t numOfGroupCols = taosArrayGetSize(pGroupColList);
|
int32_t numOfGroupCols = taosArrayGetSize(pGroupColList);
|
||||||
for (int32_t i = 0; i < numOfGroupCols; ++i) {
|
for (int32_t i = 0; i < numOfGroupCols; ++i) {
|
||||||
SColumn* pCol = taosArrayGet(pGroupColList, i);
|
SColumn* pCol = (SColumn*) taosArrayGet(pGroupColList, i);
|
||||||
(*keyLen) += pCol->bytes; // actual data + null_flag
|
(*keyLen) += pCol->bytes; // actual data + null_flag
|
||||||
|
|
||||||
SGroupKeys key = {0};
|
SGroupKeys key = {0};
|
||||||
|
@ -396,41 +397,48 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
||||||
return buildGroupResultDataBlock(pOperator);
|
return buildGroupResultDataBlock(pOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode *pAggNode, SExecTaskInfo* pTaskInfo) {
|
||||||
SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition,
|
|
||||||
SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo) {
|
|
||||||
SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo));
|
SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
if (pInfo == NULL || pOperator == NULL) {
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->pGroupCols = pGroupColList;
|
SSDataBlock* pResBlock = createResDataBlock(pAggNode->node.pOutputDataBlockDesc);
|
||||||
pInfo->pCondition = pCondition;
|
initBasicInfo(&pInfo->binfo, pResBlock);
|
||||||
|
|
||||||
|
int32_t numOfScalarExpr = 0;
|
||||||
|
SExprInfo* pScalarExprInfo = NULL;
|
||||||
|
if (pAggNode->pExprs != NULL) {
|
||||||
|
pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pInfo->pGroupCols = extractColumnInfo(pAggNode->pGroupKeys);
|
||||||
|
pInfo->pCondition = pAggNode->node.pConditions;
|
||||||
|
|
||||||
int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr);
|
int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList);
|
int32_t num = 0;
|
||||||
|
SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num);
|
||||||
|
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, numOfCols, pInfo->groupKeyLen, pTaskInfo->id.str);
|
code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, pInfo->groupKeyLen, pTaskInfo->id.str);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
initBasicInfo(&pInfo->binfo, pResultBlock);
|
|
||||||
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
initResultRowInfo(&pInfo->binfo.resultRowInfo);
|
||||||
|
|
||||||
pOperator->name = "GroupbyAggOperator";
|
pOperator->name = "GroupbyAggOperator";
|
||||||
pOperator->blocking = true;
|
pOperator->blocking = true;
|
||||||
pOperator->status = OP_NOT_OPENED;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
// pOperator->operatorType = OP_Groupby;
|
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
|
||||||
|
@ -451,8 +459,6 @@ _error:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
||||||
// SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
|
||||||
|
|
||||||
SPartitionOperatorInfo* pInfo = pOperator->info;
|
SPartitionOperatorInfo* pInfo = pOperator->info;
|
||||||
|
|
||||||
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
|
for (int32_t j = 0; j < pBlock->info.rows; ++j) {
|
||||||
|
@ -760,7 +766,6 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
|
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &numOfCols);
|
SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &numOfCols);
|
||||||
|
|
||||||
pInfo->pGroupCols = extractPartitionColInfo(pPartNode->pPartitionKeys);
|
pInfo->pGroupCols = extractPartitionColInfo(pPartNode->pPartitionKeys);
|
||||||
|
|
||||||
if (pPartNode->pExprs != NULL) {
|
if (pPartNode->pExprs != NULL) {
|
||||||
|
@ -781,14 +786,13 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
uint32_t defaultPgsz = 0;
|
uint32_t defaultPgsz = 0;
|
||||||
uint32_t defaultBufsz = 0;
|
uint32_t defaultBufsz = 0;
|
||||||
|
|
||||||
SSDataBlock* pResBlock = createResDataBlock(pPartNode->node.pOutputDataBlockDesc);
|
pInfo->binfo.pRes = createResDataBlock(pPartNode->node.pOutputDataBlockDesc);
|
||||||
getBufferPgSize(pResBlock->info.rowSize, &defaultPgsz, &defaultBufsz);
|
getBufferPgSize(pInfo->binfo.pRes->info.rowSize, &defaultPgsz, &defaultBufsz);
|
||||||
|
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
terrno = TSDB_CODE_NO_AVAIL_DISK;
|
terrno = TSDB_CODE_NO_AVAIL_DISK;
|
||||||
pTaskInfo->code = terrno;
|
pTaskInfo->code = terrno;
|
||||||
qError("Create partition operator info failed since %s", terrstr(terrno));
|
qError("Create partition operator info failed since %s", terrstr(terrno));
|
||||||
blockDataDestroy(pResBlock);
|
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,8 +801,8 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->rowCapacity = blockDataGetCapacityInRow(pResBlock, getBufPageSize(pInfo->pBuf));
|
pInfo->rowCapacity = blockDataGetCapacityInRow(pInfo->binfo.pRes, getBufPageSize(pInfo->pBuf));
|
||||||
pInfo->columnOffset = setupColumnOffset(pResBlock, pInfo->rowCapacity);
|
pInfo->columnOffset = setupColumnOffset(pInfo->binfo.pRes, pInfo->rowCapacity);
|
||||||
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
|
@ -808,7 +812,6 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
|
||||||
pOperator->blocking = true;
|
pOperator->blocking = true;
|
||||||
pOperator->status = OP_NOT_OPENED;
|
pOperator->status = OP_NOT_OPENED;
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PARTITION;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PARTITION;
|
||||||
pInfo->binfo.pRes = pResBlock;
|
|
||||||
pOperator->exprSupp.numOfExprs = numOfCols;
|
pOperator->exprSupp.numOfExprs = numOfCols;
|
||||||
pOperator->exprSupp.pExprInfo = pExprInfo;
|
pOperator->exprSupp.pExprInfo = pExprInfo;
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
|
@ -1102,3 +1105,37 @@ _error:
|
||||||
taosMemoryFreeClear(pOperator);
|
taosMemoryFreeClear(pOperator);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SArray* extractColumnInfo(SNodeList* pNodeList) {
|
||||||
|
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||||
|
SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn));
|
||||||
|
if (pList == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||||
|
STargetNode* pNode = (STargetNode*)nodesListGetNode(pNodeList, i);
|
||||||
|
|
||||||
|
if (nodeType(pNode->pExpr) == QUERY_NODE_COLUMN) {
|
||||||
|
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
||||||
|
|
||||||
|
SColumn c = extractColumnFromColumnNode(pColNode);
|
||||||
|
taosArrayPush(pList, &c);
|
||||||
|
} else if (nodeType(pNode->pExpr) == QUERY_NODE_VALUE) {
|
||||||
|
SValueNode* pValNode = (SValueNode*)pNode->pExpr;
|
||||||
|
SColumn c = {0};
|
||||||
|
c.slotId = pNode->slotId;
|
||||||
|
c.colId = pNode->slotId;
|
||||||
|
c.type = pValNode->node.type;
|
||||||
|
c.bytes = pValNode->node.resType.bytes;
|
||||||
|
c.scale = pValNode->node.resType.scale;
|
||||||
|
c.precision = pValNode->node.resType.precision;
|
||||||
|
|
||||||
|
taosArrayPush(pList, &c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pList;
|
||||||
|
}
|
||||||
|
|
|
@ -59,15 +59,16 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
||||||
SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo) {
|
SSortMergeJoinPhysiNode* pJoinNode, SExecTaskInfo* pTaskInfo) {
|
||||||
SJoinOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SJoinOperatorInfo));
|
SJoinOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SJoinOperatorInfo));
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
|
|
||||||
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
if (pOperator == NULL || pInfo == NULL) {
|
if (pOperator == NULL || pInfo == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock* pResBlock = createResDataBlock(pJoinNode->node.pOutputDataBlockDesc);
|
|
||||||
|
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
|
SSDataBlock* pResBlock = createResDataBlock(pJoinNode->node.pOutputDataBlockDesc);
|
||||||
SExprInfo* pExprInfo = createExprInfo(pJoinNode->pTargets, NULL, &numOfCols);
|
SExprInfo* pExprInfo = createExprInfo(pJoinNode->pTargets, NULL, &numOfCols);
|
||||||
|
|
||||||
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
initResultSizeInfo(&pOperator->resultInfo, 4096);
|
||||||
|
|
||||||
pInfo->pRes = pResBlock;
|
pInfo->pRes = pResBlock;
|
||||||
|
@ -84,8 +85,18 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
||||||
|
|
||||||
if (pJoinNode->pOnConditions != NULL && pJoinNode->node.pConditions != NULL) {
|
if (pJoinNode->pOnConditions != NULL && pJoinNode->node.pConditions != NULL) {
|
||||||
pInfo->pCondAfterMerge = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
pInfo->pCondAfterMerge = nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||||
|
if (pInfo->pCondAfterMerge == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(pInfo->pCondAfterMerge);
|
SLogicConditionNode* pLogicCond = (SLogicConditionNode*)(pInfo->pCondAfterMerge);
|
||||||
pLogicCond->pParameterList = nodesMakeList();
|
pLogicCond->pParameterList = nodesMakeList();
|
||||||
|
if (pLogicCond->pParameterList == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->pOnConditions));
|
nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->pOnConditions));
|
||||||
nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->node.pConditions));
|
nodesListMakeAppend(&pLogicCond->pParameterList, nodesCloneNode(pJoinNode->node.pConditions));
|
||||||
pLogicCond->condType = LOGIC_COND_TYPE_AND;
|
pLogicCond->condType = LOGIC_COND_TYPE_AND;
|
||||||
|
@ -106,7 +117,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
||||||
|
|
||||||
pOperator->fpSet =
|
pOperator->fpSet =
|
||||||
createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL, NULL, NULL);
|
createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL, NULL, NULL);
|
||||||
int32_t code = appendDownstream(pOperator, pDownstream, numOfDownstream);
|
code = appendDownstream(pOperator, pDownstream, numOfDownstream);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
@ -114,9 +125,12 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
||||||
return pOperator;
|
return pOperator;
|
||||||
|
|
||||||
_error:
|
_error:
|
||||||
taosMemoryFree(pInfo);
|
if (pInfo != NULL) {
|
||||||
|
destroyMergeJoinOperator(pInfo);
|
||||||
|
}
|
||||||
|
|
||||||
taosMemoryFree(pOperator);
|
taosMemoryFree(pOperator);
|
||||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
pTaskInfo->code = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -494,7 +494,13 @@ void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* p
|
||||||
SScalarParam srcParam = {.numOfRows = pBlock->info.rows, .param = pMeta, .columnData = &infoData};
|
SScalarParam srcParam = {.numOfRows = pBlock->info.rows, .param = pMeta, .columnData = &infoData};
|
||||||
|
|
||||||
SScalarParam param = {.columnData = pColInfoData};
|
SScalarParam param = {.columnData = pColInfoData};
|
||||||
|
|
||||||
|
if (fpSet.process != NULL) {
|
||||||
fpSet.process(&srcParam, 1, ¶m);
|
fpSet.process(&srcParam, 1, ¶m);
|
||||||
|
} else {
|
||||||
|
qError("failed to get the corresponding callback function, functionId:%d", functionId);
|
||||||
|
}
|
||||||
|
|
||||||
colDataDestroy(&infoData);
|
colDataDestroy(&infoData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -719,12 +719,16 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size
|
||||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||||
SDataBlockDescNode* pDescNode = pPhyNode->pOutputDataBlockDesc;
|
SDataBlockDescNode* pDescNode = pPhyNode->pOutputDataBlockDesc;
|
||||||
|
|
||||||
pInfo->binfo.pRes = createResDataBlock(pDescNode);
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t rowSize = pInfo->binfo.pRes->info.rowSize;
|
if (pInfo == NULL || pOperator == NULL) {
|
||||||
if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) {
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pInfo->binfo.pRes = createResDataBlock(pDescNode);
|
||||||
|
int32_t rowSize = pInfo->binfo.pRes->info.rowSize;
|
||||||
|
ASSERT(rowSize < 100 * 1024 * 1024);
|
||||||
|
|
||||||
SArray* pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys);
|
SArray* pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys);
|
||||||
int32_t numOfOutputCols = 0;
|
int32_t numOfOutputCols = 0;
|
||||||
SArray* pColMatchColInfo =
|
SArray* pColMatchColInfo =
|
||||||
|
@ -737,6 +741,9 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size
|
||||||
pInfo->pSortInfo = pSortInfo;
|
pInfo->pSortInfo = pSortInfo;
|
||||||
pInfo->pColMatchInfo = pColMatchColInfo;
|
pInfo->pColMatchInfo = pColMatchColInfo;
|
||||||
pInfo->pInputBlock = pInputBlock;
|
pInfo->pInputBlock = pInputBlock;
|
||||||
|
pInfo->bufPageSize = getProperSortPageSize(rowSize);
|
||||||
|
pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); // one additional is reserved for merged result.
|
||||||
|
|
||||||
pOperator->name = "MultiwayMerge";
|
pOperator->name = "MultiwayMerge";
|
||||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE;
|
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE;
|
||||||
pOperator->blocking = false;
|
pOperator->blocking = false;
|
||||||
|
@ -744,15 +751,10 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size
|
||||||
pOperator->info = pInfo;
|
pOperator->info = pInfo;
|
||||||
pOperator->pTaskInfo = pTaskInfo;
|
pOperator->pTaskInfo = pTaskInfo;
|
||||||
|
|
||||||
pInfo->bufPageSize = getProperSortPageSize(rowSize);
|
|
||||||
|
|
||||||
// one additional is reserved for merged result.
|
|
||||||
pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1);
|
|
||||||
|
|
||||||
pOperator->fpSet = createOperatorFpSet(doOpenMultiwayMergeOperator, doMultiwayMerge, NULL, NULL,
|
pOperator->fpSet = createOperatorFpSet(doOpenMultiwayMergeOperator, doMultiwayMerge, NULL, NULL,
|
||||||
destroyMultiwayMergeOperatorInfo, NULL, NULL, getMultiwayMergeExplainExecInfo);
|
destroyMultiwayMergeOperatorInfo, NULL, NULL, getMultiwayMergeExplainExecInfo);
|
||||||
|
|
||||||
int32_t code = appendDownstream(pOperator, downStreams, numStreams);
|
code = appendDownstream(pOperator, downStreams, numStreams);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _error;
|
goto _error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,6 +251,7 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
terrno = TSDB_CODE_NO_AVAIL_DISK;
|
terrno = TSDB_CODE_NO_AVAIL_DISK;
|
||||||
printf("tHash Init failed since %s", terrstr(terrno));
|
printf("tHash Init failed since %s", terrstr(terrno));
|
||||||
|
taosMemoryFree(pHashObj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,6 +140,7 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSource
|
||||||
int32_t* sourceId, SArray* pPageIdList) {
|
int32_t* sourceId, SArray* pPageIdList) {
|
||||||
SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource));
|
SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||||
if (pSource == NULL) {
|
if (pSource == NULL) {
|
||||||
|
taosArrayDestroy(pPageIdList);
|
||||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,6 +156,7 @@ static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSource
|
||||||
int32_t numOfRows =
|
int32_t numOfRows =
|
||||||
(getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock))) / rowSize;
|
(getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock))) / rowSize;
|
||||||
ASSERT(numOfRows > 0);
|
ASSERT(numOfRows > 0);
|
||||||
|
|
||||||
return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows);
|
return blockDataEnsureCapacity(pSource->src.pBlock, numOfRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,6 +226,22 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
|
// multi-pass internal merge sort is required
|
||||||
|
if (pHandle->pBuf == NULL) {
|
||||||
|
if (!osTempSpaceAvailable()) {
|
||||||
|
code = TSDB_CODE_NO_AVAIL_DISK;
|
||||||
|
qError("Sort compare init failed since %s", terrstr(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize,
|
||||||
|
"sortComparInit", tsTempDir);
|
||||||
|
dBufSetPrintInfo(pHandle->pBuf);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (pHandle->type == SORT_SINGLESOURCE_SORT) {
|
if (pHandle->type == SORT_SINGLESOURCE_SORT) {
|
||||||
for (int32_t i = 0; i < cmpParam->numOfSources; ++i) {
|
for (int32_t i = 0; i < cmpParam->numOfSources; ++i) {
|
||||||
SSortSource* pSource = cmpParam->pSources[i];
|
SSortSource* pSource = cmpParam->pSources[i];
|
||||||
|
@ -245,22 +263,6 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int
|
||||||
releaseBufPage(pHandle->pBuf, pPage);
|
releaseBufPage(pHandle->pBuf, pPage);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// multi-pass internal merge sort is required
|
|
||||||
if (pHandle->pBuf == NULL) {
|
|
||||||
if (!osTempSpaceAvailable()) {
|
|
||||||
terrno = TSDB_CODE_NO_AVAIL_DISK;
|
|
||||||
code = terrno;
|
|
||||||
qError("Sort compare init failed since %s", terrstr(terrno));
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize,
|
|
||||||
"sortComparInit", tsTempDir);
|
|
||||||
dBufSetPrintInfo(pHandle->pBuf);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < cmpParam->numOfSources; ++i) {
|
for (int32_t i = 0; i < cmpParam->numOfSources; ++i) {
|
||||||
SSortSource* pSource = cmpParam->pSources[i];
|
SSortSource* pSource = cmpParam->pSources[i];
|
||||||
pSource->src.pBlock = pHandle->fetchfp(pSource->param);
|
pSource->src.pBlock = pHandle->fetchfp(pSource->param);
|
||||||
|
@ -507,12 +509,14 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
|
||||||
|
|
||||||
int32_t code = sortComparInit(&pHandle->cmpParam, pHandle->pOrderedSource, i * numOfInputSources, end, pHandle);
|
int32_t code = sortComparInit(&pHandle->cmpParam, pHandle->pOrderedSource, i * numOfInputSources, end, pHandle);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
taosArrayDestroy(pResList);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
code =
|
code =
|
||||||
tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn);
|
tMergeTreeCreate(&pHandle->pMergeTree, pHandle->cmpParam.numOfSources, &pHandle->cmpParam, pHandle->comparFn);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
taosArrayDestroy(pResList);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,12 +524,16 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
|
||||||
while (1) {
|
while (1) {
|
||||||
SSDataBlock* pDataBlock = getSortedBlockDataInner(pHandle, &pHandle->cmpParam, numOfRows);
|
SSDataBlock* pDataBlock = getSortedBlockDataInner(pHandle, &pHandle->cmpParam, numOfRows);
|
||||||
if (pDataBlock == NULL) {
|
if (pDataBlock == NULL) {
|
||||||
|
taosArrayDestroy(pResList);
|
||||||
|
taosArrayDestroy(pPageIdList);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t pageId = -1;
|
int32_t pageId = -1;
|
||||||
void* pPage = getNewBufPage(pHandle->pBuf, &pageId);
|
void* pPage = getNewBufPage(pHandle->pBuf, &pageId);
|
||||||
if (pPage == NULL) {
|
if (pPage == NULL) {
|
||||||
|
taosArrayDestroy(pResList);
|
||||||
|
taosArrayDestroy(pPageIdList);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue