MySQL 8.0.30
Source Code Documentation
internal.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2022, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef SQL_RANGE_OPTIMIZER_INTERNAL_H_
24#define SQL_RANGE_OPTIMIZER_INTERNAL_H_
25
27
28#include "mysys_err.h" // EE_CAPACITY_EXCEEDED
29#include "sql/derror.h" // ER_THD
30#include "sql/error_handler.h" // Internal_error_handler
31#include "sql/sql_class.h" // THD
32
33class RANGE_OPT_PARAM;
34struct ROR_SCAN_INFO;
35class SEL_ARG;
36class SEL_IMERGE;
37class SEL_TREE;
38class SEL_ROOT;
39
40[[maybe_unused]] void print_tree(String *out, const char *tree_name,
41 SEL_TREE *tree, const RANGE_OPT_PARAM *param,
42 const bool print_full);
43
44void append_range(String *out, const KEY_PART_INFO *key_parts,
45 const uchar *min_key, const uchar *max_key, const uint flag);
46class Opt_trace_array;
48 String *range_string, String *range_so_far,
49 SEL_ROOT *keypart,
50 const KEY_PART_INFO *key_parts,
51 const bool print_full);
52
53// Simplified version of the logic in append_range_all_keyparts(),
54// supporting only append to string and using QUICK_RANGE instead of SEL_ROOT.
56 const KEY_PART_INFO *first_key_part, String *out);
57
58/**
59 Shared sentinel node for all trees. Initialized by range_optimizer_init(),
60 destroyed by range_optimizer_free();
61 Put it in a namespace, to avoid possible conflicts with the global namespace.
62*/
63namespace opt_range {
64extern SEL_ARG *null_element;
65}
66
67/**
68 Error handling class for range optimizer. We handle only out of memory
69 error here. This is to give a hint to the user to
70 raise range_optimizer_max_mem_size if required.
71 Warning for the memory error is pushed only once. The consequent errors
72 will be ignored.
73*/
75 public:
77 : m_has_errors(false), m_is_mem_error(false) {}
78
79 bool handle_condition(THD *thd, uint sql_errno, const char *,
81 const char *) override {
82 if (*level == Sql_condition::SL_ERROR) {
83 m_has_errors = true;
84 /* Out of memory error is reported only once. Return as handled */
85 if (m_is_mem_error && sql_errno == EE_CAPACITY_EXCEEDED) return true;
86 if (sql_errno == EE_CAPACITY_EXCEEDED) {
87 m_is_mem_error = true;
88 /* Convert the error into a warning. */
91 thd, Sql_condition::SL_WARNING, ER_CAPACITY_EXCEEDED,
92 ER_THD(thd, ER_CAPACITY_EXCEEDED),
94 "range_optimizer_max_mem_size",
95 ER_THD(thd, ER_CAPACITY_EXCEEDED_IN_RANGE_OPTIMIZER));
96 return true;
97 }
98 }
99 return false;
100 }
101
102 bool has_errors() const { return m_has_errors; }
103
104 private:
107};
108
109int index_next_different(bool is_index_scan, handler *file,
110 KEY_PART_INFO *key_part, uchar *record,
111 const uchar *group_prefix, uint group_prefix_len,
112 uint group_key_parts);
113
114/*
115 SEL_IMERGE is a list of possible ways to do index merge, i.e. it is
116 a condition in the following form:
117 (t_1||t_2||...||t_N) && (next)
118
119 where all t_i are SEL_TREEs, next is another SEL_IMERGE and no pair
120 (t_i,t_j) contains SEL_ARGS for the same index.
121
122 SEL_TREE contained in SEL_IMERGE always has merges=NULL.
123
124 This class relies on memory manager to do the cleanup.
125*/
126
128 public:
130
133 bool or_sel_tree(SEL_TREE *tree);
134 int or_sel_tree_with_checks(RANGE_OPT_PARAM *param, bool remove_jump_scans,
135 SEL_TREE *new_tree);
136 int or_sel_imerge_with_checks(RANGE_OPT_PARAM *param, bool remove_jump_scans,
137 SEL_IMERGE *imerge);
138};
139
140/*
141 Convert double value to #rows. Currently this does floor(), and we
142 might consider using round() instead.
143*/
144#define double2rows(x) ((ha_rows)(x))
145
146void print_key_value(String *out, const KEY_PART_INFO *key_part,
147 const uchar *key);
148
149#endif // SQL_RANGE_OPTIMIZER_INTERNAL_H_
This class represents the interface for internal error handlers.
Definition: error_handler.h:46
Definition: key.h:56
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:421
A JSON array (ordered set of values).
Definition: opt_trace.h:831
Definition: range_optimizer.h:68
Definition: range_opt_param.h:28
Error handling class for range optimizer.
Definition: internal.h:74
bool m_has_errors
Definition: internal.h:105
bool m_is_mem_error
Definition: internal.h:106
Range_optimizer_error_handler()
Definition: internal.h:76
bool handle_condition(THD *thd, uint sql_errno, const char *, Sql_condition::enum_severity_level *level, const char *) override
Handle a sql condition.
Definition: internal.h:79
bool has_errors() const
Definition: internal.h:102
Definition: tree.h:464
Definition: internal.h:127
int or_sel_imerge_with_checks(RANGE_OPT_PARAM *param, bool remove_jump_scans, SEL_IMERGE *imerge)
Definition: range_optimizer.cc:245
Mem_root_array< SEL_TREE * > trees
Definition: internal.h:129
bool or_sel_tree(SEL_TREE *tree)
Definition: range_optimizer.cc:180
SEL_IMERGE(MEM_ROOT *mem_root)
Definition: internal.h:131
int or_sel_tree_with_checks(RANGE_OPT_PARAM *param, bool remove_jump_scans, SEL_TREE *new_tree)
Definition: range_optimizer.cc:213
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:67
Definition: tree.h:870
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:62
@ SL_ERROR
Definition: sql_error.h:62
@ SL_WARNING
Definition: sql_error.h:62
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
struct System_variables variables
Definition: sql_class.h:1115
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4290
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
const char * ER_THD(const THD *thd, int mysql_errno)
Definition: derror.cc:102
static int flag
Definition: hp_test1.cc:39
void print_tree(String *out, const char *tree_name, SEL_TREE *tree, const RANGE_OPT_PARAM *param, const bool print_full)
Definition: range_optimizer.cc:1711
void append_range_to_string(const QUICK_RANGE *range, const KEY_PART_INFO *first_key_part, String *out)
Definition: range_optimizer.cc:1679
void append_range_all_keyparts(Opt_trace_array *range_trace, String *range_string, String *range_so_far, SEL_ROOT *keypart, const KEY_PART_INFO *key_parts, const bool print_full)
Traverse an R-B tree of range conditions and append all ranges for this keypart and consecutive keypa...
Definition: range_optimizer.cc:1585
void print_key_value(String *out, const KEY_PART_INFO *key_part, const uchar *key)
Print a key to a string.
Definition: range_optimizer.cc:1402
void append_range(String *out, const KEY_PART_INFO *key_parts, const uchar *min_key, const uchar *max_key, const uint flag)
Append range info for a key part to a string.
Definition: range_optimizer.cc:1507
int index_next_different(bool is_index_scan, handler *file, KEY_PART_INFO *key_part, uchar *record, const uchar *group_prefix, uint group_prefix_len, uint group_key_parts)
Find the next different key value by skipping all the rows with the same key value.
Definition: range_optimizer.cc:1377
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
#define EE_CAPACITY_EXCEEDED
Definition: mysys_err.h:77
Definition: os0file.h:85
Shared sentinel node for all trees.
Definition: internal.h:63
SEL_ARG * null_element
Definition: range_optimizer.cc:157
required string key
Definition: replication_asynchronous_connection_failover.proto:59
void push_warning_printf(THD *thd, Sql_condition::enum_severity_level severity, uint code, const char *format,...)
Push the warning to error list if there is still room in the list.
Definition: sql_error.cc:678
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: rowid_ordered_retrieval_plan.h:42
ulong range_optimizer_max_mem_size
Definition: system_variables.h:234
Definition: gen_lex_token.cc:151
Definition: mi_test3.cc:54
unsigned int uint
Definition: uca-dump.cc:29