Skip to content

Commit

Permalink
fix performance
Browse files Browse the repository at this point in the history
  • Loading branch information
liuneng1994 committed Nov 2, 2023
1 parent 61966e3 commit e774fa6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions cpp-ch/local-engine/Storages/IO/NativeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void NativeReader::readData(const ISerialization & serialization, ColumnPtr & co
"Cannot read all data in NativeReader. Rows read: {}. Rows expected: {}", column->size(), rows);
}

template <bool FIXED>
void NativeReader::readAggData(const DB::DataTypeAggregateFunction & data_type, DB::ColumnPtr & column, DB::ReadBuffer & istr, size_t rows)
{
ColumnAggregateFunction & real_column = typeid_cast<ColumnAggregateFunction &>(*column->assumeMutable());
Expand All @@ -72,9 +73,8 @@ void NativeReader::readAggData(const DB::DataTypeAggregateFunction & data_type,
for (size_t i = 0; i < rows; ++i)
{
AggregateDataPtr place = arena.alignedAlloc(size_of_state, align_of_state);

agg_function->create(place);
if (isFixedSizeAggregateFunction(agg_function))
if constexpr (FIXED)
{
auto n = istr.read(place, size_of_state);
chassert(n == size_of_state);
Expand All @@ -84,6 +84,7 @@ void NativeReader::readAggData(const DB::DataTypeAggregateFunction & data_type,
agg_function->deserialize(place, istr, std::nullopt, &arena);
istr.ignore();
}

vec.push_back(place);
}
}
Expand Down Expand Up @@ -149,7 +150,15 @@ Block NativeReader::read()
if (is_agg_state_type && agg_opt_column)
{
const DataTypeAggregateFunction * agg_type = checkAndGetDataType<DataTypeAggregateFunction>(column.type.get());
readAggData(*agg_type, read_column, istr, rows);
bool fixed = isFixedSizeAggregateFunction(agg_type->getFunction());
if (fixed)
{
readAggData<true>(*agg_type, read_column, istr, rows);
}
else
{
readAggData<false>(*agg_type, read_column, istr, rows);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions cpp-ch/local-engine/Storages/IO/NativeReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NativeReader
NativeReader(DB::ReadBuffer & istr_) : istr(istr_) {}

static void readData(const DB::ISerialization & serialization, DB::ColumnPtr & column, DB::ReadBuffer & istr, size_t rows, double avg_value_size_hint);
template <bool FIXED>
static void readAggData(const DB::DataTypeAggregateFunction & data_type, DB::ColumnPtr & column, DB::ReadBuffer & istr, size_t rows);

DB::Block getHeader() const;
Expand Down

0 comments on commit e774fa6

Please sign in to comment.