hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1630142 - /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/stats/HiveRelMdSelectivity.java
Date Wed, 08 Oct 2014 15:27:58 GMT
Author: hashutosh
Date: Wed Oct  8 15:27:57 2014
New Revision: 1630142

URL: http://svn.apache.org/r1630142
Log:
HIVE-8315 : CBO : Negate condition underestimates selectivity which results in an in-efficient
plan (Harish Butani via Ashutosh Chauhan)

Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/stats/HiveRelMdSelectivity.java

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/stats/HiveRelMdSelectivity.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/stats/HiveRelMdSelectivity.java?rev=1630142&r1=1630141&r2=1630142&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/stats/HiveRelMdSelectivity.java
(original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/optimizer/optiq/stats/HiveRelMdSelectivity.java
Wed Oct  8 15:27:57 2014
@@ -37,6 +37,7 @@ import org.eigenbase.rel.metadata.RelMet
 import org.eigenbase.rel.metadata.RelMetadataQuery;
 import org.eigenbase.rex.RexNode;
 import org.eigenbase.rex.RexUtil;
+import org.eigenbase.util.Pair;
 
 import com.google.common.collect.ImmutableMap;
 
@@ -67,7 +68,15 @@ public class HiveRelMdSelectivity extend
 
   private Double computeInnerJoinSelectivity(HiveJoinRel j, RexNode predicate) {
     double ndvCrossProduct = 1;
-    RexNode combinedPredicate = getCombinedPredicateForJoin(j, predicate);
+    Pair<Boolean, RexNode> predInfo =
+        getCombinedPredicateForJoin(j, predicate);
+    if (!predInfo.getKey()) {
+      return
+          new FilterSelectivityEstimator(j).
+          estimateSelectivity(predInfo.getValue());
+    }
+
+    RexNode combinedPredicate = predInfo.getValue();
     JoinPredicateInfo jpi = JoinPredicateInfo.constructJoinPredicateInfo(j,
         combinedPredicate);
     ImmutableMap.Builder<Integer, Double> colStatMapBuilder = ImmutableMap
@@ -175,7 +184,14 @@ public class HiveRelMdSelectivity extend
     return ndvCrossProduct;
   }
 
-  private RexNode getCombinedPredicateForJoin(HiveJoinRel j, RexNode additionalPredicate)
{
+  /**
+   * 
+   * @param j
+   * @param additionalPredicate
+   * @return if predicate is the join condition return (true, joinCond)
+   * else return (false, minusPred)
+   */
+  private Pair<Boolean,RexNode> getCombinedPredicateForJoin(HiveJoinRel j, RexNode
additionalPredicate) {
     RexNode minusPred = RelMdUtil.minusPreds(j.getCluster().getRexBuilder(), additionalPredicate,
         j.getCondition());
 
@@ -184,10 +200,10 @@ public class HiveRelMdSelectivity extend
       minusList.add(j.getCondition());
       minusList.add(minusPred);
 
-      return RexUtil.composeConjunction(j.getCluster().getRexBuilder(), minusList, true);
+      return new Pair<Boolean,RexNode>(false, minusPred);
     }
 
-    return j.getCondition();
+    return new Pair<Boolean,RexNode>(true,j.getCondition());
   }
 
   /**



Mime
View raw message