MySQL 8.1.0
Source Code Documentation
histogram.h
Go to the documentation of this file.
1#ifndef HISTOGRAMS_HISTOGRAM_INCLUDED
2#define HISTOGRAMS_HISTOGRAM_INCLUDED
3
4/* Copyright (c) 2016, 2023, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/**
27 @file sql/histograms/histogram.h
28 Histogram base class.
29
30 This file defines the base class for all histogram types. We keep the base
31 class itself non-templatized in order to more easily send a histogram as an
32 argument, collect multiple histograms in a single collection etc.
33
34 A histogram is stored as a JSON object. This gives the flexibility of storing
35 virtually an unlimited number of buckets, data values in its full length and
36 easily expanding with new histogram types in the future. They are stored
37 persistently in the system table mysql.column_stats.
38
39 We keep all histogram code in the namespace "histograms" in order to avoid
40 name conflicts etc.
41*/
42
43#include <cstddef> // size_t
44#include <functional>
45#include <map> // std::map
46#include <set> // std::set
47#include <string> // std::string
48#include <utility> // std::pair
49
50#include "lex_string.h" // LEX_CSTRING
51#include "my_base.h" // ha_rows
52#include "sql/field.h" // Field
54#include "sql/mem_root_allocator.h" // Mem_root_allocator
55#include "sql/stateless_allocator.h" // Stateless_allocator
56
57class Item;
58class Json_dom;
59class Json_object;
60class THD;
61struct TYPELIB;
62class Field;
63
64namespace dd {
65class Table;
66} // namespace dd
67namespace histograms {
68struct Histogram_comparator;
69template <class T>
70class Value_map;
71} // namespace histograms
72struct CHARSET_INFO;
73struct MEM_ROOT;
74class Table_ref;
75class Json_dom;
76
77namespace histograms {
78
79/// The default (and invalid) value for "m_null_values_fraction".
80static const double INVALID_NULL_VALUES_FRACTION = -1.0;
81
82enum class Message {
87 VIEW,
95
96 // JSON validation errors. See Error_context.
121};
122
124 void *operator()(size_t s) const;
125};
126
127template <class T>
129
130template <class T>
132
133template <typename T>
135 std::map<T, ha_rows, Histogram_comparator, value_map_allocator<T>>;
136
137using columns_set = std::set<std::string, std::less<std::string>,
139
140// Used as an array, so duplicate values are not checked.
141// TODO((tlchrist): Convert this std::map to an array.
143 std::map<std::string, Message, std::less<std::string>,
145
146/**
147 The different operators we can ask histogram statistics for selectivity
148 estimations.
149*/
150enum class enum_operator {
151 EQUALS_TO,
153 LESS_THAN,
154 IS_NULL,
159 BETWEEN,
161 IN_LIST,
163};
164
165/**
166 Error context to validate given JSON object which represents a histogram.
167
168 A validation error consists of two pieces of information:
169
170 1) error code - what kind of error it is
171 2) JSON path - where the error occurs
172
173 Errors are classified into a few conceptual categories, namely
174
175 1) absence of required attributes
176 2) unexpected JSON type of attributes
177 3) value encoding corruption
178 4) value out of domain
179 5) breaking bucket sequence semantics
180 6) breaking certain constraint between pieces of information
181
182 @see Message
183*/
185 public:
186 /// Default constructor.
189
190 /**
191 Constructor. The context will create a copy of the Field so that
192 Field::store can be used to check validity of bucket values. Results will
193 be saved to the given results store
194
195 @param thd Thread context
196 @param field The field for values on which the histogram is built
197 @param table The table on which the histogram is built
198 @param results Where reported errors are stored
199 */
200 Error_context(THD *thd, Field *field, TABLE *table, results_map *results);
201
202 /**
203 Destructor. Destroy the copy of the Field and set all pointers to nullptr
204 **/
206 if (m_field) destroy(m_field);
207 m_thd = nullptr;
208 m_field = nullptr;
209 m_results = nullptr;
210 m_binary = false;
211 }
212 /**
213 Report a global error to this context.
214
215 @param err_code The global error code
216 */
217 void report_global(Message err_code);
218
219 /**
220 Report to this context that a required attribute is missing.
221
222 @param name Name of the missing attribute
223 */
224 void report_missing_attribute(const std::string &name);
225
226 /**
227 Report to this context that an error occurs on the given dom node.
228
229 @param dom The given dom node
230 @param err_code The error code
231 */
232 void report_node(const Json_dom *dom, Message err_code);
233
234 /**
235 Check if the value is in the field definition domain.
236
237 @param v Pointer to the value.
238
239 @return true on error, false otherwise
240 */
241 template <typename T>
242 bool check_value(T *v);
243
244 /**
245 Tell whether the input json is an internal persisted copy or
246 a user-defined input. If the input is an internal copy, there
247 should never be type/format errors. If it is a user-defined input,
248 errors may occur and should be handled, and some type casting may
249 be needed.
250
251 @return true for JSON, false otherwise
252 */
253 bool binary() const { return m_binary; }
254
255 /**
256 Return data-type of field in context if present. Used to enforce
257 that histogram datatype matches column datatype for user-defined
258 histograms.
259 @return datatype string if present, nullptr if not
260 */
261 Field *field() const { return m_field; }
262
263 private:
264 /// Thread context for error handlers
266 /// Buffer for m_field
268 /// The field for checking endpoint values
270 /// Where reported errors are stored
272 /// Whether or not the JSON object to process is in binary format
274};
275
276/**
277 Histogram base class.
278
279 This is an abstract class containing the interface and shared code for
280 concrete histogram subclasses.
281
282 Histogram subclasses (Singleton, Equi_height) are constructed through factory
283 methods in order to catch memory allocation errors during construction.
284
285 The histogram subclasses have no public copy or move constructors. In order to
286 copy a histogram onto a given MEM_ROOT, use the public clone method. The clone
287 method ensures that members of the histogram, such String type buckets,
288 are also allocated on the given MEM_ROOT. Modifications to these methods need
289 to be careful that histogram buckets are cloned/copied correctly.
290*/
292 public:
293 /// All supported histogram types in MySQL.
295
296 /// String representation of the JSON field "histogram-type".
297 static constexpr const char *histogram_type_str() { return "histogram-type"; }
298
299 /// String representation of the JSON field "data-type".
300 static constexpr const char *data_type_str() { return "data-type"; }
301
302 /// String representation of the JSON field "collation-id".
303 static constexpr const char *collation_id_str() { return "collation-id"; }
304
305 /// String representation of the histogram type SINGLETON.
306 static constexpr const char *singleton_str() { return "singleton"; }
307
308 /// String representation of the histogram type EQUI-HEIGHT.
309 static constexpr const char *equi_height_str() { return "equi-height"; }
310
311 protected:
313
314 /// The fraction of NULL values in the histogram (between 0.0 and 1.0).
316
317 /// The character set for the data stored
319
320 /// The number of buckets originally specified
322
323 /// String representation of the JSON field "buckets".
324 static constexpr const char *buckets_str() { return "buckets"; }
325
326 /// String representation of the JSON field "last-updated".
327 static constexpr const char *last_updated_str() { return "last-updated"; }
328
329 /// String representation of the JSON field "null-values".
330 static constexpr const char *null_values_str() { return "null-values"; }
331
332 static constexpr const char *sampling_rate_str() { return "sampling-rate"; }
333
334 /// String representation of the JSON field "number-of-buckets-specified".
335 static constexpr const char *numer_of_buckets_specified_str() {
336 return "number-of-buckets-specified";
337 }
338
339 /**
340 Constructor.
341
342 @param mem_root the mem_root where the histogram contents will be allocated
343 @param db_name name of the database this histogram represents
344 @param tbl_name name of the table this histogram represents
345 @param col_name name of the column this histogram represents
346 @param type the histogram type (equi-height, singleton)
347 @param data_type the type of data that this histogram contains
348 @param[out] error is set to true if an error occurs
349 */
350 Histogram(MEM_ROOT *mem_root, const std::string &db_name,
351 const std::string &tbl_name, const std::string &col_name,
352 enum_histogram_type type, Value_map_type data_type, bool *error);
353
354 /**
355 Copy constructor
356
357 This will make a copy of the provided histogram onto the provided MEM_ROOT.
358
359 @param mem_root the mem_root where the histogram contents will be allocated
360 @param other the histogram to copy
361 @param[out] error is set to true if an error occurs
362 */
363 Histogram(MEM_ROOT *mem_root, const Histogram &other, bool *error);
364
365 /**
366 Write the data type of this histogram into a JSON object.
367
368 @param json_object the JSON object where we will write the histogram
369 data type
370
371 @return true on error, false otherwise
372 */
373 bool histogram_data_type_to_json(Json_object *json_object) const;
374
375 /**
376 Return the value that is contained in the JSON DOM object.
377
378 For most types, this function simply returns the contained value. For String
379 values, the value is allocated on this histograms MEM_ROOT before it is
380 returned. This allows the String value to survive the entire lifetime of the
381 histogram object.
382
383 @param json_dom the JSON DOM object to extract the value from
384 @param out the value from the JSON DOM object
385 @param context error context for validation
386
387 @return true on error, false otherwise
388 */
389 template <class T>
390 bool extract_json_dom_value(const Json_dom *json_dom, T *out,
391 Error_context *context);
392
393 /**
394 Populate the histogram with data from the provided JSON object. The base
395 class also provides an implementation that subclasses must call in order
396 to populate fields that are shared among all histogram types (character set,
397 null values fraction).
398
399 @param json_object the JSON object to read the histogram data from
400 @param context error context for validation
401
402 @return true on error, false otherwise
403 */
404 virtual bool json_to_histogram(const Json_object &json_object,
405 Error_context *context) = 0;
406
407 private:
408 /// The MEM_ROOT where the histogram contents will be allocated.
410
411 /// The type of this histogram.
413
414 /// The type of the data this histogram contains.
416
417 /// Name of the database this histogram represents.
419
420 /// Name of the table this histogram represents.
422
423 /// Name of the column this histogram represents.
425
426 /**
427 An internal function for getting a selectivity estimate prior to adustment.
428 @see get_selectivity() for details.
429 */
430 bool get_raw_selectivity(Item **items, size_t item_count, enum_operator op,
431 double *selectivity) const;
432
433 /**
434 An internal function for getting the selecitvity estimation.
435
436 This function will read/evaluate the value from the given Item, and pass
437 this value on to the correct selectivity estimation function based on the
438 data type of the histogram. For instance, if the data type of the histogram
439 is INT, we will call "val_int" on the Item to evaluate the value as an
440 integer and pass this value on to the next function.
441
442 @param item The Item to read/evaluate the value from.
443 @param op The operator we are estimating the selectivity for.
444 @param typelib In the case of ENUM or SET data type, this parameter holds
445 the type information. This is needed in order to map a
446 string representation of an ENUM/SET value into its correct
447 integer representation (ENUM/SET values are stored as
448 integer values in the histogram).
449 @param[out] selectivity The estimated selectivity, between 0.0 and 1.0
450 inclusive.
451
452 @return true on error (i.e the provided item was NULL), false on success.
453 */
454 bool get_selectivity_dispatcher(Item *item, const enum_operator op,
455 const TYPELIB *typelib,
456 double *selectivity) const;
457
458 /**
459 An internal function for getting the selecitvity estimation.
460
461 This function will cast the histogram to the correct class (using down_cast)
462 and pass the given value on to the correct selectivity estimation function
463 for that class.
464
465 @param value The value to estimate the selectivity for.
466
467 @return The estimated selectivity, between 0.0 and 1.0 inclusive.
468 */
469 template <class T>
470 double get_less_than_selectivity_dispatcher(const T &value) const;
471
472 /// @see get_less_than_selectivity_dispatcher
473 template <class T>
474 double get_greater_than_selectivity_dispatcher(const T &value) const;
475
476 /// @see get_less_than_selectivity_dispatcher
477 template <class T>
478 double get_equal_to_selectivity_dispatcher(const T &value) const;
479
480 /**
481 An internal function for applying the correct function for the given
482 operator.
483
484 @param op The operator to apply
485 @param value The value to find the selectivity for.
486
487 @return The estimated selectivity, between 0.0 and 1.0 inclusive.
488 */
489 template <class T>
490 double apply_operator(const enum_operator op, const T &value) const;
491
492 public:
493 Histogram() = delete;
494 Histogram(const Histogram &other) = delete;
495
496 /// Destructor.
497 virtual ~Histogram() = default;
498
499 /// @return the MEM_ROOT that this histogram uses for allocations
500 MEM_ROOT *get_mem_root() const { return m_mem_root; }
501
502 /**
503 @return name of the database this histogram represents
504 */
506
507 /**
508 @return name of the table this histogram represents
509 */
510 const LEX_CSTRING get_table_name() const { return m_table_name; }
511
512 /**
513 @return name of the column this histogram represents
514 */
515 const LEX_CSTRING get_column_name() const { return m_column_name; }
516
517 /**
518 @return type of this histogram
519 */
521
522 /**
523 @return the fraction of NULL values, in the range [0.0, 1.0]
524 */
525 double get_null_values_fraction() const;
526
527 /// @return the character set for the data this histogram contains
528 const CHARSET_INFO *get_character_set() const { return m_charset; }
529
530 /// @return the sampling rate used to generate this histogram
531 double get_sampling_rate() const { return m_sampling_rate; }
532
533 /**
534 Returns the histogram type as a readable string.
535
536 @return a readable string representation of the histogram type
537 */
538 virtual std::string histogram_type_to_str() const = 0;
539
540 /**
541 @return number of buckets in this histogram
542 */
543 virtual size_t get_num_buckets() const = 0;
544
545 /**
546 Get the estimated number of distinct non-NULL values.
547 @return number of distinct non-NULL values
548 */
549 virtual size_t get_num_distinct_values() const = 0;
550
551 /**
552 @return the data type that this histogram contains
553 */
555
556 /**
557 @return number of buckets originally specified by the user. This may be
558 higher than the actual number of buckets in the histogram.
559 */
561
562 /**
563 Converts the histogram to a JSON object.
564
565 @param[in,out] json_object output where the histogram is to be stored. The
566 caller is responsible for allocating/deallocating the JSON
567 object
568
569 @return true on error, false otherwise
570 */
571 virtual bool histogram_to_json(Json_object *json_object) const = 0;
572
573 /**
574 Converts JSON object to a histogram.
575
576 @param mem_root MEM_ROOT where the histogram will be allocated
577 @param schema_name the schema name
578 @param table_name the table name
579 @param column_name the column name
580 @param json_object output where the histogram is stored
581 @param context error context for validation
582
583 @return nullptr on error. Otherwise a histogram allocated on the provided
584 MEM_ROOT.
585 */
587 const std::string &schema_name,
588 const std::string &table_name,
589 const std::string &column_name,
590 const Json_object &json_object,
591 Error_context *context);
592
593 /**
594 Make a clone of the current histogram
595
596 @param mem_root the MEM_ROOT on which the new histogram will be allocated.
597
598 @return a histogram allocated on the provided MEM_ROOT. Returns nullptr
599 on error.
600 */
601 virtual Histogram *clone(MEM_ROOT *mem_root) const = 0;
602
603 /**
604 Store this histogram to persistent storage (data dictionary).
605
606 @param thd Thread handler.
607
608 @return false on success, true on error.
609 */
610 bool store_histogram(THD *thd) const;
611
612 /**
613 Get selectivity estimation.
614
615 This function will try and get the selectivity estimation for a predicate
616 on the form "COLUMN OPERATOR CONSTANT", for instance "SELECT * FROM t1
617 WHERE col1 > 23;".
618
619 This function will take care of several of things, for instance checking
620 that the value we are estimating the selectivity for is a constant value.
621
622 The order of the Items provided does not matter. For instance, of the
623 operator argument given is "EQUALS_TO", it does not matter if the constant
624 value is provided as the first or the second argument; this function will
625 take care of this.
626
627 @param items an array of items that contains both the field we
628 are estimating the selectivity for, as well as the
629 user-provided constant values.
630 @param item_count the number of Items in the Item array.
631 @param op the predicate operator
632 @param[out] selectivity the calculated selectivity if a usable histogram was
633 found
634
635 @retval true if an error occurred (the Item provided was not a constant
636 value or similar).
637 @return false if success
638 */
639 bool get_selectivity(Item **items, size_t item_count, enum_operator op,
640 double *selectivity) const;
641
642 /**
643 @return the fraction of non-null values in the histogram.
644 */
646 return 1.0 - get_null_values_fraction();
647 }
648};
649
650/** Return true if 'histogram' was built on an empty table.*/
651inline bool empty(const Histogram &histogram) {
652 return histogram.get_num_distinct_values() == 0 &&
653 histogram.get_null_values_fraction() == 0.0;
654}
655
656/**
657 Create a histogram from a value map.
658
659 This function will build a histogram from a value map. The histogram type
660 depends on both the size of the input data, as well as the number of buckets
661 specified. If the number of distinct values is less than or equal to the
662 number of buckets, a Singleton histogram will be created. Otherwise, an
663 equi-height histogram will be created.
664
665 The histogram will be allocated on the supplied mem_root, and it is the
666 callers responsibility to properly clean up when the histogram isn't needed
667 anymore.
668
669 @param mem_root the MEM_ROOT where the histogram contents will be
670 allocated
671 @param value_map a value map containing [value, frequency]
672 @param num_buckets the maximum number of buckets to create
673 @param db_name name of the database this histogram represents
674 @param tbl_name name of the table this histogram represents
675 @param col_name name of the column this histogram represents
676
677 @return a histogram, using at most "num_buckets" buckets. The histogram
678 type depends on the size of the input data, and the number of
679 buckets
680*/
681template <class T>
682Histogram *build_histogram(MEM_ROOT *mem_root, const Value_map<T> &value_map,
683 size_t num_buckets, const std::string &db_name,
684 const std::string &tbl_name,
685 const std::string &col_name);
686
687/**
688 Create or update histograms for a set of columns of a given table.
689
690 This function will try to create histogram statistics for all the columns
691 specified. If one of the columns fail, it will continue to the next one and
692 try.
693
694 @param thd Thread handler.
695 @param table The table where we should look for the columns/data.
696 @param columns Columns specified by the user.
697 @param num_buckets The maximum number of buckets to create in each
698 histogram.
699 @param data The histogram json literal for update
700 @param results A map where the result of each operation is stored.
701
702 @return false on success, true on error.
703*/
704bool update_histogram(THD *thd, Table_ref *table, const columns_set &columns,
705 int num_buckets, LEX_STRING data, results_map &results);
706
707/**
708 Drop histograms for all columns in a given table.
709
710 @param thd Thread handler.
711 @param table The table where we should look for the columns.
712 @param original_table_def Original table definition.
713 @param results A map where the result of each operation is stored.
714
715 @note Assumes that caller owns exclusive metadata lock on the table,
716 so there is no need to lock individual statistics.
717
718 @return false on success, true on error.
719*/
721 const dd::Table &original_table_def,
722 results_map &results);
723
724/**
725 Drop histograms for a set of columns in a given table.
726
727 This function will try to drop the histogram statistics for all specified
728 columns. If one of the columns fail, it will continue to the next one and try.
729
730 @param thd Thread handler.
731 @param table The table where we should look for the columns.
732 @param columns Columns specified by the user.
733 @param results A map where the result of each operation is stored.
734
735 @note Assumes that the caller has the appropriate metadata locks on both the
736 table and column statistics. That can either be an exclusive metadata lock on
737 the table itself, or a shared metadata lock on the table combined with
738 exclusive locks on individual column statistics.
739
740 @return false on success, true on error.
741*/
742bool drop_histograms(THD *thd, Table_ref &table, const columns_set &columns,
743 results_map &results);
744
745/**
746 Rename histograms for all columns in a given table.
747
748 @param thd Thread handler.
749 @param old_schema_name The old schema name
750 @param old_table_name The old table name
751 @param new_schema_name The new schema name
752 @param new_table_name The new table name
753 @param results A map where the result of each operation is stored.
754
755 @return false on success, true on error.
756*/
757bool rename_histograms(THD *thd, const char *old_schema_name,
758 const char *old_table_name, const char *new_schema_name,
759 const char *new_table_name, results_map &results);
760
761bool find_histogram(THD *thd, const std::string &schema_name,
762 const std::string &table_name,
763 const std::string &column_name,
764 const Histogram **histogram);
765} // namespace histograms
766
767#endif
Definition: field.h:575
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:174
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:67
Stateless_allocator is a C++ STL memory allocator skeleton based on Malloc_allocator,...
Definition: stateless_allocator.h:91
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: table.h:2800
Definition: table.h:46
Error context to validate given JSON object which represents a histogram.
Definition: histogram.h:184
Field * m_field
The field for checking endpoint values.
Definition: histogram.h:269
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:250
Error_context()
Default constructor.
Definition: histogram.h:187
Field * field() const
Return data-type of field in context if present.
Definition: histogram.h:261
uchar m_buffer[MAX_FIELD_WIDTH]
Buffer for m_field.
Definition: histogram.h:267
results_map * m_results
Where reported errors are stored.
Definition: histogram.h:271
bool m_binary
Whether or not the JSON object to process is in binary format.
Definition: histogram.h:273
THD * m_thd
Thread context for error handlers.
Definition: histogram.h:265
void report_missing_attribute(const std::string &name)
Report to this context that a required attribute is missing.
Definition: histogram.cc:238
bool check_value(T *v)
Check if the value is in the field definition domain.
Definition: histogram.cc:330
void report_global(Message err_code)
Report a global error to this context.
Definition: histogram.cc:226
bool binary() const
Tell whether the input json is an internal persisted copy or a user-defined input.
Definition: histogram.h:253
~Error_context()
Destructor.
Definition: histogram.h:205
Histogram base class.
Definition: histogram.h:291
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:321
Value_map_type get_data_type() const
Definition: histogram.h:554
double get_equal_to_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:1719
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:409
static constexpr const char * data_type_str()
String representation of the JSON field "data-type".
Definition: histogram.h:300
double m_sampling_rate
Definition: histogram.h:312
static constexpr const char * collation_id_str()
String representation of the JSON field "collation-id".
Definition: histogram.h:303
double get_less_than_selectivity_dispatcher(const T &value) const
An internal function for getting the selecitvity estimation.
Definition: histogram.cc:1680
static constexpr const char * buckets_str()
String representation of the JSON field "buckets".
Definition: histogram.h:324
static constexpr const char * numer_of_buckets_specified_str()
String representation of the JSON field "number-of-buckets-specified".
Definition: histogram.h:335
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:531
const enum_histogram_type m_hist_type
The type of this histogram.
Definition: histogram.h:412
virtual bool histogram_to_json(Json_object *json_object) const =0
Converts the histogram to a JSON object.
Definition: histogram.cc:407
const CHARSET_INFO * m_charset
The character set for the data stored.
Definition: histogram.h:318
static constexpr const char * last_updated_str()
String representation of the JSON field "last-updated".
Definition: histogram.h:327
LEX_CSTRING m_table_name
Name of the table this histogram represents.
Definition: histogram.h:421
Histogram(const Histogram &other)=delete
size_t get_num_buckets_specified() const
Definition: histogram.h:560
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:1953
static constexpr const char * equi_height_str()
String representation of the histogram type EQUI-HEIGHT.
Definition: histogram.h:309
double get_non_null_values_fraction() const
Definition: histogram.h:645
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:1907
double m_null_values_fraction
The fraction of NULL values in the histogram (between 0.0 and 1.0).
Definition: histogram.h:315
const Value_map_type m_data_type
The type of the data this histogram contains.
Definition: histogram.h:415
const LEX_CSTRING get_database_name() const
Definition: histogram.h:505
LEX_CSTRING m_column_name
Name of the column this histogram represents.
Definition: histogram.h:424
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:1782
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:1766
const CHARSET_INFO * get_character_set() const
Definition: histogram.h:528
const LEX_CSTRING get_table_name() const
Definition: histogram.h:510
double get_null_values_fraction() const
Definition: histogram.cc:452
MEM_ROOT * get_mem_root() const
Definition: histogram.h:500
enum_histogram_type get_histogram_type() const
Definition: histogram.h:520
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:664
LEX_CSTRING m_database_name
Name of the database this histogram represents.
Definition: histogram.h:418
bool store_histogram(THD *thd) const
Store this histogram to persistent storage (data dictionary).
Definition: histogram.cc:1497
static constexpr const char * histogram_type_str()
String representation of the JSON field "histogram-type".
Definition: histogram.h:297
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:761
static constexpr const char * singleton_str()
String representation of the histogram type SINGLETON.
Definition: histogram.h:306
static constexpr const char * sampling_rate_str()
Definition: histogram.h:332
double get_greater_than_selectivity_dispatcher(const T &value) const
Definition: histogram.cc:1699
const LEX_CSTRING get_column_name() const
Definition: histogram.h:515
enum_histogram_type
All supported histogram types in MySQL.
Definition: histogram.h:294
static constexpr const char * null_values_str()
String representation of the JSON field "null-values".
Definition: histogram.h:330
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
This file includes constants used by all storage engines.
unsigned char uchar
Definition: my_inttypes.h:51
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:42
Definition: column_statistics.h:33
std::set< std::string, std::less< std::string >, Histogram_key_allocator< std::string > > columns_set
Definition: histogram.h:138
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:1451
std::map< std::string, Message, std::less< std::string >, Histogram_key_allocator< std::pair< const std::string, Message > > > results_map
Definition: histogram.h:144
Message
Definition: histogram.h:82
@ JSON_CUMULATIVE_FREQUENCY_NOT_ASCENDING
@ JSON_NUM_BUCKETS_MORE_THAN_SPECIFIED
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:1461
enum_operator
The different operators we can ask histogram statistics for selectivity estimations.
Definition: histogram.h:150
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:1618
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:462
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:1258
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:1657
static const double INVALID_NULL_VALUES_FRACTION
The default (and invalid) value for "m_null_values_fraction".
Definition: histogram.h:80
std::map< T, ha_rows, Histogram_comparator, value_map_allocator< T > > value_map_type
Definition: histogram.h:135
Value_map_type
Datatypes that a Value_map and histogram can hold (including the invalid type).
Definition: value_map_type.h:32
bool empty(const Histogram &histogram)
Return true if 'histogram' was built on an empty table.
Definition: histogram.h:651
static int destroy(mysql_cond_t *that, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:42
const char * table_name
Definition: rules_table_service.cc:55
const char * db_name
Definition: rules_table_service.cc:54
required string type
Definition: replication_group_member_actions.proto:33
constexpr const int MAX_FIELD_WIDTH
Max column width + 1.
Definition: sql_const.h:65
case opt name
Definition: sslopt-case.h:32
Definition: m_ctype.h:422
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: mysql_lex_string.h:39
Definition: mysql_lex_string.h:34
Definition: table.h:1394
Definition: typelib.h:34
Definition: histogram.h:123
void * operator()(size_t s) const
Definition: histogram.cc:116