LuciferYang commented on code in PR #60168:
URL: https://github.com/apache/spark/pull/60168#discussion_r4573167249


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/JoinEstimation.scala:
##########
@@ -196,16 +196,22 @@ case class JoinEstimation(join: Join) extends Logging {
       // Check if the two sides are disjoint
       val leftKeyStat = leftStats.attributeStats(leftKey)
       val rightKeyStat = rightStats.attributeStats(rightKey)
-      val lInterval = ValueInterval(leftKeyStat.min, leftKeyStat.max, 
leftKey.dataType)
-      val rInterval = ValueInterval(rightKeyStat.min, rightKeyStat.max, 
rightKey.dataType)
+      val lInterval = keyInterval(leftKey, leftKeyStat)
+      val rInterval = keyInterval(rightKey, rightKeyStat)
       // A distinct count of 0 on both sides means neither has a non-null key 
value.
       val noValues = leftKeyStat.distinctCount.contains(BigInt(0)) &&
         rightKeyStat.distinctCount.contains(BigInt(0))
       if (!noValues && ValueInterval.isIntersected(lInterval, rInterval)) {
         val (newMin, newMax) = ValueInterval.intersect(lInterval, rInterval, 
leftKey.dataType)
+        // If only one key has a known range, the joined keys take it. The 
histogram of the other
+        // key may not cover that range, so it is neither used nor propagated.
+        def keepsHistogram(interval: ValueInterval): Boolean =
+          newMin.isEmpty || interval.isInstanceOf[NumericValueInterval]
         val (card, joinStat) = (leftKeyStat.histogram, rightKeyStat.histogram) 
match {
+          // Histograms are trimmed to the intersected range, so both keys 
need a known range.
           case (Some(l: Histogram), Some(r: Histogram))
-              if canEstimateWithHistogram(leftKey.dataType) =>
+              if canEstimateWithHistogram(leftKey.dataType) && 
newMin.isDefined &&

Review Comment:
   Done in 0794944416e: the guard now checks that both keys have a known range.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/statsEstimation/JoinEstimation.scala:
##########
@@ -214,8 +220,10 @@ case class JoinEstimation(join: Join) extends Logging {
           // Histograms are propagated as unchanged. During future estimation, 
they should be

Review Comment:
   Done in 0794944416e: the two comments are merged into one above the 
propagation.



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