Skip to content

Commit 86fcd89

Browse files
committed
Preserve constant index granularity (use_const_adaptive_granularity) after Vertical merges
The problem was that just before creating index granularity the blocks_are_granules_size has been set to true in case of vertical merges, and this forces to use adaptive granulas But, we do not need this, since it is written before vertical merges anyway, vertical merges does not calculate index granularity
1 parent 2359d6c commit 86fcd89

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/Storages/MergeTree/MergeTask.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,8 +2446,6 @@ void MergeTask::ExecuteAndFinalizeHorizontalPart::createMergedStream() const
24462446
}
24472447

24482448
const bool is_vertical_merge = (global_ctx->chosen_merge_algorithm == MergeAlgorithm::Vertical);
2449-
/// If merge is vertical we cannot calculate it
2450-
ctx->blocks_are_granules_size = is_vertical_merge;
24512449

24522450
if (global_ctx->cleanup && !(*merge_tree_settings)[MergeTreeSetting::allow_experimental_replacing_merge_with_cleanup])
24532451
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Experimental merges with CLEANUP are not allowed");
@@ -2469,7 +2467,7 @@ void MergeTask::ExecuteAndFinalizeHorizontalPart::createMergedStream() const
24692467
(*merge_tree_settings)[MergeTreeSetting::merge_max_block_size],
24702468
(*merge_tree_settings)[MergeTreeSetting::merge_max_block_size_bytes],
24712469
max_dynamic_subcolumns,
2472-
ctx->blocks_are_granules_size,
2470+
is_vertical_merge,
24732471
cleanup,
24742472
global_ctx->time_of_merge);
24752473

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- { echo }
2+
insert into tab select 1, if(number < 4096, 'foo', repeat('b', 1000)) from numbers(400e3) settings max_block_size=65535, max_insert_threads=1;
3+
select name, rows, marks, index_granularity_bytes_in_memory_allocated from system.parts where database = currentDatabase() and table = 'tab' and active;
4+
1_1_1_0 327675 3278 25
5+
1_2_2_0 72325 740 25
6+
optimize table tab;
7+
select name, rows, marks, index_granularity_bytes_in_memory_allocated from system.parts where database = currentDatabase() and table = 'tab' and active;
8+
1_1_2_1 400000 4001 25
9+
select * from tab format Null;
10+
check table tab;
11+
1_1_2_1 1
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
DROP TABLE IF EXISTS tab;
2+
3+
CREATE TABLE tab
4+
(
5+
part Int32,
6+
key String
7+
)
8+
ENGINE = MergeTree
9+
PARTITION BY part
10+
ORDER BY key
11+
SETTINGS
12+
index_granularity = 1000000000,
13+
index_granularity_bytes = 100000,
14+
min_bytes_for_wide_part = 0,
15+
use_const_adaptive_granularity = 1,
16+
enable_index_granularity_compression = 1,
17+
enable_block_number_column = 0,
18+
enable_block_offset_column = 0,
19+
auto_statistics_types = '',
20+
vertical_merge_algorithm_min_rows_to_activate = 0,
21+
vertical_merge_algorithm_min_columns_to_activate = 1,
22+
string_serialization_version = 'single_stream',
23+
merge_max_block_size = 65535;
24+
25+
-- { echo }
26+
insert into tab select 1, if(number < 4096, 'foo', repeat('b', 1000)) from numbers(400e3) settings max_block_size=65535, max_insert_threads=1;
27+
select name, rows, marks, index_granularity_bytes_in_memory_allocated from system.parts where database = currentDatabase() and table = 'tab' and active;
28+
optimize table tab;
29+
select name, rows, marks, index_granularity_bytes_in_memory_allocated from system.parts where database = currentDatabase() and table = 'tab' and active;
30+
select * from tab format Null;
31+
check table tab;

0 commit comments

Comments
 (0)