Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
72e63195
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
72e63195
编写于
5月 18, 2023
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: optimize order by for partition by clause
上级
5ac91597
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
88 addition
and
14 deletion
+88
-14
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+15
-8
tests/script/tsim/query/partitionby.sim
tests/script/tsim/query/partitionby.sim
+73
-6
未找到文件。
source/libs/planner/src/planLogicCreater.c
浏览文件 @
72e63195
...
...
@@ -37,19 +37,24 @@ typedef struct SRewriteExprCxt {
int32_t
errCode
;
SNodeList
*
pExprs
;
bool
*
pOutputs
;
bool
isPartitionBy
;
}
SRewriteExprCxt
;
static
void
setColumnInfo
(
SFunctionNode
*
pFunc
,
SColumnNode
*
pCol
)
{
static
void
setColumnInfo
(
SFunctionNode
*
pFunc
,
SColumnNode
*
pCol
,
bool
isPartitionBy
)
{
switch
(
pFunc
->
funcType
)
{
case
FUNCTION_TYPE_TBNAME
:
pCol
->
colType
=
COLUMN_TYPE_TBNAME
;
break
;
case
FUNCTION_TYPE_WSTART
:
pCol
->
colId
=
PRIMARYKEY_TIMESTAMP_COL_ID
;
if
(
!
isPartitionBy
)
{
pCol
->
colId
=
PRIMARYKEY_TIMESTAMP_COL_ID
;
}
pCol
->
colType
=
COLUMN_TYPE_WINDOW_START
;
break
;
case
FUNCTION_TYPE_WEND
:
pCol
->
colId
=
PRIMARYKEY_TIMESTAMP_COL_ID
;
if
(
!
isPartitionBy
)
{
pCol
->
colId
=
PRIMARYKEY_TIMESTAMP_COL_ID
;
}
pCol
->
colType
=
COLUMN_TYPE_WINDOW_END
;
break
;
case
FUNCTION_TYPE_WDURATION
:
...
...
@@ -103,7 +108,7 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
strcpy
(
pCol
->
node
.
userAlias
,
((
SExprNode
*
)
pExpr
)
->
userAlias
);
strcpy
(
pCol
->
colName
,
((
SExprNode
*
)
pExpr
)
->
aliasName
);
if
(
QUERY_NODE_FUNCTION
==
nodeType
(
pExpr
))
{
setColumnInfo
((
SFunctionNode
*
)
pExpr
,
pCol
);
setColumnInfo
((
SFunctionNode
*
)
pExpr
,
pCol
,
pCxt
->
isPartitionBy
);
}
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pCol
;
...
...
@@ -142,7 +147,8 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
static
int32_t
rewriteExprForSelect
(
SNode
*
pExpr
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
nodesWalkExpr
(
pExpr
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
NULL
,
.
pOutputs
=
NULL
};
bool
isPartitionBy
=
(
pSelect
->
pPartitionByList
&&
pSelect
->
pPartitionByList
->
length
>
0
)
?
true
:
false
;
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
NULL
,
.
pOutputs
=
NULL
,
.
isPartitionBy
=
isPartitionBy
};
cxt
.
errCode
=
nodesListMakeAppend
(
&
cxt
.
pExprs
,
pExpr
);
if
(
TSDB_CODE_SUCCESS
==
cxt
.
errCode
)
{
nodesRewriteSelectStmt
(
pSelect
,
clause
,
doRewriteExpr
,
&
cxt
);
...
...
@@ -170,7 +176,8 @@ static int32_t cloneRewriteExprs(SNodeList* pExprs, bool* pOutputs, SNodeList**
static
int32_t
rewriteExprsForSelect
(
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
SNodeList
**
pRewriteExprs
)
{
nodesWalkExprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
};
bool
isPartitionBy
=
(
pSelect
->
pPartitionByList
&&
pSelect
->
pPartitionByList
->
length
>
0
)
?
true
:
false
;
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
,
.
isPartitionBy
=
isPartitionBy
};
if
(
NULL
!=
pRewriteExprs
)
{
cxt
.
pOutputs
=
taosMemoryCalloc
(
LIST_LENGTH
(
pExprs
),
sizeof
(
bool
));
if
(
NULL
==
cxt
.
pOutputs
)
{
...
...
@@ -187,14 +194,14 @@ static int32_t rewriteExprsForSelect(SNodeList* pExprs, SSelectStmt* pSelect, ES
static
int32_t
rewriteExpr
(
SNodeList
*
pExprs
,
SNode
**
pTarget
)
{
nodesWalkExprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
};
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
,
.
isPartitionBy
=
false
};
nodesRewriteExpr
(
pTarget
,
doRewriteExpr
,
&
cxt
);
return
cxt
.
errCode
;
}
static
int32_t
rewriteExprs
(
SNodeList
*
pExprs
,
SNodeList
*
pTarget
)
{
nodesWalkExprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
};
SRewriteExprCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
,
.
pOutputs
=
NULL
,
.
isPartitionBy
=
false
};
nodesRewriteExprs
(
pTarget
,
doRewriteExpr
,
&
cxt
);
return
cxt
.
errCode
;
}
...
...
tests/script/tsim/query/partitionby.sim
浏览文件 @
72e63195
...
...
@@ -24,16 +24,83 @@ sql use $db
sql create table $mt1 (ts timestamp, f1 int) TAGS(tag1 int, tag2 binary(500))
sql create table tb0 using $mt1 tags(0, 'a');
sql create table tb1 using $mt1 tags(1, 'b');
sql create table tb2 using $mt1 tags(
1
, 'a');
sql create table tb3 using $mt1 tags(
1
, 'a');
sql create table tb4 using $mt1 tags(
3
, 'b');
sql create table tb5 using $mt1 tags(
3
, 'a');
sql create table tb6 using $mt1 tags(
3
, 'b');
sql create table tb7 using $mt1 tags(
3
, 'b');
sql create table tb2 using $mt1 tags(
2
, 'a');
sql create table tb3 using $mt1 tags(
3
, 'a');
sql create table tb4 using $mt1 tags(
4
, 'b');
sql create table tb5 using $mt1 tags(
5
, 'a');
sql create table tb6 using $mt1 tags(
6
, 'b');
sql create table tb7 using $mt1 tags(
7
, 'b');
sql select * from $mt1 partition by tag1,tag2 limit 1;
if $rows != 0 then
return -1
endi
sql insert into tb0 values ('2022-04-26 15:15:08', 1);
sql insert into tb1 values ('2022-04-26 15:15:07', 2);
sql insert into tb2 values ('2022-04-26 15:15:06', 3);
sql insert into tb3 values ('2022-04-26 15:15:05', 4);
sql insert into tb4 values ('2022-04-26 15:15:04', 5);
sql insert into tb5 values ('2022-04-26 15:15:03', 6);
sql insert into tb6 values ('2022-04-26 15:15:02', 7);
sql insert into tb7 values ('2022-04-26 15:15:01', 8);
sql select _wstart as ts, count(*) from $mt1 partition by tag1 interval(1s) order by _wstart;
if $rows != 8 then
return -1
endi
if $data00 != @22-04-26 15:15:01.000@ then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data10 != @22-04-26 15:15:02.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data20 != @22-04-26 15:15:03.000@ then
return -1
endi
if $data21 != 1 then
return -1
endi
if $data30 != @22-04-26 15:15:04.000@ then
return -1
endi
if $data31 != 1 then
return -1
endi
if $data40 != @22-04-26 15:15:05.000@ then
return -1
endi
if $data41 != 1 then
return -1
endi
if $data50 != @22-04-26 15:15:06.000@ then
return -1
endi
if $data51 != 1 then
return -1
endi
if $data60 != @22-04-26 15:15:07.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @22-04-26 15:15:08.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
sql select * from (select _wstart as ts, count(*) from $mt1 partition by tag1 interval(1s) order by _wstart) order by ts;
sql select _wstart as ts, count(*) from $mt1 interval(1s) order by _wstart;
sql select * from (select _wstart as ts, count(*) from $mt1 interval(1s) order by _wstart) order by ts;
sql select diff(a) from (select _wstart as ts, count(*) a from $mt1 interval(1s) order by _wstart);
sql select diff(a) from (select _wstart as ts, count(*) a from $mt1 partition by tag1 interval(1s) order by _wstart);
system sh/exec.sh -n dnode1 -s stop -x SIGINT
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录