diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index 90c6b0784b4..c0ce0a2612a 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -4858,17 +4858,18 @@ void MergeTreeData::removePartContributionToColumnAndSecondaryIndexSizes(const D log_subtract(total_column_size.marks, part_column_size.marks, ".marks"); } - auto indexes_descriptions = getInMemoryMetadataPtr()->secondary_indices; - for (const auto & index : indexes_descriptions) + for (auto & [secondary_index_name, total_secondary_index_size] : secondary_index_sizes) { - IndexSize & total_secondary_index_size = secondary_index_sizes[index.name]; - IndexSize part_secondary_index_size = part->getSecondaryIndexSize(index.name); + if (!part->hasSecondaryIndex(secondary_index_name)) + continue; + + IndexSize part_secondary_index_size = part->getSecondaryIndexSize(secondary_index_name); auto log_subtract = [&](size_t & from, size_t value, const char * field) { if (value > from) LOG_ERROR(log, "Possibly incorrect index size subtraction: {} - {} = {}, index: {}, field: {}", - from, value, from - value, index.name, field); + from, value, from - value, secondary_index_name, field); from -= value; }; diff --git a/tests/queries/0_stateless/02028_system_data_skipping_indices_size.reference b/tests/queries/0_stateless/02028_system_data_skipping_indices_size.reference index e455643c01e..456f9d113be 100644 --- a/tests/queries/0_stateless/02028_system_data_skipping_indices_size.reference +++ b/tests/queries/0_stateless/02028_system_data_skipping_indices_size.reference @@ -1 +1,2 @@ default test_table value_index minmax minmax value 1 38 12 24 +default test_table value_index minmax minmax value 1 38 12 24 diff --git a/tests/queries/0_stateless/02028_system_data_skipping_indices_size.sql b/tests/queries/0_stateless/02028_system_data_skipping_indices_size.sql index 1efb9cff6a4..07237c43bea 100644 --- a/tests/queries/0_stateless/02028_system_data_skipping_indices_size.sql +++ b/tests/queries/0_stateless/02028_system_data_skipping_indices_size.sql @@ -12,4 +12,10 @@ ORDER BY key SETTINGS compress_marks=false; INSERT INTO test_table VALUES (0, 'Value'); SELECT * FROM system.data_skipping_indices WHERE database = currentDatabase(); +ALTER TABLE test_table DROP INDEX value_index; +ALTER TABLE test_table ADD INDEX value_index value TYPE minmax GRANULARITY 1; +ALTER TABLE test_table MATERIALIZE INDEX value_index SETTINGS mutations_sync=1; + +SELECT * FROM system.data_skipping_indices WHERE database = currentDatabase(); + DROP TABLE test_table;