From e85941b68318acd695d4c4297acf45020b90d6f8 Mon Sep 17 00:00:00 2001 From: Alex Duan <417921451@qq.com> Date: Tue, 4 Jun 2024 18:14:38 +0800 Subject: [PATCH] fix: stmt only bind one --- inc/bench.h | 1 + src/benchData.c | 75 +++++++++++++++++++++++------------------------ src/benchInsert.c | 8 +++++ 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/inc/bench.h b/inc/bench.h index 10b8bb9a..2e9d9951 100644 --- a/inc/bench.h +++ b/inc/bench.h @@ -1033,6 +1033,7 @@ typedef struct SThreadInfo_S { // check sql result char *csql; int32_t clen; // csql current write position + bool stmtBind; } threadInfo; typedef struct SQueryThreadInfo_S { diff --git a/src/benchData.c b/src/benchData.c index ebd3aedc..b94b05e0 100644 --- a/src/benchData.c +++ b/src/benchData.c @@ -1802,42 +1802,46 @@ uint32_t bindParamBatch(threadInfo *pThreadInfo, TAOS_STMT *stmt = pThreadInfo->conn->stmt; SSuperTable *stbInfo = pThreadInfo->stbInfo; uint32_t columnCount = stbInfo->cols->size; - memset(pThreadInfo->bindParams, 0, - (sizeof(TAOS_MULTI_BIND) * (columnCount + 1))); - memset(pThreadInfo->is_null, 0, batch); - - for (int c = 0; c < columnCount + 1; c++) { - TAOS_MULTI_BIND *param = - (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + - sizeof(TAOS_MULTI_BIND) * c); - char data_type; - if (c == 0) { - data_type = TSDB_DATA_TYPE_TIMESTAMP; - param->buffer_length = sizeof(int64_t); - param->buffer = pThreadInfo->bind_ts_array; - } else { - Field *col = benchArrayGet(stbInfo->cols, c - 1); - data_type = col->type; - if (childTbl->useOwnSample) { - ChildField *childCol = benchArrayGet(childTbl->childCols, c-1); - param->buffer = childCol->stmtData.data; - param->is_null = childCol->stmtData.is_null; + + if (!pThreadInfo->stmtBind) { + pThreadInfo->stmtBind = true; + memset(pThreadInfo->bindParams, 0, + (sizeof(TAOS_MULTI_BIND) * (columnCount + 1))); + memset(pThreadInfo->is_null, 0, batch); + + for (int c = 0; c < columnCount + 1; c++) { + TAOS_MULTI_BIND *param = + (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + + sizeof(TAOS_MULTI_BIND) * c); + char data_type; + if (c == 0) { + data_type = TSDB_DATA_TYPE_TIMESTAMP; + param->buffer_length = sizeof(int64_t); + param->buffer = pThreadInfo->bind_ts_array; } else { - param->buffer = col->stmtData.data; - param->is_null = col->stmtData.is_null; + Field *col = benchArrayGet(stbInfo->cols, c - 1); + data_type = col->type; + if (childTbl->useOwnSample) { + ChildField *childCol = benchArrayGet(childTbl->childCols, c-1); + param->buffer = childCol->stmtData.data; + param->is_null = childCol->stmtData.is_null; + } else { + param->buffer = col->stmtData.data; + param->is_null = col->stmtData.is_null; + } + param->buffer_length = col->length; + debugPrint("col[%d]: type: %s, len: %d\n", c, + convertDatatypeToString(data_type), + col->length); } - param->buffer_length = col->length; - debugPrint("col[%d]: type: %s, len: %d\n", c, - convertDatatypeToString(data_type), - col->length); - } - param->buffer_type = data_type; - param->length = benchCalloc(batch, sizeof(int32_t), true); + param->buffer_type = data_type; + param->length = benchCalloc(batch, sizeof(int32_t), true); - for (int b = 0; b < batch; b++) { - param->length[b] = (int32_t)param->buffer_length; + for (int b = 0; b < batch; b++) { + param->length[b] = (int32_t)param->buffer_length; + } + param->num = batch; } - param->num = batch; } // set ts array values @@ -1867,13 +1871,6 @@ uint32_t bindParamBatch(threadInfo *pThreadInfo, } *delay2 += toolsGetTimestampUs() - start; - for (int c = 0; c < stbInfo->cols->size + 1; c++) { - TAOS_MULTI_BIND *param = - (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + - sizeof(TAOS_MULTI_BIND) * c); - tmfree(param->length); - } - // if msg > 3MB, break start = toolsGetTimestampUs(); if (taos_stmt_add_batch(stmt)) { diff --git a/src/benchInsert.c b/src/benchInsert.c index fcb8f99f..4a3d3be1 100644 --- a/src/benchInsert.c +++ b/src/benchInsert.c @@ -3733,6 +3733,12 @@ static int startMultiThreadInsertData(SDataBase* database, case STMT_IFACE: taos_stmt_close(pThreadInfo->conn->stmt); + + // free length + for (int c = 0; c < stbInfo->cols->size + 1; c++) { + TAOS_MULTI_BIND *param = (TAOS_MULTI_BIND *)(pThreadInfo->bindParams + sizeof(TAOS_MULTI_BIND) * c); + tmfree(param->length); + } tmfree(pThreadInfo->bind_ts); tmfree(pThreadInfo->bind_ts_array); tmfree(pThreadInfo->bindParams); @@ -3765,6 +3771,8 @@ static int startMultiThreadInsertData(SDataBase* database, closeBenchConn(pThreadInfo->conn); pThreadInfo->conn = NULL; } + + } // calculate result