Skip to content

Commit eba7edd

Browse files
Backport #94725 to 25.12: Preserve constant index granularity (use_const_adaptive_granularity) after Vertical merges
1 parent 4b2fbdc commit eba7edd

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
@@ -2432,8 +2432,6 @@ void MergeTask::ExecuteAndFinalizeHorizontalPart::createMergedStream() const
24322432
}
24332433

24342434
const bool is_vertical_merge = (global_ctx->chosen_merge_algorithm == MergeAlgorithm::Vertical);
2435-
/// If merge is vertical we cannot calculate it
2436-
ctx->blocks_are_granules_size = is_vertical_merge;
24372435

24382436
if (global_ctx->cleanup && !(*merge_tree_settings)[MergeTreeSetting::allow_experimental_replacing_merge_with_cleanup])
24392437
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "Experimental merges with CLEANUP are not allowed");
@@ -2455,7 +2453,7 @@ void MergeTask::ExecuteAndFinalizeHorizontalPart::createMergedStream() const
24552453
(*merge_tree_settings)[MergeTreeSetting::merge_max_block_size],
24562454
(*merge_tree_settings)[MergeTreeSetting::merge_max_block_size_bytes],
24572455
max_dynamic_subcolumns,
2458-
ctx->blocks_are_granules_size,
2456+
is_vertical_merge,
24592457
cleanup,
24602458
global_ctx->time_of_merge);
24612459

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)