diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 390cde96f0..76103a8fb7 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -433,93 +433,109 @@ static bool sysTableIsCondOnOneTable(SNode* pCond, char* condTable) { return false; } -static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - SStorageAPI* pAPI = &pTaskInfo->storageAPI; - +static SSDataBlock* doOptimizeTableNameFilter(SOperatorInfo* pOperator, SSDataBlock* dataBlock, char* dbname) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SStorageAPI* pAPI = &pTaskInfo->storageAPI; SSysTableScanInfo* pInfo = pOperator->info; - if (pOperator->status == OP_EXEC_DONE) { + int32_t numOfRows = 0; + + char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(tableName, pInfo->req.filterTb); + + SMetaReader smrTable = {0}; + pAPI->metaReaderFn.initReader(&smrTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); + int32_t code = pAPI->metaReaderFn.getTableEntryByName(&smrTable, pInfo->req.filterTb); + if (code != TSDB_CODE_SUCCESS) { + // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly + pAPI->metaReaderFn.clearReader(&smrTable); + pInfo->loadInfo.totalRows = 0; return NULL; } - blockDataCleanup(pInfo->pRes); - int32_t numOfRows = 0; + if (smrTable.me.type == TSDB_SUPER_TABLE) { + pAPI->metaReaderFn.clearReader(&smrTable); + pInfo->loadInfo.totalRows = 0; + return NULL; + } - SSDataBlock* dataBlock = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_COLS); - blockDataEnsureCapacity(dataBlock, pOperator->resultInfo.capacity); + if (smrTable.me.type == TSDB_CHILD_TABLE) { + int64_t suid = smrTable.me.ctbEntry.suid; + pAPI->metaReaderFn.clearReader(&smrTable); + pAPI->metaReaderFn.initReader(&smrTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); + code = pAPI->metaReaderFn.getTableEntryByUid(&smrTable, suid); + if (code != TSDB_CODE_SUCCESS) { + // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly + pAPI->metaReaderFn.clearReader(&smrTable); + pInfo->loadInfo.totalRows = 0; + return NULL; + } + } + char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + SSchemaWrapper* schemaRow = NULL; + if (smrTable.me.type == TSDB_SUPER_TABLE) { + schemaRow = &smrTable.me.stbEntry.schemaRow; + STR_TO_VARSTR(typeName, "CHILD_TABLE"); + } else if (smrTable.me.type == TSDB_NORMAL_TABLE) { + schemaRow = &smrTable.me.ntbEntry.schemaRow; + STR_TO_VARSTR(typeName, "NORMAL_TABLE"); + } + + sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName); + pAPI->metaReaderFn.clearReader(&smrTable); + + if (numOfRows > 0) { + relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); + numOfRows = 0; + } + + pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; + setOperatorCompleted(pOperator); + + qDebug("get cols success, total rows:%" PRIu64 ", current:%" PRId64 " %s", pInfo->loadInfo.totalRows, + pInfo->pRes->info.rows, GET_TASKID(pTaskInfo)); + return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; +} + +int32_t doExtractDbName(char* dbname, SSysTableScanInfo* pInfo, SStorageAPI* pAPI) { + SName sn = {0}; const char* db = NULL; int32_t vgId = 0; pAPI->metaFn.getBasicInfo(pInfo->readHandle.vnode, &db, &vgId, NULL, NULL); - - SName sn = {0}; - char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; tNameFromString(&sn, db, T_NAME_ACCT | T_NAME_DB); tNameGetDbName(&sn, varDataVal(dbname)); varDataSetLen(dbname, strlen(varDataVal(dbname))); - // optimize when sql like where table_name='tablename' and xxx. - if (pInfo->req.filterTb[0]) { - char tableName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - STR_TO_VARSTR(tableName, pInfo->req.filterTb); + return TSDB_CODE_SUCCESS; +} - SMetaReader smrTable = {0}; - pAPI->metaReaderFn.initReader(&smrTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); - int32_t code = pAPI->metaReaderFn.getTableEntryByName(&smrTable, pInfo->req.filterTb); - if (code != TSDB_CODE_SUCCESS) { - // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly - pAPI->metaReaderFn.clearReader(&smrTable); - blockDataDestroy(dataBlock); - pInfo->loadInfo.totalRows = 0; - return NULL; - } +static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SStorageAPI* pAPI = &pTaskInfo->storageAPI; + SSysTableScanInfo* pInfo = pOperator->info; + int32_t numOfRows = 0; + int32_t ret = 0; + char dbname[TSDB_DB_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + SSDataBlock* pDataBlock = NULL; - if (smrTable.me.type == TSDB_SUPER_TABLE) { - pAPI->metaReaderFn.clearReader(&smrTable); - blockDataDestroy(dataBlock); - pInfo->loadInfo.totalRows = 0; - return NULL; - } - - if (smrTable.me.type == TSDB_CHILD_TABLE) { - int64_t suid = smrTable.me.ctbEntry.suid; - pAPI->metaReaderFn.clearReader(&smrTable); - pAPI->metaReaderFn.initReader(&smrTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); - code = pAPI->metaReaderFn.getTableEntryByUid(&smrTable, suid); - if (code != TSDB_CODE_SUCCESS) { - // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, therefore, return directly - pAPI->metaReaderFn.clearReader(&smrTable); - blockDataDestroy(dataBlock); - pInfo->loadInfo.totalRows = 0; - return NULL; - } - } - - char typeName[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - SSchemaWrapper* schemaRow = NULL; - if (smrTable.me.type == TSDB_SUPER_TABLE) { - schemaRow = &smrTable.me.stbEntry.schemaRow; - STR_TO_VARSTR(typeName, "CHILD_TABLE"); - } else if (smrTable.me.type == TSDB_NORMAL_TABLE) { - schemaRow = &smrTable.me.ntbEntry.schemaRow; - STR_TO_VARSTR(typeName, "NORMAL_TABLE"); - } - - sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName); - pAPI->metaReaderFn.clearReader(&smrTable); - - if (numOfRows > 0) { - relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); - numOfRows = 0; - } - blockDataDestroy(dataBlock); - pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; - setOperatorCompleted(pOperator); - return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + blockDataCleanup(pInfo->pRes); + + pDataBlock = buildInfoSchemaTableMetaBlock(TSDB_INS_TABLE_COLS); + blockDataEnsureCapacity(pDataBlock, pOperator->resultInfo.capacity); + doExtractDbName(dbname, pInfo, pAPI); + + // optimize when sql like where table_name='tablename' and xxx. + if (pInfo->req.filterTb[0]) { + SSDataBlock* p = doOptimizeTableNameFilter(pOperator, pDataBlock, dbname); + blockDataDestroy(pDataBlock); + return p; } - int32_t ret = 0; if (pInfo->pCur == NULL) { pInfo->pCur = pAPI->metaFn.openTableMetaCursor(pInfo->readHandle.vnode); } else { @@ -534,7 +550,7 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { if (!pInfo->pCur || !pInfo->pSchema) { terrno = TSDB_CODE_OUT_OF_MEMORY; qError("sysTableScanUserCols failed since %s", terrstr(terrno)); - blockDataDestroy(dataBlock); + blockDataDestroy(pDataBlock); pInfo->loadInfo.totalRows = 0; return NULL; } @@ -553,7 +569,7 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { SSchemaWrapper* schemaRow = NULL; if (pInfo->pCur->mr.me.type == TSDB_SUPER_TABLE) { - qDebug("sysTableScanUserCols cursor get super table"); + qDebug("sysTableScanUserCols cursor get super table, %s", GET_TASKID(pTaskInfo)); 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); @@ -561,7 +577,8 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { } continue; } else if (pInfo->pCur->mr.me.type == TSDB_CHILD_TABLE) { - qDebug("sysTableScanUserCols cursor get child table"); + qDebug("sysTableScanUserCols cursor get child table, %s", GET_TASKID(pTaskInfo)); + STR_TO_VARSTR(typeName, "CHILD_TABLE"); STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name); int64_t suid = pInfo->pCur->mr.me.ctbEntry.suid; @@ -570,13 +587,14 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { schemaRow = *(SSchemaWrapper**)schema; } else { SMetaReader smrSuperTable = {0}; - pAPI->metaReaderFn.initReader(&smrSuperTable, pInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn); + pAPI->metaReaderFn.initReader(&smrSuperTable, pInfo->readHandle.vnode, META_READER_NOLOCK, &pAPI->metaFn); int code = pAPI->metaReaderFn.getTableEntryByUid(&smrSuperTable, suid); if (code != TSDB_CODE_SUCCESS) { // terrno has been set by pAPI->metaReaderFn.getTableEntryByName, 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, %s", suid, code, GET_TASKID(pTaskInfo)); + pAPI->metaReaderFn.clearReader(&smrSuperTable); - blockDataDestroy(dataBlock); + blockDataDestroy(pDataBlock); pInfo->loadInfo.totalRows = 0; return NULL; } @@ -586,17 +604,17 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { pAPI->metaReaderFn.clearReader(&smrSuperTable); } } else if (pInfo->pCur->mr.me.type == TSDB_NORMAL_TABLE) { - qDebug("sysTableScanUserCols cursor get normal table"); + qDebug("sysTableScanUserCols cursor get normal table, %s", GET_TASKID(pTaskInfo)); schemaRow = &pInfo->pCur->mr.me.ntbEntry.schemaRow; STR_TO_VARSTR(typeName, "NORMAL_TABLE"); STR_TO_VARSTR(tableName, pInfo->pCur->mr.me.name); } else { - qDebug("sysTableScanUserCols cursor get invalid table"); + qDebug("sysTableScanUserCols cursor get invalid table, %s", GET_TASKID(pTaskInfo)); continue; } if ((numOfRows + schemaRow->nCols) > pOperator->resultInfo.capacity) { - relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); + relocateAndFilterSysTagsScanResult(pInfo, numOfRows, pDataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; pInfo->restore = true; @@ -605,17 +623,17 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { break; } } else { - sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, dataBlock, tableName, schemaRow, typeName); + sysTableUserColsFillOneTableCols(pInfo, dbname, &numOfRows, pDataBlock, tableName, schemaRow, typeName); } } if (numOfRows > 0) { pAPI->metaFn.pauseTableMetaCursor(pInfo->pCur); - relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); + relocateAndFilterSysTagsScanResult(pInfo, numOfRows, pDataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; } - blockDataDestroy(dataBlock); + blockDataDestroy(pDataBlock); if (ret != 0) { pAPI->metaFn.closeTableMetaCursor(pInfo->pCur); pInfo->pCur = NULL; @@ -623,8 +641,7 @@ static SSDataBlock* sysTableScanUserCols(SOperatorInfo* pOperator) { } pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; - qDebug("sysTableScanUserCols get cols success, rows:%" PRIu64, pInfo->loadInfo.totalRows); - + qDebug("get cols success, rows:%" PRIu64 " %s", pInfo->loadInfo.totalRows, GET_TASKID(pTaskInfo)); return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index 789e5866ee..67c3d37960 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -130,7 +130,6 @@ class TDDnode: "locale": "en_US.UTF-8", "charset": "UTF-8", "asyncLog": "0", - "DebugFlag": "131", "mDebugFlag": "143", "dDebugFlag": "143", "vDebugFlag": "143", diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 33535f9c1d..63718417b4 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -19,6 +19,8 @@ from util.common import * from util.sqlset import * class TDTestCase: + updatecfgDict = {'qDebugFlag':135 , 'mDebugFlag':135} + def init(self, conn, logSql, replicaVar=1): self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) diff --git a/tests/system-test/2-query/qnodeCluster.py b/tests/system-test/2-query/qnodeCluster.py index 851b5bb1d1..fbddcd299c 100644 --- a/tests/system-test/2-query/qnodeCluster.py +++ b/tests/system-test/2-query/qnodeCluster.py @@ -20,9 +20,9 @@ import threading class TDTestCase: clientCfgDict = {'queryproxy': '1','debugFlag': 135} - clientCfgDict["debugFlag"] = 131 + clientCfgDict["debugFlag"] = 135 updatecfgDict = {'clientCfg': {}} - updatecfgDict = {'debugFlag': 131} + updatecfgDict = {'debugFlag': 135} updatecfgDict = {'keepColumnName': 1} updatecfgDict["clientCfg"] = clientCfgDict