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