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


##########
flink-table/flink-table-planner/src/test/resources/org/apache/flink/table/planner/plan/batch/sql/SetOperatorsTest.xml:
##########
@@ -119,6 +120,32 @@ LogicalIntersect(all=[false])
     <Resource name="optimized exec plan">
       <![CDATA[
 Values(tuples=[[]], values=[c])
+]]>
+    </Resource>
+  </TestCase>
+  <TestCase name="testIntersectRightInputWithDuplicates">
+    <Resource name="sql">
+      <![CDATA[SELECT s_suppkey FROM supplier INTERSECT SELECT ps_suppkey FROM 
partsupp]]>
+    </Resource>
+    <Resource name="ast">
+      <![CDATA[
+LogicalIntersect(all=[false])
+:- LogicalProject(s_suppkey=[$0])
+:  +- LogicalTableScan(table=[[default_catalog, default_database, supplier, 
source: [TestTableSource(s_suppkey)]]])
++- LogicalProject(ps_suppkey=[$0])
+   +- LogicalTableScan(table=[[default_catalog, default_database, partsupp, 
source: [TestTableSource(ps_suppkey)]]])
+]]>
+    </Resource>
+    <Resource name="optimized exec plan">
+      <![CDATA[
+HashAggregate(isMerge=[false], groupBy=[s_suppkey], select=[s_suppkey])
++- Exchange(distribution=[keep_input_as_is[hash[s_suppkey]]])
+   +- MultipleInput(members=[\nSortMergeJoin(joinType=[LeftSemiJoin], 
where=[IS NOT DISTINCT FROM(s_suppkey, ps_suppkey)], select=[s_suppkey])\n:- 
[#1] Exchange(distribution=[hash[s_suppkey]])\n+- HashAggregate(isMerge=[true], 
groupBy=[ps_suppkey], select=[ps_suppkey])\n   +- [#2] 
Exchange(distribution=[hash[ps_suppkey]])\n])

Review Comment:
   Hash join and sort-merge join compare DOUBLE NaN and -0.0 differently (the 
latter is FLINK-40945), so moving this join changes INTERSECT/EXCEPT results 
for those values. The commit message says they stay the same.



##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/rules/logical/ReplaceIntersectWithSemiJoinRule.java:
##########
@@ -71,6 +86,9 @@ public void onMatch(RelOptRuleCall call) {
 
         relBuilder.push(left);
         relBuilder.push(right);
+        if (config.isDistinctRightInput()) {
+            relBuilder.distinct();

Review Comment:
   The base plan of `testIntersectRightInputWithDuplicates` already dedupes the 
right input locally (`chooseSemiBuildDistinct`) and only builds on the left 
because it sizes the raw input. I think the fix belongs there.



##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/plan/rules/FlinkBatchRuleSets.scala:
##########
@@ -329,9 +329,9 @@ object FlinkBatchRuleSets {
     FlinkSemiAntiJoinFilterTransposeRule.INSTANCE,
 
     // set operators
-    ReplaceIntersectWithSemiJoinRule.INSTANCE,
+    ReplaceIntersectWithSemiJoinRule.BATCH_INSTANCE,

Review Comment:
   Without stats or a unique key this puts a two-phase aggregate on every batch 
INTERSECT/EXCEPT, and the join loses its `AdaptiveJoin` (the right input is no 
longer a hash exchange). Is that intended?



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