Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
e24e6257
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e24e6257
编写于
5月 27, 2020
作者:
A
Albert Kidrachev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
5f013a36
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
69 addition
and
148 deletion
+69
-148
src/Common/SharedBlockRowRef.h
src/Common/SharedBlockRowRef.h
+0
-29
src/Interpreters/InterpreterSelectQuery.cpp
src/Interpreters/InterpreterSelectQuery.cpp
+1
-2
src/Processors/Transforms/OptimizedPartialSortingTransform.cpp
...rocessors/Transforms/OptimizedPartialSortingTransform.cpp
+0
-83
src/Processors/Transforms/OptimizedPartialSortingTransform.h
src/Processors/Transforms/OptimizedPartialSortingTransform.h
+0
-34
src/Processors/Transforms/PartialSortingTransform.cpp
src/Processors/Transforms/PartialSortingTransform.cpp
+66
-0
src/Processors/Transforms/PartialSortingTransform.h
src/Processors/Transforms/PartialSortingTransform.h
+2
-0
未找到文件。
src/Common/SharedBlockRowRef.h
浏览文件 @
e24e6257
...
...
@@ -87,33 +87,4 @@ struct SharedBlockRowRef
}
};
struct
SharedBlockRowWithSortDescriptionRef
:
SharedBlockRowRef
{
SortDescription
*
description
=
nullptr
;
void
set
(
SharedBlockPtr
&
shared_block_
,
ColumnRawPtrs
*
columns_
,
size_t
row_num_
)
=
delete
;
bool
operator
<
(
const
SharedBlockRowRef
&
other
)
const
{
size_t
size
=
columns
->
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
int
res
=
(
*
description
)[
i
].
direction
*
(
*
columns
)[
i
]
->
compareAt
(
row_num
,
other
.
row_num
,
*
(
*
other
.
columns
)[
i
],
1
);
if
(
res
<
0
)
return
true
;
else
if
(
res
>
0
)
return
false
;
}
return
false
;
}
void
set
(
SharedBlockPtr
&
shared_block_
,
ColumnRawPtrs
*
columns_
,
size_t
row_num_
,
SortDescription
*
description_
)
{
shared_block
=
shared_block_
;
columns
=
columns_
;
row_num
=
row_num_
;
description
=
description_
;
}
};
}
src/Interpreters/InterpreterSelectQuery.cpp
浏览文件 @
e24e6257
...
...
@@ -84,7 +84,6 @@
#include <Processors/Transforms/MergingAggregatedMemoryEfficientTransform.h>
#include <Processors/Transforms/TotalsHavingTransform.h>
#include <Processors/Transforms/PartialSortingTransform.h>
#include <Processors/Transforms/OptimizedPartialSortingTransform.h>
#include <Processors/Transforms/LimitsCheckingTransform.h>
#include <Processors/Transforms/MergeSortingTransform.h>
#include <Processors/Transforms/DistinctTransform.h>
...
...
@@ -2109,7 +2108,7 @@ void InterpreterSelectQuery::executeOrder(QueryPipeline & pipeline, InputSorting
if
(
stream_type
!=
QueryPipeline
::
StreamType
::
Main
)
return
nullptr
;
return
std
::
make_shared
<
Optimized
PartialSortingTransform
>
(
header
,
output_order_descr
,
limit
);
return
std
::
make_shared
<
PartialSortingTransform
>
(
header
,
output_order_descr
,
limit
);
});
pipeline
.
addSimpleTransform
([
&
](
const
Block
&
header
,
QueryPipeline
::
StreamType
stream_type
)
->
ProcessorPtr
...
...
src/Processors/Transforms/OptimizedPartialSortingTransform.cpp
已删除
100644 → 0
浏览文件 @
5f013a36
#include <Processors/Transforms/OptimizedPartialSortingTransform.h>
#include <Interpreters/sortBlock.h>
#include <Common/PODArray.h>
namespace
DB
{
OptimizedPartialSortingTransform
::
OptimizedPartialSortingTransform
(
const
Block
&
header_
,
SortDescription
&
description_
,
UInt64
limit_
)
:
ISimpleTransform
(
header_
,
header_
,
false
)
,
description
(
description_
),
limit
(
limit_
)
,
threshold_shared_block
(
nullptr
)
{
}
static
ColumnRawPtrs
extractColumns
(
const
Block
&
block
,
const
SortDescription
&
description
)
{
size_t
size
=
description
.
size
();
ColumnRawPtrs
res
;
res
.
reserve
(
size
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
const
IColumn
*
column
=
!
description
[
i
].
column_name
.
empty
()
?
block
.
getByName
(
description
[
i
].
column_name
).
column
.
get
()
:
block
.
safeGetByPosition
(
description
[
i
].
column_number
).
column
.
get
();
res
.
emplace_back
(
column
);
}
return
res
;
}
void
OptimizedPartialSortingTransform
::
transform
(
Chunk
&
chunk
)
{
if
(
read_rows
)
read_rows
->
add
(
chunk
.
getNumRows
());
auto
block
=
getInputPort
().
getHeader
().
cloneWithColumns
(
chunk
.
detachColumns
());
chunk
.
clear
();
SharedBlockPtr
shared_block
=
new
detail
::
SharedBlock
(
std
::
move
(
block
));
UInt64
rows_num
=
shared_block
->
rows
();
if
(
threshold_shared_block
)
{
SharedBlockRowWithSortDescriptionRef
row
;
IColumn
::
Filter
filter
(
rows_num
);
ColumnRawPtrs
shared_block_columns
=
extractColumns
(
*
shared_block
,
description
);
size_t
filtered_count
=
0
;
for
(
UInt64
i
=
0
;
i
<
rows_num
;
++
i
)
{
row
.
set
(
shared_block
,
&
shared_block_columns
,
i
,
&
description
);
if
(
threshold_row
<
row
)
{
++
filtered_count
;
filter
[
i
]
=
1
;
}
}
if
(
filtered_count
)
{
for
(
auto
&
column
:
shared_block
->
getColumns
())
{
column
=
column
->
filter
(
filter
,
filtered_count
);
}
}
}
sortBlock
(
*
shared_block
,
description
,
limit
);
if
(
!
threshold_shared_block
&&
limit
&&
limit
<
rows_num
)
{
Block
threshold_block
=
shared_block
->
cloneWithColumns
(
shared_block
->
getColumns
());
threshold_shared_block
=
new
detail
::
SharedBlock
(
std
::
move
(
threshold_block
));
threshold_block_columns
=
extractColumns
(
*
threshold_shared_block
,
description
);
threshold_row
.
set
(
threshold_shared_block
,
&
threshold_block_columns
,
limit
-
1
,
&
description
);
}
chunk
.
setColumns
(
shared_block
->
getColumns
(),
shared_block
->
rows
());
}
}
src/Processors/Transforms/OptimizedPartialSortingTransform.h
已删除
100644 → 0
浏览文件 @
5f013a36
#pragma once
#include <Processors/ISimpleTransform.h>
#include <Processors/RowsBeforeLimitCounter.h>
#include <Common/SharedBlockRowRef.h>
#include <Core/SortDescription.h>
namespace
DB
{
class
OptimizedPartialSortingTransform
:
public
ISimpleTransform
{
public:
OptimizedPartialSortingTransform
(
const
Block
&
header_
,
SortDescription
&
description_
,
UInt64
limit_
=
0
);
String
getName
()
const
override
{
return
"OptimizedPartialSortingTransform"
;
}
void
setRowsBeforeLimitCounter
(
RowsBeforeLimitCounterPtr
counter
)
{
read_rows
.
swap
(
counter
);
}
protected:
void
transform
(
Chunk
&
chunk
)
override
;
private:
SortDescription
description
;
UInt64
limit
;
RowsBeforeLimitCounterPtr
read_rows
;
SharedBlockRowWithSortDescriptionRef
threshold_row
;
SharedBlockPtr
threshold_shared_block
;
ColumnRawPtrs
threshold_block_columns
;
};
}
src/Processors/Transforms/PartialSortingTransform.cpp
浏览文件 @
e24e6257
#include <Processors/Transforms/PartialSortingTransform.h>
#include <Interpreters/sortBlock.h>
#include <Common/PODArray.h>
namespace
DB
{
...
...
@@ -11,6 +12,38 @@ PartialSortingTransform::PartialSortingTransform(
{
}
static
ColumnRawPtrs
extractColumns
(
const
Block
&
block
,
const
SortDescription
&
description
)
{
size_t
size
=
description
.
size
();
ColumnRawPtrs
res
;
res
.
reserve
(
size
);
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
const
IColumn
*
column
=
!
description
[
i
].
column_name
.
empty
()
?
block
.
getByName
(
description
[
i
].
column_name
).
column
.
get
()
:
block
.
safeGetByPosition
(
description
[
i
].
column_number
).
column
.
get
();
res
.
emplace_back
(
column
);
}
return
res
;
}
bool
less
(
const
ColumnRawPtrs
&
lhs
,
UInt64
lhs_row_num
,
const
ColumnRawPtrs
&
rhs
,
UInt64
rhs_row_num
,
const
SortDescription
&
description
)
{
size_t
size
=
description
.
size
();
for
(
size_t
i
=
0
;
i
<
size
;
++
i
)
{
int
res
=
description
[
i
].
direction
*
lhs
[
i
]
->
compareAt
(
lhs_row_num
,
rhs_row_num
,
*
rhs
[
i
],
1
);
if
(
res
<
0
)
return
true
;
else
if
(
res
>
0
)
return
false
;
}
return
false
;
}
void
PartialSortingTransform
::
transform
(
Chunk
&
chunk
)
{
if
(
read_rows
)
...
...
@@ -19,7 +52,40 @@ void PartialSortingTransform::transform(Chunk & chunk)
auto
block
=
getInputPort
().
getHeader
().
cloneWithColumns
(
chunk
.
detachColumns
());
chunk
.
clear
();
UInt64
rows_num
=
block
.
rows
();
if
(
!
threshold_block_columns
.
empty
())
{
IColumn
::
Filter
filter
(
rows_num
,
0
);
ColumnRawPtrs
block_columns
=
extractColumns
(
block
,
description
);
size_t
filtered_count
=
0
;
for
(
UInt64
i
=
0
;
i
<
rows_num
;
++
i
)
{
if
(
less
(
threshold_block_columns
,
limit
-
1
,
block_columns
,
i
,
description
))
{
++
filtered_count
;
filter
[
i
]
=
1
;
}
}
if
(
filtered_count
)
{
for
(
auto
&
column
:
block
.
getColumns
())
{
column
=
column
->
filter
(
filter
,
filtered_count
);
}
}
}
sortBlock
(
block
,
description
,
limit
);
if
(
threshold_block_columns
.
empty
()
&&
limit
&&
limit
<
rows_num
)
{
threshold_block
=
block
.
cloneWithColumns
(
block
.
getColumns
());
threshold_block_columns
=
extractColumns
(
threshold_block
,
description
);
}
chunk
.
setColumns
(
block
.
getColumns
(),
block
.
rows
());
}
...
...
src/Processors/Transforms/PartialSortingTransform.h
浏览文件 @
e24e6257
...
...
@@ -29,6 +29,8 @@ private:
SortDescription
description
;
UInt64
limit
;
RowsBeforeLimitCounterPtr
read_rows
;
Block
threshold_block
;
ColumnRawPtrs
threshold_block_columns
;
};
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录