diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 04f441e0e4c2bc8f80b060757d878f5b0bb0eb6b..61e4bb37239896586efd5adfd7dc65ed7b8807dd 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -58,7 +58,7 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash int32_t qResetStmtDataBlock(void* block, bool keepBuf); int32_t qCloneStmtDataBlock(void** pDst, void* pSrc); void qFreeStmtDataBlock(void* pDataBlock); -int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid); +int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId); void qDestroyStmtDataBlock(void* pBlock); STableMeta *qGetTableMetaInDataBlock(void* pDataBlock); diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index d8262bc9a2e922b49400dd3250dc35c40f4a06c8..3a2363f8826c0962472f3e338d4aeed15ce25e3c 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -321,6 +321,18 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) { return TSDB_CODE_SUCCESS; } +int32_t stmtRebuildDataBlock(STscStmt* pStmt, STableDataBlocks *pDataBlock, STableDataBlocks **newBlock, uint64_t uid) { + SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); + SVgroupInfo vgInfo = {0}; + + STMT_ERR_RET(catalogGetTableHashVgroup(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &vgInfo)); + STMT_ERR_RET(taosHashPut(pStmt->exec.pVgHash, (const char*)&vgInfo.vgId, sizeof(vgInfo.vgId), (char*)&vgInfo, sizeof(vgInfo))); + + STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, vgInfo.vgId)); + + return TSDB_CODE_SUCCESS; +} + int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.needParse = true; pStmt->bInfo.inExecCache = false; @@ -344,14 +356,18 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { return TSDB_CODE_SUCCESS; } + if (NULL == pStmt->pCatalog) { + STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog)); + } + if (pStmt->sql.autoCreateTbl) { SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pStmt->bInfo.tbSuid, sizeof(pStmt->bInfo.tbSuid)); if (pCache) { pStmt->bInfo.needParse = false; STableDataBlocks* pNewBlock = NULL; - STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock, 0)); - + STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataBlock, &pNewBlock, 0)); + if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock, POINTER_BYTES)) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } @@ -362,9 +378,6 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { STMT_RET(stmtCleanBindInfo(pStmt)); } - if (NULL == pStmt->pCatalog) { - STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog)); - } STableMeta *pTableMeta = NULL; SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); @@ -419,7 +432,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) { pStmt->bInfo.tagsCached = true; STableDataBlocks* pNewBlock = NULL; - STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock, uid)); + STMT_ERR_RET(stmtRebuildDataBlock(pStmt, pCache->pDataBlock, &pNewBlock, uid)); if (taosHashPut(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName), &pNewBlock, POINTER_BYTES)) { STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); diff --git a/source/libs/parser/src/parInsertData.c b/source/libs/parser/src/parInsertData.c index d164df6db75e236f9afcda01cf76f29015d7c6a0..8deaad6091953d4dbf24d03ed91fb3787e14c18b 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -620,7 +620,7 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc) { return qResetStmtDataBlock(*pDst, false); } -int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid) { +int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid, int32_t vgId) { int32_t code = qCloneStmtDataBlock(pDst, pSrc); if (code) { return code; @@ -633,8 +633,11 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid) { return TSDB_CODE_OUT_OF_MEMORY; } + pBlock->vgId = vgId; + if (pBlock->pTableMeta) { pBlock->pTableMeta->uid = uid; + pBlock->pTableMeta->vgId = vgId; } memset(pBlock->pData, 0, sizeof(SSubmitBlk)); diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index 9016dca21eac0eec35d90910672b1efec8ae6031..4423ee3bc8ccc8107fcbcf2ff9c1e447ef3de299 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -230,12 +230,12 @@ CaseCtrl gCaseCtrl = { .optrIdxListNum = 0, .optrIdxList = NULL, .checkParamNum = false, - .printRes = true, + .printRes = false, .runTimes = 0, .caseIdx = -1, - .caseNum = 15, - .caseRunIdx = 8, - .caseRunNum = 15, + .caseNum = -1, + .caseRunIdx = -1, + .caseRunNum = -1, }; #endif @@ -3465,16 +3465,17 @@ void* runCaseList(TAOS *taos) { } void runAll(TAOS *taos) { -/* strcpy(gCaseCtrl.caseCatalog, "Normal Test"); printf("%s Begin\n", gCaseCtrl.caseCatalog); runCaseList(taos); -*/ + +#if 0 strcpy(gCaseCtrl.caseCatalog, "Auto Create Table Test"); gCaseCtrl.autoCreateTbl = true; printf("%s Begin\n", gCaseCtrl.caseCatalog); runCaseList(taos); gCaseCtrl.autoCreateTbl = false; +#endif /* strcpy(gCaseCtrl.caseCatalog, "Null Test");