Merge pull request #20561 from taosdata/fix/TS-2891-M
fix: select ins_columns from stb/tb
This commit is contained in:
commit
3ab55496c1
|
@ -457,6 +457,7 @@ typedef struct {
|
||||||
void* pIter;
|
void* pIter;
|
||||||
SMnode* pMnode;
|
SMnode* pMnode;
|
||||||
STableMetaRsp* pMeta;
|
STableMetaRsp* pMeta;
|
||||||
|
bool restore;
|
||||||
bool sysDbRsp;
|
bool sysDbRsp;
|
||||||
char db[TSDB_DB_FNAME_LEN];
|
char db[TSDB_DB_FNAME_LEN];
|
||||||
char filterTb[TSDB_TABLE_NAME_LEN];
|
char filterTb[TSDB_TABLE_NAME_LEN];
|
||||||
|
|
|
@ -324,7 +324,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) {
|
||||||
pReq->info.rsp = pRsp;
|
pReq->info.rsp = pRsp;
|
||||||
pReq->info.rspLen = size;
|
pReq->info.rspLen = size;
|
||||||
|
|
||||||
if (rowsRead == 0 || rowsRead < rowsToRead) {
|
if (rowsRead == 0 || ((rowsRead < rowsToRead) && !pShow->restore)) {
|
||||||
pRsp->completed = 1;
|
pRsp->completed = 1;
|
||||||
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
|
mDebug("show:0x%" PRIx64 ", retrieve completed", pShow->id);
|
||||||
mndReleaseShowObj(pShow, true);
|
mndReleaseShowObj(pShow, true);
|
||||||
|
|
|
@ -3113,9 +3113,18 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
|
|
||||||
char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(typeName, "SUPER_TABLE");
|
STR_TO_VARSTR(typeName, "SUPER_TABLE");
|
||||||
|
bool fetch = pShow->restore ? false : true;
|
||||||
|
pShow->restore = false;
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb);
|
if (fetch) {
|
||||||
if (pShow->pIter == NULL) break;
|
pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb);
|
||||||
|
if (pShow->pIter == NULL) break;
|
||||||
|
} else {
|
||||||
|
fetch = true;
|
||||||
|
void *pKey = taosHashGetKey(pShow->pIter, NULL);
|
||||||
|
pStb = sdbAcquire(pSdb, SDB_STB, pKey);
|
||||||
|
if (!pStb) continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (pDb != NULL && pStb->dbUid != pDb->uid) {
|
if (pDb != NULL && pStb->dbUid != pDb->uid) {
|
||||||
sdbRelease(pSdb, pStb);
|
sdbRelease(pSdb, pStb);
|
||||||
|
@ -3129,6 +3138,17 @@ static int32_t mndRetrieveStbCol(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
sdbRelease(pSdb, pStb);
|
sdbRelease(pSdb, pStb);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((numOfRows + pStb->numOfColumns) > rows) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
sdbRelease(pSdb, pStb);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE]));
|
varDataSetLen(stbName, strlen(&stbName[VARSTR_HEADER_SIZE]));
|
||||||
|
|
||||||
mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db);
|
mDebug("mndRetrieveStbCol get stable cols, stable name:%s, db:%s", pStb->name, pStb->db);
|
||||||
|
|
|
@ -157,7 +157,7 @@ typedef struct SMTbCursor SMTbCursor;
|
||||||
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
SMTbCursor *metaOpenTbCursor(SMeta *pMeta);
|
||||||
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
void metaCloseTbCursor(SMTbCursor *pTbCur);
|
||||||
int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType);
|
int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType);
|
||||||
int32_t metaTbCursorPrev(SMTbCursor *pTbCur);
|
int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -336,7 +336,7 @@ int32_t metaTbCursorNext(SMTbCursor *pTbCur, ETableType jumpTableType) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t metaTbCursorPrev(SMTbCursor *pTbCur) {
|
int32_t metaTbCursorPrev(SMTbCursor *pTbCur, ETableType jumpTableType) {
|
||||||
int ret;
|
int ret;
|
||||||
void *pBuf;
|
void *pBuf;
|
||||||
STbCfg tbCfg;
|
STbCfg tbCfg;
|
||||||
|
@ -350,7 +350,7 @@ int32_t metaTbCursorPrev(SMTbCursor *pTbCur) {
|
||||||
tDecoderClear(&pTbCur->mr.coder);
|
tDecoderClear(&pTbCur->mr.coder);
|
||||||
|
|
||||||
metaGetTableEntryByVersion(&pTbCur->mr, ((SUidIdxVal *)pTbCur->pVal)[0].version, *(tb_uid_t *)pTbCur->pKey);
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,9 +57,11 @@ typedef struct SSysTableScanInfo {
|
||||||
const char* pUser;
|
const char* pUser;
|
||||||
bool sysInfo;
|
bool sysInfo;
|
||||||
bool showRewrite;
|
bool showRewrite;
|
||||||
|
bool restore;
|
||||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
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.
|
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||||
SSysTableIndex* pIdx; // idx for local table meta
|
SSysTableIndex* pIdx; // idx for local table meta
|
||||||
|
SHashObj* pSchema;
|
||||||
SColMatchInfo matchInfo;
|
SColMatchInfo matchInfo;
|
||||||
SName name;
|
SName name;
|
||||||
SSDataBlock* pRes;
|
SSDataBlock* pRes;
|
||||||
|
@ -514,9 +516,23 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) {
|
||||||
pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta);
|
pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
SHashObj* stableSchema = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
if (pInfo->pSchema == NULL) {
|
||||||
taosHashSetFreeFp(stableSchema, tDeleteSSchemaWrapperForHash);
|
pInfo->pSchema = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
|
||||||
while ((ret = metaTbCursorNext(pInfo->pCur, TSDB_TABLE_MAX)) == 0) {
|
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 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 typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
|
||||||
|
@ -524,33 +540,36 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) {
|
||||||
|
|
||||||
if (pInfo->pCur->mr.me.type == TSDB_SUPER_TABLE) {
|
if (pInfo->pCur->mr.me.type == TSDB_SUPER_TABLE) {
|
||||||
qDebug("sysTableScanUserCols cursor get 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) {
|
if (schema == NULL) {
|
||||||
SSchemaWrapper* schemaWrapper = tCloneSSchemaWrapper(&pInfo->pCur->mr.me.stbEntry.schemaRow);
|
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;
|
continue;
|
||||||
} else if (pInfo->pCur->mr.me.type == TSDB_CHILD_TABLE) {
|
} else if (pInfo->pCur->mr.me.type == TSDB_CHILD_TABLE) {
|
||||||
qDebug("sysTableScanUserCols cursor get child table");
|
qDebug("sysTableScanUserCols cursor get child table");
|
||||||
STR_TO_VARSTR(typeName, "CHILD_TABLE");
|
STR_TO_VARSTR(typeName, "CHILD_TABLE");
|
||||||
STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name);
|
STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name);
|
||||||
|
|
||||||
int64_t suid = pInfo->pCur->mr.me.ctbEntry.suid;
|
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) {
|
if (schema != NULL) {
|
||||||
schemaRow = *(SSchemaWrapper**)schema;
|
schemaRow = *(SSchemaWrapper**)schema;
|
||||||
} else {
|
} else {
|
||||||
tDecoderClear(&pInfo->pCur->mr.coder);
|
SMetaReader smrSuperTable = {0};
|
||||||
int code = metaGetTableEntryByUid(&pInfo->pCur->mr, suid);
|
metaReaderInit(&smrSuperTable, pInfo->readHandle.meta, 0);
|
||||||
|
int code = metaGetTableEntryByUid(&smrSuperTable, suid);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
// terrno has been set by metaGetTableEntryByName, therefore, return directly
|
// terrno has been set by metaGetTableEntryByName, therefore, return directly
|
||||||
qError("sysTableScanUserCols get meta by suid:%" PRId64 " error, code:%d", suid, code);
|
qError("sysTableScanUserCols get meta by suid:%" PRId64 " error, code:%d", suid, code);
|
||||||
|
metaReaderClear(&smrSuperTable);
|
||||||
blockDataDestroy(dataBlock);
|
blockDataDestroy(dataBlock);
|
||||||
pInfo->loadInfo.totalRows = 0;
|
pInfo->loadInfo.totalRows = 0;
|
||||||
taosHashCleanup(stableSchema);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
schemaRow = &pInfo->pCur->mr.me.stbEntry.schemaRow;
|
SSchemaWrapper* schemaWrapper = tCloneSSchemaWrapper(&smrSuperTable.me.stbEntry.schemaRow);
|
||||||
|
taosHashPut(pInfo->pSchema, &suid, sizeof(int64_t), &schemaWrapper, POINTER_BYTES);
|
||||||
|
schemaRow = schemaWrapper;
|
||||||
|
metaReaderClear(&smrSuperTable);
|
||||||
}
|
}
|
||||||
} else if (pInfo->pCur->mr.me.type == TSDB_NORMAL_TABLE) {
|
} else if (pInfo->pCur->mr.me.type == TSDB_NORMAL_TABLE) {
|
||||||
qDebug("sysTableScanUserCols cursor get normal table");
|
qDebug("sysTableScanUserCols cursor get normal table");
|
||||||
|
@ -562,20 +581,19 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName);
|
if ((numOfRows + schemaRow->nCols) > pOperator->resultInfo.capacity) {
|
||||||
|
|
||||||
if (numOfRows >= pOperator->resultInfo.capacity) {
|
|
||||||
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo);
|
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo);
|
||||||
numOfRows = 0;
|
numOfRows = 0;
|
||||||
|
pInfo->restore = true;
|
||||||
|
|
||||||
if (pInfo->pRes->info.rows > 0) {
|
if (pInfo->pRes->info.rows > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
taosHashCleanup(stableSchema);
|
|
||||||
|
|
||||||
if (numOfRows > 0) {
|
if (numOfRows > 0) {
|
||||||
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo);
|
relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo);
|
||||||
numOfRows = 0;
|
numOfRows = 0;
|
||||||
|
@ -695,7 +713,7 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((smrSuperTable.me.stbEntry.schemaTag.nCols + numOfRows) > pOperator->resultInfo.capacity) {
|
if ((smrSuperTable.me.stbEntry.schemaTag.nCols + numOfRows) > pOperator->resultInfo.capacity) {
|
||||||
metaTbCursorPrev(pInfo->pCur);
|
metaTbCursorPrev(pInfo->pCur, TSDB_TABLE_MAX);
|
||||||
blockFull = true;
|
blockFull = true;
|
||||||
} else {
|
} else {
|
||||||
sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows,
|
sysTableUserTagsFillOneTableTags(pInfo, &smrSuperTable, &pInfo->pCur->mr, dbname, tableName, &numOfRows,
|
||||||
|
@ -1789,6 +1807,11 @@ void destroySysScanOperator(void* param) {
|
||||||
pInfo->pIdx = NULL;
|
pInfo->pIdx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(pInfo->pSchema) {
|
||||||
|
taosHashCleanup(pInfo->pSchema);
|
||||||
|
pInfo->pSchema = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pInfo->matchInfo.pList);
|
taosArrayDestroy(pInfo->matchInfo.pList);
|
||||||
taosMemoryFreeClear(pInfo->pUser);
|
taosMemoryFreeClear(pInfo->pUser);
|
||||||
|
|
||||||
|
|
|
@ -101,9 +101,38 @@ class TDTestCase:
|
||||||
tdSql.checkEqual(i[1],len(self.perf_list))
|
tdSql.checkEqual(i[1],len(self.perf_list))
|
||||||
elif i[0].lower() == self.dbname:
|
elif i[0].lower() == self.dbname:
|
||||||
tdSql.checkEqual(i[1],self.tbnum+1)
|
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 1 replica 1')
|
||||||
|
for i in range (5):
|
||||||
|
self.stb4096 = 'create table db2.stb%d (ts timestamp' % (i)
|
||||||
|
for j in range (4094 - i):
|
||||||
|
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))
|
||||||
|
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)
|
||||||
|
for j in range (4095 - i):
|
||||||
|
self.ntb4096 += ', c%d binary(10)' % (j)
|
||||||
|
self.ntb4096 += ')'
|
||||||
|
tdSql.execute(self.ntb4096)
|
||||||
|
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):
|
def run(self):
|
||||||
self.prepare_data()
|
self.prepare_data()
|
||||||
self.count_check()
|
self.count_check()
|
||||||
|
self.ins_columns_check()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
tdSql.close()
|
tdSql.close()
|
||||||
|
|
Loading…
Reference in New Issue