Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
73e0e09d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
73e0e09d
编写于
7月 05, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: split join on condition into merge condition and on condition
上级
02479659
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
85 addition
and
19 deletion
+85
-19
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+1
-2
source/libs/executor/src/joinoperator.c
source/libs/executor/src/joinoperator.c
+17
-9
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+67
-8
未找到文件。
source/libs/executor/inc/executorimpl.h
浏览文件 @
73e0e09d
...
...
@@ -680,8 +680,7 @@ typedef struct SJoinOperatorInfo {
SSDataBlock
*
pRight
;
int32_t
rightPos
;
SColumnInfo
rightCol
;
SNode
*
pOnConditions
;
SNode
*
pOtherConditions
;
SNode
*
pCondAfterMerge
;
}
SJoinOperatorInfo
;
#define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED)
...
...
source/libs/executor/src/joinoperator.c
浏览文件 @
73e0e09d
...
...
@@ -62,11 +62,19 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
ASSERT
(
false
);
}
//TODO: merge these two conditions
ASSERT
(
pJoinNode
->
pOnConditions
);
pInfo
->
pOnConditions
=
nodesCloneNode
(
pJoinNode
->
pOnConditions
);
if
(
pJoinNode
->
node
.
pConditions
!=
NULL
)
{
pInfo
->
pOtherConditions
=
pJoinNode
->
node
.
pConditions
;
if
(
pJoinNode
->
pOnConditions
!=
NULL
&&
pJoinNode
->
node
.
pConditions
!=
NULL
)
{
pInfo
->
pCondAfterMerge
=
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)(
pInfo
->
pCondAfterMerge
);
pLogicCond
->
pParameterList
=
nodesMakeList
();
nodesListMakeAppend
(
&
pLogicCond
->
pParameterList
,
nodesCloneNode
(
pJoinNode
->
pOnConditions
));
nodesListMakeAppend
(
&
pLogicCond
->
pParameterList
,
nodesCloneNode
(
pJoinNode
->
node
.
pConditions
));
pLogicCond
->
condType
=
LOGIC_COND_TYPE_AND
;
}
else
if
(
pJoinNode
->
pOnConditions
!=
NULL
)
{
pInfo
->
pCondAfterMerge
=
nodesCloneNode
(
pJoinNode
->
pOnConditions
);
}
else
if
(
pJoinNode
->
node
.
pConditions
!=
NULL
)
{
pInfo
->
pCondAfterMerge
=
nodesCloneNode
(
pJoinNode
->
node
.
pConditions
);
}
else
{
pInfo
->
pCondAfterMerge
=
NULL
;
}
pOperator
->
fpSet
=
...
...
@@ -95,8 +103,7 @@ void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode) {
void
destroyMergeJoinOperator
(
void
*
param
,
int32_t
numOfOutput
)
{
SJoinOperatorInfo
*
pJoinOperator
=
(
SJoinOperatorInfo
*
)
param
;
nodesDestroyNode
(
pJoinOperator
->
pOnConditions
);
nodesDestroyNode
(
pJoinOperator
->
pOtherConditions
);
nodesDestroyNode
(
pJoinOperator
->
pCondAfterMerge
);
}
static
void
doMergeJoinImpl
(
struct
SOperatorInfo
*
pOperator
,
SSDataBlock
*
pRes
)
{
...
...
@@ -201,8 +208,9 @@ SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
if
(
numOfNewRows
==
0
)
{
break
;
}
doFilter
(
pJoinInfo
->
pOnConditions
,
pRes
);
doFilter
(
pJoinInfo
->
pOtherConditions
,
pRes
);
if
(
pJoinInfo
->
pCondAfterMerge
!=
NULL
)
{
doFilter
(
pJoinInfo
->
pCondAfterMerge
,
pRes
);
}
if
(
pRes
->
info
.
rows
>=
pOperator
->
resultInfo
.
threshold
)
{
break
;
}
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
73e0e09d
...
...
@@ -546,15 +546,11 @@ static bool pushDownCondOptContainPriKeyEqualCond(SJoinLogicNode* pJoin, SNode*
}
return
hasPrimaryKeyEqualCond
;
}
else
{
bool
isPriKeyEqualCond
=
pushDownCondOptIsPriKeyEqualCond
(
pJoin
,
pCond
);
if
(
isPriKeyEqualCond
)
{
pJoin
->
pMergeCondition
=
nodesCloneNode
(
pCond
);
}
return
isPriKeyEqualCond
;
return
pushDownCondOptIsPriKeyEqualCond
(
pJoin
,
pCond
);
}
}
static
int32_t
pushDownCondOpt
ExtractJoinMerge
Cond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
static
int32_t
pushDownCondOpt
CheckJoinOn
Cond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
NULL
==
pJoin
->
pOnConditions
)
{
return
generateUsageErrMsg
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
TSDB_CODE_PLAN_NOT_SUPPORT_CROSS_JOIN
);
}
...
...
@@ -564,13 +560,61 @@ static int32_t pushDownCondOptExtractJoinMergeCond(SOptimizeContext* pCxt, SJoin
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
pushDownCondOptPartJoinOnCondLogicCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
ppMergeCond
,
SNode
**
ppOnCond
)
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)(
pJoin
->
pOnConditions
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNodeList
*
pOnConds
=
NULL
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
if
(
pushDownCondOptIsPriKeyEqualCond
(
pJoin
,
pCond
))
{
*
ppMergeCond
=
nodesCloneNode
(
pCond
);
}
else
{
code
=
nodesListMakeAppend
(
&
pOnConds
,
nodesCloneNode
(
pCond
));
}
}
SNode
*
pTempOnCond
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempOnCond
,
&
pOnConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
*
ppMergeCond
)
{
*
ppOnCond
=
pTempOnCond
;
nodesDestroyNode
(
pJoin
->
pOnConditions
);
pJoin
->
pOnConditions
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
else
{
nodesDestroyList
(
pOnConds
);
nodesDestroyNode
(
pTempOnCond
);
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
}
static
int32_t
pushDownCondOptPartJoinOnCond
(
SJoinLogicNode
*
pJoin
,
SNode
**
ppMergeCond
,
SNode
**
ppOnCond
)
{
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pJoin
->
pOnConditions
)
&&
LOGIC_COND_TYPE_AND
==
((
SLogicConditionNode
*
)(
pJoin
->
pOnConditions
))
->
condType
)
{
return
pushDownCondOptPartJoinOnCondLogicCond
(
pJoin
,
ppMergeCond
,
ppOnCond
);
}
if
(
pushDownCondOptIsPriKeyEqualCond
(
pJoin
,
pJoin
->
pOnConditions
))
{
*
ppMergeCond
=
nodesCloneNode
(
pJoin
->
pOnConditions
);
*
ppOnCond
=
NULL
;
nodesDestroyNode
(
pJoin
->
pOnConditions
);
pJoin
->
pOnConditions
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
else
{
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
}
static
int32_t
pushDownCondOptDealJoin
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
==
pJoin
->
node
.
pConditions
)
{
return
pushDownCondOpt
ExtractJoinMerge
Cond
(
pCxt
,
pJoin
);
return
pushDownCondOpt
CheckJoinOn
Cond
(
pCxt
,
pJoin
);
}
SNode
*
pOnCond
=
NULL
;
...
...
@@ -589,11 +633,26 @@ static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* p
pushDownCondOptPushCondToChild
(
pCxt
,
(
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
),
&
pRightChildCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
pushDownCondOptCheckJoinOnCond
(
pCxt
,
pJoin
);
}
SNode
*
pJoinMergeCond
=
NULL
;
SNode
*
pJoinOnCond
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
pushDownCondOptPartJoinOnCond
(
pJoin
,
&
pJoinMergeCond
,
&
pJoinOnCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pJoinMergeCond
)
{
pJoin
->
pMergeCondition
=
pJoinMergeCond
;
pJoin
->
pOnConditions
=
pJoinOnCond
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
);
pCxt
->
optimized
=
true
;
code
=
pushDownCondOptExtractJoinMergeCond
(
pCxt
,
pJoin
);
}
else
{
nodesDestroyNode
(
pJoinMergeCond
);
nodesDestroyNode
(
pJoinOnCond
);
nodesDestroyNode
(
pOnCond
);
nodesDestroyNode
(
pLeftChildCond
);
nodesDestroyNode
(
pRightChildCond
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录