Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8f4056ec
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看板
提交
8f4056ec
编写于
12月 07, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add height limit of expression tree
上级
7130d3de
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
12 deletion
+26
-12
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+26
-12
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
8f4056ec
...
...
@@ -109,7 +109,7 @@ static int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo);
static
int32_t
validateSqlFunctionInStreamSql
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
validateFunctionsInIntervalOrGroupbyQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
validateSQLExprItem
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
);
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
,
int32_t
*
height
);
static
int32_t
validateEp
(
char
*
ep
);
static
int32_t
validateDNodeConfig
(
SMiscInfo
*
pOptions
);
static
int32_t
validateLocalConfig
(
SMiscInfo
*
pOptions
);
...
...
@@ -1944,12 +1944,17 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
int32_t
sqlExprType
=
SQLEXPR_TYPE_UNASSIGNED
;
uint64_t
uid
;
int32_t
code
=
validateSQLExprItem
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
sqlExprType
,
&
uid
);
int32_t
height
=
0
;
int32_t
code
=
validateSQLExprItem
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
sqlExprType
,
&
uid
,
&
height
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
height
>=
16
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"the max height of expression must be less than 16"
);
}
if
(
sqlExprType
==
SQLEXPR_TYPE_SCALAR
)
{
code
=
handleScalarTypeExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
}
else
{
...
...
@@ -4366,7 +4371,7 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
}
static
int32_t
validateSQLExprItemSQLFunc
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
,
int32_t
*
height
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
const
char
*
msg1
=
"invalid function parameters"
;
const
char
*
msg2
=
"not supported functions in arithmetic expression"
;
...
...
@@ -4377,10 +4382,11 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
if
(
pExpr
->
Expr
.
paramList
!=
NULL
)
{
size_t
numChildren
=
taosArrayGetSize
(
pExpr
->
Expr
.
paramList
);
int32_t
*
childrenTypes
=
calloc
(
numChildren
,
sizeof
(
int32_t
));
int32_t
*
childrenHeight
=
calloc
(
numChildren
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
numChildren
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
code
=
validateSQLExprItem
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
childrenTypes
+
i
,
uid
);
code
=
validateSQLExprItem
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
childrenTypes
+
i
,
uid
,
childrenHeight
+
i
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
free
(
childrenTypes
);
return
code
;
...
...
@@ -4397,11 +4403,18 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
bool
anyChildScalar
=
false
;
bool
anyChildAgg
=
false
;
int32_t
maxChildrenHeight
=
0
;
for
(
int
i
=
0
;
i
<
numChildren
;
++
i
)
{
assert
(
childrenTypes
[
i
]
!=
SQLEXPR_TYPE_UNASSIGNED
);
anyChildScalar
=
anyChildScalar
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_SCALAR
);
anyChildAgg
=
anyChildAgg
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_AGG
);
if
(
childrenHeight
[
i
]
>
maxChildrenHeight
)
{
maxChildrenHeight
=
childrenHeight
[
i
];
}
}
*
height
=
maxChildrenHeight
+
1
;
if
(
anyChildAgg
&&
anyChildScalar
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
...
...
@@ -4477,19 +4490,20 @@ static int32_t validateSQLExprItemSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
static
int32_t
validateSQLExprItemArithmeticExpr
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
int32_t
*
type
,
uint64_t
*
uid
,
int32_t
*
height
)
{
uint64_t
uidLeft
=
0
;
uint64_t
uidRight
=
0
;
int32_t
leftType
=
SQLEXPR_TYPE_UNASSIGNED
;
int32_t
rightType
=
SQLEXPR_TYPE_UNASSIGNED
;
const
char
*
msg1
=
"arithmetic expression composed with columns from different tables"
;
const
char
*
msg2
=
"arithmetic expression composed with functions/columns of different types"
;
int32_t
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pLeft
,
pQueryInfo
,
pList
,
&
leftType
,
&
uidLeft
);
int32_t
leftHeight
=
0
;
int32_t
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pLeft
,
pQueryInfo
,
pList
,
&
leftType
,
&
uidLeft
,
&
leftHeight
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pRight
,
pQueryInfo
,
pList
,
&
rightType
,
&
uidRight
);
int32_t
rightHeight
=
0
;
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pRight
,
pQueryInfo
,
pList
,
&
rightType
,
&
uidRight
,
&
rightHeight
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -4499,6 +4513,7 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
*
uid
=
uidLeft
;
*
height
=
(
leftHeight
>
rightHeight
)
?
leftHeight
+
1
:
rightHeight
+
1
;
{
assert
(
leftType
!=
SQLEXPR_TYPE_UNASSIGNED
&&
rightType
!=
SQLEXPR_TYPE_UNASSIGNED
);
...
...
@@ -4519,7 +4534,7 @@ static int32_t validateSQLExprItemArithmeticExpr(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
static
int32_t
validateSQLExprItem
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
,
int32_t
*
height
)
{
const
char
*
msg1
=
"invalid column name in select clause"
;
const
char
*
msg2
=
"invalid data type in select clause"
;
const
char
*
msg3
=
"invalid select clause"
;
...
...
@@ -4527,14 +4542,13 @@ static int32_t validateSQLExprItem(SSqlCmd* pCmd, tSqlExpr* pExpr,
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
pExpr
->
type
==
SQL_NODE_EXPR
)
{
int32_t
ret
=
validateSQLExprItemArithmeticExpr
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
int32_t
ret
=
validateSQLExprItemArithmeticExpr
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
,
height
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
int32_t
ret
=
validateSQLExprItemSQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
int32_t
ret
=
validateSQLExprItemSQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
,
height
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录