Skip to content

Commit

Permalink
Merge pull request #18483 from ClickHouse/backport/20.11/18381
Browse files Browse the repository at this point in the history
Backport #18381 to 20.11: Restrict merges from wide to compact parts
  • Loading branch information
CurtizJ authored Dec 25, 2020
2 parents 7a6097f + 2115d3a commit e587946
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Storages/MergeTree/MergeTreeDataMergerMutator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,16 @@ void FutureMergedMutatedPart::assign(MergeTreeData::DataPartsVector parts_)

size_t sum_rows = 0;
size_t sum_bytes_uncompressed = 0;
MergeTreeDataPartType future_part_type = MergeTreeDataPartType::UNKNOWN;
for (const auto & part : parts_)
{
sum_rows += part->rows_count;
sum_bytes_uncompressed += part->getTotalColumnsSize().data_uncompressed;
future_part_type = std::min(future_part_type, part->getType());
}

auto future_part_type = parts_.front()->storage.choosePartTypeOnDisk(sum_bytes_uncompressed, sum_rows);
auto chosen_type = parts_.front()->storage.choosePartTypeOnDisk(sum_bytes_uncompressed, sum_rows);
future_part_type = std::min(future_part_type, chosen_type);
assign(std::move(parts_), future_part_type);
}

Expand Down
12 changes: 11 additions & 1 deletion src/Storages/MergeTree/MergeTreeDataPartType.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MergeTreeDataPartType
/// Data of all columns is stored in one file. Marks are also stored in single file.
COMPACT,

/// Format with buffering data in RAM. Not implemented yet.
/// Format with buffering data in RAM.
IN_MEMORY,

UNKNOWN,
Expand All @@ -37,6 +37,16 @@ class MergeTreeDataPartType
return !(*this == other);
}

bool operator<(const MergeTreeDataPartType & other) const
{
return value < other.value;
}

bool operator>(const MergeTreeDataPartType & other) const
{
return value > other.value;
}

void fromString(const String & str);
String toString() const;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
all_1_1_0 Wide
all_2_2_0 Wide
all_3_3_0 Wide
all_1_3_1 Wide
300000
all_1_3_1 Wide
all_4_4_0 Compact
all_1_4_2 Wide
400000
36 changes: 36 additions & 0 deletions tests/queries/0_stateless/01606_merge_from_wide_to_compact.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
DROP TABLE IF EXISTS wide_to_comp;

CREATE TABLE wide_to_comp (a Int, b Int, c Int)
ENGINE = MergeTree ORDER BY a
settings vertical_merge_algorithm_min_rows_to_activate = 1,
vertical_merge_algorithm_min_columns_to_activate = 1,
min_bytes_for_wide_part = 0;

SYSTEM STOP merges wide_to_comp;

INSERT INTO wide_to_comp SELECT number, number, number FROM numbers(100000);
INSERT INTO wide_to_comp SELECT number, number, number FROM numbers(100000);
INSERT INTO wide_to_comp SELECT number, number, number FROM numbers(100000);

SELECT name, part_type FROM system.parts WHERE table = 'wide_to_comp' AND database = currentDatabase() AND active ORDER BY name;

ALTER TABLE wide_to_comp MODIFY setting min_rows_for_wide_part = 10000000;
SYSTEM START merges wide_to_comp;
OPTIMIZE TABLE wide_to_comp FINAL;

SELECT name, part_type FROM system.parts WHERE table = 'wide_to_comp' AND database = currentDatabase() AND active ORDER BY name;
SELECT count() FROM wide_to_comp WHERE not ignore(*);

SYSTEM STOP merges wide_to_comp;
INSERT INTO wide_to_comp SELECT number, number, number FROM numbers(100000);

SELECT name, part_type FROM system.parts WHERE table = 'wide_to_comp' AND database = currentDatabase() AND active ORDER BY name;

ALTER TABLE wide_to_comp MODIFY setting min_rows_for_wide_part = 10000000;
SYSTEM START merges wide_to_comp;
OPTIMIZE TABLE wide_to_comp FINAL;

SELECT name, part_type FROM system.parts WHERE table = 'wide_to_comp' AND database = currentDatabase() AND active ORDER BY name;
SELECT count() FROM wide_to_comp WHERE not ignore(*);

DROP TABLE wide_to_comp;

0 comments on commit e587946

Please sign in to comment.