Skip to content

Commit

Permalink
Merge pull request #57476 from ClickHouse/backport/23.8/57352
Browse files Browse the repository at this point in the history
Backport #57352 to 23.8: MergeTree mutations reuse source part index granularity
  • Loading branch information
alexey-milovidov committed Jan 5, 2024
2 parents 08dc426 + 63a7d34 commit 9b1e39b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Storages/MergeTree/MergedBlockOutputStream.cpp
Expand Up @@ -23,7 +23,8 @@ MergedBlockOutputStream::MergedBlockOutputStream(
const MergeTreeTransactionPtr & txn,
bool reset_columns_,
bool blocks_are_granules_size,
const WriteSettings & write_settings_)
const WriteSettings & write_settings_,
const MergeTreeIndexGranularity & computed_index_granularity)
: IMergedBlockOutputStream(data_part, metadata_snapshot_, columns_list_, reset_columns_)
, columns_list(columns_list_)
, default_codec(default_codec_)
Expand All @@ -47,7 +48,7 @@ MergedBlockOutputStream::MergedBlockOutputStream(
data_part->version.setCreationTID(tid, nullptr);
data_part->storeVersionMetadata();

writer = data_part->getWriter(columns_list, metadata_snapshot, skip_indices, default_codec, writer_settings, {});
writer = data_part->getWriter(columns_list, metadata_snapshot, skip_indices, default_codec, writer_settings, computed_index_granularity);
}

/// If data is pre-sorted.
Expand Down
3 changes: 2 additions & 1 deletion src/Storages/MergeTree/MergedBlockOutputStream.h
Expand Up @@ -23,7 +23,8 @@ class MergedBlockOutputStream final : public IMergedBlockOutputStream
const MergeTreeTransactionPtr & txn,
bool reset_columns_ = false,
bool blocks_are_granules_size = false,
const WriteSettings & write_settings = {});
const WriteSettings & write_settings = {},
const MergeTreeIndexGranularity & computed_index_granularity = {});

Block getHeader() const { return metadata_snapshot->getSampleBlock(); }

Expand Down
19 changes: 18 additions & 1 deletion src/Storages/MergeTree/MutateTask.cpp
Expand Up @@ -1414,6 +1414,22 @@ class MutateAllPartColumnsTask : public IExecutableTask

ctx->minmax_idx = std::make_shared<IMergeTreeDataPart::MinMaxIndex>();

MergeTreeIndexGranularity computed_granularity;
bool has_delete = false;

for (auto & command_for_interpreter : ctx->for_interpreter)
{
if (command_for_interpreter.type == MutationCommand::DELETE)
{
has_delete = true;
break;
}
}

/// Reuse source part granularity if mutation does not change number of rows
if (!has_delete && ctx->execute_ttl_type == ExecuteTTLType::NONE)
computed_granularity = ctx->source_part->index_granularity;

ctx->out = std::make_shared<MergedBlockOutputStream>(
ctx->new_data_part,
ctx->metadata_snapshot,
Expand All @@ -1423,7 +1439,8 @@ class MutateAllPartColumnsTask : public IExecutableTask
ctx->txn,
/*reset_columns=*/ true,
/*blocks_are_granules_size=*/ false,
ctx->context->getWriteSettings());
ctx->context->getWriteSettings(),
computed_granularity);

ctx->mutating_pipeline = QueryPipelineBuilder::getPipeline(std::move(builder));
ctx->mutating_pipeline.setProgressCallback(ctx->progress_callback);
Expand Down

0 comments on commit 9b1e39b

Please sign in to comment.