Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
841a3f56
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
未验证
提交
841a3f56
编写于
7月 16, 2022
作者:
X
Xiaoyu Wang
提交者:
GitHub
7月 16, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15004 from taosdata/feature/3.0_debug_wxy
some problems of planner
上级
2e628dc0
43852a0e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
57 addition
and
22 deletion
+57
-22
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+22
-10
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+6
-2
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+1
-1
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+14
-7
source/libs/planner/test/planJoinTest.cpp
source/libs/planner/test/planJoinTest.cpp
+6
-0
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+6
-0
tests/script/tsim/tag/5.sim
tests/script/tsim/tag/5.sim
+2
-2
未找到文件。
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
841a3f56
...
...
@@ -1543,7 +1543,7 @@ typedef struct SCollectFuncsCxt {
int32_t
errCode
;
FFuncClassifier
classifier
;
SNodeList
*
pFuncs
;
SHashObj
*
p
AliasName
;
SHashObj
*
p
FuncsSet
;
}
SCollectFuncsCxt
;
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
...
...
@@ -1551,28 +1551,40 @@ static EDealRes collectFuncs(SNode* pNode, void* pContext) {
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
pCxt
->
classifier
(((
SFunctionNode
*
)
pNode
)
->
funcId
)
&&
!
(((
SExprNode
*
)
pNode
)
->
orderAlias
))
{
SExprNode
*
pExpr
=
(
SExprNode
*
)
pNode
;
if
(
NULL
==
taosHashGet
(
pCxt
->
p
AliasName
,
pExpr
->
aliasName
,
strlen
(
pExpr
->
aliasName
)
))
{
if
(
NULL
==
taosHashGet
(
pCxt
->
p
FuncsSet
,
&
pExpr
,
POINTER_BYTES
))
{
pCxt
->
errCode
=
nodesListStrictAppend
(
pCxt
->
pFuncs
,
nodesCloneNode
(
pNode
));
taosHashPut
(
pCxt
->
p
AliasName
,
pExpr
->
aliasName
,
strlen
(
pExpr
->
aliasName
)
,
&
pExpr
,
POINTER_BYTES
);
taosHashPut
(
pCxt
->
p
FuncsSet
,
&
pExpr
,
POINTER_BYTES
,
&
pExpr
,
POINTER_BYTES
);
}
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
);
}
return
DEAL_RES_CONTINUE
;
}
static
uint32_t
funcNodeHash
(
const
char
*
pKey
,
uint32_t
len
)
{
SExprNode
*
pExpr
=
*
(
SExprNode
**
)
pKey
;
return
MurmurHash3_32
(
pExpr
->
aliasName
,
strlen
(
pExpr
->
aliasName
));
}
static
int32_t
funcNodeEqual
(
const
void
*
pLeft
,
const
void
*
pRight
,
size_t
len
)
{
if
(
0
!=
strcmp
((
*
(
const
SExprNode
**
)
pLeft
)
->
aliasName
,
(
*
(
const
SExprNode
**
)
pRight
)
->
aliasName
))
{
return
1
;
}
return
nodesEqualNode
(
*
(
const
SNode
**
)
pLeft
,
*
(
const
SNode
**
)
pRight
)
?
0
:
1
;
}
int32_t
nodesCollectFuncs
(
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
FFuncClassifier
classifier
,
SNodeList
**
pFuncs
)
{
if
(
NULL
==
pSelect
||
NULL
==
pFuncs
)
{
return
TSDB_CODE_FAILED
;
}
SCollectFuncsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
(
NULL
==
*
pFuncs
?
nodesMakeList
()
:
*
pFuncs
),
.
pAliasName
=
taosHashInit
(
4
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_VARCHAR
),
false
,
false
)};
if
(
NULL
==
cxt
.
pFuncs
)
{
SCollectFuncsCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
(
NULL
==
*
pFuncs
?
nodesMakeList
()
:
*
pFuncs
),
.
pFuncsSet
=
taosHashInit
(
4
,
funcNodeHash
,
false
,
false
)};
if
(
NULL
==
cxt
.
pFuncs
||
NULL
==
cxt
.
pFuncsSet
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
taosHashSetEqualFp
(
cxt
.
pFuncsSet
,
funcNodeEqual
);
*
pFuncs
=
NULL
;
nodesWalkSelectStmt
(
pSelect
,
clause
,
collectFuncs
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
==
cxt
.
errCode
)
{
...
...
@@ -1584,7 +1596,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, ESqlClause clause, FFuncClassifi
}
else
{
nodesDestroyList
(
cxt
.
pFuncs
);
}
taosHashCleanup
(
cxt
.
p
AliasName
);
taosHashCleanup
(
cxt
.
p
FuncsSet
);
return
cxt
.
errCode
;
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
841a3f56
...
...
@@ -868,7 +868,8 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal,
}
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
if
(
strict
&&
(
pVal
->
node
.
resType
.
bytes
>
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
))
{
if
(
strict
&&
(
!
IS_VAR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
)
||
pVal
->
node
.
resType
.
bytes
>
targetDt
.
bytes
-
VARSTR_HEADER_SIZE
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
...
...
@@ -888,6 +889,9 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal,
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
strict
&&
!
IS_VAR_DATA_TYPE
(
pVal
->
node
.
resType
.
type
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
pVal
->
literal
);
}
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
targetDt
.
bytes
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_OUT_OF_MEMORY
);
...
...
@@ -1168,7 +1172,7 @@ static int32_t translateRepeatScanFunc(STranslateContext* pCxt, SFunctionNode* p
return
TSDB_CODE_SUCCESS
;
}
if
(
isSelectStmt
(
pCxt
->
pCurrStmt
))
{
//select percentile() without from clause is also valid
//
select percentile() without from clause is also valid
if
(
NULL
==
((
SSelectStmt
*
)
pCxt
->
pCurrStmt
)
->
pFromTable
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
841a3f56
...
...
@@ -282,7 +282,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
pScan
->
hasNormalCols
=
true
;
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
SCAN_TYPE_SYSTEM_TABLE
!=
pScan
->
scanType
)
{
code
=
addPrimaryKeyCol
(
pScan
->
tableId
,
&
pScan
->
pScanCols
);
}
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
841a3f56
...
...
@@ -1050,8 +1050,11 @@ static int32_t sortPriKeyOptApply(SOptimizeContext* pCxt, SLogicSubplan* pLogicS
}
}
int32_t
code
=
replaceLogicNode
(
pLogicSubplan
,
(
SLogicNode
*
)
pSort
,
(
SLogicNode
*
)
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
));
SLogicNode
*
pChild
=
(
SLogicNode
*
)
nodesListGetNode
(
pSort
->
node
.
pChildren
,
0
);
if
(
NULL
==
pSort
->
node
.
pParent
)
{
TSWAP
(
pSort
->
node
.
pTargets
,
pChild
->
pTargets
);
}
int32_t
code
=
replaceLogicNode
(
pLogicSubplan
,
(
SLogicNode
*
)
pSort
,
pChild
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
NODES_CLEAR_LIST
(
pSort
->
node
.
pChildren
);
nodesDestroyNode
((
SNode
*
)
pSort
);
...
...
@@ -1982,11 +1985,15 @@ static int32_t rewriteUniqueOptimize(SOptimizeContext* pCxt, SLogicSubplan* pLog
}
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
||
0
==
((
SScanLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
))
->
cacheLastMode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_AGG
!=
nodeType
(
pNode
)
||
1
!=
LIST_LENGTH
(
pNode
->
pChildren
)
||
QUERY_NODE_LOGIC_PLAN_SCAN
!=
nodeType
(
nodesListGetNode
(
pNode
->
pChildren
,
0
)))
{
return
false
;
}
SAggLogicNode
*
pAgg
=
(
SAggLogicNode
*
)
pNode
;
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
);
if
(
!
pAgg
->
hasLastRow
||
NULL
!=
pAgg
->
pGroupKeys
||
NULL
!=
pScan
->
node
.
pConditions
||
0
==
pScan
->
cacheLastMode
||
IS_TSWINDOW_SPECIFIED
(
pScan
->
scanRange
))
{
return
false
;
}
...
...
source/libs/planner/test/planJoinTest.cpp
浏览文件 @
841a3f56
...
...
@@ -45,6 +45,12 @@ TEST_F(PlanJoinTest, withWhere) {
"WHERE t1.c1 > t2.c1 AND t1.c2 = 'abc' AND t2.c2 = 'qwe'"
);
}
TEST_F
(
PlanJoinTest
,
withAggAndOrderBy
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT t1.ts, TOP(t2.c1, 10) FROM st1s1 t1 JOIN st1s2 t2 ON t1.ts = t2.ts ORDER BY t2.ts"
);
}
TEST_F
(
PlanJoinTest
,
multiJoin
)
{
useDb
(
"root"
,
"test"
);
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
841a3f56
...
...
@@ -84,6 +84,12 @@ TEST_F(PlanOptimizeTest, eliminateProjection) {
// run("select 1-abs(c1) from (select unique(c1) c1 from st1s3) order by 1 nulls first");
}
TEST_F
(
PlanOptimizeTest
,
mergeProjects
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT * FROM (SELECT * FROM t1 WHERE c1 > 10 ORDER BY ts) ORDER BY ts"
);
}
TEST_F
(
PlanOptimizeTest
,
pushDownProjectCond
)
{
useDb
(
"root"
,
"test"
);
run
(
"select 1-abs(c1) from (select unique(c1) c1 from st1s3) where 1-c1>5 order by 1 nulls first"
);
...
...
tests/script/tsim/tag/5.sim
浏览文件 @
841a3f56
...
...
@@ -24,7 +24,7 @@ sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol1 tinyint, tgcol2 int,
$i = 0
while $i < 5
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( 0, 0, 0, 0,
0
)
sql create table $tb using $mt tags( 0, 0, 0, 0,
'0'
)
$x = 0
while $x < $rowNum
$ms = $x . m
...
...
@@ -35,7 +35,7 @@ while $i < 5
endw
while $i < 10
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( 1, 1, 1, 1,
1
)
sql create table $tb using $mt tags( 1, 1, 1, 1,
'1'
)
$x = 0
while $x < $rowNum
$ms = $x . m
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录