second analyze and max_pipeline_depth

This commit is contained in:
vdimir 2022-07-05 11:50:20 +00:00
parent a0488dc901
commit 9c348380f6
No known key found for this signature in database
GPG Key ID: 6EE4CE2BEDC51862
3 changed files with 59 additions and 6 deletions

View File

@ -455,11 +455,10 @@ InterpreterSelectQuery::InterpreterSelectQuery(
{
size_t & current_query_analyze_count = context->getQueryContext()->kitchen_sink.analyze_counter;
++current_query_analyze_count;
if (current_query_analyze_count >= settings.max_pipeline_depth)
throw DB::Exception(ErrorCodes::TOO_DEEP_PIPELINE, "Query analyze overflow. Try to increase `max_pipeline_depth` or simplify the query" );
if (settings.max_pipeline_depth && current_query_analyze_count >= settings.max_pipeline_depth)
throw DB::Exception(ErrorCodes::TOO_DEEP_PIPELINE, "Query analyze overflow. Try to increase `max_pipeline_depth` or simplify the query");
}
/// Allow push down and other optimizations for VIEW: replace with subquery and rewrite it.
ASTPtr view_table;
if (view)
@ -597,8 +596,19 @@ InterpreterSelectQuery::InterpreterSelectQuery(
analyze(shouldMoveToPrewhere());
bool analyze_overflow = false;
if (context->hasQueryContext())
{
/// if we analyze to many times, give up analyzing a second time not to get stuck in the loop
/// the threshold is `max_pipeline_depth / 10` to disable the second analyze and `max_pipeline_depth` to cancel the query at all
const size_t & current_query_analyze_count = context->getQueryContext()->kitchen_sink.analyze_counter;
analyze_overflow = settings.max_pipeline_depth && current_query_analyze_count >= settings.max_pipeline_depth / 10;
}
bool need_analyze_again = false;
if (analysis_result.prewhere_constant_filter_description.always_false || analysis_result.prewhere_constant_filter_description.always_true)
bool prewhere_always_const = analysis_result.prewhere_constant_filter_description.always_false || analysis_result.prewhere_constant_filter_description.always_true;
if (!analyze_overflow && prewhere_always_const)
{
if (analysis_result.prewhere_constant_filter_description.always_true)
query.setExpression(ASTSelectQuery::Expression::PREWHERE, {});
@ -606,7 +616,9 @@ InterpreterSelectQuery::InterpreterSelectQuery(
query.setExpression(ASTSelectQuery::Expression::PREWHERE, std::make_shared<ASTLiteral>(0u));
need_analyze_again = true;
}
if (analysis_result.where_constant_filter_description.always_false || analysis_result.where_constant_filter_description.always_true)
bool where_always_const = analysis_result.where_constant_filter_description.always_false || analysis_result.where_constant_filter_description.always_true;
if (!analyze_overflow && where_always_const)
{
if (analysis_result.where_constant_filter_description.always_true)
query.setExpression(ASTSelectQuery::Expression::WHERE, {});

View File

@ -0,0 +1,26 @@
WITH
x AS
(
SELECT number
FROM numbers(10)
),
cross_sales AS
(
SELECT 1 AS xx
FROM
x,
x AS d1,
x AS d2,
x AS d3,
x AS d4,
x AS d5,
x AS d6,
x AS d7,
x AS d8,
x AS d9
WHERE x.number = d9.number
)
SELECT xx
FROM
cross_sales
WHERE xx = 2000

View File

@ -1,7 +1,10 @@
-- Tags: long
-- https://github.com/ClickHouse/ClickHouse/issues/21557
-- Not stuck at first, but proper fix should make able to process it
SET max_pipeline_depth = 100;
EXPLAIN SYNTAX
WITH
x AS ( SELECT number FROM numbers(10) ),
@ -11,3 +14,15 @@ WITH
WHERE x.number = d9.number
)
SELECT xx FROM cross_sales WHERE xx = 2000; -- { serverError TOO_DEEP_PIPELINE }
SET max_pipeline_depth = 10000;
EXPLAIN SYNTAX
WITH
x AS ( SELECT number FROM numbers(10) ),
cross_sales AS (
SELECT 1 AS xx
FROM x, x AS d1, x AS d2, x AS d3, x AS d4, x AS d5, x AS d6, x AS d7, x AS d8, x AS d9
WHERE x.number = d9.number
)
SELECT xx FROM cross_sales WHERE xx = 2000;