MySQL 8.3.0
Source Code Documentation
histograms::equi_height::Bucket< T > Class Template Reference

Equi-height bucket. More...

#include <equi_height_bucket.h>

Public Member Functions

 Bucket (T lower, T upper, double freq, ha_rows num_distinct)
 Equi-height bucket constructor. More...
 
const T & get_lower_inclusive () const
 
const T & get_upper_inclusive () const
 
double get_cumulative_frequency () const
 
ha_rows get_num_distinct () const
 
bool bucket_to_json (Json_array *json_array) const
 Convert this equi-height bucket to a JSON array. More...
 
double get_distance_from_lower (const T &value) const
 Finds the relative location of "value" between bucket endpoints. More...
 
double get_distance_from_upper (const T &value) const
 Returns the fraction of all elements between bucket endpoints [a, b] that are strictly greater than "value". More...
 
double get_distance_from_lower (const double &value) const
 
double get_distance_from_lower (const String &value) const
 An attempt to calculate the distance for string values. More...
 
double get_distance_from_lower (const MYSQL_TIME &value) const
 
double get_distance_from_lower (const my_decimal &value) const
 
double get_distance_from_upper (const longlong &value) const
 
double get_distance_from_upper (const ulonglong &value) const
 

Private Member Functions

bool add_values_json_bucket (const double &lower_value, const double &upper_value, Json_array *json_array)
 
bool add_values_json_bucket (const String &lower_value, const String &upper_value, Json_array *json_array)
 
bool add_values_json_bucket (const ulonglong &lower_value, const ulonglong &upper_value, Json_array *json_array)
 
bool add_values_json_bucket (const longlong &lower_value, const longlong &upper_value, Json_array *json_array)
 
bool add_values_json_bucket (const MYSQL_TIME &lower_value, const MYSQL_TIME &upper_value, Json_array *json_array)
 
bool add_values_json_bucket (const my_decimal &lower_value, const my_decimal &upper_value, Json_array *json_array)
 

Static Private Member Functions

static bool add_values_json_bucket (const T &lower_value, const T &upper_value, Json_array *json_array)
 Add values to a JSON bucket. More...
 

Private Attributes

m_lower_inclusive
 Lower inclusive value contained in this bucket. More...
 
m_upper_inclusive
 Upper inclusive value contained in this bucket. More...
 
double m_cumulative_frequency
 The cumulative frequency. 0.0 <= m_cumulative_frequency <= 1.0. More...
 
ha_rows m_num_distinct
 Number of distinct values in this bucket. More...
 

Detailed Description

template<class T>
class histograms::equi_height::Bucket< T >

Equi-height bucket.

Constructor & Destructor Documentation

◆ Bucket()

template<typename T >
histograms::equi_height::Bucket< T >::Bucket ( lower,
upper,
double  freq,
ha_rows  num_distinct 
)

Equi-height bucket constructor.

Does nothing more than setting the member variables.

Parameters
lowerLower inclusive value.
upperUpper inclusive value.
freqThe cumulative frequency.
num_distinctNumber of distinct values in this bucket.

Member Function Documentation

◆ add_values_json_bucket() [1/7]

bool histograms::equi_height::Bucket< double >::add_values_json_bucket ( const double &  lower_value,
const double &  upper_value,
Json_array json_array 
)
private

◆ add_values_json_bucket() [2/7]

bool histograms::equi_height::Bucket< longlong >::add_values_json_bucket ( const longlong lower_value,
const longlong upper_value,
Json_array json_array 
)
private

◆ add_values_json_bucket() [3/7]

bool histograms::equi_height::Bucket< my_decimal >::add_values_json_bucket ( const my_decimal lower_value,
const my_decimal upper_value,
Json_array json_array 
)
private

◆ add_values_json_bucket() [4/7]

bool histograms::equi_height::Bucket< MYSQL_TIME >::add_values_json_bucket ( const MYSQL_TIME lower_value,
const MYSQL_TIME upper_value,
Json_array json_array 
)
private

◆ add_values_json_bucket() [5/7]

bool histograms::equi_height::Bucket< String >::add_values_json_bucket ( const String lower_value,
const String upper_value,
Json_array json_array 
)
private

◆ add_values_json_bucket() [6/7]

template<class T >
static bool histograms::equi_height::Bucket< T >::add_values_json_bucket ( const T &  lower_value,
const T &  upper_value,
Json_array json_array 
)
staticprivate

Add values to a JSON bucket.

This function adds the lower and upper inclusive value to the supplied JSON array. The lower value is added first.

Parameters
lower_valueThe lower inclusive value to add.
upper_valueThe upper inclusive value to add.
[out]json_arrayA JSON array where the bucket data is stored.
Returns
True on error, false otherwise.

◆ add_values_json_bucket() [7/7]

bool histograms::equi_height::Bucket< ulonglong >::add_values_json_bucket ( const ulonglong lower_value,
const ulonglong upper_value,
Json_array json_array 
)
private

◆ bucket_to_json()

template<typename T >
bool histograms::equi_height::Bucket< T >::bucket_to_json ( Json_array json_array) const

Convert this equi-height bucket to a JSON array.

This function will take the contents of the current equi-height bucket and put it in the output parameter "json_array". The result is an array with the following contents: Index 0: Lower inclusive value. Index 1: Upper inclusive value. Index 2: Cumulative frequency. Index 3: Number of distinct values.

Parameters
[out]json_arrayOutput where the bucket content is to be stored.
Returns
True on error, false otherwise.

◆ get_cumulative_frequency()

template<class T >
double histograms::equi_height::Bucket< T >::get_cumulative_frequency ( ) const
inline
Returns
Cumulative frequency.

◆ get_distance_from_lower() [1/5]

double histograms::equi_height::Bucket< double >::get_distance_from_lower ( const double &  value) const

◆ get_distance_from_lower() [2/5]

double histograms::equi_height::Bucket< my_decimal >::get_distance_from_lower ( const my_decimal value) const

◆ get_distance_from_lower() [3/5]

double histograms::equi_height::Bucket< MYSQL_TIME >::get_distance_from_lower ( const MYSQL_TIME value) const

◆ get_distance_from_lower() [4/5]

double histograms::equi_height::Bucket< String >::get_distance_from_lower ( const String value) const

An attempt to calculate the distance for string values.

It goes like this:

First we transform the lower inclusive value, the upper inclusive value and the query value (COLUMN = "query value") using the method "my_strnxfrm". The result of "my_strnfxfrm" is a transformed string that gives us the correct sort order by using "memcmp" on the transformed values. For example, the strings "110", "120" and "130" in utf8mb4_0900_ai_ci gives us the following byte values:

"110": 28 62 28 62 28 61 "120": 28 63 28 63 28 61 "130": 28 64 28 64 28 61

We then find the common prefix for these three transformed strings, which is the byte value 28 in this case. We remove this, and ends up with the following:

"110": 62 28 62 28 61 "120": 63 28 63 28 61 "130": 64 28 64 28 61

The reason for removing the common prefix is that if the eight first byte values are the same, the next step will fail.

We then make a 8-byte unsigned integer representation for each of these values by concatenating together all the byte values.

See also
uchar_array_to_64bit_unsigned

If the eight first bytes were equal, we would end up with equal values here. Do this for all three, and with these values we can find out the distance from the lower inclusive value to the "query value". Note that this will NOT be 100% accurate, but it will gives us a rough estimate (and a far better estimate than nothing at all).

Parameters
valueThe value to calculate the distance for.
Returns
The distance, between 0.0 and 1.0 inclusive.

◆ get_distance_from_lower() [5/5]

template<class T >
double histograms::equi_height::Bucket< T >::get_distance_from_lower ( const T &  value) const

Finds the relative location of "value" between bucket endpoints.

This is used to determine the fraction of a bucket to include in selectivity estimates in the case where the query value lies inside a bucket.

get_distance_from_lower returns the fraction of all elements between bucket endpoints [a, b] that lie in the interval [a, value), i.e., strictly less than value. For some histogram types the return value is only an estimate.

Parameters
valueThe value to calculate the distance for.
Returns
The distance between "value" and lower inclusive value.

◆ get_distance_from_upper() [1/3]

double histograms::equi_height::Bucket< longlong >::get_distance_from_upper ( const longlong value) const

◆ get_distance_from_upper() [2/3]

template<class T >
double histograms::equi_height::Bucket< T >::get_distance_from_upper ( const T &  value) const

Returns the fraction of all elements between bucket endpoints [a, b] that are strictly greater than "value".

For some histogram types the return value is only an estimate.

Returns
The distance between "value" and upper inclusive value.

◆ get_distance_from_upper() [3/3]

double histograms::equi_height::Bucket< ulonglong >::get_distance_from_upper ( const ulonglong value) const

◆ get_lower_inclusive()

template<class T >
const T & histograms::equi_height::Bucket< T >::get_lower_inclusive ( ) const
inline
Returns
Lower inclusive value.

◆ get_num_distinct()

template<class T >
ha_rows histograms::equi_height::Bucket< T >::get_num_distinct ( ) const
inline
Returns
Number of distinct values.

◆ get_upper_inclusive()

template<class T >
const T & histograms::equi_height::Bucket< T >::get_upper_inclusive ( ) const
inline
Returns
Upper inclusive value.

Member Data Documentation

◆ m_cumulative_frequency

template<class T >
double histograms::equi_height::Bucket< T >::m_cumulative_frequency
private

The cumulative frequency. 0.0 <= m_cumulative_frequency <= 1.0.

◆ m_lower_inclusive

template<class T >
T histograms::equi_height::Bucket< T >::m_lower_inclusive
private

Lower inclusive value contained in this bucket.

◆ m_num_distinct

template<class T >
ha_rows histograms::equi_height::Bucket< T >::m_num_distinct
private

Number of distinct values in this bucket.

◆ m_upper_inclusive

template<class T >
T histograms::equi_height::Bucket< T >::m_upper_inclusive
private

Upper inclusive value contained in this bucket.


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