dbms: additional performance improvement [#METR-2944].

This commit is contained in:
Alexey Milovidov 2013-11-03 23:54:12 +00:00
parent 18a8aa74f8
commit c252785d2a
5 changed files with 25 additions and 6 deletions

View File

@ -62,6 +62,11 @@ public:
nested_func->destroy(place);
}
bool hasTrivialDestructor() const
{
return nested_func->hasTrivialDestructor();
}
size_t sizeOfData() const
{
return nested_func->sizeOfData();

View File

@ -60,6 +60,9 @@ public:
/// Уничтожить данные для агрегации.
virtual void destroy(AggregateDataPtr place) const = 0;
/// Уничтожать данные не обязательно.
virtual bool hasTrivialDestructor() const = 0;
/// Получить sizeof структуры с данными.
virtual size_t sizeOfData() const = 0;
@ -105,6 +108,11 @@ public:
data(place).~Data();
}
bool hasTrivialDestructor() const
{
return __has_trivial_destructor(Data);
}
size_t sizeOfData() const
{
return sizeof(Data);

View File

@ -45,10 +45,11 @@ public:
arenas.push_back(arena_);
}
~ColumnAggregateFunction()
~ColumnAggregateFunction()
{
for (size_t i = 0, s = data.size(); i < s; ++i)
func->destroy(data[i]);
if (!func->hasTrivialDestructor())
for (size_t i = 0, s = data.size(); i < s; ++i)
func->destroy(data[i]);
}
std::string getName() const { return "ColumnAggregateFunction"; }

View File

@ -158,7 +158,7 @@ public:
Aggregator(const ColumnNumbers & keys_, const AggregateDescriptions & aggregates_, bool with_totals_,
size_t max_rows_to_group_by_ = 0, Limits::OverflowMode group_by_overflow_mode_ = Limits::THROW)
: keys(keys_), aggregates(aggregates_), aggregates_size(aggregates.size()),
with_totals(with_totals_), total_size_of_aggregate_states(0), initialized(false),
with_totals(with_totals_), total_size_of_aggregate_states(0), all_aggregates_has_trivial_destructor(false), initialized(false),
max_rows_to_group_by(max_rows_to_group_by_), group_by_overflow_mode(group_by_overflow_mode_),
log(&Logger::get("Aggregator"))
{
@ -170,7 +170,7 @@ public:
Aggregator(const Names & key_names_, const AggregateDescriptions & aggregates_, bool with_totals_,
size_t max_rows_to_group_by_ = 0, Limits::OverflowMode group_by_overflow_mode_ = Limits::THROW)
: key_names(key_names_), aggregates(aggregates_), aggregates_size(aggregates.size()),
with_totals(with_totals_), total_size_of_aggregate_states(0), initialized(false),
with_totals(with_totals_), total_size_of_aggregate_states(0), all_aggregates_has_trivial_destructor(false), initialized(false),
max_rows_to_group_by(max_rows_to_group_by_), group_by_overflow_mode(group_by_overflow_mode_),
log(&Logger::get("Aggregator"))
{
@ -220,6 +220,7 @@ protected:
Sizes offsets_of_aggregate_states; /// Смещение до n-ой агрегатной функции в строке из агрегатных функций.
size_t total_size_of_aggregate_states; /// Суммарный размер строки из агрегатных функций.
bool all_aggregates_has_trivial_destructor;
/// Для инициализации от первого блока при конкуррентном использовании.
bool initialized;

View File

@ -18,7 +18,7 @@ namespace DB
AggregatedDataVariants::~AggregatedDataVariants()
{
if (aggregator)
if (aggregator && !aggregator->all_aggregates_has_trivial_destructor)
aggregator->destroyAggregateStates(*this);
}
@ -39,11 +39,15 @@ void Aggregator::initialize(Block & block)
/// Инициализируем размеры состояний и смещения для агрегатных функций.
offsets_of_aggregate_states.resize(aggregates_size);
total_size_of_aggregate_states = 0;
all_aggregates_has_trivial_destructor = true;
for (size_t i = 0; i < aggregates_size; ++i)
{
offsets_of_aggregate_states[i] = total_size_of_aggregate_states;
total_size_of_aggregate_states += aggregates[i].function->sizeOfData();
if (!aggregates[i].function->hasTrivialDestructor())
all_aggregates_has_trivial_destructor = false;
}
/** Всё остальное - только если передан непустой block.