Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MergeTree mutations reuse source part index granularity #57352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Storages/MergeTree/MergedBlockOutputStream.cpp
Expand Up @@ -24,7 +24,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 @@ -48,7 +49,7 @@ MergedBlockOutputStream::MergedBlockOutputStream(
data_part->version.setCreationTID(tid, nullptr);
data_part->storeVersionMetadata();

writer = data_part->getWriter(columns_list, metadata_snapshot, skip_indices, statistics, default_codec, writer_settings, {});
writer = data_part->getWriter(columns_list, metadata_snapshot, skip_indices, statistics, 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 @@ -25,7 +25,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 @@ -1525,6 +1525,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 @@ -1535,7 +1551,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