Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cf35174d
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
cf35174d
编写于
6月 30, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: the last_row function supports all scenes
上级
38ae79e6
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
66 addition
and
4 deletion
+66
-4
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+1
-0
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+13
-0
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+5
-3
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+42
-1
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+2
-0
source/libs/planner/test/planBasicTest.cpp
source/libs/planner/test/planBasicTest.cpp
+2
-0
未找到文件。
include/libs/function/functionMgt.h
浏览文件 @
cf35174d
...
...
@@ -125,6 +125,7 @@ typedef enum EFunctionType {
FUNCTION_TYPE_BLOCK_DIST_INFO
,
// block distribution pseudo column function
FUNCTION_TYPE_TO_COLUMN
,
FUNCTION_TYPE_GROUP_KEY
,
FUNCTION_TYPE_CACHE_LAST_ROW
,
// distributed splitting functions
FUNCTION_TYPE_APERCENTILE_PARTIAL
=
4000
,
...
...
include/libs/nodes/plannodes.h
浏览文件 @
cf35174d
...
...
@@ -91,6 +91,7 @@ typedef struct SAggLogicNode {
SLogicNode
node
;
SNodeList
*
pGroupKeys
;
SNodeList
*
pAggFuncs
;
bool
hasLastRow
;
}
SAggLogicNode
;
typedef
struct
SProjectLogicNode
{
...
...
source/libs/function/src/builtins.c
浏览文件 @
cf35174d
...
...
@@ -1882,6 +1882,19 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
name
=
"last_row"
,
.
type
=
FUNCTION_TYPE_LAST_ROW
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
translateFunc
=
translateFirstLast
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
.
processFunc
=
lastFunction
,
.
finalizeFunc
=
firstLastFinalize
,
.
pPartialFunc
=
"_last_partial"
,
.
pMergeFunc
=
"_last_merge"
,
.
combineFunc
=
lastCombine
,
},
{
.
name
=
"_cache_last_row"
,
.
type
=
FUNCTION_TYPE_CACHE_LAST_ROW
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
translateFunc
=
translateLastRow
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
minmaxFunctionSetup
,
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
cf35174d
...
...
@@ -160,9 +160,9 @@ static EScanType getScanType(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SNod
return
SCAN_TYPE_STREAM
;
}
if
(
pSelect
->
hasLastRowFunc
)
{
return
SCAN_TYPE_LAST_ROW
;
}
//
if (pSelect->hasLastRowFunc) {
//
return SCAN_TYPE_LAST_ROW;
//
}
if
(
NULL
==
pScanCols
)
{
// select count(*) from t
...
...
@@ -474,6 +474,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pAgg
->
hasLastRow
=
pSelect
->
hasLastRowFunc
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
// set grouyp keys, agg funcs and having conditions
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
cf35174d
...
...
@@ -1616,6 +1616,46 @@ static int32_t rewriteUniqueOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog
return
rewriteUniqueOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pIndef
);
}
static
bool
lastRowScanOptMayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_AGG
!=
nodeType
(
pNode
)
||
!
(((
SAggLogicNode
*
)
pNode
)
->
hasLastRow
)
||
NULL
!=
((
SAggLogicNode
*
)
pNode
)
->
pGroupKeys
||
1
!=
LIST_LENGTH
(
pNode
->
pChildren
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pNode
->
pChildren
,
0
))
||
NULL
!=
((
SScanLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
))
->
node
.
pConditions
)
{
return
false
;
}
SNode
*
pFunc
=
NULL
;
FOREACH
(
pFunc
,
((
SAggLogicNode
*
)
pNode
)
->
pAggFuncs
)
{
if
(
FUNCTION_TYPE_LAST_ROW
!=
((
SFunctionNode
*
)
pFunc
)
->
funcType
)
{
return
false
;
}
}
return
true
;
}
static
int32_t
lastRowScanOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SAggLogicNode
*
pAgg
=
(
SAggLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
lastRowScanOptMayBeOptimized
);
if
(
NULL
==
pAgg
)
{
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pAgg
->
pAggFuncs
)
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
pNode
;
int32_t
len
=
snprintf
(
pFunc
->
functionName
,
sizeof
(
pFunc
->
functionName
),
"_cache_last_row"
);
pFunc
->
functionName
[
len
]
=
'\0'
;
fmGetFuncInfo
(
pFunc
,
NULL
,
0
);
}
pAgg
->
hasLastRow
=
false
;
((
SScanLogicNode
*
)
nodesListGetNode
(
pAgg
->
node
.
pChildren
,
0
))
->
scanType
=
SCAN_TYPE_LAST_ROW
;
pCxt
->
optimized
=
true
;
return
TSDB_CODE_SUCCESS
;
}
// merge projects
static
bool
mergeProjectsMayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_PROJECT
!=
nodeType
(
pNode
)
||
1
!=
LIST_LENGTH
(
pNode
->
pChildren
))
{
...
...
@@ -1704,7 +1744,8 @@ static const SOptimizeRule optimizeRuleSet[] = {
{.
pName
=
"EliminateProject"
,
.
optimizeFunc
=
eliminateProjOptimize
},
{.
pName
=
"EliminateSetOperator"
,
.
optimizeFunc
=
eliminateSetOpOptimize
},
{.
pName
=
"RewriteTail"
,
.
optimizeFunc
=
rewriteTailOptimize
},
{.
pName
=
"RewriteUnique"
,
.
optimizeFunc
=
rewriteUniqueOptimize
}
{.
pName
=
"RewriteUnique"
,
.
optimizeFunc
=
rewriteUniqueOptimize
},
{.
pName
=
"LastRowScan"
,
.
optimizeFunc
=
lastRowScanOptimize
}
};
// clang-format on
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
cf35174d
...
...
@@ -197,6 +197,8 @@ static bool stbSplNeedSplit(bool streamQuery, SLogicNode* pNode) {
return
stbSplIsMultiTbScan
(
streamQuery
,
(
SScanLogicNode
*
)
pNode
);
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
return
!
(((
SJoinLogicNode
*
)
pNode
)
->
isSingleTableJoin
);
// case QUERY_NODE_LOGIC_PLAN_PARTITION:
// return stbSplHasMultiTbScan(streamQuery, pNode);
case
QUERY_NODE_LOGIC_PLAN_AGG
:
return
!
stbSplHasGatherExecFunc
(((
SAggLogicNode
*
)
pNode
)
->
pAggFuncs
)
&&
stbSplHasMultiTbScan
(
streamQuery
,
pNode
);
case
QUERY_NODE_LOGIC_PLAN_WINDOW
:
...
...
source/libs/planner/test/planBasicTest.cpp
浏览文件 @
cf35174d
...
...
@@ -99,6 +99,8 @@ TEST_F(PlanBasicTest, lastRowFunc) {
run
(
"SELECT LAST_ROW(c1, c2) FROM t1"
);
run
(
"SELECT LAST_ROW(c1) FROM st1"
);
run
(
"SELECT LAST_ROW(c1), SUM(c3) FROM t1"
);
}
TEST_F
(
PlanBasicTest
,
sampleFunc
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录