From 290f8700162daa9e7b12cc74b9d4fbeb79f5b989 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Wed, 18 Dec 2024 16:29:13 +0800 Subject: [PATCH 1/2] fix TD-33219 --- include/libs/parser/parser.h | 2 ++ source/client/src/clientStmt2.c | 3 +- source/libs/parser/src/parInsertStmt.c | 42 ++++++++++++++++++++++++++ tests/script/api/stmt2-performance.c | 30 +++++++++++++----- 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 95f522f504..23ad151787 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -137,6 +137,8 @@ int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf); int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset); int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, bool rebuildCreateTb); +int32_t qRebuildStmt2DataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, + bool rebuildCreateTb, const char* tName, const char* sTableName); void qDestroyStmtDataBlock(STableDataCxt* pBlock); STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock); int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData); diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index a479c367e1..f63d12e298 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -488,7 +488,8 @@ static int32_t stmtTryAddTableVgroupInfo(STscStmt2* pStmt, int32_t* vgId) { static int32_t stmtRebuildDataBlock(STscStmt2* pStmt, STableDataCxt* pDataBlock, STableDataCxt** newBlock, uint64_t uid, uint64_t suid, int32_t vgId) { STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId)); - STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, suid, vgId, pStmt->sql.autoCreateTbl)); + STMT_ERR_RET(qRebuildStmt2DataBlock(newBlock, pDataBlock, uid, suid, vgId, pStmt->sql.autoCreateTbl, pStmt->bInfo.sname.tname, + pStmt->bInfo.stbFName)); STMT_DLOG("tableDataCxt rebuilt, uid:%" PRId64 ", vgId:%d", uid, vgId); diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index 4ecc18d189..cf476567d7 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -1212,6 +1212,48 @@ int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_ return TSDB_CODE_SUCCESS; } +int32_t qRebuildStmt2DataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, + bool rebuildCreateTb, const char* tName, const char* sTableName) { + int32_t code = qCloneStmtDataBlock(pDst, pSrc, false); + if (code) { + return code; + } + + STableDataCxt* pBlock = (STableDataCxt*)*pDst; + if (pBlock->pMeta) { + pBlock->pMeta->uid = uid; + pBlock->pMeta->vgId = vgId; + pBlock->pMeta->suid = suid; + } + + pBlock->pData->suid = suid; + pBlock->pData->uid = uid; + + if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) { + pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); + if (NULL == pBlock->pData->pCreateTbReq) { + return terrno; + } + SArray* pTagArray = taosArrayInit(0, sizeof(STagVal)); + SArray* tagName = taosArrayInit(0, TSDB_COL_NAME_LEN); + + STag* tag = NULL; + code = tTagNew(pTagArray, 1, false, &tag); + + code = insBuildCreateTbReq(pBlock->pData->pCreateTbReq, tName, tag, suid, sTableName, tagName, 0, + TSDB_DEFAULT_TABLE_TTL); + + taosArrayDestroy(pTagArray); + taosArrayDestroy(tagName); + taosMemoryFree(tag); + if (code) { + return code; + } + } + + return TSDB_CODE_SUCCESS; +} + STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock) { return ((STableDataCxt*)pDataBlock)->pMeta; } void qDestroyStmtDataBlock(STableDataCxt* pBlock) { diff --git a/tests/script/api/stmt2-performance.c b/tests/script/api/stmt2-performance.c index aa8e5b9450..a539affaf1 100644 --- a/tests/script/api/stmt2-performance.c +++ b/tests/script/api/stmt2-performance.c @@ -5,9 +5,9 @@ #include #include "taos.h" -int CTB_NUMS = 1000; -int ROW_NUMS = 10; -int CYC_NUMS = 5; +int CTB_NUMS = 2; +int ROW_NUMS = 2; +int CYC_NUMS = 2; void do_query(TAOS* taos, const char* sql) { TAOS_RES* result = taos_query(taos, sql); @@ -57,7 +57,7 @@ void do_stmt(TAOS* taos, const char* sql) { return; } int fieldNum = 0; - TAOS_FIELD_STB* pFields = NULL; + TAOS_FIELD_ALL* pFields = NULL; // code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields); // if (code != 0) { // printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt)); @@ -74,7 +74,7 @@ void do_stmt(TAOS* taos, const char* sql) { for (int i = 0; i < CTB_NUMS; i++) { tbs[i] = (char*)malloc(sizeof(char) * 20); sprintf(tbs[i], "ctb_%d", i); - createCtb(taos, tbs[i]); + // createCtb(taos, tbs[i]); } for (int r = 0; r < CYC_NUMS; r++) { // col params @@ -138,7 +138,24 @@ void do_stmt(TAOS* taos, const char* sql) { end = clock(); cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC; printf("stmt2-exec [%s] insert Time used: %f seconds\n", sql, cpu_time_used); + + for (int i = 0; i < CTB_NUMS; i++) { + free(tags[i]); + free(paramv[i]); + free(ts[i]); + free(b[i]); + } + free(ts); + free(b); + free(ts_len); + free(b_len); + free(paramv); + free(tags); } + for (int i = 0; i < CTB_NUMS; i++) { + free(tbs[i]); + } + free(tbs); // taos_stmt2_free_fields(stmt, pFields); taos_stmt2_close(stmt); @@ -200,10 +217,9 @@ int main() { exit(1); } - sleep(3); do_stmt(taos, "insert into db.stb(tbname,ts,b,t1,t2) values(?,?,?,?,?)"); // do_stmt(taos, "insert into db.? using db.stb tags(?,?)values(?,?)"); - do_taosc(taos); + // do_taosc(taos); taos_close(taos); taos_cleanup(); } From e0c4cdf664677daa32066686952256599ddb5821 Mon Sep 17 00:00:00 2001 From: "pengrongkun94@qq.com" Date: Thu, 19 Dec 2024 10:15:02 +0800 Subject: [PATCH 2/2] fix TD-33219 2 --- include/libs/parser/parser.h | 2 -- source/client/src/clientMain.c | 5 +++ source/client/src/clientStmt2.c | 11 +++---- source/libs/parser/src/parInsertStmt.c | 42 -------------------------- 4 files changed, 10 insertions(+), 50 deletions(-) diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 23ad151787..95f522f504 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -137,8 +137,6 @@ int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf); int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset); int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, bool rebuildCreateTb); -int32_t qRebuildStmt2DataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, - bool rebuildCreateTb, const char* tName, const char* sTableName); void qDestroyStmtDataBlock(STableDataCxt* pBlock); STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock); int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index dfc18da8cd..ecd835c76f 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -2182,6 +2182,11 @@ int taos_stmt2_bind_param(TAOS_STMT2 *stmt, TAOS_STMT2_BINDV *bindv, int32_t col if (code) { return code; } + } else { + code = stmtSetTbTags2(stmt, NULL); + if (code) { + return code; + } } if (bindv->bind_cols && bindv->bind_cols[i]) { diff --git a/source/client/src/clientStmt2.c b/source/client/src/clientStmt2.c index f63d12e298..340bc299fd 100644 --- a/source/client/src/clientStmt2.c +++ b/source/client/src/clientStmt2.c @@ -488,8 +488,7 @@ static int32_t stmtTryAddTableVgroupInfo(STscStmt2* pStmt, int32_t* vgId) { static int32_t stmtRebuildDataBlock(STscStmt2* pStmt, STableDataCxt* pDataBlock, STableDataCxt** newBlock, uint64_t uid, uint64_t suid, int32_t vgId) { STMT_ERR_RET(stmtTryAddTableVgroupInfo(pStmt, &vgId)); - STMT_ERR_RET(qRebuildStmt2DataBlock(newBlock, pDataBlock, uid, suid, vgId, pStmt->sql.autoCreateTbl, pStmt->bInfo.sname.tname, - pStmt->bInfo.stbFName)); + STMT_ERR_RET(qRebuildStmtDataBlock(newBlock, pDataBlock, uid, suid, vgId, pStmt->sql.autoCreateTbl)); STMT_DLOG("tableDataCxt rebuilt, uid:%" PRId64 ", vgId:%d", uid, vgId); @@ -1013,10 +1012,10 @@ int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) { } SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags; - if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) { - tscWarn("no tags or cols bound in sql, will not bound tags"); - return TSDB_CODE_SUCCESS; - } + // if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) { + // tscWarn("no tags or cols bound in sql, will not bound tags"); + // return TSDB_CODE_SUCCESS; + // } STableDataCxt** pDataBlock = (STableDataCxt**)taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index cf476567d7..4ecc18d189 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -1212,48 +1212,6 @@ int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_ return TSDB_CODE_SUCCESS; } -int32_t qRebuildStmt2DataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId, - bool rebuildCreateTb, const char* tName, const char* sTableName) { - int32_t code = qCloneStmtDataBlock(pDst, pSrc, false); - if (code) { - return code; - } - - STableDataCxt* pBlock = (STableDataCxt*)*pDst; - if (pBlock->pMeta) { - pBlock->pMeta->uid = uid; - pBlock->pMeta->vgId = vgId; - pBlock->pMeta->suid = suid; - } - - pBlock->pData->suid = suid; - pBlock->pData->uid = uid; - - if (rebuildCreateTb && NULL == pBlock->pData->pCreateTbReq) { - pBlock->pData->pCreateTbReq = taosMemoryCalloc(1, sizeof(SVCreateTbReq)); - if (NULL == pBlock->pData->pCreateTbReq) { - return terrno; - } - SArray* pTagArray = taosArrayInit(0, sizeof(STagVal)); - SArray* tagName = taosArrayInit(0, TSDB_COL_NAME_LEN); - - STag* tag = NULL; - code = tTagNew(pTagArray, 1, false, &tag); - - code = insBuildCreateTbReq(pBlock->pData->pCreateTbReq, tName, tag, suid, sTableName, tagName, 0, - TSDB_DEFAULT_TABLE_TTL); - - taosArrayDestroy(pTagArray); - taosArrayDestroy(tagName); - taosMemoryFree(tag); - if (code) { - return code; - } - } - - return TSDB_CODE_SUCCESS; -} - STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock) { return ((STableDataCxt*)pDataBlock)->pMeta; } void qDestroyStmtDataBlock(STableDataCxt* pBlock) {