![]() |
mutable
A Database System for Research and Fast Prototyping
|
SpnEstimator that estimates cardinalities based on Sum-Product Networks. More...
#include <CardinalityEstimator.hpp>
Data Structures | |
struct | SpnDataModel |
Public Types | |
using | SpnIdentifier = std::pair< ThreadSafePooledString, ThreadSafePooledString > |
using | SpnJoin = std::pair< SpnIdentifier, SpnIdentifier > |
using | table_spn_map = std::unordered_map< ThreadSafePooledString, std::reference_wrapper< const SpnWrapper > > |
Public Member Functions | |
SpnEstimator (ThreadSafePooledString name_of_database) | |
~SpnEstimator () | |
void | learn_spns () |
Learn an Spn on every table in the database. | |
void | learn_new_spn (const ThreadSafePooledString &name_of_table) |
Add a new Spn for a table in the database. | |
std::unique_ptr< DataModel > | empty_model () const override |
std::unique_ptr< DataModel > | estimate_scan (const QueryGraph &G, Subproblem P) const override |
std::unique_ptr< DataModel > | estimate_filter (const QueryGraph &G, const DataModel &data, const cnf::CNF &filter) const override |
std::unique_ptr< DataModel > | estimate_limit (const QueryGraph &G, const DataModel &data, std::size_t limit, std::size_t offset) const override |
std::unique_ptr< DataModel > | estimate_grouping (const QueryGraph &G, const DataModel &data, const std::vector< group_type > &groups) const override |
std::unique_ptr< DataModel > | estimate_join (const QueryGraph &G, const DataModel &left, const DataModel &right, const cnf::CNF &condition) const override |
template<typename PlanTable > | |
std::unique_ptr< DataModel > | operator() (estimate_join_all_tag, PlanTable &&PT, const QueryGraph &G, Subproblem to_join, const cnf::CNF &condition) const |
std::size_t | predict_cardinality (const DataModel &data) const override |
Private Member Functions | |
void | print (std::ostream &out) const override |
Static Private Member Functions | |
static std::pair< unsigned, bool > | find_spn_id (const SpnDataModel &data, SpnJoin &join) |
Function to compute which of the two join identifiers belongs to the given data model and which attribute to choose. | |
static std::size_t | max_frequency (const SpnDataModel &data, SpnJoin &join) |
Compute the maximum frequency of values of the attribute in the join. | |
static std::size_t | max_frequency (const SpnDataModel &data, const ThreadSafePooledString &attribute) |
Compute the maximum frequency of values of the attribute . | |
Private Attributes | |
std::unordered_map< ThreadSafePooledString, SpnWrapper * > | table_to_spn_ |
| |
ThreadSafePooledString | name_of_database_ |
| |
SpnEstimator that estimates cardinalities based on Sum-Product Networks.
Definition at line 323 of file CardinalityEstimator.hpp.
using m::SpnEstimator::SpnIdentifier = std::pair<ThreadSafePooledString, ThreadSafePooledString> |
Definition at line 325 of file CardinalityEstimator.hpp.
using m::SpnEstimator::SpnJoin = std::pair<SpnIdentifier, SpnIdentifier> |
Definition at line 326 of file CardinalityEstimator.hpp.
using m::SpnEstimator::table_spn_map = std::unordered_map<ThreadSafePooledString, std::reference_wrapper<const SpnWrapper> > |
Definition at line 327 of file CardinalityEstimator.hpp.
|
inlineexplicit |
Definition at line 355 of file CardinalityEstimator.hpp.
SpnEstimator::~SpnEstimator | ( | ) |
Definition at line 528 of file CardinalityEstimator.cpp.
References table_to_spn_.
|
override |
Definition at line 585 of file CardinalityEstimator.cpp.
|
override |
Definition at line 607 of file CardinalityEstimator.cpp.
References M_insist.
|
override |
Definition at line 646 of file CardinalityEstimator.cpp.
|
override |
Definition at line 672 of file CardinalityEstimator.cpp.
References max_frequency().
|
override |
Definition at line 639 of file CardinalityEstimator.cpp.
|
override |
Definition at line 590 of file CardinalityEstimator.cpp.
References m::SmallBitset::begin(), M_insist, m::SpnWrapper::num_rows(), m::SmallBitset::size(), m::QueryGraph::sources(), and table_to_spn_.
|
staticprivate |
Function to compute which of the two join identifiers belongs to the given data model and which attribute to choose.
data | the data model |
join | the join condition as a pair of identifiers |
Definition at line 544 of file CardinalityEstimator.cpp.
References m::SpnEstimator::SpnDataModel::spns_.
Referenced by max_frequency().
void SpnEstimator::learn_new_spn | ( | const ThreadSafePooledString & | name_of_table | ) |
Add a new Spn for a table in the database.
Definition at line 536 of file CardinalityEstimator.cpp.
References m::SpnWrapper::learn_spn_table(), name_of_database_, and table_to_spn_.
void SpnEstimator::learn_spns | ( | ) |
Learn an Spn on every table in the database.
Also used to initialize spns after data inserted in tables.
Definition at line 534 of file CardinalityEstimator.cpp.
References m::SpnWrapper::learn_spn_database(), name_of_database_, and table_to_spn_.
|
staticprivate |
Compute the maximum frequency of values of the attribute .
data | the data model |
attribute | the attribute |
Definition at line 573 of file CardinalityEstimator.cpp.
References m::SpnWrapper::estimate_number_distinct_values(), m::SpnWrapper::get_attribute_to_id(), m::SpnEstimator::SpnDataModel::num_rows_, and m::SpnEstimator::SpnDataModel::spns_.
|
staticprivate |
Compute the maximum frequency of values of the attribute in the join.
data | the data model |
join | the join condition as a pair of identifiers |
Definition at line 563 of file CardinalityEstimator.cpp.
References m::SpnWrapper::estimate_number_distinct_values(), find_spn_id(), m::SpnEstimator::SpnDataModel::num_rows_, and m::SpnEstimator::SpnDataModel::spns_.
Referenced by estimate_join(), and operator()().
std::unique_ptr< DataModel > SpnEstimator::operator() | ( | estimate_join_all_tag | , |
PlanTable && | PT, | ||
const QueryGraph & | G, | ||
Subproblem | to_join, | ||
const cnf::CNF & | condition | ||
) | const |
Definition at line 727 of file CardinalityEstimator.cpp.
References m::SmallBitset::begin(), m::SmallBitset::empty(), m::SmallBitset::end(), M_insist, m::SpnEstimator::SpnDataModel::max_frequencies_, max_frequency(), m::SpnEstimator::SpnDataModel::num_rows_, and m::SpnEstimator::SpnDataModel::spns_.
|
override |
Definition at line 792 of file CardinalityEstimator.cpp.
|
overrideprivate |
Definition at line 798 of file CardinalityEstimator.cpp.
|
private |
the name of the database, the estimator is built on
Definition at line 352 of file CardinalityEstimator.hpp.
Referenced by learn_new_spn(), and learn_spns().
|
private |
the map from every table to its respective Spn, initially empty
Definition at line 350 of file CardinalityEstimator.hpp.
Referenced by estimate_scan(), learn_new_spn(), learn_spns(), and ~SpnEstimator().