MySQL  8.0.17
Source Code Documentation
parse_tree_hints.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
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 
40 class Item;
41 class THD;
42 struct 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 argumnets.
56 */
57 class PT_hint : public Parse_tree_node {
58  opt_hints_enum hint_type; // Hint type
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  : hint_type(hint_type_arg), state(switch_state_arg) {}
63 
64  opt_hints_enum type() const { return hint_type; }
65  bool switch_on() const { return state; }
66  /**
67  Print warning issuing in processing of the hint.
68 
69  @param thd Pointer to THD object
70  @param err_code Error code
71  @param qb_name_arg QB name
72  @param table_name_arg table name
73  @param key_name_arg key name
74  @param hint Pointer to hint object
75  */
76  virtual void print_warn(THD *thd, uint err_code,
77  const LEX_CSTRING *qb_name_arg,
78  LEX_CSTRING *table_name_arg,
79  LEX_CSTRING *key_name_arg, PT_hint *hint) const;
80  /**
81  Append additional hint arguments.
82 
83  @param thd Pointer to THD object
84  @param str Pointer to String object
85  */
86  virtual void append_args(const THD *thd MY_ATTRIBUTE((unused)),
87  String *str MY_ATTRIBUTE((unused))) const {}
88 };
89 
90 class PT_hint_list : public Parse_tree_node {
92 
94 
95  public:
97 
98  /**
99  Function handles list of the hints we get after
100  parse procedure. It also creates query block hint
101  object(Opt_hints_qb) if it does not exists.
102 
103  @param pc Pointer to Parse_context object
104 
105  @return true in case of error,
106  false otherwise
107  */
108  virtual bool contextualize(Parse_context *pc);
109 
110  bool push_back(PT_hint *hint) { return hints.push_back(hint); }
111 };
112 
113 /**
114  Parse tree hint object for query block level hints.
115 */
116 class PT_qb_level_hint : public PT_hint {
117  /** Name of query block. */
119  /** Bit mask of arguments to hint. */
121  /** List of tables specified in join order hint */
123 
124  typedef PT_hint super;
125 
126  public:
127  PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
128  enum opt_hints_enum hint_type_arg, uint arg)
129  : PT_hint(hint_type_arg, switch_state_arg),
130  qb_name(qb_name_arg),
131  args(arg) {}
132 
133  PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
134  enum opt_hints_enum hint_type_arg,
135  const Hint_param_table_list &table_list_arg)
136  : PT_hint(hint_type_arg, switch_state_arg),
137  qb_name(qb_name_arg),
138  args(0),
139  table_list(table_list_arg) {}
140 
141  uint get_args() const { return args; }
142 
143  /**
144  Function handles query block level hint. It also creates query block hint
145  object (Opt_hints_qb) if it does not exist.
146 
147  @param pc Pointer to Parse_context object
148 
149  @return true in case of error,
150  false otherwise
151  */
152  virtual bool contextualize(Parse_context *pc);
153 
154  /**
155  Append hint arguments to given string
156 
157  @param thd Pointer to THD object
158  @param str Pointer to String object
159  */
160  virtual void append_args(const THD *thd, String *str) const;
162 };
163 
164 /**
165  Parse tree hint object for table level hints.
166 */
167 
168 class PT_table_level_hint : public PT_hint {
171 
172  typedef PT_hint super;
173 
174  public:
175  PT_table_level_hint(const LEX_CSTRING qb_name_arg,
176  const Hint_param_table_list &table_list_arg,
177  bool switch_state_arg, opt_hints_enum hint_type_arg)
178  : PT_hint(hint_type_arg, switch_state_arg),
179  qb_name(qb_name_arg),
180  table_list(table_list_arg) {}
181 
182  /**
183  Function handles table level hint. It also creates
184  table hint object (Opt_hints_table) if it does not
185  exist.
186 
187  @param pc Pointer to Parse_context object
188 
189  @return true in case of error,
190  false otherwise
191  */
192  virtual bool contextualize(Parse_context *pc);
193 };
194 
195 /**
196  Parse tree hint object for key level hints.
197 */
198 
199 class PT_key_level_hint : public PT_hint {
202 
203  typedef PT_hint super;
204 
205  public:
207  const Hint_param_index_list &key_list_arg,
208  bool switch_state_arg, opt_hints_enum hint_type_arg)
209  : PT_hint(hint_type_arg, switch_state_arg),
210  table_name(table_name_arg),
211  key_list(key_list_arg) {}
212 
213  /**
214  Function handles key level hint.
215  It also creates key hint object
216  (Opt_hints_key) if it does not
217  exist.
218 
219  @param pc Pointer to Parse_context object
220 
221  @return true in case of error,
222  false otherwise
223  */
224  bool contextualize(Parse_context *pc) override;
225  void append_args(const THD *thd, String *str) const override;
226 };
227 
228 /**
229  Parse tree hint object for QB_NAME hint.
230 */
231 
232 class PT_hint_qb_name : public PT_hint {
234 
235  typedef PT_hint super;
236 
237  public:
238  PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
239  : PT_hint(QB_NAME_HINT_ENUM, true), qb_name(qb_name_arg) {}
240 
241  /**
242  Function sets query block name.
243 
244  @param pc Pointer to Parse_context object
245 
246  @return true in case of error,
247  false otherwise
248  */
249  bool contextualize(Parse_context *pc) override;
250  void append_args(const THD *thd, String *str) const override {
252  }
253 };
254 
255 /**
256  Parse tree hint object for MAX_EXECUTION_TIME hint.
257 */
258 
260  typedef PT_hint super;
261 
262  public:
264 
265  explicit PT_hint_max_execution_time(ulong milliseconds_arg)
267  milliseconds(milliseconds_arg) {}
268  /**
269  Function initializes MAX_EXECUTION_TIME hint
270 
271  @param pc Pointer to Parse_context object
272 
273  @return true in case of error,
274  false otherwise
275  */
276  virtual bool contextualize(Parse_context *pc);
277  virtual void append_args(const THD *, String *str) const {
279  }
280 };
281 
282 class PT_hint_sys_var : public PT_hint {
285 
286  typedef PT_hint super;
287 
288  public:
289  explicit PT_hint_sys_var(const LEX_CSTRING sys_var_name_arg,
290  Item *sys_var_value_arg)
292  sys_var_name(sys_var_name_arg),
293  sys_var_value(sys_var_value_arg) {}
294  /**
295  Function initializes SET_VAR hint.
296 
297  @param pc Pointer to Parse_context object
298 
299  @return true in case of error,
300  false otherwise
301  */
302  virtual bool contextualize(Parse_context *pc);
303 };
304 
305 /**
306  Parse tree hint object for RESOURCE_GROUP hint.
307 */
308 
311 
312  typedef PT_hint super;
313 
314  public:
317 
318  /**
319  Function initializes resource group name and checks for presence of
320  resource group. Also it checks for invocation of hint from stored
321  routines or sub query.
322 
323  @param pc Pointer to Parse_context object
324 
325  @return true in case of error,
326  false otherwise
327  */
328 
329  bool contextualize(Parse_context *pc) override;
330 
331  /**
332  Append hint arguments to given string.
333 
334  @param thd Pointer to THD object.
335  @param str Pointer to String object.
336  */
337 
338  void append_args(const THD *thd, String *str) const override {
341  }
342 };
343 
344 #endif /* PARSE_TREE_HINTS_INCLUDED */
Our own string classes, used pervasively throughout the executor.
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:776
void append_args(const THD *thd, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.cc:362
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:175
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:206
const LEX_CSTRING qb_name
Definition: parse_tree_hints.h:169
bool switch_on() const
Definition: parse_tree_hints.h:65
PT_hint super
Definition: parse_tree_hints.h:312
const string name("\ame\)
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:127
virtual Hint_param_table_list * get_table_list()
Definition: parse_tree_hints.h:161
Definition: opt_hints.h:69
PT_hint_sys_var(const LEX_CSTRING sys_var_name_arg, Item *sys_var_value_arg)
Definition: parse_tree_hints.h:289
Parse tree hint object for MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.h:259
PT_hint super
Definition: parse_tree_hints.h:172
const char * str
Definition: mysql_lex_string.h:40
Mem_root_array_YY< LEX_CSTRING > Hint_param_index_list
Definition: parse_tree_hints.h:49
bool contextualize(Parse_context *pc) override
Function handles key level hint.
Definition: parse_tree_hints.cc:375
PT_hint_resource_group(const LEX_CSTRING &name)
Definition: parse_tree_hints.h:315
uint get_args() const
Definition: parse_tree_hints.h:141
void append_args(const THD *thd, String *str) const override
Append hint arguments to given string.
Definition: parse_tree_hints.h:338
Definition: mysql_lex_string.h:39
Definition: parse_tree_hints.h:90
Mem_root_array< PT_hint * > hints
Definition: parse_tree_hints.h:93
Hint_param_table_list table_list
Definition: parse_tree_hints.h:170
PT_hint super
Definition: parse_tree_hints.h:286
Parse tree hint object for QB_NAME hint.
Definition: parse_tree_hints.h:232
Parse tree hint object for table level hints.
Definition: parse_tree_hints.h:168
const LEX_CSTRING sys_var_name
Definition: parse_tree_hints.h:283
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
PT_hint super
Definition: parse_tree_hints.h:260
Hint_param_index_list key_list
Definition: parse_tree_hints.h:201
const LEX_CSTRING m_resource_group_name
Definition: parse_tree_hints.h:310
Hint_param_table_list table_list
List of tables specified in join order hint.
Definition: parse_tree_hints.h:122
virtual bool contextualize(Parse_context *pc)
Function initializes MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.cc:450
opt_hints_enum
Hint types, MAX_HINT_ENUM should be always last.
Definition: opt_hints.h:62
PT_hint super
Definition: parse_tree_hints.h:124
bool state
Definition: parse_tree_hints.h:59
Parse tree hint object for key level hints.
Definition: parse_tree_hints.h:199
virtual bool contextualize(Parse_context *pc)
Function handles query block level hint.
Definition: parse_tree_hints.cc:202
virtual void append_args(const THD *, String *str) const
Append additional hint arguments.
Definition: parse_tree_hints.h:277
void append_args(const THD *thd, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.h:250
size_t length
Definition: mysql_lex_string.h:41
bool contextualize(Parse_context *pc) override
Function sets query block name.
Definition: parse_tree_hints.cc:432
LEX_CSTRING opt_query_block
Definition: parse_tree_hints.h:46
Parse tree hint object for query block level hints.
Definition: parse_tree_hints.h:116
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:150
bool push_back(PT_hint *hint)
Definition: parse_tree_hints.h:110
Header for compiler-dependent features.
Definition: item.h:666
unsigned int uint
Definition: uca-dump.cc:29
Parse_tree_node super
Definition: parse_tree_hints.h:91
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:111
#define true
Definition: config_static.h:44
virtual bool contextualize(Parse_context *pc)
Function handles table level hint.
Definition: parse_tree_hints.cc:325
The class is a base class for representation of the different types of the hints. ...
Definition: parse_tree_hints.h:57
ulong milliseconds
Definition: parse_tree_hints.h:263
Definition: parse_tree_hints.h:44
uint args
Bit mask of arguments to hint.
Definition: parse_tree_hints.h:120
bool contextualize(Parse_context *pc) override
Function initializes resource group name and checks for presence of resource group.
Definition: parse_tree_hints.cc:516
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:397
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:99
Parse tree hint object for RESOURCE_GROUP hint.
Definition: parse_tree_hints.h:309
Hint_param_table table_name
Definition: parse_tree_hints.h:200
opt_hints_enum hint_type
Definition: parse_tree_hints.h:58
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
virtual void append_args(const THD *thd, String *str) const
Append hint arguments to given string.
Definition: parse_tree_hints.cc:263
virtual void append_args(const THD *thd, String *str) const
Append additional hint arguments.
Definition: parse_tree_hints.h:86
PT_hint_list(MEM_ROOT *mem_root)
Definition: parse_tree_hints.h:96
Mem_root_array_YY< Hint_param_table > Hint_param_table_list
Definition: parse_tree_hints.h:50
LEX_CSTRING table
Definition: parse_tree_hints.h:45
Item * sys_var_value
Definition: parse_tree_hints.h:284
Definition: opt_hints.h:78
Definition: parse_tree_hints.h:282
bool push_back(const Element_type &element)
Adds a new element at the end of the array, after its current last element.
Definition: mem_root_array.h:188
PT_hint_max_execution_time(ulong milliseconds_arg)
Definition: parse_tree_hints.h:265
virtual bool contextualize(Parse_context *pc)
Function handles list of the hints we get after parse procedure.
Definition: parse_tree_hints.cc:314
PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
Definition: parse_tree_hints.h:238
const LEX_CSTRING qb_name
Definition: parse_tree_hints.h:233
virtual bool contextualize(Parse_context *pc)
Function initializes SET_VAR hint.
Definition: parse_tree_hints.cc:476
opt_hints_enum type() const
Definition: parse_tree_hints.h:64
bool append_ulonglong(ulonglong val)
Append an unsigned longlong to the string.
Definition: sql_string.cc:498
PT_hint super
Definition: parse_tree_hints.h:203
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
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:133
PT_hint(opt_hints_enum hint_type_arg, bool switch_state_arg)
Definition: parse_tree_hints.h:61
PT_hint super
Definition: parse_tree_hints.h:235
unsigned long ulong
Definition: my_inttypes.h:48
Definition: opt_hints.h:80
Definition: opt_hints.h:68
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
const LEX_CSTRING qb_name
Name of query block.
Definition: parse_tree_hints.h:118