MySQL 8.4.0
Source Code Documentation
parse_tree_hints.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 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/*
25 Parse tree node classes for optimizer hint syntax
26*/
27
28#ifndef PARSE_TREE_HINTS_INCLUDED
29#define PARSE_TREE_HINTS_INCLUDED
30
31#include <sys/types.h>
32
33#include "lex_string.h"
34#include "my_compiler.h"
35#include "sql/mem_root_array.h"
36#include "sql/opt_hints.h"
38#include "sql/sql_show.h"
39#include "sql_string.h"
40
41class Item;
42class THD;
43struct MEM_ROOT;
44
48};
49
52
53/**
54 The class is a base class for representation of the
55 different types of the hints. For the complex hints
56 it is also used as a container for additional arguments.
57*/
58class PT_hint : public Parse_tree_node {
60 bool state; // true if hints is on, false otherwise
61 public:
62 PT_hint(opt_hints_enum hint_type_arg, bool switch_state_arg)
63 : Parse_tree_node(POS()) /* TODO: handle position in hints */,
64 hint_type(hint_type_arg),
65 state(switch_state_arg) {}
66
67 opt_hints_enum type() const { return hint_type; }
68 bool switch_on() const { return state; }
69 /**
70 Print warning issuing in processing of the hint.
71
72 @param thd Pointer to THD object
73 @param err_code Error code
74 @param qb_name_arg QB name
75 @param table_name_arg table name
76 @param key_name_arg key name
77 @param hint Pointer to hint object
78 */
79 virtual void print_warn(THD *thd, uint err_code,
80 const LEX_CSTRING *qb_name_arg,
81 LEX_CSTRING *table_name_arg,
82 LEX_CSTRING *key_name_arg, PT_hint *hint) const;
83 /**
84 Append additional hint arguments.
85
86 @param thd Pointer to THD object
87 @param str Pointer to String object
88 */
89 virtual void append_args(const THD *thd [[maybe_unused]],
90 String *str [[maybe_unused]]) const {}
92 /*
93 Only index hints are supported to be used in views.
94 Other hints can be added separately.
95 */
96 return (type() >= INDEX_HINT_ENUM && type() <= ORDER_INDEX_HINT_ENUM);
97 }
98};
99
102
104
105 public:
107 : super(POS()) /* TODO: handle position of hints */, hints(mem_root) {}
108
109 /**
110 Function handles list of the hints we get after
111 parse procedure. It also creates query block hint
112 object(Opt_hints_qb) if it does not exists.
113
114 @param pc Pointer to Parse_context object
115
116 @return true in case of error,
117 false otherwise
118 */
119 bool do_contextualize(Parse_context *pc) override;
120
121 bool push_back(PT_hint *hint) { return hints.push_back(hint); }
122};
123
124/**
125 Parse tree hint object for query block level hints.
126*/
127class PT_qb_level_hint : public PT_hint {
128 /** Name of query block. */
130 /** Bit mask of arguments to hint. */
131 uint args;
132 /** List of tables specified in join order hint */
134
135 typedef PT_hint super;
136
137 public:
138 PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
139 enum opt_hints_enum hint_type_arg, uint arg)
140 : PT_hint(hint_type_arg, switch_state_arg),
141 qb_name(qb_name_arg),
142 args(arg) {}
143
144 PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
145 enum opt_hints_enum hint_type_arg,
146 const Hint_param_table_list &table_list_arg)
147 : PT_hint(hint_type_arg, switch_state_arg),
148 qb_name(qb_name_arg),
149 args(0),
150 table_list(table_list_arg) {}
151
152 uint get_args() const { return args; }
153
154 /**
155 Function handles query block level hint. It also creates query block hint
156 object (Opt_hints_qb) if it does not exist.
157
158 @param pc Pointer to Parse_context object
159
160 @return true in case of error,
161 false otherwise
162 */
163 bool do_contextualize(Parse_context *pc) override;
164
165 /**
166 Append hint arguments to given string
167
168 @param thd Pointer to THD object
169 @param str Pointer to String object
170 */
171 void append_args(const THD *thd, String *str) const override;
173};
174
175/**
176 Parse tree hint object for table level hints.
177*/
178
182
183 typedef PT_hint super;
184
185 public:
187 const Hint_param_table_list &table_list_arg,
188 bool switch_state_arg, opt_hints_enum hint_type_arg)
189 : PT_hint(hint_type_arg, switch_state_arg),
190 qb_name(qb_name_arg),
191 table_list(table_list_arg) {}
192
193 /**
194 Function handles table level hint. It also creates
195 table hint object (Opt_hints_table) if it does not
196 exist.
197
198 @param pc Pointer to Parse_context object
199
200 @return true in case of error,
201 false otherwise
202 */
203 bool do_contextualize(Parse_context *pc) override;
204};
205
206/**
207 Parse tree hint object for key level hints.
208*/
209
213
214 typedef PT_hint super;
215
216 public:
218 const Hint_param_index_list &key_list_arg,
219 bool switch_state_arg, opt_hints_enum hint_type_arg)
220 : PT_hint(hint_type_arg, switch_state_arg),
221 table_name(table_name_arg),
222 key_list(key_list_arg) {}
223
224 /**
225 Function handles key level hint.
226 It also creates key hint object
227 (Opt_hints_key) if it does not
228 exist.
229
230 @param pc Pointer to Parse_context object
231
232 @return true in case of error,
233 false otherwise
234 */
235 bool do_contextualize(Parse_context *pc) override;
236 void append_args(const THD *thd, String *str) const override;
237};
238
239/**
240 Parse tree hint object for QB_NAME hint.
241*/
242
243class PT_hint_qb_name : public PT_hint {
245
246 typedef PT_hint super;
247
248 public:
249 PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
250 : PT_hint(QB_NAME_HINT_ENUM, true), qb_name(qb_name_arg) {}
251
252 /**
253 Function sets query block name.
254
255 @param pc Pointer to Parse_context object
256
257 @return true in case of error,
258 false otherwise
259 */
260 bool do_contextualize(Parse_context *pc) override;
261 void append_args(const THD *thd, String *str) const override {
263 }
264};
265
266/**
267 Parse tree hint object for MAX_EXECUTION_TIME hint.
268*/
269
271 typedef PT_hint super;
272
273 public:
275
276 explicit PT_hint_max_execution_time(ulong milliseconds_arg)
278 milliseconds(milliseconds_arg) {}
279 /**
280 Function initializes MAX_EXECUTION_TIME hint
281
282 @param pc Pointer to Parse_context object
283
284 @return true in case of error,
285 false otherwise
286 */
287 bool do_contextualize(Parse_context *pc) override;
288 void append_args(const THD *, String *str) const override {
289 str->append_ulonglong(milliseconds);
290 }
291};
292
293class PT_hint_sys_var : public PT_hint {
296
297 typedef PT_hint super;
298
299 public:
300 explicit PT_hint_sys_var(const LEX_CSTRING sys_var_name_arg,
301 Item *sys_var_value_arg)
302 : PT_hint(MAX_HINT_ENUM, true),
303 sys_var_name(sys_var_name_arg),
304 sys_var_value(sys_var_value_arg) {}
305 /**
306 Function initializes SET_VAR hint.
307
308 @param pc Pointer to Parse_context object
309
310 @return true in case of error,
311 false otherwise
312 */
313 bool do_contextualize(Parse_context *pc) override;
314};
315
316/**
317 Parse tree hint object for RESOURCE_GROUP hint.
318*/
319
322
323 typedef PT_hint super;
324
325 public:
328
329 /**
330 Function initializes resource group name and checks for presence of
331 resource group. Also it checks for invocation of hint from stored
332 routines or sub query.
333
334 @param pc Pointer to Parse_context object
335
336 @return true in case of error,
337 false otherwise
338 */
339
340 bool do_contextualize(Parse_context *pc) override;
341
342 /**
343 Append hint arguments to given string.
344
345 @param thd Pointer to THD object.
346 @param str Pointer to String object.
347 */
348
349 void append_args(const THD *thd, String *str) const override {
352 }
353};
354
355#endif /* PARSE_TREE_HINTS_INCLUDED */
void append_identifier(String *packet, const char *name, size_t length)
Convert and quote the given identifier if needed and append it to the target string.
Definition: sql_show.cc:1461
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:934
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Definition: parse_tree_hints.h:100
PT_hint_list(MEM_ROOT *mem_root)
Definition: parse_tree_hints.h:106
Parse_tree_node super
Definition: parse_tree_hints.h:101
bool push_back(PT_hint *hint)
Definition: parse_tree_hints.h:121
Mem_root_array< PT_hint * > hints
Definition: parse_tree_hints.h:103
bool do_contextualize(Parse_context *pc) override
Function handles list of the hints we get after parse procedure.
Definition: parse_tree_hints.cc:338
Parse tree hint object for MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.h:270
PT_hint_max_execution_time(ulong milliseconds_arg)
Definition: parse_tree_hints.h:276
bool do_contextualize(Parse_context *pc) override
Function initializes MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.cc:497
PT_hint super
Definition: parse_tree_hints.h:271
void append_args(const THD *, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.h:288
ulong milliseconds
Definition: parse_tree_hints.h:274
Parse tree hint object for QB_NAME hint.
Definition: parse_tree_hints.h:243
const LEX_CSTRING qb_name
Definition: parse_tree_hints.h:244
void append_args(const THD *thd, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.h:261
PT_hint super
Definition: parse_tree_hints.h:246
PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
Definition: parse_tree_hints.h:249
bool do_contextualize(Parse_context *pc) override
Function sets query block name.
Definition: parse_tree_hints.cc:478
Parse tree hint object for RESOURCE_GROUP hint.
Definition: parse_tree_hints.h:320
void append_args(const THD *thd, String *str) const override
Append hint arguments to given string.
Definition: parse_tree_hints.h:349
PT_hint super
Definition: parse_tree_hints.h:323
PT_hint_resource_group(const LEX_CSTRING &name)
Definition: parse_tree_hints.h:326
bool do_contextualize(Parse_context *pc) override
Function initializes resource group name and checks for presence of resource group.
Definition: parse_tree_hints.cc:566
const LEX_CSTRING m_resource_group_name
Definition: parse_tree_hints.h:321
Definition: parse_tree_hints.h:293
PT_hint_sys_var(const LEX_CSTRING sys_var_name_arg, Item *sys_var_value_arg)
Definition: parse_tree_hints.h:300
Item * sys_var_value
Definition: parse_tree_hints.h:295
const LEX_CSTRING sys_var_name
Definition: parse_tree_hints.h:294
bool do_contextualize(Parse_context *pc) override
Function initializes SET_VAR hint.
Definition: parse_tree_hints.cc:524
PT_hint super
Definition: parse_tree_hints.h:297
The class is a base class for representation of the different types of the hints.
Definition: parse_tree_hints.h:58
PT_hint(opt_hints_enum hint_type_arg, bool switch_state_arg)
Definition: parse_tree_hints.h:62
virtual void print_warn(THD *thd, uint err_code, const LEX_CSTRING *qb_name_arg, LEX_CSTRING *table_name_arg, LEX_CSTRING *key_name_arg, PT_hint *hint) const
Print warning issuing in processing of the hint.
Definition: parse_tree_hints.cc:173
bool state
Definition: parse_tree_hints.h:60
opt_hints_enum hint_type
Definition: parse_tree_hints.h:59
bool switch_on() const
Definition: parse_tree_hints.h:68
virtual void append_args(const THD *thd, String *str) const
Append additional hint arguments.
Definition: parse_tree_hints.h:89
bool supports_view()
Definition: parse_tree_hints.h:91
opt_hints_enum type() const
Definition: parse_tree_hints.h:67
Parse tree hint object for key level hints.
Definition: parse_tree_hints.h:210
void append_args(const THD *thd, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.cc:393
Hint_param_table table_name
Definition: parse_tree_hints.h:211
PT_key_level_hint(Hint_param_table &table_name_arg, const Hint_param_index_list &key_list_arg, bool switch_state_arg, opt_hints_enum hint_type_arg)
Definition: parse_tree_hints.h:217
Hint_param_index_list key_list
Definition: parse_tree_hints.h:212
PT_hint super
Definition: parse_tree_hints.h:214
bool do_contextualize(Parse_context *pc) override
Function handles key level hint.
Definition: parse_tree_hints.cc:406
Parse tree hint object for query block level hints.
Definition: parse_tree_hints.h:127
PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg, enum opt_hints_enum hint_type_arg, uint arg)
Definition: parse_tree_hints.h:138
void append_args(const THD *thd, String *str) const override
Append hint arguments to given string.
Definition: parse_tree_hints.cc:287
Hint_param_table_list table_list
List of tables specified in join order hint.
Definition: parse_tree_hints.h:133
const LEX_CSTRING qb_name
Name of query block.
Definition: parse_tree_hints.h:129
bool do_contextualize(Parse_context *pc) override
Function handles query block level hint.
Definition: parse_tree_hints.cc:225
PT_hint super
Definition: parse_tree_hints.h:135
uint get_args() const
Definition: parse_tree_hints.h:152
virtual Hint_param_table_list * get_table_list()
Definition: parse_tree_hints.h:172
PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg, enum opt_hints_enum hint_type_arg, const Hint_param_table_list &table_list_arg)
Definition: parse_tree_hints.h:144
uint args
Bit mask of arguments to hint.
Definition: parse_tree_hints.h:131
Parse tree hint object for table level hints.
Definition: parse_tree_hints.h:179
PT_table_level_hint(const LEX_CSTRING qb_name_arg, const Hint_param_table_list &table_list_arg, bool switch_state_arg, opt_hints_enum hint_type_arg)
Definition: parse_tree_hints.h:186
bool do_contextualize(Parse_context *pc) override
Function handles table level hint.
Definition: parse_tree_hints.cc:354
Hint_param_table_list table_list
Definition: parse_tree_hints.h:181
const LEX_CSTRING qb_name
Definition: parse_tree_hints.h:180
PT_hint super
Definition: parse_tree_hints.h:183
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:231
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
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
Header for compiler-dependent features.
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1073
opt_hints_enum
Hint types, MAX_HINT_ENUM should be always last.
Definition: opt_hints.h:64
@ MAX_HINT_ENUM
Definition: opt_hints.h:88
@ ORDER_INDEX_HINT_ENUM
Definition: opt_hints.h:86
@ RESOURCE_GROUP_HINT_ENUM
Definition: opt_hints.h:80
@ QB_NAME_HINT_ENUM
Definition: opt_hints.h:71
@ MAX_EXEC_TIME_HINT_ENUM
Definition: opt_hints.h:70
@ INDEX_HINT_ENUM
Definition: opt_hints.h:83
Mem_root_array_YY< LEX_CSTRING > Hint_param_index_list
Definition: parse_tree_hints.h:50
Mem_root_array_YY< Hint_param_table > Hint_param_table_list
Definition: parse_tree_hints.h:51
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:29
Definition: parse_tree_hints.h:45
LEX_CSTRING table
Definition: parse_tree_hints.h:46
LEX_CSTRING opt_query_block
Definition: parse_tree_hints.h:47
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
const char * str
Definition: mysql_lex_string.h:41
size_t length
Definition: mysql_lex_string.h:42
Bison "location" class.
Definition: parse_location.h:43
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:420