23 CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(estimator_.get()));
24 CHECK(host_estimator_buffer_);
25 auto bits_set =
bitmap_set_size(host_estimator_buffer_, estimator_->getBufferSize());
26 const auto total_bits = estimator_->getBufferSize() * 8;
28 const auto unset_bits = total_bits - bits_set;
29 const auto ratio =
static_cast<double>(unset_bits) / total_bits;
31 throw std::runtime_error(
"Failed to get a high quality cardinality estimation");
33 return -
static_cast<double>(total_bits) * log(ratio);
44 const auto estimator_result =
56 if (!estimator_result) {
59 return std::max(estimator_result->getNDVEstimator(), size_t(1));
62 throw std::runtime_error(
"Cardinality estimation query ran out of time");
65 throw std::runtime_error(
"Cardinality estimation query has been interrupted");
67 throw std::runtime_error(
"Failed to run the cardinality estimation query: " +
89 std::shared_ptr<Analyzer::Expr> replacement_target) {
96 {replacement_target.get()},
104 std::vector<std::pair<
ResultSetPtr, std::vector<size_t>>>& results_per_device) {
105 if (results_per_device.empty()) {
108 CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(ra_exe_unit.
estimator.get()));
109 const auto& result_set = results_per_device.front().first;
111 auto estimator_buffer = result_set->getHostEstimatorBuffer();
112 CHECK(estimator_buffer);
113 for (
size_t i = 1; i < results_per_device.size(); ++i) {
114 const auto& next_result_set = results_per_device[i].first;
115 const auto other_estimator_buffer = next_result_set->getHostEstimatorBuffer();
116 for (
size_t off = 0; off < ra_exe_unit.
estimator->getBufferSize(); ++off) {
117 estimator_buffer[off] |= other_estimator_buffer[off];
120 return std::move(result_set);
bool is_agg(const Analyzer::Expr *expr)
int32_t getErrorCode() const
static const int32_t ERR_INTERRUPTED
RelAlgExecutionUnit exe_unit
std::shared_ptr< ResultSet > ResultSetPtr
const std::list< std::shared_ptr< Analyzer::Expr > > groupby_exprs
RelAlgExecutionUnit create_ndv_execution_unit(const RelAlgExecutionUnit &ra_exe_unit)
size_t getNDVEstimation(const WorkUnit &work_unit, const bool is_agg, const CompilationOptions &co, const ExecutionOptions &eo)
const std::vector< InputDescriptor > input_descs
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
const std::shared_ptr< Analyzer::Estimator > estimator
size_t getNDVEstimator() const
std::list< std::shared_ptr< Analyzer::Expr > > quals
Estimators to be used when precise cardinality isn't useful.
static std::string getErrorMessageFromCode(const int32_t error_code)
std::unordered_map< int, std::unordered_map< int, std::shared_ptr< const ColumnarResults > > > ColumnCacheMap
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