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