1#ifndef HISTOGRAMS_HISTOGRAM_INCLUDED
2#define HISTOGRAMS_HISTOGRAM_INCLUDED
68struct Histogram_comparator;
135 std::map<T, ha_rows, Histogram_comparator, value_map_allocator<T>>;
143 std::map<std::string, Message, std::less<std::string>,
241 template <
typename T>
336 return "number-of-buckets-specified";
351 const std::string &tbl_name,
const std::string &col_name,
431 double *selectivity)
const;
456 double *selectivity)
const;
587 const std::string &schema_name,
589 const std::string &column_name,
640 double *selectivity)
const;
683 size_t num_buckets,
const std::string &
db_name,
684 const std::string &tbl_name,
685 const std::string &col_name);
758 const char *old_table_name,
const char *new_schema_name,
763 const std::string &column_name,
764 const Histogram **histogram);
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
JSON DOM abstract base class.
Definition: json_dom.h:174
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:374
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:67
Stateless_allocator is a C++ STL memory allocator skeleton based on Malloc_allocator,...
Definition: stateless_allocator.h:91
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Error context to validate given JSON object which represents a histogram.
Definition: histogram.h:184
Field * m_field
The field for checking endpoint values.
Definition: histogram.h:269
void report_node(const Json_dom *dom, Message err_code)
Report to this context that an error occurs on the given dom node.
Definition: histogram.cc:250
Error_context()
Default constructor.
Definition: histogram.h:187
Field * field() const
Return data-type of field in context if present.
Definition: histogram.h:261
uchar m_buffer[MAX_FIELD_WIDTH]
Buffer for m_field.
Definition: histogram.h:267
results_map * m_results
Where reported errors are stored.
Definition: histogram.h:271
bool m_binary
Whether or not the JSON object to process is in binary format.
Definition: histogram.h:273
THD * m_thd
Thread context for error handlers.
Definition: histogram.h:265
void report_missing_attribute(const std::string &name)
Report to this context that a required attribute is missing.
Definition: histogram.cc:238
bool check_value(T *v)
Check if the value is in the field definition domain.
Definition: histogram.cc:330
void report_global(Message err_code)
Report a global error to this context.
Definition: histogram.cc:226
bool binary() const
Tell whether the input json is an internal persisted copy or a user-defined input.
Definition: histogram.h:253
~Error_context()
Destructor.
Definition: histogram.h:205
Histogram base class.
Definition: histogram.h:291
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.
virtual std::string histogram_type_to_str() const =0
Returns the histogram type as a readable string.
size_t m_num_buckets_specified
The number of buckets originally specified.
Definition: histogram.h:321
Value_map_type get_data_type() const
Definition: histogram.h:554
double get_equal_to_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:1719
virtual size_t get_num_buckets() const =0
MEM_ROOT * m_mem_root
The MEM_ROOT where the histogram contents will be allocated.
Definition: histogram.h:409
static constexpr const char * data_type_str()
String representation of the JSON field "data-type".
Definition: histogram.h:300
double m_sampling_rate
Definition: histogram.h:312
static constexpr const char * collation_id_str()
String representation of the JSON field "collation-id".
Definition: histogram.h:303
double get_less_than_selectivity_dispatcher(const T &value) const
An internal function for getting the selecitvity estimation.
Definition: histogram.cc:1680
static constexpr const char * buckets_str()
String representation of the JSON field "buckets".
Definition: histogram.h:324
static constexpr const char * numer_of_buckets_specified_str()
String representation of the JSON field "number-of-buckets-specified".
Definition: histogram.h:335
virtual ~Histogram()=default
Destructor.
virtual size_t get_num_distinct_values() const =0
Get the estimated number of distinct non-NULL values.
double get_sampling_rate() const
Definition: histogram.h:531
const enum_histogram_type m_hist_type
The type of this histogram.
Definition: histogram.h:412
virtual bool histogram_to_json(Json_object *json_object) const =0
Converts the histogram to a JSON object.
Definition: histogram.cc:407
const CHARSET_INFO * m_charset
The character set for the data stored.
Definition: histogram.h:318
static constexpr const char * last_updated_str()
String representation of the JSON field "last-updated".
Definition: histogram.h:327
LEX_CSTRING m_table_name
Name of the table this histogram represents.
Definition: histogram.h:421
Histogram(const Histogram &other)=delete
size_t get_num_buckets_specified() const
Definition: histogram.h:560
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.
Definition: histogram.cc:1953
static constexpr const char * equi_height_str()
String representation of the histogram type EQUI-HEIGHT.
Definition: histogram.h:309
double get_non_null_values_fraction() const
Definition: histogram.h:645
virtual Histogram * clone(MEM_ROOT *mem_root) const =0
Make a clone of the current histogram.
bool get_selectivity(Item **items, size_t item_count, enum_operator op, double *selectivity) const
Get selectivity estimation.
Definition: histogram.cc:1907
double m_null_values_fraction
The fraction of NULL values in the histogram (between 0.0 and 1.0).
Definition: histogram.h:315
const Value_map_type m_data_type
The type of the data this histogram contains.
Definition: histogram.h:415
const LEX_CSTRING get_database_name() const
Definition: histogram.h:505
LEX_CSTRING m_column_name
Name of the column this histogram represents.
Definition: histogram.h:424
bool get_selectivity_dispatcher(Item *item, const enum_operator op, const TYPELIB *typelib, double *selectivity) const
An internal function for getting the selecitvity estimation.
Definition: histogram.cc:1782
double apply_operator(const enum_operator op, const T &value) const
An internal function for applying the correct function for the given operator.
Definition: histogram.cc:1766
const CHARSET_INFO * get_character_set() const
Definition: histogram.h:528
const LEX_CSTRING get_table_name() const
Definition: histogram.h:510
double get_null_values_fraction() const
Definition: histogram.cc:452
MEM_ROOT * get_mem_root() const
Definition: histogram.h:500
enum_histogram_type get_histogram_type() const
Definition: histogram.h:520
virtual bool json_to_histogram(const Json_object &json_object, Error_context *context)=0
Populate the histogram with data from the provided JSON object.
Definition: histogram.cc:664
LEX_CSTRING m_database_name
Name of the database this histogram represents.
Definition: histogram.h:418
bool store_histogram(THD *thd) const
Store this histogram to persistent storage (data dictionary).
Definition: histogram.cc:1497
static constexpr const char * histogram_type_str()
String representation of the JSON field "histogram-type".
Definition: histogram.h:297
bool histogram_data_type_to_json(Json_object *json_object) const
Write the data type of this histogram into a JSON object.
Definition: histogram.cc:761
static constexpr const char * singleton_str()
String representation of the histogram type SINGLETON.
Definition: histogram.h:306
static constexpr const char * sampling_rate_str()
Definition: histogram.h:332
double get_greater_than_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:1699
const LEX_CSTRING get_column_name() const
Definition: histogram.h:515
enum_histogram_type
All supported histogram types in MySQL.
Definition: histogram.h:294
static constexpr const char * null_values_str()
String representation of the JSON field "null-values".
Definition: histogram.h:330
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
This file includes constants used by all storage engines.
unsigned char uchar
Definition: my_inttypes.h:51
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Definition: column_statistics.h:33
std::set< std::string, std::less< std::string >, Histogram_key_allocator< std::string > > columns_set
Definition: histogram.h:138
bool drop_all_histograms(THD *thd, Table_ref &table, const dd::Table &table_definition, results_map &results)
Drop histograms for all columns in a given table.
Definition: histogram.cc:1451
std::map< std::string, Message, std::less< std::string >, Histogram_key_allocator< std::pair< const std::string, Message > > > results_map
Definition: histogram.h:144
Message
Definition: histogram.h:82
@ JSON_VALUE_OUT_OF_RANGE
@ JSON_INVALID_NUM_BUCKETS_SPECIFIED
@ JSON_VALUE_FORMAT_ERROR
@ JSON_CUMULATIVE_FREQUENCY_NOT_ASCENDING
@ JSON_INVALID_SAMPLING_RATE
@ JSON_WRONG_ATTRIBUTE_TYPE
@ MULTIPLE_COLUMNS_SPECIFIED
@ JSON_IMPOSSIBLE_EMPTY_EQUI_HEIGHT
@ JSON_UNSUPPORTED_CHARSET
@ JSON_INVALID_NULL_VALUES_FRACTION
@ COVERED_BY_SINGLE_PART_UNIQUE_INDEX
@ JSON_NUM_BUCKETS_MORE_THAN_SPECIFIED
@ JSON_INVALID_TOTAL_FREQUENCY
@ JSON_UNSUPPORTED_DATA_TYPE
@ JSON_VALUE_DESCENDING_IN_BUCKET
@ JSON_UNSUPPORTED_HISTOGRAM_TYPE
@ JSON_WRONG_BUCKET_TYPE_2
@ MULTIPLE_TABLES_SPECIFIED
@ JSON_VALUE_NOT_ASCENDING_1
@ JSON_VALUE_NOT_ASCENDING_2
@ JSON_WRONG_BUCKET_TYPE_4
@ JSON_INVALID_NUM_DISTINCT
bool drop_histograms(THD *thd, Table_ref &table, const columns_set &columns, results_map &results)
Drop histograms for a set of columns in a given table.
Definition: histogram.cc:1461
enum_operator
The different operators we can ask histogram statistics for selectivity estimations.
Definition: histogram.h:150
bool rename_histograms(THD *thd, const char *old_schema_name, const char *old_table_name, const char *new_schema_name, const char *new_table_name, results_map &results)
Rename histograms for all columns in a given table.
Definition: histogram.cc:1618
Histogram * build_histogram(MEM_ROOT *mem_root, const Value_map< T > &value_map, size_t num_buckets, const std::string &db_name, const std::string &tbl_name, const std::string &col_name)
Create a histogram from a value map.
Definition: histogram.cc:462
bool update_histogram(THD *thd, Table_ref *table, const columns_set &columns, int num_buckets, LEX_STRING data, results_map &results)
Create or update histograms for a set of columns of a given table.
Definition: histogram.cc:1258
bool find_histogram(THD *thd, const std::string &schema_name, const std::string &table_name, const std::string &column_name, const Histogram **histogram)
Definition: histogram.cc:1657
static const double INVALID_NULL_VALUES_FRACTION
The default (and invalid) value for "m_null_values_fraction".
Definition: histogram.h:80
std::map< T, ha_rows, Histogram_comparator, value_map_allocator< T > > value_map_type
Definition: histogram.h:135
Value_map_type
Datatypes that a Value_map and histogram can hold (including the invalid type).
Definition: value_map_type.h:32
bool empty(const Histogram &histogram)
Return true if 'histogram' was built on an empty table.
Definition: histogram.h:651
static int destroy(mysql_cond_t *that, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:42
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
required string type
Definition: replication_group_member_actions.proto:33
constexpr const int MAX_FIELD_WIDTH
Max column width + 1.
Definition: sql_const.h:65
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:422
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
Definition: histogram.h:123
void * operator()(size_t s) const
Definition: histogram.cc:116