konstantinb commented on code in PR #6505:
URL: https://github.com/apache/hive/pull/6505#discussion_r4702202691


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java:
##########
@@ -1519,14 +1537,12 @@ public Object process(Node nd, Stack<Node> stack, 
NodeProcessorCtx procCtx,
         // compute product of distinct values of grouping columns
         long ndvProduct =
             StatsUtils.computeNDVGroupingColumns(colStats, parentStats, false);
-        // if ndvProduct is 0 then column stats state must be partial and we 
are missing
-        // column stats for a group by column
-        if (ndvProduct == 0) {
+        if (ndvProduct < 0) {

Review Comment:
   Good catch on the helper itself: `safeMult` and `safeAdd` (from HIVE-8689) 
turn every overflow into `Long.MAX_VALUE`, so a negative overflow saturates the 
wrong way. It can't happen here: `computeNDVGroupingColumns` returns -1 as soon 
as a key's NDV is unknown, before multiplying, so `safeMult` only sees 
non-negative operands and `ndvProduct < 0` still means only "unknown". The 
other callers combine row counts, data sizes, NDVs and null counts, which are 
non-negative, and for such quantities `MAX_VALUE` on any overflow matches the 
convention of `StatsUtils.getMaxIfOverflow`. `LongMath.saturatedMultiply` would 
instead return `Long.MIN_VALUE` where an operand has already wrapped negative, 
for example the `1L << 63` slot count in 
`ConvertJoinMapJoin.computeOnlineDataSizeGeneric` for very large row counts, 
which would make the hash table look tiny. So I'd rather keep it out of this 
PR; I can open a follow-up to document the non-negative contract.
   



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