Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force reanalysis if parallel replicas changed #60362

Merged
merged 11 commits into from Mar 4, 2024
Merged
13 changes: 13 additions & 0 deletions src/Interpreters/InterpreterSelectQuery.cpp
Expand Up @@ -777,12 +777,25 @@ InterpreterSelectQuery::InterpreterSelectQuery(
result_header = getSampleBlockImpl();
};

/// This is a hack to make sure we reanalyze if GlobalSubqueriesVisitor changed allow_experimental_parallel_reading_from_replicas
UInt64 parallel_replicas_before_analysis
= context->hasQueryContext() ? context->getQueryContext()->getSettingsRef().allow_experimental_parallel_reading_from_replicas : 0;
analyze(shouldMoveToPrewhere());

bool need_analyze_again = false;
bool can_analyze_again = false;

if (context->hasQueryContext())
{
/// No buts or ifs, if the analysis changed this setting we must reanalyze without parallel replicas
if (context->getQueryContext()->getSettingsRef().allow_experimental_parallel_reading_from_replicas
!= parallel_replicas_before_analysis)
{
context->setSetting("allow_experimental_parallel_reading_from_replicas", Field(0));
context->setSetting("max_parallel_replicas", UInt64{0});
need_analyze_again = true;
}

/// Check number of calls of 'analyze' function.
/// If it is too big, we will not analyze the query again not to have exponential blowup.
std::atomic<size_t> & current_query_analyze_count = context->getQueryContext()->kitchen_sink.analyze_counter;
Expand Down
@@ -1,3 +1,4 @@
990000
990000
10
990000
9 changes: 9 additions & 0 deletions tests/queries/0_stateless/02972_parallel_replicas_cte.sql
Expand Up @@ -28,5 +28,14 @@ SETTINGS allow_experimental_analyzer = 0, allow_experimental_parallel_reading_fr
SELECT count() FROM pr_2 JOIN numbers(10) as pr_1 ON pr_2.a = pr_1.number
SETTINGS allow_experimental_parallel_reading_from_replicas = 1, parallel_replicas_for_non_replicated_merge_tree = 1, cluster_for_parallel_replicas = 'test_cluster_one_shard_three_replicas_localhost', max_parallel_replicas = 3;

-- Being a subquery should still disable parallel replicas
SELECT *
FROM
(
WITH filtered_groups AS (SELECT a FROM pr_1 WHERE a >= 10000)
SELECT count() FROM pr_2 INNER JOIN filtered_groups ON pr_2.a = filtered_groups.a
)
SETTINGS allow_experimental_parallel_reading_from_replicas = 1, parallel_replicas_for_non_replicated_merge_tree = 1, cluster_for_parallel_replicas = 'test_cluster_one_shard_three_replicas_localhost', max_parallel_replicas = 3;

DROP TABLE IF EXISTS pr_1;
DROP TABLE IF EXISTS pr_2;