mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-01 20:12:02 +00:00
Merge pull request #38438 from ClickHouse/distinct_sorted_small_refact
Distinct sorted: calculate column positions once
This commit is contained in:
commit
bd4a208428
@ -13,10 +13,20 @@ DistinctSortedTransform::DistinctSortedTransform(
|
|||||||
: ISimpleTransform(header_, header_, true)
|
: ISimpleTransform(header_, header_, true)
|
||||||
, header(std::move(header_))
|
, header(std::move(header_))
|
||||||
, description(std::move(sort_description))
|
, description(std::move(sort_description))
|
||||||
, columns_names(columns)
|
, column_names(columns)
|
||||||
, limit_hint(limit_hint_)
|
, limit_hint(limit_hint_)
|
||||||
, set_size_limits(set_size_limits_)
|
, 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)
|
void DistinctSortedTransform::transform(Chunk & chunk)
|
||||||
@ -119,24 +129,13 @@ bool DistinctSortedTransform::buildFilter(
|
|||||||
|
|
||||||
ColumnRawPtrs DistinctSortedTransform::getKeyColumns(const Chunk & chunk) const
|
ColumnRawPtrs DistinctSortedTransform::getKeyColumns(const Chunk & chunk) const
|
||||||
{
|
{
|
||||||
size_t columns = columns_names.empty() ? chunk.getNumColumns() : columns_names.size();
|
|
||||||
|
|
||||||
ColumnRawPtrs column_ptrs;
|
ColumnRawPtrs column_ptrs;
|
||||||
column_ptrs.reserve(columns);
|
column_ptrs.reserve(column_positions.size());
|
||||||
|
for (const auto pos : column_positions)
|
||||||
for (size_t i = 0; i < columns; ++i)
|
|
||||||
{
|
{
|
||||||
auto pos = i;
|
|
||||||
if (!columns_names.empty())
|
|
||||||
pos = input.getHeader().getPositionByName(columns_names[i]);
|
|
||||||
|
|
||||||
const auto & column = chunk.getColumns()[pos];
|
const auto & column = chunk.getColumns()[pos];
|
||||||
|
|
||||||
/// Ignore all constant columns.
|
|
||||||
if (!isColumnConst(*column))
|
|
||||||
column_ptrs.emplace_back(column.get());
|
column_ptrs.emplace_back(column.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
return column_ptrs;
|
return column_ptrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <Processors/ISimpleTransform.h>
|
#include <Processors/ISimpleTransform.h>
|
||||||
#include <Interpreters/SetVariants.h>
|
#include <Interpreters/SetVariants.h>
|
||||||
#include <Core/SortDescription.h>
|
#include <Core/SortDescription.h>
|
||||||
|
#include <Core/ColumnNumbers.h>
|
||||||
|
|
||||||
|
|
||||||
namespace DB
|
namespace DB
|
||||||
@ -57,7 +58,8 @@ private:
|
|||||||
};
|
};
|
||||||
PreviousChunk prev_chunk;
|
PreviousChunk prev_chunk;
|
||||||
|
|
||||||
Names columns_names;
|
Names column_names;
|
||||||
|
ColumnNumbers column_positions;
|
||||||
ClearableSetVariants data;
|
ClearableSetVariants data;
|
||||||
Sizes key_sizes;
|
Sizes key_sizes;
|
||||||
UInt64 limit_hint;
|
UInt64 limit_hint;
|
||||||
|
Loading…
Reference in New Issue
Block a user