From 60188e82a6a686e08e2fd12d3e8132a68b92a8e3 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 28 Feb 2023 13:42:19 +0800 Subject: [PATCH 1/6] fix(query): fix coverity issue. --- source/dnode/vnode/src/tsdb/tsdbRead.c | 6 ++++-- source/libs/executor/src/executor.c | 2 +- source/libs/executor/src/executorimpl.c | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index c0331f5513..bc162e8f63 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -874,8 +874,10 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN pBlockNum->numOfBlocks += 1; } - if ((pScanInfo->pBlockList != NULL )&& (taosArrayGetSize(pScanInfo->pBlockList) > 0)) { - numOfQTable += 1; + if (pScanInfo->pBlockList != NULL) { + if (taosArrayGetSize(pScanInfo->pBlockList) > 0) { + numOfQTable += 1; + } } } diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index c599b479e6..ee0ae91cbd 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -471,7 +471,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, if (handle) { void* pSinkParam = NULL; code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo, readHandle); - if (code != TSDB_CODE_SUCCESS) { + if (code != TSDB_CODE_SUCCESS || pSinkParam == NULL) { qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str); goto _error; } diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index dd12baede3..052c0d8c1e 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -2015,6 +2015,11 @@ SSchemaWrapper* extractQueriedColumnSchema(SScanPhysiNode* pScanNode); int32_t extractTableSchemaInfo(SReadHandle* pHandle, SScanPhysiNode* pScanNode, SExecTaskInfo* pTaskInfo) { SMetaReader mr = {0}; + if (pHandle == NULL) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + metaReaderInit(&mr, pHandle->meta, 0); int32_t code = metaGetTableEntryByUidCache(&mr, pScanNode->uid); if (code != TSDB_CODE_SUCCESS) { From 4172041ec8f95cf848448c05b6239e017a1be5d4 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 28 Feb 2023 14:20:14 +0800 Subject: [PATCH 2/6] fix(query): fix error in displaying block distribution. --- source/dnode/vnode/src/tsdb/tsdbRead.c | 2 +- source/libs/function/src/builtinsimpl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index bc162e8f63..2cced6543c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -4680,7 +4680,7 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { } static int32_t getBucketIndex(int32_t startRow, int32_t bucketRange, int32_t numOfRows) { - return (numOfRows - startRow) / bucketRange; + return ((numOfRows - startRow) / bucketRange) - 1; } int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTableBlockInfo) { diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 5f8c35a841..ebe1ea4f05 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -5582,7 +5582,7 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t bucketRange = (pData->defMaxRows - pData->defMinRows) / numOfBuckets; for (int32_t i = 0; i < tListLen(pData->blockRowsHisto); ++i) { - len = sprintf(st + VARSTR_HEADER_SIZE, "%04d |", pData->defMinRows + bucketRange * i); + len = sprintf(st + VARSTR_HEADER_SIZE, "%04d |", pData->defMinRows + bucketRange * (i + 1)); int32_t num = 0; if (pData->blockRowsHisto[i] > 0) { From dc45ec26605964528a1b113ca82c900587572c73 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 28 Feb 2023 15:17:32 +0800 Subject: [PATCH 3/6] fix(query): set the correct bucket index. --- source/dnode/vnode/src/tsdb/tsdbRead.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 2cced6543c..e91f104c99 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -4679,8 +4679,13 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { return code; } -static int32_t getBucketIndex(int32_t startRow, int32_t bucketRange, int32_t numOfRows) { - return ((numOfRows - startRow) / bucketRange) - 1; +static int32_t getBucketIndex(int32_t startRow, int32_t bucketRange, int32_t numOfRows, int32_t numOfBucket) { + int32_t bucketIndex = ((numOfRows - startRow) / bucketRange); + if (bucketIndex == numOfBucket) { + bucketIndex -= 1; + } + + return bucketIndex; } int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTableBlockInfo) { @@ -4689,6 +4694,8 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa pTableBlockInfo->totalRows = 0; pTableBlockInfo->numOfVgroups = 1; + const int32_t numOfBuckets = 20.0; + // find the start data block in file SReaderStatus* pStatus = &pReader->status; @@ -4696,7 +4703,7 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa pTableBlockInfo->defMinRows = pc->minRows; pTableBlockInfo->defMaxRows = pc->maxRows; - int32_t bucketRange = ceil((pc->maxRows - pc->minRows) / 20.0); + int32_t bucketRange = ceil((pc->maxRows - pc->minRows) / numOfBuckets); pTableBlockInfo->numOfFiles += 1; @@ -4734,7 +4741,7 @@ int32_t tsdbGetFileBlocksDistInfo(STsdbReader* pReader, STableBlockDistInfo* pTa pTableBlockInfo->totalSize += pBlock->aSubBlock[0].szBlock; - int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows); + int32_t bucketIndex = getBucketIndex(pTableBlockInfo->defMinRows, bucketRange, numOfRows, numOfBuckets); pTableBlockInfo->blockRowsHisto[bucketIndex]++; hasNext = blockIteratorNext(&pStatus->blockIter, pReader->idStr); From 281c774f6e48994e2d5dc0f84db9e652c6ea0e7a Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 28 Feb 2023 16:04:38 +0800 Subject: [PATCH 4/6] fix(query): remove unused hash. --- source/util/src/thashutil.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/util/src/thashutil.c b/source/util/src/thashutil.c index 21b9359076..f9c7eb1f56 100644 --- a/source/util/src/thashutil.c +++ b/source/util/src/thashutil.c @@ -50,11 +50,6 @@ uint32_t taosDJB2Hash(const char *key, uint32_t len) { return hash; } -uint32_t xxHash(const char *key, uint32_t len) { - int32_t seed = 0xcc9e2d51; - return XXH32(key, len, seed); -} - uint32_t MurmurHash3_32(const char *key, uint32_t len) { const uint8_t *data = (const uint8_t *)key; const int32_t nblocks = len >> 2u; From 95c662993733db5fcc70c9a72c05c8825dbd7aad Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 28 Feb 2023 16:28:02 +0800 Subject: [PATCH 5/6] fix(query): check for the handle value. --- source/libs/executor/src/dataSinkMgt.c | 12 ++++++++++-- source/libs/executor/src/executor.c | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/source/libs/executor/src/dataSinkMgt.c b/source/libs/executor/src/dataSinkMgt.c index 2b50be33ad..cc09efdf83 100644 --- a/source/libs/executor/src/dataSinkMgt.c +++ b/source/libs/executor/src/dataSinkMgt.c @@ -37,10 +37,18 @@ int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHand switch ((int)nodeType(pDataSink)) { case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); - case QUERY_NODE_PHYSICAL_PLAN_DELETE: + case QUERY_NODE_PHYSICAL_PLAN_DELETE: { + if (pParam == NULL) { + return TSDB_CODE_QRY_INVALID_INPUT; + } return createDataDeleter(&gDataSinkManager, pDataSink, pHandle, pParam); - case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: + } + case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: { + if (pParam == NULL) { + return TSDB_CODE_QRY_INVALID_INPUT; + } return createDataInserter(&gDataSinkManager, pDataSink, pHandle, pParam); + } } qError("invalid input node type:%d, %s", nodeType(pDataSink), id); diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index 55c8ed23c8..347ac369d8 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -469,7 +469,7 @@ int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, if (handle) { void* pSinkParam = NULL; code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, pTaskInfo, readHandle); - if (code != TSDB_CODE_SUCCESS || pSinkParam == NULL) { + if (code != TSDB_CODE_SUCCESS) { qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str); goto _error; } From 744a942ae98d007b41cc1b08a6c8b4feec8eb986 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 28 Feb 2023 19:03:15 +0800 Subject: [PATCH 6/6] fix(query): remove the invalid null check. --- source/libs/executor/src/dataSinkMgt.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/source/libs/executor/src/dataSinkMgt.c b/source/libs/executor/src/dataSinkMgt.c index cc09efdf83..7fbde07f59 100644 --- a/source/libs/executor/src/dataSinkMgt.c +++ b/source/libs/executor/src/dataSinkMgt.c @@ -38,15 +38,9 @@ int32_t dsCreateDataSinker(const SDataSinkNode* pDataSink, DataSinkHandle* pHand case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: return createDataDispatcher(&gDataSinkManager, pDataSink, pHandle); case QUERY_NODE_PHYSICAL_PLAN_DELETE: { - if (pParam == NULL) { - return TSDB_CODE_QRY_INVALID_INPUT; - } return createDataDeleter(&gDataSinkManager, pDataSink, pHandle, pParam); } case QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT: { - if (pParam == NULL) { - return TSDB_CODE_QRY_INVALID_INPUT; - } return createDataInserter(&gDataSinkManager, pDataSink, pHandle, pParam); } }