MySQL 9.0.0
Source Code Documentation
opt_hints.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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 "my_compiler.h"
37
38#include "my_inttypes.h"
40#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#include "string_with_len.h"
47
48enum class Subquery_strategy : int;
49class Item;
50class JOIN;
51class Opt_hints_table;
52class Sys_var_hint;
53class THD;
54class set_var;
55class sys_var;
56struct MEM_ROOT;
57struct TABLE;
58class Table_ref;
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:
355
357 : Opt_hints(nullptr, nullptr, mem_root_arg) {
358 max_exec_time = nullptr;
359 sys_var_hint = nullptr;
360 }
361
362 void append_name(const THD *, String *) override {}
364 void print_irregular_hints(const THD *thd, String *str) override;
365};
366
367class PT_qb_level_hint;
368
369/**
370 Query block level hints.
371*/
372
373class Opt_hints_qb : public Opt_hints {
374 uint select_number; // Query_block number
375 LEX_CSTRING sys_name; // System QB name
376 char buff[32]; // Buffer to hold sys name
377
379
380 /// Array of join order hints
382 /// Bit map of which hints are ignored.
384
385 /*
386 PT_qb_level_hint::do_contextualize sets subquery/semijoin_hint during
387 parsing. it also registers join order hints during parsing.
388 */
389 friend class PT_qb_level_hint;
390
391 public:
392 Opt_hints_qb(Opt_hints *opt_hints_arg, MEM_ROOT *mem_root_arg,
393 uint select_number_arg);
394
395 const LEX_CSTRING *get_print_name() override {
397 return str ? str : &sys_name;
398 }
399
400 /**
401 Append query block hint.
402
403 @param thd pointer to THD object
404 @param str pointer to String object
405 */
406 void append_qb_hint(const THD *thd, String *str) {
407 if (get_name()) {
408 str->append(STRING_WITH_LEN("QB_NAME("));
410 str->append(STRING_WITH_LEN(") "));
411 }
412 }
413 /**
414 Append query block name.
415
416 @param thd pointer to THD object
417 @param str pointer to String object
418 */
419 void append_name(const THD *thd, String *str) override {
420 str->append(STRING_WITH_LEN("@"));
423 }
424
426
427 /**
428 Function finds Opt_hints_table object corresponding to
429 table alias in the query block and attaches corresponding
430 key hint objects to appropriate KEY structures.
431
432 @param table Table reference
433
434 @return pointer Opt_hints_table object if this object is found,
435 NULL otherwise.
436 */
438
439 /**
440 Returns whether semi-join is enabled for this query block
441
442 A SEMIJOIN hint will force semi-join regardless of optimizer_switch
443 settings. A NO_SEMIJOIN hint will only turn off semi-join if the variant
444 with no strategies is used. A SUBQUERY hint will turn off semi-join. If
445 there is no SEMIJOIN/SUBQUERY hint, optimizer_switch setting determines
446 whether SEMIJOIN is used.
447
448 @param thd Pointer to THD object for session.
449 Used to access optimizer_switch
450
451 @return true if semijoin is enabled
452 */
453 bool semijoin_enabled(const THD *thd) const;
454
455 /**
456 Returns bit mask of which semi-join strategies are enabled for this query
457 block.
458
459 @param opt_switches Bit map of strategies enabled by optimizer_switch
460
461 @return Bit mask of strategies that are enabled
462 */
463 uint sj_enabled_strategies(uint opt_switches) const;
464
465 /**
466 Returns which subquery execution strategy has been specified by hints
467 for this query block.
468
469 @retval SUBQ_MATERIALIZATION Subquery Materialization should be used
470 @retval SUBQ_EXISTS In-to-exists execution should be used
471 @retval UNSPECIFIED No SUBQUERY hint for this query block
472 */
474
475 void print_irregular_hints(const THD *thd, String *str) override;
477 JOIN *join, const mem_root_deque<Table_ref *> *, bool toplevel = false);
480 const mem_root_deque<Table_ref *> *join_list);
483 const mem_root_deque<Table_ref *> *join_list);
484
485 bool has_join_order_hints() const;
487
488 /**
489 Checks if join order hints are applicable and
490 applies table dependencies if possible.
491
492 @param join JOIN object
493 */
495
496 private:
498 join_order_hints.push_back(hint_arg);
499 }
500};
501
503
504/**
505 Auxiliary class for compound key objects.
506*/
508 PT_key_level_hint *pt_hint; // Pointer to PT_key_level_hint object.
509 Key_map key_map; // Indexes, specified in the hint.
510 bool resolved; // true if hint does not have unresolved index.
511
512 public:
514 key_map.init();
515 resolved = false;
516 pt_hint = nullptr;
517 }
518
519 virtual ~Compound_key_hint() = default;
520
521 void set_pt_hint(PT_key_level_hint *pt_hint_arg) { pt_hint = pt_hint_arg; }
523
524 void set_resolved(bool arg) { resolved = arg; }
525 bool is_resolved() { return resolved; }
526
527 void set_key_map(uint i) { key_map.set_bit(i); }
528 bool is_set_key_map(uint i) { return key_map.is_set(i); }
531 virtual bool is_hint_conflicting(Opt_hints_table *table_hint [[maybe_unused]],
532 Opt_hints_key *key_hint [[maybe_unused]]) {
533 return false;
534 }
535};
536
537/**
538 Auxiliary class for JOIN_INDEX, GROUP_INDEX, ORDER_INDEX hints.
539*/
541 public:
542 bool is_hint_conflicting(Opt_hints_table *table_hint,
543 Opt_hints_key *key_hint) override;
544};
545
546/**
547 Auxiliary class for INDEX hint.
548*/
550 public:
551 bool is_hint_conflicting(Opt_hints_table *table_hint,
552 Opt_hints_key *key_hint) override;
553};
554
555bool is_compound_hint(opt_hints_enum type_arg);
556
557/**
558 Table level hints.
559*/
560
562 public:
570
571 Opt_hints_table(const LEX_CSTRING *table_name_arg, Opt_hints_qb *qb_hints_arg,
572 MEM_ROOT *mem_root_arg)
573 : Opt_hints(table_name_arg, qb_hints_arg, mem_root_arg),
574 keyinfo_array(mem_root_arg) {}
575
576 /**
577 Append table name.
578
579 @param thd pointer to THD object
580 @param str pointer to String object
581 */
582 void append_name(const THD *thd, String *str) override {
584 get_parent()->append_name(thd, str);
585 }
586 /**
587 Function sets correlation between key hint objects and
588 appropriate KEY structures.
589
590 @param table Pointer to Table_ref object
591 */
594
595 void set_resolved() override {
603 }
604
605 void set_unresolved(opt_hints_enum type_arg) override {
606 if (is_specified(type_arg) && is_compound_hint(type_arg))
607 get_compound_key_hint(type_arg)->set_resolved(false);
608 }
609
610 bool is_resolved(opt_hints_enum type_arg) override {
611 if (is_compound_hint(type_arg))
612 return Opt_hints::is_resolved(type_arg) &&
614 return Opt_hints::is_resolved(type_arg);
615 }
616
617 void set_compound_key_hint_map(Opt_hints *hint, uint arg) {
624 }
625
627 if (type_arg == INDEX_MERGE_HINT_ENUM) return &index_merge;
628 if (type_arg == SKIP_SCAN_HINT_ENUM) return &skip_scan;
629 if (type_arg == INDEX_HINT_ENUM) return &index;
630 if (type_arg == JOIN_INDEX_HINT_ENUM) return &join_index;
631 if (type_arg == GROUP_INDEX_HINT_ENUM) return &group_index;
632 if (type_arg == ORDER_INDEX_HINT_ENUM) return &order_index;
633 assert(0);
634 return nullptr;
635 }
636
638 return (get_compound_key_hint(type_arg)->is_resolved() &&
639 get_switch(type_arg));
640 }
641
643 void update_index_hint_map(Key_map *keys_to_use,
644 Key_map *available_keys_to_use,
645 opt_hints_enum type_arg);
646 bool update_index_hint_maps(THD *thd, TABLE *tbl);
647};
648
649/**
650 Key level hints.
651*/
652
653class Opt_hints_key : public Opt_hints {
654 public:
655 Opt_hints_key(const LEX_CSTRING *key_name_arg,
656 Opt_hints_table *table_hints_arg, MEM_ROOT *mem_root_arg)
657 : Opt_hints(key_name_arg, table_hints_arg, mem_root_arg) {}
658
659 /**
660 Append key name.
661
662 @param thd pointer to THD object
663 @param str pointer to String object
664 */
665 void append_name(const THD *thd, String *str) override {
666 get_parent()->append_name(thd, str);
667 str->append(' ');
669 }
670 /**
671 Ignore printing of the object since parent complex hint has
672 its own printing method.
673 */
674 bool ignore_print(opt_hints_enum type_arg) const override {
675 return is_compound_hint(type_arg);
676 }
677};
678
679/**
680 Container for set_var object and original variable value.
681*/
682
684 public:
685 Hint_set_var(set_var *var_arg) : var(var_arg), save_value(nullptr) {}
686 set_var *var; // Pointer to set_var object
687 Item *save_value; // Original variable value
688};
689
690/**
691 SET_VAR hints.
692*/
693
695 // List of str_var variables which need to be updated.
697
698 public:
699 Sys_var_hint(MEM_ROOT *mem_root_arg) : var_list(mem_root_arg) {}
700 /**
701 Add variable to hint list.
702
703 @param thd pointer to THD object
704 @param var_tracker pointer to System_variable_tracker object
705 @param sys_var_value variable value
706
707 @return true if variable is added,
708 false otherwise
709 */
710 bool add_var(THD *thd, const System_variable_tracker &var_tracker,
711 Item *sys_var_value);
712 /**
713 Find variable in hint list.
714
715 @param thd Pointer to thread object
716 */
717 void update_vars(THD *thd);
718 /**
719 Restore system variables with original values.
720
721 @param thd Pointer to thread object
722 */
723 void restore_vars(THD *thd);
724 /**
725 Print applicable hints.
726
727 @param thd Thread handle
728 @param str Pointer to string object
729 */
730 void print(const THD *thd, String *str);
731};
732
733/**
734 Returns key hint value if hint is specified, returns
735 optimizer switch value if hint is not specified.
736
737 @param thd Pointer to THD object
738 @param table Pointer to Table_ref object
739 @param keyno Key number
740 @param type_arg Hint type
741 @param optimizer_switch Optimizer switch flag
742
743 @return key hint value if hint is specified,
744 otherwise optimizer switch value.
745*/
746bool hint_key_state(const THD *thd, const Table_ref *table, uint keyno,
747 opt_hints_enum type_arg, uint optimizer_switch);
748
749/**
750 Returns table hint value if hint is specified, returns
751 optimizer switch value if hint is not specified.
752
753 @param thd Pointer to THD object
754 @param table Pointer to Table_ref object
755 @param type_arg Hint type
756 @param optimizer_switch Optimizer switch flag
757
758 @return table hint value if hint is specified,
759 otherwise optimizer switch value.
760*/
761bool hint_table_state(const THD *thd, const Table_ref *table,
762 opt_hints_enum type_arg, uint optimizer_switch);
763/**
764 Append table and query block name.
765
766 @param thd pointer to THD object
767 @param str pointer to String object
768 @param qb_name pointer to query block name, may be null
769 @param table_name pointer to table name
770*/
771void append_table_name(const THD *thd, String *str, const LEX_CSTRING *qb_name,
772 const LEX_CSTRING *table_name);
773
774/**
775 Returns true if compound hint state is on with or without
776 specified keys, otherwise returns false.
777 If compound hint state is on and hint is specified without indexes,
778 function returns 'true' for any 'keyno' argument. If hint specified
779 with indexes, function returns true only for appropriate 'keyno' index.
780
781
782 @param table Pointer to TABLE object
783 @param keyno Key number
784 @param type_arg Hint type
785
786 @return true if compound hint state is on with or without
787 specified keys, otherwise returns false.
788*/
789
790bool compound_hint_key_enabled(const TABLE *table, uint keyno,
791 opt_hints_enum type_arg);
792
793/**
794 Returns true if index merge hint state is on otherwise returns false.
795
796 @param thd Thread handler
797 @param table Pointer to TABLE object
798 @param use_cheapest_index_merge IN/OUT Returns true if INDEX_MERGE hint is
799 used without any specified key.
800
801 @return true if index merge hint state is on otherwise returns false.
802*/
803
804bool idx_merge_hint_state(THD *thd, const TABLE *table,
805 bool *use_cheapest_index_merge);
806
807int cmp_lex_string(const LEX_CSTRING &s, const LEX_CSTRING &t,
808 const CHARSET_INFO *cs);
809
810#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:1462
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: sql_bitmap.h:154
bool is_set(uint n) const
Definition: sql_bitmap.h:186
void set_bit(uint n)
Definition: sql_bitmap.h:165
bool is_clear_all() const
Definition: sql_bitmap.h:197
void init()
Definition: sql_bitmap.h:162
void clear_bit(uint n)
Definition: sql_bitmap.h:169
Auxiliary class for compound key objects.
Definition: opt_hints.h:507
void set_key_map(uint i)
Definition: opt_hints.h:527
PT_key_level_hint * pt_hint
Definition: opt_hints.h:508
void set_pt_hint(PT_key_level_hint *pt_hint_arg)
Definition: opt_hints.h:521
Key_map key_map
Definition: opt_hints.h:509
virtual ~Compound_key_hint()=default
void set_resolved(bool arg)
Definition: opt_hints.h:524
Compound_key_hint()
Definition: opt_hints.h:513
bool resolved
Definition: opt_hints.h:510
bool is_resolved()
Definition: opt_hints.h:525
bool is_set_key_map(uint i)
Definition: opt_hints.h:528
Key_map * get_key_map()
Definition: opt_hints.h:530
bool is_key_map_clear_all()
Definition: opt_hints.h:529
virtual bool is_hint_conflicting(Opt_hints_table *table_hint, Opt_hints_key *key_hint)
Definition: opt_hints.h:531
PT_key_level_hint * get_pt_hint()
Definition: opt_hints.h:522
Auxiliary class for INDEX hint.
Definition: opt_hints.h:549
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:1242
Container for set_var object and original variable value.
Definition: opt_hints.h:683
Item * save_value
Definition: opt_hints.h:687
Hint_set_var(set_var *var_arg)
Definition: opt_hints.h:685
set_var * var
Definition: opt_hints.h:686
Auxiliary class for JOIN_INDEX, GROUP_INDEX, ORDER_INDEX hints.
Definition: opt_hints.h:540
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:1259
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
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:362
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:356
Sys_var_hint * sys_var_hint
Definition: opt_hints.h:354
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_max_execution_time * max_exec_time
Definition: opt_hints.h:353
Key level hints.
Definition: opt_hints.h:653
void append_name(const THD *thd, String *str) override
Append key name.
Definition: opt_hints.h:665
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:674
Opt_hints_key(const LEX_CSTRING *key_name_arg, Opt_hints_table *table_hints_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:655
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:373
bool has_join_order_hints() const
Checks if any join order hints have been specified in query.
Definition: opt_hints.cc:524
bool check_join_order_hints(RelationalExpression *left, RelationalExpression *right, const mem_root_deque< Table_ref * > *join_list)
Checks if a combination of left and right RelationalExpressions satisfy one or more join order hints.
Definition: opt_hints.cc:899
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:497
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:378
uint select_number
Definition: opt_hints.h:374
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:383
void clear_join_order_hints()
Deletes all the join order hints.
Definition: opt_hints.cc:531
void apply_join_order_hints(JOIN *join)
Checks if join order hints are applicable and applies table dependencies if possible.
Definition: opt_hints.cc:1066
PT_qb_level_hint * subquery_hint
Definition: opt_hints.h:378
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:375
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:419
mem_root_deque< Table_ref * > * sort_tables_in_join_order(JOIN *join, const mem_root_deque< Table_ref * > *, bool toplevel=false)
Sorts tables from the join list to create a new join list which contains the tables in an order which...
Definition: opt_hints.cc:627
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:376
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:395
void append_qb_hint(const THD *thd, String *str)
Append query block hint.
Definition: opt_hints.h:406
bool hinted_join_order(PT_qb_level_hint *hint, RelationalExpression *left, RelationalExpression *right, const mem_root_deque< Table_ref * > *join_list)
Checks if a combination of left and right RelationalExpressions satisfy a hint.
Definition: opt_hints.cc:926
Mem_root_array< PT_qb_level_hint * > join_order_hints
Array of join order hints.
Definition: opt_hints.h:381
Table level hints.
Definition: opt_hints.h:561
Compound_key_hint skip_scan
Definition: opt_hints.h:565
Index_key_hint group_index
Definition: opt_hints.h:568
void set_resolved() override
Definition: opt_hints.h:595
Index_key_hint join_index
Definition: opt_hints.h:567
bool is_hint_conflicting(Opt_hints_key *key_hint, opt_hints_enum type)
Definition: opt_hints.cc:1132
void append_name(const THD *thd, String *str) override
Append table name.
Definition: opt_hints.h:582
Glob_index_key_hint index
Definition: opt_hints.h:566
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:1146
bool is_resolved(opt_hints_enum type_arg) override
Returns 'resolved' flag value for depending on hint type.
Definition: opt_hints.h:610
void set_unresolved(opt_hints_enum type_arg) override
Set hint to unresolved state.
Definition: opt_hints.h:605
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:1188
Compound_key_hint * get_compound_key_hint(opt_hints_enum type_arg)
Definition: opt_hints.h:626
void set_compound_key_hint_map(Opt_hints *hint, uint arg)
Definition: opt_hints.h:617
Mem_root_array< Opt_hints_key * > keyinfo_array
Definition: opt_hints.h:563
Opt_hints_table(const LEX_CSTRING *table_name_arg, Opt_hints_qb *qb_hints_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:571
void adjust_key_hints(Table_ref *table)
Function sets correlation between key hint objects and appropriate KEY structures.
Definition: opt_hints.cc:1076
PT_hint * get_complex_hints(opt_hints_enum type) override
Returns pointer to complex hint for a given type.
Definition: opt_hints.cc:1127
Compound_key_hint index_merge
Definition: opt_hints.h:564
bool is_force_index_hint(opt_hints_enum type_arg)
Definition: opt_hints.h:637
Index_key_hint order_index
Definition: opt_hints.h:569
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
Parse tree hint object for MAX_EXECUTION_TIME hint.
Definition: parse_tree_hints.h:270
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:210
Parse tree hint object for query block level hints.
Definition: parse_tree_hints.h:127
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
SET_VAR hints.
Definition: opt_hints.h:694
Mem_root_array< Hint_set_var * > var_list
Definition: opt_hints.h:696
bool add_var(THD *thd, const System_variable_tracker &var_tracker, Item *sys_var_value)
Add variable to hint list.
Definition: opt_hints.cc:1303
void restore_vars(THD *thd)
Restore system variables with original values.
Definition: opt_hints.cc:1359
void print(const THD *thd, String *str)
Print applicable hints.
Definition: opt_hints.cc:1385
void update_vars(THD *thd)
Find variable in hint list.
Definition: opt_hints.cc:1336
Sys_var_hint(MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:699
Wrapper interface for all kinds of system variables.
Definition: set_var.h:580
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2871
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
set_var_base descendant for assignments to the system variables.
Definition: set_var.h:983
A class representing one system variable - that is something that can be accessed as @global....
Definition: set_var.h:107
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:31
Subquery_strategy
Classes that represent predicates over table subqueries: [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL.
Definition: item_subselect.h:419
A better implementation of the UNIX ctype(3) library.
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:1081
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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:1120
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:1455
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:1479
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:1497
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:1467
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:1438
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.
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29
Definition: m_ctype.h:421
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
Represents an expression tree in the relational algebra of joins.
Definition: relational_expression.h:145
Definition: table.h:1407
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