Skip to content

Commit

Permalink
WindowTransform decrease amount of virtual function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kitaisreal committed Oct 30, 2023
1 parent 58824fb commit f8e209e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Processors/Transforms/WindowTransform.cpp
Expand Up @@ -257,6 +257,7 @@ WindowTransform::WindowTransform(const Block & input_header_,
window_description.frame = *custom_default_frame;
}

workspace.is_aggregate_function_state = workspace.aggregate_function->isState();
workspace.aggregate_function_state.reset(
aggregate_function->sizeOfData(),
aggregate_function->alignOfData());
Expand Down Expand Up @@ -957,10 +958,7 @@ void WindowTransform::updateAggregationState()
auto * columns = ws.argument_columns.data();
// Removing arena.get() from the loop makes it faster somehow...
auto * arena_ptr = arena.get();
for (auto row = first_row; row < past_the_end_row; ++row)
{
a->add(buf, columns, row, arena_ptr);
}
a->addBatchSinglePlaceFromInterval(first_row, past_the_end_row, buf, columns, arena_ptr);
}
}
}
Expand All @@ -987,9 +985,16 @@ void WindowTransform::writeOutCurrentRow()
// FIXME does it also allocate the result on the arena?
// We'll have to pass it out with blocks then...

/// We should use insertMergeResultInto to insert result into ColumnAggregateFunction
/// correctly if result contains AggregateFunction's states
a->insertMergeResultInto(buf, *result_column, arena.get());
if (ws.is_aggregate_function_state)
{
/// We should use insertMergeResultInto to insert result into ColumnAggregateFunction
/// correctly if result contains AggregateFunction's states
a->insertMergeResultInto(buf, *result_column, arena.get());
}
else
{
a->insertResultInto(buf, *result_column, arena.get());
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Processors/Transforms/WindowTransform.h
Expand Up @@ -26,6 +26,9 @@ struct WindowFunctionWorkspace
{
AggregateFunctionPtr aggregate_function;

// Cached value of aggregate function isState virtual method
bool is_aggregate_function_state = false;

// This field is set for pure window functions. When set, we ignore the
// window_function.aggregate_function, and work through this interface
// instead.
Expand Down

0 comments on commit f8e209e

Please sign in to comment.