Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d8762d40
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看板
提交
d8762d40
编写于
4月 12, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): child table or normal table support JOIN-clause
上级
ec643cee
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
2378 addition
and
2682 deletion
+2378
-2682
include/common/ttokendef.h
include/common/ttokendef.h
+83
-82
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+11
-13
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+10
-0
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+4
-3
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+1
-1
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+7
-7
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+38
-2
source/libs/parser/src/sql.c
source/libs/parser/src/sql.c
+2113
-2516
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+73
-1
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+11
-44
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+1
-0
source/libs/planner/test/plannerTest.cpp
source/libs/planner/test/plannerTest.cpp
+26
-13
未找到文件。
include/common/ttokendef.h
浏览文件 @
d8762d40
...
...
@@ -140,88 +140,89 @@
#define TK_APPS 122
#define TK_CONNECTIONS 123
#define TK_LICENCE 124
#define TK_QUERIES 125
#define TK_SCORES 126
#define TK_TOPICS 127
#define TK_VARIABLES 128
#define TK_BNODES 129
#define TK_SNODES 130
#define TK_LIKE 131
#define TK_INDEX 132
#define TK_FULLTEXT 133
#define TK_FUNCTION 134
#define TK_INTERVAL 135
#define TK_TOPIC 136
#define TK_AS 137
#define TK_DESC 138
#define TK_DESCRIBE 139
#define TK_RESET 140
#define TK_QUERY 141
#define TK_EXPLAIN 142
#define TK_ANALYZE 143
#define TK_VERBOSE 144
#define TK_NK_BOOL 145
#define TK_RATIO 146
#define TK_COMPACT 147
#define TK_VNODES 148
#define TK_IN 149
#define TK_OUTPUTTYPE 150
#define TK_AGGREGATE 151
#define TK_BUFSIZE 152
#define TK_STREAM 153
#define TK_INTO 154
#define TK_KILL 155
#define TK_CONNECTION 156
#define TK_MERGE 157
#define TK_VGROUP 158
#define TK_REDISTRIBUTE 159
#define TK_SPLIT 160
#define TK_SYNCDB 161
#define TK_NULL 162
#define TK_FIRST 163
#define TK_LAST 164
#define TK_NOW 165
#define TK_ROWTS 166
#define TK_TBNAME 167
#define TK_QSTARTTS 168
#define TK_QENDTS 169
#define TK_WSTARTTS 170
#define TK_WENDTS 171
#define TK_WDURATION 172
#define TK_BETWEEN 173
#define TK_IS 174
#define TK_NK_LT 175
#define TK_NK_GT 176
#define TK_NK_LE 177
#define TK_NK_GE 178
#define TK_NK_NE 179
#define TK_MATCH 180
#define TK_NMATCH 181
#define TK_JOIN 182
#define TK_INNER 183
#define TK_SELECT 184
#define TK_DISTINCT 185
#define TK_WHERE 186
#define TK_PARTITION 187
#define TK_BY 188
#define TK_SESSION 189
#define TK_STATE_WINDOW 190
#define TK_SLIDING 191
#define TK_FILL 192
#define TK_VALUE 193
#define TK_NONE 194
#define TK_PREV 195
#define TK_LINEAR 196
#define TK_NEXT 197
#define TK_GROUP 198
#define TK_HAVING 199
#define TK_ORDER 200
#define TK_SLIMIT 201
#define TK_SOFFSET 202
#define TK_LIMIT 203
#define TK_OFFSET 204
#define TK_ASC 205
#define TK_NULLS 206
#define TK_GRANTS 125
#define TK_QUERIES 126
#define TK_SCORES 127
#define TK_TOPICS 128
#define TK_VARIABLES 129
#define TK_BNODES 130
#define TK_SNODES 131
#define TK_LIKE 132
#define TK_INDEX 133
#define TK_FULLTEXT 134
#define TK_FUNCTION 135
#define TK_INTERVAL 136
#define TK_TOPIC 137
#define TK_AS 138
#define TK_DESC 139
#define TK_DESCRIBE 140
#define TK_RESET 141
#define TK_QUERY 142
#define TK_EXPLAIN 143
#define TK_ANALYZE 144
#define TK_VERBOSE 145
#define TK_NK_BOOL 146
#define TK_RATIO 147
#define TK_COMPACT 148
#define TK_VNODES 149
#define TK_IN 150
#define TK_OUTPUTTYPE 151
#define TK_AGGREGATE 152
#define TK_BUFSIZE 153
#define TK_STREAM 154
#define TK_INTO 155
#define TK_KILL 156
#define TK_CONNECTION 157
#define TK_MERGE 158
#define TK_VGROUP 159
#define TK_REDISTRIBUTE 160
#define TK_SPLIT 161
#define TK_SYNCDB 162
#define TK_NULL 163
#define TK_FIRST 164
#define TK_LAST 165
#define TK_NOW 166
#define TK_ROWTS 167
#define TK_TBNAME 168
#define TK_QSTARTTS 169
#define TK_QENDTS 170
#define TK_WSTARTTS 171
#define TK_WENDTS 172
#define TK_WDURATION 173
#define TK_BETWEEN 174
#define TK_IS 175
#define TK_NK_LT 176
#define TK_NK_GT 177
#define TK_NK_LE 178
#define TK_NK_GE 179
#define TK_NK_NE 180
#define TK_MATCH 181
#define TK_NMATCH 182
#define TK_JOIN 183
#define TK_INNER 184
#define TK_SELECT 185
#define TK_DISTINCT 186
#define TK_WHERE 187
#define TK_PARTITION 188
#define TK_BY 189
#define TK_SESSION 190
#define TK_STATE_WINDOW 191
#define TK_SLIDING 192
#define TK_FILL 193
#define TK_VALUE 194
#define TK_NONE 195
#define TK_PREV 196
#define TK_LINEAR 197
#define TK_NEXT 198
#define TK_GROUP 199
#define TK_HAVING 200
#define TK_ORDER 201
#define TK_SLIMIT 202
#define TK_SOFFSET 203
#define TK_LIMIT 204
#define TK_OFFSET 205
#define TK_ASC 206
#define TK_NULLS 207
#define TK_NK_SPACE 300
#define TK_NK_COMMENT 301
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
d8762d40
...
...
@@ -95,7 +95,6 @@ static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) {
static
void
exprNodeCopy
(
const
SExprNode
*
pSrc
,
SExprNode
*
pDst
)
{
dataTypeCopy
(
&
pSrc
->
resType
,
&
pDst
->
resType
);
COPY_CHAR_ARRAY_FIELD
(
aliasName
);
// CLONE_NODE_LIST_FIELD(pAssociationList);
}
static
SNode
*
columnNodeCopy
(
const
SColumnNode
*
pSrc
,
SColumnNode
*
pDst
)
{
...
...
@@ -222,15 +221,19 @@ static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) {
}
static
SNode
*
logicScanCopy
(
const
SScanLogicNode
*
pSrc
,
SScanLogicNode
*
pDst
)
{
COPY_ALL_SCALAR_FIELDS
;
COPY_BASE_OBJECT_FIELD
(
node
,
logicNodeCopy
);
CLONE_NODE_LIST_FIELD
(
pScanCols
);
CLONE_OBJECT_FIELD
(
pMeta
,
tableMetaClone
);
CLONE_OBJECT_FIELD
(
pVgroupList
,
vgroupsInfoClone
);
COPY_SCALAR_FIELD
(
scanType
);
COPY_SCALAR_FIELD
(
scanFlag
);
COPY_SCALAR_FIELD
(
scanRange
);
COPY_SCALAR_FIELD
(
tableName
);
COPY_SCALAR_FIELD
(
showRewrite
);
CLONE_NODE_LIST_FIELD
(
pDynamicScanFuncs
);
return
(
SNode
*
)
pDst
;
}
static
SNode
*
logicJoinCopy
(
const
SJoinLogicNode
*
pSrc
,
SJoinLogicNode
*
pDst
)
{
COPY_ALL_SCALAR_FIELDS
;
COPY_BASE_OBJECT_FIELD
(
node
,
logicNodeCopy
);
CLONE_NODE_FIELD
(
pOnConditions
);
return
(
SNode
*
)
pDst
;
}
...
...
@@ -263,15 +266,8 @@ static SNode* logicExchangeCopy(const SExchangeLogicNode* pSrc, SExchangeLogicNo
static
SNode
*
logicWindowCopy
(
const
SWindowLogicNode
*
pSrc
,
SWindowLogicNode
*
pDst
)
{
COPY_ALL_SCALAR_FIELDS
;
COPY_BASE_OBJECT_FIELD
(
node
,
logicNodeCopy
);
// COPY_SCALAR_FIELD(winType);
CLONE_NODE_LIST_FIELD
(
pFuncs
);
// COPY_SCALAR_FIELD(interval);
// COPY_SCALAR_FIELD(offset);
// COPY_SCALAR_FIELD(sliding);
// COPY_SCALAR_FIELD(intervalUnit);
// COPY_SCALAR_FIELD(slidingUnit);
CLONE_NODE_FIELD
(
pFill
);
// COPY_SCALAR_FIELD(sessionGap);
CLONE_NODE_FIELD
(
pTspk
);
return
(
SNode
*
)
pDst
;
}
...
...
@@ -360,6 +356,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
return
downstreamSourceCopy
((
const
SDownstreamSourceNode
*
)
pNode
,
(
SDownstreamSourceNode
*
)
pDst
);
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
return
logicScanCopy
((
const
SScanLogicNode
*
)
pNode
,
(
SScanLogicNode
*
)
pDst
);
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
return
logicJoinCopy
((
const
SJoinLogicNode
*
)
pNode
,
(
SJoinLogicNode
*
)
pDst
);
case
QUERY_NODE_LOGIC_PLAN_AGG
:
return
logicAggCopy
((
const
SAggLogicNode
*
)
pNode
,
(
SAggLogicNode
*
)
pDst
);
case
QUERY_NODE_LOGIC_PLAN_PROJECT
:
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
d8762d40
...
...
@@ -158,6 +158,16 @@ SNodeptr nodesMakeNode(ENodeType type) {
case
QUERY_NODE_SHOW_FUNCTIONS_STMT
:
case
QUERY_NODE_SHOW_INDEXES_STMT
:
case
QUERY_NODE_SHOW_STREAMS_STMT
:
case
QUERY_NODE_SHOW_APPS_STMT
:
case
QUERY_NODE_SHOW_CONNECTIONS_STMT
:
case
QUERY_NODE_SHOW_LICENCE_STMT
:
case
QUERY_NODE_SHOW_CREATE_DATABASE_STMT
:
case
QUERY_NODE_SHOW_CREATE_TABLE_STMT
:
case
QUERY_NODE_SHOW_CREATE_STABLE_STMT
:
case
QUERY_NODE_SHOW_QUERIES_STMT
:
case
QUERY_NODE_SHOW_SCORES_STMT
:
case
QUERY_NODE_SHOW_TOPICS_STMT
:
case
QUERY_NODE_SHOW_VARIABLE_STMT
:
case
QUERY_NODE_SHOW_BNODES_STMT
:
case
QUERY_NODE_SHOW_SNODES_STMT
:
return
makeNode
(
type
,
sizeof
(
SShowStmt
));
...
...
source/libs/parser/inc/sql.y
浏览文件 @
d8762d40
...
...
@@ -79,13 +79,13 @@ alter_account_option ::= USERS literal.
alter_account_option ::= CONNS literal. { }
alter_account_option ::= STATE literal. { }
/************************************************ create/alter/drop
/show user
*****************************************/
/************************************************ create/alter/drop
user *****
*****************************************/
cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createCreateUserStmt(pCxt, &A, &B); }
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B); }
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B); }
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
/************************************************ create/drop/alter
/show dnode
****************************************/
/************************************************ create/drop/alter
dnode *****
****************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); }
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); }
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); }
...
...
@@ -124,7 +124,7 @@ cmd ::= DROP SNODE ON DNODE NK_INTEGER(A).
cmd ::= CREATE MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &A); }
cmd ::= DROP MNODE ON DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &A); }
/************************************************ create/drop/
show/use database
***************************************/
/************************************************ create/drop/
use database *****
***************************************/
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C); }
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A); }
...
...
@@ -332,6 +332,7 @@ cmd ::= SHOW ACCOUNTS.
cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); }
cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); }
cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); }
cmd ::= SHOW GRANTS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); }
cmd ::= SHOW CREATE DATABASE db_name(A). { pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &A); }
cmd ::= SHOW CREATE TABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, A); }
cmd ::= SHOW CREATE STABLE full_table_name(A). { pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, A); }
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
d8762d40
...
...
@@ -143,7 +143,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
pCxt
->
code
=
rewriteConditionForFromTable
(
pCxt
,
pJoin
->
pRight
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
&&
NULL
!=
pJoin
->
pOnCond
)
{
pCxt
->
code
=
rewriteCondition
(
pCxt
,
&
pJoin
->
pOnCond
);
}
}
...
...
source/libs/parser/src/parTokenizer.c
浏览文件 @
d8762d40
...
...
@@ -80,6 +80,7 @@ static SKeyword keywordTable[] = {
{
"FSYNC"
,
TK_FSYNC
},
{
"FUNCTION"
,
TK_FUNCTION
},
{
"FUNCTIONS"
,
TK_FUNCTIONS
},
{
"GRANTS"
,
TK_GRANTS
},
{
"GROUP"
,
TK_GROUP
},
{
"HAVING"
,
TK_HAVING
},
{
"IF"
,
TK_IF
},
...
...
@@ -131,10 +132,10 @@ static SKeyword keywordTable[] = {
{
"PRECISION"
,
TK_PRECISION
},
{
"PRIVILEGE"
,
TK_PRIVILEGE
},
{
"PREV"
,
TK_PREV
},
{
"_QENDTS"
,
TK_QENDTS
},
{
"_QENDTS"
,
TK_QENDTS
},
{
"QNODE"
,
TK_QNODE
},
{
"QNODES"
,
TK_QNODES
},
{
"_QSTARTTS"
,
TK_QSTARTTS
},
{
"_QSTARTTS"
,
TK_QSTARTTS
},
{
"QTIME"
,
TK_QTIME
},
{
"QUERIES"
,
TK_QUERIES
},
{
"QUERY"
,
TK_QUERY
},
...
...
@@ -144,7 +145,7 @@ static SKeyword keywordTable[] = {
{
"RESET"
,
TK_RESET
},
{
"RETENTIONS"
,
TK_RETENTIONS
},
{
"ROLLUP"
,
TK_ROLLUP
},
{
"_ROWTS"
,
TK_ROWTS
},
{
"_ROWTS"
,
TK_ROWTS
},
{
"SCORES"
,
TK_SCORES
},
{
"SELECT"
,
TK_SELECT
},
{
"SESSION"
,
TK_SESSION
},
...
...
@@ -163,7 +164,7 @@ static SKeyword keywordTable[] = {
{
"STATE"
,
TK_STATE
},
{
"STATE_WINDOW"
,
TK_STATE_WINDOW
},
{
"STORAGE"
,
TK_STORAGE
},
{
"STREAM"
,
TK_STREAM
},
{
"STREAM"
,
TK_STREAM
},
{
"STREAMS"
,
TK_STREAMS
},
{
"STREAM_MODE"
,
TK_STREAM_MODE
},
{
"SYNCDB"
,
TK_SYNCDB
},
...
...
@@ -192,8 +193,8 @@ static SKeyword keywordTable[] = {
{
"VGROUPS"
,
TK_VGROUPS
},
{
"VNODES"
,
TK_VNODES
},
{
"WAL"
,
TK_WAL
},
{
"_WDURATION"
,
TK_WDURATION
},
{
"_WENDTS"
,
TK_WENDTS
},
{
"_WDURATION"
,
TK_WDURATION
},
{
"_WENDTS"
,
TK_WENDTS
},
{
"WHERE"
,
TK_WHERE
},
{
"_WSTARTTS"
,
TK_WSTARTTS
},
// {"ID", TK_ID},
...
...
@@ -221,7 +222,6 @@ static SKeyword keywordTable[] = {
// {"UMINUS", TK_UMINUS},
// {"UPLUS", TK_UPLUS},
// {"BITNOT", TK_BITNOT},
// {"GRANTS", TK_GRANTS},
// {"DOT", TK_DOT},
// {"CTIME", TK_CTIME},
// {"LP", TK_LP},
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
d8762d40
...
...
@@ -762,7 +762,7 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) {
size_t
nums
=
taosArrayGetSize
(
pTables
);
for
(
size_t
i
=
0
;
i
<
nums
;
++
i
)
{
STableNode
*
pTable
=
taosArrayGetP
(
pTables
,
i
);
int32_t
code
=
createColumnNodeByTable
(
pCxt
,
pTable
,
*
pCols
);
int32_t
code
=
createColumnNodeByTable
(
pCxt
,
pTable
,
*
pCols
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
...
...
@@ -829,11 +829,39 @@ static int32_t createFirstLastAllCols(STranslateContext* pCxt, SFunctionNode* pS
return
TSDB_CODE_SUCCESS
;
}
static
bool
isTableStar
(
SNode
*
pNode
)
{
return
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
&&
(
0
==
strcmp
(((
SColumnNode
*
)
pNode
)
->
colName
,
"*"
));
}
static
int32_t
createTableAllCols
(
STranslateContext
*
pCxt
,
SColumnNode
*
pCol
,
SNodeList
**
pOutput
)
{
*
pOutput
=
nodesMakeList
();
if
(
NULL
==
*
pOutput
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_OUT_OF_MEMORY
);
}
bool
foundTable
=
false
;
SArray
*
pTables
=
taosArrayGetP
(
pCxt
->
pNsLevel
,
pCxt
->
currLevel
);
size_t
nums
=
taosArrayGetSize
(
pTables
);
for
(
size_t
i
=
0
;
i
<
nums
;
++
i
)
{
STableNode
*
pTable
=
taosArrayGetP
(
pTables
,
i
);
if
(
0
==
strcmp
(
pTable
->
tableAlias
,
pCol
->
tableAlias
))
{
int32_t
code
=
createColumnNodeByTable
(
pCxt
,
pTable
,
*
pOutput
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
foundTable
=
true
;
break
;
}
}
if
(
!
foundTable
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
pCol
->
tableAlias
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
translateStar
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
if
(
NULL
==
pSelect
->
pProjectionList
)
{
// select * ...
return
createAllColumns
(
pCxt
,
&
pSelect
->
pProjectionList
);
}
else
{
// todo : t.*
SNode
*
pNode
=
NULL
;
WHERE_EACH
(
pNode
,
pSelect
->
pProjectionList
)
{
if
(
isFirstLastStar
(
pNode
))
{
...
...
@@ -844,6 +872,14 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
INSERT_LIST
(
pSelect
->
pProjectionList
,
pFuncs
);
ERASE_NODE
(
pSelect
->
pProjectionList
);
continue
;
}
else
if
(
isTableStar
(
pNode
))
{
SNodeList
*
pCols
=
NULL
;
if
(
TSDB_CODE_SUCCESS
!=
createTableAllCols
(
pCxt
,
(
SColumnNode
*
)
pNode
,
&
pCols
))
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
INSERT_LIST
(
pSelect
->
pProjectionList
,
pCols
);
ERASE_NODE
(
pSelect
->
pProjectionList
);
continue
;
}
WHERE_NEXT
;
}
...
...
source/libs/parser/src/sql.c
浏览文件 @
d8762d40
此差异已折叠。
点击以展开。
source/libs/planner/src/planOptimizer.c
浏览文件 @
d8762d40
...
...
@@ -147,8 +147,80 @@ static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) {
return
code
;
}
static
int32_t
cpdOptimizeScanCondition
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPartitionCondition
(
SJoinLogicNode
*
pJoin
,
SNodeList
**
pMultiTableCond
,
SNodeList
**
pSingleTableCond
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushJoinCondToOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNodeList
*
pMultiTableCond
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushJoinCondToChildren
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNodeList
*
pSingleTableCond
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushJoinCondition
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
NULL
!=
pJoin
->
node
.
pConditions
)
{
SNodeList
*
pMultiTableCond
=
NULL
;
SNodeList
*
pSingleTableCond
=
NULL
;
int32_t
code
=
cpdPartitionCondition
(
pJoin
,
&
pMultiTableCond
,
&
pSingleTableCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pMultiTableCond
)
{
code
=
cpdPushJoinCondToOnCond
(
pCxt
,
pJoin
,
pMultiTableCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pSingleTableCond
)
{
code
=
cpdPushJoinCondToChildren
(
pCxt
,
pJoin
,
pSingleTableCond
);
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushAggCondition
(
SOptimizeContext
*
pCxt
,
SAggLogicNode
*
pAgg
)
{
// todo
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdPushCondition
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
switch
(
nodeType
(
pLogicNode
))
{
case
QUERY_NODE_LOGIC_PLAN_SCAN
:
code
=
cpdOptimizeScanCondition
(
pCxt
,
(
SScanLogicNode
*
)
pLogicNode
);
break
;
case
QUERY_NODE_LOGIC_PLAN_JOIN
:
code
=
cpdPushJoinCondition
(
pCxt
,
(
SJoinLogicNode
*
)
pLogicNode
);
break
;
case
QUERY_NODE_LOGIC_PLAN_AGG
:
code
=
cpdPushAggCondition
(
pCxt
,
(
SAggLogicNode
*
)
pLogicNode
);
break
;
default:
break
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
SNode
*
pChild
=
NULL
;
FOREACH
(
pChild
,
pLogicNode
->
pChildren
)
{
code
=
cpdPushCondition
(
pCxt
,
(
SLogicNode
*
)
pChild
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
}
}
return
code
;
}
static
int32_t
cpdOptimize
(
SOptimizeContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
return
cpdPushCondition
(
pCxt
,
pLogicNode
);
}
static
const
SOptimizeRule
optimizeRuleSet
[]
=
{
{
.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
}
{
.
pName
=
"OptimizeScanData"
,
.
optimizeFunc
=
osdOptimize
},
{
.
pName
=
"ConditionPushDown"
,
.
optimizeFunc
=
cpdOptimize
}
};
static
const
int32_t
optimizeRuleNum
=
(
sizeof
(
optimizeRuleSet
)
/
sizeof
(
SOptimizeRule
));
...
...
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
d8762d40
...
...
@@ -492,58 +492,25 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan,
return
TSDB_CODE_FAILED
;
}
static
int32_t
createColFromDataBlockDesc
(
SDataBlockDescNode
*
pDesc
,
SNodeList
*
pCols
)
{
SNode
*
pNode
;
FOREACH
(
pNode
,
pDesc
->
pSlots
)
{
SSlotDescNode
*
pSlot
=
(
SSlotDescNode
*
)
pNode
;
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
pCol
->
node
.
resType
=
pSlot
->
dataType
;
pCol
->
dataBlockId
=
pDesc
->
dataBlockId
;
pCol
->
slotId
=
pSlot
->
slotId
;
pCol
->
colId
=
-
1
;
int32_t
code
=
nodesListStrictAppend
(
pCols
,
pCol
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
createJoinOutputCols
(
SPhysiPlanContext
*
pCxt
,
SDataBlockDescNode
*
pLeftDesc
,
SDataBlockDescNode
*
pRightDesc
,
SNodeList
**
pList
)
{
SNodeList
*
pCols
=
nodesMakeList
();
if
(
NULL
==
pCols
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
int32_t
code
=
createColFromDataBlockDesc
(
pLeftDesc
,
pCols
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createColFromDataBlockDesc
(
pRightDesc
,
pCols
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pList
=
pCols
;
}
else
{
nodesDestroyList
(
pCols
);
}
return
code
;
}
static
int32_t
createJoinPhysiNode
(
SPhysiPlanContext
*
pCxt
,
SNodeList
*
pChildren
,
SJoinLogicNode
*
pJoinLogicNode
,
SPhysiNode
**
pPhyNode
)
{
SJoinPhysiNode
*
pJoin
=
(
SJoinPhysiNode
*
)
makePhysiNode
(
pCxt
,
getPrecision
(
pChildren
),
(
SLogicNode
*
)
pJoinLogicNode
,
QUERY_NODE_PHYSICAL_PLAN_JOIN
);
if
(
NULL
==
pJoin
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
SDataBlockDescNode
*
pLeftDesc
=
((
SPhysiNode
*
)
nodesListGetNode
(
pChildren
,
0
))
->
pOutputDataBlockDesc
;
SDataBlockDescNode
*
pRightDesc
=
((
SPhysiNode
*
)
nodesListGetNode
(
pChildren
,
1
))
->
pOutputDataBlockDesc
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
setNodeSlotId
(
pCxt
,
pLeftDesc
->
dataBlockId
,
pRightDesc
->
dataBlockId
,
pJoinLogicNode
->
pOnConditions
,
&
pJoin
->
pOnConditions
);
pJoin
->
joinType
=
pJoinLogicNode
->
joinType
;
if
(
NULL
!=
pJoinLogicNode
->
pOnConditions
)
{
SDataBlockDescNode
*
pLeftDesc
=
((
SPhysiNode
*
)
nodesListGetNode
(
pChildren
,
0
))
->
pOutputDataBlockDesc
;
SDataBlockDescNode
*
pRightDesc
=
((
SPhysiNode
*
)
nodesListGetNode
(
pChildren
,
1
))
->
pOutputDataBlockDesc
;
code
=
setNodeSlotId
(
pCxt
,
pLeftDesc
->
dataBlockId
,
pRightDesc
->
dataBlockId
,
pJoinLogicNode
->
pOnConditions
,
&
pJoin
->
pOnConditions
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createJoinOutputCols
(
pCxt
,
pLeftDesc
,
pRightDesc
,
&
pJoin
->
pTargets
);
pJoin
->
pTargets
=
nodesCloneList
(
pJoinLogicNode
->
node
.
pTargets
);
if
(
NULL
==
pJoin
->
pTargets
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
addDataBlockSlots
(
pCxt
,
pJoin
->
pTargets
,
pJoin
->
node
.
pOutputDataBlockDesc
);
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
d8762d40
...
...
@@ -190,6 +190,7 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
}
pSubplan
->
id
.
queryId
=
pCxt
->
queryId
;
pSubplan
->
id
.
groupId
=
1
;
setLogicNodeParent
(
pSubplan
->
pNode
);
int32_t
code
=
applySplitRule
(
pSubplan
);
...
...
source/libs/planner/test/plannerTest.cpp
浏览文件 @
d8762d40
...
...
@@ -150,7 +150,7 @@ private:
SQuery
*
query_
;
};
TEST_F
(
PlannerTest
,
s
imple
)
{
TEST_F
(
PlannerTest
,
s
electBasic
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM t1"
);
...
...
@@ -164,14 +164,27 @@ TEST_F(PlannerTest, selectConstant) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
s
tSimple
)
{
TEST_F
(
PlannerTest
,
s
electStableBasic
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM st1"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
groupBy
)
{
TEST_F
(
PlannerTest
,
selectJoin
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts"
);
ASSERT_TRUE
(
run
());
bind
(
"SELECT * FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1"
);
ASSERT_TRUE
(
run
());
bind
(
"SELECT t1.* FROM st1s1 t1 join st1s2 t2 on t1.ts = t2.ts where t1.c1 > t2.c1"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
selectGroupBy
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT count(*) FROM t1"
);
...
...
@@ -187,14 +200,14 @@ TEST_F(PlannerTest, groupBy) {
// ASSERT_TRUE(run());
}
TEST_F
(
PlannerTest
,
subquery
)
{
TEST_F
(
PlannerTest
,
s
electS
ubquery
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT count(*) FROM (SELECT c1 + c3 a, c1 + count(*) b FROM t1 where c2 = 'abc' GROUP BY c1, c3) where a > 100 group by b"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
i
nterval
)
{
TEST_F
(
PlannerTest
,
selectI
nterval
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT count(*) FROM t1 interval(10s)"
);
...
...
@@ -210,14 +223,14 @@ TEST_F(PlannerTest, interval) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
sessionWindow
)
{
TEST_F
(
PlannerTest
,
se
lectSe
ssionWindow
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT count(*) FROM t1 session(ts, 10s)"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
stateWindow
)
{
TEST_F
(
PlannerTest
,
s
electS
tateWindow
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT count(*) FROM t1 state_window(c1)"
);
...
...
@@ -227,7 +240,7 @@ TEST_F(PlannerTest, stateWindow) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
p
artitionBy
)
{
TEST_F
(
PlannerTest
,
selectP
artitionBy
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM t1 partition by c1"
);
...
...
@@ -243,7 +256,7 @@ TEST_F(PlannerTest, partitionBy) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
o
rderBy
)
{
TEST_F
(
PlannerTest
,
selectO
rderBy
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT c1 FROM t1 order by c1"
);
...
...
@@ -259,7 +272,7 @@ TEST_F(PlannerTest, orderBy) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
g
roupByOrderBy
)
{
TEST_F
(
PlannerTest
,
selectG
roupByOrderBy
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"select count(*), sum(c1) from t1 order by sum(c1)"
);
...
...
@@ -269,7 +282,7 @@ TEST_F(PlannerTest, groupByOrderBy) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
d
istinct
)
{
TEST_F
(
PlannerTest
,
selectD
istinct
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT distinct c1 FROM t1"
);
...
...
@@ -282,7 +295,7 @@ TEST_F(PlannerTest, distinct) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
l
imit
)
{
TEST_F
(
PlannerTest
,
selectL
imit
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM t1 limit 2"
);
...
...
@@ -295,7 +308,7 @@ TEST_F(PlannerTest, limit) {
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
slimit
)
{
TEST_F
(
PlannerTest
,
s
electS
limit
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM t1 partition by c1 slimit 2"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录