MySQL 8.4.0
Source Code Documentation
histograms::Equi_height< T > Class Template Reference

#include <equi_height.h>

Inheritance diagram for histograms::Equi_height< T >:
[legend]

Public Member Functions

Histogramclone (MEM_ROOT *mem_root) const override
 Make a clone of this histogram on a MEM_ROOT. More...
 
 Equi_height (const Equi_height< T > &other)=delete
 
bool build_histogram (const Value_map< T > &value_map, size_t num_buckets)
 Build the histogram. More...
 
double get_equal_to_selectivity (const T &value) const
 Find the fraction of values equal to 'value'. More...
 
double get_less_than_selectivity (const T &value) const
 Find the fraction of values that is less than 'value'. More...
 
double get_greater_than_selectivity (const T &value) const
 Find the fraction of values that is greater than 'value'. 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...
 
bool histogram_to_json (Json_object *json_object) const override
 Convert this histogram to a JSON object. More...
 
const Mem_root_array< equi_height::Bucket< T > > & get_buckets () const
 Get the buckets of the histogram. More...
 
std::string histogram_type_to_str () const override
 Returns the histogram type as a readable string. More...
 
- Public Member Functions inherited from histograms::Histogram
 Histogram ()=delete
 
 Histogram (const Histogram &other)=delete
 
virtual ~Histogram ()=default
 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 get_auto_update () const
 
void set_auto_update (bool auto_update)
 Sets the auto update property for the histogram. More...
 
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_fraction () const
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, double *out, Error_context *context)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, String *out, Error_context *context)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, ulonglong *out, Error_context *context)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, longlong *out, Error_context *context)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, MYSQL_TIME *out, Error_context *context)
 
template<>
bool extract_json_dom_value (const Json_dom *json_dom, my_decimal *out, Error_context *context)
 

Static Public Member Functions

static Equi_height< T > * create (MEM_ROOT *mem_root, const std::string &db_name, const std::string &tbl_name, const std::string &col_name, Value_map_type data_type)
 Equi-height histogram factory method. 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, Error_context *context)
 Converts JSON object to a histogram. More...
 

Protected Member Functions

bool json_to_histogram (const Json_object &json_object, Error_context *context) override
 Populate this histogram with contents from a JSON object. More...
 
- Protected 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, bool *error)
 Constructor. More...
 
 Histogram (MEM_ROOT *mem_root, const Histogram &other, bool *error)
 Copy constructor. More...
 
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, Error_context *context)
 Return the value that is contained in the JSON DOM object. More...
 

Private Member Functions

 Equi_height (MEM_ROOT *mem_root, const std::string &db_name, const std::string &tbl_name, const std::string &col_name, Value_map_type data_type, bool *error)
 Equi-height constructor. More...
 
 Equi_height (MEM_ROOT *mem_root, const Equi_height< T > &other, bool *error)
 Equi-height copy-constructor. More...
 
bool add_bucket_from_json (const Json_array *json_bucket, Error_context *context)
 Create Equi-height buckets from a JSON array. More...
 

Static Private Member Functions

static constexpr const char * equi_height_str ()
 String representation of the histogram type EQUI-HEIGHT. More...
 

Private Attributes

Mem_root_array< equi_height::Bucket< T > > m_buckets
 The buckets for this histogram. More...
 

Additional Inherited Members

- Public Types inherited from histograms::Histogram
enum class  enum_histogram_type { EQUI_HEIGHT , SINGLETON }
 All supported histogram types in MySQL. 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...
 
static constexpr const char * auto_update_str ()
 String representation of the JSON field "auto-update". 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...
 

Constructor & Destructor Documentation

◆ Equi_height() [1/3]

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

◆ Equi_height() [2/3]

template<class T >
histograms::Equi_height< T >::Equi_height ( MEM_ROOT mem_root,
const std::string &  db_name,
const std::string &  tbl_name,
const std::string &  col_name,
Value_map_type  data_type,
bool *  error 
)
private

Equi-height 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
[out]erroris set to true if an error occurs

◆ Equi_height() [3/3]

template<class T >
histograms::Equi_height< T >::Equi_height ( MEM_ROOT mem_root,
const Equi_height< T > &  other,
bool *  error 
)
private

Equi-height 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
[out]erroris set to true if an error occurs

Member Function Documentation

◆ add_bucket_from_json()

template<class T >
bool histograms::Equi_height< T >::add_bucket_from_json ( const Json_array json_bucket,
Error_context context 
)
private

Create Equi-height buckets from a JSON array.

This function will add new buckets to the current histogram by going through the provided JSON array. Contents are allocated as needed on the current histograms MEM_ROOT.

Parameters
json_bucketa JSON array containing the histogram buckets
contexterror context for validation
Returns
true on error, false otherwise

◆ build_histogram()

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

Build the histogram.

This function will build a new histogram from a "value map". The function will create at most num_buckets buckets, but may use less.

Parameters
value_mapa value map, where the map key is a value and the map value is the absolute frequency for that value
num_bucketsmaximum number of buckets to create
Returns
true on error, false otherwise

◆ clone()

template<class T >
Histogram * histograms::Equi_height< 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()

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

Equi-height histogram factory method.

Attempts to allocate and initialize an equi-height histogram on the supplied mem_root. This will not build the histogram, but only set its properties. If the attempt to allocate the histogram fails or if an error occurs during construction we return nullptr.

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
Returns
A pointer to an equi-height histogram on success. Returns nullptr on error.

◆ equi_height_str()

template<class T >
static constexpr const char * histograms::Equi_height< T >::equi_height_str ( )
inlinestaticconstexprprivate

String representation of the histogram type EQUI-HEIGHT.

◆ get_buckets()

template<class T >
const Mem_root_array< equi_height::Bucket< T > > & histograms::Equi_height< T >::get_buckets ( ) const
inline

Get the buckets of the histogram.

Exposed for unit testing.

Returns
A const reference to the collection of buckets.

◆ get_equal_to_selectivity()

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

Find the fraction of values equal to 'value'.

This function will estimate the fraction 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::Equi_height< T >::get_greater_than_selectivity ( const T &  value) const

Find the fraction of values that is greater than 'value'.

This function will estimate the fraction 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::Equi_height< T >::get_less_than_selectivity ( const T &  value) const

Find the fraction of values that is less than 'value'.

This function will estimate the fraction 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::Equi_height< T >::get_num_buckets ( ) const
inlineoverridevirtual
Returns
number of buckets in this histogram

Implements histograms::Histogram.

◆ get_num_distinct_values()

template<class T >
size_t histograms::Equi_height< T >::get_num_distinct_values
overridevirtual

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::Equi_height< 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::Equi_height< T >::histogram_type_to_str
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::Equi_height< T >::json_to_histogram ( const Json_object json_object,
Error_context context 
)
overrideprotectedvirtual

Populate this histogram with contents from a JSON object.

Parameters
json_objecta JSON object that represents an Equi-height histogram
contexterror context for validation
Returns
True on error, false otherwise.

Implements histograms::Histogram.

Member Data Documentation

◆ m_buckets

template<class T >
Mem_root_array<equi_height::Bucket<T> > histograms::Equi_height< T >::m_buckets
private

The buckets for this histogram.


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