MySQL 9.1.0
Source Code Documentation
|
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 | |
T | m_lower_inclusive |
Lower inclusive value contained in this bucket. More... | |
T | 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... | |
Equi-height bucket.
histograms::equi_height::Bucket< T >::Bucket | ( | T | lower, |
T | upper, | ||
double | freq, | ||
ha_rows | num_distinct | ||
) |
Equi-height bucket constructor.
Does nothing more than setting the member variables.
lower | Lower inclusive value. |
upper | Upper inclusive value. |
freq | The cumulative frequency. |
num_distinct | Number of distinct values in this bucket. |
|
private |
|
private |
|
private |
|
private |
|
private |
|
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.
lower_value | The lower inclusive value to add. | |
upper_value | The upper inclusive value to add. | |
[out] | json_array | A JSON array where the bucket data is stored. |
|
private |
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.
[out] | json_array | Output where the bucket content is to be stored. |
|
inline |
double histograms::equi_height::Bucket< double >::get_distance_from_lower | ( | const double & | value | ) | const |
double histograms::equi_height::Bucket< my_decimal >::get_distance_from_lower | ( | const my_decimal & | value | ) | const |
double histograms::equi_height::Bucket< MYSQL_TIME >::get_distance_from_lower | ( | const MYSQL_TIME & | value | ) | const |
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.
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).
value | The value to calculate the distance for. |
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.
value | The value to calculate the distance for. |
double histograms::equi_height::Bucket< longlong >::get_distance_from_upper | ( | const longlong & | value | ) | const |
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.
double histograms::equi_height::Bucket< ulonglong >::get_distance_from_upper | ( | const ulonglong & | value | ) | const |
|
inline |
|
inline |
|
inline |
|
private |
The cumulative frequency. 0.0 <= m_cumulative_frequency <= 1.0.
|
private |
Lower inclusive value contained in this bucket.
|
private |
Number of distinct values in this bucket.
|
private |
Upper inclusive value contained in this bucket.