Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
149587c9
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看板
未验证
提交
149587c9
编写于
7月 05, 2022
作者:
S
shenglian-zhou
提交者:
GitHub
7月 05, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14560 from taosdata/szhou/feature/push-project-condition
feat: push project condition down to its child
上级
8f3cd451
dd1dbe22
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
16 deletion
+81
-16
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+76
-16
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+5
-0
未找到文件。
source/libs/planner/src/planOptimizer.c
浏览文件 @
149587c9
...
...
@@ -490,18 +490,7 @@ static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicN
}
static
int32_t
pushDownCondOptPushCondToChild
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pChild
,
SNode
**
pCond
)
{
switch
(
nodeType
(
pChild
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
pushDownCondOptPushCondToScan
(
pCxt
,
(
SScanLogicNode
*
)
pChild
,
pCond
);
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
return
pushDownCondOptPushCondToProject
(
pCxt
,
(
SProjectLogicNode
*
)
pChild
,
pCond
);
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
return
pushDownCondOptPushCondToJoin
(
pCxt
,
(
SJoinLogicNode
*
)
pChild
,
pCond
);
default:
break
;
}
planError
(
"pushDownCondOptPushCondToChild failed, invalid logic plan node %s"
,
nodesNodeName
(
nodeType
(
pChild
)));
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
return
pushDownCondOptAppendCond
(
&
pChild
->
pConditions
,
pCond
);
}
static
bool
pushDownCondOptIsPriKey
(
SNode
*
pNode
,
SNodeList
*
pTableCols
)
{
...
...
@@ -802,10 +791,7 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
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
))
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_JOIN
!=
nodeType
(
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
)))
{
if
(
1
!=
LIST_LENGTH
(
pAgg
->
node
.
pChildren
))
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -832,6 +818,77 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
return
code
;
}
typedef
struct
SRewriteProjCondContext
{
SProjectLogicNode
*
pProj
;
int32_t
errCode
;
}
SRewriteProjCondContext
;
static
EDealRes
rewriteProjectCondForPushDownImpl
(
SNode
**
ppNode
,
void
*
pContext
)
{
SRewriteProjCondContext
*
pCxt
=
pContext
;
SProjectLogicNode
*
pProj
=
pCxt
->
pProj
;
if
(
QUERY_NODE_COLUMN
==
nodeType
(
*
ppNode
))
{
SNode
*
pTarget
=
NULL
;
FOREACH
(
pTarget
,
pProj
->
node
.
pTargets
)
{
if
(
nodesEqualNode
(
pTarget
,
*
ppNode
))
{
SNode
*
pProjection
=
NULL
;
FOREACH
(
pProjection
,
pProj
->
pProjections
)
{
if
(
0
==
strcmp
(((
SExprNode
*
)
pProjection
)
->
aliasName
,
((
SColumnNode
*
)(
*
ppNode
))
->
colName
))
{
SNode
*
pExpr
=
nodesCloneNode
(
pProjection
);
if
(
pExpr
==
NULL
)
{
pCxt
->
errCode
=
terrno
;
return
DEAL_RES_ERROR
;
}
nodesDestroyNode
(
*
ppNode
);
*
ppNode
=
pExpr
;
}
// end if expr alias name equal column name
}
// end for each project
}
// end if target node equals cond column node
}
// end for each targets
return
DEAL_RES_IGNORE_CHILD
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
rewriteProjectCondForPushDown
(
SOptimizeContext
*
pCxt
,
SProjectLogicNode
*
pProject
,
SNode
**
ppProjectCond
)
{
SRewriteProjCondContext
cxt
=
{.
pProj
=
pProject
,
.
errCode
=
TSDB_CODE_SUCCESS
};
SNode
*
pProjectCond
=
pProject
->
node
.
pConditions
;
nodesRewriteExpr
(
&
pProjectCond
,
rewriteProjectCondForPushDownImpl
,
&
cxt
);
*
ppProjectCond
=
pProjectCond
;
pProject
->
node
.
pConditions
=
NULL
;
return
cxt
.
errCode
;
}
static
int32_t
pushDownCondOptDealProject
(
SOptimizeContext
*
pCxt
,
SProjectLogicNode
*
pProject
)
{
if
(
NULL
==
pProject
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pProject
->
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
(
pProject
->
node
.
pChildren
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
!=
pProject
->
node
.
pLimit
||
NULL
!=
pProject
->
node
.
pSlimit
)
{
return
TSDB_CODE_SUCCESS
;
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
SNode
*
pProjCond
=
NULL
;
code
=
rewriteProjectCondForPushDown
(
pCxt
,
pProject
,
&
pProjCond
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
SLogicNode
*
pChild
=
(
SLogicNode
*
)
nodesListGetNode
(
pProject
->
node
.
pChildren
,
0
);
code
=
pushDownCondOptPushCondToChild
(
pCxt
,
pChild
,
&
pProjCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pProject
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
);
pCxt
->
optimized
=
true
;
}
else
{
nodesDestroyNode
(
pProjCond
);
}
return
code
;
}
static
int32_t
pushDownCondOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pLogicNode
))
{
...
...
@@ -844,6 +901,9 @@ static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLog
case
QUERY_NODE_LOGIC_PLAN_AGG
:
code
=
pushDownCondOptDealAgg
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
break
;
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
code
=
pushDownCondOptDealProject
(
pCxt
,
(
SProjectLogicNode
*
)
pLogicNode
);
break
;
default:
break
;
}
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
149587c9
...
...
@@ -81,3 +81,8 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
run
(
"SELECT c1 FROM st1s3"
);
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
}
TEST_F
(
PlanOptimizeTest
,
pushDownProjectCond
)
{
useDb
(
"root"
,
"test"
);
run
(
"select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first"
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录