Merge pull request #38438 from ClickHouse/distinct_sorted_small_refact

Distinct sorted: calculate column positions once
This commit is contained in:
Igor Nikonov 2022-06-30 00:53:17 +02:00 committed by GitHub
commit bd4a208428
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 16 deletions

View File

@ -13,10 +13,20 @@ DistinctSortedTransform::DistinctSortedTransform(
: ISimpleTransform(header_, header_, true)
, header(std::move(header_))
, description(std::move(sort_description))
, columns_names(columns)
, column_names(columns)
, limit_hint(limit_hint_)
, set_size_limits(set_size_limits_)
{
/// pre-calculate column positions to use during chunk transformation
const size_t num_columns = column_names.empty() ? header.columns() : column_names.size();
column_positions.reserve(num_columns);
for (size_t i = 0; i < num_columns; ++i)
{
auto pos = column_names.empty() ? i : header.getPositionByName(column_names[i]);
const auto & col = header.getByPosition(pos).column;
if (col && !isColumnConst(*col))
column_positions.emplace_back(pos);
}
}
void DistinctSortedTransform::transform(Chunk & chunk)
@ -119,24 +129,13 @@ bool DistinctSortedTransform::buildFilter(
ColumnRawPtrs DistinctSortedTransform::getKeyColumns(const Chunk & chunk) const
{
size_t columns = columns_names.empty() ? chunk.getNumColumns() : columns_names.size();
ColumnRawPtrs column_ptrs;
column_ptrs.reserve(columns);
for (size_t i = 0; i < columns; ++i)
column_ptrs.reserve(column_positions.size());
for (const auto pos : column_positions)
{
auto pos = i;
if (!columns_names.empty())
pos = input.getHeader().getPositionByName(columns_names[i]);
const auto & column = chunk.getColumns()[pos];
/// Ignore all constant columns.
if (!isColumnConst(*column))
column_ptrs.emplace_back(column.get());
}
return column_ptrs;
}

View File

@ -3,6 +3,7 @@
#include <Processors/ISimpleTransform.h>
#include <Interpreters/SetVariants.h>
#include <Core/SortDescription.h>
#include <Core/ColumnNumbers.h>
namespace DB
@ -57,7 +58,8 @@ private:
};
PreviousChunk prev_chunk;
Names columns_names;
Names column_names;
ColumnNumbers column_positions;
ClearableSetVariants data;
Sizes key_sizes;
UInt64 limit_hint;