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