MySQL  8.0.18
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, 2019, Oracle and/or its affiliates. All rights reserved.
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 <stddef.h>
29 #include <sys/types.h>
30 
31 #include "field_types.h" // enum_field_types
32 #include "my_dbug.h"
33 #include "my_inttypes.h"
34 #include "my_table_map.h"
35 #include "my_time.h"
37 #include "mysql_time.h"
38 #include "sql/enum_query_type.h"
39 #include "sql/item.h" // Item_result_field
41 
42 class Comp_creator;
43 class Field;
44 class Item_func_not_all;
45 class Item_in_optimizer;
46 class JOIN;
47 class Json_wrapper;
48 class PT_subquery;
49 class QEP_TAB;
52 class SELECT_LEX;
53 class SELECT_LEX_UNIT;
54 class String;
55 class THD;
56 class Temp_table_param;
57 class my_decimal;
58 class subselect_engine;
59 struct TABLE_LIST;
60 template <class T>
61 class List;
62 
63 /**
64  Convenience typedef used in this file, and further used by any files
65  including this file.
66 
67  @retval NULL In case of semantic errors.
68 */
69 typedef Comp_creator *(*chooser_compare_func_creator)(bool invert);
70 
71 /* base class for subselects */
72 
75 
76  private:
77  bool value_assigned; /* value already assigned to subselect */
78  /**
79  Whether or not execution of this subselect has been traced by
80  optimizer tracing already. If optimizer trace option
81  REPEATED_SUBSELECT is disabled, this is used to disable tracing
82  after the first one.
83  */
85 
86  public:
87  /*
88  Used inside Item_subselect::fix_fields() according to this scenario:
89  > Item_subselect::fix_fields
90  > engine->prepare
91  > query_block->prepare
92  (Here we realize we need to do the rewrite and set
93  substitution= some new Item, eg. Item_in_optimizer )
94  < query_block->prepare
95  < engine->prepare
96  *ref= substitution;
97  < Item_subselect::fix_fields
98  */
100 
101  public:
102  /* unit of subquery */
104  /**
105  If !=NO_PLAN_IDX: this Item is in the condition attached to the JOIN_TAB
106  having this index in the parent JOIN.
107  */
109 
110  /// EXPLAIN needs read-only access to the engine
111  const subselect_engine *get_engine_for_explain() const { return engine; }
112 
113  protected:
114  /* engine that perform execution of subselect (single select or union) */
116  /* old engine if engine was changed */
118  /* cache of used external tables */
120  /* allowed number of columns (1 for single value subqueries) */
122  /* where subquery is placed */
124  /* work with 'substitution' */
126 
127  public:
128  /* subquery is transformed */
129  bool changed;
130 
132  enum subs_type {
139  };
140 
141  Item_subselect();
142  explicit Item_subselect(const POS &pos);
143 
144  private:
145  /// Accumulate properties from underlying query expression
146  void accumulate_properties();
147  /// Accumulate properties from underlying query block
148  void accumulate_properties(SELECT_LEX *select);
149  /// Accumulate properties from a selected expression within a query block.
150  void accumulate_expression(Item *item);
151  /// Accumulate properties from a condition or GROUP/ORDER within a query
152  /// block.
153  void accumulate_condition(Item *item);
154  /// Accumulate properties from a join condition within a query block.
156 
157  public:
158  /// Accumulate used tables
160  used_tables_cache |= add_tables;
161  }
162 
163  virtual subs_type substype() const { return UNKNOWN_SUBS; }
164 
165  /*
166  We need this method, because some compilers do not allow 'this'
167  pointer in constructor initialization list, but we need to pass a pointer
168  to subselect Item class to Query_result_interceptor's constructor.
169  */
171 
172  ~Item_subselect() override;
173  void cleanup() override;
174  virtual void reset() { null_value = 1; }
175  virtual trans_res select_transformer(THD *thd, SELECT_LEX *select) = 0;
176  bool assigned() const { return value_assigned; }
177  void assigned(bool a) { value_assigned = a; }
178  enum Type type() const override;
179  bool is_null() override {
180  /*
181  TODO : Implement error handling for this function as
182  update_null_value() can return error.
183  */
184  (void)update_null_value();
185  return null_value;
186  }
187  bool fix_fields(THD *thd, Item **ref) override;
188  void fix_after_pullout(SELECT_LEX *parent_select,
189  SELECT_LEX *removed_select) override;
190  virtual bool exec(THD *thd);
191  bool resolve_type(THD *) override;
192  table_map used_tables() const override { return used_tables_cache; }
193  table_map not_null_tables() const override { return 0; }
194  Item *get_tmp_table_item(THD *thd) override;
195  void update_used_tables() override;
196  void print(const THD *thd, String *str,
197  enum_query_type query_type) const override;
198  virtual bool have_guarded_conds() { return false; }
200  old_engine = engine;
201  engine = eng;
202  return eng == 0;
203  }
204 
205  /*
206  True if this subquery has been already evaluated. Implemented only for
207  single select and union subqueries only.
208  */
209  bool is_evaluated() const;
210  bool is_uncacheable() const;
211 
212  /*
213  Used by max/min subquery to initialize value presence registration
214  mechanism. Engine call this method before rexecution query.
215  */
216  virtual void reset_value_registration() {}
218  bool walk_body(Item_processor processor, enum_walk walk, uchar *arg);
219  bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
220  bool explain_subquery_checker(uchar **arg) override;
221  bool inform_item_in_cond_of_tab(uchar *arg) override;
222  bool clean_up_after_removal(uchar *arg) override;
223 
224  const char *func_name() const override {
225  DBUG_ASSERT(0);
226  return "subselect";
227  }
228 
232  func_arg->err_code = func_arg->get_unnamed_function_error_code();
233  return true;
234  }
235 
237  friend class Item_in_optimizer;
238  friend bool Item_field::fix_fields(THD *, Item **);
239  friend int Item_field::fix_outer_field(THD *, Field **, Item **);
240  friend bool Item_ref::fix_fields(THD *, Item **);
241  friend void Item_ident::fix_after_pullout(SELECT_LEX *parent_select,
242  SELECT_LEX *removed_select);
243 
244  private:
245  bool subq_opt_away_processor(uchar *arg) override;
246 };
247 
248 /* single value subselect */
249 
251  protected:
253  bool no_rows; ///< @c no_rows_in_result
254  public:
257  : Item_subselect(), value(0), row(0), no_rows(false) {}
258 
259  void cleanup() override;
260  subs_type substype() const override { return SINGLEROW_SUBS; }
261 
262  void reset() override;
263  trans_res select_transformer(THD *thd, SELECT_LEX *select) override;
264  void store(uint i, Item *item);
265  double val_real() override;
266  longlong val_int() override;
267  String *val_str(String *) override;
268  my_decimal *val_decimal(my_decimal *) override;
269  bool val_json(Json_wrapper *result) override;
270  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
271  bool get_time(MYSQL_TIME *ltime) override;
272  bool val_bool() override;
273  enum Item_result result_type() const override;
274  bool resolve_type(THD *) override;
275 
276  /*
277  Mark the subquery as having no rows.
278  If there are aggregate functions (in the outer query),
279  we need to generate a NULL row. @c return_zero_rows().
280  */
281  void no_rows_in_result() override;
282 
283  uint cols() const override;
284  /**
285  @note that this returns the i-th element of the SELECT list.
286  To check for nullability, look at this->maybe_null and not
287  element_index[i]->maybe_null, since the selected expressions are
288  always NULL if the subquery is empty.
289  */
290  Item *element_index(uint i) override {
291  return reinterpret_cast<Item *>(row[i]);
292  }
293  Item **addr(uint i) override { return (Item **)row + i; }
294  bool check_cols(uint c) override;
295  bool null_inside() override;
296  void bring_value() override;
297 
298  /**
299  This method is used to implement a special case of semantic tree
300  rewriting, mandated by a SQL:2003 exception in the specification.
301  The only caller of this method is handle_sql2003_note184_exception(),
302  see the code there for more details.
303  Note that this method breaks the object internal integrity, by
304  removing it's association with the corresponding SELECT_LEX,
305  making this object orphan from the parse tree.
306  No other method, beside the destructor, should be called on this
307  object, as it is now invalid.
308  @return the SELECT_LEX structure that was given in the constructor.
309  */
311 
313 };
314 
315 /* used in static ALL/ANY optimization */
317  protected:
318  bool max;
319  bool was_values; // Set if we have found at least one row
320  public:
321  Item_maxmin_subselect(Item_subselect *parent, SELECT_LEX *select_lex,
322  bool max, bool ignore_nulls);
323  void print(const THD *thd, String *str,
324  enum_query_type query_type) const override;
325  void cleanup() override;
326  bool any_value() { return was_values; }
327  void register_value() { was_values = true; }
328  void reset_value_registration() override { was_values = false; }
329 };
330 
331 /* exists subselect */
332 
335 
336  protected:
337  /// value of this item (boolean: exists/not-exists)
338  bool value{false};
339 
340  public:
341  /**
342  The method chosen to execute the predicate, currently used for IN, =ANY
343  and EXISTS predicates.
344  */
346  EXEC_UNSPECIFIED, ///< No execution method specified yet.
347  EXEC_SEMI_JOIN, ///< Predicate is converted to semi-join nest.
348  /// IN was converted to correlated EXISTS, and this is a final decision.
350  /**
351  Decision between EXEC_EXISTS and EXEC_MATERIALIZATION is not yet taken.
352  IN was temporarily converted to correlated EXISTS.
353  All descendants of Item_in_subselect must go through this method
354  before they can reach EXEC_EXISTS.
355  */
357  /// Predicate executed via materialization, and this is a final decision.
359  };
361  /// Priority of this predicate in the convert-to-semi-join-nest process.
363  /// Decision on whether predicate is selected for semi-join transformation
365  /// Not selected for semi-join, evaluate as subquery predicate, or
366  /// replace with a substitution for the Item (e.g. Item_in_optimizer)
368  /// Selected for semi-join, replace predicate with "true"
370  /// Subquery's WHERE is always false, replace predicate with "false"
372  };
374  /**
375  Used by subquery optimizations to keep track about where this subquery
376  predicate is located, and whether it is a candidate for transformation.
377  (TABLE_LIST*) 1 - the predicate is an AND-part of the WHERE
378  join nest pointer - the predicate is an AND-part of ON expression
379  of a join nest
380  NULL - for all other locations. It also means that the
381  predicate is not a candidate for transformation.
382  See also THD::emb_on_expr_nest.
383  */
385 
387 
389  : Item_subselect(),
390  value(false),
394 
395  explicit Item_exists_subselect(const POS &pos)
396  : super(pos),
397  value(false),
401 
404  return RES_OK;
405  }
406  subs_type substype() const override { return EXISTS_SUBS; }
407  bool is_bool_func() const override { return true; }
408  void reset() override { value = 0; }
409 
410  enum Item_result result_type() const override { return INT_RESULT; }
411  /*
412  The item is
413  ([NOT] IN/EXISTS) [ IS [NOT] TRUE|FALSE ]
414  */
416  bool with_is_op() const {
417  switch (value_transform) {
418  case BOOL_IS_TRUE:
419  case BOOL_IS_FALSE:
420  case BOOL_NOT_TRUE:
421  case BOOL_NOT_FALSE:
422  return true;
423  default:
424  return false;
425  }
426  }
427  /// True if the IS TRUE/FALSE wasn't explicit in the query
428  bool implicit_is_op = false;
429  Item *truth_transformer(THD *, enum Bool_test test) override;
430  bool translate(bool &null_v, bool v);
431  void apply_is_true() override {
432  bool had_is = with_is_op();
434  if (!had_is && value_transform == BOOL_IS_TRUE)
435  implicit_is_op = true; // needn't be written by EXPLAIN
436  }
437  /// True if the Item has decided that it can do antijoin
438  bool can_do_aj = false;
440  longlong val_int() override;
441  double val_real() override;
442  String *val_str(String *) override;
443  my_decimal *val_decimal(my_decimal *) override;
444  bool val_bool() override;
445  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
446  return get_date_from_int(ltime, fuzzydate);
447  }
448  bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
449  bool resolve_type(THD *thd) override;
450  void print(const THD *thd, String *str,
451  enum_query_type query_type) const override;
452 
455 };
456 
457 /**
458  Representation of IN subquery predicates of the form
459  "left_expr IN (SELECT ...)".
460 
461  @details
462  This class has:
463  - A "subquery execution engine" (as a subclass of Item_subselect) that allows
464  it to evaluate subqueries. (and this class participates in execution by
465  having was_null variable where part of execution result is stored.
466  - Transformation methods (todo: more on this).
467 
468  This class is not used directly, it is "wrapped" into Item_in_optimizer
469  which provides some small bits of subquery evaluation.
470 */
471 
474 
475  public:
477 
478  protected:
479  /**
480  Cache of the left operand of the subquery predicate. Allocated in the
481  runtime memory root, for each execution, thus need not be freed.
482  */
484  bool left_expr_cache_filled; ///< Whether left_expr_cache holds a value
485  /** The need for expr cache may be optimized away, @sa init_left_expr_cache.
486  */
488 
489  private:
490  /**
491  In the case of
492 
493  x COMP_OP (SELECT1 UNION SELECT2 ...)
494 
495  - the subquery transformation is done on SELECT1; this requires wrapping
496  'x' with more Item layers, and injecting that in a condition in SELECT1.
497 
498  - the same transformation is done on SELECT2; but the wrapped 'x' doesn't
499  need to be created again, the one created for SELECT1 could be reused
500 
501  - to achieve this, the wrapped 'x' is stored in member
502  'm_injected_left_expr' when it is created for SELECT1, and is later
503  reused for SELECT2.
504 
505  This will refer to a cached value which is reevaluated once for each
506  candidate row, cf. setup in #single_value_transformer.
507  */
509 
510  /**
511  Pointer to the created Item_in_optimizer; it is stored for the same
512  reasons as 'm_injected_left_expr'.
513  */
515  bool was_null;
516 
517  protected:
518  /**
519  True if naked IN is allowed to exchange FALSE for UNKNOWN.
520  Because this is about the naked IN, there is no public ignore_unknown(),
521  intentionally, so that callers don't get it wrong.
522  */
524 
525  private:
526  /**
527  This bundles several pieces of information useful when doing the
528  IN->EXISTS transform. If this transform has not been done, pointer is
529  NULL.
530  */
531  struct In2exists_info {
532  /**
533  True: if IN->EXISTS has been done and has added a condition to the
534  subquery's WHERE clause.
535  */
537  /**
538  True: if subquery was dependent (correlated) before IN->EXISTS
539  was done.
540  */
542  /**
543  True: if subquery was dependent (correlated) after IN->EXISTS
544  was done.
545  */
547  } * in2exists_info;
548 
550  bool mark_as_outer(Item *left_row, size_t col);
551 
552  public:
553  /* Used to trigger on/off conditions that were pushed down to subselect */
555 
556  Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery
557 
558  private:
560 
561  public:
564  }
565 
566  /// Is reliable only if IN->EXISTS has been done.
569  }
570 
571  bool *get_cond_guard(int i) {
573  }
574  void set_cond_guard_var(int i, bool v) {
576  }
577  bool have_guarded_conds() override { return pushed_cond_guards != nullptr; }
578 
581  PT_subquery *pt_subquery_arg);
582 
585  left_expr(NULL),
590  optimizer(NULL),
591  was_null(false),
595  upper_item(NULL) {}
596 
597  bool itemize(Parse_context *pc, Item **res) override;
598 
599  void cleanup() override;
600  subs_type substype() const override { return IN_SUBS; }
601 
602  void reset() override {
603  value = 0;
604  null_value = 0;
605  was_null = 0;
606  }
607  trans_res select_transformer(THD *thd, SELECT_LEX *select) override;
609  Comp_creator *func);
611  Comp_creator *func);
614  Comp_creator *func);
616  bool subquery_allows_materialization(THD *thd, SELECT_LEX *select_lex,
617  const SELECT_LEX *outer);
618  bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
619  bool exec(THD *thd) override;
620  longlong val_int() override;
621  double val_real() override;
622  String *val_str(String *) override;
623  my_decimal *val_decimal(my_decimal *) override;
624  bool val_bool() override;
625  bool test_limit();
626  void print(const THD *thd, String *str,
627  enum_query_type query_type) const override;
628  bool fix_fields(THD *thd, Item **ref) override;
629  void fix_after_pullout(SELECT_LEX *parent_select,
630  SELECT_LEX *removed_select) override;
631  bool init_left_expr_cache(THD *thd);
632 
633  /**
634  Once the decision to use IN->EXISTS has been taken, performs some last
635  steps of this transformation.
636  */
637  bool finalize_exists_transform(THD *thd, SELECT_LEX *select);
638  /**
639  Once the decision to use materialization has been taken, performs some
640  last steps of this transformation.
641  */
643 
644  friend class Item_ref_null_helper;
645  friend class Item_is_not_null_test;
646  friend class Item_in_optimizer;
649 
650  private:
651  bool val_bool_naked();
652 };
653 
654 /// ALL/ANY/SOME subselect.
656  public:
659  bool all;
660 
662  SELECT_LEX *select, bool all);
663 
664  // only ALL subquery has upper not
665  subs_type substype() const override { return all ? ALL_SUBS : ANY_SUBS; }
666  trans_res select_transformer(THD *thd, SELECT_LEX *select) override;
667  void print(const THD *thd, String *str,
668  enum_query_type query_type) const override;
669 };
670 
672  protected:
673  Query_result_interceptor *result; /* results storage class */
674  Item_subselect *item; /* item, that use this engine */
675  enum Item_result res_type; /* type of results */
676  enum_field_types res_field_type; /* column type of the results */
677  /**
678  True if at least one of the columns returned by the subquery may
679  be null, or if a single-row subquery may return zero rows.
680  */
682 
683  public:
689  };
690 
692  : result(res),
693  item(si),
696  maybe_null(false) {}
697  virtual ~subselect_engine() {} // to satisfy compiler
698  /**
699  Cleanup engine after complete query execution, free all resources.
700  */
701  virtual void cleanup(THD *thd) = 0;
702 
703  virtual bool prepare(THD *thd) = 0;
704  virtual void fix_length_and_dec(Item_cache **row) = 0;
705  /*
706  Execute the engine
707 
708  SYNOPSIS
709  exec()
710 
711  DESCRIPTION
712  Execute the engine. The result of execution is subquery value that is
713  either captured by previously set up Query_result-based 'sink' or
714  stored somewhere by the exec() method itself.
715 
716  RETURN
717  0 - OK
718  1 - Either an execution error, or the engine was "changed", and the
719  caller should call exec() again for the new engine.
720  */
721  virtual bool exec(THD *thd) = 0;
722  virtual uint cols() const = 0; /* return number of columns in select */
723  virtual uint8 uncacheable() const = 0; /* query is uncacheable */
724  virtual enum Item_result type() const { return res_type; }
725  virtual enum_field_types field_type() const { return res_field_type; }
726  virtual void exclude() = 0;
727  bool may_be_null() const { return maybe_null; }
728  virtual table_map upper_select_const_tables() const = 0;
730  virtual void print(const THD *thd, String *str,
731  enum_query_type query_type) = 0;
732  virtual bool change_query_result(THD *thd, Item_subselect *si,
734  virtual enum_engine_type engine_type() const { return ABSTRACT_ENGINE; }
735 #ifndef DBUG_OFF
736  /**
737  @returns the internal Item. Defined only in debug builds, because should
738  be used only for debug asserts.
739  */
740  const Item_subselect *get_item() const { return item; }
741 #endif
742 };
743 
745  public:
749  void cleanup(THD *thd) override;
750  bool prepare(THD *thd) override;
751  void fix_length_and_dec(Item_cache **row) override;
752  bool exec(THD *thd) override;
753  uint cols() const override;
754  uint8 uncacheable() const override;
755  void exclude() override;
756  table_map upper_select_const_tables() const override;
757  void print(const THD *thd, String *str, enum_query_type query_type) override;
758  bool change_query_result(THD *thd, Item_subselect *si,
759  Query_result_subquery *result) override;
760  enum_engine_type engine_type() const override { return ITERATOR_ENGINE; }
761  SELECT_LEX *single_select_lex() const; // Only if unit is simple.
762 
763  private:
764  SELECT_LEX_UNIT *unit; /* corresponding unit structure */
765 
766  void set_row(List<Item> &item_list, Item_cache **row, bool never_empty);
767 
769 };
770 
771 /**
772  A subquery execution engine that evaluates the subquery by doing index
773  lookups in a single table's index.
774 
775  This engine is used to resolve subqueries in forms
776 
777  outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)
778 
779  or, row-based:
780 
781  (oe1, .. oeN) IN (SELECT key_part1, ... key_partK
782  FROM tbl WHERE subqwhere)
783 
784  i.e. the subquery is a single table SELECT without GROUP BY, aggregate
785  functions, etc.
786 */
788  protected:
789  /// Table which is read, using one of eq_ref, ref, ref_or_null.
791  Item *cond; /* The WHERE condition of subselect */
792  ulonglong hash; /* Hash value calculated by copy_ref_key, when needed. */
793  private:
794  /*
795  The "having" clause. This clause (further referred to as "artificial
796  having") was inserted by subquery transformation code. It contains
797  Item(s) that have a side-effect: they record whether the subquery has
798  produced a row with NULL certain components. We need to use it for cases
799  like
800  (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
801  where we do index lookup on t.key=oe1 but need also to check if there
802  was a row such that t.no_key IS NULL.
803  */
805 
806  public:
808  Item *where, Item *having_arg)
809  : subselect_engine(subs, 0),
810  tab(tab_arg),
811  cond(where),
812  having(having_arg) {}
813  bool exec(THD *thd) override;
814  void print(const THD *thd, String *str, enum_query_type query_type) override;
815  enum_engine_type engine_type() const override { return INDEXSUBQUERY_ENGINE; }
816  void cleanup(THD *) override {}
817  bool prepare(THD *thd) override;
818  void fix_length_and_dec(Item_cache **row) override;
819  uint cols() const override { return 1; }
820  uint8 uncacheable() const override { return UNCACHEABLE_DEPENDENT; }
821  void exclude() override;
822  table_map upper_select_const_tables() const override { return 0; }
823  bool change_query_result(THD *thd, Item_subselect *si,
824  Query_result_subquery *result) override;
825  bool scan_table();
826  void copy_ref_key(bool *require_scan, bool *convert_error);
827 };
828 
829 /*
830  This function is actually defined in sql_parse.cc, but it depends on
831  chooser_compare_func_creator defined in this file.
832  */
835  SELECT_LEX *select);
836 
837 inline bool Item_subselect::is_uncacheable() const {
838  return engine->uncacheable();
839 }
840 
841 /**
842  Compute an IN predicate via a hash semi-join. The subquery is materialized
843  during the first evaluation of the IN predicate. The IN predicate is executed
844  via the functionality inherited from subselect_indexsubquery_engine.
845 */
846 
848  private:
849  /* TRUE if the subquery was materialized into a temp table. */
851  /**
852  Existence of inner NULLs in materialized table:
853  By design, other values than IRRELEVANT_OR_FALSE are possible only if the
854  subquery has only one inner expression.
855  */
856  enum nulls_exist {
857  /// none, or they don't matter
859  /// they matter, and we don't know yet if they exists
861  /// they matter, and we know there exists at least one.
863  };
865  /*
866  The old engine already chosen at parse time and stored in permanent memory.
867  Through this member we can re-create and re-prepare the join object
868  used to materialize the subquery for each execution of a prepared
869  statement. We also reuse the functionality of
870  subselect_iterator_engine::[prepare | cols].
871  */
873  /* Temp table context of the outer select's JOIN. */
875 
876  public:
878  subselect_iterator_engine *old_engine)
879  : subselect_indexsubquery_engine(NULL, in_predicate, NULL, NULL),
881  materialize_engine(old_engine),
882  tmp_param(NULL) {}
883  ~subselect_hash_sj_engine() override;
884 
885  bool setup(THD *thd, List<Item> *tmp_columns);
886  void cleanup(THD *thd) override;
887  bool prepare(THD *thd) override { return materialize_engine->prepare(thd); }
888  bool exec(THD *thd) override;
889  void print(const THD *thd, String *str, enum_query_type query_type) override;
890  uint cols() const override { return materialize_engine->cols(); }
891  enum_engine_type engine_type() const override { return HASH_SJ_ENGINE; }
892 
893  const QEP_TAB *get_qep_tab() const { return tab; }
894 };
895 #endif /* ITEM_SUBSELECT_INCLUDED */
Item_cache * value
Definition: item_subselect.h:252
chooser_compare_func_creator func_creator
Definition: item_subselect.h:657
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1141
static int cmp(Bigint *a, Bigint *b)
Definition: dtoa.cc:1074
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.cc:1221
void reset_value_registration() override
Definition: item_subselect.h:328
Definition: item_subselect.h:687
Definition: result.h:33
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Item_ref * m_injected_left_expr
In the case of.
Definition: item_subselect.h:508
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:1308
Selected for semi-join, replace predicate with "true".
Definition: item_subselect.h:369
Item_cache ** row
Definition: item_subselect.h:252
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1215
This file contains the field type.
bool null_inside() override
Definition: item_subselect.cc:1155
void accumulate_join_condition(List< TABLE_LIST > *tables)
Accumulate properties from a join condition within a query block.
Definition: item_subselect.cc:292
unsigned char uchar
Definition: my_inttypes.h:51
longlong val_int() override
Definition: item_subselect.cc:1568
bool choose_semijoin_or_antijoin()
Helper for resolve_subquery().
Definition: item_subselect.cc:1474
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
Definition: item_subselect.cc:686
Definition: sql_optimizer.h:177
bool walk_body(Item_processor processor, enum_walk walk, uchar *arg)
Workaround for bug in gcc 4.1.
Definition: item_subselect.cc:611
Item * substitution
Definition: item_subselect.h:99
const char * func_name() const override
Definition: item_subselect.h:224
Definition: item_cmpfunc.h:874
Query_result_interceptor * result
Definition: item_subselect.h:673
Item * having
Definition: item_subselect.h:804
Item_result
Type of the user defined function return slot and arguments
Definition: udf_registration_types.h:38
not valid for UDFs
Definition: udf_registration_types.h:40
my_decimal * val_decimal(my_decimal *) override
Definition: item_subselect.cc:1201
void accumulate_properties()
Accumulate properties from underlying query expression.
Definition: item_subselect.cc:214
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1526
Definition: item_subselect.h:138
ulonglong table_map
Definition: my_table_map.h:32
Definition: item.h:756
bool exec(THD *thd) override
Definition: item_subselect.cc:3023
T pointer_cast(void *p)
Casts from one pointer type, to another, without using reinterpret_cast or C-style cast: foo f; bar *...
Definition: template_utils.h:70
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:108
uint8 uncacheable() const override
Definition: item_subselect.h:820
virtual uint8 uncacheable() const =0
subs_type substype() const override
Definition: item_subselect.h:665
double val_real() override
Definition: item_subselect.cc:1169
void cleanup(THD *thd) override
Cleanup engine after complete query execution, free all resources.
Definition: item_subselect.cc:2686
Definition: item_subselect.h:131
SELECT_LEX_UNIT * unit
Definition: item_subselect.h:764
bool changed
Definition: item_subselect.h:129
double val_real() override
Definition: item_subselect.cc:1561
Definition: item_subselect.h:136
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_subselect.cc:1115
bool finalize_exists_transform(THD *thd, SELECT_LEX *select)
Once the decision to use IN->EXISTS has been taken, performs some last steps of this transformation...
Definition: item_subselect.cc:364
bool can_do_aj
True if the Item has decided that it can do antijoin.
Definition: item_subselect.h:438
Definition: item_subselect.h:744
void update_used_tables() override
Definition: item_subselect.cc:773
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1575
void cleanup() override
Definition: item_subselect.cc:304
enum_parsing_context
Names for different query parse tree parts.
Definition: parse_tree_node_base.h:55
void cleanup(THD *) override
Cleanup engine after complete query execution, free all resources.
Definition: item_subselect.h:816
Some integer typedefs for easier portability.
nulls_exist
Existence of inner NULLs in materialized table: By design, other values than IRRELEVANT_OR_FALSE are ...
Definition: item_subselect.h:856
bool with_is_op() const
Definition: item_subselect.h:416
bool may_be_null() const
Definition: item_subselect.h:727
enum Bool_test value_transform
Definition: item_subselect.h:415
bool prepare(THD *thd) override
Definition: item_subselect.h:887
virtual bool have_guarded_conds()
Definition: item_subselect.h:198
void accumulate_expression(Item *item)
Accumulate properties from a selected expression within a query block.
Definition: item_subselect.cc:271
bool subquery_allows_materialization(THD *thd, SELECT_LEX *select_lex, const SELECT_LEX *outer)
Check if the subquery predicate can be executed via materialization.
Definition: sql_resolver.cc:692
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:2507
bool value_assigned
Definition: item_subselect.h:77
subselect_iterator_engine(SELECT_LEX_UNIT *u, Query_result_interceptor *result, Item_subselect *item)
Definition: item_subselect.cc:2692
bool assigned() const
Definition: item_subselect.h:176
Item_maxmin_subselect(Item_subselect *parent, SELECT_LEX *select_lex, bool max, bool ignore_nulls)
Definition: item_subselect.cc:1009
bool change_engine(subselect_engine *eng)
Definition: item_subselect.h:199
Definition: item_subselect.h:685
bool subq_opt_away_processor(uchar *arg) override
Mark the subquery as optimized away, for EXPLAIN.
Definition: item_subselect.cc:2606
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the subquery from the item tree.
Definition: item_subselect.cc:2622
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:971
void exclude() override
Definition: item_subselect.cc:3157
Definition: field.h:700
Definition: item.h:5678
void set_cond_guard_var(int i, bool v)
Definition: item_subselect.h:574
Definition: item_cmpfunc.h:462
bool have_to_be_excluded
Definition: item_subselect.h:125
uint max_columns
Definition: item_subselect.h:121
void cleanup() override
Definition: item_subselect.cc:1028
Definition: item_subselect.h:137
enum_exec_method
The method chosen to execute the predicate, currently used for IN, =ANY and EXISTS predicates...
Definition: item_subselect.h:345
virtual enum_engine_type engine_type() const
Definition: item_subselect.h:734
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:451
none, or they don&#39;t matter
Definition: item_subselect.h:858
std::string join(Container cont, const std::string &delim)
join elements of an container into a string seperated by a delimiter.
Definition: string.h:144
const Item_subselect * get_item() const
Definition: item_subselect.h:740
void no_rows_in_result() override
Definition: item_subselect.cc:1136
void fix_length_and_dec(Item_cache **row) override
Definition: item_subselect.cc:2780
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:2594
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_subselect.cc:1211
TABLE_LIST * embedding_join_nest
Used by subquery optimizations to keep track about where this subquery predicate is located...
Definition: item_subselect.h:384
void reset() override
Definition: item_subselect.cc:1041
table_map used_tables_cache
Definition: item_subselect.h:119
bool exec(THD *thd) override
Definition: item_subselect.cc:714
enum nulls_exist mat_table_has_nulls
Definition: item_subselect.h:864
enum_walk
Enumeration for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:435
virtual void fix_length_and_dec(Item_cache **row)=0
virtual void exclude()=0
enum_engine_type engine_type() const override
Definition: item_subselect.h:760
Item * get_tmp_table_item(THD *thd) override
Definition: item_subselect.cc:763
enum_sj_selection sj_selection
Definition: item_subselect.h:373
void print(const THD *thd, String *str, enum_query_type query_type) override
Definition: item_subselect.cc:3182
Temp_table_param * tmp_param
Definition: item_subselect.h:874
Definition: item.h:5033
List< Cached_item > * left_expr_cache
Cache of the left operand of the subquery predicate.
Definition: item_subselect.h:483
Definition: item_subselect.h:73
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:161
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1035
enum Item_result result_type() const override
Definition: item_subselect.h:410
int fix_outer_field(THD *thd, Field **field, Item **reference)
Resolve the name of an outer select column reference.
Definition: item.cc:4718
table_map used_tables() const override
Definition: item_subselect.h:192
bool val_bool() override
Definition: item_subselect.cc:1582
bool init_left_expr_cache(THD *thd)
Initialize the cache of the left operand of the IN predicate.
Definition: item_subselect.cc:2544
void set_row(List< 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:2735
int sj_convert_priority
Priority of this predicate in the convert-to-semi-join-nest process.
Definition: item_subselect.h:362
longlong val_int() override
Definition: item_subselect.cc:1514
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:7214
Compute an IN predicate via a hash semi-join.
Definition: item_subselect.h:847
bool explain_subquery_checker(uchar **arg) override
Register subquery to the table where it is used within a condition.
Definition: item_subselect.cc:637
Item_subselect()
Definition: item_subselect.cc:95
subselect_engine * engine
Definition: item_subselect.h:115
Item_in_subselect()
Definition: item_subselect.h:583
enum_field_types res_field_type
Definition: item_subselect.h:676
virtual ~subselect_engine()
Definition: item_subselect.h:697
~Item_subselect() override
Definition: item_subselect.cc:541
virtual enum_field_types field_type() const
Definition: item_subselect.h:725
#define DBUG_ASSERT(A)
Definition: my_dbug.h:197
Item_func_not_all * upper_item
Definition: item_subselect.h:556
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result) override
change query result emulation, never should be called.
Definition: item_subselect.cc:3256
Item * cond
Definition: item_subselect.h:791
Definition: item_subselect.h:135
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2673
bool exec(THD *thd) override
Definition: item_subselect.cc:2807
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_subselect.cc:1451
Definition: item.h:4643
char * pos
Definition: do_ctype.cc:76
void bring_value() override
Definition: item_subselect.cc:1162
enum_parsing_context parsing_place
Definition: item_subselect.h:123
bool added_to_where
True: if IN->EXISTS has been done and has added a condition to the subquery&#39;s WHERE clause...
Definition: item_subselect.h:536
Item_subselect * item
Definition: item_subselect.h:674
they matter, and we don&#39;t know yet if they exists
Definition: item_subselect.h:860
Decision between EXEC_EXISTS and EXEC_MATERIALIZATION is not yet taken.
Definition: item_subselect.h:356
virtual trans_res select_transformer(THD *thd, SELECT_LEX *select)=0
Bison "location" class.
Definition: parse_location.h:43
void cleanup() override
Definition: item_subselect.cc:322
subs_type
Definition: item_subselect.h:132
void cleanup(THD *thd) override
Cleanup performed after each PS execution.
Definition: item_subselect.cc:3482
bool is_uncacheable() const
Definition: item_subselect.h:837
uint cols() const override
Definition: item_subselect.h:819
void copy_ref_key(bool *require_scan, bool *convert_error)
Copy ref key and check for null parts in it.
Definition: item_subselect.cc:2904
bool prepare(THD *thd) override
Prepare the query expression underlying the subquery.
Definition: item_subselect.cc:2712
enum Item_result result_type() const override
Definition: item_subselect.cc:1111
Item_exists_subselect(const POS &pos)
Definition: item_subselect.h:395
Definition: aggregate_check.h:523
Definition: item.h:753
subs_type substype() const override
Definition: item_subselect.h:260
bool need_expr_cache
The need for expr cache may be optimized away,.
Definition: item_subselect.h:487
void reset() override
Definition: item_subselect.h:408
Item_singlerow_subselect()
Definition: item_subselect.h:256
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:543
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_subselect.cc:758
my_decimal class limits &#39;decimal_t&#39; type to what we need in MySQL.
Definition: my_decimal.h:91
const subselect_engine * get_engine_for_explain() const
EXPLAIN needs read-only access to the engine.
Definition: item_subselect.h:111
Definition: item_cmpfunc.h:2087
SELECT_LEX_UNIT * unit
Definition: item_subselect.h:103
Definition: item.h:752
double
Definition: udf_registration_types.h:42
Item * all_any_subquery_creator(Item *left_expr, chooser_compare_func_creator cmp, bool all, SELECT_LEX *select)
Construct ALL/ANY/SOME subquery Item.
Definition: sql_parse.cc:6646
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:621
enum_sj_selection
Decision on whether predicate is selected for semi-join transformation.
Definition: item_subselect.h:364
bool val_bool_naked()
Definition: item_subselect.cc:1589
void accumulate_condition(Item *item)
Accumulate properties from a condition or GROUP/ORDER within a query block.
Definition: item_subselect.cc:282
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:497
bool * pushed_cond_guards
Definition: item_subselect.h:554
bool test_limit()
Definition: item_subselect.cc:1374
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.h:445
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:501
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
table_map upper_select_const_tables() const override
Definition: item_subselect.cc:3173
String * val_str(String *) override
Definition: item_subselect.cc:1191
Definition: item.h:668
unsigned int uint
Definition: uca-dump.cc:29
#define final(a, b, c)
Definition: hash.c:109
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:111
bool null_value
True if item is null.
Definition: item.h:2732
#define true
Definition: config_static.h:44
trans_res
Definition: item_subselect.h:131
Definition: parse_tree_nodes.h:1949
virtual enum Item_result type() const
Definition: item_subselect.h:724
Definition: item_subselect.cc:800
long long int longlong
Definition: my_inttypes.h:54
uint cols() const override
Definition: item_subselect.h:890
Type
Definition: item.h:704
Item_subselect super
Definition: item_subselect.h:334
Definition: item_subselect.h:333
Bool_test
< Modifier for result transformation
Definition: item.h:751
#define UNCACHEABLE_DEPENDENT
Definition: parse_tree_node_base.h:44
Base class for result from a subquery.
Definition: query_result.h:296
Definition: item_subselect.h:134
bool scan_table()
Search, using a table scan, for at least one row satisfying select condition.
Definition: item_subselect.cc:2824
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:431
This class represents a query expression (one query block or several query blocks combined with UNION...
Definition: sql_lex.h:554
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2478
virtual bool prepare(THD *thd)=0
enum Type type() const override
Definition: item_subselect.cc:756
bool exec(THD *thd) override
Execute a subquery IN predicate via materialization.
Definition: item_subselect.cc:3509
uint8_t uint8
Definition: my_inttypes.h:62
trans_res row_value_in_to_exists_transformer(THD *thd, SELECT_LEX *select)
Tranform a (possibly non-correlated) IN subquery into a correlated EXISTS.
Definition: item_subselect.cc:2181
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1287
bool val_bool() override
Definition: item_subselect.cc:1550
No execution method specified yet.
Definition: item_subselect.h:346
virtual bool exec(THD *thd)
Definition: item_subselect.cc:644
subselect_hash_sj_engine(Item_subselect *in_predicate, subselect_iterator_engine *old_engine)
Definition: item_subselect.h:877
virtual table_map upper_select_const_tables() const =0
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:99
bool is_evaluated() const
Definition: item_subselect.cc:2671
bool was_values
Definition: item_subselect.h:319
Definition: item_subselect.cc:1253
subselect_engine * old_engine
Definition: item_subselect.h:117
subs_type substype() const override
Definition: item_subselect.h:406
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:358
void init(SELECT_LEX *select, Query_result_subquery *result)
Definition: item_subselect.cc:135
static char * where
Definition: mysqldump.cc:127
Definition: item.h:758
bool dependent_before_in2exists() const
Is reliable only if IN->EXISTS has been done.
Definition: item_subselect.h:567
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1543
subselect_iterator_engine * materialize_engine
Definition: item_subselect.h:872
bool dependent_after
True: if subquery was dependent (correlated) after IN->EXISTS was done.
Definition: item_subselect.h:546
Definition: sql_executor.h:406
const QEP_TAB * get_qep_tab() const
Definition: item_subselect.h:893
void store(uint i, Item *item)
Definition: item_subselect.cc:1106
bool value
value of this item (boolean: exists/not-exists)
Definition: item_subselect.h:338
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:5158
bool(Item::* Item_processor)(uchar *arg)
Processor type for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:453
unsigned int my_time_flags_t
Flags to str_to_datetime and number_to_datetime.
Definition: my_time.h:82
Definition: query_result.h:177
void print(const THD *thd, String *str, enum_query_type query_type) override
Definition: item_subselect.cc:3177
bool abort_on_null
True if naked IN is allowed to exchange FALSE for UNKNOWN.
Definition: item_subselect.h:523
void accumulate_used_tables(table_map add_tables)
Accumulate used tables.
Definition: item_subselect.h:159
enum Item_result res_type
Definition: item_subselect.h:675
virtual void print(const THD *thd, String *str, enum_query_type query_type)=0
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:3633
int err_code
the error code found during check(if any)
Definition: item.h:489
uint cols() const override
Definition: item_subselect.cc:3148
bool prepare(THD *thd) override
Definition: item_subselect.cc:2721
bool all
Definition: item_subselect.h:659
Definition: mysql_time.h:64
Definition: item.h:755
bool val_bool() override
Definition: item_subselect.cc:1242
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.cc:1232
subselect_indexsubquery_engine(QEP_TAB *tab_arg, Item_subselect *subs, Item *where, Item *having_arg)
Definition: item_subselect.h:807
they matter, and we know there exists at least one.
Definition: item_subselect.h:862
enum_engine_type engine_type() const override
Definition: item_subselect.h:815
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
Definition: item_subselect.cc:2524
virtual bool exec(THD *thd)=0
virtual uint cols() const =0
virtual subs_type substype() const
Definition: item_subselect.h:163
void register_value()
Definition: item_subselect.h:327
uint8 uncacheable() const override
Definition: item_subselect.cc:3153
Item_in_optimizer * optimizer
Pointer to the created Item_in_optimizer; it is stored for the same reasons as &#39;m_injected_left_expr&#39;...
Definition: item_subselect.h:514
table_map upper_select_const_tables() const override
Definition: item_subselect.h:822
void exclude() override
Definition: item_subselect.cc:3159
virtual void reset()
Definition: item_subselect.h:174
PT_subquery * pt_subselect
Definition: item_subselect.h:559
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:6612
trans_res single_value_in_to_exists_transformer(THD *thd, SELECT_LEX *select, Comp_creator *func)
Transform an IN predicate into EXISTS via predicate injection.
Definition: item_subselect.cc:1879
bool left_expr_cache_filled
Whether left_expr_cache holds a value.
Definition: item_subselect.h:484
static table_map calc_const_tables(TABLE_LIST *)
Definition: item_subselect.cc:3164
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result) override
change query result object of engine.
Definition: item_subselect.cc:3234
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:681
trans_res row_value_transformer(THD *thd, SELECT_LEX *select)
Definition: item_subselect.cc:2111
trans_res single_value_transformer(THD *thd, SELECT_LEX *select, Comp_creator *func)
Rewrite a single-column IN/ALL/ANY subselect.
Definition: item_subselect.cc:1643
subs_type substype() const override
Definition: item_subselect.h:600
bool setup(THD *thd, List< Item > *tmp_columns)
Create all structures needed for subquery execution using hash semijoin.
Definition: item_subselect.cc:3289
Item * element_index(uint i) override
Definition: item_subselect.h:290
Item * remove_in2exists_conds(Item *conds)
Definition: item_subselect.cc:426
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:779
trans_res select_transformer(THD *, SELECT_LEX *) override
Definition: item_subselect.h:402
Predicate is converted to semi-join nest.
Definition: item_subselect.h:347
SELECT_LEX * single_select_lex() const
Definition: item_subselect.cc:3242
Definition: item_subselect.h:131
subselect_engine(Item_subselect *si, Query_result_interceptor *res)
Definition: item_subselect.h:691
IN was converted to correlated EXISTS, and this is a final decision.
Definition: item_subselect.h:349
ALL/ANY/SOME subselect.
Definition: item_subselect.h:655
Time declarations shared between the server and client API: you should not add anything to this heade...
Item with result field.
Definition: item.h:4559
void fix_length_and_dec(Item_cache **row) override
Definition: item_subselect.cc:2802
Item_result_field super
Definition: item_subselect.h:74
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:482
Definition: item_subselect.h:250
Definition: item_subselect.h:688
#define NULL
Definition: types.h:55
bool * get_cond_guard(int i)
Definition: item_subselect.h:571
struct Item_in_subselect::In2exists_info * in2exists_info
virtual bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result)=0
virtual void reset_value_registration()
Definition: item_subselect.h:216
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize()/contextualize_() but with additional parameter.
Definition: item_subselect.cc:1426
bool was_null
Definition: item_subselect.h:515
Definition: item_subselect.h:316
bool is_bool_func() const override
Definition: item_subselect.h:407
bool check_cols(uint c) override
Definition: item_subselect.cc:1147
ulonglong hash
Definition: item_subselect.h:792
QEP_TAB * tab
Table which is read, using one of eq_ref, ref, ref_or_null.
Definition: item_subselect.h:790
bool dependent_before
True: if subquery was dependent (correlated) before IN->EXISTS was done.
Definition: item_subselect.h:541
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:229
bool no_rows
no_rows_in_result
Definition: item_subselect.h:253
Interface for low level time utilities.
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)". ...
Definition: item_subselect.h:472
bool in2exists_added_to_where() const
Definition: item_subselect.h:562
longlong val_int() override
Definition: item_subselect.cc:1180
bool implicit_is_op
True if the IS TRUE/FALSE wasn&#39;t explicit in the query.
Definition: item_subselect.h:428
bool is_materialized
Definition: item_subselect.h:850
trans_res select_transformer(THD *thd, SELECT_LEX *select) override
Definition: item_subselect.cc:1056
void assigned(bool a)
Definition: item_subselect.h:177
Predicate executed via materialization, and this is a final decision.
Definition: item_subselect.h:358
A subquery execution engine that evaluates the subquery by doing index lookups in a single table&#39;s in...
Definition: item_subselect.h:787
Definition: table.h:2468
Item ** addr(uint i) override
Definition: item_subselect.h:293
enum_exec_method exec_method
Definition: item_subselect.h:360
trans_res select_transformer(THD *thd, SELECT_LEX *select) override
Definition: item_subselect.cc:2663
Definition: item_subselect.h:671
double val_real() override
Definition: item_subselect.cc:1512
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
Fix after tables have been moved from one select_lex level to the parent level, e.g by semijoin conversion.
Definition: item.cc:2782
Definition: item_subselect.h:131
enum_parsing_context place()
Definition: item_subselect.h:217
void cleanup() override
Definition: item_subselect.cc:509
bool any_value()
Definition: item_subselect.h:326
Comp_creator *(* chooser_compare_func_creator)(bool invert)
Convenience typedef used in this file, and further used by any files including this file...
Definition: item_subselect.h:69
enum_engine_type engine_type() const override
Definition: item_subselect.h:891
Subquery&#39;s WHERE is always false, replace predicate with "false".
Definition: item_subselect.h:371
This bundles several pieces of information useful when doing the IN->EXISTS transform.
Definition: item_subselect.h:531
#define false
Definition: config_static.h:43
Item * truth_transformer(THD *, enum Bool_test test) override
Definition: item_subselect.cc:1345
Item * left_expr
Definition: item_subselect.h:476
SELECT_LEX * invalidate_and_restore_select_lex()
This method is used to implement a special case of semantic tree rewriting, mandated by a SQL:2003 ex...
Definition: item_subselect.cc:831
trans_res select_transformer(THD *thd, SELECT_LEX *select) override
Definition: item_subselect.cc:2372
table_map not_null_tables() const override
Definition: item_subselect.h:193
Comp_creator * func
Definition: item_subselect.h:658
uint cols() const override
Definition: item_subselect.cc:1145
Definition: field_types.h:86
bool traced_before
Whether or not execution of this subselect has been traced by optimizer tracing already.
Definition: item_subselect.h:84
bool get_time_from_int(MYSQL_TIME *ltime)
Convert val_int() to time in MYSQL_TIME.
Definition: item.cc:1302
Item_allany_subselect(Item *left_expr, chooser_compare_func_creator fc, SELECT_LEX *select, bool all)
Definition: item_subselect.cc:1437
Object containing parameters used when creating and using temporary tables.
Definition: temp_table_param.h:70
my_decimal * val_decimal(my_decimal *) override
Return the result of EXISTS as a decimal value.
Definition: item_subselect.cc:1604
void reset() override
Definition: item_subselect.h:602
bool max
Definition: item_subselect.h:318
Definition: item_subselect.h:686
~subselect_hash_sj_engine() override
Definition: item_subselect.cc:3467
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:699
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.h:448
trans_res select_in_like_transformer(THD *thd, SELECT_LEX *select, Comp_creator *func)
Prepare IN/ALL/ANY/SOME subquery transformation and call appropriate transformation function...
Definition: item_subselect.cc:2399
bool have_guarded_conds() override
Definition: item_subselect.h:577
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:778
virtual void cleanup(THD *thd)=0
Cleanup engine after complete query execution, free all resources.
Item_exists_subselect()
Definition: item_subselect.h:388
bool is_null() override
Definition: item_subselect.h:179
Item_exists_subselect super
Definition: item_subselect.h:473
Definition: item_subselect.h:133
Not selected for semi-join, evaluate as subquery predicate, or replace with a substitution for the It...
Definition: item_subselect.h:367
enum_engine_type
Definition: item_subselect.h:684