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