Merge pull request #39191 from ClickHouse/sort_transform_cleanup

Cleanup: done during #38719 (SortingStep: deduce way to sort based on input stream sort)
This commit is contained in:
Igor Nikonov 2022-07-16 01:53:58 +02:00 committed by GitHub
commit ef0ef9e03b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 22 deletions

View File

@ -10,7 +10,7 @@ namespace DB
MergingSortedAlgorithm::MergingSortedAlgorithm( MergingSortedAlgorithm::MergingSortedAlgorithm(
Block header_, Block header_,
size_t num_inputs, size_t num_inputs,
SortDescription description_, const SortDescription & description_,
size_t max_block_size, size_t max_block_size,
SortingQueueStrategy sorting_queue_strategy_, SortingQueueStrategy sorting_queue_strategy_,
UInt64 limit_, UInt64 limit_,
@ -18,7 +18,7 @@ MergingSortedAlgorithm::MergingSortedAlgorithm(
bool use_average_block_sizes) bool use_average_block_sizes)
: header(std::move(header_)) : header(std::move(header_))
, merged_data(header.cloneEmptyColumns(), use_average_block_sizes, max_block_size) , merged_data(header.cloneEmptyColumns(), use_average_block_sizes, max_block_size)
, description(std::move(description_)) , description(description_)
, limit(limit_) , limit(limit_)
, out_row_sources_buf(out_row_sources_buf_) , out_row_sources_buf(out_row_sources_buf_)
, current_inputs(num_inputs) , current_inputs(num_inputs)
@ -29,7 +29,7 @@ MergingSortedAlgorithm::MergingSortedAlgorithm(
sort_description_types.reserve(description.size()); sort_description_types.reserve(description.size());
/// Replace column names in description to positions. /// Replace column names in description to positions.
for (auto & column_description : description) for (const auto & column_description : description)
{ {
has_collation |= column_description.collator != nullptr; has_collation |= column_description.collator != nullptr;
sort_description_types.emplace_back(header.getByName(column_description.column_name).type); sort_description_types.emplace_back(header.getByName(column_description.column_name).type);

View File

@ -16,7 +16,7 @@ public:
MergingSortedAlgorithm( MergingSortedAlgorithm(
Block header_, Block header_,
size_t num_inputs, size_t num_inputs,
SortDescription description_, const SortDescription & description_,
size_t max_block_size, size_t max_block_size,
SortingQueueStrategy sorting_queue_strategy_, SortingQueueStrategy sorting_queue_strategy_,
UInt64 limit_ = 0, UInt64 limit_ = 0,
@ -38,7 +38,7 @@ private:
/// Settings /// Settings
SortDescription description; SortDescription description;
UInt64 limit; const UInt64 limit;
bool has_collation = false; bool has_collation = false;
/// Used in Vertical merge algorithm to gather non-PK/non-index columns (on next step) /// Used in Vertical merge algorithm to gather non-PK/non-index columns (on next step)

View File

@ -10,7 +10,7 @@ namespace DB
MergingSortedTransform::MergingSortedTransform( MergingSortedTransform::MergingSortedTransform(
const Block & header, const Block & header,
size_t num_inputs, size_t num_inputs,
SortDescription description_, const SortDescription & description_,
size_t max_block_size, size_t max_block_size,
SortingQueueStrategy sorting_queue_strategy, SortingQueueStrategy sorting_queue_strategy,
UInt64 limit_, UInt64 limit_,
@ -19,10 +19,14 @@ MergingSortedTransform::MergingSortedTransform(
bool use_average_block_sizes, bool use_average_block_sizes,
bool have_all_inputs_) bool have_all_inputs_)
: IMergingTransform( : IMergingTransform(
num_inputs, header, header, have_all_inputs_, limit_, num_inputs,
header,
header,
have_all_inputs_,
limit_,
header, header,
num_inputs, num_inputs,
std::move(description_), description_,
max_block_size, max_block_size,
sorting_queue_strategy, sorting_queue_strategy,
limit_, limit_,

View File

@ -14,7 +14,7 @@ public:
MergingSortedTransform( MergingSortedTransform(
const Block & header, const Block & header,
size_t num_inputs, size_t num_inputs,
SortDescription description, const SortDescription & description,
size_t max_block_size, size_t max_block_size,
SortingQueueStrategy sorting_queue_strategy, SortingQueueStrategy sorting_queue_strategy,
UInt64 limit_ = 0, UInt64 limit_ = 0,

View File

@ -36,9 +36,8 @@ FinishSortingTransform::FinishSortingTransform(
/// The target description is modified in SortingTransform constructor. /// The target description is modified in SortingTransform constructor.
/// To avoid doing the same actions with description_sorted just copy it from prefix of target description. /// To avoid doing the same actions with description_sorted just copy it from prefix of target description.
size_t prefix_size = description_sorted_.size(); for (const auto & column_sort_desc : description_sorted_)
for (size_t i = 0; i < prefix_size; ++i) description_with_positions.emplace_back(column_sort_desc, header_without_constants.getPositionByName(column_sort_desc.column_name));
description_with_positions.emplace_back(description[i], header_without_constants.getPositionByName(description[i].column_name));
} }
void FinishSortingTransform::consume(Chunk chunk) void FinishSortingTransform::consume(Chunk chunk)

View File

@ -85,7 +85,7 @@ bool compareWithThreshold(const ColumnRawPtrs & raw_block_columns, size_t min_bl
} }
PartialSortingTransform::PartialSortingTransform( PartialSortingTransform::PartialSortingTransform(
const Block & header_, SortDescription & description_, UInt64 limit_) const Block & header_, const SortDescription & description_, UInt64 limit_)
: ISimpleTransform(header_, header_, false) : ISimpleTransform(header_, header_, false)
, description(description_) , description(description_)
, limit(limit_) , limit(limit_)
@ -93,9 +93,8 @@ PartialSortingTransform::PartialSortingTransform(
// Sorting by no columns doesn't make sense. // Sorting by no columns doesn't make sense.
assert(!description_.empty()); assert(!description_.empty());
size_t description_size = description.size(); for (const auto & column_sort_desc : description)
for (size_t i = 0; i < description_size; ++i) description_with_positions.emplace_back(column_sort_desc, header_.getPositionByName(column_sort_desc.column_name));
description_with_positions.emplace_back(description[i], header_.getPositionByName(description[i].column_name));
} }
void PartialSortingTransform::transform(Chunk & chunk) void PartialSortingTransform::transform(Chunk & chunk)

View File

@ -15,7 +15,7 @@ public:
/// limit - if not 0, then you can sort each block not completely, but only `limit` first rows by order. /// limit - if not 0, then you can sort each block not completely, but only `limit` first rows by order.
PartialSortingTransform( PartialSortingTransform(
const Block & header_, const Block & header_,
SortDescription & description_, const SortDescription & description_,
UInt64 limit_ = 0); UInt64 limit_ = 0);
String getName() const override { return "PartialSortingTransform"; } String getName() const override { return "PartialSortingTransform"; }
@ -26,9 +26,9 @@ protected:
void transform(Chunk & chunk) override; void transform(Chunk & chunk) override;
private: private:
SortDescription description; const SortDescription description;
SortDescriptionWithPositions description_with_positions; SortDescriptionWithPositions description_with_positions;
UInt64 limit; const UInt64 limit;
RowsBeforeLimitCounterPtr read_rows; RowsBeforeLimitCounterPtr read_rows;
Columns sort_description_threshold_columns; Columns sort_description_threshold_columns;

View File

@ -73,8 +73,8 @@ public:
~SortingTransform() override; ~SortingTransform() override;
protected: protected:
Status prepare() override final; Status prepare() final;
void work() override final; void work() final;
virtual void consume(Chunk chunk) = 0; virtual void consume(Chunk chunk) = 0;
virtual void generate() = 0; virtual void generate() = 0;
@ -82,7 +82,7 @@ protected:
SortDescription description; SortDescription description;
size_t max_merged_block_size; size_t max_merged_block_size;
UInt64 limit; const UInt64 limit;
/// Before operation, will remove constant columns from blocks. And after, place constant columns back. /// Before operation, will remove constant columns from blocks. And after, place constant columns back.
/// (to avoid excessive virtual function calls and because constants cannot be serialized in Native format for temporary files) /// (to avoid excessive virtual function calls and because constants cannot be serialized in Native format for temporary files)