Merge pull request #17273 from zhang2014/fix/ISSUES-17244

ISSUES-17244 try fix indeterministic functions with predicate optimizer
This commit is contained in:
alexey-milovidov 2020-12-20 09:51:20 +03:00 committed by GitHub
commit af4c3956da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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())
data.is_stateful_function = true;
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 stateful 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.));