MySQL  8.0.17
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  */
170  void init(SELECT_LEX *select, Query_result_subquery *result);
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:
690  };
691 
693  : result(res),
694  item(si),
697  maybe_null(false) {}
698  virtual ~subselect_engine() {} // to satisfy compiler
699  /**
700  Cleanup engine after complete query execution, free all resources.
701  */
702  virtual void cleanup(THD *thd) = 0;
703 
704  virtual bool prepare(THD *thd) = 0;
705  virtual void fix_length_and_dec(Item_cache **row) = 0;
706  /*
707  Execute the engine
708 
709  SYNOPSIS
710  exec()
711 
712  DESCRIPTION
713  Execute the engine. The result of execution is subquery value that is
714  either captured by previously set up Query_result-based 'sink' or
715  stored somewhere by the exec() method itself.
716 
717  RETURN
718  0 - OK
719  1 - Either an execution error, or the engine was "changed", and the
720  caller should call exec() again for the new engine.
721  */
722  virtual bool exec(THD *thd) = 0;
723  virtual uint cols() const = 0; /* return number of columns in select */
724  virtual uint8 uncacheable() const = 0; /* query is uncacheable */
725  virtual enum Item_result type() const { return res_type; }
726  virtual enum_field_types field_type() const { return res_field_type; }
727  virtual void exclude() = 0;
728  bool may_be_null() const { return maybe_null; }
729  virtual table_map upper_select_const_tables() const = 0;
731  virtual void print(const THD *thd, String *str,
732  enum_query_type query_type) = 0;
733  virtual bool change_query_result(THD *thd, Item_subselect *si,
735  virtual enum_engine_type engine_type() const { return ABSTRACT_ENGINE; }
736 #ifndef DBUG_OFF
737  /**
738  @returns the internal Item. Defined only in debug builds, because should
739  be used only for debug asserts.
740  */
741  const Item_subselect *get_item() const { return item; }
742 #endif
743 
744  protected:
745  void set_row(List<Item> &item_list, Item_cache **row, bool never_empty);
746 };
747 
749  private:
750  SELECT_LEX *select_lex; /* corresponding select_lex */
751  public:
755  void cleanup(THD *thd) override;
756  bool prepare(THD *thd) override;
757  void fix_length_and_dec(Item_cache **row) override;
758  bool exec(THD *thd) override;
759  uint cols() const override;
760  uint8 uncacheable() const override;
761  void exclude() override;
762  table_map upper_select_const_tables() const override;
763  void print(const THD *thd, String *str, enum_query_type query_type) override;
764  bool change_query_result(THD *thd, Item_subselect *si,
765  Query_result_subquery *result) override;
766  enum_engine_type engine_type() const override { return SINGLE_SELECT_ENGINE; }
767 
769  friend class Item_in_subselect;
770 };
771 
773  public:
776  void cleanup(THD *thd) override;
777  bool prepare(THD *thd) override;
778  void fix_length_and_dec(Item_cache **row) override;
779  bool exec(THD *thd) override;
780  uint cols() const override;
781  uint8 uncacheable() const override;
782  void exclude() override;
783  table_map upper_select_const_tables() const override;
784  void print(const THD *thd, String *str, enum_query_type query_type) override;
785  bool change_query_result(THD *thd, Item_subselect *si,
786  Query_result_subquery *result) override;
787  enum_engine_type engine_type() const override { return UNION_ENGINE; }
788 
789  private:
790  SELECT_LEX_UNIT *unit; /* corresponding unit structure */
791 };
792 
793 /**
794  A subquery execution engine that evaluates the subquery by doing index
795  lookups in a single table's index.
796 
797  This engine is used to resolve subqueries in forms
798 
799  outer_expr IN (SELECT tbl.key FROM tbl WHERE subq_where)
800 
801  or, row-based:
802 
803  (oe1, .. oeN) IN (SELECT key_part1, ... key_partK
804  FROM tbl WHERE subqwhere)
805 
806  i.e. the subquery is a single table SELECT without GROUP BY, aggregate
807  functions, etc.
808 */
810  protected:
811  /// Table which is read, using one of eq_ref, ref, ref_or_null.
813  Item *cond; /* The WHERE condition of subselect */
814  ulonglong hash; /* Hash value calculated by copy_ref_key, when needed. */
815  private:
816  /*
817  The "having" clause. This clause (further referred to as "artificial
818  having") was inserted by subquery transformation code. It contains
819  Item(s) that have a side-effect: they record whether the subquery has
820  produced a row with NULL certain components. We need to use it for cases
821  like
822  (oe1, oe2) IN (SELECT t.key, t.no_key FROM t1)
823  where we do index lookup on t.key=oe1 but need also to check if there
824  was a row such that t.no_key IS NULL.
825  */
827 
828  public:
830  Item *where, Item *having_arg)
831  : subselect_engine(subs, 0),
832  tab(tab_arg),
833  cond(where),
834  having(having_arg) {}
835  bool exec(THD *thd) override;
836  void print(const THD *thd, String *str, enum_query_type query_type) override;
837  enum_engine_type engine_type() const override { return INDEXSUBQUERY_ENGINE; }
838  void cleanup(THD *) override {}
839  bool prepare(THD *thd) override;
840  void fix_length_and_dec(Item_cache **row) override;
841  uint cols() const override { return 1; }
842  uint8 uncacheable() const override { return UNCACHEABLE_DEPENDENT; }
843  void exclude() override;
844  table_map upper_select_const_tables() const override { return 0; }
845  bool change_query_result(THD *thd, Item_subselect *si,
846  Query_result_subquery *result) override;
847  bool scan_table();
848  void copy_ref_key(bool *require_scan, bool *convert_error);
849 };
850 
851 /*
852  This function is actually defined in sql_parse.cc, but it depends on
853  chooser_compare_func_creator defined in this file.
854  */
857  SELECT_LEX *select);
858 
859 inline bool Item_subselect::is_uncacheable() const {
860  return engine->uncacheable();
861 }
862 
863 /**
864  Compute an IN predicate via a hash semi-join. The subquery is materialized
865  during the first evaluation of the IN predicate. The IN predicate is executed
866  via the functionality inherited from subselect_indexsubquery_engine.
867 */
868 
870  private:
871  /* TRUE if the subquery was materialized into a temp table. */
873  /**
874  Existence of inner NULLs in materialized table:
875  By design, other values than IRRELEVANT_OR_FALSE are possible only if the
876  subquery has only one inner expression.
877  */
878  enum nulls_exist {
879  /// none, or they don't matter
881  /// they matter, and we don't know yet if they exists
883  /// they matter, and we know there exists at least one.
885  };
887  /*
888  The old engine already chosen at parse time and stored in permanent memory.
889  Through this member we can re-create and re-prepare the join object
890  used to materialize the subquery for each execution of a prepared
891  statement. We also reuse the functionality of
892  subselect_single_select_engine::[prepare | cols].
893  */
895  /* Temp table context of the outer select's JOIN. */
897 
898  public:
900  subselect_single_select_engine *old_engine)
901  : subselect_indexsubquery_engine(NULL, in_predicate, NULL, NULL),
903  materialize_engine(old_engine),
904  tmp_param(NULL) {}
905  ~subselect_hash_sj_engine() override;
906 
907  bool setup(THD *thd, List<Item> *tmp_columns);
908  void cleanup(THD *thd) override;
909  bool prepare(THD *thd) override { return materialize_engine->prepare(thd); }
910  bool exec(THD *thd) override;
911  void print(const THD *thd, String *str, enum_query_type query_type) override;
912  uint cols() const override { return materialize_engine->cols(); }
913  enum_engine_type engine_type() const override { return HASH_SJ_ENGINE; }
914 
915  const QEP_TAB *get_qep_tab() const { return tab; }
916 };
917 #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
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_subselect.cc:1232
void reset_value_registration() override
Definition: item_subselect.h:328
Definition: item_subselect.h:688
unsigned long long int ulonglong
Definition: my_inttypes.h:74
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:1320
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:1217
This file contains the field type.
bool null_inside() override
Definition: item_subselect.cc:1166
void accumulate_join_condition(List< TABLE_LIST > *tables)
Accumulate properties from a join condition within a query block.
Definition: item_subselect.cc:297
unsigned char uchar
Definition: my_inttypes.h:51
longlong val_int() override
Definition: item_subselect.cc:1583
bool choose_semijoin_or_antijoin()
Helper for resolve_subquery().
Definition: item_subselect.cc:1489
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
Definition: item_subselect.cc:692
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:619
Item * substitution
Definition: item_subselect.h:99
const char * func_name() const override
Definition: item_subselect.h:224
Definition: item_cmpfunc.h:770
Query_result_interceptor * result
Definition: item_subselect.h:673
Item * having
Definition: item_subselect.h:826
t pos
Definition: dbug_analyze.cc:148
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:1212
void accumulate_properties()
Accumulate properties from underlying query expression.
Definition: item_subselect.cc:219
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1541
Definition: item_subselect.h:138
ulonglong table_map
Definition: my_table_map.h:32
Definition: item.h:754
bool exec(THD *thd) override
Definition: item_subselect.cc:3118
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
uint8 uncacheable() const override
Definition: item_subselect.cc:3253
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.cc:3257
uint8 uncacheable() const override
Definition: item_subselect.h:842
virtual uint8 uncacheable() const =0
subs_type substype() const override
Definition: item_subselect.h:665
Definition: item_subselect.h:687
double val_real() override
Definition: item_subselect.cc:1180
Definition: item_subselect.h:131
bool changed
Definition: item_subselect.h:129
double val_real() override
Definition: item_subselect.cc:1576
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:1126
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:371
bool can_do_aj
True if the Item has decided that it can do antijoin.
Definition: item_subselect.h:438
int cmp
Definition: dbug_analyze.cc:237
void update_used_tables() override
Definition: item_subselect.cc:779
String * val_str(String *) override
Return the result of EXISTS as a string value.
Definition: item_subselect.cc:1590
void cleanup() override
Definition: item_subselect.cc:309
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:838
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:878
bool with_is_op() const
Definition: item_subselect.h:416
uint cols() const override
Definition: item_subselect.cc:3248
bool may_be_null() const
Definition: item_subselect.h:728
enum Bool_test value_transform
Definition: item_subselect.h:415
bool prepare(THD *thd) override
Definition: item_subselect.h:909
virtual bool have_guarded_conds()
Definition: item_subselect.h:198
bool exec(THD *thd) override
Definition: item_subselect.cc:2865
void accumulate_expression(Item *item)
Accumulate properties from a selected expression within a query block.
Definition: item_subselect.cc:276
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:2522
bool value_assigned
Definition: item_subselect.h:77
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:1017
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:2621
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the subquery from the item tree.
Definition: item_subselect.cc:2637
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:847
Definition: field.h:709
Definition: item.h:5685
void set_cond_guard_var(int i, bool v)
Definition: item_subselect.h:574
Definition: item_cmpfunc.h:362
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
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:1038
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:735
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:458
none, or they don&#39;t matter
Definition: item_subselect.h:880
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:741
void no_rows_in_result() override
Definition: item_subselect.cc:1147
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:2609
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item_subselect.cc:1222
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:1052
table_map used_tables_cache
Definition: item_subselect.h:119
bool exec(THD *thd) override
Definition: item_subselect.cc:720
enum nulls_exist mat_table_has_nulls
Definition: item_subselect.h:886
enum_walk
Enumeration for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:434
virtual void fix_length_and_dec(Item_cache **row)=0
void exclude() override
Definition: item_subselect.cc:3263
virtual void exclude()=0
Item * get_tmp_table_item(THD *thd) override
Definition: item_subselect.cc:769
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:3297
enum_engine_type engine_type() const override
Definition: item_subselect.h:787
Temp_table_param * tmp_param
Definition: item_subselect.h:896
Definition: item.h:5040
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:159
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1046
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:4725
table_map used_tables() const override
Definition: item_subselect.h:192
bool val_bool() override
Definition: item_subselect.cc:1597
bool init_left_expr_cache(THD *thd)
Initialize the cache of the left operand of the IN predicate.
Definition: item_subselect.cc:2559
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:1529
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:7215
Compute an IN predicate via a hash semi-join.
Definition: item_subselect.h:869
bool explain_subquery_checker(uchar **arg) override
Register subquery to the table where it is used within a condition.
Definition: item_subselect.cc:645
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:698
~Item_subselect() override
Definition: item_subselect.cc:549
virtual enum_field_types field_type() const
Definition: item_subselect.h:726
#define DBUG_ASSERT(A)
Definition: my_dbug.h:183
Item_func_not_all * upper_item
Definition: item_subselect.h:556
subselect_hash_sj_engine(Item_subselect *in_predicate, subselect_single_select_engine *old_engine)
Definition: item_subselect.h:899
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:3386
Item * cond
Definition: item_subselect.h:813
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:2689
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_subselect.cc:1466
Definition: item.h:4650
void bring_value() override
Definition: item_subselect.cc:1173
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:882
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:328
subs_type
Definition: item_subselect.h:132
SELECT_LEX_UNIT * unit
Definition: item_subselect.h:790
void cleanup(THD *thd) override
Cleanup performed after each PS execution.
Definition: item_subselect.cc:3613
bool is_uncacheable() const
Definition: item_subselect.h:859
uint cols() const override
Definition: item_subselect.h:841
void copy_ref_key(bool *require_scan, bool *convert_error)
Copy ref key and check for null parts in it.
Definition: item_subselect.cc:2998
enum Item_result result_type() const override
Definition: item_subselect.cc:1122
Item_exists_subselect(const POS &pos)
Definition: item_subselect.h:395
Definition: aggregate_check.h:523
Definition: item.h:751
subs_type substype() const override
Definition: item_subselect.h:260
void fix_length_and_dec(Item_cache **row) override
Definition: item_subselect.cc:2843
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
enum_engine_type engine_type() const override
Definition: item_subselect.h:766
Item_singlerow_subselect()
Definition: item_subselect.h:256
bool fix_fields(THD *thd, Item **ref) override
Definition: item_subselect.cc:551
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_subselect.cc:764
my_decimal class limits &#39;decimal_t&#39; type to what we need in MySQL.
Definition: my_decimal.h:100
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:1942
SELECT_LEX_UNIT * unit
Definition: item_subselect.h:103
Definition: item.h:750
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:6599
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:629
enum_sj_selection
Decision on whether predicate is selected for semi-join transformation.
Definition: item_subselect.h:364
Definition: item_subselect.h:772
bool val_bool_naked()
Definition: item_subselect.cc:1604
void accumulate_condition(Item *item)
Accumulate properties from a condition or GROUP/ORDER within a query block.
Definition: item_subselect.cc:287
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:397
bool * pushed_cond_guards
Definition: item_subselect.h:554
bool test_limit()
Definition: item_subselect.cc:1386
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:499
subselect_single_select_engine * materialize_engine
Definition: item_subselect.h:894
enum_field_types
Column types for MySQL.
Definition: field_types.h:52
String * val_str(String *) override
Definition: item_subselect.cc:1202
Definition: item.h:666
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:2736
#define true
Definition: config_static.h:44
trans_res
Definition: item_subselect.h:131
Definition: parse_tree_nodes.h:1945
virtual enum Item_result type() const
Definition: item_subselect.h:725
Definition: item_subselect.cc:806
long long int longlong
Definition: my_inttypes.h:73
uint cols() const override
Definition: item_subselect.h:912
Type
Definition: item.h:702
Item_subselect super
Definition: item_subselect.h:334
Definition: item_subselect.h:333
Bool_test
< Modifier for result transformation
Definition: item.h:749
#define UNCACHEABLE_DEPENDENT
Definition: parse_tree_node_base.h:44
Base class for result from a subquery.
Definition: query_result.h:296
subselect_union_engine(SELECT_LEX_UNIT *u, Query_result_interceptor *result, Item_subselect *item)
Definition: item_subselect.cc:2723
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result) override
change query result object of engine.
Definition: item_subselect.cc:3369
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:2918
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:539
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:2493
SELECT_LEX * select_lex
Definition: item_subselect.h:750
virtual bool prepare(THD *thd)=0
enum Type type() const override
Definition: item_subselect.cc:762
bool exec(THD *thd) override
Execute a subquery IN predicate via materialization.
Definition: item_subselect.cc:3641
uint8_t uint8
Definition: my_inttypes.h:58
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:2196
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:1299
bool val_bool() override
Definition: item_subselect.cc:1565
No execution method specified yet.
Definition: item_subselect.h:346
virtual bool exec(THD *thd)
Definition: item_subselect.cc:652
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:2687
bool change_query_result(THD *thd, Item_subselect *si, Query_result_subquery *result) override
change query result object of engine.
Definition: item_subselect.cc:3349
bool was_values
Definition: item_subselect.h:319
Definition: item_subselect.cc:1264
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:365
void init(SELECT_LEX *select, Query_result_subquery *result)
Definition: item_subselect.cc:135
static char * where
Definition: mysqldump.cc:125
Definition: item.h:756
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:1558
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:915
table_map upper_select_const_tables() const override
Definition: item_subselect.cc:3283
void store(uint i, Item *item)
Definition: item_subselect.cc:1117
bool prepare(THD *thd) override
Definition: item_subselect.cc:2764
bool value
value of this item (boolean: exists/not-exists)
Definition: item_subselect.h:338
void cleanup(THD *thd) override
Cleanup engine after complete query execution, free all resources.
Definition: item_subselect.cc:2716
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:5165
bool(Item::* Item_processor)(uchar *arg)
Processor type for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:452
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
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:3760
int err_code
the error code found during check(if any)
Definition: item.h:487
bool prepare(THD *thd) override
Definition: item_subselect.cc:2773
bool all
Definition: item_subselect.h:659
Definition: mysql_time.h:64
Definition: item.h:753
bool val_bool() override
Definition: item_subselect.cc:1253
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.cc:1243
subselect_indexsubquery_engine(QEP_TAB *tab_arg, Item_subselect *subs, Item *where, Item *having_arg)
Definition: item_subselect.h:829
they matter, and we know there exists at least one.
Definition: item_subselect.h:884
enum_engine_type engine_type() const override
Definition: item_subselect.h:837
void fix_after_pullout(SELECT_LEX *parent_select, SELECT_LEX *removed_select) override
Definition: item_subselect.cc:2539
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
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:844
void exclude() override
Definition: item_subselect.cc:3265
virtual void reset()
Definition: item_subselect.h:174
void fix_length_and_dec(Item_cache **row) override
Definition: item_subselect.cc:2837
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:6613
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:1894
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:3270
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:2126
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:1658
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:3419
Item * element_index(uint i) override
Definition: item_subselect.h:290
Item * remove_in2exists_conds(Item *conds)
Definition: item_subselect.cc:433
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_subselect.cc:785
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
Definition: item_subselect.h:131
bool exec(THD *thd) override
Definition: item_subselect.cc:2901
subselect_engine(Item_subselect *si, Query_result_interceptor *res)
Definition: item_subselect.h:692
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:4566
void fix_length_and_dec(Item_cache **row) override
Definition: item_subselect.cc:2860
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:480
Definition: item_subselect.h:250
Definition: item_subselect.h:689
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:1440
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:1158
ulonglong hash
Definition: item_subselect.h:814
QEP_TAB * tab
Table which is read, using one of eq_ref, ref, ref_or_null.
Definition: item_subselect.h:812
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:1191
Definition: item_subselect.h:686
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:872
trans_res select_transformer(THD *thd, SELECT_LEX *select) override
Definition: item_subselect.cc:1067
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:809
uint cols() const override
Definition: item_subselect.cc:3244
Definition: table.h:2442
void cleanup(THD *thd) override
Cleanup engine after complete query execution, free all resources.
Definition: item_subselect.cc:2709
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:2679
Definition: item_subselect.h:671
double val_real() override
Definition: item_subselect.cc:1527
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:2785
Definition: item_subselect.h:131
enum_parsing_context place()
Definition: item_subselect.h:217
void cleanup() override
Definition: item_subselect.cc:516
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:913
Subquery&#39;s WHERE is always false, replace predicate with "false".
Definition: item_subselect.h:371
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:2789
void exclude() override
Definition: item_subselect.cc:3259
This bundles several pieces of information useful when doing the IN->EXISTS transform.
Definition: item_subselect.h:531
table_map upper_select_const_tables() const override
Definition: item_subselect.cc:3279
#define false
Definition: config_static.h:43
Item * truth_transformer(THD *, enum Bool_test test) override
Definition: item_subselect.cc:1357
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:838
trans_res select_transformer(THD *thd, SELECT_LEX *select) override
Definition: item_subselect.cc:2387
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:1156
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:1304
Item_allany_subselect(Item *left_expr, chooser_compare_func_creator fc, SELECT_LEX *select, bool all)
Definition: item_subselect.cc:1451
subselect_single_select_engine(SELECT_LEX *select, Query_result_interceptor *result, Item_subselect *item)
Definition: item_subselect.cc:2702
void print(const THD *thd, String *str, enum_query_type query_type) override
Definition: item_subselect.cc:3287
Definition: item_subselect.h:748
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:1619
void reset() override
Definition: item_subselect.h:602
bool max
Definition: item_subselect.h:318
~subselect_hash_sj_engine() override
Definition: item_subselect.cc:3598
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:705
bool get_time(MYSQL_TIME *ltime) override
Definition: item_subselect.h:448
void print(const THD *thd, String *str, enum_query_type query_type) override
Definition: item_subselect.cc:3292
bool prepare(THD *thd) override
Prepare the query expression underlying the subquery.
Definition: item_subselect.cc:2743
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:2414
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:777
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