Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
72738040
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看板
提交
72738040
编写于
7月 10, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: some problem of parser and planner
上级
a64a0320
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
71 addition
and
87 deletion
+71
-87
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+50
-3
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+2
-82
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+2
-0
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+8
-2
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+1
-0
source/libs/planner/test/planOrderByTest.cpp
source/libs/planner/test/planOrderByTest.cpp
+6
-0
source/libs/planner/test/planPartByTest.cpp
source/libs/planner/test/planPartByTest.cpp
+2
-0
未找到文件。
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
72738040
...
...
@@ -543,11 +543,40 @@ static int32_t jsonToLogicPlanNode(const SJson* pJson, void* pObj) {
static
const
char
*
jkScanLogicPlanScanCols
=
"ScanCols"
;
static
const
char
*
jkScanLogicPlanScanPseudoCols
=
"ScanPseudoCols"
;
static
const
char
*
jkScanLogicPlanTableId
=
"TableId"
;
static
const
char
*
jkScanLogicPlanTableType
=
"TableType"
;
static
const
char
*
jkScanLogicPlanTableId
=
"TableId"
;
static
const
char
*
jkScanLogicPlanStableId
=
"StableId"
;
static
const
char
*
jkScanLogicPlanScanCount
=
"ScanCount"
;
static
const
char
*
jkScanLogicPlanReverseScanCount
=
"ReverseScanCount"
;
static
const
char
*
jkScanLogicPlanTagCond
=
"TagCond"
;
static
const
char
*
jkScanLogicPlanGroupTags
=
"GroupTags"
;
// typedef struct SScanLogicNode {
// uint64_t stableId;
// SVgroupsInfo* pVgroupList;
// EScanType scanType;
// uint8_t scanSeq[2]; // first is scan count, and second is reverse scan count
// STimeWindow scanRange;
// SName tableName;
// bool showRewrite;
// double ratio;
// SNodeList* pDynamicScanFuncs;
// int32_t dataRequired;
// int64_t interval;
// int64_t offset;
// int64_t sliding;
// int8_t intervalUnit;
// int8_t slidingUnit;
// SNode* pTagCond;
// SNode* pTagIndexCond;
// int8_t triggerType;
// int64_t watermark;
// int8_t igExpired;
// SArray* pSmaIndexes;
// SNodeList* pGroupTags;
// bool groupSort;
// } SScanLogicNode;
static
int32_t
logicScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SScanLogicNode
*
pNode
=
(
const
SScanLogicNode
*
)
pObj
;
...
...
@@ -558,11 +587,20 @@ static int32_t logicScanNodeToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodeListToJson
(
pJson
,
jkScanLogicPlanScanPseudoCols
,
pNode
->
pScanPseudoCols
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkScanLogicPlanTableType
,
pNode
->
tableType
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkScanLogicPlanTableId
,
pNode
->
tableId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkScanLogicPlanTableType
,
pNode
->
tableType
);
code
=
tjsonAddIntegerToObject
(
pJson
,
jkScanLogicPlanStableId
,
pNode
->
stableId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkScanLogicPlanScanCount
,
pNode
->
scanSeq
[
0
]);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkScanLogicPlanReverseScanCount
,
pNode
->
scanSeq
[
1
]);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddObject
(
pJson
,
jkScanLogicPlanTagCond
,
nodeToJson
,
pNode
->
pTagCond
);
...
...
@@ -585,11 +623,20 @@ static int32_t jsonToLogicScanNode(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeList
(
pJson
,
jkScanLogicPlanScanPseudoCols
,
&
pNode
->
pScanPseudoCols
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetTinyIntValue
(
pJson
,
jkScanLogicPlanTableType
,
&
pNode
->
tableType
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetUBigIntValue
(
pJson
,
jkScanLogicPlanTableId
,
&
pNode
->
tableId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetTinyIntValue
(
pJson
,
jkScanLogicPlanTableType
,
&
pNode
->
tableType
);
code
=
tjsonGetUBigIntValue
(
pJson
,
jkScanLogicPlanStableId
,
&
pNode
->
stableId
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetUTinyIntValue
(
pJson
,
jkScanLogicPlanScanCount
,
&
pNode
->
scanSeq
[
0
]);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetUTinyIntValue
(
pJson
,
jkScanLogicPlanReverseScanCount
,
&
pNode
->
scanSeq
[
1
]);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
jsonToNodeObject
(
pJson
,
jkScanLogicPlanTagCond
,
&
pNode
->
pTagCond
);
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
72738040
...
...
@@ -120,86 +120,6 @@ static int32_t skipInsertInto(char** pSql, SMsgBuf* pMsg) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
parserValidateIdToken
(
SToken
*
pToken
)
{
if
(
pToken
==
NULL
||
pToken
->
z
==
NULL
||
pToken
->
type
!=
TK_NK_ID
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// it is a token quoted with escape char '`'
if
(
pToken
->
z
[
0
]
==
TS_ESCAPE_CHAR
&&
pToken
->
z
[
pToken
->
n
-
1
]
==
TS_ESCAPE_CHAR
)
{
return
TSDB_CODE_SUCCESS
;
}
char
*
sep
=
strnchr
(
pToken
->
z
,
TS_PATH_DELIMITER
[
0
],
pToken
->
n
,
true
);
if
(
sep
==
NULL
)
{
// It is a single part token, not a complex type
if
(
isNumber
(
pToken
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
strntolower
(
pToken
->
z
,
pToken
->
z
,
pToken
->
n
);
}
else
{
// two part
int32_t
oldLen
=
pToken
->
n
;
char
*
pStr
=
pToken
->
z
;
if
(
pToken
->
type
==
TK_NK_SPACE
)
{
pToken
->
n
=
(
uint32_t
)
strtrim
(
pToken
->
z
);
}
pToken
->
n
=
tGetToken
(
pToken
->
z
,
&
pToken
->
type
);
if
(
pToken
->
z
[
pToken
->
n
]
!=
TS_PATH_DELIMITER
[
0
])
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
pToken
->
type
!=
TK_NK_ID
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
int32_t
firstPartLen
=
pToken
->
n
;
pToken
->
z
=
sep
+
1
;
pToken
->
n
=
(
uint32_t
)(
oldLen
-
(
sep
-
pStr
)
-
1
);
int32_t
len
=
tGetToken
(
pToken
->
z
,
&
pToken
->
type
);
if
(
len
!=
pToken
->
n
||
pToken
->
type
!=
TK_NK_ID
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// re-build the whole name string
if
(
pStr
[
firstPartLen
]
==
TS_PATH_DELIMITER
[
0
])
{
// first part do not have quote do nothing
}
else
{
pStr
[
firstPartLen
]
=
TS_PATH_DELIMITER
[
0
];
memmove
(
&
pStr
[
firstPartLen
+
1
],
pToken
->
z
,
pToken
->
n
);
uint32_t
offset
=
(
uint32_t
)(
pToken
->
z
-
(
pStr
+
firstPartLen
+
1
));
memset
(
pToken
->
z
+
pToken
->
n
-
offset
,
' '
,
offset
);
}
pToken
->
n
+=
(
firstPartLen
+
sizeof
(
TS_PATH_DELIMITER
[
0
]));
pToken
->
z
=
pStr
;
strntolower
(
pToken
->
z
,
pToken
->
z
,
pToken
->
n
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildName
(
SInsertParseContext
*
pCxt
,
SToken
*
pStname
,
char
*
fullDbName
,
char
*
tableName
)
{
if
(
parserValidateIdToken
(
pStname
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
"invalid table name"
,
pStname
->
z
);
}
char
*
p
=
strnchr
(
pStname
->
z
,
TS_PATH_DELIMITER
[
0
],
pStname
->
n
,
false
);
if
(
NULL
!=
p
)
{
// db.table
int32_t
n
=
sprintf
(
fullDbName
,
"%d."
,
pCxt
->
pComCxt
->
acctId
);
strncpy
(
fullDbName
+
n
,
pStname
->
z
,
p
-
pStname
->
z
);
strncpy
(
tableName
,
p
+
1
,
pStname
->
n
-
(
p
-
pStname
->
z
)
-
1
);
}
else
{
snprintf
(
fullDbName
,
TSDB_DB_FNAME_LEN
,
"%d.%s"
,
pCxt
->
pComCxt
->
acctId
,
pCxt
->
pComCxt
->
db
);
strncpy
(
tableName
,
pStname
->
z
,
pStname
->
n
);
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
createSName
(
SName
*
pName
,
SToken
*
pTableName
,
int32_t
acctId
,
const
char
*
dbName
,
SMsgBuf
*
pMsgBuf
)
{
const
char
*
msg1
=
"name too long"
;
const
char
*
msg2
=
"invalid database name"
;
...
...
@@ -978,11 +898,11 @@ static int32_t parseTagToken(char** end, SToken* pToken, SSchema* pSchema, int16
case
TSDB_DATA_TYPE_NCHAR
:
{
int32_t
output
=
0
;
void
*
p
=
taosMemoryCalloc
(
1
,
p
Token
->
n
*
TSDB_NCHA
R_SIZE
);
void
*
p
=
taosMemoryCalloc
(
1
,
p
Schema
->
bytes
-
VARSTR_HEADE
R_SIZE
);
if
(
p
==
NULL
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
!
taosMbsToUcs4
(
pToken
->
z
,
pToken
->
n
,
(
TdUcs4
*
)(
p
),
p
Token
->
n
*
TSDB_NCHA
R_SIZE
,
&
output
))
{
if
(
!
taosMbsToUcs4
(
pToken
->
z
,
pToken
->
n
,
(
TdUcs4
*
)(
p
),
p
Schema
->
bytes
-
VARSTR_HEADE
R_SIZE
,
&
output
))
{
if
(
errno
==
E2BIG
)
{
taosMemoryFree
(
p
);
return
generateSyntaxErrMsg
(
pMsgBuf
,
TSDB_CODE_PAR_VALUE_TOO_LONG
,
pSchema
->
name
);
...
...
source/libs/parser/src/parser.c
浏览文件 @
72738040
...
...
@@ -38,6 +38,8 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) {
t
=
tStrGetToken
((
char
*
)
pStr
,
&
index
,
false
);
if
(
TK_USING
==
t
.
type
||
TK_VALUES
==
t
.
type
)
{
return
true
;
}
else
if
(
TK_SELECT
==
t
.
type
)
{
return
false
;
}
if
(
0
==
t
.
type
)
{
break
;
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
72738040
...
...
@@ -1010,8 +1010,13 @@ static int32_t sortPriKeyOptApply(SOptimizeContext* pCxt, SLogicSubplan* pLogicS
SNodeList
*
pScanNodes
)
{
EOrder
order
=
sortPriKeyOptGetPriKeyOrder
(
pSort
);
if
(
ORDER_DESC
==
order
)
{
SNode
*
pScan
=
NULL
;
FOREACH
(
pScan
,
pScanNodes
)
{
TSWAP
(((
SScanLogicNode
*
)
pScan
)
->
scanSeq
[
0
],
((
SScanLogicNode
*
)
pScan
)
->
scanSeq
[
1
]);
}
SNode
*
pScanNode
=
NULL
;
FOREACH
(
pScanNode
,
pScanNodes
)
{
SScanLogicNode
*
pScan
=
(
SScanLogicNode
*
)
pScanNode
;
if
(
pScan
->
scanSeq
[
0
]
>
0
)
{
TSWAP
(
pScan
->
scanSeq
[
0
],
pScan
->
scanSeq
[
1
]);
}
}
}
int32_t
code
=
...
...
@@ -1020,6 +1025,7 @@ static int32_t sortPriKeyOptApply(SOptimizeContext* pCxt, SLogicSubplan* pLogicS
NODES_CLEAR_LIST
(
pSort
->
node
.
pChildren
);
nodesDestroyNode
((
SNode
*
)
pSort
);
}
pCxt
->
optimized
=
true
;
return
code
;
}
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
72738040
...
...
@@ -945,6 +945,7 @@ static int32_t stbSplSplitPartitionNode(SSplitContext* pCxt, SStableSplitInfo* p
code
=
nodesListMakeStrictAppend
(
&
pInfo
->
pSubplan
->
pChildren
,
(
SNode
*
)
splCreateScanSubplan
(
pCxt
,
pInfo
->
pSplitNode
,
SPLIT_FLAG_STABLE_SPLIT
));
}
pInfo
->
pSubplan
->
subplanType
=
SUBPLAN_TYPE_MERGE
;
++
(
pCxt
->
groupId
);
return
code
;
}
...
...
source/libs/planner/test/planOrderByTest.cpp
浏览文件 @
72738040
...
...
@@ -53,6 +53,12 @@ TEST_F(PlanOrderByTest, withGroupBy) {
run
(
"SELECT SUM(c1) AS a FROM t1 GROUP BY c2 ORDER BY a"
);
}
TEST_F
(
PlanOrderByTest
,
withSubquery
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT ts FROM (SELECT * FROM t1 ORDER BY ts DESC) ORDER BY ts DESC"
);
}
TEST_F
(
PlanOrderByTest
,
stable
)
{
useDb
(
"root"
,
"test"
);
...
...
source/libs/planner/test/planPartByTest.cpp
浏览文件 @
72738040
...
...
@@ -37,6 +37,8 @@ TEST_F(PlanPartitionByTest, withAggFunc) {
run
(
"select count(*) from st1 partition by c1"
);
run
(
"select sample(c1, 2) from st1 partition by c1"
);
run
(
"select count(*), c1 from t1 partition by c1"
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录