Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7cf9919a
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,发现更多精彩内容 >>
未验证
提交
7cf9919a
编写于
4月 19, 2023
作者:
X
Xiaoyu Wang
提交者:
GitHub
4月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20964 from taosdata/enh/3.0_planner_optimize
feat: last queries with tags output can be read from cache
上级
95b78f32
586b3945
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
37 addition
and
37 deletion
+37
-37
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
+6
-9
source/libs/executor/src/cachescanoperator.c
source/libs/executor/src/cachescanoperator.c
+16
-16
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+15
-12
未找到文件。
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
浏览文件 @
7cf9919a
...
...
@@ -362,15 +362,6 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
p
->
ts
=
pCol
->
ts
;
p
->
colVal
=
pCol
->
colVal
;
singleTableLastTs
=
pCol
->
ts
;
// only set value for last row query
if
(
HASTYPE
(
pr
->
type
,
CACHESCAN_RETRIEVE_LAST_ROW
))
{
if
(
taosArrayGetSize
(
pTableUidList
)
==
0
)
{
taosArrayPush
(
pTableUidList
,
&
pKeyInfo
->
uid
);
}
else
{
taosArraySet
(
pTableUidList
,
0
,
&
pKeyInfo
->
uid
);
}
}
}
}
else
{
SLastCol
*
p
=
taosArrayGet
(
pLastCols
,
slotId
);
...
...
@@ -417,6 +408,12 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
}
}
if
(
taosArrayGetSize
(
pTableUidList
)
==
0
)
{
taosArrayPush
(
pTableUidList
,
&
pKeyInfo
->
uid
);
}
else
{
taosArraySet
(
pTableUidList
,
0
,
&
pKeyInfo
->
uid
);
}
tsdbCacheRelease
(
lruCache
,
h
);
}
...
...
source/libs/executor/src/cachescanoperator.c
浏览文件 @
7cf9919a
...
...
@@ -45,13 +45,13 @@ static void destroyCacheScanOperator(void* param);
static
int32_t
extractCacheScanSlotId
(
const
SArray
*
pColMatchInfo
,
SExecTaskInfo
*
pTaskInfo
,
int32_t
**
pSlotIds
);
static
int32_t
removeRedundantTsCol
(
SLastRowScanPhysiNode
*
pScanNode
,
SColMatchInfo
*
pColMatchInfo
);
#define SCAN_ROW_TYPE(_t)
((_t)
? CACHESCAN_RETRIEVE_LAST : CACHESCAN_RETRIEVE_LAST_ROW)
#define SCAN_ROW_TYPE(_t)
((_t)
? CACHESCAN_RETRIEVE_LAST : CACHESCAN_RETRIEVE_LAST_ROW)
SOperatorInfo
*
createCacherowsScanOperator
(
SLastRowScanPhysiNode
*
pScanNode
,
SReadHandle
*
readHandle
,
STableListInfo
*
pTableListInfo
,
SExecTaskInfo
*
pTaskInfo
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
SCacheRowsScanInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SCacheRowsScanInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
tableListDestroy
(
pTableListInfo
);
...
...
@@ -91,7 +91,8 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
uint64_t
suid
=
tableListGetSuid
(
pTableListInfo
);
code
=
tsdbCacherowsReaderOpen
(
pInfo
->
readHandle
.
vnode
,
pInfo
->
retrieveType
,
pList
,
totalTables
,
taosArrayGetSize
(
pInfo
->
matchInfo
.
pList
),
suid
,
&
pInfo
->
pLastrowReader
,
pTaskInfo
->
id
.
str
);
taosArrayGetSize
(
pInfo
->
matchInfo
.
pList
),
suid
,
&
pInfo
->
pLastrowReader
,
pTaskInfo
->
id
.
str
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
...
...
@@ -114,7 +115,8 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
p
->
pCtx
=
createSqlFunctionCtx
(
p
->
pExprInfo
,
p
->
numOfExprs
,
&
p
->
rowEntryInfoOffset
);
}
setOperatorInfo
(
pOperator
,
"CachedRowScanOperator"
,
QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN
,
false
,
OP_NOT_OPENED
,
pInfo
,
pTaskInfo
);
setOperatorInfo
(
pOperator
,
"CachedRowScanOperator"
,
QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN
,
false
,
OP_NOT_OPENED
,
pInfo
,
pTaskInfo
);
pOperator
->
exprSupp
.
numOfExprs
=
taosArrayGetSize
(
pInfo
->
pRes
->
pDataBlock
);
pOperator
->
fpSet
=
...
...
@@ -123,7 +125,7 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe
pOperator
->
cost
.
openCost
=
0
;
return
pOperator
;
_error:
_error:
pTaskInfo
->
code
=
code
;
destroyCacheScanOperator
(
pInfo
);
taosMemoryFree
(
pOperator
);
...
...
@@ -136,8 +138,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
}
SCacheRowsScanInfo
*
pInfo
=
pOperator
->
info
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
STableListInfo
*
pTableList
=
pInfo
->
pTableList
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
STableListInfo
*
pTableList
=
pInfo
->
pTableList
;
uint64_t
suid
=
tableListGetSuid
(
pTableList
);
int32_t
size
=
tableListGetSize
(
pTableList
);
...
...
@@ -194,8 +196,8 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
pRes
->
info
.
rows
=
1
;
SExprSupp
*
pSup
=
&
pInfo
->
pseudoExprSup
;
int32_t
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pRes
,
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
),
NULL
);
int32_t
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pRes
,
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
),
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pTaskInfo
->
code
=
code
;
return
NULL
;
...
...
@@ -217,7 +219,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
}
STableKeyInfo
*
pList
=
NULL
;
int32_t
num
=
0
;
int32_t
num
=
0
;
int32_t
code
=
tableListGetGroupList
(
pTableList
,
pInfo
->
currentGroupIndex
,
&
pList
,
&
num
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -251,11 +253,9 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) {
pInfo
->
pRes
->
info
.
id
.
groupId
=
pKeyInfo
->
groupId
;
if
(
taosArrayGetSize
(
pInfo
->
pUidList
)
>
0
)
{
ASSERT
((
pInfo
->
retrieveType
&
CACHESCAN_RETRIEVE_LAST_ROW
)
==
CACHESCAN_RETRIEVE_LAST_ROW
);
pInfo
->
pRes
->
info
.
id
.
uid
=
*
(
tb_uid_t
*
)
taosArrayGet
(
pInfo
->
pUidList
,
0
);
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
),
NULL
);
code
=
addTagPseudoColumnData
(
&
pInfo
->
readHandle
,
pSup
->
pExprInfo
,
pSup
->
numOfExprs
,
pInfo
->
pRes
,
pInfo
->
pRes
->
info
.
rows
,
GET_TASKID
(
pTaskInfo
),
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pTaskInfo
->
code
=
code
;
return
NULL
;
...
...
@@ -325,7 +325,7 @@ int32_t removeRedundantTsCol(SLastRowScanPhysiNode* pScanNode, SColMatchInfo* pC
return
TSDB_CODE_SUCCESS
;
}
size_t
size
=
taosArrayGetSize
(
pColMatchInfo
->
pList
);
size_t
size
=
taosArrayGetSize
(
pColMatchInfo
->
pList
);
SArray
*
pMatchInfo
=
taosArrayInit
(
size
,
sizeof
(
SColMatchItem
));
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
7cf9919a
...
...
@@ -1095,7 +1095,7 @@ static int32_t sortPriKeyOptGetSequencingNodesImpl(SLogicNode* pNode, bool group
*
pNotOptimize
=
false
;
return
TSDB_CODE_SUCCESS
;
}
switch
(
nodeType
(
pNode
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
{
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
pNode
;
...
...
@@ -2139,7 +2139,7 @@ typedef struct SLastRowScanOptLastParaCkCxt {
bool
hasCol
;
}
SLastRowScanOptLastParaCkCxt
;
static
EDealRes
lastRowScanOptLastPara
Check
Impl
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
lastRowScanOptLastPara
IsTag
Impl
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
SLastRowScanOptLastParaCkCxt
*
pCxt
=
pContext
;
if
(
COLUMN_TYPE_TAG
==
((
SColumnNode
*
)
pNode
)
->
colType
||
COLUMN_TYPE_TBNAME
==
((
SColumnNode
*
)
pNode
)
->
colType
)
{
...
...
@@ -2152,10 +2152,10 @@ static EDealRes lastRowScanOptLastParaCheckImpl(SNode* pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
static
bool
lastRowScanOptLastPara
Check
(
SNode
*
pExpr
)
{
static
bool
lastRowScanOptLastPara
IsTag
(
SNode
*
pExpr
)
{
SLastRowScanOptLastParaCkCxt
cxt
=
{.
hasTag
=
false
,
.
hasCol
=
false
};
nodesWalkExpr
(
pExpr
,
lastRowScanOptLastPara
Check
Impl
,
&
cxt
);
return
!
cxt
.
hasTag
&&
cxt
.
hasCol
;
nodesWalkExpr
(
pExpr
,
lastRowScanOptLastPara
IsTag
Impl
,
&
cxt
);
return
cxt
.
hasTag
&&
!
cxt
.
hasCol
;
}
static
bool
hasSuitableCache
(
int8_t
cacheLastMode
,
bool
hasLastRow
,
bool
hasLast
)
{
...
...
@@ -2195,15 +2195,19 @@ static bool lastRowScanOptMayBeOptimized(SLogicNode* pNode) {
FOREACH
(
pFunc
,
((
SAggLogicNode
*
)
pNode
)
->
pAggFuncs
)
{
SFunctionNode
*
pAggFunc
=
(
SFunctionNode
*
)
pFunc
;
if
(
FUNCTION_TYPE_LAST
==
pAggFunc
->
funcType
)
{
if
(
hasSelectFunc
||
!
lastRowScanOptLastParaCheck
(
nodesListGetNode
(
pAggFunc
->
pParameterList
,
0
)))
{
if
(
hasSelectFunc
||
QUERY_NODE_VALUE
==
nodeType
(
nodesListGetNode
(
pAggFunc
->
pParameterList
,
0
)))
{
return
false
;
}
hasLastFunc
=
true
;
}
else
if
(
FUNCTION_TYPE_SELECT_VALUE
==
pAggFunc
->
funcType
||
FUNCTION_TYPE_GROUP_KEY
==
pAggFunc
->
funcType
)
{
}
else
if
(
FUNCTION_TYPE_SELECT_VALUE
==
pAggFunc
->
funcType
)
{
if
(
hasLastFunc
)
{
return
false
;
}
hasSelectFunc
=
true
;
}
else
if
(
FUNCTION_TYPE_GROUP_KEY
==
pAggFunc
->
funcType
)
{
if
(
!
lastRowScanOptLastParaIsTag
(
nodesListGetNode
(
pAggFunc
->
pParameterList
,
0
)))
{
return
false
;
}
}
else
if
(
FUNCTION_TYPE_LAST_ROW
!=
pAggFunc
->
funcType
)
{
return
false
;
}
...
...
@@ -2237,7 +2241,7 @@ static EDealRes lastRowScanOptSetColDataType(SNode* pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
static
void
lastRowScanOptSetLastTargets
(
SNodeList
*
pTargets
,
SNodeList
*
pLastCols
)
{
static
void
lastRowScanOptSetLastTargets
(
SNodeList
*
pTargets
,
SNodeList
*
pLastCols
,
bool
erase
)
{
SNode
*
pTarget
=
NULL
;
WHERE_EACH
(
pTarget
,
pTargets
)
{
bool
found
=
false
;
...
...
@@ -2249,7 +2253,7 @@ static void lastRowScanOptSetLastTargets(SNodeList* pTargets, SNodeList* pLastCo
break
;
}
}
if
(
!
found
)
{
if
(
!
found
&&
erase
)
{
ERASE_NODE
(
pTargets
);
continue
;
}
...
...
@@ -2290,9 +2294,8 @@ static int32_t lastRowScanOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogic
pScan
->
igLastNull
=
pAgg
->
hasLast
?
true
:
false
;
if
(
NULL
!=
cxt
.
pLastCols
)
{
cxt
.
doAgg
=
false
;
lastRowScanOptSetLastTargets
(
pScan
->
pScanCols
,
cxt
.
pLastCols
);
NODES_DESTORY_LIST
(
pScan
->
pScanPseudoCols
);
lastRowScanOptSetLastTargets
(
pScan
->
node
.
pTargets
,
cxt
.
pLastCols
);
lastRowScanOptSetLastTargets
(
pScan
->
pScanCols
,
cxt
.
pLastCols
,
true
);
lastRowScanOptSetLastTargets
(
pScan
->
node
.
pTargets
,
cxt
.
pLastCols
,
false
);
nodesClearList
(
cxt
.
pLastCols
);
}
pAgg
->
hasLastRow
=
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录