Merge pull request #29131 from taosdata/fix/3.0/TD-33167
fix:[TD-33167]fix cycle stmt2_bind error
This commit is contained in:
commit
c91ad8152b
|
@ -150,6 +150,7 @@ typedef struct {
|
||||||
SStmtExecInfo exec;
|
SStmtExecInfo exec;
|
||||||
SStmtBindInfo bInfo;
|
SStmtBindInfo bInfo;
|
||||||
|
|
||||||
|
char *db;
|
||||||
int64_t reqid;
|
int64_t reqid;
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
tsem_t asyncQuerySem;
|
tsem_t asyncQuerySem;
|
||||||
|
|
|
@ -75,6 +75,10 @@ static int32_t stmtCreateRequest(STscStmt2* pStmt) {
|
||||||
if (pStmt->reqid != 0) {
|
if (pStmt->reqid != 0) {
|
||||||
pStmt->reqid++;
|
pStmt->reqid++;
|
||||||
}
|
}
|
||||||
|
if (pStmt->db != NULL) {
|
||||||
|
taosMemoryFreeClear(pStmt->exec.pRequest->pDb);
|
||||||
|
pStmt->exec.pRequest->pDb = strdup(pStmt->db);
|
||||||
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
pStmt->exec.pRequest->syncQuery = true;
|
pStmt->exec.pRequest->syncQuery = true;
|
||||||
pStmt->exec.pRequest->isStmtBind = true;
|
pStmt->exec.pRequest->isStmtBind = true;
|
||||||
|
@ -109,7 +113,7 @@ static int32_t stmtSwitchStatus(STscStmt2* pStmt, STMT_STATUS newStatus) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case STMT_SETTAGS:
|
case STMT_SETTAGS:
|
||||||
if (STMT_STATUS_NE(SETTBNAME) && STMT_STATUS_NE(FETCH_FIELDS)) {
|
if (STMT_STATUS_EQ(INIT)) {
|
||||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -412,6 +416,7 @@ static void stmtFreeTbCols(void* buf) {
|
||||||
static int32_t stmtCleanSQLInfo(STscStmt2* pStmt) {
|
static int32_t stmtCleanSQLInfo(STscStmt2* pStmt) {
|
||||||
STMT_DLOG_E("start to free SQL info");
|
STMT_DLOG_E("start to free SQL info");
|
||||||
|
|
||||||
|
taosMemoryFreeClear(pStmt->db);
|
||||||
taosMemoryFree(pStmt->sql.pBindInfo);
|
taosMemoryFree(pStmt->sql.pBindInfo);
|
||||||
taosMemoryFree(pStmt->sql.queryRes.fields);
|
taosMemoryFree(pStmt->sql.queryRes.fields);
|
||||||
taosMemoryFree(pStmt->sql.queryRes.userFields);
|
taosMemoryFree(pStmt->sql.queryRes.userFields);
|
||||||
|
@ -842,6 +847,7 @@ static int stmtSetDbName2(TAOS_STMT2* stmt, const char* dbName) {
|
||||||
|
|
||||||
STMT_DLOG("start to set dbName: %s", dbName);
|
STMT_DLOG("start to set dbName: %s", dbName);
|
||||||
|
|
||||||
|
pStmt->db = taosStrdup(dbName);
|
||||||
STMT_ERR_RET(stmtCreateRequest(pStmt));
|
STMT_ERR_RET(stmtCreateRequest(pStmt));
|
||||||
|
|
||||||
// The SQL statement specifies a database name, overriding the previously specified database
|
// The SQL statement specifies a database name, overriding the previously specified database
|
||||||
|
@ -992,6 +998,19 @@ int stmtSetTbTags2(TAOS_STMT2* stmt, TAOS_STMT2_BIND* tags) {
|
||||||
|
|
||||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
|
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
|
||||||
|
|
||||||
|
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 &&
|
||||||
|
STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
||||||
|
pStmt->bInfo.needParse = false;
|
||||||
|
}
|
||||||
|
STMT_ERR_RET(stmtCreateRequest(pStmt));
|
||||||
|
|
||||||
|
if (pStmt->bInfo.needParse) {
|
||||||
|
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||||
|
}
|
||||||
|
if (pStmt->sql.stbInterlaceMode && NULL == pStmt->sql.siInfo.pDataCtx) {
|
||||||
|
STMT_ERR_RET(stmtInitStbInterlaceTableInfo(pStmt));
|
||||||
|
}
|
||||||
|
|
||||||
SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags;
|
SBoundColInfo* tags_info = (SBoundColInfo*)pStmt->bInfo.boundTags;
|
||||||
if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) {
|
if (tags_info->numOfBound <= 0 || tags_info->numOfCols <= 0) {
|
||||||
tscWarn("no tags or cols bound in sql, will not bound tags");
|
tscWarn("no tags or cols bound in sql, will not bound tags");
|
||||||
|
|
|
@ -5,8 +5,9 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
|
|
||||||
int CTB_NUMS = 10;
|
int CTB_NUMS = 1000;
|
||||||
int ROW_NUMS = 2;
|
int ROW_NUMS = 10;
|
||||||
|
int CYC_NUMS = 5;
|
||||||
|
|
||||||
void do_query(TAOS* taos, const char* sql) {
|
void do_query(TAOS* taos, const char* sql) {
|
||||||
TAOS_RES* result = taos_query(taos, sql);
|
TAOS_RES* result = taos_query(taos, sql);
|
||||||
|
@ -19,10 +20,32 @@ void do_query(TAOS* taos, const char* sql) {
|
||||||
taos_free_result(result);
|
taos_free_result(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_stmt(TAOS* taos, const char* sql) {
|
void do_ins(TAOS* taos, const char* sql) {
|
||||||
|
TAOS_RES* result = taos_query(taos, sql);
|
||||||
|
int code = taos_errno(result);
|
||||||
|
if (code) {
|
||||||
|
printf("failed to query: %s, reason:%s\n", sql, taos_errstr(result));
|
||||||
|
taos_free_result(result);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
taos_free_result(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createCtb(TAOS* taos, const char* tbname) {
|
||||||
|
char* tmp = (char*)malloc(sizeof(char) * 100);
|
||||||
|
sprintf(tmp, "create table db.%s using db.stb tags(0, 'after')", tbname);
|
||||||
|
do_query(taos, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void initEnv(TAOS* taos) {
|
||||||
do_query(taos, "drop database if exists db");
|
do_query(taos, "drop database if exists db");
|
||||||
do_query(taos, "create database db");
|
do_query(taos, "create database db");
|
||||||
do_query(taos, "create table db.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
|
do_query(taos, "create table db.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
|
||||||
|
do_query(taos, "use db");
|
||||||
|
}
|
||||||
|
|
||||||
|
void do_stmt(TAOS* taos, const char* sql) {
|
||||||
|
initEnv(taos);
|
||||||
|
|
||||||
TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
|
TAOS_STMT2_OPTION option = {0, true, true, NULL, NULL};
|
||||||
|
|
||||||
|
@ -35,26 +58,25 @@ void do_stmt(TAOS* taos, const char* sql) {
|
||||||
}
|
}
|
||||||
int fieldNum = 0;
|
int fieldNum = 0;
|
||||||
TAOS_FIELD_STB* pFields = NULL;
|
TAOS_FIELD_STB* pFields = NULL;
|
||||||
code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields);
|
// code = taos_stmt2_get_stb_fields(stmt, &fieldNum, &pFields);
|
||||||
if (code != 0) {
|
// if (code != 0) {
|
||||||
printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
|
// printf("failed get col,ErrCode: 0x%x, ErrMessage: %s.\n", code, taos_stmt2_error(stmt));
|
||||||
} else {
|
// } else {
|
||||||
printf("col nums:%d\n", fieldNum);
|
// printf("col nums:%d\n", fieldNum);
|
||||||
for (int i = 0; i < fieldNum; i++) {
|
// for (int i = 0; i < fieldNum; i++) {
|
||||||
printf("field[%d]: %s, data_type:%d, field_type:%d\n", i, pFields[i].name, pFields[i].type,
|
// printf("field[%d]: %s, data_type:%d, field_type:%d\n", i, pFields[i].name, pFields[i].type,
|
||||||
pFields[i].field_type);
|
// pFields[i].field_type);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// tbname
|
// tbname
|
||||||
char** tbs = (char**)malloc(CTB_NUMS * sizeof(char*));
|
char** tbs = (char**)malloc(CTB_NUMS * sizeof(char*));
|
||||||
for (int i = 0; i < CTB_NUMS; i++) {
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
tbs[i] = (char*)malloc(sizeof(char) * 20);
|
tbs[i] = (char*)malloc(sizeof(char) * 20);
|
||||||
sprintf(tbs[i], "ctb_%d", i);
|
sprintf(tbs[i], "ctb_%d", i);
|
||||||
// char* tmp=(char*)malloc(sizeof(char) * 100);
|
createCtb(taos, tbs[i]);
|
||||||
// sprintf(tmp, "create table db.%s using db.stb tags(0, 'abc')", tbs[i]);
|
|
||||||
// do_query(taos, tmp);
|
|
||||||
}
|
}
|
||||||
|
for (int r = 0; r < CYC_NUMS; r++) {
|
||||||
// col params
|
// col params
|
||||||
int64_t** ts = (int64_t**)malloc(CTB_NUMS * sizeof(int64_t*));
|
int64_t** ts = (int64_t**)malloc(CTB_NUMS * sizeof(int64_t*));
|
||||||
char** b = (char**)malloc(CTB_NUMS * sizeof(char*));
|
char** b = (char**)malloc(CTB_NUMS * sizeof(char*));
|
||||||
|
@ -68,7 +90,7 @@ void do_stmt(TAOS* taos, const char* sql) {
|
||||||
ts[i] = (int64_t*)malloc(ROW_NUMS * sizeof(int64_t));
|
ts[i] = (int64_t*)malloc(ROW_NUMS * sizeof(int64_t));
|
||||||
b[i] = (char*)malloc(ROW_NUMS * sizeof(char));
|
b[i] = (char*)malloc(ROW_NUMS * sizeof(char));
|
||||||
for (int j = 0; j < ROW_NUMS; j++) {
|
for (int j = 0; j < ROW_NUMS; j++) {
|
||||||
ts[i][j] = 1591060628000 + j;
|
ts[i][j] = 1591060628000 + r * 100000 + j;
|
||||||
b[i][j] = 'a' + j;
|
b[i][j] = 'a' + j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,43 +138,59 @@ void do_stmt(TAOS* taos, const char* sql) {
|
||||||
end = clock();
|
end = clock();
|
||||||
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
|
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
|
||||||
printf("stmt2-exec [%s] insert Time used: %f seconds\n", sql, cpu_time_used);
|
printf("stmt2-exec [%s] insert Time used: %f seconds\n", sql, cpu_time_used);
|
||||||
|
}
|
||||||
|
|
||||||
taos_stmt2_free_fields(stmt, pFields);
|
// taos_stmt2_free_fields(stmt, pFields);
|
||||||
taos_stmt2_close(stmt);
|
taos_stmt2_close(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_taosc(TAOS* taos) {
|
void do_taosc(TAOS* taos) {
|
||||||
do_query(taos, "drop database if exists testdb");
|
initEnv(taos);
|
||||||
do_query(taos, "create database testdb");
|
// cols
|
||||||
do_query(taos, "create table testdb.stb (ts timestamp, b binary(10)) tags(t1 int, t2 binary(10))");
|
int64_t** ts = (int64_t*)malloc(CTB_NUMS * sizeof(int64_t));
|
||||||
int64_t* ts = (int64_t*)malloc(CTB_NUMS * sizeof(int64_t));
|
char** b = (char**)malloc(CTB_NUMS * sizeof(char*));
|
||||||
|
// ctbnames
|
||||||
char** tbs = (char**)malloc(CTB_NUMS * sizeof(char*));
|
char** tbs = (char**)malloc(CTB_NUMS * sizeof(char*));
|
||||||
|
|
||||||
|
// create table before insert
|
||||||
for (int i = 0; i < CTB_NUMS; i++) {
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
tbs[i] = (char*)malloc(sizeof(char) * 10);
|
tbs[i] = (char*)malloc(sizeof(char) * 20);
|
||||||
|
sprintf(tbs[i], "ctb_%d", i);
|
||||||
|
createCtb(taos, tbs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
|
ts[i] = (int64_t*)malloc(ROW_NUMS * sizeof(int64_t));
|
||||||
|
b[i] = (char*)malloc(ROW_NUMS * sizeof(char));
|
||||||
|
for (int j = 0; j < ROW_NUMS; j++) {
|
||||||
|
ts[i][j] = 1591060628000 + j;
|
||||||
|
b[i][j] = 'a' + j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int r = 0; r < CYC_NUMS; r++) {
|
||||||
clock_t start, end;
|
clock_t start, end;
|
||||||
double cpu_time_used;
|
double cpu_time_used;
|
||||||
char* tsc_sql = malloc(sizeof(char) * 1000000);
|
char* tsc_sql = malloc(sizeof(char) * 1000000);
|
||||||
sprintf(tsc_sql, "insert into testdb.stb(tbname,ts,b,t1,t2) values");
|
sprintf(tsc_sql, "insert into db.stb(tbname,ts,b,t1,t2) values");
|
||||||
|
|
||||||
for (int j = 0; j < ROW_NUMS; j++) {
|
|
||||||
for (int i = 0; i < CTB_NUMS; i++) {
|
for (int i = 0; i < CTB_NUMS; i++) {
|
||||||
ts[i] = 1591060628000 + i + j * CTB_NUMS;
|
snprintf(tbs[i], sizeof(tbs[i]), "ctb_%d", i);
|
||||||
snprintf(tbs[i], sizeof(tbs[i]), "ctb_%d", i + j * CTB_NUMS);
|
for (int j = 0; j < ROW_NUMS; j++) {
|
||||||
if (i == CTB_NUMS - 1 && j == ROW_NUMS - 1) {
|
if (i == CTB_NUMS - 1 && j == ROW_NUMS - 1) {
|
||||||
sprintf(tsc_sql + strlen(tsc_sql), "('%s',%lld,'abc',0,'after')", tbs[i], ts[i]);
|
sprintf(tsc_sql + strlen(tsc_sql), "('%s',%lld,'%c',0,'after')", tbs[i], ts[i][j] + r * 10000, b[i][j]);
|
||||||
} else {
|
} else {
|
||||||
sprintf(tsc_sql + strlen(tsc_sql), "('%s',%lld,'abc'0,'after'),", tbs[i], ts[i]);
|
sprintf(tsc_sql + strlen(tsc_sql), "('%s',%lld,'%c',0,'after'),", tbs[i], ts[i][j] + r * 10000, b[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
start = clock();
|
start = clock();
|
||||||
// printf("%s", tsc_sql);
|
// printf("%s", tsc_sql);
|
||||||
taos_query(taos, tsc_sql);
|
do_ins(taos, tsc_sql);
|
||||||
end = clock();
|
end = clock();
|
||||||
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
|
cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
|
||||||
printf("taosc insert Time used: %f seconds\n", cpu_time_used);
|
printf("taosc insert Time used: %f seconds\n", cpu_time_used);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -162,10 +200,10 @@ int main() {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sleep(3);
|
sleep(3);
|
||||||
do_stmt(taos, "insert into db.stb(tbname,ts,b,t1,t2) values(?,?,?,?,?)");
|
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_stmt(taos, "insert into db.? using db.stb tags(?,?)values(?,?)");
|
||||||
// do_taosc(taos);
|
do_taosc(taos);
|
||||||
taos_close(taos);
|
taos_close(taos);
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue