MySQL 8.2.0
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/// Implements classes that represent subqueries and predicates containing
27/// table subqueries.
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;
67class THD;
69class my_decimal;
71struct AccessPath;
72class Table_ref;
73
74template <class T>
75class List;
76
77/// Base class that is common to all subqueries and subquery predicates
78
81
82 public:
84
85 /**
86 If !=NO_PLAN_IDX: this Item is in the condition attached to the JOIN_TAB
87 having this index in the parent JOIN.
88 */
90
91 // For EXPLAIN.
94
95 // For EXPLAIN. Only valid if engine_type() == HASH_SJ_ENGINE.
96 const TABLE *get_table() const;
97 const Index_lookup &index_lookup() const;
99
100 void create_iterators(THD *thd);
101 virtual AccessPath *root_access_path() const { return nullptr; }
102
104 SCALAR_SUBQUERY, ///< Scalar or row subquery
105 EXISTS_SUBQUERY, ///< [NOT] EXISTS subquery predicate
106 IN_SUBQUERY, ///< [NOT] IN subquery predicate
107 ALL_SUBQUERY, ///< comp-op ALL quantified comparison predicate
108 ANY_SUBQUERY ///< comp-op ANY quantified comparison predicate
109 };
110
111 /// Accumulate used tables
115 }
116
117 virtual Subquery_type subquery_type() const = 0;
118
119 void cleanup() override;
120 /**
121 Reset state after a single execution of a subquery, useful when a
122 dependent subquery must be evaluated multiple times for varying values
123 of the outer references.
124 This is a lighter cleanup procedure than the one provided by cleanup().
125 */
126 virtual void reset() {
127 m_value_assigned = false;
128 null_value = true;
129 }
130 bool is_value_assigned() const { return m_value_assigned; }
133 enum Type type() const override;
134 bool is_null() override { return update_null_value() || null_value; }
135 bool fix_fields(THD *thd, Item **ref) override;
136 void fix_after_pullout(Query_block *parent_query_block,
137 Query_block *removed_query_block) override;
138 virtual bool exec(THD *thd);
139 table_map used_tables() const override { return m_used_tables_cache; }
140 table_map not_null_tables() const override { return 0; }
141 /// @returns used tables for subquery (excluding any left-hand expression)
143 Item *get_tmp_table_item(THD *thd) override;
144 void update_used_tables() override;
145 void print(const THD *thd, String *str,
146 enum_query_type query_type) const override;
147
150 }
151
152 /*
153 True if this subquery has been already evaluated. Implemented only for
154 single select and union subqueries only.
155 */
156 bool is_evaluated() const;
157 bool is_uncacheable() const;
158
159 /**
160 Used by max/min subquery to initialize value presence registration
161 mechanism. Engine calls this function before re-execution of subquery.
162 */
163 virtual void reset_has_values() {}
164 /**
165 @returns the "place" where this subquery is located in the simply
166 containing query block.
167 */
169
170 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
171 bool explain_subquery_checker(uchar **arg) override;
172 bool inform_item_in_cond_of_tab(uchar *arg) override;
173 bool clean_up_after_removal(uchar *arg) override;
174
175 const char *func_name() const override {
176 assert(0);
177 return "subquery";
178 }
179
182 pointer_cast<Check_function_as_value_generator_parameters *>(args);
183 func_arg->err_code = func_arg->get_unnamed_function_error_code();
184 return true;
185 }
186
187 /// argument used by walk method collect_scalar_subqueries ("css")
189 ///< accumulated all subq (or aggregates) found
190 std::vector<Item_subselect *> list;
193 bool contains(Query_expression *candidate) {
194 for (auto sq : list) {
195 if (sq->m_query_expr == candidate) return true;
196 }
197 return false;
198 }
199 };
200
201 bool collect_subqueries(uchar *) override;
202 Item *replace_item_field(uchar *arg) override;
203 Item *replace_item_view_ref(uchar *arg) override;
204
205 protected:
207 explicit Item_subselect(const POS &pos) : super(pos) { set_subquery(); }
208 /**
209 Bind this subquery object with the supplied query expression.
210 As part of transformations, this function may re-bind the subquery to
211 a different query expression.
212
213 @param qe supplied query expression
214 */
215 void bind(Query_expression *qe);
216
217 /// The query expression of the subquery
218 Query_expression *m_query_expr{nullptr}; // Actual value set in construction
219
220 /// The query result object associated with the query expression
222
223 /// Only relevant for Item_in_subselect; optimized structure used for
224 /// execution in place of running the entire subquery.
226
227 /// cache of used tables
229 /// cache of used tables from subquery only (not including LHS of IN subquery)
231
232 /// allowed number of columns (1 for scalar subqueries)
233 uint m_max_columns{0}; // Irrelevant value, actually set during construction
234 /// where subquery is placed
236
237 private:
238 bool subq_opt_away_processor(uchar *arg) override;
239
240 /// Accumulate properties from underlying query expression
242 /// Accumulate properties from underlying query block
244 /// Accumulate properties from a selected expression within a query block.
245 void accumulate_expression(Item *item);
246 /// Accumulate properties from a condition or GROUP/ORDER within a query
247 /// block.
248 void accumulate_condition(Item *item);
249
250 /// True if value has been assigned to subquery
251 bool m_value_assigned{false};
252 /**
253 Whether or not execution of this subquery has been traced by
254 optimizer tracing already. If optimizer trace option
255 REPEATED_SUBSELECT is disabled, this is used to disable tracing
256 after the first one.
257 */
258 bool m_traced_before{false};
259};
260
261/// Class that represents scalar subquery and row subquery
262
264 public:
267
268 bool fix_fields(THD *thd, Item **ref) override;
269 void cleanup() override;
270 Subquery_type subquery_type() const override { return SCALAR_SUBQUERY; }
271 bool create_row(const mem_root_deque<Item *> &item_list, Item_cache **row,
272 bool possibly_empty);
273
274 void reset() override;
275 void store(uint i, Item *item);
276 double val_real() override;
277 longlong val_int() override;
278 String *val_str(String *) override;
279 my_decimal *val_decimal(my_decimal *) override;
280 bool val_json(Json_wrapper *result) override;
281 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
282 bool get_time(MYSQL_TIME *ltime) override;
283 bool val_bool() override;
284 enum Item_result result_type() const override;
285 bool resolve_type(THD *) override;
286
287 /*
288 Mark the subquery as having no rows.
289 If there are aggregate functions (in the outer query),
290 we need to generate a NULL row. @c return_zero_rows().
291 */
292 void no_rows_in_result() override;
293
294 uint cols() const override;
295
296 /**
297 @note that this returns the i-th element of the SELECT list.
298 To check for nullability, look at this->is_nullable() and not
299 element_index[i]->is_nullable(), since the selected expressions are
300 always NULL if the subquery is empty.
301 */
302 Item *element_index(uint i) override { return m_row[i]; }
303 Item **addr(uint i) override { return pointer_cast<Item **>(m_row) + i; }
304 bool check_cols(uint c) override;
305 bool null_inside() override;
306 void bring_value() override;
307
308 bool collect_scalar_subqueries(uchar *) override;
309 virtual bool is_maxmin() const { return false; }
310
311 /**
312 Argument for walk method replace_scalar_subquery
313 */
315 Item_singlerow_subselect *m_target; ///< subquery to be replaced with field
316 Field *m_field; ///< the replacement field
317 Query_block *m_outer_query_block; ///< The transformed query block.
318 Query_block *m_inner_query_block; ///< The immediately surrounding query
319 ///< block. This will be the transformed
320 ///< block or a subquery of it
321 bool m_add_coalesce{false};
323 Query_block *select, bool add_coalesce)
324 : m_target(target),
325 m_field(field),
326 m_outer_query_block(select),
327 m_inner_query_block(select),
328 m_add_coalesce(add_coalesce) {}
329 };
330
331 Item *replace_scalar_subquery(uchar *arge) override;
332 /**
333 This method is used to implement a special case of semantic tree
334 rewriting, mandated by a SQL:2003 exception in the specification.
335 The only caller of this method is handle_sql2003_note184_exception(),
336 see the code there for more details.
337 Note that this method breaks the object internal integrity, by
338 removing it's association with the corresponding Query_block,
339 making this object orphan from the parse tree.
340 No other method, beside the destructor, should be called on this
341 object, as it is now invalid.
342 @return the Query_block structure that was given in the constructor.
343 */
345 std::optional<ContainedSubquery> get_contained_subquery(
346 const Query_block *outer_query_block) override;
348
349 private:
350 /// Value cache of a scalar subquery
352 /**
353 Value cache for a row or scalar subquery. In case of a scalar subquery,
354 m_row points directly at m_value. In case of a row subquery, m_row
355 is an array of pointers to individual Item_cache objects.
356 */
357 Item_cache **m_row{nullptr};
358 bool m_no_rows{false}; ///< @c no_rows_in_result
359};
360
361/* used in static ALL/ANY optimization */
363 public:
364 /**
365 Create an Item for use in transformation of quantified comparison
366 predicates that can be evaluated using MAX or MIN aggregation.
367
368 @param parent The quantified comparison predicate that is transformed.
369 @param query_block The query block representing the inner part of the subq.
370 @param max_arg Whether the aggregation is for MAX or MIN.
371 */
373 bool max_arg);
374 void print(const THD *thd, String *str,
375 enum_query_type query_type) const override;
376 void cleanup() override;
377 bool has_values() const { return m_has_values; }
378 void register_value() { m_has_values = true; }
379 void reset_has_values() override { m_has_values = false; }
380 bool is_maxmin() const override { return true; }
381
382 private:
383 bool m_max; ///< True if performing MAX, false if MIN
384 bool m_has_values{false}; ///< Set if we have found at least one row
385};
386
387/// Classes that represent predicates over table subqueries:
388/// [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL
389
390/**
391 Strategy which will be used to handle this subquery: flattening to a
392 semi-join, conversion to a derived table, rewrite of IN to EXISTS...
393 Sometimes the strategy is first only a candidate, then the real decision
394 happens in a second phase. Other times the first decision is final.
395 */
396enum class Subquery_strategy : int {
397 /// Nothing decided yet
399 /// Candidate for rewriting IN(subquery) to EXISTS, or subquery
400 /// materialization
402 /// Candidate for semi-join flattening
404 /// Candidate for rewriting to joined derived table
406 /// Semi-join flattening
407 SEMIJOIN,
408 /// Rewrite to joined derived table
410 /// Evaluate as EXISTS subquery (possibly after rewriting from another type)
412 /// Subquery materialization (HASH_SJ_ENGINE)
414 /// Subquery has been deleted, probably because it was always false
415 DELETED,
416};
417
420
421 public:
422 /**
423 Create an Item that represents an EXISTS subquery predicate, or any
424 quantified comparison predicate that uses the same base class.
425
426 @param query_block First query block of query expression representing
427 the contained subquery.
428 */
429 explicit Item_exists_subselect(Query_block *query_block);
430
432
433 explicit Item_exists_subselect(const POS &pos) : super(pos) {}
434
435 // The left-hand expression of the subquery predicate. Unused with EXISTS
436 Item *left_expr{nullptr};
437
438 /// Priority of this predicate in the convert-to-semi-join-nest process.
440 /// Execution strategy chosen for this Item
442 /// Used by the transformation to derived table
444
445 /**
446 Used by subquery optimizations to keep track about where this subquery
447 predicate is located, and whether it is a candidate for transformation.
448 (Table_ref*) 1 - the predicate is an AND-part of the WHERE
449 join nest pointer - the predicate is an AND-part of ON expression
450 of a join nest
451 NULL - for all other locations. It also means that the
452 predicate is not a candidate for transformation.
453 See also THD::emb_on_expr_nest.
454
455 As for the second case above (the join nest pointer), note that this value
456 may change if scalar subqueries are transformed to derived tables,
457 cf. transform_scalar_subqueries_to_join_with_derived, due to the need to
458 build new join nests. The change is performed in Query_block::nest_derived.
459 */
461
463
464 /*
465 Transform subquery predicate to a form that can be executed, e.g.
466 as an EXISTS subquery, or a MAX or MIN aggregation on the subquery.
467
468 This is a virtual function that has implementations for EXISTS, IN
469 and quantified comparison subquery predicates.
470
471 @param thd Thread handle
472 @param[out] transformed Points to transformed representation of the object
473 if unchanged: No transformation was performed
474
475 @returns false if success, true if error
476 */
477 virtual bool transformer(THD *thd, Item **transformed);
478
479 Subquery_type subquery_type() const override { return EXISTS_SUBQUERY; }
480 bool is_bool_func() const override { return true; }
481 void reset() override {
483 m_value = false;
484 }
485
486 enum Item_result result_type() const override { return INT_RESULT; }
487 /*
488 The item is
489 ([NOT] IN/EXISTS) [ IS [NOT] TRUE|FALSE ]
490 */
492 bool with_is_op() const {
493 switch (value_transform) {
494 case BOOL_IS_TRUE:
495 case BOOL_IS_FALSE:
496 case BOOL_NOT_TRUE:
497 case BOOL_NOT_FALSE:
498 return true;
499 default:
500 return false;
501 }
502 }
503 /// True if the IS TRUE/FALSE wasn't explicit in the query
504 bool implicit_is_op = false;
505 Item *truth_transformer(THD *, enum Bool_test test) override;
506 bool translate(bool &null_v, bool v);
507 void apply_is_true() override {
508 const bool had_is = with_is_op();
510 if (!had_is && value_transform == BOOL_IS_TRUE)
511 implicit_is_op = true; // needn't be written by EXPLAIN
512 }
513 /// True if the Item has decided that it can do antijoin
514 bool can_do_aj = false;
516 bool fix_fields(THD *thd, Item **ref) override;
517 longlong val_int() override;
518 double val_real() override;
519 String *val_str(String *) override;
520 my_decimal *val_decimal(my_decimal *) override;
521 bool val_bool() override;
522 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
523 return get_date_from_int(ltime, fuzzydate);
524 }
525 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
526 bool resolve_type(THD *thd) override;
527 void print(const THD *thd, String *str,
528 enum_query_type query_type) const override;
529
531
532 protected:
533 bool is_semijoin_candidate(THD *thd);
534 bool is_derived_candidate(THD *thd);
535
536 /// value of this item (boolean: exists/not-exists)
537 bool m_value{false};
538
539 /**
540 True if naked IN is allowed to exchange FALSE for UNKNOWN.
541 Because this is about the naked IN, there is no public ignore_unknown(),
542 intentionally, so that callers don't get it wrong.
543 */
544 bool abort_on_null{false};
545};
546
547/**
548 Representation of IN subquery predicates of the form
549 "left_expr IN (SELECT ...)".
550
551 @details
552 This class has:
553 - A "subquery execution engine" (as a subclass of Item_subselect) that allows
554 it to evaluate subqueries. (and this class participates in execution by
555 having m_was_null variable where part of execution result is stored.
556 - Transformation methods (todo: more on this).
557
558 This class is not used directly, it is "wrapped" into Item_in_optimizer
559 which provides some small bits of subquery evaluation.
560*/
561
564
565 public:
567 Item_in_subselect(const POS &pos, Item *left_expr,
568 PT_subquery *pt_subquery_arg);
569
571
572 bool do_itemize(Parse_context *pc, Item **res) override;
573
574 void cleanup() override;
575 Subquery_type subquery_type() const override { return IN_SUBQUERY; }
576
577 void reset() override {
578 m_value = false;
579 null_value = false;
580 m_was_null = false;
581 }
582 bool transformer(THD *thd, Item **transformed) override;
584 Item **transformed);
586 Item **transformed);
587 bool row_value_transformer(THD *thd, Item **transformed);
589 Comp_creator *func);
591 Item_in_optimizer *optimizer);
592 bool subquery_allows_materialization(THD *thd, Query_block *query_block,
593 const Query_block *outer);
594 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
596 Item *compile(Item_analyzer analyzer, uchar **arg_p,
597 Item_transformer transformer, uchar *arg_t) override;
598
599 bool exec(THD *thd) override;
600 longlong val_int() override;
601 double val_real() override;
602 String *val_str(String *) override;
603 my_decimal *val_decimal(my_decimal *) override;
604 bool val_bool() override;
605 bool test_limit();
606 void print(const THD *thd, String *str,
607 enum_query_type query_type) const override;
608 void fix_after_pullout(Query_block *parent_query_block,
609 Query_block *removed_query_block) override;
610 void update_used_tables() override;
611 bool init_left_expr_cache(THD *thd);
612
613 /**
614 Once the decision to use IN->EXISTS has been taken, performs some last
615 steps of this transformation.
616 */
617 bool finalize_exists_transform(THD *thd, Query_block *select);
618 /**
619 Once the decision to use materialization has been taken, performs some
620 last steps of this transformation.
621 */
623 AccessPath *root_access_path() const override;
624 std::optional<ContainedSubquery> get_contained_subquery(
625 const Query_block *outer_query_block) override;
626
628 return m_in2exists_info != nullptr && m_in2exists_info->added_to_where;
629 }
630
631 /// Is reliable only if IN->EXISTS has been done.
633 return m_in2exists_info->dependent_before;
634 }
635
636 bool *get_cond_guard(int i) const {
637 return m_pushed_cond_guards != nullptr ? m_pushed_cond_guards + i : nullptr;
638 }
639 void set_cond_guard_var(int i, bool v) const {
640 if (m_pushed_cond_guards != nullptr) m_pushed_cond_guards[i] = v;
641 }
642
645 friend class Item_in_optimizer;
648
649 /// Used to trigger on/off conditions that were pushed down to subquery
650 bool *m_pushed_cond_guards{nullptr};
651
652 /// Point on NOT/NOP before ALL/SOME subquery
654
655 protected:
656 /**
657 Cache of the left operand of the subquery predicate. Allocated in the
658 runtime memory root, for each execution, thus need not be freed.
659 */
661
662 /// Whether m_left_expr_cache holds a value
664
665 /// The need for expr cache may be optimized away, @sa init_left_expr_cache.
666 bool need_expr_cache{true};
667
668 private:
669 bool mark_as_outer(Item *left_row, size_t col);
670
671 /**
672 In the case of
673
674 x COMP_OP (SELECT1 UNION SELECT2 ...)
675
676 - the subquery transformation is done on SELECT1; this requires wrapping
677 'x' with more Item layers, and injecting that in a condition in SELECT1.
678
679 - the same transformation is done on SELECT2; but the wrapped 'x' doesn't
680 need to be created again, the one created for SELECT1 could be reused
681
682 - to achieve this, the wrapped 'x' is stored in member
683 'm_injected_left_expr' when it is created for SELECT1, and is later
684 reused for SELECT2.
685
686 This will refer to a cached value which is reevaluated once for each
687 candidate row, cf. setup in #single_value_transformer.
688 */
690
691 bool m_was_null{false};
692
693 /**
694 This bundles several pieces of information useful when doing the
695 IN->EXISTS transform. If this transform has not been done, pointer is
696 NULL.
697 */
699 /**
700 True: if IN->EXISTS has been done and has added a condition to the
701 subquery's WHERE clause.
702 */
704 /**
705 True: if subquery was dependent (correlated) before IN->EXISTS
706 was done.
707 */
709 /**
710 True: if subquery was dependent (correlated) after IN->EXISTS
711 was done.
712 */
714 } * m_in2exists_info{nullptr};
715
717
718 bool val_bool_naked();
719};
720
721/**
722 Class that represents a quantified comparison predicate.
723
724 expression comp-op ANY ( subquery )
725 expression comp-op ALL ( subquery )
726
727 Note that the special cases = ANY (aka IN) and <> ALL (aka NOT IN)
728 are handled by the base class Item_in_subselect.
729*/
731 public:
733 Query_block *select, bool all);
734
735 Subquery_type subquery_type() const override {
737 }
738 bool transformer(THD *thd, Item **transformed) override;
739 void print(const THD *thd, String *str,
740 enum_query_type query_type) const override;
741
744 bool m_all;
745};
746
747/**
748 A subquery execution engine that evaluates the subquery by doing index
749 lookups in a single table's index.
750
751 This engine is used to resolve subqueries in forms
752
753 outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)
754
755 or, row-based:
756
757 (oe1, .. oeN) IN (SELECT key_part1, ... key_partK
758 FROM tbl WHERE subqwhere)
759
760 i.e. the subquery is a single table SELECT without GROUP BY, aggregate
761 functions, etc.
762*/
764 protected:
765 Query_result_union *result = nullptr; /* results storage class */
766 /// Table which is read, using one of eq_ref, ref, ref_or_null.
767 TABLE *table{nullptr};
771 Item *m_cond; ///< The WHERE condition of the subquery
772 ulonglong m_hash; ///< Hash value calculated by RefIterator, when needed.
773 /*
774 The "having" clause. This clause (further referred to as "artificial
775 having") was inserted by subquery transformation code. It contains
776 Item(s) that have a side-effect: they record whether the subquery has
777 produced a row with NULL certain components. We need to use it for cases
778 like
779 (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
780 where we do index lookup on t.key=oe1 but need also to check if there
781 was a row such that t.no_key IS NULL.
782 */
784
785 Item_in_subselect *item; /* item that uses this engine */
786
787 public:
789
791 const Index_lookup &ref,
792 enum join_type join_type,
794 Item *having)
795 : table(table),
797 ref(ref),
799 m_cond(where),
800 m_having(having),
801 item(subs) {}
803 virtual bool exec(THD *thd);
804 virtual void print(const THD *thd, String *str, enum_query_type query_type);
806 virtual void cleanup() {}
807 virtual void create_iterators(THD *) {}
808};
809
810/*
811 This function is actually defined in sql_parse.cc, but it depends on
812 chooser_compare_func_creator defined in this file.
813 */
816 Query_block *select);
817
818/**
819 Compute an IN predicate via a hash semi-join. The subquery is materialized
820 during the first evaluation of the IN predicate. The IN predicate is executed
821 via the functionality inherited from subselect_indexsubquery_engine.
822*/
823
825 private:
826 /* true if the subquery was materialized into a temp table. */
828 // true if we know for sure that there are zero rows in the table.
829 // Set only after is_materialized is true.
830 bool has_zero_rows = false;
831 /**
832 Existence of inner NULLs in materialized table:
833 By design, other values than IRRELEVANT_OR_FALSE are possible only if the
834 subquery has only one inner expression.
835 */
837 /// none, or they don't matter
839 /// they matter, and we don't know yet if they exists
841 /// they matter, and we know there exists at least one.
842 NEX_TRUE = 2
843 };
848
849 /// Saved result object, must be restored after use
851
852 public:
854 Query_expression *query_expr)
856 in_predicate, nullptr, nullptr),
857 is_materialized(false),
858 m_query_expr(query_expr) {}
859 ~subselect_hash_sj_engine() override;
860
861 bool setup(THD *thd, const mem_root_deque<Item *> &tmp_columns);
862 void cleanup() override;
863 bool exec(THD *thd) override;
864 void print(const THD *thd, String *str, enum_query_type query_type) override;
865 enum_engine_type engine_type() const override { return HASH_SJ_ENGINE; }
866
867 TABLE *get_table() const { return table; }
868 const Index_lookup &index_lookup() const { return ref; }
869 enum join_type get_join_type() const { return type; }
871 void create_iterators(THD *thd) override;
872};
873
874/**
875 Removes every predicate injected by IN->EXISTS.
876
877 This function is different from others:
878 - it wants to remove all traces of IN->EXISTS (for
879 materialization)
880 - remove_subq_pushed_predicates() and remove_additional_cond() want to
881 remove only the conditions of IN->EXISTS which index lookup already
882 satisfies (they are just an optimization).
883
884 If there are no in2exists conditions, it will return the exact same
885 pointer. If it returns a new Item, the old Item is left alone, so it
886 can be reused in other settings.
887
888 @param conds Condition; may be nullptr.
889 @returns new condition
890 */
892
893/// @returns whether the item is a quantified comparison predicate
895
896#endif /* ITEM_SUBSELECT_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:250
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:522
Definition: field.h:576
Class that represents a quantified comparison predicate.
Definition: item_subselect.h:730
Item_allany_subselect(Item *left_expr, chooser_compare_func_creator fc, Query_block *select, bool all)
Definition: item_subselect.cc:1445
bool transformer(THD *thd, Item **transformed) override
Definition: item_subselect.cc:2904
bool m_all
Definition: item_subselect.h:744
Subquery_type subquery_type() const override
Definition: item_subselect.h:735
Comp_creator * m_func
Definition: item_subselect.h:743
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2914
chooser_compare_func_creator m_func_creator
Definition: item_subselect.h:742
Definition: item.h:6810
Definition: item_subselect.h:418
enum_condition_context outer_condition_context
Used by the transformation to derived table.
Definition: item_subselect.h:443
bool is_semijoin_candidate(THD *thd)
Definition: item_subselect.cc:1501
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:507
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1462
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.h:522
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1710
bool m_value
value of this item (boolean: exists/not-exists)
Definition: item_subselect.h:537
Item_exists_subselect()
Definition: item_subselect.h:431
double val_real() override
Definition: item_subselect.cc:1696
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.h:525
bool implicit_is_op
True if the IS TRUE/FALSE wasn't explicit in the query.
Definition: item_subselect.h:504
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:1373
longlong val_int() override
Definition: item_subselect.cc:1698
Subquery_strategy strategy
Execution strategy chosen for this Item.
Definition: item_subselect.h:441
Item * left_expr
Definition: item_subselect.h:436
bool val_bool() override
Definition: item_subselect.cc:1734
int sj_convert_priority
Priority of this predicate in the convert-to-semi-join-nest process.
Definition: item_subselect.h:439
void reset() override
Reset state after a single execution of a subquery, useful when a dependent subquery must be evaluate...
Definition: item_subselect.h:481
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1315
bool abort_on_null
True if naked IN is allowed to exchange FALSE for UNKNOWN.
Definition: item_subselect.h:544
virtual bool transformer(THD *thd, Item **transformed)
Definition: item_subselect.cc:1484
bool is_derived_candidate(THD *thd)
Definition: item_subselect.cc:1592
bool can_do_aj
True if the Item has decided that it can do antijoin.
Definition: item_subselect.h:514
bool with_is_op() const
Definition: item_subselect.h:492
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:2650
enum Bool_test value_transform
Definition: item_subselect.h:491
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:462
Subquery_type subquery_type() const override
Definition: item_subselect.h:479
Item_subselect super
Definition: item_subselect.h:419
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:1336
bool is_bool_func() const override
Definition: item_subselect.h:480
Table_ref * embedding_join_nest
Used by subquery optimizations to keep track about where this subquery predicate is located,...
Definition: item_subselect.h:460
bool choose_semijoin_or_antijoin()
Helper for is_semijoin_candidate() and is_derived_candidate().
Definition: item_subselect.cc:1659
Item_exists_subselect(const POS &pos)
Definition: item_subselect.h:433
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1727
enum Item_result result_type() const override
Definition: item_subselect.h:486
Definition: item_cmpfunc.h:909
Definition: item_cmpfunc.h:489
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:562
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:2720
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1787
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:767
double val_real() override
Definition: item_subselect.cc:1745
struct Item_in_subselect::In2exists_info nullptr
bool m_left_expr_cache_filled
Whether m_left_expr_cache holds a value.
Definition: item_subselect.h:663
bool single_value_transformer(THD *thd, Comp_creator *func, Item **transformed)
Transform a single-column IN/ALL/ANY subquery predicate.
Definition: item_subselect.cc:1823
void set_cond_guard_var(int i, bool v) const
Definition: item_subselect.h:639
bool row_value_transformer(THD *thd, Item **transformed)
Transform a multi-column IN/ALL/ANY subquery predicate.
Definition: item_subselect.cc:2252
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:2777
Item_func_not_all * m_upper_item
Point on NOT/NOP before ALL/SOME subquery.
Definition: item_subselect.h:653
bool need_expr_cache
The need for expr cache may be optimized away,.
Definition: item_subselect.h:666
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:478
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_subselect.cc:1432
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2608
void reset() override
Reset state after a single execution of a subquery, useful when a dependent subquery must be evaluate...
Definition: item_subselect.h:577
List< Cached_item > * m_left_expr_cache
Cache of the left operand of the subquery predicate.
Definition: item_subselect.h:660
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:430
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:760
bool * m_pushed_cond_guards
Used to trigger on/off conditions that were pushed down to subquery.
Definition: item_subselect.h:650
bool dependent_before_in2exists() const
Is reliable only if IN->EXISTS has been done.
Definition: item_subselect.h:632
AccessPath * root_access_path() const override
Definition: item_subselect.cc:569
PT_subquery * pt_subselect
Definition: item_subselect.h:716
longlong val_int() override
Definition: item_subselect.cc:1752
bool * get_cond_guard(int i) const
Definition: item_subselect.h:636
bool row_value_in_to_exists_transformer(THD *thd, Query_block *select, Item_in_optimizer *optimizer)
Transform a (possibly non-correlated) IN subquery into a correlated EXISTS.
Definition: item_subselect.cc:2317
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:437
bool val_bool() override
Definition: item_subselect.cc:1766
bool m_was_null
Definition: item_subselect.h:691
bool init_left_expr_cache(THD *thd)
Initialize the cache of the left operand of the IN predicate.
Definition: item_subselect.cc:2744
bool quantified_comp_transformer(THD *thd, Comp_creator *func, Item **transformed)
Perform transformation of quantified comparison predicates (ie.
Definition: item_subselect.cc:2527
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:537
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1759
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_subselect.cc:2727
bool in2exists_added_to_where() const
Definition: item_subselect.h:627
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:754
Item_exists_subselect super
Definition: item_subselect.h:563
Subquery_type subquery_type() const override
Definition: item_subselect.h:575
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:2044
bool test_limit()
Definition: item_subselect.cc:1404
Item_in_subselect()
Definition: item_subselect.h:570
bool val_bool_naked()
Definition: item_subselect.cc:1773
Item_ref * m_injected_left_expr
In the case of.
Definition: item_subselect.h:689
bool exec(THD *thd) override
Definition: item_subselect.cc:783
bool transformer(THD *thd, Item **transformed) override
Definition: item_subselect.cc:2511
Definition: item_cmpfunc.h:2294
Definition: item_subselect.h:362
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1107
bool m_has_values
Set if we have found at least one row.
Definition: item_subselect.h:384
bool is_maxmin() const override
Definition: item_subselect.h:380
bool m_max
True if performing MAX, false if MIN.
Definition: item_subselect.h:383
void reset_has_values() override
Used by max/min subquery to initialize value presence registration mechanism.
Definition: item_subselect.h:379
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:1100
bool has_values() const
Definition: item_subselect.h:377
void register_value()
Definition: item_subselect.h:378
Item_maxmin_subselect(Item_subselect *parent, Query_block *query_block, bool max_arg)
Create an Item for use in transformation of quantified comparison predicates that can be evaluated us...
Definition: item_subselect.cc:1084
Definition: item.h:6295
Definition: item.h:5863
Item with result field.
Definition: item.h:5786
Class that represents scalar subquery and row subquery.
Definition: item_subselect.h:263
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:3002
enum Item_result result_type() const override
Definition: item_subselect.cc:1123
void store(uint i, Item *item)
Definition: item_subselect.cc:1118
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:396
bool null_inside() override
Definition: item_subselect.cc:1177
Item ** addr(uint i) override
Definition: item_subselect.h:303
double val_real() override
Definition: item_subselect.cc:1191
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_subselect.cc:1128
void no_rows_in_result() override
Definition: item_subselect.cc:1160
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_subselect.cc:1236
Item_cache ** m_row
Value cache for a row or scalar subquery.
Definition: item_subselect.h:357
bool m_no_rows
no_rows_in_result
Definition: item_subselect.h:358
void reset() override
Reset state after a single execution of a subquery, useful when a dependent subquery must be evaluate...
Definition: item_subselect.cc:1113
Subquery_type subquery_type() const override
Definition: item_subselect.h:270
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.cc:1247
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:3041
longlong val_int() override
Definition: item_subselect.cc:1202
uint cols() const override
Definition: item_subselect.cc:3252
virtual bool is_maxmin() const
Definition: item_subselect.h:309
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:328
Item * element_index(uint i) override
Definition: item_subselect.h:302
Item_singlerow_subselect()
Definition: item_subselect.h:266
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:899
bool collect_scalar_subqueries(uchar *) override
Definition: item_subselect.cc:2928
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.cc:1259
String * val_str(String *) override
Definition: item_subselect.cc:1213
bool val_bool() override
Definition: item_subselect.cc:1270
void bring_value() override
Definition: item_subselect.cc:1184
bool create_row(const mem_root_deque< Item * > &item_list, Item_cache **row, bool possibly_empty)
Makes storage for the output values for a scalar or row subquery and calculates their data and column...
Definition: item_subselect.cc:3158
bool check_cols(uint c) override
Definition: item_subselect.cc:1169
my_decimal * val_decimal(my_decimal *) override
Definition: item_subselect.cc:1224
Item_cache * m_value
Value cache of a scalar subquery.
Definition: item_subselect.h:351
Base class that is common to all subqueries and subquery predicates.
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:225
Item * replace_item_view_ref(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:3142
void set_value_assigned()
Definition: item_subselect.h:131
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the subquery from the item tree.
Definition: item_subselect.cc:2870
bool is_evaluated() const
Definition: item_subselect.cc:2910
enum_parsing_context m_parsing_place
where subquery is placed
Definition: item_subselect.h:235
bool collect_subqueries(uchar *) override
Definition: item_subselect.cc:2897
table_map used_tables() const override
Definition: item_subselect.h:139
void accumulate_expression(Item *item)
Accumulate properties from a selected expression within a query block.
Definition: item_subselect.cc:262
void accumulate_used_tables(table_map add_tables)
Accumulate used tables.
Definition: item_subselect.h:112
Query_expression * m_query_expr
The query expression of the subquery.
Definition: item_subselect.h:218
virtual Subquery_type subquery_type() const =0
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:180
table_map subquery_used_tables() const
Definition: item_subselect.h:142
bool is_uncacheable() const
Definition: item_subselect.cc:3257
void accumulate_properties()
Accumulate properties from underlying query expression.
Definition: item_subselect.cc:198
virtual bool exec(THD *thd)
Definition: item_subselect.cc:660
Query_expression * query_expr() const
Definition: item_subselect.h:83
enum_engine_type
Definition: item_subselect.h:92
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:92
@ HASH_SJ_ENGINE
Definition: item_subselect.h:92
@ OTHER_ENGINE
Definition: item_subselect.h:92
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:859
Subquery_type
Definition: item_subselect.h:103
@ ALL_SUBQUERY
comp-op ALL quantified comparison predicate
Definition: item_subselect.h:107
@ IN_SUBQUERY
[NOT] IN subquery predicate
Definition: item_subselect.h:106
@ SCALAR_SUBQUERY
Scalar or row subquery.
Definition: item_subselect.h:104
@ ANY_SUBQUERY
comp-op ANY quantified comparison predicate
Definition: item_subselect.h:108
@ EXISTS_SUBQUERY
[NOT] EXISTS subquery predicate
Definition: item_subselect.h:105
bool explain_subquery_checker(uchar **arg) override
Register subquery to the table where it is used within a condition.
Definition: item_subselect.cc:653
bool m_value_assigned
True if value has been assigned to subquery.
Definition: item_subselect.h:251
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:838
enum_parsing_context place()
Definition: item_subselect.h:168
virtual void reset()
Reset state after a single execution of a subquery, useful when a dependent subquery must be evaluate...
Definition: item_subselect.h:126
Item * replace_item_field(uchar *arg) override
Transform processor.
Definition: item_subselect.cc:3132
join_type get_join_type() const
Definition: item_subselect.cc:308
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:89
void accumulate_condition(Item *item)
Accumulate properties from a condition or GROUP/ORDER within a query block.
Definition: item_subselect.cc:273
virtual AccessPath * root_access_path() const
Definition: item_subselect.h:101
void create_iterators(THD *thd)
Definition: item_subselect.cc:278
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_subselect.cc:313
Query_result_interceptor * m_query_result
The query result object associated with the query expression.
Definition: item_subselect.h:221
table_map m_subquery_used_tables
cache of used tables from subquery only (not including LHS of IN subquery)
Definition: item_subselect.h:230
const TABLE * get_table() const
Definition: item_subselect.cc:298
enum Type type() const override
Definition: item_subselect.cc:836
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:590
void set_indexsubquery_engine(subselect_indexsubquery_engine *eng)
Definition: item_subselect.h:148
const char * func_name() const override
Definition: item_subselect.h:175
void bind(Query_expression *qe)
Bind this subquery object with the supplied query expression.
Definition: item_subselect.cc:142
void reset_value_assigned()
Definition: item_subselect.h:132
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:140
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_subselect.cc:850
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:632
Item_subselect()
Definition: item_subselect.h:206
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_subselect.h:134
const Index_lookup & index_lookup() const
Definition: item_subselect.cc:303
enum_engine_type engine_type() const
Definition: item_subselect.cc:284
bool is_value_assigned() const
Definition: item_subselect.h:130
Item_result_field super
Definition: item_subselect.h:80
bool m_traced_before
Whether or not execution of this subquery has been traced by optimizer tracing already.
Definition: item_subselect.h:258
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:2842
virtual void reset_has_values()
Used by max/min subquery to initialize value presence registration mechanism.
Definition: item_subselect.h:163
bool subq_opt_away_processor(uchar *arg) override
Mark the subquery as optimized away, for EXPLAIN.
Definition: item_subselect.cc:2854
uint m_max_columns
allowed number of columns (1 for scalar subqueries)
Definition: item_subselect.h:233
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Definition: item_subselect.cc:734
Item_subselect(const POS &pos)
Definition: item_subselect.h:207
table_map m_used_tables_cache
cache of used tables
Definition: item_subselect.h:228
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:932
void set_subquery()
Set the "has subquery" property.
Definition: item.h:3368
bool null_value
True if item is null.
Definition: item.h:3630
Type
Definition: item.h:967
Bool_test
< Modifier for result transformation
Definition: item.h:1015
@ BOOL_NOT_FALSE
Definition: item.h:1019
@ BOOL_NOT_TRUE
Definition: item.h:1018
@ BOOL_IS_TRUE
Definition: item.h:1015
@ BOOL_IS_FALSE
Definition: item.h:1016
@ BOOL_IDENTITY
Definition: item.h:1021
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1626
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:7568
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1713
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:1168
Definition: sql_list.h:433
Definition: parse_tree_nodes.h:1743
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:229
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1161
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:624
Definition: item_subselect.cc:1281
Definition: query_result.h:177
Query result class for scalar and row subqueries.
Definition: item_subselect.cc:105
Base class for result from a subquery.
Definition: query_result.h:299
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
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: table.h:2846
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:94
Compute an IN predicate via a hash semi-join.
Definition: item_subselect.h:824
void create_iterators(THD *thd) override
Definition: item_subselect.cc:3496
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:3728
nulls_exist
Existence of inner NULLs in materialized table: By design, other values than IRRELEVANT_OR_FALSE are ...
Definition: item_subselect.h:836
@ NEX_TRUE
they matter, and we know there exists at least one.
Definition: item_subselect.h:842
@ NEX_UNKNOWN
they matter, and we don't know yet if they exists
Definition: item_subselect.h:840
@ NEX_IRRELEVANT_OR_FALSE
none, or they don't matter
Definition: item_subselect.h:838
void cleanup() override
Cleanup performed after each execution.
Definition: item_subselect.cc:3574
unique_ptr_destroy_only< RowIterator > m_iterator
Definition: item_subselect.h:846
subselect_hash_sj_engine(Item_in_subselect *in_predicate, Query_expression *query_expr)
Definition: item_subselect.h:853
TABLE * get_table() const
Definition: item_subselect.h:867
~subselect_hash_sj_engine() override
Definition: item_subselect.cc:3563
Query_result_interceptor * saved_result
Saved result object, must be restored after use.
Definition: item_subselect.h:850
enum nulls_exist mat_table_has_nulls
Definition: item_subselect.h:844
bool is_materialized
Definition: item_subselect.h:827
Query_expression *const m_query_expr
Definition: item_subselect.h:845
bool has_zero_rows
Definition: item_subselect.h:830
const Index_lookup & index_lookup() const
Definition: item_subselect.h:868
bool exec(THD *thd) override
Execute a subquery IN predicate via materialization.
Definition: item_subselect.cc:3609
enum_engine_type engine_type() const override
Definition: item_subselect.h:865
AccessPath * root_access_path() const
Definition: item_subselect.h:870
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:3325
enum join_type get_join_type() const
Definition: item_subselect.h:869
AccessPath * m_root_access_path
Definition: item_subselect.h:847
A subquery execution engine that evaluates the subquery by doing index lookups in a single table's in...
Definition: item_subselect.h:763
Item * m_cond
The WHERE condition of the subquery.
Definition: item_subselect.h:771
TABLE * table
Table which is read, using one of eq_ref, ref, ref_or_null.
Definition: item_subselect.h:767
virtual ~subselect_indexsubquery_engine()=default
virtual void cleanup()
Definition: item_subselect.h:806
virtual bool exec(THD *thd)
Definition: item_subselect.cc:3241
virtual void print(const THD *thd, String *str, enum_query_type query_type)
Definition: item_subselect.cc:3261
virtual void create_iterators(THD *)
Definition: item_subselect.h:807
Item * m_having
Definition: item_subselect.h:783
join_type type
Definition: item_subselect.h:770
enum_engine_type
Definition: item_subselect.h:788
@ HASH_SJ_ENGINE
Definition: item_subselect.h:788
@ INDEXSUBQUERY_ENGINE
Definition: item_subselect.h:788
Index_lookup ref
Definition: item_subselect.h:769
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)
Definition: item_subselect.h:790
ulonglong m_hash
Hash value calculated by RefIterator, when needed.
Definition: item_subselect.h:772
virtual enum_engine_type engine_type() const
Definition: item_subselect.h:805
Item_in_subselect * item
Definition: item_subselect.h:785
Table_ref * table_ref
Definition: item_subselect.h:768
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:1059
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
This file contains the field type.
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:953
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:6805
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:462
Subquery_strategy
Classes that represent predicates over table subqueries: [NOT] EXISTS, [NOT] IN, ANY/SOME and ALL.
Definition: item_subselect.h:396
@ 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.
bool is_quantified_comp_predicate(Item *item)
Definition: item_subselect.cc:2809
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:151
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1085
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
int add_tables(PFS_engine_table_share_proxy **, unsigned int) noexcept
Definition: pfs_plugin_table_v1_all_empty.cc:32
enum_parsing_context
Names for different query parse tree parts.
Definition: parse_tree_node_base.h:60
@ CTX_NONE
Empty value.
Definition: parse_tree_node_base.h:61
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:185
@ JT_UNKNOWN
Definition: sql_opt_exec_shared.h:187
#define NO_PLAN_IDX
undefined index
Definition: sql_opt_exec_shared.h:54
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:489
int err_code
the error code found during check(if any)
Definition: item.h:496
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:508
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:698
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:703
bool dependent_before
True: if subquery was dependent (correlated) before IN->EXISTS was done.
Definition: item_subselect.h:708
bool dependent_after
True: if subquery was dependent (correlated) after IN->EXISTS was done.
Definition: item_subselect.h:713
Argument for walk method replace_scalar_subquery.
Definition: item_subselect.h:314
Query_block * m_outer_query_block
The transformed query block.
Definition: item_subselect.h:317
Field * m_field
the replacement field
Definition: item_subselect.h:316
Query_block * m_inner_query_block
The immediately surrounding query.
Definition: item_subselect.h:318
bool m_add_coalesce
Definition: item_subselect.h:321
Item_singlerow_subselect * m_target
subquery to be replaced with field
Definition: item_subselect.h:315
Scalar_subquery_replacement(Item_singlerow_subselect *target, Field *field, Query_block *select, bool add_coalesce)
Definition: item_subselect.h:322
argument used by walk method collect_scalar_subqueries ("css")
Definition: item_subselect.h:188
Collect_subq_info(Query_block *owner)
Definition: item_subselect.h:192
Query_block * m_query_block
Definition: item_subselect.h:191
std::vector< Item_subselect * > list
< accumulated all subq (or aggregates) found
Definition: item_subselect.h:190
bool contains(Query_expression *candidate)
Definition: item_subselect.h:193
Definition: mysql_time.h:81
Bison "location" class.
Definition: parse_location.h:42
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:418
Definition: table.h:1396
Definition: result.h:29
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
@ INT_RESULT
double
Definition: udf_registration_types.h:42
static int all(site_def const *s, node_no node)
Definition: xcom_transport.cc:868