MySQL 8.0.39
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, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27/* subselect Item */
28
29#include <assert.h>
30#include <sys/types.h>
31
32#include <cstddef>
33#include <memory> // unique_ptr
34#include <vector>
35
36#include "field_types.h" // enum_field_types
37#include "my_alloc.h" // Destroy_only
38
39#include "my_inttypes.h"
40#include "my_table_map.h"
41#include "my_time.h"
43#include "mysql_time.h"
44#include "sql/comp_creator.h"
45#include "sql/enum_query_type.h"
46#include "sql/item.h" // Item_result_field
47#include "sql/iterators/row_iterator.h" // IWYU pragma: keep
48#include "sql/parse_location.h" // POS
50#include "sql/sql_const.h"
52#include "template_utils.h"
53
54class Comp_creator;
55class Field;
58class JOIN;
59class Json_wrapper;
60class PT_subquery;
64class Query_block;
66class String;
68class THD;
70class my_decimal;
72struct AccessPath;
73class Table_ref;
74
75template <class T>
76class List;
77
78/* base class for subselects */
79
82
83 private:
84 bool value_assigned; /* value already assigned to subselect */
85 /**
86 Whether or not execution of this subselect has been traced by
87 optimizer tracing already. If optimizer trace option
88 REPEATED_SUBSELECT is disabled, this is used to disable tracing
89 after the first one.
90 */
92
93 public:
94 /*
95 Used inside Item_subselect::fix_fields() according to this scenario:
96 > Item_subselect::fix_fields
97 > subquery->prepare
98 > query_block->prepare
99 (Here we realize we need to do the rewrite and set
100 substitution= some new Item, eg. Item_in_optimizer )
101 < query_block->prepare
102 < subquery->prepare
103 *ref= substitution;
104 < Item_subselect::fix_fields
105 */
107
108 /* unit of subquery */
110 /**
111 If !=NO_PLAN_IDX: this Item is in the condition attached to the JOIN_TAB
112 having this index in the parent JOIN.
113 */
115
116 // For EXPLAIN.
119
120 // For EXPLAIN. Only valid if engine_type() == HASH_SJ_ENGINE.
121 const TABLE *get_table() const;
122 const Index_lookup &index_lookup() const;
123 join_type get_join_type() const;
124
125 void create_iterators(THD *thd);
126 virtual AccessPath *root_access_path() const { return nullptr; }
127
128 protected:
129 /**
130 We need this method, because some compilers do not allow 'this'
131 pointer in constructor initialization list, but we need to pass a pointer
132 to subselect Item class to Query_result_interceptor's constructor.
133 */
135
136 /// The inner part of the subquery.
138
139 /// Only relevant for Item_in_subselect; optimized structure used for
140 /// execution in place of running the entire subquery.
142
143 /// cache of used tables
145 /// allowed number of columns (1 for scalar subqueries)
147 /// where subquery is placed
149 /// work with 'substitution'
151
152 public:
153 /// cache of used tables, used to identify tables added for IN subquery
155 /// subquery is transformed
157
165 };
166
168 explicit Item_subselect(const POS &pos);
169
170 private:
171 /// Accumulate properties from underlying query expression
173 /// Accumulate properties from underlying query block
175 /// Accumulate properties from a selected expression within a query block.
176 void accumulate_expression(Item *item);
177 /// Accumulate properties from a condition or GROUP/ORDER within a query
178 /// block.
179 void accumulate_condition(Item *item);
180
181 public:
182 /// Accumulate used tables
186 }
187
188 virtual subs_type substype() const { return UNKNOWN_SUBS; }
189
190 void cleanup() override;
191 virtual void reset() { null_value = true; }
192 virtual bool select_transformer(THD *thd, Query_block *select) = 0;
193 bool assigned() const { return value_assigned; }
194 void assigned(bool a) { value_assigned = a; }
195 enum Type type() const override;
196 bool is_null() override { return update_null_value() || null_value; }
197 bool fix_fields(THD *thd, Item **ref) override;
198 void fix_after_pullout(Query_block *parent_query_block,
199 Query_block *removed_query_block) override;
200 virtual bool exec(THD *thd);
201 bool resolve_type(THD *) override;
202 table_map used_tables() const override { return used_tables_cache; }
203 table_map not_null_tables() const override { return 0; }
204 Item *get_tmp_table_item(THD *thd) override;
205 void update_used_tables() override;
206 void print(const THD *thd, String *str,
207 enum_query_type query_type) const override;
208
211 }
212
213 /*
214 True if this subquery has been already evaluated. Implemented only for
215 single select and union subqueries only.
216 */
217 bool is_evaluated() const;
218 bool is_uncacheable() const;
219
220 /*
221 Used by max/min subquery to initialize value presence registration
222 mechanism. Engine call this method before rexecution query.
223 */
224 virtual void reset_value_registration() {}
226 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
227 bool explain_subquery_checker(uchar **arg) override;
228 bool inform_item_in_cond_of_tab(uchar *arg) override;
229 bool clean_up_after_removal(uchar *arg) override;
230
231 const char *func_name() const override {
232 assert(0);
233 return "subselect";
234 }
235
238 pointer_cast<Check_function_as_value_generator_parameters *>(args);
239 func_arg->err_code = func_arg->get_unnamed_function_error_code();
240 return true;
241 }
242
243 /// argument used by walk method collect_scalar_subqueries ("css")
245 ///< accumulated all subq (or aggregates) found
246 std::vector<Item_subselect *> list;
249 bool contains(Query_expression *candidate) {
250 for (auto sq : list) {
251 if (sq->unit == candidate) return true;
252 }
253 return false;
254 }
255 };
256
257 bool collect_subqueries(uchar *) override;
258 Item *replace_item_field(uchar *arg) override;
259 Item *replace_item_view_ref(uchar *arg) override;
261
263 friend class Item_in_optimizer;
264 friend bool Item_field::fix_fields(THD *, Item **);
266 friend bool Item_ref::fix_fields(THD *, Item **);
267 friend void Item_ident::fix_after_pullout(Query_block *parent_query_block,
268 Query_block *removed_query_block);
269
270 private:
271 bool subq_opt_away_processor(uchar *arg) override;
272
273 protected:
274 uint unit_cols() const;
275};
276
277/* single value subselect */
278
280 protected:
282 bool no_rows; ///< @c no_rows_in_result
283 public:
286 : Item_subselect(), value(nullptr), row(nullptr), no_rows(false) {}
287
288 void cleanup() override;
289 subs_type substype() const override { return SINGLEROW_SUBS; }
290
291 void reset() override;
292 bool select_transformer(THD *thd, Query_block *select) override;
293 void store(uint i, Item *item);
294 double val_real() override;
295 longlong val_int() override;
296 String *val_str(String *) override;
297 my_decimal *val_decimal(my_decimal *) override;
298 bool val_json(Json_wrapper *result) override;
299 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
300 bool get_time(MYSQL_TIME *ltime) override;
301 bool val_bool() override;
302 enum Item_result result_type() const override;
303 bool resolve_type(THD *) override;
304
305 /*
306 Mark the subquery as having no rows.
307 If there are aggregate functions (in the outer query),
308 we need to generate a NULL row. @c return_zero_rows().
309 */
310 void no_rows_in_result() override;
311
312 uint cols() const override { return unit_cols(); }
313
314 /**
315 @note that this returns the i-th element of the SELECT list.
316 To check for nullability, look at this->maybe_null and not
317 element_index[i]->maybe_null, since the selected expressions are
318 always NULL if the subquery is empty.
319 */
320 Item *element_index(uint i) override {
321 return reinterpret_cast<Item *>(row[i]);
322 }
323 Item **addr(uint i) override { return (Item **)row + i; }
324 bool check_cols(uint c) override;
325 bool null_inside() override;
326 void bring_value() override;
327
328 bool collect_scalar_subqueries(uchar *) override;
329 virtual bool is_maxmin() const { return false; }
330
331 /**
332 Argument for walk method replace_scalar_subquery
333 */
335 Item_singlerow_subselect *m_target; ///< subquery to be replaced with field
336 Field *m_field; ///< the replacement field
337 Query_block *m_outer_query_block; ///< The transformed query block.
338 Query_block *m_inner_query_block; ///< The immediately surrounding query
339 ///< block. This will be the transformed
340 ///< block or a subquery of it
341 bool m_add_coalesce{false};
343 Query_block *select, bool add_coalesce)
344 : m_target(target),
345 m_field(field),
346 m_outer_query_block(select),
347 m_inner_query_block(select),
348 m_add_coalesce(add_coalesce) {}
349 };
350
351 Item *replace_scalar_subquery(uchar *arge) override;
352 /**
353 This method is used to implement a special case of semantic tree
354 rewriting, mandated by a SQL:2003 exception in the specification.
355 The only caller of this method is handle_sql2003_note184_exception(),
356 see the code there for more details.
357 Note that this method breaks the object internal integrity, by
358 removing it's association with the corresponding Query_block,
359 making this object orphan from the parse tree.
360 No other method, beside the destructor, should be called on this
361 object, as it is now invalid.
362 @return the Query_block structure that was given in the constructor.
363 */
365 std::optional<ContainedSubquery> get_contained_subquery(
366 const Query_block *outer_query_block) override;
368};
369
370/* used in static ALL/ANY optimization */
372 protected:
373 bool max;
374 bool was_values; // Set if we have found at least one row
375 public:
377 bool max, bool ignore_nulls);
378 void print(const THD *thd, String *str,
379 enum_query_type query_type) const override;
380 void cleanup() override;
381 bool any_value() { return was_values; }
382 void register_value() { was_values = true; }
383 void reset_value_registration() override { was_values = false; }
384 bool is_maxmin() const override { return true; }
385};
386
387/* exists subselect */
388
389/**
390 Strategy which will be used to handle this subquery: flattening to a
391 semi-join, conversion to a derived table, rewrite of IN to EXISTS...
392 Sometimes the strategy is first only a candidate, then the real decision
393 happens in a second phase. Other times the first decision is final.
394 */
395enum class Subquery_strategy : int {
396 /// Nothing decided yet
398 /// Candidate for rewriting IN(subquery) to EXISTS, or subquery
399 /// materialization
401 /// Candidate for semi-join flattening
403 /// Candidate for rewriting to joined derived table
405 /// Semi-join flattening
406 SEMIJOIN,
407 /// Rewrite to joined derived table
409 /// Evaluate as EXISTS subquery (possibly after rewriting from another type)
411 /// Subquery materialization (HASH_SJ_ENGINE)
413 /// Subquery has been deleted, probably because it was always false
414 DELETED,
415};
416
419
420 protected:
421 /// value of this item (boolean: exists/not-exists)
422 bool value{false};
423
424 public:
425 /// Priority of this predicate in the convert-to-semi-join-nest process.
427 /// Execution strategy chosen for this Item
429 /// Used by the transformation to derived table
431
432 /**
433 Used by subquery optimizations to keep track about where this subquery
434 predicate is located, and whether it is a candidate for transformation.
435 (Table_ref*) 1 - the predicate is an AND-part of the WHERE
436 join nest pointer - the predicate is an AND-part of ON expression
437 of a join nest
438 NULL - for all other locations. It also means that the
439 predicate is not a candidate for transformation.
440 See also THD::emb_on_expr_nest.
441
442 As for the second case above (the join nest pointer), note that this value
443 may change if scalar subqueries are transformed to derived tables,
444 cf. transform_scalar_subqueries_to_join_with_derived, due to the need to
445 build new join nests. The change is performed in Query_block::nest_derived.
446 */
448
450
452
453 explicit Item_exists_subselect(const POS &pos) : super(pos) {}
454
456
457 bool select_transformer(THD *, Query_block *) override {
459 return false;
460 }
461 subs_type substype() const override { return EXISTS_SUBS; }
462 bool is_bool_func() const override { return true; }
463 void reset() override { value = false; }
464
465 enum Item_result result_type() const override { return INT_RESULT; }
466 /*
467 The item is
468 ([NOT] IN/EXISTS) [ IS [NOT] TRUE|FALSE ]
469 */
471 bool with_is_op() const {
472 switch (value_transform) {
473 case BOOL_IS_TRUE:
474 case BOOL_IS_FALSE:
475 case BOOL_NOT_TRUE:
476 case BOOL_NOT_FALSE:
477 return true;
478 default:
479 return false;
480 }
481 }
482 /// True if the IS TRUE/FALSE wasn't explicit in the query
483 bool implicit_is_op = false;
484 Item *truth_transformer(THD *, enum Bool_test test) override;
485 bool translate(bool &null_v, bool v);
486 void apply_is_true() override {
487 bool had_is = with_is_op();
489 if (!had_is && value_transform == BOOL_IS_TRUE)
490 implicit_is_op = true; // needn't be written by EXPLAIN
491 }
492 /// True if the Item has decided that it can do antijoin
493 bool can_do_aj = false;
495 longlong val_int() override;
496 double val_real() override;
497 String *val_str(String *) override;
498 my_decimal *val_decimal(my_decimal *) override;
499 bool val_bool() override;
500 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
501 return get_date_from_int(ltime, fuzzydate);
502 }
503 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
504 bool resolve_type(THD *thd) override;
505 void print(const THD *thd, String *str,
506 enum_query_type query_type) const override;
507
509};
510
511/**
512 Representation of IN subquery predicates of the form
513 "left_expr IN (SELECT ...)".
514
515 @details
516 This class has:
517 - A "subquery execution engine" (as a subclass of Item_subselect) that allows
518 it to evaluate subqueries. (and this class participates in execution by
519 having was_null variable where part of execution result is stored.
520 - Transformation methods (todo: more on this).
521
522 This class is not used directly, it is "wrapped" into Item_in_optimizer
523 which provides some small bits of subquery evaluation.
524*/
525
528
529 public:
531
532 protected:
533 /**
534 Cache of the left operand of the subquery predicate. Allocated in the
535 runtime memory root, for each execution, thus need not be freed.
536 */
538 bool left_expr_cache_filled; ///< Whether left_expr_cache holds a value
539 /** The need for expr cache may be optimized away, @sa init_left_expr_cache.
540 */
542
543 private:
544 /**
545 In the case of
546
547 x COMP_OP (SELECT1 UNION SELECT2 ...)
548
549 - the subquery transformation is done on SELECT1; this requires wrapping
550 'x' with more Item layers, and injecting that in a condition in SELECT1.
551
552 - the same transformation is done on SELECT2; but the wrapped 'x' doesn't
553 need to be created again, the one created for SELECT1 could be reused
554
555 - to achieve this, the wrapped 'x' is stored in member
556 'm_injected_left_expr' when it is created for SELECT1, and is later
557 reused for SELECT2.
558
559 This will refer to a cached value which is reevaluated once for each
560 candidate row, cf. setup in #single_value_transformer.
561 */
563
564 /**
565 Pointer to the created Item_in_optimizer; it is stored for the same
566 reasons as 'm_injected_left_expr'.
567 */
570
571 protected:
572 /**
573 True if naked IN is allowed to exchange FALSE for UNKNOWN.
574 Because this is about the naked IN, there is no public ignore_unknown(),
575 intentionally, so that callers don't get it wrong.
576 */
578
579 private:
580 /**
581 This bundles several pieces of information useful when doing the
582 IN->EXISTS transform. If this transform has not been done, pointer is
583 NULL.
584 */
586 /**
587 True: if IN->EXISTS has been done and has added a condition to the
588 subquery's WHERE clause.
589 */
591 /**
592 True: if subquery was dependent (correlated) before IN->EXISTS
593 was done.
594 */
596 /**
597 True: if subquery was dependent (correlated) after IN->EXISTS
598 was done.
599 */
602
603 bool mark_as_outer(Item *left_row, size_t col);
604
605 public:
606 /* Used to trigger on/off conditions that were pushed down to subselect */
608
609 Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
610
611 private:
613
614 public:
617 }
618
619 /// Is reliable only if IN->EXISTS has been done.
622 }
623
624 bool *get_cond_guard(int i) {
625 return pushed_cond_guards ? pushed_cond_guards + i : nullptr;
626 }
627 void set_cond_guard_var(int i, bool v) {
629 }
630
632 Item_in_subselect(const POS &pos, Item *left_expr,
633 PT_subquery *pt_subquery_arg);
634
640 need_expr_cache(true),
643 was_null(false),
644 abort_on_null(false),
648
649 bool itemize(Parse_context *pc, Item **res) override;
650
651 void cleanup() override;
652 subs_type substype() const override { return IN_SUBS; }
653
654 void reset() override {
655 value = false;
656 null_value = false;
657 was_null = false;
658 }
659 bool select_transformer(THD *thd, Query_block *select) override;
660 bool select_in_like_transformer(THD *thd, Query_block *select,
661 Comp_creator *func);
662 bool single_value_transformer(THD *thd, Query_block *select,
663 Comp_creator *func);
664 bool row_value_transformer(THD *thd, Query_block *select);
666 Comp_creator *func);
668 bool subquery_allows_materialization(THD *thd, Query_block *query_block,
669 const Query_block *outer);
670 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
671 Item *transform(Item_transformer transformer, uchar *arg) override;
672 Item *compile(Item_analyzer analyzer, uchar **arg_p,
673 Item_transformer transformer, uchar *arg_t) override;
674
675 bool exec(THD *thd) override;
676 longlong val_int() override;
677 double val_real() override;
678 String *val_str(String *) override;
679 my_decimal *val_decimal(my_decimal *) override;
680 bool val_bool() override;
681 bool test_limit();
682 void print(const THD *thd, String *str,
683 enum_query_type query_type) const override;
684 bool fix_fields(THD *thd, Item **ref) override;
685 void fix_after_pullout(Query_block *parent_query_block,
686 Query_block *removed_query_block) override;
687 void update_used_tables() override;
688 bool init_left_expr_cache(THD *thd);
689
690 /**
691 Once the decision to use IN->EXISTS has been taken, performs some last
692 steps of this transformation.
693 */
694 bool finalize_exists_transform(THD *thd, Query_block *select);
695 /**
696 Once the decision to use materialization has been taken, performs some
697 last steps of this transformation.
698 */
700 AccessPath *root_access_path() const override;
701 std::optional<ContainedSubquery> get_contained_subquery(
702 const Query_block *outer_query_block) override;
703
706 friend class Item_in_optimizer;
709
710 private:
711 bool val_bool_naked();
712};
713
714/// ALL/ANY/SOME subselect.
716 public:
719 bool all;
720
722 Query_block *select, bool all);
723
724 // only ALL subquery has upper not
725 subs_type substype() const override { return all ? ALL_SUBS : ANY_SUBS; }
726 bool select_transformer(THD *thd, Query_block *select) override;
727 void print(const THD *thd, String *str,
728 enum_query_type query_type) const override;
729};
730
732 public:
734 Item_subselect *si);
735 /**
736 Cleanup subquery after complete query execution, free all resources.
737 */
738 void cleanup();
739 bool prepare(THD *thd);
740 void fix_length_and_dec(Item_cache **row);
741 /**
742 Execute the subquery
743
744 SYNOPSIS
745 exec()
746
747 DESCRIPTION
748 Execute the subquery. The result of execution is subquery value that is
749 captured by previously set up Query_result-based 'sink'.
750
751 RETURN
752 false - OK
753 true - Execution error.
754 */
755 bool exec(THD *thd);
756 void print(const THD *thd, String *str, enum_query_type query_type);
759 Query_block *single_query_block() const; // Only if unit is simple.
760
761 enum Item_result type() const { return res_type; }
763 bool may_be_null() const { return maybe_null; }
764
765#ifndef NDEBUG
766 /**
767 @returns the internal Item. Defined only in debug builds, because should
768 be used only for debug asserts.
769 */
770 const Item_subselect *get_item() const { return item; }
771#endif
772
773 private:
774 Query_result_interceptor *result; /* results storage class */
775 Item_subselect *item; /* item, that use this subquery */
776 enum Item_result res_type; /* type of results */
777 enum_field_types res_field_type; /* column type of the results */
778 /**
779 True if at least one of the columns returned by the subquery may
780 be null, or if a single-row subquery may return zero rows.
781 */
783
784 Query_expression *unit; /* corresponding unit structure */
785
786 void set_row(const mem_root_deque<Item *> &item_list, Item_cache **row,
787 bool never_empty);
788
790};
791
792/**
793 A subquery execution engine that evaluates the subquery by doing index
794 lookups in a single table's index.
795
796 This engine is used to resolve subqueries in forms
797
798 outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)
799
800 or, row-based:
801
802 (oe1, .. oeN) IN (SELECT key_part1, ... key_partK
803 FROM tbl WHERE subqwhere)
804
805 i.e. the subquery is a single table SELECT without GROUP BY, aggregate
806 functions, etc.
807*/
809 protected:
810 Query_result_union *result = nullptr; /* results storage class */
811 /// Table which is read, using one of eq_ref, ref, ref_or_null.
812 TABLE *table{nullptr};
816 Item *cond; /* The WHERE condition of subselect */
817 ulonglong hash; /* Hash value calculated by RefIterator, when needed. */
818 /*
819 The "having" clause. This clause (further referred to as "artificial
820 having") was inserted by subquery transformation code. It contains
821 Item(s) that have a side-effect: they record whether the subquery has
822 produced a row with NULL certain components. We need to use it for cases
823 like
824 (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
825 where we do index lookup on t.key=oe1 but need also to check if there
826 was a row such that t.no_key IS NULL.
827 */
829
830 Item_in_subselect *item; /* item that uses this engine */
831
832 public:
834
836 const Index_lookup &ref,
837 enum join_type join_type,
839 Item *having_arg)
840 : table(table),
842 ref(ref),
844 cond(where),
845 having(having_arg),
846 item(subs) {}
848 virtual bool exec(THD *thd);
849 virtual void print(const THD *thd, String *str, enum_query_type query_type);
851 virtual void cleanup() {}
852 virtual void create_iterators(THD *) {}
853};
854
855/*
856 This function is actually defined in sql_parse.cc, but it depends on
857 chooser_compare_func_creator defined in this file.
858 */
861 Query_block *select);
862
863/**
864 Compute an IN predicate via a hash semi-join. The subquery is materialized
865 during the first evaluation of the IN predicate. The IN predicate is executed
866 via the functionality inherited from subselect_indexsubquery_engine.
867*/
868
870 private:
871 /* true if the subquery was materialized into a temp table. */
873 // true if we know for sure that there are zero rows in the table.
874 // Set only after is_materialized is true.
875 bool has_zero_rows = false;
876 /**
877 Existence of inner NULLs in materialized table:
878 By design, other values than IRRELEVANT_OR_FALSE are possible only if the
879 subquery has only one inner expression.
880 */
882 /// none, or they don't matter
884 /// they matter, and we don't know yet if they exists
886 /// they matter, and we know there exists at least one.
887 NEX_TRUE = 2
888 };
893
894 /// Saved result object, must be restored after use
896
897 public:
899 Query_expression *unit_arg)
901 in_predicate, nullptr, nullptr),
902 is_materialized(false),
903 unit(unit_arg) {}
904 ~subselect_hash_sj_engine() override;
905
906 bool setup(THD *thd, const mem_root_deque<Item *> &tmp_columns);
907 void cleanup() override;
908 bool exec(THD *thd) override;
909 void print(const THD *thd, String *str, enum_query_type query_type) override;
910 enum_engine_type engine_type() const override { return HASH_SJ_ENGINE; }
911
912 TABLE *get_table() const { return table; }
913 const Index_lookup &index_lookup() const { return ref; }
914 enum join_type get_join_type() const { return type; }
916 void create_iterators(THD *thd) override;
917};
918
919/**
920 Removes every predicate injected by IN->EXISTS.
921
922 This function is different from others:
923 - it wants to remove all traces of IN->EXISTS (for
924 materialization)
925 - remove_subq_pushed_predicates() and remove_additional_cond() want to
926 remove only the conditions of IN->EXISTS which index lookup already
927 satisfies (they are just an optimization).
928
929 If there are no in2exists conditions, it will return the exact same
930 pointer. If it returns a new Item, the old Item is left alone, so it
931 can be reused in other settings.
932
933 @param conds Condition; may be nullptr.
934 @returns new condition
935 */
937
938/// Returns whether the Item is an IN-subselect.
939bool IsItemInSubSelect(Item *item);
940
941#endif /* ITEM_SUBSELECT_INCLUDED */
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:525
Definition: field.h:575
ALL/ANY/SOME subselect.
Definition: item_subselect.h:715
Item_allany_subselect(Item *left_expr, chooser_compare_func_creator fc, Query_block *select, bool all)
Definition: item_subselect.cc:1490
Comp_creator * func
Definition: item_subselect.h:718
bool select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:2722
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2730
chooser_compare_func_creator func_creator
Definition: item_subselect.h:717
bool all
Definition: item_subselect.h:719
subs_type substype() const override
Definition: item_subselect.h:725
Definition: item.h:6649
Definition: item_subselect.h:417
enum_condition_context outer_condition_context
Used by the transformation to derived table.
Definition: item_subselect.h:430
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:486
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1504
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.h:500
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1583
Item_exists_subselect()
Definition: item_subselect.h:451
double val_real() override
Definition: item_subselect.cc:1569
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.h:503
bool implicit_is_op
True if the IS TRUE/FALSE wasn't explicit in the query.
Definition: item_subselect.h:483
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:1571
Subquery_strategy strategy
Execution strategy chosen for this Item.
Definition: item_subselect.h:428
bool val_bool() override
Definition: item_subselect.cc:1607
int sj_convert_priority
Priority of this predicate in the convert-to-semi-join-nest process.
Definition: item_subselect.h:426
void reset() override
Definition: item_subselect.h:463
bool value
value of this item (boolean: exists/not-exists)
Definition: item_subselect.h:422
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
bool can_do_aj
True if the Item has decided that it can do antijoin.
Definition: item_subselect.h:493
bool with_is_op() const
Definition: item_subselect.h:471
enum Bool_test value_transform
Definition: item_subselect.h:470
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:455
subs_type substype() const override
Definition: item_subselect.h:461
Item_subselect super
Definition: item_subselect.h:418
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:462
Table_ref * embedding_join_nest
Used by subquery optimizations to keep track about where this subquery predicate is located,...
Definition: item_subselect.h:447
bool choose_semijoin_or_antijoin()
Helper for resolve_subquery().
Definition: item_subselect.cc:1532
Item_exists_subselect(const POS &pos)
Definition: item_subselect.h:453
bool select_transformer(THD *, Query_block *) override
Definition: item_subselect.h:457
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1600
enum Item_result result_type() const override
Definition: item_subselect.h:465
int fix_outer_field(THD *thd, Field **field, Item **reference)
Resolve the name of an outer select column reference.
Definition: item.cc:5251
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:5690
Definition: item_cmpfunc.h:912
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:3153
Definition: item_cmpfunc.h:492
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:526
bool fix_fields(THD *thd, Item **ref) override
An object of class Item_in_subselect is always substituted with another object of class Item_in_optim...
Definition: item_subselect.cc:2512
Item * left_expr
Definition: item_subselect.h:530
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:2533
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1661
bool row_value_transformer(THD *thd, Query_block *select)
Definition: item_subselect.cc:2125
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:568
Item * compile(Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t) override
Perform a generic "compilation" of the Item tree, ie transform the Item tree by adding zero or more I...
Definition: item_subselect.cc:736
bool row_value_in_to_exists_transformer(THD *thd, Query_block *select)
Transform a (possibly non-correlated) IN subquery into a correlated EXISTS.
Definition: item_subselect.cc:2189
double val_real() override
Definition: item_subselect.cc:1618
bool select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:2383
std::optional< ContainedSubquery > get_contained_subquery(const Query_block *outer_query_block) override
If this item represents a IN/ALL/ANY/comparison_operator subquery, return that (along with data on ho...
Definition: item_subselect.cc:2589
bool need_expr_cache
The need for expr cache may be optimized away,.
Definition: item_subselect.h:541
void set_cond_guard_var(int i, bool v)
Definition: item_subselect.h:627
Item_func_not_all * upper_item
Definition: item_subselect.h:609
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:422
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_subselect.cc:1479
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2470
bool abort_on_null
True if naked IN is allowed to exchange FALSE for UNKNOWN.
Definition: item_subselect.h:577
void reset() override
Definition: item_subselect.h:654
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:376
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:729
bool dependent_before_in2exists() const
Is reliable only if IN->EXISTS has been done.
Definition: item_subselect.h:620
bool * pushed_cond_guards
Definition: item_subselect.h:607
AccessPath * root_access_path() const override
Definition: item_subselect.cc:512
bool 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:2403
PT_subquery * pt_subselect
Definition: item_subselect.h:612
longlong val_int() override
Definition: item_subselect.cc:1625
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:383
bool val_bool() override
Definition: item_subselect.cc:1639
bool single_value_transformer(THD *thd, Query_block *select, Comp_creator *func)
Rewrite a single-column IN/ALL/ANY subselect.
Definition: item_subselect.cc:1697
List< Cached_item > * left_expr_cache
Cache of the left operand of the subquery predicate.
Definition: item_subselect.h:537
bool was_null
Definition: item_subselect.h:569
bool init_left_expr_cache(THD *thd)
Initialize the cache of the left operand of the IN predicate.
Definition: item_subselect.cc:2558
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:480
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1632
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_subselect.cc:2540
bool in2exists_added_to_where() const
Definition: item_subselect.h:615
bool * get_cond_guard(int i)
Definition: item_subselect.h:624
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:723
subs_type substype() const override
Definition: item_subselect.h:652
Item_exists_subselect super
Definition: item_subselect.h:527
bool 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:1906
bool test_limit()
Definition: item_subselect.cc:1430
Item_in_subselect()
Definition: item_subselect.h:635
bool val_bool_naked()
Definition: item_subselect.cc:1646
Item_ref * m_injected_left_expr
In the case of.
Definition: item_subselect.h:562
bool exec(THD *thd) override
Definition: item_subselect.cc:752
bool left_expr_cache_filled
Whether left_expr_cache holds a value.
Definition: item_subselect.h:538
Definition: item_cmpfunc.h:2292
Definition: item_subselect.h:371
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1094
bool max
Definition: item_subselect.h:373
Item_maxmin_subselect(Item_subselect *parent, Query_block *query_block, bool max, bool ignore_nulls)
Definition: item_subselect.cc:1068
bool any_value()
Definition: item_subselect.h:381
bool is_maxmin() const override
Definition: item_subselect.h:384
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:1087
void reset_value_registration() override
Definition: item_subselect.h:383
void register_value()
Definition: item_subselect.h:382
bool was_values
Definition: item_subselect.h:374
Definition: item.h:6132
Definition: item.h:5703
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:8082
Item with result field.
Definition: item.h:5626
Definition: item_subselect.h:279
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:2819
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:342
bool null_inside() override
Definition: item_subselect.cc:1212
Item ** addr(uint i) override
Definition: item_subselect.h:323
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:1100
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.cc:1279
std::optional< ContainedSubquery > get_contained_subquery(const Query_block *outer_query_block) override
If this item represents a IN/ALL/ANY/comparison_operator subquery, return that (along with data on ho...
Definition: item_subselect.cc:2858
longlong val_int() override
Definition: item_subselect.cc:1237
uint cols() const override
Definition: item_subselect.h:312
virtual bool is_maxmin() const
Definition: item_subselect.h:329
Item * element_index(uint i) override
Definition: item_subselect.h:320
Item_cache ** row
Definition: item_subselect.h:281
Item_singlerow_subselect()
Definition: item_subselect.h:285
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:884
bool collect_scalar_subqueries(uchar *) override
Definition: item_subselect.cc:2744
bool select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:1115
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:282
subs_type substype() const override
Definition: item_subselect.h:289
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:281
my_decimal * val_decimal(my_decimal *) override
Definition: item_subselect.cc:1258
Definition: item_subselect.h:80
subselect_indexsubquery_engine * indexsubquery_engine
Only relevant for Item_in_subselect; optimized structure used for execution in place of running the e...
Definition: item_subselect.h:141
enum_parsing_context parsing_place
where subquery is placed
Definition: item_subselect.h:148
Item * replace_item_view_ref(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:2947
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the subquery from the item tree.
Definition: item_subselect.cc:2682
bool is_evaluated() const
Definition: item_subselect.cc:2728
bool collect_subqueries(uchar *) override
Definition: item_subselect.cc:2715
table_map used_tables() const override
Definition: item_subselect.h:202
subs_type
Definition: item_subselect.h:158
@ UNKNOWN_SUBS
Definition: item_subselect.h:159
@ EXISTS_SUBS
Definition: item_subselect.h:161
@ SINGLEROW_SUBS
Definition: item_subselect.h:160
@ ALL_SUBS
Definition: item_subselect.h:163
@ ANY_SUBS
Definition: item_subselect.h:164
@ IN_SUBS
Definition: item_subselect.h:162
void accumulate_expression(Item *item)
Accumulate properties from a selected expression within a query block.
Definition: item_subselect.cc:277
void accumulate_used_tables(table_map add_tables)
Accumulate used tables.
Definition: item_subselect.h:183
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:236
bool is_uncacheable() const
Definition: item_subselect.cc:3149
void accumulate_properties()
Accumulate properties from underlying query expression.
Definition: item_subselect.cc:213
virtual bool exec(THD *thd)
Definition: item_subselect.cc:633
enum_engine_type
Definition: item_subselect.h:117
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:117
@ HASH_SJ_ENGINE
Definition: item_subselect.h:117
@ OTHER_ENGINE
Definition: item_subselect.h:117
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:832
Query_expression * unit
Definition: item_subselect.h:109
virtual void reset_value_registration()
Definition: item_subselect.h:224
bool explain_subquery_checker(uchar **arg) override
Register subquery to the table where it is used within a condition.
Definition: item_subselect.cc:626
bool traced_before
Whether or not execution of this subselect has been traced by optimizer tracing already.
Definition: item_subselect.h:91
virtual bool select_transformer(THD *thd, Query_block *select)=0
Item * substitution
Definition: item_subselect.h:106
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:811
enum_parsing_context place()
Definition: item_subselect.h:225
virtual void reset()
Definition: item_subselect.h:191
Item * replace_item_field(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:2939
uint max_columns
allowed number of columns (1 for scalar subqueries)
Definition: item_subselect.h:146
join_type get_join_type() const
Definition: item_subselect.cc:323
bool assigned() const
Definition: item_subselect.h:193
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:114
void accumulate_condition(Item *item)
Accumulate properties from a condition or GROUP/ORDER within a query block.
Definition: item_subselect.cc:288
virtual AccessPath * root_access_path() const
Definition: item_subselect.h:126
void create_iterators(THD *thd)
Definition: item_subselect.cc:293
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:328
Item * replace_item(Item_transformer t, uchar *arg)
Definition: item_subselect.cc:2882
table_map m_subquery_used_tables
cache of used tables, used to identify tables added for IN subquery
Definition: item_subselect.h:154
const TABLE * get_table() const
Definition: item_subselect.cc:313
enum Type type() const override
Definition: item_subselect.cc:804
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:533
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:806
void set_indexsubquery_engine(subselect_indexsubquery_engine *eng)
Definition: item_subselect.h:209
void assigned(bool a)
Definition: item_subselect.h:194
const char * func_name() const override
Definition: item_subselect.h:231
bool have_to_be_excluded
work with 'substitution'
Definition: item_subselect.h:150
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:203
table_map used_tables_cache
cache of used tables
Definition: item_subselect.h:144
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_subselect.cc:823
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:605
bool changed
subquery is transformed
Definition: item_subselect.h:156
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:196
void init(Query_block *select, Query_result_subquery *result)
We need this method, because some compilers do not allow 'this' pointer in constructor initialization...
Definition: item_subselect.cc:138
const Index_lookup & index_lookup() const
Definition: item_subselect.cc:318
enum_engine_type engine_type() const
Definition: item_subselect.cc:299
virtual subs_type substype() const
Definition: item_subselect.h:188
unique_ptr_destroy_only< SubqueryWithResult > subquery
The inner part of the subquery.
Definition: item_subselect.h:137
Item_result_field super
Definition: item_subselect.h:81
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:2654
bool value_assigned
Definition: item_subselect.h:84
bool subq_opt_away_processor(uchar *arg) override
Mark the subquery as optimized away, for EXPLAIN.
Definition: item_subselect.cc:2666
uint unit_cols() const
Definition: item_subselect.cc:3144
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:703
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:853
bool null_value
True if item is null.
Definition: item.h:3495
Type
Definition: item.h:889
Bool_test
< Modifier for result transformation
Definition: item.h:937
@ BOOL_NOT_FALSE
Definition: item.h:941
@ BOOL_NOT_TRUE
Definition: item.h:940
@ BOOL_IS_TRUE
Definition: item.h:937
@ BOOL_IS_FALSE
Definition: item.h:938
@ BOOL_IDENTITY
Definition: item.h:943
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1481
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:7419
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1568
Definition: sql_optimizer.h:133
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1161
Definition: sql_list.h:434
Definition: parse_tree_nodes.h:1606
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:139
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1156
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:623
Definition: item_subselect.cc:1311
Definition: query_result.h:174
Definition: item_subselect.cc:851
Base class for result from a subquery.
Definition: query_result.h:296
Definition: sql_union.h:40
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:168
Definition: item_subselect.h:731
enum Item_result type() const
Definition: item_subselect.h:761
Item_subselect * item
Definition: item_subselect.h:775
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:782
bool may_be_null() const
Definition: item_subselect.h:763
void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3151
Query_block * single_query_block() const
Definition: item_subselect.cc:3215
enum Item_result res_type
Definition: item_subselect.h:776
enum_field_types res_field_type
Definition: item_subselect.h:777
bool exec(THD *thd)
Execute the subquery.
Definition: item_subselect.cc:3070
SubqueryWithResult(Query_expression *u, Query_result_interceptor *res, Item_subselect *si)
Definition: item_subselect.cc:2956
Query_result_interceptor * result
Definition: item_subselect.h:774
enum_field_types field_type() const
Definition: item_subselect.h:762
Query_expression * unit
Definition: item_subselect.h:784
void fix_length_and_dec(Item_cache **row)
Definition: item_subselect.cc:3050
bool prepare(THD *thd)
Prepare the query expression underlying the subquery.
Definition: item_subselect.cc:2980
const Item_subselect * get_item() const
Definition: item_subselect.h:770
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:2997
void cleanup()
Cleanup subquery after complete query execution, free all resources.
Definition: item_subselect.cc:2951
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result)
change query result object of subquery.
Definition: item_subselect.cc:3207
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: table.h:2791
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:95
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:110
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:94
Compute an IN predicate via a hash semi-join.
Definition: item_subselect.h:869
void create_iterators(THD *thd) override
Definition: item_subselect.cc:3417
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:3648
nulls_exist
Existence of inner NULLs in materialized table: By design, other values than IRRELEVANT_OR_FALSE are ...
Definition: item_subselect.h:881
@ NEX_TRUE
they matter, and we know there exists at least one.
Definition: item_subselect.h:887
@ NEX_UNKNOWN
they matter, and we don't know yet if they exists
Definition: item_subselect.h:885
@ NEX_IRRELEVANT_OR_FALSE
none, or they don't matter
Definition: item_subselect.h:883
void cleanup() override
Cleanup performed after each execution.
Definition: item_subselect.cc:3494
unique_ptr_destroy_only< RowIterator > m_iterator
Definition: item_subselect.h:891
TABLE * get_table() const
Definition: item_subselect.h:912
subselect_hash_sj_engine(Item_in_subselect *in_predicate, Query_expression *unit_arg)
Definition: item_subselect.h:898
Query_expression *const unit
Definition: item_subselect.h:890
~subselect_hash_sj_engine() override
Definition: item_subselect.cc:3483
Query_result_interceptor * saved_result
Saved result object, must be restored after use.
Definition: item_subselect.h:895
enum nulls_exist mat_table_has_nulls
Definition: item_subselect.h:889
bool is_materialized
Definition: item_subselect.h:872
bool has_zero_rows
Definition: item_subselect.h:875
const Index_lookup & index_lookup() const
Definition: item_subselect.h:913
bool exec(THD *thd) override
Execute a subquery IN predicate via materialization.
Definition: item_subselect.cc:3530
enum_engine_type engine_type() const override
Definition: item_subselect.h:910
AccessPath * root_access_path() const
Definition: item_subselect.h:915
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:3247
enum join_type get_join_type() const
Definition: item_subselect.h:914
AccessPath * m_root_access_path
Definition: item_subselect.h:892
A subquery execution engine that evaluates the subquery by doing index lookups in a single table's in...
Definition: item_subselect.h:808
Item * having
Definition: item_subselect.h:828
TABLE * table
Table which is read, using one of eq_ref, ref, ref_or_null.
Definition: item_subselect.h:812
virtual ~subselect_indexsubquery_engine()=default
virtual void cleanup()
Definition: item_subselect.h:851
virtual bool exec(THD *thd)
Definition: item_subselect.cc:3133
virtual void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3156
Item * cond
Definition: item_subselect.h:816
subselect_indexsubquery_engine(TABLE *table, Table_ref *table_ref, const Index_lookup &ref, enum join_type join_type, Item_in_subselect *subs, Item *where, Item *having_arg)
Definition: item_subselect.h:835
virtual void create_iterators(THD *)
Definition: item_subselect.h:852
join_type type
Definition: item_subselect.h:815
enum_engine_type
Definition: item_subselect.h:833
@ HASH_SJ_ENGINE
Definition: item_subselect.h:833
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:833
Index_lookup ref
Definition: item_subselect.h:814
ulonglong hash
Definition: item_subselect.h:817
virtual enum_engine_type engine_type() const
Definition: item_subselect.h:850
Item_in_subselect * item
Definition: item_subselect.h:830
Table_ref * table_ref
Definition: item_subselect.h:813
Comp_creator *(*)(bool invert) chooser_compare_func_creator
Convenience typedef for a function that returns factories for Item comparators (ie....
Definition: comp_creator.h:39
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:31
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
This file contains the field type.
enum_field_types
Column types for MySQL.
Definition: field_types.h:53
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:981
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:6695
bool(Item::* Item_analyzer)(uchar **argp)
Definition: item.h:714
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:723
Item * remove_in2exists_conds(Item *conds)
Removes every predicate injected by IN->EXISTS.
Definition: item_subselect.cc:406
bool IsItemInSubSelect(Item *item)
Returns whether the Item is an IN-subselect.
Definition: item_subselect.cc:2621
Subquery_strategy
Strategy which will be used to handle this subquery: flattening to a semi-join, conversion to a deriv...
Definition: item_subselect.h:395
@ 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:489
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
uint64_t table_map
Definition: my_table_map.h:30
Interface for low level time utilities.
unsigned int my_time_flags_t
Flags to str_to_datetime and number_to_datetime.
Definition: my_time.h:94
Time declarations shared between the server and client API: you should not add anything to this heade...
static char * where
Definition: mysqldump.cc:140
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1052
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
std::string join(Container cont, const std::string &delim)
join elements of an container into a string separated by a delimiter.
Definition: string.h:151
int add_tables(PFS_engine_table_share_proxy **, unsigned int) noexcept
Definition: pfs_plugin_table_v1_all_empty.cc:33
enum_parsing_context
Names for different query parse tree parts.
Definition: parse_tree_node_base.h:58
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:287
bool(Item::*)(unsigned char *) Item_processor
Processor type for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:305
enum_condition_context
Enumeration for Query_block::condition_context.
Definition: sql_const.h:311
Common types of the Optimizer, used by optimization and execution.
join_type
Definition: sql_opt_exec_shared.h:186
@ JT_UNKNOWN
Definition: sql_opt_exec_shared.h:188
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:193
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:488
int err_code
the error code found during check(if any)
Definition: item.h:495
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:507
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:67
This bundles several pieces of information useful when doing the IN->EXISTS transform.
Definition: item_subselect.h:585
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:590
bool dependent_before
True: if subquery was dependent (correlated) before IN->EXISTS was done.
Definition: item_subselect.h:595
bool dependent_after
True: if subquery was dependent (correlated) after IN->EXISTS was done.
Definition: item_subselect.h:600
Argument for walk method replace_scalar_subquery.
Definition: item_subselect.h:334
Query_block * m_outer_query_block
The transformed query block.
Definition: item_subselect.h:337
Field * m_field
the replacement field
Definition: item_subselect.h:336
Query_block * m_inner_query_block
The immediately surrounding query.
Definition: item_subselect.h:338
bool m_add_coalesce
Definition: item_subselect.h:341
Item_singlerow_subselect * m_target
subquery to be replaced with field
Definition: item_subselect.h:335
Scalar_subquery_replacement(Item_singlerow_subselect *target, Field *field, Query_block *select, bool add_coalesce)
Definition: item_subselect.h:342
argument used by walk method collect_scalar_subqueries ("css")
Definition: item_subselect.h:244
Collect_subq_info(Query_block *owner)
Definition: item_subselect.h:248
Query_block * m_query_block
Definition: item_subselect.h:247
std::vector< Item_subselect * > list
< accumulated all subq (or aggregates) found
Definition: item_subselect.h:246
bool contains(Query_expression *candidate)
Definition: item_subselect.h:249
Definition: mysql_time.h:82
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:121
Definition: table.h:1399
Bison "location" class.
Definition: parse_location.h:43
Definition: result.h:30
unsigned int uint
Definition: uca9-dump.cc:75
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39
@ INT_RESULT
double
Definition: udf_registration_types.h:43
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:871