-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathparse_tree_hints.h
355 lines (279 loc) · 10 KB
/
parse_tree_hints.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/* Copyright (c) 2015, 2024, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is designed to work with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have either included with
the program or referenced in the documentation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
/*
Parse tree node classes for optimizer hint syntax
*/
#ifndef PARSE_TREE_HINTS_INCLUDED
#define PARSE_TREE_HINTS_INCLUDED
#include <sys/types.h>
#include "lex_string.h"
#include "my_compiler.h"
#include "sql/mem_root_array.h"
#include "sql/opt_hints.h"
#include "sql/parse_tree_node_base.h"
#include "sql/sql_show.h"
#include "sql_string.h"
class Item;
class THD;
struct MEM_ROOT;
struct Hint_param_table {
LEX_CSTRING table;
LEX_CSTRING opt_query_block;
};
typedef Mem_root_array_YY<LEX_CSTRING> Hint_param_index_list;
typedef Mem_root_array_YY<Hint_param_table> Hint_param_table_list;
/**
The class is a base class for representation of the
different types of the hints. For the complex hints
it is also used as a container for additional arguments.
*/
class PT_hint : public Parse_tree_node {
opt_hints_enum hint_type; // Hint type
bool state; // true if hints is on, false otherwise
public:
PT_hint(opt_hints_enum hint_type_arg, bool switch_state_arg)
: Parse_tree_node(POS()) /* TODO: handle position in hints */,
hint_type(hint_type_arg),
state(switch_state_arg) {}
opt_hints_enum type() const { return hint_type; }
bool switch_on() const { return state; }
/**
Print warning issuing in processing of the hint.
@param thd Pointer to THD object
@param err_code Error code
@param qb_name_arg QB name
@param table_name_arg table name
@param key_name_arg key name
@param hint Pointer to hint object
*/
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;
/**
Append additional hint arguments.
@param thd Pointer to THD object
@param str Pointer to String object
*/
virtual void append_args(const THD *thd [[maybe_unused]],
String *str [[maybe_unused]]) const {}
bool supports_view() {
/*
Only index hints are supported to be used in views.
Other hints can be added separately.
*/
return (type() >= INDEX_HINT_ENUM && type() <= ORDER_INDEX_HINT_ENUM);
}
};
class PT_hint_list : public Parse_tree_node {
typedef Parse_tree_node super;
Mem_root_array<PT_hint *> hints;
public:
explicit PT_hint_list(MEM_ROOT *mem_root)
: super(POS()) /* TODO: handle position of hints */, hints(mem_root) {}
/**
Function handles list of the hints we get after
parse procedure. It also creates query block hint
object(Opt_hints_qb) if it does not exists.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
bool push_back(PT_hint *hint) { return hints.push_back(hint); }
};
/**
Parse tree hint object for query block level hints.
*/
class PT_qb_level_hint : public PT_hint {
/** Name of query block. */
const LEX_CSTRING qb_name;
/** Bit mask of arguments to hint. */
uint args;
/** List of tables specified in join order hint */
Hint_param_table_list table_list;
typedef PT_hint super;
public:
PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
enum opt_hints_enum hint_type_arg, uint arg)
: PT_hint(hint_type_arg, switch_state_arg),
qb_name(qb_name_arg),
args(arg) {}
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)
: PT_hint(hint_type_arg, switch_state_arg),
qb_name(qb_name_arg),
args(0),
table_list(table_list_arg) {}
uint get_args() const { return args; }
/**
Function handles query block level hint. It also creates query block hint
object (Opt_hints_qb) if it does not exist.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
/**
Append hint arguments to given string
@param thd Pointer to THD object
@param str Pointer to String object
*/
void append_args(const THD *thd, String *str) const override;
virtual Hint_param_table_list *get_table_list() { return &table_list; }
};
/**
Parse tree hint object for table level hints.
*/
class PT_table_level_hint : public PT_hint {
const LEX_CSTRING qb_name;
Hint_param_table_list table_list;
typedef PT_hint super;
public:
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)
: PT_hint(hint_type_arg, switch_state_arg),
qb_name(qb_name_arg),
table_list(table_list_arg) {}
/**
Function handles table level hint. It also creates
table hint object (Opt_hints_table) if it does not
exist.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
};
/**
Parse tree hint object for key level hints.
*/
class PT_key_level_hint : public PT_hint {
Hint_param_table table_name;
Hint_param_index_list key_list;
typedef PT_hint super;
public:
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)
: PT_hint(hint_type_arg, switch_state_arg),
table_name(table_name_arg),
key_list(key_list_arg) {}
/**
Function handles key level hint.
It also creates key hint object
(Opt_hints_key) if it does not
exist.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
void append_args(const THD *thd, String *str) const override;
};
/**
Parse tree hint object for QB_NAME hint.
*/
class PT_hint_qb_name : public PT_hint {
const LEX_CSTRING qb_name;
typedef PT_hint super;
public:
PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
: PT_hint(QB_NAME_HINT_ENUM, true), qb_name(qb_name_arg) {}
/**
Function sets query block name.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
void append_args(const THD *thd, String *str) const override {
append_identifier(thd, str, qb_name.str, qb_name.length);
}
};
/**
Parse tree hint object for MAX_EXECUTION_TIME hint.
*/
class PT_hint_max_execution_time : public PT_hint {
typedef PT_hint super;
public:
ulong milliseconds;
explicit PT_hint_max_execution_time(ulong milliseconds_arg)
: PT_hint(MAX_EXEC_TIME_HINT_ENUM, true),
milliseconds(milliseconds_arg) {}
/**
Function initializes MAX_EXECUTION_TIME hint
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
void append_args(const THD *, String *str) const override {
str->append_ulonglong(milliseconds);
}
};
class PT_hint_sys_var : public PT_hint {
const LEX_CSTRING sys_var_name;
Item *sys_var_value;
typedef PT_hint super;
public:
explicit PT_hint_sys_var(const LEX_CSTRING sys_var_name_arg,
Item *sys_var_value_arg)
: PT_hint(MAX_HINT_ENUM, true),
sys_var_name(sys_var_name_arg),
sys_var_value(sys_var_value_arg) {}
/**
Function initializes SET_VAR hint.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
};
/**
Parse tree hint object for RESOURCE_GROUP hint.
*/
class PT_hint_resource_group : public PT_hint {
const LEX_CSTRING m_resource_group_name;
typedef PT_hint super;
public:
PT_hint_resource_group(const LEX_CSTRING &name)
: PT_hint(RESOURCE_GROUP_HINT_ENUM, true), m_resource_group_name(name) {}
/**
Function initializes resource group name and checks for presence of
resource group. Also it checks for invocation of hint from stored
routines or sub query.
@param pc Pointer to Parse_context object
@return true in case of error,
false otherwise
*/
bool do_contextualize(Parse_context *pc) override;
/**
Append hint arguments to given string.
@param thd Pointer to THD object.
@param str Pointer to String object.
*/
void append_args(const THD *thd, String *str) const override {
append_identifier(thd, str, m_resource_group_name.str,
m_resource_group_name.length);
}
};
#endif /* PARSE_TREE_HINTS_INCLUDED */