MySQL  8.0.20
Source Code Documentation
histograms::Singleton< T > Class Template Reference

#include <singleton.h>

Inheritance diagram for histograms::Singleton< T >:
histograms::Histogram

Public Member Functions

 Singleton (MEM_ROOT *mem_root, const std::string &db_name, const std::string &tbl_name, const std::string &col_name, Value_map_type data_type)
 Singleton constructor. More...
 
 Singleton (MEM_ROOT *mem_root, const Singleton< T > &other)
 Singleton copy-constructor. More...
 
 Singleton (const Singleton< T > &other)=delete
 
bool build_histogram (const Value_map< T > &value_map, size_t num_buckets)
 Build the Singleton histogram. More...
 
bool histogram_to_json (Json_object *json_object) const override
 Convert this histogram to a JSON object. More...
 
size_t get_num_buckets () const override
 
size_t get_num_distinct_values () const override
 Get the estimated number of distinct non-NULL values. More...
 
std::string histogram_type_to_str () const override
 Returns the histogram type as a readable string. More...
 
Histogramclone (MEM_ROOT *mem_root) const override
 Make a clone of this histogram on a MEM_ROOT. More...
 
double get_equal_to_selectivity (const T &value) const
 Find the number of values equal to 'value'. More...
 
double get_less_than_selectivity (const T &value) const
 Find the number of values less than 'value'. More...
 
double get_greater_than_selectivity (const T &value) const
 Find the number of values greater than 'value'. More...
 
template<>
 Singleton (MEM_ROOT *mem_root, const Singleton< String > &other)
 
- Public Member Functions inherited from histograms::Histogram
 Histogram (MEM_ROOT *mem_root, const std::string &db_name, const std::string &tbl_name, const std::string &col_name, enum_histogram_type type, Value_map_type data_type)
 Constructor. More...
 
 Histogram (MEM_ROOT *mem_root, const Histogram &other)
 Copy constructor. More...
 
 Histogram (const Histogram &other)=delete
 
virtual ~Histogram ()
 Destructor. More...
 
MEM_ROOTget_mem_root () const
 
const LEX_CSTRING get_database_name () const
 
const LEX_CSTRING get_table_name () const
 
const LEX_CSTRING get_column_name () const
 
enum_histogram_type get_histogram_type () const
 
double get_null_values_fraction () const
 
const CHARSET_INFOget_character_set () const
 
double get_sampling_rate () const
 
Value_map_type get_data_type () const
 
size_t get_num_buckets_specified () const
 
bool store_histogram (THD *thd) const
 Store this histogram to persistent storage (data dictionary). More...
 
bool get_selectivity (Item **items, size_t item_count, enum_operator op, double *selectivity) const
 Get selectivity estimation. More...
 
double get_non_null_values_frequency () const
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, double *out)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, String *out)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, ulonglong *out)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, longlong *out)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, MYSQL_TIME *out)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, my_decimal *out)
 

Protected Member Functions

bool json_to_histogram (const Json_object &json_object) override
 Populate this histogram with contents from a JSON object. More...
 
- Protected Member Functions inherited from histograms::Histogram
bool histogram_data_type_to_json (Json_object *json_object) const
 Write the data type of this histogram into a JSON object. More...
 
template<class T >
bool extract_json_dom_value (const Json_dom *json_dom, T *out)
 Return the value that is contained in the JSON DOM object. More...
 

Private Types

using singleton_buckets_allocator = Mem_root_allocator< std::pair< const T, double > >
 
using singleton_buckets_type = std::map< const T, double, Histogram_comparator, singleton_buckets_allocator >
 

Private Member Functions

template<>
bool add_value_json_bucket (const double &value, Json_array *json_bucket)
 
template<>
bool add_value_json_bucket (const String &value, Json_array *json_bucket)
 
template<>
bool add_value_json_bucket (const ulonglong &value, Json_array *json_bucket)
 
template<>
bool add_value_json_bucket (const longlong &value, Json_array *json_bucket)
 
template<>
bool add_value_json_bucket (const MYSQL_TIME &value, Json_array *json_bucket)
 
template<>
bool add_value_json_bucket (const my_decimal &value, Json_array *json_bucket)
 

Static Private Member Functions

static constexpr const char * singleton_str ()
 String representation of the histogram type SINGLETON. More...
 
static bool add_value_json_bucket (const T &value, Json_array *json_bucket)
 Add value to a JSON bucket. More...
 
static bool create_json_bucket (const std::pair< T, double > &bucket, Json_array *json_bucket)
 Convert one bucket to a JSON object. More...
 

Private Attributes

singleton_buckets_type m_buckets
 The buckets for this histogram [key, cumulative frequency]. More...
 

Additional Inherited Members

- Public Types inherited from histograms::Histogram
enum  enum_histogram_type { enum_histogram_type::EQUI_HEIGHT, enum_histogram_type::SINGLETON }
 All supported histogram types in MySQL. More...
 
- Static Public Member Functions inherited from histograms::Histogram
static constexpr const char * histogram_type_str ()
 String representation of the JSON field "histogram-type". More...
 
static constexpr const char * data_type_str ()
 String representation of the JSON field "data-type". More...
 
static constexpr const char * collation_id_str ()
 String representation of the JSON field "collation-id". More...
 
static constexpr const char * singleton_str ()
 String representation of the histogram type SINGLETON. More...
 
static constexpr const char * equi_height_str ()
 String representation of the histogram type EQUI-HEIGHT. More...
 
static Histogramjson_to_histogram (MEM_ROOT *mem_root, const std::string &schema_name, const std::string &table_name, const std::string &column_name, const Json_object &json_object)
 Converts JSON object to a histogram. More...
 
- Static Protected Member Functions inherited from histograms::Histogram
static constexpr const char * buckets_str ()
 String representation of the JSON field "buckets". More...
 
static constexpr const char * last_updated_str ()
 String representation of the JSON field "last-updated". More...
 
static constexpr const char * null_values_str ()
 String representation of the JSON field "null-values". More...
 
static constexpr const char * sampling_rate_str ()
 
static constexpr const char * numer_of_buckets_specified_str ()
 String representation of the JSON field "number-of-buckets-specified". More...
 
- Protected Attributes inherited from histograms::Histogram
double m_sampling_rate
 
double m_null_values_fraction
 The fraction of NULL values in the histogram (between 0.0 and 1.0). More...
 
const CHARSET_INFOm_charset
 The character set for the data stored. More...
 
size_t m_num_buckets_specified
 The number of buckets originally specified. More...
 

Member Typedef Documentation

◆ singleton_buckets_allocator

template<class T>
using histograms::Singleton< T >::singleton_buckets_allocator = Mem_root_allocator<std::pair<const T, double> >
private

◆ singleton_buckets_type

template<class T>
using histograms::Singleton< T >::singleton_buckets_type = std::map<const T, double, Histogram_comparator, singleton_buckets_allocator>
private

Constructor & Destructor Documentation

◆ Singleton() [1/4]

template<class T >
histograms::Singleton< T >::Singleton ( MEM_ROOT mem_root,
const std::string &  db_name,
const std::string &  tbl_name,
const std::string &  col_name,
Value_map_type  data_type 
)

Singleton constructor.

This will not build the histogram, but only set its properties.

Parameters
mem_rootthe mem_root where the histogram contents will be allocated
db_namename of the database this histogram represents
tbl_namename of the table this histogram represents
col_namename of the column this histogram represents
data_typethe type of data that this histogram contains

◆ Singleton() [2/4]

template<class T >
histograms::Singleton< T >::Singleton ( MEM_ROOT mem_root,
const Singleton< T > &  other 
)

Singleton copy-constructor.

This will take a copy of the histogram and all of its contents on the provided MEM_ROOT.

Parameters
mem_rootthe MEM_ROOT to allocate the new histogram on.
otherthe histogram to take a copy of

◆ Singleton() [3/4]

template<class T>
histograms::Singleton< T >::Singleton ( const Singleton< T > &  other)
delete

◆ Singleton() [4/4]

template<>
histograms::Singleton< String >::Singleton ( MEM_ROOT mem_root,
const Singleton< String > &  other 
)

Member Function Documentation

◆ add_value_json_bucket() [1/7]

template<>
bool histograms::Singleton< double >::add_value_json_bucket ( const double &  value,
Json_array json_bucket 
)
private

◆ add_value_json_bucket() [2/7]

template<>
bool histograms::Singleton< String >::add_value_json_bucket ( const String value,
Json_array json_bucket 
)
private

◆ add_value_json_bucket() [3/7]

template<>
bool histograms::Singleton< ulonglong >::add_value_json_bucket ( const ulonglong value,
Json_array json_bucket 
)
private

◆ add_value_json_bucket() [4/7]

template<>
bool histograms::Singleton< longlong >::add_value_json_bucket ( const longlong value,
Json_array json_bucket 
)
private

◆ add_value_json_bucket() [5/7]

template<>
bool histograms::Singleton< MYSQL_TIME >::add_value_json_bucket ( const MYSQL_TIME value,
Json_array json_bucket 
)
private

◆ add_value_json_bucket() [6/7]

template<class T>
static bool histograms::Singleton< T >::add_value_json_bucket ( const T &  value,
Json_array json_bucket 
)
staticprivate

Add value to a JSON bucket.

This function adds the value to the supplied JSON array.

Parameters
valuethe value to add
[out]json_bucketa JSON array where the bucket data is to be stored
Returns
true on error, false otherwise

◆ add_value_json_bucket() [7/7]

template<>
bool histograms::Singleton< my_decimal >::add_value_json_bucket ( const my_decimal value,
Json_array json_bucket 
)
private

◆ build_histogram()

template<class T >
bool histograms::Singleton< T >::build_histogram ( const Value_map< T > &  value_map,
size_t  num_buckets 
)

Build the Singleton histogram.

Parameters
value_mapvalues to create the histogram for
num_bucketsthe number of buckets specified/requested by the user
Returns
true on error, false otherwise

◆ clone()

template<class T >
Histogram * histograms::Singleton< T >::clone ( MEM_ROOT mem_root) const
overridevirtual

Make a clone of this histogram on a MEM_ROOT.

Parameters
mem_rootthe MEM_ROOT to allocate the new histogram contents on.
Returns
a copy of the histogram allocated on the provided MEM_ROOT.

Implements histograms::Histogram.

◆ create_json_bucket()

template<class T >
bool histograms::Singleton< T >::create_json_bucket ( const std::pair< T, double > &  bucket,
Json_array json_bucket 
)
staticprivate

Convert one bucket to a JSON object.

Parameters
bucketthe histogram bucket to convert
[out]json_bucketa JSON array where the bucket data is to be stored
Returns
true on error, false otherwise

◆ get_equal_to_selectivity()

template<class T >
double histograms::Singleton< T >::get_equal_to_selectivity ( const T &  value) const

Find the number of values equal to 'value'.

This function will estimate the number of values that is equal to the provided value.

Parameters
valueThe value to estimate the selectivity for.
Returns
the selectivity between 0.0 and 1.0 inclusive.

◆ get_greater_than_selectivity()

template<class T >
double histograms::Singleton< T >::get_greater_than_selectivity ( const T &  value) const

Find the number of values greater than 'value'.

This function will estimate the number of values that is greater than the provided value.

Parameters
valueThe value to estimate the selectivity for.
Returns
the selectivity between 0.0 and 1.0 inclusive.

◆ get_less_than_selectivity()

template<class T >
double histograms::Singleton< T >::get_less_than_selectivity ( const T &  value) const

Find the number of values less than 'value'.

This function will estimate the number of values that is less than the provided value.

Parameters
valueThe value to estimate the selectivity for.
Returns
the selectivity between 0.0 and 1.0 inclusive.

◆ get_num_buckets()

template<class T>
size_t histograms::Singleton< T >::get_num_buckets ( ) const
inlineoverridevirtual
Returns
number of values/buckets in this histogram

Implements histograms::Histogram.

◆ get_num_distinct_values()

template<class T>
size_t histograms::Singleton< T >::get_num_distinct_values ( ) const
inlineoverridevirtual

Get the estimated number of distinct non-NULL values.

Returns
number of distinct non-NULL values

Implements histograms::Histogram.

◆ histogram_to_json()

template<class T >
bool histograms::Singleton< T >::histogram_to_json ( Json_object json_object) const
overridevirtual

Convert this histogram to a JSON object.

This function will take the contents of the current histogram and put it in the output parameter "json_object".

Parameters
[in,out]json_objectoutput where the histogram is to be stored. The caller is responsible for allocating/deallocating the JSON object
Returns
true on error, false otherwise

Implements histograms::Histogram.

◆ histogram_type_to_str()

template<class T >
std::string histograms::Singleton< T >::histogram_type_to_str ( ) const
overridevirtual

Returns the histogram type as a readable string.

Returns
a readable string representation of the histogram type

Implements histograms::Histogram.

◆ json_to_histogram()

template<class T >
bool histograms::Singleton< T >::json_to_histogram ( const Json_object json_object)
overrideprotectedvirtual

Populate this histogram with contents from a JSON object.

Parameters
json_objecta JSON object that represents an Singleton histogram
Returns
true on error, false otherwise.

Implements histograms::Histogram.

◆ singleton_str()

template<class T>
static constexpr const char* histograms::Singleton< T >::singleton_str ( )
inlinestaticprivate

String representation of the histogram type SINGLETON.

Member Data Documentation

◆ m_buckets

template<class T>
singleton_buckets_type histograms::Singleton< T >::m_buckets
private

The buckets for this histogram [key, cumulative frequency].


The documentation for this class was generated from the following files: