Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6185c3d2
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看板
提交
6185c3d2
编写于
10月 19, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support invertal+group by tag in subquery
上级
6c4dd103
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
433 addition
and
2 deletion
+433
-2
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+1
-0
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+20
-0
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+14
-0
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+1
-0
src/query/inc/qTableMeta.h
src/query/inc/qTableMeta.h
+2
-1
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+16
-0
tests/script/general/parser/nestquery.sim
tests/script/general/parser/nestquery.sim
+378
-1
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
6185c3d2
...
...
@@ -143,6 +143,7 @@ bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo);
bool
tscIsSecondStageQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tsIsArithmeticQueryOnAggResult
(
SQueryInfo
*
pQueryInfo
);
bool
tscGroupbyColumn
(
SQueryInfo
*
pQueryInfo
);
bool
tscGroupbyTag
(
SQueryInfo
*
pQueryInfo
);
int32_t
tscGetTopBotQueryExprIndex
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsTopBotQuery
(
SQueryInfo
*
pQueryInfo
);
bool
hasTagValOutput
(
SQueryInfo
*
pQueryInfo
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
6185c3d2
...
...
@@ -8895,6 +8895,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
pQueryInfo
->
simpleAgg
=
isSimpleAggregateRv
(
pQueryInfo
);
pQueryInfo
->
onlyTagQuery
=
onlyTagPrjFunction
(
pQueryInfo
);
pQueryInfo
->
groupbyColumn
=
tscGroupbyColumn
(
pQueryInfo
);
pQueryInfo
->
groupbyTag
=
tscGroupbyTag
(
pQueryInfo
);
pQueryInfo
->
arithmeticOnAgg
=
tsIsArithmeticQueryOnAggResult
(
pQueryInfo
);
pQueryInfo
->
orderProjectQuery
=
tscOrderedProjectionQueryOnSTable
(
pQueryInfo
,
0
);
...
...
src/client/src/tscSubquery.c
浏览文件 @
6185c3d2
...
...
@@ -3736,6 +3736,25 @@ static UNUSED_FUNC bool tscHasRemainDataInSubqueryResultSet(SSqlObj *pSql) {
return
hasData
;
}
void
tscSetQuerySort
(
SQueryInfo
*
pQueryInfo
,
SQueryAttr
*
pQueryAttr
)
{
if
(
pQueryInfo
->
interval
.
interval
<=
0
)
{
return
;
}
if
(
pQueryInfo
->
pUpstream
!=
NULL
&&
taosArrayGetSize
(
pQueryInfo
->
pUpstream
)
>
0
)
{
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
pUpstream
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SQueryInfo
*
pq
=
taosArrayGetP
(
pQueryInfo
->
pUpstream
,
i
);
if
(
pq
->
groupbyTag
&&
pq
->
interval
.
interval
>
0
)
{
pQueryAttr
->
needSort
=
true
;
return
;
}
}
}
}
void
*
createQInfoFromQueryNode
(
SQueryInfo
*
pQueryInfo
,
STableGroupInfo
*
pTableGroupInfo
,
SOperatorInfo
*
pSourceOperator
,
char
*
sql
,
void
*
merger
,
int32_t
stage
,
uint64_t
qId
)
{
assert
(
pQueryInfo
!=
NULL
);
...
...
@@ -3838,6 +3857,7 @@ void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGr
SArray
*
pa
=
NULL
;
if
(
stage
==
MASTER_SCAN
)
{
pQueryAttr
->
createFilterOperator
=
false
;
// no need for parent query
tscSetQuerySort
(
pQueryInfo
,
pQueryAttr
);
pa
=
createExecOperatorPlan
(
pQueryAttr
);
}
else
{
pa
=
createGlobalMergePlan
(
pQueryAttr
);
...
...
src/client/src/tscUtil.c
浏览文件 @
6185c3d2
...
...
@@ -385,6 +385,19 @@ bool tscGroupbyColumn(SQueryInfo* pQueryInfo) {
return
false
;
}
bool
tscGroupbyTag
(
SQueryInfo
*
pQueryInfo
)
{
SGroupbyExpr
*
pGroupbyExpr
=
&
pQueryInfo
->
groupbyExpr
;
for
(
int32_t
k
=
0
;
k
<
pGroupbyExpr
->
numOfGroupCols
;
++
k
)
{
SColIndex
*
pIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
k
);
if
(
TSDB_COL_IS_TAG
(
pIndex
->
flag
))
{
// group by tag
return
true
;
}
}
return
false
;
}
int32_t
tscGetTopBotQueryExprIndex
(
SQueryInfo
*
pQueryInfo
)
{
size_t
numOfExprs
=
tscNumOfExprs
(
pQueryInfo
);
...
...
@@ -1217,6 +1230,7 @@ static void createInputDataFilterInfo(SQueryInfo* px, int32_t numOfCol1, int32_t
tfree
(
tableCols
);
}
void
handleDownstreamOperator
(
SSqlObj
**
pSqlObjList
,
int32_t
numOfUpstream
,
SQueryInfo
*
px
,
SSqlObj
*
pSql
)
{
SSqlRes
*
pOutput
=
&
pSql
->
res
;
...
...
src/query/inc/qExecutor.h
浏览文件 @
6185c3d2
...
...
@@ -227,6 +227,7 @@ typedef struct SQueryAttr {
bool
stateWindow
;
// window State on sub/normal table
bool
createFilterOperator
;
// if filter operator is needed
bool
multigroupResult
;
// multigroup result can exist in one SSDataBlock
bool
needSort
;
// need sort rowRes
int32_t
interBufSize
;
// intermediate buffer sizse
int32_t
havingNum
;
// having expr number
...
...
src/query/inc/qTableMeta.h
浏览文件 @
6185c3d2
...
...
@@ -142,7 +142,8 @@ typedef struct SQueryInfo {
struct
SQueryInfo
*
pDownstream
;
int32_t
havingFieldNum
;
bool
stableQuery
;
bool
groupbyColumn
;
bool
groupbyColumn
;
bool
groupbyTag
;
bool
simpleAgg
;
bool
arithmeticOnAgg
;
bool
projectionQuery
;
...
...
src/query/src/qExecutor.c
浏览文件 @
6185c3d2
...
...
@@ -5917,6 +5917,18 @@ static SSDataBlock* doFilter(void* param, bool* newgroup) {
return
NULL
;
}
static
int32_t
resRowCompare
(
const
void
*
r1
,
const
void
*
r2
)
{
SResultRow
*
res1
=
*
(
SResultRow
**
)
r1
;
SResultRow
*
res2
=
*
(
SResultRow
**
)
r2
;
if
(
res1
->
win
.
skey
==
res2
->
win
.
skey
)
{
return
0
;
}
else
{
return
res1
->
win
.
skey
>
res2
->
win
.
skey
?
1
:
-
1
;
}
}
static
SSDataBlock
*
doIntervalAgg
(
void
*
param
,
bool
*
newgroup
)
{
SOperatorInfo
*
pOperator
=
(
SOperatorInfo
*
)
param
;
if
(
pOperator
->
status
==
OP_EXEC_DONE
)
{
...
...
@@ -5962,6 +5974,10 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) {
pQueryAttr
->
window
=
win
;
pOperator
->
status
=
OP_RES_TO_RETURN
;
if
(
pIntervalInfo
->
resultRowInfo
.
size
>
0
&&
pQueryAttr
->
needSort
)
{
qsort
(
pIntervalInfo
->
resultRowInfo
.
pResult
,
pIntervalInfo
->
resultRowInfo
.
size
,
POINTER_BYTES
,
resRowCompare
);
}
closeAllResultRows
(
&
pIntervalInfo
->
resultRowInfo
);
setQueryStatus
(
pRuntimeEnv
,
QUERY_COMPLETED
);
finalizeQueryResult
(
pOperator
,
pIntervalInfo
->
pCtx
,
&
pIntervalInfo
->
resultRowInfo
,
pIntervalInfo
->
rowCellInfoOffset
);
...
...
tests/script/general/parser/nestquery.sim
浏览文件 @
6185c3d2
...
...
@@ -508,4 +508,381 @@ if $data11 != 2.000000000 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
sql create database test2;
sql use test2;
sql create table meters (ts TIMESTAMP,a INT,b INT) TAGS (area INT);
sql CREATE TABLE t0 USING meters TAGS (0);
sql CREATE TABLE t1 USING meters TAGS (1);
sql CREATE TABLE t2 USING meters TAGS (1);
sql CREATE TABLE t3 USING meters TAGS (0);
sql insert into t0 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t0 values ('2021-09-30 15:00:01.00',1,1);
sql insert into t0 values ('2021-09-30 15:00:03.00',3,3);
sql insert into t0 values ('2021-09-30 15:00:05.00',5,5);
sql insert into t0 values ('2021-09-30 15:00:07.00',7,7);
sql insert into t0 values ('2021-09-30 15:00:09.00',9,9);
sql insert into t1 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t1 values ('2021-09-30 15:00:02.00',2,2);
sql insert into t1 values ('2021-09-30 15:00:04.00',4,4);
sql insert into t1 values ('2021-09-30 15:00:06.00',6,6);
sql insert into t1 values ('2021-09-30 15:00:08.00',8,8);
sql insert into t1 values ('2021-09-30 15:00:10.00',10,10);
sql insert into t2 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t2 values ('2021-09-30 15:00:01.00',11,11);
sql insert into t2 values ('2021-09-30 15:00:02.00',22,22);
sql insert into t2 values ('2021-09-30 15:00:03.00',33,33);
sql insert into t2 values ('2021-09-30 15:00:04.00',44,44);
sql insert into t2 values ('2021-09-30 15:00:05.00',55,55);
sql insert into t3 values ('2021-09-30 15:00:00.00',0,0);
sql insert into t3 values ('2021-09-30 15:00:01.00',11,11);
sql insert into t3 values ('2021-09-30 15:00:02.00',22,22);
sql insert into t3 values ('2021-09-30 15:00:03.00',33,33);
sql insert into t3 values ('2021-09-30 15:00:04.00',44,44);
sql insert into t3 values ('2021-09-30 15:00:05.00',55,55);
sql select count(*) from meters interval(1s) group by tbname;
if $rows != 24 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s) group by tbname) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 4 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 3 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 3 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 3 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 3 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 3 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 1 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 1 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s) group by area) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 2 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 2 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 2 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 2 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 2 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 2 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 1 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 1 then
return -1
endi
sql select sum(sa) from (select sum(a) as sa from meters interval(1s) group by tbname) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 23 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 46 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 69 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 92 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 115 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 6 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 7 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 8 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 9 then
return -1
endi
sql select sum(sa) from (select sum(a) as sa from meters interval(1s) group by area) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 23 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 46 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 69 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 92 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 115 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 6 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 7 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 8 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 9 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s)) interval(1s);
if $rows != 11 then
return -1
endi
if $data00 != @21-09-30 15:00:00.000@ then
return -1
endi
if $data01 != 1 then
return -1
endi
if $data10 != @21-09-30 15:00:01.000@ then
return -1
endi
if $data11 != 1 then
return -1
endi
if $data20 != @21-09-30 15:00:02.000@ then
return -1
endi
if $data21 != 1 then
return -1
endi
if $data30 != @21-09-30 15:00:03.000@ then
return -1
endi
if $data31 != 1 then
return -1
endi
if $data40 != @21-09-30 15:00:04.000@ then
return -1
endi
if $data41 != 1 then
return -1
endi
if $data50 != @21-09-30 15:00:05.000@ then
return -1
endi
if $data51 != 1 then
return -1
endi
if $data60 != @21-09-30 15:00:06.000@ then
return -1
endi
if $data61 != 1 then
return -1
endi
if $data70 != @21-09-30 15:00:07.000@ then
return -1
endi
if $data71 != 1 then
return -1
endi
if $data80 != @21-09-30 15:00:08.000@ then
return -1
endi
if $data81 != 1 then
return -1
endi
if $data90 != @21-09-30 15:00:09.000@ then
return -1
endi
if $data91 != 1 then
return -1
endi
sql select count(*) from (select count(*) from meters interval(1s) group by tbname);
if $rows != 1 then
return -1
endi
if $data00 != 24 then
return -1
endi
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录