MySQL  8.0.20
Source Code Documentation
parse_tree_hints.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2020, 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  bool supports_view() {
89  /*
90  Only index hints are supported to be used in views.
91  Other hints can be added separately.
92  */
93  return (type() >= INDEX_HINT_ENUM && type() <= ORDER_INDEX_HINT_ENUM);
94  }
95 };
96 
97 class PT_hint_list : public Parse_tree_node {
99 
101 
102  public:
103  explicit PT_hint_list(MEM_ROOT *mem_root) : hints(mem_root) {}
104 
105  /**
106  Function handles list of the hints we get after
107  parse procedure. It also creates query block hint
108  object(Opt_hints_qb) if it does not exists.
109 
110  @param pc Pointer to Parse_context object
111 
112  @return true in case of error,
113  false otherwise
114  */
115  bool contextualize(Parse_context *pc) override;
116 
117  bool push_back(PT_hint *hint) { return hints.push_back(hint); }
118 };
119 
120 /**
121  Parse tree hint object for query block level hints.
122 */
123 class PT_qb_level_hint : public PT_hint {
124  /** Name of query block. */
126  /** Bit mask of arguments to hint. */
128  /** List of tables specified in join order hint */
130 
131  typedef PT_hint super;
132 
133  public:
134  PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
135  enum opt_hints_enum hint_type_arg, uint arg)
136  : PT_hint(hint_type_arg, switch_state_arg),
137  qb_name(qb_name_arg),
138  args(arg) {}
139 
140  PT_qb_level_hint(const LEX_CSTRING qb_name_arg, bool switch_state_arg,
141  enum opt_hints_enum hint_type_arg,
142  const Hint_param_table_list &table_list_arg)
143  : PT_hint(hint_type_arg, switch_state_arg),
144  qb_name(qb_name_arg),
145  args(0),
146  table_list(table_list_arg) {}
147 
148  uint get_args() const { return args; }
149 
150  /**
151  Function handles query block level hint. It also creates query block hint
152  object (Opt_hints_qb) if it does not exist.
153 
154  @param pc Pointer to Parse_context object
155 
156  @return true in case of error,
157  false otherwise
158  */
159  bool contextualize(Parse_context *pc) override;
160 
161  /**
162  Append hint arguments to given string
163 
164  @param thd Pointer to THD object
165  @param str Pointer to String object
166  */
167  void append_args(const THD *thd, String *str) const override;
168  virtual Hint_param_table_list *get_table_list() { return &table_list; }
169 };
170 
171 /**
172  Parse tree hint object for table level hints.
173 */
174 
175 class PT_table_level_hint : public PT_hint {
178 
179  typedef PT_hint super;
180 
181  public:
182  PT_table_level_hint(const LEX_CSTRING qb_name_arg,
183  const Hint_param_table_list &table_list_arg,
184  bool switch_state_arg, opt_hints_enum hint_type_arg)
185  : PT_hint(hint_type_arg, switch_state_arg),
186  qb_name(qb_name_arg),
187  table_list(table_list_arg) {}
188 
189  /**
190  Function handles table level hint. It also creates
191  table hint object (Opt_hints_table) if it does not
192  exist.
193 
194  @param pc Pointer to Parse_context object
195 
196  @return true in case of error,
197  false otherwise
198  */
199  bool contextualize(Parse_context *pc) override;
200 };
201 
202 /**
203  Parse tree hint object for key level hints.
204 */
205 
206 class PT_key_level_hint : public PT_hint {
209 
210  typedef PT_hint super;
211 
212  public:
214  const Hint_param_index_list &key_list_arg,
215  bool switch_state_arg, opt_hints_enum hint_type_arg)
216  : PT_hint(hint_type_arg, switch_state_arg),
217  table_name(table_name_arg),
218  key_list(key_list_arg) {}
219 
220  /**
221  Function handles key level hint.
222  It also creates key hint object
223  (Opt_hints_key) if it does not
224  exist.
225 
226  @param pc Pointer to Parse_context object
227 
228  @return true in case of error,
229  false otherwise
230  */
231  bool contextualize(Parse_context *pc) override;
232  void append_args(const THD *thd, String *str) const override;
233 };
234 
235 /**
236  Parse tree hint object for QB_NAME hint.
237 */
238 
239 class PT_hint_qb_name : public PT_hint {
241 
242  typedef PT_hint super;
243 
244  public:
245  PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
246  : PT_hint(QB_NAME_HINT_ENUM, true), qb_name(qb_name_arg) {}
247 
248  /**
249  Function sets query block name.
250 
251  @param pc Pointer to Parse_context object
252 
253  @return true in case of error,
254  false otherwise
255  */
256  bool contextualize(Parse_context *pc) override;
257  void append_args(const THD *thd, String *str) const override {
258  append_identifier(thd, str, qb_name.str, qb_name.length);
259  }
260 };
261 
262 /**
263  Parse tree hint object for MAX_EXECUTION_TIME hint.
264 */
265 
267  typedef PT_hint super;
268 
269  public:
271 
272  explicit PT_hint_max_execution_time(ulong milliseconds_arg)
274  milliseconds(milliseconds_arg) {}
275  /**
276  Function initializes MAX_EXECUTION_TIME hint
277 
278  @param pc Pointer to Parse_context object
279 
280  @return true in case of error,
281  false otherwise
282  */
283  bool contextualize(Parse_context *pc) override;
284  void append_args(const THD *, String *str) const override {
285  str->append_ulonglong(milliseconds);
286  }
287 };
288 
289 class PT_hint_sys_var : public PT_hint {
292 
293  typedef PT_hint super;
294 
295  public:
296  explicit PT_hint_sys_var(const LEX_CSTRING sys_var_name_arg,
297  Item *sys_var_value_arg)
299  sys_var_name(sys_var_name_arg),
300  sys_var_value(sys_var_value_arg) {}
301  /**
302  Function initializes SET_VAR hint.
303 
304  @param pc Pointer to Parse_context object
305 
306  @return true in case of error,
307  false otherwise
308  */
309  bool contextualize(Parse_context *pc) override;
310 };
311 
312 /**
313  Parse tree hint object for RESOURCE_GROUP hint.
314 */
315 
318 
319  typedef PT_hint super;
320 
321  public:
323  : PT_hint(RESOURCE_GROUP_HINT_ENUM, true), m_resource_group_name(name) {}
324 
325  /**
326  Function initializes resource group name and checks for presence of
327  resource group. Also it checks for invocation of hint from stored
328  routines or sub query.
329 
330  @param pc Pointer to Parse_context object
331 
332  @return true in case of error,
333  false otherwise
334  */
335 
336  bool contextualize(Parse_context *pc) override;
337 
338  /**
339  Append hint arguments to given string.
340 
341  @param thd Pointer to THD object.
342  @param str Pointer to String object.
343  */
344 
345  void append_args(const THD *thd, String *str) const override {
346  append_identifier(thd, str, m_resource_group_name.str,
347  m_resource_group_name.length);
348  }
349 };
350 
351 #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:840
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:182
Definition: opt_hints.h:84
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:213
const LEX_CSTRING qb_name
Definition: parse_tree_hints.h:176
bool switch_on() const
Definition: parse_tree_hints.h:65
PT_hint super
Definition: parse_tree_hints.h:319
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:134
virtual Hint_param_table_list * get_table_list()
Definition: parse_tree_hints.h:168
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:296
Parse tree hint object for MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.h:266
PT_hint super
Definition: parse_tree_hints.h:179
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
PT_hint_resource_group(const LEX_CSTRING &name)
Definition: parse_tree_hints.h:322
uint get_args() const
Definition: parse_tree_hints.h:148
void append_args(const THD *thd, String *str) const override
Append hint arguments to given string.
Definition: parse_tree_hints.h:345
Definition: mysql_lex_string.h:39
Definition: parse_tree_hints.h:97
Mem_root_array< PT_hint * > hints
Definition: parse_tree_hints.h:100
Definition: opt_hints.h:81
Hint_param_table_list table_list
Definition: parse_tree_hints.h:177
PT_hint super
Definition: parse_tree_hints.h:293
Parse tree hint object for QB_NAME hint.
Definition: parse_tree_hints.h:239
Parse tree hint object for table level hints.
Definition: parse_tree_hints.h:175
const LEX_CSTRING sys_var_name
Definition: parse_tree_hints.h:290
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:164
PT_hint super
Definition: parse_tree_hints.h:267
Hint_param_index_list key_list
Definition: parse_tree_hints.h:208
const LEX_CSTRING m_resource_group_name
Definition: parse_tree_hints.h:317
Hint_param_table_list table_list
List of tables specified in join order hint.
Definition: parse_tree_hints.h:129
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:131
bool state
Definition: parse_tree_hints.h:59
Parse tree hint object for key level hints.
Definition: parse_tree_hints.h:206
bool supports_view()
Definition: parse_tree_hints.h:88
void append_args(const THD *thd, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.h:257
size_t length
Definition: mysql_lex_string.h:41
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:123
bool push_back(PT_hint *hint)
Definition: parse_tree_hints.h:117
Header for compiler-dependent features.
void append_args(const THD *, String *str) const override
Append additional hint arguments.
Definition: parse_tree_hints.h:284
Definition: item.h:740
unsigned int uint
Definition: uca-dump.cc:29
Parse_tree_node super
Definition: parse_tree_hints.h:98
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:111
case opt name
Definition: sslopt-case.h:32
#define true
Definition: config_static.h:44
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:270
Definition: parse_tree_hints.h:44
uint args
Bit mask of arguments to hint.
Definition: parse_tree_hints.h:127
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:389
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:316
Hint_param_table table_name
Definition: parse_tree_hints.h:207
opt_hints_enum hint_type
Definition: parse_tree_hints.h:58
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
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:103
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:291
Definition: opt_hints.h:78
Definition: parse_tree_hints.h:289
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:180
PT_hint_max_execution_time(ulong milliseconds_arg)
Definition: parse_tree_hints.h:272
PT_hint_qb_name(const LEX_CSTRING qb_name_arg)
Definition: parse_tree_hints.h:245
const LEX_CSTRING qb_name
Definition: parse_tree_hints.h:240
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:492
PT_hint super
Definition: parse_tree_hints.h:210
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:140
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:242
Definition: opt_hints.h:85
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:765
const LEX_CSTRING qb_name
Name of query block.
Definition: parse_tree_hints.h:125