Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6d9e229a
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看板
提交
6d9e229a
编写于
12月 02, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: fix the in-memory row merge.
上级
1cf9974b
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
33 addition
and
32 deletion
+33
-32
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+27
-17
source/libs/function/src/detail/tavgfunction.c
source/libs/function/src/detail/tavgfunction.c
+6
-15
未找到文件。
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
6d9e229a
...
@@ -194,7 +194,7 @@ static void setComposedBlockFlag(STsdbReader* pReader, bool composed);
...
@@ -194,7 +194,7 @@ static void setComposedBlockFlag(STsdbReader* pReader, bool composed);
static
bool
hasBeenDropped
(
const
SArray
*
pDelList
,
int32_t
*
index
,
TSDBKEY
*
pKey
,
int32_t
order
,
static
bool
hasBeenDropped
(
const
SArray
*
pDelList
,
int32_t
*
index
,
TSDBKEY
*
pKey
,
int32_t
order
,
SVersionRange
*
pVerRange
);
SVersionRange
*
pVerRange
);
static
int32_t
doMergeMemTableMultiRows
(
TSDBROW
*
pRow
,
uint64_t
uid
,
SIterInfo
*
pIter
,
SArray
*
pDelList
,
SRow
*
*
pTSRow
,
static
int32_t
doMergeMemTableMultiRows
(
TSDBROW
*
pRow
,
uint64_t
uid
,
SIterInfo
*
pIter
,
SArray
*
pDelList
,
TSDBROW
*
pTSRow
,
STsdbReader
*
pReader
,
bool
*
freeTSRow
);
STsdbReader
*
pReader
,
bool
*
freeTSRow
);
static
int32_t
doMergeMemIMemRows
(
TSDBROW
*
pRow
,
TSDBROW
*
piRow
,
STableBlockScanInfo
*
pBlockScanInfo
,
static
int32_t
doMergeMemIMemRows
(
TSDBROW
*
pRow
,
TSDBROW
*
piRow
,
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
,
SRow
**
pTSRow
);
STsdbReader
*
pReader
,
SRow
**
pTSRow
);
...
@@ -3358,7 +3358,7 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
...
@@ -3358,7 +3358,7 @@ int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockSc
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
doMergeMemTableMultiRows
(
TSDBROW
*
pRow
,
uint64_t
uid
,
SIterInfo
*
pIter
,
SArray
*
pDelList
,
SRow
**
pTS
Row
,
int32_t
doMergeMemTableMultiRows
(
TSDBROW
*
pRow
,
uint64_t
uid
,
SIterInfo
*
pIter
,
SArray
*
pDelList
,
TSDBROW
*
pRes
Row
,
STsdbReader
*
pReader
,
bool
*
freeTSRow
)
{
STsdbReader
*
pReader
,
bool
*
freeTSRow
)
{
TSDBROW
*
pNextRow
=
NULL
;
TSDBROW
*
pNextRow
=
NULL
;
TSDBROW
current
=
*
pRow
;
TSDBROW
current
=
*
pRow
;
...
@@ -3367,25 +3367,27 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
...
@@ -3367,25 +3367,27 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
pIter
->
hasVal
=
tsdbTbDataIterNext
(
pIter
->
iter
);
pIter
->
hasVal
=
tsdbTbDataIterNext
(
pIter
->
iter
);
if
(
!
pIter
->
hasVal
)
{
if
(
!
pIter
->
hasVal
)
{
*
p
TSRow
=
current
.
pTS
Row
;
*
p
ResRow
=
*
p
Row
;
*
freeTSRow
=
false
;
*
freeTSRow
=
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
else
{
// has next point in mem/imem
}
else
{
// has next point in mem/imem
pNextRow
=
getValidMemRow
(
pIter
,
pDelList
,
pReader
);
pNextRow
=
getValidMemRow
(
pIter
,
pDelList
,
pReader
);
if
(
pNextRow
==
NULL
)
{
if
(
pNextRow
==
NULL
)
{
*
p
TSRow
=
current
.
pTS
Row
;
*
p
ResRow
=
*
p
Row
;
*
freeTSRow
=
false
;
*
freeTSRow
=
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
if
(
TSDBROW_TS
(
&
current
)
!=
TSDBROW_TS
(
pNextRow
))
{
if
(
TSDBROW_TS
(
&
current
)
!=
TSDBROW_TS
(
pNextRow
))
{
*
p
TSRow
=
current
.
pTS
Row
;
*
p
ResRow
=
*
p
Row
;
*
freeTSRow
=
false
;
*
freeTSRow
=
false
;
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
}
}
}
}
#if 0
// todo handle the data block merge
SRowMerger merge = {0};
SRowMerger merge = {0};
// get the correct schema for data in memory
// get the correct schema for data in memory
...
@@ -3423,6 +3425,8 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
...
@@ -3423,6 +3425,8 @@ int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter,
tsdbRowMergerClear(&merge);
tsdbRowMergerClear(&merge);
*freeTSRow = true;
*freeTSRow = true;
#endif
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -3480,7 +3484,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
...
@@ -3480,7 +3484,7 @@ int32_t doMergeMemIMemRows(TSDBROW* pRow, TSDBROW* piRow, STableBlockScanInfo* p
return
code
;
return
code
;
}
}
int32_t
tsdbGetNextRowInMem
(
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
,
SRow
**
pTS
Row
,
int64_t
endKey
,
int32_t
tsdbGetNextRowInMem
(
STableBlockScanInfo
*
pBlockScanInfo
,
STsdbReader
*
pReader
,
TSDBROW
*
pRes
Row
,
int64_t
endKey
,
bool
*
freeTSRow
)
{
bool
*
freeTSRow
)
{
TSDBROW
*
pRow
=
getValidMemRow
(
&
pBlockScanInfo
->
iter
,
pBlockScanInfo
->
delSkyline
,
pReader
);
TSDBROW
*
pRow
=
getValidMemRow
(
&
pBlockScanInfo
->
iter
,
pBlockScanInfo
->
delSkyline
,
pReader
);
TSDBROW
*
piRow
=
getValidMemRow
(
&
pBlockScanInfo
->
iiter
,
pBlockScanInfo
->
delSkyline
,
pReader
);
TSDBROW
*
piRow
=
getValidMemRow
(
&
pBlockScanInfo
->
iiter
,
pBlockScanInfo
->
delSkyline
,
pReader
);
...
@@ -3510,13 +3514,14 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
...
@@ -3510,13 +3514,14 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
ik
.
ts
!=
k
.
ts
)
{
if
(
ik
.
ts
!=
k
.
ts
)
{
if
(((
ik
.
ts
<
k
.
ts
)
&&
asc
)
||
((
ik
.
ts
>
k
.
ts
)
&&
(
!
asc
)))
{
// ik.ts < k.ts
if
(((
ik
.
ts
<
k
.
ts
)
&&
asc
)
||
((
ik
.
ts
>
k
.
ts
)
&&
(
!
asc
)))
{
// ik.ts < k.ts
code
=
doMergeMemTableMultiRows
(
piRow
,
uid
,
&
pBlockScanInfo
->
iiter
,
pDelList
,
p
TS
Row
,
pReader
,
freeTSRow
);
code
=
doMergeMemTableMultiRows
(
piRow
,
uid
,
&
pBlockScanInfo
->
iiter
,
pDelList
,
p
Res
Row
,
pReader
,
freeTSRow
);
}
else
if
(((
k
.
ts
<
ik
.
ts
)
&&
asc
)
||
((
k
.
ts
>
ik
.
ts
)
&&
(
!
asc
)))
{
}
else
if
(((
k
.
ts
<
ik
.
ts
)
&&
asc
)
||
((
k
.
ts
>
ik
.
ts
)
&&
(
!
asc
)))
{
code
=
doMergeMemTableMultiRows
(
pRow
,
uid
,
&
pBlockScanInfo
->
iter
,
pDelList
,
p
TS
Row
,
pReader
,
freeTSRow
);
code
=
doMergeMemTableMultiRows
(
pRow
,
uid
,
&
pBlockScanInfo
->
iter
,
pDelList
,
p
Res
Row
,
pReader
,
freeTSRow
);
}
}
}
else
{
// ik.ts == k.ts
}
else
{
// ik.ts == k.ts
*
freeTSRow
=
true
;
*
freeTSRow
=
true
;
code
=
doMergeMemIMemRows
(
pRow
,
piRow
,
pBlockScanInfo
,
pReader
,
pTSRow
);
pResRow
->
type
=
TSDBROW_ROW_FMT
;
code
=
doMergeMemIMemRows
(
pRow
,
piRow
,
pBlockScanInfo
,
pReader
,
&
pResRow
->
pTSRow
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
return
code
;
}
}
...
@@ -3526,12 +3531,12 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
...
@@ -3526,12 +3531,12 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR
}
}
if
(
pBlockScanInfo
->
iter
.
hasVal
&&
pRow
!=
NULL
)
{
if
(
pBlockScanInfo
->
iter
.
hasVal
&&
pRow
!=
NULL
)
{
return
doMergeMemTableMultiRows
(
pRow
,
pBlockScanInfo
->
uid
,
&
pBlockScanInfo
->
iter
,
pDelList
,
p
TS
Row
,
pReader
,
return
doMergeMemTableMultiRows
(
pRow
,
pBlockScanInfo
->
uid
,
&
pBlockScanInfo
->
iter
,
pDelList
,
p
Res
Row
,
pReader
,
freeTSRow
);
freeTSRow
);
}
}
if
(
pBlockScanInfo
->
iiter
.
hasVal
&&
piRow
!=
NULL
)
{
if
(
pBlockScanInfo
->
iiter
.
hasVal
&&
piRow
!=
NULL
)
{
return
doMergeMemTableMultiRows
(
piRow
,
uid
,
&
pBlockScanInfo
->
iiter
,
pDelList
,
p
TS
Row
,
pReader
,
freeTSRow
);
return
doMergeMemTableMultiRows
(
piRow
,
uid
,
&
pBlockScanInfo
->
iiter
,
pDelList
,
p
Res
Row
,
pReader
,
freeTSRow
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -3636,17 +3641,22 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e
...
@@ -3636,17 +3641,22 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e
SSDataBlock
*
pBlock
=
pReader
->
pResBlock
;
SSDataBlock
*
pBlock
=
pReader
->
pResBlock
;
do
{
do
{
SRow
*
pTSRow
=
NULL
;
// SRow* pTSRow = NULL;
TSDBROW
row
=
{.
type
=
-
1
};
bool
freeTSRow
=
false
;
bool
freeTSRow
=
false
;
tsdbGetNextRowInMem
(
pBlockScanInfo
,
pReader
,
&
pTSR
ow
,
endKey
,
&
freeTSRow
);
tsdbGetNextRowInMem
(
pBlockScanInfo
,
pReader
,
&
r
ow
,
endKey
,
&
freeTSRow
);
if
(
pTSRow
==
NULL
)
{
if
(
row
.
type
==
-
1
)
{
break
;
break
;
}
}
doAppendRowFromTSRow
(
pBlock
,
pReader
,
pTSRow
,
pBlockScanInfo
);
if
(
row
.
type
==
TSDBROW_ROW_FMT
)
{
doAppendRowFromTSRow
(
pBlock
,
pReader
,
row
.
pTSRow
,
pBlockScanInfo
);
if
(
freeTSRow
)
{
if
(
freeTSRow
)
{
taosMemoryFree
(
pTSRow
);
taosMemoryFree
(
row
.
pTSRow
);
}
}
else
{
doAppendRowFromFileBlock
(
pBlock
,
pReader
,
row
.
pBlockData
,
row
.
iRow
);
}
}
// no data in buffer, return immediately
// no data in buffer, return immediately
...
...
source/libs/function/src/detail/tavgfunction.c
浏览文件 @
6d9e229a
...
@@ -270,7 +270,7 @@ static void i64VectorSumAVX2(const int64_t* plist, int32_t numOfRows, SAvgRes* p
...
@@ -270,7 +270,7 @@ static void i64VectorSumAVX2(const int64_t* plist, int32_t numOfRows, SAvgRes* p
#if __AVX2__
#if __AVX2__
// find the start position that are aligned to 32bytes address in memory
// find the start position that are aligned to 32bytes address in memory
int32_t
width
=
(
bitWidth
>>
3u
)
/
sizeof
(
int64_t
);
int32_t
width
=
(
bitWidth
>>
3u
)
/
sizeof
(
int64_t
);
int32_t
remainder
=
numOfRows
%
width
;
int32_t
remainder
=
numOfRows
%
width
;
int32_t
rounds
=
numOfRows
/
width
;
int32_t
rounds
=
numOfRows
/
width
;
...
@@ -286,21 +286,12 @@ static void i64VectorSumAVX2(const int64_t* plist, int32_t numOfRows, SAvgRes* p
...
@@ -286,21 +286,12 @@ static void i64VectorSumAVX2(const int64_t* plist, int32_t numOfRows, SAvgRes* p
}
}
// let sum up the final results
// let sum up the final results
if
(
type
==
TSDB_DATA_TYPE_BIGINT
)
{
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
const
int64_t
*
q
=
(
const
int64_t
*
)
&
sum
;
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
pRes
->
sum
.
isum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
isum
+=
plist
[
j
+
rounds
*
width
];
pRes
->
sum
.
isum
+=
plist
[
j
+
rounds
*
width
];
}
}
}
else
{
const
uint64_t
*
q
=
(
const
uint64_t
*
)
&
sum
;
pRes
->
sum
.
usum
+=
q
[
0
]
+
q
[
1
]
+
q
[
2
]
+
q
[
3
];
for
(
int32_t
j
=
0
;
j
<
remainder
;
++
j
)
{
pRes
->
sum
.
usum
+=
(
uint64_t
)
plist
[
j
+
rounds
*
width
];
}
}
#endif
#endif
}
}
...
@@ -588,7 +579,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
...
@@ -588,7 +579,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) {
const
int64_t
*
plist
=
(
const
int64_t
*
)
pCol
->
pData
;
const
int64_t
*
plist
=
(
const
int64_t
*
)
pCol
->
pData
;
// 1. If the CPU supports AVX, let's employ AVX instructions to speedup this loop
// 1. If the CPU supports AVX, let's employ AVX instructions to speedup this loop
if
(
simdAvailable
)
{
if
(
simdAvailable
&&
type
==
TSDB_DATA_TYPE_BIGINT
)
{
i64VectorSumAVX2
(
plist
,
numOfRows
,
pAvgRes
);
i64VectorSumAVX2
(
plist
,
numOfRows
,
pAvgRes
);
}
else
{
}
else
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录