MySQL 8.0.29
Source Code Documentation
item_subselect.h
Go to the documentation of this file.
1#ifndef ITEM_SUBSELECT_INCLUDED
2#define ITEM_SUBSELECT_INCLUDED
3
4/* Copyright (c) 2002, 2021, 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/* subselect Item */
27
28#include <assert.h>
29#include <sys/types.h>
30
31#include <cstddef>
32#include <memory> // unique_ptr
33#include <vector>
34
35#include "field_types.h" // enum_field_types
36#include "my_alloc.h" // Destroy_only
37
38#include "my_inttypes.h"
39#include "my_table_map.h"
40#include "my_time.h"
42#include "mysql_time.h"
43#include "sql/comp_creator.h"
44#include "sql/enum_query_type.h"
45#include "sql/item.h" // Item_result_field
46#include "sql/iterators/row_iterator.h" // IWYU pragma: keep
47#include "sql/parse_location.h" // POS
49#include "sql/sql_const.h"
51#include "template_utils.h"
52
53class Comp_creator;
54class Field;
57class JOIN;
58class Json_wrapper;
59class PT_subquery;
63class Query_block;
65class String;
67class THD;
69class my_decimal;
71struct AccessPath;
72struct TABLE_LIST;
73
74template <class T>
75class List;
76
77/* base class for subselects */
78
81
82 private:
83 bool value_assigned; /* value already assigned to subselect */
84 /**
85 Whether or not execution of this subselect has been traced by
86 optimizer tracing already. If optimizer trace option
87 REPEATED_SUBSELECT is disabled, this is used to disable tracing
88 after the first one.
89 */
91
92 public:
93 /*
94 Used inside Item_subselect::fix_fields() according to this scenario:
95 > Item_subselect::fix_fields
96 > subquery->prepare
97 > query_block->prepare
98 (Here we realize we need to do the rewrite and set
99 substitution= some new Item, eg. Item_in_optimizer )
100 < query_block->prepare
101 < subquery->prepare
102 *ref= substitution;
103 < Item_subselect::fix_fields
104 */
106
107 /* unit of subquery */
109 /**
110 If !=NO_PLAN_IDX: this Item is in the condition attached to the JOIN_TAB
111 having this index in the parent JOIN.
112 */
114
115 // For EXPLAIN.
118
119 // For EXPLAIN. Only valid if engine_type() == HASH_SJ_ENGINE.
120 const TABLE *get_table() const;
121 const TABLE_REF &get_table_ref() const;
122 join_type get_join_type() const;
123
124 void create_iterators(THD *thd);
125 virtual AccessPath *root_access_path() const { return nullptr; }
126
127 protected:
128 /*
129 We need this method, because some compilers do not allow 'this'
130 pointer in constructor initialization list, but we need to pass a pointer
131 to subselect Item class to Query_result_interceptor's constructor.
132 */
134
135 // The inner part of the subquery.
137
138 // Only relevant for Item_in_subselect; optimized structure used for
139 // execution in place of running the entire subquery.
141
142 /* cache of used external tables */
144 /* allowed number of columns (1 for single value subqueries) */
146 /* where subquery is placed */
148 /* work with 'substitution' */
150
151 public:
152 /* subquery is transformed */
154
163 };
164
166 explicit Item_subselect(const POS &pos);
167
168 private:
169 /// Accumulate properties from underlying query expression
171 /// Accumulate properties from underlying query block
173 /// Accumulate properties from a selected expression within a query block.
174 void accumulate_expression(Item *item);
175 /// Accumulate properties from a condition or GROUP/ORDER within a query
176 /// block.
177 void accumulate_condition(Item *item);
178
179 public:
180 /// Accumulate used tables
182 used_tables_cache |= add_tables;
183 }
184
185 virtual subs_type substype() const { return UNKNOWN_SUBS; }
186
187 void cleanup() override;
188 virtual void reset() { null_value = true; }
189 virtual trans_res select_transformer(THD *thd, Query_block *select) = 0;
190 bool assigned() const { return value_assigned; }
191 void assigned(bool a) { value_assigned = a; }
192 enum Type type() const override;
193 bool is_null() override { return update_null_value() || null_value; }
194 bool fix_fields(THD *thd, Item **ref) override;
195 void fix_after_pullout(Query_block *parent_query_block,
196 Query_block *removed_query_block) override;
197 virtual bool exec(THD *thd);
198 bool resolve_type(THD *) override;
199 table_map used_tables() const override { return used_tables_cache; }
200 table_map not_null_tables() const override { return 0; }
201 Item *get_tmp_table_item(THD *thd) override;
202 void update_used_tables() override;
203 void print(const THD *thd, String *str,
204 enum_query_type query_type) const override;
205
208 }
209
210 /*
211 True if this subquery has been already evaluated. Implemented only for
212 single select and union subqueries only.
213 */
214 bool is_evaluated() const;
215 bool is_uncacheable() const;
216
217 /*
218 Used by max/min subquery to initialize value presence registration
219 mechanism. Engine call this method before rexecution query.
220 */
221 virtual void reset_value_registration() {}
223 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
224 bool explain_subquery_checker(uchar **arg) override;
225 bool inform_item_in_cond_of_tab(uchar *arg) override;
226 bool clean_up_after_removal(uchar *arg) override;
227
228 const char *func_name() const override {
229 assert(0);
230 return "subselect";
231 }
232
235 pointer_cast<Check_function_as_value_generator_parameters *>(args);
236 func_arg->err_code = func_arg->get_unnamed_function_error_code();
237 return true;
238 }
239
240 /// argument used by walk method collect_scalar_subqueries ("css")
242 ///< accumulated all subq (or aggregates) found
243 std::vector<Item_subselect *> list;
246 bool contains(Query_expression *candidate) {
247 for (auto sq : list) {
248 if (sq->unit == candidate) return true;
249 }
250 return false;
251 }
252 };
253
254 bool collect_subqueries(uchar *) override;
255 Item *replace_item_field(uchar *arg) override;
256 Item *replace_item_view_ref(uchar *arg) override;
258
260 friend class Item_in_optimizer;
261 friend bool Item_field::fix_fields(THD *, Item **);
263 friend bool Item_ref::fix_fields(THD *, Item **);
264 friend void Item_ident::fix_after_pullout(Query_block *parent_query_block,
265 Query_block *removed_query_block);
266
267 private:
268 bool subq_opt_away_processor(uchar *arg) override;
269
270 protected:
271 uint unit_cols() const;
272};
273
274/* single value subselect */
275
277 protected:
279 bool no_rows; ///< @c no_rows_in_result
280 public:
283 : Item_subselect(), value(nullptr), row(nullptr), no_rows(false) {}
284
285 void cleanup() override;
286 subs_type substype() const override { return SINGLEROW_SUBS; }
287
288 void reset() override;
289 trans_res select_transformer(THD *thd, Query_block *select) override;
290 void store(uint i, Item *item);
291 double val_real() override;
292 longlong val_int() override;
293 String *val_str(String *) override;
294 my_decimal *val_decimal(my_decimal *) override;
295 bool val_json(Json_wrapper *result) override;
296 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
297 bool get_time(MYSQL_TIME *ltime) override;
298 bool val_bool() override;
299 enum Item_result result_type() const override;
300 bool resolve_type(THD *) override;
301
302 /*
303 Mark the subquery as having no rows.
304 If there are aggregate functions (in the outer query),
305 we need to generate a NULL row. @c return_zero_rows().
306 */
307 void no_rows_in_result() override;
308
309 uint cols() const override { return unit_cols(); }
310
311 /**
312 @note that this returns the i-th element of the SELECT list.
313 To check for nullability, look at this->maybe_null and not
314 element_index[i]->maybe_null, since the selected expressions are
315 always NULL if the subquery is empty.
316 */
317 Item *element_index(uint i) override {
318 return reinterpret_cast<Item *>(row[i]);
319 }
320 Item **addr(uint i) override { return (Item **)row + i; }
321 bool check_cols(uint c) override;
322 bool null_inside() override;
323 void bring_value() override;
324
325 bool collect_scalar_subqueries(uchar *) override;
326 virtual bool is_maxmin() const { return false; }
327
328 /**
329 Argument for walk method replace_scalar_subquery
330 */
332 Item_singlerow_subselect *m_target; ///< subquery to be replaced with field
333 Field *m_field; ///< the replacement field
334 Query_block *m_outer_query_block; ///< The transformed query block.
335 Query_block *m_inner_query_block; ///< The immediately surrounding query
336 ///< block. This will be the transformed
337 ///< block or a subquery of it
338 bool m_add_coalesce{false};
340 Query_block *select, bool add_coalesce)
341 : m_target(target),
342 m_field(field),
343 m_outer_query_block(select),
344 m_inner_query_block(select),
345 m_add_coalesce(add_coalesce) {}
346 };
347
348 Item *replace_scalar_subquery(uchar *arge) override;
349 /**
350 This method is used to implement a special case of semantic tree
351 rewriting, mandated by a SQL:2003 exception in the specification.
352 The only caller of this method is handle_sql2003_note184_exception(),
353 see the code there for more details.
354 Note that this method breaks the object internal integrity, by
355 removing it's association with the corresponding Query_block,
356 making this object orphan from the parse tree.
357 No other method, beside the destructor, should be called on this
358 object, as it is now invalid.
359 @return the Query_block structure that was given in the constructor.
360 */
363};
364
365/* used in static ALL/ANY optimization */
367 protected:
368 bool max;
369 bool was_values; // Set if we have found at least one row
370 public:
372 bool max, bool ignore_nulls);
373 void print(const THD *thd, String *str,
374 enum_query_type query_type) const override;
375 void cleanup() override;
376 bool any_value() { return was_values; }
377 void register_value() { was_values = true; }
378 void reset_value_registration() override { was_values = false; }
379 bool is_maxmin() const override { return true; }
380};
381
382/* exists subselect */
383
384/**
385 Strategy which will be used to handle this subquery: flattening to a
386 semi-join, conversion to a derived table, rewrite of IN to EXISTS...
387 Sometimes the strategy is first only a candidate, then the real decision
388 happens in a second phase. Other times the first decision is final.
389 */
390enum class Subquery_strategy : int {
391 /// Nothing decided yet
393 /// Candidate for rewriting IN(subquery) to EXISTS, or subquery
394 /// materialization
396 /// Candidate for semi-join flattening
398 /// Candidate for rewriting to joined derived table
400 /// Semi-join flattening
401 SEMIJOIN,
402 /// Rewrite to joined derived table
404 /// Evaluate as EXISTS subquery (possibly after rewriting from another type)
406 /// Subquery materialization (HASH_SJ_ENGINE)
408 /// Subquery has been deleted, probably because it was always false
409 DELETED,
410};
411
414
415 protected:
416 /// value of this item (boolean: exists/not-exists)
417 bool value{false};
418
419 public:
420 /// Priority of this predicate in the convert-to-semi-join-nest process.
422 /// Execution strategy chosen for this Item
424 /// Used by the transformation to derived table
426
427 /**
428 Used by subquery optimizations to keep track about where this subquery
429 predicate is located, and whether it is a candidate for transformation.
430 (TABLE_LIST*) 1 - the predicate is an AND-part of the WHERE
431 join nest pointer - the predicate is an AND-part of ON expression
432 of a join nest
433 NULL - for all other locations. It also means that the
434 predicate is not a candidate for transformation.
435 See also THD::emb_on_expr_nest.
436
437 As for the second case above (the join nest pointer), note that this value
438 may change if scalar subqueries are transformed to derived tables,
439 cf. transform_scalar_subqueries_to_join_with_derived, due to the need to
440 build new join nests. The change is performed in Query_block::nest_derived.
441 */
443
445
447
448 explicit Item_exists_subselect(const POS &pos) : super(pos) {}
449
451
454 return RES_OK;
455 }
456 subs_type substype() const override { return EXISTS_SUBS; }
457 bool is_bool_func() const override { return true; }
458 void reset() override { value = false; }
459
460 enum Item_result result_type() const override { return INT_RESULT; }
461 /*
462 The item is
463 ([NOT] IN/EXISTS) [ IS [NOT] TRUE|FALSE ]
464 */
466 bool with_is_op() const {
467 switch (value_transform) {
468 case BOOL_IS_TRUE:
469 case BOOL_IS_FALSE:
470 case BOOL_NOT_TRUE:
471 case BOOL_NOT_FALSE:
472 return true;
473 default:
474 return false;
475 }
476 }
477 /// True if the IS TRUE/FALSE wasn't explicit in the query
478 bool implicit_is_op = false;
479 Item *truth_transformer(THD *, enum Bool_test test) override;
480 bool translate(bool &null_v, bool v);
481 void apply_is_true() override {
482 bool had_is = with_is_op();
484 if (!had_is && value_transform == BOOL_IS_TRUE)
485 implicit_is_op = true; // needn't be written by EXPLAIN
486 }
487 /// True if the Item has decided that it can do antijoin
488 bool can_do_aj = false;
490 longlong val_int() override;
491 double val_real() override;
492 String *val_str(String *) override;
493 my_decimal *val_decimal(my_decimal *) override;
494 bool val_bool() override;
495 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
496 return get_date_from_int(ltime, fuzzydate);
497 }
498 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
499 bool resolve_type(THD *thd) override;
500 void print(const THD *thd, String *str,
501 enum_query_type query_type) const override;
502
504};
505
506/**
507 Representation of IN subquery predicates of the form
508 "left_expr IN (SELECT ...)".
509
510 @details
511 This class has:
512 - A "subquery execution engine" (as a subclass of Item_subselect) that allows
513 it to evaluate subqueries. (and this class participates in execution by
514 having was_null variable where part of execution result is stored.
515 - Transformation methods (todo: more on this).
516
517 This class is not used directly, it is "wrapped" into Item_in_optimizer
518 which provides some small bits of subquery evaluation.
519*/
520
523
524 public:
526
527 protected:
528 /**
529 Cache of the left operand of the subquery predicate. Allocated in the
530 runtime memory root, for each execution, thus need not be freed.
531 */
533 bool left_expr_cache_filled; ///< Whether left_expr_cache holds a value
534 /** The need for expr cache may be optimized away, @sa init_left_expr_cache.
535 */
537
538 private:
539 /**
540 In the case of
541
542 x COMP_OP (SELECT1 UNION SELECT2 ...)
543
544 - the subquery transformation is done on SELECT1; this requires wrapping
545 'x' with more Item layers, and injecting that in a condition in SELECT1.
546
547 - the same transformation is done on SELECT2; but the wrapped 'x' doesn't
548 need to be created again, the one created for SELECT1 could be reused
549
550 - to achieve this, the wrapped 'x' is stored in member
551 'm_injected_left_expr' when it is created for SELECT1, and is later
552 reused for SELECT2.
553
554 This will refer to a cached value which is reevaluated once for each
555 candidate row, cf. setup in #single_value_transformer.
556 */
558
559 /**
560 Pointer to the created Item_in_optimizer; it is stored for the same
561 reasons as 'm_injected_left_expr'.
562 */
565
566 protected:
567 /**
568 True if naked IN is allowed to exchange FALSE for UNKNOWN.
569 Because this is about the naked IN, there is no public ignore_unknown(),
570 intentionally, so that callers don't get it wrong.
571 */
573
574 private:
575 /**
576 This bundles several pieces of information useful when doing the
577 IN->EXISTS transform. If this transform has not been done, pointer is
578 NULL.
579 */
581 /**
582 True: if IN->EXISTS has been done and has added a condition to the
583 subquery's WHERE clause.
584 */
586 /**
587 True: if subquery was dependent (correlated) before IN->EXISTS
588 was done.
589 */
591 /**
592 True: if subquery was dependent (correlated) after IN->EXISTS
593 was done.
594 */
597
598 bool mark_as_outer(Item *left_row, size_t col);
599
600 public:
601 /* Used to trigger on/off conditions that were pushed down to subselect */
603
604 Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
605
606 private:
608
609 public:
612 }
613
614 /// Is reliable only if IN->EXISTS has been done.
617 }
618
619 bool *get_cond_guard(int i) {
620 return pushed_cond_guards ? pushed_cond_guards + i : nullptr;
621 }
622 void set_cond_guard_var(int i, bool v) {
624 }
625
628 PT_subquery *pt_subquery_arg);
629
635 need_expr_cache(true),
638 was_null(false),
639 abort_on_null(false),
643
644 bool itemize(Parse_context *pc, Item **res) override;
645
646 void cleanup() override;
647 subs_type substype() const override { return IN_SUBS; }
648
649 void reset() override {
650 value = false;
651 null_value = false;
652 was_null = false;
653 }
654 trans_res select_transformer(THD *thd, Query_block *select) override;
656 Comp_creator *func);
658 Comp_creator *func);
661 Comp_creator *func);
663 bool subquery_allows_materialization(THD *thd, Query_block *query_block,
664 const Query_block *outer);
665 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
666 Item *transform(Item_transformer transformer, uchar *arg) override;
667 bool exec(THD *thd) override;
668 longlong val_int() override;
669 double val_real() override;
670 String *val_str(String *) override;
671 my_decimal *val_decimal(my_decimal *) override;
672 bool val_bool() override;
673 bool test_limit();
674 void print(const THD *thd, String *str,
675 enum_query_type query_type) const override;
676 bool fix_fields(THD *thd, Item **ref) override;
677 void fix_after_pullout(Query_block *parent_query_block,
678 Query_block *removed_query_block) override;
679 bool init_left_expr_cache(THD *thd);
680
681 /**
682 Once the decision to use IN->EXISTS has been taken, performs some last
683 steps of this transformation.
684 */
685 bool finalize_exists_transform(THD *thd, Query_block *select);
686 /**
687 Once the decision to use materialization has been taken, performs some
688 last steps of this transformation.
689 */
691
692 AccessPath *root_access_path() const override;
693
696 friend class Item_in_optimizer;
699
700 private:
701 bool val_bool_naked();
702};
703
704/// ALL/ANY/SOME subselect.
706 public:
709 bool all;
710
712 Query_block *select, bool all);
713
714 // only ALL subquery has upper not
715 subs_type substype() const override { return all ? ALL_SUBS : ANY_SUBS; }
716 trans_res select_transformer(THD *thd, Query_block *select) override;
717 void print(const THD *thd, String *str,
718 enum_query_type query_type) const override;
719};
720
722 public:
724 Item_subselect *si);
725 /**
726 Cleanup subquery after complete query execution, free all resources.
727 */
728 void cleanup(THD *thd);
729 bool prepare(THD *thd);
730 void fix_length_and_dec(Item_cache **row);
731 /**
732 Execute the subquery
733
734 SYNOPSIS
735 exec()
736
737 DESCRIPTION
738 Execute the subquery. The result of execution is subquery value that is
739 captured by previously set up Query_result-based 'sink'.
740
741 RETURN
742 false - OK
743 true - Execution error.
744 */
745 bool exec(THD *thd);
746 void print(const THD *thd, String *str, enum_query_type query_type);
749 Query_block *single_query_block() const; // Only if unit is simple.
750
751 enum Item_result type() const { return res_type; }
753 bool may_be_null() const { return maybe_null; }
754
755#ifndef NDEBUG
756 /**
757 @returns the internal Item. Defined only in debug builds, because should
758 be used only for debug asserts.
759 */
760 const Item_subselect *get_item() const { return item; }
761#endif
762
763 private:
764 Query_result_interceptor *result; /* results storage class */
765 Item_subselect *item; /* item, that use this subquery */
766 enum Item_result res_type; /* type of results */
767 enum_field_types res_field_type; /* column type of the results */
768 /**
769 True if at least one of the columns returned by the subquery may
770 be null, or if a single-row subquery may return zero rows.
771 */
773
774 Query_expression *unit; /* corresponding unit structure */
775
776 void set_row(const mem_root_deque<Item *> &item_list, Item_cache **row,
777 bool never_empty);
778
780};
781
782/**
783 A subquery execution engine that evaluates the subquery by doing index
784 lookups in a single table's index.
785
786 This engine is used to resolve subqueries in forms
787
788 outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)
789
790 or, row-based:
791
792 (oe1, .. oeN) IN (SELECT key_part1, ... key_partK
793 FROM tbl WHERE subqwhere)
794
795 i.e. the subquery is a single table SELECT without GROUP BY, aggregate
796 functions, etc.
797*/
799 protected:
800 Query_result_union *result = nullptr; /* results storage class */
801 /// Table which is read, using one of eq_ref, ref, ref_or_null.
802 TABLE *table{nullptr};
806 Item *cond; /* The WHERE condition of subselect */
807 ulonglong hash; /* Hash value calculated by RefIterator, when needed. */
808 /*
809 The "having" clause. This clause (further referred to as "artificial
810 having") was inserted by subquery transformation code. It contains
811 Item(s) that have a side-effect: they record whether the subquery has
812 produced a row with NULL certain components. We need to use it for cases
813 like
814 (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
815 where we do index lookup on t.key=oe1 but need also to check if there
816 was a row such that t.no_key IS NULL.
817 */
819
820 Item_in_subselect *item; /* item that uses this engine */
821
822 public:
824
826 const TABLE_REF &ref, enum join_type join_type,
828 Item *having_arg)
829 : table(table),
831 ref(ref),
833 cond(where),
834 having(having_arg),
835 item(subs) {}
837 virtual bool exec(THD *thd);
838 virtual void print(const THD *thd, String *str, enum_query_type query_type);
840 virtual void cleanup(THD *) {}
841 virtual void create_iterators(THD *) {}
842};
843
844/*
845 This function is actually defined in sql_parse.cc, but it depends on
846 chooser_compare_func_creator defined in this file.
847 */
850 Query_block *select);
851
852/**
853 Compute an IN predicate via a hash semi-join. The subquery is materialized
854 during the first evaluation of the IN predicate. The IN predicate is executed
855 via the functionality inherited from subselect_indexsubquery_engine.
856*/
857
859 private:
860 /* true if the subquery was materialized into a temp table. */
862 // true if we know for sure that there are zero rows in the table.
863 // Set only after is_materialized is true.
864 bool has_zero_rows = false;
865 /**
866 Existence of inner NULLs in materialized table:
867 By design, other values than IRRELEVANT_OR_FALSE are possible only if the
868 subquery has only one inner expression.
869 */
871 /// none, or they don't matter
873 /// they matter, and we don't know yet if they exists
875 /// they matter, and we know there exists at least one.
876 NEX_TRUE = 2
877 };
882
883 /// Saved result object, must be restored after use
885
886 public:
888 Query_expression *unit_arg)
890 in_predicate, nullptr, nullptr),
891 is_materialized(false),
892 unit(unit_arg) {}
893 ~subselect_hash_sj_engine() override;
894
895 bool setup(THD *thd, const mem_root_deque<Item *> &tmp_columns);
896 void cleanup(THD *thd) override;
897 bool exec(THD *thd) override;
898 void print(const THD *thd, String *str, enum_query_type query_type) override;
899 enum_engine_type engine_type() const override { return HASH_SJ_ENGINE; }
900
901 TABLE *get_table() const { return table; }
902 const TABLE_REF &get_table_ref() const { return ref; }
903 enum join_type get_join_type() const { return type; }
905 void create_iterators(THD *thd) override;
906};
907
908/**
909 Removes every predicate injected by IN->EXISTS.
910
911 This function is different from others:
912 - it wants to remove all traces of IN->EXISTS (for
913 materialization)
914 - remove_subq_pushed_predicates() and remove_additional_cond() want to
915 remove only the conditions of IN->EXISTS which index lookup already
916 satisfies (they are just an optimization).
917
918 If there are no in2exists conditions, it will return the exact same
919 pointer. If it returns a new Item, the old Item is left alone, so it
920 can be reused in other settings.
921
922 @param thd Thread handle.
923 @param conds Condition; may be nullptr.
924 @returns new condition
925 */
926Item *remove_in2exists_conds(THD *thd, Item *conds);
927
928/// Returns whether the Item is an IN-subselect.
929bool IsItemInSubSelect(Item *item);
930
931#endif /* ITEM_SUBSELECT_INCLUDED */
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:520
Definition: field.h:573
ALL/ANY/SOME subselect.
Definition: item_subselect.h:705
Item_allany_subselect(Item *left_expr, chooser_compare_func_creator fc, Query_block *select, bool all)
Definition: item_subselect.cc:1496
Comp_creator * func
Definition: item_subselect.h:708
trans_res select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:2697
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2707
chooser_compare_func_creator func_creator
Definition: item_subselect.h:707
bool all
Definition: item_subselect.h:709
subs_type substype() const override
Definition: item_subselect.h:715
Definition: item.h:6492
Definition: item_subselect.h:412
enum_condition_context outer_condition_context
Used by the transformation to derived table.
Definition: item_subselect.h:425
void apply_is_true() override
Apply the IS TRUE truth property, meaning that an UNKNOWN result and a FALSE result are treated the s...
Definition: item_subselect.h:481
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1510
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.h:495
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1589
Item_exists_subselect()
Definition: item_subselect.h:446
double val_real() override
Definition: item_subselect.cc:1575
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.h:498
bool implicit_is_op
True if the IS TRUE/FALSE wasn't explicit in the query.
Definition: item_subselect.h:478
Item * truth_transformer(THD *, enum Bool_test test) override
Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implemen...
Definition: item_subselect.cc:1400
longlong val_int() override
Definition: item_subselect.cc:1577
Subquery_strategy strategy
Execution strategy chosen for this Item.
Definition: item_subselect.h:423
TABLE_LIST * embedding_join_nest
Used by subquery optimizations to keep track about where this subquery predicate is located,...
Definition: item_subselect.h:442
bool val_bool() override
Definition: item_subselect.cc:1613
int sj_convert_priority
Priority of this predicate in the convert-to-semi-join-nest process.
Definition: item_subselect.h:421
void reset() override
Definition: item_subselect.h:458
bool value
value of this item (boolean: exists/not-exists)
Definition: item_subselect.h:417
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1342
trans_res select_transformer(THD *, Query_block *) override
Definition: item_subselect.h:452
bool can_do_aj
True if the Item has decided that it can do antijoin.
Definition: item_subselect.h:488
bool with_is_op() const
Definition: item_subselect.h:466
enum Bool_test value_transform
Definition: item_subselect.h:465
void notify_removal() override
Called when an item has been removed, can be used to notify external objects about the removal,...
Definition: item_subselect.h:450
subs_type substype() const override
Definition: item_subselect.h:456
Item_subselect super
Definition: item_subselect.h:413
bool translate(bool &null_v, bool v)
Translates the value of the naked EXISTS to a value taking into account the optional NULL and IS [NOT...
Definition: item_subselect.cc:1363
bool is_bool_func() const override
Definition: item_subselect.h:457
bool choose_semijoin_or_antijoin()
Helper for resolve_subquery().
Definition: item_subselect.cc:1538
Item_exists_subselect(const POS &pos)
Definition: item_subselect.h:448
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1606
enum Item_result result_type() const override
Definition: item_subselect.h:460
int fix_outer_field(THD *thd, Field **field, Item **reference)
Resolve the name of an outer select column reference.
Definition: item.cc:5171
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:5598
Definition: item_cmpfunc.h:903
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Fix after tables have been moved from one query_block level to the parent level, e....
Definition: item.cc:3085
Definition: item_cmpfunc.h:484
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:521
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:2527
Item * left_expr
Definition: item_subselect.h:525
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:2542
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1667
struct Item_in_subselect::In2exists_info * in2exists_info
Item_in_optimizer * optimizer
Pointer to the created Item_in_optimizer; it is stored for the same reasons as 'm_injected_left_expr'...
Definition: item_subselect.h:563
double val_real() override
Definition: item_subselect.cc:1624
bool need_expr_cache
The need for expr cache may be optimized away,.
Definition: item_subselect.h:536
void set_cond_guard_var(int i, bool v)
Definition: item_subselect.h:622
Item_func_not_all * upper_item
Definition: item_subselect.h:604
bool finalize_materialization_transform(THD *thd, JOIN *join)
Once the decision to use materialization has been taken, performs some last steps of this transformat...
Definition: item_subselect.cc:438
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_subselect.cc:1485
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2497
bool abort_on_null
True if naked IN is allowed to exchange FALSE for UNKNOWN.
Definition: item_subselect.h:572
void reset() override
Definition: item_subselect.h:649
bool mark_as_outer(Item *left_row, size_t col)
Decide whether to mark the injected left expression "outer" relative to the subquery.
Definition: item_subselect.cc:373
Item * transform(Item_transformer transformer, uchar *arg) override
Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to ...
Definition: item_subselect.cc:738
bool dependent_before_in2exists() const
Is reliable only if IN->EXISTS has been done.
Definition: item_subselect.h:615
bool * pushed_cond_guards
Definition: item_subselect.h:602
AccessPath * root_access_path() const override
Definition: item_subselect.cc:528
PT_subquery * pt_subselect
Definition: item_subselect.h:607
longlong val_int() override
Definition: item_subselect.cc:1631
trans_res single_value_in_to_exists_transformer(THD *thd, Query_block *select, Comp_creator *func)
Transform an IN predicate into EXISTS via predicate injection.
Definition: item_subselect.cc:1914
bool finalize_exists_transform(THD *thd, Query_block *select)
Once the decision to use IN->EXISTS has been taken, performs some last steps of this transformation.
Definition: item_subselect.cc:380
bool val_bool() override
Definition: item_subselect.cc:1645
List< Cached_item > * left_expr_cache
Cache of the left operand of the subquery predicate.
Definition: item_subselect.h:532
trans_res single_value_transformer(THD *thd, Query_block *select, Comp_creator *func)
Rewrite a single-column IN/ALL/ANY subselect.
Definition: item_subselect.cc:1706
bool was_null
Definition: item_subselect.h:564
bool init_left_expr_cache(THD *thd)
Initialize the cache of the left operand of the IN predicate.
Definition: item_subselect.cc:2560
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:496
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1638
trans_res row_value_in_to_exists_transformer(THD *thd, Query_block *select)
Tranform a (possibly non-correlated) IN subquery into a correlated EXISTS.
Definition: item_subselect.cc:2200
trans_res select_in_like_transformer(THD *thd, Query_block *select, Comp_creator *func)
Prepare IN/ALL/ANY/SOME subquery transformation and call appropriate transformation function.
Definition: item_subselect.cc:2416
bool in2exists_added_to_where() const
Definition: item_subselect.h:610
bool * get_cond_guard(int i)
Definition: item_subselect.h:619
bool walk(Item_processor processor, enum_walk walk, uchar *arg) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item_subselect.cc:732
subs_type substype() const override
Definition: item_subselect.h:647
Item_exists_subselect super
Definition: item_subselect.h:522
bool test_limit()
Definition: item_subselect.cc:1431
trans_res row_value_transformer(THD *thd, Query_block *select)
Definition: item_subselect.cc:2133
Item_in_subselect()
Definition: item_subselect.h:630
bool val_bool_naked()
Definition: item_subselect.cc:1652
Item_ref * m_injected_left_expr
In the case of.
Definition: item_subselect.h:557
bool exec(THD *thd) override
Definition: item_subselect.cc:749
bool left_expr_cache_filled
Whether left_expr_cache holds a value.
Definition: item_subselect.h:533
trans_res select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:2389
Definition: item_cmpfunc.h:2227
Definition: item_subselect.h:366
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1093
bool max
Definition: item_subselect.h:368
Item_maxmin_subselect(Item_subselect *parent, Query_block *query_block, bool max, bool ignore_nulls)
Definition: item_subselect.cc:1067
bool any_value()
Definition: item_subselect.h:376
bool is_maxmin() const override
Definition: item_subselect.h:379
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:1086
void reset_value_registration() override
Definition: item_subselect.h:378
void register_value()
Definition: item_subselect.h:377
bool was_values
Definition: item_subselect.h:369
Definition: item.h:5987
Definition: item.h:5580
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:7906
Item with result field.
Definition: item.h:5503
Definition: item_subselect.h:276
Item * replace_scalar_subquery(uchar *arge) override
When walking the item tree seeing an Item_singlerow_subselect matching a target, replace it with a su...
Definition: item_subselect.cc:2795
enum Item_result result_type() const override
Definition: item_subselect.cc:1168
void store(uint i, Item *item)
Definition: item_subselect.cc:1163
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:339
trans_res select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:1114
bool null_inside() override
Definition: item_subselect.cc:1212
Item ** addr(uint i) override
Definition: item_subselect.h:320
double val_real() override
Definition: item_subselect.cc:1226
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1172
void no_rows_in_result() override
Definition: item_subselect.cc:1195
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_subselect.cc:1269
void reset() override
Definition: item_subselect.cc:1099
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.cc:1279
longlong val_int() override
Definition: item_subselect.cc:1237
uint cols() const override
Definition: item_subselect.h:309
virtual bool is_maxmin() const
Definition: item_subselect.h:326
Item * element_index(uint i) override
Definition: item_subselect.h:317
Item_cache ** row
Definition: item_subselect.h:278
Item_singlerow_subselect()
Definition: item_subselect.h:282
Query_block * invalidate_and_restore_query_block()
This method is used to implement a special case of semantic tree rewriting, mandated by a SQL:2003 ex...
Definition: item_subselect.cc:883
bool collect_scalar_subqueries(uchar *) override
Definition: item_subselect.cc:2721
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.cc:1290
String * val_str(String *) override
Definition: item_subselect.cc:1248
bool val_bool() override
Definition: item_subselect.cc:1300
bool no_rows
no_rows_in_result
Definition: item_subselect.h:279
subs_type substype() const override
Definition: item_subselect.h:286
void bring_value() override
Definition: item_subselect.cc:1219
bool check_cols(uint c) override
Definition: item_subselect.cc:1204
Item_cache * value
Definition: item_subselect.h:278
my_decimal * val_decimal(my_decimal *) override
Definition: item_subselect.cc:1258
Definition: item_subselect.h:79
subselect_indexsubquery_engine * indexsubquery_engine
Definition: item_subselect.h:140
enum_parsing_context parsing_place
Definition: item_subselect.h:147
Item * replace_item_view_ref(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:2898
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the subquery from the item tree.
Definition: item_subselect.cc:2652
bool is_evaluated() const
Definition: item_subselect.cc:2705
bool collect_subqueries(uchar *) override
Definition: item_subselect.cc:2690
table_map used_tables() const override
Definition: item_subselect.h:199
subs_type
Definition: item_subselect.h:156
@ UNKNOWN_SUBS
Definition: item_subselect.h:157
@ EXISTS_SUBS
Definition: item_subselect.h:159
@ SINGLEROW_SUBS
Definition: item_subselect.h:158
@ ALL_SUBS
Definition: item_subselect.h:161
@ ANY_SUBS
Definition: item_subselect.h:162
@ IN_SUBS
Definition: item_subselect.h:160
void accumulate_expression(Item *item)
Accumulate properties from a selected expression within a query block.
Definition: item_subselect.cc:274
void accumulate_used_tables(table_map add_tables)
Accumulate used tables.
Definition: item_subselect.h:181
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item_subselect.h:233
bool is_uncacheable() const
Definition: item_subselect.cc:3095
void accumulate_properties()
Accumulate properties from underlying query expression.
Definition: item_subselect.cc:213
virtual bool exec(THD *thd)
Definition: item_subselect.cc:644
enum_engine_type
Definition: item_subselect.h:116
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:116
@ HASH_SJ_ENGINE
Definition: item_subselect.h:116
@ OTHER_ENGINE
Definition: item_subselect.h:116
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:827
const TABLE_REF & get_table_ref() const
Definition: item_subselect.cc:315
Query_expression * unit
Definition: item_subselect.h:108
virtual void reset_value_registration()
Definition: item_subselect.h:221
bool explain_subquery_checker(uchar **arg) override
Register subquery to the table where it is used within a condition.
Definition: item_subselect.cc:637
bool traced_before
Whether or not execution of this subselect has been traced by optimizer tracing already.
Definition: item_subselect.h:90
Item * substitution
Definition: item_subselect.h:105
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item_subselect.cc:808
enum_parsing_context place()
Definition: item_subselect.h:222
virtual void reset()
Definition: item_subselect.h:188
Item * replace_item_field(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:2890
uint max_columns
Definition: item_subselect.h:145
join_type get_join_type() const
Definition: item_subselect.cc:320
bool assigned() const
Definition: item_subselect.h:190
int in_cond_of_tab
If !=NO_PLAN_IDX: this Item is in the condition attached to the JOIN_TAB having this index in the par...
Definition: item_subselect.h:113
void accumulate_condition(Item *item)
Accumulate properties from a condition or GROUP/ORDER within a query block.
Definition: item_subselect.cc:285
virtual AccessPath * root_access_path() const
Definition: item_subselect.h:125
void create_iterators(THD *thd)
Definition: item_subselect.cc:290
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:325
Item * replace_item(Item_transformer t, uchar *arg)
Definition: item_subselect.cc:2833
virtual trans_res select_transformer(THD *thd, Query_block *select)=0
const TABLE * get_table() const
Definition: item_subselect.cc:310
enum Type type() const override
Definition: item_subselect.cc:801
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:549
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:803
void set_indexsubquery_engine(subselect_indexsubquery_engine *eng)
Definition: item_subselect.h:206
void assigned(bool a)
Definition: item_subselect.h:191
const char * func_name() const override
Definition: item_subselect.h:228
bool have_to_be_excluded
Definition: item_subselect.h:149
table_map not_null_tables() const override
Return table map of tables that can't be NULL tables (tables that are used in a context where if they...
Definition: item_subselect.h:200
table_map used_tables_cache
Definition: item_subselect.h:143
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_subselect.cc:820
bool walk(Item_processor processor, enum_walk walk, uchar *arg) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item_subselect.cc:616
bool changed
Definition: item_subselect.h:153
Item_subselect()
Definition: item_subselect.cc:102
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_subselect.h:193
void init(Query_block *select, Query_result_subquery *result)
Definition: item_subselect.cc:138
enum_engine_type engine_type() const
Definition: item_subselect.cc:296
virtual subs_type substype() const
Definition: item_subselect.h:185
unique_ptr_destroy_only< SubqueryWithResult > subquery
Definition: item_subselect.h:136
Item_result_field super
Definition: item_subselect.h:80
bool inform_item_in_cond_of_tab(uchar *arg) override
Tells an Item that it is in the condition of a JOIN_TAB of a query block.
Definition: item_subselect.cc:2624
trans_res
Definition: item_subselect.h:155
@ RES_REDUCE
Definition: item_subselect.h:155
@ RES_ERROR
Definition: item_subselect.h:155
@ RES_OK
Definition: item_subselect.h:155
bool value_assigned
Definition: item_subselect.h:83
bool subq_opt_away_processor(uchar *arg) override
Mark the subquery as optimized away, for EXPLAIN.
Definition: item_subselect.cc:2636
uint unit_cols() const
Definition: item_subselect.cc:3090
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:714
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
bool null_value
True if item is null.
Definition: item.h:3369
Type
Definition: item.h:838
Bool_test
< Modifier for result transformation
Definition: item.h:886
@ BOOL_NOT_FALSE
Definition: item.h:890
@ BOOL_NOT_TRUE
Definition: item.h:889
@ BOOL_IS_TRUE
Definition: item.h:886
@ BOOL_IS_FALSE
Definition: item.h:887
@ BOOL_IDENTITY
Definition: item.h:892
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1428
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:7281
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1515
Definition: sql_optimizer.h:125
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1167
Definition: sql_list.h:433
Definition: parse_tree_nodes.h:1607
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:102
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1124
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:629
Definition: item_subselect.cc:1311
Definition: query_result.h:200
Definition: item_subselect.cc:850
Base class for result from a subquery.
Definition: query_result.h:323
Definition: sql_union.h:39
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:166
Definition: item_subselect.h:721
enum Item_result type() const
Definition: item_subselect.h:751
Item_subselect * item
Definition: item_subselect.h:765
bool maybe_null
True if at least one of the columns returned by the subquery may be null, or if a single-row subquery...
Definition: item_subselect.h:772
bool may_be_null() const
Definition: item_subselect.h:753
void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3097
Query_block * single_query_block() const
Definition: item_subselect.cc:3161
enum Item_result res_type
Definition: item_subselect.h:766
enum_field_types res_field_type
Definition: item_subselect.h:767
bool exec(THD *thd)
Execute the subquery.
Definition: item_subselect.cc:3016
SubqueryWithResult(Query_expression *u, Query_result_interceptor *res, Item_subselect *si)
Definition: item_subselect.cc:2907
Query_result_interceptor * result
Definition: item_subselect.h:764
enum_field_types field_type() const
Definition: item_subselect.h:752
Query_expression * unit
Definition: item_subselect.h:774
void fix_length_and_dec(Item_cache **row)
Definition: item_subselect.cc:2993
bool prepare(THD *thd)
Prepare the query expression underlying the subquery.
Definition: item_subselect.cc:2931
void cleanup(THD *thd)
Cleanup subquery after complete query execution, free all resources.
Definition: item_subselect.cc:2902
const Item_subselect * get_item() const
Definition: item_subselect.h:760
void set_row(const mem_root_deque< Item * > &item_list, Item_cache **row, bool never_empty)
Makes storage for the output values for a scalar or row subquery and calculates their data and column...
Definition: item_subselect.cc:2948
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result)
change query result object of subquery.
Definition: item_subselect.cc:3153
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:945
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:98
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:109
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:93
Compute an IN predicate via a hash semi-join.
Definition: item_subselect.h:858
void create_iterators(THD *thd) override
Definition: item_subselect.cc:3363
const TABLE_REF & get_table_ref() const
Definition: item_subselect.h:902
void print(const THD *thd, String *str, enum_query_type query_type) override
Print the state of this engine into a string for debugging and views.
Definition: item_subselect.cc:3594
nulls_exist
Existence of inner NULLs in materialized table: By design, other values than IRRELEVANT_OR_FALSE are ...
Definition: item_subselect.h:870
@ NEX_TRUE
they matter, and we know there exists at least one.
Definition: item_subselect.h:876
@ NEX_UNKNOWN
they matter, and we don't know yet if they exists
Definition: item_subselect.h:874
@ NEX_IRRELEVANT_OR_FALSE
none, or they don't matter
Definition: item_subselect.h:872
unique_ptr_destroy_only< RowIterator > m_iterator
Definition: item_subselect.h:880
TABLE * get_table() const
Definition: item_subselect.h:901
subselect_hash_sj_engine(Item_in_subselect *in_predicate, Query_expression *unit_arg)
Definition: item_subselect.h:887
Query_expression *const unit
Definition: item_subselect.h:879
~subselect_hash_sj_engine() override
Definition: item_subselect.cc:3428
void cleanup(THD *thd) override
Cleanup performed after each execution.
Definition: item_subselect.cc:3439
Query_result_interceptor * saved_result
Saved result object, must be restored after use.
Definition: item_subselect.h:884
enum nulls_exist mat_table_has_nulls
Definition: item_subselect.h:878
bool is_materialized
Definition: item_subselect.h:861
bool has_zero_rows
Definition: item_subselect.h:864
bool exec(THD *thd) override
Execute a subquery IN predicate via materialization.
Definition: item_subselect.cc:3476
enum_engine_type engine_type() const override
Definition: item_subselect.h:899
AccessPath * root_access_path() const
Definition: item_subselect.h:904
bool setup(THD *thd, const mem_root_deque< Item * > &tmp_columns)
Create all structures needed for subquery execution using hash semijoin.
Definition: item_subselect.cc:3193
enum join_type get_join_type() const
Definition: item_subselect.h:903
AccessPath * m_root_access_path
Definition: item_subselect.h:881
A subquery execution engine that evaluates the subquery by doing index lookups in a single table's in...
Definition: item_subselect.h:798
Item * having
Definition: item_subselect.h:818
TABLE * table
Table which is read, using one of eq_ref, ref, ref_or_null.
Definition: item_subselect.h:802
virtual ~subselect_indexsubquery_engine()=default
TABLE_LIST * table_ref
Definition: item_subselect.h:803
virtual bool exec(THD *thd)
Definition: item_subselect.cc:3079
subselect_indexsubquery_engine(TABLE *table, TABLE_LIST *table_ref, const TABLE_REF &ref, enum join_type join_type, Item_in_subselect *subs, Item *where, Item *having_arg)
Definition: item_subselect.h:825
virtual void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3102
Item * cond
Definition: item_subselect.h:806
virtual void create_iterators(THD *)
Definition: item_subselect.h:841
join_type type
Definition: item_subselect.h:805
enum_engine_type
Definition: item_subselect.h:823
@ HASH_SJ_ENGINE
Definition: item_subselect.h:823
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:823
ulonglong hash
Definition: item_subselect.h:807
TABLE_REF ref
Definition: item_subselect.h:804
virtual enum_engine_type engine_type() const
Definition: item_subselect.h:839
Item_in_subselect * item
Definition: item_subselect.h:820
virtual void cleanup(THD *)
Definition: item_subselect.h:840
Comp_creator *(*)(bool invert) chooser_compare_func_creator
Convenience typedef for a function that returns factories for Item comparators (ie....
Definition: comp_creator.h:38
char * pos
Definition: do_ctype.cc:76
static int cmp(Bigint *a, Bigint *b)
Definition: dtoa.cc:1064
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
This file contains the field type.
enum_field_types
Column types for MySQL.
Definition: field_types.h:57
bool subquery_allows_materialization(THD *thd, Query_block *query_block, const Query_block *outer)
Check if the subquery predicate can be executed via materialization.
Definition: sql_resolver.cc:964
Item * all_any_subquery_creator(Item *left_expr, chooser_compare_func_creator cmp, bool all, Query_block *select)
Construct ALL/ANY/SOME subquery Item.
Definition: sql_parse.cc:6581
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:719
Item * remove_in2exists_conds(THD *thd, Item *conds)
Removes every predicate injected by IN->EXISTS.
Definition: item_subselect.cc:403
bool IsItemInSubSelect(Item *item)
Returns whether the Item is an IN-subselect.
Definition: item_subselect.cc:2591
Subquery_strategy
Strategy which will be used to handle this subquery: flattening to a semi-join, conversion to a deriv...
Definition: item_subselect.h:390
@ CANDIDATE_FOR_SEMIJOIN
Candidate for semi-join flattening.
@ UNSPECIFIED
Nothing decided yet.
@ SUBQ_EXISTS
Evaluate as EXISTS subquery (possibly after rewriting from another type)
@ DERIVED_TABLE
Rewrite to joined derived table.
@ DELETED
Subquery has been deleted, probably because it was always false.
@ CANDIDATE_FOR_IN2EXISTS_OR_MAT
Candidate for rewriting IN(subquery) to EXISTS, or subquery materialization.
@ SEMIJOIN
Semi-join flattening.
@ SUBQ_MATERIALIZATION
Subquery materialization (HASH_SJ_ENGINE)
@ CANDIDATE_FOR_DERIVED_TABLE
Candidate for rewriting to joined derived table.
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:488
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
long long int longlong
Definition: my_inttypes.h:54
uint64_t table_map
Definition: my_table_map.h:29
Interface for low level time utilities.
unsigned int my_time_flags_t
Time handling defaults.
Time declarations shared between the server and client API: you should not add anything to this heade...
static char * where
Definition: mysqldump.cc:133
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1055
PT & ref(PT *tp)
Definition: tablespace_impl.cc:358
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
enum_parsing_context
Names for different query parse tree parts.
Definition: parse_tree_node_base.h:55
File containing constants that can be used throughout the server.
enum_walk
Enumeration for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:292
bool(Item::*)(unsigned char *) Item_processor
Processor type for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:310
enum_condition_context
Enumeration for Query_block::condition_context.
Definition: sql_const.h:316
Common types of the Optimizer, used by optimization and execution.
join_type
Definition: sql_opt_exec_shared.h:177
@ JT_UNKNOWN
Definition: sql_opt_exec_shared.h:179
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:188
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:485
int err_code
the error code found during check(if any)
Definition: item.h:492
int get_unnamed_function_error_code() const
Return the correct error code, based on whether or not if we are checking for disallowed functions in...
Definition: item.h:504
This bundles several pieces of information useful when doing the IN->EXISTS transform.
Definition: item_subselect.h:580
bool added_to_where
True: if IN->EXISTS has been done and has added a condition to the subquery's WHERE clause.
Definition: item_subselect.h:585
bool dependent_before
True: if subquery was dependent (correlated) before IN->EXISTS was done.
Definition: item_subselect.h:590
bool dependent_after
True: if subquery was dependent (correlated) after IN->EXISTS was done.
Definition: item_subselect.h:595
Argument for walk method replace_scalar_subquery.
Definition: item_subselect.h:331
Query_block * m_outer_query_block
The transformed query block.
Definition: item_subselect.h:334
Field * m_field
the replacement field
Definition: item_subselect.h:333
Query_block * m_inner_query_block
The immediately surrounding query.
Definition: item_subselect.h:335
bool m_add_coalesce
Definition: item_subselect.h:338
Item_singlerow_subselect * m_target
subquery to be replaced with field
Definition: item_subselect.h:332
Scalar_subquery_replacement(Item_singlerow_subselect *target, Field *field, Query_block *select, bool add_coalesce)
Definition: item_subselect.h:339
argument used by walk method collect_scalar_subqueries ("css")
Definition: item_subselect.h:241
Collect_subq_info(Query_block *owner)
Definition: item_subselect.h:245
Query_block * m_query_block
Definition: item_subselect.h:244
std::vector< Item_subselect * > list
< accumulated all subq (or aggregates) found
Definition: item_subselect.h:243
bool contains(Query_expression *candidate)
Definition: item_subselect.h:246
Definition: mysql_time.h:81
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:90
Definition: table.h:2684
Definition: sql_opt_exec_shared.h:58
Definition: table.h:1394
Bison "location" class.
Definition: parse_location.h:42
Definition: result.h:29
unsigned int uint
Definition: uca-dump.cc:29
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
@ INT_RESULT
double
Definition: udf_registration_types.h:42
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:868