Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a44b71f2
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a44b71f2
编写于
5月 24, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: problem of useless col optimize
上级
e7a182fc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
23 deletion
+31
-23
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-0
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+12
-5
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+18
-18
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
a44b71f2
...
@@ -242,6 +242,7 @@ typedef struct SSelectStmt {
...
@@ -242,6 +242,7 @@ typedef struct SSelectStmt {
bool
hasAggFuncs
;
bool
hasAggFuncs
;
bool
hasRepeatScanFuncs
;
bool
hasRepeatScanFuncs
;
bool
hasIndefiniteRowsFunc
;
bool
hasIndefiniteRowsFunc
;
bool
hasSelectValFunc
;
}
SSelectStmt
;
}
SSelectStmt
;
typedef
enum
ESetOperatorType
{
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
typedef
enum
ESetOperatorType
{
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
a44b71f2
...
@@ -189,11 +189,18 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
...
@@ -189,11 +189,18 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
return
code
;
return
code
;
}
}
static
int32_t
calcConstProjections
(
SCalcConstContext
*
pCxt
,
SNodeList
*
pProjections
,
bool
subquery
)
{
static
bool
isUselessCol
(
bool
hasSelectValFunc
,
SExprNode
*
pProj
)
{
if
(
hasSelectValFunc
&&
QUERY_NODE_FUNCTION
==
nodeType
(
pProj
)
&&
fmIsSelectFunc
(((
SFunctionNode
*
)
pProj
)
->
funcId
))
{
return
false
;
}
return
NULL
==
((
SExprNode
*
)
pProj
)
->
pAssociation
;
}
static
int32_t
calcConstProjections
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
SNode
*
pProj
=
NULL
;
SNode
*
pProj
=
NULL
;
WHERE_EACH
(
pProj
,
p
Projections
)
{
WHERE_EACH
(
pProj
,
p
Select
->
pProjectionList
)
{
if
(
subquery
&&
NULL
==
((
SExprNode
*
)
pProj
)
->
pAssociation
)
{
if
(
subquery
&&
isUselessCol
(
pSelect
->
hasSelectValFunc
,
(
SExprNode
*
)
pProj
)
)
{
ERASE_NODE
(
p
Projections
);
ERASE_NODE
(
p
Select
->
pProjectionList
);
continue
;
continue
;
}
}
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
...
@@ -226,7 +233,7 @@ static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
...
@@ -226,7 +233,7 @@ static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
}
}
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
static
int32_t
calcConstSelect
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
,
bool
subquery
)
{
int32_t
code
=
calcConstProjections
(
pCxt
,
pSelect
->
pProjectionList
,
subquery
);
int32_t
code
=
calcConstProjections
(
pCxt
,
pSelect
,
subquery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calcConstFromTable
(
pCxt
,
pSelect
);
code
=
calcConstFromTable
(
pCxt
,
pSelect
);
}
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
a44b71f2
...
@@ -812,7 +812,7 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
...
@@ -812,7 +812,7 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
static
EDealRes
have
AggOrNonstd
Function
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
have
Vector
Function
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
isAggFunc
(
pNode
))
{
if
(
isAggFunc
(
pNode
))
{
*
((
bool
*
)
pContext
)
=
true
;
*
((
bool
*
)
pContext
)
=
true
;
return
DEAL_RES_END
;
return
DEAL_RES_END
;
...
@@ -857,7 +857,7 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
...
@@ -857,7 +857,7 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
static
bool
hasInvalidFuncNesting
(
SNodeList
*
pParameterList
)
{
static
bool
hasInvalidFuncNesting
(
SNodeList
*
pParameterList
)
{
bool
hasInvalidFunc
=
false
;
bool
hasInvalidFunc
=
false
;
nodesWalkExprs
(
pParameterList
,
have
AggOrNonstd
Function
,
&
hasInvalidFunc
);
nodesWalkExprs
(
pParameterList
,
have
Vector
Function
,
&
hasInvalidFunc
);
return
hasInvalidFunc
;
return
hasInvalidFunc
;
}
}
...
@@ -1042,6 +1042,7 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
...
@@ -1042,6 +1042,7 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
return
generateDealNodeErrMsg
(
pCxt
->
pTranslateCxt
,
getGroupByErrorCode
(
pCxt
->
pTranslateCxt
));
return
generateDealNodeErrMsg
(
pCxt
->
pTranslateCxt
,
getGroupByErrorCode
(
pCxt
->
pTranslateCxt
));
}
else
{
}
else
{
pCxt
->
hasSelectValFunc
=
true
;
pCxt
->
hasSelectValFunc
=
true
;
pCxt
->
pTranslateCxt
->
pCurrStmt
->
hasSelectValFunc
=
true
;
return
rewriteColToSelectValFunc
(
pCxt
->
pTranslateCxt
,
pNode
);
return
rewriteColToSelectValFunc
(
pCxt
->
pTranslateCxt
,
pNode
);
}
}
}
}
...
@@ -1096,7 +1097,7 @@ typedef struct CheckAggColCoexistCxt {
...
@@ -1096,7 +1097,7 @@ typedef struct CheckAggColCoexistCxt {
STranslateContext
*
pTranslateCxt
;
STranslateContext
*
pTranslateCxt
;
bool
existAggFunc
;
bool
existAggFunc
;
bool
existCol
;
bool
existCol
;
bool
exist
Nonstd
Func
;
bool
exist
IndefiniteRows
Func
;
int32_t
selectFuncNum
;
int32_t
selectFuncNum
;
bool
existOtherAggFunc
;
bool
existOtherAggFunc
;
}
CheckAggColCoexistCxt
;
}
CheckAggColCoexistCxt
;
...
@@ -1113,7 +1114,7 @@ static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
...
@@ -1113,7 +1114,7 @@ static EDealRes doCheckAggColCoexist(SNode* pNode, void* pContext) {
return
DEAL_RES_IGNORE_CHILD
;
return
DEAL_RES_IGNORE_CHILD
;
}
}
if
(
isIndefiniteRowsFunc
(
pNode
))
{
if
(
isIndefiniteRowsFunc
(
pNode
))
{
pCxt
->
exist
Nonstd
Func
=
true
;
pCxt
->
exist
IndefiniteRows
Func
=
true
;
return
DEAL_RES_IGNORE_CHILD
;
return
DEAL_RES_IGNORE_CHILD
;
}
}
if
(
isScanPseudoColumnFunc
(
pNode
)
||
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
isScanPseudoColumnFunc
(
pNode
)
||
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
...
@@ -1129,7 +1130,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
...
@@ -1129,7 +1130,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
CheckAggColCoexistCxt
cxt
=
{.
pTranslateCxt
=
pCxt
,
CheckAggColCoexistCxt
cxt
=
{.
pTranslateCxt
=
pCxt
,
.
existAggFunc
=
false
,
.
existAggFunc
=
false
,
.
existCol
=
false
,
.
existCol
=
false
,
.
exist
Nonstd
Func
=
false
,
.
exist
IndefiniteRows
Func
=
false
,
.
selectFuncNum
=
0
,
.
selectFuncNum
=
0
,
.
existOtherAggFunc
=
false
};
.
existOtherAggFunc
=
false
};
nodesWalkExprs
(
pSelect
->
pProjectionList
,
doCheckAggColCoexist
,
&
cxt
);
nodesWalkExprs
(
pSelect
->
pProjectionList
,
doCheckAggColCoexist
,
&
cxt
);
...
@@ -1142,7 +1143,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
...
@@ -1142,7 +1143,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
if
((
cxt
.
selectFuncNum
>
1
||
cxt
.
existAggFunc
||
NULL
!=
pSelect
->
pWindow
)
&&
cxt
.
existCol
)
{
if
((
cxt
.
selectFuncNum
>
1
||
cxt
.
existAggFunc
||
NULL
!=
pSelect
->
pWindow
)
&&
cxt
.
existCol
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
}
}
if
(
cxt
.
exist
Nonstd
Func
&&
cxt
.
existCol
)
{
if
(
cxt
.
exist
IndefiniteRows
Func
&&
cxt
.
existCol
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -4079,9 +4080,7 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
...
@@ -4079,9 +4080,7 @@ static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SS
return
parseJsontoTagData
(
pVal
->
literal
,
pBuilder
,
&
pCxt
->
msgBuf
,
pSchema
->
colId
);
return
parseJsontoTagData
(
pVal
->
literal
,
pBuilder
,
&
pCxt
->
msgBuf
,
pSchema
->
colId
);
}
}
if
(
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_NULL
)
{
if
(
pVal
->
node
.
resType
.
type
!=
TSDB_DATA_TYPE_NULL
)
{
// todo
}
else
{
tdAddColToKVRow
(
pBuilder
,
pSchema
->
colId
,
nodesGetValueFromNode
(
pVal
),
tdAddColToKVRow
(
pBuilder
,
pSchema
->
colId
,
nodesGetValueFromNode
(
pVal
),
IS_VAR_DATA_TYPE
(
pSchema
->
type
)
?
varDataTLen
(
pVal
->
datum
.
p
)
:
TYPE_BYTES
[
pSchema
->
type
]);
IS_VAR_DATA_TYPE
(
pSchema
->
type
)
?
varDataTLen
(
pVal
->
datum
.
p
)
:
TYPE_BYTES
[
pSchema
->
type
]);
}
}
...
@@ -4452,14 +4451,15 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
...
@@ -4452,14 +4451,15 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
}
}
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
if
(
pStmt
->
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
pStmt
->
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
)
{
SKVRowBuilder
kvRowBuilder
=
{
0
};
SKVRowBuilder
kvRowBuilder
=
{
0
};
int32_t
code
=
tdInitKVRowBuilder
(
&
kvRowBuilder
);
int32_t
code
=
tdInitKVRowBuilder
(
&
kvRowBuilder
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
if
(
pStmt
->
pVal
->
literal
&&
strlen
(
pStmt
->
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
if
(
pStmt
->
pVal
->
literal
&&
strlen
(
pStmt
->
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pStmt
->
pVal
->
literal
);
return
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pStmt
->
pVal
->
literal
);
}
}
...
@@ -4477,7 +4477,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
...
@@ -4477,7 +4477,7 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
pReq
->
pTagVal
=
row
;
pReq
->
pTagVal
=
row
;
pStmt
->
pVal
->
datum
.
p
=
row
;
// for free
pStmt
->
pVal
->
datum
.
p
=
row
;
// for free
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
}
else
{
}
else
{
pReq
->
nTagVal
=
pStmt
->
pVal
->
node
.
resType
.
bytes
;
pReq
->
nTagVal
=
pStmt
->
pVal
->
node
.
resType
.
bytes
;
if
(
TSDB_DATA_TYPE_NCHAR
==
pStmt
->
pVal
->
node
.
resType
.
type
)
{
if
(
TSDB_DATA_TYPE_NCHAR
==
pStmt
->
pVal
->
node
.
resType
.
type
)
{
pReq
->
nTagVal
=
pReq
->
nTagVal
*
TSDB_NCHAR_SIZE
;
pReq
->
nTagVal
=
pReq
->
nTagVal
*
TSDB_NCHAR_SIZE
;
...
@@ -4688,16 +4688,16 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
...
@@ -4688,16 +4688,16 @@ static int32_t rewriteAlterTable(STranslateContext* pCxt, SQuery* pQuery) {
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COL_JSON
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_COL_JSON
);
}
}
if
(
getNumOfTags
(
pTableMeta
)
==
1
&&
pStmt
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
)
{
if
(
getNumOfTags
(
pTableMeta
)
==
1
&&
pStmt
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
,
"can not drop tag if there is only one tag"
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_ALTER_TABLE
,
"can not drop tag if there is only one tag"
);
}
}
if
(
TSDB_SUPER_TABLE
==
pTableMeta
->
tableType
)
{
if
(
TSDB_SUPER_TABLE
==
pTableMeta
->
tableType
)
{
SSchema
*
pTagsSchema
=
getTableTagSchema
(
pTableMeta
);
SSchema
*
pTagsSchema
=
getTableTagSchema
(
pTableMeta
);
if
(
getNumOfTags
(
pTableMeta
)
==
1
&&
pTagsSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
if
(
getNumOfTags
(
pTableMeta
)
==
1
&&
pTagsSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
(
pStmt
->
alterType
==
TSDB_ALTER_TABLE_ADD_TAG
||
(
pStmt
->
alterType
==
TSDB_ALTER_TABLE_ADD_TAG
||
pStmt
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
||
pStmt
->
alterType
==
TSDB_ALTER_TABLE_DROP_TAG
||
pStmt
->
alterType
==
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
))
{
pStmt
->
alterType
==
TSDB_ALTER_TABLE_UPDATE_TAG_BYTES
))
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ONLY_ONE_JSON_TAG
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_ONLY_ONE_JSON_TAG
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录