diff --git a/src/Core/Settings.h b/src/Core/Settings.h index ba8f6563ec9..e2aa4e2f2d8 100644 --- a/src/Core/Settings.h +++ b/src/Core/Settings.h @@ -141,7 +141,6 @@ class IColumn; \ M(Bool, force_index_by_date, 0, "Throw an exception if there is a partition key in a table, and it is not used.", 0) \ M(Bool, force_primary_key, 0, "Throw an exception if there is primary key in a table, and it is not used.", 0) \ - M(Bool, force_max_partition_limit, 0, "Throw an exception if max_partitions_to_read is violated.", 0) \ M(String, force_data_skipping_indices, "", "Comma separated list of strings or literals with the name of the data skipping indices that should be used during query execution, otherwise an exception will be thrown.", 0) \ \ M(Float, max_streams_to_max_threads_ratio, 1, "Allows you to use more sources than the number of threads - to more evenly distribute work across threads. It is assumed that this is a temporary solution, since it will be possible in the future to make the number of sources equal to the number of threads, but for each source to dynamically select available work for itself.", 0) \ @@ -354,6 +353,7 @@ class IColumn; M(Bool, allow_introspection_functions, false, "Allow functions for introspection of ELF and DWARF for query profiling. These functions are slow and may impose security considerations.", 0) \ \ M(UInt64, max_partitions_per_insert_block, 100, "Limit maximum number of partitions in single INSERTed block. Zero means unlimited. Throw exception if the block contains too many partitions. This setting is a safety threshold, because using large number of partitions is a common misconception.", 0) \ + M(UInt64, max_partitions_to_read, 0, "Limit the max number of partitions that can be accessed in one query. 0 means unlimited.", 0) \ M(Bool, check_query_single_value_result, true, "Return check query result as single 1/0 value", 0) \ M(Bool, allow_drop_detached, false, "Allow ALTER TABLE ... DROP DETACHED PART[ITION] ... queries", 0) \ \ diff --git a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index ada216b38b9..75760e145d3 100644 --- a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -707,8 +707,9 @@ QueryPlanPtr MergeTreeDataSelectExecutor::readFromParts( if (parts_with_ranges.empty()) return std::make_unique(); - auto max_partitions_to_read = data.getSettings()->max_partitions_to_read; - if (settings.force_max_partition_limit && max_partitions_to_read) + auto max_partitions_to_read + = settings.max_partitions_to_read.changed ? settings.max_partitions_to_read : data.getSettings()->max_partitions_to_read; + if (max_partitions_to_read) { std::set partitions; for (auto & part_with_ranges : parts_with_ranges) diff --git a/tests/queries/0_stateless/01632_max_partitions_to_read.reference b/tests/queries/0_stateless/01632_max_partitions_to_read.reference index e24dfbd1231..ea2526e1301 100644 --- a/tests/queries/0_stateless/01632_max_partitions_to_read.reference +++ b/tests/queries/0_stateless/01632_max_partitions_to_read.reference @@ -1,6 +1,6 @@ -2021-01-03 1 2 -2021-01-04 3 4 -2021-01-03 1 2 -2021-01-04 3 4 -2021-01-03 1 2 -2021-01-04 3 4 +2021-01-01 1 2 +2021-01-02 4 5 +2021-01-01 1 2 +2021-01-02 4 5 +2021-01-01 1 2 +2021-01-02 4 5 diff --git a/tests/queries/0_stateless/01632_max_partitions_to_read.sql b/tests/queries/0_stateless/01632_max_partitions_to_read.sql index 8e0d2ba0ed6..b91405569bc 100644 --- a/tests/queries/0_stateless/01632_max_partitions_to_read.sql +++ b/tests/queries/0_stateless/01632_max_partitions_to_read.sql @@ -2,16 +2,16 @@ drop table if exists p; create table p(d Date, i int, j int) engine MergeTree partition by d order by i settings max_partitions_to_read = 1; -insert into p values (yesterday(), 1, 2), (today(), 3, 4); +insert into p values ('2021-01-01', 1, 2), ('2021-01-02', 4, 5); -select * from p order by i; -- default no limit +select * from p order by i; -- { serverError 565 } -select * from p order by i settings force_max_partition_limit = 0; +select * from p order by i settings max_partitions_to_read = 2; -select * from p order by i settings force_max_partition_limit = 1; -- { serverError 565 } +select * from p order by i settings max_partitions_to_read = 0; -- unlimited alter table p modify setting max_partitions_to_read = 2; -select * from p order by i settings force_max_partition_limit = 1; +select * from p order by i; drop table if exists p;