Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1e1cca98
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
1e1cca98
编写于
4月 18, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stmt
上级
c8fe5bc8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
113 addition
and
97 deletion
+113
-97
source/client/inc/clientStmt.h
source/client/inc/clientStmt.h
+3
-4
source/client/src/clientMain.c
source/client/src/clientMain.c
+4
-0
source/client/src/clientStmt.c
source/client/src/clientStmt.c
+57
-57
tests/script/api/batchprepare.c
tests/script/api/batchprepare.c
+49
-36
未找到文件。
source/client/inc/clientStmt.h
浏览文件 @
1e1cca98
...
...
@@ -26,7 +26,7 @@ typedef void STableDataBlocks;
typedef
enum
{
STMT_TYPE_INSERT
=
1
,
STMT_TYPE_MULTI_INSERT
,
STMT_TYPE_QUERY
STMT_TYPE_QUERY
,
}
STMT_TYPE
;
typedef
enum
{
...
...
@@ -38,7 +38,7 @@ typedef enum {
STMT_BIND
,
STMT_BIND_COL
,
STMT_ADD_BATCH
,
STMT_EXECUTE
STMT_EXECUTE
,
}
STMT_STATUS
;
typedef
struct
SStmtTableCache
{
...
...
@@ -79,7 +79,7 @@ typedef struct STscStmt {
SStmtSQLInfo
sql
;
SStmtExecInfo
exec
;
SStmtBindInfo
b
ind
;
SStmtBindInfo
b
Info
;
}
STscStmt
;
...
...
@@ -91,7 +91,6 @@ typedef struct STscStmt {
do { \
switch (_newstatus) { \
case STMT_INIT: \
if ((_stmt)->sql.status != 0) return (_errcode); \
break; \
case STMT_PREPARE: \
if ((_stmt)->sql.status != STMT_INIT) STMT_ERR_RET(_errcode); \
...
...
source/client/src/clientMain.c
浏览文件 @
1e1cca98
...
...
@@ -127,6 +127,10 @@ const char *taos_errstr(TAOS_RES *res) {
}
void
taos_free_result
(
TAOS_RES
*
res
)
{
if
(
NULL
==
res
)
{
return
;
}
SRequestObj
*
pRequest
=
(
SRequestObj
*
)
res
;
destroyRequest
(
pRequest
);
}
...
...
source/client/src/clientStmt.c
浏览文件 @
1e1cca98
...
...
@@ -9,12 +9,12 @@ int32_t stmtGetTbName(TAOS_STMT *stmt, char **tbName) {
pStmt
->
sql
.
type
=
STMT_TYPE_MULTI_INSERT
;
if
(
NULL
==
pStmt
->
b
ind
.
tbName
)
{
if
(
NULL
==
pStmt
->
b
Info
.
tbName
)
{
tscError
(
"no table name set"
);
STMT_ERR_RET
(
TSDB_CODE_TSC_STMT_TBNAME_ERROR
);
}
*
tbName
=
pStmt
->
b
ind
.
tbName
;
*
tbName
=
pStmt
->
b
Info
.
tbName
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -22,10 +22,10 @@ int32_t stmtGetTbName(TAOS_STMT *stmt, char **tbName) {
int32_t
stmtSetBindInfo
(
TAOS_STMT
*
stmt
,
STableMeta
*
pTableMeta
,
void
*
tags
)
{
STscStmt
*
pStmt
=
(
STscStmt
*
)
stmt
;
pStmt
->
b
ind
.
tbUid
=
pTableMeta
->
uid
;
pStmt
->
b
ind
.
tbSuid
=
pTableMeta
->
suid
;
pStmt
->
b
ind
.
tbType
=
pTableMeta
->
tableType
;
pStmt
->
b
ind
.
boundTags
=
tags
;
pStmt
->
b
Info
.
tbUid
=
pTableMeta
->
uid
;
pStmt
->
b
Info
.
tbSuid
=
pTableMeta
->
suid
;
pStmt
->
b
Info
.
tbType
=
pTableMeta
->
tableType
;
pStmt
->
b
Info
.
boundTags
=
tags
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -54,11 +54,11 @@ int32_t stmtCacheBlock(STscStmt *pStmt) {
}
uint64_t
uid
;
if
(
TSDB_CHILD_TABLE
==
pStmt
->
b
ind
.
tbType
)
{
uid
=
pStmt
->
b
ind
.
tbSuid
;
if
(
TSDB_CHILD_TABLE
==
pStmt
->
b
Info
.
tbType
)
{
uid
=
pStmt
->
b
Info
.
tbSuid
;
}
else
{
ASSERT
(
TSDB_NORMAL_TABLE
==
pStmt
->
b
ind
.
tbType
);
uid
=
pStmt
->
b
ind
.
tbUid
;
ASSERT
(
TSDB_NORMAL_TABLE
==
pStmt
->
b
Info
.
tbType
);
uid
=
pStmt
->
b
Info
.
tbUid
;
}
if
(
taosHashGet
(
pStmt
->
sql
.
pTableCache
,
&
uid
,
sizeof
(
uid
)))
{
...
...
@@ -72,14 +72,14 @@ int32_t stmtCacheBlock(STscStmt *pStmt) {
SStmtTableCache
cache
=
{
.
pDataBlock
=
pDst
,
.
boundTags
=
pStmt
->
b
ind
.
boundTags
,
.
boundTags
=
pStmt
->
b
Info
.
boundTags
,
};
if
(
taosHashPut
(
pStmt
->
sql
.
pTableCache
,
&
uid
,
sizeof
(
uid
),
&
cache
,
sizeof
(
cache
)))
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pStmt
->
b
ind
.
boundTags
=
NULL
;
pStmt
->
b
Info
.
boundTags
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -95,7 +95,7 @@ int32_t stmtParseSql(STscStmt* pStmt) {
STMT_ERR_RET
(
parseSql
(
pStmt
->
exec
.
pRequest
,
false
,
&
pStmt
->
sql
.
pQuery
,
&
stmtCb
));
pStmt
->
b
ind
.
needParse
=
false
;
pStmt
->
b
Info
.
needParse
=
false
;
switch
(
nodeType
(
pStmt
->
sql
.
pQuery
->
pRoot
))
{
case
QUERY_NODE_VNODE_MODIF_STMT
:
...
...
@@ -116,14 +116,14 @@ int32_t stmtParseSql(STscStmt* pStmt) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
stmtCleanBindInfo
(
STscStmt
*
pStmt
)
{
pStmt
->
b
ind
.
tbUid
=
0
;
pStmt
->
b
ind
.
tbSuid
=
0
;
pStmt
->
b
ind
.
tbType
=
0
;
pStmt
->
b
ind
.
needParse
=
true
;
pStmt
->
b
Info
.
tbUid
=
0
;
pStmt
->
b
Info
.
tbSuid
=
0
;
pStmt
->
b
Info
.
tbType
=
0
;
pStmt
->
b
Info
.
needParse
=
true
;
taosMemoryFreeClear
(
pStmt
->
b
ind
.
tbName
);
destroyBoundColumnInfo
(
pStmt
->
b
ind
.
boundTags
);
taosMemoryFreeClear
(
pStmt
->
b
ind
.
boundTags
);
taosMemoryFreeClear
(
pStmt
->
b
Info
.
tbName
);
destroyBoundColumnInfo
(
pStmt
->
b
Info
.
boundTags
);
taosMemoryFreeClear
(
pStmt
->
b
Info
.
boundTags
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -137,7 +137,7 @@ int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable) {
STableDataBlocks
*
pBlocks
=
*
(
STableDataBlocks
**
)
pIter
;
uint64_t
*
key
=
taosHashGetKey
(
pIter
,
NULL
);
if
(
keepTable
&&
(
*
key
==
pStmt
->
b
ind
.
tbUid
))
{
if
(
keepTable
&&
(
*
key
==
pStmt
->
b
Info
.
tbUid
))
{
qResetStmtDataBlock
(
pBlocks
,
true
);
pIter
=
taosHashIterate
(
pStmt
->
exec
.
pBlockHash
,
pIter
);
...
...
@@ -197,10 +197,10 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
STableMeta
*
pTableMeta
=
NULL
;
SEpSet
ep
=
getEpSet_s
(
&
pStmt
->
taos
->
pAppInfo
->
mgmtEp
);
STMT_ERR_RET
(
catalogGetTableMeta
(
pStmt
->
pCatalog
,
pStmt
->
taos
->
pAppInfo
->
pTransporter
,
&
ep
,
&
pStmt
->
b
ind
.
sname
,
&
pTableMeta
));
STMT_ERR_RET
(
catalogGetTableMeta
(
pStmt
->
pCatalog
,
pStmt
->
taos
->
pAppInfo
->
pTransporter
,
&
ep
,
&
pStmt
->
b
Info
.
sname
,
&
pTableMeta
));
if
(
pTableMeta
->
uid
==
pStmt
->
b
ind
.
tbUid
)
{
pStmt
->
b
ind
.
needParse
=
false
;
if
(
pTableMeta
->
uid
==
pStmt
->
b
Info
.
tbUid
)
{
pStmt
->
b
Info
.
needParse
=
false
;
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -212,29 +212,29 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
STMT_ERR_RET
(
TSDB_CODE_TSC_APP_ERROR
);
}
pStmt
->
b
ind
.
needParse
=
false
;
pStmt
->
b
Info
.
needParse
=
false
;
pStmt
->
b
ind
.
tbUid
=
pTableMeta
->
uid
;
pStmt
->
b
ind
.
tbSuid
=
pTableMeta
->
suid
;
pStmt
->
b
ind
.
tbType
=
pTableMeta
->
tableType
;
pStmt
->
b
ind
.
boundTags
=
pCache
->
boundTags
;
pStmt
->
b
Info
.
tbUid
=
pTableMeta
->
uid
;
pStmt
->
b
Info
.
tbSuid
=
pTableMeta
->
suid
;
pStmt
->
b
Info
.
tbType
=
pTableMeta
->
tableType
;
pStmt
->
b
Info
.
boundTags
=
pCache
->
boundTags
;
return
TSDB_CODE_SUCCESS
;
}
SStmtTableCache
*
pCache
=
taosHashGet
(
pStmt
->
sql
.
pTableCache
,
&
pTableMeta
->
uid
,
sizeof
(
pTableMeta
->
uid
));
if
(
pCache
)
{
pStmt
->
b
ind
.
needParse
=
false
;
pStmt
->
b
Info
.
needParse
=
false
;
pStmt
->
b
ind
.
tbUid
=
pTableMeta
->
uid
;
pStmt
->
b
ind
.
tbSuid
=
pTableMeta
->
suid
;
pStmt
->
b
ind
.
tbType
=
pTableMeta
->
tableType
;
pStmt
->
b
ind
.
boundTags
=
pCache
->
boundTags
;
pStmt
->
b
Info
.
tbUid
=
pTableMeta
->
uid
;
pStmt
->
b
Info
.
tbSuid
=
pTableMeta
->
suid
;
pStmt
->
b
Info
.
tbType
=
pTableMeta
->
tableType
;
pStmt
->
b
Info
.
boundTags
=
pCache
->
boundTags
;
STableDataBlocks
*
pNewBlock
=
NULL
;
STMT_ERR_RET
(
qRebuildStmtDataBlock
(
&
pNewBlock
,
pCache
->
pDataBlock
));
if
(
taosHashPut
(
pStmt
->
exec
.
pBlockHash
,
&
pStmt
->
b
ind
.
tbUid
,
sizeof
(
pStmt
->
bind
.
tbUid
),
&
pNewBlock
,
POINTER_BYTES
))
{
if
(
taosHashPut
(
pStmt
->
exec
.
pBlockHash
,
&
pStmt
->
b
Info
.
tbUid
,
sizeof
(
pStmt
->
bInfo
.
tbUid
),
&
pNewBlock
,
POINTER_BYTES
))
{
STMT_ERR_RET
(
TSDB_CODE_OUT_OF_MEMORY
);
}
...
...
@@ -261,11 +261,11 @@ TAOS_STMT *stmtInit(TAOS *taos) {
taosMemoryFree
(
pStmt
);
return
NULL
;
}
pStmt
->
taos
=
pObj
;
pStmt
->
bInfo
.
needParse
=
true
;
pStmt
->
sql
.
status
=
STMT_INIT
;
pStmt
->
bind
.
needParse
=
true
;
return
pStmt
;
}
...
...
@@ -290,15 +290,15 @@ int stmtSetTbName(TAOS_STMT *stmt, const char *tbName) {
STMT_SWITCH_STATUS
(
pStmt
,
STMT_SETTBNAME
,
TSDB_CODE_TSC_STMT_API_ERROR
);
taosMemoryFree
(
pStmt
->
b
ind
.
tbName
);
taosMemoryFree
(
pStmt
->
b
Info
.
tbName
);
if
(
NULL
==
pStmt
->
exec
.
pRequest
)
{
STMT_ERR_RET
(
buildRequest
(
pStmt
->
taos
,
pStmt
->
sql
.
sqlStr
,
pStmt
->
sql
.
sqlLen
,
&
pStmt
->
exec
.
pRequest
));
}
STMT_ERR_RET
(
qCreateSName
(
&
pStmt
->
b
ind
.
sname
,
tbName
,
pStmt
->
taos
->
acctId
,
pStmt
->
exec
.
pRequest
->
pDb
,
pStmt
->
exec
.
pRequest
->
msgBuf
,
pStmt
->
exec
.
pRequest
->
msgBufLen
));
STMT_ERR_RET
(
qCreateSName
(
&
pStmt
->
b
Info
.
sname
,
tbName
,
pStmt
->
taos
->
acctId
,
pStmt
->
exec
.
pRequest
->
pDb
,
pStmt
->
exec
.
pRequest
->
msgBuf
,
pStmt
->
exec
.
pRequest
->
msgBufLen
));
pStmt
->
b
ind
.
tbName
=
strdup
(
tbName
);
pStmt
->
b
Info
.
tbName
=
strdup
(
tbName
);
STMT_ERR_RET
(
stmtGetFromCache
(
pStmt
));
...
...
@@ -310,17 +310,17 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags) {
STMT_SWITCH_STATUS
(
pStmt
,
STMT_SETTBNAME
,
TSDB_CODE_TSC_STMT_API_ERROR
);
if
(
pStmt
->
b
ind
.
needParse
)
{
if
(
pStmt
->
b
Info
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
ind
.
tbUid
,
sizeof
(
pStmt
->
bind
.
tbUid
));
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
Info
.
tbUid
,
sizeof
(
pStmt
->
bInfo
.
tbUid
));
if
(
NULL
==
pDataBlock
)
{
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
ind
.
tbUid
);
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
Info
.
tbUid
);
STMT_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
STMT_ERR_RET
(
qBindStmtTagsValue
(
pDataBlock
,
pStmt
->
b
ind
.
boundTags
,
pStmt
->
bind
.
tbSuid
,
&
pStmt
->
bind
.
sname
,
tags
,
pStmt
->
exec
.
pRequest
->
msgBuf
,
pStmt
->
exec
.
pRequest
->
msgBufLen
));
STMT_ERR_RET
(
qBindStmtTagsValue
(
pDataBlock
,
pStmt
->
b
Info
.
boundTags
,
pStmt
->
bInfo
.
tbSuid
,
&
pStmt
->
bInfo
.
sname
,
tags
,
pStmt
->
exec
.
pRequest
->
msgBuf
,
pStmt
->
exec
.
pRequest
->
msgBufLen
));
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -331,7 +331,7 @@ int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
STMT_SWITCH_STATUS
(
pStmt
,
STMT_FETCH_TAG_FIELDS
,
TSDB_CODE_TSC_STMT_API_ERROR
);
if
(
pStmt
->
b
ind
.
needParse
)
{
if
(
pStmt
->
b
Info
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
...
...
@@ -340,13 +340,13 @@ int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
STMT_ERR_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
}
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
ind
.
tbUid
,
sizeof
(
pStmt
->
bind
.
tbUid
));
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
Info
.
tbUid
,
sizeof
(
pStmt
->
bInfo
.
tbUid
));
if
(
NULL
==
pDataBlock
)
{
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
ind
.
tbUid
);
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
Info
.
tbUid
);
STMT_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
STMT_ERR_RET
(
qBuildStmtTagFields
(
pDataBlock
,
pStmt
->
b
ind
.
boundTags
,
fieldNum
,
fields
));
STMT_ERR_RET
(
qBuildStmtTagFields
(
pDataBlock
,
pStmt
->
b
Info
.
boundTags
,
fieldNum
,
fields
));
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -356,7 +356,7 @@ int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
STMT_SWITCH_STATUS
(
pStmt
,
STMT_FETCH_COL_FIELDS
,
TSDB_CODE_TSC_STMT_API_ERROR
);
if
(
pStmt
->
b
ind
.
needParse
)
{
if
(
pStmt
->
b
Info
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
...
...
@@ -365,9 +365,9 @@ int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fiel
STMT_ERR_RET
(
TSDB_CODE_TSC_STMT_API_ERROR
);
}
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
ind
.
tbUid
,
sizeof
(
pStmt
->
bind
.
tbUid
));
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
Info
.
tbUid
,
sizeof
(
pStmt
->
bInfo
.
tbUid
));
if
(
NULL
==
pDataBlock
)
{
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
ind
.
tbUid
);
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
Info
.
tbUid
);
STMT_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
...
...
@@ -381,21 +381,21 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) {
STMT_SWITCH_STATUS
(
pStmt
,
STMT_BIND
,
TSDB_CODE_TSC_STMT_API_ERROR
);
if
(
pStmt
->
b
ind
.
needParse
&&
pStmt
->
sql
.
runTimes
&&
pStmt
->
sql
.
type
>
0
&&
STMT_TYPE_MULTI_INSERT
!=
pStmt
->
sql
.
type
)
{
pStmt
->
b
ind
.
needParse
=
false
;
if
(
pStmt
->
b
Info
.
needParse
&&
pStmt
->
sql
.
runTimes
&&
pStmt
->
sql
.
type
>
0
&&
STMT_TYPE_MULTI_INSERT
!=
pStmt
->
sql
.
type
)
{
pStmt
->
b
Info
.
needParse
=
false
;
}
if
(
NULL
==
pStmt
->
exec
.
pRequest
)
{
STMT_ERR_RET
(
buildRequest
(
pStmt
->
taos
,
pStmt
->
sql
.
sqlStr
,
pStmt
->
sql
.
sqlLen
,
&
pStmt
->
exec
.
pRequest
));
}
if
(
pStmt
->
b
ind
.
needParse
)
{
if
(
pStmt
->
b
Info
.
needParse
)
{
STMT_ERR_RET
(
stmtParseSql
(
pStmt
));
}
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
ind
.
tbUid
,
sizeof
(
pStmt
->
bind
.
tbUid
));
STableDataBlocks
*
pDataBlock
=
(
STableDataBlocks
**
)
taosHashGet
(
pStmt
->
exec
.
pBlockHash
,
(
const
char
*
)
&
pStmt
->
b
Info
.
tbUid
,
sizeof
(
pStmt
->
bInfo
.
tbUid
));
if
(
NULL
==
pDataBlock
)
{
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
ind
.
tbUid
);
tscError
(
"table uid %"
PRIx64
"not found in exec blockHash"
,
pStmt
->
b
Info
.
tbUid
);
STMT_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
...
...
tests/script/api/batchprepare.c
浏览文件 @
1e1cca98
...
...
@@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <pthread.h>
#include <unistd.h>
#include "../../../include/client/taos.h"
...
...
@@ -15,19 +16,23 @@ typedef struct {
void
taosMsleep
(
int
mseconds
);
unsigned
long
long
getCurrentTime
(){
struct
timeval
tv
;
if
(
taosGetTimeOfDay
(
&
tv
)
!=
0
)
{
perror
(
"Failed to get current time in ms"
);
exit
(
EXIT_FAILURE
);
}
return
(
uint64_t
)
tv
.
tv_sec
*
1000000ULL
+
(
uint64_t
)
tv
.
tv_usec
;
int32_t
taosGetTimeOfDay
(
struct
timeval
*
tv
)
{
return
gettimeofday
(
tv
,
NULL
);
}
void
*
taosMemoryCalloc
(
int32_t
num
,
int32_t
size
)
{
return
calloc
(
num
,
size
);
}
void
taosMemoryFree
(
const
void
*
ptr
)
{
if
(
ptr
==
NULL
)
return
;
return
free
((
void
*
)
ptr
);
}
static
int64_t
taosGetTimestampUs
()
{
struct
timeval
systemTime
;
taosGetTimeOfDay
(
&
systemTime
);
return
(
int64_t
)
systemTime
.
tv_sec
*
1000000L
+
(
int64_t
)
systemTime
.
tv_usec
;
}
int
stmt_scol_func1
(
TAOS_STMT
*
stmt
)
{
struct
{
...
...
@@ -42,43 +47,50 @@ int stmt_scol_func1(TAOS_STMT *stmt) {
char
bin
[
40
];
char
blob
[
80
];
}
v
=
{
0
};
int32_t
len
[
10
]
=
{
sizeof
(
v
.
ts
),
sizeof
(
v
.
v1
),
sizeof
(
v
.
v2
),
sizeof
(
v
.
f4
),
sizeof
(
v
.
bin
),
sizeof
(
v
.
bin
)};
TAOS_BIND
params
[
10
];
TAOS_BIND
_v2
params
[
10
];
params
[
0
].
buffer_type
=
TSDB_DATA_TYPE_TIMESTAMP
;
params
[
0
].
buffer_length
=
sizeof
(
v
.
ts
);
params
[
0
].
buffer
=
&
v
.
ts
;
params
[
0
].
length
=
&
params
[
0
].
buffer_length
;
params
[
0
].
length
=
&
len
[
0
]
;
params
[
0
].
is_null
=
NULL
;
params
[
0
].
num
=
1
;
params
[
1
].
buffer_type
=
TSDB_DATA_TYPE_TINYINT
;
params
[
1
].
buffer_length
=
sizeof
(
v
.
v1
);
params
[
1
].
buffer
=
&
v
.
v1
;
params
[
1
].
length
=
&
params
[
1
].
buffer_length
;
params
[
1
].
length
=
&
len
[
1
]
;
params
[
1
].
is_null
=
NULL
;
params
[
1
].
num
=
1
;
params
[
2
].
buffer_type
=
TSDB_DATA_TYPE_SMALLINT
;
params
[
2
].
buffer_length
=
sizeof
(
v
.
v2
);
params
[
2
].
buffer
=
&
v
.
v2
;
params
[
2
].
length
=
&
params
[
2
].
buffer_length
;
params
[
2
].
length
=
&
len
[
2
]
;
params
[
2
].
is_null
=
NULL
;
params
[
2
].
num
=
1
;
params
[
3
].
buffer_type
=
TSDB_DATA_TYPE_FLOAT
;
params
[
3
].
buffer_length
=
sizeof
(
v
.
f4
);
params
[
3
].
buffer
=
&
v
.
f4
;
params
[
3
].
length
=
&
params
[
3
].
buffer_length
;
params
[
3
].
length
=
&
len
[
3
]
;
params
[
3
].
is_null
=
NULL
;
params
[
3
].
num
=
1
;
params
[
4
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
4
].
buffer_length
=
sizeof
(
v
.
bin
);
params
[
4
].
buffer
=
v
.
bin
;
params
[
4
].
length
=
&
params
[
4
].
buffer_length
;
params
[
4
].
length
=
&
len
[
4
]
;
params
[
4
].
is_null
=
NULL
;
params
[
4
].
num
=
1
;
params
[
5
].
buffer_type
=
TSDB_DATA_TYPE_BINARY
;
params
[
5
].
buffer_length
=
sizeof
(
v
.
bin
);
params
[
5
].
buffer
=
v
.
bin
;
params
[
5
].
length
=
&
params
[
5
].
buffer_length
;
params
[
5
].
length
=
&
len
[
5
]
;
params
[
5
].
is_null
=
NULL
;
params
[
5
].
num
=
1
;
char
*
sql
=
"insert into ? (ts, v1,v2,f4,bin,bin2) values(?,?,?,?,?,?)"
;
int
code
=
taos_stmt_prepare
(
stmt
,
sql
,
0
);
...
...
@@ -122,7 +134,7 @@ int stmt_scol_func1(TAOS_STMT *stmt) {
return
0
;
}
#if 0
int stmt_scol_func2(TAOS_STMT *stmt) {
struct {
...
...
@@ -4192,7 +4204,7 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) {
return 0;
}
#endif
void
check_result
(
TAOS
*
taos
,
char
*
tname
,
int
printr
,
int
expected
)
{
char
sql
[
255
]
=
"SELECT * FROM "
;
...
...
@@ -4263,7 +4275,7 @@ int sql_perf1(TAOS *taos) {
}
unsigned
long
long
starttime
=
getCurrentTime
();
int64_t
starttime
=
taosGetTimestampUs
();
for
(
int
i
=
0
;
i
<
3000
;
++
i
)
{
result
=
taos_query
(
taos
,
sql
[
i
]);
int
code
=
taos_errno
(
result
);
...
...
@@ -4275,7 +4287,7 @@ int sql_perf1(TAOS *taos) {
taos_free_result
(
result
);
}
unsigned
long
long
endtime
=
getCurrentTime
();
int64_t
endtime
=
taosGetTimestampUs
();
printf
(
"insert total %d records, used %u seconds, avg:%.1f useconds
\n
"
,
3000
*
120
*
60
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
3000
*
120
*
60
));
for
(
int
i
=
0
;
i
<
3000
;
i
++
)
{
...
...
@@ -4291,7 +4303,7 @@ int sql_perf1(TAOS *taos) {
//one table 60 records one time
int
sql_perf_s1
(
TAOS
*
taos
)
{
char
**
sql
=
taosMemoryC
alloc
(
1
,
sizeof
(
char
*
)
*
360000
);
char
**
sql
=
c
alloc
(
1
,
sizeof
(
char
*
)
*
360000
);
TAOS_RES
*
result
;
for
(
int
i
=
0
;
i
<
360000
;
i
++
)
{
...
...
@@ -4316,7 +4328,7 @@ int sql_perf_s1(TAOS *taos) {
}
unsigned
long
long
starttime
=
getCurrentTime
();
unsigned
long
long
starttime
=
taosGetTimestampUs
();
for
(
int
i
=
0
;
i
<
360000
;
++
i
)
{
result
=
taos_query
(
taos
,
sql
[
i
]);
int
code
=
taos_errno
(
result
);
...
...
@@ -4328,7 +4340,7 @@ int sql_perf_s1(TAOS *taos) {
taos_free_result
(
result
);
}
unsigned
long
long
endtime
=
getCurrentTime
();
unsigned
long
long
endtime
=
taosGetTimestampUs
();
printf
(
"insert total %d records, used %u seconds, avg:%.1f useconds
\n
"
,
3000
*
120
*
60
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
3000
*
120
*
60
));
for
(
int
i
=
0
;
i
<
360000
;
i
++
)
{
...
...
@@ -4363,7 +4375,7 @@ int sql_s_perf1(TAOS *taos) {
}
unsigned
long
long
starttime
=
getCurrentTime
();
unsigned
long
long
starttime
=
taosGetTimestampUs
();
for
(
int
i
=
0
;
i
<
3000
;
++
i
)
{
result
=
taos_query
(
taos
,
sql
[
i
]);
int
code
=
taos_errno
(
result
);
...
...
@@ -4375,7 +4387,7 @@ int sql_s_perf1(TAOS *taos) {
taos_free_result
(
result
);
}
unsigned
long
long
endtime
=
getCurrentTime
();
unsigned
long
long
endtime
=
taosGetTimestampUs
();
printf
(
"insert total %d records, used %u seconds, avg:%.1f useconds
\n
"
,
3000
*
120
*
60
,
(
endtime
-
starttime
)
/
1000000UL
,
(
endtime
-
starttime
)
/
(
3000
*
120
*
60
));
for
(
int
i
=
0
;
i
<
3000
;
i
++
)
{
...
...
@@ -4528,7 +4540,7 @@ void* runcase(void *par) {
taos_stmt_close
(
stmt
);
#endif
#if 0
#if 1
prepare(taos, 1, 1);
...
...
@@ -5024,6 +5036,7 @@ void* runcase(void *par) {
printf("check result end\n");
taos_stmt_close(stmt);
#endif
#endif
printf
(
"test end
\n
"
);
...
...
@@ -5066,11 +5079,11 @@ int main(int argc, char *argv[])
exit
(
1
);
}
TdThread
*
pThreadList
=
(
TdThread
*
)
taosMemoryCalloc
(
sizeof
(
TdThread
),
4
);
pthread_t
*
pThreadList
=
(
pthread_t
*
)
taosMemoryCalloc
(
sizeof
(
pthread_t
),
4
);
TdThreadAttr
thattr
;
taosThreadAttrI
nit
(
&
thattr
);
taosThreadAttrSetDetachS
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
pthread_attr_t
thattr
;
pthread_attr_i
nit
(
&
thattr
);
pthread_attr_setdetachs
tate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
T_par
par
[
4
];
par
[
0
].
taos
=
taos
[
0
];
...
...
@@ -5082,13 +5095,13 @@ int main(int argc, char *argv[])
par
[
3
].
taos
=
taos
[
3
];
par
[
3
].
idx
=
3
;
taosThreadC
reate
(
&
(
pThreadList
[
0
]),
&
thattr
,
runcase
,
(
void
*
)
&
par
[
0
]);
//
taosThreadC
reate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//
taosThreadC
reate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//
taosThreadC
reate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
pthread_c
reate
(
&
(
pThreadList
[
0
]),
&
thattr
,
runcase
,
(
void
*
)
&
par
[
0
]);
//
pthread_c
reate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]);
//
pthread_c
reate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]);
//
pthread_c
reate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]);
while
(
1
)
{
taosS
sleep
(
1
);
sleep
(
1
);
}
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录