Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
81d795c2
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看板
提交
81d795c2
编写于
10月 26, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(query): enable limit in grouped scan.
上级
8d2de8d7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
27 deletion
+40
-27
source/libs/executor/inc/executorimpl.h
source/libs/executor/inc/executorimpl.h
+2
-1
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+35
-23
tests/script/tsim/parser/limit_stb.sim
tests/script/tsim/parser/limit_stb.sim
+3
-3
未找到文件。
source/libs/executor/inc/executorimpl.h
浏览文件 @
81d795c2
...
@@ -352,7 +352,7 @@ typedef struct STableMergeScanInfo {
...
@@ -352,7 +352,7 @@ typedef struct STableMergeScanInfo {
SSDataBlock
*
pSortInputBlock
;
SSDataBlock
*
pSortInputBlock
;
int64_t
startTs
;
// sort start time
int64_t
startTs
;
// sort start time
SArray
*
sortSourceParams
;
SArray
*
sortSourceParams
;
SLimitInfo
limitInfo
;
SFileBlockLoadRecorder
readRecorder
;
SFileBlockLoadRecorder
readRecorder
;
int64_t
numOfRows
;
int64_t
numOfRows
;
SScanInfo
scanInfo
;
SScanInfo
scanInfo
;
...
@@ -369,6 +369,7 @@ typedef struct STableMergeScanInfo {
...
@@ -369,6 +369,7 @@ typedef struct STableMergeScanInfo {
SQueryTableDataCond
cond
;
SQueryTableDataCond
cond
;
int32_t
scanFlag
;
// table scan flag to denote if it is a repeat/reverse/main scan
int32_t
scanFlag
;
// table scan flag to denote if it is a repeat/reverse/main scan
int32_t
dataBlockLoadFlag
;
int32_t
dataBlockLoadFlag
;
// if the upstream is an interval operator, the interval info is also kept here to get the time
// if the upstream is an interval operator, the interval info is also kept here to get the time
// window to check if current data block needs to be loaded.
// window to check if current data block needs to be loaded.
SInterval
interval
;
SInterval
interval
;
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
81d795c2
...
@@ -355,6 +355,33 @@ static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlo
...
@@ -355,6 +355,33 @@ static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlo
}
}
}
}
static
void
applyLimitOffset
(
SLimitInfo
*
pLimitInfo
,
SSDataBlock
*
pBlock
,
SExecTaskInfo
*
pTaskInfo
,
SOperatorInfo
*
pOperator
)
{
SLimit
*
pLimit
=
&
pLimitInfo
->
limit
;
if
(
pLimit
->
offset
>
0
&&
pLimitInfo
->
remainOffset
>
0
)
{
if
(
pLimitInfo
->
remainOffset
>=
pBlock
->
info
.
rows
)
{
pLimitInfo
->
remainOffset
-=
pBlock
->
info
.
rows
;
pBlock
->
info
.
rows
=
0
;
qDebug
(
"current block ignore due to offset, current:%"
PRId64
", %s"
,
pLimitInfo
->
remainOffset
,
GET_TASKID
(
pTaskInfo
));
}
else
{
blockDataTrimFirstNRows
(
pBlock
,
pLimitInfo
->
remainOffset
);
pLimitInfo
->
remainOffset
=
0
;
}
}
if
(
pLimit
->
limit
!=
-
1
&&
pLimit
->
limit
<=
(
pLimitInfo
->
numOfOutputRows
+
pBlock
->
info
.
rows
))
{
// limit the output rows
int32_t
overflowRows
=
pLimitInfo
->
numOfOutputRows
+
pBlock
->
info
.
rows
-
pLimit
->
limit
;
int32_t
keep
=
pBlock
->
info
.
rows
-
overflowRows
;
blockDataKeepFirstNRows
(
pBlock
,
keep
);
qDebug
(
"output limit %"
PRId64
" has reached, %s"
,
pLimit
->
limit
,
GET_TASKID
(
pTaskInfo
));
setTaskStatus
(
pTaskInfo
,
TASK_COMPLETED
);
pOperator
->
status
=
OP_EXEC_DONE
;
}
}
static
int32_t
loadDataBlock
(
SOperatorInfo
*
pOperator
,
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
,
static
int32_t
loadDataBlock
(
SOperatorInfo
*
pOperator
,
STableScanInfo
*
pTableScanInfo
,
SSDataBlock
*
pBlock
,
uint32_t
*
status
)
{
uint32_t
*
status
)
{
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
SExecTaskInfo
*
pTaskInfo
=
pOperator
->
pTaskInfo
;
...
@@ -467,29 +494,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca
...
@@ -467,29 +494,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca
}
}
}
}
SLimit
*
pLimit
=
&
pInfo
->
limitInfo
.
limit
;
applyLimitOffset
(
&
pInfo
->
limitInfo
,
pBlock
,
pTaskInfo
,
pOperator
);
if
(
pLimit
->
offset
>
0
&&
pInfo
->
limitInfo
.
remainOffset
>
0
)
{
if
(
pInfo
->
limitInfo
.
remainOffset
>=
pBlock
->
info
.
rows
)
{
pInfo
->
limitInfo
.
remainOffset
-=
pBlock
->
info
.
rows
;
pBlock
->
info
.
rows
=
0
;
qDebug
(
"current block ignore due to offset, current:%"
PRId64
", %s"
,
pInfo
->
limitInfo
.
remainOffset
,
GET_TASKID
(
pTaskInfo
));
}
else
{
blockDataTrimFirstNRows
(
pBlock
,
pInfo
->
limitInfo
.
remainOffset
);
pInfo
->
limitInfo
.
remainOffset
=
0
;
}
}
if
(
pLimit
->
limit
!=
-
1
&&
pLimit
->
limit
<=
(
pInfo
->
limitInfo
.
numOfOutputRows
+
pBlock
->
info
.
rows
))
{
// limit the output rows
int32_t
overflowRows
=
pInfo
->
limitInfo
.
numOfOutputRows
+
pBlock
->
info
.
rows
-
pLimit
->
limit
;
int32_t
keep
=
pBlock
->
info
.
rows
-
overflowRows
;
blockDataKeepFirstNRows
(
pBlock
,
keep
);
qDebug
(
"output limit %"
PRId64
" has reached, %s"
,
pLimit
->
limit
,
GET_TASKID
(
pTaskInfo
));
setTaskStatus
(
pTaskInfo
,
TASK_COMPLETED
);
pOperator
->
status
=
OP_EXEC_DONE
;
}
pCost
->
totalRows
+=
pBlock
->
info
.
rows
;
pCost
->
totalRows
+=
pBlock
->
info
.
rows
;
pInfo
->
limitInfo
.
numOfOutputRows
=
pCost
->
totalRows
;
pInfo
->
limitInfo
.
numOfOutputRows
=
pCost
->
totalRows
;
...
@@ -4468,6 +4473,9 @@ SSDataBlock* getSortedTableMergeScanBlockData(SSortHandle* pHandle, SSDataBlock*
...
@@ -4468,6 +4473,9 @@ SSDataBlock* getSortedTableMergeScanBlockData(SSortHandle* pHandle, SSDataBlock*
}
}
qDebug
(
"%s get sorted row blocks, rows:%d"
,
GET_TASKID
(
pTaskInfo
),
pResBlock
->
info
.
rows
);
qDebug
(
"%s get sorted row blocks, rows:%d"
,
GET_TASKID
(
pTaskInfo
),
pResBlock
->
info
.
rows
);
applyLimitOffset
(
&
pInfo
->
limitInfo
,
pResBlock
,
pTaskInfo
,
pOperator
);
pInfo
->
limitInfo
.
numOfOutputRows
+=
pResBlock
->
info
.
rows
;
return
(
pResBlock
->
info
.
rows
>
0
)
?
pResBlock
:
NULL
;
return
(
pResBlock
->
info
.
rows
>
0
)
?
pResBlock
:
NULL
;
}
}
...
@@ -4483,6 +4491,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
...
@@ -4483,6 +4491,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
T_LONG_JMP
(
pTaskInfo
->
env
,
code
);
T_LONG_JMP
(
pTaskInfo
->
env
,
code
);
}
}
size_t
tableListSize
=
taosArrayGetSize
(
pInfo
->
tableListInfo
->
pTableList
);
size_t
tableListSize
=
taosArrayGetSize
(
pInfo
->
tableListInfo
->
pTableList
);
if
(
!
pInfo
->
hasGroupId
)
{
if
(
!
pInfo
->
hasGroupId
)
{
pInfo
->
hasGroupId
=
true
;
pInfo
->
hasGroupId
=
true
;
...
@@ -4495,6 +4504,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
...
@@ -4495,6 +4504,7 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) {
pInfo
->
groupId
=
((
STableKeyInfo
*
)
taosArrayGet
(
pInfo
->
tableListInfo
->
pTableList
,
pInfo
->
tableStartIndex
))
->
groupId
;
pInfo
->
groupId
=
((
STableKeyInfo
*
)
taosArrayGet
(
pInfo
->
tableListInfo
->
pTableList
,
pInfo
->
tableStartIndex
))
->
groupId
;
startGroupTableMergeScan
(
pOperator
);
startGroupTableMergeScan
(
pOperator
);
}
}
SSDataBlock
*
pBlock
=
NULL
;
SSDataBlock
*
pBlock
=
NULL
;
while
(
pInfo
->
tableStartIndex
<
tableListSize
)
{
while
(
pInfo
->
tableStartIndex
<
tableListSize
)
{
pBlock
=
getSortedTableMergeScanBlockData
(
pInfo
->
pSortHandle
,
pInfo
->
pResBlock
,
pOperator
->
resultInfo
.
capacity
,
pBlock
=
getSortedTableMergeScanBlockData
(
pInfo
->
pSortHandle
,
pInfo
->
pResBlock
,
pOperator
->
resultInfo
.
capacity
,
...
@@ -4582,6 +4592,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
...
@@ -4582,6 +4592,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
goto
_error
;
goto
_error
;
}
}
if
(
pTableScanNode
->
pGroupTags
)
{
if
(
pTableScanNode
->
pGroupTags
)
{
taosArraySort
(
pTableListInfo
->
pTableList
,
compareTableKeyInfoByGid
);
taosArraySort
(
pTableListInfo
->
pTableList
,
compareTableKeyInfoByGid
);
}
}
...
@@ -4619,6 +4630,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
...
@@ -4619,6 +4630,7 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN
pInfo
->
pSortInfo
=
generateSortByTsInfo
(
pInfo
->
matchInfo
.
pList
,
pInfo
->
cond
.
order
);
pInfo
->
pSortInfo
=
generateSortByTsInfo
(
pInfo
->
matchInfo
.
pList
,
pInfo
->
cond
.
order
);
pInfo
->
pSortInputBlock
=
createOneDataBlock
(
pInfo
->
pResBlock
,
false
);
pInfo
->
pSortInputBlock
=
createOneDataBlock
(
pInfo
->
pResBlock
,
false
);
initLimitInfo
(
pTableScanNode
->
scan
.
node
.
pLimit
,
pTableScanNode
->
scan
.
node
.
pSlimit
,
&
pInfo
->
limitInfo
);
int32_t
rowSize
=
pInfo
->
pResBlock
->
info
.
rowSize
;
int32_t
rowSize
=
pInfo
->
pResBlock
->
info
.
rowSize
;
pInfo
->
bufPageSize
=
getProperSortPageSize
(
rowSize
);
pInfo
->
bufPageSize
=
getProperSortPageSize
(
rowSize
);
...
...
tests/script/tsim/parser/limit_stb.sim
浏览文件 @
81d795c2
...
@@ -39,9 +39,9 @@ endi
...
@@ -39,9 +39,9 @@ endi
if $data01 != 1 then
if $data01 != 1 then
return -1
return -1
endi
endi
if $data41 != 5 then
#
if $data41 != 5 then
return -1
#
return -1
endi
#
endi
sql select * from $stb order by ts desc limit 5
sql select * from $stb order by ts desc limit 5
if $rows != 5 then
if $rows != 5 then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录