1#ifndef HISTOGRAMS_HISTOGRAM_INCLUDED
2#define HISTOGRAMS_HISTOGRAM_INCLUDED
70struct Histogram_comparator;
138 std::map<T, ha_rows, Histogram_comparator, value_map_allocator<T>>;
146 std::map<std::string, Message, std::less<std::string>,
265 template <
typename T>
359 return "number-of-buckets-specified";
377 const std::string &tbl_name,
const std::string &col_name,
461 double *selectivity)
const;
486 double *selectivity)
const;
628 const std::string &schema_name,
630 const std::string &column_name,
682 double *selectivity)
const;
725 size_t num_buckets,
const std::string &
db_name,
726 const std::string &tbl_name,
727 const std::string &col_name);
897 const char *old_table_name,
const char *new_schema_name,
902 const std::string &column_name,
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:936
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:369
Mem_root_allocator is a C++ STL memory allocator based on MEM_ROOT.
Definition: mem_root_allocator.h:68
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
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:36
Error context to validate given JSON object which represents a histogram.
Definition: histogram.h:209
Field * m_field
The field for checking endpoint values.
Definition: histogram.h:292
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:244
Error_context()
Default constructor.
Definition: histogram.h:214
Error_context(THD *thd, Field *field, results_map *results)
Constructor.
Definition: histogram.h:225
Field * field() const
Return data-type of field in context if present.
Definition: histogram.h:286
results_map * m_results
Where reported errors are stored.
Definition: histogram.h:294
bool m_binary
Whether or not the JSON object to process is in binary format.
Definition: histogram.h:296
THD * m_thd
Thread context for error handlers.
Definition: histogram.h:290
void report_missing_attribute(const std::string &name)
Report to this context that a required attribute is missing.
Definition: histogram.cc:232
bool check_value(T *v)
Check if the value is in the field definition domain.
Definition: histogram.cc:292
void report_global(Message err_code)
Report a global error to this context.
Definition: histogram.cc:220
bool binary() const
Tell whether the input json is an internal persisted copy or a user-defined input.
Definition: histogram.h:277
Histogram base class.
Definition: histogram.h:314
static constexpr const char * auto_update_str()
String representation of the JSON field "auto-update".
Definition: histogram.h:363
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:344
Value_map_type get_data_type() const
Definition: histogram.h:584
double get_equal_to_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:2169
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:435
static constexpr const char * data_type_str()
String representation of the JSON field "data-type".
Definition: histogram.h:323
double m_sampling_rate
Definition: histogram.h:335
static constexpr const char * collation_id_str()
String representation of the JSON field "collation-id".
Definition: histogram.h:326
double get_less_than_selectivity_dispatcher(const T &value) const
An internal function for getting the selecitvity estimation.
Definition: histogram.cc:2130
static constexpr const char * buckets_str()
String representation of the JSON field "buckets".
Definition: histogram.h:347
static constexpr const char * numer_of_buckets_specified_str()
String representation of the JSON field "number-of-buckets-specified".
Definition: histogram.h:358
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:561
const enum_histogram_type m_hist_type
The type of this histogram.
Definition: histogram.h:438
virtual bool histogram_to_json(Json_object *json_object) const =0
Converts the histogram to a JSON object.
Definition: histogram.cc:367
const CHARSET_INFO * m_charset
The character set for the data stored.
Definition: histogram.h:341
static constexpr const char * last_updated_str()
String representation of the JSON field "last-updated".
Definition: histogram.h:350
void set_auto_update(bool auto_update)
Sets the auto update property for the histogram.
Definition: histogram.h:601
LEX_CSTRING m_table_name
Name of the table this histogram represents.
Definition: histogram.h:447
Histogram(const Histogram &other)=delete
size_t get_num_buckets_specified() const
Definition: histogram.h:590
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:2403
static constexpr const char * equi_height_str()
String representation of the histogram type EQUI-HEIGHT.
Definition: histogram.h:332
double get_non_null_values_fraction() const
Definition: histogram.h:687
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:2357
double m_null_values_fraction
The fraction of NULL values in the histogram (between 0.0 and 1.0).
Definition: histogram.h:338
bool m_auto_update
True if the histogram was created with the AUTO UPDATE option, false if MANUAL UPDATE.
Definition: histogram.h:454
const Value_map_type m_data_type
The type of the data this histogram contains.
Definition: histogram.h:441
const LEX_CSTRING get_database_name() const
Definition: histogram.h:535
LEX_CSTRING m_column_name
Name of the column this histogram represents.
Definition: histogram.h:450
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:2232
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:2216
const CHARSET_INFO * get_character_set() const
Definition: histogram.h:558
bool get_auto_update() const
Definition: histogram.h:596
const LEX_CSTRING get_table_name() const
Definition: histogram.h:540
double get_null_values_fraction() const
Definition: histogram.cc:417
MEM_ROOT * get_mem_root() const
Definition: histogram.h:530
enum_histogram_type get_histogram_type() const
Definition: histogram.h:550
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:629
LEX_CSTRING m_database_name
Name of the database this histogram represents.
Definition: histogram.h:444
bool store_histogram(THD *thd) const
Store this histogram to persistent storage (data dictionary).
Definition: histogram.cc:1946
static constexpr const char * histogram_type_str()
String representation of the JSON field "histogram-type".
Definition: histogram.h:320
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:740
static constexpr const char * singleton_str()
String representation of the histogram type SINGLETON.
Definition: histogram.h:329
static constexpr const char * sampling_rate_str()
Definition: histogram.h:355
double get_greater_than_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:2149
const LEX_CSTRING get_column_name() const
Definition: histogram.h:545
enum_histogram_type
All supported histogram types in MySQL.
Definition: histogram.h:317
static constexpr const char * null_values_str()
String representation of the JSON field "null-values".
Definition: histogram.h:353
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
This file includes constants used by all storage engines.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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:141
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:1900
std::map< std::string, Message, std::less< std::string >, Histogram_key_allocator< std::pair< const std::string, Message > > > results_map
Definition: histogram.h:147
Message
Definition: histogram.h:84
@ 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
@ SYSTEM_SCHEMA_NOT_SUPPORTED
@ 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 update_share_histograms(THD *thd, Table_ref *table)
Retrieve an updated snapshot of the histograms on a table directly from the dictionary (in an ineffic...
Definition: histogram.cc:1485
bool auto_update_table_histograms_from_background_thread(THD *thd, const std::string &db_name, const std::string &table_name)
Updates existing histograms on a table that were specified with the AUTO UPDATE option.
Definition: histogram.cc:1750
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:1910
enum_operator
The different operators we can ask histogram statistics for selectivity estimations.
Definition: histogram.h:153
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:2067
bool auto_update_table_histograms(THD *thd, Table_ref *table)
Updates existing histograms on a table that were specified with the AUTO UPDATE option.
Definition: histogram.cc:1628
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:427
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:2106
bool update_histograms(THD *thd, Table_ref *table, Mem_root_array< HistogramSetting > *settings, results_map &results)
Create or update histograms for a set of columns of a given table.
Definition: histogram.cc:1406
static const double INVALID_NULL_VALUES_FRACTION
The default (and invalid) value for "m_null_values_fraction".
Definition: histogram.h:82
std::map< T, ha_rows, Histogram_comparator, value_map_allocator< T > > value_map_type
Definition: histogram.h:138
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:693
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:29
Definition: m_ctype.h:423
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
A simple struct containing the settings for a histogram to be built.
Definition: histogram.h:732
bool auto_update
True if AUTO UPDATE, false for MANUAL UPDATE.
Definition: histogram.h:745
LEX_STRING data
Holds the JSON specification of the histogram for the UPDATE HISTOGRAM ... USING DATA command,...
Definition: histogram.h:742
Field * field
A pointer to the field, used internally by update_histograms().
Definition: histogram.h:748
size_t num_buckets
The target number of buckets for the histogram.
Definition: histogram.h:738
const char * column_name
A null-terminated C-style string with the name of the column to build the histogram for.
Definition: histogram.h:735
Definition: histogram.h:126
void * operator()(size_t s) const
Definition: histogram.cc:123