Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c2ee6972
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c2ee6972
编写于
5月 06, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-198] super table interval query join without ts matched.
上级
cf212a1e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
179 addition
and
32 deletion
+179
-32
src/client/inc/tscJoinProcess.h
src/client/inc/tscJoinProcess.h
+2
-0
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-1
src/client/src/tscJoinProcess.c
src/client/src/tscJoinProcess.c
+91
-0
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+6
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+15
-4
src/client/src/tscServer.c
src/client/src/tscServer.c
+30
-19
src/client/src/tscSql.c
src/client/src/tscSql.c
+30
-3
src/inc/tsdb.h
src/inc/tsdb.h
+2
-0
src/inc/tsqlfunction.h
src/inc/tsqlfunction.h
+1
-1
src/system/detail/src/vnodeQueryImpl.c
src/system/detail/src/vnodeQueryImpl.c
+0
-1
src/util/src/ttypes.c
src/util/src/ttypes.c
+1
-1
未找到文件。
src/client/inc/tscJoinProcess.h
浏览文件 @
c2ee6972
...
...
@@ -27,6 +27,8 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql);
void
tscGetQualifiedTSList
(
SSqlObj
*
pSql
,
SJoinSubquerySupporter
*
p1
,
SJoinSubquerySupporter
*
p2
,
int32_t
*
num
);
void
tscSetupOutputColumnIndex
(
SSqlObj
*
pSql
);
int32_t
tscLaunchSecondPhaseDirectly
(
SSqlObj
*
pSql
,
SSubqueryState
*
pState
);
int32_t
tscLaunchSecondPhaseSubqueries
(
SSqlObj
*
pSql
);
void
tscJoinQueryCallback
(
void
*
param
,
TAOS_RES
*
tres
,
int
code
);
...
...
src/client/inc/tsclient.h
浏览文件 @
c2ee6972
...
...
@@ -196,7 +196,7 @@ typedef struct SDataBlockList {
typedef
struct
SQueryInfo
{
int16_t
command
;
// the command may be different for each subclause, so keep it seperately.
uint
16
_t
type
;
// query/insert/import type
uint
32
_t
type
;
// query/insert/import type
char
slidingTimeUnit
;
int64_t
etime
,
stime
;
...
...
src/client/src/tscJoinProcess.c
浏览文件 @
c2ee6972
...
...
@@ -219,6 +219,97 @@ bool needSecondaryQuery(SQueryInfo* pQueryInfo) {
return
false
;
}
int32_t
tscLaunchSecondPhaseDirectly
(
SSqlObj
*
pSql
,
SSubqueryState
*
pState
)
{
/*
* If the columns are not involved in the final select clause, the secondary query will not be launched
* for the subquery.
*/
pSql
->
res
.
qhandle
=
0x1
;
pSql
->
res
.
numOfRows
=
0
;
tscTrace
(
"%p start to launch secondary subqueries"
,
pSql
);
bool
success
=
true
;
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
SJoinSubquerySupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
assert
(
pSupporter
!=
NULL
);
SSqlObj
*
pNew
=
createSubqueryObj
(
pSql
,
(
int16_t
)
i
,
tscJoinQueryCallback
,
pSupporter
,
NULL
);
if
(
pNew
==
NULL
)
{
tscDestroyJoinSupporter
(
pSupporter
);
success
=
false
;
break
;
}
pSql
->
pSubs
[
i
]
=
pNew
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
&
pNew
->
cmd
,
0
);
pQueryInfo
->
tsBuf
=
NULL
;
// transfer the ownership of timestamp comp-z data to the new created object
// set the second stage sub query for join process
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_JOIN_SEC_STAGE
;
/*
* if the first column of the secondary query is not ts function, add this function.
* Because this column is required to filter with timestamp after intersecting.
*/
assert
(
pNew
->
numOfSubs
==
0
&&
pNew
->
cmd
.
numOfClause
==
1
&&
pQueryInfo
->
numOfTables
==
1
);
/*
* if the first column of the secondary query is not ts function, add this function.
* Because this column is required to filter with timestamp after intersecting.
*/
if
(
tscSqlExprGet
(
pQueryInfo
,
0
)
->
functionId
!=
TSDB_FUNC_TS
)
{
tscAddTimestampColumn
(
pQueryInfo
,
TSDB_FUNC_TS
,
0
);
}
tscFieldInfoCalOffset
(
pQueryInfo
);
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
/*
* When handling the projection query, the offset value will be modified for table-table join, which is changed
* during the timestamp intersection.
*/
// fetch the join tag column
if
(
UTIL_METER_IS_SUPERTABLE
(
pMeterMetaInfo
))
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
0
);
assert
(
pQueryInfo
->
tagCond
.
joinInfo
.
hasJoin
);
int16_t
tagColIndex
=
tscGetJoinTagColIndexByUid
(
&
pQueryInfo
->
tagCond
,
pMeterMetaInfo
->
pMeterMeta
->
uid
);
pExpr
->
param
[
0
].
i64Key
=
tagColIndex
;
pExpr
->
numOfParams
=
1
;
}
tscPrintSelectClause
(
pNew
,
0
);
tscTrace
(
"%p subquery:%p tableIndex:%d, vnodeIdx:%d, type:%d, exprInfo:%d, colList:%d, fieldsInfo:%d, name:%s"
,
pSql
,
pNew
,
0
,
pMeterMetaInfo
->
vnodeIndex
,
pQueryInfo
->
type
,
pQueryInfo
->
exprsInfo
.
numOfExprs
,
pQueryInfo
->
colList
.
numOfCols
,
pQueryInfo
->
fieldsInfo
.
numOfOutputCols
,
pQueryInfo
->
pMeterInfo
[
0
]
->
name
);
}
//prepare the subqueries object failed, abort
if
(
!
success
)
{
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
tscError
(
"%p failed to prepare subqueries objs for secondary phase query, numOfSub:%d, code:%d"
,
pSql
,
pSql
->
numOfSubs
,
pSql
->
res
.
code
);
freeSubqueryObj
(
pSql
);
return
pSql
->
res
.
code
;
}
for
(
int32_t
i
=
0
;
i
<
pSql
->
numOfSubs
;
++
i
)
{
SSqlObj
*
pSub
=
pSql
->
pSubs
[
i
];
if
(
pSub
==
NULL
)
{
continue
;
}
tscProcessSql
(
pSub
);
}
return
TSDB_CODE_SUCCESS
;
}
/*
* launch secondary stage query to fetch the result that contains timestamp in set
*/
...
...
src/client/src/tscParseInsert.c
浏览文件 @
c2ee6972
...
...
@@ -949,7 +949,11 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
}
else
{
*
sqlstr
=
sql
;
}
if
(
*
sqlstr
==
NULL
)
{
code
=
TSDB_CODE_INVALID_SQL
;
}
return
code
;
}
...
...
@@ -1290,7 +1294,7 @@ int tsParseInsertSql(SSqlObj *pSql) {
SQueryInfo
*
pQueryInfo
=
NULL
;
tscGetQueryInfoDetailSafely
(
pCmd
,
pCmd
->
clauseIndex
,
&
pQueryInfo
);
uint
16
_t
type
=
(
sToken
.
type
==
TK_INSERT
)
?
TSDB_QUERY_TYPE_INSERT
:
TSDB_QUERY_TYPE_IMPORT
;
uint
32
_t
type
=
(
sToken
.
type
==
TK_INSERT
)
?
TSDB_QUERY_TYPE_INSERT
:
TSDB_QUERY_TYPE_IMPORT
;
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
type
);
sToken
=
tStrGetToken
(
pSql
->
sqlstr
,
&
index
,
false
,
0
,
NULL
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
c2ee6972
...
...
@@ -1135,6 +1135,10 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
const
char
*
msg5
=
"invalid function name"
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
clauseIndex
);
if
(
isSTable
)
{
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_STABLE_QUERY
);
}
for
(
int32_t
i
=
0
;
i
<
pSelection
->
nExpr
;
++
i
)
{
int32_t
outputIndex
=
pQueryInfo
->
exprsInfo
.
numOfExprs
;
...
...
@@ -3653,7 +3657,9 @@ static int32_t validateJoinExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr) {
}
if
(
!
pCondExpr
->
tsJoin
)
{
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
msg2
);
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TS_NO_MATCH_JOIN_QUERY
);
}
else
{
TSDB_QUERY_UNSET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TS_NO_MATCH_JOIN_QUERY
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -5625,9 +5631,14 @@ int32_t doCheckForQuery(SSqlObj* pSql, SQuerySQL* pQuerySql, int32_t index) {
pQuerySql
->
pSortOrder
==
NULL
);
return
doLocalQueryProcess
(
pQueryInfo
,
pQuerySql
);
}
if
(
pQuerySql
->
from
->
nExpr
>
TSDB_MAX_JOIN_TABLE_NUM
)
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
if
(
pQuerySql
->
from
->
nExpr
>
1
)
{
if
(
pQuerySql
->
from
->
nExpr
>
2
)
{
// not support more than 2 tables join query
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
// set the timestamp not matched join query
TSDB_QUERY_SET_TYPE
(
pQueryInfo
->
type
,
TSDB_QUERY_TYPE_TS_NO_MATCH_JOIN_QUERY
);
}
pQueryInfo
->
command
=
TSDB_SQL_SELECT
;
...
...
src/client/src/tscServer.c
浏览文件 @
c2ee6972
...
...
@@ -635,7 +635,7 @@ int32_t tscLaunchJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSubquerySu
pSql
->
pSubs
[
pSql
->
numOfSubs
++
]
=
pNew
;
assert
(
pSql
->
numOfSubs
<=
pSupporter
->
pState
->
numOfTotal
);
if
(
QUERY_IS_JOIN_QUERY
(
pQueryInfo
->
type
))
{
addGroupInfoForSubquery
(
pSql
,
pNew
,
0
,
tableIndex
);
...
...
@@ -749,7 +749,7 @@ int tscProcessSql(SSqlObj *pSql) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
SMeterMetaInfo
*
pMeterMetaInfo
=
NULL
;
int16
_t
type
=
0
;
uint32
_t
type
=
0
;
if
(
pQueryInfo
!=
NULL
)
{
pMeterMetaInfo
=
tscGetMeterMetaInfoFromQueryInfo
(
pQueryInfo
,
0
);
...
...
@@ -794,26 +794,37 @@ int tscProcessSql(SSqlObj *pSql) {
if
(
QUERY_IS_JOIN_QUERY
(
type
))
{
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_SUBQUERY
)
==
0
)
{
SSubqueryState
*
pState
=
calloc
(
1
,
sizeof
(
SSubqueryState
));
pState
->
numOfTotal
=
pQueryInfo
->
numOfTables
;
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
SJoinSubquerySupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
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
);
pState
->
numOfCompleted
=
pQueryInfo
->
numOfTables
-
i
-
1
;
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
pSql
->
res
.
code
;
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_TS_NO_MATCH_JOIN_QUERY
)
!=
0
)
{
pSql
->
numOfSubs
=
pQueryInfo
->
numOfTables
;
if
(
pSql
->
pSubs
==
NULL
)
{
pSql
->
pSubs
=
calloc
(
pSql
->
numOfSubs
,
POINTER_BYTES
);
if
(
pSql
->
pSubs
==
NULL
)
{
return
TSDB_CODE_CLI_OUT_OF_MEMORY
;
}
}
int32_t
code
=
tscLaunchJoinSubquery
(
pSql
,
i
,
pSupporter
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// failed to create subquery object, quit query
tscDestroyJoinSupporter
(
pSupporter
);
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
break
;
tscLaunchSecondPhaseDirectly
(
pSql
,
pState
);
}
else
{
for
(
int32_t
i
=
0
;
i
<
pQueryInfo
->
numOfTables
;
++
i
)
{
SJoinSubquerySupporter
*
pSupporter
=
tscCreateJoinSupporter
(
pSql
,
pState
,
i
);
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
);
pState
->
numOfCompleted
=
pQueryInfo
->
numOfTables
-
i
-
1
;
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
return
pSql
->
res
.
code
;
}
int32_t
code
=
tscLaunchJoinSubquery
(
pSql
,
i
,
pSupporter
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
// failed to create subquery object, quit query
tscDestroyJoinSupporter
(
pSupporter
);
pSql
->
res
.
code
=
TSDB_CODE_CLI_OUT_OF_MEMORY
;
break
;
}
}
}
...
...
src/client/src/tscSql.c
浏览文件 @
c2ee6972
...
...
@@ -551,9 +551,36 @@ static void **tscBuildResFromSubqueries(SSqlObj *pSql) {
}
if
(
numOfTableHasRes
>=
2
)
{
// do merge result
success
=
(
doSetResultRowData
(
pSql
->
pSubs
[
0
],
false
)
!=
NULL
)
&&
(
doSetResultRowData
(
pSql
->
pSubs
[
1
],
false
)
!=
NULL
);
// printf("first:%" PRId64 ", second:%" PRId64 "\n", key1, key2);
bool
s1
=
doSetResultRowData
(
pSql
->
pSubs
[
0
],
false
);
bool
s2
=
doSetResultRowData
(
pSql
->
pSubs
[
1
],
false
);
success
=
s1
&&
s2
;
if
(
success
)
{
TSKEY
key1
=
*
(
TSKEY
*
)
pSql
->
pSubs
[
0
]
->
res
.
tsrow
[
0
];
TSKEY
key2
=
*
(
TSKEY
*
)
pSql
->
pSubs
[
1
]
->
res
.
tsrow
[
0
];
while
(
1
)
{
if
(
key1
<
key2
)
{
s1
=
doSetResultRowData
(
pSql
->
pSubs
[
0
],
false
);
if
(
!
s1
)
{
// retrieve next block
break
;
}
}
else
if
(
key1
>
key2
)
{
s2
=
doSetResultRowData
(
pSql
->
pSubs
[
1
],
false
);
if
(
!
s2
)
{
break
;
}
}
else
{
break
;
}
key1
=
*
(
TSKEY
*
)
pSql
->
pSubs
[
0
]
->
res
.
tsrow
[
0
];
key2
=
*
(
TSKEY
*
)
pSql
->
pSubs
[
1
]
->
res
.
tsrow
[
0
];
}
success
=
s1
&&
s2
;
// printf("first:%" PRId64 ", second:%" PRId64 "\n", key1, key2);
}
}
else
{
// only one subquery
SSqlObj
*
pSub
=
pSql
->
pSubs
[
0
];
if
(
pSub
==
NULL
)
{
...
...
src/inc/tsdb.h
浏览文件 @
c2ee6972
...
...
@@ -230,10 +230,12 @@ extern "C" {
#define TSDB_QUERY_TYPE_INSERT 0x100U // insert type
#define TSDB_QUERY_TYPE_IMPORT 0x200U // import data
#define TSDB_QUERY_TYPE_TS_NO_MATCH_JOIN_QUERY 0x400u // join query without ts match
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
#define TSDB_QUERY_RESET_TYPE(x) ((x) = TSDB_QUERY_TYPE_NON_TYPE)
#define TSDB_QUERY_UNSET_TYPE(x, _type) ((x) &= ~(_type))
#define TSQL_SO_ASC 1
#define TSQL_SO_DESC 0
...
...
src/inc/tsqlfunction.h
浏览文件 @
c2ee6972
...
...
@@ -115,7 +115,7 @@ enum {
};
#define QUERY_IS_STABLE_QUERY(type) (((type)&TSDB_QUERY_TYPE_STABLE_QUERY) != 0)
#define QUERY_IS_JOIN_QUERY(type) (((type)&
TSDB_QUERY_TYPE_JOIN_QUERY
) != 0)
#define QUERY_IS_JOIN_QUERY(type) (((type)&
(TSDB_QUERY_TYPE_JOIN_QUERY|TSDB_QUERY_TYPE_TS_NO_MATCH_JOIN_QUERY)
) != 0)
#define QUERY_IS_PROJECTION_QUERY(type) (((type)&TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0)
#define QUERY_IS_FREE_RESOURCE(type) (((type)&TSDB_QUERY_TYPE_FREE_RESOURCE) != 0)
...
...
src/system/detail/src/vnodeQueryImpl.c
浏览文件 @
c2ee6972
...
...
@@ -2665,7 +2665,6 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t *
int32_t
j
=
0
;
TSKEY
lastKey
=
-
1
;
int32_t
lastIndex
=
-
1
;
//bool firstAccessedPoint = true;
for
(
j
=
0
;
j
<
(
*
forwardStep
);
++
j
)
{
int32_t
offset
=
GET_COL_DATA_POS
(
pQuery
,
j
,
step
);
...
...
src/util/src/ttypes.c
浏览文件 @
c2ee6972
...
...
@@ -217,7 +217,7 @@ int32_t tVariantCompare(const tVariant *pDst, const tVariant *pSrc) {
case
TSDB_DATA_TYPE_NCHAR
:
return
strncasecmp
(
pSrc
->
pz
,
pDst
->
pz
,
pSrc
->
nLen
);
default:
return
1
;
return
0
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录