Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
09297fba
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看板
未验证
提交
09297fba
编写于
4月 04, 2021
作者:
H
haojun Liao
提交者:
GitHub
4月 04, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5675 from taosdata/feature/qrefactor
[td-3662] <fix>: fix invalid write caused by top/bottom query.
上级
3f273cbf
ecfe8eca
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
76 addition
and
2 deletion
+76
-2
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+2
-0
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+16
-2
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+35
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+15
-0
tests/script/general/parser/select_with_tags.sim
tests/script/general/parser/select_with_tags.sim
+8
-0
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
09297fba
...
...
@@ -129,6 +129,8 @@ bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
bool
tscIsTWAQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsSecondStageQuery
(
SQueryInfo
*
pQueryInfo
);
bool
tscGroupbyColumn
(
SQueryInfo
*
pQueryInfo
);
bool
tscIsTopbotQuery
(
SQueryInfo
*
pQueryInfo
);
int32_t
tscGetTopbotQueryParam
(
SQueryInfo
*
pQueryInfo
);
bool
tscNonOrderedProjectionQueryOnSTable
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
bool
tscOrderedProjectionQueryOnSTable
(
SQueryInfo
*
pQueryInfo
,
int32_t
tableIndex
);
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
09297fba
...
...
@@ -338,11 +338,20 @@ void tscCreateLocalMerger(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrde
pReducer
->
resColModel
->
capacity
=
pReducer
->
nResultBufSize
;
pReducer
->
finalModel
=
pFFModel
;
int32_t
expandFactor
=
1
;
if
(
finalmodel
->
rowSize
>
0
)
{
bool
topBotQuery
=
tscIsTopbotQuery
(
pQueryInfo
);
if
(
topBotQuery
)
{
expandFactor
=
tscGetTopbotQueryParam
(
pQueryInfo
);
pReducer
->
resColModel
->
capacity
/=
(
finalmodel
->
rowSize
*
expandFactor
);
pReducer
->
resColModel
->
capacity
*=
expandFactor
;
}
else
{
pReducer
->
resColModel
->
capacity
/=
finalmodel
->
rowSize
;
}
}
assert
(
finalmodel
->
rowSize
>
0
&&
finalmodel
->
rowSize
<=
pReducer
->
rowSize
);
pReducer
->
pFinalRes
=
calloc
(
1
,
pReducer
->
rowSize
*
pReducer
->
resColModel
->
capacity
);
if
(
pReducer
->
pTempBuffer
==
NULL
||
pReducer
->
discardData
==
NULL
||
pReducer
->
pResultBuf
==
NULL
||
...
...
@@ -1440,6 +1449,11 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
pCmd
->
clauseIndex
);
tFilePage
*
tmpBuffer
=
pLocalMerge
->
pTempBuffer
;
int32_t
remain
=
1
;
if
(
tscIsTopbotQuery
(
pQueryInfo
))
{
remain
=
tscGetTopbotQueryParam
(
pQueryInfo
);
}
if
(
doHandleLastRemainData
(
pSql
))
{
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -1528,7 +1542,7 @@ int32_t tscDoLocalMerge(SSqlObj *pSql) {
* if the previous group does NOT generate any result (pResBuf->num == 0),
* continue to process results instead of return results.
*/
if
((
!
sameGroup
&&
pResBuf
->
num
>
0
)
||
(
pResBuf
->
num
=
=
pLocalMerge
->
resColModel
->
capacity
))
{
if
((
!
sameGroup
&&
pResBuf
->
num
>
0
)
||
(
pResBuf
->
num
+
remain
>
=
pLocalMerge
->
resColModel
->
capacity
))
{
// does not belong to the same group
bool
notSkipped
=
genFinalResults
(
pSql
,
pLocalMerge
,
!
sameGroup
);
...
...
src/client/src/tscUtil.c
浏览文件 @
09297fba
...
...
@@ -271,6 +271,41 @@ bool tscIsTWAQuery(SQueryInfo* pQueryInfo) {
return
false
;
}
bool
tscIsTopbotQuery
(
SQueryInfo
*
pQueryInfo
)
{
size_t
numOfExprs
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
==
NULL
)
{
continue
;
}
int32_t
functionId
=
pExpr
->
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
return
true
;
}
}
return
false
;
}
int32_t
tscGetTopbotQueryParam
(
SQueryInfo
*
pQueryInfo
)
{
size_t
numOfExprs
=
tscSqlExprNumOfExprs
(
pQueryInfo
);
for
(
int32_t
i
=
0
;
i
<
numOfExprs
;
++
i
)
{
SSqlExpr
*
pExpr
=
tscSqlExprGet
(
pQueryInfo
,
i
);
if
(
pExpr
==
NULL
)
{
continue
;
}
int32_t
functionId
=
pExpr
->
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
return
(
int32_t
)
pExpr
->
param
[
0
].
i64
;
}
}
return
0
;
}
void
tscClearInterpInfo
(
SQueryInfo
*
pQueryInfo
)
{
if
(
!
tscIsPointInterpQuery
(
pQueryInfo
))
{
return
;
...
...
src/query/src/qExecutor.c
浏览文件 @
09297fba
...
...
@@ -2631,6 +2631,21 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
tsdbRetrieveDataBlockStatisInfo
(
pTableScanInfo
->
pQueryHandle
,
&
pBlock
->
pBlockStatis
);
if
(
pQuery
->
topBotQuery
&&
pBlock
->
pBlockStatis
!=
NULL
)
{
{
// set previous window
if
(
QUERY_IS_INTERVAL_QUERY
(
pQuery
))
{
SResultRow
*
pResult
=
NULL
;
bool
masterScan
=
IS_MASTER_SCAN
(
pRuntimeEnv
);
TSKEY
k
=
ascQuery
?
pBlock
->
info
.
window
.
skey
:
pBlock
->
info
.
window
.
ekey
;
STimeWindow
win
=
getActiveTimeWindow
(
pTableScanInfo
->
pResultRowInfo
,
k
,
pQuery
);
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pTableScanInfo
->
pResultRowInfo
,
&
win
,
masterScan
,
&
pResult
,
groupId
,
pTableScanInfo
->
pCtx
,
pTableScanInfo
->
numOfOutput
,
pTableScanInfo
->
rowCellInfoOffset
)
!=
TSDB_CODE_SUCCESS
)
{
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
}
bool
load
=
false
;
for
(
int32_t
i
=
0
;
i
<
pQuery
->
numOfOutput
;
++
i
)
{
int32_t
functionId
=
pTableScanInfo
->
pCtx
[
i
].
functionId
;
...
...
tests/script/general/parser/select_with_tags.sim
浏览文件 @
09297fba
...
...
@@ -159,6 +159,14 @@ if $data03 != @abc15@ then
return -1
endi
#sql select top(c6, 3) from select_tags_mt0 interval(10a)
#sql select top(c6, 3) from select_tags_mt0 interval(10a) group by tbname;
sql select top(c6, 10) from select_tags_mt0 interval(10a);
if $rows != 12800 then
return -1
endi
sql select top(c1, 100), tbname, t1, t2 from select_tags_mt0;
if $rows != 100 then
return -1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录