MySQL 9.1.0
Source Code Documentation
internal.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_RANGE_OPTIMIZER_INTERNAL_H_
25#define SQL_RANGE_OPTIMIZER_INTERNAL_H_
26
28
29#include "mysys_err.h" // EE_CAPACITY_EXCEEDED
30#include "sql/derror.h" // ER_THD
31#include "sql/error_handler.h" // Internal_error_handler
32#include "sql/sql_class.h" // THD
33
34class RANGE_OPT_PARAM;
35struct ROR_SCAN_INFO;
36class SEL_ARG;
37class SEL_IMERGE;
38class SEL_TREE;
39class SEL_ROOT;
40
41[[maybe_unused]] void print_tree(String *out, const char *tree_name,
42 SEL_TREE *tree, const RANGE_OPT_PARAM *param,
43 const bool print_full);
44
45void append_range(String *out, const KEY_PART_INFO *key_parts,
46 const uchar *min_key, const uchar *max_key, const uint flag);
47class Opt_trace_array;
49 String *range_string, String *range_so_far,
50 SEL_ROOT *keypart,
51 const KEY_PART_INFO *key_parts,
52 const bool print_full);
53
54// Simplified version of the logic in append_range_all_keyparts(),
55// supporting only append to string and using QUICK_RANGE instead of SEL_ROOT.
57 const KEY_PART_INFO *first_key_part, String *out);
58
59/**
60 Shared sentinel node for all trees. Initialized by range_optimizer_init(),
61 destroyed by range_optimizer_free();
62 Put it in a namespace, to avoid possible conflicts with the global namespace.
63*/
64namespace opt_range {
65extern SEL_ARG *null_element;
66}
67
68/**
69 Error handling class for range optimizer. We handle only out of memory
70 error here. This is to give a hint to the user to
71 raise range_optimizer_max_mem_size if required.
72 Warning for the memory error is pushed only once. The consequent errors
73 will be ignored.
74*/
76 public:
78 : m_has_errors(false), m_is_mem_error(false) {}
79
80 bool handle_condition(THD *thd, uint sql_errno, const char *,
82 const char *) override {
83 if (*level == Sql_condition::SL_ERROR) {
84 m_has_errors = true;
85 /* Out of memory error is reported only once. Return as handled */
86 if (m_is_mem_error && sql_errno == EE_CAPACITY_EXCEEDED) return true;
87 if (sql_errno == EE_CAPACITY_EXCEEDED) {
88 m_is_mem_error = true;
89 /* Convert the error into a warning. */
92 thd, Sql_condition::SL_WARNING, ER_CAPACITY_EXCEEDED,
93 ER_THD(thd, ER_CAPACITY_EXCEEDED),
94 (ulonglong)thd->variables.range_optimizer_max_mem_size,
95 "range_optimizer_max_mem_size",
96 ER_THD(thd, ER_CAPACITY_EXCEEDED_IN_RANGE_OPTIMIZER));
97 return true;
98 }
99 }
100 return false;
101 }
102
103 bool has_errors() const { return m_has_errors; }
104
105 private:
108};
109
110int index_next_different(bool is_index_scan, handler *file,
111 KEY_PART_INFO *key_part, uchar *record,
112 const uchar *group_prefix, uint group_prefix_len,
113 uint group_key_parts);
114
115/*
116 SEL_IMERGE is a list of possible ways to do index merge, i.e. it is
117 a condition in the following form:
118 (t_1||t_2||...||t_N) && (next)
119
120 where all t_i are SEL_TREEs, next is another SEL_IMERGE and no pair
121 (t_i,t_j) contains SEL_ARGS for the same index.
122
123 SEL_TREE contained in SEL_IMERGE always has merges=NULL.
124
125 This class relies on memory manager to do the cleanup.
126*/
127
129 public:
131
134 bool or_sel_tree(SEL_TREE *tree);
135 int or_sel_tree_with_checks(RANGE_OPT_PARAM *param, bool remove_jump_scans,
136 SEL_TREE *new_tree);
137 int or_sel_imerge_with_checks(RANGE_OPT_PARAM *param, bool remove_jump_scans,
138 SEL_IMERGE *imerge);
139};
140
141/*
142 Convert double value to #rows. Currently this does floor(), and we
143 might consider using round() instead.
144*/
145#define double2rows(x) ((ha_rows)(x))
146
147void print_key_value(String *out, const KEY_PART_INFO *key_part,
148 const uchar *key);
149
150#endif // SQL_RANGE_OPTIMIZER_INTERNAL_H_
This class represents the interface for internal error handlers.
Definition: error_handler.h:47
Definition: key.h:57
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
A JSON array (ordered set of values).
Definition: opt_trace.h:832
Definition: range_optimizer.h:69
Definition: range_opt_param.h:29
Error handling class for range optimizer.
Definition: internal.h:75
bool m_has_errors
Definition: internal.h:106
bool m_is_mem_error
Definition: internal.h:107
Range_optimizer_error_handler()
Definition: internal.h:77
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:80
bool has_errors() const
Definition: internal.h:103
Definition: tree.h:465
Definition: internal.h:128
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:130
bool or_sel_tree(SEL_TREE *tree)
Definition: range_optimizer.cc:180
SEL_IMERGE(MEM_ROOT *mem_root)
Definition: internal.h:132
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:68
Definition: tree.h:871
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:63
@ SL_ERROR
Definition: sql_error.h:63
@ SL_WARNING
Definition: sql_error.h:63
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
System_variables variables
Definition: sql_lexer_thd.h:64
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4583
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
const char * ER_THD(const THD *thd, int mysql_errno)
Definition: derror.cc:104
static int flag
Definition: hp_test1.cc:40
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:1691
void append_range_to_string(const QUICK_RANGE *range, const KEY_PART_INFO *first_key_part, String *out)
Definition: range_optimizer.cc:1659
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:1565
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:1382
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:1487
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:1354
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
static int record
Definition: mysqltest.cc:193
#define EE_CAPACITY_EXCEEDED
Definition: mysys_err.h:78
Definition: os0file.h:89
Shared sentinel node for all trees.
Definition: internal.h:64
SEL_ARG * null_element
Definition: range_optimizer.cc:157
required string key
Definition: replication_asynchronous_connection_failover.proto:60
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:690
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: rowid_ordered_retrieval_plan.h:44
Definition: gen_lex_token.cc:149