Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cf245fa5
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cf245fa5
编写于
11月 23, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: last cache optimize
上级
937e5d20
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
87 addition
and
25 deletion
+87
-25
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+67
-19
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+20
-6
未找到文件。
source/libs/planner/src/planLogicCreater.c
浏览文件 @
cf245fa5
...
...
@@ -36,6 +36,7 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi
typedef
struct
SRewriteExprCxt
{
int32_t
errCode
;
SNodeList
*
pExprs
;
bool
*
pOutputs
;
}
SRewriteExprCxt
;
static
void
setColumnInfo
(
SFunctionNode
*
pFunc
,
SColumnNode
*
pCol
)
{
...
...
@@ -63,14 +64,30 @@ static void setColumnInfo(SFunctionNode* pFunc, SColumnNode* pCol) {
}
static
EDealRes
doRewriteExpr
(
SNode
**
pNode
,
void
*
pContext
)
{
SRewriteExprCxt
*
pCxt
=
(
SRewriteExprCxt
*
)
pContext
;
switch
(
nodeType
(
*
pNode
))
{
case
QUERY_NODE_COLUMN
:
{
if
(
NULL
!=
pCxt
->
pOutputs
)
{
SNode
*
pExpr
;
int32_t
index
=
0
;
FOREACH
(
pExpr
,
pCxt
->
pExprs
)
{
if
(
QUERY_NODE_GROUPING_SET
==
nodeType
(
pExpr
))
{
pExpr
=
nodesListGetNode
(((
SGroupingSetNode
*
)
pExpr
)
->
pParameterList
,
0
);
}
if
(
nodesEqualNode
(
pExpr
,
*
pNode
))
{
pCxt
->
pOutputs
[
index
]
=
true
;
break
;
}
}
}
break
;
}
case
QUERY_NODE_OPERATOR
:
case
QUERY_NODE_LOGIC_CONDITION
:
case
QUERY_NODE_FUNCTION
:
case
QUERY_NODE_CASE_WHEN
:
{
SRewriteExprCxt
*
pCxt
=
(
SRewriteExprCxt
*
)
pContext
;
SNode
*
pExpr
;
int32_t
index
=
0
;
SNode
*
pExpr
;
int32_t
index
=
0
;
FOREACH
(
pExpr
,
pCxt
->
pExprs
)
{
if
(
QUERY_NODE_GROUPING_SET
==
nodeType
(
pExpr
))
{
pExpr
=
nodesListGetNode
(((
SGroupingSetNode
*
)
pExpr
)
->
pParameterList
,
0
);
...
...
@@ -89,6 +106,9 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
}
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pCol
;
if
(
NULL
!=
pCxt
->
pOutputs
)
{
pCxt
->
pOutputs
[
index
]
=
true
;
}
return
DEAL_RES_IGNORE_CHILD
;
}
++
index
;
...
...
@@ -121,7 +141,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
static
int32_t
rewriteExprForSelect
(
SNode
*
pExpr
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
nodesWalkExpr
(
pExpr
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
NULL
};
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
NULL
,
.
pOutputs
=
NULL
};
cxt
.
errCode
=
nodesListMakeAppend
(
&
cxt
.
pExprs
,
pExpr
);
if
(
TSDB_CODE_SUCCESS
==
cxt
.
errCode
)
{
nodesRewriteSelectStmt
(
pSelect
,
clause
,
doRewriteExpr
,
&
cxt
);
...
...
@@ -130,23 +150,50 @@ static int32_t rewriteExprForSelect(SNode* pExpr, SSelectStmt* pSelect, ESqlClau
return
cxt
.
errCode
;
}
static
int32_t
rewriteExprsForSelect
(
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
static
int32_t
cloneRewriteExprs
(
SNodeList
*
pExprs
,
bool
*
pOutputs
,
SNodeList
**
pRewriteExpr
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
index
=
0
;
SNode
*
pExpr
=
NULL
;
FOREACH
(
pExpr
,
pExprs
)
{
if
(
pOutputs
[
index
])
{
code
=
nodesListMakeStrictAppend
(
pRewriteExpr
,
nodesCloneNode
(
pExpr
));
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
NODES_DESTORY_LIST
(
*
pRewriteExpr
);
break
;
}
}
}
return
code
;
}
static
int32_t
rewriteExprsForSelect
(
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
SNodeList
**
pRewriteExpr
)
{
nodesWalkExprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
};
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
};
if
(
NULL
!=
pRewriteExpr
)
{
cxt
.
pOutputs
=
taosMemoryCalloc
(
LIST_LENGTH
(
pExprs
),
sizeof
(
bool
));
if
(
NULL
==
cxt
.
pOutputs
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
nodesRewriteSelectStmt
(
pSelect
,
clause
,
doRewriteExpr
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
==
cxt
.
errCode
&&
NULL
!=
pRewriteExpr
)
{
cxt
.
errCode
=
cloneRewriteExprs
(
pExprs
,
cxt
.
pOutputs
,
pRewriteExpr
);
}
taosMemoryFree
(
cxt
.
pOutputs
);
return
cxt
.
errCode
;
}
static
int32_t
rewriteExpr
(
SNodeList
*
pExprs
,
SNode
**
pTarget
)
{
nodesWalkExprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
};
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
};
nodesRewriteExpr
(
pTarget
,
doRewriteExpr
,
&
cxt
);
return
cxt
.
errCode
;
}
static
int32_t
rewriteExprs
(
SNodeList
*
pExprs
,
SNodeList
*
pTarget
)
{
nodesWalkExprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
};
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
};
nodesRewriteExprs
(
pTarget
,
doRewriteExpr
,
&
cxt
);
return
cxt
.
errCode
;
}
...
...
@@ -311,7 +358,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
// rewrite the expression in subsequent clauses
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pScan
->
pScanPseudoCols
,
pSelect
,
SQL_CLAUSE_FROM
);
code
=
rewriteExprsForSelect
(
pScan
->
pScanPseudoCols
,
pSelect
,
SQL_CLAUSE_FROM
,
NULL
);
}
pScan
->
scanType
=
getScanType
(
pCxt
,
pScan
->
pScanPseudoCols
,
pScan
->
pScanCols
,
pScan
->
tableType
,
pSelect
->
tagScan
);
...
...
@@ -509,7 +556,7 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
// rewrite the expression in subsequent clauses
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pAgg
->
pAggFuncs
)
{
code
=
rewriteExprsForSelect
(
pAgg
->
pAggFuncs
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
code
=
rewriteExprsForSelect
(
pAgg
->
pAggFuncs
,
pSelect
,
SQL_CLAUSE_GROUP_BY
,
NULL
);
}
if
(
NULL
!=
pSelect
->
pGroupByList
)
{
...
...
@@ -524,8 +571,9 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
}
// rewrite the expression in subsequent clauses
SNodeList
*
pOutputGroupKeys
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
code
=
rewriteExprsForSelect
(
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_GROUP_BY
,
&
pOutputGroupKeys
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pSelect
->
pHaving
)
{
...
...
@@ -536,8 +584,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
}
// set the output
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
p
Agg
->
p
GroupKeys
)
{
code
=
createColumnByRewriteExprs
(
p
Agg
->
p
GroupKeys
,
&
pAgg
->
node
.
pTargets
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
p
Output
GroupKeys
)
{
code
=
createColumnByRewriteExprs
(
p
Output
GroupKeys
,
&
pAgg
->
node
.
pTargets
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pAgg
->
pAggFuncs
)
{
code
=
createColumnByRewriteExprs
(
pAgg
->
pAggFuncs
,
&
pAgg
->
node
.
pTargets
);
...
...
@@ -574,7 +622,7 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
// indefinite rows functions and _select_values functions
int32_t
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_SELECT
,
fmIsVectorFunc
,
&
pIdfRowsFunc
->
pFuncs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pIdfRowsFunc
->
pFuncs
,
pSelect
,
SQL_CLAUSE_SELECT
);
code
=
rewriteExprsForSelect
(
pIdfRowsFunc
->
pFuncs
,
pSelect
,
SQL_CLAUSE_SELECT
,
NULL
);
}
// set the output
...
...
@@ -612,7 +660,7 @@ static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p
// interp functions and _group_key functions
int32_t
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_SELECT
,
isInterpFunc
,
&
pInterpFunc
->
pFuncs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pInterpFunc
->
pFuncs
,
pSelect
,
SQL_CLAUSE_SELECT
);
code
=
rewriteExprsForSelect
(
pInterpFunc
->
pFuncs
,
pSelect
,
SQL_CLAUSE_SELECT
,
NULL
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pSelect
->
pFill
)
{
...
...
@@ -656,7 +704,7 @@ static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStm
int32_t
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_WINDOW
,
fmIsWindowClauseFunc
,
&
pWindow
->
pFuncs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pWindow
->
pFuncs
,
pSelect
,
SQL_CLAUSE_WINDOW
);
code
=
rewriteExprsForSelect
(
pWindow
->
pFuncs
,
pSelect
,
SQL_CLAUSE_WINDOW
,
NULL
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -854,10 +902,10 @@ static int32_t createFillLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
int32_t
code
=
partFillExprs
(
pSelect
,
&
pFill
->
pFillExprs
,
&
pFill
->
pNotFillExprs
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pFill
->
pFillExprs
,
pSelect
,
SQL_CLAUSE_FILL
);
code
=
rewriteExprsForSelect
(
pFill
->
pFillExprs
,
pSelect
,
SQL_CLAUSE_FILL
,
NULL
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pFill
->
pNotFillExprs
,
pSelect
,
SQL_CLAUSE_FILL
);
code
=
rewriteExprsForSelect
(
pFill
->
pNotFillExprs
,
pSelect
,
SQL_CLAUSE_FILL
,
NULL
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createColumnByRewriteExprs
(
pFill
->
pFillExprs
,
&
pFill
->
node
.
pTargets
);
...
...
@@ -1066,7 +1114,7 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe
// rewrite the expression in subsequent clauses
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExprsForSelect
(
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_DISTINCT
);
code
=
rewriteExprsForSelect
(
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_DISTINCT
,
NULL
);
}
// set the output
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
cf245fa5
...
...
@@ -1476,19 +1476,33 @@ static bool partTagsHasIndefRowsSelectFunc(SNodeList* pFuncs) {
return
false
;
}
static
int32_t
partTagsRewriteGroupTagsToFuncs
(
SNodeList
*
pGroupTags
,
int32_t
start
,
SNodeList
*
pAggFuncs
)
{
bool
hasIndefRowsSelectFunc
=
partTagsHasIndefRowsSelectFunc
(
pAggFuncs
);
static
bool
partTagsNeedOutput
(
SNode
*
pExpr
,
SNodeList
*
pTargets
)
{
SNode
*
pOutput
=
NULL
;
FOREACH
(
pOutput
,
pTargets
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pExpr
))
{
if
(
nodesEqualNode
(
pExpr
,
pOutput
))
{
return
true
;
}
}
else
if
(
0
==
strcmp
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
((
SColumnNode
*
)
pOutput
)
->
colName
))
{
return
true
;
}
}
return
false
;
}
static
int32_t
partTagsRewriteGroupTagsToFuncs
(
SNodeList
*
pGroupTags
,
int32_t
start
,
SAggLogicNode
*
pAgg
)
{
bool
hasIndefRowsSelectFunc
=
partTagsHasIndefRowsSelectFunc
(
pAgg
->
pAggFuncs
);
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
index
=
0
;
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pGroupTags
)
{
if
(
index
++
<
start
)
{
if
(
index
++
<
start
||
!
partTagsNeedOutput
(
pNode
,
pAgg
->
node
.
pTargets
)
)
{
continue
;
}
if
(
hasIndefRowsSelectFunc
)
{
code
=
nodesListStrictAppend
(
pAggFuncs
,
partTagsCreateWrapperFunc
(
"_select_value"
,
pNode
));
code
=
nodesListStrictAppend
(
pAgg
->
pAgg
Funcs
,
partTagsCreateWrapperFunc
(
"_select_value"
,
pNode
));
}
else
{
code
=
nodesListStrictAppend
(
pAggFuncs
,
partTagsCreateWrapperFunc
(
"_group_key"
,
pNode
));
code
=
nodesListStrictAppend
(
pAgg
->
pAgg
Funcs
,
partTagsCreateWrapperFunc
(
"_group_key"
,
pNode
));
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
...
...
@@ -1541,7 +1555,7 @@ static int32_t partTagsOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSub
}
NODES_DESTORY_LIST
(
pAgg
->
pGroupKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
start
>=
0
)
{
code
=
partTagsRewriteGroupTagsToFuncs
(
pScan
->
pGroupTags
,
start
,
pAgg
->
pAggFuncs
);
code
=
partTagsRewriteGroupTagsToFuncs
(
pScan
->
pGroupTags
,
start
,
pAgg
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录