Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
7f78d4a7
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看板
提交
7f78d4a7
编写于
6月 15, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: partition by tags optimize
上级
b7b64fda
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
105 addition
and
47 deletion
+105
-47
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+6
-0
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+2
-1
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+28
-30
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+2
-1
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+15
-6
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+49
-8
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+3
-1
未找到文件。
include/libs/nodes/nodes.h
浏览文件 @
7f78d4a7
...
...
@@ -65,6 +65,12 @@ extern "C" {
(list) = NULL; \
} while (0)
#define NODES_CLEAR_LIST(list) \
do { \
nodesClearList((list)); \
(list) = NULL; \
} while (0)
typedef
enum
ENodeType
{
// Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN,
// VALUE, OPERATOR, FUNCTION and so on.
...
...
include/libs/nodes/plannodes.h
浏览文件 @
7f78d4a7
...
...
@@ -69,6 +69,7 @@ typedef struct SScanLogicNode {
int16_t
tsColId
;
double
filesFactor
;
SArray
*
pSmaIndexes
;
SNodeList
*
pPartTags
;
}
SScanLogicNode
;
typedef
struct
SJoinLogicNode
{
...
...
@@ -257,7 +258,7 @@ typedef struct STableScanPhysiNode {
double
ratio
;
int32_t
dataRequired
;
SNodeList
*
pDynamicScanFuncs
;
SNodeList
*
pPartition
Key
s
;
SNodeList
*
pPartition
Tag
s
;
int64_t
interval
;
int64_t
offset
;
int64_t
sliding
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
7f78d4a7
...
...
@@ -2909,7 +2909,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo*
size_t
numOfSources
=
LIST_LENGTH
(
pExNode
->
pSrcEndPoints
);
if
(
numOfSources
==
0
)
{
qError
(
"%s invalid number: %d of sources in exchange operator"
,
id
,
(
int32_t
)
numOfSources
);
qError
(
"%s invalid number: %d of sources in exchange operator"
,
id
,
(
int32_t
)
numOfSources
);
return
TSDB_CODE_INVALID_PARA
;
}
...
...
@@ -4591,8 +4591,8 @@ int32_t extractTableSchemaVersion(SReadHandle* pHandle, uint64_t uid, SExecTaskI
return
TSDB_CODE_SUCCESS
;
}
int32_t
generateGroupIdMap
(
STableListInfo
*
pTableListInfo
,
SReadHandle
*
pHandle
,
SArray
*
groupKey
){
if
(
groupKey
==
NULL
)
{
int32_t
generateGroupIdMap
(
STableListInfo
*
pTableListInfo
,
SReadHandle
*
pHandle
,
SArray
*
groupKey
)
{
if
(
groupKey
==
NULL
)
{
return
TDB_CODE_SUCCESS
;
}
...
...
@@ -4601,11 +4601,11 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
return
TSDB_CODE_OUT_OF_MEMORY
;
}
int32_t
keyLen
=
0
;
void
*
keyBuf
=
NULL
;
void
*
keyBuf
=
NULL
;
int32_t
numOfGroupCols
=
taosArrayGetSize
(
groupKey
);
for
(
int32_t
j
=
0
;
j
<
numOfGroupCols
;
++
j
)
{
SColumn
*
pCol
=
taosArrayGet
(
groupKey
,
j
);
keyLen
+=
pCol
->
bytes
;
// actual data + null_flag
keyLen
+=
pCol
->
bytes
;
// actual data + null_flag
}
int32_t
nullFlagSize
=
sizeof
(
int8_t
)
*
numOfGroupCols
;
...
...
@@ -4616,9 +4616,9 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
return
TSDB_CODE_OUT_OF_MEMORY
;
}
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pTableListInfo
->
pTableList
);
i
++
)
{
STableKeyInfo
*
info
=
taosArrayGet
(
pTableListInfo
->
pTableList
,
i
);
SMetaReader
mr
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pTableListInfo
->
pTableList
);
i
++
)
{
STableKeyInfo
*
info
=
taosArrayGet
(
pTableListInfo
->
pTableList
,
i
);
SMetaReader
mr
=
{
0
};
metaReaderInit
(
&
mr
,
pHandle
->
meta
,
0
);
metaGetTableEntryByUid
(
&
mr
,
info
->
uid
);
...
...
@@ -4627,23 +4627,23 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
for
(
int32_t
j
=
0
;
j
<
numOfGroupCols
;
++
j
)
{
SColumn
*
pCol
=
taosArrayGet
(
groupKey
,
j
);
if
(
strcmp
(
pCol
->
name
,
"tbname"
)
==
0
)
{
if
(
strcmp
(
pCol
->
name
,
"tbname"
)
==
0
)
{
isNull
[
i
]
=
0
;
memcpy
(
pStart
,
mr
.
me
.
name
,
strlen
(
mr
.
me
.
name
));
pStart
+=
strlen
(
mr
.
me
.
name
);
}
else
{
}
else
{
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pCol
->
type
,
&
tagVal
);
if
(
p
==
NULL
)
{
if
(
p
==
NULL
)
{
isNull
[
j
]
=
1
;
continue
;
}
isNull
[
i
]
=
0
;
if
(
pCol
->
type
==
TSDB_DATA_TYPE_JSON
)
{
// int32_t dataLen = getJsonValueLen(pkey->pData);
// memcpy(pStart, (pkey->pData), dataLen);
// pStart += dataLen;
// int32_t dataLen = getJsonValueLen(pkey->pData);
// memcpy(pStart, (pkey->pData), dataLen);
// pStart += dataLen;
}
else
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
memcpy
(
pStart
,
tagVal
.
pData
,
tagVal
.
nData
);
pStart
+=
tagVal
.
nData
;
...
...
@@ -4655,7 +4655,7 @@ int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle,
}
}
int32_t
len
=
(
int32_t
)
(
pStart
-
(
char
*
)
keyBuf
);
int32_t
len
=
(
int32_t
)
(
pStart
-
(
char
*
)
keyBuf
);
uint64_t
*
groupId
=
taosHashGet
(
pTableListInfo
->
map
,
keyBuf
,
len
);
if
(
groupId
)
{
taosHashPut
(
pTableListInfo
->
map
,
&
(
info
->
uid
),
sizeof
(
uint64_t
),
groupId
,
sizeof
(
uint64_t
));
...
...
@@ -4690,16 +4690,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
return
NULL
;
}
SArray
*
groupKeys
=
extractPartitionColInfo
(
pTableScanNode
->
pPartition
Key
s
);
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
groupKeys
);
//
todo for json
SArray
*
groupKeys
=
extractPartitionColInfo
(
pTableScanNode
->
pPartition
Tag
s
);
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
groupKeys
);
//
todo for json
taosArrayDestroy
(
groupKeys
);
if
(
code
){
if
(
code
)
{
tsdbCleanupReadHandle
(
pDataReader
);
return
NULL
;
}
SOperatorInfo
*
pOperator
=
createTableScanOperatorInfo
(
pTableScanNode
,
pDataReader
,
pHandle
,
pTaskInfo
);
SOperatorInfo
*
pOperator
=
createTableScanOperatorInfo
(
pTableScanNode
,
pDataReader
,
pHandle
,
pTaskInfo
);
STableScanInfo
*
pScanInfo
=
pOperator
->
info
;
pTaskInfo
->
cost
.
pRecoder
=
&
pScanInfo
->
readRecorder
;
...
...
@@ -4726,16 +4725,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
qDebug
(
"%s pDataReader is not NULL"
,
GET_TASKID
(
pTaskInfo
));
}
SArray
*
groupKeys
=
extractPartitionColInfo
(
pTableScanNode
->
pPartition
Key
s
);
int32_t
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
groupKeys
);
//
todo for json
SArray
*
groupKeys
=
extractPartitionColInfo
(
pTableScanNode
->
pPartition
Tag
s
);
int32_t
code
=
generateGroupIdMap
(
pTableListInfo
,
pHandle
,
groupKeys
);
//
todo for json
taosArrayDestroy
(
groupKeys
);
if
(
code
){
if
(
code
)
{
tsdbCleanupReadHandle
(
pDataReader
);
return
NULL
;
}
SOperatorInfo
*
pOperator
=
createStreamScanOperatorInfo
(
pDataReader
,
pHandle
,
pTableScanNode
,
pTaskInfo
,
&
twSup
);
SOperatorInfo
*
pOperator
=
createStreamScanOperatorInfo
(
pDataReader
,
pHandle
,
pTableScanNode
,
pTaskInfo
,
&
twSup
);
return
pOperator
;
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN
==
type
)
{
...
...
@@ -4744,7 +4742,8 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN
==
type
)
{
STagScanPhysiNode
*
pScanPhyNode
=
(
STagScanPhysiNode
*
)
pPhyNode
;
int32_t
code
=
getTableList
(
pHandle
->
meta
,
pScanPhyNode
->
tableType
,
pScanPhyNode
->
uid
,
pTableListInfo
,
pScanPhyNode
->
node
.
pConditions
);
int32_t
code
=
getTableList
(
pHandle
->
meta
,
pScanPhyNode
->
tableType
,
pScanPhyNode
->
uid
,
pTableListInfo
,
pScanPhyNode
->
node
.
pConditions
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
NULL
;
}
...
...
@@ -4821,7 +4820,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
createIntervalOperatorInfo
(
ops
[
0
],
pExprInfo
,
num
,
pResBlock
,
&
interval
,
tsSlotId
,
&
as
,
pTaskInfo
,
isStream
);
}
else
if
(
QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL
==
type
)
{
SMergeIntervalPhysiNode
*
pIntervalPhyNode
=
(
SMergeIntervalPhysiNode
*
)
pPhyNode
;
SMergeIntervalPhysiNode
*
pIntervalPhyNode
=
(
SMergeIntervalPhysiNode
*
)
pPhyNode
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pIntervalPhyNode
->
window
.
pFuncs
,
NULL
,
&
num
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPhyNode
->
pOutputDataBlockDesc
);
...
...
@@ -5061,7 +5060,7 @@ SArray* extractColumnInfo(SNodeList* pNodeList) {
}
SArray
*
extractPartitionColInfo
(
SNodeList
*
pNodeList
)
{
if
(
!
pNodeList
)
return
NULL
;
if
(
!
pNodeList
)
return
NULL
;
size_t
numOfCols
=
LIST_LENGTH
(
pNodeList
);
SArray
*
pList
=
taosArrayInit
(
numOfCols
,
sizeof
(
SColumn
));
if
(
pList
==
NULL
)
{
...
...
@@ -5166,7 +5165,7 @@ int32_t getTableList(void* metaHandle, int32_t tableType, uint64_t tableUid, STa
SArray
*
res
=
taosArrayInit
(
8
,
sizeof
(
uint64_t
));
code
=
doFilterTag
(
pTagCond
,
&
metaArg
,
res
);
if
(
code
==
TSDB_CODE_INDEX_REBUILDING
)
{
// todo
if
(
code
==
TSDB_CODE_INDEX_REBUILDING
)
{
// todo
// doFilter();
}
else
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
qError
(
"failed to get tableIds, reason: %s, suid: %"
PRIu64
""
,
tstrerror
(
code
),
tableUid
);
...
...
@@ -5524,4 +5523,3 @@ int32_t initStreamAggSupporter(SStreamAggSupporter* pSup, const char* pKey, SqlF
}
return
code
;
}
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
7f78d4a7
...
...
@@ -355,6 +355,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
COPY_SCALAR_FIELD
(
watermark
);
COPY_SCALAR_FIELD
(
tsColId
);
COPY_SCALAR_FIELD
(
filesFactor
);
CLONE_NODE_LIST_FIELD
(
pPartTags
);
return
(
SNode
*
)
pDst
;
}
...
...
@@ -495,7 +496,7 @@ static SNode* physiTableScanCopy(const STableScanPhysiNode* pSrc, STableScanPhys
COPY_SCALAR_FIELD
(
ratio
);
COPY_SCALAR_FIELD
(
dataRequired
);
CLONE_NODE_LIST_FIELD
(
pDynamicScanFuncs
);
CLONE_NODE_LIST_FIELD
(
pPartition
Key
s
);
CLONE_NODE_LIST_FIELD
(
pPartition
Tag
s
);
COPY_SCALAR_FIELD
(
interval
);
COPY_SCALAR_FIELD
(
offset
);
COPY_SCALAR_FIELD
(
sliding
);
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
7f78d4a7
...
...
@@ -515,6 +515,7 @@ static const char* jkScanLogicPlanScanPseudoCols = "ScanPseudoCols";
static
const
char
*
jkScanLogicPlanTableId
=
"TableId"
;
static
const
char
*
jkScanLogicPlanTableType
=
"TableType"
;
static
const
char
*
jkScanLogicPlanTagCond
=
"TagCond"
;
static
const
char
*
jkScanLogicPlanPartTags
=
"PartTags"
;
static
int32_t
logicScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SScanLogicNode
*
pNode
=
(
const
SScanLogicNode
*
)
pObj
;
...
...
@@ -535,6 +536,9 @@ static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkScanLogicPlanTagCond
,
nodeToJson
,
pNode
->
pTagCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkScanLogicPlanPartTags
,
pNode
->
pPartTags
);
}
return
code
;
}
...
...
@@ -559,6 +563,9 @@ static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkScanLogicPlanTagCond
,
&
pNode
->
pTagCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkScanLogicPlanPartTags
,
&
pNode
->
pPartTags
);
}
return
code
;
}
...
...
@@ -1368,6 +1375,7 @@ static const char* jkTableScanPhysiPlanTriggerType = "triggerType";
static
const
char
*
jkTableScanPhysiPlanWatermark
=
"watermark"
;
static
const
char
*
jkTableScanPhysiPlanTsColId
=
"tsColId"
;
static
const
char
*
jkTableScanPhysiPlanFilesFactor
=
"FilesFactor"
;
static
const
char
*
jkTableScanPhysiPlanPartitionTags
=
"PartitionTags"
;
static
int32_t
physiTableScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
STableScanPhysiNode
*
pNode
=
(
const
STableScanPhysiNode
*
)
pObj
;
...
...
@@ -1421,6 +1429,9 @@ static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddDoubleToObject
(
pJson
,
jkTableScanPhysiPlanFilesFactor
,
pNode
->
filesFactor
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkTableScanPhysiPlanPartitionTags
,
pNode
->
pPartitionTags
);
}
return
code
;
}
...
...
@@ -1446,30 +1457,24 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanDataRequired
,
pNode
->
dataRequired
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkTableScanPhysiPlanDynamicScanFuncs
,
&
pNode
->
pDynamicScanFuncs
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanInterval
,
pNode
->
interval
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanOffset
,
pNode
->
offset
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanSliding
,
pNode
->
sliding
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanIntervalUnit
,
pNode
->
intervalUnit
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanSlidingUnit
,
pNode
->
slidingUnit
,
code
);
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
tjsonGetNumberValue
(
pJson
,
jkTableScanPhysiPlanTriggerType
,
pNode
->
triggerType
,
code
);
...
...
@@ -1483,6 +1488,10 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetDoubleValue
(
pJson
,
jkTableScanPhysiPlanFilesFactor
,
&
pNode
->
filesFactor
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkTableScanPhysiPlanPartitionTags
,
&
pNode
->
pPartitionTags
);
}
return
code
;
}
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
7f78d4a7
...
...
@@ -109,9 +109,8 @@ static bool osdMayBeOptimized(SLogicNode* pNode) {
return
false
;
}
if
(
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pNode
->
pParent
)
||
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pNode
->
pParent
)
&&
pNode
->
pParent
->
pParent
&&
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pNode
->
pParent
->
pParent
))
)
{
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pNode
->
pParent
)
&&
pNode
->
pParent
->
pParent
&&
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pNode
->
pParent
->
pParent
)))
{
return
true
;
}
return
!
osdHaveNormalCol
(((
SAggLogicNode
*
)
pNode
->
pParent
)
->
pGroupKeys
);
...
...
@@ -222,9 +221,8 @@ static int32_t osdGetDataRequired(SNodeList* pFuncs) {
static
void
setScanWindowInfo
(
SScanLogicNode
*
pScan
)
{
SLogicNode
*
pParent
=
pScan
->
node
.
pParent
;
if
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pParent
)
&&
pParent
->
pParent
&&
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pParent
->
pParent
))
{
if
(
QUERY_NODE_LOGIC_PLAN_PARTITION
==
nodeType
(
pParent
)
&&
pParent
->
pParent
&&
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pParent
->
pParent
))
{
pParent
=
pParent
->
pParent
;
}
if
(
QUERY_NODE_LOGIC_PLAN_WINDOW
==
nodeType
(
pParent
))
{
...
...
@@ -1041,12 +1039,55 @@ static int32_t smaOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLogicSubplan)
return
smaOptimizeImpl
(
pCxt
,
pLogicSubplan
,
pScan
);
}
static
EDealRes
partTagsOptHasColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
COLUMN_TYPE_TAG
!=
((
SColumnNode
*
)
pNode
)
->
colType
)
{
*
(
bool
*
)
pContext
=
true
;
return
DEAL_RES_END
;
}
}
return
DEAL_RES_CONTINUE
;
}
static
bool
partTagsOptHasCol
(
SNodeList
*
pPartKeys
)
{
bool
hasCol
=
false
;
nodesWalkExprs
(
pPartKeys
,
partTagsOptHasColImpl
,
&
hasCol
);
return
hasCol
;
}
static
bool
partTagsOptMayBeOptimized
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_PARTITION
!=
nodeType
(
pNode
)
||
1
!=
LIST_LENGTH
(
pNode
->
pChildren
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pNode
->
pChildren
,
0
)))
{
return
false
;
}
return
!
partTagsOptHasCol
(((
SPartitionLogicNode
*
)
pNode
)
->
pPartitionKeys
);
}
static
int32_t
partTagsOptimize
(
SOptimizeContext
*
pCxt
,
SLogicSubplan
*
pLogicSubplan
)
{
SPartitionLogicNode
*
pPart
=
(
SPartitionLogicNode
*
)
optFindPossibleNode
(
pLogicSubplan
->
pNode
,
partTagsOptMayBeOptimized
);
if
(
NULL
==
pPart
)
{
return
TSDB_CODE_SUCCESS
;
}
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
nodesListGetNode
(
pPart
->
node
.
pChildren
,
0
);
TSWAP
(
pPart
->
pPartitionKeys
,
pScan
->
pPartTags
);
int32_t
code
=
replaceLogicNode
(
pLogicSubplan
,
(
SLogicNode
*
)
pPart
,
(
SLogicNode
*
)
pScan
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
NODES_CLEAR_LIST
(
pPart
->
node
.
pChildren
);
nodesDestroyNode
((
SNode
*
)
pPart
);
}
return
code
;
}
// clang-format off
static
const
SOptimizeRule
optimizeRuleSet
[]
=
{
{.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
},
{.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
},
{.
pName
=
"ConditionPushDown"
,
.
optimizeFunc
=
cpdOptimize
},
{.
pName
=
"OrderByPrimaryKey"
,
.
optimizeFunc
=
opkOptimize
},
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
smaOptimize
}
{.
pName
=
"SmaIndex"
,
.
optimizeFunc
=
smaOptimize
},
{.
pName
=
"PartitionByTags"
,
.
optimizeFunc
=
partTagsOptimize
}
};
// clang-format on
...
...
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
7f78d4a7
...
...
@@ -500,7 +500,9 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
tNameGetFullDbName
(
&
pScanLogicNode
->
tableName
,
pSubplan
->
dbFName
);
pTableScan
->
dataRequired
=
pScanLogicNode
->
dataRequired
;
pTableScan
->
pDynamicScanFuncs
=
nodesCloneList
(
pScanLogicNode
->
pDynamicScanFuncs
);
if
(
NULL
!=
pScanLogicNode
->
pDynamicScanFuncs
&&
NULL
==
pTableScan
->
pDynamicScanFuncs
)
{
pTableScan
->
pPartitionTags
=
nodesCloneList
(
pScanLogicNode
->
pPartTags
);
if
((
NULL
!=
pScanLogicNode
->
pDynamicScanFuncs
&&
NULL
==
pTableScan
->
pDynamicScanFuncs
)
||
(
NULL
!=
pScanLogicNode
->
pPartTags
&&
NULL
==
pTableScan
->
pPartitionTags
))
{
nodesDestroyNode
((
SNode
*
)
pTableScan
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录