MCPcopy Create free account
hub / github.com/apache/impala / ShouldExpandPreaggHashTables

Method ShouldExpandPreaggHashTables

be/src/exec/grouping-aggregator.cc:348–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

346}
347
348bool GroupingAggregator::ShouldExpandPreaggHashTables() const {
349 int64_t ht_mem = 0;
350 int64_t ht_rows = 0;
351 for (int i = 0; i < PARTITION_FANOUT; ++i) {
352 HashTable* ht = hash_partitions_[i]->hash_tbl.get();
353 ht_mem += ht->CurrentMemSize();
354 ht_rows += ht->size();
355 }
356
357 // Need some rows in tables to have valid statistics.
358 if (ht_rows == 0) return true;
359
360 // Find the appropriate reduction factor in our table for the current hash table sizes.
361 int cache_level = 0;
362 while (cache_level + 1 < STREAMING_HT_MIN_REDUCTION_SIZE
363 && ht_mem >= STREAMING_HT_MIN_REDUCTION[cache_level + 1].min_ht_mem) {
364 ++cache_level;
365 }
366
367 // Compare the number of rows in the hash table with the number of input rows that
368 // were aggregated into it. Exclude passed through rows from this calculation since
369 // they were not in hash tables.
370 const int64_t aggregated_input_rows = num_input_rows_ - num_rows_returned_;
371 const int64_t expected_input_rows = estimated_input_cardinality_ - num_rows_returned_;
372 double current_reduction = static_cast<double>(aggregated_input_rows) / ht_rows;
373
374 // TODO: workaround for IMPALA-2490: subplan node rows_returned counter may be
375 // inaccurate, which could lead to a divide by zero below.
376 if (aggregated_input_rows <= 0) return true;
377
378 // Extrapolate the current reduction factor (r) using the formula
379 // R = 1 + (N / n) * (r - 1), where R is the reduction factor over the full input data
380 // set, N is the number of input rows, excluding passed-through rows, and n is the
381 // number of rows inserted or merged into the hash tables. This is a very rough
382 // approximation but is good enough to be useful.
383 // TODO: consider collecting more statistics to better estimate reduction.
384 double estimated_reduction = aggregated_input_rows >= expected_input_rows ?
385 current_reduction :
386 1 + (expected_input_rows / aggregated_input_rows) * (current_reduction - 1);
387 double min_reduction =
388 STREAMING_HT_MIN_REDUCTION[cache_level].streaming_ht_min_reduction;
389
390 COUNTER_SET(preagg_estimated_reduction_, estimated_reduction);
391 COUNTER_SET(preagg_streaming_ht_min_reduction_, min_reduction);
392 return estimated_reduction > min_reduction;
393}
394
395void GroupingAggregator::CleanupHashTbl(
396 const vector<AggFnEvaluator*>& agg_fn_evals, HashTable::Iterator it) {

Callers

nothing calls this directly

Calls 3

CurrentMemSizeMethod · 0.80
getMethod · 0.65
sizeMethod · 0.45

Tested by

no test coverage detected