diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 81ed5b5ecd..0600d16d72 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -375,6 +375,7 @@ typedef struct SQuery { int8_t precision; SCmdMsgInfo* pCmdMsg; int32_t msgType; + SArray* pTargetTableList; SArray* pTableList; SArray* pDbList; bool showRewrite; diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 779fa68140..b4c0fd380e 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -222,6 +222,7 @@ typedef struct SRequestObj { int32_t code; SArray* dbList; SArray* tableList; + SArray* targetTableList; SQueryExecMetric metric; SRequestSendRecvBody body; bool syncQuery; // todo refactor: async query object diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index eecb22abe5..68f47ba915 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -235,6 +235,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) { TSWAP(pRequest->dbList, (*pQuery)->pDbList); TSWAP(pRequest->tableList, (*pQuery)->pTableList); + TSWAP(pRequest->targetTableList, (*pQuery)->pTargetTableList); } return code; @@ -851,7 +852,7 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { tscDebug("schedulerExecCb request type %s", TMSG_INFO(pRequest->type)); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { - removeMeta(pTscObj, pRequest->tableList); + removeMeta(pTscObj, pRequest->targetTableList); } // return to client @@ -1094,7 +1095,7 @@ SRequestObj* execQuery(uint64_t connId, const char* sql, int sqlLen, bool valida } while (retryNum++ < REQUEST_TOTAL_EXEC_TIMES); if (NEED_CLIENT_RM_TBLMETA_REQ(pRequest->type)) { - removeMeta(pRequest->pTscObj, pRequest->tableList); + removeMeta(pRequest->pTscObj, pRequest->targetTableList); } return pRequest; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 416d50d987..b04b4ea2aa 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -687,6 +687,7 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { TSWAP(pRequest->dbList, (pQuery)->pDbList); TSWAP(pRequest->tableList, (pQuery)->pTableList); + TSWAP(pRequest->targetTableList, (pQuery)->pTargetTableList); destorySqlParseWrapper(pWrapper); diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 70edb32f2d..fa21f82d19 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -693,6 +693,7 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { TSWAP(pStmt->exec.pRequest->dbList, pStmt->sql.pQuery->pDbList); TSWAP(pStmt->exec.pRequest->tableList, pStmt->sql.pQuery->pTableList); + TSWAP(pStmt->exec.pRequest->targetTableList, pStmt->sql.pQuery->pTargetTableList); // if (STMT_TYPE_QUERY == pStmt->sql.queryRes) { // STMT_ERR_RET(stmtRestoreQueryFields(pStmt)); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 1424a522c4..c692693848 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -39,6 +39,7 @@ typedef struct STranslateContext { SCmdMsgInfo* pCmdMsg; SHashObj* pDbs; SHashObj* pTables; + SHashObj* pTargetTables; SExplainOptions* pExplainOpt; SParseMetaCache* pMetaCache; bool createStream; @@ -89,10 +90,10 @@ static int32_t collectUseDatabase(const SName* pName, SHashObj* pDbs) { return collectUseDatabaseImpl(dbFName, pDbs); } -static int32_t collectUseTable(const SName* pName, SHashObj* pDbs) { +static int32_t collectUseTable(const SName* pName, SHashObj* pTable) { char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); - return taosHashPut(pDbs, fullName, strlen(fullName), pName, sizeof(SName)); + return taosHashPut(pTable, fullName, strlen(fullName), pName, sizeof(SName)); } static int32_t getTableMetaImpl(STranslateContext* pCxt, const SName* pName, STableMeta** pMeta) { @@ -357,7 +358,8 @@ static int32_t initTranslateContext(SParseContext* pParseCxt, SParseMetaCache* p pCxt->pMetaCache = pMetaCache; pCxt->pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pCxt->pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - if (NULL == pCxt->pNsLevel || NULL == pCxt->pDbs || NULL == pCxt->pTables) { + pCxt->pTargetTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + if (NULL == pCxt->pNsLevel || NULL == pCxt->pDbs || NULL == pCxt->pTables || NULL == pCxt->pTargetTables) { return TSDB_CODE_OUT_OF_MEMORY; } return TSDB_CODE_SUCCESS; @@ -3933,6 +3935,9 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm SName tableName; tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &tableName), pReq->name); int32_t code = collectUseTable(&tableName, pCxt->pTables); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(&tableName, pCxt->pTargetTables); + } if (TSDB_CODE_SUCCESS == code) { code = buildRollupAst(pCxt, pStmt, pReq); } @@ -3953,11 +3958,14 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt } static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* pTableName, bool ignoreNotExists) { - SMDropStbReq dropReq = {0}; - tNameExtractFullName(pTableName, dropReq.name); - dropReq.igNotExists = ignoreNotExists; - - return buildCmdMsg(pCxt, TDMT_MND_DROP_STB, (FSerializeFunc)tSerializeSMDropStbReq, &dropReq); + int32_t code = collectUseTable(pTableName, pCxt->pTargetTables); + if (TSDB_CODE_SUCCESS == code) { + SMDropStbReq dropReq = {0}; + tNameExtractFullName(pTableName, dropReq.name); + dropReq.igNotExists = ignoreNotExists; + code = buildCmdMsg(pCxt, TDMT_MND_DROP_STB, (FSerializeFunc)tSerializeSMDropStbReq, &dropReq); + } + return code; } static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt) { @@ -5559,8 +5567,13 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) { int32_t code = checkCreateTable(pCxt, pStmt, false); SVgroupInfo info = {0}; + SName name; + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); if (TSDB_CODE_SUCCESS == code) { - code = getTableHashVgroup(pCxt, pStmt->dbName, pStmt->tableName, &info); + code = getTableHashVgroupImpl(pCxt, &name, &info); + } + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(&name, pCxt->pTargetTables); } SArray* pBufArray = NULL; if (TSDB_CODE_SUCCESS == code) { @@ -5829,6 +5842,11 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla if (TSDB_CODE_SUCCESS == code) { code = getTableMeta(pCxt, pStmt->useDbName, pStmt->useTableName, &pSuperTableMeta); } + if (TSDB_CODE_SUCCESS == code) { + SName name; + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + code = collectUseTable(&name, pCxt->pTargetTables); + } STag* pTag = NULL; SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN); @@ -5927,8 +5945,13 @@ static void addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SDropTableClause* p static int32_t buildDropTableVgroupHashmap(STranslateContext* pCxt, SDropTableClause* pClause, bool* pIsSuperTable, SHashObj* pVgroupHashmap) { + SName name; + toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); STableMeta* pTableMeta = NULL; - int32_t code = getTableMeta(pCxt, pClause->dbName, pClause->tableName, &pTableMeta); + int32_t code = getTableMetaImpl(pCxt, &name, &pTableMeta); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(&name, pCxt->pTargetTables); + } if (TSDB_CODE_SUCCESS == code && TSDB_SUPER_TABLE == pTableMeta->tableType) { *pIsSuperTable = true; @@ -6509,6 +6532,20 @@ static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery) { pTable = taosHashIterate(pCxt->pTables, pTable); } } + + if (NULL != pCxt->pTargetTables) { + taosArrayDestroy(pQuery->pTargetTableList); + pQuery->pTargetTableList = taosArrayInit(taosHashGetSize(pCxt->pTargetTables), sizeof(SName)); + if (NULL == pQuery->pTargetTableList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SName* pTable = taosHashIterate(pCxt->pTargetTables, NULL); + while (NULL != pTable) { + taosArrayPush(pQuery->pTargetTableList, pTable); + pTable = taosHashIterate(pCxt->pTargetTables, pTable); + } + } + return TSDB_CODE_SUCCESS; }