diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggScalarSubQueryToWindowFunction.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggScalarSubQueryToWindowFunction.java index 0dc9832638..ce93d25cb9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggScalarSubQueryToWindowFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggScalarSubQueryToWindowFunction.java @@ -67,7 +67,7 @@ import java.util.stream.Collectors; * change the plan: * logicalFilter(logicalApply(any(), logicalAggregate())) * to - * logicalProject((logicalFilter(logicalWindow(logicalFilter(any()))))) + * logicalProject(logicalFilter(logicalWindow(logicalFilter(any())))) *

* refer paper: WinMagic - Subquery Elimination Using Window Aggregation *

diff --git a/regression-test/data/nereids_rules_p0/eliminate_not_null/eliminate_not_null.out b/regression-test/data/nereids_rules_p0/eliminate_not_null/eliminate_not_null.out new file mode 100644 index 0000000000..a02974e6cc --- /dev/null +++ b/regression-test/data/nereids_rules_p0/eliminate_not_null/eliminate_not_null.out @@ -0,0 +1,70 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !eliminate_not_null_basic_comparison -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not score IS NULL) and (t.score > 13)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_in_clause -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not id IS NULL) and id IN (1, 2, 3)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_not_equal -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not (score = 13)) and ( not score IS NULL)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_string_function -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not name IS NULL) and (length(name) > 0)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_aggregate -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashAgg[LOCAL] +--------PhysicalProject +----------filter(( not score IS NULL) and (t.score > 0)) +------------PhysicalOlapScan[t] + +-- !eliminate_not_null_between -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not score IS NULL) and (t.score <= 10) and (t.score >= 1)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_math_function -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not score IS NULL) and (abs(score) = 5)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_complex_logic -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not score IS NULL) and ((t.score > 5) OR (t.id < 10))) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_date_function -- +PhysicalResultSink +--PhysicalDistribute +----filter(( not name IS NULL) and (year(cast(name as DATEV2)) = 2022)) +------PhysicalOlapScan[t] + +-- !eliminate_not_null_with_subquery -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_SEMI_JOIN] hashCondition=((t.score = t.score)) otherCondition=() build RFs:RF0 score->[score] +--------filter(( not score IS NULL) and (t.score > 0)) +----------PhysicalOlapScan[t] apply RFs: RF0 +--------PhysicalDistribute +----------PhysicalProject +------------filter((t.score > 0)) +--------------PhysicalOlapScan[t] + diff --git a/regression-test/data/nereids_rules_p0/eliminate_outer_join/eliminate_outer_join.out b/regression-test/data/nereids_rules_p0/eliminate_outer_join/eliminate_outer_join.out new file mode 100644 index 0000000000..3211d71aa2 --- /dev/null +++ b/regression-test/data/nereids_rules_p0/eliminate_outer_join/eliminate_outer_join.out @@ -0,0 +1,303 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !left_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t2.score > 10)) +----------PhysicalOlapScan[t] + +-- !right_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] + +-- !full_outer_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] + +-- !full_outer_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t2.score > 10)) +----------PhysicalOlapScan[t] + +-- !full_outer_join -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t2.score > 10)) +----------PhysicalOlapScan[t] + +-- !left_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t2.score > 10)) +----------PhysicalOlapScan[t] + +-- !multiple_left_outer_1 -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() +--------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 +----------filter((t1.score > 10)) +------------PhysicalOlapScan[t] +--------PhysicalOlapScan[t] + +-- !multiple_left_outer_2 -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() +--------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 +----------filter((t2.score > 10)) +------------PhysicalOlapScan[t] +--------PhysicalOlapScan[t] + +-- !multiple_right_outer_1 -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() build RFs:RF1 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF1 +--------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 +----------filter((t1.score > 10)) +------------PhysicalOlapScan[t] + +-- !multiple_right_outer_2 -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() build RFs:RF1 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF1 +--------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 +----------filter((t2.score > 10)) +------------PhysicalOlapScan[t] + +-- !multiple_full_outer_1 -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() +--------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 +----------filter((t1.score > 10)) +------------PhysicalOlapScan[t] +--------PhysicalOlapScan[t] + +-- !multiple_full_outer_2 -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() +--------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 +----------filter((t2.score > 10)) +------------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalOlapScan[t] + +-- !left_outer_join_non_null_assertion -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter(( not id IS NULL) and (t1.score > 5)) +----------PhysicalOlapScan[t] + +-- !right_outer_join_non_null_assertion -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[RIGHT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter(( not id IS NULL) and (t2.score > 5)) +----------PhysicalOlapScan[t] + +-- !full_outer_join_compound_conditions -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------filter(((t1.score > 5) OR (t2.score > 5))) +--------hashJoin[FULL_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +----------PhysicalOlapScan[t] +----------PhysicalOlapScan[t] + +-- !multiple_joins_complex_conditions -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t2.id = t3.id)) otherCondition=() build RFs:RF1 id->[id] +--------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +----------PhysicalOlapScan[t] apply RFs: RF0 RF1 +----------filter((t1.score > 5)) +------------PhysicalOlapScan[t] +--------filter(( not score IS NULL)) +----------PhysicalOlapScan[t] + +-- !using_non_equijoin_conditions -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_OUTER_JOIN] hashCondition=((expr_cast(score as BIGINT) = expr_(score + 10))) otherCondition=() +--------PhysicalProject +----------filter(( not id IS NULL)) +------------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !joining_multiple_tables_with_aggregate_functions -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------filter((count(id) > 1)) +--------hashAgg[LOCAL] +----------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +------------PhysicalProject +--------------PhysicalOlapScan[t] +------------PhysicalProject +--------------PhysicalOlapScan[t] + +-- !using_subqueries -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +--------filter(( not id IS NULL)) +----------PhysicalOlapScan[t] +--------PhysicalProject +----------PhysicalOlapScan[t] + +-- !left_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------filter(( not name IS NULL)) +----------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] + +-- !right_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------filter(( not name IS NULL)) +----------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] + +-- !full_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------filter(( not name IS NULL)) +----------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t1.score > 10)) +----------PhysicalOlapScan[t] + +-- !self_left_outer -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t1_alias.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter((t1_alias.name > '2023-01-01')) +----------PhysicalOlapScan[t] + +-- !right_outer_aggregate -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[LOCAL] +------PhysicalProject +--------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +----------PhysicalProject +------------PhysicalOlapScan[t] +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !full_outer_multiple_tables -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------filter(name IS NULL) +--------hashJoin[FULL_OUTER_JOIN] hashCondition=((t1.id = t3.id)) otherCondition=() +----------PhysicalDistribute +------------hashJoin[FULL_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +--------------PhysicalOlapScan[t] +--------------PhysicalOlapScan[t] +----------PhysicalDistribute +------------PhysicalOlapScan[t] + +-- !left_outer_with_subquery -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------PhysicalProject +----------filter((t2.score > 20)) +------------PhysicalOlapScan[t] + +-- !complex_join_conditions -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((expr_cast(score as BIGINT) = expr_(score * 2))) otherCondition=((t1.id < t2.id)) +--------PhysicalProject +----------PhysicalOlapScan[t] +--------PhysicalDistribute +----------PhysicalProject +------------PhysicalOlapScan[t] + +-- !multiple_outer_with_window_function -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------PhysicalWindow +--------PhysicalQuickSort[LOCAL_SORT] +----------PhysicalDistribute +------------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +--------------PhysicalProject +----------------PhysicalOlapScan[t] +--------------PhysicalProject +----------------PhysicalOlapScan[t] + +-- !join_different_tables_non_null -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalProject +------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() build RFs:RF0 id->[id] +--------PhysicalOlapScan[t] apply RFs: RF0 +--------filter(( not name IS NULL)) +----------PhysicalOlapScan[t] + diff --git a/regression-test/data/nereids_rules_p0/infer_set_operator_distinct/infer_set_operator_distinct.out b/regression-test/data/nereids_rules_p0/infer_set_operator_distinct/infer_set_operator_distinct.out new file mode 100644 index 0000000000..ecd234e1fc --- /dev/null +++ b/regression-test/data/nereids_rules_p0/infer_set_operator_distinct/infer_set_operator_distinct.out @@ -0,0 +1,334 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !union_distinct -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------PhysicalOlapScan[t2] + +-- !union_complex_conditions -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------filter((t1.score > 10)) +----------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------filter((t2.name = 'Test')) +----------------PhysicalOlapScan[t2] + +-- !multi_union -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !except_distinct -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalExcept +------PhysicalDistribute +--------PhysicalOlapScan[t1] +------PhysicalDistribute +--------PhysicalOlapScan[t2] + +-- !except_with_filter -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalExcept +------PhysicalDistribute +--------filter((t1.id > 100)) +----------PhysicalOlapScan[t1] +------PhysicalDistribute +--------filter((t2.id < 50)) +----------PhysicalOlapScan[t2] + +-- !intersect_distinct -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalIntersect +------PhysicalDistribute +--------PhysicalOlapScan[t1] +------PhysicalDistribute +--------PhysicalOlapScan[t2] + +-- !intersect_with_aggregate -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalIntersect +------PhysicalDistribute +--------hashAgg[GLOBAL] +----------PhysicalDistribute +------------hashAgg[LOCAL] +--------------PhysicalProject +----------------PhysicalOlapScan[t1] +------PhysicalDistribute +--------PhysicalProject +----------hashAgg[GLOBAL] +------------PhysicalDistribute +--------------hashAgg[LOCAL] +----------------PhysicalProject +------------------PhysicalOlapScan[t2] + +-- !mixed_set_operators -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalIntersect +------PhysicalExcept +--------hashAgg[GLOBAL] +----------PhysicalDistribute +------------hashAgg[LOCAL] +--------------PhysicalUnion +----------------PhysicalDistribute +------------------PhysicalOlapScan[t1] +----------------PhysicalDistribute +------------------PhysicalOlapScan[t2] +--------PhysicalDistribute +----------PhysicalOlapScan[t3] +------PhysicalDistribute +--------PhysicalOlapScan[t4] + +-- !join_with_union -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalProject +----------------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +------------------PhysicalOlapScan[t1] +------------------PhysicalDistribute +--------------------PhysicalProject +----------------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !set_operator_with_subquery -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------filter((t1.score > 10)) +----------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------filter((t2.score < 5)) +----------------PhysicalOlapScan[t2] + +-- !nested_union -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] +------------PhysicalDistribute +--------------PhysicalOlapScan[t4] + +-- !union_order_limit -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------PhysicalTopN[MERGE_SORT] +----------------PhysicalDistribute +------------------PhysicalTopN[LOCAL_SORT] +--------------------PhysicalOlapScan[t2] + +-- !union_inner_join_combination -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalProject +----------------hashJoin[INNER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +------------------PhysicalOlapScan[t1] +------------------PhysicalDistribute +--------------------PhysicalProject +----------------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !union_left_join_combination -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalProject +----------------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +------------------PhysicalOlapScan[t1] +------------------PhysicalDistribute +--------------------PhysicalProject +----------------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !union_right_join_combination -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalProject +----------------hashJoin[LEFT_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +------------------PhysicalProject +--------------------PhysicalOlapScan[t2] +------------------PhysicalDistribute +--------------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !union_full_join_combination -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalProject +--------------hashJoin[FULL_OUTER_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +----------------PhysicalDistribute +------------------PhysicalOlapScan[t1] +----------------PhysicalDistribute +------------------PhysicalProject +--------------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !union_left_semi_join_combination -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------hashJoin[LEFT_SEMI_JOIN] hashCondition=((t1.id = t2.id)) otherCondition=() +----------------PhysicalOlapScan[t1] +----------------PhysicalDistribute +------------------PhysicalProject +--------------------PhysicalOlapScan[t2] +------------PhysicalDistribute +--------------PhysicalOlapScan[t3] + +-- !except_with_subquery -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalExcept +------PhysicalDistribute +--------PhysicalOlapScan[t1] +------PhysicalDistribute +--------filter((t2.score > 10)) +----------PhysicalOlapScan[t2] + +-- !intersect_different_types -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalIntersect +------PhysicalDistribute +--------PhysicalProject +----------PhysicalOlapScan[t1] +------PhysicalDistribute +--------PhysicalProject +----------PhysicalOlapScan[t2] + +-- !union_complex_aggregate -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------hashAgg[GLOBAL] +----------------PhysicalDistribute +------------------hashAgg[LOCAL] +--------------------PhysicalProject +----------------------filter((t1.id > 100)) +------------------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------hashAgg[GLOBAL] +----------------PhysicalDistribute +------------------hashAgg[LOCAL] +--------------------PhysicalProject +----------------------filter((t2.id < 50)) +------------------------PhysicalOlapScan[t2] + +-- !union_all_distinct -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalUnion +------PhysicalDistribute +--------PhysicalOlapScan[t1] +------PhysicalDistribute +--------PhysicalOlapScan[t2] + +-- !except_complex_subquery -- +PhysicalResultSink +--PhysicalDistribute +----PhysicalExcept +------PhysicalDistribute +--------PhysicalProject +----------PhysicalOlapScan[t1] +------PhysicalDistribute +--------PhysicalProject +----------filter((t2.score > 20)) +------------PhysicalOlapScan[t2] + +-- !agg_not_output_groupby -- +PhysicalResultSink +--PhysicalDistribute +----hashAgg[GLOBAL] +------PhysicalDistribute +--------hashAgg[LOCAL] +----------PhysicalUnion +------------PhysicalDistribute +--------------PhysicalProject +----------------hashAgg[LOCAL] +------------------PhysicalProject +--------------------PhysicalOlapScan[t1] +------------PhysicalDistribute +--------------PhysicalProject +----------------hashAgg[LOCAL] +------------------PhysicalProject +--------------------PhysicalOlapScan[t2] + diff --git a/regression-test/suites/nereids_rules_p0/eliminate_not_null/eliminate_not_null.groovy b/regression-test/suites/nereids_rules_p0/eliminate_not_null/eliminate_not_null.groovy new file mode 100644 index 0000000000..1b81108ada --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/eliminate_not_null/eliminate_not_null.groovy @@ -0,0 +1,76 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("eliminate_not_null") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql """ + DROP TABLE IF EXISTS t + """ + sql """ + CREATE TABLE IF NOT EXISTS t( + `id` int(32) NULL, + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + qt_eliminate_not_null_basic_comparison """ + explain shape plan select * from t where score > 13 and score is not null; + """ + + qt_eliminate_not_null_in_clause """ + explain shape plan select * from t where id in (1, 2, 3) and id is not null; + """ + + qt_eliminate_not_null_not_equal """ + explain shape plan select * from t where score != 13 and score is not null; + """ + + qt_eliminate_not_null_string_function """ + explain shape plan select * from t where LENGTH(name) > 0 and name is not null; + """ + + qt_eliminate_not_null_aggregate """ + explain shape plan select AVG(score) from t where score > 0 and score is not null group by id; + """ + + qt_eliminate_not_null_between """ + explain shape plan select * from t where score between 1 and 10 and score is not null; + """ + + qt_eliminate_not_null_math_function """ + explain shape plan select * from t where ABS(score) = 5 and score is not null; + """ + + qt_eliminate_not_null_complex_logic """ + explain shape plan select * from t where (score > 5 or id < 10) and score is not null; + """ + + qt_eliminate_not_null_date_function """ + explain shape plan select * from t where YEAR(name) = 2022 and name is not null; + """ + + qt_eliminate_not_null_with_subquery """ + explain shape plan select * from t where score in (select score from t where score > 0) and score is not null; + """ +} diff --git a/regression-test/suites/nereids_rules_p0/eliminate_outer_join/eliminate_outer_join.groovy b/regression-test/suites/nereids_rules_p0/eliminate_outer_join/eliminate_outer_join.groovy new file mode 100644 index 0000000000..b2f5856880 --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/eliminate_outer_join/eliminate_outer_join.groovy @@ -0,0 +1,153 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("eliminate_outer_join") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql """ + DROP TABLE IF EXISTS t + """ + sql """ + CREATE TABLE IF NOT EXISTS t( + `id` int(32) NULL, + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + qt_left_outer """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id where t2.score > 10; + """ + + qt_right_outer """ + explain shape plan select * from t t1 right outer join t t2 on t1.id = t2.id where t1.score > 10; + """ + + qt_full_outer_join """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id where t1.score > 10; + """ + + qt_full_outer_join """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id where t2.score > 10; + """ + + qt_full_outer_join """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id where t1.score > 10 and t2.score > 10; + """ + + qt_left_outer """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id where t1.score > 10 and t2.score > 10; + """ + + qt_multiple_left_outer_1 """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id left join t t3 on t1.id = t3.id where t1.score > 10; + """ + + qt_multiple_left_outer_2 """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id left join t t3 on t1.id = t3.id where t2.score > 10; + """ + + qt_multiple_right_outer_1 """ + explain shape plan select * from t t1 right outer join t t2 on t1.id = t2.id right join t t3 on t1.id = t3.id where t1.score > 10; + """ + + qt_multiple_right_outer_2 """ + explain shape plan select * from t t1 right outer join t t2 on t1.id = t2.id right join t t3 on t1.id = t3.id where t2.score > 10; + """ + + qt_multiple_full_outer_1 """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id full join t t3 on t1.id = t3.id where t1.score > 10; + """ + + qt_multiple_full_outer_2 """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id full join t t3 on t1.id = t3.id where t2.score > 10; + """ + + qt_left_outer_join_non_null_assertion """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id where t1.id is not null and t1.score > 5; + """ + + qt_right_outer_join_non_null_assertion """ + explain shape plan select * from t t1 right outer join t t2 on t1.id = t2.id where t2.id is not null and t2.score > 5; + """ + + qt_full_outer_join_compound_conditions """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id where t1.score > 5 or t2.score > 5; + """ + + qt_multiple_joins_complex_conditions """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id left join t t3 on t2.id = t3.id where t1.score > 5 and t3.score is not null; + """ + + qt_using_non_equijoin_conditions """ + explain shape plan select * from t t1 left outer join t t2 on t1.score = t2.score + 10 where t1.id is not null; + """ + + qt_joining_multiple_tables_with_aggregate_functions """ + explain shape plan select t1.id, max(t2.score) from t t1 left outer join t t2 on t1.id = t2.id group by t1.id having count(t2.id) > 1; + """ + + qt_using_subqueries """ + explain shape plan select * from (select t1.* from t t1 left outer join t t2 on t1.id = t2.id) as sub where sub.id is not null; + """ + + qt_left_outer """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id where t1.score > 10 and t2.name is not null; + """ + + qt_right_outer """ + explain shape plan select * from t t1 right outer join t t2 on t1.id = t2.id where t1.score > 10 and t2.name is not null; + """ + + qt_full_outer """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id where t1.score > 10 and t2.name is not null; + """ + + qt_self_left_outer """ + explain shape plan select * from t t1 left outer join t t1_alias on t1.id = t1_alias.id where t1_alias.name > '2023-01-01'; + """ + + qt_right_outer_aggregate """ + explain shape plan select t2.id, sum(t1.score) from t t1 right outer join t t2 on t1.id = t2.id group by t2.id; + """ + + qt_full_outer_multiple_tables """ + explain shape plan select * from t t1 full outer join t t2 on t1.id = t2.id full join t t3 on t1.id = t3.id where t3.name is null; + """ + + qt_left_outer_with_subquery """ + explain shape plan select * from t t1 left outer join (select id, score from t) as t2 on t1.id = t2.id where t2.score > 20; + """ + + qt_complex_join_conditions """ + explain shape plan select * from t t1 left outer join t t2 on t1.score = t2.score * 2 where t1.id < t2.id; + """ + + qt_multiple_outer_with_window_function """ + explain shape plan select t1.id, rank() over (partition by t2.id order by t1.score) from t t1 left outer join t t2 on t1.id = t2.id; + """ + + qt_join_different_tables_non_null """ + explain shape plan select * from t t1 left outer join t t2 on t1.id = t2.id where t2.name is not null; + """ +} + diff --git a/regression-test/suites/nereids_rules_p0/infer_set_operator_distinct/infer_set_operator_distinct.groovy b/regression-test/suites/nereids_rules_p0/infer_set_operator_distinct/infer_set_operator_distinct.groovy new file mode 100644 index 0000000000..7e27fc9c6d --- /dev/null +++ b/regression-test/suites/nereids_rules_p0/infer_set_operator_distinct/infer_set_operator_distinct.groovy @@ -0,0 +1,171 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +suite("test_infer_set_operator_distinct") { + sql "SET enable_nereids_planner=true" + sql "SET enable_fallback_to_original_planner=false" + + sql """ + DROP TABLE IF EXISTS t1; + """ + sql """ + DROP TABLE IF EXISTS t2; + """ + sql """ + DROP TABLE IF EXISTS t3; + """ + sql """ + DROP TABLE IF EXISTS t4; + """ + + sql """ + CREATE TABLE IF NOT EXISTS t1( + `id` int(32) NULL, + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql """ + CREATE TABLE IF NOT EXISTS t2( + `id` int(32) NULL, + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql """ + CREATE TABLE IF NOT EXISTS t3( + `id` int(32) NULL, + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql """ + CREATE TABLE IF NOT EXISTS t4( + `id` int(32) NULL, + `score` int(64) NULL, + `name` varchar(64) NULL + ) ENGINE = OLAP + DISTRIBUTED BY HASH(id) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + qt_union_distinct """ + explain shape plan select * from t1 union select * from t2; + """ + + qt_union_complex_conditions """ + explain shape plan select * from t1 where t1.score > 10 union select * from t2 where t2.name = 'Test'; + """ + + qt_multi_union """ + explain shape plan select * from t1 union select * from t2 union select * from t3; + """ + + qt_except_distinct """ + explain shape plan select * from t1 except select * from t2; + """ + + qt_except_with_filter """ + explain shape plan select * from t1 where t1.id > 100 except select * from t2 where t2.id < 50; + """ + + qt_intersect_distinct """ + explain shape plan select * from t1 intersect select * from t2; + """ + + qt_intersect_with_aggregate """ + explain shape plan select AVG(t1.score) from t1 intersect select SUM(t2.score) from t2; + """ + + qt_mixed_set_operators """ + explain shape plan select * from t1 union select * from t2 except select * from t3 intersect select * from t4; + """ + + qt_join_with_union """ + explain shape plan select t1.* from t1 join t2 on t1.id = t2.id union select * from t3; + """ + + qt_set_operator_with_subquery """ + explain shape plan select * from (select * from t1 where score > 10) sub1 union select * from (select * from t2 where score < 5) sub2; + """ + + qt_nested_union """ + explain shape plan select * from ((select * from t1 union select * from t2) union (select * from t3 union select * from t4)) sub1; + """ + + qt_union_order_limit """ + explain shape plan select * from t1 union select * from t2 order by id limit 10; + """ + + qt_union_inner_join_combination """ + explain shape plan select t1.* from t1 join t2 on t1.id = t2.id union select * from t3; + """ + + qt_union_left_join_combination """ + explain shape plan select t1.* from t1 left join t2 on t1.id = t2.id union select * from t3; + """ + + qt_union_right_join_combination """ + explain shape plan select t1.* from t1 right join t2 on t1.id = t2.id union select * from t3; + """ + + qt_union_full_join_combination """ + explain shape plan select t1.* from t1 full join t2 on t1.id = t2.id union select * from t3; + """ + + qt_union_left_semi_join_combination """ + explain shape plan select t1.* from t1 left semi join t2 on t1.id = t2.id union select * from t3; + """ + + qt_except_with_subquery """ + explain shape plan select * from t1 except select * from (select * from t2 where score > 10) sub1; + """ + + qt_intersect_different_types """ + explain shape plan select name from t1 intersect select name from t2; + """ + + qt_union_complex_aggregate """ + explain shape plan select MAX(score) from t1 where id > 100 union select MIN(score) from t2 where id < 50; + """ + + qt_union_all_distinct """ + explain shape plan select * from t1 union all select * from t2; + """ + + qt_except_complex_subquery """ + explain shape plan select * from (select id, name from t1) sub1 except select * from (select id, name from t2 where score > 20) sub2; + """ + + qt_agg_not_output_groupby """ + explain shape plan select sum(t1.score) from t1 group by t1.id union select sum(t2.score) from t2 group by t2.id + """ +}