MartijnVisser commented on code in PR #30038:
URL: https://github.com/apache/flink/pull/30038#discussion_r4641668924


##########
flink-table/flink-table-planner/src/test/scala/org/apache/flink/table/planner/plan/stream/sql/join/SemiAntiJoinTest.scala:
##########
@@ -573,4 +574,34 @@ class SemiAntiJoinTest extends TableTestBase {
       " AND NOT EXISTS (SELECT * FROM r WHERE l.b <> r.e)"
     util.verifyExecPlan(sqlQuery)
   }
+
+  @Test
+  def testNullAwareNotInStaysAboveJoin(): Unit = {
+    // A null-aware NOT IN over nullable columns becomes an anti join on
+    // (a = b) OR ((a = b) IS NULL), which has no equi-join keys.
+    SemiAntiJoinTestStats.addTables(util)
+    val sqlQuery =
+      """
+        |SELECT p_brand, ps_suppkey FROM partsupp, part
+        |WHERE p_partkey = ps_partkey AND p_brand <> 'Brand#45'
+        |AND ps_suppkey NOT IN (
+        |    SELECT s_suppkey FROM supplier WHERE s_comment LIKE 
'%Complaints%')
+        |""".stripMargin
+    util.verifyRelPlan(sqlQuery)
+  }
+
+  @Test
+  def testNonEquiExistsStaysAboveJoin(): Unit = {

Review Comment:
   I think the stream test needs `testEquiExistsPushedBelowJoin` too: with 
every SEMI/ANTI join costed as `L*R`, the stream tests still pass.



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/plan/common/SemiAntiJoinTestStats.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.
+ */
+
+package org.apache.flink.table.planner.plan.common;
+
+import org.apache.flink.api.common.typeinfo.BasicTypeInfo;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.table.plan.stats.ColumnStats;
+import org.apache.flink.table.plan.stats.TableStats;
+import org.apache.flink.table.planner.plan.stats.FlinkStatistic;
+import org.apache.flink.table.planner.utils.TableTestUtil;
+
+import java.util.Map;
+
+/**
+ * Tables modeled on TPC-H q16: partsupp, part and supplier. The key columns 
carry NDVs, so the

Review Comment:
   Master already plans q16 right on SF10 when all columns have stats. I only 
see the pushdown with key NDVs but no filter column stats, as here. Was that 
your SF1000 setup?



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/nodes/logical/FlinkLogicalJoin.scala:
##########
@@ -66,7 +66,12 @@ class FlinkLogicalJoin(
       case JoinRelType.SEMI | JoinRelType.ANTI =>
         val rightRowSize = mq.getAverageRowSize(getRight)
         val ioCost = (leftRowCnt * leftRowSize) + (rightRowCnt * rightRowSize)
-        val cpuCost = leftRowCnt + rightRowCnt
+        // without equi-join keys, every left row is compared with every right 
row
+        val cpuCost = if (analyzeCondition().leftKeys.isEmpty) {

Review Comment:
   A streaming job with catalog stats and such a join gets a new topology: its 
savepoint from master doesn't restore on this branch without a compiled plan. I 
think FLINK-41523 needs a release note.



-- 
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]

Reply via email to