Fix system.data_skipping_indices for recreated indices

Fix secondary index size in system.data_skipping_indices table in the
case of dropped and added again index.
This commit is contained in:
Artur Malchanau 2023-09-03 20:36:55 +03:00
parent 97061f6806
commit 04d0b0c09a
No known key found for this signature in database
GPG Key ID: 150F92E9060ADF60
3 changed files with 13 additions and 5 deletions

View File

@ -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;
};

View File

@ -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

View File

@ -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;