github-actions[bot] commented on code in PR #62492:
URL: https://github.com/apache/doris/pull/62492#discussion_r3092921082


##########
regression-test/suites/nereids_rules_p0/mv/join/left_outer/outer_join_two_hop_null_reject.groovy:
##########
@@ -0,0 +1,138 @@
+// 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("outer_join_two_hop_null_reject") {
+    String db = context.config.getDbNameByFile(context.file)
+    sql "use ${db}"
+    sql "set runtime_filter_mode=OFF"
+    sql "set enable_nereids_planner=true"
+    sql "set enable_fallback_to_original_planner=false"
+    sql "set enable_materialized_view_rewrite=true"
+    sql "set enable_nereids_timeout=false"
+
+    sql """drop table if exists fact_orders_2hop"""
+    sql """drop table if exists dim_stores_2hop"""
+    sql """drop table if exists dim_regions_2hop"""
+
+    sql """
+        CREATE TABLE IF NOT EXISTS fact_orders_2hop (
+          order_date DATE NOT NULL,
+          store_id INT NOT NULL,
+          amount DECIMALV3(10, 2) NOT NULL
+        )
+        DUPLICATE KEY(order_date, store_id)
+        DISTRIBUTED BY HASH(store_id) BUCKETS 1
+        PROPERTIES (
+          "replication_num" = "1"
+        )
+    """
+
+    sql """
+        CREATE TABLE IF NOT EXISTS dim_stores_2hop (
+          id INT NOT NULL,
+          store_name VARCHAR(32) NOT NULL
+        )
+        DUPLICATE KEY(id)
+        DISTRIBUTED BY HASH(id) BUCKETS 1
+        PROPERTIES (
+          "replication_num" = "1"
+        )
+    """
+
+    sql """
+        CREATE TABLE IF NOT EXISTS dim_regions_2hop (
+          store_id INT NOT NULL,
+          region_name VARCHAR(32) NOT NULL
+        )
+        DUPLICATE KEY(store_id)
+        DISTRIBUTED BY HASH(store_id) BUCKETS 1
+        PROPERTIES (
+          "replication_num" = "1"
+        )
+    """
+
+    sql """
+        insert into fact_orders_2hop values
+        ('2024-01-01', 1, 100.00),
+        ('2024-01-01', 2, 200.00),
+        ('2024-01-02', 3, 300.00),
+        ('2024-01-02', 4, 400.00)
+    """
+
+    sql """
+        insert into dim_stores_2hop values
+        (1, 'Store A'),
+        (2, 'Store B'),
+        (3, 'Store C')
+    """
+
+    sql """
+        insert into dim_regions_2hop values
+        (1, 'West'),
+        (2, 'East'),
+        (3, 'West')
+    """
+
+    sql """analyze table fact_orders_2hop with sync"""
+    sql """analyze table dim_stores_2hop with sync"""
+    sql """analyze table dim_regions_2hop with sync"""
+
+    def compare_res = { def stmt ->
+        sql "set enable_materialized_view_rewrite=false"
+        def origin_res = sql stmt
+        logger.info("origin_res: " + origin_res)
+        sql "set enable_materialized_view_rewrite=true"
+        def mv_origin_res = sql stmt
+        logger.info("mv_origin_res: " + mv_origin_res)
+        assertTrue((mv_origin_res == [] && origin_res == []) || 
(mv_origin_res.size() == origin_res.size()))
+        for (int row = 0; row < mv_origin_res.size(); row++) {
+            assertTrue(mv_origin_res[row].size() == origin_res[row].size())
+            for (int col = 0; col < mv_origin_res[row].size(); col++) {
+                assertTrue(mv_origin_res[row][col] == origin_res[row][col])
+            }
+        }
+    }
+
+    def mvName = "mv_orders_2hop_null_reject"
+    def mvSql = """
+        select o.order_date, o.store_id, d.store_name, r.region_name,
+               sum(o.amount) as total_amount
+        from fact_orders_2hop o
+        left join dim_stores_2hop d
+          on o.store_id = d.id
+        left join dim_regions_2hop r
+          on d.id = r.store_id
+        group by o.order_date, o.store_id, d.store_name, r.region_name
+    """
+    def querySql = """
+        select o.order_date, sum(o.amount)
+        from fact_orders_2hop o
+        left join dim_stores_2hop d
+          on o.store_id = d.id
+        left join dim_regions_2hop r
+          on d.id = r.store_id
+        where r.region_name = 'West'
+        group by o.order_date
+        order by 1
+    """
+
+    create_async_mv(db, mvName, mvSql)
+    mv_rewrite_success_without_check_chosen(querySql, mvName)

Review Comment:
   This new regression is supposed to guard the end-to-end rewrite, but 
`mv_rewrite_success_without_check_chosen(...)` also passes when the memo plan 
says `.mv_orders_2hop_null_reject not chose`. In that case 
`compare_res(querySql)` can still go green because both executions read the 
base tables. Can we tighten this to `mv_rewrite_success(...)` (or otherwise 
assert the MV is actually chosen), so the test really exercises the fixed 
rewrite path?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java:
##########
@@ -871,36 +871,35 @@ private boolean containsNullRejectSlot(Set<Set<Slot>> 
requireNoNullableViewSlot,
             StructInfo queryStructInfo,
             StructInfo viewStructInfo,
             CascadesContext cascadesContext) {
-        Set<Expression> queryPulledUpPredicates = queryPredicates.stream()
-                .flatMap(expr -> 
ExpressionUtils.extractConjunction(expr).stream())
-                .map(expr -> {
-                    // NOTICE inferNotNull generate Not with 
isGeneratedIsNotNull = false,
-                    //  so, we need set this flag to false before comparison.
-                    if (expr instanceof Not) {
-                        return ((Not) expr).withGeneratedIsNotNull(false);
-                    }
-                    return expr;
-                })
-                .collect(Collectors.toSet());
-        Set<Expression> queryNullRejectPredicates =
-                ExpressionUtils.inferNotNull(queryPulledUpPredicates, 
cascadesContext);
-        if (queryPulledUpPredicates.containsAll(queryNullRejectPredicates)) {
-            // Query has no null reject predicates, return
-            return false;
+        Set<Slot> queryNullRejectSlots = new HashSet<>();
+        for (Expression queryPredicate : queryPredicates) {
+            Optional<Slot> explicitNotNullSlot = 
TypeUtils.isNotNull(queryPredicate);
+            explicitNotNullSlot.ifPresent(queryNullRejectSlots::add);
         }
-        // Get query null reject predicate slots
-        Set<Expression> queryNullRejectSlotSet = new HashSet<>();
+        Set<Expression> queryNullRejectPredicates = 
ExpressionUtils.inferNotNull(queryPredicates, cascadesContext);
         for (Expression queryNullRejectPredicate : queryNullRejectPredicates) {
             Optional<Slot> notNullSlot = 
TypeUtils.isNotNull(queryNullRejectPredicate);
-            if (!notNullSlot.isPresent()) {
-                continue;
+            notNullSlot.ifPresent(queryNullRejectSlots::add);
+        }
+        // INNER JOIN conditions guarantee NOT NULL on join-key slots.
+        // After EliminateOuterJoin converts LEFT→INNER, the JoinEdge objects 
in the HyperGraph
+        // retain the INNER type even though EliminateNotNull removes 
filter-level NOT NULL predicates.
+        for (JoinEdge joinEdge : 
queryStructInfo.getHyperGraph().getJoinEdges()) {

Review Comment:
   `containsNullRejectSlot()` now relies on join-edge-derived null-reject 
slots, but this condition only accepts `INNER_JOIN`. That leaves the parallel 
ASOF path unfixed: this rule explicitly supports 
`ASOF_LEFT/RIGHT_{INNER,OUTER}_JOIN`, `EliminateOuterJoin` can convert ASOF 
outer joins to ASOF inner joins, and `HyperGraphComparator` already models that 
inference. In those cases `EliminateNotNull` can still erase the filter-level 
`IS NOT NULL` predicates, and this branch will ignore the surviving ASOF inner 
`JoinEdge` conditions. Please include `isAsofInnerJoin()` here (and add 
coverage) so the bug is fixed consistently for all supported join families.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to