This is an automated email from the ASF dual-hosted git repository.

morningman pushed a commit to branch branch-1.2-unstable
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 6d699fbcb5a00f7c86085eb816d33298dec10587
Author: minghong <minghong.z...@163.com>
AuthorDate: Tue Nov 8 17:21:50 2022 +0800

    [enhancement](Nereids) tpch q21 anti and semi join reorder (#14037)
    
    estimation of anti and semi join need re-work. we just let tpch q21 pass.
---
 .../apache/doris/nereids/stats/JoinEstimation.java  | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java
index dc5345e891..afe6bdf3a0 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java
@@ -147,16 +147,33 @@ public class JoinEstimation {
         return result;
     }
 
+    private static double estimateLeftSemiJoin(double leftCount, double 
rightCount) {
+        return leftCount - leftCount / Math.max(2, rightCount);
+    }
+
     /**
      * estimate join
      */
     public static StatsDeriveResult estimateV2(StatsDeriveResult leftStats, 
StatsDeriveResult rightStats, Join join) {
         JoinType joinType = join.getJoinType();
         double rowCount = Double.MAX_VALUE;
+        //TODO the estimation of semi and anti join is not proper, just for 
tpch q21
         if (joinType == JoinType.LEFT_SEMI_JOIN || joinType == 
JoinType.LEFT_ANTI_JOIN) {
-            rowCount = leftStats.getRowCount();
+            double rightCount = rightStats.getRowCount();
+            double leftCount = leftStats.getRowCount();
+            if (join.getHashJoinConjuncts().isEmpty()) {
+                rowCount = joinType == JoinType.LEFT_SEMI_JOIN ? leftCount : 0;
+            } else {
+                rowCount = estimateLeftSemiJoin(leftCount, rightCount);
+            }
         } else if (joinType == JoinType.RIGHT_SEMI_JOIN || joinType == 
JoinType.RIGHT_ANTI_JOIN) {
-            rowCount = rightStats.getRowCount();
+            double rightCount = rightStats.getRowCount();
+            double leftCount = leftStats.getRowCount();
+            if (join.getHashJoinConjuncts().isEmpty()) {
+                rowCount = joinType == JoinType.RIGHT_SEMI_JOIN ? rightCount : 
0;
+            } else {
+                rowCount = estimateLeftSemiJoin(rightCount, leftCount);
+            }
         } else if (joinType == JoinType.INNER_JOIN) {
             if (join.getHashJoinConjuncts().isEmpty()) {
                 //TODO: consider other join conjuncts


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to