diff --git a/src/Interpreters/MutationsInterpreter.cpp b/src/Interpreters/MutationsInterpreter.cpp index 4b0cbec4f9f..4650ba39770 100644 --- a/src/Interpreters/MutationsInterpreter.cpp +++ b/src/Interpreters/MutationsInterpreter.cpp @@ -40,6 +40,7 @@ #include #include #include +#include namespace DB { @@ -304,6 +305,11 @@ bool MutationsInterpreter::Source::hasProjection(const String & name) const return part && part->hasProjection(name); } +bool MutationsInterpreter::Source::isCompactPart() const +{ + return part && part->getType() == MergeTreeDataPartType::Compact; +} + static Names getAvailableColumnsWithVirtuals(StorageMetadataPtr metadata_snapshot, const IStorage & storage) { auto all_columns = metadata_snapshot->getColumns().getNamesOfPhysical(); @@ -562,7 +568,7 @@ void MutationsInterpreter::prepare(bool dry_run) if (settings.recalculate_dependencies_of_updated_columns) dependencies = getAllColumnDependencies(metadata_snapshot, updated_columns, has_dependency); - bool has_alter_delete = false; + bool need_rebuild_indexes_projections = false; std::vector read_columns; /// First, break a sequence of commands into stages. @@ -583,7 +589,7 @@ void MutationsInterpreter::prepare(bool dry_run) predicate = makeASTFunction("isZeroOrNull", predicate); stages.back().filters.push_back(predicate); - has_alter_delete = true; + need_rebuild_indexes_projections = true; } else if (command.type == MutationCommand::UPDATE) { @@ -687,6 +693,9 @@ void MutationsInterpreter::prepare(bool dry_run) } } } + + if (source.isCompactPart() && source.getMergeTreeData() && source.getMergeTreeData()->getSettings()->index_granularity_bytes > 0) + need_rebuild_indexes_projections = true; } else if (command.type == MutationCommand::MATERIALIZE_COLUMN) { @@ -892,7 +901,7 @@ void MutationsInterpreter::prepare(bool dry_run) if (!source.hasSecondaryIndex(index.name)) continue; - if (has_alter_delete) + if (need_rebuild_indexes_projections) { materialized_indices.insert(index.name); continue; @@ -913,7 +922,7 @@ void MutationsInterpreter::prepare(bool dry_run) if (!source.hasProjection(projection.name)) continue; - if (has_alter_delete) + if (need_rebuild_indexes_projections) { materialized_projections.insert(projection.name); continue; diff --git a/src/Interpreters/MutationsInterpreter.h b/src/Interpreters/MutationsInterpreter.h index 9b4caaae231..c53b86ddb5e 100644 --- a/src/Interpreters/MutationsInterpreter.h +++ b/src/Interpreters/MutationsInterpreter.h @@ -122,6 +122,7 @@ public: bool materializeTTLRecalculateOnly() const; bool hasSecondaryIndex(const String & name) const; bool hasProjection(const String & name) const; + bool isCompactPart() const; void read( Stage & first_stage,