1#ifndef HISTOGRAMS_HISTOGRAM_INCLUDED
2#define HISTOGRAMS_HISTOGRAM_INCLUDED
69struct Histogram_comparator;
136 std::map<T, ha_rows, Histogram_comparator, value_map_allocator<T>>;
144 std::map<std::string, Message, std::less<std::string>,
263 template <
typename T>
357 return "number-of-buckets-specified";
372 const std::string &tbl_name,
const std::string &col_name,
452 double *selectivity)
const;
477 double *selectivity)
const;
608 const std::string &schema_name,
610 const std::string &column_name,
661 double *selectivity)
const;
704 size_t num_buckets,
const std::string &
db_name,
705 const std::string &tbl_name,
706 const std::string &col_name);
780 const char *old_table_name,
const char *new_schema_name,
785 const std::string &column_name,
786 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:173
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:373
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:68
Stateless_allocator is a C++ STL memory allocator skeleton based on Malloc_allocator,...
Definition: stateless_allocator.h:92
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Error context to validate given JSON object which represents a histogram.
Definition: histogram.h:207
Field * m_field
The field for checking endpoint values.
Definition: histogram.h:290
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:238
Error_context()
Default constructor.
Definition: histogram.h:212
Error_context(THD *thd, Field *field, results_map *results)
Constructor.
Definition: histogram.h:223
Field * field() const
Return data-type of field in context if present.
Definition: histogram.h:284
results_map * m_results
Where reported errors are stored.
Definition: histogram.h:292
bool m_binary
Whether or not the JSON object to process is in binary format.
Definition: histogram.h:294
THD * m_thd
Thread context for error handlers.
Definition: histogram.h:288
void report_missing_attribute(const std::string &name)
Report to this context that a required attribute is missing.
Definition: histogram.cc:226
bool check_value(T *v)
Check if the value is in the field definition domain.
Definition: histogram.cc:310
void report_global(Message err_code)
Report a global error to this context.
Definition: histogram.cc:214
bool binary() const
Tell whether the input json is an internal persisted copy or a user-defined input.
Definition: histogram.h:275
Histogram base class.
Definition: histogram.h:312
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:342
Value_map_type get_data_type() const
Definition: histogram.h:575
double get_equal_to_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:1813
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:430
static constexpr const char * data_type_str()
String representation of the JSON field "data-type".
Definition: histogram.h:321
double m_sampling_rate
Definition: histogram.h:333
static constexpr const char * collation_id_str()
String representation of the JSON field "collation-id".
Definition: histogram.h:324
double get_less_than_selectivity_dispatcher(const T &value) const
An internal function for getting the selecitvity estimation.
Definition: histogram.cc:1774
static constexpr const char * buckets_str()
String representation of the JSON field "buckets".
Definition: histogram.h:345
static constexpr const char * numer_of_buckets_specified_str()
String representation of the JSON field "number-of-buckets-specified".
Definition: histogram.h:356
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:552
const enum_histogram_type m_hist_type
The type of this histogram.
Definition: histogram.h:433
virtual bool histogram_to_json(Json_object *json_object) const =0
Converts the histogram to a JSON object.
Definition: histogram.cc:387
const CHARSET_INFO * m_charset
The character set for the data stored.
Definition: histogram.h:339
static constexpr const char * last_updated_str()
String representation of the JSON field "last-updated".
Definition: histogram.h:348
LEX_CSTRING m_table_name
Name of the table this histogram represents.
Definition: histogram.h:442
Histogram(const Histogram &other)=delete
size_t get_num_buckets_specified() const
Definition: histogram.h:581
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:2047
static constexpr const char * equi_height_str()
String representation of the histogram type EQUI-HEIGHT.
Definition: histogram.h:330
double get_non_null_values_fraction() const
Definition: histogram.h:666
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:2001
double m_null_values_fraction
The fraction of NULL values in the histogram (between 0.0 and 1.0).
Definition: histogram.h:336
const Value_map_type m_data_type
The type of the data this histogram contains.
Definition: histogram.h:436
const LEX_CSTRING get_database_name() const
Definition: histogram.h:526
LEX_CSTRING m_column_name
Name of the column this histogram represents.
Definition: histogram.h:445
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:1876
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:1860
const CHARSET_INFO * get_character_set() const
Definition: histogram.h:549
const LEX_CSTRING get_table_name() const
Definition: histogram.h:531
double get_null_values_fraction() const
Definition: histogram.cc:432
MEM_ROOT * get_mem_root() const
Definition: histogram.h:521
enum_histogram_type get_histogram_type() const
Definition: histogram.h:541
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:644
LEX_CSTRING m_database_name
Name of the database this histogram represents.
Definition: histogram.h:439
bool store_histogram(THD *thd) const
Store this histogram to persistent storage (data dictionary).
Definition: histogram.cc:1581
static constexpr const char * histogram_type_str()
String representation of the JSON field "histogram-type".
Definition: histogram.h:318
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:741
static constexpr const char * singleton_str()
String representation of the histogram type SINGLETON.
Definition: histogram.h:327
static constexpr const char * sampling_rate_str()
Definition: histogram.h:353
double get_greater_than_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:1793
const LEX_CSTRING get_column_name() const
Definition: histogram.h:536
enum_histogram_type
All supported histogram types in MySQL.
Definition: histogram.h:315
static constexpr const char * null_values_str()
String representation of the JSON field "null-values".
Definition: histogram.h:351
static MEM_ROOT mem_root
Definition: client_plugin.cc:110
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
This file includes constants used by all storage engines.
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
Definition: column_statistics.h:34
std::set< std::string, std::less< std::string >, Histogram_key_allocator< std::string > > columns_set
Definition: histogram.h:139
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:1487
std::map< std::string, Message, std::less< std::string >, Histogram_key_allocator< std::pair< const std::string, Message > > > results_map
Definition: histogram.h:145
Message
Definition: histogram.h:83
@ 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
enum_operator
The different operators we can ask histogram statistics for selectivity estimations.
Definition: histogram.h:151
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:1712
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:442
bool drop_histograms(THD *thd, Table_ref &table, const columns_set &columns, bool needs_lock, results_map &results)
Drop histograms for a set of columns in a given table.
Definition: histogram.cc:1497
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:1238
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:1751
static const double INVALID_NULL_VALUES_FRACTION
The default (and invalid) value for "m_null_values_fraction".
Definition: histogram.h:81
std::map< T, ha_rows, Histogram_comparator, value_map_allocator< T > > value_map_type
Definition: histogram.h:136
Value_map_type
Datatypes that a Value_map and histogram can hold (including the invalid type).
Definition: value_map_type.h:33
bool empty(const Histogram &histogram)
Return true if 'histogram' was built on an empty table.
Definition: histogram.h:672
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:33
Definition: m_ctype.h:385
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
Definition: mysql_lex_string.h:35
Definition: histogram.h:124
void * operator()(size_t s) const
Definition: histogram.cc:117