Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d6e1d1bc
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
未验证
提交
d6e1d1bc
编写于
6月 30, 2022
作者:
S
shenglian-zhou
提交者:
GitHub
6月 30, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14389 from taosdata/szhou/feature/pushdown-agg-cond
feat: support push agg operator condition to scan
上级
8cf9f9c7
82bd8a56
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
153 addition
and
5 deletion
+153
-5
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+0
-1
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+152
-3
未找到文件。
source/libs/executor/src/executorimpl.c
浏览文件 @
d6e1d1bc
...
...
@@ -1348,7 +1348,7 @@ void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const int8_t* rowR
SColumnInfoData
*
pSrc
=
taosArrayGet
(
px
->
pDataBlock
,
i
);
SColumnInfoData
*
pDst
=
taosArrayGet
(
pBlock
->
pDataBlock
,
i
);
// it is a reserved column for scalar function, and no data in this column yet.
if
(
pDst
->
pData
==
NULL
)
{
if
(
pDst
->
pData
==
NULL
||
pSrc
->
pData
==
NULL
)
{
continue
;
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
d6e1d1bc
...
...
@@ -1728,7 +1728,6 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
}
else
{
pCxt
->
hasOtherCol
=
true
;
}
return
*
((
bool
*
)
pContext
)
?
DEAL_RES_CONTINUE
:
DEAL_RES_END
;
}
return
DEAL_RES_CONTINUE
;
}
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
d6e1d1bc
...
...
@@ -586,11 +586,160 @@ static int32_t pushDownCondOptDealJoin(SOptimizeContext* pCxt, SJoinLogicNode* p
return
code
;
}
static
int32_t
pushDownCondOptDealAgg
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
// todo
typedef
struct
SPartAggCondContext
{
SAggLogicNode
*
pAgg
;
bool
hasAggFunc
;
}
SPartAggCondContext
;
static
EDealRes
partAggCondHasAggFuncImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
SPartAggCondContext
*
pCxt
=
pContext
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
SNode
*
pAggFunc
=
NULL
;
FOREACH
(
pAggFunc
,
pCxt
->
pAgg
->
pAggFuncs
)
{
if
(
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
((
SFunctionNode
*
)
pAggFunc
)
->
node
.
aliasName
)
==
0
)
{
pCxt
->
hasAggFunc
=
true
;
return
DEAL_RES_END
;
}
}
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
partitionAggCondHasAggFunc
(
SAggLogicNode
*
pAgg
,
SNode
*
pCond
)
{
SPartAggCondContext
cxt
=
{.
pAgg
=
pAgg
,
.
hasAggFunc
=
false
};
nodesWalkExpr
(
pCond
,
partAggCondHasAggFuncImpl
,
&
cxt
);
return
cxt
.
hasAggFunc
;
}
static
int32_t
partitionAggCondConj
(
SAggLogicNode
*
pAgg
,
SNode
**
ppAggFuncCond
,
SNode
**
ppGroupKeyCond
)
{
SLogicConditionNode
*
pLogicCond
=
(
SLogicConditionNode
*
)
pAgg
->
node
.
pConditions
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNodeList
*
pAggFuncConds
=
NULL
;
SNodeList
*
pGroupKeyConds
=
NULL
;
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pLogicCond
->
pParameterList
)
{
if
(
partitionAggCondHasAggFunc
(
pAgg
,
pCond
))
{
code
=
nodesListMakeAppend
(
&
pAggFuncConds
,
nodesCloneNode
(
pCond
));
}
else
{
code
=
nodesListMakeAppend
(
&
pGroupKeyConds
,
nodesCloneNode
(
pCond
));
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
}
SNode
*
pTempAggFuncCond
=
NULL
;
SNode
*
pTempGroupKeyCond
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempAggFuncCond
,
&
pAggFuncConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesMergeConds
(
&
pTempGroupKeyCond
,
&
pGroupKeyConds
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
ppAggFuncCond
=
pTempAggFuncCond
;
*
ppGroupKeyCond
=
pTempGroupKeyCond
;
}
else
{
nodesDestroyList
(
pAggFuncConds
);
nodesDestroyList
(
pGroupKeyConds
);
nodesDestroyNode
(
pTempAggFuncCond
);
nodesDestroyNode
(
pTempGroupKeyCond
);
}
pAgg
->
node
.
pConditions
=
NULL
;
return
code
;
}
static
int32_t
partitionAggCond
(
SAggLogicNode
*
pAgg
,
SNode
**
ppAggFunCond
,
SNode
**
ppGroupKeyCond
)
{
SNode
*
pAggNodeCond
=
pAgg
->
node
.
pConditions
;
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pAggNodeCond
)
&&
LOGIC_COND_TYPE_AND
==
((
SLogicConditionNode
*
)(
pAggNodeCond
))
->
condType
)
{
return
partitionAggCondConj
(
pAgg
,
ppAggFunCond
,
ppGroupKeyCond
);
}
if
(
partitionAggCondHasAggFunc
(
pAgg
,
pAggNodeCond
))
{
*
ppAggFunCond
=
pAggNodeCond
;
}
else
{
*
ppGroupKeyCond
=
pAggNodeCond
;
}
pAgg
->
node
.
pConditions
=
NULL
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
pushCondToAggCond
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
,
SNode
**
pAggFuncCond
)
{
pushDownCondOptAppendCond
(
&
pAgg
->
node
.
pConditions
,
pAggFuncCond
);
return
TSDB_CODE_SUCCESS
;
}
typedef
struct
SRewriteAggGroupKeyCondContext
{
SAggLogicNode
*
pAgg
;
int32_t
errCode
;
}
SRewriteAggGroupKeyCondContext
;
static
EDealRes
rewriteAggGroupKeyCondForPushDownImpl
(
SNode
**
pNode
,
void
*
pContext
)
{
SRewriteAggGroupKeyCondContext
*
pCxt
=
pContext
;
SAggLogicNode
*
pAgg
=
pCxt
->
pAgg
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
*
pNode
))
{
SNode
*
pGroupKey
=
NULL
;
FOREACH
(
pGroupKey
,
pAgg
->
pGroupKeys
)
{
SNode
*
pGroup
=
NULL
;
FOREACH
(
pGroup
,
((
SGroupingSetNode
*
)
pGroupKey
)
->
pParameterList
)
{
if
(
0
==
strcmp
(((
SExprNode
*
)
pGroup
)
->
aliasName
,
((
SColumnNode
*
)(
*
pNode
))
->
colName
))
{
SNode
*
pExpr
=
nodesCloneNode
(
pGroup
);
if
(
pExpr
==
NULL
)
{
pCxt
->
errCode
=
terrno
;
return
DEAL_RES_ERROR
;
}
nodesDestroyNode
(
*
pNode
);
*
pNode
=
pExpr
;
}
}
}
return
DEAL_RES_IGNORE_CHILD
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
rewriteAggGroupKeyCondForPushDown
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
,
SNode
*
pGroupKeyCond
)
{
SRewriteAggGroupKeyCondContext
cxt
=
{.
pAgg
=
pAgg
,
.
errCode
=
TSDB_CODE_SUCCESS
};
nodesRewriteExpr
(
&
pGroupKeyCond
,
rewriteAggGroupKeyCondForPushDownImpl
,
&
cxt
);
return
cxt
.
errCode
;
}
static
int32_t
pushDownCondOptDealAgg
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
if
(
NULL
==
pAgg
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pAgg
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
))
{
return
TSDB_CODE_SUCCESS
;
}
//TODO: remove it after full implementation of pushing down to child
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pAggFuncCond
=
NULL
;
SNode
*
pGroupKeyCond
=
NULL
;
int32_t
code
=
partitionAggCond
(
pAgg
,
&
pAggFuncCond
,
&
pGroupKeyCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pAggFuncCond
)
{
code
=
pushCondToAggCond
(
pCxt
,
pAgg
,
&
pAggFuncCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pGroupKeyCond
)
{
code
=
rewriteAggGroupKeyCondForPushDown
(
pCxt
,
pAgg
,
pGroupKeyCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pGroupKeyCond
)
{
SLogicNode
*
pChild
=
(
SLogicNode
*
)
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
);
code
=
pushDownCondOptPushCondToChild
(
pCxt
,
pChild
,
&
pGroupKeyCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pAgg
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
);
pCxt
->
optimized
=
true
;
}
else
{
nodesDestroyNode
(
pGroupKeyCond
);
nodesDestroyNode
(
pAggFuncCond
);
}
return
code
;
}
static
int32_t
pushDownCondOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pLogicNode
))
{
...
...
@@ -1707,8 +1856,8 @@ static EDealRes mergeProjectionsExpr(SNode** pNode, void* pContext) {
static
int32_t
mergeProjectsOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SLogicNode
*
pSelfNode
)
{
SLogicNode
*
pChild
=
(
SLogicNode
*
)
nodesListGetNode
(
pSelfNode
->
pChildren
,
0
);
SMergeProjectionsContext
cxt
=
{.
pChildProj
=
(
SProjectLogicNode
*
)
pChild
,
.
errCode
=
TSDB_CODE_SUCCESS
};
SMergeProjectionsContext
cxt
=
{.
pChildProj
=
(
SProjectLogicNode
*
)
pChild
,
.
errCode
=
TSDB_CODE_SUCCESS
};
nodesRewriteExprs
(((
SProjectLogicNode
*
)
pSelfNode
)
->
pProjections
,
mergeProjectionsExpr
,
&
cxt
);
int32_t
code
=
cxt
.
errCode
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录