From 532d72a7d8b74eeb1608f103e8540a7b7deb1294 Mon Sep 17 00:00:00 2001 From: liuneng <1398775315@qq.com> Date: Tue, 19 Mar 2024 17:30:16 +0800 Subject: [PATCH] add test case --- ...qualsPass.cpp => ConvertInToEqualPass.cpp} | 10 ++--- ...nToEqualsPass.h => ConvertInToEqualPass.h} | 4 +- src/Analyzer/QueryTreePassManager.cpp | 4 +- tests/performance/function_in.xml | 30 +++++++++++++++ .../03013_optimize_in_to_equal.reference | 37 +++++++++++++++++++ .../03013_optimize_in_to_equal.sql | 10 +++++ 6 files changed, 86 insertions(+), 9 deletions(-) rename src/Analyzer/Passes/{ConvertInToEqualsPass.cpp => ConvertInToEqualPass.cpp} (84%) rename src/Analyzer/Passes/{ConvertInToEqualsPass.h => ConvertInToEqualPass.h} (75%) create mode 100644 tests/performance/function_in.xml create mode 100644 tests/queries/0_stateless/03013_optimize_in_to_equal.reference create mode 100644 tests/queries/0_stateless/03013_optimize_in_to_equal.sql diff --git a/src/Analyzer/Passes/ConvertInToEqualsPass.cpp b/src/Analyzer/Passes/ConvertInToEqualPass.cpp similarity index 84% rename from src/Analyzer/Passes/ConvertInToEqualsPass.cpp rename to src/Analyzer/Passes/ConvertInToEqualPass.cpp index cf9f1dd6ad13..26db3a4f4aa0 100644 --- a/src/Analyzer/Passes/ConvertInToEqualsPass.cpp +++ b/src/Analyzer/Passes/ConvertInToEqualPass.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -11,10 +11,10 @@ namespace DB using FunctionEquals = FunctionComparison; -class ConvertInToEqualsPassVisitor : public InDepthQueryTreeVisitorWithContext +class ConvertInToEqualPassVisitor : public InDepthQueryTreeVisitorWithContext { public: - using Base = InDepthQueryTreeVisitorWithContext; + using Base = InDepthQueryTreeVisitorWithContext; using Base::Base; FunctionOverloadResolverPtr createInternalFunctionEqualOverloadResolver() @@ -47,9 +47,9 @@ class ConvertInToEqualsPassVisitor : public InDepthQueryTreeVisitorWithContext #include #include -#include +#include #include #include #include @@ -264,7 +264,7 @@ void addQueryTreePasses(QueryTreePassManager & manager, bool only_analyze) manager.addPass(std::make_unique()); manager.addPass(std::make_unique()); manager.addPass(std::make_unique()); - manager.addPass(std::make_unique()); + manager.addPass(std::make_unique()); /// should before AggregateFunctionsArithmericOperationsPass manager.addPass(std::make_unique()); diff --git a/tests/performance/function_in.xml b/tests/performance/function_in.xml new file mode 100644 index 000000000000..16e6bb91469f --- /dev/null +++ b/tests/performance/function_in.xml @@ -0,0 +1,30 @@ + + + 8 + 1 + + + + CREATE TABLE t_nullable + ( + key_string1 Nullable(String), + key_string2 Nullable(String), + key_string3 Nullable(String), + key_int64_1 Nullable(Int64), + key_int64_2 Nullable(Int64), + key_int64_3 Nullable(Int64), + key_int64_4 Nullable(Int64), + key_int64_5 Nullable(Int64), + m1 Int64, + m2 Int64 + ) + ENGINE = Memory + + insert into t_nullable select ['aaaaaa','bbaaaa','ccaaaa','ddaaaa'][number % 101 + 1], ['aa','bb','cc','dd'][number % 100 + 1], ['aa','bb','cc','dd'][number % 102 + 1], number%10+1, number%10+2, number%10+3, number%10+4,number%10+5, number%6000+1, number%5000+2 from numbers_mt(30000000) + select * from t_nullable where key_string1 in ('aaaaaa') format Null + select * from t_nullable where key_string1 in ('aaaaaa') format Null SETTINGS allow_experimental_analyzer=1 + select * from t_nullable where key_string2 in ('3') format Null + select * from t_nullable where key_string2 in ('3') format Null SETTINGS allow_experimental_analyzer=1 + drop table if exists t_nullable + + \ No newline at end of file diff --git a/tests/queries/0_stateless/03013_optimize_in_to_equal.reference b/tests/queries/0_stateless/03013_optimize_in_to_equal.reference new file mode 100644 index 000000000000..f55a7b76eaff --- /dev/null +++ b/tests/queries/0_stateless/03013_optimize_in_to_equal.reference @@ -0,0 +1,37 @@ +a 1 +------------------- +QUERY id: 0 + PROJECTION COLUMNS + x String + y Int32 + PROJECTION + LIST id: 1, nodes: 2 + COLUMN id: 2, column_name: x, result_type: String, source_id: 3 + COLUMN id: 4, column_name: y, result_type: Int32, source_id: 3 + JOIN TREE + TABLE id: 3, alias: __table1, table_name: default.test + WHERE + FUNCTION id: 5, function_name: equals, function_type: ordinary, result_type: UInt8 + ARGUMENTS + LIST id: 6, nodes: 2 + COLUMN id: 7, column_name: x, result_type: String, source_id: 3 + CONSTANT id: 8, constant_value: \'a\', constant_value_type: String + SETTINGS allow_experimental_analyzer=1 +------------------- +QUERY id: 0 + PROJECTION COLUMNS + x String + y Int32 + PROJECTION + LIST id: 1, nodes: 2 + COLUMN id: 2, column_name: x, result_type: String, source_id: 3 + COLUMN id: 4, column_name: y, result_type: Int32, source_id: 3 + JOIN TREE + TABLE id: 3, alias: __table1, table_name: default.test + WHERE + FUNCTION id: 5, function_name: in, function_type: ordinary, result_type: UInt8 + ARGUMENTS + LIST id: 6, nodes: 2 + COLUMN id: 7, column_name: x, result_type: String, source_id: 3 + CONSTANT id: 8, constant_value: Tuple_(\'a\', \'b\'), constant_value_type: Tuple(String, String) + SETTINGS allow_experimental_analyzer=1 diff --git a/tests/queries/0_stateless/03013_optimize_in_to_equal.sql b/tests/queries/0_stateless/03013_optimize_in_to_equal.sql new file mode 100644 index 000000000000..9d80825ceb46 --- /dev/null +++ b/tests/queries/0_stateless/03013_optimize_in_to_equal.sql @@ -0,0 +1,10 @@ +DROP TABLE IF EXISTS test; +CREATE TABLE test (x String, y Int32) ENGINE = MergeTree() ORDER BY x; + +INSERT INTO test VALUES ('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5); + +select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1; +select '-------------------'; +explain query tree select * from test where x in ('a') SETTINGS allow_experimental_analyzer = 1; +select '-------------------'; +explain query tree select * from test where x in ('a','b') SETTINGS allow_experimental_analyzer = 1; \ No newline at end of file