From ae57aaae1c9b81d67591e68603471182a5db6b63 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Sat, 18 Jul 2020 00:02:52 +0800 Subject: [PATCH] [td-225] fix bugs in interp --- src/inc/tsdb.h | 7 +------ src/query/src/qExecutor.c | 4 ++-- src/tsdb/src/tsdbRead.c | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index a1e87a7437..2c67973298 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -175,11 +175,6 @@ typedef struct { SHashObj *map; // speedup acquire the tableQueryInfo from STableId } STableGroupInfo; -typedef struct SQueryRowCond { - int32_t rel; - TSKEY ts; -} SQueryRowCond; - /** * Get the data block iterator, starting from position according to the query condition * @@ -276,7 +271,7 @@ int32_t tsdbQuerySTableByTagCond(TSDB_REPO_T *tsdb, uint64_t uid, const char *pT * destory the created table group list, which is generated by tag query * @param pGroupList */ -void tsdbDestoryTableGroup(STableGroupInfo *pGroupList); +void tsdbDestroyTableGroup(STableGroupInfo *pGroupList); /** * create the table group result including only one table, used to handle the normal table query diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 52154c1ca1..cf13ace11f 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -5859,7 +5859,7 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SArray* pTableIdList, return pQInfo; _cleanup_qinfo: - tsdbDestoryTableGroup(pTableGroupInfo); + tsdbDestroyTableGroup(pTableGroupInfo); _cleanup_query: taosArrayDestroy(pGroupbyExpr->columnInfo); @@ -6009,7 +6009,7 @@ static void freeQInfo(SQInfo *pQInfo) { tfree(pQInfo->pBuf); taosArrayDestroy(pQInfo->tableqinfoGroupInfo.pGroupList); taosHashCleanup(pQInfo->tableqinfoGroupInfo.map); - tsdbDestoryTableGroup(&pQInfo->tableGroupInfo); + tsdbDestroyTableGroup(&pQInfo->tableGroupInfo); taosArrayDestroy(pQInfo->arrTableIdInfo); if (pQuery->pGroupbyExpr != NULL) { diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 884b52a54a..eb34805de4 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -107,7 +107,7 @@ typedef struct STsdbQueryHandle { bool locateStart; int32_t outputCapacity; int32_t realNumOfRows; - SArray* pTableCheckInfo; //SArray + SArray* pTableCheckInfo; // SArray int32_t activeIndex; bool checkFiles; // check file stage void* qinfo; // query info handle, for debug purpose @@ -191,6 +191,7 @@ TsdbQueryHandleT* tsdbQueryTables(TSDB_REPO_T* tsdb, STsdbQueryCond* pCond, STab free(pQueryHandle); return NULL; } + tsdbTakeMemSnapshot(pQueryHandle->pTsdb, &pQueryHandle->mem, &pQueryHandle->imem); size_t sizeOfGroup = taosArrayGetSize(groupList->pGroupList); @@ -348,6 +349,11 @@ static bool initTableMemIterator(STsdbQueryHandle* pHandle, STableCheckInfo* pCh return true; } +static void destroyTableMemIterator(STableCheckInfo* pCheckInfo) { + tSkipListDestroyIter(pCheckInfo->iter); + tSkipListDestroyIter(pCheckInfo->iiter); +} + SDataRow getSDataRowInTableMem(STableCheckInfo* pCheckInfo) { SDataRow rmem = NULL, rimem = NULL; if (pCheckInfo->iter) { @@ -1543,6 +1549,7 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { free(pSecQueryHandle); return false; } + tsdbTakeMemSnapshot(pSecQueryHandle->pTsdb, &pSecQueryHandle->mem, &pSecQueryHandle->imem); // allocate buffer in order to load data blocks from file @@ -1567,7 +1574,6 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { for (int32_t j = 0; j < si; ++j) { STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pQueryHandle->pTableCheckInfo, j); - STableCheckInfo info = { .lastKey = pSecQueryHandle->window.skey, .tableId = pCheckInfo->tableId, @@ -1604,9 +1610,9 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { pQueryHandle->window = pQueryHandle->cur.win; pQueryHandle->cur.rows = 2; pQueryHandle->cur.mixBlock = true; - pQueryHandle->order = TSDB_ORDER_ASC; + pQueryHandle->order = TSDB_ORDER_DESC; - int32_t step = -1; + int32_t step = -1;// one step for ascending order traverse for (int32_t j = 0; j < si; ++j) { STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pQueryHandle->pTableCheckInfo, j); pCheckInfo->lastKey = pQueryHandle->cur.win.ekey + step; @@ -1615,8 +1621,9 @@ bool tsdbNextDataBlock(TsdbQueryHandleT* pHandle) { tsdbCleanupQueryHandle(pSecQueryHandle); } -// disable it after retrieve data - pQueryHandle->type = TSDB_QUERY_TYPE_ALL; + //disable it after retrieve data + pQueryHandle->type = TSDB_QUERY_TYPE_EXTERNAL; + pQueryHandle->checkFiles = false; return true; } @@ -2365,7 +2372,7 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo); for (int32_t i = 0; i < size; ++i) { STableCheckInfo* pTableCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i); - tSkipListDestroyIter(pTableCheckInfo->iter); + destroyTableMemIterator(pTableCheckInfo); if (pTableCheckInfo->pDataCols != NULL) { tfree(pTableCheckInfo->pDataCols->buf); @@ -2401,7 +2408,7 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { tfree(pQueryHandle); } -void tsdbDestoryTableGroup(STableGroupInfo *pGroupList) { +void tsdbDestroyTableGroup(STableGroupInfo *pGroupList) { assert(pGroupList != NULL); size_t numOfGroup = taosArrayGetSize(pGroupList->pGroupList); -- GitLab