Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c3484ce8
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c3484ce8
编写于
4月 29, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stmt query
上级
6973e355
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
84 addition
and
1052 deletion
+84
-1052
source/client/src/clientStmt.c
source/client/src/clientStmt.c
+17
-1
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+21
-1
tests/script/api/batchprepare.c
tests/script/api/batchprepare.c
+46
-1050
未找到文件。
source/client/src/clientStmt.c
浏览文件 @
c3484ce8
...
...
@@ -649,6 +649,19 @@ int stmtGetParamNum(TAOS_STMT *stmt, int *nums) {
STMT_ERR_RET
(
stmtSwitchStatus
(
pStmt
,
STMT_FETCH_FIELDS
));
if
(
pStmt
->
bInfo
.
needParse
&&
pStmt
->
sql
.
runTimes
&&
pStmt
->
sql
.
type
>
0
&&
STMT_TYPE_MULTI_INSERT
!=
pStmt
->
sql
.
type
)
{
pStmt
->
bInfo
.
needParse
=
false
;
}
if
(
pStmt
->
exec
.
pRequest
&&
STMT_TYPE_QUERY
==
pStmt
->
sql
.
type
&&
pStmt
->
sql
.
runTimes
)
{
taos_free_result
(
pStmt
->
exec
.
pRequest
);
pStmt
->
exec
.
pRequest
=
NULL
;
}
if
(
NULL
==
pStmt
->
exec
.
pRequest
)
{
STMT_ERR_RET
(
buildRequest
(
pStmt
->
taos
,
pStmt
->
sql
.
sqlStr
,
pStmt
->
sql
.
sqlLen
,
&
pStmt
->
exec
.
pRequest
));
}
if
(
pStmt
->
bInfo
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
...
...
@@ -658,8 +671,11 @@ int stmtGetParamNum(TAOS_STMT *stmt, int *nums) {
STMT_ERR_RET
(
getQueryPlan
(
pStmt
->
exec
.
pRequest
,
pStmt
->
sql
.
pQuery
,
&
pStmt
->
sql
.
nodeList
));
pStmt
->
sql
.
pQueryPlan
=
pStmt
->
exec
.
pRequest
->
body
.
pDag
;
pStmt
->
exec
.
pRequest
->
body
.
pDag
=
NULL
;
STMT_ERR_RET
(
stmtBackupQueryFields
(
pStmt
));
}
else
{
STMT_ERR_RET
(
stmtRestoreQueryFields
(
pStmt
));
}
*
nums
=
taosArrayGetSize
(
pStmt
->
sql
.
pQueryPlan
->
pPlaceholderValues
);
}
else
{
STMT_ERR_RET
(
stmtFetchColFields
(
stmt
,
nums
,
NULL
));
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
c3484ce8
...
...
@@ -297,6 +297,22 @@ static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIn
taosMemoryFree
(
t
);
}
static
FORCE_INLINE
void
ncharToVar
(
char
*
buf
,
SScalarParam
*
pOut
,
int32_t
rowIndex
)
{
int32_t
inputLen
=
varDataLen
(
buf
);
char
*
t
=
taosMemoryCalloc
(
1
,
inputLen
+
VARSTR_HEADER_SIZE
);
int32_t
len
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
buf
),
varDataLen
(
buf
),
varDataVal
(
t
));
if
(
len
<
0
)
{
taosMemoryFree
(
t
);
return
;
}
varDataSetLen
(
t
,
len
);
colDataAppend
(
pOut
->
columnData
,
rowIndex
,
t
,
false
);
taosMemoryFree
(
t
);
}
//TODO opt performance, tmp is not needed.
int32_t
vectorConvertFromVarData
(
const
SScalarParam
*
pIn
,
SScalarParam
*
pOut
,
int32_t
inType
,
int32_t
outType
)
{
int32_t
bufSize
=
pIn
->
columnData
->
info
.
bytes
;
...
...
@@ -313,6 +329,10 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
func
=
varToUnsigned
;
}
else
if
(
IS_FLOAT_TYPE
(
outType
))
{
func
=
varToFloat
;
}
else
if
(
outType
==
TSDB_DATA_TYPE_BINARY
)
{
// nchar -> binary
ASSERT
(
inType
==
TSDB_DATA_TYPE_NCHAR
);
func
=
ncharToVar
;
vton
=
true
;
}
else
if
(
outType
==
TSDB_DATA_TYPE_NCHAR
)
{
// binary -> nchar
ASSERT
(
inType
==
TSDB_DATA_TYPE_VARCHAR
);
func
=
varToNchar
;
...
...
@@ -608,7 +628,7 @@ int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = {
/*BIGI*/
0
,
0
,
0
,
0
,
0
,
0
,
6
,
7
,
7
,
0
,
7
,
5
,
5
,
5
,
7
,
0
,
7
,
0
,
0
,
/*FLOA*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
6
,
7
,
6
,
6
,
6
,
6
,
0
,
7
,
0
,
0
,
/*DOUB*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
7
,
7
,
7
,
0
,
7
,
0
,
0
,
/*VARC*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
9
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
0
,
0
,
/*VARC*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
9
,
8
,
7
,
7
,
7
,
7
,
0
,
0
,
0
,
0
,
/*TIME*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
9
,
9
,
9
,
9
,
7
,
0
,
7
,
0
,
0
,
/*NCHA*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
7
,
7
,
7
,
7
,
0
,
0
,
0
,
0
,
/*UTIN*/
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
12
,
13
,
14
,
0
,
7
,
0
,
0
,
...
...
tests/script/api/batchprepare.c
浏览文件 @
c3484ce8
...
...
@@ -11,8 +11,8 @@
int32_t
shortColList
[]
=
{
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_DATA_TYPE_INT
};
int32_t
fullColList
[]
=
{
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_DATA_TYPE_BOOL
,
TSDB_DATA_TYPE_TINYINT
,
TSDB_DATA_TYPE_UTINYINT
,
TSDB_DATA_TYPE_SMALLINT
,
TSDB_DATA_TYPE_USMALLINT
,
TSDB_DATA_TYPE_INT
,
TSDB_DATA_TYPE_UINT
,
TSDB_DATA_TYPE_BIGINT
,
TSDB_DATA_TYPE_UBIGINT
,
TSDB_DATA_TYPE_FLOAT
,
TSDB_DATA_TYPE_DOUBLE
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DATA_TYPE_NCHAR
};
int32_t
bindColTypeList
[]
=
{
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_DATA_TYPE_
NCHAR
,
TSDB_DATA_TYPE_BOOL
};
int32_t
optrIdxList
[]
=
{
2
,
11
,
6
};
int32_t
bindColTypeList
[]
=
{
TSDB_DATA_TYPE_TIMESTAMP
,
TSDB_DATA_TYPE_
SMALLINT
,
TSDB_DATA_TYPE_DOUBLE
};
int32_t
optrIdxList
[]
=
{
0
,
1
,
2
};
typedef
struct
{
char
*
oper
;
...
...
@@ -169,8 +169,8 @@ typedef struct {
int32_t
caseRunNum
;
// total run case num
}
CaseCtrl
;
#if
1
CaseCtrl
gCaseCtrl
=
{
#if
0
CaseCtrl gCaseCtrl = {
// default
.bindNullNum = 0,
.prepareStb = false,
.printCreateTblSql = false,
...
...
@@ -186,23 +186,43 @@ CaseCtrl gCaseCtrl = {
.checkParamNum = false,
.printRes = true,
.runTimes = 0,
//
.caseIdx = -1,
//
.caseNum = -1,
.caseIdx = -1,
.caseNum = -1,
.caseRunIdx = -1,
// .caseRunNum = -1,
.caseRunNum = -1,
};
#endif
// .optrIdxListNum = tListLen(optrIdxList),
// .optrIdxList = optrIdxList,
// .bindColTypeNum = tListLen(bindColTypeList),
// .bindColTypeList = bindColTypeList,
#if 0
CaseCtrl gCaseCtrl = { // query case with specified col&oper
.bindNullNum = 0,
.prepareStb = false,
.printCreateTblSql = false,
.printQuerySql = true,
.printStmtSql = true,
.rowNum = 0,
.bindColNum = 0,
.bindRowNum = 0,
.bindColTypeNum = 0,
.bindColTypeList = NULL,
.optrIdxListNum = 0,
.optrIdxList = NULL,
.checkParamNum = false,
.printRes = true,
.runTimes = 0,
.caseRunIdx = -1,
.optrIdxListNum = 0,
.optrIdxList = NULL,
.bindColTypeNum = 0,
.bindColTypeList = NULL,
.caseIdx = 22,
.caseNum = 1,
.caseRunNum = 1,
};
#else
CaseCtrl
gCaseCtrl
=
{
#endif
#if 1
CaseCtrl
gCaseCtrl
=
{
// query case with specified col&oper
.
bindNullNum
=
0
,
.
prepareStb
=
false
,
.
printCreateTblSql
=
false
,
...
...
@@ -211,17 +231,22 @@ CaseCtrl gCaseCtrl = {
.
rowNum
=
0
,
.
bindColNum
=
0
,
.
bindRowNum
=
0
,
.
bindColTypeNum
=
tListLen
(
bindColTypeList
),
.
bindColTypeList
=
bindColTypeList
,
.
checkParamNum
=
false
,
.
bindColTypeNum
=
0
,
.
bindColTypeList
=
NULL
,
.
optrIdxListNum
=
0
,
.
optrIdxList
=
NULL
,
.
checkParamNum
=
true
,
.
printRes
=
true
,
.
runTimes
=
0
,
.
caseIdx
=
2
,
.
caseNum
=
1
,
.
caseRunIdx
=
-
1
,
.
optrIdxListNum
=
tListLen
(
optrIdxList
),
.
optrIdxList
=
optrIdxList
,
.
bindColTypeNum
=
tListLen
(
bindColTypeList
),
.
bindColTypeList
=
bindColTypeList
,
.
caseIdx
=
22
,
.
caseNum
=
1
,
.
caseRunNum
=
1
,
};
#endif
int32_t
taosGetTimeOfDay
(
struct
timeval
*
tv
)
{
...
...
@@ -3218,1035 +3243,6 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) {
return 0;
}
//samets
int stmt_funcb4(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int8_t b[60];
int8_t v1[60];
int16_t v2[60];
int32_t v4[60];
int64_t v8[60];
float f4[60];
double f8[60];
char bin[60][40];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
int *lb = taosMemoryMalloc(60 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
char* is_null = taosMemoryMalloc(sizeof(char) * 60);
char* no_null = taosMemoryMalloc(sizeof(char) * 60);
for (int i = 0; i < 60; ++i) {
lb[i] = 40;
no_null[i] = 0;
is_null[i] = (i % 10 == 2) ? 1 : 0;
v.b[i] = (int8_t)(i % 2);
v.v1[i] = (int8_t)((i+1) % 2);
v.v2[i] = (int16_t)i;
v.v4[i] = (int32_t)(i+1);
v.v8[i] = (int64_t)(i+2);
v.f4[i] = (float)(i+3);
v.f8[i] = (double)(i+4);
memset(v.bin[i], '0'+i%10, 40);
}
for (int i = 0; i < 9000000; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[60*i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = 60;
params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
params[i+1].buffer_length = sizeof(int8_t);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = is_null;
params[i+1].num = 60;
params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
params[i+2].buffer_length = sizeof(int8_t);
params[i+2].buffer = v.v1;
params[i+2].length = NULL;
params[i+2].is_null = is_null;
params[i+2].num = 60;
params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
params[i+3].buffer_length = sizeof(int16_t);
params[i+3].buffer = v.v2;
params[i+3].length = NULL;
params[i+3].is_null = is_null;
params[i+3].num = 60;
params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
params[i+4].buffer_length = sizeof(int32_t);
params[i+4].buffer = v.v4;
params[i+4].length = NULL;
params[i+4].is_null = is_null;
params[i+4].num = 60;
params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
params[i+5].buffer_length = sizeof(int64_t);
params[i+5].buffer = v.v8;
params[i+5].length = NULL;
params[i+5].is_null = is_null;
params[i+5].num = 60;
params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[i+6].buffer_length = sizeof(float);
params[i+6].buffer = v.f4;
params[i+6].length = NULL;
params[i+6].is_null = is_null;
params[i+6].num = 60;
params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
params[i+7].buffer_length = sizeof(double);
params[i+7].buffer = v.f8;
params[i+7].length = NULL;
params[i+7].is_null = is_null;
params[i+7].num = 60;
params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+8].buffer_length = 40;
params[i+8].buffer = v.bin;
params[i+8].length = lb;
params[i+8].is_null = is_null;
params[i+8].num = 60;
params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+9].buffer_length = 40;
params[i+9].buffer = v.bin;
params[i+9].length = lb;
params[i+9].is_null = is_null;
params[i+9].num = 60;
}
int64_t tts = 1591060628000;
for (int i = 0; i < 54000000; ++i) {
v.ts[i] = tts;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int l = 0; l < 3000; l++) {
for (int zz = 0; zz < 300; zz++) {
char buf[32];
sprintf(buf, "m%d", zz);
code = taos_stmt_set_tbname(stmt, buf);
if (code != 0){
printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
}
taos_stmt_bind_param_batch(stmt, params + id * 10);
taos_stmt_add_batch(stmt);
}
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
++id;
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(is_null);
taosMemoryFree(no_null);
return 0;
}
//1table 18000 reocrds
int stmt_funcb5(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int8_t b[18000];
int8_t v1[18000];
int16_t v2[18000];
int32_t v4[18000];
int64_t v8[18000];
float f4[18000];
double f8[18000];
char bin[18000][40];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
int *lb = taosMemoryMalloc(18000 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10);
char* is_null = taosMemoryMalloc(sizeof(char) * 18000);
char* no_null = taosMemoryMalloc(sizeof(char) * 18000);
for (int i = 0; i < 18000; ++i) {
lb[i] = 40;
no_null[i] = 0;
is_null[i] = (i % 10 == 2) ? 1 : 0;
v.b[i] = (int8_t)(i % 2);
v.v1[i] = (int8_t)((i+1) % 2);
v.v2[i] = (int16_t)i;
v.v4[i] = (int32_t)(i+1);
v.v8[i] = (int64_t)(i+2);
v.f4[i] = (float)(i+3);
v.f8[i] = (double)(i+4);
memset(v.bin[i], '0'+i%10, 40);
}
for (int i = 0; i < 30000; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[18000*i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = 18000;
params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
params[i+1].buffer_length = sizeof(int8_t);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = is_null;
params[i+1].num = 18000;
params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
params[i+2].buffer_length = sizeof(int8_t);
params[i+2].buffer = v.v1;
params[i+2].length = NULL;
params[i+2].is_null = is_null;
params[i+2].num = 18000;
params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
params[i+3].buffer_length = sizeof(int16_t);
params[i+3].buffer = v.v2;
params[i+3].length = NULL;
params[i+3].is_null = is_null;
params[i+3].num = 18000;
params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
params[i+4].buffer_length = sizeof(int32_t);
params[i+4].buffer = v.v4;
params[i+4].length = NULL;
params[i+4].is_null = is_null;
params[i+4].num = 18000;
params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
params[i+5].buffer_length = sizeof(int64_t);
params[i+5].buffer = v.v8;
params[i+5].length = NULL;
params[i+5].is_null = is_null;
params[i+5].num = 18000;
params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[i+6].buffer_length = sizeof(float);
params[i+6].buffer = v.f4;
params[i+6].length = NULL;
params[i+6].is_null = is_null;
params[i+6].num = 18000;
params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
params[i+7].buffer_length = sizeof(double);
params[i+7].buffer = v.f8;
params[i+7].length = NULL;
params[i+7].is_null = is_null;
params[i+7].num = 18000;
params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+8].buffer_length = 40;
params[i+8].buffer = v.bin;
params[i+8].length = lb;
params[i+8].is_null = is_null;
params[i+8].num = 18000;
params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+9].buffer_length = 40;
params[i+9].buffer = v.bin;
params[i+9].length = lb;
params[i+9].is_null = is_null;
params[i+9].num = 18000;
}
int64_t tts = 1591060628000;
for (int i = 0; i < 54000000; ++i) {
v.ts[i] = tts + i;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into m0 values(?,?,?,?,?,?,?,?,?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int l = 0; l < 10; l++) {
for (int zz = 0; zz < 1; zz++) {
taos_stmt_bind_param_batch(stmt, params + id * 10);
taos_stmt_add_batch(stmt);
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
++id;
}
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(is_null);
taosMemoryFree(no_null);
return 0;
}
//1table 200000 reocrds
int stmt_funcb_ssz1(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int b[30000];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 30000 * 3000);
int *lb = taosMemoryMalloc(30000 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10);
char* no_null = taosMemoryMalloc(sizeof(int) * 200000);
for (int i = 0; i < 30000; ++i) {
lb[i] = 40;
no_null[i] = 0;
v.b[i] = (int8_t)(i % 2);
}
for (int i = 0; i < 30000; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[30000*i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = 30000;
params[i+1].buffer_type = TSDB_DATA_TYPE_INT;
params[i+1].buffer_length = sizeof(int);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = no_null;
params[i+1].num = 30000;
}
int64_t tts = 0;
for (int64_t i = 0; i < 90000000LL; ++i) {
v.ts[i] = tts + i;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into ? values(?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int l = 0; l < 10; l++) {
for (int zz = 0; zz < 300; zz++) {
char buf[32];
sprintf(buf, "m%d", zz);
code = taos_stmt_set_tbname(stmt, buf);
if (code != 0){
printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
}
taos_stmt_bind_param_batch(stmt, params + id * 10);
taos_stmt_add_batch(stmt);
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
++id;
}
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(no_null);
return 0;
}
//one table 60 records one time
int stmt_funcb_s1(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int8_t b[60];
int8_t v1[60];
int16_t v2[60];
int32_t v4[60];
int64_t v8[60];
float f4[60];
double f8[60];
char bin[60][40];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
int *lb = taosMemoryMalloc(60 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
char* is_null = taosMemoryMalloc(sizeof(char) * 60);
char* no_null = taosMemoryMalloc(sizeof(char) * 60);
for (int i = 0; i < 60; ++i) {
lb[i] = 40;
no_null[i] = 0;
is_null[i] = (i % 10 == 2) ? 1 : 0;
v.b[i] = (int8_t)(i % 2);
v.v1[i] = (int8_t)((i+1) % 2);
v.v2[i] = (int16_t)i;
v.v4[i] = (int32_t)(i+1);
v.v8[i] = (int64_t)(i+2);
v.f4[i] = (float)(i+3);
v.f8[i] = (double)(i+4);
memset(v.bin[i], '0'+i%10, 40);
}
for (int i = 0; i < 9000000; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[60*i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = 60;
params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
params[i+1].buffer_length = sizeof(int8_t);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = is_null;
params[i+1].num = 60;
params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
params[i+2].buffer_length = sizeof(int8_t);
params[i+2].buffer = v.v1;
params[i+2].length = NULL;
params[i+2].is_null = is_null;
params[i+2].num = 60;
params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
params[i+3].buffer_length = sizeof(int16_t);
params[i+3].buffer = v.v2;
params[i+3].length = NULL;
params[i+3].is_null = is_null;
params[i+3].num = 60;
params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
params[i+4].buffer_length = sizeof(int32_t);
params[i+4].buffer = v.v4;
params[i+4].length = NULL;
params[i+4].is_null = is_null;
params[i+4].num = 60;
params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
params[i+5].buffer_length = sizeof(int64_t);
params[i+5].buffer = v.v8;
params[i+5].length = NULL;
params[i+5].is_null = is_null;
params[i+5].num = 60;
params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[i+6].buffer_length = sizeof(float);
params[i+6].buffer = v.f4;
params[i+6].length = NULL;
params[i+6].is_null = is_null;
params[i+6].num = 60;
params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
params[i+7].buffer_length = sizeof(double);
params[i+7].buffer = v.f8;
params[i+7].length = NULL;
params[i+7].is_null = is_null;
params[i+7].num = 60;
params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+8].buffer_length = 40;
params[i+8].buffer = v.bin;
params[i+8].length = lb;
params[i+8].is_null = is_null;
params[i+8].num = 60;
params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+9].buffer_length = 40;
params[i+9].buffer = v.bin;
params[i+9].length = lb;
params[i+9].is_null = is_null;
params[i+9].num = 60;
}
int64_t tts = 1591060628000;
for (int i = 0; i < 54000000; ++i) {
v.ts[i] = tts + i;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int l = 0; l < 3000; l++) {
for (int zz = 0; zz < 300; zz++) {
char buf[32];
sprintf(buf, "m%d", zz);
code = taos_stmt_set_tbname(stmt, buf);
if (code != 0){
printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
}
taos_stmt_bind_param_batch(stmt, params + id * 10);
taos_stmt_add_batch(stmt);
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
++id;
}
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(is_null);
taosMemoryFree(no_null);
return 0;
}
//300 tables 60 records single column bind
int stmt_funcb_sc1(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int8_t b[60];
int8_t v1[60];
int16_t v2[60];
int32_t v4[60];
int64_t v8[60];
float f4[60];
double f8[60];
char bin[60][40];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
int *lb = taosMemoryMalloc(60 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
char* is_null = taosMemoryMalloc(sizeof(char) * 60);
char* no_null = taosMemoryMalloc(sizeof(char) * 60);
for (int i = 0; i < 60; ++i) {
lb[i] = 40;
no_null[i] = 0;
is_null[i] = (i % 10 == 2) ? 1 : 0;
v.b[i] = (int8_t)(i % 2);
v.v1[i] = (int8_t)((i+1) % 2);
v.v2[i] = (int16_t)i;
v.v4[i] = (int32_t)(i+1);
v.v8[i] = (int64_t)(i+2);
v.f4[i] = (float)(i+3);
v.f8[i] = (double)(i+4);
memset(v.bin[i], '0'+i%10, 40);
}
for (int i = 0; i < 9000000; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[60*i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = 60;
params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
params[i+1].buffer_length = sizeof(int8_t);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = is_null;
params[i+1].num = 60;
params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
params[i+2].buffer_length = sizeof(int8_t);
params[i+2].buffer = v.v1;
params[i+2].length = NULL;
params[i+2].is_null = is_null;
params[i+2].num = 60;
params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
params[i+3].buffer_length = sizeof(int16_t);
params[i+3].buffer = v.v2;
params[i+3].length = NULL;
params[i+3].is_null = is_null;
params[i+3].num = 60;
params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
params[i+4].buffer_length = sizeof(int32_t);
params[i+4].buffer = v.v4;
params[i+4].length = NULL;
params[i+4].is_null = is_null;
params[i+4].num = 60;
params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
params[i+5].buffer_length = sizeof(int64_t);
params[i+5].buffer = v.v8;
params[i+5].length = NULL;
params[i+5].is_null = is_null;
params[i+5].num = 60;
params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[i+6].buffer_length = sizeof(float);
params[i+6].buffer = v.f4;
params[i+6].length = NULL;
params[i+6].is_null = is_null;
params[i+6].num = 60;
params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
params[i+7].buffer_length = sizeof(double);
params[i+7].buffer = v.f8;
params[i+7].length = NULL;
params[i+7].is_null = is_null;
params[i+7].num = 60;
params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+8].buffer_length = 40;
params[i+8].buffer = v.bin;
params[i+8].length = lb;
params[i+8].is_null = is_null;
params[i+8].num = 60;
params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+9].buffer_length = 40;
params[i+9].buffer = v.bin;
params[i+9].length = lb;
params[i+9].is_null = is_null;
params[i+9].num = 60;
}
int64_t tts = 1591060628000;
for (int i = 0; i < 54000000; ++i) {
v.ts[i] = tts + i;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int l = 0; l < 3000; l++) {
for (int zz = 0; zz < 300; zz++) {
char buf[32];
sprintf(buf, "m%d", zz);
code = taos_stmt_set_tbname(stmt, buf);
if (code != 0){
printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
}
for (int col=0; col < 10; ++col) {
taos_stmt_bind_single_param_batch(stmt, params + id++, col);
}
taos_stmt_add_batch(stmt);
}
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(is_null);
taosMemoryFree(no_null);
return 0;
}
//1 tables 60 records single column bind
int stmt_funcb_sc2(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int8_t b[60];
int8_t v1[60];
int16_t v2[60];
int32_t v4[60];
int64_t v8[60];
float f4[60];
double f8[60];
char bin[60][40];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60);
int *lb = taosMemoryMalloc(60 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10);
char* is_null = taosMemoryMalloc(sizeof(char) * 60);
char* no_null = taosMemoryMalloc(sizeof(char) * 60);
for (int i = 0; i < 60; ++i) {
lb[i] = 40;
no_null[i] = 0;
is_null[i] = (i % 10 == 2) ? 1 : 0;
v.b[i] = (int8_t)(i % 2);
v.v1[i] = (int8_t)((i+1) % 2);
v.v2[i] = (int16_t)i;
v.v4[i] = (int32_t)(i+1);
v.v8[i] = (int64_t)(i+2);
v.f4[i] = (float)(i+3);
v.f8[i] = (double)(i+4);
memset(v.bin[i], '0'+i%10, 40);
}
for (int i = 0; i < 9000000; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[60*i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = 60;
params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
params[i+1].buffer_length = sizeof(int8_t);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = is_null;
params[i+1].num = 60;
params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
params[i+2].buffer_length = sizeof(int8_t);
params[i+2].buffer = v.v1;
params[i+2].length = NULL;
params[i+2].is_null = is_null;
params[i+2].num = 60;
params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
params[i+3].buffer_length = sizeof(int16_t);
params[i+3].buffer = v.v2;
params[i+3].length = NULL;
params[i+3].is_null = is_null;
params[i+3].num = 60;
params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
params[i+4].buffer_length = sizeof(int32_t);
params[i+4].buffer = v.v4;
params[i+4].length = NULL;
params[i+4].is_null = is_null;
params[i+4].num = 60;
params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
params[i+5].buffer_length = sizeof(int64_t);
params[i+5].buffer = v.v8;
params[i+5].length = NULL;
params[i+5].is_null = is_null;
params[i+5].num = 60;
params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[i+6].buffer_length = sizeof(float);
params[i+6].buffer = v.f4;
params[i+6].length = NULL;
params[i+6].is_null = is_null;
params[i+6].num = 60;
params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
params[i+7].buffer_length = sizeof(double);
params[i+7].buffer = v.f8;
params[i+7].length = NULL;
params[i+7].is_null = is_null;
params[i+7].num = 60;
params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+8].buffer_length = 40;
params[i+8].buffer = v.bin;
params[i+8].length = lb;
params[i+8].is_null = is_null;
params[i+8].num = 60;
params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+9].buffer_length = 40;
params[i+9].buffer = v.bin;
params[i+9].length = lb;
params[i+9].is_null = is_null;
params[i+9].num = 60;
}
int64_t tts = 1591060628000;
for (int i = 0; i < 54000000; ++i) {
v.ts[i] = tts + i;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int l = 0; l < 3000; l++) {
for (int zz = 0; zz < 300; zz++) {
char buf[32];
sprintf(buf, "m%d", zz);
code = taos_stmt_set_tbname(stmt, buf);
if (code != 0){
printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
}
for (int col=0; col < 10; ++col) {
taos_stmt_bind_single_param_batch(stmt, params + id++, col);
}
taos_stmt_add_batch(stmt);
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
}
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(is_null);
taosMemoryFree(no_null);
return 0;
}
//10 tables [1...10] records single column bind
int stmt_funcb_sc3(TAOS_STMT *stmt) {
struct {
int64_t *ts;
int8_t b[60];
int8_t v1[60];
int16_t v2[60];
int32_t v4[60];
int64_t v8[60];
float f4[60];
double f8[60];
char bin[60][40];
} v = {0};
v.ts = taosMemoryMalloc(sizeof(int64_t) * 60);
int *lb = taosMemoryMalloc(60 * sizeof(int));
TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 60*10);
char* is_null = taosMemoryMalloc(sizeof(char) * 60);
char* no_null = taosMemoryMalloc(sizeof(char) * 60);
for (int i = 0; i < 60; ++i) {
lb[i] = 40;
no_null[i] = 0;
is_null[i] = (i % 10 == 2) ? 1 : 0;
v.b[i] = (int8_t)(i % 2);
v.v1[i] = (int8_t)((i+1) % 2);
v.v2[i] = (int16_t)i;
v.v4[i] = (int32_t)(i+1);
v.v8[i] = (int64_t)(i+2);
v.f4[i] = (float)(i+3);
v.f8[i] = (double)(i+4);
memset(v.bin[i], '0'+i%10, 40);
}
int g = 0;
for (int i = 0; i < 600; i+=10) {
params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP;
params[i+0].buffer_length = sizeof(int64_t);
params[i+0].buffer = &v.ts[i/10];
params[i+0].length = NULL;
params[i+0].is_null = no_null;
params[i+0].num = g%10+1;
params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL;
params[i+1].buffer_length = sizeof(int8_t);
params[i+1].buffer = v.b;
params[i+1].length = NULL;
params[i+1].is_null = is_null;
params[i+1].num = g%10+1;
params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT;
params[i+2].buffer_length = sizeof(int8_t);
params[i+2].buffer = v.v1;
params[i+2].length = NULL;
params[i+2].is_null = is_null;
params[i+2].num = g%10+1;
params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT;
params[i+3].buffer_length = sizeof(int16_t);
params[i+3].buffer = v.v2;
params[i+3].length = NULL;
params[i+3].is_null = is_null;
params[i+3].num = g%10+1;
params[i+4].buffer_type = TSDB_DATA_TYPE_INT;
params[i+4].buffer_length = sizeof(int32_t);
params[i+4].buffer = v.v4;
params[i+4].length = NULL;
params[i+4].is_null = is_null;
params[i+4].num = g%10+1;
params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT;
params[i+5].buffer_length = sizeof(int64_t);
params[i+5].buffer = v.v8;
params[i+5].length = NULL;
params[i+5].is_null = is_null;
params[i+5].num = g%10+1;
params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT;
params[i+6].buffer_length = sizeof(float);
params[i+6].buffer = v.f4;
params[i+6].length = NULL;
params[i+6].is_null = is_null;
params[i+6].num = g%10+1;
params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE;
params[i+7].buffer_length = sizeof(double);
params[i+7].buffer = v.f8;
params[i+7].length = NULL;
params[i+7].is_null = is_null;
params[i+7].num = g%10+1;
params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+8].buffer_length = 40;
params[i+8].buffer = v.bin;
params[i+8].length = lb;
params[i+8].is_null = is_null;
params[i+8].num = g%10+1;
params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY;
params[i+9].buffer_length = 40;
params[i+9].buffer = v.bin;
params[i+9].length = lb;
params[i+9].is_null = is_null;
params[i+9].num = g%10+1;
++g;
}
int64_t tts = 1591060628000;
for (int i = 0; i < 60; ++i) {
v.ts[i] = tts + i;
}
unsigned long long starttime = taosGetTimestampUs();
char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)";
int code = taos_stmt_prepare(stmt, sql, 0);
if (code != 0){
printf("failed to execute taos_stmt_prepare. code:0x%x\n", code);
}
int id = 0;
for (int zz = 0; zz < 10; zz++) {
char buf[32];
sprintf(buf, "m%d", zz);
code = taos_stmt_set_tbname(stmt, buf);
if (code != 0){
printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code);
}
for (int col=0; col < 10; ++col) {
taos_stmt_bind_single_param_batch(stmt, params + id++, col);
}
taos_stmt_add_batch(stmt);
}
if (taos_stmt_execute(stmt) != 0) {
printf("failed to execute insert statement.\n");
exit(1);
}
unsigned long long endtime = taosGetTimestampUs();
printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60));
taosMemoryFree(v.ts);
taosMemoryFree(lb);
taosMemoryFree(params);
taosMemoryFree(is_null);
taosMemoryFree(no_null);
return 0;
}
#endif
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录