konstantinb commented on code in PR #6505:
URL: https://github.com/apache/hive/pull/6505#discussion_r4701709158
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/stats/annotation/StatsRulesProcFactory.java:
##########
@@ -1820,9 +1835,24 @@ private boolean checkMapSideAggregation(GroupByOperator
gop,
// estimate size of key from column statistics
long avgKeySize = 0;
+ // lazily computed on first unknown NDV (null = not yet looked up)
+ Long parentNumRows = null;
for (ColStatistics cs : colStats) {
if (cs != null) {
- numEstimatedRows = StatsUtils.safeMult(numEstimatedRows,
cs.getCountDistint());
+ long ndv = cs.getCountDistint();
+ if (ndv < 0) {
+ if (parentNumRows == null) {
+ // unknown NDV: fall back to parentNumRows / 2, matching the
heuristic
+ // used elsewhere in this file when GROUP BY cardinality
cannot be computed
+ Statistics parentStats =
gop.getParentOperators().get(0).getStatistics();
+ parentNumRows = (parentStats != null) ?
parentStats.getNumRows() : -1L;
+ }
+ if (parentNumRows <= 0) {
+ return false;
+ }
+ ndv = parentNumRows / 2;
+ }
+ numEstimatedRows = StatsUtils.safeMult(numEstimatedRows, ndv);
Review Comment:
Update: after a later review question
([r4675031550](https://github.com/apache/hive/pull/6505#discussion_r4675031550)),
[a90be13](https://github.com/apache/hive/pull/6505/commits/a90be13412)
replaces the master-parity guard described above. The table is now sized once
with the GROUP BY's grouping cardinality, so the per-key `parentNumRows / 2`
inflation does not return, but an unknown key on a large input can now take the
no-hash-aggregation branch, unlike master. Grouping-set expansion is still not
counted in the memory check, as on master.
--
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]