1#ifndef HISTOGRAMS_HISTOGRAM_INCLUDED
2#define HISTOGRAMS_HISTOGRAM_INCLUDED
70struct Histogram_comparator;
139 std::map<T, ha_rows, Histogram_comparator, value_map_allocator<T>>;
147 std::map<std::string, Message, std::less<std::string>,
266 template <
typename T>
360 return "number-of-buckets-specified";
378 const std::string &tbl_name,
const std::string &col_name,
462 double *selectivity)
const;
487 double *selectivity)
const;
629 const std::string &schema_name,
631 const std::string &column_name,
683 double *selectivity)
const;
726 size_t num_buckets,
const std::string &
db_name,
727 const std::string &tbl_name,
728 const std::string &col_name);
898 const char *old_table_name,
const char *new_schema_name,
903 const std::string &column_name,
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:929
JSON DOM abstract base class.
Definition: json_dom.h:179
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:68
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
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:210
Field * m_field
The field for checking endpoint values.
Definition: histogram.h:293
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:245
Error_context()
Default constructor.
Definition: histogram.h:215
Error_context(THD *thd, Field *field, results_map *results)
Constructor.
Definition: histogram.h:226
Field * field() const
Return data-type of field in context if present.
Definition: histogram.h:287
results_map * m_results
Where reported errors are stored.
Definition: histogram.h:295
bool m_binary
Whether or not the JSON object to process is in binary format.
Definition: histogram.h:297
THD * m_thd
Thread context for error handlers.
Definition: histogram.h:291
void report_missing_attribute(const std::string &name)
Report to this context that a required attribute is missing.
Definition: histogram.cc:233
bool check_value(T *v)
Check if the value is in the field definition domain.
Definition: histogram.cc:299
void report_global(Message err_code)
Report a global error to this context.
Definition: histogram.cc:221
bool binary() const
Tell whether the input json is an internal persisted copy or a user-defined input.
Definition: histogram.h:278
Histogram base class.
Definition: histogram.h:315
static constexpr const char * auto_update_str()
String representation of the JSON field "auto-update".
Definition: histogram.h:364
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:345
Value_map_type get_data_type() const
Definition: histogram.h:585
double get_equal_to_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:2277
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:436
static constexpr const char * data_type_str()
String representation of the JSON field "data-type".
Definition: histogram.h:324
double m_sampling_rate
Definition: histogram.h:336
static constexpr const char * collation_id_str()
String representation of the JSON field "collation-id".
Definition: histogram.h:327
double get_less_than_selectivity_dispatcher(const T &value) const
An internal function for getting the selecitvity estimation.
Definition: histogram.cc:2238
static constexpr const char * buckets_str()
String representation of the JSON field "buckets".
Definition: histogram.h:348
static constexpr const char * numer_of_buckets_specified_str()
String representation of the JSON field "number-of-buckets-specified".
Definition: histogram.h:359
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:562
const enum_histogram_type m_hist_type
The type of this histogram.
Definition: histogram.h:439
virtual bool histogram_to_json(Json_object *json_object) const =0
Converts the histogram to a JSON object.
Definition: histogram.cc:376
const CHARSET_INFO * m_charset
The character set for the data stored.
Definition: histogram.h:342
static constexpr const char * last_updated_str()
String representation of the JSON field "last-updated".
Definition: histogram.h:351
void set_auto_update(bool auto_update)
Sets the auto update property for the histogram.
Definition: histogram.h:602
LEX_CSTRING m_table_name
Name of the table this histogram represents.
Definition: histogram.h:448
Histogram(const Histogram &other)=delete
size_t get_num_buckets_specified() const
Definition: histogram.h:591
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:2531
static constexpr const char * equi_height_str()
String representation of the histogram type EQUI-HEIGHT.
Definition: histogram.h:333
double get_non_null_values_fraction() const
Definition: histogram.h:688
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:2485
double m_null_values_fraction
The fraction of NULL values in the histogram (between 0.0 and 1.0).
Definition: histogram.h:339
bool m_auto_update
True if the histogram was created with the AUTO UPDATE option, false if MANUAL UPDATE.
Definition: histogram.h:455
const Value_map_type m_data_type
The type of the data this histogram contains.
Definition: histogram.h:442
const LEX_CSTRING get_database_name() const
Definition: histogram.h:536
LEX_CSTRING m_column_name
Name of the column this histogram represents.
Definition: histogram.h:451
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:2347
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:2331
const CHARSET_INFO * get_character_set() const
Definition: histogram.h:559
bool get_auto_update() const
Definition: histogram.h:597
const LEX_CSTRING get_table_name() const
Definition: histogram.h:541
double get_null_values_fraction() const
Definition: histogram.cc:426
MEM_ROOT * get_mem_root() const
Definition: histogram.h:531
enum_histogram_type get_histogram_type() const
Definition: histogram.h:551
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:638
LEX_CSTRING m_database_name
Name of the database this histogram represents.
Definition: histogram.h:445
bool store_histogram(THD *thd) const
Store this histogram to persistent storage (data dictionary).
Definition: histogram.cc:2054
static constexpr const char * histogram_type_str()
String representation of the JSON field "histogram-type".
Definition: histogram.h:321
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:749
static constexpr const char * singleton_str()
String representation of the histogram type SINGLETON.
Definition: histogram.h:330
static constexpr const char * sampling_rate_str()
Definition: histogram.h:356
double get_greater_than_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:2257
const LEX_CSTRING get_column_name() const
Definition: histogram.h:546
enum_histogram_type
All supported histogram types in MySQL.
Definition: histogram.h:318
static constexpr const char * null_values_str()
String representation of the JSON field "null-values".
Definition: histogram.h:354
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
#define T
Definition: jit_executor_value.cc:373
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:44
Definition: column_statistics.h:34
std::set< std::string, std::less< std::string >, Histogram_key_allocator< std::string > > columns_set
Definition: histogram.h:142
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:2008
std::map< std::string, Message, std::less< std::string >, Histogram_key_allocator< std::pair< const std::string, Message > > > results_map
Definition: histogram.h:148
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:1592
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:1858
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:2018
enum_operator
The different operators we can ask histogram statistics for selectivity estimations.
Definition: histogram.h:154
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:2175
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:1735
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:436
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:2214
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:1511
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:139
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:694
entry::Table Table
Definition: select.h:51
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
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
Definition: m_ctype.h:421
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:733
bool auto_update
True if AUTO UPDATE, false for MANUAL UPDATE.
Definition: histogram.h:746
LEX_STRING data
Holds the JSON specification of the histogram for the UPDATE HISTOGRAM ... USING DATA command,...
Definition: histogram.h:743
Field * field
A pointer to the field, used internally by update_histograms().
Definition: histogram.h:749
size_t num_buckets
The target number of buckets for the histogram.
Definition: histogram.h:739
const char * column_name
A null-terminated C-style string with the name of the column to build the histogram for.
Definition: histogram.h:736
Definition: histogram.h:127
void * operator()(size_t s) const
Definition: histogram.cc:123