MySQL 9.1.0
Source Code Documentation
histogram.cc File Reference

Histogram base class (implementation). More...

#include "sql/histograms/histogram.h"
#include <sys/types.h>
#include <algorithm>
#include <map>
#include <memory>
#include <new>
#include <random>
#include <string>
#include <vector>
#include "base64.h"
#include "decimal.h"
#include "field_types.h"
#include "lex_string.h"
#include "my_alloc.h"
#include "my_bitmap.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_sys.h"
#include "my_systime.h"
#include "my_time.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "scope_guard.h"
#include "sql-common/json_dom.h"
#include "sql-common/my_decimal.h"
#include "sql/auth/auth_common.h"
#include "sql/create_field.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/column.h"
#include "sql/dd/types/column_statistics.h"
#include "sql/dd/types/table.h"
#include "sql/debug_sync.h"
#include "sql/error_handler.h"
#include "sql/handler.h"
#include "sql/histograms/equi_height.h"
#include "sql/histograms/singleton.h"
#include "sql/histograms/table_histograms.h"
#include "sql/histograms/value_map.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_json_func.h"
#include "sql/key.h"
#include "sql/mdl.h"
#include "sql/mem_root_array.h"
#include "sql/mysqld.h"
#include "sql/psi_memory_key.h"
#include "sql/sql_base.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_time.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "sql/transaction.h"
#include "sql/tztime.h"
#include "sql_string.h"
#include "template_utils.h"

Classes

class  histograms::Background_error_handler
 Custom error handling for histogram updates from the background thread. More...
 

Namespaces

namespace  histograms
 

Typedefs

using histograms::value_map_collection = std::map< uint16, std::unique_ptr< histograms::Value_map_base >, std::less< uint16 >, Histogram_key_allocator< std::pair< const uint16, std::unique_ptr< histograms::Value_map_base > > > >
 

Functions

static Value_map_type histograms::field_type_to_value_map_type (const enum_field_types field_type, const bool is_unsigned)
 Convert from enum_field_types to Value_map_type. More...
 
static Value_map_type histograms::field_type_to_value_map_type (const Field *field)
 Get the Value_map_type from a Field object. More...
 
static type_conversion_status histograms::check_value_aux (Field *field, const double *nr)
 Helper function for check_value(). More...
 
static type_conversion_status histograms::check_value_aux (Field *field, const String *str)
 
static type_conversion_status histograms::check_value_aux (Field *field, const longlong *nr)
 
static type_conversion_status histograms::check_value_aux (Field *field, const ulonglong *nr)
 
static type_conversion_status histograms::check_value_aux (Field *field, MYSQL_TIME *ltime)
 
static type_conversion_status histograms::check_value_aux (Field *field, const my_decimal *mdec)
 
static bool histograms::lock_for_write (THD *thd, const MDL_key &mdl_key)
 Lock a column statistic MDL key for writing (exclusive lock). More...
 
template<class T >
Histogram * histograms::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. More...
 
static bool histograms::covered_by_single_part_index (const THD *thd, const Field *field)
 Check if a field is covered by a single-part unique index (primary key or unique index). More...
 
static bool histograms::prepare_value_maps (const Mem_root_array< HistogramSetting > &settings, value_map_collection &value_maps, size_t *row_size_bytes)
 Prepare one Value_map for each field we are creating histogram statistics for. More...
 
static bool histograms::fill_value_maps (const Mem_root_array< HistogramSetting > &settings, double sample_percentage, const TABLE *table, value_map_collection &value_maps)
 Read data from a table into the provided Value_maps. More...
 
static bool histograms::is_using_data (const HistogramSetting &setting)
 
static void histograms::resolve_histogram_fields (THD *thd, TABLE *table, Mem_root_array< HistogramSetting > *settings, results_map &results)
 Resolve histogram fields on the supplied collection of histogram update settings. More...
 
static bool histograms::update_histogram_using_data (THD *thd, Table_ref *table, const HistogramSetting &setting, results_map &results)
 Builds a histogram from a user-supplied JSON string and persists it to the dictionary. More...
 
bool histograms::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. More...
 
bool histograms::update_share_histograms (THD *thd, Table_ref *table)
 Retrieve an updated snapshot of the histograms on a table directly from the dictionary (in an inefficient manner, querying all columns) and inserts this snapshot in the Table_histograms_collection on the TABLE_SHARE. More...
 
static bool histograms::lock_table_histograms (THD *thd, TABLE *table)
 Acquire exclusive metadata locks on histograms for all columns. More...
 
static bool histograms::supports_histogram_updates (THD *thd, Table_ref *table)
 A collection of checks to determine whether the session context and table properties support histogram updates. More...
 
static bool histograms::retrieve_auto_update_histogram_settings (THD *thd, Table_ref *table, Mem_root_array< HistogramSetting > *settings)
 Collects the settings for automatically updated histograms on a table. More...
 
bool histograms::auto_update_table_histograms (THD *thd, Table_ref *table)
 Updates existing histograms on a table that were specified with the AUTO UPDATE option. More...
 
static loglevel histograms::log_level (const Sql_condition *condition)
 
static void histograms::write_diagnostics_area_to_error_log (THD *thd, std::string db_name, std::string table_name)
 Writes messages from the diagnostics area to the error log. More...
 
static void histograms::prepare_session_context (THD *thd)
 Prepare the session context for histogram updates. More...
 
static void histograms::cleanup_session_context (THD *thd)
 Clean up the session context following histogram updates. More...
 
static bool histograms::is_hidden_by_system (const dd::Column *col)
 Determine whether a column is hidden from the user. More...
 
bool histograms::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. More...
 
bool histograms::drop_all_histograms (THD *thd, Table_ref &table, const dd::Table &original_table_def, results_map &results)
 Drop histograms for all columns in a given table. More...
 
bool histograms::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. More...
 
static bool histograms::rename_histogram (THD *thd, const char *old_schema_name, const char *old_table_name, const char *new_schema_name, const char *new_table_name, const char *column_name, results_map &results)
 Rename a single histogram from a old schema/table name to a new schema/table name. More...
 
bool histograms::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. More...
 
bool histograms::find_histogram (THD *thd, const std::string &schema_name, const std::string &table_name, const std::string &column_name, const Histogram **histogram)
 
static bool histograms::get_temporal (Item *item, Value_map_type preferred_type, MYSQL_TIME *time_value)
 
template Histogram * histograms::build_histogram (MEM_ROOT *, const Value_map< double > &, size_t, const std::string &, const std::string &, const std::string &)
 
template Histogram * histograms::build_histogram (MEM_ROOT *, const Value_map< String > &, size_t, const std::string &, const std::string &, const std::string &)
 
template Histogram * histograms::build_histogram (MEM_ROOT *, const Value_map< ulonglong > &, size_t, const std::string &, const std::string &, const std::string &)
 
template Histogram * histograms::build_histogram (MEM_ROOT *, const Value_map< longlong > &, size_t, const std::string &, const std::string &, const std::string &)
 
template Histogram * histograms::build_histogram (MEM_ROOT *, const Value_map< MYSQL_TIME > &, size_t, const std::string &, const std::string &, const std::string &)
 
template Histogram * histograms::build_histogram (MEM_ROOT *, const Value_map< my_decimal > &, size_t, const std::string &, const std::string &, const std::string &)
 

Variables

static constexpr int histograms::MAX_NUMBER_OF_HISTOGRAM_BUCKETS = 1024
 
static std::map< const Value_map_type, const std::string > histograms::value_map_type_to_str
 

Detailed Description

Histogram base class (implementation).