Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0db2e65d
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0db2e65d
编写于
3月 17, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
logic plan code reorganize
上级
d49adcd4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
167 addition
and
175 deletion
+167
-175
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+0
-1
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+0
-1
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+1
-5
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+166
-168
未找到文件。
include/libs/nodes/plannodes.h
浏览文件 @
0db2e65d
...
...
@@ -26,7 +26,6 @@ extern "C" {
typedef
struct
SLogicNode
{
ENodeType
type
;
int32_t
id
;
SNodeList
*
pTargets
;
// SColumnNode
SNode
*
pConditions
;
SNodeList
*
pChildren
;
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
0db2e65d
...
...
@@ -190,7 +190,6 @@ static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) {
}
static
SNode
*
logicNodeCopy
(
const
SLogicNode
*
pSrc
,
SLogicNode
*
pDst
)
{
COPY_SCALAR_FIELD
(
id
);
CLONE_NODE_LIST_FIELD
(
pTargets
);
CLONE_NODE_FIELD
(
pConditions
);
CLONE_NODE_LIST_FIELD
(
pChildren
);
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
0db2e65d
...
...
@@ -193,7 +193,6 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
return
code
;
}
static
const
char
*
jkLogicPlanId
=
"Id"
;
static
const
char
*
jkLogicPlanTargets
=
"Targets"
;
static
const
char
*
jkLogicPlanConditions
=
"Conditions"
;
static
const
char
*
jkLogicPlanChildren
=
"Children"
;
...
...
@@ -201,10 +200,7 @@ static const char* jkLogicPlanChildren = "Children";
static
int32_t
logicPlanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SLogicNode
*
pNode
=
(
const
SLogicNode
*
)
pObj
;
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkLogicPlanId
,
pNode
->
id
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkLogicPlanTargets
,
pNode
->
pTargets
);
}
int32_t
code
=
nodeListToJson
(
pJson
,
jkLogicPlanTargets
,
pNode
->
pTargets
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkLogicPlanConditions
,
nodeToJson
,
pNode
->
pConditions
);
}
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
0db2e65d
...
...
@@ -19,10 +19,10 @@
typedef
struct
SLogicPlanContext
{
SPlanContext
*
pPlanCxt
;
int32_t
errCode
;
int32_t
planNodeId
;
}
SLogicPlanContext
;
typedef
int32_t
(
*
FCreateLogicNode
)(
SLogicPlanContext
*
,
SSelectStmt
*
,
SLogicNode
**
);
static
int32_t
doCreateLogicNodeByTable
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
*
pTable
,
SLogicNode
**
pLogicNode
);
static
int32_t
createQueryLogicNode
(
SLogicPlanContext
*
pCxt
,
SNode
*
pStmt
,
SLogicNode
**
pLogicNode
);
...
...
@@ -66,7 +66,6 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
}
typedef
struct
SNameExprCxt
{
int32_t
planNodeId
;
int32_t
rewriteId
;
}
SNameExprCxt
;
...
...
@@ -76,7 +75,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
case
QUERY_NODE_LOGIC_CONDITION
:
case
QUERY_NODE_FUNCTION
:
{
SNameExprCxt
*
pCxt
=
(
SNameExprCxt
*
)
pContext
;
sprintf
(((
SExprNode
*
)
pNode
)
->
aliasName
,
"#expr_%d
_%d"
,
pCxt
->
planNodeId
,
pCxt
->
rewriteId
++
);
sprintf
(((
SExprNode
*
)
pNode
)
->
aliasName
,
"#expr_%d
"
,
pCxt
->
rewriteId
++
);
return
DEAL_RES_IGNORE_CHILD
;
}
default:
...
...
@@ -86,8 +85,9 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
static
int32_t
rewriteExpr
(
int32_t
planNodeId
,
int32_t
rewriteId
,
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
SNameExprCxt
nameCxt
=
{
.
planNodeId
=
planNodeId
,
.
rewriteId
=
rewriteId
};
static
int32_t
rewriteExpr
(
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
static
int32_t
rewriteId
=
1
;
SNameExprCxt
nameCxt
=
{
.
rewriteId
=
rewriteId
};
nodesWalkList
(
pExprs
,
doNameExpr
,
&
nameCxt
);
SRewriteExprCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
};
nodesRewriteSelectStmt
(
pSelect
,
clause
,
doRewriteExpr
,
&
cxt
);
...
...
@@ -111,60 +111,170 @@ static int32_t pushLogicNode(SLogicPlanContext* pCxt, SLogicNode** pOldRoot, SLo
return
TSDB_CODE_SUCCESS
;
}
static
SColumnNode
*
createColumnByExpr
(
SExprNode
*
pExpr
)
{
SColumnNode
*
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
return
NULL
;
static
int32_t
createChildLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
FCreateLogicNode
func
,
SLogicNode
**
pRoot
)
{
SLogicNode
*
pNode
=
NULL
;
int32_t
code
=
func
(
pCxt
,
pSelect
,
&
pNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
pushLogicNode
(
pCxt
,
pRoot
,
pNode
);
}
pCol
->
node
.
resType
=
pExpr
->
resType
;
strcpy
(
pCol
->
colName
,
pExpr
->
aliasName
);
return
pCol
;
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyNode
(
pNode
);
}
return
code
;
}
static
int32_t
create
ColumnByProjections
(
SLogicPlanContext
*
pCxt
,
SNodeList
*
pExprs
,
SNodeList
**
pCols
)
{
S
NodeList
*
pList
=
nodesMakeList
(
);
if
(
NULL
==
p
List
)
{
static
int32_t
create
ScanLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SRealTableNode
*
pRealTable
,
SLogicNode
**
pLogicNode
)
{
S
ScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_SCAN
);
if
(
NULL
==
p
Scan
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
SNode
*
pNode
;
FOREACH
(
pNode
,
pExprs
)
{
if
(
TSDB_CODE_SUCCESS
!=
nodesListAppend
(
pList
,
createColumnByExpr
((
SExprNode
*
)
pNode
)))
{
nodesDestroyList
(
pList
);
return
TSDB_CODE_OUT_OF_MEMORY
;
TSWAP
(
pScan
->
pMeta
,
pRealTable
->
pMeta
,
STableMeta
*
);
TSWAP
(
pScan
->
pVgroupList
,
pRealTable
->
pVgroupList
,
SVgroupsInfo
*
);
pScan
->
scanType
=
SCAN_TYPE_TABLE
;
pScan
->
scanFlag
=
MAIN_SCAN
;
pScan
->
scanRange
=
TSWINDOW_INITIALIZER
;
pScan
->
tableName
.
type
=
TSDB_TABLE_NAME_T
;
pScan
->
tableName
.
acctId
=
pCxt
->
pPlanCxt
->
acctId
;
strcpy
(
pScan
->
tableName
.
dbname
,
pRealTable
->
table
.
dbName
);
strcpy
(
pScan
->
tableName
.
tname
,
pRealTable
->
table
.
tableName
);
// set columns to scan
SNodeList
*
pCols
=
NULL
;
int32_t
code
=
nodesCollectColumns
(
pSelect
,
SQL_CLAUSE_FROM
,
pRealTable
->
table
.
tableAlias
,
&
pCols
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pCols
)
{
pScan
->
pScanCols
=
nodesCloneList
(
pCols
);
if
(
NULL
==
pScan
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
*
pCols
=
pList
;
return
TSDB_CODE_SUCCESS
;
// set output
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pCols
)
{
pScan
->
node
.
pTargets
=
nodesCloneList
(
pCols
);
if
(
NULL
==
pScan
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicNode
=
(
SLogicNode
*
)
pScan
;
}
else
{
nodesDestroyNode
(
pScan
);
}
return
code
;
}
static
int32_t
createProjectLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
SProjectLogicNode
*
pProject
=
(
SProjectLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_PROJECT
);
if
(
NULL
==
pProject
)
{
static
int32_t
createSubqueryLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
STempTableNode
*
pTable
,
SLogicNode
**
pLogicNode
)
{
int32_t
code
=
createQueryLogicNode
(
pCxt
,
pTable
->
pSubquery
,
pLogicNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
SNode
*
pNode
;
FOREACH
(
pNode
,
(
*
pLogicNode
)
->
pTargets
)
{
strcpy
(((
SColumnNode
*
)
pNode
)
->
tableAlias
,
pTable
->
table
.
tableAlias
);
}
}
return
code
;
}
static
int32_t
createJoinLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SJoinTableNode
*
pJoinTable
,
SLogicNode
**
pLogicNode
)
{
SJoinLogicNode
*
pJoin
=
(
SJoinLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_JOIN
);
if
(
NULL
==
pJoin
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pJoin
->
joinType
=
pJoinTable
->
joinType
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
pProject
->
pProjections
=
nodesCloneList
(
pSelect
->
pProjectionList
);
if
(
NULL
==
pProject
->
pProjections
)
{
// set left and right node
pJoin
->
node
.
pChildren
=
nodesMakeList
();
if
(
NULL
==
pJoin
->
node
.
pChildren
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
SLogicNode
*
pLeft
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createColumnByProjections
(
pCxt
,
pSelect
->
pProjectionList
,
&
pProject
->
node
.
pTargets
);
code
=
doCreateLogicNodeByTable
(
pCxt
,
pSelect
,
pJoinTable
->
pLeft
,
&
pLeft
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppend
(
pJoin
->
node
.
pChildren
,
(
SNode
*
)
pLeft
);
}
}
SLogicNode
*
pRight
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicNode
=
(
SLogicNode
*
)
pProject
;
code
=
doCreateLogicNodeByTable
(
pCxt
,
pSelect
,
pJoinTable
->
pRight
,
&
pRight
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppend
(
pJoin
->
node
.
pChildren
,
(
SNode
*
)
pRight
);
}
}
// set on conditions
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pJoinTable
->
pOnCond
)
{
pJoin
->
pOnConditions
=
nodesCloneNode
(
pJoinTable
->
pOnCond
);
if
(
NULL
==
pJoin
->
pOnConditions
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
// set the output
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pJoin
->
node
.
pTargets
=
nodesCloneList
(
pLeft
->
pTargets
);
if
(
NULL
==
pJoin
->
pOnConditions
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppendList
(
pJoin
->
node
.
pTargets
,
nodesCloneList
(
pRight
->
pTargets
));
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicNode
=
(
SLogicNode
*
)
pJoin
;
}
else
{
nodesDestroyNode
(
p
Project
);
nodesDestroyNode
(
p
Join
);
}
return
code
;
}
static
int32_t
doCreateLogicNodeByTable
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
*
pTable
,
SLogicNode
**
pLogicNode
)
{
switch
(
nodeType
(
pTable
))
{
case
QUERY_NODE_REAL_TABLE
:
return
createScanLogicNode
(
pCxt
,
pSelect
,
(
SRealTableNode
*
)
pTable
,
pLogicNode
);
case
QUERY_NODE_TEMP_TABLE
:
return
createSubqueryLogicNode
(
pCxt
,
pSelect
,
(
STempTableNode
*
)
pTable
,
pLogicNode
);
case
QUERY_NODE_JOIN_TABLE
:
return
createJoinLogicNode
(
pCxt
,
pSelect
,
(
SJoinTableNode
*
)
pTable
,
pLogicNode
);
default:
break
;
}
return
TSDB_CODE_FAILED
;
}
static
int32_t
createLogicNodeByTable
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
*
pTable
,
SLogicNode
**
pLogicNode
)
{
SLogicNode
*
pNode
=
NULL
;
int32_t
code
=
doCreateLogicNodeByTable
(
pCxt
,
pSelect
,
pTable
,
&
pNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pNode
->
pConditions
=
nodesCloneNode
(
pSelect
->
pWhere
);
if
(
NULL
!=
pSelect
->
pWhere
&&
NULL
==
pNode
->
pConditions
)
{
nodesDestroyNode
(
pNode
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
*
pLogicNode
=
pNode
;
}
return
code
;
}
static
SColumnNode
*
createColumnByExpr
(
SExprNode
*
pExpr
)
{
SColumnNode
*
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
return
NULL
;
}
pCol
->
node
.
resType
=
pExpr
->
resType
;
strcpy
(
pCol
->
colName
,
pExpr
->
aliasName
);
return
pCol
;
}
typedef
struct
SCreateColumnCxt
{
int32_t
errCode
;
SNodeList
*
pList
;
...
...
@@ -246,10 +356,10 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
// rewrite the expression in subsequent clauses
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExpr
(
pAgg
->
node
.
id
,
1
,
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
code
=
rewriteExpr
(
pAgg
->
pGroupKeys
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExpr
(
pAgg
->
node
.
id
,
1
+
LIST_LENGTH
(
pAgg
->
pGroupKeys
),
pAgg
->
pAggFuncs
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
code
=
rewriteExpr
(
pAgg
->
pAggFuncs
,
pSelect
,
SQL_CLAUSE_GROUP_BY
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pSelect
->
pHaving
)
{
...
...
@@ -303,7 +413,7 @@ static int32_t createWindowLogicNodeByInterval(SLogicPlanContext* pCxt, SInterva
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteExpr
(
pWindow
->
node
.
id
,
1
,
pWindow
->
pFuncs
,
pSelect
,
SQL_CLAUSE_WINDOW
);
code
=
rewriteExpr
(
pWindow
->
pFuncs
,
pSelect
,
SQL_CLAUSE_WINDOW
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -334,159 +444,47 @@ static int32_t createWindowLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele
return
TSDB_CODE_FAILED
;
}
static
int32_t
create
JoinLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SJoinTableNode
*
pJoinTable
,
SLogicNode
**
pLogicNode
)
{
S
JoinLogicNode
*
pJoin
=
(
SJoinLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_JOIN
);
if
(
NULL
==
p
Join
)
{
static
int32_t
create
ColumnByProjections
(
SLogicPlanContext
*
pCxt
,
SNodeList
*
pExprs
,
SNodeList
**
pCols
)
{
S
NodeList
*
pList
=
nodesMakeList
(
);
if
(
NULL
==
p
List
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pJoin
->
joinType
=
pJoinTable
->
joinType
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
// set left and right node
pJoin
->
node
.
pChildren
=
nodesMakeList
();
if
(
NULL
==
pJoin
->
node
.
pChildren
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
SLogicNode
*
pLeft
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
doCreateLogicNodeByTable
(
pCxt
,
pSelect
,
pJoinTable
->
pLeft
,
&
pLeft
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppend
(
pJoin
->
node
.
pChildren
,
(
SNode
*
)
pLeft
);
}
}
SLogicNode
*
pRight
=
NULL
;
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
doCreateLogicNodeByTable
(
pCxt
,
pSelect
,
pJoinTable
->
pRight
,
&
pRight
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppend
(
pJoin
->
node
.
pChildren
,
(
SNode
*
)
pRight
);
}
}
// set on conditions
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pJoinTable
->
pOnCond
)
{
pJoin
->
pOnConditions
=
nodesCloneNode
(
pJoinTable
->
pOnCond
);
if
(
NULL
==
pJoin
->
pOnConditions
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
// set the output
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pJoin
->
node
.
pTargets
=
nodesCloneList
(
pLeft
->
pTargets
);
if
(
NULL
==
pJoin
->
pOnConditions
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListStrictAppendList
(
pJoin
->
node
.
pTargets
,
nodesCloneList
(
pRight
->
pTargets
));
SNode
*
pNode
;
FOREACH
(
pNode
,
pExprs
)
{
if
(
TSDB_CODE_SUCCESS
!=
nodesListAppend
(
pList
,
createColumnByExpr
((
SExprNode
*
)
pNode
)))
{
nodesDestroyList
(
pList
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicNode
=
(
SLogicNode
*
)
pJoin
;
}
else
{
nodesDestroyNode
(
pJoin
);
}
return
code
;
}
static
int32_t
createSubqueryLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
STempTableNode
*
pTable
,
SLogicNode
**
pLogicNode
)
{
int32_t
code
=
createQueryLogicNode
(
pCxt
,
pTable
->
pSubquery
,
pLogicNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
SNode
*
pNode
;
FOREACH
(
pNode
,
(
*
pLogicNode
)
->
pTargets
)
{
strcpy
(((
SColumnNode
*
)
pNode
)
->
tableAlias
,
pTable
->
table
.
tableAlias
);
}
}
return
code
;
*
pCols
=
pList
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
create
ScanLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SRealTableNode
*
pRealTable
,
SLogicNode
**
pLogicNode
)
{
S
ScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_SCAN
);
if
(
NULL
==
p
Scan
)
{
static
int32_t
create
ProjectLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SLogicNode
**
pLogicNode
)
{
S
ProjectLogicNode
*
pProject
=
(
SProjectLogicNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_PROJECT
);
if
(
NULL
==
p
Project
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
TSWAP
(
pScan
->
pMeta
,
pRealTable
->
pMeta
,
STableMeta
*
);
TSWAP
(
pScan
->
pVgroupList
,
pRealTable
->
pVgroupList
,
SVgroupsInfo
*
);
pScan
->
scanType
=
SCAN_TYPE_TABLE
;
pScan
->
scanFlag
=
MAIN_SCAN
;
pScan
->
scanRange
=
TSWINDOW_INITIALIZER
;
pScan
->
tableName
.
type
=
TSDB_TABLE_NAME_T
;
pScan
->
tableName
.
acctId
=
pCxt
->
pPlanCxt
->
acctId
;
strcpy
(
pScan
->
tableName
.
dbname
,
pRealTable
->
table
.
dbName
);
strcpy
(
pScan
->
tableName
.
tname
,
pRealTable
->
table
.
tableName
);
// set columns to scan
SNodeList
*
pCols
=
NULL
;
int32_t
code
=
nodesCollectColumns
(
pSelect
,
SQL_CLAUSE_FROM
,
pRealTable
->
table
.
tableAlias
,
&
pCols
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pCols
)
{
pScan
->
pScanCols
=
nodesCloneList
(
pCols
);
if
(
NULL
==
pScan
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
// set output
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pCols
)
{
pScan
->
node
.
pTargets
=
nodesCloneList
(
pCols
);
if
(
NULL
==
pScan
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
pProject
->
pProjections
=
nodesCloneList
(
pSelect
->
pProjectionList
);
if
(
NULL
==
pProject
->
pProjections
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicNode
=
(
SLogicNode
*
)
pScan
;
}
else
{
nodesDestroyNode
(
pScan
);
}
return
code
;
}
static
int32_t
doCreateLogicNodeByTable
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
*
pTable
,
SLogicNode
**
pLogicNode
)
{
switch
(
nodeType
(
pTable
))
{
case
QUERY_NODE_REAL_TABLE
:
return
createScanLogicNode
(
pCxt
,
pSelect
,
(
SRealTableNode
*
)
pTable
,
pLogicNode
);
case
QUERY_NODE_TEMP_TABLE
:
return
createSubqueryLogicNode
(
pCxt
,
pSelect
,
(
STempTableNode
*
)
pTable
,
pLogicNode
);
case
QUERY_NODE_JOIN_TABLE
:
return
createJoinLogicNode
(
pCxt
,
pSelect
,
(
SJoinTableNode
*
)
pTable
,
pLogicNode
);
default:
break
;
code
=
createColumnByProjections
(
pCxt
,
pSelect
->
pProjectionList
,
&
pProject
->
node
.
pTargets
);
}
return
TSDB_CODE_FAILED
;
}
static
int32_t
createLogicNodeByTable
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
SNode
*
pTable
,
SLogicNode
**
pLogicNode
)
{
SLogicNode
*
pNode
=
NULL
;
int32_t
code
=
doCreateLogicNodeByTable
(
pCxt
,
pSelect
,
pTable
,
&
pNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pNode
->
pConditions
=
nodesCloneNode
(
pSelect
->
pWhere
);
if
(
NULL
!=
pSelect
->
pWhere
&&
NULL
==
pNode
->
pConditions
)
{
nodesDestroyNode
(
pNode
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
*
pLogicNode
=
pNode
;
*
pLogicNode
=
(
SLogicNode
*
)
pProject
;
}
else
{
nodesDestroyNode
(
pProject
);
}
return
code
;
}
typedef
int32_t
(
*
FCreateLogicNode
)(
SLogicPlanContext
*
,
SSelectStmt
*
,
SLogicNode
**
);
static
int32_t
createChildLogicNode
(
SLogicPlanContext
*
pCxt
,
SSelectStmt
*
pSelect
,
FCreateLogicNode
func
,
SLogicNode
**
pRoot
)
{
SLogicNode
*
pNode
=
NULL
;
int32_t
code
=
func
(
pCxt
,
pSelect
,
&
pNode
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
pushLogicNode
(
pCxt
,
pRoot
,
pNode
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
nodesDestroyNode
(
pNode
);
}
return
code
;
}
...
...
@@ -540,7 +538,7 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi
}
int32_t
createLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
**
pLogicNode
)
{
SLogicPlanContext
cxt
=
{
.
pPlanCxt
=
pCxt
,
.
errCode
=
TSDB_CODE_SUCCESS
,
.
planNodeId
=
1
};
SLogicPlanContext
cxt
=
{
.
pPlanCxt
=
pCxt
};
int32_t
code
=
createQueryLogicNode
(
&
cxt
,
pCxt
->
pAstRoot
,
pLogicNode
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录