From 4ad4fc3f7ba30459f54a29aa3adaaf72c74a0eca Mon Sep 17 00:00:00 2001 From: alesapin Date: Mon, 18 Mar 2019 19:21:52 +0300 Subject: [PATCH] Fix granule size less than row size --- .../MergeTree/MergedBlockOutputStream.cpp | 2 ++ ...00926_adaptive_index_granularity.reference | 2 ++ .../00926_adaptive_index_granularity.sql | 28 ++++++++++++++++++- 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/dbms/src/Storages/MergeTree/MergedBlockOutputStream.cpp b/dbms/src/Storages/MergeTree/MergedBlockOutputStream.cpp index 05333fd57b3..bf48793c0d2 100644 --- a/dbms/src/Storages/MergeTree/MergedBlockOutputStream.cpp +++ b/dbms/src/Storages/MergeTree/MergedBlockOutputStream.cpp @@ -139,6 +139,8 @@ void fillIndexGranularityImpl( index_granularity_for_block = index_granularity_bytes / size_of_row_in_bytes; } } + if (index_granularity_for_block == 0) /// very rare case when index granularity bytes less then single row + index_granularity_for_block = 1; std::cerr << "GRANULARITY SIZE IN ROWS:"<< index_granularity_for_block << std::endl; for (size_t current_row = index_offset; current_row < rows_in_block; current_row += index_granularity_for_block) diff --git a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.reference b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.reference index ee713837485..492c132873e 100644 --- a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.reference +++ b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.reference @@ -2,3 +2,5 @@ 8 4 8 +4 +8 diff --git a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.sql b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.sql index 6f5289c8b91..d671188f133 100644 --- a/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.sql +++ b/dbms/tests/queries/0_stateless/00926_adaptive_index_granularity.sql @@ -1,3 +1,27 @@ +DROP TABLE IF EXISTS test.zero_rows_per_granule; + +CREATE TABLE test.zero_rows_per_granule ( + p Date, + k UInt64, + v1 UInt64, + v2 Int64 +) ENGINE MergeTree() PARTITION BY toYYYYMM(p) ORDER BY k SETTINGS index_granularity_bytes = 20; + +INSERT INTO test.zero_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 2, 3000, 4000), ('2018-05-17', 3, 5000, 6000), ('2018-05-18', 4, 7000, 8000); + +SELECT COUNT(*) FROM test.zero_rows_per_granule; + +OPTIMIZE TABLE test.zero_rows_per_granule FINAL; + + +INSERT INTO test.zero_rows_per_granule (p, k, v1, v2) VALUES ('2018-05-15', 1, 1000, 2000), ('2018-05-16', 5, 3000, 4000), ('2018-05-17', 6, 5000, 6000), ('2018-05-19', 7, 7000, 8000); + +SELECT COUNT(*) FROM test.zero_rows_per_granule; + +DROP TABLE IF EXISTS test.zero_rows_per_granule; + +----- + DROP TABLE IF EXISTS test.two_rows_per_granule; CREATE TABLE test.two_rows_per_granule ( @@ -20,7 +44,9 @@ SELECT COUNT(*) FROM test.two_rows_per_granule; DROP TABLE IF EXISTS test.two_rows_per_granule; -DROP TABLE IF EXISTS test.two_rows_per_granule; +------ + +DROP TABLE IF EXISTS test.four_rows_per_granule; CREATE TABLE test.four_rows_per_granule ( p Date,