Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4ecbfd07
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看板
未验证
提交
4ecbfd07
编写于
7月 11, 2022
作者:
X
Xiaoyu Wang
提交者:
GitHub
7月 11, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14760 from taosdata/feature/3.0_debug_wxy
fix: some problems of parser
上级
a50960aa
e64cdd54
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
124 addition
and
100 deletion
+124
-100
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+33
-30
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+21
-18
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+1
-1
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+4
-0
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+1
-1
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+31
-32
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+27
-18
source/libs/planner/test/planOptimizeTest.cpp
source/libs/planner/test/planOptimizeTest.cpp
+2
-0
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+4
-0
未找到文件。
source/client/src/clientImpl.c
浏览文件 @
4ecbfd07
...
@@ -148,7 +148,8 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas
...
@@ -148,7 +148,8 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas
return
taosConnectImpl
(
user
,
&
secretEncrypt
[
0
],
localDb
,
NULL
,
NULL
,
*
pInst
,
connType
);
return
taosConnectImpl
(
user
,
&
secretEncrypt
[
0
],
localDb
,
NULL
,
NULL
,
*
pInst
,
connType
);
}
}
int32_t
buildRequest
(
uint64_t
connId
,
const
char
*
sql
,
int
sqlLen
,
void
*
param
,
bool
validateSql
,
SRequestObj
**
pRequest
)
{
int32_t
buildRequest
(
uint64_t
connId
,
const
char
*
sql
,
int
sqlLen
,
void
*
param
,
bool
validateSql
,
SRequestObj
**
pRequest
)
{
*
pRequest
=
createRequest
(
connId
,
TSDB_SQL_SELECT
);
*
pRequest
=
createRequest
(
connId
,
TSDB_SQL_SELECT
);
if
(
*
pRequest
==
NULL
)
{
if
(
*
pRequest
==
NULL
)
{
tscError
(
"failed to malloc sqlObj, %s"
,
sql
);
tscError
(
"failed to malloc sqlObj, %s"
,
sql
);
...
@@ -165,7 +166,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
...
@@ -165,7 +166,7 @@ int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param,
strntolower
((
*
pRequest
)
->
sqlstr
,
sql
,
(
int32_t
)
sqlLen
);
strntolower
((
*
pRequest
)
->
sqlstr
,
sql
,
(
int32_t
)
sqlLen
);
(
*
pRequest
)
->
sqlstr
[
sqlLen
]
=
0
;
(
*
pRequest
)
->
sqlstr
[
sqlLen
]
=
0
;
(
*
pRequest
)
->
sqlLen
=
sqlLen
;
(
*
pRequest
)
->
sqlLen
=
sqlLen
;
(
*
pRequest
)
->
validateOnly
=
validateSql
;
(
*
pRequest
)
->
validateOnly
=
validateSql
;
if
(
param
==
NULL
)
{
if
(
param
==
NULL
)
{
...
@@ -351,7 +352,8 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) {
...
@@ -351,7 +352,8 @@ int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList) {
if
(
pNodeList
)
{
if
(
pNodeList
)
{
pInfo
->
pQnodeList
=
taosArrayDup
(
pNodeList
);
pInfo
->
pQnodeList
=
taosArrayDup
(
pNodeList
);
taosArraySort
(
pInfo
->
pQnodeList
,
compareQueryNodeLoad
);
taosArraySort
(
pInfo
->
pQnodeList
,
compareQueryNodeLoad
);
tscDebug
(
"QnodeList updated in cluster 0x%"
PRIx64
", num:%d"
,
pInfo
->
clusterId
,
taosArrayGetSize
(
pInfo
->
pQnodeList
));
tscDebug
(
"QnodeList updated in cluster 0x%"
PRIx64
", num:%d"
,
pInfo
->
clusterId
,
taosArrayGetSize
(
pInfo
->
pQnodeList
));
}
}
taosThreadMutexUnlock
(
&
pInfo
->
qnodeMutex
);
taosThreadMutexUnlock
(
&
pInfo
->
qnodeMutex
);
...
@@ -649,22 +651,22 @@ _return:
...
@@ -649,22 +651,22 @@ _return:
int32_t
scheduleQuery
(
SRequestObj
*
pRequest
,
SQueryPlan
*
pDag
,
SArray
*
pNodeList
)
{
int32_t
scheduleQuery
(
SRequestObj
*
pRequest
,
SQueryPlan
*
pDag
,
SArray
*
pNodeList
)
{
void
*
pTransporter
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
void
*
pTransporter
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
;
SExecResult
res
=
{
0
};
SExecResult
res
=
{
0
};
SRequestConnInfo
conn
=
{.
pTrans
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
SRequestConnInfo
conn
=
{.
pTrans
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
};
.
requestObjRefId
=
pRequest
->
self
};
SSchedulerReq
req
=
{
SSchedulerReq
req
=
{
.
syncReq
=
true
,
.
syncReq
=
true
,
.
pConn
=
&
conn
,
.
pConn
=
&
conn
,
.
pNodeList
=
pNodeList
,
.
pNodeList
=
pNodeList
,
.
pDag
=
pDag
,
.
pDag
=
pDag
,
.
sql
=
pRequest
->
sqlstr
,
.
sql
=
pRequest
->
sqlstr
,
.
startTs
=
pRequest
->
metric
.
start
,
.
startTs
=
pRequest
->
metric
.
start
,
.
execFp
=
NULL
,
.
execFp
=
NULL
,
.
cbParam
=
NULL
,
.
cbParam
=
NULL
,
.
chkKillFp
=
chkRequestKilled
,
.
chkKillFp
=
chkRequestKilled
,
.
chkKillParam
=
(
void
*
)
pRequest
->
self
,
.
chkKillParam
=
(
void
*
)
pRequest
->
self
,
.
pExecRes
=
&
res
,
.
pExecRes
=
&
res
,
};
};
int32_t
code
=
schedulerExecJob
(
&
req
,
&
pRequest
->
body
.
queryJob
);
int32_t
code
=
schedulerExecJob
(
&
req
,
&
pRequest
->
body
.
queryJob
);
...
@@ -778,7 +780,7 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) {
...
@@ -778,7 +780,7 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) {
return
code
;
return
code
;
}
}
SEpSet
epset
=
getEpSet_s
(
&
pAppInfo
->
mgmtEp
);
SEpSet
epset
=
getEpSet_s
(
&
pAppInfo
->
mgmtEp
);
SExecResult
*
pRes
=
&
pRequest
->
body
.
resInfo
.
execRes
;
SExecResult
*
pRes
=
&
pRequest
->
body
.
resInfo
.
execRes
;
switch
(
pRes
->
msgType
)
{
switch
(
pRes
->
msgType
)
{
...
@@ -964,17 +966,17 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
...
@@ -964,17 +966,17 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
SRequestConnInfo
conn
=
{
SRequestConnInfo
conn
=
{
.
pTrans
=
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
};
.
pTrans
=
pAppInfo
->
pTransporter
,
.
requestId
=
pRequest
->
requestId
,
.
requestObjRefId
=
pRequest
->
self
};
SSchedulerReq
req
=
{
SSchedulerReq
req
=
{
.
syncReq
=
false
,
.
syncReq
=
false
,
.
pConn
=
&
conn
,
.
pConn
=
&
conn
,
.
pNodeList
=
pNodeList
,
.
pNodeList
=
pNodeList
,
.
pDag
=
pDag
,
.
pDag
=
pDag
,
.
sql
=
pRequest
->
sqlstr
,
.
sql
=
pRequest
->
sqlstr
,
.
startTs
=
pRequest
->
metric
.
start
,
.
startTs
=
pRequest
->
metric
.
start
,
.
execFp
=
schedulerExecCb
,
.
execFp
=
schedulerExecCb
,
.
cbParam
=
pRequest
,
.
cbParam
=
pRequest
,
.
chkKillFp
=
chkRequestKilled
,
.
chkKillFp
=
chkRequestKilled
,
.
chkKillParam
=
(
void
*
)
pRequest
->
self
,
.
chkKillParam
=
(
void
*
)
pRequest
->
self
,
.
pExecRes
=
NULL
,
.
pExecRes
=
NULL
,
};
};
code
=
schedulerExecJob
(
&
req
,
&
pRequest
->
body
.
queryJob
);
code
=
schedulerExecJob
(
&
req
,
&
pRequest
->
body
.
queryJob
);
taosArrayDestroy
(
pNodeList
);
taosArrayDestroy
(
pNodeList
);
...
@@ -993,6 +995,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
...
@@ -993,6 +995,7 @@ void launchAsyncQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaData* pResultM
pRequest
->
body
.
queryFp
(
pRequest
->
body
.
param
,
pRequest
,
0
);
pRequest
->
body
.
queryFp
(
pRequest
->
body
.
param
,
pRequest
,
0
);
break
;
break
;
default:
default:
pRequest
->
body
.
queryFp
(
pRequest
->
body
.
param
,
pRequest
,
-
1
);
break
;
break
;
}
}
...
@@ -1416,9 +1419,9 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4)
...
@@ -1416,9 +1419,9 @@ void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4)
}
}
SReqResultInfo
*
pResInfo
=
&
pRequest
->
body
.
resInfo
;
SReqResultInfo
*
pResInfo
=
&
pRequest
->
body
.
resInfo
;
SSchedulerReq
req
=
{
SSchedulerReq
req
=
{
.
syncReq
=
true
,
.
syncReq
=
true
,
.
pFetchRes
=
(
void
**
)
&
pResInfo
->
pData
,
.
pFetchRes
=
(
void
**
)
&
pResInfo
->
pData
,
};
};
pRequest
->
code
=
schedulerFetchRows
(
pRequest
->
body
.
queryJob
,
&
req
);
pRequest
->
code
=
schedulerFetchRows
(
pRequest
->
body
.
queryJob
,
&
req
);
if
(
pRequest
->
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
pRequest
->
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
source/libs/function/src/builtins.c
浏览文件 @
4ecbfd07
...
@@ -48,8 +48,8 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
...
@@ -48,8 +48,8 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
return
TIME_UNIT_INVALID
;
return
TIME_UNIT_INVALID
;
}
}
if
(
TSDB_TIME_PRECISION_MILLI
==
dbPrec
&&
(
0
==
strcasecmp
(
pVal
->
literal
,
"1u"
)
||
if
(
TSDB_TIME_PRECISION_MILLI
==
dbPrec
&&
0
==
strcasecmp
(
pVal
->
literal
,
"1b"
)))
{
(
0
==
strcasecmp
(
pVal
->
literal
,
"1u"
)
||
0
==
strcasecmp
(
pVal
->
literal
,
"1b"
)))
{
return
TIME_UNIT_TOO_SMALL
;
return
TIME_UNIT_TOO_SMALL
;
}
}
...
@@ -57,10 +57,9 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
...
@@ -57,10 +57,9 @@ static int32_t validateTimeUnitParam(uint8_t dbPrec, const SValueNode* pVal) {
return
TIME_UNIT_TOO_SMALL
;
return
TIME_UNIT_TOO_SMALL
;
}
}
if
(
pVal
->
literal
[
0
]
!=
'1'
||
(
pVal
->
literal
[
1
]
!=
'u'
&&
pVal
->
literal
[
1
]
!=
'a'
&&
if
(
pVal
->
literal
[
0
]
!=
'1'
||
pVal
->
literal
[
1
]
!=
's'
&&
pVal
->
literal
[
1
]
!=
'm'
&&
(
pVal
->
literal
[
1
]
!=
'u'
&&
pVal
->
literal
[
1
]
!=
'a'
&&
pVal
->
literal
[
1
]
!=
's'
&&
pVal
->
literal
[
1
]
!=
'm'
&&
pVal
->
literal
[
1
]
!=
'h'
&&
pVal
->
literal
[
1
]
!=
'd'
&&
pVal
->
literal
[
1
]
!=
'h'
&&
pVal
->
literal
[
1
]
!=
'd'
&&
pVal
->
literal
[
1
]
!=
'w'
&&
pVal
->
literal
[
1
]
!=
'b'
))
{
pVal
->
literal
[
1
]
!=
'w'
&&
pVal
->
literal
[
1
]
!=
'b'
))
{
return
TIME_UNIT_INVALID
;
return
TIME_UNIT_INVALID
;
}
}
...
@@ -678,9 +677,10 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
...
@@ -678,9 +677,10 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
uint8_t
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
.
type
;
SNode
*
pPara1
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
if
(
TSDB_DATA_TYPE_TIMESTAMP
!=
paraType
)
{
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pPara1
)
||
PRIMARYKEY_TIMESTAMP_COL_ID
!=
((
SColumnNode
*
)
pPara1
)
->
colId
)
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"The first parameter of the ELAPSED function can only be the timestamp primary key"
);
}
}
// param1
// param1
...
@@ -694,8 +694,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
...
@@ -694,8 +694,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
pValue
->
notReserved
=
true
;
pValue
->
notReserved
=
true
;
paraType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
))
->
resType
.
type
;
if
(
!
IS_INTEGER_TYPE
(
pValue
->
node
.
resType
.
type
))
{
if
(
!
IS_INTEGER_TYPE
(
paraType
))
{
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
}
...
@@ -706,8 +705,9 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
...
@@ -706,8 +705,9 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be greater than db precision"
);
"ELAPSED function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
"ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"ELAPSED function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
}
}
...
@@ -1229,7 +1229,8 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
...
@@ -1229,7 +1229,8 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
"STATEDURATION function time unit parameter should be greater than db precision"
);
"STATEDURATION function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
"STATEDURATION function time unit parameter should be one of the following: [1b, 1u, 1a, "
"1s, 1m, 1h, 1d, 1w]"
);
}
}
}
}
...
@@ -1740,8 +1741,9 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
...
@@ -1740,8 +1741,9 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be greater than db precision"
);
"TIMETRUNCATE function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
"TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMETRUNCATE function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
@@ -1779,8 +1781,9 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
...
@@ -1779,8 +1781,9 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be greater than db precision"
);
"TIMEDIFF function time unit parameter should be greater than db precision"
);
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
}
else
if
(
ret
==
TIME_UNIT_INVALID
)
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
return
buildFuncErrMsg
(
"TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"TIMEDIFF function time unit parameter should be one of the following: [1b, 1u, 1a, 1s, 1m, 1h, 1d, 1w]"
);
}
}
}
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
4ecbfd07
...
@@ -1793,7 +1793,7 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
...
@@ -1793,7 +1793,7 @@ static EDealRes classifyConditionImpl(SNode* pNode, void* pContext) {
}
else
if
(
pCol
->
hasIndex
)
{
}
else
if
(
pCol
->
hasIndex
)
{
pCxt
->
hasTagIndexCol
=
true
;
pCxt
->
hasTagIndexCol
=
true
;
pCxt
->
hasTagCol
=
true
;
pCxt
->
hasTagCol
=
true
;
}
else
if
(
COLUMN_TYPE_TAG
==
pCol
->
colType
)
{
}
else
if
(
COLUMN_TYPE_TAG
==
pCol
->
colType
||
COLUMN_TYPE_TBNAME
==
pCol
->
colType
)
{
pCxt
->
hasTagCol
=
true
;
pCxt
->
hasTagCol
=
true
;
}
else
{
}
else
{
pCxt
->
hasOtherCol
=
true
;
pCxt
->
hasOtherCol
=
true
;
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
4ecbfd07
...
@@ -339,6 +339,10 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
...
@@ -339,6 +339,10 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
SNode
*
createPlaceholderValueNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLiteral
)
{
SNode
*
createPlaceholderValueNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLiteral
)
{
CHECK_PARSER_STATUS
(
pCxt
);
CHECK_PARSER_STATUS
(
pCxt
);
if
(
NULL
==
pCxt
->
pQueryCxt
->
pStmtCb
)
{
pCxt
->
errCode
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_SYNTAX_ERROR
,
pLiteral
->
z
);
return
NULL
;
}
SValueNode
*
val
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
SValueNode
*
val
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
CHECK_OUT_OF_MEM
(
val
);
CHECK_OUT_OF_MEM
(
val
);
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
...
...
source/libs/parser/src/parser.c
浏览文件 @
4ecbfd07
...
@@ -41,7 +41,7 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) {
...
@@ -41,7 +41,7 @@ bool qIsInsertValuesSql(const char* pStr, size_t length) {
}
else
if
(
TK_SELECT
==
t
.
type
)
{
}
else
if
(
TK_SELECT
==
t
.
type
)
{
return
false
;
return
false
;
}
}
if
(
0
==
t
.
type
)
{
if
(
0
==
t
.
type
||
0
==
t
.
n
)
{
break
;
break
;
}
}
}
while
(
pStr
-
pSql
<
length
);
}
while
(
pStr
-
pSql
<
length
);
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
4ecbfd07
...
@@ -337,70 +337,69 @@ TEST_F(ParserSelectTest, semanticCheck) {
...
@@ -337,70 +337,69 @@ TEST_F(ParserSelectTest, semanticCheck) {
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
// TSDB_CODE_PAR_INVALID_COLUMN
// TSDB_CODE_PAR_INVALID_COLUMN
run
(
"SELECT c1, cc1 FROM t1"
,
TSDB_CODE_PAR_INVALID_COLUMN
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c1, cc1 FROM t1"
,
TSDB_CODE_PAR_INVALID_COLUMN
);
run
(
"SELECT t1.c1, t1.cc1 FROM t1"
,
TSDB_CODE_PAR_INVALID_COLUMN
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT t1.c1, t1.cc1 FROM t1"
,
TSDB_CODE_PAR_INVALID_COLUMN
);
// TSDB_CODE_PAR_TABLE_NOT_EXIST
// TSDB_CODE_PAR_TABLE_NOT_EXIST
run
(
"SELECT * FROM t10"
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT * FROM t10"
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
);
run
(
"SELECT * FROM test.t10"
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT * FROM test.t10"
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
);
run
(
"SELECT t2.c1 FROM t1"
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT t2.c1 FROM t1"
,
TSDB_CODE_PAR_TABLE_NOT_EXIST
);
// TSDB_CODE_PAR_AMBIGUOUS_COLUMN
// TSDB_CODE_PAR_AMBIGUOUS_COLUMN
run
(
"SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1"
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM t1 tt1, t1 tt2 WHERE tt1.c1 = tt2.c1"
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
);
run
(
"SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)"
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM (SELECT c1 c2, c2 FROM t1)"
,
TSDB_CODE_PAR_AMBIGUOUS_COLUMN
);
// TSDB_CODE_PAR_WRONG_VALUE_TYPE
// TSDB_CODE_PAR_WRONG_VALUE_TYPE
run
(
"SELECT timestamp '2010a' FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT timestamp '2010a' FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
);
run
(
"SELECT LAST(*) + SUM(c1) FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT LAST(*) + SUM(c1) FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
);
run
(
"SELECT CEIL(LAST(ts, c1)) FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT CEIL(LAST(ts, c1)) FROM t1"
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
);
// TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
// TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
run
(
"SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
,
run
(
"SELECT c2 FROM t1 tt1 join t1 tt2 on COUNT(*) > 0"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM t1 WHERE COUNT(*) > 0"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM t1 WHERE COUNT(*) > 0"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
run
(
"SELECT c2 FROM t1 GROUP BY COUNT(*)"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM t1 GROUP BY COUNT(*)"
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
// TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT
// TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT
run
(
"SELECT c2 FROM t1 order by 0"
,
TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM t1 order by 0"
,
TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT
);
run
(
"SELECT c2 FROM t1 order by 2"
,
TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c2 FROM t1 order by 2"
,
TSDB_CODE_PAR_WRONG_NUMBER_OF_SELECT
);
// TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
// TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
run
(
"SELECT COUNT(*) cnt FROM t1 having c1 > 0"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT COUNT(*) cnt FROM t1 having c1 > 0"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
);
run
(
"SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c1 > 0"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
,
run
(
"SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c1 > 0"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
);
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT COUNT(*), c1 cnt FROM t1 GROUP BY c2 having c2 > 0"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
,
run
(
"SELECT COUNT(*), c1 cnt FROM t1 GROUP BY c2 having c2 > 0"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
);
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c2 > 0 order by c1"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
,
run
(
"SELECT COUNT(*) cnt FROM t1 GROUP BY c2 having c2 > 0 order by c1"
,
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
);
PARSER_STAGE_TRANSLATE
);
// TSDB_CODE_PAR_NOT_SINGLE_GROUP
// TSDB_CODE_PAR_NOT_SINGLE_GROUP
run
(
"SELECT COUNT(*), c1 FROM t1"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT COUNT(*), c1 FROM t1"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
run
(
"SELECT COUNT(*) FROM t1 order by c1"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT COUNT(*) FROM t1 order by c1"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
run
(
"SELECT c1 FROM t1 order by COUNT(*)"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
,
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT c1 FROM t1 order by COUNT(*)"
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
// TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
// TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
run
(
"SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts"
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
,
run
(
"SELECT distinct c1, c2 FROM t1 WHERE c1 > 0 order by ts"
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
);
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT distinct c1 FROM t1 WHERE c1 > 0 order by COUNT(c2)"
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
,
run
(
"SELECT distinct c1 FROM t1 WHERE c1 > 0 order by COUNT(c2)"
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
);
PARSER_STAGE_TRANSLATE
);
run
(
"SELECT distinct c2 FROM t1 WHERE c1 > 0 order by COUNT(c2)"
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
,
run
(
"SELECT distinct c2 FROM t1 WHERE c1 > 0 order by COUNT(c2)"
,
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
);
PARSER_STAGE_TRANSLATE
);
}
TEST_F
(
ParserSelectTest
,
syntaxError
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT CAST(? AS BINARY(10)) FROM t1"
,
TSDB_CODE_PAR_SYNTAX_ERROR
,
PARSER_STAGE_PARSE
);
}
}
TEST_F
(
ParserSelectTest
,
setOperator
)
{
TEST_F
(
ParserSelectTest
,
setOperator
)
{
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
4ecbfd07
...
@@ -80,6 +80,23 @@ static void optResetParent(SLogicNode* pNode) {
...
@@ -80,6 +80,23 @@ static void optResetParent(SLogicNode* pNode) {
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
((
SLogicNode
*
)
pChild
)
->
pParent
=
pNode
;
}
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
((
SLogicNode
*
)
pChild
)
->
pParent
=
pNode
;
}
}
}
static
EDealRes
optRebuildTbanme
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
*
pNode
)
&&
COLUMN_TYPE_TBNAME
==
((
SColumnNode
*
)
*
pNode
)
->
colType
)
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
if
(
NULL
==
pFunc
)
{
*
(
int32_t
*
)
pContext
=
TSDB_CODE_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
strcpy
(
pFunc
->
functionName
,
"tbname"
);
pFunc
->
funcType
=
FUNCTION_TYPE_TBNAME
;
pFunc
->
node
.
resType
=
((
SColumnNode
*
)
*
pNode
)
->
node
.
resType
;
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pFunc
;
return
DEAL_RES_IGNORE_CHILD
;
}
return
DEAL_RES_CONTINUE
;
}
EDealRes
scanPathOptHaveNormalColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
EDealRes
scanPathOptHaveNormalColImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
...
@@ -312,6 +329,12 @@ static int32_t pushDownCondOptCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNo
...
@@ -312,6 +329,12 @@ static int32_t pushDownCondOptCalcTimeRange(SOptimizeContext* pCxt, SScanLogicNo
return
code
;
return
code
;
}
}
static
int32_t
pushDownCondOptRebuildTbanme
(
SNode
**
pTagCond
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
nodesRewriteExpr
(
pTagCond
,
optRebuildTbanme
,
&
code
);
return
code
;
}
static
int32_t
pushDownCondOptDealScan
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
)
{
static
int32_t
pushDownCondOptDealScan
(
SOptimizeContext
*
pCxt
,
SScanLogicNode
*
pScan
)
{
if
(
NULL
==
pScan
->
node
.
pConditions
||
if
(
NULL
==
pScan
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
)
||
OPTIMIZE_FLAG_TEST_MASK
(
pScan
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_PUSH_DOWN_CONDE
)
||
...
@@ -323,6 +346,9 @@ static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* p
...
@@ -323,6 +346,9 @@ static int32_t pushDownCondOptDealScan(SOptimizeContext* pCxt, SScanLogicNode* p
SNode
*
pOtherCond
=
NULL
;
SNode
*
pOtherCond
=
NULL
;
int32_t
code
=
nodesPartitionCond
(
&
pScan
->
node
.
pConditions
,
&
pPrimaryKeyCond
,
&
pScan
->
pTagIndexCond
,
&
pScan
->
pTagCond
,
int32_t
code
=
nodesPartitionCond
(
&
pScan
->
node
.
pConditions
,
&
pPrimaryKeyCond
,
&
pScan
->
pTagIndexCond
,
&
pScan
->
pTagCond
,
&
pOtherCond
);
&
pOtherCond
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pScan
->
pTagCond
)
{
code
=
pushDownCondOptRebuildTbanme
(
&
pScan
->
pTagCond
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pPrimaryKeyCond
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
NULL
!=
pPrimaryKeyCond
)
{
code
=
pushDownCondOptCalcTimeRange
(
pCxt
,
pScan
,
&
pPrimaryKeyCond
,
&
pOtherCond
);
code
=
pushDownCondOptCalcTimeRange
(
pCxt
,
pScan
,
&
pPrimaryKeyCond
,
&
pOtherCond
);
}
}
...
@@ -1386,26 +1412,9 @@ static bool partTagsOptMayBeOptimized(SLogicNode* pNode) {
...
@@ -1386,26 +1412,9 @@ static bool partTagsOptMayBeOptimized(SLogicNode* pNode) {
return
!
partTagsOptHasCol
(
partTagsGetPartKeys
(
pNode
))
&&
partTagsOptAreSupportedFuncs
(
partTagsGetFuncs
(
pNode
));
return
!
partTagsOptHasCol
(
partTagsGetPartKeys
(
pNode
))
&&
partTagsOptAreSupportedFuncs
(
partTagsGetFuncs
(
pNode
));
}
}
static
EDealRes
partTagsOptRebuildTbanmeImpl
(
SNode
**
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
*
pNode
)
&&
COLUMN_TYPE_TBNAME
==
((
SColumnNode
*
)
*
pNode
)
->
colType
)
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
if
(
NULL
==
pFunc
)
{
*
(
int32_t
*
)
pContext
=
TSDB_CODE_OUT_OF_MEMORY
;
return
DEAL_RES_ERROR
;
}
strcpy
(
pFunc
->
functionName
,
"tbname"
);
pFunc
->
funcType
=
FUNCTION_TYPE_TBNAME
;
pFunc
->
node
.
resType
=
((
SColumnNode
*
)
*
pNode
)
->
node
.
resType
;
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pFunc
;
return
DEAL_RES_IGNORE_CHILD
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
partTagsOptRebuildTbanme
(
SNodeList
*
pPartKeys
)
{
static
int32_t
partTagsOptRebuildTbanme
(
SNodeList
*
pPartKeys
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
nodesRewriteExprs
(
pPartKeys
,
partTagsOptRebuildTbanmeImpl
,
&
code
);
nodesRewriteExprs
(
pPartKeys
,
optRebuildTbanme
,
&
code
);
return
code
;
return
code
;
}
}
...
...
source/libs/planner/test/planOptimizeTest.cpp
浏览文件 @
4ecbfd07
...
@@ -37,6 +37,8 @@ TEST_F(PlanOptimizeTest, pushDownCondition) {
...
@@ -37,6 +37,8 @@ TEST_F(PlanOptimizeTest, pushDownCondition) {
run
(
"SELECT ts, c1 FROM st1 WHERE tag1 > 4"
);
run
(
"SELECT ts, c1 FROM st1 WHERE tag1 > 4"
);
run
(
"SELECT ts, c1 FROM st1 WHERE TBNAME = 'st1s1'"
);
run
(
"SELECT ts, c1 FROM st1 WHERE tag1 > 4 or tag1 < 2"
);
run
(
"SELECT ts, c1 FROM st1 WHERE tag1 > 4 or tag1 < 2"
);
run
(
"SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello'"
);
run
(
"SELECT ts, c1 FROM st1 WHERE tag1 > 4 AND tag2 = 'hello'"
);
...
...
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
4ecbfd07
...
@@ -330,6 +330,10 @@ class PlannerTestBaseImpl {
...
@@ -330,6 +330,10 @@ class PlannerTestBaseImpl {
cxt
.
pMsg
=
stmtEnv_
.
msgBuf_
.
data
();
cxt
.
pMsg
=
stmtEnv_
.
msgBuf_
.
data
();
cxt
.
msgLen
=
stmtEnv_
.
msgBuf_
.
max_size
();
cxt
.
msgLen
=
stmtEnv_
.
msgBuf_
.
max_size
();
cxt
.
svrVer
=
"3.0.0.0"
;
cxt
.
svrVer
=
"3.0.0.0"
;
if
(
prepare
)
{
SStmtCallback
stmtCb
=
{
0
};
cxt
.
pStmtCb
=
&
stmtCb
;
}
DO_WITH_THROW
(
qParseSql
,
&
cxt
,
pQuery
);
DO_WITH_THROW
(
qParseSql
,
&
cxt
,
pQuery
);
if
(
prepare
)
{
if
(
prepare
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录