MySQL 8.4.2
Source Code Documentation
sql_select.h
Go to the documentation of this file.
1#ifndef SQL_SELECT_INCLUDED
2#define SQL_SELECT_INCLUDED
3
4/* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27/**
28 @file sql/sql_select.h
29*/
30
31#include <assert.h>
32#include <sys/types.h>
33
34#include <climits>
35#include <string_view>
36
37#include "my_base.h"
38
39#include "my_inttypes.h"
40#include "my_sqlcommand.h"
41#include "my_table_map.h"
42#include "sql/field.h" // Copy_field
43#include "sql/handler.h"
44#include "sql/item_cmpfunc.h" // Item_cond_and
45#include "sql/opt_costmodel.h"
46#include "sql/sql_bitmap.h"
47#include "sql/sql_cmd_dml.h" // Sql_cmd_dml
48#include "sql/sql_const.h"
49#include "sql/sql_opt_exec_shared.h" // join_type
50
51class Func_ptr;
52class Item;
53class Item_func;
54class JOIN_TAB;
55class KEY;
56class QEP_TAB;
57class Query_result;
58class Query_block;
60class SJ_TMP_TABLE;
62class THD;
63template <class T>
64class List;
65struct LEX;
67struct ORDER;
68struct SJ_TMP_TABLE_TAB;
69struct TABLE;
70class Table_ref;
71class Window;
72
75
77 public:
78 explicit Sql_cmd_select(Query_result *result_arg) : Sql_cmd_dml() {
79 result = result_arg;
80 }
81
82 enum_sql_command sql_command_code() const override { return SQLCOM_SELECT; }
83
84 bool is_data_change_stmt() const override { return false; }
85
86 bool accept(THD *thd, Select_lex_visitor *visitor) override;
87
89 THD *thd) const override;
90
91 protected:
92 bool may_use_cursor() const override { return true; }
93 bool precheck(THD *thd) override;
94 bool check_privileges(THD *thd) override;
95 bool prepare_inner(THD *thd) override;
96};
97
98/**
99 Returns a constant of type 'type' with the 'A' lowest-weight bits set.
100 Example: LOWER_BITS(uint, 3) == 7.
101 Requirement: A < sizeof(type) * 8.
102*/
103#define LOWER_BITS(type, A) ((type)(((type)1 << (A)) - 1))
104
105/* Values in optimize */
106#define KEY_OPTIMIZE_EXISTS 1
107#define KEY_OPTIMIZE_REF_OR_NULL 2
108#define FT_KEYPART (MAX_REF_PARTS + 10)
109
110/**
111 A Key_use represents an equality predicate of the form (table.column = val),
112 where the column is indexed by @c keypart in @c key and @c val is either a
113 constant, a column from other table, or an expression over column(s) from
114 other table(s). If @c val is not a constant, then the Key_use specifies an
115 equi-join predicate, and @c table must be put in the join plan after all
116 tables in @c used_tables.
117
118 At an abstract level a Key_use instance can be viewed as a directed arc
119 of an equi-join graph, where the arc originates from the table(s)
120 containing the column(s) that produce the values used for index lookup
121 into @c table, and the arc points into @c table.
122
123 For instance, assuming there is only an index t3(c), the query
124
125 @code
126 SELECT * FROM t1, t2, t3
127 WHERE t1.a = t3.c AND
128 t2.b = t3.c;
129 @endcode
130
131 would generate two arcs (instances of Key_use)
132
133 @code
134 t1-- a ->- c --.
135 |
136 V
137 t3
138 ^
139 |
140 t2-- b ->- c --'
141 @endcode
142
143 If there were indexes t1(a), and t2(b), then the equi-join graph
144 would have two additional arcs "c->a" and "c->b" recording the fact
145 that it is possible to perform lookup in either direction.
146
147 @code
148 t1-- a ->- c --. ,-- c -<- b --- t2
149 ^ | | ^
150 | | | |
151 `-- a -<- c - v v-- c ->- b ----'
152 t3
153 @endcode
154
155 The query
156
157 @code
158 SELECT * FROM t1, t2, t3 WHERE t1.a + t2.b = t3.c;
159 @endcode
160
161 can be viewed as a graph with one "multi-source" arc:
162
163 @code
164 t1-- a ---
165 |
166 >-- c --> t3
167 |
168 t2-- b ---
169 @endcode
170
171 The graph of all equi-join conditions usable for index lookup is
172 stored as an ordered sequence of Key_use elements in
173 JOIN::keyuse_array. See sort_keyuse() for details on the
174 ordering. Each JOIN_TAB::keyuse points to the first array element
175 with the same table.
176*/
177class Key_use {
178 public:
179 // We need the default constructor for unit testing.
182 val(nullptr),
183 used_tables(0),
184 key(0),
185 keypart(0),
186 optimize(0),
187 keypart_map(0),
189 null_rejecting(false),
191 sj_pred_no(UINT_MAX),
193 fanout(0.0),
194 read_cost(0.0) {}
195
196 Key_use(Table_ref *table_ref_arg, Item *val_arg, table_map used_tables_arg,
197 uint key_arg, uint keypart_arg, uint optimize_arg,
198 key_part_map keypart_map_arg, ha_rows ref_table_rows_arg,
199 bool null_rejecting_arg, bool *cond_guard_arg, uint sj_pred_no_arg)
200 : table_ref(table_ref_arg),
201 val(val_arg),
202 used_tables(used_tables_arg),
203 key(key_arg),
204 keypart(keypart_arg),
205 optimize(optimize_arg),
206 keypart_map(keypart_map_arg),
207 ref_table_rows(ref_table_rows_arg),
208 null_rejecting(null_rejecting_arg),
209 cond_guard(cond_guard_arg),
210 sj_pred_no(sj_pred_no_arg),
212 fanout(0.0),
213 read_cost(0.0) {}
214
215 Table_ref *table_ref; ///< table owning the index
216 /**
217 Value used for lookup into @c key. It may be an Item_field, a
218 constant or any other expression. If @c val contains a field from
219 another table, then we have a join condition, and the table(s) of
220 the field(s) in @c val should be before @c table in the join plan.
221 */
223 /**
224 All tables used in @c val, that is all tables that provide bindings
225 for the expression @c val. These tables must be in the plan before
226 executing the equi-join described by a Key_use.
227 For all expressions except for the MATCH function, this is the same
228 as val->used_tables().
229 For the MATCH function, val is the actual MATCH function, and used_tables
230 is the set of tables used in the AGAINST argument.
231 */
233 uint key; ///< number of index
234 uint keypart; ///< used part of the index
235 uint optimize; ///< 0, or KEY_OPTIMIZE_*
236 key_part_map keypart_map; ///< like keypart, but as a bitmap
237 ha_rows ref_table_rows; ///< Estimate of how many rows for a key value
238 /**
239 If true, the comparison this value was created from will not be
240 satisfied if val has NULL 'value' (unless KEY_OPTIMIZE_REF_OR_NULL is set).
241 Not used if the index is fulltext (such index cannot be used for
242 equalities).
243 */
245 /**
246 !NULL - This Key_use was created from an equality that was wrapped into
247 an Item_func_trig_cond. This means the equality (and validity of
248 this Key_use element) can be turned on and off. The on/off state
249 is indicted by the pointed value:
250 *cond_guard == true @<=@> equality condition is on
251 *cond_guard == false @<=@> equality condition is off
252
253 NULL - Otherwise (the source equality can't be turned off)
254
255 Not used if the index is fulltext (such index cannot be used for
256 equalities).
257 */
259 /**
260 0..63 @<=@> This was created from semi-join IN-equality # sj_pred_no.
261 UINT_MAX Otherwise
262
263 Not used if the index is fulltext (such index cannot be used for
264 semijoin).
265
266 @see get_semi_join_select_list_index()
267 */
269
270 /*
271 The three members below are different from the rest of Key_use: they are
272 set only by Optimize_table_order, and they change with the currently
273 considered join prefix.
274 */
275
276 /**
277 The key columns which are equal to expressions depending only of earlier
278 tables of the current join prefix.
279 This information is stored only in the first Key_use of the index.
280 */
282
283 /**
284 Fanout of the ref access path for this index, in the current join
285 prefix.
286 This information is stored only in the first Key_use of the index.
287 */
288 double fanout;
289
290 /**
291 Cost of the ref access path for the current join prefix, i.e. the
292 cost of using ref access once multiplied by estimated number of
293 partial rows from tables earlier in the join sequence.
294 read_cost does NOT include cost of processing rows on the
295 server side (row_evaluate_cost).
296
297 Example: If the cost of ref access on this index is 5, and the
298 estimated number of partial rows from earlier tables is 10,
299 read_cost=50.
300
301 This information is stored only in the first Key_use of the index.
302 */
303 double read_cost;
304};
305
306/// @returns join type according to quick select type used
307/// (which must be a form of range scan, or asserts will happen)
309
310class JOIN;
311
312#define SJ_OPT_NONE 0
313#define SJ_OPT_DUPS_WEEDOUT 1
314#define SJ_OPT_LOOSE_SCAN 2
315#define SJ_OPT_FIRST_MATCH 3
316#define SJ_OPT_MATERIALIZE_LOOKUP 4
317#define SJ_OPT_MATERIALIZE_SCAN 5
318
319inline bool sj_is_materialize_strategy(uint strategy) {
320 return strategy >= SJ_OPT_MATERIALIZE_LOOKUP;
321}
322
323/**
324 Bits describing quick select type
325*/
327
328/**
329 A position of table within a join order. This structure is primarily used
330 as a part of @c join->positions and @c join->best_positions arrays.
331
332 One POSITION element contains information about:
333 - Which table is accessed
334 - Which access method was chosen
335 = Its cost and \#of output records
336 - Semi-join strategy choice. Note that there are two different
337 representation formats:
338 1. The one used during join optimization
339 2. The one used at plan refinement/code generation stage.
340 We call fix_semijoin_strategies_for_picked_join_order() to switch
341 between #1 and #2. See that function's comment for more details.
342
343 - Semi-join optimization state. When we're running join optimization,
344 we main a state for every semi-join strategy which are various
345 variables that tell us if/at which point we could consider applying the
346 strategy.
347 The variables are really a function of join prefix but they are too
348 expensive to re-caclulate for every join prefix we consider, so we
349 maintain current state in join->positions[\#tables_in_prefix]. See
350 advance_sj_state() for details.
351
352 This class has to stay a POD, because it is memcpy'd in many places.
353*/
354
355struct POSITION {
356 /**
357 The number of rows that will be fetched by the chosen access
358 method per each row combination of previous tables. That is:
359
360 rows_fetched = selectivity(access_condition) * cardinality(table)
361
362 where 'access_condition' is whatever condition was chosen for
363 index access, depending on the access method ('ref', 'range',
364 etc.)
365
366 @note For index/table scans, rows_fetched may be less than
367 the number of rows in the table because the cost of evaluating
368 constant conditions is included in the scan cost, and the number
369 of rows produced by these scans is the estimated number of rows
370 that pass the constant conditions. @see
371 Optimize_table_order::calculate_scan_cost() . But this is only during
372 planning; make_join_readinfo() simplifies it for EXPLAIN.
373 */
375
376 /**
377 Cost of accessing the table in course of the entire complete join
378 execution, i.e. cost of one access method use (e.g. 'range' or
379 'ref' scan ) multiplied by estimated number of rows from tables
380 earlier in the join sequence.
381
382 read_cost does NOT include cost of processing rows within the
383 executor (row_evaluate_cost).
384 */
385 double read_cost;
386
387 /**
388 The fraction of the 'rows_fetched' rows that will pass the table
389 conditions that were NOT used by the access method. If, e.g.,
390
391 "SELECT ... WHERE t1.colx = 4 and t1.coly @> 5"
392
393 is resolved by ref access on t1.colx, filter_effect will be the
394 fraction of rows that will pass the "t1.coly @> 5" predicate. The
395 valid range is 0..1, where 0.0 means that no rows will pass the
396 table conditions and 1.0 means that all rows will pass.
397
398 It is used to calculate how many row combinations will be joined
399 with the next table, @see prefix_rowcount below.
400
401 @note With condition filtering enabled, it is possible to get
402 a fanout = rows_fetched * filter_effect that is less than 1.0.
403 Consider, e.g., a join between t1 and t2:
404
405 "SELECT ... WHERE t1.col1=t2.colx and t2.coly OP @<something@>"
406
407 where t1 is a prefix table and the optimizer currently calculates
408 the cost of adding t2 to the join. Assume that the chosen access
409 method on t2 is a 'ref' access on 'colx' that is estimated to
410 produce 2 rows per row from t1 (i.e., rows_fetched = 2). It will
411 in this case be perfectly fine to calculate a filtering effect
412 @<0.5 (resulting in "rows_fetched * filter_effect @< 1.0") from the
413 predicate "t2.coly OP @<something@>". If so, the number of row
414 combinations from (t1,t2) is lower than the prefix_rowcount of t1.
415
416 The above is just an example of how the fanout of a table can
417 become less than one. It can happen for any access method.
418 */
420
421 /**
422 prefix_rowcount and prefix_cost form a stack of partial join
423 order costs and output sizes
424
425 prefix_rowcount: The number of row combinations that will be
426 joined to the next table in the join sequence.
427
428 For a joined table it is calculated as
429 prefix_rowcount =
430 last_table.prefix_rowcount * rows_fetched * filter_effect
431
432 @see filter_effect
433
434 For a semijoined table it may be less than this formula due to
435 duplicate elimination.
436 */
439
441
442 /**
443 NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used.
444 Other - [eq_]ref[_or_null] access is used. Pointer to {t.keypart1 = expr}
445 */
447
448 /** If ref-based access is used: bitmap of tables this table depends on */
451
452 /**
453 Current optimization state: Semi-join strategy to be used for this
454 and preceding join tables.
455
456 Join optimizer sets this for the *last* join_tab in the
457 duplicate-generating range. That is, in order to interpret this field,
458 one needs to traverse join->[best_]positions array from right to left.
459 When you see a join table with sj_strategy!= SJ_OPT_NONE, some other
460 field (depending on the strategy) tells how many preceding positions
461 this applies to. The values of covered_preceding_positions->sj_strategy
462 must be ignored.
463 */
465 /**
466 Valid only after fix_semijoin_strategies_for_picked_join_order() call:
467 if sj_strategy!=SJ_OPT_NONE, this is the number of subsequent tables that
468 are covered by the specified semi-join strategy
469 */
471
472 /**
473 Bitmap of semi-join inner tables that are in the join prefix and for
474 which there's no provision yet for how to eliminate semi-join duplicates
475 which they produce.
476 */
478
479 /* LooseScan strategy members */
480
481 /* The first (i.e. driving) table we're doing loose scan for */
483 /*
484 Tables that need to be in the prefix before we can calculate the cost
485 of using LooseScan strategy.
486 */
488
489 /*
490 keyno - Planning to do LooseScan on this key. If keyuse is NULL then
491 this is a full index scan, otherwise this is a ref+loosescan
492 scan (and keyno matches the KEUSE's)
493 MAX_KEY - Not doing a LooseScan
494 */
495 uint loosescan_key; // final (one for strategy instance )
496 uint loosescan_parts; /* Number of keyparts to be kept distinct */
497
498 /* FirstMatch strategy */
499 /*
500 Index of the first inner table that we intend to handle with this
501 strategy
502 */
504 /**
505 Value of Optimize_table_order::cur_embedding_map after this table has
506 been added to the plan. Used to constrain FirstMatch table orders.
507 */
509 /*
510 Tables that were not in the join prefix when we've started considering
511 FirstMatch strategy.
512 */
514 /*
515 Tables that need to be in the prefix before we can calculate the cost
516 of using FirstMatch strategy.
517 */
519
520 /* Duplicate Weedout strategy */
521 /* The first table that the strategy will need to handle */
523 /*
524 Tables that we will need to have in the prefix to do the weedout step
525 (all inner and all outer that the involved semi-joins are correlated with)
526 */
528
529 /* SJ-Materialization-Scan strategy */
530 /* The last inner table (valid once we're after it) */
532 /*
533 Tables that we need to have in the prefix to calculate the correct cost.
534 Basically, we need all inner tables and outer tables mentioned in the
535 semi-join's ON expression so we can correctly account for fanout.
536 */
538
539 /**
540 Even if the query has no semijoin, two sj-related members are read and
541 must thus have been set, by this function.
542 */
543 void no_semijoin() {
546 }
547 /**
548 Set complete estimated cost and produced rowcount for the prefix of tables
549 up to and including this table, in the join plan.
550
551 @param cost Estimated cost
552 @param rowcount Estimated row count
553 */
554 void set_prefix_cost(double cost, double rowcount) {
555 prefix_cost = cost;
556 prefix_rowcount = rowcount;
557 }
558 /**
559 Set complete estimated cost and produced rowcount for the prefix of tables
560 up to and including this table, calculated from the cost of the previous
561 stage, the fanout of the current stage and the cost to process a row at
562 the current stage.
563
564 @param idx Index of position object within array, if zero there is no
565 "previous" stage that can be added.
566 @param cm Cost model that provides the actual calculation
567 */
568 void set_prefix_join_cost(uint idx, const Cost_model_server *cm) {
569 if (idx == 0) {
572 } else {
574 prefix_cost = (this - 1)->prefix_cost + read_cost +
576 }
578 }
579
581
583
584 private:
585 /**
586 The lateral dependendencies of 'table' and all subsequent JOIN_TABs
587 in the join plan.
588 */
590};
591
592/**
593 Query optimization plan node.
594
595 Specifies:
596
597 - a table access operation on the table specified by this node, and
598
599 - a join between the result of the set of previous plan nodes and
600 this plan node.
601*/
603 public:
604 JOIN_TAB();
605
606 void set_table(TABLE *t);
607
608 /// Sets the pointer to the join condition of Table_ref
610
611 /// @returns join condition
612 Item *join_cond() const { return *m_join_cond_ref; }
613
614 /**
615 Sets join condition
616 @note this also changes Table_ref::m_join_cond.
617 */
618 void set_join_cond(Item *cond) { *m_join_cond_ref = cond; }
619
620 /// Set the combined condition for a table (may be performed several times)
621 void set_condition(Item *to) {
622 if (condition() != to) {
623 m_qs->set_condition(to);
624 // Condition changes, so some indexes may become usable or not:
626 }
627 }
628
629 uint use_join_cache() const { return m_use_join_cache; }
631 Key_use *keyuse() const { return m_keyuse; }
632 void set_keyuse(Key_use *k) { m_keyuse = k; }
633
634 Table_ref *table_ref; /**< points to table reference */
635
636 private:
637 Key_use *m_keyuse; /**< pointer to first used key */
638
639 /**
640 Pointer to the associated join condition:
641
642 - if this is a table with position==NULL (e.g. internal sort/group
643 temporary table), pointer is NULL
644
645 - otherwise, pointer is the address of some Table_ref::m_join_cond.
646 Thus, the pointee is the same as Table_ref::m_join_cond (changing
647 one changes the other; thus, optimizations made on the second are reflected
648 in Query_block::print_table_array() which uses the first one).
649 */
651
652 public:
653 COND_EQUAL *cond_equal; /**< multiple equalities for the on expression*/
654
655 /**
656 The maximum value for the cost of seek operations for key lookup
657 during ref access. The cost model for ref access assumes every key
658 lookup will cause reading a block from disk. With many key lookups
659 into the same table, most of the blocks will soon be in a memory
660 buffer. As a consequence, there will in most cases be an upper
661 limit on the number of actual disk accesses the ref access will
662 cause. This variable is used for storing a maximum cost estimate
663 for the disk accesses for ref access. It is used for limiting the
664 cost estimate for ref access to a more realistic value than
665 assuming every key lookup causes a random disk access. Without
666 having this upper limit for the cost of ref access, table scan
667 would be more likely to be chosen for cases where ref access
668 performs better.
669 */
671 /** Keys with constant part. Subset of keys. */
673 Key_map checked_keys; /**< Keys checked */
674 /**
675 Keys which can be used for skip scan access. We store it
676 separately from tab->const_keys & join_tab->keys() to avoid
677 unnecessary printing of the prossible keys in EXPLAIN output
678 as some of these keys can be marked not usable for skip scan later.
679 More strict check for prossible keys is performed in
680 get_best_skip_scan() function.
681 */
684
685 /**
686 Used to avoid repeated range analysis for the same key in
687 test_if_skip_sort_order(). This would otherwise happen if the best
688 range access plan found for a key is turned down.
689 quick_order_tested is cleared every time the select condition for
690 this JOIN_TAB changes since a new condition may give another plan
691 and cost from range analysis.
692 */
694
695 /*
696 Number of records that will be scanned (yes scanned, not returned) by the
697 best 'independent' access method, i.e. table scan or QUICK_*_SELECT)
698 */
700 /*
701 Cost of accessing the table using "ALL" or range/index_merge access
702 method (but not 'index' for some reason), i.e. this matches method which
703 E(#records) is in found_records.
704 */
705 double read_time;
706 /**
707 The set of tables that this table depends on. Used for outer join and
708 straight join dependencies.
709 */
711 /**
712 The set of tables that are referenced by key from this table.
713 */
715
716 public:
719
720 /**
721 Join buffering strategy.
722 After optimization it contains chosen join buffering strategy (if any).
723 */
725
726 /* SemiJoinDuplicateElimination variables: */
727 /*
728 Embedding SJ-nest (may be not the direct parent), or NULL if none.
729 It is the closest semijoin or antijoin nest.
730 This variable holds the result of table pullout.
731 */
733
734 /* NestedOuterJoins: Bitmap of nested joins this table is part of */
736
737 /** Flags from SE's MRR implementation, to be used by JOIN_CACHE */
739
740 /** true <=> AM will scan backward */
742
743 /** Clean up associated table after query execution, including resources */
744 void cleanup();
745
746 /// @returns semijoin strategy for this table.
747 uint get_sj_strategy() const;
748
749 private:
750 JOIN_TAB(const JOIN_TAB &); // not defined
751 JOIN_TAB &operator=(const JOIN_TAB &); // not defined
752};
753
756 table_ref(nullptr),
757 m_keyuse(nullptr),
758 m_join_cond_ref(nullptr),
759 cond_equal(nullptr),
760 worst_seeks(0.0),
761 const_keys(),
762 checked_keys(),
763 skip_scan_keys(),
764 needed_reg(),
765 quick_order_tested(),
766 found_records(0),
767 read_time(0),
768 dependent(0),
769 key_dependent(0),
770 used_fieldlength(0),
771 use_quick(QS_NONE),
772 m_use_join_cache(0),
773 emb_sj_nest(nullptr),
774 embedding_map(0),
775 join_cache_flags(0),
776 reversed_access(false) {}
777
778/* Extern functions in sql_select.cc */
779void count_field_types(const Query_block *query_block, Temp_table_param *param,
780 const mem_root_deque<Item *> &fields,
781 bool reset_with_sum_func, bool save_sum_fields);
782uint find_shortest_key(TABLE *table, const Key_map *usable_keys);
783
784/* functions from opt_sum.cc */
785bool is_simple_predicate(Item_func *func_item, Item **args, bool *inv_order);
786
788 AGGR_COMPLETE, // All aggregates were evaluated
789 AGGR_REGULAR, // Aggregates not fully evaluated, regular execution required
790 AGGR_DELAYED, // Aggregates not fully evaluated, execute with ha_records()
791 AGGR_EMPTY // Source tables empty, aggregates are NULL or 0 (for COUNT)
793
794bool optimize_aggregated_query(THD *thd, Query_block *select,
795 const mem_root_deque<Item *> &all_fields,
796 Item *conds, aggregate_evaluated *decision);
797
798/* from sql_delete.cc, used by opt_range.cc */
799extern "C" int refpos_order_cmp(const void *arg, const void *a, const void *b);
800
801/// The name of store_key instances that represent constant items.
802constexpr const char *STORE_KEY_CONST_NAME = "const";
803
804/// Check privileges for all columns referenced from join expression
806
807/// Check privileges for all columns referenced from an expression list
809 Access_bitmask privileges);
810
811/** class to copying an field/item to a key struct */
812
814 public:
815 bool null_key{false}; /* true <=> the value of the key has a null part */
817 store_key(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg,
818 uint length, Item *item_arg);
819 virtual ~store_key() = default;
820 virtual const char *name() const {
821 // Compatible with legacy behavior.
822 if (item->type() == Item::FIELD_ITEM) {
823 return item->full_name();
824 } else {
825 return "func";
826 }
827 }
828
829 /**
830 @brief sets ignore truncation warnings mode and calls the real copy method
831
832 @details this function makes sure truncation warnings when preparing the
833 key buffers don't end up as errors (because of an enclosing INSERT/UPDATE).
834 */
836
837 protected:
838 Field *to_field; // Store data here
840
841 virtual enum store_key_result copy_inner();
842};
843
844/*
845 Class used for unique constraint implementation by subselect_hash_sj_engine.
846 It uses store_key implementation to do actual copying, but after
847 that, copy_inner calculates hash of each key part for unique constraint.
848*/
849
850class store_key_hash_item final : public store_key {
852
853 public:
854 store_key_hash_item(THD *thd, Field *to_field_arg, uchar *ptr,
855 uchar *null_ptr_arg, uint length, Item *item_arg,
856 ulonglong *hash_arg)
857 : store_key(thd, to_field_arg, ptr, null_ptr_arg, length, item_arg),
858 hash(hash_arg) {}
859 const char *name() const override { return "func"; }
860
861 protected:
862 enum store_key_result copy_inner() override;
863};
864
865// Statement timeout function(s)
866bool set_statement_timer(THD *thd);
867void reset_statement_timer(THD *thd);
868
870
871void calc_used_field_length(TABLE *table, bool needs_rowid,
872 uint *p_used_fieldlength);
873
875bool check_field_is_const(Item *cond, const Item *order_item,
876 const Field *order_field = nullptr,
877 Item **const_item = nullptr);
878bool test_if_subpart(ORDER *a, ORDER *b);
879void calc_group_buffer(JOIN *join, ORDER *group);
880bool make_join_readinfo(JOIN *join, uint no_jbuf_after);
881bool create_ref_for_key(JOIN *join, JOIN_TAB *j, Key_use *org_keyuse,
882 table_map used_tables);
883bool types_allow_materialization(Item *outer, Item *inner);
884bool and_conditions(Item **e1, Item *e2);
885
886/**
887 Create a AND item of two existing items.
888 A new Item_cond_and item is created with the two supplied items as
889 arguments.
890
891 @note About handling of null pointers as arguments: if the first
892 argument is a null pointer, then the item given as second argument is
893 returned (no new Item_cond_and item is created). The second argument
894 must not be a null pointer.
895
896 @param cond the first argument to the new AND condition
897 @param item the second argument to the new AND condition
898
899 @return the new AND item
900*/
901static inline Item *and_items(Item *cond, Item *item) {
902 assert(item != nullptr);
903 return (cond ? (new Item_cond_and(cond, item)) : item);
904}
905
906/// A variant of the above, guaranteed to return Item_bool_func.
907static inline Item_bool_func *and_items(Item *cond, Item_bool_func *item) {
908 assert(item != nullptr);
909 return (cond ? (new Item_cond_and(cond, item)) : item);
910}
911
912uint actual_key_parts(const KEY *key_info);
913
914class ORDER_with_src;
915
917 AccessPath *range_scan, bool *need_sort,
918 bool *reverse);
920 uint *used_key_parts, bool *skip_quick);
922 TABLE *table, Key_map usable_keys, int key,
923 ha_rows select_limit, int *new_key,
924 int *new_key_direction, ha_rows *new_select_limit,
925 uint *new_used_key_parts = nullptr,
926 uint *saved_best_key_parts = nullptr,
927 double *new_read_time = nullptr);
928/**
929 Calculate properties of ref key: key length, number of used key parts,
930 dependency map, possibility of null. After calling this function
931 thd::is_error() needs to be checked, as it can set an error.
932
933 @param keyuse Array of keys to consider
934 @param tab join_tab to calculate ref parameters for
935 @param key number of the key to use
936 @param used_tables tables read prior to this table
937 @param [out] chosen_keyuses when given, this function will fill array with
938 chosen keyuses
939 @param [out] length_out calculated length of the ref
940 @param [out] keyparts_out calculated number of used keyparts
941 @param [out] dep_map when given, calculated dependency map
942 @param [out] maybe_null when given, calculated maybe_null property
943*/
944
945void calc_length_and_keyparts(Key_use *keyuse, JOIN_TAB *tab, const uint key,
946 table_map used_tables, Key_use **chosen_keyuses,
947 uint *length_out, uint *keyparts_out,
948 table_map *dep_map, bool *maybe_null);
949
950/**
951 Initialize the given TABLE_REF; setting basic fields and allocating memory
952 for arrays. Call init_ref_part() for each keypart (index field) that is to
953 take part in the ref lookup.
954 */
955bool init_ref(THD *thd, unsigned keyparts, unsigned length, unsigned keyno,
957
958/**
959 Initialize a given keypart in the table ref. In particular, sets up the
960 right function pointer to copy the value from “val” into the ref at
961 execution time (or copies the value right now, if it is constant).
962 */
963bool init_ref_part(THD *thd, unsigned part_no, Item *val, bool *cond_guard,
964 bool null_rejecting, table_map const_tables,
965 table_map used_tables, bool nullable,
966 const KEY_PART_INFO *key_part_info, uchar *key_buff,
968
969/**
970 Set up the support structures (NULL bits, row offsets, etc.) for a semijoin
971 duplicate weedout table. The object is allocated on the given THD's MEM_ROOT.
972
973 @param thd the THD to allocate the object on
974 @param join the JOIN that will own the temporary table (ie., has the
975 responsibility to destroy it after use)
976 @param first_tab first table in row key (inclusive)
977 @param last_tab last table in row key (exclusive)
978 */
980 SJ_TMP_TABLE_TAB *first_tab,
981 SJ_TMP_TABLE_TAB *last_tab);
982
983/**
984 Returns key flags depending on
985 OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag.
986
987 @param key_info pointer to KEY structure
988
989 @return key flags.
990 */
991uint actual_key_flags(const KEY *key_info);
992
993/**
994 Check if equality can be used to remove sub-clause of GROUP BY/ORDER BY
995
996 @param func comparison operator (= or <=>)
997 @param v variable comparison operand (validated to be equal to
998 ordering expression)
999 @param c other comparison operand (likely to be a constant)
1000
1001 @returns whether equality determines uniqueness
1002
1003 Checks if an equality predicate can be used to remove a GROUP BY/ORDER BY
1004 sub-clause when it is known to be true for exactly one distinct value
1005 (e.g. "expr" == "const").
1006 Arguments must be of the same type because e.g. "string_field" = "int_const"
1007 may match more than one distinct value from the column.
1008 */
1010 const Item *v, const Item *c);
1011
1012/**
1013 Check whether equality between two items is exact, ie., there are no implicit
1014 casts involved. This is especially important for GROUP BY/ORDER BY, as it
1015 means they can be treated interchangeably. The primary difference between this
1016 and equality_determines_uniqueness() is that item2 does not need to be
1017 a constant (which makes it stricter in other aspects).
1018 */
1020 const Item *item1, const Item *item2);
1021
1023 THD *thd, const Temp_table_param &tmp_table_param,
1024 const Query_block &query_block, const mem_root_deque<Item *> &source_fields,
1025 const mem_root_deque<Item *> &window_output_fields,
1026 Func_ptr_array *mapping_from_source_to_window_output, Window *window);
1027
1028/**
1029 Validates a query that uses the secondary engine
1030
1031 No validations are done if query has not been prepared against the secondary
1032 engine.
1033
1034 @param lex Parse tree descriptor.
1035
1036 @return True if error, false otherwise.
1037*/
1038bool validate_use_secondary_engine(const LEX *lex);
1039
1040/**
1041 Perform query optimizations that are specific to a secondary storage
1042 engine.
1043
1044 @param thd the current session
1045 @return true on error, false on success
1046*/
1048
1049/**
1050 Calculates the cost of executing a statement, including all its
1051 subqueries and stores it in thd->m_current_query_cost.
1052
1053 @param lex the statement
1054*/
1055void accumulate_statement_cost(const LEX *lex);
1056
1057/**
1058 Returns secondary_engine handler for the statement.
1059 If none exist, nullptr is returned.
1060
1061 @param lex the statement
1062*/
1064
1065/**
1066 Checks if any of the tables referenced belong to an external engine.
1067 If an external table is found, return true, false otherwise.
1068
1069 @param lex the statement
1070*/
1071bool has_external_table(const LEX *lex);
1072
1073/**
1074 Sets the reason of failure for the statement to the external engine.
1075
1076 @param lex the statement
1077 @param reason the reason of failure
1078*/
1079void set_external_engine_fail_reason(const LEX *lex, const char *reason);
1080
1081/**
1082 Notify plugins about an executed SELECT statement.
1083
1084 @param thd the current session
1085 @param cmd command to be notified about
1086*/
1087void notify_plugins_after_select(THD *thd, const Sql_cmd *cmd);
1088
1089std::string_view get_secondary_engine_fail_reason(const LEX *lex);
1090
1091void set_fail_reason_and_raise_error(const LEX *lex, std::string_view reason);
1092
1094
1095std::string_view find_secondary_engine_fail_reason(const LEX *lex);
1096
1097void find_and_set_offload_fail_reason(const LEX *lex);
1098
1099bool reads_not_secondary_columns(const LEX *lex);
1100
1101#endif /* SQL_SELECT_INCLUDED */
uint32_t Access_bitmask
Definition: auth_acls.h:34
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Definition: sql_bitmap.h:154
void clear_all()
Definition: sql_bitmap.h:180
Definition: item_cmpfunc.h:2727
API for getting cost estimates for server operations that are not directly related to a table object.
Definition: opt_costmodel.h:54
double row_evaluate_cost(double rows) const
Cost of processing a number of records and evaluating the query condition on the records.
Definition: opt_costmodel.h:98
Definition: field.h:575
Helper class for copy_funcs(); represents an Item to copy from table to next tmp table.
Definition: temp_table_param.h:48
Definition: item_cmpfunc.h:295
Definition: item_cmpfunc.h:2737
Item_func_comparison is a class for comparison functions that take two arguments and return a boolean...
Definition: item_cmpfunc.h:696
Definition: item_func.h:102
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:936
@ FIELD_ITEM
A reference to a field (column) in a table.
Definition: item.h:973
virtual const char * full_name() const
Definition: item.h:2333
virtual enum Type type() const =0
Query optimization plan node.
Definition: sql_select.h:602
Key_map needed_reg
Definition: sql_select.h:683
enum quick_type use_quick
Definition: sql_select.h:718
uint m_use_join_cache
Join buffering strategy.
Definition: sql_select.h:724
Table_ref * table_ref
points to table reference
Definition: sql_select.h:634
void set_condition(Item *to)
Set the combined condition for a table (may be performed several times)
Definition: sql_select.h:621
JOIN_TAB(const JOIN_TAB &)
void set_keyuse(Key_use *k)
Definition: sql_select.h:632
double read_time
Definition: sql_select.h:705
Table_ref * emb_sj_nest
Definition: sql_select.h:732
Key_map quick_order_tested
Used to avoid repeated range analysis for the same key in test_if_skip_sort_order().
Definition: sql_select.h:693
Key_map const_keys
Keys with constant part.
Definition: sql_select.h:672
table_map dependent
The set of tables that this table depends on.
Definition: sql_select.h:710
void set_use_join_cache(uint u)
Definition: sql_select.h:630
Key_use * keyuse() const
Definition: sql_select.h:631
Key_map skip_scan_keys
Keys which can be used for skip scan access.
Definition: sql_select.h:682
bool reversed_access
true <=> AM will scan backward
Definition: sql_select.h:741
Item * join_cond() const
Definition: sql_select.h:612
void set_join_cond(Item *cond)
Sets join condition.
Definition: sql_select.h:618
table_map key_dependent
The set of tables that are referenced by key from this table.
Definition: sql_select.h:714
double worst_seeks
The maximum value for the cost of seek operations for key lookup during ref access.
Definition: sql_select.h:670
uint join_cache_flags
Flags from SE's MRR implementation, to be used by JOIN_CACHE.
Definition: sql_select.h:738
COND_EQUAL * cond_equal
multiple equalities for the on expression
Definition: sql_select.h:653
ha_rows found_records
Definition: sql_select.h:699
JOIN_TAB()
Definition: sql_select.h:754
Key_map checked_keys
Keys checked.
Definition: sql_select.h:673
Item ** m_join_cond_ref
Pointer to the associated join condition:
Definition: sql_select.h:650
Key_use * m_keyuse
pointer to first used key
Definition: sql_select.h:637
nested_join_map embedding_map
Definition: sql_select.h:735
JOIN_TAB & operator=(const JOIN_TAB &)
uint use_join_cache() const
Definition: sql_select.h:629
uint used_fieldlength
Definition: sql_select.h:717
Definition: sql_optimizer.h:133
Definition: key.h:57
Definition: key.h:113
A Key_use represents an equality predicate of the form (table.column = val), where the column is inde...
Definition: sql_select.h:177
key_part_map bound_keyparts
The key columns which are equal to expressions depending only of earlier tables of the current join p...
Definition: sql_select.h:281
Item * val
Value used for lookup into key.
Definition: sql_select.h:222
double read_cost
Cost of the ref access path for the current join prefix, i.e.
Definition: sql_select.h:303
uint optimize
0, or KEY_OPTIMIZE_*
Definition: sql_select.h:235
Table_ref * table_ref
table owning the index
Definition: sql_select.h:215
key_part_map keypart_map
like keypart, but as a bitmap
Definition: sql_select.h:236
ha_rows ref_table_rows
Estimate of how many rows for a key value.
Definition: sql_select.h:237
uint sj_pred_no
0..63 <=> This was created from semi-join IN-equality # sj_pred_no.
Definition: sql_select.h:268
uint keypart
used part of the index
Definition: sql_select.h:234
Key_use(Table_ref *table_ref_arg, Item *val_arg, table_map used_tables_arg, uint key_arg, uint keypart_arg, uint optimize_arg, key_part_map keypart_map_arg, ha_rows ref_table_rows_arg, bool null_rejecting_arg, bool *cond_guard_arg, uint sj_pred_no_arg)
Definition: sql_select.h:196
uint key
number of index
Definition: sql_select.h:233
bool null_rejecting
If true, the comparison this value was created from will not be satisfied if val has NULL 'value' (un...
Definition: sql_select.h:244
Key_use()
Definition: sql_select.h:180
bool * cond_guard
!NULL - This Key_use was created from an equality that was wrapped into an Item_func_trig_cond.
Definition: sql_select.h:258
table_map used_tables
All tables used in val, that is all tables that provide bindings for the expression val.
Definition: sql_select.h:232
double fanout
Fanout of the ref access path for this index, in the current join prefix.
Definition: sql_select.h:288
Definition: sql_list.h:467
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Wrapper for ORDER* pointer to trace origins of ORDER list.
Definition: sql_optimizer.h:96
ORDER * order
ORDER expression that we are wrapping with this class.
Definition: sql_optimizer.h:98
Definition: sql_executor.h:254
Owner of a QEP_shared; parent of JOIN_TAB and QEP_TAB.
Definition: sql_opt_exec_shared.h:478
QEP_shared * m_qs
Definition: sql_opt_exec_shared.h:574
Item * condition() const
Definition: sql_opt_exec_shared.h:526
void set_condition(Item *c)
Definition: sql_opt_exec_shared.h:298
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1163
Definition: query_result.h:58
Definition: sql_executor.h:95
Abstract base class for traversing the Query_block tree.
Definition: select_lex_visitor.h:40
Definition: sql_cmd_dml.h:35
Definition: sql_select.h:76
Sql_cmd_select(Query_result *result_arg)
Definition: sql_select.h:78
enum_sql_command sql_command_code() const override
Return the command code for this statement.
Definition: sql_select.h:82
bool may_use_cursor() const override
Definition: sql_select.h:92
bool is_data_change_stmt() const override
Definition: sql_select.h:84
Representation of an SQL command.
Definition: sql_cmd.h:83
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
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:95
Represents the (explicit) window of a SQL 2003 section 7.11 <window clause>, or the implicit (inlined...
Definition: window.h:110
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
Definition: sql_select.h:850
const char * name() const override
Definition: sql_select.h:859
store_key_hash_item(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg, uint length, Item *item_arg, ulonglong *hash_arg)
Definition: sql_select.h:854
ulonglong * hash
Definition: sql_select.h:851
class to copying an field/item to a key struct
Definition: sql_select.h:813
Field * to_field
Definition: sql_select.h:838
virtual ~store_key()=default
bool null_key
Definition: sql_select.h:815
virtual const char * name() const
Definition: sql_select.h:820
Item * item
Definition: sql_select.h:839
store_key_result
Definition: sql_select.h:816
@ STORE_KEY_OK
Definition: sql_select.h:816
@ STORE_KEY_FATAL
Definition: sql_select.h:816
@ STORE_KEY_CONV
Definition: sql_select.h:816
const MYSQL_LEX_CSTRING * get_eligible_secondary_engine_from(const LEX *lex)
Definition: sql_select.cc:311
bool accept(THD *thd, Select_lex_visitor *visitor) override
Definition: sql_select.cc:601
enum store_key_result copy_inner() override
Definition: sql_select.cc:2683
bool make_join_readinfo(JOIN *join, uint no_jbuf_after)
Plan refinement stage: do various setup things for the executor.
Definition: sql_select.cc:3314
ORDER * simple_remove_const(ORDER *order, Item *where)
Filter out ORDER BY items that are equal to constants in WHERE condition.
Definition: sql_select.cc:3795
SJ_TMP_TABLE * create_sj_tmp_table(THD *thd, JOIN *join, SJ_TMP_TABLE_TAB *first_tab, SJ_TMP_TABLE_TAB *last_tab)
Set up the support structures (NULL bits, row offsets, etc.) for a semijoin duplicate weedout table.
Definition: sql_select.cc:1366
const handlerton * get_secondary_engine_handlerton(const LEX *lex)
Returns secondary_engine handler for the statement.
Definition: sql_select.cc:356
void reset_statement_timer(THD *thd)
Deactivate the timer associated with the statement that was executed.
Definition: sql_select.cc:239
void set_fail_reason_and_raise_error(const LEX *lex, std::string_view reason)
Definition: sql_select.cc:412
void accumulate_statement_cost(const LEX *lex)
Calculates the cost of executing a statement, including all its subqueries and stores it in thd->m_cu...
Definition: sql_select.cc:853
bool create_ref_for_key(JOIN *join, JOIN_TAB *j, Key_use *org_keyuse, table_map used_tables)
Setup a ref access for looking up rows via an index (a key).
Definition: sql_select.cc:2450
void count_field_types(const Query_block *query_block, Temp_table_param *param, const mem_root_deque< Item * > &fields, bool reset_with_sum_func, bool save_sum_fields)
Update TMP_TABLE_PARAM with count of the different type of fields.
Definition: sql_select.cc:3942
bool types_allow_materialization(Item *outer, Item *inner)
Check if two items are compatible wrt.
Definition: sql_select.cc:1269
void init_join_cond_ref(Table_ref *tl)
Sets the pointer to the join condition of Table_ref.
Definition: sql_select.cc:3532
bool reads_not_secondary_columns(const LEX *lex)
Checks if a query reads a column that is not available in the secondary engine (i....
Definition: sql_select.cc:255
bool test_if_subpart(ORDER *a, ORDER *b)
Return 1 if second is a subpart of first argument.
Definition: sql_select.cc:4007
void find_and_set_offload_fail_reason(const LEX *lex)
Definition: sql_select.cc:426
int test_if_order_by_key(ORDER_with_src *order, TABLE *table, uint idx, uint *used_key_parts, bool *skip_quick)
Test if one can use the key to resolve ordering.
Definition: sql_optimizer.cc:1829
void free_underlaid_joins(Query_block *select)
Free joins of subselect of this select.
Definition: sql_select.cc:4183
std::string_view find_secondary_engine_fail_reason(const LEX *lex)
Definition: sql_select.cc:381
bool test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER_with_src *order, TABLE *table, Key_map usable_keys, int key, ha_rows select_limit, int *new_key, int *new_key_direction, ha_rows *new_select_limit, uint *new_used_key_parts=nullptr, uint *saved_best_key_parts=nullptr, double *new_read_time=nullptr)
Find a cheaper access key than a given key.
Definition: sql_select.cc:5114
void calc_length_and_keyparts(Key_use *keyuse, JOIN_TAB *tab, const uint key, table_map used_tables, Key_use **chosen_keyuses, uint *length_out, uint *keyparts_out, table_map *dep_map, bool *maybe_null)
Calculate properties of ref key: key length, number of used key parts, dependency map,...
Definition: sql_select.cc:2302
bool CreateFramebufferTable(THD *thd, const Temp_table_param &tmp_table_param, const Query_block &query_block, const mem_root_deque< Item * > &source_fields, const mem_root_deque< Item * > &window_output_fields, Func_ptr_array *mapping_from_source_to_window_output, Window *window)
Definition: sql_select.cc:4292
store_key_result copy()
sets ignore truncation warnings mode and calls the real copy method
Definition: sql_select.cc:2665
uint actual_key_parts(const KEY *key_info)
Returns number of key parts depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag.
Definition: sql_select.cc:5449
uint find_shortest_key(TABLE *table, const Key_map *usable_keys)
Find shortest key suitable for full table scan.
Definition: sql_optimizer.cc:1996
bool check_privileges_for_list(THD *thd, const mem_root_deque< Item * > &items, Access_bitmask privileges)
Check privileges for all columns referenced from an expression list.
Definition: sql_select.cc:2161
bool set_statement_timer(THD *thd)
Set the time until the currently running statement is aborted.
Definition: sql_select.cc:208
join_type calc_join_type(AccessPath *path)
Definition: sql_select.cc:5463
const MYSQL_LEX_CSTRING * eligible_secondary_storage_engine(THD *thd) const override
Is this statement of a type and on a form that makes it eligible for execution in a secondary storage...
Definition: sql_select.cc:605
bool precheck(THD *thd) override
Perform an authorization precheck for an unprepared SELECT statement.
Definition: sql_select.cc:1145
virtual enum store_key_result copy_inner()
Definition: sql_select.cc:2750
bool equality_determines_uniqueness(const Item_func_comparison *func, const Item *v, const Item *c)
Check if equality can be used to remove sub-clause of GROUP BY/ORDER BY.
Definition: sql_select.cc:3811
bool init_ref(THD *thd, unsigned keyparts, unsigned length, unsigned keyno, Index_lookup *ref)
Initialize the given TABLE_REF; setting basic fields and allocating memory for arrays.
Definition: sql_select.cc:2348
store_key(THD *thd, Field *to_field_arg, uchar *ptr, uchar *null_ptr_arg, uint length, Item *item_arg)
Definition: sql_select.cc:2641
bool optimize_secondary_engine(THD *thd)
Perform query optimizations that are specific to a secondary storage engine.
Definition: sql_select.cc:953
uint get_index_for_order(ORDER_with_src *order, TABLE *table, ha_rows limit, AccessPath *range_scan, bool *need_sort, bool *reverse)
Find a key to apply single table UPDATE/DELETE by a given ORDER.
Definition: sql_select.cc:5360
bool check_field_is_const(Item *cond, const Item *order_item, const Field *order_field=nullptr, Item **const_item=nullptr)
Check if a field is equal to a constant value in a condition.
Definition: sql_select.cc:3882
void set_table(TABLE *t)
Definition: sql_select.cc:3527
void calc_group_buffer(JOIN *join, ORDER *group)
calc how big buffer we need for comparing group entries.
Definition: sql_select.cc:4027
uint actual_key_flags(const KEY *key_info)
Returns key flags depending on OPTIMIZER_SWITCH_USE_INDEX_EXTENSIONS flag.
Definition: sql_select.cc:5456
uint get_sj_strategy() const
Definition: sql_optimizer.cc:1414
bool check_privileges(THD *thd) override
Perform an authorization check for a prepared SELECT statement.
Definition: sql_select.cc:1186
bool check_privileges_for_join(THD *thd, mem_root_deque< Table_ref * > *tables)
Check privileges for all columns referenced from join expression.
Definition: sql_select.cc:2134
bool and_conditions(Item **e1, Item *e2)
Extend e1 by AND'ing e2 to the condition e1 points to.
Definition: sql_select.cc:2783
bool prepare_inner(THD *thd) override
Prepare a SELECT statement.
Definition: sql_select.cc:614
bool validate_use_secondary_engine(const LEX *lex)
Validates a query that uses the secondary engine.
Definition: sql_select.cc:450
void cleanup()
Clean up associated table after query execution, including resources.
Definition: sql_select.cc:3540
bool has_external_table(const LEX *lex)
Checks if any of the tables referenced belong to an external engine.
Definition: sql_select.cc:663
bool init_ref_part(THD *thd, unsigned part_no, Item *val, bool *cond_guard, bool null_rejecting, table_map const_tables, table_map used_tables, bool nullable, const KEY_PART_INFO *key_part_info, uchar *key_buff, Index_lookup *ref)
Initialize a given keypart in the table ref.
Definition: sql_select.cc:2368
bool equality_has_no_implicit_casts(const Item_func_comparison *func, const Item *item1, const Item *item2)
Check whether equality between two items is exact, ie., there are no implicit casts involved.
Definition: sql_select.cc:3829
void notify_plugins_after_select(THD *thd, const Sql_cmd *cmd)
Notify plugins about an executed SELECT statement.
Definition: sql_select.cc:990
std::string_view get_secondary_engine_fail_reason(const LEX *lex)
Definition: sql_select.cc:371
void calc_used_field_length(TABLE *table, bool needs_rowid, uint *p_used_fieldlength)
Find how much space the previous read not const tables takes in cache.
Definition: sql_select.cc:2201
This file includes constants used by all storage engines.
ulong key_part_map
Definition: my_base.h:1008
my_off_t ha_rows
Definition: my_base.h:1141
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
enum_sql_command
Definition: my_sqlcommand.h:46
@ SQLCOM_SELECT
Definition: my_sqlcommand.h:47
uint64_t table_map
Definition: my_table_map.h:30
static ulong select_limit
Definition: mysql.cc:217
static char * path
Definition: mysqldump.cc:149
static char * where
Definition: mysqldump.cc:152
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
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
RangeReverse< Range > reverse(Range &x)
Iterate over a range in reverse.
Definition: utilities.h:132
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:151
ulonglong nested_join_map
Definition: nested_join.h:37
required string key
Definition: replication_asynchronous_connection_failover.proto:60
File containing constants that can be used throughout the server.
Common types of the Optimizer, used by optimization and execution.
join_type
Definition: sql_opt_exec_shared.h:186
bool sj_is_materialize_strategy(uint strategy)
Definition: sql_select.h:319
void set_external_engine_fail_reason(const LEX *lex, const char *reason)
Sets the reason of failure for the statement to the external engine.
#define SJ_OPT_MATERIALIZE_LOOKUP
Definition: sql_select.h:316
aggregate_evaluated
Definition: sql_select.h:787
@ AGGR_COMPLETE
Definition: sql_select.h:788
@ AGGR_EMPTY
Definition: sql_select.h:791
@ AGGR_REGULAR
Definition: sql_select.h:789
@ AGGR_DELAYED
Definition: sql_select.h:790
#define SJ_OPT_NONE
Definition: sql_select.h:312
bool optimize_aggregated_query(THD *thd, Query_block *select, const mem_root_deque< Item * > &all_fields, Item *conds, aggregate_evaluated *decision)
Substitute constants for some COUNT(), MIN() and MAX() functions in an aggregated (implicitly grouped...
Definition: opt_sum.cc:277
constexpr const char * STORE_KEY_CONST_NAME
The name of store_key instances that represent constant items.
Definition: sql_select.h:802
quick_type
Bits describing quick select type.
Definition: sql_select.h:326
@ QS_DYNAMIC_RANGE
Definition: sql_select.h:326
@ QS_NONE
Definition: sql_select.h:326
@ QS_RANGE
Definition: sql_select.h:326
ulonglong nested_join_map
Definition: sql_select.h:71
Mem_root_array< Func_ptr > Func_ptr_array
Definition: sql_select.h:74
int refpos_order_cmp(const void *arg, const void *a, const void *b)
Definition: sql_delete.cc:914
bool is_simple_predicate(Item_func *func_item, Item **args, bool *inv_order)
Test if the predicate compares a field with constants.
Definition: opt_sum.cc:636
static Item * and_items(Item *cond, Item *item)
Create a AND item of two existing items.
Definition: sql_select.h:901
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:213
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:67
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3823
Definition: mysql_lex_string.h:40
Definition: table.h:286
A position of table within a join order.
Definition: sql_select.h:355
table_map m_suffix_lateral_deps
The lateral dependendencies of 'table' and all subsequent JOIN_TABs in the join plan.
Definition: sql_select.h:589
uint first_loosescan_table
Definition: sql_select.h:482
uint sjm_scan_last_inner
Definition: sql_select.h:531
float filter_effect
The fraction of the 'rows_fetched' rows that will pass the table conditions that were NOT used by the...
Definition: sql_select.h:419
table_map loosescan_need_tables
Definition: sql_select.h:487
double read_cost
Cost of accessing the table in course of the entire complete join execution, i.e.
Definition: sql_select.h:385
JOIN_TAB * table
Definition: sql_select.h:440
uint first_dupsweedout_table
Definition: sql_select.h:522
table_map sjm_scan_need_tables
Definition: sql_select.h:537
bool use_join_buffer
Definition: sql_select.h:450
nested_join_map cur_embedding_map
Value of Optimize_table_order::cur_embedding_map after this table has been added to the plan.
Definition: sql_select.h:508
void set_prefix_cost(double cost, double rowcount)
Set complete estimated cost and produced rowcount for the prefix of tables up to and including this t...
Definition: sql_select.h:554
table_map ref_depend_map
If ref-based access is used: bitmap of tables this table depends on
Definition: sql_select.h:449
table_map dupsweedout_tables
Definition: sql_select.h:527
uint sj_strategy
Current optimization state: Semi-join strategy to be used for this and preceding join tables.
Definition: sql_select.h:464
table_map get_suffix_lateral_deps() const
Definition: sql_select.h:582
table_map firstmatch_need_tables
Definition: sql_select.h:518
uint n_sj_tables
Valid only after fix_semijoin_strategies_for_picked_join_order() call: if sj_strategy!...
Definition: sql_select.h:470
void no_semijoin()
Even if the query has no semijoin, two sj-related members are read and must thus have been set,...
Definition: sql_select.h:543
void set_suffix_lateral_deps(table_map deps)
Definition: sql_select.h:580
table_map dups_producing_tables
Bitmap of semi-join inner tables that are in the join prefix and for which there's no provision yet f...
Definition: sql_select.h:477
Key_use * key
NULL - 'index' or 'range' or 'index_merge' or 'ALL' access is used.
Definition: sql_select.h:446
void set_prefix_join_cost(uint idx, const Cost_model_server *cm)
Set complete estimated cost and produced rowcount for the prefix of tables up to and including this t...
Definition: sql_select.h:568
uint loosescan_parts
Definition: sql_select.h:496
double prefix_cost
Definition: sql_select.h:438
table_map first_firstmatch_rtbl
Definition: sql_select.h:513
uint loosescan_key
Definition: sql_select.h:495
double rows_fetched
The number of rows that will be fetched by the chosen access method per each row combination of previ...
Definition: sql_select.h:374
uint first_firstmatch_table
Definition: sql_select.h:503
double prefix_rowcount
prefix_rowcount and prefix_cost form a stack of partial join order costs and output sizes
Definition: sql_select.h:437
Definition: sql_executor.h:71
Definition: table.h:1406
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2734
Definition: result.h:30