Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
loser646
TDengine
提交
b7cec307
T
TDengine
项目概览
loser646
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b7cec307
编写于
5月 09, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
7db07e73
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
445 addition
and
55 deletion
+445
-55
src/client/src/tscPrepare.c
src/client/src/tscPrepare.c
+57
-30
tests/script/api/batchprepare.c
tests/script/api/batchprepare.c
+388
-25
未找到文件。
src/client/src/tscPrepare.c
浏览文件 @
b7cec307
...
...
@@ -148,7 +148,7 @@ static int normalStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
break
;
default:
tscDebug
(
"
param %d: type mismatch or invalid"
,
i
);
tscDebug
(
"
0x%"
PRIx64
" param %d: type mismatch or invalid"
,
stmt
->
pSql
->
self
,
i
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
}
...
...
@@ -804,7 +804,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
if
(
pStmt
->
multiTbInsert
)
{
if
(
pCmd
->
pTableBlockHashList
==
NULL
)
{
tscError
(
"
Table block hash list is empty"
);
tscError
(
"
0x%"
PRIx64
" Table block hash list is empty"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -850,7 +850,7 @@ static int insertStmtBindParam(STscStmt* stmt, TAOS_BIND* bind) {
int
code
=
doBindParam
(
pBlock
,
data
,
param
,
&
bind
[
param
->
idx
],
1
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscDebug
(
"
param %d: type mismatch or invalid"
,
param
->
idx
);
tscDebug
(
"
0x%"
PRIx64
" param %d: type mismatch or invalid"
,
pStmt
->
pSql
->
self
,
param
->
idx
);
return
code
;
}
}
...
...
@@ -866,18 +866,34 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c
STableDataBlocks
*
pBlock
=
NULL
;
if
(
pCmd
->
pTableBlockHashList
==
NULL
)
{
tscError
(
"Table block hash list is empty"
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
if
(
pStmt
->
multiTbInsert
)
{
if
(
pCmd
->
pTableBlockHashList
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" Table block hash list is empty"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pCmd
->
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
;
}
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pCmd
->
pTableBlockHashList
,
(
const
char
*
)
&
pStmt
->
mtb
.
currentUid
,
sizeof
(
pStmt
->
mtb
.
currentUid
));
if
(
t1
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" no table data block in hash list, uid:%"
PRId64
,
pStmt
->
pSql
->
self
,
pStmt
->
mtb
.
currentUid
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
pBlock
=
*
t1
;
pBlock
=
*
t1
;
}
else
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pCmd
,
0
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
if
(
pCmd
->
pTableBlockHashList
==
NULL
)
{
pCmd
->
pTableBlockHashList
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
}
int32_t
ret
=
tscGetDataBlockFromList
(
pCmd
->
pTableBlockHashList
,
pTableMeta
->
id
.
uid
,
TSDB_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
pTableMeta
->
tableInfo
.
rowSize
,
&
pTableMetaInfo
->
name
,
pTableMeta
,
&
pBlock
,
NULL
);
if
(
ret
!=
0
)
{
return
ret
;
}
}
assert
(
colIdx
==
-
1
||
(
colIdx
>=
0
&&
colIdx
<
pBlock
->
numOfParams
));
...
...
@@ -898,13 +914,13 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c
for
(
uint32_t
j
=
0
;
j
<
pBlock
->
numOfParams
;
++
j
)
{
SParamInfo
*
param
=
&
pBlock
->
params
[
j
];
if
(
bind
[
param
->
idx
].
num
!=
rowNum
)
{
tscError
(
"
param %d: num[%d:%d] not match"
,
param
->
idx
,
rowNum
,
bind
[
param
->
idx
].
num
);
tscError
(
"
0x%"
PRIx64
" param %d: num[%d:%d] not match"
,
pStmt
->
pSql
->
self
,
param
->
idx
,
rowNum
,
bind
[
param
->
idx
].
num
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
int
code
=
doBindBatchParam
(
pBlock
,
param
,
&
bind
[
param
->
idx
],
pCmd
->
batchSize
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"
param %d: type mismatch or invalid"
,
param
->
idx
);
tscError
(
"
0x%"
PRIx64
" param %d: type mismatch or invalid"
,
pStmt
->
pSql
->
self
,
param
->
idx
);
return
code
;
}
}
...
...
@@ -915,7 +931,7 @@ static int insertStmtBindParamBatch(STscStmt* stmt, TAOS_MULTI_BIND* bind, int c
int
code
=
doBindBatchParam
(
pBlock
,
param
,
bind
,
pCmd
->
batchSize
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"
param %d: type mismatch or invalid"
,
param
->
idx
);
tscError
(
"
0x%"
PRIx64
" param %d: type mismatch or invalid"
,
pStmt
->
pSql
->
self
,
param
->
idx
);
return
code
;
}
...
...
@@ -940,7 +956,7 @@ static int insertStmtUpdateBatch(STscStmt* stmt) {
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pCmd
->
pTableBlockHashList
,
(
const
char
*
)
&
stmt
->
mtb
.
currentUid
,
sizeof
(
stmt
->
mtb
.
currentUid
));
if
(
t1
==
NULL
)
{
tscError
(
"
no table data block in hash list, uid:%"
PRId64
,
stmt
->
mtb
.
currentUid
);
tscError
(
"
0x%"
PRIx64
" no table data block in hash list, uid:%"
PRId64
,
pSql
->
self
,
stmt
->
mtb
.
currentUid
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -1110,7 +1126,7 @@ static int insertBatchStmtExecute(STscStmt* pStmt) {
int32_t
code
=
0
;
if
(
pStmt
->
mtb
.
nameSet
==
false
)
{
tscError
(
"
no table name set"
);
tscError
(
"
0x%"
PRIx64
" no table name set"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -1276,13 +1292,13 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
if
(
name
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_APP_ERROR
;
tscError
(
"
name is NULL"
);
tscError
(
"
0x%"
PRIx64
" name is NULL"
,
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
if
(
pStmt
->
multiTbInsert
==
false
||
!
tscIsInsertData
(
pSql
->
sqlstr
))
{
terrno
=
TSDB_CODE_TSC_APP_ERROR
;
tscError
(
"
not multi table insert"
);
tscError
(
"
0x%"
PRIx64
" not multi table insert"
,
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -1292,7 +1308,7 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
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
);
tscError
(
"
0x%"
PRIx64
" no table data block in hash list, uid:%"
PRId64
,
pSql
->
self
,
pStmt
->
mtb
.
currentUid
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -1301,7 +1317,7 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
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
);
tscDebug
(
"
0x%"
PRIx64
" table:%s is already prepared, uid:%"
PRIu64
,
pSql
->
self
,
name
,
pStmt
->
mtb
.
currentUid
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -1350,7 +1366,7 @@ int taos_stmt_set_tbname(TAOS_STMT* stmt, const char* name) {
taosHashPut
(
pStmt
->
mtb
.
pTableHash
,
name
,
strlen
(
name
),
(
char
*
)
&
pTableMeta
->
id
.
uid
,
sizeof
(
pTableMeta
->
id
.
uid
));
tscDebug
(
"
table:%s is prepared, uid:%"
PRIu64
,
name
,
pStmt
->
mtb
.
currentUid
);
tscDebug
(
"
0x%"
PRIx64
" table:%s is prepared, uid:%"
PRIu64
,
pSql
->
self
,
name
,
pStmt
->
mtb
.
currentUid
);
}
return
code
;
...
...
@@ -1396,12 +1412,17 @@ int taos_stmt_bind_param(TAOS_STMT* stmt, TAOS_BIND* bind) {
int
taos_stmt_bind_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
bind
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
bind
==
NULL
||
bind
->
num
<=
0
)
{
tscError
(
"
invalid parameter"
);
tscError
(
"
0x%"
PRIx64
" invalid parameter"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
if
(
!
pStmt
->
isInsert
||
!
pStmt
->
multiTbInsert
||
!
pStmt
->
mtb
.
nameSet
)
{
tscError
(
"not or invalid batch insert"
);
if
(
!
pStmt
->
isInsert
)
{
tscError
(
"0x%"
PRIx64
" not or invalid batch insert"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
if
(
pStmt
->
multiTbInsert
&&
!
pStmt
->
mtb
.
nameSet
)
{
tscError
(
"0x%"
PRIx64
" no table name set"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
...
...
@@ -1411,14 +1432,20 @@ int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
int
taos_stmt_bind_single_param_batch
(
TAOS_STMT
*
stmt
,
TAOS_MULTI_BIND
*
bind
,
int
colIdx
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
if
(
bind
==
NULL
||
bind
->
num
<=
0
)
{
tscError
(
"
invalid parameter"
);
tscError
(
"
0x%"
PRIx64
" invalid parameter"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
if
(
!
pStmt
->
isInsert
||
!
pStmt
->
multiTbInsert
||
!
pStmt
->
mtb
.
nameSet
)
{
tscError
(
"
not or invalid batch insert"
);
if
(
!
pStmt
->
isInsert
)
{
tscError
(
"
0x%"
PRIx64
" not or invalid batch insert"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
if
(
pStmt
->
multiTbInsert
&&
!
pStmt
->
mtb
.
nameSet
)
{
tscError
(
"0x%"
PRIx64
" no table name set"
,
pStmt
->
pSql
->
self
);
return
TSDB_CODE_TSC_APP_ERROR
;
}
return
insertStmtBindParamBatch
(
pStmt
,
bind
,
colIdx
);
}
...
...
@@ -1544,7 +1571,7 @@ int taos_stmt_get_param(TAOS_STMT *stmt, int idx, int *type, int *bytes) {
}
if
(
idx
<
0
||
idx
>=
pBlock
->
numOfParams
)
{
tscError
(
"
param %d: out of range"
,
idx
);
tscError
(
"
0x%"
PRIx64
" param %d: out of range"
,
pStmt
->
pSql
->
self
,
idx
);
abort
();
}
...
...
tests/script/api/batchprepare.c
浏览文件 @
b7cec307
...
...
@@ -6,7 +6,13 @@
#include <string.h>
#include "taos.h"
#include <sys/time.h>
#include <pthread.h>
#include <unistd.h>
typedef
struct
{
TAOS
*
taos
;
int
idx
;
}
T_par
;
void
taosMsleep
(
int
mseconds
);
...
...
@@ -585,7 +591,7 @@ int stmt_funcb2(TAOS_STMT *stmt) {
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
[
6
0
*
i
/
10
];
params
[
i
+
0
].
buffer
=
&
v
.
ts
[
1800
0
*
i
/
10
];
params
[
i
+
0
].
length
=
NULL
;
params
[
i
+
0
].
is_null
=
no_null
;
params
[
i
+
0
].
num
=
18000
;
...
...
@@ -1008,6 +1014,232 @@ int stmt_funcb4(TAOS_STMT *stmt) {
}
//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
=
malloc
(
sizeof
(
int64_t
)
*
900000
*
60
);
uintptr_t
*
lb
=
malloc
(
18000
*
sizeof
(
uintptr_t
));
TAOS_MULTI_BIND
*
params
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
)
*
3000
*
10
);
int
*
is_null
=
malloc
(
sizeof
(
int
)
*
18000
);
int
*
no_null
=
malloc
(
sizeof
(
int
)
*
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
=
getCurrentTime
();
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
=
getCurrentTime
();
printf
(
"insert total %d records, used %u seconds, avg:%u useconds
\n
"
,
3000
*
300
*
60
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
3000
*
300
*
60
));
return
0
;
}
//1table 200000 reocrds
int
stmt_funcb_ssz1
(
TAOS_STMT
*
stmt
)
{
struct
{
int64_t
*
ts
;
int
b
[
30000
];
}
v
=
{
0
};
v
.
ts
=
malloc
(
sizeof
(
int64_t
)
*
30000
*
3000
);
uintptr_t
*
lb
=
malloc
(
30000
*
sizeof
(
uintptr_t
));
TAOS_MULTI_BIND
*
params
=
calloc
(
1
,
sizeof
(
TAOS_MULTI_BIND
)
*
3000
*
10
);
int
*
no_null
=
malloc
(
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
=
getCurrentTime
();
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
=
getCurrentTime
();
printf
(
"insert total %d records, used %u seconds, avg:%u useconds
\n
"
,
3000
*
300
*
60
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
3000
*
300
*
60
));
return
0
;
}
//one table 60 records one time
int
stmt_funcb_s1
(
TAOS_STMT
*
stmt
)
{
struct
{
...
...
@@ -1796,7 +2028,7 @@ int sql_s_perf1(TAOS *taos) {
}
void
prepare
(
TAOS
*
taos
)
{
void
prepare
(
TAOS
*
taos
,
int
bigsize
)
{
TAOS_RES
*
result
;
int
code
;
...
...
@@ -1818,7 +2050,11 @@ void prepare(TAOS *taos) {
// create table
for
(
int
i
=
0
;
i
<
300
;
i
++
)
{
char
buf
[
1024
];
sprintf
(
buf
,
"create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), bin2 binary(40))"
,
i
)
;
if
(
bigsize
)
{
sprintf
(
buf
,
"create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), bin2 binary(40))"
,
i
)
;
}
else
{
sprintf
(
buf
,
"create table m%d (ts timestamp, b int)"
,
i
)
;
}
result
=
taos_query
(
taos
,
buf
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
...
...
@@ -1832,12 +2068,68 @@ void prepare(TAOS *taos) {
}
void
runcase
(
TAOS
*
taos
)
{
void
preparem
(
TAOS
*
taos
,
int
bigsize
,
int
idx
)
{
TAOS_RES
*
result
;
int
code
;
char
dbname
[
32
],
sql
[
255
];
sprintf
(
dbname
,
"demo%d"
,
idx
);
sprintf
(
sql
,
"drop database %s"
,
dbname
);
result
=
taos_query
(
taos
,
sql
);
taos_free_result
(
result
);
sprintf
(
sql
,
"create database %s"
,
dbname
);
result
=
taos_query
(
taos
,
sql
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
printf
(
"failed to create database, reason:%s
\n
"
,
taos_errstr
(
result
));
taos_free_result
(
result
);
exit
(
1
);
}
taos_free_result
(
result
);
sprintf
(
sql
,
"use %s"
,
dbname
);
result
=
taos_query
(
taos
,
sql
);
taos_free_result
(
result
);
// create table
for
(
int
i
=
0
;
i
<
300
;
i
++
)
{
char
buf
[
1024
];
if
(
bigsize
)
{
sprintf
(
buf
,
"create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), bin2 binary(40))"
,
i
)
;
}
else
{
sprintf
(
buf
,
"create table m%d (ts timestamp, b int)"
,
i
)
;
}
result
=
taos_query
(
taos
,
buf
);
code
=
taos_errno
(
result
);
if
(
code
!=
0
)
{
printf
(
"failed to create table, reason:%s
\n
"
,
taos_errstr
(
result
));
taos_free_result
(
result
);
exit
(
1
);
}
taos_free_result
(
result
);
}
}
//void runcase(TAOS *taos, int idx) {
void
*
runcase
(
void
*
par
)
{
T_par
*
tpar
=
(
T_par
*
)
par
;
TAOS
*
taos
=
tpar
->
taos
;
int
idx
=
tpar
->
idx
;
TAOS_STMT
*
stmt
;
(
void
)
idx
;
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -1861,7 +2153,7 @@ void runcase(TAOS *taos) {
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -1885,7 +2177,7 @@ void runcase(TAOS *taos) {
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -1910,7 +2202,7 @@ void runcase(TAOS *taos) {
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -1928,14 +2220,14 @@ void runcase(TAOS *taos) {
#endif
#if 1
prepare
(
taos
);
#if 1
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
printf
(
"1t+
9
000r+bm start
\n
"
);
printf
(
"1t+
18
000r+bm start
\n
"
);
stmt_funcb2
(
stmt
);
printf
(
"1t+
9
000r+bm end
\n
"
);
printf
(
"1t+
18
000r+bm end
\n
"
);
printf
(
"check result start
\n
"
);
check_result
(
taos
,
"m0"
,
0
,
180000
);
check_result
(
taos
,
"m1"
,
0
,
180000
);
...
...
@@ -1945,11 +2237,10 @@ void runcase(TAOS *taos) {
printf
(
"check result end
\n
"
);
taos_stmt_close
(
stmt
);
//stmt_perf1(stmt);
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -1969,7 +2260,7 @@ void runcase(TAOS *taos) {
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -1986,9 +2277,24 @@ void runcase(TAOS *taos) {
taos_stmt_close
(
stmt
);
#endif
#if 1
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
printf
(
"1t+18000r+nodyntable+bm start
\n
"
);
stmt_funcb5
(
stmt
);
printf
(
"1t+18000r+nodyntable+bm end
\n
"
);
printf
(
"check result start
\n
"
);
check_result
(
taos
,
"m0"
,
0
,
180000
);
printf
(
"check result end
\n
"
);
taos_stmt_close
(
stmt
);
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -2006,7 +2312,7 @@ void runcase(TAOS *taos) {
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -2025,7 +2331,7 @@ void runcase(TAOS *taos) {
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -2050,7 +2356,7 @@ void runcase(TAOS *taos) {
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
stmt
=
taos_stmt_init
(
taos
);
...
...
@@ -2070,7 +2376,7 @@ void runcase(TAOS *taos) {
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
(
void
)
stmt
;
printf
(
"120t+60r+sql start
\n
"
);
...
...
@@ -2086,7 +2392,7 @@ void runcase(TAOS *taos) {
#endif
#if 1
prepare
(
taos
);
prepare
(
taos
,
1
);
(
void
)
stmt
;
printf
(
"1t+60r+sql start
\n
"
);
...
...
@@ -2102,12 +2408,32 @@ void runcase(TAOS *taos) {
#endif
#if 1
preparem
(
taos
,
0
,
idx
);
stmt
=
taos_stmt_init
(
taos
);
printf
(
"1t+30000r+bm start
\n
"
);
stmt_funcb_ssz1
(
stmt
);
printf
(
"1t+30000r+bm end
\n
"
);
printf
(
"check result start
\n
"
);
check_result
(
taos
,
"m0"
,
0
,
300000
);
check_result
(
taos
,
"m1"
,
0
,
300000
);
check_result
(
taos
,
"m111"
,
0
,
300000
);
check_result
(
taos
,
"m223"
,
0
,
300000
);
check_result
(
taos
,
"m299"
,
0
,
300000
);
printf
(
"check result end
\n
"
);
taos_stmt_close
(
stmt
);
#endif
return
NULL
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
TAOS
*
taos
;
TAOS
*
taos
[
4
]
;
// connect to server
if
(
argc
<
2
)
{
...
...
@@ -2115,17 +2441,54 @@ int main(int argc, char *argv[])
return
0
;
}
taos
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
taos
[
0
]
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to db, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
prepare
(
taos
);
taos
[
1
]
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to db, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
runcase
(
taos
);
taos
[
2
]
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to db, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
taos
[
3
]
=
taos_connect
(
argv
[
1
],
"root"
,
"taosdata"
,
NULL
,
0
);
if
(
taos
==
NULL
)
{
printf
(
"failed to connect to db, reason:%s
\n
"
,
taos_errstr
(
taos
));
exit
(
1
);
}
pthread_t
*
pThreadList
=
(
pthread_t
*
)
calloc
(
sizeof
(
pthread_t
),
4
);
pthread_attr_t
thattr
;
pthread_attr_init
(
&
thattr
);
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
T_par
par
[
4
];
par
[
0
].
taos
=
taos
[
0
];
par
[
0
].
idx
=
0
;
par
[
1
].
taos
=
taos
[
1
];
par
[
1
].
idx
=
1
;
par
[
2
].
taos
=
taos
[
2
];
par
[
2
].
idx
=
2
;
par
[
3
].
taos
=
taos
[
3
];
par
[
3
].
idx
=
3
;
pthread_create
(
&
(
pThreadList
[
0
]),
&
thattr
,
runcase
,
(
void
*
)
&
par
[
0
]);
//pthread_create(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//pthread_create(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//pthread_create(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
while
(
1
)
{
sleep
(
1
);
}
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录