Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
99563fc1
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1181
Star
22014
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,发现更多精彩内容 >>
未验证
提交
99563fc1
编写于
6月 30, 2022
作者:
X
Xiaoyu Wang
提交者:
GitHub
6月 30, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14376 from taosdata/feature/3.0_debug_wxy
feat: the last_row function supports all scenes
上级
903649e7
2ad65998
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
81 addition
and
10 deletion
+81
-10
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
-7
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+42
-1
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+1
-1
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+16
-1
source/libs/planner/test/planBasicTest.cpp
source/libs/planner/test/planBasicTest.cpp
+2
-0
未找到文件。
include/libs/function/functionMgt.h
浏览文件 @
99563fc1
...
...
@@ -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
浏览文件 @
99563fc1
...
...
@@ -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
浏览文件 @
99563fc1
...
...
@@ -1938,6 +1938,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
浏览文件 @
99563fc1
...
...
@@ -154,16 +154,12 @@ static int32_t createSelectRootLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p
return
createRootLogicNode
(
pCxt
,
pSelect
,
pSelect
->
precision
,
(
FCreateLogicNode
)
func
,
pRoot
);
}
static
EScanType
getScanType
(
SLogicPlanContext
*
pCxt
,
S
SelectStmt
*
pSelect
,
SNodeList
*
pScanPseudo
Cols
,
SNodeList
*
pScanCols
,
int8_t
tableType
)
{
static
EScanType
getScanType
(
SLogicPlanContext
*
pCxt
,
S
NodeList
*
pScanPseudoCols
,
SNodeList
*
pScan
Cols
,
int8_t
tableType
)
{
if
(
pCxt
->
pPlanCxt
->
topicQuery
||
pCxt
->
pPlanCxt
->
streamQuery
)
{
return
SCAN_TYPE_STREAM
;
}
if
(
pSelect
->
hasLastRowFunc
)
{
return
SCAN_TYPE_LAST_ROW
;
}
if
(
NULL
==
pScanCols
)
{
// select count(*) from t
return
NULL
==
pScanPseudoCols
...
...
@@ -279,7 +275,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
code
=
rewriteExprsForSelect
(
pScan
->
pScanPseudoCols
,
pSelect
,
SQL_CLAUSE_FROM
);
}
pScan
->
scanType
=
getScanType
(
pCxt
,
pS
elect
,
pS
can
->
pScanPseudoCols
,
pScan
->
pScanCols
,
pScan
->
tableType
);
pScan
->
scanType
=
getScanType
(
pCxt
,
pScan
->
pScanPseudoCols
,
pScan
->
pScanCols
,
pScan
->
tableType
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
addPrimaryKeyCol
(
pScan
->
tableId
,
&
pScan
->
pScanCols
);
...
...
@@ -474,6 +470,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
浏览文件 @
99563fc1
...
...
@@ -1622,6 +1622,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
))
{
...
...
@@ -1710,7 +1750,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/planPhysiCreater.c
浏览文件 @
99563fc1
...
...
@@ -1344,7 +1344,7 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SMergeLogicNode* pM
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pMergeLogicNode
->
pMergeKeys
)
{
code
=
setListSlotId
(
pCxt
,
pMerge
->
node
.
pOutputDataBlockDesc
->
dataBlockId
,
-
1
,
pMergeLogicNode
->
pMergeKeys
,
&
pMerge
->
pMergeKeys
);
}
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
99563fc1
...
...
@@ -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
:
...
...
@@ -431,7 +433,7 @@ static int32_t stbSplSplitIntervalForBatch(SSplitContext* pCxt, SStableSplitInfo
SNodeList
*
pMergeKeys
=
NULL
;
code
=
stbSplCreateMergeKeysByPrimaryKey
(((
SWindowLogicNode
*
)
pInfo
->
pSplitNode
)
->
pTspk
,
&
pMergeKeys
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
stbSplCreateMergeNode
(
pCxt
,
NULL
,
pInfo
->
pSplitNode
,
pMergeKeys
,
pPartWindow
,
fals
e
);
code
=
stbSplCreateMergeNode
(
pCxt
,
NULL
,
pInfo
->
pSplitNode
,
pMergeKeys
,
pPartWindow
,
tru
e
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyList
(
pMergeKeys
);
...
...
@@ -887,6 +889,16 @@ static int32_t stbSplSplitJoinNode(SSplitContext* pCxt, SStableSplitInfo* pInfo)
return
code
;
}
static
int32_t
stbSplSplitPartitionNode
(
SSplitContext
*
pCxt
,
SStableSplitInfo
*
pInfo
)
{
int32_t
code
=
stbSplCreateMergeNode
(
pCxt
,
pInfo
->
pSubplan
,
pInfo
->
pSplitNode
,
NULL
,
pInfo
->
pSplitNode
,
true
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListMakeStrictAppend
(
&
pInfo
->
pSubplan
->
pChildren
,
(
SNode
*
)
splCreateScanSubplan
(
pCxt
,
pInfo
->
pSplitNode
,
SPLIT_FLAG_STABLE_SPLIT
));
}
++
(
pCxt
->
groupId
);
return
code
;
}
static
int32_t
stableSplit
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
)
{
if
(
pCxt
->
pPlanCxt
->
rSmaQuery
)
{
return
TSDB_CODE_SUCCESS
;
...
...
@@ -905,6 +917,9 @@ static int32_t stableSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
code
=
stbSplSplitJoinNode
(
pCxt
,
&
info
);
break
;
case
QUERY_NODE_LOGIC_PLAN_PARTITION
:
code
=
stbSplSplitPartitionNode
(
pCxt
,
&
info
);
break
;
case
QUERY_NODE_LOGIC_PLAN_AGG
:
code
=
stbSplSplitAggNode
(
pCxt
,
&
info
);
break
;
...
...
source/libs/planner/test/planBasicTest.cpp
浏览文件 @
99563fc1
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录