Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5972ee30
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看板
未验证
提交
5972ee30
编写于
4月 09, 2022
作者:
X
Xiaoyu Wang
提交者:
GitHub
4月 09, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11332 from taosdata/feature/3.0_wxy
constant condition optimize
上级
cd8a0e89
9df566b2
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
78 addition
and
25 deletion
+78
-25
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+8
-2
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+24
-11
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+39
-8
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+1
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+5
-3
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
5972ee30
...
@@ -238,6 +238,7 @@ typedef struct SSelectStmt {
...
@@ -238,6 +238,7 @@ typedef struct SSelectStmt {
SNode
*
pSlimit
;
SNode
*
pSlimit
;
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
uint8_t
precision
;
bool
isEmptyResult
;
}
SSelectStmt
;
}
SSelectStmt
;
typedef
enum
ESetOperatorType
{
typedef
enum
ESetOperatorType
{
...
...
include/libs/parser/parser.h
浏览文件 @
5972ee30
...
@@ -44,8 +44,15 @@ typedef struct SCmdMsgInfo {
...
@@ -44,8 +44,15 @@ typedef struct SCmdMsgInfo {
void
*
pExtension
;
// todo remove it soon
void
*
pExtension
;
// todo remove it soon
}
SCmdMsgInfo
;
}
SCmdMsgInfo
;
typedef
enum
EQueryExecMode
{
QUERY_EXEC_MODE_LOCAL
=
1
,
QUERY_EXEC_MODE_RPC
,
QUERY_EXEC_MODE_SCHEDULE
,
QUERY_EXEC_MODE_EMPTY_RESULT
}
EQueryExecMode
;
typedef
struct
SQuery
{
typedef
struct
SQuery
{
bool
directRpc
;
EQueryExecMode
execMode
;
bool
haveResultSet
;
bool
haveResultSet
;
SNode
*
pRoot
;
SNode
*
pRoot
;
int32_t
numOfResCols
;
int32_t
numOfResCols
;
...
@@ -55,7 +62,6 @@ typedef struct SQuery {
...
@@ -55,7 +62,6 @@ typedef struct SQuery {
SArray
*
pDbList
;
SArray
*
pDbList
;
SArray
*
pTableList
;
SArray
*
pTableList
;
bool
showRewrite
;
bool
showRewrite
;
bool
localCmd
;
}
SQuery
;
}
SQuery
;
int32_t
qParseQuerySql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
);
int32_t
qParseQuerySql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
);
...
...
source/client/src/clientImpl.c
浏览文件 @
5972ee30
...
@@ -281,22 +281,35 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
...
@@ -281,22 +281,35 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
SRequestObj
*
execQueryImpl
(
STscObj
*
pTscObj
,
const
char
*
sql
,
int
sqlLen
)
{
SRequestObj
*
execQueryImpl
(
STscObj
*
pTscObj
,
const
char
*
sql
,
int
sqlLen
)
{
SRequestObj
*
pRequest
=
NULL
;
SRequestObj
*
pRequest
=
NULL
;
SQuery
*
pQuery
=
NULL
;
SQuery
*
pQuery
=
NULL
;
int32_t
code
=
0
;
SArray
*
pNodeList
=
taosArrayInit
(
4
,
sizeof
(
struct
SQueryNodeAddr
));
SArray
*
pNodeList
=
taosArrayInit
(
4
,
sizeof
(
struct
SQueryNodeAddr
));
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
int32_t
code
=
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
);
CHECK_CODE_GOTO
(
parseSql
(
pRequest
,
false
,
&
pQuery
),
_return
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
parseSql
(
pRequest
,
false
,
&
pQuery
);
}
if
(
pQuery
->
localCmd
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
CHECK_CODE_GOTO
(
execLocalCmd
(
pRequest
,
pQuery
),
_return
);
switch
(
pQuery
->
execMode
)
{
}
else
if
(
pQuery
->
directRpc
)
{
case
QUERY_EXEC_MODE_LOCAL
:
CHECK_CODE_GOTO
(
execDdlQuery
(
pRequest
,
pQuery
),
_return
);
code
=
execLocalCmd
(
pRequest
,
pQuery
);
}
else
{
break
;
CHECK_CODE_GOTO
(
getPlan
(
pRequest
,
pQuery
,
&
pRequest
->
body
.
pDag
,
pNodeList
),
_return
);
case
QUERY_EXEC_MODE_RPC
:
CHECK_CODE_GOTO
(
scheduleQuery
(
pRequest
,
pRequest
->
body
.
pDag
,
pNodeList
),
_return
);
code
=
execDdlQuery
(
pRequest
,
pQuery
);
break
;
case
QUERY_EXEC_MODE_SCHEDULE
:
code
=
getPlan
(
pRequest
,
pQuery
,
&
pRequest
->
body
.
pDag
,
pNodeList
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
scheduleQuery
(
pRequest
,
pRequest
->
body
.
pDag
,
pNodeList
);
}
break
;
case
QUERY_EXEC_MODE_EMPTY_RESULT
:
pRequest
->
type
=
TSDB_SQL_RETRIEVE_EMPTY_RESULT
;
break
;
default:
break
;
}
}
}
_return:
taosArrayDestroy
(
pNodeList
);
taosArrayDestroy
(
pNodeList
);
qDestroyQuery
(
pQuery
);
qDestroyQuery
(
pQuery
);
if
(
NULL
!=
pRequest
&&
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
NULL
!=
pRequest
&&
TSDB_CODE_SUCCESS
!=
code
)
{
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
5972ee30
...
@@ -149,22 +149,37 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab
...
@@ -149,22 +149,37 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab
return
pCxt
->
code
;
return
pCxt
->
code
;
}
}
static
void
rewriteConstCondition
(
SSelectStmt
*
pSelect
,
SNode
**
pCond
)
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
*
pCond
))
{
return
;
}
if
(((
SValueNode
*
)
*
pCond
)
->
datum
.
b
)
{
nodesDestroyNode
(
*
pCond
);
*
pCond
=
NULL
;
}
else
{
pSelect
->
isEmptyResult
=
true
;
}
}
static
int32_t
calcConstFromTable
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
static
int32_t
calcConstFromTable
(
SCalcConstContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
nodesRewriteExprPostOrder
(
&
pSelect
->
pFromTable
,
calcConst
,
pCxt
);
pCxt
->
code
=
rewriteConditionForFromTable
(
pCxt
,
pSelect
->
pFromTable
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
pCxt
->
code
=
rewriteConditionForFromTable
(
pCxt
,
pSelect
->
pFromTable
);
nodesRewriteExprPostOrder
(
&
pSelect
->
pFromTable
,
calcConst
,
pCxt
);
}
}
return
pCxt
->
code
;
return
pCxt
->
code
;
}
}
static
int32_t
calcConstCondition
(
SCalcConstContext
*
pCxt
,
SNode
**
pCond
)
{
static
int32_t
calcConstCondition
(
SCalcConstContext
*
pCxt
,
S
SelectStmt
*
pSelect
,
S
Node
**
pCond
)
{
if
(
NULL
==
*
pCond
)
{
if
(
NULL
==
*
pCond
)
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
nodesRewriteExprPostOrder
(
pCond
,
calcConst
,
pCxt
);
pCxt
->
code
=
rewriteCondition
(
pCxt
,
pCond
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
pCxt
->
code
=
rewriteCondition
(
pCxt
,
pCond
);
nodesRewriteExprPostOrder
(
pCond
,
calcConst
,
pCxt
);
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
)
{
rewriteConstCondition
(
pSelect
,
pCond
);
}
}
return
pCxt
->
code
;
return
pCxt
->
code
;
}
}
...
@@ -176,7 +191,7 @@ static int32_t calcConstSelect(SSelectStmt* pSelect) {
...
@@ -176,7 +191,7 @@ static int32_t calcConstSelect(SSelectStmt* pSelect) {
cxt
.
code
=
calcConstFromTable
(
&
cxt
,
pSelect
);
cxt
.
code
=
calcConstFromTable
(
&
cxt
,
pSelect
);
}
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
cxt
.
code
=
calcConstCondition
(
&
cxt
,
&
pSelect
->
pWhere
);
cxt
.
code
=
calcConstCondition
(
&
cxt
,
pSelect
,
&
pSelect
->
pWhere
);
}
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pPartitionByList
,
calcConst
,
&
cxt
);
nodesRewriteExprsPostOrder
(
pSelect
->
pPartitionByList
,
calcConst
,
&
cxt
);
...
@@ -188,7 +203,7 @@ static int32_t calcConstSelect(SSelectStmt* pSelect) {
...
@@ -188,7 +203,7 @@ static int32_t calcConstSelect(SSelectStmt* pSelect) {
nodesRewriteExprsPostOrder
(
pSelect
->
pGroupByList
,
calcConst
,
&
cxt
);
nodesRewriteExprsPostOrder
(
pSelect
->
pGroupByList
,
calcConst
,
&
cxt
);
}
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
cxt
.
code
=
calcConstCondition
(
&
cxt
,
&
pSelect
->
pHaving
);
cxt
.
code
=
calcConstCondition
(
&
cxt
,
pSelect
,
&
pSelect
->
pHaving
);
}
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pOrderByList
,
calcConst
,
&
cxt
);
nodesRewriteExprsPostOrder
(
pSelect
->
pOrderByList
,
calcConst
,
&
cxt
);
...
@@ -208,6 +223,22 @@ static int32_t calcConstQuery(SNode* pStmt) {
...
@@ -208,6 +223,22 @@ static int32_t calcConstQuery(SNode* pStmt) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
bool
isEmptyResultQuery
(
SNode
*
pStmt
)
{
switch
(
nodeType
(
pStmt
))
{
case
QUERY_NODE_SELECT_STMT
:
return
((
SSelectStmt
*
)
pStmt
)
->
isEmptyResult
;
case
QUERY_NODE_EXPLAIN_STMT
:
return
isEmptyResultQuery
(((
SExplainStmt
*
)
pStmt
)
->
pQuery
);
default:
break
;
}
return
false
;
}
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
return
calcConstQuery
(
pQuery
->
pRoot
);
int32_t
code
=
calcConstQuery
(
pQuery
->
pRoot
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
pQuery
->
execMode
=
isEmptyResultQuery
(
pQuery
->
pRoot
)
?
QUERY_EXEC_MODE_EMPTY_RESULT
:
pQuery
->
execMode
;
}
return
code
;
}
}
source/libs/parser/src/parInsert.c
浏览文件 @
5972ee30
...
@@ -1084,7 +1084,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
...
@@ -1084,7 +1084,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) {
if
(
NULL
==
*
pQuery
)
{
if
(
NULL
==
*
pQuery
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
(
*
pQuery
)
->
directRpc
=
false
;
(
*
pQuery
)
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
(
*
pQuery
)
->
haveResultSet
=
false
;
(
*
pQuery
)
->
haveResultSet
=
false
;
(
*
pQuery
)
->
msgType
=
TDMT_VND_SUBMIT
;
(
*
pQuery
)
->
msgType
=
TDMT_VND_SUBMIT
;
(
*
pQuery
)
->
pRoot
=
(
SNode
*
)
context
.
pOutput
;
(
*
pQuery
)
->
pRoot
=
(
SNode
*
)
context
.
pOutput
;
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
5972ee30
...
@@ -2923,21 +2923,23 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
...
@@ -2923,21 +2923,23 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
switch
(
nodeType
(
pQuery
->
pRoot
))
{
switch
(
nodeType
(
pQuery
->
pRoot
))
{
case
QUERY_NODE_SELECT_STMT
:
case
QUERY_NODE_SELECT_STMT
:
case
QUERY_NODE_EXPLAIN_STMT
:
case
QUERY_NODE_EXPLAIN_STMT
:
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
haveResultSet
=
true
;
pQuery
->
haveResultSet
=
true
;
pQuery
->
msgType
=
TDMT_VND_QUERY
;
pQuery
->
msgType
=
TDMT_VND_QUERY
;
break
;
break
;
case
QUERY_NODE_VNODE_MODIF_STMT
:
case
QUERY_NODE_VNODE_MODIF_STMT
:
pQuery
->
execMode
=
QUERY_EXEC_MODE_SCHEDULE
;
pQuery
->
msgType
=
TDMT_VND_CREATE_TABLE
;
pQuery
->
msgType
=
TDMT_VND_CREATE_TABLE
;
break
;
break
;
case
QUERY_NODE_DESCRIBE_STMT
:
case
QUERY_NODE_DESCRIBE_STMT
:
pQuery
->
localCmd
=
true
;
pQuery
->
execMode
=
QUERY_EXEC_MODE_LOCAL
;
pQuery
->
haveResultSet
=
true
;
pQuery
->
haveResultSet
=
true
;
break
;
break
;
case
QUERY_NODE_RESET_QUERY_CACHE_STMT
:
case
QUERY_NODE_RESET_QUERY_CACHE_STMT
:
pQuery
->
localCmd
=
true
;
pQuery
->
execMode
=
QUERY_EXEC_MODE_LOCAL
;
break
;
break
;
default:
default:
pQuery
->
directRpc
=
true
;
pQuery
->
execMode
=
QUERY_EXEC_MODE_RPC
;
if
(
NULL
!=
pCxt
->
pCmdMsg
)
{
if
(
NULL
!=
pCxt
->
pCmdMsg
)
{
TSWAP
(
pQuery
->
pCmdMsg
,
pCxt
->
pCmdMsg
,
SCmdMsgInfo
*
);
TSWAP
(
pQuery
->
pCmdMsg
,
pCxt
->
pCmdMsg
,
SCmdMsgInfo
*
);
pQuery
->
msgType
=
pQuery
->
pCmdMsg
->
msgType
;
pQuery
->
msgType
=
pQuery
->
pCmdMsg
->
msgType
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录