From a061be9cdeaaa82cc64c8880e458e474be360332 Mon Sep 17 00:00:00 2001 From: hjxilinx Date: Sat, 4 Apr 2020 12:40:51 +0800 Subject: [PATCH] [td-98] --- src/client/src/tscSql.c | 2 +- src/query/src/queryExecutor.c | 2 +- src/vnode/tsdb/src/tsdbFile.c | 5 +++++ src/vnode/tsdb/src/tsdbRead.c | 16 ++++++++++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 1150bd479e..f33e589c82 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -793,7 +793,7 @@ void taos_free_result_imp(TAOS_RES *res, int keepCmd) { * be executed, and the retry efforts may result in double free the resources, e.g.,SRetrieveSupport */ if (pRes->code != TSDB_CODE_QUERY_CANCELLED && - ((pRes->numOfRows > 0 && pCmd->command < TSDB_SQL_LOCAL) || + ((pRes->numOfRows > 0 && pCmd->command < TSDB_SQL_LOCAL && pRes->completed == false) || (pRes->code == TSDB_CODE_SUCCESS && pRes->numOfRows == 0 && pCmd->command == TSDB_SQL_SELECT && pSql->pStream == NULL && pTableMetaInfo->pTableMeta != NULL))) { pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index 75823c4e2e..932c043377 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -5148,7 +5148,7 @@ static void singleTableQueryImpl(SQInfo* pQInfo) { int64_t st = taosGetTimestampUs(); // group by normal column, sliding window query, interval query are handled by interval query processor - if (pQuery->intervalTime != 0 || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { // interval (down sampling operation) + if (isIntervalQuery(pQuery) || isGroupbyNormalCol(pQuery->pGroupbyExpr)) { // interval (down sampling operation) tableIntervalProcessor(pQInfo); } else { if (isFixedOutputQuery(pQuery)) { diff --git a/src/vnode/tsdb/src/tsdbFile.c b/src/vnode/tsdb/src/tsdbFile.c index ff8da1cdad..bd6699eb84 100644 --- a/src/vnode/tsdb/src/tsdbFile.c +++ b/src/vnode/tsdb/src/tsdbFile.c @@ -147,6 +147,11 @@ void tsdbInitFileGroupIter(STsdbFileH *pFileH, SFileGroupIter *pIter, int direct } void tsdbSeekFileGroupIter(SFileGroupIter *pIter, int fid) { + if (pIter->numOfFGroups == 0) { + assert(pIter->pFileGroup == NULL); + return; + } + int flags = (pIter->direction == TSDB_FGROUP_ITER_FORWARD) ? TD_GE : TD_LE; void *ptr = taosbsearch(&fid, pIter->base, sizeof(SFileGroup), pIter->numOfFGroups, compFGroupKey, flags); if (ptr == NULL) { diff --git a/src/vnode/tsdb/src/tsdbRead.c b/src/vnode/tsdb/src/tsdbRead.c index c134ba257a..599d8bd347 100644 --- a/src/vnode/tsdb/src/tsdbRead.c +++ b/src/vnode/tsdb/src/tsdbRead.c @@ -745,12 +745,23 @@ static bool getQualifiedDataBlock(STsdbQueryHandle *pQueryHandle, STableCheckInf int32_t index = -1; int32_t tid = pCheckInfo->tableId.tid; - SFile* pFile = &pCheckInfo->pFileGroup->files[TSDB_FILE_TYPE_DATA]; - while (1) { + while (pCheckInfo->pFileGroup != NULL) { if ((fid = getFileCompInfo(pCheckInfo, pCheckInfo->pFileGroup)) < 0) { break; } + + SFile* pFile = &pCheckInfo->pFileGroup->files[TSDB_FILE_TYPE_DATA]; + + // no data block in current file, try next + if (pCheckInfo->compIndex[tid].numOfSuperBlocks == 0) { + dTrace("QInfo:%p no data block in file, fid:%d, tid:%d, try next", pQueryHandle->qinfo, + pCheckInfo->pFileGroup->fileId, tid); + + pCheckInfo->pFileGroup = tsdbGetFileGroupNext(&pCheckInfo->fileIter); + + continue; + } index = binarySearchForBlockImpl(pCheckInfo->pCompInfo->blocks, pCheckInfo->compIndex[tid].numOfSuperBlocks, pQueryHandle->order, key); @@ -792,6 +803,7 @@ static bool getQualifiedDataBlock(STsdbQueryHandle *pQueryHandle, STableCheckInf pCheckInfo->pDataCols = tdNewDataCols(1000, 2, 4096); tdInitDataCols(pCheckInfo->pDataCols, pCheckInfo->pTableObj->schema); + SFile* pFile = &pCheckInfo->pFileGroup->files[TSDB_FILE_TYPE_DATA]; if (pFile->fd == FD_INITIALIZER) { pFile->fd = open(pFile->fname, O_RDONLY); } -- GitLab