MySQL 8.0.33
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, 2023, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is also distributed with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have included with MySQL.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
25
26/* 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;
72class Table_ref;
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 Index_lookup &index_lookup() 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 tables
144 /// allowed number of columns (1 for scalar subqueries)
146 /// where subquery is placed
148 /// work with 'substitution'
150
151 public:
152 /// cache of used tables, used to identify tables added for IN subquery
154 /// subquery is transformed
156
164 };
165
167 explicit Item_subselect(const POS &pos);
168
169 private:
170 /// Accumulate properties from underlying query expression
172 /// Accumulate properties from underlying query block
174 /// Accumulate properties from a selected expression within a query block.
175 void accumulate_expression(Item *item);
176 /// Accumulate properties from a condition or GROUP/ORDER within a query
177 /// block.
178 void accumulate_condition(Item *item);
179
180 public:
181 /// Accumulate used tables
183 used_tables_cache |= add_tables;
184 m_subquery_used_tables |= add_tables;
185 }
186
187 virtual subs_type substype() const { return UNKNOWN_SUBS; }
188
189 void cleanup() override;
190 virtual void reset() { null_value = true; }
191 virtual bool select_transformer(THD *thd, Query_block *select) = 0;
192 bool assigned() const { return value_assigned; }
193 void assigned(bool a) { value_assigned = a; }
194 enum Type type() const override;
195 bool is_null() override { return update_null_value() || null_value; }
196 bool fix_fields(THD *thd, Item **ref) override;
197 void fix_after_pullout(Query_block *parent_query_block,
198 Query_block *removed_query_block) override;
199 virtual bool exec(THD *thd);
200 bool resolve_type(THD *) override;
201 table_map used_tables() const override { return used_tables_cache; }
202 table_map not_null_tables() const override { return 0; }
203 Item *get_tmp_table_item(THD *thd) override;
204 void update_used_tables() override;
205 void print(const THD *thd, String *str,
206 enum_query_type query_type) const override;
207
210 }
211
212 /*
213 True if this subquery has been already evaluated. Implemented only for
214 single select and union subqueries only.
215 */
216 bool is_evaluated() const;
217 bool is_uncacheable() const;
218
219 /*
220 Used by max/min subquery to initialize value presence registration
221 mechanism. Engine call this method before rexecution query.
222 */
223 virtual void reset_value_registration() {}
225 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
226 bool explain_subquery_checker(uchar **arg) override;
227 bool inform_item_in_cond_of_tab(uchar *arg) override;
228 bool clean_up_after_removal(uchar *arg) override;
229
230 const char *func_name() const override {
231 assert(0);
232 return "subselect";
233 }
234
237 pointer_cast<Check_function_as_value_generator_parameters *>(args);
238 func_arg->err_code = func_arg->get_unnamed_function_error_code();
239 return true;
240 }
241
242 /// argument used by walk method collect_scalar_subqueries ("css")
244 ///< accumulated all subq (or aggregates) found
245 std::vector<Item_subselect *> list;
248 bool contains(Query_expression *candidate) {
249 for (auto sq : list) {
250 if (sq->unit == candidate) return true;
251 }
252 return false;
253 }
254 };
255
256 bool collect_subqueries(uchar *) override;
257 Item *replace_item_field(uchar *arg) override;
258 Item *replace_item_view_ref(uchar *arg) override;
260
262 friend class Item_in_optimizer;
263 friend bool Item_field::fix_fields(THD *, Item **);
265 friend bool Item_ref::fix_fields(THD *, Item **);
266 friend void Item_ident::fix_after_pullout(Query_block *parent_query_block,
267 Query_block *removed_query_block);
268
269 private:
270 bool subq_opt_away_processor(uchar *arg) override;
271
272 protected:
273 uint unit_cols() const;
274};
275
276/* single value subselect */
277
279 protected:
281 bool no_rows; ///< @c no_rows_in_result
282 public:
285 : Item_subselect(), value(nullptr), row(nullptr), no_rows(false) {}
286
287 void cleanup() override;
288 subs_type substype() const override { return SINGLEROW_SUBS; }
289
290 void reset() override;
291 bool select_transformer(THD *thd, Query_block *select) override;
292 void store(uint i, Item *item);
293 double val_real() override;
294 longlong val_int() override;
295 String *val_str(String *) override;
296 my_decimal *val_decimal(my_decimal *) override;
297 bool val_json(Json_wrapper *result) override;
298 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
299 bool get_time(MYSQL_TIME *ltime) override;
300 bool val_bool() override;
301 enum Item_result result_type() const override;
302 bool resolve_type(THD *) override;
303
304 /*
305 Mark the subquery as having no rows.
306 If there are aggregate functions (in the outer query),
307 we need to generate a NULL row. @c return_zero_rows().
308 */
309 void no_rows_in_result() override;
310
311 uint cols() const override { return unit_cols(); }
312
313 /**
314 @note that this returns the i-th element of the SELECT list.
315 To check for nullability, look at this->maybe_null and not
316 element_index[i]->maybe_null, since the selected expressions are
317 always NULL if the subquery is empty.
318 */
319 Item *element_index(uint i) override {
320 return reinterpret_cast<Item *>(row[i]);
321 }
322 Item **addr(uint i) override { return (Item **)row + i; }
323 bool check_cols(uint c) override;
324 bool null_inside() override;
325 void bring_value() override;
326
327 bool collect_scalar_subqueries(uchar *) override;
328 virtual bool is_maxmin() const { return false; }
329
330 /**
331 Argument for walk method replace_scalar_subquery
332 */
334 Item_singlerow_subselect *m_target; ///< subquery to be replaced with field
335 Field *m_field; ///< the replacement field
336 Query_block *m_outer_query_block; ///< The transformed query block.
337 Query_block *m_inner_query_block; ///< The immediately surrounding query
338 ///< block. This will be the transformed
339 ///< block or a subquery of it
340 bool m_add_coalesce{false};
342 Query_block *select, bool add_coalesce)
343 : m_target(target),
344 m_field(field),
345 m_outer_query_block(select),
346 m_inner_query_block(select),
347 m_add_coalesce(add_coalesce) {}
348 };
349
350 Item *replace_scalar_subquery(uchar *arge) override;
351 /**
352 This method is used to implement a special case of semantic tree
353 rewriting, mandated by a SQL:2003 exception in the specification.
354 The only caller of this method is handle_sql2003_note184_exception(),
355 see the code there for more details.
356 Note that this method breaks the object internal integrity, by
357 removing it's association with the corresponding Query_block,
358 making this object orphan from the parse tree.
359 No other method, beside the destructor, should be called on this
360 object, as it is now invalid.
361 @return the Query_block structure that was given in the constructor.
362 */
364 std::optional<ContainedSubquery> get_contained_subquery(
365 const Query_block *outer_query_block) override;
367};
368
369/* used in static ALL/ANY optimization */
371 protected:
372 bool max;
373 bool was_values; // Set if we have found at least one row
374 public:
376 bool max, bool ignore_nulls);
377 void print(const THD *thd, String *str,
378 enum_query_type query_type) const override;
379 void cleanup() override;
380 bool any_value() { return was_values; }
381 void register_value() { was_values = true; }
382 void reset_value_registration() override { was_values = false; }
383 bool is_maxmin() const override { return true; }
384};
385
386/* exists subselect */
387
388/**
389 Strategy which will be used to handle this subquery: flattening to a
390 semi-join, conversion to a derived table, rewrite of IN to EXISTS...
391 Sometimes the strategy is first only a candidate, then the real decision
392 happens in a second phase. Other times the first decision is final.
393 */
394enum class Subquery_strategy : int {
395 /// Nothing decided yet
397 /// Candidate for rewriting IN(subquery) to EXISTS, or subquery
398 /// materialization
400 /// Candidate for semi-join flattening
402 /// Candidate for rewriting to joined derived table
404 /// Semi-join flattening
405 SEMIJOIN,
406 /// Rewrite to joined derived table
408 /// Evaluate as EXISTS subquery (possibly after rewriting from another type)
410 /// Subquery materialization (HASH_SJ_ENGINE)
412 /// Subquery has been deleted, probably because it was always false
413 DELETED,
414};
415
418
419 protected:
420 /// value of this item (boolean: exists/not-exists)
421 bool value{false};
422
423 public:
424 /// Priority of this predicate in the convert-to-semi-join-nest process.
426 /// Execution strategy chosen for this Item
428 /// Used by the transformation to derived table
430
431 /**
432 Used by subquery optimizations to keep track about where this subquery
433 predicate is located, and whether it is a candidate for transformation.
434 (Table_ref*) 1 - the predicate is an AND-part of the WHERE
435 join nest pointer - the predicate is an AND-part of ON expression
436 of a join nest
437 NULL - for all other locations. It also means that the
438 predicate is not a candidate for transformation.
439 See also THD::emb_on_expr_nest.
440
441 As for the second case above (the join nest pointer), note that this value
442 may change if scalar subqueries are transformed to derived tables,
443 cf. transform_scalar_subqueries_to_join_with_derived, due to the need to
444 build new join nests. The change is performed in Query_block::nest_derived.
445 */
447
449
451
452 explicit Item_exists_subselect(const POS &pos) : super(pos) {}
453
455
456 bool select_transformer(THD *, Query_block *) override {
458 return false;
459 }
460 subs_type substype() const override { return EXISTS_SUBS; }
461 bool is_bool_func() const override { return true; }
462 void reset() override { value = false; }
463
464 enum Item_result result_type() const override { return INT_RESULT; }
465 /*
466 The item is
467 ([NOT] IN/EXISTS) [ IS [NOT] TRUE|FALSE ]
468 */
470 bool with_is_op() const {
471 switch (value_transform) {
472 case BOOL_IS_TRUE:
473 case BOOL_IS_FALSE:
474 case BOOL_NOT_TRUE:
475 case BOOL_NOT_FALSE:
476 return true;
477 default:
478 return false;
479 }
480 }
481 /// True if the IS TRUE/FALSE wasn't explicit in the query
482 bool implicit_is_op = false;
483 Item *truth_transformer(THD *, enum Bool_test test) override;
484 bool translate(bool &null_v, bool v);
485 void apply_is_true() override {
486 bool had_is = with_is_op();
488 if (!had_is && value_transform == BOOL_IS_TRUE)
489 implicit_is_op = true; // needn't be written by EXPLAIN
490 }
491 /// True if the Item has decided that it can do antijoin
492 bool can_do_aj = false;
494 longlong val_int() override;
495 double val_real() override;
496 String *val_str(String *) override;
497 my_decimal *val_decimal(my_decimal *) override;
498 bool val_bool() override;
499 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
500 return get_date_from_int(ltime, fuzzydate);
501 }
502 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
503 bool resolve_type(THD *thd) override;
504 void print(const THD *thd, String *str,
505 enum_query_type query_type) const override;
506
508};
509
510/**
511 Representation of IN subquery predicates of the form
512 "left_expr IN (SELECT ...)".
513
514 @details
515 This class has:
516 - A "subquery execution engine" (as a subclass of Item_subselect) that allows
517 it to evaluate subqueries. (and this class participates in execution by
518 having was_null variable where part of execution result is stored.
519 - Transformation methods (todo: more on this).
520
521 This class is not used directly, it is "wrapped" into Item_in_optimizer
522 which provides some small bits of subquery evaluation.
523*/
524
527
528 public:
530
531 protected:
532 /**
533 Cache of the left operand of the subquery predicate. Allocated in the
534 runtime memory root, for each execution, thus need not be freed.
535 */
537 bool left_expr_cache_filled; ///< Whether left_expr_cache holds a value
538 /** The need for expr cache may be optimized away, @sa init_left_expr_cache.
539 */
541
542 private:
543 /**
544 In the case of
545
546 x COMP_OP (SELECT1 UNION SELECT2 ...)
547
548 - the subquery transformation is done on SELECT1; this requires wrapping
549 'x' with more Item layers, and injecting that in a condition in SELECT1.
550
551 - the same transformation is done on SELECT2; but the wrapped 'x' doesn't
552 need to be created again, the one created for SELECT1 could be reused
553
554 - to achieve this, the wrapped 'x' is stored in member
555 'm_injected_left_expr' when it is created for SELECT1, and is later
556 reused for SELECT2.
557
558 This will refer to a cached value which is reevaluated once for each
559 candidate row, cf. setup in #single_value_transformer.
560 */
562
563 /**
564 Pointer to the created Item_in_optimizer; it is stored for the same
565 reasons as 'm_injected_left_expr'.
566 */
569
570 protected:
571 /**
572 True if naked IN is allowed to exchange FALSE for UNKNOWN.
573 Because this is about the naked IN, there is no public ignore_unknown(),
574 intentionally, so that callers don't get it wrong.
575 */
577
578 private:
579 /**
580 This bundles several pieces of information useful when doing the
581 IN->EXISTS transform. If this transform has not been done, pointer is
582 NULL.
583 */
585 /**
586 True: if IN->EXISTS has been done and has added a condition to the
587 subquery's WHERE clause.
588 */
590 /**
591 True: if subquery was dependent (correlated) before IN->EXISTS
592 was done.
593 */
595 /**
596 True: if subquery was dependent (correlated) after IN->EXISTS
597 was done.
598 */
601
602 bool mark_as_outer(Item *left_row, size_t col);
603
604 public:
605 /* Used to trigger on/off conditions that were pushed down to subselect */
607
608 Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
609
610 private:
612
613 public:
616 }
617
618 /// Is reliable only if IN->EXISTS has been done.
621 }
622
623 bool *get_cond_guard(int i) {
624 return pushed_cond_guards ? pushed_cond_guards + i : nullptr;
625 }
626 void set_cond_guard_var(int i, bool v) {
628 }
629
631 Item_in_subselect(const POS &pos, Item *left_expr,
632 PT_subquery *pt_subquery_arg);
633
639 need_expr_cache(true),
642 was_null(false),
643 abort_on_null(false),
647
648 bool itemize(Parse_context *pc, Item **res) override;
649
650 void cleanup() override;
651 subs_type substype() const override { return IN_SUBS; }
652
653 void reset() override {
654 value = false;
655 null_value = false;
656 was_null = false;
657 }
658 bool select_transformer(THD *thd, Query_block *select) override;
659 bool select_in_like_transformer(THD *thd, Query_block *select,
660 Comp_creator *func);
661 bool single_value_transformer(THD *thd, Query_block *select,
662 Comp_creator *func);
663 bool row_value_transformer(THD *thd, Query_block *select);
665 Comp_creator *func);
667 bool subquery_allows_materialization(THD *thd, Query_block *query_block,
668 const Query_block *outer);
669 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
670 Item *transform(Item_transformer transformer, uchar *arg) override;
671 Item *compile(Item_analyzer analyzer, uchar **arg_p,
672 Item_transformer transformer, uchar *arg_t) override;
673
674 bool exec(THD *thd) override;
675 longlong val_int() override;
676 double val_real() override;
677 String *val_str(String *) override;
678 my_decimal *val_decimal(my_decimal *) override;
679 bool val_bool() override;
680 bool test_limit();
681 void print(const THD *thd, String *str,
682 enum_query_type query_type) const override;
683 bool fix_fields(THD *thd, Item **ref) override;
684 void fix_after_pullout(Query_block *parent_query_block,
685 Query_block *removed_query_block) override;
686 void update_used_tables() override;
687 bool init_left_expr_cache(THD *thd);
688
689 /**
690 Once the decision to use IN->EXISTS has been taken, performs some last
691 steps of this transformation.
692 */
693 bool finalize_exists_transform(THD *thd, Query_block *select);
694 /**
695 Once the decision to use materialization has been taken, performs some
696 last steps of this transformation.
697 */
699 AccessPath *root_access_path() const override;
700 std::optional<ContainedSubquery> get_contained_subquery(
701 const Query_block *outer_query_block) override;
702
705 friend class Item_in_optimizer;
708
709 private:
710 bool val_bool_naked();
711};
712
713/// ALL/ANY/SOME subselect.
715 public:
718 bool all;
719
721 Query_block *select, bool all);
722
723 // only ALL subquery has upper not
724 subs_type substype() const override { return all ? ALL_SUBS : ANY_SUBS; }
725 bool select_transformer(THD *thd, Query_block *select) override;
726 void print(const THD *thd, String *str,
727 enum_query_type query_type) const override;
728};
729
731 public:
733 Item_subselect *si);
734 /**
735 Cleanup subquery after complete query execution, free all resources.
736 */
737 void cleanup();
738 bool prepare(THD *thd);
739 void fix_length_and_dec(Item_cache **row);
740 /**
741 Execute the subquery
742
743 SYNOPSIS
744 exec()
745
746 DESCRIPTION
747 Execute the subquery. The result of execution is subquery value that is
748 captured by previously set up Query_result-based 'sink'.
749
750 RETURN
751 false - OK
752 true - Execution error.
753 */
754 bool exec(THD *thd);
755 void print(const THD *thd, String *str, enum_query_type query_type);
758 Query_block *single_query_block() const; // Only if unit is simple.
759
760 enum Item_result type() const { return res_type; }
762 bool may_be_null() const { return maybe_null; }
763
764#ifndef NDEBUG
765 /**
766 @returns the internal Item. Defined only in debug builds, because should
767 be used only for debug asserts.
768 */
769 const Item_subselect *get_item() const { return item; }
770#endif
771
772 private:
773 Query_result_interceptor *result; /* results storage class */
774 Item_subselect *item; /* item, that use this subquery */
775 enum Item_result res_type; /* type of results */
776 enum_field_types res_field_type; /* column type of the results */
777 /**
778 True if at least one of the columns returned by the subquery may
779 be null, or if a single-row subquery may return zero rows.
780 */
782
783 Query_expression *unit; /* corresponding unit structure */
784
785 void set_row(const mem_root_deque<Item *> &item_list, Item_cache **row,
786 bool never_empty);
787
789};
790
791/**
792 A subquery execution engine that evaluates the subquery by doing index
793 lookups in a single table's index.
794
795 This engine is used to resolve subqueries in forms
796
797 outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)
798
799 or, row-based:
800
801 (oe1, .. oeN) IN (SELECT key_part1, ... key_partK
802 FROM tbl WHERE subqwhere)
803
804 i.e. the subquery is a single table SELECT without GROUP BY, aggregate
805 functions, etc.
806*/
808 protected:
809 Query_result_union *result = nullptr; /* results storage class */
810 /// Table which is read, using one of eq_ref, ref, ref_or_null.
811 TABLE *table{nullptr};
815 Item *cond; /* The WHERE condition of subselect */
816 ulonglong hash; /* Hash value calculated by RefIterator, when needed. */
817 /*
818 The "having" clause. This clause (further referred to as "artificial
819 having") was inserted by subquery transformation code. It contains
820 Item(s) that have a side-effect: they record whether the subquery has
821 produced a row with NULL certain components. We need to use it for cases
822 like
823 (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
824 where we do index lookup on t.key=oe1 but need also to check if there
825 was a row such that t.no_key IS NULL.
826 */
828
829 Item_in_subselect *item; /* item that uses this engine */
830
831 public:
833
835 const Index_lookup &ref,
836 enum join_type join_type,
838 Item *having_arg)
839 : table(table),
841 ref(ref),
843 cond(where),
844 having(having_arg),
845 item(subs) {}
847 virtual bool exec(THD *thd);
848 virtual void print(const THD *thd, String *str, enum_query_type query_type);
850 virtual void cleanup() {}
851 virtual void create_iterators(THD *) {}
852};
853
854/*
855 This function is actually defined in sql_parse.cc, but it depends on
856 chooser_compare_func_creator defined in this file.
857 */
860 Query_block *select);
861
862/**
863 Compute an IN predicate via a hash semi-join. The subquery is materialized
864 during the first evaluation of the IN predicate. The IN predicate is executed
865 via the functionality inherited from subselect_indexsubquery_engine.
866*/
867
869 private:
870 /* true if the subquery was materialized into a temp table. */
872 // true if we know for sure that there are zero rows in the table.
873 // Set only after is_materialized is true.
874 bool has_zero_rows = false;
875 /**
876 Existence of inner NULLs in materialized table:
877 By design, other values than IRRELEVANT_OR_FALSE are possible only if the
878 subquery has only one inner expression.
879 */
881 /// none, or they don't matter
883 /// they matter, and we don't know yet if they exists
885 /// they matter, and we know there exists at least one.
886 NEX_TRUE = 2
887 };
892
893 /// Saved result object, must be restored after use
895
896 public:
898 Query_expression *unit_arg)
900 in_predicate, nullptr, nullptr),
901 is_materialized(false),
902 unit(unit_arg) {}
903 ~subselect_hash_sj_engine() override;
904
905 bool setup(THD *thd, const mem_root_deque<Item *> &tmp_columns);
906 void cleanup() override;
907 bool exec(THD *thd) override;
908 void print(const THD *thd, String *str, enum_query_type query_type) override;
909 enum_engine_type engine_type() const override { return HASH_SJ_ENGINE; }
910
911 TABLE *get_table() const { return table; }
912 const Index_lookup &index_lookup() const { return ref; }
913 enum join_type get_join_type() const { return type; }
915 void create_iterators(THD *thd) override;
916};
917
918/**
919 Removes every predicate injected by IN->EXISTS.
920
921 This function is different from others:
922 - it wants to remove all traces of IN->EXISTS (for
923 materialization)
924 - remove_subq_pushed_predicates() and remove_additional_cond() want to
925 remove only the conditions of IN->EXISTS which index lookup already
926 satisfies (they are just an optimization).
927
928 If there are no in2exists conditions, it will return the exact same
929 pointer. If it returns a new Item, the old Item is left alone, so it
930 can be reused in other settings.
931
932 @param conds Condition; may be nullptr.
933 @returns new condition
934 */
936
937/// Returns whether the Item is an IN-subselect.
938bool IsItemInSubSelect(Item *item);
939
940#endif /* ITEM_SUBSELECT_INCLUDED */
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:522
Definition: field.h:574
ALL/ANY/SOME subselect.
Definition: item_subselect.h:714
Item_allany_subselect(Item *left_expr, chooser_compare_func_creator fc, Query_block *select, bool all)
Definition: item_subselect.cc:1487
Comp_creator * func
Definition: item_subselect.h:717
bool select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:2712
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2720
chooser_compare_func_creator func_creator
Definition: item_subselect.h:716
bool all
Definition: item_subselect.h:718
subs_type substype() const override
Definition: item_subselect.h:724
Definition: item.h:6611
Definition: item_subselect.h:416
enum_condition_context outer_condition_context
Used by the transformation to derived table.
Definition: item_subselect.h:429
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:485
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1501
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.h:499
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1580
Item_exists_subselect()
Definition: item_subselect.h:450
double val_real() override
Definition: item_subselect.cc:1566
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.h:502
bool implicit_is_op
True if the IS TRUE/FALSE wasn't explicit in the query.
Definition: item_subselect.h:482
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:1397
longlong val_int() override
Definition: item_subselect.cc:1568
Subquery_strategy strategy
Execution strategy chosen for this Item.
Definition: item_subselect.h:427
bool val_bool() override
Definition: item_subselect.cc:1604
int sj_convert_priority
Priority of this predicate in the convert-to-semi-join-nest process.
Definition: item_subselect.h:425
void reset() override
Definition: item_subselect.h:462
bool value
value of this item (boolean: exists/not-exists)
Definition: item_subselect.h:421
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1339
bool can_do_aj
True if the Item has decided that it can do antijoin.
Definition: item_subselect.h:492
bool with_is_op() const
Definition: item_subselect.h:470
enum Bool_test value_transform
Definition: item_subselect.h:469
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:454
subs_type substype() const override
Definition: item_subselect.h:460
Item_subselect super
Definition: item_subselect.h:417
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:1360
bool is_bool_func() const override
Definition: item_subselect.h:461
Table_ref * embedding_join_nest
Used by subquery optimizations to keep track about where this subquery predicate is located,...
Definition: item_subselect.h:446
bool choose_semijoin_or_antijoin()
Helper for resolve_subquery().
Definition: item_subselect.cc:1529
Item_exists_subselect(const POS &pos)
Definition: item_subselect.h:452
bool select_transformer(THD *, Query_block *) override
Definition: item_subselect.h:456
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1597
enum Item_result result_type() const override
Definition: item_subselect.h:464
int fix_outer_field(THD *thd, Field **field, Item **reference)
Resolve the name of an outer select column reference.
Definition: item.cc:5239
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:5680
Definition: item_cmpfunc.h:909
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:3148
Definition: item_cmpfunc.h:489
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:525
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:2509
Item * left_expr
Definition: item_subselect.h:529
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:2530
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1658
bool row_value_transformer(THD *thd, Query_block *select)
Definition: item_subselect.cc:2122
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:567
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:733
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:2186
double val_real() override
Definition: item_subselect.cc:1615
bool select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:2380
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:2585
bool need_expr_cache
The need for expr cache may be optimized away,.
Definition: item_subselect.h:540
void set_cond_guard_var(int i, bool v)
Definition: item_subselect.h:626
Item_func_not_all * upper_item
Definition: item_subselect.h:608
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:421
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_subselect.cc:1476
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2467
bool abort_on_null
True if naked IN is allowed to exchange FALSE for UNKNOWN.
Definition: item_subselect.h:576
void reset() override
Definition: item_subselect.h:653
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:375
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:726
bool dependent_before_in2exists() const
Is reliable only if IN->EXISTS has been done.
Definition: item_subselect.h:619
bool * pushed_cond_guards
Definition: item_subselect.h:606
AccessPath * root_access_path() const override
Definition: item_subselect.cc:511
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:2400
PT_subquery * pt_subselect
Definition: item_subselect.h:611
longlong val_int() override
Definition: item_subselect.cc:1622
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:382
bool val_bool() override
Definition: item_subselect.cc:1636
bool single_value_transformer(THD *thd, Query_block *select, Comp_creator *func)
Rewrite a single-column IN/ALL/ANY subselect.
Definition: item_subselect.cc:1694
List< Cached_item > * left_expr_cache
Cache of the left operand of the subquery predicate.
Definition: item_subselect.h:536
bool was_null
Definition: item_subselect.h:568
bool init_left_expr_cache(THD *thd)
Initialize the cache of the left operand of the IN predicate.
Definition: item_subselect.cc:2554
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:479
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1629
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_subselect.cc:2537
bool in2exists_added_to_where() const
Definition: item_subselect.h:614
bool * get_cond_guard(int i)
Definition: item_subselect.h:623
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:720
subs_type substype() const override
Definition: item_subselect.h:651
Item_exists_subselect super
Definition: item_subselect.h:526
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:1903
bool test_limit()
Definition: item_subselect.cc:1427
Item_in_subselect()
Definition: item_subselect.h:634
bool val_bool_naked()
Definition: item_subselect.cc:1643
Item_ref * m_injected_left_expr
In the case of.
Definition: item_subselect.h:561
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:537
Definition: item_cmpfunc.h:2287
Definition: item_subselect.h:370
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1091
bool max
Definition: item_subselect.h:372
Item_maxmin_subselect(Item_subselect *parent, Query_block *query_block, bool max, bool ignore_nulls)
Definition: item_subselect.cc:1065
bool any_value()
Definition: item_subselect.h:380
bool is_maxmin() const override
Definition: item_subselect.h:383
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:1084
void reset_value_registration() override
Definition: item_subselect.h:382
void register_value()
Definition: item_subselect.h:381
bool was_values
Definition: item_subselect.h:373
Definition: item.h:6099
Definition: item.h:5667
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:8004
Item with result field.
Definition: item.h:5590
Definition: item_subselect.h:278
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:2808
enum Item_result result_type() const override
Definition: item_subselect.cc:1165
void store(uint i, Item *item)
Definition: item_subselect.cc:1160
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:341
bool null_inside() override
Definition: item_subselect.cc:1209
Item ** addr(uint i) override
Definition: item_subselect.h:322
double val_real() override
Definition: item_subselect.cc:1223
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1169
void no_rows_in_result() override
Definition: item_subselect.cc:1192
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_subselect.cc:1266
void reset() override
Definition: item_subselect.cc:1097
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.cc:1276
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:2847
longlong val_int() override
Definition: item_subselect.cc:1234
uint cols() const override
Definition: item_subselect.h:311
virtual bool is_maxmin() const
Definition: item_subselect.h:328
Item * element_index(uint i) override
Definition: item_subselect.h:319
Item_cache ** row
Definition: item_subselect.h:280
Item_singlerow_subselect()
Definition: item_subselect.h:284
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:881
bool collect_scalar_subqueries(uchar *) override
Definition: item_subselect.cc:2734
bool select_transformer(THD *thd, Query_block *select) override
Definition: item_subselect.cc:1112
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.cc:1287
String * val_str(String *) override
Definition: item_subselect.cc:1245
bool val_bool() override
Definition: item_subselect.cc:1297
bool no_rows
no_rows_in_result
Definition: item_subselect.h:281
subs_type substype() const override
Definition: item_subselect.h:288
void bring_value() override
Definition: item_subselect.cc:1216
bool check_cols(uint c) override
Definition: item_subselect.cc:1201
Item_cache * value
Definition: item_subselect.h:280
my_decimal * val_decimal(my_decimal *) override
Definition: item_subselect.cc:1255
Definition: item_subselect.h:79
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:140
enum_parsing_context parsing_place
where subquery is placed
Definition: item_subselect.h:147
Item * replace_item_view_ref(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:2936
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the subquery from the item tree.
Definition: item_subselect.cc:2678
bool is_evaluated() const
Definition: item_subselect.cc:2718
bool collect_subqueries(uchar *) override
Definition: item_subselect.cc:2705
table_map used_tables() const override
Definition: item_subselect.h:201
subs_type
Definition: item_subselect.h:157
@ UNKNOWN_SUBS
Definition: item_subselect.h:158
@ EXISTS_SUBS
Definition: item_subselect.h:160
@ SINGLEROW_SUBS
Definition: item_subselect.h:159
@ ALL_SUBS
Definition: item_subselect.h:162
@ ANY_SUBS
Definition: item_subselect.h:163
@ IN_SUBS
Definition: item_subselect.h:161
void accumulate_expression(Item *item)
Accumulate properties from a selected expression within a query block.
Definition: item_subselect.cc:276
void accumulate_used_tables(table_map add_tables)
Accumulate used tables.
Definition: item_subselect.h:182
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:235
bool is_uncacheable() const
Definition: item_subselect.cc:3138
void accumulate_properties()
Accumulate properties from underlying query expression.
Definition: item_subselect.cc:212
virtual bool exec(THD *thd)
Definition: item_subselect.cc:630
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:829
Query_expression * unit
Definition: item_subselect.h:108
virtual void reset_value_registration()
Definition: item_subselect.h:223
bool explain_subquery_checker(uchar **arg) override
Register subquery to the table where it is used within a condition.
Definition: item_subselect.cc:623
bool traced_before
Whether or not execution of this subselect has been traced by optimizer tracing already.
Definition: item_subselect.h:90
virtual bool select_transformer(THD *thd, Query_block *select)=0
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:224
virtual void reset()
Definition: item_subselect.h:190
Item * replace_item_field(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:2928
uint max_columns
allowed number of columns (1 for scalar subqueries)
Definition: item_subselect.h:145
join_type get_join_type() const
Definition: item_subselect.cc:322
bool assigned() const
Definition: item_subselect.h:192
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:287
virtual AccessPath * root_access_path() const
Definition: item_subselect.h:125
void create_iterators(THD *thd)
Definition: item_subselect.cc:292
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:327
Item * replace_item(Item_transformer t, uchar *arg)
Definition: item_subselect.cc:2871
table_map m_subquery_used_tables
cache of used tables, used to identify tables added for IN subquery
Definition: item_subselect.h:153
const TABLE * get_table() const
Definition: item_subselect.cc:312
enum Type type() const override
Definition: item_subselect.cc:801
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:532
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:208
void assigned(bool a)
Definition: item_subselect.h:193
const char * func_name() const override
Definition: item_subselect.h:230
bool have_to_be_excluded
work with 'substitution'
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:202
table_map used_tables_cache
cache of used tables
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:602
bool changed
subquery is transformed
Definition: item_subselect.h:155
Item_subselect()
Definition: item_subselect.cc:101
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_subselect.h:195
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:137
const Index_lookup & index_lookup() const
Definition: item_subselect.cc:317
enum_engine_type engine_type() const
Definition: item_subselect.cc:298
virtual subs_type substype() const
Definition: item_subselect.h:187
unique_ptr_destroy_only< SubqueryWithResult > subquery
The inner part of the 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:2650
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:2662
uint unit_cols() const
Definition: item_subselect.cc:3133
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:700
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:850
bool null_value
True if item is null.
Definition: item.h:3449
Type
Definition: item.h:886
Bool_test
< Modifier for result transformation
Definition: item.h:934
@ BOOL_NOT_FALSE
Definition: item.h:938
@ BOOL_NOT_TRUE
Definition: item.h:937
@ BOOL_IS_TRUE
Definition: item.h:934
@ BOOL_IS_FALSE
Definition: item.h:935
@ BOOL_IDENTITY
Definition: item.h:940
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1478
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:7357
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1565
Definition: sql_optimizer.h:132
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1160
Definition: sql_list.h:433
Definition: parse_tree_nodes.h:1605
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:138
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1155
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:622
Definition: item_subselect.cc:1308
Definition: query_result.h:173
Definition: item_subselect.cc:848
Base class for result from a subquery.
Definition: query_result.h:295
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:730
enum Item_result type() const
Definition: item_subselect.h:760
Item_subselect * item
Definition: item_subselect.h:774
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:781
bool may_be_null() const
Definition: item_subselect.h:762
void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3140
Query_block * single_query_block() const
Definition: item_subselect.cc:3204
enum Item_result res_type
Definition: item_subselect.h:775
enum_field_types res_field_type
Definition: item_subselect.h:776
bool exec(THD *thd)
Execute the subquery.
Definition: item_subselect.cc:3059
SubqueryWithResult(Query_expression *u, Query_result_interceptor *res, Item_subselect *si)
Definition: item_subselect.cc:2945
Query_result_interceptor * result
Definition: item_subselect.h:773
enum_field_types field_type() const
Definition: item_subselect.h:761
Query_expression * unit
Definition: item_subselect.h:783
void fix_length_and_dec(Item_cache **row)
Definition: item_subselect.cc:3039
bool prepare(THD *thd)
Prepare the query expression underlying the subquery.
Definition: item_subselect.cc:2969
const Item_subselect * get_item() const
Definition: item_subselect.h:769
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:2986
void cleanup()
Cleanup subquery after complete query execution, free all resources.
Definition: item_subselect.cc:2940
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result)
change query result object of subquery.
Definition: item_subselect.cc:3196
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:33
Definition: table.h:2761
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:94
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:868
void create_iterators(THD *thd) override
Definition: item_subselect.cc:3406
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:3637
nulls_exist
Existence of inner NULLs in materialized table: By design, other values than IRRELEVANT_OR_FALSE are ...
Definition: item_subselect.h:880
@ NEX_TRUE
they matter, and we know there exists at least one.
Definition: item_subselect.h:886
@ NEX_UNKNOWN
they matter, and we don't know yet if they exists
Definition: item_subselect.h:884
@ NEX_IRRELEVANT_OR_FALSE
none, or they don't matter
Definition: item_subselect.h:882
void cleanup() override
Cleanup performed after each execution.
Definition: item_subselect.cc:3483
unique_ptr_destroy_only< RowIterator > m_iterator
Definition: item_subselect.h:890
TABLE * get_table() const
Definition: item_subselect.h:911
subselect_hash_sj_engine(Item_in_subselect *in_predicate, Query_expression *unit_arg)
Definition: item_subselect.h:897
Query_expression *const unit
Definition: item_subselect.h:889
~subselect_hash_sj_engine() override
Definition: item_subselect.cc:3472
Query_result_interceptor * saved_result
Saved result object, must be restored after use.
Definition: item_subselect.h:894
enum nulls_exist mat_table_has_nulls
Definition: item_subselect.h:888
bool is_materialized
Definition: item_subselect.h:871
bool has_zero_rows
Definition: item_subselect.h:874
const Index_lookup & index_lookup() const
Definition: item_subselect.h:912
bool exec(THD *thd) override
Execute a subquery IN predicate via materialization.
Definition: item_subselect.cc:3519
enum_engine_type engine_type() const override
Definition: item_subselect.h:909
AccessPath * root_access_path() const
Definition: item_subselect.h:914
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:3236
enum join_type get_join_type() const
Definition: item_subselect.h:913
AccessPath * m_root_access_path
Definition: item_subselect.h:891
A subquery execution engine that evaluates the subquery by doing index lookups in a single table's in...
Definition: item_subselect.h:807
Item * having
Definition: item_subselect.h:827
TABLE * table
Table which is read, using one of eq_ref, ref, ref_or_null.
Definition: item_subselect.h:811
virtual ~subselect_indexsubquery_engine()=default
virtual void cleanup()
Definition: item_subselect.h:850
virtual bool exec(THD *thd)
Definition: item_subselect.cc:3122
virtual void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3145
Item * cond
Definition: item_subselect.h:815
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:834
virtual void create_iterators(THD *)
Definition: item_subselect.h:851
join_type type
Definition: item_subselect.h:814
enum_engine_type
Definition: item_subselect.h:832
@ HASH_SJ_ENGINE
Definition: item_subselect.h:832
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:832
Index_lookup ref
Definition: item_subselect.h:813
ulonglong hash
Definition: item_subselect.h:816
virtual enum_engine_type engine_type() const
Definition: item_subselect.h:849
Item_in_subselect * item
Definition: item_subselect.h:829
Table_ref * table_ref
Definition: item_subselect.h:812
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
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:52
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:983
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:6687
bool(Item::* Item_analyzer)(uchar **argp)
Definition: item.h:711
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:720
Item * remove_in2exists_conds(Item *conds)
Removes every predicate injected by IN->EXISTS.
Definition: item_subselect.cc:405
bool IsItemInSubSelect(Item *item)
Returns whether the Item is an IN-subselect.
Definition: item_subselect.cc:2617
Subquery_strategy
Strategy which will be used to handle this subquery: flattening to a semi-join, conversion to a deriv...
Definition: item_subselect.h:394
@ 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
Flags to str_to_datetime and number_to_datetime.
Definition: my_time.h:93
Time declarations shared between the server and client API: you should not add anything to this heade...
static char * where
Definition: mysqldump.cc:136
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1054
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:57
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:286
bool(Item::*)(unsigned char *) Item_processor
Processor type for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:304
enum_condition_context
Enumeration for Query_block::condition_context.
Definition: sql_const.h:310
Common types of the Optimizer, used by optimization and execution.
join_type
Definition: sql_opt_exec_shared.h:185
@ JT_UNKNOWN
Definition: sql_opt_exec_shared.h:187
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:192
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:486
int err_code
the error code found during check(if any)
Definition: item.h:493
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:505
Structure used for index-based lookups.
Definition: sql_opt_exec_shared.h:66
This bundles several pieces of information useful when doing the IN->EXISTS transform.
Definition: item_subselect.h:584
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:589
bool dependent_before
True: if subquery was dependent (correlated) before IN->EXISTS was done.
Definition: item_subselect.h:594
bool dependent_after
True: if subquery was dependent (correlated) after IN->EXISTS was done.
Definition: item_subselect.h:599
Argument for walk method replace_scalar_subquery.
Definition: item_subselect.h:333
Query_block * m_outer_query_block
The transformed query block.
Definition: item_subselect.h:336
Field * m_field
the replacement field
Definition: item_subselect.h:335
Query_block * m_inner_query_block
The immediately surrounding query.
Definition: item_subselect.h:337
bool m_add_coalesce
Definition: item_subselect.h:340
Item_singlerow_subselect * m_target
subquery to be replaced with field
Definition: item_subselect.h:334
Scalar_subquery_replacement(Item_singlerow_subselect *target, Field *field, Query_block *select, bool add_coalesce)
Definition: item_subselect.h:341
argument used by walk method collect_scalar_subqueries ("css")
Definition: item_subselect.h:243
Collect_subq_info(Query_block *owner)
Definition: item_subselect.h:247
Query_block * m_query_block
Definition: item_subselect.h:246
std::vector< Item_subselect * > list
< accumulated all subq (or aggregates) found
Definition: item_subselect.h:245
bool contains(Query_expression *candidate)
Definition: item_subselect.h:248
Definition: mysql_time.h:81
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:120
Definition: table.h:1395
Bison "location" class.
Definition: parse_location.h:42
Definition: result.h:29
unsigned int uint
Definition: uca9-dump.cc:74
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