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


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java:
##########
@@ -1822,6 +1842,11 @@ private boolean checkMapSideAggregation(GroupByOperator 
gop,
         long avgKeySize = 0;
         for (ColStatistics cs : colStats) {
           if (cs != null) {
+            if (cs.getCountDistint() < 0) {
+              // unknown NDV: the hash table cannot be sized. Keep the 
decision made when unknown
+              // was stored as 0: an empty estimated table, so only the memory 
budget matters.
+              return maxMemHashAgg > 0;

Review Comment:
   You're right: for an unknown NDV, `return maxMemHashAgg > 0` only reproduced 
what NDV = 0 used to give (an empty estimated table). It was my answer to an 
earlier review comment 
([r4461508408](https://github.com/apache/hive/pull/6505#discussion_r4461508408))
 about applying `parentNumRows / 2` per unknown key. In 
[a90be13](https://github.com/apache/hive/pull/6505/commits/a90be13412), 
`checkMapSideAggregation` sizes the table with the grouping cardinality the 
GROUP BY row estimate already uses (`computeNDVGroupingColumns`, with its 
`parentNumRows / 2` fallback for unknown keys). Unknown keys count once, not 
per key, and a key with NULLs adds the NULL group, so an all-NULL key no longer 
makes the table look empty. Compared with master, estimates can only go up: 
when the table counted this way does not fit in the hash-aggregation memory, 
the map-side GROUP BY is estimated without reduction (rows instead of rows / 
2). With unknown keys and the default memory settings, that happens above
  roughly 6-8 million input rows.
   



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