MySQL  8.0.18
Source Code Documentation
opt_hints.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2019, 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 OPT_HINTS_INCLUDED
28 #define OPT_HINTS_INCLUDED
29 
30 #include <stddef.h>
31 #include <sys/types.h>
32 
33 #include "lex_string.h"
34 #include "m_ctype.h"
35 #include "m_string.h"
36 #include "my_compiler.h"
37 #include "my_dbug.h"
38 #include "my_inttypes.h"
39 #include "sql/enum_query_type.h"
40 #include "sql/item_subselect.h" // Item_exists_subselect
41 #include "sql/mem_root_array.h" // Mem_root_array
42 #include "sql/sql_bitmap.h" // Bitmap
43 #include "sql/sql_show.h" // append_identifier
44 #include "sql_string.h" // String
45 
46 class Item;
47 class JOIN;
48 class Opt_hints_table;
49 class Sys_var_hint;
50 class THD;
51 class set_var;
52 class sys_var;
53 struct MEM_ROOT;
54 struct TABLE;
55 struct TABLE_LIST;
56 
57 /**
58  Hint types, MAX_HINT_ENUM should be always last.
59  This enum should be synchronized with opt_hint_info
60  array(see opt_hints.cc).
61 */
82 };
83 
85  const char *hint_name; // Hint name.
86  bool check_upper_lvl; // true if upper level hint check is needed (for hints
87  // which can be specified on more than one level).
88  bool switch_hint; // true if hint is not complex.
89  bool irregular_hint; ///< true if hint requires some special handling.
90  ///< Currently it's used only for join order hints
91  ///< since they need special printing procedure.
92 };
93 
94 /**
95  Opt_hints_map contains information
96  about hint state(specified or not, hint value).
97 */
98 
100  Bitmap<64> hints; // hint state
101  Bitmap<64> hints_specified; // true if hint is specified
102  public:
103  /**
104  Check if hint is specified.
105 
106  @param type_arg hint type
107 
108  @return true if hint is specified
109  */
110  bool is_specified(opt_hints_enum type_arg) const {
111  return hints_specified.is_set(type_arg);
112  }
113  /**
114  Set switch value and set hint into specified state.
115 
116  @param type_arg hint type
117  @param switch_state_arg switch value
118  */
119  void set_switch(opt_hints_enum type_arg, bool switch_state_arg) {
120  if (switch_state_arg)
121  hints.set_bit(type_arg);
122  else
123  hints.clear_bit(type_arg);
124  hints_specified.set_bit(type_arg);
125  }
126  /**
127  Get switch value.
128 
129  @param type_arg hint type
130 
131  @return switch value.
132  */
133  bool switch_on(opt_hints_enum type_arg) const {
134  return hints.is_set(type_arg);
135  }
136 };
137 
138 class Opt_hints_key;
139 class PT_hint;
141 
142 /**
143  Opt_hints class is used as ancestor for Opt_hints_global,
144  Opt_hints_qb, Opt_hints_table, Opt_hints_key classes.
145 
146  Opt_hints_global class is hierarchical structure.
147  It contains information about global hints and also
148  conains array of QUERY BLOCK level objects (Opt_hints_qb class).
149  Each QUERY BLOCK level object contains array of TABLE level hints
150  (class Opt_hints_table). Each TABLE level hint contains array of
151  KEY lelev hints (Opt_hints_key class).
152  Hint information(specified, on|off state) is stored in hints_map object.
153 */
154 
155 class Opt_hints {
156  /*
157  Name of object referred by the hint.
158  This name is empty for global level,
159  query block name for query block level,
160  table name for table level and key name
161  for key level.
162  */
164  /*
165  Parent object. There is no parent for global level,
166  for query block level parent is Opt_hints_global object,
167  for table level parent is Opt_hints_qb object,
168  for key level parent is Opt_hints_key object.
169  */
171 
173 
174  /* Array of child objects. i.e. array of the lower level objects */
176  /* true if hint is connected to the real object */
177  bool resolved;
178  /* Number of resolved children */
180 
181  public:
182  Opt_hints(const LEX_CSTRING *name_arg, Opt_hints *parent_arg,
183  MEM_ROOT *mem_root_arg)
184  : name(name_arg),
185  parent(parent_arg),
186  child_array(mem_root_arg),
187  resolved(false),
188  resolved_children(0) {}
189 
190  virtual ~Opt_hints() {}
191 
192  bool is_specified(opt_hints_enum type_arg) const {
193  return hints_map.is_specified(type_arg);
194  }
195 
196  /**
197  Function sets switch hint state.
198 
199  @param switch_state_arg switch hint state
200  @param type_arg hint type
201  @param check_parent true if hint can be on parent level
202 
203  @return true if hint is already specified,
204  false otherwise
205  */
206  bool set_switch(bool switch_state_arg, opt_hints_enum type_arg,
207  bool check_parent) {
208  if (is_specified(type_arg) ||
209  (check_parent && parent->is_specified(type_arg)))
210  return true;
211 
212  hints_map.set_switch(type_arg, switch_state_arg);
213  return false;
214  }
215 
216  /**
217  Function returns switch hint state.
218 
219  @param type_arg hint type
220 
221  @return hint value if hint is specified,
222  false otherwise
223  */
224  bool get_switch(opt_hints_enum type_arg) const;
225 
226  virtual const LEX_CSTRING *get_name() const { return name; }
227  void set_name(const LEX_CSTRING *name_arg) { name = name_arg; }
228  Opt_hints *get_parent() const { return parent; }
229  virtual void set_resolved() { resolved = true; }
230  /**
231  Returns 'resolved' flag value for depending on hint type.
232 
233  @param type_arg hint type
234 
235  @return true if all hint objects are resolved, false otherwise.
236  */
237  virtual bool is_resolved(opt_hints_enum type_arg MY_ATTRIBUTE((unused))) {
238  return resolved;
239  }
240  /**
241  Set hint to unresolved state.
242 
243  @param type_arg hint type
244  */
245  virtual void set_unresolved(opt_hints_enum type_arg MY_ATTRIBUTE((unused))) {}
246  /**
247  If ignore_print() returns true, hint is not printed
248  in Opt_hints::print() function. Atm used for
249  INDEX_MERGE, SKIP_SCAN hints.
250 
251  @param type_arg hint type
252 
253  @return true if the hint should not be printed
254  in Opt_hints::print() function, false otherwise.
255  */
256  virtual bool ignore_print(
257  opt_hints_enum type_arg MY_ATTRIBUTE((unused))) const {
258  return false;
259  }
262 
263  bool is_all_resolved() const {
264  return child_array.size() == resolved_children;
265  }
266 
267  void register_child(Opt_hints *hint_arg) { child_array.push_back(hint_arg); }
268 
269  /**
270  Returns pointer to complex hint for a given type.
271 
272  A complex hint is a hint that has arguments.
273  (It is not just an on/off switch.)
274 
275  @param type hint type
276 
277  @return pointer to complex hint for a given type.
278  */
280  opt_hints_enum type MY_ATTRIBUTE((unused))) {
281  DBUG_ASSERT(0);
282  return NULL; /* error C4716: must return a value */
283  }
284 
285  /**
286  Find hint among lower-level hint objects.
287 
288  @param name_arg hint name
289  @param cs Pointer to character set
290 
291  @return hint if found,
292  NULL otherwise
293  */
294  Opt_hints *find_by_name(const LEX_CSTRING *name_arg,
295  const CHARSET_INFO *cs) const;
296  /**
297  Print all hints except of QB_NAME hint.
298 
299  @param thd Pointer to THD object
300  @param str Pointer to String object
301  @param query_type If query type is QT_NORMALIZED_FORMAT,
302  un-resolved hints will also be printed
303  */
304  void print(const THD *thd, String *str, enum_query_type query_type);
305  /**
306  Check if there are any unresolved hint objects and
307  print warnings for them.
308 
309  @param thd Pointer to THD object
310  */
311  void check_unresolved(THD *thd);
312  virtual void append_name(const THD *thd, String *str) = 0;
313 
314  private:
315  /**
316  Append hint type.
317 
318  @param str Pointer to String object
319  @param type Hint type
320  */
322  /**
323  Print warning for unresolved hint name.
324 
325  @param thd Pointer to THD object
326  */
327  void print_warn_unresolved(THD *thd);
328  /**
329  Function prints hints which are non-standard and don't
330  fit into existing hint infrastructure.
331 
332  @param thd pointer to THD object
333  @param str pointer to String object
334  */
335  virtual void print_irregular_hints(const THD *thd MY_ATTRIBUTE((unused)),
336  String *str MY_ATTRIBUTE((unused))) {}
337 };
338 
339 /**
340  Global level hints.
341 */
342 
343 class Opt_hints_global : public Opt_hints {
344  public:
347 
348  Opt_hints_global(MEM_ROOT *mem_root_arg)
349  : Opt_hints(NULL, NULL, mem_root_arg) {
351  sys_var_hint = NULL;
352  }
353 
354  void append_name(const THD *, String *) override {}
356  void print_irregular_hints(const THD *thd, String *str) override;
357 };
358 
359 class PT_qb_level_hint;
360 
361 /**
362  Query block level hints.
363 */
364 
365 class Opt_hints_qb : public Opt_hints {
366  uint select_number; // SELECT_LEX number
367  LEX_CSTRING sys_name; // System QB name
368  char buff[32]; // Buffer to hold sys name
369 
371 
372  /// Array of join order hints
374  /// Bit map of which hints are ignored.
376 
377  /*
378  PT_qb_level_hint::contextualize sets subquery/semijoin_hint during parsing.
379  it also registers join order hints during parsing.
380  */
381  friend class PT_qb_level_hint;
382 
383  public:
384  Opt_hints_qb(Opt_hints *opt_hints_arg, MEM_ROOT *mem_root_arg,
385  uint select_number_arg);
386 
388  const LEX_CSTRING *str = Opt_hints::get_name();
389  return str ? str : &sys_name;
390  }
391 
392  /**
393  Append query block hint.
394 
395  @param thd pointer to THD object
396  @param str pointer to String object
397  */
398  void append_qb_hint(const THD *thd, String *str) {
399  if (get_name()) {
400  str->append(STRING_WITH_LEN("QB_NAME("));
401  append_identifier(thd, str, get_name()->str, get_name()->length);
402  str->append(STRING_WITH_LEN(") "));
403  }
404  }
405  /**
406  Append query block name.
407 
408  @param thd pointer to THD object
409  @param str pointer to String object
410  */
411  void append_name(const THD *thd, String *str) override {
412  str->append(STRING_WITH_LEN("@"));
413  append_identifier(thd, str, get_print_name()->str,
415  }
416 
418 
419  /**
420  Function finds Opt_hints_table object corresponding to
421  table alias in the query block and attaches corresponding
422  key hint objects to appropriate KEY structures.
423 
424  @param table Table reference
425 
426  @return pointer Opt_hints_table object if this object is found,
427  NULL otherwise.
428  */
430 
431  /**
432  Returns whether semi-join is enabled for this query block
433 
434  A SEMIJOIN hint will force semi-join regardless of optimizer_switch
435  settings. A NO_SEMIJOIN hint will only turn off semi-join if the variant
436  with no strategies is used. A SUBQUERY hint will turn off semi-join. If
437  there is no SEMIJOIN/SUBQUERY hint, optimizer_switch setting determines
438  whether SEMIJOIN is used.
439 
440  @param thd Pointer to THD object for session.
441  Used to access optimizer_switch
442 
443  @return true if semijoin is enabled
444  */
445  bool semijoin_enabled(THD *thd) const;
446 
447  /**
448  Returns bit mask of which semi-join strategies are enabled for this query
449  block.
450 
451  @param opt_switches Bit map of strategies enabled by optimizer_switch
452 
453  @return Bit mask of strategies that are enabled
454  */
455  uint sj_enabled_strategies(uint opt_switches) const;
456 
457  /**
458  Returns which subquery execution strategy has been specified by hints
459  for this query block.
460 
461  @retval EXEC_MATERIALIZATION Subquery Materialization should be used
462  @retval EXEC_EXISTS In-to-exists execution should be used
463  @retval EXEC_UNSPECIFIED No SUBQUERY hint for this query block
464  */
466 
467  void print_irregular_hints(const THD *thd, String *str) override;
468 
469  /**
470  Checks if join order hints are applicable and
471  applies table dependencies if possible.
472 
473  @param join JOIN object
474  */
476 
477  private:
479  join_order_hints.push_back(hint_arg);
480  }
481 };
482 
483 class PT_key_level_hint;
484 
485 /**
486  Auxiluary class for compound key objects.
487 */
489  PT_key_level_hint *pt_hint; // Pointer to PT_key_level_hint object.
490  Key_map key_map; // Indexes, specified in the hint.
491  bool resolved; // true if hint does not have unresolved index.
492 
493  public:
495  key_map.init();
496  resolved = false;
497  pt_hint = NULL;
498  }
499 
500  void set_pt_hint(PT_key_level_hint *pt_hint_arg) { pt_hint = pt_hint_arg; }
502 
503  void set_resolved(bool arg) { resolved = arg; }
504  bool is_resolved() { return resolved; }
505 
506  void set_key_map(uint i) { key_map.set_bit(i); }
507  bool is_set_key_map(uint i) { return key_map.is_set(i); }
509 };
510 
511 /**
512  Table level hints.
513 */
514 
515 class Opt_hints_table : public Opt_hints {
516  public:
520 
521  Opt_hints_table(const LEX_CSTRING *table_name_arg, Opt_hints_qb *qb_hints_arg,
522  MEM_ROOT *mem_root_arg)
523  : Opt_hints(table_name_arg, qb_hints_arg, mem_root_arg),
524  keyinfo_array(mem_root_arg) {}
525 
526  /**
527  Append table name.
528 
529  @param thd pointer to THD object
530  @param str pointer to String object
531  */
532  void append_name(const THD *thd, String *str) override {
533  append_identifier(thd, str, get_name()->str, get_name()->length);
534  get_parent()->append_name(thd, str);
535  }
536  /**
537  Function sets correlation between key hint objects and
538  appropriate KEY structures.
539 
540  @param table Pointer to TABLE_LIST object
541  */
542  void adjust_key_hints(TABLE_LIST *table);
543  virtual PT_hint *get_complex_hints(opt_hints_enum type) override;
544 
545  void set_resolved() override {
549  }
550 
551  void set_unresolved(opt_hints_enum type_arg) override {
552  if (is_specified(type_arg) && is_compound_key_hint(type_arg))
553  get_compound_key_hint(type_arg)->set_resolved(false);
554  }
555 
556  bool is_resolved(opt_hints_enum type_arg) override {
557  if (is_compound_key_hint(type_arg))
558  return Opt_hints::is_resolved(type_arg) &&
559  get_compound_key_hint(type_arg)->is_resolved();
560  return Opt_hints::is_resolved(type_arg);
561  }
562 
566  }
567 
569  if (type_arg == INDEX_MERGE_HINT_ENUM) return &index_merge;
570  if (type_arg == SKIP_SCAN_HINT_ENUM) return &skip_scan;
571  DBUG_ASSERT(0);
572  return NULL;
573  }
574 
576  return (type_arg == INDEX_MERGE_HINT_ENUM ||
577  type_arg == SKIP_SCAN_HINT_ENUM);
578  }
579 };
580 
581 /**
582  Key level hints.
583 */
584 
585 class Opt_hints_key : public Opt_hints {
586  public:
587  Opt_hints_key(const LEX_CSTRING *key_name_arg,
588  Opt_hints_table *table_hints_arg, MEM_ROOT *mem_root_arg)
589  : Opt_hints(key_name_arg, table_hints_arg, mem_root_arg) {}
590 
591  /**
592  Append key name.
593 
594  @param thd pointer to THD object
595  @param str pointer to String object
596  */
597  void append_name(const THD *thd, String *str) override {
598  get_parent()->append_name(thd, str);
599  str->append(' ');
600  append_identifier(thd, str, get_name()->str, get_name()->length);
601  }
602  /**
603  Ignore printing of the object since parent complex hint has
604  its own printing method.
605  */
606  bool ignore_print(opt_hints_enum type_arg) const override {
607  return (type_arg == INDEX_MERGE_HINT_ENUM ||
608  type_arg == SKIP_SCAN_HINT_ENUM);
609  }
610 };
611 
612 /**
613  Container for set_var object and original variable value.
614 */
615 
617  public:
618  Hint_set_var(set_var *var_arg) : var(var_arg), save_value(NULL) {}
619  set_var *var; // Pointer to set_var object
620  Item *save_value; // Original variable value
621 };
622 
623 /**
624  SET_VAR hints.
625 */
626 
628  // List of str_var variables which need to be updated.
630 
631  public:
632  Sys_var_hint(MEM_ROOT *mem_root_arg) : var_list(mem_root_arg) {}
633  /**
634  Add variable to hint list.
635 
636  @param thd pointer to THD object
637  @param sys_var pointer to sys_var object
638  @param sys_var_value variable value
639 
640  @return true if variable is added,
641  false otherwise
642  */
643  bool add_var(THD *thd, sys_var *sys_var, Item *sys_var_value);
644  /**
645  Find variable in hint list.
646 
647  @param thd Pointer to thread object
648 
649  @return true if variable is found,
650  false otherwise
651  */
652  void update_vars(THD *thd);
653  /**
654  Restore system variables with original values.
655 
656  @param thd Pointer to thread object
657  */
658  void restore_vars(THD *thd);
659  /**
660  Print applicable hints.
661 
662  @param thd Thread handle
663  @param str Pointer to string object
664  */
665  void print(const THD *thd, String *str);
666 };
667 
668 /**
669  Returns key hint value if hint is specified, returns
670  optimizer switch value if hint is not specified.
671 
672  @param thd Pointer to THD object
673  @param table Pointer to TABLE_LIST object
674  @param keyno Key number
675  @param type_arg Hint type
676  @param optimizer_switch Optimizer switch flag
677 
678  @return key hint value if hint is specified,
679  otherwise optimizer switch value.
680 */
681 bool hint_key_state(const THD *thd, const TABLE_LIST *table, uint keyno,
682  opt_hints_enum type_arg, uint optimizer_switch);
683 
684 /**
685  Returns table hint value if hint is specified, returns
686  optimizer switch value if hint is not specified.
687 
688  @param thd Pointer to THD object
689  @param table Pointer to TABLE_LIST object
690  @param type_arg Hint type
691  @param optimizer_switch Optimizer switch flag
692 
693  @return table hint value if hint is specified,
694  otherwise optimizer switch value.
695 */
696 bool hint_table_state(const THD *thd, const TABLE_LIST *table,
697  opt_hints_enum type_arg, uint optimizer_switch);
698 /**
699  Append table and query block name.
700 
701  @param thd pointer to THD object
702  @param str pointer to String object
703  @param qb_name pointer to query block name, may be null
704  @param table_name pointer to table name
705 */
706 void append_table_name(const THD *thd, String *str, const LEX_CSTRING *qb_name,
707  const LEX_CSTRING *table_name);
708 
709 /**
710  Returns true if compoubd hint state is on with or without
711  specified keys, otherwise returns false.
712  If compound hint state is on and hint is specified without indexes,
713  function returns 'true' for any 'keyno' argument. If hint specified
714  with indexes, function returns true only for appropriate 'keyno' index.
715 
716 
717  @param table Pointer to TABLE object
718  @param keyno Key number
719  @param type_arg Hint type
720 
721  @return true if compound hint state is on with or without
722  specified keys, otherwise returns false.
723 */
724 
725 bool compound_hint_key_enabled(const TABLE *table, uint keyno,
726  opt_hints_enum type_arg);
727 
728 /**
729  Returns true if index merge hint state is on otherwise returns false.
730 
731  @param table Pointer to TABLE object
732  @param use_cheapest_index_merge IN/OUT Returns true if INDEX_MERGE hint is
733  used without any specified key.
734 
735  @return true if index merge hint state is on otherwise returns false.
736 */
737 
738 bool idx_merge_hint_state(const TABLE *table, bool *use_cheapest_index_merge);
739 
740 #endif /* OPT_HINTS_INCLUDED */
Definition: opt_hints.h:63
Compound_key_hint * get_compound_key_hint(opt_hints_enum type_arg)
Definition: opt_hints.h:568
unsigned long long int ulonglong
Definition: my_inttypes.h:55
virtual bool is_resolved(opt_hints_enum type_arg)
Returns &#39;resolved&#39; flag value for depending on hint type.
Definition: opt_hints.h:237
Mem_root_array< Opt_hints_key * > keyinfo_array
Definition: opt_hints.h:517
Definition: sql_optimizer.h:177
Our own string classes, used pervasively throughout the executor.
void update_vars(THD *thd)
Find variable in hint list.
Definition: opt_hints.cc:645
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
bool irregular_hint
true if hint requires some special handling.
Definition: opt_hints.h:89
Opt_hints_key(const LEX_CSTRING *key_name_arg, Opt_hints_table *table_hints_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:587
bool resolved
Definition: opt_hints.h:491
Definition: opt_hints.h:72
virtual void append_name(const THD *thd, String *str)=0
void check_unresolved(THD *thd)
Check if there are any unresolved hint objects and print warnings for them.
Definition: opt_hints.cc:176
void append_name(const THD *thd, String *str) override
Append key name.
Definition: opt_hints.h:597
PT_key_level_hint * pt_hint
Definition: opt_hints.h:489
void set_pt_hint(PT_key_level_hint *pt_hint_arg)
Definition: opt_hints.h:500
void set_name(const LEX_CSTRING *name_arg)
Definition: opt_hints.h:227
Opt_hints_map hints_map
Definition: opt_hints.h:172
Opt_hints_qb(Opt_hints *opt_hints_arg, MEM_ROOT *mem_root_arg, uint select_number_arg)
Definition: opt_hints.cc:196
Definition: opt_hints.h:80
Definition: opt_hints.h:75
bool resolved
Definition: opt_hints.h:177
Some integer typedefs for easier portability.
bool is_specified(opt_hints_enum type_arg) const
Definition: opt_hints.h:192
Bitmap< 64 > hints_specified
Definition: opt_hints.h:101
Definition: opt_hints.h:69
Parse tree hint object for MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.h:259
Key_map key_map
Definition: opt_hints.h:490
Definition: opt_hints.h:76
Definition: sql_bitmap.h:135
bool is_resolved(opt_hints_enum type_arg) override
Returns &#39;resolved&#39; flag value for depending on hint type.
Definition: opt_hints.h:556
bool is_set(uint n) const
Definition: sql_bitmap.h:167
PT_qb_level_hint * semijoin_hint
Definition: opt_hints.h:370
void append_name(const THD *thd, String *str) override
Append table name.
Definition: opt_hints.h:532
void set_resolved(bool arg)
Definition: opt_hints.h:503
Key level hints.
Definition: opt_hints.h:585
Mem_root_array< PT_qb_level_hint * > join_order_hints
Array of join order hints.
Definition: opt_hints.h:373
Definition: opt_hints.h:79
bool idx_merge_hint_state(const TABLE *table, bool *use_cheapest_index_merge)
Returns true if index merge hint state is on otherwise returns false.
Definition: opt_hints.cc:800
bool semijoin_enabled(THD *thd) const
Returns whether semi-join is enabled for this query block.
Definition: opt_hints.cc:232
PT_qb_level_hint * subquery_hint
Definition: opt_hints.h:370
uint resolved_children
Definition: opt_hints.h:179
void print_warn_unresolved(THD *thd)
Print warning for unresolved hint name.
Definition: opt_hints.cc:159
Definition: mysql_lex_string.h:39
void set_compound_key_hint_map(Opt_hints *hint, uint arg)
Definition: opt_hints.h:563
Definition: opt_hints.h:74
bool is_all_resolved() const
Definition: opt_hints.h:263
enum_exec_method
The method chosen to execute the predicate, currently used for IN, =ANY and EXISTS predicates...
Definition: item_subselect.h:345
bool is_clear_all() const
Definition: sql_bitmap.h:178
std::string join(Container cont, const std::string &delim)
join elements of an container into a string seperated by a delimiter.
Definition: string.h:144
void register_child(Opt_hints *hint_arg)
Definition: opt_hints.h:267
Opt_hints(const LEX_CSTRING *name_arg, Opt_hints *parent_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:182
Definition: opt_hints.h:67
Sys_var_hint * sys_var_hint
Definition: opt_hints.h:346
Definition: opt_hints.h:66
void set_bit(uint n)
Definition: sql_bitmap.h:146
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
virtual void set_unresolved(opt_hints_enum type_arg)
Set hint to unresolved state.
Definition: opt_hints.h:245
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:161
virtual void set_resolved()
Definition: opt_hints.h:229
Definition: table.h:1301
Query block level hints.
Definition: opt_hints.h:365
virtual const LEX_CSTRING * get_name() const
Definition: opt_hints.h:226
set_var_base descendant for assignments to the system variables.
Definition: set_var.h:386
SET_VAR hints.
Definition: opt_hints.h:627
uint sj_enabled_strategies(uint opt_switches) const
Returns bit mask of which semi-join strategies are enabled for this query block.
Definition: opt_hints.cc:249
Bitmap< 64 > hints
Definition: opt_hints.h:100
Definition: opt_hints.h:84
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
opt_hints_enum
Hint types, MAX_HINT_ENUM should be always last.
Definition: opt_hints.h:62
Definition: opt_hints.h:77
A class representing one system variable - that is something that can be accessed as @global...
Definition: set_var.h:102
Auxiluary class for compound key objects.
Definition: opt_hints.h:488
Parse tree hint object for key level hints.
Definition: parse_tree_hints.h:199
void set_key_map(uint i)
Definition: opt_hints.h:506
Definition: opt_hints.h:71
virtual void print_irregular_hints(const THD *thd, String *str)
Function prints hints which are non-standard and don&#39;t fit into existing hint infrastructure.
Definition: opt_hints.h:335
void print(const THD *thd, String *str)
Print applicable hints.
Definition: opt_hints.cc:689
void print_irregular_hints(const THD *thd, String *str) override
Function prints hints which are non-standard and don&#39;t fit into existing hint infrastructure.
Definition: opt_hints.cc:272
bool append(const String &s)
Definition: sql_string.cc:447
bool switch_hint
Definition: opt_hints.h:88
PT_hint * get_complex_hints(opt_hints_enum type) override
Returns pointer to complex hint for a given type.
Definition: opt_hints.cc:209
void restore_vars(THD *thd)
Restore system variables with original values.
Definition: opt_hints.cc:663
Compound_key_hint index_merge
Definition: opt_hints.h:518
void print(const THD *thd, String *str, enum_query_type query_type)
Print all hints except of QB_NAME hint.
Definition: opt_hints.cc:127
bool switch_on(opt_hints_enum type_arg) const
Get switch value.
Definition: opt_hints.h:133
void append_name(const THD *, String *) override
Definition: opt_hints.h:354
virtual PT_hint * get_complex_hints(opt_hints_enum type)
Returns pointer to complex hint for a given type.
Definition: opt_hints.h:279
void clear_bit(uint n)
Definition: sql_bitmap.h:150
Mem_root_array< Opt_hints * > child_array
Definition: opt_hints.h:175
void set_switch(opt_hints_enum type_arg, bool switch_state_arg)
Set switch value and set hint into specified state.
Definition: opt_hints.h:119
Opt_hints_map contains information about hint state(specified or not, hint value).
Definition: opt_hints.h:99
Compound_key_hint skip_scan
Definition: opt_hints.h:519
bool hint_key_state(const THD *thd, const TABLE_LIST *table, uint keyno, opt_hints_enum type_arg, uint optimizer_switch)
Returns key hint value if hint is specified, returns optimizer switch value if hint is not specified...
Definition: opt_hints.cc:741
Parse tree hint object for query block level hints.
Definition: parse_tree_hints.h:116
void set_resolved() override
Definition: opt_hints.h:545
Hint_set_var(set_var *var_arg)
Definition: opt_hints.h:618
Header for compiler-dependent features.
bool set_switch(bool switch_state_arg, opt_hints_enum type_arg, bool check_parent)
Function sets switch hint state.
Definition: opt_hints.h:206
bool is_specified(opt_hints_enum type_arg) const
Check if hint is specified.
Definition: opt_hints.h:110
Definition: item.h:668
bool is_key_map_clear_all()
Definition: opt_hints.h:508
unsigned int uint
Definition: uca-dump.cc:29
uint select_number
Definition: opt_hints.h:366
The class is a base class for representation of the different types of the hints. ...
Definition: parse_tree_hints.h:57
size_t size() const
Definition: mem_root_array.h:379
void append_qb_hint(const THD *thd, String *str)
Append query block hint.
Definition: opt_hints.h:398
Sys_var_hint(MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:632
Opt_hints class is used as ancestor for Opt_hints_global, Opt_hints_qb, Opt_hints_table, Opt_hints_key classes.
Definition: opt_hints.h:155
Definition: m_ctype.h:359
bool ignore_print(opt_hints_enum type_arg) const override
Ignore printing of the object since parent complex hint has its own printing method.
Definition: opt_hints.h:606
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:398
void append_name(const THD *thd, String *str) override
Append query block name.
Definition: opt_hints.h:411
bool add_var(THD *thd, sys_var *sys_var, Item *sys_var_value)
Add variable to hint list.
Definition: opt_hints.cc:618
Mem_root_array< Opt_hints * > * child_array_ptr()
Definition: opt_hints.h:261
void init()
Definition: sql_bitmap.h:143
Global level hints.
Definition: opt_hints.h:343
const LEX_CSTRING * get_print_name()
Definition: opt_hints.h:387
Item * save_value
Definition: opt_hints.h:620
void adjust_key_hints(TABLE_LIST *table)
Function sets correlation between key hint objects and appropriate KEY structures.
Definition: opt_hints.cc:531
bool is_set_key_map(uint i)
Definition: opt_hints.h:507
Opt_hints * parent
Definition: opt_hints.h:170
Definition: opt_hints.h:73
set_var * var
Definition: opt_hints.h:619
int type
Definition: http_common.h:411
Definition: opt_hints.h:78
Compound_key_hint()
Definition: opt_hints.h:494
Opt_hints_table(const LEX_CSTRING *table_name_arg, Opt_hints_qb *qb_hints_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:521
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:189
bool check_upper_lvl
Definition: opt_hints.h:86
void set_unresolved(opt_hints_enum type_arg) override
Set hint to unresolved state.
Definition: opt_hints.h:551
void incr_resolved_children()
Definition: opt_hints.h:260
Opt_hints * get_parent() const
Definition: opt_hints.h:228
bool hint_table_state(const THD *thd, const TABLE_LIST *table, opt_hints_enum type_arg, uint optimizer_switch)
Returns table hint value if hint is specified, returns optimizer switch value if hint is not specifie...
Definition: opt_hints.cc:758
virtual PT_hint * get_complex_hints(opt_hints_enum type) override
Returns pointer to complex hint for a given type.
Definition: opt_hints.cc:574
Container for set_var object and original variable value.
Definition: opt_hints.h:616
Table level hints.
Definition: opt_hints.h:515
#define NULL
Definition: types.h:55
virtual bool ignore_print(opt_hints_enum type_arg) const
If ignore_print() returns true, hint is not printed in Opt_hints::print() function.
Definition: opt_hints.h:256
LEX_CSTRING sys_name
Definition: opt_hints.h:367
PT_hint_max_execution_time * max_exec_time
Definition: opt_hints.h:345
const LEX_CSTRING * name
Definition: opt_hints.h:163
bool compound_hint_key_enabled(const TABLE *table, uint keyno, opt_hints_enum type_arg)
Returns true if compoubd hint state is on with or without specified keys, otherwise returns false...
Definition: opt_hints.cc:782
A better implementation of the UNIX ctype(3) library.
void register_join_order_hint(PT_qb_level_hint *hint_arg)
Definition: opt_hints.h:478
const char * hint_name
Definition: opt_hints.h:85
char buff[32]
Definition: opt_hints.h:368
void apply_join_order_hints(JOIN *join)
Checks if join order hints are applicable and applies table dependencies if possible.
Definition: opt_hints.cc:521
void print_irregular_hints(const THD *thd, String *str) override
Function prints hints which are non-standard and don&#39;t fit into existing hint infrastructure.
Definition: opt_hints.cc:192
bool is_resolved()
Definition: opt_hints.h:504
PT_key_level_hint * get_pt_hint()
Definition: opt_hints.h:501
void append_hint_type(String *str, opt_hints_enum type)
Append hint type.
Definition: opt_hints.cc:153
Opt_hints_table * adjust_table_hints(TABLE_LIST *table)
Function finds Opt_hints_table object corresponding to table alias in the query block and attaches co...
Definition: opt_hints.cc:218
ulonglong join_order_hints_ignored
Bit map of which hints are ignored.
Definition: opt_hints.h:375
Opt_hints * find_by_name(const LEX_CSTRING *name_arg, const CHARSET_INFO *cs) const
Find hint among lower-level hint objects.
Definition: opt_hints.cc:118
Opt_hints_global(MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:348
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
bool get_switch(opt_hints_enum type_arg) const
Function returns switch hint state.
Definition: opt_hints.cc:109
Definition: table.h:2468
Definition: opt_hints.h:65
Definition: opt_hints.h:64
Item_exists_subselect::enum_exec_method subquery_strategy() const
Returns which subquery execution strategy has been specified by hints for this query block...
Definition: opt_hints.cc:263
Definition: opt_hints.h:70
#define false
Definition: config_static.h:43
PT_hint * get_complex_hints(opt_hints_enum type) override
Returns pointer to complex hint for a given type.
Definition: opt_hints.cc:185
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:75
Definition: opt_hints.h:81
Definition: opt_hints.h:68
void append_table_name(const THD *thd, String *str, const LEX_CSTRING *qb_name, const LEX_CSTRING *table_name)
Append table and query block name.
Definition: opt_hints.cc:770
Mem_root_array< Hint_set_var * > var_list
Definition: opt_hints.h:629
#define STRING_WITH_LEN(X)
Definition: m_string.h:315
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
bool is_compound_key_hint(opt_hints_enum type_arg)
Definition: opt_hints.h:575
const char * table_name
Definition: rules_table_service.cc:55
virtual ~Opt_hints()
Definition: opt_hints.h:190