mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
ISSUES-17244 try fix deterministic functions with predicate optimizer
This commit is contained in:
parent
1cdb447b77
commit
213c7639b7
@ -27,8 +27,14 @@ void ExpressionInfoMatcher::visit(const ASTFunction & ast_function, const ASTPtr
|
||||
const auto & function = FunctionFactory::instance().tryGet(ast_function.name, data.context);
|
||||
|
||||
/// Skip lambda, tuple and other special functions
|
||||
if (function && function->isStateful())
|
||||
data.is_stateful_function = true;
|
||||
if (function)
|
||||
{
|
||||
if (function->isStateful())
|
||||
data.is_stateful_function = true;
|
||||
|
||||
if (!function->isDeterministicInScopeOfQuery())
|
||||
data.is_deterministic_function = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ struct ExpressionInfoMatcher
|
||||
bool is_array_join = false;
|
||||
bool is_stateful_function = false;
|
||||
bool is_aggregate_function = false;
|
||||
bool is_deterministic_function = true;
|
||||
std::unordered_set<size_t> unique_reference_tables_pos = {};
|
||||
};
|
||||
|
||||
|
@ -90,8 +90,8 @@ std::vector<ASTs> PredicateExpressionsOptimizer::extractTablesPredicates(const A
|
||||
ExpressionInfoVisitor::Data expression_info{.context = context, .tables = tables_with_columns};
|
||||
ExpressionInfoVisitor(expression_info).visit(predicate_expression);
|
||||
|
||||
if (expression_info.is_stateful_function)
|
||||
return {}; /// give up the optimization when the predicate contains stateful function
|
||||
if (expression_info.is_stateful_function || !expression_info.is_deterministic_function)
|
||||
return {}; /// Not optimized when predicate contains state function or indeterministic function
|
||||
|
||||
if (!expression_info.is_array_join)
|
||||
{
|
||||
|
@ -0,0 +1,11 @@
|
||||
SELECT count()
|
||||
FROM
|
||||
(
|
||||
SELECT number
|
||||
FROM
|
||||
(
|
||||
SELECT number
|
||||
FROM numbers(1000000)
|
||||
)
|
||||
WHERE rand64() < (0.01 * 18446744073709552000.)
|
||||
)
|
@ -0,0 +1 @@
|
||||
EXPLAIN SYNTAX SELECT count(*) FROM ( SELECT number FROM ( SELECT number FROM numbers(1000000) ) WHERE rand64() < (0.01 * 18446744073709552000.));
|
Loading…
Reference in New Issue
Block a user