Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
8972ebc1
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8972ebc1
编写于
8月 18, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-1103] refactor the structure for reducing memory consumption during interval query.
上级
18926450
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
177 addition
and
171 deletion
+177
-171
src/query/inc/qExecutor.h
src/query/inc/qExecutor.h
+7
-9
src/query/inc/qUtil.h
src/query/inc/qUtil.h
+2
-1
src/query/inc/tsqlfunction.h
src/query/inc/tsqlfunction.h
+7
-7
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+137
-134
src/query/src/qUtil.c
src/query/src/qUtil.c
+24
-20
未找到文件。
src/query/inc/qExecutor.h
浏览文件 @
8972ebc1
...
...
@@ -42,20 +42,16 @@ typedef struct SSqlGroupbyExpr {
}
SSqlGroupbyExpr
;
typedef
struct
SPosInfo
{
int32_t
pageId
;
int32_t
rowId
;
int32_t
pageId
:
20
;
int32_t
rowId
:
12
;
}
SPosInfo
;
typedef
struct
SWindowStatus
{
bool
closed
;
}
SWindowStatus
;
typedef
struct
SWindowResult
{
uint16_t
numOfRows
;
// number of rows of current time window
SWindowStatus
status
;
// this result status: closed or opened
SPosInfo
pos
;
// Position of current result in disk-based output buffer
uint16_t
numOfRows
;
// number of rows of current time window
bool
closed
;
// this result status: closed or opened
SResultInfo
*
resultInfo
;
// For each result column, there is a resultInfo
STimeWindow
window
;
// The time window that current result covers.
TSKEY
skey
;
// start key of current time window
}
SWindowResult
;
/**
...
...
@@ -79,6 +75,7 @@ typedef struct SWindowResInfo {
int64_t
startTime
;
// start time of the first time window for sliding query
int64_t
prevSKey
;
// previous (not completed) sliding window start key
int64_t
threshold
;
// threshold to halt query and return the generated results.
int64_t
interval
;
// time window interval
}
SWindowResInfo
;
typedef
struct
SColumnFilterElem
{
...
...
@@ -123,6 +120,7 @@ typedef struct SQueryCostInfo {
uint64_t
elapsedTime
;
uint64_t
computTime
;
uint64_t
internalSupSize
;
uint64_t
numOfTimeWindows
;
}
SQueryCostInfo
;
typedef
struct
SQuery
{
...
...
src/query/inc/qUtil.h
浏览文件 @
8972ebc1
...
...
@@ -38,7 +38,8 @@ static FORCE_INLINE SWindowResult *getWindowResult(SWindowResInfo *pWindowResInf
return
&
pWindowResInfo
->
pResult
[
slot
];
}
#define curTimeWindow(_winres) ((_winres)->curIndex)
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
#define GET_TIMEWINDOW(_winresInfo, _win) (STimeWindow) {(_win)->skey, ((_win)->skey + (_winresInfo)->interval)}
#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!sq))? (_q)->pSelectExpr[1].base.arg->argValue.i64:1)
bool
isWindowResClosed
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
);
...
...
src/query/inc/tsqlfunction.h
浏览文件 @
8972ebc1
...
...
@@ -137,13 +137,13 @@ typedef struct SInterpInfoDetail {
}
SInterpInfoDetail
;
typedef
struct
SResultInfo
{
int8_t
hasResult
;
// result generated, not NULL value
bool
initialized
;
// output buffer has been initialized
bool
complete
;
// query has completed
bool
superTableQ
;
// is super table query
int
32_t
numOfRes
;
// num of output result in current buffer
int32_t
bufLen
;
// buffer size
void
*
interResultBuf
;
// output result buffer
int8_t
hasResult
;
// result generated, not NULL value
bool
initialized
:
1
;
// output buffer has been initialized
bool
complete
:
1
;
// query has completed
bool
superTableQ
:
1
;
// is super table query
int
16_t
numOfRes
;
// num of output result in current buffer
u
int32_t
bufLen
;
// buffer size
void
*
interResultBuf
;
// output result buffer
}
SResultInfo
;
struct
SQLFunctionCtx
;
...
...
src/query/src/qExecutor.c
浏览文件 @
8972ebc1
此差异已折叠。
点击以展开。
src/query/src/qUtil.c
浏览文件 @
8972ebc1
...
...
@@ -45,8 +45,8 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun
pWindowResInfo
->
curIndex
=
-
1
;
pWindowResInfo
->
size
=
0
;
pWindowResInfo
->
prevSKey
=
TSKEY_INITIAL_VAL
;
pRuntimeEnv
->
summary
.
internalSupSize
+=
sizeof
(
SWindowResult
)
*
threshold
;
SQueryCostInfo
*
pSummary
=
&
pRuntimeEnv
->
summary
;
// use the pointer arraylist
pWindowResInfo
->
pResult
=
calloc
(
threshold
,
sizeof
(
SWindowResult
));
...
...
@@ -54,8 +54,11 @@ int32_t initWindowResInfo(SWindowResInfo *pWindowResInfo, SQueryRuntimeEnv *pRun
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
pRuntimeEnv
->
summary
.
internalSupSize
+=
sizeof
(
SWindowResult
)
*
threshold
;
pRuntimeEnv
->
summary
.
internalSupSize
+=
(
pRuntimeEnv
->
pQuery
->
numOfOutput
*
sizeof
(
SResultInfo
)
+
pRuntimeEnv
->
interBufSize
)
*
pWindowResInfo
->
capacity
;
pWindowResInfo
->
interval
=
pRuntimeEnv
->
pQuery
->
intervalTime
;
pSummary
->
internalSupSize
+=
sizeof
(
SWindowResult
)
*
threshold
;
pSummary
->
internalSupSize
+=
(
pRuntimeEnv
->
pQuery
->
numOfOutput
*
sizeof
(
SResultInfo
)
+
pRuntimeEnv
->
interBufSize
)
*
pWindowResInfo
->
capacity
;
pSummary
->
numOfTimeWindows
=
threshold
;
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
capacity
;
++
i
)
{
int32_t
code
=
createQueryResultInfo
(
pRuntimeEnv
->
pQuery
,
&
pWindowResInfo
->
pResult
[
i
],
pRuntimeEnv
->
stableQuery
,
pRuntimeEnv
->
interBufSize
);
...
...
@@ -126,8 +129,8 @@ void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SWindowResult
*
pResult
=
&
pWindowResInfo
->
pResult
[
i
];
if
(
pResult
->
status
.
closed
)
{
// remove the window slot from hash table
taosHashRemove
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
pWindowResInfo
->
type
);
if
(
pResult
->
closed
)
{
// remove the window slot from hash table
taosHashRemove
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
skey
,
pWindowResInfo
->
type
);
}
else
{
break
;
}
...
...
@@ -149,12 +152,12 @@ void clearFirstNTimeWindow(SQueryRuntimeEnv *pRuntimeEnv, int32_t num) {
pWindowResInfo
->
size
=
remain
;
for
(
int32_t
k
=
0
;
k
<
pWindowResInfo
->
size
;
++
k
)
{
SWindowResult
*
pResult
=
&
pWindowResInfo
->
pResult
[
k
];
int32_t
*
p
=
(
int32_t
*
)
taosHashGet
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
window
.
skey
,
int32_t
*
p
=
(
int32_t
*
)
taosHashGet
(
pWindowResInfo
->
hashList
,
(
const
char
*
)
&
pResult
->
skey
,
tDataTypeDesc
[
pWindowResInfo
->
type
].
nSize
);
assert
(
p
!=
NULL
);
int32_t
v
=
(
*
p
-
num
);
assert
(
v
>=
0
&&
v
<=
pWindowResInfo
->
size
);
taosHashPut
(
pWindowResInfo
->
hashList
,
(
char
*
)
&
pResult
->
window
.
skey
,
tDataTypeDesc
[
pWindowResInfo
->
type
].
nSize
,
taosHashPut
(
pWindowResInfo
->
hashList
,
(
char
*
)
&
pResult
->
skey
,
tDataTypeDesc
[
pWindowResInfo
->
type
].
nSize
,
(
char
*
)
&
v
,
sizeof
(
int32_t
));
}
...
...
@@ -173,7 +176,7 @@ void clearClosedTimeWindow(SQueryRuntimeEnv *pRuntimeEnv) {
int32_t
numOfClosedTimeWindow
(
SWindowResInfo
*
pWindowResInfo
)
{
int32_t
i
=
0
;
while
(
i
<
pWindowResInfo
->
size
&&
pWindowResInfo
->
pResult
[
i
].
status
.
closed
)
{
while
(
i
<
pWindowResInfo
->
size
&&
pWindowResInfo
->
pResult
[
i
].
closed
)
{
++
i
;
}
...
...
@@ -184,11 +187,11 @@ void closeAllTimeWindow(SWindowResInfo *pWindowResInfo) {
assert
(
pWindowResInfo
->
size
>=
0
&&
pWindowResInfo
->
capacity
>=
pWindowResInfo
->
size
);
for
(
int32_t
i
=
0
;
i
<
pWindowResInfo
->
size
;
++
i
)
{
if
(
pWindowResInfo
->
pResult
[
i
].
status
.
closed
)
{
if
(
pWindowResInfo
->
pResult
[
i
].
closed
)
{
continue
;
}
pWindowResInfo
->
pResult
[
i
].
status
.
closed
=
true
;
pWindowResInfo
->
pResult
[
i
].
closed
=
true
;
}
}
...
...
@@ -204,7 +207,7 @@ void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_
}
// get the result order
int32_t
resultOrder
=
(
pWindowResInfo
->
pResult
[
0
].
window
.
skey
<
pWindowResInfo
->
pResult
[
1
].
window
.
skey
)
?
1
:-
1
;
int32_t
resultOrder
=
(
pWindowResInfo
->
pResult
[
0
].
skey
<
pWindowResInfo
->
pResult
[
1
]
.
skey
)
?
1
:-
1
;
if
(
order
!=
resultOrder
)
{
return
;
...
...
@@ -212,11 +215,12 @@ void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_
int32_t
i
=
0
;
if
(
order
==
QUERY_ASC_FORWARD_STEP
)
{
while
(
i
<
pWindowResInfo
->
size
&&
(
pWindowResInfo
->
pResult
[
i
].
window
.
ekey
<
lastKey
))
{
TSKEY
ekey
=
pWindowResInfo
->
pResult
[
i
].
skey
+
pWindowResInfo
->
interval
;
while
(
i
<
pWindowResInfo
->
size
&&
(
ekey
<
lastKey
))
{
++
i
;
}
}
else
if
(
order
==
QUERY_DESC_FORWARD_STEP
)
{
while
(
i
<
pWindowResInfo
->
size
&&
(
pWindowResInfo
->
pResult
[
i
].
window
.
skey
>
lastKey
))
{
while
(
i
<
pWindowResInfo
->
size
&&
(
pWindowResInfo
->
pResult
[
i
].
skey
>
lastKey
))
{
++
i
;
}
}
...
...
@@ -227,11 +231,11 @@ void removeRedundantWindow(SWindowResInfo *pWindowResInfo, TSKEY lastKey, int32_
}
bool
isWindowResClosed
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
)
{
return
(
getWindowResult
(
pWindowResInfo
,
slot
)
->
status
.
closed
==
true
);
return
(
getWindowResult
(
pWindowResInfo
,
slot
)
->
closed
==
true
);
}
void
closeTimeWindow
(
SWindowResInfo
*
pWindowResInfo
,
int32_t
slot
)
{
getWindowResult
(
pWindowResInfo
,
slot
)
->
status
.
closed
=
true
;
getWindowResult
(
pWindowResInfo
,
slot
)
->
closed
=
true
;
}
void
clearTimeWindowResBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
pWindowRes
)
{
...
...
@@ -253,8 +257,8 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
pWindowRes
->
numOfRows
=
0
;
pWindowRes
->
pos
=
(
SPosInfo
){
-
1
,
-
1
};
pWindowRes
->
status
.
closed
=
false
;
pWindowRes
->
window
=
TSWINDOW_INITIALIZER
;
pWindowRes
->
closed
=
false
;
pWindowRes
->
skey
=
TSKEY_INITIAL_VAL
;
}
/**
...
...
@@ -264,8 +268,8 @@ void clearTimeWindowResBuf(SQueryRuntimeEnv *pRuntimeEnv, SWindowResult *pWindow
*/
void
copyTimeWindowResBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SWindowResult
*
dst
,
const
SWindowResult
*
src
)
{
dst
->
numOfRows
=
src
->
numOfRows
;
dst
->
window
=
src
->
window
;
dst
->
status
=
src
->
status
;
dst
->
skey
=
src
->
skey
;
dst
->
closed
=
src
->
closed
;
int32_t
nOutputCols
=
pRuntimeEnv
->
pQuery
->
numOfOutput
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录