Disable parallel replicas with IN with subquery

This commit is contained in:
Igor Nikonov 2023-12-21 16:21:02 +00:00
parent 34fd555ee6
commit f0933d2714
5 changed files with 48 additions and 2 deletions

View File

@ -882,6 +882,17 @@ bool InterpreterSelectQuery::adjustParallelReplicasAfterAnalysis()
return true;
}
if (query_analyzer->getPreparedSets()->hasSubqueries())
{
if (settings.allow_experimental_parallel_reading_from_replicas == 2)
throw Exception(ErrorCodes::SUPPORT_IS_DISABLED, "IN with subquery is not supported with parallel replicas");
context->setSetting("allow_experimental_parallel_reading_from_replicas", Field(0));
context->setSetting("max_parallel_replicas", UInt64{0});
LOG_INFO(log, "Disabling parallel replicas to execute a query with IN with subquery");
return true;
}
auto storage_merge_tree = std::dynamic_pointer_cast<MergeTreeData>(storage);
if (!storage_merge_tree || settings.parallel_replicas_min_number_of_rows_per_replica == 0)
return false;

View File

@ -327,7 +327,7 @@ std::shared_ptr<FutureSetFromStorage> PreparedSets::findStorage(const Hash & key
return it->second;
}
PreparedSets::Subqueries PreparedSets::getSubqueries()
PreparedSets::Subqueries PreparedSets::getSubqueries() const
{
PreparedSets::Subqueries res;
res.reserve(sets_from_subqueries.size());

View File

@ -157,7 +157,8 @@ public:
std::shared_ptr<FutureSetFromSubquery> findSubquery(const Hash & key) const;
using Subqueries = std::vector<std::shared_ptr<FutureSetFromSubquery>>;
Subqueries getSubqueries();
Subqueries getSubqueries() const;
bool hasSubqueries() const { return !sets_from_subqueries.empty(); }
const SetsFromTuple & getSetsFromTuple() const { return sets_from_tuple; }
// const SetsFromStorage & getSetsFromStorage() const { return sets_from_storage; }

View File

@ -0,0 +1,8 @@
---
2 test2 8
3 test3 8
4 test4 1985
---
1 test1 42
---
3 test3

View File

@ -0,0 +1,26 @@
DROP TABLE IF EXISTS merge_tree_in_subqueries;
CREATE TABLE merge_tree_in_subqueries (id UInt64, name String, num UInt64) ENGINE = MergeTree ORDER BY (id, name);
INSERT INTO merge_tree_in_subqueries VALUES(1, 'test1', 42);
INSERT INTO merge_tree_in_subqueries VALUES(2, 'test2', 8);
INSERT INTO merge_tree_in_subqueries VALUES(3, 'test3', 8);
INSERT INTO merge_tree_in_subqueries VALUES(4, 'test4', 1985);
INSERT INTO merge_tree_in_subqueries VALUES(5, 'test5', 0);
SET max_parallel_replicas=3, cluster_for_parallel_replicas='test_cluster_one_shard_three_replicas_localhost', parallel_replicas_for_non_replicated_merge_tree=1;
SELECT * FROM merge_tree_in_subqueries WHERE id IN (SELECT * FROM system.numbers LIMIT 0) SETTINGS allow_experimental_parallel_reading_from_replicas=2; -- { serverError SUPPORT_IS_DISABLED }
SELECT * FROM merge_tree_in_subqueries WHERE id IN (SELECT * FROM system.numbers LIMIT 0) SETTINGS allow_experimental_parallel_reading_from_replicas=1;
SELECT '---';
SELECT * FROM merge_tree_in_subqueries WHERE id IN (SELECT * FROM system.numbers LIMIT 2, 3) ORDER BY id SETTINGS allow_experimental_parallel_reading_from_replicas=2; -- { serverError SUPPORT_IS_DISABLED };
SELECT * FROM merge_tree_in_subqueries WHERE id IN (SELECT * FROM system.numbers LIMIT 2, 3) ORDER BY id SETTINGS allow_experimental_parallel_reading_from_replicas=1;
SELECT '---';
SELECT * FROM merge_tree_in_subqueries WHERE id IN (SELECT 1) ORDER BY id SETTINGS allow_experimental_parallel_reading_from_replicas=2; -- { serverError SUPPORT_IS_DISABLED };
SELECT * FROM merge_tree_in_subqueries WHERE id IN (SELECT 1) ORDER BY id SETTINGS allow_experimental_parallel_reading_from_replicas=1;
-- IN with tuples is allowed
SELECT '---';
SELECT id, name FROM merge_tree_in_subqueries WHERE (id, name) IN (3, 'test3') SETTINGS allow_experimental_parallel_reading_from_replicas=2;
DROP TABLE IF EXISTS merge_tree_in_subqueries;