From 597ae0b937650d5d1cc700f9982f72668948de4d Mon Sep 17 00:00:00 2001 From: zhang2014 Date: Fri, 15 Feb 2019 16:03:18 +0800 Subject: [PATCH] ISSUES-4389 fix lambda function with predicate optimizer --- dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp | 6 ++++-- .../0_stateless/00808_not_optimize_predicate.reference | 3 +++ .../queries/0_stateless/00808_not_optimize_predicate.sql | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp b/dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp index 85f8f09b867..11bd6f564b7 100644 --- a/dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp +++ b/dbms/src/Interpreters/PredicateExpressionsOptimizer.cpp @@ -119,8 +119,10 @@ bool PredicateExpressionsOptimizer::allowPushDown(const ASTSelectQuery * subquer for (const auto & subquery_function : extract_data.functions) { - const auto & function = FunctionFactory::instance().get(subquery_function->name, context); - if (function->isStateful()) + const auto & function = FunctionFactory::instance().tryGet(subquery_function->name, context); + + /// Skip lambda态tuple and other special functions + if (function && function->isStateful()) return false; } diff --git a/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.reference b/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.reference index 1454dfe443b..1899fa2045d 100644 --- a/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.reference +++ b/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.reference @@ -7,3 +7,6 @@ 1 a 0 2 b 0 2 a 0 +(1,1) +(3,2) +(5,2) diff --git a/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.sql b/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.sql index f0b29f413ff..ab57047f3e0 100644 --- a/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.sql +++ b/dbms/tests/queries/0_stateless/00808_not_optimize_predicate.sql @@ -29,4 +29,11 @@ SELECT n, z, changed FROM ( ) ) WHERE changed = 0; + +SELECT arrayJoin(arrayMap(x -> x, arraySort(groupArray((ts, n))))) AS k FROM ( + SELECT ts, n, z FROM system.one ARRAY JOIN [1, 3, 4, 5, 6] AS ts, [1, 2, 2, 2, 1] AS n, ['a', 'a', 'b', 'a', 'b'] AS z + ORDER BY n ASC, ts DESC +) WHERE z = 'a' GROUP BY z; + + DROP TABLE IF EXISTS test.test;