ISSUES-17244 try fix deterministic functions with predicate optimizer

This commit is contained in:
zhang2014 2020-11-22 22:17:09 +08:00
parent 1cdb447b77
commit 213c7639b7
5 changed files with 23 additions and 4 deletions

View File

@ -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())
if (function)
{
if (function->isStateful())
data.is_stateful_function = true;
if (!function->isDeterministicInScopeOfQuery())
data.is_deterministic_function = false;
}
}
}

View File

@ -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 = {};
};

View File

@ -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)
{

View File

@ -0,0 +1,11 @@
SELECT count()
FROM
(
SELECT number
FROM
(
SELECT number
FROM numbers(1000000)
)
WHERE rand64() < (0.01 * 18446744073709552000.)
)

View File

@ -0,0 +1 @@
EXPLAIN SYNTAX SELECT count(*) FROM ( SELECT number FROM ( SELECT number FROM numbers(1000000) ) WHERE rand64() < (0.01 * 18446744073709552000.));