Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c1968083
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
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看板
未验证
提交
c1968083
编写于
6月 18, 2020
作者:
S
Shengliang Guan
提交者:
GitHub
6月 18, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2340 from taosdata/feature/query
Feature/query
上级
6c5c703d
f311f8aa
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
441 addition
and
428 deletion
+441
-428
src/client/inc/tscLocalMerge.h
src/client/inc/tscLocalMerge.h
+6
-19
src/client/inc/tscSubquery.h
src/client/inc/tscSubquery.h
+0
-2
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+2
-1
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+385
-352
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+0
-1
src/util/src/terror.c
src/util/src/terror.c
+0
-1
tests/script/general/parser/alter.sim
tests/script/general/parser/alter.sim
+40
-40
tests/script/general/parser/testSuite.sim
tests/script/general/parser/testSuite.sim
+7
-11
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+1
-1
未找到文件。
src/client/inc/tscLocalMerge.h
浏览文件 @
c1968083
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#ifndef TDENGINE_TSC
SECONARY
MERGE_H
#ifndef TDENGINE_TSC
LOCAL
MERGE_H
#define TDENGINE_TSC
SECONARY
MERGE_H
#define TDENGINE_TSC
LOCAL
MERGE_H
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -27,14 +27,7 @@ extern "C" {
...
@@ -27,14 +27,7 @@ extern "C" {
#include "tsclient.h"
#include "tsclient.h"
#define MAX_NUM_OF_SUBQUERY_RETRY 3
#define MAX_NUM_OF_SUBQUERY_RETRY 3
/*
* @version 0.1
* @date 2018/01/05
* @author liaohj
* management of client-side reducer for metric query
*/
struct
SQLFunctionCtx
;
struct
SQLFunctionCtx
;
typedef
struct
SLocalDataSource
{
typedef
struct
SLocalDataSource
{
...
@@ -60,7 +53,6 @@ typedef struct SLocalReducer {
...
@@ -60,7 +53,6 @@ typedef struct SLocalReducer {
char
*
prevRowOfInput
;
char
*
prevRowOfInput
;
tFilePage
*
pResultBuf
;
tFilePage
*
pResultBuf
;
int32_t
nResultBufSize
;
int32_t
nResultBufSize
;
// char * pBufForInterpo; // intermediate buffer for interpolation
tFilePage
*
pTempBuffer
;
tFilePage
*
pTempBuffer
;
struct
SQLFunctionCtx
*
pCtx
;
struct
SQLFunctionCtx
*
pCtx
;
int32_t
rowSize
;
// size of each intermediate result.
int32_t
rowSize
;
// size of each intermediate result.
...
@@ -81,13 +73,8 @@ typedef struct SLocalReducer {
...
@@ -81,13 +73,8 @@ typedef struct SLocalReducer {
}
SLocalReducer
;
}
SLocalReducer
;
typedef
struct
SSubqueryState
{
typedef
struct
SSubqueryState
{
/*
int32_t
numOfRemain
;
// the number of remain unfinished subquery
* the number of completed retrieval subquery, once this value equals to numOfVnodes,
int32_t
numOfTotal
;
// the number of total sub-queries
* all retrieval are completed.Local merge is launched.
*/
int32_t
numOfCompleted
;
int32_t
numOfTotal
;
// number of total sub-queries
int32_t
code
;
// code from subqueries
uint64_t
numOfRetrievedRows
;
// total number of points in this query
uint64_t
numOfRetrievedRows
;
// total number of points in this query
}
SSubqueryState
;
}
SSubqueryState
;
...
@@ -128,4 +115,4 @@ int32_t tscDoLocalMerge(SSqlObj *pSql);
...
@@ -128,4 +115,4 @@ int32_t tscDoLocalMerge(SSqlObj *pSql);
}
}
#endif
#endif
#endif // TDENGINE_TSC
SECONARY
MERGE_H
#endif // TDENGINE_TSC
LOCAL
MERGE_H
src/client/inc/tscSubquery.h
浏览文件 @
c1968083
...
@@ -26,11 +26,9 @@ extern "C" {
...
@@ -26,11 +26,9 @@ extern "C" {
void
tscFetchDatablockFromSubquery
(
SSqlObj
*
pSql
);
void
tscFetchDatablockFromSubquery
(
SSqlObj
*
pSql
);
void
tscSetupOutputColumnIndex
(
SSqlObj
*
pSql
);
void
tscSetupOutputColumnIndex
(
SSqlObj
*
pSql
);
int32_t
tscLaunchSecondPhaseSubqueries
(
SSqlObj
*
pSql
);
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
);
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
);
SJoinSupporter
*
tscCreateJoinSupporter
(
SSqlObj
*
pSql
,
SSubqueryState
*
pState
,
int32_t
index
);
SJoinSupporter
*
tscCreateJoinSupporter
(
SSqlObj
*
pSql
,
SSubqueryState
*
pState
,
int32_t
index
);
void
tscDestroyJoinSupporter
(
SJoinSupporter
*
pSupporter
);
int32_t
tscHandleMasterJoinQuery
(
SSqlObj
*
pSql
);
int32_t
tscHandleMasterJoinQuery
(
SSqlObj
*
pSql
);
...
...
src/client/inc/tscUtil.h
浏览文件 @
c1968083
...
@@ -64,7 +64,8 @@ typedef struct SJoinSupporter {
...
@@ -64,7 +64,8 @@ typedef struct SJoinSupporter {
SSubqueryState
*
pState
;
SSubqueryState
*
pState
;
SSqlObj
*
pObj
;
// parent SqlObj
SSqlObj
*
pObj
;
// parent SqlObj
int32_t
subqueryIndex
;
// index of sub query
int32_t
subqueryIndex
;
// index of sub query
int64_t
interval
;
// interval time
int64_t
intervalTime
;
// interval time
int64_t
slidingTime
;
// sliding time
SLimitVal
limit
;
// limit info
SLimitVal
limit
;
// limit info
uint64_t
uid
;
// query meter uid
uint64_t
uid
;
// query meter uid
SArray
*
colList
;
// previous query information, no need to use this attribute, and the corresponding attribution
SArray
*
colList
;
// previous query information, no need to use this attribute, and the corresponding attribution
...
...
src/client/src/tscSubquery.c
浏览文件 @
c1968083
...
@@ -12,12 +12,12 @@
...
@@ -12,12 +12,12 @@
* You should have received a copy of the GNU Affero General Public License
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "os.h"
#include "tscSubquery.h"
#include "tscSubquery.h"
#include <qast.h>
#include "qast.h"
#include <tcompare.h>
#include "tcompare.h"
#include <tschemautil.h>
#include "tschemautil.h"
#include "os.h"
#include "qtsbuf.h"
#include "qtsbuf.h"
#include "tscLog.h"
#include "tscLog.h"
#include "tsclient.h"
#include "tsclient.h"
...
@@ -169,7 +169,8 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
...
@@ -169,7 +169,8 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
pSupporter
->
subqueryIndex
=
index
;
pSupporter
->
subqueryIndex
=
index
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
);
pSupporter
->
interval
=
pQueryInfo
->
intervalTime
;
pSupporter
->
intervalTime
=
pQueryInfo
->
intervalTime
;
pSupporter
->
slidingTime
=
pQueryInfo
->
slidingTime
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
pSupporter
->
limit
=
pQueryInfo
->
limit
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
index
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetTableMetaInfoFromCmd
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
index
);
...
@@ -186,7 +187,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
...
@@ -186,7 +187,7 @@ SJoinSupporter* tscCreateJoinSupporter(SSqlObj* pSql, SSubqueryState* pState, in
return
pSupporter
;
return
pSupporter
;
}
}
void
tscDestroyJoinSupporter
(
SJoinSupporter
*
pSupporter
)
{
static
void
tscDestroyJoinSupporter
(
SJoinSupporter
*
pSupporter
)
{
if
(
pSupporter
==
NULL
)
{
if
(
pSupporter
==
NULL
)
{
return
;
return
;
}
}
...
@@ -217,7 +218,7 @@ void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
...
@@ -217,7 +218,7 @@ void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) {
* primary timestamp column , the secondary query is not necessary
* primary timestamp column , the secondary query is not necessary
*
*
*/
*/
bool
needSecondaryQuery
(
SQueryInfo
*
pQueryInfo
)
{
static
UNUSED_FUNC
bool
needSecondaryQuery
(
SQueryInfo
*
pQueryInfo
)
{
size_t
numOfCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
size_t
numOfCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
@@ -233,14 +234,11 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
...
@@ -233,14 +234,11 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
/*
/*
* launch secondary stage query to fetch the result that contains timestamp in set
* launch secondary stage query to fetch the result that contains timestamp in set
*/
*/
int32_t
tscLaunchSecondPhaseSubqueries
(
SSqlObj
*
pSql
)
{
static
int32_t
tscLaunchSecondPhaseSubqueries
(
SSqlObj
*
pSql
)
{
int32_t
numOfSub
=
0
;
int32_t
numOfSub
=
0
;
SJoinSupporter
*
pSupporter
=
NULL
;
SJoinSupporter
*
pSupporter
=
NULL
;
/*
//If the columns are not involved in the final select clause, the corresponding query will not be issued.
* If the columns are not involved in the final select clause,
* the corresponding query will not be issued.
*/
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
pSupporter
=
pSql
->
pSubs
[
i
]
->
param
;
pSupporter
=
pSql
->
pSubs
[
i
]
->
param
;
if
(
taosArrayGetSize
(
pSupporter
->
exprList
)
>
0
)
{
if
(
taosArrayGetSize
(
pSupporter
->
exprList
)
>
0
)
{
...
@@ -251,13 +249,12 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
...
@@ -251,13 +249,12 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
assert
(
numOfSub
>
0
);
assert
(
numOfSub
>
0
);
// scan all subquery, if one sub query has only ts, ignore it
// scan all subquery, if one sub query has only ts, ignore it
tscTrace
(
"%p start to launch secondary subquery, total:%d, only:%d needs to query, others are not retrieve in "
tscTrace
(
"%p start to launch secondary subquery, total:%d, only:%d needs to query"
,
pSql
,
pSql
->
numOfSubs
,
numOfSub
);
"select clause"
,
pSql
,
pSql
->
numOfSubs
,
numOfSub
);
//the subqueries that do not actually launch the secondary query to virtual node is set as completed.
//the subqueries that do not actually launch the secondary query to virtual node is set as completed.
SSubqueryState
*
pState
=
pSupporter
->
pState
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOf
Completed
=
(
pSql
->
numOfSubs
-
numOfSub
)
;
pState
->
numOf
Remain
=
numOfSub
;
bool
success
=
true
;
bool
success
=
true
;
...
@@ -301,7 +298,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
...
@@ -301,7 +298,8 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
// set the second stage sub query for join process
// set the second stage sub query for join process
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
);
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
);
pQueryInfo
->
intervalTime
=
pSupporter
->
interval
;
pQueryInfo
->
intervalTime
=
pSupporter
->
intervalTime
;
pQueryInfo
->
slidingTime
=
pSupporter
->
slidingTime
;
pQueryInfo
->
groupbyExpr
=
pSupporter
->
groupbyExpr
;
pQueryInfo
->
groupbyExpr
=
pSupporter
->
groupbyExpr
;
tscTagCondCopy
(
&
pQueryInfo
->
tagCond
,
&
pSupporter
->
tagCond
);
tscTagCondCopy
(
&
pQueryInfo
->
tagCond
,
&
pSupporter
->
tagCond
);
...
@@ -375,6 +373,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
...
@@ -375,6 +373,7 @@ int32_t tscLaunchSecondPhaseSubqueries(SSqlObj* pSql) {
if
(
pSql
->
pSubs
[
i
]
==
NULL
)
{
if
(
pSql
->
pSubs
[
i
]
==
NULL
)
{
continue
;
continue
;
}
}
tscDoQuery
(
pSql
->
pSubs
[
i
]);
tscDoQuery
(
pSql
->
pSubs
[
i
]);
}
}
...
@@ -405,11 +404,9 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
...
@@ -405,11 +404,9 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
}
}
static
void
quitAllSubquery
(
SSqlObj
*
pSqlObj
,
SJoinSupporter
*
pSupporter
)
{
static
void
quitAllSubquery
(
SSqlObj
*
pSqlObj
,
SJoinSupporter
*
pSupporter
)
{
int32_t
numOfTotal
=
pSupporter
->
pState
->
numOfTotal
;
assert
(
pSupporter
->
pState
->
numOfRemain
>
0
);
int32_t
finished
=
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
);
if
(
atomic_sub_fetch_32
(
&
pSupporter
->
pState
->
numOfRemain
,
1
)
<=
0
)
{
pSqlObj
->
res
.
code
=
pSupporter
->
pState
->
code
;
if
(
finished
>=
numOfTotal
)
{
tscError
(
"%p all subquery return and query failed, global code:%d"
,
pSqlObj
,
pSqlObj
->
res
.
code
);
tscError
(
"%p all subquery return and query failed, global code:%d"
,
pSqlObj
,
pSqlObj
->
res
.
code
);
freeJoinSubqueryObj
(
pSqlObj
);
freeJoinSubqueryObj
(
pSqlObj
);
}
}
...
@@ -421,7 +418,7 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, STimeWindow* win) {
...
@@ -421,7 +418,7 @@ static void updateQueryTimeRange(SQueryInfo* pQueryInfo, STimeWindow* win) {
pQueryInfo
->
window
=
*
win
;
pQueryInfo
->
window
=
*
win
;
}
}
static
void
tSIntersectionAndLaunchSecQuery
(
SJoinSupporter
*
pSupporter
,
SSqlObj
*
pSql
)
{
static
UNUSED_FUNC
void
tSIntersectionAndLaunchSecQuery
(
SJoinSupporter
*
pSupporter
,
SSqlObj
*
pSql
)
{
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SQueryInfo
*
pParentQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
SQueryInfo
*
pParentQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
...
@@ -443,22 +440,7 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj*
...
@@ -443,22 +440,7 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj*
// return;
// return;
// }
// }
// }
// }
int32_t
numOfTotal
=
pSupporter
->
pState
->
numOfTotal
;
int32_t
finished
=
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
);
if
(
finished
>=
numOfTotal
)
{
assert
(
finished
==
numOfTotal
);
if
(
pSupporter
->
pState
->
code
!=
TSDB_CODE_SUCCESS
)
{
tscTrace
(
"%p sub:%p, numOfSub:%d, quit from further procedure due to other queries failure"
,
pParentSql
,
pSql
,
pSupporter
->
subqueryIndex
);
freeJoinSubqueryObj
(
pParentSql
);
return
;
}
tscTrace
(
"%p all subqueries retrieve ts complete, do ts block intersect"
,
pParentSql
);
SJoinSupporter
*
p1
=
pParentSql
->
pSubs
[
0
]
->
param
;
SJoinSupporter
*
p1
=
pParentSql
->
pSubs
[
0
]
->
param
;
SJoinSupporter
*
p2
=
pParentSql
->
pSubs
[
1
]
->
param
;
SJoinSupporter
*
p2
=
pParentSql
->
pSubs
[
1
]
->
param
;
...
@@ -471,7 +453,6 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj*
...
@@ -471,7 +453,6 @@ static void tSIntersectionAndLaunchSecQuery(SJoinSupporter* pSupporter, SSqlObj*
updateQueryTimeRange
(
pParentQueryInfo
,
&
win
);
updateQueryTimeRange
(
pParentQueryInfo
,
&
win
);
tscLaunchSecondPhaseSubqueries
(
pParentSql
);
tscLaunchSecondPhaseSubqueries
(
pParentSql
);
}
}
}
}
}
int32_t
tscCompareTidTags
(
const
void
*
p1
,
const
void
*
p2
)
{
int32_t
tscCompareTidTags
(
const
void
*
p1
,
const
void
*
p2
)
{
...
@@ -545,11 +526,13 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
...
@@ -545,11 +526,13 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
tscAddSpecialColumnForSelect
(
pQueryInfo
,
0
,
TSDB_FUNC_TS_COMP
,
&
index
,
&
colSchema
,
TSDB_COL_NORMAL
);
tscAddSpecialColumnForSelect
(
pQueryInfo
,
0
,
TSDB_FUNC_TS_COMP
,
&
index
,
&
colSchema
,
TSDB_COL_NORMAL
);
// set the tags value for ts_comp function
// set the tags value for ts_comp function
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
if
(
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
int16_t
tagColId
=
tscGetJoinTagColIdByUid
(
&
pSupporter
->
tagCond
,
pTableMetaInfo
->
pTableMeta
->
uid
);
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
pExpr
->
param
->
i64Key
=
tagColId
;
int16_t
tagColId
=
tscGetJoinTagColIdByUid
(
&
pSupporter
->
tagCond
,
pTableMetaInfo
->
pTableMeta
->
uid
);
pExpr
->
numOfParams
=
1
;
pExpr
->
param
->
i64Key
=
tagColId
;
pExpr
->
numOfParams
=
1
;
}
// add the filter tag column
// add the filter tag column
if
(
pSupporter
->
colList
!=
NULL
)
{
if
(
pSupporter
->
colList
!=
NULL
)
{
size_t
s
=
taosArrayGetSize
(
pSupporter
->
colList
);
size_t
s
=
taosArrayGetSize
(
pSupporter
->
colList
);
...
@@ -575,7 +558,7 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
...
@@ -575,7 +558,7 @@ static void issueTSCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj*
tscProcessSql
(
pSql
);
tscProcessSql
(
pSql
);
}
}
static
bool
checkFor
IdenticalTagVal
(
SQueryInfo
*
pQueryInfo
,
SJoinSupporter
*
p1
,
void
*
pSql
)
{
static
bool
checkFor
DuplicateTagVal
(
SQueryInfo
*
pQueryInfo
,
SJoinSupporter
*
p1
,
SSqlObj
*
pPSqlObj
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
SSchema
*
pSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
// todo: tags mismatch, tags not completed
SSchema
*
pSchema
=
tscGetTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
// todo: tags mismatch, tags not completed
...
@@ -587,8 +570,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1,
...
@@ -587,8 +570,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1,
STidTags
*
p
=
(
STidTags
*
)
varDataVal
(
p1
->
pIdTagList
+
i
*
p1
->
tagSize
);
STidTags
*
p
=
(
STidTags
*
)
varDataVal
(
p1
->
pIdTagList
+
i
*
p1
->
tagSize
);
if
(
doCompare
(
prev
->
tag
,
p
->
tag
,
pColSchema
->
type
,
pColSchema
->
bytes
)
==
0
)
{
if
(
doCompare
(
prev
->
tag
,
p
->
tag
,
pColSchema
->
type
,
pColSchema
->
bytes
)
==
0
)
{
tscError
(
"%p join tags have same value for different table, free all sub SqlObj and quit"
,
p
Sql
);
tscError
(
"%p join tags have same value for different table, free all sub SqlObj and quit"
,
p
PSqlObj
);
p
1
->
pState
->
code
=
TSDB_CODE_QRY_DUP_JOIN_KEY
;
p
PSqlObj
->
res
.
code
=
TSDB_CODE_QRY_DUP_JOIN_KEY
;
return
false
;
return
false
;
}
}
}
}
...
@@ -596,8 +579,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1,
...
@@ -596,8 +579,8 @@ static bool checkForIdenticalTagVal(SQueryInfo* pQueryInfo, SJoinSupporter* p1,
return
true
;
return
true
;
}
}
static
void
getIntersectionOfTa
gVal
(
SQueryInfo
*
pQueryInfo
,
SSqlObj
*
pParentSql
,
SArray
**
s1
,
SArray
**
s2
)
{
static
void
getIntersectionOfTa
bleTuple
(
SQueryInfo
*
pQueryInfo
,
SSqlObj
*
pParentSql
,
SArray
**
s1
,
SArray
**
s2
)
{
tscTrace
(
"%p all subqueries retrieve
tags
complete, do tags match"
,
pParentSql
);
tscTrace
(
"%p all subqueries retrieve
<tid, tags>
complete, do tags match"
,
pParentSql
);
SJoinSupporter
*
p1
=
pParentSql
->
pSubs
[
0
]
->
param
;
SJoinSupporter
*
p1
=
pParentSql
->
pSubs
[
0
]
->
param
;
SJoinSupporter
*
p2
=
pParentSql
->
pSubs
[
1
]
->
param
;
SJoinSupporter
*
p2
=
pParentSql
->
pSubs
[
1
]
->
param
;
...
@@ -613,7 +596,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql,
...
@@ -613,7 +596,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql,
*
s1
=
taosArrayInit
(
p1
->
num
,
p1
->
tagSize
);
*
s1
=
taosArrayInit
(
p1
->
num
,
p1
->
tagSize
);
*
s2
=
taosArrayInit
(
p2
->
num
,
p2
->
tagSize
);
*
s2
=
taosArrayInit
(
p2
->
num
,
p2
->
tagSize
);
if
(
!
(
checkFor
IdenticalTagVal
(
pQueryInfo
,
p1
,
pParentSql
)
&&
checkForIdentical
TagVal
(
pQueryInfo
,
p2
,
pParentSql
)))
{
if
(
!
(
checkFor
DuplicateTagVal
(
pQueryInfo
,
p1
,
pParentSql
)
&&
checkForDuplicate
TagVal
(
pQueryInfo
,
p2
,
pParentSql
)))
{
freeJoinSubqueryObj
(
pParentSql
);
freeJoinSubqueryObj
(
pParentSql
);
pParentSql
->
res
.
code
=
TSDB_CODE_QRY_DUP_JOIN_KEY
;
pParentSql
->
res
.
code
=
TSDB_CODE_QRY_DUP_JOIN_KEY
;
tscQueueAsyncRes
(
pParentSql
);
tscQueueAsyncRes
(
pParentSql
);
...
@@ -642,7 +625,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql,
...
@@ -642,7 +625,7 @@ static void getIntersectionOfTagVal(SQueryInfo* pQueryInfo, SSqlObj* pParentSql,
}
}
}
}
static
void
joinRetrieveCallback
(
void
*
param
,
TAOS_RES
*
tres
,
in
t
numOfRows
)
{
static
void
tidTagRetrieveCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int32_
t
numOfRows
)
{
SJoinSupporter
*
pSupporter
=
(
SJoinSupporter
*
)
param
;
SJoinSupporter
*
pSupporter
=
(
SJoinSupporter
*
)
param
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
...
@@ -652,239 +635,287 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -652,239 +635,287 @@ static void joinRetrieveCallback(void* param, TAOS_RES* tres, int numOfRows) {
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
assert
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
));
//
response of tag retrieve
//
check for the error code firstly
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
)
)
{
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
// todo
handle error
// todo
retry if other subqueries are not failed
if
(
numOfRows
==
0
||
pRes
->
completed
)
{
assert
(
numOfRows
<
0
&&
numOfRows
==
taos_errno
(
pSql
));
if
(
numOfRows
>
0
)
{
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
size_t
validLen
=
pSupporter
->
tagSize
*
pRes
->
numOfRows
;
size_t
length
=
pSupporter
->
totalLen
+
validLen
;
pParentSql
->
res
.
code
=
numOfRows
;
char
*
tmp
=
realloc
(
pSupporter
->
pIdTagList
,
length
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
assert
(
tmp
!=
NULL
);
pSupporter
->
pIdTagList
=
tmp
;
memcpy
(
pSupporter
->
pIdTagList
+
pSupporter
->
totalLen
,
pRes
->
data
,
validLen
);
tscQueueAsyncRes
(
pParentSql
);
pSupporter
->
totalLen
+=
validLen
;
return
;
pSupporter
->
num
+=
pRes
->
numOfRows
;
}
}
// <tid + tag> tuples have been retrieved to client, try <tid + tag> tuples from the next vnode
// keep the results in memory
if
(
hasMoreVnodesToTry
(
pSql
))
{
if
(
numOfRows
>
0
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
size_t
validLen
=
pSupporter
->
tagSize
*
pRes
->
numOfRows
;
size_t
length
=
pSupporter
->
totalLen
+
validLen
;
int32_t
totalVgroups
=
pTableMetaInfo
->
vgroupList
->
numOfVgroups
;
// todo handle memory error
pTableMetaInfo
->
vgroupIndex
+=
1
;
char
*
tmp
=
realloc
(
pSupporter
->
pIdTagList
,
length
);
assert
(
pTableMetaInfo
->
vgroupIndex
<
totalVgroups
);
if
(
tmp
==
NULL
)
{
tscError
(
"%p failed to malloc memory"
,
pSql
);
tscTrace
(
"%p tid_tag from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d"
,
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
pSql
,
pTableMetaInfo
->
vgroupIndex
-
1
,
pTableMetaInfo
->
vgroupIndex
,
totalVgroups
,
quitAllSubquery
(
pParentSql
,
pSupporter
);
pSupporter
->
num
);
pCmd
->
command
=
TSDB_SQL_SELECT
;
tscQueueAsyncRes
(
pParentSql
);
tscResetForNextRetrieve
(
&
pSql
->
res
);
return
;
}
// set the callback function
pSupporter
->
pIdTagList
=
tmp
;
pSql
->
fp
=
tscJoinQueryCallback
;
tscProcessSql
(
pSql
);
return
;
}
int32_t
numOfTotal
=
pSupporter
->
pState
->
numOfTotal
;
memcpy
(
pSupporter
->
pIdTagList
+
pSupporter
->
totalLen
,
pRes
->
data
,
validLen
);
int32_t
finished
=
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
);
pSupporter
->
totalLen
+=
validLen
;
if
(
finished
<
numOfTotal
)
{
pSupporter
->
num
+=
pRes
->
numOfRows
;
return
;
}
// all subquery are returned, start to compare the tags
// query not completed, continue to retrieve tid + tag tuples
assert
(
finished
==
numOfTotal
);
if
(
!
pRes
->
completed
)
{
taos_fetch_rows_a
(
tres
,
tidTagRetrieveCallback
,
param
);
return
;
}
}
SArray
*
s1
=
NULL
,
*
s2
=
NULL
;
// data in current vnode has all returned to client, try next vnode if exits
getIntersectionOfTagVal
(
pQueryInfo
,
pParentSql
,
&
s1
,
&
s2
);
// <tid + tag> tuples have been retrieved to client, try <tid + tag> tuples from the next vnode
if
(
hasMoreVnodesToTry
(
pSql
))
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
taosArrayGetSize
(
s1
)
==
0
||
taosArrayGetSize
(
s2
)
==
0
)
{
// no results,return.
int32_t
totalVgroups
=
pTableMetaInfo
->
vgroupList
->
numOfVgroups
;
tscTrace
(
"%p free all sub SqlObj and quit"
,
pParentSql
);
pTableMetaInfo
->
vgroupIndex
+=
1
;
freeJoinSubqueryObj
(
pParentSql
);
assert
(
pTableMetaInfo
->
vgroupIndex
<
totalVgroups
);
return
;
}
else
{
SSqlCmd
*
pSubCmd1
=
&
pParentSql
->
pSubs
[
0
]
->
cmd
;
SSqlCmd
*
pSubCmd2
=
&
pParentSql
->
pSubs
[
1
]
->
cmd
;
SQueryInfo
*
pQueryInfo1
=
tscGetQueryInfoDetail
(
pSubCmd1
,
0
);
tscTrace
(
"%p tid_tag from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d"
,
STableMetaInfo
*
pTableMetaInfo1
=
tscGetMetaInfo
(
pQueryInfo1
,
0
);
pSql
,
pTableMetaInfo
->
vgroupIndex
-
1
,
pTableMetaInfo
->
vgroupIndex
,
totalVgroups
,
pSupporter
->
num
);
tscBuildVgroupTableInfo
(
pParentSql
,
pTableMetaInfo1
,
s1
);
SQueryInfo
*
pQueryInfo2
=
tscGetQueryInfoDetail
(
pSubCmd2
,
0
);
pCmd
->
command
=
TSDB_SQL_SELECT
;
STableMetaInfo
*
pTableMetaInfo2
=
tscGetMetaInfo
(
pQueryInfo2
,
0
);
tscResetForNextRetrieve
(
&
pSql
->
res
);
tscBuildVgroupTableInfo
(
pParentSql
,
pTableMetaInfo2
,
s2
);
pSupporter
->
pState
->
numOfCompleted
=
0
;
// set the callback function
pSupporter
->
pState
->
code
=
0
;
pSql
->
fp
=
tscJoinQueryCallback
;
pSupporter
->
pState
->
numOfTotal
=
2
;
tscProcessSql
(
pSql
);
return
;
}
for
(
int32_t
m
=
0
;
m
<
pParentSql
->
numOfSubs
;
++
m
)
{
// no data exists in next vnode, mark the <tid, tags> query completed
SSqlObj
*
psub
=
pParentSql
->
pSubs
[
m
];
// only when there is no subquery exits any more, proceeds to get the intersect of the <tid, tags> tuple sets.
issueTSCompQuery
(
psub
,
psub
->
param
,
pParentSql
);
if
(
atomic_sub_fetch_32
(
&
pSupporter
->
pState
->
numOfRemain
,
1
)
>
0
)
{
}
return
;
}
}
}
else
{
SArray
*
s1
=
NULL
,
*
s2
=
NULL
;
if
(
numOfRows
<
0
)
{
// error
getIntersectionOfTableTuple
(
pQueryInfo
,
pParentSql
,
&
s1
,
&
s2
);
pSupporter
->
pState
->
code
=
numOfRows
;
if
(
taosArrayGetSize
(
s1
)
==
0
||
taosArrayGetSize
(
s2
)
==
0
)
{
// no results,return.
quitAllSubquery
(
pParentSql
,
pSupporter
);
tscTrace
(
"%p free all sub SqlObj and quit"
,
pParentSql
);
freeJoinSubqueryObj
(
pParentSql
);
return
;
}
pParentSql
->
res
.
code
=
numOfRows
;
// proceed to for ts_comp query
tscQueueAsyncRes
(
pParentSql
);
SSqlCmd
*
pSubCmd1
=
&
pParentSql
->
pSubs
[
0
]
->
cmd
;
return
;
SSqlCmd
*
pSubCmd2
=
&
pParentSql
->
pSubs
[
1
]
->
cmd
;
}
size_t
length
=
pSupporter
->
totalLen
+
pRes
->
rspLen
;
SQueryInfo
*
pQueryInfo1
=
tscGetQueryInfoDetail
(
pSubCmd1
,
0
);
assert
(
length
>
0
);
STableMetaInfo
*
pTableMetaInfo1
=
tscGetMetaInfo
(
pQueryInfo1
,
0
);
tscBuildVgroupTableInfo
(
pParentSql
,
pTableMetaInfo1
,
s1
);
char
*
tmp
=
realloc
(
pSupporter
->
pIdTagList
,
length
);
SQueryInfo
*
pQueryInfo2
=
tscGetQueryInfoDetail
(
pSubCmd2
,
0
);
assert
(
tmp
!=
NULL
);
STableMetaInfo
*
pTableMetaInfo2
=
tscGetMetaInfo
(
pQueryInfo2
,
0
);
tscBuildVgroupTableInfo
(
pParentSql
,
pTableMetaInfo2
,
s2
);
pSupporter
->
pIdTagList
=
tmp
;
pSupporter
->
pState
->
numOfTotal
=
2
;
pSupporter
->
pState
->
numOfRemain
=
pSupporter
->
pState
->
numOfTotal
;
memcpy
(
pSupporter
->
pIdTagList
,
pRes
->
data
,
pRes
->
rspLen
);
for
(
int32_t
m
=
0
;
m
<
pParentSql
->
numOfSubs
;
++
m
)
{
pSupporter
->
totalLen
+=
pRes
->
rspLen
;
SSqlObj
*
sub
=
pParentSql
->
pSubs
[
m
];
pSupporter
->
num
+=
pRes
->
numOfRows
;
issueTSCompQuery
(
sub
,
sub
->
param
,
pParentSql
);
}
}
// continue retrieve data from vnode
static
void
tsCompRetrieveCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int32_t
numOfRows
)
{
taos_fetch_rows_a
(
tres
,
joinRetrieveCallback
,
param
);
SJoinSupporter
*
pSupporter
=
(
SJoinSupporter
*
)
param
;
}
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
assert
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
));
// check for the error code firstly
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
// todo retry if other subqueries are not failed yet
assert
(
numOfRows
<
0
&&
numOfRows
==
taos_errno
(
pSql
));
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
pParentSql
->
res
.
code
=
numOfRows
;
quitAllSubquery
(
pParentSql
,
pSupporter
);
tscQueueAsyncRes
(
pParentSql
);
return
;
return
;
}
}
if
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
))
{
if
(
numOfRows
>
0
)
{
// write the compressed timestamp to disk file
if
(
numOfRows
<
0
)
{
fwrite
(
pRes
->
data
,
pRes
->
numOfRows
,
1
,
pSupporter
->
f
);
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
fclose
(
pSupporter
->
f
);
pSupporter
->
pState
->
code
=
numOfRows
;
pSupporter
->
f
=
NULL
;
quitAllSubquery
(
pParentSql
,
pSupporter
);
STSBuf
*
pBuf
=
tsBufCreateFromFile
(
pSupporter
->
path
,
true
);
if
(
pBuf
==
NULL
)
{
// in error process, close the fd
tscError
(
"%p invalid ts comp file from vnode, abort subquery, file size:%d"
,
pSql
,
numOfRows
);
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
tscQueueAsyncRes
(
pParentSql
);
return
;
return
;
}
}
if
(
numOfRows
>
0
)
{
// write the compressed timestamp to disk file
if
(
pSupporter
->
pTSBuf
==
NULL
)
{
fwrite
(
pRes
->
data
,
pRes
->
numOfRows
,
1
,
pSupporter
->
f
);
tscTrace
(
"%p create tmp file for ts block:%s, size:%d bytes"
,
pSql
,
pBuf
->
path
,
numOfRows
);
fclose
(
pSupporter
->
f
);
pSupporter
->
pTSBuf
=
pBuf
;
pSupporter
->
f
=
NULL
;
}
else
{
assert
(
pQueryInfo
->
numOfTables
==
1
);
// for subquery, only one
STSBuf
*
pBuf
=
tsBufCreateFromFile
(
pSupporter
->
path
,
true
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
pBuf
==
NULL
)
{
// in error process, close the fd
tscError
(
"%p invalid ts comp file from vnode, abort subquery, file size:%d"
,
pSql
,
numOfRows
);
pSupporter
->
pState
->
code
=
TSDB_CODE_TSC_APP_ERROR
;
// todo set the informative code
tsBufMerge
(
pSupporter
->
pTSBuf
,
pBuf
,
pTableMetaInfo
->
vgroupIndex
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
tsBufDestory
(
pBuf
);
return
;
}
}
if
(
pSupporter
->
pTSBuf
==
NULL
)
{
// continue to retrieve ts-comp data from vnode
tscTrace
(
"%p create tmp file for ts block:%s, size:%d bytes"
,
pSql
,
pBuf
->
path
,
numOfRows
);
if
(
!
pRes
->
completed
)
{
pSupporter
->
pTSBuf
=
pBuf
;
getTmpfilePath
(
"ts-join"
,
pSupporter
->
path
);
}
else
{
pSupporter
->
f
=
fopen
(
pSupporter
->
path
,
"w"
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
// for subquery, only one
pRes
->
row
=
pRes
->
numOfRows
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
tsBufMerge
(
pSupporter
->
pTSBuf
,
pBuf
,
pTableMetaInfo
->
vgroupIndex
);
taos_fetch_rows_a
(
tres
,
tsCompRetrieveCallback
,
param
);
tsBufDestory
(
pBuf
);
return
;
}
}
}
}
if
(
pRes
->
completed
)
{
if
(
hasMoreVnodesToTry
(
pSql
))
{
if
(
hasMoreVnodesToTry
(
pSql
))
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
int32_t
totalVgroups
=
pTableMetaInfo
->
vgroupList
->
numOfVgroups
;
int32_t
totalVgroups
=
pTableMetaInfo
->
vgroupList
->
numOfVgroups
;
pTableMetaInfo
->
vgroupIndex
+=
1
;
pTableMetaInfo
->
vgroupIndex
+=
1
;
assert
(
pTableMetaInfo
->
vgroupIndex
<
totalVgroups
);
assert
(
pTableMetaInfo
->
vgroupIndex
<
totalVgroups
);
tscTrace
(
"%p results from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d"
,
tscTrace
(
"%p results from vgroup index:%d completed, try next vgroup:%d. total vgroups:%d. current numOfRes:%d"
,
pSql
,
pTableMetaInfo
->
vgroupIndex
-
1
,
pTableMetaInfo
->
vgroupIndex
,
totalVgroups
,
pSql
,
pTableMetaInfo
->
vgroupIndex
-
1
,
pTableMetaInfo
->
vgroupIndex
,
totalVgroups
,
pRes
->
numOfClauseTotal
);
pRes
->
numOfClauseTotal
);
pCmd
->
command
=
TSDB_SQL_SELECT
;
pCmd
->
command
=
TSDB_SQL_SELECT
;
tscResetForNextRetrieve
(
&
pSql
->
res
);
tscResetForNextRetrieve
(
&
pSql
->
res
);
assert
(
pSupporter
->
f
==
NULL
);
assert
(
pSupporter
->
f
==
NULL
);
getTmpfilePath
(
"ts-join"
,
pSupporter
->
path
);
getTmpfilePath
(
"ts-join"
,
pSupporter
->
path
);
pSupporter
->
f
=
fopen
(
pSupporter
->
path
,
"w"
);
pRes
->
row
=
pRes
->
numOfRows
;
// TODO check for failure
pSupporter
->
f
=
fopen
(
pSupporter
->
path
,
"w"
);
pRes
->
row
=
pRes
->
numOfRows
;
// set the callback function
// set the callback function
pSql
->
fp
=
tscJoinQueryCallback
;
pSql
->
fp
=
tscJoinQueryCallback
;
tscProcessSql
(
pSql
);
tscProcessSql
(
pSql
);
return
;
return
;
}
else
{
}
tSIntersectionAndLaunchSecQuery
(
pSupporter
,
pSql
);
}
}
else
{
// open a new file to save the incoming result
if
(
atomic_sub_fetch_32
(
&
pSupporter
->
pState
->
numOfRemain
,
1
)
>
0
)
{
getTmpfilePath
(
"ts-join"
,
pSupporter
->
path
);
return
;
pSupporter
->
f
=
fopen
(
pSupporter
->
path
,
"w"
);
}
pRes
->
row
=
pRes
->
numOfRows
;
taos_fetch_rows_a
(
tres
,
joinRetrieveCallback
,
param
);
tscTrace
(
"%p all subquery retrieve ts complete, do ts block intersect"
,
pParentSql
);
}
}
else
{
// secondary stage retrieve, driven by taos_fetch_row or other functions
if
(
numOfRows
<
0
)
{
pSupporter
->
pState
->
code
=
numOfRows
;
tscError
(
"%p retrieve failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
}
if
(
numOfRows
>=
0
)
{
// proceeds to launched secondary query to retrieve final data
pRes
->
numOfTotal
+=
pRes
->
numOfRows
;
SJoinSupporter
*
p1
=
pParentSql
->
pSubs
[
0
]
->
param
;
}
SJoinSupporter
*
p2
=
pParentSql
->
pSubs
[
1
]
->
param
;
if
(
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
numOfRows
==
0
)
{
STimeWindow
win
=
TSWINDOW_INITIALIZER
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
int64_t
num
=
doTSBlockIntersect
(
pParentSql
,
p1
,
p2
,
&
win
);
assert
(
pQueryInfo
->
numOfTables
==
1
);
if
(
num
<=
0
)
{
// no result during ts intersect
tscTrace
(
"%p no results generated in ts intersection, free all sub SqlObj and quit"
,
pParentSql
);
freeJoinSubqueryObj
(
pParentSql
);
return
;
}
// launch the query the retrieve actual results from vnode along with the filtered timestamp
SQueryInfo
*
pPQueryInfo
=
tscGetQueryInfoDetail
(
&
pParentSql
->
cmd
,
pParentSql
->
cmd
.
clauseIndex
);
updateQueryTimeRange
(
pPQueryInfo
,
&
win
);
tscLaunchSecondPhaseSubqueries
(
pParentSql
);
}
// for projection query, need to try next vnode if current vnode is exhausted
static
void
joinRetrieveFinalResCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
if
((
++
pTableMetaInfo
->
vgroupIndex
)
<
pTableMetaInfo
->
vgroupList
->
numOfVgroups
)
{
SJoinSupporter
*
pSupporter
=
(
SJoinSupporter
*
)
param
;
pSupporter
->
pState
->
numOfCompleted
=
0
;
pSupporter
->
pState
->
numOfTotal
=
1
;
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
pSql
->
fp
=
tscJoinQueryCallback
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
tscProcessSql
(
pSql
);
return
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
}
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
}
SSqlRes
*
pRes
=
&
pSql
->
res
;
int32_t
numOfTotal
=
pSupporter
->
pState
->
numOfTotal
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
int32_t
finished
=
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
);
if
(
finished
>=
numOfTotal
)
{
// TODO put to async res?
assert
(
finished
==
numOfTotal
);
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
tscTrace
(
"%p all %d secondary subquery retrieves completed, global code:%d"
,
tres
,
numOfTotal
,
assert
(
numOfRows
==
taos_errno
(
pSql
));
pParentSql
->
res
.
code
);
if
(
pSupporter
->
pState
->
code
!=
TSDB_CODE_SUCCESS
)
{
pParentSql
->
res
.
code
=
numOfRows
;
pParentSql
->
res
.
code
=
pSupporter
->
pState
->
code
;
tscError
(
"%p retrieve failed, index:%d, code:%s"
,
pSql
,
pSupporter
->
subqueryIndex
,
tstrerror
(
numOfRows
));
freeJoinSubqueryObj
(
pParentSql
);
}
pParentSql
->
res
.
completed
=
true
;
}
// update the records for each subquery in parent sql object.
if
(
numOfRows
>=
0
)
{
for
(
int32_t
i
=
0
;
i
<
pParentSql
->
numOfSubs
;
++
i
)
{
pRes
->
numOfTotal
+=
pRes
->
numOfRows
;
if
(
pParentSql
->
pSubs
[
i
]
==
NULL
)
{
}
continue
;
}
SSqlRes
*
pRes1
=
&
pParentSql
->
pSubs
[
i
]
->
res
;
if
(
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
numOfRows
==
0
)
{
pRes1
->
numOfClauseTotal
+=
pRes1
->
numOfRows
;
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
;
}
assert
(
pQueryInfo
->
numOfTables
==
1
);
// data has retrieved to client, build the join results
// for projection query, need to try next vnode if current vnode is exhausted
tscBuildResFromSubqueries
(
pParentSql
);
if
((
++
pTableMetaInfo
->
vgroupIndex
)
<
pTableMetaInfo
->
vgroupList
->
numOfVgroups
)
{
}
else
{
pState
->
numOfRemain
=
1
;
tscTrace
(
"%p sub:%p completed, completed:%d, total:%d"
,
pParentSql
,
tres
,
finished
,
numOfTotal
);
pState
->
numOfTotal
=
1
;
pSql
->
cmd
.
command
=
TSDB_SQL_SELECT
;
pSql
->
fp
=
tscJoinQueryCallback
;
tscProcessSql
(
pSql
);
return
;
}
}
if
(
atomic_sub_fetch_32
(
&
pState
->
numOfRemain
,
1
)
>
0
)
{
tscTrace
(
"%p sub:%p completed, remain:%d, total:%d"
,
pParentSql
,
tres
,
pState
->
numOfRemain
,
pState
->
numOfTotal
);
return
;
}
tscTrace
(
"%p all %d secondary subqueries retrieval completed, code:%d"
,
tres
,
pState
->
numOfTotal
,
pParentSql
->
res
.
code
);
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
freeJoinSubqueryObj
(
pParentSql
);
pParentSql
->
res
.
completed
=
true
;
}
// update the records for each subquery in parent sql object.
for
(
int32_t
i
=
0
;
i
<
pParentSql
->
numOfSubs
;
++
i
)
{
if
(
pParentSql
->
pSubs
[
i
]
==
NULL
)
{
continue
;
}
}
SSqlRes
*
pRes1
=
&
pParentSql
->
pSubs
[
i
]
->
res
;
pRes1
->
numOfClauseTotal
+=
pRes1
->
numOfRows
;
}
}
// data has retrieved to client, build the join results
tscBuildResFromSubqueries
(
pParentSql
);
}
}
static
SJoinSupporter
*
tscUpdateSubqueryStatus
(
SSqlObj
*
pSql
,
int32_t
numOfFetch
)
{
static
SJoinSupporter
*
tscUpdateSubqueryStatus
(
SSqlObj
*
pSql
,
int32_t
numOfFetch
)
{
...
@@ -902,7 +933,7 @@ static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch
...
@@ -902,7 +933,7 @@ static SJoinSupporter* tscUpdateSubqueryStatus(SSqlObj* pSql, int32_t numOfFetch
}
}
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOf
Completed
=
pSql
->
numOfSubs
-
numOfFetch
;
pState
->
numOf
Remain
=
numOfFetch
;
return
pSupporter
;
return
pSupporter
;
}
}
...
@@ -990,7 +1021,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
...
@@ -990,7 +1021,7 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
pSupporter
->
subqueryIndex
,
pTableMetaInfo
->
vgroupIndex
);
pSupporter
->
subqueryIndex
,
pTableMetaInfo
->
vgroupIndex
);
tscResetForNextRetrieve
(
pRes1
);
tscResetForNextRetrieve
(
pRes1
);
pSql1
->
fp
=
joinRetrieveCallback
;
pSql1
->
fp
=
joinRetrieve
FinalRes
Callback
;
if
(
pCmd1
->
command
<
TSDB_SQL_LOCAL
)
{
if
(
pCmd1
->
command
<
TSDB_SQL_LOCAL
)
{
pCmd1
->
command
=
(
pCmd1
->
command
>
TSDB_SQL_MGMT
)
?
TSDB_SQL_RETRIEVE
:
TSDB_SQL_FETCH
;
pCmd1
->
command
=
(
pCmd1
->
command
>
TSDB_SQL_MGMT
)
?
TSDB_SQL_RETRIEVE
:
TSDB_SQL_FETCH
;
...
@@ -1008,8 +1039,9 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
...
@@ -1008,8 +1039,9 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
tscTrace
(
"%p all subquery response, retrieve data"
,
pSql
);
tscTrace
(
"%p all subquery response, retrieve data"
,
pSql
);
// the column transfer support struct has been built
if
(
pRes
->
pColumnIndex
!=
NULL
)
{
if
(
pRes
->
pColumnIndex
!=
NULL
)
{
return
;
// the column transfer support struct has been built
return
;
}
}
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
...
@@ -1045,68 +1077,76 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
...
@@ -1045,68 +1077,76 @@ void tscSetupOutputColumnIndex(SSqlObj* pSql) {
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SJoinSupporter
*
pSupporter
=
(
SJoinSupporter
*
)
param
;
SJoinSupporter
*
pSupporter
=
(
SJoinSupporter
*
)
param
;
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
// There is only one subquery and table for each subquery.
// There is only one subquery and table for each subquery.
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pSql
->
cmd
,
0
);
assert
(
pQueryInfo
->
numOfTables
==
1
&&
pSql
->
cmd
.
numOfClause
==
1
);
assert
(
pQueryInfo
->
numOfTables
==
1
&&
pSql
->
cmd
.
numOfClause
==
1
);
if
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
))
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// direct call joinRetrieveCallback and set the error code
joinRetrieveCallback
(
param
,
pSql
,
code
);
}
else
{
// first stage query, continue to retrieve compressed time stamp data
pSql
->
fp
=
joinRetrieveCallback
;
pSql
->
cmd
.
command
=
TSDB_SQL_FETCH
;
tscProcessSql
(
pSql
);
}
}
else
{
// second stage join subquery
// retrieve actual query results from vnode during the second stage join subquery
SSqlObj
*
pParentSql
=
pSupporter
->
pObj
;
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
code
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
tscQueueAsyncRes
(
pParentSql
);
if
(
pSupporter
->
pState
->
code
!=
TSDB_CODE_SUCCESS
)
{
return
;
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
code
,
}
pSupporter
->
pState
->
code
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
return
;
// TODO here retry is required, not directly returns to client
}
if
(
taos_errno
(
pSql
)
!=
TSDB_CODE_SUCCESS
)
{
assert
(
taos_errno
(
pSql
)
==
code
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query, code:%d, global code:%d"
,
pSql
,
code
,
pParentSql
->
res
.
code
);
tscError
(
"%p sub query failed, code:%s, set global code:%s, index:%d"
,
pSql
,
tstrerror
(
code
),
tstrerror
(
code
),
pParentSql
->
res
.
code
=
code
;
pSupporter
->
subqueryIndex
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
pSupporter
->
pState
->
code
=
code
;
tscQueueAsyncRes
(
pParentSql
);
quitAllSubquery
(
pParentSql
,
pSupporter
);
return
;
}
// retrieve <tid, tag> tuples from vnode
if
(
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TAG_FILTER_QUERY
))
{
pSql
->
fp
=
tidTagRetrieveCallback
;
pSql
->
cmd
.
command
=
TSDB_SQL_FETCH
;
tscProcessSql
(
pSql
);
return
;
}
// retrieve ts_comp info from vnode
if
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
))
{
pSql
->
fp
=
tsCompRetrieveCallback
;
pSql
->
cmd
.
command
=
TSDB_SQL_FETCH
;
tscProcessSql
(
pSql
);
return
;
}
// wait for the other subqueries response from vnode
if
(
atomic_sub_fetch_32
(
&
pSupporter
->
pState
->
numOfRemain
,
1
)
>
0
)
{
return
;
}
tscSetupOutputColumnIndex
(
pParentSql
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
/**
* if the query is a continue query (vgroupIndex > 0 for projection query) for next vnode, do the retrieval of
* data instead of returning to its invoker
*/
if
(
pTableMetaInfo
->
vgroupIndex
>
0
&&
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
))
{
pSupporter
->
pState
->
numOfRemain
=
pSupporter
->
pState
->
numOfTotal
;
// reset the record value
pSql
->
fp
=
joinRetrieveFinalResCallback
;
// continue retrieve data
pSql
->
cmd
.
command
=
TSDB_SQL_FETCH
;
tscProcessSql
(
pSql
);
}
else
{
// first retrieve from vnode during the secondary stage sub-query
// set the command flag must be after the semaphore been correctly set.
if
(
pParentSql
->
res
.
code
==
TSDB_CODE_SUCCESS
)
{
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
0
);
}
else
{
}
else
{
int32_t
numOfTotal
=
pSupporter
->
pState
->
numOfTotal
;
tscQueueAsyncRes
(
pParentSql
);
int32_t
finished
=
atomic_add_fetch_32
(
&
pSupporter
->
pState
->
numOfCompleted
,
1
);
if
(
finished
>=
numOfTotal
)
{
assert
(
finished
==
numOfTotal
);
tscSetupOutputColumnIndex
(
pParentSql
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
/**
* if the query is a continue query (vgroupIndex > 0 for projection query) for next vnode, do the retrieval of
* data instead of returning to its invoker
*/
if
(
pTableMetaInfo
->
vgroupIndex
>
0
&&
tscNonOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
))
{
pSupporter
->
pState
->
numOfCompleted
=
0
;
// reset the record value
pSql
->
fp
=
joinRetrieveCallback
;
// continue retrieve data
pSql
->
cmd
.
command
=
TSDB_SQL_FETCH
;
tscProcessSql
(
pSql
);
}
else
{
// first retrieve from vnode during the secondary stage sub-query
// set the command flag must be after the semaphore been correctly set.
if
(
pParentSql
->
res
.
code
==
TSDB_CODE_SUCCESS
)
{
(
*
pParentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
0
);
}
else
{
tscQueueAsyncRes
(
pParentSql
);
}
}
}
}
}
}
}
}
}
...
@@ -1257,14 +1297,15 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
...
@@ -1257,14 +1297,15 @@ int32_t tscHandleMasterJoinQuery(SSqlObj* pSql) {
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
pState
->
numOfTotal
=
pQueryInfo
->
numOfTables
;
pState
->
numOfTotal
=
pQueryInfo
->
numOfTables
;
pState
->
numOfRemain
=
pState
->
numOfTotal
;
tscTrace
(
"%p start launch subquery, total:%d"
,
pSql
,
pQueryInfo
->
numOfTables
);
tscTrace
(
"%p start launch subquery, total:%d"
,
pSql
,
pQueryInfo
->
numOfTables
);
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
SJoinSupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
SJoinSupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
if
(
pSupporter
==
NULL
)
{
// failed to create support struct, abort current query
if
(
pSupporter
==
NULL
)
{
// failed to create support struct, abort current query
tscError
(
"%p tableIndex:%d, failed to allocate join support object, abort further query"
,
pSql
,
i
);
tscError
(
"%p tableIndex:%d, failed to allocate join support object, abort further query"
,
pSql
,
i
);
pState
->
numOf
Completed
=
pQueryInfo
->
numOfTables
-
i
-
1
;
pState
->
numOf
Remain
=
i
;
pSql
->
res
.
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
pSql
->
res
.
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
pSql
->
res
.
code
;
return
pSql
->
res
.
code
;
...
@@ -1342,6 +1383,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
...
@@ -1342,6 +1383,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) {
tscTrace
(
"%p retrieved query data from %d vnode(s)"
,
pSql
,
pSql
->
numOfSubs
);
tscTrace
(
"%p retrieved query data from %d vnode(s)"
,
pSql
,
pSql
->
numOfSubs
);
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOfTotal
=
pSql
->
numOfSubs
;
pState
->
numOfRemain
=
pSql
->
numOfSubs
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
pRes
->
code
=
TSDB_CODE_SUCCESS
;
int32_t
i
=
0
;
int32_t
i
=
0
;
...
@@ -1436,7 +1479,7 @@ static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
...
@@ -1436,7 +1479,7 @@ static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) {
static
void
tscRetrieveFromDnodeCallBack
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
static
void
tscRetrieveFromDnodeCallBack
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
static
void
tscHandleSubqueryError
(
SRetrieveSupport
*
trsupport
,
SSqlObj
*
pSql
,
int
numOfRows
);
static
void
tscHandleSubqueryError
(
SRetrieveSupport
*
trsupport
,
SSqlObj
*
pSql
,
int
numOfRows
);
static
void
tscAbortFurtherRetryRetrieval
(
SRetrieveSupport
*
trsupport
,
TAOS_RES
*
tres
,
int32_t
errC
ode
)
{
static
void
tscAbortFurtherRetryRetrieval
(
SRetrieveSupport
*
trsupport
,
TAOS_RES
*
tres
,
int32_t
c
ode
)
{
// set no disk space error info
// set no disk space error info
#ifdef WINDOWS
#ifdef WINDOWS
LPVOID
lpMsgBuf
;
LPVOID
lpMsgBuf
;
...
@@ -1448,44 +1491,44 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES
...
@@ -1448,44 +1491,44 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES
#else
#else
tscError
(
"sub:%p failed to flush data to disk:reason:%s"
,
tres
,
strerror
(
errno
));
tscError
(
"sub:%p failed to flush data to disk:reason:%s"
,
tres
,
strerror
(
errno
));
#endif
#endif
trsupport
->
pState
->
code
=
-
errCode
;
SSqlObj
*
pParentSql
=
trsupport
->
pParentSqlObj
;
pParentSql
->
res
.
code
=
code
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
pthread_mutex_unlock
(
&
trsupport
->
queryMutex
);
pthread_mutex_unlock
(
&
trsupport
->
queryMutex
);
tscHandleSubqueryError
(
trsupport
,
tres
,
trsupport
->
pState
->
code
);
tscHandleSubqueryError
(
trsupport
,
tres
,
pParentSql
->
res
.
code
);
}
}
void
tscHandleSubqueryError
(
SRetrieveSupport
*
trsupport
,
SSqlObj
*
pSql
,
int
numOfRows
)
{
void
tscHandleSubqueryError
(
SRetrieveSupport
*
trsupport
,
SSqlObj
*
pSql
,
int
numOfRows
)
{
SSqlObj
*
pP
Obj
=
trsupport
->
pParentSqlObj
;
SSqlObj
*
pP
arentSql
=
trsupport
->
pParentSqlObj
;
int32_t
subqueryIndex
=
trsupport
->
subqueryIndex
;
int32_t
subqueryIndex
=
trsupport
->
subqueryIndex
;
assert
(
pSql
!=
NULL
);
assert
(
pSql
!=
NULL
);
SSubqueryState
*
pState
=
trsupport
->
pState
;
SSubqueryState
*
pState
=
trsupport
->
pState
;
assert
(
pState
->
numOfCompleted
<
pState
->
numOfTotal
&&
pState
->
numOfCompleted
>=
0
&&
assert
(
pState
->
numOfRemain
<=
pState
->
numOfTotal
&&
pState
->
numOfRemain
>=
0
&&
pParentSql
->
numOfSubs
==
pState
->
numOfTotal
);
pPObj
->
numOfSubs
==
pState
->
numOfTotal
);
// retrieved in subquery failed. OR query cancelled in retrieve phase.
// retrieved in subquery failed. OR query cancelled in retrieve phase.
if
(
pState
->
code
==
TSDB_CODE_SUCCESS
&&
pPObj
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
taos_errno
(
pSql
)
==
TSDB_CODE_SUCCESS
&&
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
pState
->
code
=
pPObj
->
res
.
code
;
/*
/*
* kill current sub-query connection, which may retrieve data from vnodes;
* kill current sub-query connection, which may retrieve data from vnodes;
* Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED
* Here we get: pPObj->res.code == TSDB_CODE_TSC_QUERY_CANCELLED
*/
*/
pSql
->
res
.
numOfRows
=
0
;
pSql
->
res
.
numOfRows
=
0
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
// disable retry efforts
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
// disable retry efforts
tscTrace
(
"%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d"
,
trsupport
->
pParentSqlObj
,
pSql
,
tscTrace
(
"%p query is cancelled, sub:%p, orderOfSub:%d abort retrieve, code:%d"
,
pParentSql
,
pSql
,
subqueryIndex
,
p
State
->
code
);
subqueryIndex
,
p
ParentSql
->
res
.
code
);
}
}
if
(
numOfRows
>=
0
)
{
// current query is successful, but other sub query failed, still abort current query.
if
(
numOfRows
>=
0
)
{
// current query is successful, but other sub query failed, still abort current query.
tscTrace
(
"%p sub:%p retrieve numOfRows:%d,orderOfSub:%d"
,
pP
Obj
,
pSql
,
numOfRows
,
subqueryIndex
);
tscTrace
(
"%p sub:%p retrieve numOfRows:%d,orderOfSub:%d"
,
pP
arentSql
,
pSql
,
numOfRows
,
subqueryIndex
);
tscError
(
"%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d"
,
pP
Obj
,
pSql
,
tscError
(
"%p sub:%p abort further retrieval due to other queries failure,orderOfSub:%d,code:%d"
,
pP
arentSql
,
pSql
,
subqueryIndex
,
p
State
->
code
);
subqueryIndex
,
p
ParentSql
->
res
.
code
);
}
else
{
}
else
{
if
(
trsupport
->
numOfRetry
++
<
MAX_NUM_OF_SUBQUERY_RETRY
&&
p
State
->
code
==
TSDB_CODE_SUCCESS
)
{
if
(
trsupport
->
numOfRetry
++
<
MAX_NUM_OF_SUBQUERY_RETRY
&&
p
ParentSql
->
res
.
code
==
TSDB_CODE_SUCCESS
)
{
/*
/*
* current query failed, and the retry count is less than the available
* current query failed, and the retry count is less than the available
* count, retry query clear previous retrieved data, then launch a new sub query
* count, retry query clear previous retrieved data, then launch a new sub query
...
@@ -1503,8 +1546,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
...
@@ -1503,8 +1546,8 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
tscError
(
"%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry"
,
tscError
(
"%p sub:%p failed to create new subquery sqlObj due to out of memory, abort retry"
,
trsupport
->
pParentSqlObj
,
pSql
);
trsupport
->
pParentSqlObj
,
pSql
);
p
State
->
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
p
ParentSql
->
res
.
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
return
;
return
;
}
}
...
@@ -1512,24 +1555,24 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
...
@@ -1512,24 +1555,24 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
tscProcessSql
(
pNew
);
tscProcessSql
(
pNew
);
return
;
return
;
}
else
{
// reach the maximum retry count, abort
}
else
{
// reach the maximum retry count, abort
atomic_val_compare_exchange_32
(
&
p
State
->
code
,
TSDB_CODE_SUCCESS
,
numOfRows
);
atomic_val_compare_exchange_32
(
&
p
ParentSql
->
res
.
code
,
TSDB_CODE_SUCCESS
,
numOfRows
);
tscError
(
"%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s"
,
pP
Obj
,
pSql
,
tscError
(
"%p sub:%p retrieve failed,code:%s,orderOfSub:%d failed.no more retry,set global code:%s"
,
pP
arentSql
,
pSql
,
tstrerror
(
numOfRows
),
subqueryIndex
,
tstrerror
(
p
State
->
code
));
tstrerror
(
numOfRows
),
subqueryIndex
,
tstrerror
(
p
ParentSql
->
res
.
code
));
}
}
}
}
int32_t
numOfTotal
=
pState
->
numOfTotal
;
int32_t
remain
=
-
1
;
if
((
remain
=
atomic_sub_fetch_32
(
&
pState
->
numOfRemain
,
1
))
>
0
)
{
int32_t
finished
=
atomic_add_fetch_32
(
&
pState
->
numOfCompleted
,
1
);
tscTrace
(
"%p sub:%p orderOfSub:%d freed, finished subqueries:%d"
,
pParentSql
,
pSql
,
trsupport
->
subqueryIndex
,
if
(
finished
<
numOfTotal
)
{
pState
->
numOfTotal
-
remain
);
tscTrace
(
"%p sub:%p orderOfSub:%d freed, finished subqueries:%d"
,
pPObj
,
pSql
,
trsupport
->
subqueryIndex
,
finished
);
return
tscFreeSubSqlObj
(
trsupport
,
pSql
);
return
tscFreeSubSqlObj
(
trsupport
,
pSql
);
}
}
// all subqueries are failed
// all subqueries are failed
tscError
(
"%p retrieve from %d vnode(s) completed,code:%s.FAILED."
,
pP
Obj
,
pState
->
numOfTotal
,
tstrerror
(
pState
->
code
));
tscError
(
"%p retrieve from %d vnode(s) completed,code:%s.FAILED."
,
pP
arentSql
,
pState
->
numOfTotal
,
pPObj
->
res
.
code
=
pState
->
code
;
tstrerror
(
pParentSql
->
res
.
code
))
;
// release allocated resource
// release allocated resource
tscLocalReducerEnvDestroy
(
trsupport
->
pExtMemBuffer
,
trsupport
->
pOrderDescriptor
,
trsupport
->
pFinalColModel
,
tscLocalReducerEnvDestroy
(
trsupport
->
pExtMemBuffer
,
trsupport
->
pOrderDescriptor
,
trsupport
->
pFinalColModel
,
pState
->
numOfTotal
);
pState
->
numOfTotal
);
...
@@ -1538,13 +1581,13 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
...
@@ -1538,13 +1581,13 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO
tscFreeSubSqlObj
(
trsupport
,
pSql
);
tscFreeSubSqlObj
(
trsupport
,
pSql
);
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
// in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pP
Obj
->
cmd
,
0
);
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pP
arentSql
->
cmd
,
0
);
if
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
))
{
if
(
!
TSDB_QUERY_HAS_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
))
{
(
*
pP
Obj
->
fp
)(
pPObj
->
param
,
pPObj
,
pPObj
->
res
.
code
);
(
*
pP
arentSql
->
fp
)(
pParentSql
->
param
,
pParentSql
,
pParentSql
->
res
.
code
);
}
else
{
// regular super table query
}
else
{
// regular super table query
if
(
pP
Obj
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pP
arentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscQueueAsyncRes
(
pP
Obj
);
tscQueueAsyncRes
(
pP
arentSql
);
}
}
}
}
}
}
...
@@ -1590,14 +1633,11 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
...
@@ -1590,14 +1633,11 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
return
tscAbortFurtherRetryRetrieval
(
trsupport
,
pSql
,
TSDB_CODE_TSC_NO_DISKSPACE
);
return
tscAbortFurtherRetryRetrieval
(
trsupport
,
pSql
,
TSDB_CODE_TSC_NO_DISKSPACE
);
}
}
// keep this value local variable, since the pState variable may be released by other threads, if atomic_add opertion
int32_t
remain
=
-
1
;
// increases the finished value up to pState->numOfTotal value, which means all subqueries are completed.
if
((
remain
=
atomic_sub_fetch_32
(
&
pState
->
numOfRemain
,
1
))
>
0
)
{
// In this case, the comparsion between finished value and released pState->numOfTotal is not safe.
tscTrace
(
"%p sub:%p orderOfSub:%d freed, finished subqueries:%d"
,
pPObj
,
pSql
,
trsupport
->
subqueryIndex
,
int32_t
numOfTotal
=
pState
->
numOfTotal
;
pState
->
numOfTotal
-
remain
);
int32_t
finished
=
atomic_add_fetch_32
(
&
pState
->
numOfCompleted
,
1
);
if
(
finished
<
numOfTotal
)
{
tscTrace
(
"%p sub:%p orderOfSub:%d freed, finished subqueries:%d"
,
pPObj
,
pSql
,
trsupport
->
subqueryIndex
,
finished
);
return
tscFreeSubSqlObj
(
trsupport
,
pSql
);
return
tscFreeSubSqlObj
(
trsupport
,
pSql
);
}
}
...
@@ -1632,10 +1672,10 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
...
@@ -1632,10 +1672,10 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p
static
void
tscRetrieveFromDnodeCallBack
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
static
void
tscRetrieveFromDnodeCallBack
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
)
{
SRetrieveSupport
*
trsupport
=
(
SRetrieveSupport
*
)
param
;
SRetrieveSupport
*
trsupport
=
(
SRetrieveSupport
*
)
param
;
int32_t
idx
=
trsupport
->
subqueryIndex
;
SSqlObj
*
pPObj
=
trsupport
->
pParentSqlObj
;
tOrderDescriptor
*
pDesc
=
trsupport
->
pOrderDescriptor
;
tOrderDescriptor
*
pDesc
=
trsupport
->
pOrderDescriptor
;
int32_t
idx
=
trsupport
->
subqueryIndex
;
SSqlObj
*
pPObj
=
trsupport
->
pParentSqlObj
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
SSqlObj
*
pSql
=
(
SSqlObj
*
)
tres
;
if
(
pSql
==
NULL
)
{
// sql object has been released in error process, return immediately
if
(
pSql
==
NULL
)
{
// sql object has been released in error process, return immediately
tscTrace
(
"%p subquery has been released, idx:%d, abort"
,
pPObj
,
idx
);
tscTrace
(
"%p subquery has been released, idx:%d, abort"
,
pPObj
,
idx
);
...
@@ -1643,13 +1683,12 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
...
@@ -1643,13 +1683,12 @@ static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfR
}
}
SSubqueryState
*
pState
=
trsupport
->
pState
;
SSubqueryState
*
pState
=
trsupport
->
pState
;
assert
(
pState
->
numOfCompleted
<
pState
->
numOfTotal
&&
pState
->
numOfCompleted
>=
0
&&
assert
(
pState
->
numOfRemain
<=
pState
->
numOfTotal
&&
pState
->
numOfRemain
>=
0
&&
pPObj
->
numOfSubs
==
pState
->
numOfTotal
);
pPObj
->
numOfSubs
==
pState
->
numOfTotal
);
// query process and cancel query process may execute at the same time
// query process and cancel query process may execute at the same time
pthread_mutex_lock
(
&
trsupport
->
queryMutex
);
pthread_mutex_lock
(
&
trsupport
->
queryMutex
);
if
(
numOfRows
<
0
||
p
State
->
code
<
0
||
p
PObj
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
numOfRows
<
0
||
pPObj
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
return
tscHandleSubqueryError
(
trsupport
,
pSql
,
numOfRows
);
return
tscHandleSubqueryError
(
trsupport
,
pSql
,
numOfRows
);
}
}
...
@@ -1738,18 +1777,16 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1738,18 +1777,16 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
SCMVgroupInfo
*
pVgroup
=
&
pTableMetaInfo
->
vgroupList
->
vgroups
[
0
];
SCMVgroupInfo
*
pVgroup
=
&
pTableMetaInfo
->
vgroupList
->
vgroups
[
0
];
SSubqueryState
*
pState
=
trsupport
->
pState
;
SSubqueryState
*
pState
=
trsupport
->
pState
;
assert
(
pState
->
numOf
Completed
<
pState
->
numOfTotal
&&
pState
->
numOfCompleted
>=
0
&&
assert
(
pState
->
numOf
Remain
<=
pState
->
numOfTotal
&&
pState
->
numOfRemain
>=
0
&&
pParentSql
->
numOfSubs
==
pState
->
numOfTotal
);
pParentSql
->
numOfSubs
==
pState
->
numOfTotal
);
// todo set error code
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
||
pState
->
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
// stable query is killed, abort further retry
// stable query is killed, abort further retry
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
code
=
pParentSql
->
res
.
code
;
code
=
pParentSql
->
res
.
code
;
}
else
{
code
=
pState
->
code
;
}
}
tscTrace
(
"%p query cancelled or failed, sub:%p, orderOfSub:%d abort, code:%s"
,
pParentSql
,
pSql
,
tscTrace
(
"%p query cancelled or failed, sub:%p, orderOfSub:%d abort, code:%s"
,
pParentSql
,
pSql
,
...
@@ -1766,7 +1803,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1766,7 +1803,7 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
trsupport
->
numOfRetry
++
>=
MAX_NUM_OF_SUBQUERY_RETRY
)
{
if
(
trsupport
->
numOfRetry
++
>=
MAX_NUM_OF_SUBQUERY_RETRY
)
{
tscTrace
(
"%p sub:%p reach the max retry times, set global code:%s"
,
pParentSql
,
pSql
,
tstrerror
(
code
));
tscTrace
(
"%p sub:%p reach the max retry times, set global code:%s"
,
pParentSql
,
pSql
,
tstrerror
(
code
));
atomic_val_compare_exchange_32
(
&
p
State
->
code
,
0
,
code
);
atomic_val_compare_exchange_32
(
&
p
ParentSql
->
res
.
code
,
TSDB_CODE_SUCCESS
,
code
);
}
else
{
// does not reach the maximum retry time, go on
}
else
{
// does not reach the maximum retry time, go on
tscTrace
(
"%p sub:%p failed code:%s, retry:%d"
,
pParentSql
,
pSql
,
tstrerror
(
code
),
trsupport
->
numOfRetry
);
tscTrace
(
"%p sub:%p failed code:%s, retry:%d"
,
pParentSql
,
pSql
,
tstrerror
(
code
),
trsupport
->
numOfRetry
);
...
@@ -1775,8 +1812,8 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1775,8 +1812,8 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
if
(
pNew
==
NULL
)
{
if
(
pNew
==
NULL
)
{
tscError
(
"%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d"
,
tscError
(
"%p sub:%p failed to create new subquery due to out of memory, abort retry, vgId:%d, orderOfSub:%d"
,
trsupport
->
pParentSqlObj
,
pSql
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
);
trsupport
->
pParentSqlObj
,
pSql
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
);
p
State
->
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
p
ParentSql
->
res
.
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
trsupport
->
numOfRetry
=
MAX_NUM_OF_SUBQUERY_RETRY
;
}
else
{
}
else
{
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
SQueryInfo
*
pNewQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
...
@@ -1789,11 +1826,11 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
...
@@ -1789,11 +1826,11 @@ void tscRetrieveDataRes(void *param, TAOS_RES *tres, int code) {
}
}
}
}
if
(
p
State
->
code
!=
TSDB_CODE_SUCCESS
)
{
// at least one peer subquery failed, abort current query
if
(
p
ParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
// at least one peer subquery failed, abort current query
tscTrace
(
"%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d"
,
pParentSql
,
pSql
,
tscTrace
(
"%p sub:%p query failed,ip:%u,vgId:%d,orderOfSub:%d,global code:%d"
,
pParentSql
,
pSql
,
pVgroup
->
ipAddr
[
0
].
fqdn
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
,
p
State
->
code
);
pVgroup
->
ipAddr
[
0
].
fqdn
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
,
p
ParentSql
->
res
.
code
);
tscHandleSubqueryError
(
param
,
tres
,
p
State
->
code
);
tscHandleSubqueryError
(
param
,
tres
,
p
ParentSql
->
res
.
code
);
}
else
{
// success, proceed to retrieve data from dnode
}
else
{
// success, proceed to retrieve data from dnode
tscTrace
(
"%p sub:%p query complete, ip:%s, vgId:%d, orderOfSub:%d, retrieve data"
,
trsupport
->
pParentSqlObj
,
pSql
,
tscTrace
(
"%p sub:%p query complete, ip:%s, vgId:%d, orderOfSub:%d, retrieve data"
,
trsupport
->
pParentSqlObj
,
pSql
,
pVgroup
->
ipAddr
[
0
].
fqdn
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
);
pVgroup
->
ipAddr
[
0
].
fqdn
,
pVgroup
->
vgId
,
trsupport
->
subqueryIndex
);
...
@@ -1813,8 +1850,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -1813,8 +1850,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
SSqlCmd
*
pParentCmd
=
&
pParentObj
->
cmd
;
SSqlCmd
*
pParentCmd
=
&
pParentObj
->
cmd
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
SSubqueryState
*
pState
=
pSupporter
->
pState
;
int32_t
total
=
pState
->
numOfTotal
;
// increase the total inserted rows
// increase the total inserted rows
if
(
numOfRows
>
0
)
{
if
(
numOfRows
>
0
)
{
pParentObj
->
res
.
numOfRows
+=
numOfRows
;
pParentObj
->
res
.
numOfRows
+=
numOfRows
;
...
@@ -1826,8 +1862,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
...
@@ -1826,8 +1862,7 @@ static void multiVnodeInsertMerge(void* param, TAOS_RES* tres, int numOfRows) {
}
}
taos_free_result
(
tres
);
taos_free_result
(
tres
);
int32_t
completed
=
atomic_add_fetch_32
(
&
pState
->
numOfCompleted
,
1
);
if
(
atomic_sub_fetch_32
(
&
pState
->
numOfRemain
,
1
)
>
0
)
{
if
(
completed
<
total
)
{
return
;
return
;
}
}
...
@@ -2157,5 +2192,3 @@ static bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) {
...
@@ -2157,5 +2192,3 @@ static bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) {
return
hasData
;
return
hasData
;
}
}
src/query/src/qExecutor.c
浏览文件 @
c1968083
...
@@ -1216,7 +1216,6 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
...
@@ -1216,7 +1216,6 @@ static int32_t tableApplyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SDataBl
// interval query with limit applied
// interval query with limit applied
int32_t
numOfRes
=
0
;
int32_t
numOfRes
=
0
;
if
(
isIntervalQuery
(
pQuery
))
{
if
(
isIntervalQuery
(
pQuery
))
{
numOfRes
=
doCheckQueryCompleted
(
pRuntimeEnv
,
lastKey
,
pWindowResInfo
);
numOfRes
=
doCheckQueryCompleted
(
pRuntimeEnv
,
lastKey
,
pWindowResInfo
);
}
else
{
}
else
{
...
...
src/util/src/terror.c
浏览文件 @
c1968083
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
#include <stdint.h>
#include <stdint.h>
#include <pthread.h>
#include <pthread.h>
#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
...
...
tests/script/general/parser/alter.sim
浏览文件 @
c1968083
...
@@ -114,46 +114,46 @@ sql drop table tb
...
@@ -114,46 +114,46 @@ sql drop table tb
sql drop table mt
sql drop table mt
sleep 3000
sleep 3000
## ALTER TABLE WHILE STREAMING [TBASE271]
##
#
ALTER TABLE WHILE STREAMING [TBASE271]
sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int)
#
sql create table tb1 (ts timestamp, c1 int, c2 nchar(5), c3 int)
sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s)
#
sql create table strm as select count(*), avg(c1), first(c2), sum(c3) from tb1 interval(2s)
sql select * from strm
#
sql select * from strm
if $rows != 0 then
#
if $rows != 0 then
return -1
#
return -1
endi
#
endi
#sleep 12000
#
#
sleep 12000
sql insert into tb1 values (now, 1, 'taos', 1)
#
sql insert into tb1 values (now, 1, 'taos', 1)
sleep 20000
#
sleep 20000
sql select * from strm
#
sql select * from strm
print rows = $rows
#
print rows = $rows
if $rows != 1 then
#
if $rows != 1 then
return -1
#
return -1
endi
#
endi
if $data04 != 1 then
#
if $data04 != 1 then
return -1
#
return -1
endi
#
endi
sql alter table tb1 drop column c3
#sql alter table tb1 drop column c3
sleep 6000
#
sleep 6000
sql insert into tb1 values (now, 2, 'taos')
#
sql insert into tb1 values (now, 2, 'taos')
sleep 30000
#
sleep 30000
sql select * from strm
#
sql select * from strm
if $rows != 2 then
#
if $rows != 2 then
return -1
#
return -1
endi
#
endi
if $data04 != 1 then
#
if $data04 != 1 then
return -1
#
return -1
endi
#
endi
sql alter table tb1 add column c3 int
#
sql alter table tb1 add column c3 int
sleep 6000
#
sleep 6000
sql insert into tb1 values (now, 3, 'taos', 3);
#
sql insert into tb1 values (now, 3, 'taos', 3);
sleep 3000
#
sleep 3000
sql select * from strm
#
sql select * from strm
if $rows != 3 then
#
if $rows != 3 then
return -1
#
return -1
endi
#
endi
if $data04 != 1 then
#
if $data04 != 1 then
return -1
#
return -1
endi
#
endi
## ALTER TABLE AND INSERT BY COLUMNS
## ALTER TABLE AND INSERT BY COLUMNS
sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int)
sql create table mt (ts timestamp, c1 int, c2 int) tags(t1 int)
...
...
tests/script/general/parser/testSuite.sim
浏览文件 @
c1968083
...
@@ -82,26 +82,22 @@ sleep 2000
...
@@ -82,26 +82,22 @@ sleep 2000
run general/parser/groupby.sim
run general/parser/groupby.sim
sleep 2000
sleep 2000
run general/parser/set_tag_vals.sim
run general/parser/set_tag_vals.sim
sleep 2000
sleep 2000
run general/parser/slimit_alter_tags.sim # persistent failed
run general/parser/slimit_alter_tags.sim # persistent failed
sleep 2000
sleep 2000
run general/parser/join.sim
run general/parser/join.sim
sleep 2000
sleep 2000
run general/parser/join_multivnode.sim
run general/parser/join_multivnode.sim
sleep 2000
sleep 2000
#run general/parser/repeatAlter.sim
run general/parser/repeatAlter.sim
sleep 2000
#run general/parser/repeatStream.sim
sleep 2000
sleep 2000
run general/parser/binary_escapeCharacter.sim
run general/parser/binary_escapeCharacter.sim
sleep 2000
sleep 2000
run general/parser/bug.sim
run general/parser/bug.sim
sleep 2000
#sleep 2000
run general/parser/stream_on_sys.sim
#run general/parser/repeatStream.sim
sleep 2000
#sleep 2000
run general/parser/stream.sim
#run general/parser/stream_on_sys.sim
\ No newline at end of file
#sleep 2000
#run general/parser/stream.sim
\ No newline at end of file
tests/script/jenkins/basic.txt
浏览文件 @
c1968083
...
@@ -324,7 +324,7 @@ cd ../../../debug; make
...
@@ -324,7 +324,7 @@ cd ../../../debug; make
./test.sh -f unique/vnode/replica3_vgroup.sim
./test.sh -f unique/vnode/replica3_vgroup.sim
./test.sh -f unique/arbitrator/check_cluster_cfg_para.sim
./test.sh -f unique/arbitrator/check_cluster_cfg_para.sim
./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim
./test.sh -f unique/arbitrator/dn2_mn1_cache_file_sync.sim
./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim
./test.sh -f unique/arbitrator/dn3_mn1_full_createTableFail.sim
./test.sh -f unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim
./test.sh -f unique/arbitrator/dn3_mn1_full_dropDnodeFail.sim
./test.sh -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim
./test.sh -f unique/arbitrator/dn3_mn1_multiCreateDropTable.sim
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录