Merge pull request #59405 from nickitat/dont_merge_just_created_aggr_projection_block

Don't merge just created aggregating projection blocks
This commit is contained in:
Nikita Taranov 2024-05-01 11:34:21 +00:00 committed by GitHub
commit 77c5221a0e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 21 deletions

View File

@ -618,7 +618,8 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeTempPartImpl(
if (projection_block.rows())
{
auto proj_temp_part = writeProjectionPart(data, log, projection_block, projection, new_data_part.get());
auto proj_temp_part
= writeProjectionPart(data, log, projection_block, projection, new_data_part.get(), /*merge_is_needed=*/false);
new_data_part->addProjectionPart(projection.name, std::move(proj_temp_part.part));
for (auto & stream : proj_temp_part.streams)
temp_part.streams.emplace_back(std::move(stream));
@ -647,7 +648,8 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeProjectionPartImpl(
const MergeTreeData & data,
LoggerPtr log,
Block block,
const ProjectionDescription & projection)
const ProjectionDescription & projection,
bool merge_is_needed)
{
TemporaryPart temp_part;
const auto & metadata_snapshot = projection.metadata;
@ -716,7 +718,7 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeProjectionPartImpl(
ProfileEvents::increment(ProfileEvents::MergeTreeDataProjectionWriterBlocksAlreadySorted);
}
if (projection.type == ProjectionDescription::Type::Aggregate)
if (projection.type == ProjectionDescription::Type::Aggregate && merge_is_needed)
{
ProfileEventTimeIncrement<Microseconds> watch(ProfileEvents::MergeTreeDataProjectionWriterMergingBlocksMicroseconds);
@ -756,16 +758,11 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeProjectionPart(
LoggerPtr log,
Block block,
const ProjectionDescription & projection,
IMergeTreeDataPart * parent_part)
IMergeTreeDataPart * parent_part,
bool merge_is_needed)
{
return writeProjectionPartImpl(
projection.name,
false /* is_temp */,
parent_part,
data,
log,
std::move(block),
projection);
projection.name, false /* is_temp */, parent_part, data, log, std::move(block), projection, merge_is_needed);
}
/// This is used for projection materialization process which may contain multiple stages of
@ -780,13 +777,7 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeTempProjectionPart(
{
auto part_name = fmt::format("{}_{}", projection.name, block_num);
return writeProjectionPartImpl(
part_name,
true /* is_temp */,
parent_part,
data,
log,
std::move(block),
projection);
part_name, true /* is_temp */, parent_part, data, log, std::move(block), projection, /*merge_is_needed=*/true);
}
}

View File

@ -95,7 +95,8 @@ public:
LoggerPtr log,
Block block,
const ProjectionDescription & projection,
IMergeTreeDataPart * parent_part);
IMergeTreeDataPart * parent_part,
bool merge_is_needed);
/// For mutation: MATERIALIZE PROJECTION.
static TemporaryPart writeTempProjectionPart(
@ -129,7 +130,8 @@ private:
const MergeTreeData & data,
LoggerPtr log,
Block block,
const ProjectionDescription & projection);
const ProjectionDescription & projection,
bool merge_is_needed);
MergeTreeData & data;
LoggerPtr log;

View File

@ -36,7 +36,7 @@ FROM numbers_mt(1000000);
$CLICKHOUSE_CLIENT -q "SYSTEM FLUSH LOGS"
$CLICKHOUSE_CLIENT -q """
SELECT
ProfileEvents['MergeTreeDataProjectionWriterMergingBlocksMicroseconds'] > 0,
ProfileEvents['MergeTreeDataProjectionWriterMergingBlocksMicroseconds'] = 0,
ProfileEvents['MergeTreeDataProjectionWriterSortingBlocksMicroseconds'] > 0,
ProfileEvents['MergeTreeDataWriterSortingBlocksMicroseconds'] > 0,
ProfileEvents['MergeTreeDataWriterProjectionsCalculationMicroseconds'] > 0,