You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by mi...@apache.org on 2026/09/23 20:19:40 UTC

(impala) 01/03: IMPALA-15381: Reduce reservoir RNG state

This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit a95c64c756f66156399f9e4de2a5067f34765e37
Author: Aleksandr Efimov <dz...@gmail.com>
AuthorDate: Tue Sep 22 09:09:07 2026 +0300

    IMPALA-15381: Reduce reservoir RNG state
    
    boost::mt19937_64 makes ReservoirSampleState 2536 bytes. FreePool
    rounds the allocation to 4 KiB, so sampling aggregates use 4624
    bytes per function and group with their initial sample array.
    
    Use pcg32 to reduce the state to 48 bytes. The sampling sequence
    changes, so approximate results can change.
    
    Testing:
    - Full release build
    - HistogramTest.*
    - Large appx_median(), sample(), and histogram() queries
    - Updated the Init() allocation size in alloc-fail-init.test
    
    Change-Id: I9e046e3f0c1b91f1761ce578601a330bd864eb84
    Assisted-by: gpt-5.6-sol (OpenAI Codex)
    Reviewed-on: http://gerrit.cloudera.org:8080/24896
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exprs/aggregate-functions-ir.cc                 | 18 +++++++-----------
 .../queries/QueryTest/alloc-fail-init.test             |  4 ++--
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/be/src/exprs/aggregate-functions-ir.cc b/be/src/exprs/aggregate-functions-ir.cc
index 48e703306..8b72f7ec1 100644
--- a/be/src/exprs/aggregate-functions-ir.cc
+++ b/be/src/exprs/aggregate-functions-ir.cc
@@ -18,13 +18,11 @@
 #include "exprs/aggregate-functions.h"
 
 #include <algorithm>
+#include <cmath>
 #include <map>
+#include <random>
 #include <sstream>
 #include <utility>
-#include <cmath>
-
-#include <boost/random/mersenne_twister.hpp>
-#include <boost/random/uniform_int.hpp>
 
 #include "codegen/impala-ir.h"
 #include "common/logging.h"
@@ -46,14 +44,13 @@
 #include "thirdparty/datasketches/theta_union.hpp"
 #include "thirdparty/datasketches/theta_intersection.hpp"
 #include "thirdparty/datasketches/kll_sketch.hpp"
+#include "thirdparty/pcg-cpp-0.98/include/pcg_random.hpp"
 #include "util/arithmetic-util.h"
 #include "util/mpfit-util.h"
 #include "util/pretty-printer.h"
 
 #include "common/names.h"
 
-using boost::uniform_int;
-using boost::mt19937_64;
 using std::make_pair;
 using std::map;
 using std::min_element;
@@ -62,6 +59,7 @@ using std::pop_heap;
 using std::push_heap;
 using std::string;
 using std::stringstream;
+using std::uniform_int_distribution;
 
 namespace {
 // Threshold for each precision where it's better to use linear counting instead
@@ -1923,10 +1921,8 @@ class ReservoirSampleState {
   // Number of values over which the samples were collected.
   int64_t source_size_;
 
-  // Random number generator for generating 64-bit integers
-  // Replace ranlux64_3 with mt19937_64 for better performance. See boost benchmark at
-  // https://www.boost.org/doc/libs/1_74_0/doc/html/boost_random/performance.html
-  mt19937_64 rng_;
+  // Random number generator used to select samples from the input stream.
+  pcg32 rng_;
 
   // True if the array of samples is in the same memory allocation as this object. If
   // false, this object is responsible for freeing the memory.
@@ -1959,7 +1955,7 @@ class ReservoirSampleState {
 
   // Returns a random integer in the range [0, max].
   int64_t GetNext64(int64_t max) {
-    uniform_int<int64_t> dist(0, max);
+    uniform_int_distribution<int64_t> dist(0, max);
     return dist(rng_);
   }
 };
diff --git a/testdata/workloads/functional-query/queries/QueryTest/alloc-fail-init.test b/testdata/workloads/functional-query/queries/QueryTest/alloc-fail-init.test
index c6d77d6a0..5a841f1d1 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/alloc-fail-init.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/alloc-fail-init.test
@@ -13,7 +13,7 @@ FunctionContext::Allocate() failed to allocate 1 bytes.
 ---- QUERY
 select sample(timestamp_col) from functional.alltypes
 ---- CATCH
-FunctionContext::Allocate() failed to allocate 2536 bytes.
+FunctionContext::Allocate() failed to allocate 48 bytes.
 ====
 ---- QUERY
 select group_concat(string_col) from functional.alltypes
@@ -58,7 +58,7 @@ FunctionContextImpl::AllocateForResults() failed to allocate 120 bytes.
 ---- QUERY
 select appx_median(int_col) from functional.alltypes
 ---- CATCH
-FunctionContext::Allocate() failed to allocate 2536 bytes.
+FunctionContext::Allocate() failed to allocate 48 bytes.
 ====
 ---- QUERY
 select to_date(now())