Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2a89ac7d
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
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看板
提交
2a89ac7d
编写于
2月 14, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bugs in sliding query processing
上级
eb39c4bf
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
215 addition
and
184 deletion
+215
-184
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+4
-0
src/system/detail/inc/vnodeQueryImpl.h
src/system/detail/inc/vnodeQueryImpl.h
+1
-1
src/system/detail/src/vnodeQueryImpl.c
src/system/detail/src/vnodeQueryImpl.c
+193
-171
src/system/detail/src/vnodeQueryProcess.c
src/system/detail/src/vnodeQueryProcess.c
+17
-12
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
2a89ac7d
...
...
@@ -609,6 +609,10 @@ int32_t parseIntervalClause(SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql) {
// for top/bottom + interval query, we do not add additional timestamp column in the front
if
(
isTopBottomQuery
(
pQueryInfo
))
{
if
(
parseSlidingClause
(
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_INVALID_SQL
;
}
return
TSDB_CODE_SUCCESS
;
}
...
...
src/system/detail/inc/vnodeQueryImpl.h
浏览文件 @
2a89ac7d
...
...
@@ -282,7 +282,7 @@ void clearGroupResultBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pOneOutpu
void
copyGroupResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
dst
,
const
SWindowResult
*
src
);
void
resetSlidingWindowInfo
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResInfo
*
pWindowResInfo
);
void
clearC
omplet
edSlidingWindows
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
void
clearC
los
edSlidingWindows
(
SQueryRuntimeEnv
*
pRuntimeEnv
);
int32_t
numOfClosedSlidingWindow
(
SWindowResInfo
*
pWindowResInfo
);
void
closeSlidingWindow
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
);
void
closeAllSlidingWindow
(
SWindowResInfo
*
pWindowResInfo
);
...
...
src/system/detail/src/vnodeQueryImpl.c
浏览文件 @
2a89ac7d
...
...
@@ -1010,16 +1010,10 @@ SBlockInfo getBlockBasicInfo(SQueryRuntimeEnv *pRuntimeEnv, void *pBlock, int32_
return
blockInfo
;
}
static
bool
checkQueryRangeAgainstNextBlock
(
SBlockInfo
*
pBlockInfo
,
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
static
bool
checkQueryRangeAgainstNextBlock
(
SBlockInfo
*
pBlockInfo
,
SQuery
*
pQuery
)
{
if
((
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
pBlockInfo
->
keyFirst
>
pQuery
->
ekey
)
||
(
!
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
pBlockInfo
->
keyLast
<
pQuery
->
ekey
))
{
int32_t
pos
=
QUERY_IS_ASC_QUERY
(
pQuery
)
?
0
:
pBlockInfo
->
size
-
1
;
savePointPosition
(
&
pRuntimeEnv
->
nextPos
,
pQuery
->
fileId
,
pQuery
->
slot
,
pos
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
return
false
;
}
...
...
@@ -1033,7 +1027,7 @@ static bool checkQueryRangeAgainstNextBlock(SBlockInfo *pBlockInfo, SQueryRuntim
* @param forwardStep
* @return TRUE means query not completed, FALSE means query is completed
*/
static
bool
query
CompleteIn
Block
(
SQuery
*
pQuery
,
SBlockInfo
*
pBlockInfo
,
int32_t
forwardStep
)
{
static
bool
query
PausedInCurrent
Block
(
SQuery
*
pQuery
,
SBlockInfo
*
pBlockInfo
,
int32_t
forwardStep
)
{
if
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_RESBUF_FULL
))
{
// assert(pQuery->checkBufferInLoop == 1 && pQuery->over == QUERY_RESBUF_FULL && pQuery->pointsOffset == 0);
...
...
@@ -1466,12 +1460,12 @@ static SWindowResult *doSetSlidingWindowFromKey(SQueryRuntimeEnv *pRuntimeEnv, S
// todo
}
pWindowResInfo
->
capacity
=
newCap
;
for
(
int32_t
i
=
pWindowResInfo
->
capacity
;
i
<
newCap
;
++
i
)
{
SPosInfo
pos
=
{
-
1
,
-
1
};
createQueryResultInfo
(
pQuery
,
&
pWindowResInfo
->
pResult
[
i
],
pRuntimeEnv
->
stableQuery
,
&
pos
);
}
pWindowResInfo
->
capacity
=
newCap
;
}
// add a new result set for a new group
...
...
@@ -1491,12 +1485,15 @@ static STimeWindow getActiveSlidingWindow(SWindowResInfo *pWindowResInfo, int64_
w
.
ekey
=
w
.
skey
+
pQuery
->
intervalTime
-
1
;
}
else
{
int32_t
slot
=
curSlidingWindow
(
pWindowResInfo
);
STimeWindow
*
window
=
&
pWindowResInfo
->
pResult
[
slot
].
window
;
w
=
pWindowResInfo
->
pResult
[
slot
].
window
;
}
// STimeWindow *window = &pWindowResInfo->pResult[slot].window;
if
(
window
->
skey
<=
ts
&&
window
->
ekey
>=
ts
)
{
w
=
*
window
;
// belongs to current active window
}
else
{
int64_t
st
=
window
->
skey
;
if
(
w
.
skey
>
ts
||
w
.
ekey
<
ts
)
{
// if (w.skey <= ts && w.ekey >= ts) {
// w = *window; // belongs to current active window
// } else {
int64_t
st
=
w
.
skey
;
while
(
st
>
ts
)
{
st
-=
pQuery
->
slidingTime
;
...
...
@@ -1509,7 +1506,6 @@ static STimeWindow getActiveSlidingWindow(SWindowResInfo *pWindowResInfo, int64_
w
.
skey
=
st
;
w
.
ekey
=
w
.
skey
+
pQuery
->
intervalTime
-
1
;
}
}
assert
(
ts
>=
w
.
skey
&&
ts
<=
w
.
ekey
);
return
w
;
...
...
@@ -1582,6 +1578,7 @@ static int32_t setWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SWindowRes
}
static
SWindowStatus
*
getSlidingWindowStatus
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
)
{
assert
(
slot
>=
0
&&
slot
<
pWindowResInfo
->
size
);
return
&
pWindowResInfo
->
pResult
[
slot
].
status
;
}
...
...
@@ -1629,7 +1626,13 @@ static void doCheckQueryCompleted(SQueryRuntimeEnv *pRuntimeEnv, TSKEY lastKey,
}
}
// all windows are closed, set the last one to be the skey
if
(
skey
==
0
)
{
skey
=
pWindowResInfo
->
pResult
[
pWindowResInfo
->
size
-
1
].
window
.
skey
;
}
pWindowResInfo
->
prevSKey
=
skey
;
assert
(
skey
!=
0
);
// the number of completed slots are larger than the threshold, dump to client immediately.
int32_t
v
=
numOfClosedSlidingWindow
(
pWindowResInfo
);
...
...
@@ -1639,6 +1642,8 @@ static void doCheckQueryCompleted(SQueryRuntimeEnv *pRuntimeEnv, TSKEY lastKey,
dTrace
(
"QInfo:%p total window:%d, closed:%d"
,
GET_QINFO_ADDR
(
pQuery
),
pWindowResInfo
->
size
,
v
);
}
assert
(
pWindowResInfo
->
prevSKey
!=
0
);
}
}
...
...
@@ -1696,8 +1701,7 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
TSKEY
ts
=
primaryKeyCol
[
offset
];
STimeWindow
win
=
getActiveSlidingWindow
(
pWindowResInfo
,
ts
,
pQuery
);
int32_t
ret
=
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pRuntimeEnv
->
pMeterObj
->
sid
,
&
win
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pRuntimeEnv
->
pMeterObj
->
sid
,
&
win
)
!=
TSDB_CODE_SUCCESS
)
{
return
0
;
}
...
...
@@ -1716,16 +1720,20 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
}
}
SWindowStatus
*
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
pStatus
->
closed
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
pCtx
[
k
].
nStartQueryTimestamp
=
win
.
skey
;
pCtx
[
k
].
size
=
forwardStep
;
pCtx
[
k
].
startOffset
=
pQuery
->
pos
;
pCtx
[
k
].
startOffset
=
(
QUERY_IS_ASC_QUERY
(
pQuery
))
?
pQuery
->
pos
:
pQuery
->
pos
-
(
forwardStep
-
1
)
;
int32_t
functionId
=
pQuery
->
pSelectExpr
[
k
].
pBase
.
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
}
}
}
int32_t
index
=
pWindowResInfo
->
curIndex
;
STimeWindow
nextWin
=
win
;
...
...
@@ -1783,22 +1791,20 @@ static int32_t blockwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t
}
}
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
pStatus
->
closed
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
pCtx
[
k
].
nStartQueryTimestamp
=
nextWin
.
skey
;
pCtx
[
k
].
size
=
forwardStep
;
pCtx
[
k
].
startOffset
=
startPos
;
SWindowStatus
*
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
!
IS_MASTER_SCAN
(
pRuntimeEnv
)
&&
!
pStatus
->
closed
)
{
continue
;
}
pCtx
[
k
].
startOffset
=
(
QUERY_IS_ASC_QUERY
(
pQuery
))
?
startPos
:
startPos
-
(
forwardStep
-
1
);
int32_t
functionId
=
pQuery
->
pSelectExpr
[
k
].
pBase
.
functionId
;
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
}
}
}
// } else {
// pWindowResInfo->curIndex = index;
// break;
...
...
@@ -1941,8 +1947,8 @@ void resetSlidingWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWind
}
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
SWindowResult
*
p
One
Res
=
&
pWindowResInfo
->
pResult
[
i
];
clearGroupResultBuf
(
pRuntimeEnv
,
p
One
Res
);
SWindowResult
*
p
Window
Res
=
&
pWindowResInfo
->
pResult
[
i
];
clearGroupResultBuf
(
pRuntimeEnv
,
p
Window
Res
);
}
pWindowResInfo
->
curIndex
=
-
1
;
...
...
@@ -1956,7 +1962,7 @@ void resetSlidingWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWind
pWindowResInfo
->
prevSKey
=
0
;
}
void
clearC
omplet
edSlidingWindows
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
void
clearC
los
edSlidingWindows
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
SWindowResInfo
*
pWindowResInfo
=
&
pRuntimeEnv
->
windowResInfo
;
if
(
pWindowResInfo
==
NULL
||
pWindowResInfo
->
capacity
==
0
||
pWindowResInfo
->
size
==
0
)
{
return
;
...
...
@@ -1972,33 +1978,34 @@ void clearCompletedSlidingWindows(SQueryRuntimeEnv *pRuntimeEnv) {
}
}
// no window is closed, no need to clear the window list
if
(
i
==
0
)
{
return
;
}
int32_t
remain
=
pWindowResInfo
->
size
-
i
;
int32_t
unclosed
=
pWindowResInfo
->
size
-
i
;
// clear
remain
list
for
(
int32_t
k
=
0
;
k
<
remain
;
++
k
)
{
// clear
all the closed windows from the window
list
for
(
int32_t
k
=
0
;
k
<
unclosed
;
++
k
)
{
copyGroupResultBuf
(
pRuntimeEnv
,
&
pWindowResInfo
->
pResult
[
k
],
&
pWindowResInfo
->
pResult
[
i
+
k
]);
}
for
(
int32_t
k
=
remain
;
k
<
pWindowResInfo
->
size
;
++
k
)
{
SWindowResult
*
pOneRes
=
&
pWindowResInfo
->
pResult
[
k
];
clearGroupResultBuf
(
pRuntimeEnv
,
pOneRes
);
// move the unclosed window in the front of the window list
for
(
int32_t
k
=
unclosed
;
k
<
pWindowResInfo
->
size
;
++
k
)
{
SWindowResult
*
pWindowRes
=
&
pWindowResInfo
->
pResult
[
k
];
clearGroupResultBuf
(
pRuntimeEnv
,
pWindowRes
);
}
pWindowResInfo
->
size
=
remain
;
pWindowResInfo
->
size
=
unclosed
;
for
(
int32_t
k
=
0
;
k
<
pWindowResInfo
->
size
;
++
k
)
{
SWindowResult
*
pResult
=
&
pWindowResInfo
->
pResult
[
k
];
int32_t
*
p
=
(
int32_t
*
)
taosGetDataFromHashTable
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
TSDB_KEYSIZE
);
int32_t
v
=
*
p
;
v
=
(
v
-
i
);
int32_t
v
=
(
*
p
-
i
);
//todo add the update function for hash table
taosDeleteFromHashTable
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
TSDB_KEYSIZE
);
taosAddToHashTable
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
TSDB_KEYSIZE
,
(
char
*
)
&
v
,
sizeof
(
int32_t
));
}
...
...
@@ -2222,32 +2229,28 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t *
// all startOffset are identical
offset
-=
pCtx
[
0
].
startOffset
;
SWindowStatus
*
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
pStatus
->
closed
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
int32_t
functionId
=
pQuery
->
pSelectExpr
[
k
].
pBase
.
functionId
;
pCtx
[
k
].
nStartQueryTimestamp
=
win
.
skey
;
SWindowStatus
*
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
!
IS_MASTER_SCAN
(
pRuntimeEnv
)
&&
!
pStatus
->
closed
)
{
// qTrace("QInfo:%p not completed in supplementary scan, ignore funcId:%d, window:%lld-%lld",
// GET_QINFO_ADDR(pQuery), functionId, pStatus->window.skey, pStatus->window.ekey);
continue
;
}
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
aAggs
[
functionId
].
xFunctionF
(
&
pCtx
[
k
],
offset
);
}
}
}
lastKey
=
ts
;
int32_t
index
=
pWindowResInfo
->
curIndex
;
int32_t
prev
=
pWindowResInfo
->
curIndex
;
STimeWindow
nextWin
=
win
;
while
(
1
)
{
getNextLogicalQueryRange
(
pRuntimeEnv
,
&
nextWin
);
if
(
pWindowResInfo
->
startTime
>
nextWin
.
skey
||
(
nextWin
.
skey
>
pQuery
->
ekey
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
(
nextWin
.
skey
>
pQuery
->
skey
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
)))
{
pWindowResInfo
->
curIndex
=
index
;
pWindowResInfo
->
curIndex
=
prev
;
break
;
}
...
...
@@ -2255,27 +2258,23 @@ static int32_t rowwiseApplyAllFunctions(SQueryRuntimeEnv *pRuntimeEnv, int32_t *
// null data, failed to allocate more memory buffer
if
(
setWindowOutputBufByKey
(
pRuntimeEnv
,
pWindowResInfo
,
pRuntimeEnv
->
pMeterObj
->
sid
,
&
nextWin
)
!=
TSDB_CODE_SUCCESS
)
{
pWindowResInfo
->
curIndex
=
index
;
pWindowResInfo
->
curIndex
=
prev
;
break
;
}
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
IS_MASTER_SCAN
(
pRuntimeEnv
)
||
pStatus
->
closed
)
{
for
(
int32_t
k
=
0
;
k
<
pQuery
->
numOfOutputCols
;
++
k
)
{
int32_t
functionId
=
pQuery
->
pSelectExpr
[
k
].
pBase
.
functionId
;
pCtx
[
k
].
nStartQueryTimestamp
=
nextWin
.
skey
;
SWindowStatus
*
pStatus
=
getSlidingWindowStatus
(
pWindowResInfo
,
curSlidingWindow
(
pWindowResInfo
));
if
(
!
IS_MASTER_SCAN
(
pRuntimeEnv
)
&&
!
pStatus
->
closed
)
{
// qTrace("QInfo:%p not completed in supplementary scan, ignore funcId:%d, window:%lld-%lld",
// GET_QINFO_ADDR(pQuery), functionId, pStatus->window.skey, pStatus->window.ekey);
continue
;
}
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
aAggs
[
functionId
].
xFunctionF
(
&
pCtx
[
k
],
offset
);
}
}
}
}
else
{
pWindowResInfo
->
curIndex
=
index
;
pWindowResInfo
->
curIndex
=
prev
;
break
;
}
}
...
...
@@ -2389,48 +2388,38 @@ static int32_t applyFunctionsOnBlock(SQueryRuntimeEnv *pRuntimeEnv, SBlockInfo *
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQuery
->
order
.
order
);
validateQueryRangeAndData
(
pRuntimeEnv
,
pPrimaryColumn
,
pBlockInfo
);
if
(
QUERY_IS_ASC_QUERY
(
pQuery
))
{
if
(
pQuery
->
ekey
<
pBlockInfo
->
keyLast
)
{
forwardStep
=
getForwardStepsInBlock
(
pBlockInfo
->
size
,
searchFn
,
pQuery
->
ekey
,
pQuery
->
pos
,
pQuery
->
order
.
order
,
pPrimaryColumn
);
assert
(
forwardStep
>=
0
);
if
(
forwardStep
==
0
)
{
// no qualified data in current block, do not update the lastKey value
if
(
forwardStep
==
0
)
{
// no qualified data in current block, do not update the lastKey value
assert
(
pQuery
->
ekey
<
pPrimaryColumn
[
pQuery
->
pos
]);
}
else
{
// todo MAX()!
pQuery
->
lastKey
=
pQuery
->
ekey
+
step
;
// pPrimaryColumn[pQuery->pos + (forwardStep - 1)]
+ step;
}
else
{
pQuery
->
lastKey
=
MAX
(
pQuery
->
ekey
,
pPrimaryColumn
[
pQuery
->
pos
+
(
forwardStep
-
1
)])
+
step
;
}
}
else
{
forwardStep
=
pBlockInfo
->
size
-
pQuery
->
pos
;
assert
(
forwardStep
>
0
);
pQuery
->
lastKey
=
pBlockInfo
->
keyLast
+
step
;
}
}
else
{
// desc
if
(
pQuery
->
ekey
>
pBlockInfo
->
keyFirst
)
{
forwardStep
=
getForwardStepsInBlock
(
pBlockInfo
->
size
,
searchFn
,
pQuery
->
ekey
,
pQuery
->
pos
,
pQuery
->
order
.
order
,
pPrimaryColumn
);
assert
(
forwardStep
>=
0
);
if
(
forwardStep
==
0
)
{
// no qualified data in current block, do not update the lastKey value
if
(
forwardStep
==
0
)
{
// no qualified data in current block, do not update the lastKey value
assert
(
pQuery
->
ekey
>
pPrimaryColumn
[
pQuery
->
pos
]);
}
else
{
pQuery
->
lastKey
=
pQuery
->
ekey
+
step
;
// pPrimaryColumn[pQuery->pos - (forwardStep - 1)]
+ step;
pQuery
->
lastKey
=
MIN
(
pQuery
->
ekey
,
pPrimaryColumn
[
pQuery
->
pos
-
(
forwardStep
-
1
)])
+
step
;
}
}
else
{
forwardStep
=
pQuery
->
pos
+
1
;
assert
(
forwardStep
>
0
);
pQuery
->
lastKey
=
pBlockInfo
->
keyFirst
+
step
;
}
}
assert
(
forwardStep
>=
0
);
int32_t
newForwardStep
=
reviseForwardSteps
(
pRuntimeEnv
,
forwardStep
);
assert
(
newForwardStep
<=
forwardStep
&&
newForwardStep
>=
0
);
...
...
@@ -4380,8 +4369,8 @@ static int32_t createQueryResultBuffer(SQueryRuntimeEnv *pRuntimeEnv, int32_t nu
// pRuntimeEnv->windowResInfo.pResult = calloc(numOfRows, sizeof(SWindowResult));
//
// for (int32_t k = 0; k < numOfRows; ++k) {
// SWindowResult *p
One
Res = &pRuntimeEnv->windowResInfo.pResult[k];
// p
One
Res->nAlloc = 1;
// SWindowResult *p
Window
Res = &pRuntimeEnv->windowResInfo.pResult[k];
// p
Window
Res->nAlloc = 1;
//
// /*
// * for single table top/bottom query, the output for group by normal column, the output rows is
...
...
@@ -4391,7 +4380,7 @@ static int32_t createQueryResultBuffer(SQueryRuntimeEnv *pRuntimeEnv, int32_t nu
// assert(pQuery->numOfOutputCols > 1);
//
// SSqlFunctionExpr *pExpr = &pQuery->pSelectExpr[1];
// p
One
Res->nAlloc = pExpr->pBase.arg[0].argValue.i64;
// p
Window
Res->nAlloc = pExpr->pBase.arg[0].argValue.i64;
// }
//
// if (page == NULL || page->numOfElems >= pRuntimeEnv->numOfRowsPerPage) {
...
...
@@ -4401,7 +4390,7 @@ static int32_t createQueryResultBuffer(SQueryRuntimeEnv *pRuntimeEnv, int32_t nu
// assert(pageId >= 0);
//
// SPosInfo posInfo = {.pageId = pageId, .rowId = page->numOfElems};
// createQueryResultInfo(pQuery, p
One
Res, isSTableQuery, &posInfo);
// createQueryResultInfo(pQuery, p
Window
Res, isSTableQuery, &posInfo);
// page->numOfElems += 1; // next row is available
// }
...
...
@@ -4564,7 +4553,8 @@ int32_t vnodeQuerySingleMeterPrepare(SQInfo *pQInfo, SMeterObj *pMeterObj, SMete
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
||
(
pQuery
->
intervalTime
>
0
&&
pQuery
->
slidingTime
>
0
))
{
int32_t
rows
=
initialNumOfRows
(
pSupporter
);
if
((
code
=
createQueryResultBuffer
(
pRuntimeEnv
,
rows
,
false
))
!=
TSDB_CODE_SUCCESS
)
{
code
=
createDiskbasedResultBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
rows
,
pQuery
->
rowSize
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
@@ -4771,7 +4761,8 @@ int32_t vnodeMultiMeterQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param)
vnodeRecordAllFiles
(
pQInfo
,
pMeter
->
vnode
);
if
(
pQuery
->
intervalTime
==
0
&&
pQuery
->
slidingTime
<=
0
)
{
if
((
ret
=
createQueryResultBuffer
(
pRuntimeEnv
,
3
,
true
))
!=
TSDB_CODE_SUCCESS
)
{
ret
=
createDiskbasedResultBuffer
(
&
pRuntimeEnv
->
pResultBuf
,
3
,
pQuery
->
rowSize
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -5194,7 +5185,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
cnt
+=
forwardStep
;
if
(
query
CompleteIn
Block
(
pQuery
,
&
blockInfo
,
forwardStep
))
{
if
(
query
PausedInCurrent
Block
(
pQuery
,
&
blockInfo
,
forwardStep
))
{
int32_t
nextPos
=
accessPos
+
step
;
/*
...
...
@@ -5203,33 +5194,38 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
* 2. multi-output query that may cause buffer overflow.
*/
if
(
pQuery
->
intervalTime
>
0
||
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_RESBUF_FULL
)
&&
pQuery
->
checkBufferInLoop
==
1
))
{
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_RESBUF_FULL
)
/* && pQuery->checkBufferInLoop == 1*/
))
{
if
(
nextPos
>=
blockInfo
.
size
||
nextPos
<
0
)
{
moveToNextBlock
(
pRuntimeEnv
,
step
,
searchFn
,
!
LOAD_DATA
);
if
(
!
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_NO_DATA_TO_CHECK
|
QUERY_COMPLETED
))
{
// slot/pos/fileId is updated in moveToNextBlock function
savePointPosition
(
&
pRuntimeEnv
->
nextPos
,
pQuery
->
fileId
,
pQuery
->
slot
,
pQuery
->
pos
);
// check next block
void
*
pNextBlock
=
getGenericDataBlock
(
pMeterObj
,
pRuntimeEnv
,
pQuery
->
slot
);
int32_t
blockType
=
(
IS_DISK_DATA_BLOCK
(
pQuery
))
?
BLK_FILE_BLOCK
:
BLK_CACHE_BLOCK
;
blockInfo
=
getBlockBasicInfo
(
pRuntimeEnv
,
pNextBlock
,
blockType
);
// check if need to close window result or not
if
(
pQuery
->
intervalTime
>
0
&&
pQuery
->
slidingTime
>
0
)
{
TSKEY
t
=
(
QUERY_IS_ASC_QUERY
(
pQuery
))
?
blockInfo
.
keyFirst
:
blockInfo
.
keyLast
;
doCheckQueryCompleted
(
pRuntimeEnv
,
t
,
&
pRuntimeEnv
->
windowResInfo
);
}
}
}
else
{
savePointPosition
(
&
pRuntimeEnv
->
nextPos
,
pQuery
->
fileId
,
pQuery
->
slot
,
accessPos
+
step
);
}
}
break
;
}
else
{
// query not completed, move to next block
int64_t
start
=
taosGetTimestampUs
();
blockLoadStatus
=
moveToNextBlock
(
pRuntimeEnv
,
step
,
searchFn
,
LOAD_DATA
);
if
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_NO_DATA_TO_CHECK
|
QUERY_COMPLETED
))
{
savePointPosition
(
&
pRuntimeEnv
->
nextPos
,
pQuery
->
fileId
,
pQuery
->
slot
,
pQuery
->
pos
);
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
break
;
}
int64_t
delta
=
(
taosGetTimestampUs
()
-
start
);
if
(
IS_DISK_DATA_BLOCK
(
pQuery
))
{
pSummary
->
fileTimeUs
+=
delta
;
}
else
{
pSummary
->
cacheTimeUs
+=
delta
;
}
}
// check next block
...
...
@@ -5237,9 +5233,23 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) {
int32_t
blockType
=
(
IS_DISK_DATA_BLOCK
(
pQuery
))
?
BLK_FILE_BLOCK
:
BLK_CACHE_BLOCK
;
blockInfo
=
getBlockBasicInfo
(
pRuntimeEnv
,
pNextBlock
,
blockType
);
if
(
!
checkQueryRangeAgainstNextBlock
(
&
blockInfo
,
pRuntimeEnv
))
{
if
((
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
blockInfo
.
keyFirst
>
pQuery
->
ekey
)
||
(
!
QUERY_IS_ASC_QUERY
(
pQuery
)
&&
blockInfo
.
keyLast
<
pQuery
->
ekey
))
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
break
;
}
// check if need to close window result or not
if
(
pQuery
->
intervalTime
>
0
&&
pQuery
->
slidingTime
>
0
)
{
TSKEY
t
=
(
QUERY_IS_ASC_QUERY
(
pQuery
))
?
blockInfo
.
keyFirst
:
blockInfo
.
keyLast
;
doCheckQueryCompleted
(
pRuntimeEnv
,
t
,
&
pRuntimeEnv
->
windowResInfo
);
}
if
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_RESBUF_FULL
))
{
break
;
}
}
// while(1)
return
cnt
;
...
...
@@ -5914,25 +5924,38 @@ void createQueryResultInfo(SQuery *pQuery, SWindowResult *pResultRow, bool isSTa
}
}
void
clearGroupResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
p
OneOutput
Res
)
{
if
(
p
OneOutput
Res
==
NULL
)
{
void
clearGroupResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
p
Window
Res
)
{
if
(
p
Window
Res
==
NULL
)
{
return
;
}
for
(
int32_t
i
=
0
;
i
<
pRuntimeEnv
->
pQuery
->
numOfOutputCols
;
++
i
)
{
SResultInfo
*
pResultInfo
=
&
p
OneOutput
Res
->
resultInfo
[
i
];
SResultInfo
*
pResultInfo
=
&
p
Window
Res
->
resultInfo
[
i
];
char
*
s
=
getPosInResultPage
(
pRuntimeEnv
,
i
,
p
OneOutput
Res
);
char
*
s
=
getPosInResultPage
(
pRuntimeEnv
,
i
,
p
Window
Res
);
size_t
size
=
pRuntimeEnv
->
pQuery
->
pSelectExpr
[
i
].
resBytes
;
memset
(
s
,
0
,
size
);
resetResultInfo
(
pResultInfo
);
}
pWindowRes
->
numOfRows
=
0
;
pWindowRes
->
nAlloc
=
0
;
pWindowRes
->
pos
=
(
SPosInfo
){
-
1
,
-
1
};
pWindowRes
->
status
.
closed
=
false
;
pWindowRes
->
window
=
(
STimeWindow
)
{
0
,
0
};
}
/**
* The source window result pos attribution of the source window result does not assign to the destination,
* since the attribute of "Pos" is bound to each window result when the window result is created in the
* disk-based result buffer.
*/
void
copyGroupResultBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
dst
,
const
SWindowResult
*
src
)
{
dst
->
numOfRows
=
src
->
numOfRows
;
dst
->
nAlloc
=
src
->
nAlloc
;
dst
->
window
=
src
->
window
;
dst
->
status
=
src
->
status
;
int32_t
nOutputCols
=
pRuntimeEnv
->
pQuery
->
numOfOutputCols
;
...
...
@@ -5956,16 +5979,16 @@ void copyGroupResultBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *dst, const
}
}
void
destroyGroupResultBuf
(
SWindowResult
*
p
OneOutput
Res
,
int32_t
nOutputCols
)
{
if
(
p
OneOutput
Res
==
NULL
)
{
void
destroyGroupResultBuf
(
SWindowResult
*
p
Window
Res
,
int32_t
nOutputCols
)
{
if
(
p
Window
Res
==
NULL
)
{
return
;
}
for
(
int32_t
i
=
0
;
i
<
nOutputCols
;
++
i
)
{
free
(
p
OneOutput
Res
->
resultInfo
[
i
].
interResultBuf
);
free
(
p
Window
Res
->
resultInfo
[
i
].
interResultBuf
);
}
free
(
p
OneOutput
Res
->
resultInfo
);
free
(
p
Window
Res
->
resultInfo
);
}
void
resetCtxOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
)
{
...
...
@@ -6005,7 +6028,7 @@ void forwardCtxOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, int64_t output) {
// set next output position
if
(
IS_OUTER_FORWARD
(
aAggs
[
functionId
].
nStatus
))
{
pRuntimeEnv
->
pCtx
[
j
].
aOutputBuf
+=
pRuntimeEnv
->
pCtx
[
j
].
outputBytes
*
output
/** factor*/
;
pRuntimeEnv
->
pCtx
[
j
].
aOutputBuf
+=
pRuntimeEnv
->
pCtx
[
j
].
outputBytes
*
output
;
}
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
)
{
...
...
@@ -6239,8 +6262,7 @@ void vnodeScanAllData(SQueryRuntimeEnv *pRuntimeEnv) {
doSingleMeterSupplementScan
(
pRuntimeEnv
);
// update the pQuery->skey/pQuery->ekey to limit the scan scope of sliding query during
// supplementary scan
// update the pQuery->skey/pQuery->ekey to limit the scan scope of sliding query during supplementary scan
pQuery
->
skey
=
newSkey
;
}
...
...
@@ -6375,30 +6397,30 @@ void forwardIntervalQueryRange(SMeterQuerySupportObj *pSupporter, SQueryRuntimeE
return
;
}
int32_t
r
=
getNextIntervalQueryRange
(
pSupporter
,
pRuntimeEnv
,
&
pQuery
->
skey
,
&
pQuery
->
ekey
);
if
(
r
==
QUERY_COMPLETED
)
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
return
;
}
getNextLogicalQueryRange
(
pRuntimeEnv
,
&
pRuntimeEnv
->
intervalWindow
);
/* ensure the search in cache will return right position */
pQuery
->
lastKey
=
pQuery
->
skey
;
TSKEY
nextTimestamp
=
loadRequiredBlockIntoMem
(
pRuntimeEnv
,
&
pRuntimeEnv
->
nextPos
);
if
((
nextTimestamp
>
pSupporter
->
rawEKey
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
(
nextTimestamp
<
pSupporter
->
rawEKey
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
))
||
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_NO_DATA_TO_CHECK
))
{
setQueryStatus
(
pQuery
,
QUERY_COMPLETED
);
return
;
}
// bridge the gap in group by time function
if
((
nextTimestamp
>
pQuery
->
ekey
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
(
nextTimestamp
<
pQuery
->
ekey
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
)))
{
getAlignedIntervalQueryRange
(
pRuntimeEnv
,
nextTimestamp
,
pSupporter
->
rawSKey
,
pSupporter
->
rawEKey
);
}
//
int32_t r = getNextIntervalQueryRange(pSupporter, pRuntimeEnv, &pQuery->skey, &pQuery->ekey);
//
if (r == QUERY_COMPLETED) {
//
setQueryStatus(pQuery, QUERY_COMPLETED);
//
return;
//
}
//
//
getNextLogicalQueryRange(pRuntimeEnv, &pRuntimeEnv->intervalWindow);
//
//
/* ensure the search in cache will return right position */
//
pQuery->lastKey = pQuery->skey;
//
//
TSKEY nextTimestamp = loadRequiredBlockIntoMem(pRuntimeEnv, &pRuntimeEnv->nextPos);
//
if ((nextTimestamp > pSupporter->rawEKey && QUERY_IS_ASC_QUERY(pQuery)) ||
//
(nextTimestamp < pSupporter->rawEKey && !QUERY_IS_ASC_QUERY(pQuery)) ||
//
Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) {
//
setQueryStatus(pQuery, QUERY_COMPLETED);
//
return;
//
}
//
//
// bridge the gap in group by time function
//
if ((nextTimestamp > pQuery->ekey && QUERY_IS_ASC_QUERY(pQuery)) ||
//
(nextTimestamp < pQuery->ekey && !QUERY_IS_ASC_QUERY(pQuery))) {
//
getAlignedIntervalQueryRange(pRuntimeEnv, nextTimestamp, pSupporter->rawSKey, pSupporter->rawEKey);
//
}
}
static
int32_t
offsetComparator
(
const
void
*
pLeft
,
const
void
*
pRight
)
{
...
...
src/system/detail/src/vnodeQueryProcess.c
浏览文件 @
2a89ac7d
...
...
@@ -1114,11 +1114,8 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
SQuery
*
pQuery
=
pRuntimeEnv
->
pQuery
;
while
(
1
)
{
assert
((
pQuery
->
skey
<=
pQuery
->
ekey
&&
QUERY_IS_ASC_QUERY
(
pQuery
))
||
(
pQuery
->
skey
>=
pQuery
->
ekey
&&
!
QUERY_IS_ASC_QUERY
(
pQuery
)));
initCtxOutputBuf
(
pRuntimeEnv
);
clearC
omplet
edSlidingWindows
(
pRuntimeEnv
);
clearC
los
edSlidingWindows
(
pRuntimeEnv
);
vnodeScanAllData
(
pRuntimeEnv
);
if
(
isQueryKilled
(
pQuery
))
{
...
...
@@ -1141,16 +1138,17 @@ static void vnodeSingleMeterIntervalMainLooper(SMeterQuerySupportObj *pSupporter
pQuery
->
limit
.
offset
--
;
}
}
else
{
pQuery
->
pointsRead
+=
maxOutput
;
forwardCtxOutputBuf
(
pRuntimeEnv
,
maxOutput
);
// assert(0);
// pQuery->pointsRead += maxOutput;
// forwardCtxOutputBuf(pRuntimeEnv, maxOutput);
}
if
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_NO_DATA_TO_CHECK
))
{
break
;
}
forwardIntervalQueryRange
(
pSupporter
,
pRuntimeEnv
);
if
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_
COMPLETED
|
QUERY_
RESBUF_FULL
))
{
loadRequiredBlockIntoMem
(
pRuntimeEnv
,
&
pRuntimeEnv
->
nextPos
);
if
(
Q_STATUS_EQUAL
(
pQuery
->
over
,
QUERY_RESBUF_FULL
))
{
break
;
}
...
...
@@ -1181,6 +1179,12 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
resetCtxOutputBuf
(
pRuntimeEnv
);
vnodeSingleMeterIntervalMainLooper
(
pSupporter
,
pRuntimeEnv
);
if
(
pQuery
->
intervalTime
>
0
)
{
pSupporter
->
subgroupIdx
=
0
;
pQuery
->
pointsRead
=
0
;
copyFromGroupBuf
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
}
// the offset is handled at prepare stage if no interpolation involved
if
(
pQuery
->
interpoType
==
TSDB_INTERPO_NONE
)
{
doRevisedResultsByLimit
(
pQInfo
);
...
...
@@ -1208,8 +1212,9 @@ static void vnodeSingleTableIntervalProcessor(SQInfo *pQInfo) {
}
}
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
)
||
(
pQuery
->
slidingTime
>
0
&&
pQuery
->
intervalTime
>
0
))
{
pQInfo
->
pMeterQuerySupporter
->
subgroupIdx
=
0
;
// all data scanned, the group by normal column can return
if
(
isGroupbyNormalCol
(
pQuery
->
pGroupbyExpr
))
{
pSupporter
->
subgroupIdx
=
0
;
pQuery
->
pointsRead
=
0
;
copyFromGroupBuf
(
pQInfo
,
pRuntimeEnv
->
windowResInfo
.
pResult
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录