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