Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
f12d2521
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
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看板
提交
f12d2521
编写于
7月 29, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-5175]
上级
c7ae4f57
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
113 addition
and
28 deletion
+113
-28
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+9
-9
src/client/src/tscServer.c
src/client/src/tscServer.c
+7
-4
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+5
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+92
-12
未找到文件。
src/client/src/tscAsync.c
浏览文件 @
f12d2521
...
...
@@ -211,27 +211,27 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) {
pSql
->
fp
=
tscAsyncFetchRowsProxy
;
pSql
->
param
=
param
;
if
(
pRes
->
qId
==
0
)
{
tscError
(
"qhandle is invalid"
);
pRes
->
code
=
TSDB_CODE_TSC_INVALID_QHANDLE
;
tscAsyncResultOnError
(
pSql
);
return
;
}
tscResetForNextRetrieve
(
pRes
);
// handle outer query based on the already retrieved nest query results.
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
pCmd
);
if
(
pQueryInfo
->
pUpstream
!=
NULL
&&
taosArrayGetSize
(
pQueryInfo
->
pUpstream
)
>
0
)
{
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
doRetrieveSubqueryData
;
schedMsg
.
fp
=
doRetrieveSubqueryData
;
schedMsg
.
ahandle
=
(
void
*
)
pSql
;
schedMsg
.
thandle
=
(
void
*
)
1
;
schedMsg
.
msg
=
0
;
schedMsg
.
msg
=
0
;
taosScheduleTask
(
tscQhandle
,
&
schedMsg
);
return
;
}
if
(
pRes
->
qId
==
0
)
{
tscError
(
"qhandle is invalid"
);
pRes
->
code
=
TSDB_CODE_TSC_INVALID_QHANDLE
;
tscAsyncResultOnError
(
pSql
);
return
;
}
if
(
pCmd
->
command
==
TSDB_SQL_TABLE_JOIN_RETRIEVE
)
{
tscFetchDatablockForSubquery
(
pSql
);
}
else
if
(
pRes
->
completed
)
{
...
...
src/client/src/tscServer.c
浏览文件 @
f12d2521
...
...
@@ -392,14 +392,17 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg, SRpcEpSet *pEpSet) {
// single table query error need to be handled here.
if
((
cmd
==
TSDB_SQL_SELECT
||
cmd
==
TSDB_SQL_UPDATE_TAGS_VAL
)
&&
(((
rpcMsg
->
code
==
TSDB_CODE_TDB_INVALID_TABLE_ID
||
// change the retry procedure
(((
rpcMsg
->
code
==
TSDB_CODE_TDB_INVALID_TABLE_ID
||
rpcMsg
->
code
==
TSDB_CODE_VND_INVALID_VGROUP_ID
))
||
rpcMsg
->
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
||
// change the retry procedure
rpcMsg
->
code
==
TSDB_CODE_RPC_NETWORK_UNAVAIL
||
rpcMsg
->
code
==
TSDB_CODE_APP_NOT_READY
))
{
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
(
TSDB_QUERY_TYPE_STABLE_SUBQUERY
|
TSDB_QUERY_TYPE_SUBQUERY
|
// 1. super table subquery
// 2. nest queries are all not updated the tablemeta and retry parse the sql after cleanup local tablemeta/vgroup id buffer
if
((
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
(
TSDB_QUERY_TYPE_STABLE_SUBQUERY
|
TSDB_QUERY_TYPE_SUBQUERY
|
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
))
&&
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_PROJECTION_QUERY
))
{
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_PROJECTION_QUERY
))
||
(
pQueryInfo
->
pUpstream
!=
NULL
))
{
// do nothing in case of super table subquery
}
else
{
pSql
->
retry
+=
1
;
...
...
src/client/src/tscSubquery.c
浏览文件 @
f12d2521
...
...
@@ -2705,7 +2705,6 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
// release allocated resource
tscDestroyGlobalMergerEnv
(
trsupport
->
pExtMemBuffer
,
trsupport
->
pOrderDescriptor
,
pState
->
numOfSub
);
tscFreeRetrieveSup
(
pSql
);
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
...
...
@@ -2716,10 +2715,13 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
int32_t
code
=
pParentSql
->
res
.
code
;
if
((
code
==
TSDB_CODE_TDB_INVALID_TABLE_ID
||
code
==
TSDB_CODE_VND_INVALID_VGROUP_ID
)
&&
pParentSql
->
retry
<
pParentSql
->
maxRetry
)
{
// remove the cached tableMeta and vgroup id list, and then parse the sql again
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pParentSql
->
cmd
,
0
);
SSqlCmd
*
pParentCmd
=
&
pParentSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pParentCmd
,
0
);
tscRemoveTableMetaBuf
(
pTableMetaInfo
,
pParentSql
->
self
);
tscResetSqlCmd
(
&
pParentSql
->
cmd
,
true
);
pParentCmd
->
pTableMetaMap
=
tscCleanupTableMetaMap
(
pParentCmd
->
pTableMetaMap
);
pParentCmd
->
pTableMetaMap
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
pParentSql
->
res
.
code
=
TSDB_CODE_SUCCESS
;
pParentSql
->
retry
++
;
...
...
src/client/src/tscUtil.c
浏览文件 @
f12d2521
...
...
@@ -3829,13 +3829,64 @@ static void tscSubqueryRetrieveCallback(void* param, TAOS_RES* tres, int code) {
}
}
// todo handle the failure
static
void
tscSubqueryCompleteCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
SSqlObj
*
pSql
=
tres
;
SRetrieveSupport
*
ps
=
param
;
if
(
pSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
SSqlObj
*
pParentSql
=
ps
->
pParentSql
;
int32_t
index
=
ps
->
subqueryIndex
;
bool
ret
=
subAndCheckDone
(
pSql
,
pParentSql
,
index
);
tfree
(
ps
);
pSql
->
param
=
NULL
;
if
(
!
ret
)
{
tscDebug
(
"0x%"
PRIx64
" sub:0x%"
PRIx64
" orderOfSub:%d completed, not all subquery finished"
,
pParentSql
->
self
,
pSql
->
self
,
index
);
return
;
}
// todo refactor
tscDebug
(
"0x%"
PRIx64
" all subquery response received, retry"
,
pParentSql
->
self
);
SSqlCmd
*
pParentCmd
=
&
pParentSql
->
cmd
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
pParentCmd
,
0
);
tscRemoveTableMetaBuf
(
pTableMetaInfo
,
pParentSql
->
self
);
pParentCmd
->
pTableMetaMap
=
tscCleanupTableMetaMap
(
pParentCmd
->
pTableMetaMap
);
pParentCmd
->
pTableMetaMap
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
HASH_NO_LOCK
);
pParentSql
->
res
.
code
=
TSDB_CODE_SUCCESS
;
pParentSql
->
retry
++
;
tscDebug
(
"0x%"
PRIx64
" retry parse sql and send query, prev error: %s, retry:%d"
,
pParentSql
->
self
,
tstrerror
(
code
),
pParentSql
->
retry
);
code
=
tsParseSql
(
pParentSql
,
true
);
if
(
code
==
TSDB_CODE_TSC_ACTION_IN_PROGRESS
)
{
return
;
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pParentSql
->
res
.
code
=
code
;
tscAsyncResultOnError
(
pParentSql
);
return
;
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfo
(
pParentCmd
);
executeQuery
(
pParentSql
,
pQueryInfo
);
return
;
}
taos_fetch_rows_a
(
tres
,
tscSubqueryRetrieveCallback
,
param
);
}
// do execute the query according to the query execution plan
void
executeQuery
(
SSqlObj
*
pSql
,
SQueryInfo
*
pQueryInfo
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
numOfInit
=
0
;
if
(
pSql
->
cmd
.
command
==
TSDB_SQL_RETRIEVE_EMPTY_RESULT
)
{
(
*
pSql
->
fp
)(
pSql
->
param
,
pSql
,
0
);
return
;
...
...
@@ -3850,7 +3901,12 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
pSql
->
pSubs
=
calloc
(
pSql
->
subState
.
numOfSub
,
POINTER_BYTES
);
pSql
->
subState
.
states
=
calloc
(
pSql
->
subState
.
numOfSub
,
sizeof
(
int8_t
));
pthread_mutex_init
(
&
pSql
->
subState
.
mutex
,
NULL
);
code
=
pthread_mutex_init
(
&
pSql
->
subState
.
mutex
,
NULL
);
if
(
pSql
->
pSubs
==
NULL
||
pSql
->
subState
.
states
==
NULL
||
code
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
}
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SQueryInfo
*
pSub
=
taosArrayGetP
(
pQueryInfo
->
pUpstream
,
i
);
...
...
@@ -3858,45 +3914,69 @@ void executeQuery(SSqlObj* pSql, SQueryInfo* pQueryInfo) {
pSql
->
cmd
.
active
=
pSub
;
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
// TODO handle memory failure
SSqlObj
*
pNew
=
(
SSqlObj
*
)
calloc
(
1
,
sizeof
(
SSqlObj
));
if
(
pNew
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
// return NULL
;
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
_error
;
}
pNew
->
pTscObj
=
pSql
->
pTscObj
;
pNew
->
pTscObj
=
pSql
->
pTscObj
;
pNew
->
signature
=
pNew
;
pNew
->
sqlstr
=
strdup
(
pSql
->
sqlstr
);
// todo refactor
pNew
->
fp
=
tscSubqueryCompleteCallback
;
pNew
->
sqlstr
=
strdup
(
pSql
->
sqlstr
);
pNew
->
fp
=
tscSubqueryCompleteCallback
;
pNew
->
maxRetry
=
pSql
->
maxRetry
;
tsem_init
(
&
pNew
->
rspSem
,
0
,
0
);
SRetrieveSupport
*
ps
=
calloc
(
1
,
sizeof
(
SRetrieveSupport
));
// todo use object id
if
(
ps
==
NULL
)
{
tscFreeSqlObj
(
pNew
);
goto
_error
;
}
ps
->
pParentSql
=
pSql
;
ps
->
subqueryIndex
=
i
;
pNew
->
param
=
ps
;
pSql
->
pSubs
[
i
]
=
pNew
;
registerSqlObj
(
pNew
);
SSqlCmd
*
pCmd
=
&
pNew
->
cmd
;
pCmd
->
command
=
TSDB_SQL_SELECT
;
if
(
tscAddQueryInfo
(
pCmd
)
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
tscAddQueryInfo
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfo
(
pCmd
);
tscQueryInfoCopy
(
pNewQueryInfo
,
pSub
);
numOfInit
++
;
}
for
(
int32_t
i
=
0
;
i
<
pSql
->
subState
.
numOfSub
;
++
i
)
{
SSqlObj
*
psub
=
pSql
->
pSubs
[
i
];
registerSqlObj
(
psub
);
// create sub query to handle the sub query.
executeQuery
(
pNew
,
pNewQueryInfo
);
SQueryInfo
*
pq
=
tscGetQueryInfo
(
&
psub
->
cmd
);
executeQuery
(
psub
,
pq
);
}
// merge sub query result and generate final results
return
;
}
pSql
->
cmd
.
active
=
pQueryInfo
;
doExecuteQuery
(
pSql
,
pQueryInfo
);
return
;
_error:
for
(
int32_t
i
=
0
;
i
<
numOfInit
;
++
i
)
{
SSqlObj
*
p
=
pSql
->
pSubs
[
i
];
tscFreeSqlObj
(
p
);
}
pSql
->
res
.
code
=
code
;
pSql
->
subState
.
numOfSub
=
0
;
// not initialized sub query object will not be freed
tfree
(
pSql
->
subState
.
states
);
tfree
(
pSql
->
pSubs
);
tscAsyncResultOnError
(
pSql
);
}
int16_t
tscGetJoinTagColIdByUid
(
STagCond
*
pTagCond
,
uint64_t
uid
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录