34 CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(estimator_.get()));
35 CHECK(host_estimator_buffer_);
36 auto bits_set =
bitmap_set_size(host_estimator_buffer_, estimator_->getBufferSize());
37 const auto total_bits = estimator_->getBufferSize() * 8;
39 const auto unset_bits = total_bits - bits_set;
40 const auto ratio =
static_cast<double>(unset_bits) / total_bits;
42 throw std::runtime_error(
"Failed to get a high quality cardinality estimation");
44 return -
static_cast<double>(total_bits) * log(ratio);
56 const auto estimator_result =
67 if (!estimator_result) {
70 return std::max(estimator_result->getNDVEstimator(), size_t(1));
73 throw std::runtime_error(
"Cardinality estimation query ran out of time");
76 throw std::runtime_error(
"Cardinality estimation query has been interrupted");
78 throw std::runtime_error(
"Failed to run the cardinality estimation query: " +
86 const int64_t range) {
95 ? makeExpr<Analyzer::LargeNDVEstimator>(ra_exe_unit.
groupby_exprs)
96 : makeExpr<Analyzer::NDVEstimator>(ra_exe_unit.
groupby_exprs),
107 std::shared_ptr<Analyzer::Expr> replacement_target) {
114 {replacement_target.get()},
126 std::vector<std::pair<
ResultSetPtr, std::vector<size_t>>>& results_per_device) {
127 if (results_per_device.empty()) {
130 CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(ra_exe_unit.
estimator.get()));
131 const auto& result_set = results_per_device.front().first;
133 auto estimator_buffer = result_set->getHostEstimatorBuffer();
134 CHECK(estimator_buffer);
135 for (
size_t i = 1;
i < results_per_device.size(); ++
i) {
136 const auto& next_result_set = results_per_device[
i].first;
137 const auto other_estimator_buffer = next_result_set->getHostEstimatorBuffer();
138 for (
size_t off = 0; off < ra_exe_unit.
estimator->getBufferSize(); ++off) {
139 estimator_buffer[off] |= other_estimator_buffer[off];
142 return std::move(result_set);
size_t getBufferSize() const final
bool is_agg(const Analyzer::Expr *expr)
int64_t g_large_ndv_threshold
int32_t getErrorCode() const
static const int32_t ERR_INTERRUPTED
const std::optional< bool > union_all
RelAlgExecutionUnit exe_unit
std::vector< InputDescriptor > input_descs
std::shared_ptr< ResultSet > ResultSetPtr
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
std::list< std::shared_ptr< Analyzer::Expr > > strip_join_covered_filter_quals(const std::list< std::shared_ptr< Analyzer::Expr >> &quals, const JoinQualsPerNestingLevel &join_quals)
RelAlgExecutionUnit create_count_all_execution_unit(const RelAlgExecutionUnit &ra_exe_unit, std::shared_ptr< Analyzer::Expr > replacement_target)
const JoinQualsPerNestingLevel join_quals
const Catalog_Namespace::Catalog & cat_
static const int32_t ERR_OUT_OF_TIME
size_t getNDVEstimation(const WorkUnit &work_unit, const int64_t range, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo)
const std::shared_ptr< Analyzer::Estimator > estimator
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults >>> ColumnCacheMap
size_t getNDVEstimator() const
std::list< std::shared_ptr< Analyzer::Expr > > quals
RelAlgExecutionUnit create_ndv_execution_unit(const RelAlgExecutionUnit &ra_exe_unit, const int64_t range)
Estimators to be used when precise cardinality isn't useful.
static std::string getErrorMessageFromCode(const int32_t error_code)
std::shared_ptr< const query_state::QueryState > query_state
ResultSetPtr reduce_estimator_results(const RelAlgExecutionUnit &ra_exe_unit, std::vector< std::pair< ResultSetPtr, std::vector< size_t >>> &results_per_device)
std::list< std::shared_ptr< const InputColDescriptor > > input_col_descs
size_t bitmap_set_size(const int8_t *bitmap, const size_t bitmap_byte_sz)
std::list< std::shared_ptr< Analyzer::Expr > > simple_quals
size_t g_large_ndv_multiplier