diff --git a/src/Storages/MergeTree/IMergeTreeDataPart.cpp b/src/Storages/MergeTree/IMergeTreeDataPart.cpp index 1d04118643f..0c329299209 100644 --- a/src/Storages/MergeTree/IMergeTreeDataPart.cpp +++ b/src/Storages/MergeTree/IMergeTreeDataPart.cpp @@ -552,6 +552,29 @@ void IMergeTreeDataPart::loadRowsCount() auto buf = openForReading(volume->getDisk(), path); readIntText(rows_count, *buf); assertEOF(*buf); + +#ifndef NDEBUG + /// columns have to be loaded + for (const auto & column : getColumns()) + { + if (column.type->isValueRepresentedByNumber()) + { + auto size = getColumnSize(column.name, *column.type); + + if (size.data_uncompressed == 0) + continue; + + size_t rows_in_column = size.data_uncompressed / column.type->getSizeOfValueInMemory(); + if (rows_in_column != rows_count) + { + throw Exception( + ErrorCodes::LOGICAL_ERROR, + "Column {} has rows count {} according to size in memory " + "and size of single value, but data part {} has {} rows", backQuote(column.name), rows_in_column, name, rows_count); + } + } + } +#endif } else { diff --git a/src/Storages/MergeTree/MergeTreeDataPartWide.cpp b/src/Storages/MergeTree/MergeTreeDataPartWide.cpp index b33a3d4645d..fb6784434a8 100644 --- a/src/Storages/MergeTree/MergeTreeDataPartWide.cpp +++ b/src/Storages/MergeTree/MergeTreeDataPartWide.cpp @@ -237,7 +237,20 @@ void MergeTreeDataPartWide::calculateEachColumnSizes(ColumnSizeByName & each_col ColumnSize size = getColumnSizeImpl(column.name, *column.type, &processed_substreams); each_columns_size[column.name] = size; total_size.add(size); + +#ifndef NDEBUG + if (rows_count != 0 && column.type->isValueRepresentedByNumber()) + { + size_t rows_in_column = size.data_uncompressed / column.type->getSizeOfValueInMemory(); + if (rows_in_column != rows_count) + { + throw Exception( + ErrorCodes::LOGICAL_ERROR, + "Column {} has rows count {} according to size in memory and size of single value, but data part {} has {} rows", backQuote(column.name), rows_in_column, name, rows_count); + } + } } +#endif } } diff --git a/tests/queries/0_stateless/01415_sticking_mutations.reference b/tests/queries/0_stateless/01415_sticking_mutations.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/01415_sticking_mutations.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/01415_sticking_mutations.sh b/tests/queries/0_stateless/01415_sticking_mutations.sh new file mode 100755 index 00000000000..fdc9b580274 --- /dev/null +++ b/tests/queries/0_stateless/01415_sticking_mutations.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. $CURDIR/../shell_config.sh + +$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS sticking_mutations" + +$CLICKHOUSE_CLIENT -n --query "CREATE TABLE sticking_mutations ( + key UInt64, + value1 String, + value2 UInt8 +) +ENGINE = MergeTree() +ORDER BY key;" + +$CLICKHOUSE_CLIENT --query "INSERT INTO sticking_mutations SELECT number, toString(number), number % 128 FROM numbers(1000)" + +# if merges stopped for normal merge tree mutations will stick +$CLICKHOUSE_CLIENT --query "SYSTEM STOP MERGES sticking_mutations" + +$CLICKHOUSE_CLIENT --query "ALTER TABLE sticking_mutations DELETE WHERE value2 % 32 == 0, MODIFY COLUMN value1 UInt64;" & + + +##### wait mutation to start ##### +check_query="SELECT count() FROM system.mutations WHERE table='sticking_mutations' and database='$CLICKHOUSE_DATABASE'" + +query_result=`$CLICKHOUSE_CLIENT --query="$check_query" 2>&1` + +while [ "$query_result" == "0" ] +do + query_result=`$CLICKHOUSE_CLIENT --query="$check_query" 2>&1` + sleep 0.5 +done +##### wait mutation to start ##### + +# Starting merges to execute sticked mutations + +$CLICKHOUSE_CLIENT --query "SYSTEM START MERGES sticking_mutations" + +# just to be sure, that previous mutations finished +$CLICKHOUSE_CLIENT --query "ALTER TABLE sticking_mutations DELETE WHERE value % 31 == 0 SETTINGS mutations_sync = 1" + +$CLICKHOUSE_CLIENT --query "OPTIMIZE TABLE sticking_mutations FINAL" + +$CLICKHOUSE_CLIENT --query "SELECT 1" + +$CLICKHOUSE_CLIENT --query "DROP TABLE IF EXISTS sticking_mutations"