MySQL 8.0.39
Source Code Documentation
histogram.h File Reference

Histogram base class. More...

#include <cstddef>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <utility>
#include "lex_string.h"
#include "my_base.h"
#include "sql/field.h"
#include "sql/histograms/value_map_type.h"
#include "sql/mem_root_allocator.h"
#include "sql/stateless_allocator.h"

Go to the source code of this file.

Classes

struct  histograms::Histogram_psi_key_alloc
 
class  histograms::Error_context
 Error context to validate given JSON object which represents a histogram. More...
 
class  histograms::Histogram
 Histogram base class. More...
 

Namespaces

namespace  dd
 The version of the current data dictionary table definitions.
 
namespace  histograms
 

Typedefs

template<class T >
using histograms::Histogram_key_allocator = Stateless_allocator< T, Histogram_psi_key_alloc >
 
template<class T >
using histograms::value_map_allocator = Mem_root_allocator< std::pair< const T, ha_rows > >
 
template<typename T >
using histograms::value_map_type = std::map< T, ha_rows, Histogram_comparator, value_map_allocator< T > >
 
using histograms::columns_set = std::set< std::string, std::less< std::string >, Histogram_key_allocator< std::string > >
 
using histograms::results_map = std::map< std::string, Message, std::less< std::string >, Histogram_key_allocator< std::pair< const std::string, Message > > >
 

Enumerations

enum class  histograms::Message {
  histograms::FIELD_NOT_FOUND , histograms::UNSUPPORTED_DATA_TYPE , histograms::TEMPORARY_TABLE , histograms::ENCRYPTED_TABLE ,
  histograms::VIEW , histograms::HISTOGRAM_CREATED , histograms::MULTIPLE_TABLES_SPECIFIED , histograms::COVERED_BY_SINGLE_PART_UNIQUE_INDEX ,
  histograms::NO_HISTOGRAM_FOUND , histograms::HISTOGRAM_DELETED , histograms::SERVER_READ_ONLY , histograms::MULTIPLE_COLUMNS_SPECIFIED ,
  histograms::JSON_FORMAT_ERROR , histograms::JSON_NOT_AN_OBJECT , histograms::JSON_MISSING_ATTRIBUTE , histograms::JSON_WRONG_ATTRIBUTE_TYPE ,
  histograms::JSON_WRONG_BUCKET_TYPE_2 , histograms::JSON_WRONG_BUCKET_TYPE_4 , histograms::JSON_WRONG_DATA_TYPE , histograms::JSON_UNSUPPORTED_DATA_TYPE ,
  histograms::JSON_UNSUPPORTED_HISTOGRAM_TYPE , histograms::JSON_UNSUPPORTED_CHARSET , histograms::JSON_INVALID_SAMPLING_RATE , histograms::JSON_INVALID_NUM_BUCKETS_SPECIFIED ,
  histograms::JSON_INVALID_FREQUENCY , histograms::JSON_INVALID_NUM_DISTINCT , histograms::JSON_VALUE_FORMAT_ERROR , histograms::JSON_VALUE_OUT_OF_RANGE ,
  histograms::JSON_VALUE_NOT_ASCENDING_1 , histograms::JSON_VALUE_NOT_ASCENDING_2 , histograms::JSON_VALUE_DESCENDING_IN_BUCKET , histograms::JSON_CUMULATIVE_FREQUENCY_NOT_ASCENDING ,
  histograms::JSON_INVALID_NULL_VALUES_FRACTION , histograms::JSON_INVALID_TOTAL_FREQUENCY , histograms::JSON_NUM_BUCKETS_MORE_THAN_SPECIFIED , histograms::JSON_IMPOSSIBLE_EMPTY_EQUI_HEIGHT
}
 
enum class  histograms::enum_operator {
  histograms::EQUALS_TO , histograms::GREATER_THAN , histograms::LESS_THAN , histograms::IS_NULL ,
  histograms::IS_NOT_NULL , histograms::LESS_THAN_OR_EQUAL , histograms::GREATER_THAN_OR_EQUAL , histograms::NOT_EQUALS_TO ,
  histograms::BETWEEN , histograms::NOT_BETWEEN , histograms::IN_LIST , histograms::NOT_IN_LIST
}
 The different operators we can ask histogram statistics for selectivity estimations. More...
 

Functions

bool histograms::empty (const Histogram &histogram)
 Return true if 'histogram' was built on an empty table. 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...
 
bool histograms::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. 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, bool needs_lock, results_map &results)
 Drop histograms for a set of columns in a given table. 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)
 

Variables

static const double histograms::INVALID_NULL_VALUES_FRACTION = -1.0
 The default (and invalid) value for "m_null_values_fraction". More...
 

Detailed Description

Histogram base class.

This file defines the base class for all histogram types. We keep the base class itself non-templatized in order to more easily send a histogram as an argument, collect multiple histograms in a single collection etc.

A histogram is stored as a JSON object. This gives the flexibility of storing virtually an unlimited number of buckets, data values in its full length and easily expanding with new histogram types in the future. They are stored persistently in the system table mysql.column_stats.

We keep all histogram code in the namespace "histograms" in order to avoid name conflicts etc.