Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
26e4fcf5
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看板
提交
26e4fcf5
编写于
7月 05, 2022
作者:
S
slzhou@taodata.com
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: push project cond to child
上级
cf9a6dea
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
82 addition
and
0 deletion
+82
-0
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+77
-0
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+5
-0
未找到文件。
source/libs/planner/src/planOptimizer.c
浏览文件 @
26e4fcf5
...
@@ -832,6 +832,80 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
...
@@ -832,6 +832,80 @@ static int32_t pushDownCondOptDealAgg(SOptimizeContext* pCxt, SAggLogicNode* pAg
return
code
;
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
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pProject
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
nodesListGetNode
(
pProject
->
node
.
pChildren
,
0
))
&&
QUERY_NODE_LOGIC_PLAN_JOIN
!=
nodeType
(
nodesListGetNode
(
pProject
->
node
.
pChildren
,
0
)))
{
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
)
{
static
int32_t
pushDownCondOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pLogicNode
))
{
switch
(
nodeType
(
pLogicNode
))
{
...
@@ -844,6 +918,9 @@ static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLog
...
@@ -844,6 +918,9 @@ static int32_t pushDownCondOptimizeImpl(SOptimizeContext* pCxt, SLogicNode* pLog
case
QUERY_NODE_LOGIC_PLAN_AGG
:
case
QUERY_NODE_LOGIC_PLAN_AGG
:
code
=
pushDownCondOptDealAgg
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
code
=
pushDownCondOptDealAgg
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
break
;
break
;
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
code
=
pushDownCondOptDealProject
(
pCxt
,
(
SProjectLogicNode
*
)
pLogicNode
);
break
;
default:
default:
break
;
break
;
}
}
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
26e4fcf5
...
@@ -81,3 +81,8 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
...
@@ -81,3 +81,8 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
run
(
"SELECT c1 FROM st1s3"
);
run
(
"SELECT c1 FROM st1s3"
);
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
// 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录