Skip to content

Commit

Permalink
Merge pull request #746 from taosdata/fix/TS-4960
Browse files Browse the repository at this point in the history
fix: stmt only bind one , improve performance
  • Loading branch information
DuanKuanJun committed Jun 4, 2024
2 parents 0806e0c + e85941b commit 22f9a5f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
1 change: 1 addition & 0 deletions inc/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
75 changes: 36 additions & 39 deletions src/benchData.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
8 changes: 8 additions & 0 deletions src/benchInsert.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -3765,6 +3771,8 @@ static int startMultiThreadInsertData(SDataBase* database,
closeBenchConn(pThreadInfo->conn);
pThreadInfo->conn = NULL;
}


}

// calculate result
Expand Down

0 comments on commit 22f9a5f

Please sign in to comment.