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

Equi-height bucket. More...

#include <equi_height.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
 Returns the "distance" between lower inclusive value and the argument "value". More...
 
double value_probability () const
 Calculate how high the probability is for a single value existing in the bucket. 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 value_probability () const
 
double value_probability () 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

const T m_lower_inclusive
 Lower inclusive value contained in this bucket. More...
 
const T m_upper_inclusive
 Upper inclusive value contained in this bucket. More...
 
const double m_cumulative_frequency
 The cumulative frequency. 0.0 <= m_cumulative_frequency <= 1.0. More...
 
const 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

Returns the "distance" between lower inclusive value and the argument "value".

The return value is a number between 0.0 and 1.0. A value of 0.0 indicates that "value" is equal to or less than the lower inclusive value. A value of 1.0 indicates that "value" is equal or greater to the upper inclusive value.

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

◆ 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

◆ value_probability() [1/3]

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

Calculate how high the probability is for a single value existing in the bucket.

This is basically equal to the number of distinct values in the bucket divided by the number of possible values in the bucket range. For strings, double, decimals and such, the probability will be very low since the number of possible values is VERY big. For integer values, the probability may be rather high if the difference between the lower and upper value is low.

Returns
Probability of a value existing in the bucket, between 0.0 and 1.0 inclusive.

◆ value_probability() [2/3]

double histograms::equi_height::Bucket< longlong >::value_probability ( ) const

◆ value_probability() [3/3]

double histograms::equi_height::Bucket< ulonglong >::value_probability ( ) const

Member Data Documentation

◆ m_cumulative_frequency

template<class T >
const 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 >
const T histograms::equi_height::Bucket< T >::m_lower_inclusive
private

Lower inclusive value contained in this bucket.

◆ m_num_distinct

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

Number of distinct values in this bucket.

◆ m_upper_inclusive

template<class T >
const 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: