From 7ed966e3f19511adc24a18311a4cb7b47c2f99b0 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 12:33:34 +0800 Subject: [PATCH 01/15] fix: select ins_columns from stb/tb --- source/dnode/mnode/impl/src/mndShow.c | 2 +- source/dnode/mnode/impl/src/mndStb.c | 28 +++++++---- source/dnode/mnode/sdb/inc/sdb.h | 1 + source/dnode/mnode/sdb/src/sdbHash.c | 25 ++++++++++ source/libs/executor/src/sysscanoperator.c | 35 ++++++++----- .../0-others/information_schema.py | 49 +++++++++++++++---- 6 files changed, 107 insertions(+), 33 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 48d8e89bfe..188137311b 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -324,7 +324,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pReq->info.rsp = pRsp; pReq->info.rspLen = size; - if (rowsRead == 0 || rowsRead < rowsToRead) { + if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->pIter)) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 9e61364801..e6e4a15198 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -3113,22 +3113,22 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(typeName, "SUPER_TABLE"); + bool fetch = pShow->pIter ? false : true; while (numOfRows < rows) { - void *prevIter = pShow->pIter; - pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); - if (pShow->pIter == NULL) break; + if (fetch) { + pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); + if (pShow->pIter == NULL) break; + } else { + fetch = true; + sdbGet(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); + if (!pStb) continue; + } if (pDb != NULL && pStb->dbUid != pDb->uid) { sdbRelease(pSdb, pStb); continue; } - if ((numOfRows + pStb->numOfColumns) > rows) { - pShow->pIter = prevIter; - sdbRelease(pSdb, pStb); - break; - } - SName name = {0}; char stbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; mndExtractTbNameFromStbFullName(pStb->name, &stbName[VARSTR_HEADER_SIZE], TSDB_TABLE_NAME_LEN); @@ -3136,6 +3136,16 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB sdbRelease(pSdb, pStb); continue; } + + if ((numOfRows + pStb->numOfColumns) > rows) { + if (numOfRows == 0) { + mError("mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s", + rows, pStb->numOfColumns, pStb->name, pStb->db); + } + sdbRelease(pSdb, pStb); + break; + } + varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE])); mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db); diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index e9a9e425e3..43f47daa69 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -312,6 +312,7 @@ void sdbReleaseLock(SSdb *pSdb, void *pObj, bool lock); */ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock); +void sdbGet(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); /** * @brief Cancel a traversal diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 569c78a68c..4cee3d8772 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -390,6 +390,31 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { return ppRow; } +void sdbGet(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { + *ppObj = NULL; + + SHashObj *hash = sdbGetHash(pSdb, type); + if (hash == NULL) return; + + size_t keyLen = 0; + void *pKey = taosHashGetKey(pIter, &keyLen); + + sdbReadLock(pSdb, type); + + SSdbRow **ppRow = (SSdbRow **)taosHashGet(hash, pKey, keyLen); + if (ppRow != NULL) { + SSdbRow *pRow = *ppRow; + if (pRow == NULL || pRow->status != SDB_STATUS_READY) { + sdbUnLock(pSdb, type); + return; + } + atomic_add_fetch_32(&pRow->refCount, 1); + *ppObj = pRow->pObj; + } + + sdbUnLock(pSdb, type); +} + void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock) { *ppObj = NULL; diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 20766b38d6..ec227ceb23 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -60,6 +60,7 @@ typedef struct SSysTableScanInfo { SNode* pCondition; // db_name filter condition, to discard data that are not in current database SMTbCursor* pCur; // cursor for iterate the local table meta store. SSysTableIndex* pIdx; // idx for local table meta + SHashObj* pSchema; SColMatchInfo matchInfo; SName name; SSDataBlock* pRes; @@ -514,8 +515,11 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); } - SHashObj* stableSchema = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); - taosHashSetFreeFp(stableSchema, tDeleteSSchemaWrapperForHash); + if (pInfo->pSchema == NULL) { + pInfo->pSchema = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + taosHashSetFreeFp(pInfo->pSchema, tDeleteSSchemaWrapperForHash); + } + while ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0) { char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; @@ -524,33 +528,36 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { if (pInfo->pCur->mr.me.type == TSDB_SUPER_TABLE) { qDebug("sysTableScanUserCols cursor get super table"); - void* schema = taosHashGet(stableSchema, &pInfo->pCur->mr.me.uid, sizeof(int64_t)); + void* schema = taosHashGet(pInfo->pSchema, &pInfo->pCur->mr.me.uid, sizeof(int64_t)); if (schema == NULL) { SSchemaWrapper* schemaWrapper = tCloneSSchemaWrapper(&pInfo->pCur->mr.me.stbEntry.schemaRow); - taosHashPut(stableSchema, &pInfo->pCur->mr.me.uid, sizeof(int64_t), &schemaWrapper, POINTER_BYTES); + taosHashPut(pInfo->pSchema, &pInfo->pCur->mr.me.uid, sizeof(int64_t), &schemaWrapper, POINTER_BYTES); } continue; } else if (pInfo->pCur->mr.me.type == TSDB_CHILD_TABLE) { qDebug("sysTableScanUserCols cursor get child table"); STR_TO_VARSTR(typeName, "CHILD_TABLE"); STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name); - int64_t suid = pInfo->pCur->mr.me.ctbEntry.suid; - void* schema = taosHashGet(stableSchema, &pInfo->pCur->mr.me.ctbEntry.suid, sizeof(int64_t)); + void* schema = taosHashGet(pInfo->pSchema, &pInfo->pCur->mr.me.ctbEntry.suid, sizeof(int64_t)); if (schema != NULL) { schemaRow = *(SSchemaWrapper**)schema; } else { - tDecoderClear(&pInfo->pCur->mr.coder); - int code = metaGetTableEntryByUid(&pInfo->pCur->mr, suid); + SMetaReader metaReader = {0}; + metaReaderInit(&metaReader, pInfo->readHandle.meta, 0); + int code = metaGetTableEntryByUid(&metaReader, suid); if (code != TSDB_CODE_SUCCESS) { // terrno has been set by metaGetTableEntryByName, therefore, return directly qError("sysTableScanUserCols get meta by suid:%" PRId64 " error, code:%d", suid, code); + metaReaderClear(&metaReader); blockDataDestroy(dataBlock); pInfo->loadInfo.totalRows = 0; - taosHashCleanup(stableSchema); return NULL; } - schemaRow = &pInfo->pCur->mr.me.stbEntry.schemaRow; + SSchemaWrapper* schemaWrapper = tCloneSSchemaWrapper(&metaReader.me.stbEntry.schemaRow); + taosHashPut(pInfo->pSchema, &suid, sizeof(int64_t), &schemaWrapper, POINTER_BYTES); + schemaRow = schemaWrapper; + metaReaderClear(&metaReader); } } else if (pInfo->pCur->mr.me.type == TSDB_NORMAL_TABLE) { qDebug("sysTableScanUserCols cursor get normal table"); @@ -565,7 +572,6 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { if ((numOfRows + schemaRow->nCols) > pOperator->resultInfo.capacity) { relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; - metaTbCursorPrev(pInfo->pCur); if (pInfo->pRes->info.rows > 0) { @@ -576,8 +582,6 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { } } - taosHashCleanup(stableSchema); - if (numOfRows > 0) { relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; @@ -1791,6 +1795,11 @@ void destroySysScanOperator(void* param) { pInfo->pIdx = NULL; } + if(pInfo->pSchema) { + taosHashCleanup(pInfo->pSchema); + pInfo->pSchema = NULL; + } + taosArrayDestroy(pInfo->matchInfo.pList); taosMemoryFreeClear(pInfo->pUser); diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 23ddb12d79..fc5c062dd4 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -22,7 +22,7 @@ class TDTestCase: def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(), True) self.setsql = TDSetSql() self.dbname = 'db' self.stbname = 'stb' @@ -101,18 +101,47 @@ class TDTestCase: tdSql.checkEqual(i[1],len(self.perf_list)) elif i[0].lower() == self.dbname: tdSql.checkEqual(i[1],self.tbnum+1) - def ins_columns_check(self): - tdSql.execute('create database db2 vgroups 2 replica 1') - tdSql.execute('create table db2.stb2 (ts timestamp,c0 int,c1 int, c2 double, c3 float, c4 binary(1000), c5 nchar(100),c7 bigint, c8 bool, c9 smallint) tags(t0 int)') - for i in range(2000): - tdSql.execute("create table db2.ctb%d using db2.stb2 tags(%d)" %(i,i)) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type="CHILD_TABLE"') - tdSql.checkEqual(20000,len(tdSql.queryResult)) - print("number of ins_columns of child table in db2 is %s" % len(tdSql.queryResult)) + # def ins_columns_check(self): + # tdSql.execute('drop database if exists db2') + # tdSql.execute('create database if not exists db2 vgroups 2 replica 1') + # tdSql.execute('create table db2.stb2 (ts timestamp,c0 int,c1 int, c2 double, c3 float, c4 binary(1000), c5 nchar(100),c7 bigint, c8 bool, c9 smallint) tags(t0 int)') + # for i in range(2000): + # tdSql.execute("create table db2.ctb%d using db2.stb2 tags(%d)" %(i,i)) + # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type="CHILD_TABLE"') + # tdSql.checkEqual(20000,len(tdSql.queryResult)) + # print("number of ins_columns of child table in db2 is %s" % len(tdSql.queryResult)) + # def ins_columns_check(self): + # tdSql.execute('drop database if exists db2') + # tdSql.execute('create database if not exists db2 vgroups 1 replica 1') + # for i in range (5): + # self.stb4096 = 'create table db2.stb%d (ts timestamp' % (i) + # for j in range (4094 - i): + # # for j in range (499): + # self.stb4096 += ', c%d int' % (j) + # self.stb4096 += ') tags (t1 int)' + # tdSql.execute(self.stb4096) + # # print ("stb sql is %s" % (self.stb4096)) + # for k in range(10): + # tdSql.execute("create table db2.ctb_%d_%dc using db2.stb%d tags(%d)" %(i,k,i,k)) + # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') + # tdSql.checkEqual(20465,len(tdSql.queryResult)) + # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') + # tdSql.checkEqual(20465,len(tdSql.queryResult)) + + # for j in range (5): + # self.ntb4096 = 'create table db2.ntb%d (ts timestamp' % (j) + # for i in range (4095 - j): + # self.ntb4096 += ', c%d binary(10)' % (i) + # self.ntb4096 += ')' + # tdSql.execute(self.ntb4096) + # # print ("ntb sql is %s" % (self.ntb4096)) + # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') + # tdSql.checkEqual(20000,len(tdSql.queryResult)) + def run(self): self.prepare_data() self.count_check() - self.ins_columns_check() + # self.ins_columns_check() def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From a85e30efe610e8be578eab2f93394dcb8fbd548a Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 14:19:00 +0800 Subject: [PATCH 02/15] fix: select ins_columns from stb/ctb --- source/libs/executor/src/sysscanoperator.c | 8 ++- .../0-others/information_schema.py | 61 ++++++++----------- 2 files changed, 31 insertions(+), 38 deletions(-) diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index ec227ceb23..0744908167 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -57,6 +57,7 @@ typedef struct SSysTableScanInfo { const char* pUser; bool sysInfo; bool showRewrite; + bool resume; SNode* pCondition; // db_name filter condition, to discard data that are not in current database SMTbCursor* pCur; // cursor for iterate the local table meta store. SSysTableIndex* pIdx; // idx for local table meta @@ -520,12 +521,15 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { taosHashSetFreeFp(pInfo->pSchema, tDeleteSSchemaWrapperForHash); } - while ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0) { + int32_t resume = pInfo->resume; + pInfo->resume = false; + while (resume || ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0)) { char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; SSchemaWrapper* schemaRow = NULL; + if (resume) resume = false; if (pInfo->pCur->mr.me.type == TSDB_SUPER_TABLE) { qDebug("sysTableScanUserCols cursor get super table"); void* schema = taosHashGet(pInfo->pSchema, &pInfo->pCur->mr.me.uid, sizeof(int64_t)); @@ -572,7 +576,7 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { if ((numOfRows + schemaRow->nCols) > pOperator->resultInfo.capacity) { relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; - metaTbCursorPrev(pInfo->pCur); + pInfo->resume = true; if (pInfo->pRes->info.rows > 0) { break; diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index fc5c062dd4..e0c48e9608 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -101,47 +101,36 @@ class TDTestCase: tdSql.checkEqual(i[1],len(self.perf_list)) elif i[0].lower() == self.dbname: tdSql.checkEqual(i[1],self.tbnum+1) - # def ins_columns_check(self): - # tdSql.execute('drop database if exists db2') - # tdSql.execute('create database if not exists db2 vgroups 2 replica 1') - # tdSql.execute('create table db2.stb2 (ts timestamp,c0 int,c1 int, c2 double, c3 float, c4 binary(1000), c5 nchar(100),c7 bigint, c8 bool, c9 smallint) tags(t0 int)') - # for i in range(2000): - # tdSql.execute("create table db2.ctb%d using db2.stb2 tags(%d)" %(i,i)) - # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type="CHILD_TABLE"') - # tdSql.checkEqual(20000,len(tdSql.queryResult)) - # print("number of ins_columns of child table in db2 is %s" % len(tdSql.queryResult)) - # def ins_columns_check(self): - # tdSql.execute('drop database if exists db2') - # tdSql.execute('create database if not exists db2 vgroups 1 replica 1') - # for i in range (5): - # self.stb4096 = 'create table db2.stb%d (ts timestamp' % (i) - # for j in range (4094 - i): - # # for j in range (499): - # self.stb4096 += ', c%d int' % (j) - # self.stb4096 += ') tags (t1 int)' - # tdSql.execute(self.stb4096) - # # print ("stb sql is %s" % (self.stb4096)) - # for k in range(10): - # tdSql.execute("create table db2.ctb_%d_%dc using db2.stb%d tags(%d)" %(i,k,i,k)) - # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') - # tdSql.checkEqual(20465,len(tdSql.queryResult)) - # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') - # tdSql.checkEqual(20465,len(tdSql.queryResult)) + def ins_columns_check(self): + tdSql.execute('drop database if exists db2') + tdSql.execute('create database if not exists db2 vgroups 1 replica 1') + for i in range (5): + self.stb4096 = 'create table db2.stb%d (ts timestamp' % (i) + for j in range (4094 - i): + # for j in range (499): + self.stb4096 += ', c%d int' % (j) + self.stb4096 += ') tags (t1 int)' + tdSql.execute(self.stb4096) + for k in range(10): + tdSql.execute("create table db2.ctb_%d_%dc using db2.stb%d tags(%d)" %(i,k,i,k)) + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') + tdSql.checkEqual(20465,len(tdSql.queryResult)) + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') + tdSql.checkEqual(204650,len(tdSql.queryResult)) - # for j in range (5): - # self.ntb4096 = 'create table db2.ntb%d (ts timestamp' % (j) - # for i in range (4095 - j): - # self.ntb4096 += ', c%d binary(10)' % (i) - # self.ntb4096 += ')' - # tdSql.execute(self.ntb4096) - # # print ("ntb sql is %s" % (self.ntb4096)) - # tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') - # tdSql.checkEqual(20000,len(tdSql.queryResult)) + for i in range (5): + self.ntb4096 = 'create table db2.ntb%d (ts timestamp' % (i) + for j in range (4095 - i): + self.ntb4096 += ', c%d binary(10)' % (j) + self.ntb4096 += ')' + tdSql.execute(self.ntb4096) + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') + tdSql.checkEqual(204700,len(tdSql.queryResult)) def run(self): self.prepare_data() self.count_check() - # self.ins_columns_check() + self.ins_columns_check() def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) From ed3fc6bdf16f0b578647484c595110b90d5d9002 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 14:48:23 +0800 Subject: [PATCH 03/15] fix: select ins_columns from stb/ctb --- source/libs/executor/src/sysscanoperator.c | 12 ++++++------ tests/system-test/0-others/information_schema.py | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 0744908167..f114c58a0b 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -547,21 +547,21 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { if (schema != NULL) { schemaRow = *(SSchemaWrapper**)schema; } else { - SMetaReader metaReader = {0}; - metaReaderInit(&metaReader, pInfo->readHandle.meta, 0); - int code = metaGetTableEntryByUid(&metaReader, suid); + SMetaReader smrSuperTable = {0}; + metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, 0); + int code = metaGetTableEntryByUid(&smrSuperTable, suid); if (code != TSDB_CODE_SUCCESS) { // terrno has been set by metaGetTableEntryByName, therefore, return directly qError("sysTableScanUserCols get meta by suid:%" PRId64 " error, code:%d", suid, code); - metaReaderClear(&metaReader); + metaReaderClear(&smrSuperTable); blockDataDestroy(dataBlock); pInfo->loadInfo.totalRows = 0; return NULL; } - SSchemaWrapper* schemaWrapper = tCloneSSchemaWrapper(&metaReader.me.stbEntry.schemaRow); + SSchemaWrapper* schemaWrapper = tCloneSSchemaWrapper(&smrSuperTable.me.stbEntry.schemaRow); taosHashPut(pInfo->pSchema, &suid, sizeof(int64_t), &schemaWrapper, POINTER_BYTES); schemaRow = schemaWrapper; - metaReaderClear(&metaReader); + metaReaderClear(&smrSuperTable); } } else if (pInfo->pCur->mr.me.type == TSDB_NORMAL_TABLE) { qDebug("sysTableScanUserCols cursor get normal table"); diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index e0c48e9608..f4c07eec64 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -107,7 +107,6 @@ class TDTestCase: for i in range (5): self.stb4096 = 'create table db2.stb%d (ts timestamp' % (i) for j in range (4094 - i): - # for j in range (499): self.stb4096 += ', c%d int' % (j) self.stb4096 += ') tags (t1 int)' tdSql.execute(self.stb4096) @@ -125,7 +124,7 @@ class TDTestCase: self.ntb4096 += ')' tdSql.execute(self.ntb4096) tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') - tdSql.checkEqual(204700,len(tdSql.queryResult)) + tdSql.checkEqual(20470,len(tdSql.queryResult)) def run(self): self.prepare_data() From bfa7eabff6165c1f7209d1bde13ab0e024de5a84 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 14:50:57 +0800 Subject: [PATCH 04/15] fix: select ins_columns from stb/ctb --- tests/system-test/0-others/information_schema.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index f4c07eec64..8f1bf97138 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -114,6 +114,10 @@ class TDTestCase: tdSql.execute("create table db2.ctb_%d_%dc using db2.stb%d tags(%d)" %(i,k,i,k)) tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') tdSql.checkEqual(20465,len(tdSql.queryResult)) + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') + tdSql.checkEqual(20465,len(tdSql.queryResult)) + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') + tdSql.checkEqual(204650,len(tdSql.queryResult)) tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') tdSql.checkEqual(204650,len(tdSql.queryResult)) @@ -125,6 +129,8 @@ class TDTestCase: tdSql.execute(self.ntb4096) tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') tdSql.checkEqual(20470,len(tdSql.queryResult)) + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') + tdSql.checkEqual(20470,len(tdSql.queryResult)) def run(self): self.prepare_data() From 31d38dfd2331447637000f80fc5d01797a152b98 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 14:51:47 +0800 Subject: [PATCH 05/15] fix: select ins_columns from stb/ctb --- tests/system-test/0-others/information_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 8f1bf97138..e1c0e3d9c4 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -22,7 +22,7 @@ class TDTestCase: def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), True) + tdSql.init(conn.cursor()) self.setsql = TDSetSql() self.dbname = 'db' self.stbname = 'stb' From f297f676984998e1472b8a067e38f8a31a627902 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 16:40:29 +0800 Subject: [PATCH 06/15] fix: show obj --- source/dnode/mnode/impl/inc/mndDef.h | 1 + source/dnode/mnode/impl/src/mndShow.c | 4 +++- source/dnode/mnode/impl/src/mndStb.c | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index dfc3b3fde8..63b394a0ca 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -457,6 +457,7 @@ typedef struct { void* pIter; SMnode* pMnode; STableMetaRsp* pMeta; + bool resume; bool sysDbRsp; char db[TSDB_DB_FNAME_LEN]; char filterTb[TSDB_TABLE_NAME_LEN]; diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 188137311b..3e58ba1e28 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -133,6 +133,7 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) { showObj.id = showId; showObj.pMnode = pMnode; showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb)); + showObj.resume = false; memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); strncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN); @@ -324,7 +325,8 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pReq->info.rsp = pRsp; pReq->info.rspLen = size; - if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->pIter)) { + // if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->resume)) { + if (rowsRead == 0 || rowsRead < rowsToRead) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index e6e4a15198..f0e3361112 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -3113,7 +3113,8 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(typeName, "SUPER_TABLE"); - bool fetch = pShow->pIter ? false : true; + bool fetch = pShow->resume ? false : true; + pShow->resume = false; while (numOfRows < rows) { if (fetch) { pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); @@ -3138,6 +3139,7 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB } if ((numOfRows + pStb->numOfColumns) > rows) { + pShow->resume = true; if (numOfRows == 0) { mError("mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s", rows, pStb->numOfColumns, pStb->name, pStb->db); From b61a5ece5aaeadc3d90f96132091ddafa060a875 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 16:48:55 +0800 Subject: [PATCH 07/15] chore: more code --- source/dnode/mnode/impl/src/mndShow.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 3e58ba1e28..6068092ee1 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -133,7 +133,6 @@ static SShowObj *mndCreateShowObj(SMnode *pMnode, SRetrieveTableReq *pReq) { showObj.id = showId; showObj.pMnode = pMnode; showObj.type = convertToRetrieveType(pReq->tb, tListLen(pReq->tb)); - showObj.resume = false; memcpy(showObj.db, pReq->db, TSDB_DB_FNAME_LEN); strncpy(showObj.filterTb, pReq->filterTb, TSDB_TABLE_NAME_LEN); From 0c4e9f6646b4852dd98009d52c5651ad54b993a4 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 16:53:28 +0800 Subject: [PATCH 08/15] chore: more code --- source/dnode/mnode/impl/src/mndShow.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 6068092ee1..ffb027c7e2 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -324,8 +324,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pReq->info.rsp = pRsp; pReq->info.rspLen = size; - // if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->resume)) { - if (rowsRead == 0 || rowsRead < rowsToRead) { + if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->resume)) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); From 5d82380993e1b9a19d592b130b2a7aea465b1b09 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 16:55:53 +0800 Subject: [PATCH 09/15] chore: code optimization --- source/libs/executor/src/sysscanoperator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index f114c58a0b..59cb0d8426 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -524,12 +524,12 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { int32_t resume = pInfo->resume; pInfo->resume = false; while (resume || ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0)) { + if (resume) resume = false; char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; SSchemaWrapper* schemaRow = NULL; - if (resume) resume = false; if (pInfo->pCur->mr.me.type == TSDB_SUPER_TABLE) { qDebug("sysTableScanUserCols cursor get super table"); void* schema = taosHashGet(pInfo->pSchema, &pInfo->pCur->mr.me.uid, sizeof(int64_t)); From f3b4dbd2b5b5135f3a7a7283b7b5e804e916f473 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 17 Mar 2023 19:16:01 +0800 Subject: [PATCH 10/15] chore: test case optimization --- .../0-others/information_schema.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index e1c0e3d9c4..3199569879 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -112,14 +112,12 @@ class TDTestCase: tdSql.execute(self.stb4096) for k in range(10): tdSql.execute("create table db2.ctb_%d_%dc using db2.stb%d tags(%d)" %(i,k,i,k)) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') - tdSql.checkEqual(20465,len(tdSql.queryResult)) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') - tdSql.checkEqual(20465,len(tdSql.queryResult)) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') - tdSql.checkEqual(204650,len(tdSql.queryResult)) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') - tdSql.checkEqual(204650,len(tdSql.queryResult)) + for t in range (2): + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="SUPER_TABLE"') + tdSql.checkEqual(20465,len(tdSql.queryResult)) + for t in range (2): + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="CHILD_TABLE"') + tdSql.checkEqual(204650,len(tdSql.queryResult)) for i in range (5): self.ntb4096 = 'create table db2.ntb%d (ts timestamp' % (i) @@ -127,10 +125,9 @@ class TDTestCase: self.ntb4096 += ', c%d binary(10)' % (j) self.ntb4096 += ')' tdSql.execute(self.ntb4096) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') - tdSql.checkEqual(20470,len(tdSql.queryResult)) - tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') - tdSql.checkEqual(20470,len(tdSql.queryResult)) + for t in range (2): + tdSql.query(f'select * from information_schema.ins_columns where db_name="db2" and table_type=="NORMAL_TABLE"') + tdSql.checkEqual(20470,len(tdSql.queryResult)) def run(self): self.prepare_data() From 45a625f2dc3e167677d868b2131619390b449230 Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 18 Mar 2023 12:50:37 +0800 Subject: [PATCH 11/15] fix: add mem check --- source/libs/executor/src/sysscanoperator.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 59cb0d8426..2862d96c60 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -521,6 +521,14 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { taosHashSetFreeFp(pInfo->pSchema, tDeleteSSchemaWrapperForHash); } + if (!pInfo->pCur || !pInfo->pSchema) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + qError("sysTableScanUserCols failed since %s", terrstr(terrno)); + blockDataDestroy(dataBlock); + pInfo->loadInfo.totalRows = 0; + return NULL; + } + int32_t resume = pInfo->resume; pInfo->resume = false; while (resume || ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0)) { From d90c8e834a96bbb8b65bb000be36554179f0032b Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 18 Mar 2023 13:07:15 +0800 Subject: [PATCH 12/15] chore: var def optimization --- source/dnode/mnode/impl/inc/mndDef.h | 2 +- source/dnode/mnode/impl/src/mndStb.c | 6 +++--- source/libs/executor/src/sysscanoperator.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 63b394a0ca..e891eef1d8 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -457,7 +457,7 @@ typedef struct { void* pIter; SMnode* pMnode; STableMetaRsp* pMeta; - bool resume; + bool restore; bool sysDbRsp; char db[TSDB_DB_FNAME_LEN]; char filterTb[TSDB_TABLE_NAME_LEN]; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index f0e3361112..3f2761d0fa 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -3113,8 +3113,8 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; STR_TO_VARSTR(typeName, "SUPER_TABLE"); - bool fetch = pShow->resume ? false : true; - pShow->resume = false; + bool fetch = pShow->restore ? false : true; + pShow->restore = false; while (numOfRows < rows) { if (fetch) { pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); @@ -3139,7 +3139,7 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB } if ((numOfRows + pStb->numOfColumns) > rows) { - pShow->resume = true; + pShow->restore = true; if (numOfRows == 0) { mError("mndRetrieveStbCol failed to get stable cols since buf:%d less than result:%d, stable name:%s, db:%s", rows, pStb->numOfColumns, pStb->name, pStb->db); diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 2862d96c60..65b554a927 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -57,7 +57,7 @@ typedef struct SSysTableScanInfo { const char* pUser; bool sysInfo; bool showRewrite; - bool resume; + bool restore; SNode* pCondition; // db_name filter condition, to discard data that are not in current database SMTbCursor* pCur; // cursor for iterate the local table meta store. SSysTableIndex* pIdx; // idx for local table meta @@ -529,10 +529,10 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { return NULL; } - int32_t resume = pInfo->resume; - pInfo->resume = false; - while (resume || ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0)) { - if (resume) resume = false; + int32_t restore = pInfo->restore; + pInfo->restore = false; + while (restore || ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0)) { + if (restore) restore = false; char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; @@ -584,7 +584,7 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { if ((numOfRows + schemaRow->nCols) > pOperator->resultInfo.capacity) { relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; - pInfo->resume = true; + pInfo->restore = true; if (pInfo->pRes->info.rows > 0) { break; From 01074ed6cfd165fc6ff9ea840e48b8b89d2e164d Mon Sep 17 00:00:00 2001 From: kailixu Date: Sat, 18 Mar 2023 13:08:34 +0800 Subject: [PATCH 13/15] chore: var def optimization --- source/dnode/mnode/impl/src/mndShow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index ffb027c7e2..d80361da82 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -324,7 +324,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pReq->info.rsp = pRsp; pReq->info.rspLen = size; - if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->resume)) { + if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->restore)) { pRsp->completed = 1; mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id); mndReleaseShowObj(pShow, true); From 179579f204465f1d8d47c6e7658448b4ad4cea77 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 20 Mar 2023 17:41:22 +0800 Subject: [PATCH 14/15] chore: more code --- source/dnode/mnode/impl/src/mndStb.c | 4 ++- source/dnode/mnode/sdb/inc/sdb.h | 1 - source/dnode/mnode/sdb/src/sdbHash.c | 25 ------------------- source/dnode/vnode/inc/vnode.h | 2 +- source/dnode/vnode/src/meta/metaQuery.c | 4 +-- source/libs/executor/src/sysscanoperator.c | 9 ++++--- .../0-others/information_schema.py | 3 ++- 7 files changed, 13 insertions(+), 35 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 3f2761d0fa..85ea7a29f1 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -3121,7 +3121,9 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB if (pShow->pIter == NULL) break; } else { fetch = true; - sdbGet(pSdb, SDB_STB, pShow->pIter, (void **)&pStb); + size_t keyLen = 0; + void *pKey = taosHashGetKey(pShow->pIter, &keyLen); + pStb = sdbAcquire(pSdb, SDB_STB, pKey); if (!pStb) continue; } diff --git a/source/dnode/mnode/sdb/inc/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h index 43f47daa69..e9a9e425e3 100644 --- a/source/dnode/mnode/sdb/inc/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -312,7 +312,6 @@ void sdbReleaseLock(SSdb *pSdb, void *pObj, bool lock); */ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock); -void sdbGet(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj); /** * @brief Cancel a traversal diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 4cee3d8772..569c78a68c 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -390,31 +390,6 @@ void *sdbFetch(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { return ppRow; } -void sdbGet(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj) { - *ppObj = NULL; - - SHashObj *hash = sdbGetHash(pSdb, type); - if (hash == NULL) return; - - size_t keyLen = 0; - void *pKey = taosHashGetKey(pIter, &keyLen); - - sdbReadLock(pSdb, type); - - SSdbRow **ppRow = (SSdbRow **)taosHashGet(hash, pKey, keyLen); - if (ppRow != NULL) { - SSdbRow *pRow = *ppRow; - if (pRow == NULL || pRow->status != SDB_STATUS_READY) { - sdbUnLock(pSdb, type); - return; - } - atomic_add_fetch_32(&pRow->refCount, 1); - *ppObj = pRow->pObj; - } - - sdbUnLock(pSdb, type); -} - void *sdbFetchAll(SSdb *pSdb, ESdbType type, void *pIter, void **ppObj, ESdbStatus *status, bool lock) { *ppObj = NULL; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 29d1d0aafa..2d053d04ae 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -157,7 +157,7 @@ typedef struct SMTbCursor SMTbCursor; SMTbCursor *metaOpenTbCursor(SMeta *pMeta); void metaCloseTbCursor(SMTbCursor *pTbCur); int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType); -int32_t metaTbCursorPrev(SMTbCursor *pTbCur); +int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType); #endif diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 6ab322d26a..3376150d26 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -336,7 +336,7 @@ int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType) { return 0; } -int32_t metaTbCursorPrev(SMTbCursor *pTbCur) { +int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType) { int ret; void *pBuf; STbCfg tbCfg; @@ -350,7 +350,7 @@ int32_t metaTbCursorPrev(SMTbCursor *pTbCur) { tDecoderClear(&pTbCur->mr.coder); metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey); - if (pTbCur->mr.me.type == TSDB_SUPER_TABLE) { + if (pTbCur->mr.me.type == jumpTableType) { continue; } diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 7c2690d221..f24d3523c8 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -581,15 +581,16 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { continue; } - sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName); - - if (numOfRows >= pOperator->resultInfo.capacity) { + if ((numOfRows + schemaRow->nCols) > pOperator->resultInfo.capacity) { relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; + pInfo->restore = true; if (pInfo->pRes->info.rows > 0) { break; } + } else { + sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName); } } @@ -712,7 +713,7 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { } if ((smrSuperTable.me.stbEntry.schemaTag.nCols + numOfRows) > pOperator->resultInfo.capacity) { - metaTbCursorPrev(pInfo->pCur); + metaTbCursorPrev(pInfo->pCur, TSDB_TABLE_MAX); blockFull = true; } else { sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows, diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index daf348ff5b..6234e3cd92 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -22,7 +22,7 @@ class TDTestCase: def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(), True) self.setsql = TDSetSql() self.dbname = 'db' self.stbname = 'stb' @@ -132,6 +132,7 @@ class TDTestCase: def run(self): self.prepare_data() self.count_check() + self.ins_columns_check() def stop(self): tdSql.close() From aa4c1cb5ebda880e72bc761c3c08766de7d1d208 Mon Sep 17 00:00:00 2001 From: kailixu Date: Mon, 20 Mar 2023 17:44:34 +0800 Subject: [PATCH 15/15] chore: more code --- source/dnode/mnode/impl/src/mndStb.c | 3 +-- tests/system-test/0-others/information_schema.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 85ea7a29f1..c577097644 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -3121,8 +3121,7 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB if (pShow->pIter == NULL) break; } else { fetch = true; - size_t keyLen = 0; - void *pKey = taosHashGetKey(pShow->pIter, &keyLen); + void *pKey = taosHashGetKey(pShow->pIter, NULL); pStb = sdbAcquire(pSdb, SDB_STB, pKey); if (!pStb) continue; } diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 6234e3cd92..dd3bd4db83 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -22,7 +22,7 @@ class TDTestCase: def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), True) + tdSql.init(conn.cursor()) self.setsql = TDSetSql() self.dbname = 'db' self.stbname = 'stb'