fix corner cases in vertical merges with ReplacingMergeTree

This commit is contained in:
Anton Popov 2021-04-22 01:22:40 +03:00
parent a25e6d96a5
commit 3548e31afd
4 changed files with 53 additions and 1 deletions

View File

@ -53,7 +53,7 @@ ColumnGathererStream::ColumnGathererStream(
Block ColumnGathererStream::readImpl()
{
/// Special case: single source and there are no skipped rows
if (children.size() == 1 && row_sources_buf.eof())
if (children.size() == 1 && row_sources_buf.eof() && !source_to_fully_copy)
return children[0]->read();
if (!source_to_fully_copy && row_sources_buf.eof())

View File

@ -93,6 +93,10 @@ IMergingAlgorithm::Status ReplacingSortedAlgorithm::merge()
}
}
/// If have enough rows, return block, because it prohibited to overflow requested number of rows.
if (merged_data.hasEnoughRows())
return Status(merged_data.pull());
/// We will write the data for the last primary key.
if (!selected_row.empty())
insertRow();

View File

@ -0,0 +1,4 @@
1720 32
220 17
33558527 8193
33550336 8192

View File

@ -0,0 +1,44 @@
SET optimize_on_insert = 0;
DROP TABLE IF EXISTS replacing_table;
CREATE TABLE replacing_table (a UInt32, b UInt32, c UInt32)
ENGINE = ReplacingMergeTree ORDER BY a
SETTINGS vertical_merge_algorithm_min_rows_to_activate = 1,
vertical_merge_algorithm_min_columns_to_activate = 1,
index_granularity = 16,
min_bytes_for_wide_part = 0,
merge_max_block_size = 16;
INSERT INTO replacing_table SELECT number, number, number from numbers(16);
INSERT INTO replacing_table SELECT 100, number, number from numbers(16);
SELECT sum(a), count() FROM replacing_table;
OPTIMIZE TABLE replacing_table FINAL;
SELECT sum(a), count() FROM replacing_table;
DROP TABLE IF EXISTS replacing_table;
CREATE TABLE replacing_table
(
key UInt64,
value UInt64
)
ENGINE = ReplacingMergeTree
ORDER BY key
SETTINGS
vertical_merge_algorithm_min_rows_to_activate=0,
vertical_merge_algorithm_min_columns_to_activate=0,
min_bytes_for_wide_part = 0;
INSERT INTO replacing_table SELECT if(number == 8192, 8191, number), 1 FROM numbers(8193);
SELECT sum(key), count() from replacing_table;
OPTIMIZE TABLE replacing_table FINAL;
SELECT sum(key), count() from replacing_table;
DROP TABLE IF EXISTS replacing_table;