MySQL 9.1.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 THD *thd, const mem_root_deque<Table_ref *> &join_list,
478 bool toplevel = false);
481 const mem_root_deque<Table_ref *> *join_list);
484 const mem_root_deque<Table_ref *> *join_list);
485
486 bool has_join_order_hints() const;
488
489 /**
490 Checks if join order hints are applicable and
491 applies table dependencies if possible.
492
493 @param join JOIN object
494 */
496
497 private:
499 join_order_hints.push_back(hint_arg);
500 }
501};
502
504
505/**
506 Auxiliary class for compound key objects.
507*/
509 PT_key_level_hint *pt_hint; // Pointer to PT_key_level_hint object.
510 Key_map key_map; // Indexes, specified in the hint.
511 bool resolved; // true if hint does not have unresolved index.
512
513 public:
515 key_map.init();
516 resolved = false;
517 pt_hint = nullptr;
518 }
519
520 virtual ~Compound_key_hint() = default;
521
522 void set_pt_hint(PT_key_level_hint *pt_hint_arg) { pt_hint = pt_hint_arg; }
524
525 void set_resolved(bool arg) { resolved = arg; }
526 bool is_resolved() { return resolved; }
527
528 void set_key_map(uint i) { key_map.set_bit(i); }
529 bool is_set_key_map(uint i) { return key_map.is_set(i); }
532 virtual bool is_hint_conflicting(Opt_hints_table *table_hint [[maybe_unused]],
533 Opt_hints_key *key_hint [[maybe_unused]]) {
534 return false;
535 }
536};
537
538/**
539 Auxiliary class for JOIN_INDEX, GROUP_INDEX, ORDER_INDEX hints.
540*/
542 public:
543 bool is_hint_conflicting(Opt_hints_table *table_hint,
544 Opt_hints_key *key_hint) override;
545};
546
547/**
548 Auxiliary class for INDEX hint.
549*/
551 public:
552 bool is_hint_conflicting(Opt_hints_table *table_hint,
553 Opt_hints_key *key_hint) override;
554};
555
556bool is_compound_hint(opt_hints_enum type_arg);
557
558/**
559 Table level hints.
560*/
561
563 public:
571
572 Opt_hints_table(const LEX_CSTRING *table_name_arg, Opt_hints_qb *qb_hints_arg,
573 MEM_ROOT *mem_root_arg)
574 : Opt_hints(table_name_arg, qb_hints_arg, mem_root_arg),
575 keyinfo_array(mem_root_arg) {}
576
577 /**
578 Append table name.
579
580 @param thd pointer to THD object
581 @param str pointer to String object
582 */
583 void append_name(const THD *thd, String *str) override {
585 get_parent()->append_name(thd, str);
586 }
587 /**
588 Function sets correlation between key hint objects and
589 appropriate KEY structures.
590
591 @param table Pointer to Table_ref object
592 */
595
596 void set_resolved() override {
604 }
605
606 void set_unresolved(opt_hints_enum type_arg) override {
607 if (is_specified(type_arg) && is_compound_hint(type_arg))
608 get_compound_key_hint(type_arg)->set_resolved(false);
609 }
610
611 bool is_resolved(opt_hints_enum type_arg) override {
612 if (is_compound_hint(type_arg))
613 return Opt_hints::is_resolved(type_arg) &&
615 return Opt_hints::is_resolved(type_arg);
616 }
617
618 void set_compound_key_hint_map(Opt_hints *hint, uint arg) {
625 }
626
628 if (type_arg == INDEX_MERGE_HINT_ENUM) return &index_merge;
629 if (type_arg == SKIP_SCAN_HINT_ENUM) return &skip_scan;
630 if (type_arg == INDEX_HINT_ENUM) return &index;
631 if (type_arg == JOIN_INDEX_HINT_ENUM) return &join_index;
632 if (type_arg == GROUP_INDEX_HINT_ENUM) return &group_index;
633 if (type_arg == ORDER_INDEX_HINT_ENUM) return &order_index;
634 assert(0);
635 return nullptr;
636 }
637
639 return (get_compound_key_hint(type_arg)->is_resolved() &&
640 get_switch(type_arg));
641 }
642
644 void update_index_hint_map(Key_map *keys_to_use,
645 Key_map *available_keys_to_use,
646 opt_hints_enum type_arg);
647 bool update_index_hint_maps(THD *thd, TABLE *tbl);
648};
649
650/**
651 Key level hints.
652*/
653
654class Opt_hints_key : public Opt_hints {
655 public:
656 Opt_hints_key(const LEX_CSTRING *key_name_arg,
657 Opt_hints_table *table_hints_arg, MEM_ROOT *mem_root_arg)
658 : Opt_hints(key_name_arg, table_hints_arg, mem_root_arg) {}
659
660 /**
661 Append key name.
662
663 @param thd pointer to THD object
664 @param str pointer to String object
665 */
666 void append_name(const THD *thd, String *str) override {
667 get_parent()->append_name(thd, str);
668 str->append(' ');
670 }
671 /**
672 Ignore printing of the object since parent complex hint has
673 its own printing method.
674 */
675 bool ignore_print(opt_hints_enum type_arg) const override {
676 return is_compound_hint(type_arg);
677 }
678};
679
680/**
681 Container for set_var object and original variable value.
682*/
683
685 public:
686 Hint_set_var(set_var *var_arg) : var(var_arg), save_value(nullptr) {}
687 set_var *var; // Pointer to set_var object
688 Item *save_value; // Original variable value
689};
690
691/**
692 SET_VAR hints.
693*/
694
696 // List of str_var variables which need to be updated.
698
699 public:
700 Sys_var_hint(MEM_ROOT *mem_root_arg) : var_list(mem_root_arg) {}
701 /**
702 Add variable to hint list.
703
704 @param thd pointer to THD object
705 @param var_tracker pointer to System_variable_tracker object
706 @param sys_var_value variable value
707
708 @return true if variable is added,
709 false otherwise
710 */
711 bool add_var(THD *thd, const System_variable_tracker &var_tracker,
712 Item *sys_var_value);
713 /**
714 Find variable in hint list.
715
716 @param thd Pointer to thread object
717 */
718 void update_vars(THD *thd);
719 /**
720 Restore system variables with original values.
721
722 @param thd Pointer to thread object
723 */
724 void restore_vars(THD *thd);
725 /**
726 Print applicable hints.
727
728 @param thd Thread handle
729 @param str Pointer to string object
730 */
731 void print(const THD *thd, String *str);
732};
733
734/**
735 Returns key hint value if hint is specified, returns
736 optimizer switch value if hint is not specified.
737
738 @param thd Pointer to THD object
739 @param table Pointer to Table_ref object
740 @param keyno Key number
741 @param type_arg Hint type
742 @param optimizer_switch Optimizer switch flag
743
744 @return key hint value if hint is specified,
745 otherwise optimizer switch value.
746*/
747bool hint_key_state(const THD *thd, const Table_ref *table, uint keyno,
748 opt_hints_enum type_arg, uint optimizer_switch);
749
750/**
751 Returns table hint value if hint is specified, returns
752 optimizer switch value if hint is not specified.
753
754 @param thd Pointer to THD object
755 @param table Pointer to Table_ref object
756 @param type_arg Hint type
757 @param optimizer_switch Optimizer switch flag
758
759 @return table hint value if hint is specified,
760 otherwise optimizer switch value.
761*/
762bool hint_table_state(const THD *thd, const Table_ref *table,
763 opt_hints_enum type_arg, uint optimizer_switch);
764/**
765 Append table and query block name.
766
767 @param thd pointer to THD object
768 @param str pointer to String object
769 @param qb_name pointer to query block name, may be null
770 @param table_name pointer to table name
771*/
772void append_table_name(const THD *thd, String *str, const LEX_CSTRING *qb_name,
773 const LEX_CSTRING *table_name);
774
775/**
776 Returns true if compound hint state is on with or without
777 specified keys, otherwise returns false.
778 If compound hint state is on and hint is specified without indexes,
779 function returns 'true' for any 'keyno' argument. If hint specified
780 with indexes, function returns true only for appropriate 'keyno' index.
781
782
783 @param table Pointer to TABLE object
784 @param keyno Key number
785 @param type_arg Hint type
786
787 @return true if compound hint state is on with or without
788 specified keys, otherwise returns false.
789*/
790
791bool compound_hint_key_enabled(const TABLE *table, uint keyno,
792 opt_hints_enum type_arg);
793
794/**
795 Returns true if index merge hint state is on otherwise returns false.
796
797 @param thd Thread handler
798 @param table Pointer to TABLE object
799 @param use_cheapest_index_merge IN/OUT Returns true if INDEX_MERGE hint is
800 used without any specified key.
801
802 @return true if index merge hint state is on otherwise returns false.
803*/
804
805bool idx_merge_hint_state(THD *thd, const TABLE *table,
806 bool *use_cheapest_index_merge);
807
808int cmp_lex_string(const LEX_CSTRING &s, const LEX_CSTRING &t,
809 const CHARSET_INFO *cs);
810
811#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:508
void set_key_map(uint i)
Definition: opt_hints.h:528
PT_key_level_hint * pt_hint
Definition: opt_hints.h:509
void set_pt_hint(PT_key_level_hint *pt_hint_arg)
Definition: opt_hints.h:522
Key_map key_map
Definition: opt_hints.h:510
virtual ~Compound_key_hint()=default
void set_resolved(bool arg)
Definition: opt_hints.h:525
Compound_key_hint()
Definition: opt_hints.h:514
bool resolved
Definition: opt_hints.h:511
bool is_resolved()
Definition: opt_hints.h:526
bool is_set_key_map(uint i)
Definition: opt_hints.h:529
Key_map * get_key_map()
Definition: opt_hints.h:531
bool is_key_map_clear_all()
Definition: opt_hints.h:530
virtual bool is_hint_conflicting(Opt_hints_table *table_hint, Opt_hints_key *key_hint)
Definition: opt_hints.h:532
PT_key_level_hint * get_pt_hint()
Definition: opt_hints.h:523
Auxiliary class for INDEX hint.
Definition: opt_hints.h:550
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:1237
Container for set_var object and original variable value.
Definition: opt_hints.h:684
Item * save_value
Definition: opt_hints.h:688
Hint_set_var(set_var *var_arg)
Definition: opt_hints.h:686
set_var * var
Definition: opt_hints.h:687
Auxiliary class for JOIN_INDEX, GROUP_INDEX, ORDER_INDEX hints.
Definition: opt_hints.h:541
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:1254
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:654
void append_name(const THD *thd, String *str) override
Append key name.
Definition: opt_hints.h:666
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:675
Opt_hints_key(const LEX_CSTRING *key_name_arg, Opt_hints_table *table_hints_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:656
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:894
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:498
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:1061
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
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 mem_root_deque< Table_ref * > * sort_tables_in_join_order(THD *thd, const mem_root_deque< Table_ref * > &join_list, 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
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:921
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:562
Compound_key_hint skip_scan
Definition: opt_hints.h:566
Index_key_hint group_index
Definition: opt_hints.h:569
void set_resolved() override
Definition: opt_hints.h:596
Index_key_hint join_index
Definition: opt_hints.h:568
bool is_hint_conflicting(Opt_hints_key *key_hint, opt_hints_enum type)
Definition: opt_hints.cc:1127
void append_name(const THD *thd, String *str) override
Append table name.
Definition: opt_hints.h:583
Glob_index_key_hint index
Definition: opt_hints.h:567
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:1141
bool is_resolved(opt_hints_enum type_arg) override
Returns 'resolved' flag value for depending on hint type.
Definition: opt_hints.h:611
void set_unresolved(opt_hints_enum type_arg) override
Set hint to unresolved state.
Definition: opt_hints.h:606
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:1183
Compound_key_hint * get_compound_key_hint(opt_hints_enum type_arg)
Definition: opt_hints.h:627
void set_compound_key_hint_map(Opt_hints *hint, uint arg)
Definition: opt_hints.h:618
Mem_root_array< Opt_hints_key * > keyinfo_array
Definition: opt_hints.h:564
Opt_hints_table(const LEX_CSTRING *table_name_arg, Opt_hints_qb *qb_hints_arg, MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:572
void adjust_key_hints(Table_ref *table)
Function sets correlation between key hint objects and appropriate KEY structures.
Definition: opt_hints.cc:1071
PT_hint * get_complex_hints(opt_hints_enum type) override
Returns pointer to complex hint for a given type.
Definition: opt_hints.cc:1122
Compound_key_hint index_merge
Definition: opt_hints.h:565
bool is_force_index_hint(opt_hints_enum type_arg)
Definition: opt_hints.h:638
Index_key_hint order_index
Definition: opt_hints.h:570
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:695
Mem_root_array< Hint_set_var * > var_list
Definition: opt_hints.h:697
bool add_var(THD *thd, const System_variable_tracker &var_tracker, Item *sys_var_value)
Add variable to hint list.
Definition: opt_hints.cc:1298
void restore_vars(THD *thd)
Restore system variables with original values.
Definition: opt_hints.cc:1354
void print(const THD *thd, String *str)
Print applicable hints.
Definition: opt_hints.cc:1380
void update_vars(THD *thd)
Find variable in hint list.
Definition: opt_hints.cc:1331
Sys_var_hint(MEM_ROOT *mem_root_arg)
Definition: opt_hints.h:700
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:2900
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:426
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:1105
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(const detail::range auto &rng, std::string_view delim)
join elements of a range into a string separated by a delimiter.
Definition: string.h:74
const char * table_name
Definition: rules_table_service.cc:56
bool is_compound_hint(opt_hints_enum type_arg)
Definition: opt_hints.cc:1115
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:1450
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:1474
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:1492
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:1462
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:1433
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:147
Definition: table.h:1421
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