Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
74fb0f4b
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,发现更多精彩内容 >>
提交
74fb0f4b
编写于
4月 24, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: order by primary key optimize
上级
809a78b0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
124 addition
and
25 deletion
+124
-25
include/libs/planner/planner.h
include/libs/planner/planner.h
+2
-0
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+3
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+45
-20
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+2
-0
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+71
-4
未找到文件。
include/libs/planner/planner.h
浏览文件 @
74fb0f4b
...
...
@@ -37,6 +37,8 @@ typedef struct SPlanContext {
bool
isStmtQuery
;
void
*
pTransporter
;
struct
SCatalog
*
pCatalog
;
char
*
pMsg
;
int32_t
msgLen
;
}
SPlanContext
;
// Create the physical plan for the query, according to the AST.
...
...
include/util/taoserror.h
浏览文件 @
74fb0f4b
...
...
@@ -623,6 +623,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_PAR_INVALID_DAYS_VALUE TAOS_DEF_ERROR_CODE(0, 0x2636)
#define TSDB_CODE_PAR_OFFSET_LESS_ZERO TAOS_DEF_ERROR_CODE(0, 0x2637)
#define TSDB_CODE_PAR_SLIMIT_LEAK_PARTITION_BY TAOS_DEF_ERROR_CODE(0, 0x2638)
#define TSDB_CODE_PAR_INVALID_TOPIC_QUERY TAOS_DEF_ERROR_CODE(0, 0x2639)
//planner
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
...
...
source/client/src/clientImpl.c
浏览文件 @
74fb0f4b
...
...
@@ -232,7 +232,9 @@ int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArra
.
mgmtEpSet
=
getEpSet_s
(
&
pRequest
->
pTscObj
->
pAppInfo
->
mgmtEp
),
.
pAstRoot
=
pQuery
->
pRoot
,
.
showRewrite
=
pQuery
->
showRewrite
,
.
pTransporter
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
.
pTransporter
=
pRequest
->
pTscObj
->
pAppInfo
->
pTransporter
,
.
pMsg
=
pRequest
->
msgBuf
,
.
msgLen
=
ERROR_MSG_BUF_DEFAULT_SIZE
};
int32_t
code
=
catalogGetHandle
(
pRequest
->
pTscObj
->
pAppInfo
->
clusterId
,
&
cxt
.
pCatalog
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
74fb0f4b
...
...
@@ -2614,37 +2614,62 @@ static int32_t translateDropComponentNode(STranslateContext* pCxt, SDropComponen
(
FSerializeFunc
)
tSerializeSCreateDropMQSBNodeReq
,
&
dropReq
);
}
static
int32_t
translateCreateTopic
(
STranslateContext
*
pCxt
,
SCreateTopicStmt
*
pStmt
)
{
SCMCreateTopicReq
createReq
=
{
0
};
static
int32_t
buildCreateTopicReq
(
STranslateContext
*
pCxt
,
SCreateTopicStmt
*
pStmt
,
SCMCreateTopicReq
*
pReq
)
{
SName
name
;
// tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->topicName, strlen(pStmt->topicName));
// tNameGetFullDbName(&name, pReq->name);
tNameExtractFullName
(
toName
(
pCxt
->
pParseCxt
->
acctId
,
pCxt
->
pParseCxt
->
db
,
pStmt
->
topicName
,
&
name
),
pReq
->
name
);
pReq
->
igExists
=
pStmt
->
ignoreExists
;
pReq
->
withTbName
=
pStmt
->
pOptions
->
withTable
;
pReq
->
withSchema
=
pStmt
->
pOptions
->
withSchema
;
pReq
->
withTag
=
pStmt
->
pOptions
->
withTag
;
pReq
->
sql
=
strdup
(
pCxt
->
pParseCxt
->
pSql
);
if
(
NULL
==
pReq
->
sql
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
NULL
!=
pStmt
->
pQuery
)
{
strcpy
(
pReq
->
subscribeDbName
,
((
SRealTableNode
*
)(((
SSelectStmt
*
)
pStmt
->
pQuery
)
->
pFromTable
))
->
table
.
dbName
);
pCxt
->
pParseCxt
->
topicQuery
=
true
;
int32_t
code
=
translateQuery
(
pCxt
,
pStmt
->
pQuery
);
code
=
translateQuery
(
pCxt
,
pStmt
->
pQuery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesNodeToString
(
pStmt
->
pQuery
,
false
,
&
createReq
.
ast
,
NULL
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
code
=
nodesNodeToString
(
pStmt
->
pQuery
,
false
,
&
pReq
->
ast
,
NULL
);
}
}
else
{
strcpy
(
createReq
.
subscribeDbName
,
pStmt
->
subscribeDbName
);
strcpy
(
pReq
->
subscribeDbName
,
pStmt
->
subscribeDbName
);
}
createReq
.
sql
=
strdup
(
pCxt
->
pParseCxt
->
pSql
);
if
(
NULL
==
createReq
.
sql
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
code
;
}
static
int32_t
checkCreateTopic
(
STranslateContext
*
pCxt
,
SCreateTopicStmt
*
pStmt
)
{
if
(
NULL
==
pStmt
->
pQuery
)
{
return
TSDB_CODE_SUCCESS
;
}
SName
name
;
// tNameSetDbName(&name, pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, strlen(pCxt->pParseCxt->db));
// tNameGetFullDbName(&name, createReq.name);
tNameExtractFullName
(
toName
(
pCxt
->
pParseCxt
->
acctId
,
pCxt
->
pParseCxt
->
db
,
pStmt
->
topicName
,
&
name
),
createReq
.
name
);
createReq
.
igExists
=
pStmt
->
ignoreExists
;
createReq
.
withTbName
=
pStmt
->
pOptions
->
withTable
;
createReq
.
withSchema
=
pStmt
->
pOptions
->
withSchema
;
createReq
.
withTag
=
pStmt
->
pOptions
->
withTag
;
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
->
pQuery
))
{
SSelectStmt
*
pSelect
=
(
SSelectStmt
*
)
pStmt
->
pQuery
;
if
(
!
pSelect
->
isDistinct
&&
QUERY_NODE_REAL_TABLE
==
nodeType
(
pSelect
->
pFromTable
)
&&
NULL
==
pSelect
->
pGroupByList
&&
NULL
==
pSelect
->
pLimit
&&
NULL
==
pSelect
->
pSlimit
&&
NULL
==
pSelect
->
pOrderByList
&&
NULL
==
pSelect
->
pPartitionByList
)
{
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
code
=
buildCmdMsg
(
pCxt
,
TDMT_MND_CREATE_TOPIC
,
(
FSerializeFunc
)
tSerializeSCMCreateTopicReq
,
&
createReq
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TOPIC_QUERY
);
}
static
int32_t
translateCreateTopic
(
STranslateContext
*
pCxt
,
SCreateTopicStmt
*
pStmt
)
{
SCMCreateTopicReq
createReq
=
{
0
};
int32_t
code
=
checkCreateTopic
(
pCxt
,
pStmt
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCreateTopicReq
(
pCxt
,
pStmt
,
&
createReq
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
buildCmdMsg
(
pCxt
,
TDMT_MND_CREATE_TOPIC
,
(
FSerializeFunc
)
tSerializeSCMCreateTopicReq
,
&
createReq
);
}
tFreeSCMCreateTopicReq
(
&
createReq
);
return
code
;
}
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
74fb0f4b
...
...
@@ -128,6 +128,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
return
"soffset/offset can not be less than 0"
;
case
TSDB_CODE_PAR_SLIMIT_LEAK_PARTITION_BY
:
return
"slimit/soffset only available for PARTITION BY query"
;
case
TSDB_CODE_PAR_INVALID_TOPIC_QUERY
:
return
"Invalid topic query"
;
case
TSDB_CODE_OUT_OF_MEMORY
:
return
"Out of memory"
;
default:
...
...
source/libs/planner/src/planOptimizer.c
浏览文件 @
74fb0f4b
...
...
@@ -27,6 +27,7 @@
#define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
typedef
struct
SOptimizeContext
{
SPlanContext
*
pPlanCxt
;
bool
optimized
;
}
SOptimizeContext
;
...
...
@@ -515,11 +516,76 @@ static int32_t cpdPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SN
return
TSDB_CODE_PLAN_INTERNAL_ERROR
;
}
static
bool
cpdIsPrimaryKey
(
SNode
*
pNode
,
SNodeList
*
pTableCols
)
{
if
(
QUERY_NODE_COLUMN
!=
nodeType
(
pNode
))
{
return
false
;
}
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pNode
;
if
(
PRIMARYKEY_TIMESTAMP_COL_ID
!=
pCol
->
colId
)
{
return
false
;
}
return
cpdBelongThisTable
(
pNode
,
pTableCols
);
}
static
bool
cpdIsPrimaryKeyEqualCond
(
SJoinLogicNode
*
pJoin
,
SNode
*
pCond
)
{
if
(
QUERY_NODE_OPERATOR
!=
nodeType
(
pCond
))
{
return
false
;
}
SNodeList
*
pLeftCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
0
))
->
pTargets
;
SNodeList
*
pRightCols
=
((
SLogicNode
*
)
nodesListGetNode
(
pJoin
->
node
.
pChildren
,
1
))
->
pTargets
;
SOperatorNode
*
pOper
=
(
SOperatorNode
*
)
pJoin
->
pOnConditions
;
if
(
cpdIsPrimaryKey
(
pOper
->
pLeft
,
pLeftCols
))
{
return
cpdIsPrimaryKey
(
pOper
->
pRight
,
pRightCols
);
}
else
if
(
cpdIsPrimaryKey
(
pOper
->
pLeft
,
pRightCols
))
{
return
cpdIsPrimaryKey
(
pOper
->
pRight
,
pLeftCols
);
}
return
false
;
}
static
int32_t
cpdCheckOpCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SNode
*
pOnCond
)
{
if
(
!
cpdIsPrimaryKeyEqualCond
(
pJoin
,
pOnCond
))
{
snprintf
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
"l.ts = r.ts is expected in join expression"
);
return
TSDB_CODE_FAILED
;
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdCheckLogicCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
,
SLogicConditionNode
*
pOnCond
)
{
if
(
LOGIC_COND_TYPE_AND
!=
pOnCond
->
condType
)
{
snprintf
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
"l.ts = r.ts is expected in join expression"
);
return
TSDB_CODE_FAILED
;
}
SNode
*
pCond
=
NULL
;
FOREACH
(
pCond
,
pOnCond
->
pParameterList
)
{
if
(
!
cpdIsPrimaryKeyEqualCond
(
pJoin
,
pCond
))
{
snprintf
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
"l.ts = r.ts is expected in join expression"
);
return
TSDB_CODE_FAILED
;
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
cpdCheckJoinOnCond
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
NULL
==
pJoin
->
pOnConditions
)
{
snprintf
(
pCxt
->
pPlanCxt
->
pMsg
,
pCxt
->
pPlanCxt
->
msgLen
,
"not support cross join"
);
return
TSDB_CODE_FAILED
;
}
if
(
QUERY_NODE_LOGIC_CONDITION
==
nodeType
(
pJoin
->
pOnConditions
))
{
return
cpdCheckLogicCond
(
pCxt
,
pJoin
,
(
SLogicConditionNode
*
)
pJoin
->
pOnConditions
);
}
else
{
return
cpdCheckOpCond
(
pCxt
,
pJoin
,
pJoin
->
pOnConditions
);
}
}
static
int32_t
cpdPushJoinCondition
(
SOptimizeContext
*
pCxt
,
SJoinLogicNode
*
pJoin
)
{
if
(
NULL
==
pJoin
->
node
.
pConditions
||
OPTIMIZE_FLAG_TEST_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_CPD
))
{
if
(
OPTIMIZE_FLAG_TEST_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_CPD
))
{
return
TSDB_CODE_SUCCESS
;
}
if
(
NULL
==
pJoin
->
node
.
pConditions
)
{
return
cpdCheckJoinOnCond
(
pCxt
,
pJoin
);
}
SNode
*
pOnCond
=
NULL
;
SNode
*
pLeftChildCond
=
NULL
;
SNode
*
pRightChildCond
=
NULL
;
...
...
@@ -537,6 +603,7 @@ static int32_t cpdPushJoinCondition(SOptimizeContext* pCxt, SJoinLogicNode* pJoi
if
(
TSDB_CODE_SUCCESS
==
code
)
{
OPTIMIZE_FLAG_SET_MASK
(
pJoin
->
node
.
optimizedFlag
,
OPTIMIZE_FLAG_CPD
);
pCxt
->
optimized
=
true
;
code
=
cpdCheckJoinOnCond
(
pCxt
,
pJoin
);
}
else
{
nodesDestroyNode
(
pOnCond
);
nodesDestroyNode
(
pLeftChildCond
);
...
...
@@ -703,8 +770,8 @@ static const SOptimizeRule optimizeRuleSet[] = {
static
const
int32_t
optimizeRuleNum
=
(
sizeof
(
optimizeRuleSet
)
/
sizeof
(
SOptimizeRule
));
static
int32_t
applyOptimizeRule
(
SLogicNode
*
pLogicNode
)
{
SOptimizeContext
cxt
=
{
.
optimized
=
false
};
static
int32_t
applyOptimizeRule
(
S
PlanContext
*
pCxt
,
S
LogicNode
*
pLogicNode
)
{
SOptimizeContext
cxt
=
{
.
pPlanCxt
=
pCxt
,
.
optimized
=
false
};
do
{
cxt
.
optimized
=
false
;
for
(
int32_t
i
=
0
;
i
<
optimizeRuleNum
;
++
i
)
{
...
...
@@ -718,5 +785,5 @@ static int32_t applyOptimizeRule(SLogicNode* pLogicNode) {
}
int32_t
optimizeLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
)
{
return
applyOptimizeRule
(
pLogicNode
);
return
applyOptimizeRule
(
p
Cxt
,
p
LogicNode
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录