Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aced34c4
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看板
提交
aced34c4
编写于
4月 06, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix error in sort operation
上级
4bc0e507
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
34 addition
and
35 deletion
+34
-35
source/libs/executor/inc/tsort.h
source/libs/executor/inc/tsort.h
+10
-9
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+2
-2
source/libs/executor/src/tsort.c
source/libs/executor/src/tsort.c
+13
-14
source/libs/executor/test/sortTests.cpp
source/libs/executor/test/sortTests.cpp
+9
-10
未找到文件。
source/libs/executor/inc/tsort.h
浏览文件 @
aced34c4
...
...
@@ -34,16 +34,17 @@ typedef struct SMultiMergeSource {
SSDataBlock
*
pBlock
;
}
SMultiMergeSource
;
typedef
struct
S
ExternalMem
Source
{
typedef
struct
S
Sort
Source
{
SMultiMergeSource
src
;
union
{
struct
{
SArray
*
pageIdList
;
int32_t
pageIndex
;
}
SExternalMemSource
;
typedef
struct
SGenericSource
{
SMultiMergeSource
src
;
};
void
*
param
;
}
SGenericSource
;
};
}
SSortSource
;
typedef
struct
SMsortComparParam
{
void
**
pSources
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
aced34c4
...
...
@@ -5982,7 +5982,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator, bool* newgroup) {
tsortSetFetchRawDataFp
(
pInfo
->
pSortHandle
,
loadNextDataBlock
);
for
(
int32_t
i
=
0
;
i
<
pOperator
->
numOfDownstream
;
++
i
)
{
S
GenericSource
*
ps
=
taosMemoryCalloc
(
1
,
sizeof
(
SGeneric
Source
));
S
SortSource
*
ps
=
taosMemoryCalloc
(
1
,
sizeof
(
SSort
Source
));
ps
->
param
=
pOperator
->
pDownstream
[
i
];
tsortAddSource
(
pInfo
->
pSortHandle
,
ps
);
}
...
...
@@ -6128,7 +6128,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator, bool* newgroup) {
tsortSetFetchRawDataFp
(
pInfo
->
pSortHandle
,
loadNextDataBlock
);
S
GenericSource
*
ps
=
taosMemoryCalloc
(
1
,
sizeof
(
SGeneric
Source
));
S
SortSource
*
ps
=
taosMemoryCalloc
(
1
,
sizeof
(
SSort
Source
));
ps
->
param
=
pOperator
->
pDownstream
[
0
];
tsortAddSource
(
pInfo
->
pSortHandle
,
ps
);
...
...
source/libs/executor/src/tsort.c
浏览文件 @
aced34c4
...
...
@@ -113,7 +113,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, int32_t type, int32_t page
static
int32_t
sortComparClearup
(
SMsortComparParam
*
cmpParam
)
{
for
(
int32_t
i
=
0
;
i
<
cmpParam
->
numOfSources
;
++
i
)
{
S
ExternalMemSource
*
pSource
=
cmpParam
->
pSources
[
i
];
S
SortSource
*
pSource
=
cmpParam
->
pSources
[
i
];
// NOTICE: pSource may be SGenericSource *, if it is SORT_MULTISOURCE_MERGE
blockDataDestroy
(
pSource
->
src
.
pBlock
);
taosMemoryFreeClear
(
pSource
);
}
...
...
@@ -132,7 +132,7 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) {
taosMemoryFreeClear
(
pSortHandle
->
idStr
);
blockDataDestroy
(
pSortHandle
->
pDataBlock
);
for
(
size_t
i
=
0
;
i
<
taosArrayGetSize
(
pSortHandle
->
pOrderedSource
);
i
++
){
S
ExternalMem
Source
**
pSource
=
taosArrayGet
(
pSortHandle
->
pOrderedSource
,
i
);
S
Sort
Source
**
pSource
=
taosArrayGet
(
pSortHandle
->
pOrderedSource
,
i
);
blockDataDestroy
((
*
pSource
)
->
src
.
pBlock
);
taosMemoryFreeClear
(
*
pSource
);
}
...
...
@@ -146,7 +146,7 @@ int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) {
}
static
int32_t
doAddNewExternalMemSource
(
SDiskbasedBuf
*
pBuf
,
SArray
*
pAllSources
,
SSDataBlock
*
pBlock
,
int32_t
*
sourceId
)
{
S
ExternalMemSource
*
pSource
=
taosMemoryCalloc
(
1
,
sizeof
(
SExternalMem
Source
));
S
SortSource
*
pSource
=
taosMemoryCalloc
(
1
,
sizeof
(
SSort
Source
));
if
(
pSource
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
...
...
@@ -216,7 +216,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int
if
(
pHandle
->
type
==
SORT_SINGLESOURCE_SORT
)
{
for
(
int32_t
i
=
0
;
i
<
cmpParam
->
numOfSources
;
++
i
)
{
S
ExternalMem
Source
*
pSource
=
cmpParam
->
pSources
[
i
];
S
Sort
Source
*
pSource
=
cmpParam
->
pSources
[
i
];
SPageInfo
*
pPgInfo
=
*
(
SPageInfo
**
)
taosArrayGet
(
pSource
->
pageIdList
,
pSource
->
pageIndex
);
void
*
pPage
=
getBufPage
(
pHandle
->
pBuf
,
getPageId
(
pPgInfo
));
...
...
@@ -238,7 +238,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int
}
for
(
int32_t
i
=
0
;
i
<
cmpParam
->
numOfSources
;
++
i
)
{
S
Generic
Source
*
pSource
=
cmpParam
->
pSources
[
i
];
S
Sort
Source
*
pSource
=
cmpParam
->
pSources
[
i
];
pSource
->
src
.
pBlock
=
pHandle
->
fetchfp
(
pSource
->
param
);
}
}
...
...
@@ -265,7 +265,7 @@ static void appendOneRowToDataBlock(SSDataBlock *pBlock, const SSDataBlock* pSou
*
rowIndex
+=
1
;
}
static
int32_t
adjustMergeTreeForNextTuple
(
S
ExternalMem
Source
*
pSource
,
SMultiwayMergeTreeInfo
*
pTree
,
SSortHandle
*
pHandle
,
int32_t
*
numOfCompleted
)
{
static
int32_t
adjustMergeTreeForNextTuple
(
S
Sort
Source
*
pSource
,
SMultiwayMergeTreeInfo
*
pTree
,
SSortHandle
*
pHandle
,
int32_t
*
numOfCompleted
)
{
/*
* load a new SDataBlock into memory of a given intermediate data-set source,
* since it's last record in buffer has been chosen to be processed, as the winner of loser-tree
...
...
@@ -292,7 +292,7 @@ static int32_t adjustMergeTreeForNextTuple(SExternalMemSource *pSource, SMultiwa
releaseBufPage
(
pHandle
->
pBuf
,
pPage
);
}
}
else
{
pSource
->
src
.
pBlock
=
pHandle
->
fetchfp
(((
S
Generic
Source
*
)
pSource
)
->
param
);
pSource
->
src
.
pBlock
=
pHandle
->
fetchfp
(((
S
Sort
Source
*
)
pSource
)
->
param
);
if
(
pSource
->
src
.
pBlock
==
NULL
)
{
(
*
numOfCompleted
)
+=
1
;
pSource
->
src
.
rowIndex
=
-
1
;
...
...
@@ -330,7 +330,7 @@ static SSDataBlock* getSortedBlockDataInner(SSortHandle* pHandle, SMsortComparPa
int32_t
index
=
tMergeTreeGetChosenIndex
(
pHandle
->
pMergeTree
);
S
ExternalMem
Source
*
pSource
=
(
*
cmpParam
).
pSources
[
index
];
S
Sort
Source
*
pSource
=
(
*
cmpParam
).
pSources
[
index
];
appendOneRowToDataBlock
(
pHandle
->
pDataBlock
,
pSource
->
src
.
pBlock
,
&
pSource
->
src
.
rowIndex
);
int32_t
code
=
adjustMergeTreeForNextTuple
(
pSource
,
pHandle
->
pMergeTree
,
pHandle
,
&
pHandle
->
numOfCompletedSources
);
...
...
@@ -355,8 +355,8 @@ int32_t msortComparFn(const void *pLeft, const void *pRight, void *param) {
SArray
*
pInfo
=
pParam
->
orderInfo
;
S
ExternalMem
Source
*
pLeftSource
=
pParam
->
pSources
[
pLeftIdx
];
S
ExternalMem
Source
*
pRightSource
=
pParam
->
pSources
[
pRightIdx
];
S
Sort
Source
*
pLeftSource
=
pParam
->
pSources
[
pLeftIdx
];
S
Sort
Source
*
pRightSource
=
pParam
->
pSources
[
pRightIdx
];
// this input is exhausted, set the special value to denote this
if
(
pLeftSource
->
src
.
rowIndex
==
-
1
)
{
...
...
@@ -484,6 +484,7 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
blockDataCleanup
(
pDataBlock
);
}
sortComparClearup
(
&
pHandle
->
cmpParam
);
tMergeTreeDestroy
(
pHandle
->
pMergeTree
);
pHandle
->
numOfCompletedSources
=
0
;
...
...
@@ -494,8 +495,6 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
}
}
sortComparClearup
(
&
pHandle
->
cmpParam
);
taosArrayClear
(
pHandle
->
pOrderedSource
);
taosArrayAddAll
(
pHandle
->
pOrderedSource
,
pResList
);
taosArrayDestroy
(
pResList
);
...
...
@@ -523,7 +522,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
size_t
sortBufSize
=
pHandle
->
numOfPages
*
pHandle
->
pageSize
;
if
(
pHandle
->
type
==
SORT_SINGLESOURCE_SORT
)
{
S
Generic
Source
*
source
=
taosArrayGetP
(
pHandle
->
pOrderedSource
,
0
);
S
Sort
Source
*
source
=
taosArrayGetP
(
pHandle
->
pOrderedSource
,
0
);
taosArrayClear
(
pHandle
->
pOrderedSource
);
while
(
1
)
{
SSDataBlock
*
pBlock
=
pHandle
->
fetchfp
(
source
->
param
);
...
...
@@ -652,7 +651,7 @@ STupleHandle* tsortNextTuple(SSortHandle* pHandle) {
}
int32_t
index
=
tMergeTreeGetChosenIndex
(
pHandle
->
pMergeTree
);
S
ExternalMem
Source
*
pSource
=
pHandle
->
cmpParam
.
pSources
[
index
];
S
Sort
Source
*
pSource
=
pHandle
->
cmpParam
.
pSources
[
index
];
if
(
pHandle
->
needAdjust
)
{
int32_t
code
=
adjustMergeTreeForNextTuple
(
pSource
,
pHandle
->
pMergeTree
,
pHandle
,
&
pHandle
->
numOfCompletedSources
);
...
...
source/libs/executor/test/sortTests.cpp
浏览文件 @
aced34c4
...
...
@@ -138,12 +138,12 @@ int32_t docomp(const void* p1, const void* p2, void* param) {
int32_t
pRightIdx
=
*
(
int32_t
*
)
p2
;
SMsortComparParam
*
pParam
=
(
SMsortComparParam
*
)
param
;
S
GenericSource
**
px
=
reinterpret_cast
<
SGeneric
Source
**>
(
pParam
->
pSources
);
S
SortSource
**
px
=
reinterpret_cast
<
SSort
Source
**>
(
pParam
->
pSources
);
SArray
*
pInfo
=
pParam
->
orderInfo
;
S
Generic
Source
*
pLeftSource
=
px
[
pLeftIdx
];
S
Generic
Source
*
pRightSource
=
px
[
pRightIdx
];
S
Sort
Source
*
pLeftSource
=
px
[
pLeftIdx
];
S
Sort
Source
*
pRightSource
=
px
[
pRightIdx
];
// this input is exhausted, set the special value to denote this
if
(
pLeftSource
->
src
.
rowIndex
==
-
1
)
{
...
...
@@ -218,7 +218,7 @@ TEST(testCase, inMem_sort_Test) {
pInfo
->
count
=
6
;
pInfo
->
type
=
TSDB_DATA_TYPE_USMALLINT
;
S
GenericSource
*
ps
=
static_cast
<
SGenericSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SGeneric
Source
)));
S
SortSource
*
ps
=
static_cast
<
SSortSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SSort
Source
)));
ps
->
param
=
pInfo
;
tsortAddSource
(
phandle
,
ps
);
...
...
@@ -301,7 +301,7 @@ TEST(testCase, external_mem_sort_Test) {
SSortHandle
*
phandle
=
tsortCreateSortHandle
(
orderInfo
,
SORT_SINGLESOURCE_SORT
,
128
,
3
,
NULL
,
"test_abc"
);
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
);
S
GenericSource
*
ps
=
static_cast
<
SGenericSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SGeneric
Source
)));
S
SortSource
*
ps
=
static_cast
<
SSortSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SSort
Source
)));
ps
->
param
=
&
pInfo
[
i
];
tsortAddSource
(
phandle
,
ps
);
...
...
@@ -369,10 +369,10 @@ TEST(testCase, ordered_merge_sort_Test) {
tsortSetFetchRawDataFp
(
phandle
,
getSingleColDummyBlock
);
tsortSetComparFp
(
phandle
,
docomp
);
S
Generic
Source
*
p
[
10
]
=
{
0
};
S
Sort
Source
*
p
[
10
]
=
{
0
};
_info
c
[
10
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
10
;
++
i
)
{
p
[
i
]
=
static_cast
<
S
GenericSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SGeneric
Source
)));
p
[
i
]
=
static_cast
<
S
SortSource
*>
(
taosMemoryCalloc
(
1
,
sizeof
(
SSort
Source
)));
c
[
i
].
count
=
1
;
c
[
i
].
pageRows
=
1000
;
c
[
i
].
startVal
=
i
*
1000
;
...
...
@@ -396,9 +396,8 @@ TEST(testCase, ordered_merge_sort_Test) {
ASSERT_EQ
(
row
++
,
*
(
int32_t
*
)
v
);
}
for
(
int32_t
i
=
0
;
i
<
10
;
++
i
)
{
taosMemoryFree
(
p
[
i
]);
}
taosArrayDestroy
(
orderInfo
);
tsortDestroySortHandle
(
phandle
);
blockDataDestroy
(
pBlock
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录