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());
41 const auto total_bits = estimator_->getBufferSize() * 8;
43 const auto unset_bits = total_bits - bits_set;
44 const auto ratio =
static_cast<double>(unset_bits) / total_bits;
47 <<
"Failed to get a high quality cardinality estimation, falling back to "
48 "approximate group by buffer size guess.";
51 return -
static_cast<double>(total_bits) * log(ratio);
63 const auto estimator_result =
73 if (!estimator_result) {
76 return estimator_result->getNDVEstimator();
79 throw std::runtime_error(
"Cardinality estimation query ran out of time");
82 throw std::runtime_error(
"Cardinality estimation query has been interrupted");
84 throw std::runtime_error(
"Failed to run the cardinality estimation query: " +
92 const int64_t range)
const {
93 const bool use_large_estimator =
103 use_large_estimator ? makeExpr<Analyzer::LargeNDVEstimator>(
groupby_exprs)
125 {replacement_target},
137 {replacement_target},
143 std::vector<std::pair<
ResultSetPtr, std::vector<size_t>>>& results_per_device) {
144 if (results_per_device.empty()) {
147 CHECK(dynamic_cast<const Analyzer::NDVEstimator*>(ra_exe_unit.
estimator.get()));
148 const auto& result_set = results_per_device.front().first;
150 auto estimator_buffer = result_set->getHostEstimatorBuffer();
151 CHECK(estimator_buffer);
152 for (
size_t i = 1; i < results_per_device.size(); ++i) {
153 const auto& next_result_set = results_per_device[i].first;
154 const auto other_estimator_buffer = next_result_set->getHostEstimatorBuffer();
155 for (
size_t off = 0; off < ra_exe_unit.
estimator->getBufferSize(); ++off) {
156 estimator_buffer[off] |= other_estimator_buffer[off];
159 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
QueryPlanHash query_plan_dag_hash
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)
const JoinQualsPerNestingLevel join_quals
TableIdToNodeMap table_id_to_node_map
bool hasErrorCode(ErrorCode const ec) const
RelAlgExecutionUnit createCountAllExecutionUnit(Analyzer::Expr *replacement_target) const
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
RelAlgExecutionUnit createNdvExecutionUnit(const int64_t range) const
size_t getNDVEstimator() const
std::unordered_map< shared::TableKey, std::unordered_map< int, std::shared_ptr< const ColumnarResults >>> ColumnCacheMap
std::list< std::shared_ptr< Analyzer::Expr > > quals
RegisteredQueryHint query_hint
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
HashTableBuildDagMap hash_table_build_plan_dag