MySQL 9.1.0
Source Code Documentation
|
Histogram base class. More...
#include <histogram.h>
Public Types | |
enum class | enum_histogram_type { EQUI_HEIGHT , SINGLETON } |
All supported histogram types in MySQL. More... | |
Public Member Functions | |
Histogram ()=delete | |
Histogram (const Histogram &other)=delete | |
virtual | ~Histogram ()=default |
Destructor. More... | |
MEM_ROOT * | get_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_INFO * | get_character_set () const |
double | get_sampling_rate () const |
virtual std::string | histogram_type_to_str () const =0 |
Returns the histogram type as a readable string. More... | |
virtual size_t | get_num_buckets () const =0 |
virtual size_t | get_num_distinct_values () const =0 |
Get the estimated number of distinct non-NULL values. More... | |
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... | |
virtual bool | histogram_to_json (Json_object *json_object) const =0 |
Converts the histogram to a JSON object. More... | |
virtual Histogram * | clone (MEM_ROOT *mem_root) const =0 |
Make a clone of the current 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 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 Histogram * | json_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 | |
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... | |
virtual bool | json_to_histogram (const Json_object &json_object, Error_context *context)=0 |
Populate the histogram with data from the provided JSON object. More... | |
Static Protected Member Functions | |
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 | |
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_INFO * | m_charset |
The character set for the data stored. More... | |
size_t | m_num_buckets_specified |
The number of buckets originally specified. More... | |
Private Member Functions | |
bool | get_raw_selectivity (Item **items, size_t item_count, enum_operator op, double *selectivity) const |
An internal function for getting a selectivity estimate prior to adustment. More... | |
bool | get_selectivity_dispatcher (Item *item, const enum_operator op, const TYPELIB *typelib, double *selectivity) const |
An internal function for getting the selecitvity estimation. More... | |
template<class T > | |
double | get_less_than_selectivity_dispatcher (const T &value) const |
An internal function for getting the selecitvity estimation. More... | |
template<class T > | |
double | get_greater_than_selectivity_dispatcher (const T &value) const |
template<class T > | |
double | get_equal_to_selectivity_dispatcher (const T &value) const |
template<class T > | |
double | apply_operator (const enum_operator op, const T &value) const |
An internal function for applying the correct function for the given operator. More... | |
Private Attributes | |
MEM_ROOT * | m_mem_root |
The MEM_ROOT where the histogram contents will be allocated. More... | |
const enum_histogram_type | m_hist_type |
The type of this histogram. More... | |
const Value_map_type | m_data_type |
The type of the data this histogram contains. More... | |
LEX_CSTRING | m_database_name |
Name of the database this histogram represents. More... | |
LEX_CSTRING | m_table_name |
Name of the table this histogram represents. More... | |
LEX_CSTRING | m_column_name |
Name of the column this histogram represents. More... | |
bool | m_auto_update |
True if the histogram was created with the AUTO UPDATE option, false if MANUAL UPDATE. More... | |
Histogram base class.
This is an abstract class containing the interface and shared code for concrete histogram subclasses.
Histogram subclasses (Singleton, Equi_height) are constructed through factory methods in order to catch memory allocation errors during construction.
The histogram subclasses have no public copy or move constructors. In order to copy a histogram onto a given MEM_ROOT, use the public clone method. The clone method ensures that members of the histogram, such String type buckets, are also allocated on the given MEM_ROOT. Modifications to these methods need to be careful that histogram buckets are cloned/copied correctly.
|
strong |
|
protected |
Constructor.
mem_root | the mem_root where the histogram contents will be allocated | |
db_name | name of the database this histogram represents | |
tbl_name | name of the table this histogram represents | |
col_name | name of the column this histogram represents | |
type | the histogram type (equi-height, singleton) | |
data_type | the type of data that this histogram contains | |
[out] | error | is set to true if an error occurs |
|
protected |
Copy constructor.
This will make a copy of the provided histogram onto the provided MEM_ROOT.
mem_root | the mem_root where the histogram contents will be allocated | |
other | the histogram to copy | |
[out] | error | is set to true if an error occurs |
|
delete |
|
delete |
|
virtualdefault |
Destructor.
|
private |
An internal function for applying the correct function for the given operator.
op | The operator to apply |
value | The value to find the selectivity for. |
|
inlinestaticconstexprprotected |
String representation of the JSON field "auto-update".
|
inlinestaticconstexprprotected |
String representation of the JSON field "buckets".
Make a clone of the current histogram.
mem_root | the MEM_ROOT on which the new histogram will be allocated. |
Implemented in histograms::Equi_height< T >, and histograms::Singleton< T >.
|
inlinestaticconstexpr |
String representation of the JSON field "collation-id".
|
inlinestaticconstexpr |
String representation of the JSON field "data-type".
|
inlinestaticconstexpr |
String representation of the histogram type EQUI-HEIGHT.
bool histograms::Histogram::extract_json_dom_value | ( | const Json_dom * | json_dom, |
double * | out, | ||
Error_context * | context | ||
) |
bool histograms::Histogram::extract_json_dom_value | ( | const Json_dom * | json_dom, |
longlong * | out, | ||
Error_context * | context | ||
) |
bool histograms::Histogram::extract_json_dom_value | ( | const Json_dom * | json_dom, |
my_decimal * | out, | ||
Error_context * | context | ||
) |
bool histograms::Histogram::extract_json_dom_value | ( | const Json_dom * | json_dom, |
MYSQL_TIME * | out, | ||
Error_context * | context | ||
) |
bool histograms::Histogram::extract_json_dom_value | ( | const Json_dom * | json_dom, |
String * | out, | ||
Error_context * | context | ||
) |
|
protected |
Return the value that is contained in the JSON DOM object.
For most types, this function simply returns the contained value. For String values, the value is allocated on this histograms MEM_ROOT before it is returned. This allows the String value to survive the entire lifetime of the histogram object.
json_dom | the JSON DOM object to extract the value from |
out | the value from the JSON DOM object |
context | error context for validation |
bool histograms::Histogram::extract_json_dom_value | ( | const Json_dom * | json_dom, |
ulonglong * | out, | ||
Error_context * | context | ||
) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
private |
|
private |
|
inline |
|
private |
An internal function for getting the selecitvity estimation.
This function will cast the histogram to the correct class (using down_cast) and pass the given value on to the correct selectivity estimation function for that class.
value | The value to estimate the selectivity for. |
|
inline |
|
inline |
double histograms::Histogram::get_null_values_fraction | ( | ) | const |
|
pure virtual |
Implemented in histograms::Equi_height< T >, and histograms::Singleton< T >.
|
inline |
|
pure virtual |
Get the estimated number of distinct non-NULL values.
Implemented in histograms::Equi_height< T >, and histograms::Singleton< T >.
|
private |
An internal function for getting a selectivity estimate prior to adustment.
|
inline |
bool histograms::Histogram::get_selectivity | ( | Item ** | items, |
size_t | item_count, | ||
enum_operator | op, | ||
double * | selectivity | ||
) | const |
Get selectivity estimation.
This function will try and get the selectivity estimation for a predicate on the form "COLUMN OPERATOR CONSTANT", for instance "SELECT * FROM t1 WHERE col1 > 23;".
This function will take care of several of things, for instance checking that the value we are estimating the selectivity for is a constant value.
The order of the Items provided does not matter. For instance, of the operator argument given is "EQUALS_TO", it does not matter if the constant value is provided as the first or the second argument; this function will take care of this.
items | an array of items that contains both the field we are estimating the selectivity for, as well as the user-provided constant values. | |
item_count | the number of Items in the Item array. | |
op | the predicate operator | |
[out] | selectivity | the calculated selectivity if a usable histogram was found |
true | if an error occurred (the Item provided was not a constant value or similar). |
|
private |
An internal function for getting the selecitvity estimation.
This function will read/evaluate the value from the given Item, and pass this value on to the correct selectivity estimation function based on the data type of the histogram. For instance, if the data type of the histogram is INT, we will call "val_int" on the Item to evaluate the value as an integer and pass this value on to the next function.
item | The Item to read/evaluate the value from. | |
op | The operator we are estimating the selectivity for. | |
typelib | In the case of ENUM or SET data type, this parameter holds the type information. This is needed in order to map a string representation of an ENUM/SET value into its correct integer representation (ENUM/SET values are stored as integer values in the histogram). | |
[out] | selectivity | The estimated selectivity, between 0.0 and 1.0 inclusive. |
|
inline |
|
protected |
Write the data type of this histogram into a JSON object.
json_object | the JSON object where we will write the histogram data type |
|
pure virtual |
Converts the histogram to a JSON object.
[in,out] | json_object | output where the histogram is to be stored. The caller is responsible for allocating/deallocating the JSON object |
Implemented in histograms::Equi_height< T >, and histograms::Singleton< T >.
|
inlinestaticconstexpr |
String representation of the JSON field "histogram-type".
|
pure virtual |
Returns the histogram type as a readable string.
Implemented in histograms::Equi_height< T >, and histograms::Singleton< T >.
|
protectedpure virtual |
Populate the histogram with data from the provided JSON object.
The base class also provides an implementation that subclasses must call in order to populate fields that are shared among all histogram types (character set, null values fraction).
json_object | the JSON object to read the histogram data from |
context | error context for validation |
Implemented in histograms::Equi_height< T >, and histograms::Singleton< T >.
|
static |
Converts JSON object to a histogram.
mem_root | MEM_ROOT where the histogram will be allocated |
schema_name | the schema name |
table_name | the table name |
column_name | the column name |
json_object | output where the histogram is stored |
context | error context for validation |
|
inlinestaticconstexprprotected |
String representation of the JSON field "last-updated".
|
inlinestaticconstexprprotected |
String representation of the JSON field "null-values".
|
inlinestaticconstexprprotected |
String representation of the JSON field "number-of-buckets-specified".
|
inlinestaticconstexprprotected |
|
inline |
Sets the auto update property for the histogram.
|
inlinestaticconstexpr |
String representation of the histogram type SINGLETON.
bool histograms::Histogram::store_histogram | ( | THD * | thd | ) | const |
Store this histogram to persistent storage (data dictionary).
The MEM_ROOT that the histogram is allocated on is transferred to the dictionary.
thd | Thread handler. |
|
private |
True if the histogram was created with the AUTO UPDATE option, false if MANUAL UPDATE.
|
protected |
The character set for the data stored.
|
private |
Name of the column this histogram represents.
|
private |
The type of the data this histogram contains.
|
private |
Name of the database this histogram represents.
|
private |
The type of this histogram.
|
private |
The MEM_ROOT where the histogram contents will be allocated.
|
protected |
The fraction of NULL values in the histogram (between 0.0 and 1.0).
|
protected |
The number of buckets originally specified.
|
protected |
|
private |
Name of the table this histogram represents.