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