From 020fa3dd06751e50c96b11b5ec82c82d79dc9411 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Sat, 8 May 2021 11:52:24 +0800 Subject: [PATCH] performance issue --- src/client/src/tscPrepare.c | 16 ++++++++++++++-- src/client/src/tscUtil.c | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index baff65d6b9..ec85dff359 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -49,7 +49,8 @@ typedef struct SMultiTbStmt { uint64_t currentUid; uint32_t tbNum; SStrToken tbname; - SHashObj *pTableHash; + SHashObj *pTableHash; + SHashObj *pTableBlockHashList; // data block for each table } SMultiTbStmt; typedef struct STscStmt { @@ -975,6 +976,7 @@ static void insertBatchClean(STscStmt* pStmt) { tfree(pCmd->pTableNameList); +/* STableDataBlocks** p = taosHashIterate(pCmd->pTableBlockHashList, NULL); STableDataBlocks* pOneTableBlock = *p; @@ -993,10 +995,12 @@ static void insertBatchClean(STscStmt* pStmt) { pOneTableBlock = *p; } +*/ pCmd->pDataBlocks = tscDestroyBlockArrayList(pCmd->pDataBlocks); pCmd->numOfTables = 0; + taosHashEmpty(pCmd->pTableBlockHashList); tscFreeSqlResult(pSql); tscFreeSubobj(pSql); tfree(pSql->pSubs); @@ -1136,6 +1140,10 @@ int taos_stmt_prepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { if (pStmt->mtb.pTableHash == NULL) { pStmt->mtb.pTableHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); } + if (pStmt->mtb.pTableBlockHashList == NULL) { + pStmt->mtb.pTableBlockHashList = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false); + } + return TSDB_CODE_SUCCESS; } @@ -1183,7 +1191,7 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { if (uid != NULL) { pStmt->mtb.currentUid = *uid; - STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pCmd->pTableBlockHashList, (const char*)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid)); + STableDataBlocks** t1 = (STableDataBlocks**)taosHashGet(pStmt->mtb.pTableBlockHashList, (const char*)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid)); if (t1 == NULL) { tscError("no table data block in hash list, uid:%" PRId64 , pStmt->mtb.currentUid); return TSDB_CODE_TSC_APP_ERROR; @@ -1191,6 +1199,8 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { SSubmitBlk* pBlk = (SSubmitBlk*) (*t1)->pData; pCmd->batchSize = pBlk->numOfRows; + + taosHashPut(pCmd->pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)t1, POINTER_BYTES); tscDebug("table:%s is already prepared, uid:%" PRIu64, name, pStmt->mtb.currentUid); return TSDB_CODE_SUCCESS; @@ -1236,6 +1246,8 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) { pStmt->mtb.currentUid = pTableMeta->id.uid; pStmt->mtb.tbNum++; + + taosHashPut(pStmt->mtb.pTableBlockHashList, (void *)&pStmt->mtb.currentUid, sizeof(pStmt->mtb.currentUid), (void*)&pBlock, POINTER_BYTES); taosHashPut(pStmt->mtb.pTableHash, name, strlen(name), (char*) &pTableMeta->id.uid, sizeof(pTableMeta->id.uid)); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index eb31048433..7a6842869a 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -1316,8 +1316,10 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, bool freeBlockMap) { // the length does not include the SSubmitBlk structure pBlocks->dataLen = htonl(finalLen); dataBuf->numOfTables += 1; + + pBlocks->numOfRows = 0; }else { - tscWarn("table %s data block is empty", pOneTableBlock->tableName.tname); + tscDebug("table %s data block is empty", pOneTableBlock->tableName.tname); } p = taosHashIterate(pCmd->pTableBlockHashList, p); -- GitLab