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