fix secondary indices corruption in compact parts

This commit is contained in:
Anton Popov 2020-08-09 04:45:10 +03:00
parent dcf94d08e9
commit 2280619ad0
3 changed files with 18 additions and 0 deletions

View File

@ -261,6 +261,11 @@ void MergeTreeDataPartWriterOnDisk::calculateAndSerializeSkipIndices(const Block
{ {
limit = current_index_offset; limit = current_index_offset;
} }
else if (skip_index_current_data_mark == index_granularity.getMarksCount())
{
/// Case, when last granule was exceeded and no new granule was created.
limit = rows - prev_pos;
}
else else
{ {
limit = index_granularity.getMarkRows(skip_index_current_data_mark); limit = index_granularity.getMarkRows(skip_index_current_data_mark);

View File

@ -0,0 +1,12 @@
DROP TABLE IF EXISTS index_compact;
CREATE TABLE index_compact(a UInt32, b UInt32, index i1 b type minmax granularity 1)
ENGINE = MergeTree ORDER BY a
SETTINGS min_rows_for_wide_part = 1000, index_granularity = 128, merge_max_block_size = 100;
INSERT INTO index_compact SELECT number, toString(number) FROM numbers(100);
INSERT INTO index_compact SELECT number, toString(number) FROM numbers(30);
OPTIMIZE TABLE index_compact FINAL;
SELECT count() FROM index_compact WHERE b < 10;