Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ef84dcbe
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看板
未验证
提交
ef84dcbe
编写于
6月 25, 2022
作者:
S
shenglian-zhou
提交者:
GitHub
6月 25, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14252 from taosdata/szhou/feature/set-op-optimization
feat: add set operator optimization
上级
013c3820
1bc2f81b
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
73 addition
and
20 deletion
+73
-20
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+73
-20
未找到文件。
source/libs/planner/src/planOptimizer.c
浏览文件 @
ef84dcbe
...
...
@@ -1107,6 +1107,26 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
return
code
;
}
//=====================================================================================================================
// eliminate project optimization
static
bool
eliminateProjOptCheckProjColumnNames
(
SProjectLogicNode
*
pProjectNode
)
{
SHashObj
*
pProjColNameHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
SNode
*
pProjection
;
FOREACH
(
pProjection
,
pProjectNode
->
pProjections
)
{
char
*
projColumnName
=
((
SColumnNode
*
)
pProjection
)
->
colName
;
int32_t
*
pExist
=
taosHashGet
(
pProjColNameHash
,
projColumnName
,
strlen
(
projColumnName
));
if
(
NULL
!=
pExist
)
{
taosHashCleanup
(
pProjColNameHash
);
return
false
;
}
else
{
int32_t
exist
=
1
;
taosHashPut
(
pProjColNameHash
,
projColumnName
,
strlen
(
projColumnName
),
&
exist
,
sizeof
(
exist
));
}
}
taosHashCleanup
(
pProjColNameHash
);
return
true
;
}
static
bool
eliminateProjOptMayBeOptimized
(
SLogicNode
*
pNode
)
{
// TODO: enable this optimization after new mechanising that map projection and targets of project node
if
(
NULL
!=
pNode
->
pParent
)
{
...
...
@@ -1122,28 +1142,15 @@ static bool eliminateProjOptMayBeOptimized(SLogicNode* pNode) {
return
false
;
}
SHashObj
*
pProjColNameHash
=
taosHashInit
(
16
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
SNode
*
pProjection
;
FOREACH
(
pProjection
,
pProjectNode
->
pProjections
)
{
SExprNode
*
pExprNode
=
(
SExprNode
*
)
pProjection
;
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pExprNode
))
{
taosHashCleanup
(
pProjColNameHash
);
return
false
;
}
char
*
projColumnName
=
((
SColumnNode
*
)
pProjection
)
->
colName
;
int32_t
*
pExist
=
taosHashGet
(
pProjColNameHash
,
projColumnName
,
strlen
(
projColumnName
));
if
(
NULL
!=
pExist
)
{
taosHashCleanup
(
pProjColNameHash
);
return
false
;
}
else
{
int32_t
exist
=
1
;
taosHashPut
(
pProjColNameHash
,
projColumnName
,
strlen
(
projColumnName
),
&
exist
,
sizeof
(
exist
));
}
}
taosHashCleanup
(
pProjColNameHash
);
return
true
;
return
eliminateProjOptCheckProjColumnNames
(
pProjectNode
)
;
}
static
int32_t
eliminateProjOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
...
...
@@ -1183,14 +1190,60 @@ static int32_t eliminateProjOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog
return
eliminateProjOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pProjectNode
);
}
//=====================================================================================================================
// eliminate Set Operator optimization
static
bool
eliminateSetOpMayBeOptimized
(
SLogicNode
*
pNode
)
{
SLogicNode
*
pParent
=
pNode
->
pParent
;
if
(
NULL
==
pParent
||
QUERY_NODE_LOGIC_PLAN_AGG
!=
nodeType
(
pParent
)
&&
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
pParent
)
||
LIST_LENGTH
(
pParent
->
pChildren
)
<
2
)
{
return
false
;
}
if
(
nodeType
(
pNode
)
!=
nodeType
(
pNode
->
pParent
)
||
LIST_LENGTH
(
pNode
->
pChildren
)
<
2
)
{
return
false
;
}
return
true
;
}
static
int32_t
eliminateSetOpOptimizeImpl
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
,
SLogicNode
*
pSetOpNode
)
{
SNode
*
pSibling
;
FOREACH
(
pSibling
,
pSetOpNode
->
pParent
->
pChildren
)
{
if
(
nodesEqualNode
(
pSibling
,
(
SNode
*
)
pSetOpNode
))
{
SNode
*
pChild
;
FOREACH
(
pChild
,
pSetOpNode
->
pChildren
)
{
((
SLogicNode
*
)
pChild
)
->
pParent
=
pSetOpNode
->
pParent
;
}
INSERT_LIST
(
pSetOpNode
->
pParent
->
pChildren
,
pSetOpNode
->
pChildren
);
pSetOpNode
->
pChildren
=
NULL
;
ERASE_NODE
(
pSetOpNode
->
pParent
->
pChildren
);
return
TSDB_CODE_SUCCESS
;
}
}
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
static
int32_t
eliminateSetOpOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SLogicNode
*
pSetOpNode
=
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
eliminateSetOpMayBeOptimized
);
if
(
NULL
==
pSetOpNode
)
{
return
TSDB_CODE_SUCCESS
;
}
return
eliminateSetOpOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pSetOpNode
);
}
// clang-format off
static
const
SOptimizeRule
optimizeRuleSet
[]
=
{
{.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
},
{.
pName
=
"ConditionPushDown"
,
.
optimizeFunc
=
cpdOptimize
},
{.
pName
=
"OrderByPrimaryKey"
,
.
optimizeFunc
=
opkOptimize
},
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
smaOptimize
},
{.
pName
=
"PartitionTags"
,
.
optimizeFunc
=
partTagsOptimize
},
{.
pName
=
"EliminateProject"
,
.
optimizeFunc
=
eliminateProjOptimize
}
{.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
},
{.
pName
=
"ConditionPushDown"
,
.
optimizeFunc
=
cpdOptimize
},
{.
pName
=
"OrderByPrimaryKey"
,
.
optimizeFunc
=
opkOptimize
},
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
smaOptimize
},
{.
pName
=
"PartitionTags"
,
.
optimizeFunc
=
partTagsOptimize
},
{.
pName
=
"EliminateProject"
,
.
optimizeFunc
=
eliminateProjOptimize
},
{.
pName
=
"EliminateSetOperator"
,
.
optimizeFunc
=
eliminateSetOpOptimize
}
};
// clang-format on
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录