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