From c6112f052ea5b0232351f71b3ff65805dcdc537d Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Tue, 8 Oct 2024 14:09:31 +0000 Subject: [PATCH] Backport #70452 to 24.8: Don't prefetch parts with no rows --- .../MergeTree/MergeTreeSequentialSource.cpp | 2 +- .../03250_avoid_prefetch_empty_parts.reference | 0 .../03250_avoid_prefetch_empty_parts.sql | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.reference create mode 100644 tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.sql diff --git a/src/Storages/MergeTree/MergeTreeSequentialSource.cpp b/src/Storages/MergeTree/MergeTreeSequentialSource.cpp index 39aa191a3d2..f06dbabaeb5 100644 --- a/src/Storages/MergeTree/MergeTreeSequentialSource.cpp +++ b/src/Storages/MergeTree/MergeTreeSequentialSource.cpp @@ -174,7 +174,7 @@ MergeTreeSequentialSource::MergeTreeSequentialSource( /*avg_value_size_hints=*/ {}, /*profile_callback=*/ {}); - if (prefetch) + if (prefetch && !data_part->isEmpty()) reader->prefetchBeginOfRange(Priority{}); } diff --git a/tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.reference b/tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.sql b/tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.sql new file mode 100644 index 00000000000..f2e0f630350 --- /dev/null +++ b/tests/queries/0_stateless/03250_avoid_prefetch_empty_parts.sql @@ -0,0 +1,15 @@ +-- Tags: no-fasttest + +DROP TABLE IF EXISTS 03250_avoid_prefetch; +CREATE table 03250_avoid_prefetch(id UInt64, string LowCardinality(String)) +ENGINE = MergeTree +ORDER BY id +SETTINGS enable_vertical_merge_algorithm = 1, vertical_merge_algorithm_min_rows_to_activate = 1, vertical_merge_remote_filesystem_prefetch = 1, +vertical_merge_algorithm_min_bytes_to_activate = 1, vertical_merge_algorithm_min_columns_to_activate = 1, +min_rows_for_wide_part = 1, min_bytes_for_wide_part = 1, remove_empty_parts = 0, storage_policy = 's3_no_cache'; + +INSERT INTO 03250_avoid_prefetch VALUES (1, 'test'); +ALTER TABLE 03250_avoid_prefetch DELETE WHERE id = 1; +INSERT INTO 03250_avoid_prefetch VALUES (2, 'test'); +OPTIMIZE TABLE 03250_avoid_prefetch FINAL; +