MySQL  8.0.21
Source Code Documentation
item_cmpfunc.h
Go to the documentation of this file.
1 #ifndef ITEM_CMPFUNC_INCLUDED
2 #define ITEM_CMPFUNC_INCLUDED
3 
4 /* Copyright (c) 2000, 2020, 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 /* compare and test functions */
27 
28 #include <string.h>
29 #include <sys/types.h>
30 #include <memory>
31 
32 #include "field_types.h"
33 #include "my_alloc.h"
34 #include "my_compiler.h"
35 #include "my_dbug.h"
36 #include "my_inttypes.h"
37 #include "my_table_map.h"
38 #include "my_time.h"
40 #include "mysql_time.h"
41 #include "sql/enum_query_type.h"
42 #include "sql/item.h"
43 #include "sql/item_func.h" // Item_int_func
44 #include "sql/item_row.h" // Item_row
45 #include "sql/mem_root_array.h" // Mem_root_array
46 #include "sql/my_decimal.h"
48 #include "sql/sql_const.h"
49 #include "sql/sql_list.h"
50 #include "sql/table.h"
51 #include "sql_string.h"
52 #include "template_utils.h" // down_cast
53 
54 class Arg_comparator;
55 class Field;
56 class Item_func_eq;
57 class Item_in_subselect;
58 class Item_subselect;
59 class Item_sum_hybrid;
60 class Json_scalar_holder;
61 class Json_wrapper;
62 class PT_item_list;
63 class QEP_TAB;
64 class SELECT_LEX;
65 class THD;
66 struct CHARSET_INFO;
67 struct MY_BITMAP;
68 
70 
71 typedef int (Arg_comparator::*arg_cmp_func)();
72 
73 /// A class that represents a join condition in a hash join. The class holds an
74 /// equality condition, as well as a pre-calculated bitmap of the used tables
75 /// (Item::used_tables()) for each side of the condition.
76 ///
77 /// The class also contains one Item for each side of the condition. In most
78 /// cases, the Item is only a pointer to the left/right Item of the join
79 /// condition. But for certain data types (DECIMAL, DOUBLE(M, N), FLOAT(M, N)),
80 /// the Item might be a typecast. Either way, the caller should use these Items
81 /// when i.e. reading the values from the join condition, so that the values are
82 /// read in the right data type context. See the comments for
83 /// Item_func_eq::create_cast_if_needed for more details around this.
85  public:
87 
89 
90  Item *left_extractor() const { return m_left_extractor; }
91  Item *right_extractor() const { return m_right_extractor; }
92  bool left_uses_any_table(table_map tables) const {
93  return (m_left_used_tables & tables) != 0;
94  }
95 
96  bool right_uses_any_table(table_map tables) const {
97  return (m_right_used_tables & tables) != 0;
98  }
99 
100  size_t max_character_length() const { return m_max_character_length; }
101 
103 
104  private:
108 
109  // Item::used_tables() is heavily used during the join to determine which side
110  // of the condition we are to read the value from, so caching the result of
111  // used_tables() gives a nice speedup.
114 
115  // The maximum number of characters among the two arguments. This is
116  // especially relevant when we have a PAD SPACE collation and the SQL mode
117  // PAD_CHAR_TO_FULL_LENGTH enabled, since we will have to pad the shortest
118  // argument to the same length as the longest argument.
119  const size_t m_max_character_length{0};
120 
121  // Normally, we store the full sort key for the condition as key in the hash
122  // table. However, if the string is very long, or we have a PAD SPACE
123  // collation, this could result in huge sort keys. If we detect that this
124  // could happen in the worst case, we store just a hash in the key instead (so
125  // we hash the hash). If so, we have to do a recheck afterwards, in order to
126  // guard against hash collisions.
128 };
129 
131  Item **left{nullptr};
132  Item **right{nullptr};
135  Arg_comparator *comparators{nullptr}; // used only for compare_row()
136  uint16 comparator_count{0};
137  double precision;
138  /* Fields used in DATE/DATETIME comparison. */
139  Item *left_cache{nullptr}; // Cached values of "left" and "right" items
140  Item *right_cache{nullptr};
141  bool set_null{true}; // true <=> set owner->null_value
142  // when one of arguments is NULL.
143 
144  bool try_year_cmp_func(Item_result type);
145  static bool get_date_from_const(Item *date_arg, Item *str_arg,
146  ulonglong *const_value);
147  /**
148  Only used by compare_json() in the case where a JSON value is
149  compared to an SQL value. This member points to pre-allocated
150  memory that can be used instead of the heap when converting the
151  SQL value to a JSON value.
152  */
153  Json_scalar_holder *json_scalar{nullptr};
154 
155  /**
156  When comparing strings, compare at most these many bytes.
157  A value of zero means "no limit".
158  */
159  size_t m_max_str_length{0};
160 
161  public:
163  /* Allow owner function to use string buffers. */
164  String value1, value2;
165 
166  Arg_comparator() = default;
167 
168  Arg_comparator(Item **left, Item **right) : left(left), right(right) {}
169 
170  bool set_compare_func(Item_result_field *owner, Item_result type);
171  bool set_cmp_func(Item_result_field *owner_arg, Item **left, Item **right,
172  Item_result type);
173 
174  bool set_cmp_func(Item_result_field *owner_arg, Item **left, Item **right,
175  bool set_null_arg);
176  /**
177  Comparison function are expected to operate on arguments having the
178  same data types. Since MySQL has very loosened up rules, it accepts
179  all kind of arguments which the standard SQL does not allow, and then it
180  converts the arguments internally to ones usable in the comparison.
181  This function transforms these internal conversions to explicit CASTs
182  so that the internally executed query becomes compatible with the standard
183  At the moment nodes are injected only for comparisons between:
184 
185  1) temporal types and numeric data types: in which case the
186  comparison is normally done as DOUBLE, so the arguments which are not
187  floating point, will get converted to DOUBLE, and also for
188 
189  2) comparisons between temporal types: in which case the
190  comparison happens as DATETIME if the arguments have different data
191  types, so in this case the temporal arguments that are not DATETIME
192  will get wrapped in a CAST to DATETIME.
193 
194  WL#12108; This function will limit itself to comparison between regular
195  functions, aggregation functions and fields, all of which are constant
196  for execution (so this excludes stored procedures, stored functions, GC,
197  user defined functions, as well as literals).
198  For const arguments, see type conversions done in fold_condition.
199 
200  @return false if successful, true otherwise
201  */
202  bool inject_cast_nodes();
203 
204  /**
205  When comparing strings, compare at most max_length bytes.
206  @param max_length how much to compare
207  */
208  void set_max_str_length(size_t max_length) { m_max_str_length = max_length; }
209  inline int compare() { return (this->*func)(); }
210 
211  int compare_string(); // compare args[0] & args[1]
212  int compare_binary_string(); // compare args[0] & args[1]
213  int compare_real(); // compare args[0] & args[1]
214  int compare_decimal(); // compare args[0] & args[1]
215  int compare_int_signed(); // compare args[0] & args[1]
216  int compare_int_signed_unsigned();
217  int compare_int_unsigned_signed();
218  int compare_int_unsigned();
219  int compare_time_packed();
220  int compare_row(); // compare args[0] & args[1]
221  int compare_real_fixed();
222  int compare_datetime(); // compare args[0] & args[1] as DATETIMEs
223  int compare_json();
224  bool compare_null_values();
225 
226  static bool can_compare_as_dates(const Item *a, const Item *b);
227 
228  Item **cache_converted_constant(THD *thd, Item **value, Item **cache,
229  Item_result type);
230  void set_datetime_cmp_func(Item_result_field *owner_arg, Item **a1,
231  Item **b1);
232  static arg_cmp_func comparator_matrix[5];
233  void cleanup();
234  /*
235  Set correct cmp_context if items would be compared as INTs.
236  */
239  if ((*left)->is_temporal()) (*left)->cmp_context = INT_RESULT;
240  if ((*right)->is_temporal()) (*right)->cmp_context = INT_RESULT;
241  }
242 
243  Item_result get_compare_type() const { return m_compare_type; }
244 
245  uint get_child_comparator_count() const { return comparator_count; }
246 
247  Arg_comparator *get_child_comparators() const { return comparators; }
248 
249  /// @returns true if the class has decided that values should be extracted
250  /// from the Items using function pointers set up by this class.
252  return get_value_a_func != nullptr;
253  }
254 
255  // Read the value from one of the Items (decided by "left_argument"), using
256  // the function pointers that this class has set up. This can happen for DATE,
257  // TIME, DATETIME and YEAR values, and the returned value is a temporal value
258  // in packed format.
259  longlong extract_value_from_argument(THD *thd, Item *item, bool left_argument,
260  bool *is_null) const;
261 
262  private:
263  /// A function pointer that is used for retrieving the value from argument
264  /// "left". This function is only used when we are comparing in a datetime
265  /// context, and it retrieves the value as a DATE, TIME, DATETIME or YEAR,
266  /// depending on the comparison context.
267  ///
268  /// @param thd thread handle. Used to retrieve the SQL mode among other things
269  /// @param item_arg the item to retrieve the value from
270  /// @param cache_arg a pointer to an Item where we can cache the value
271  /// from "item_arg". Can be nullptr
272  /// @param warn_item if rasing an conversion warning, the warning gets the
273  /// data type and item name from this item
274  /// @param is_null whether or not "item_arg" returned SQL NULL
275  ///
276  /// @returns a DATE/TIME/YEAR/DATETIME value, in packed format
277  longlong (*get_value_a_func)(THD *thd, Item ***item_arg, Item **cache_arg,
278  const Item *warn_item, bool *is_null){nullptr};
279 
280  // This function does the same as "get_value_a_func", except that it returns
281  // the value from the argument "right" (the right side of the comparison).
282  longlong (*get_value_b_func)(THD *thd, Item ***item_arg, Item **cache_arg,
283  const Item *warn_item, bool *is_null){nullptr};
284 
285  // The data type that is used when comparing the two Items. I.e., if the type
286  // is INT_RESULT, we call val_int() on both sides and compare those.
287  Item_result m_compare_type{INVALID_RESULT};
288 };
289 
291  public:
292  Item_bool_func() : Item_int_func(), m_created_by_in2exists(false) {}
293  explicit Item_bool_func(const POS &pos)
294  : Item_int_func(pos), m_created_by_in2exists(false) {}
295 
296  Item_bool_func(Item *a) : Item_int_func(a), m_created_by_in2exists(false) {}
298  : Item_int_func(pos, a), m_created_by_in2exists(false) {}
299 
301  : Item_int_func(a, b), m_created_by_in2exists(false) {}
302  Item_bool_func(const POS &pos, Item *a, Item *b)
303  : Item_int_func(pos, a, b), m_created_by_in2exists(false) {}
304 
306  : Item_int_func(thd, item),
307  m_created_by_in2exists(item->m_created_by_in2exists) {}
308  bool is_bool_func() const override { return true; }
309  bool resolve_type(THD *) override {
310  max_length = 1;
311  return false;
312  }
313  uint decimal_precision() const override { return 1; }
314  bool created_by_in2exists() const override { return m_created_by_in2exists; }
315  void set_created_by_in2exists() { m_created_by_in2exists = true; }
316 
317  static const char *bool_transform_names[10];
318  /**
319  Array that transforms a boolean test according to another.
320  First dimension is existing value, second dimension is test to apply
321  */
322  static const Bool_test bool_transform[10][8];
323 
324  private:
325  /**
326  True <=> this item was added by IN->EXISTS subquery transformation, and
327  should thus be deleted if we switch to materialization.
328  */
330 };
331 
332 /**
333  A predicate that is "always true" or "always false". To be used as a
334  standalone condition or as part of conditions, together with other condition
335  and predicate objects.
336  Mostly used when generating conditions internally.
337 */
339  public:
341  max_length = 1;
342  used_tables_cache = 0;
343  not_null_tables_cache = 0;
344  fixed = true;
345  }
346  explicit Item_func_bool_const(const POS &pos) : Item_bool_func(pos) {
347  max_length = 1;
348  used_tables_cache = 0;
349  not_null_tables_cache = 0;
350  fixed = true;
351  }
352  bool fix_fields(THD *, Item **) override { return false; }
353  bool basic_const_item() const override { return true; }
354  void cleanup() override { result_field = nullptr; }
355 };
356 
357 /// A predicate that is "always true".
358 
360  public:
362  explicit Item_func_true(const POS &pos) : Item_func_bool_const(pos) {}
363  const char *func_name() const override { return "true"; }
364  bool val_bool() override { return true; }
365  longlong val_int() override { return 1; }
366  void print(const THD *, String *str, enum_query_type) const override {
367  str->append("true");
368  }
369  enum Functype functype() const override { return TRUE_FUNC; }
370 };
371 
372 /// A predicate that is "always false".
373 
375  public:
377  explicit Item_func_false(const POS &pos) : Item_func_bool_const(pos) {}
378  const char *func_name() const override { return "false"; }
379  bool val_bool() override { return false; }
380  longlong val_int() override { return 0; }
381  void print(const THD *, String *str, enum_query_type) const override {
382  str->append("false");
383  }
384 };
385 
386 /**
387  Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
388  boolean predicates.
389 */
392 
393  public:
394  longlong val_int() override;
395  bool resolve_type(THD *) override;
396  void print(const THD *thd, String *str,
397  enum_query_type query_type) const override;
398  Item *truth_transformer(THD *, Bool_test test) override {
399  truth_test = super::bool_transform[truth_test][test];
400  return this;
401  }
402  const char *func_name() const override {
403  return super::bool_transform_names[truth_test];
404  }
405  virtual enum Functype functype() const override { return ISTRUTH_FUNC; }
406 
407  Item_func_truth(const POS &pos, Item *a, Bool_test truth_test)
408  : super(pos, a), truth_test(truth_test) {
409  null_on_null = false;
410  switch (truth_test) {
411  case BOOL_IS_TRUE:
412  case BOOL_IS_FALSE:
413  case BOOL_NOT_TRUE:
414  case BOOL_NOT_FALSE:
415  break;
416  default:
417  DBUG_ASSERT(false);
418  }
419  }
421  : super(a), truth_test(truth_test) {
422  null_on_null = false;
423  switch (truth_test) {
424  case BOOL_IS_TRUE:
425  case BOOL_IS_FALSE:
426  case BOOL_NOT_TRUE:
427  case BOOL_NOT_FALSE:
428  break;
429  default:
430  DBUG_ASSERT(false);
431  }
432  }
433  void apply_is_true() override {
434  /*
435  This item cannot produce NULL result. But, if the upper item confuses
436  NULL and FALSE, we can do as if NULL input caused a NULL result when it
437  actually causes a FALSE result.
438  */
439  switch (truth_test) {
440  case BOOL_IS_TRUE:
441  case BOOL_IS_FALSE:
442  null_on_null = true;
443  default:
444  break;
445  }
446  }
447 
448  protected:
449  Bool_test truth_test; ///< The value we're testing for.
450 };
451 
452 static const int UNKNOWN = -1;
453 
454 /*
455  Item_in_optimizer(left_expr, Item_in_subselect(...))
456 
457  Item_in_optimizer is used to wrap an instance of Item_in_subselect. This
458  class does the following:
459  - Evaluate the left expression and store it in Item_cache_* object (to
460  avoid re-evaluating it many times during subquery execution)
461  - Shortcut the evaluation of "NULL IN (...)" to NULL in the cases where we
462  don't care if the result is NULL or FALSE.
463 
464  args[1] keeps a reference to the Item_in_subselect object.
465 
466  args[0] is a copy of Item_in_subselect's left expression and should be
467  kept equal also after resolving.
468 
469  NOTE
470  It is not quite clear why the above listed functionality should be
471  placed into a separate class called 'Item_in_optimizer'.
472 */
473 
475  private:
478  /*
479  Stores the value of "NULL IN (SELECT ...)" for uncorrelated subqueries:
480  UNKNOWN - "NULL in (SELECT ...)" has not yet been evaluated
481  FALSE - result is FALSE
482  TRUE - result is NULL
483  */
485 
486  public:
488  : Item_bool_func(a, reinterpret_cast<Item *>(b)),
489  cache(nullptr),
490  save_cache(false),
491  result_for_null_param(UNKNOWN) {
492  set_subquery();
493  }
494  bool fix_fields(THD *, Item **) override;
495  bool fix_left(THD *thd, Item **ref);
496  void fix_after_pullout(SELECT_LEX *parent_select,
497  SELECT_LEX *removed_select) override;
498  bool is_null() override;
499  longlong val_int() override;
500  void cleanup() override;
501  const char *func_name() const override { return "<in_optimizer>"; }
502  Item_cache **get_cache() { return &cache; }
503  void keep_top_level_cache();
504  Item *transform(Item_transformer transformer, uchar *arg) override;
505  void replace_argument(THD *thd, Item **oldpp, Item *newp) override;
506  void update_used_tables() override;
507 };
508 
509 /// Abstract factory interface for creating comparison predicates.
511  public:
512  virtual ~Comp_creator() {}
513  virtual Item_bool_func *create(Item *a, Item *b) const = 0;
514 
515  /// This interface is only used by Item_allany_subselect.
516  virtual const char *symbol(bool invert) const = 0;
517  virtual bool eqne_op() const = 0;
518  virtual bool l_op() const = 0;
519 };
520 
521 /// Abstract base class for the comparison operators =, <> and <=>.
523  public:
524  virtual Item_bool_func *create(Item *a, Item *b) const;
525  virtual bool eqne_op() const { return true; }
526  virtual bool l_op() const { return false; }
527 
528  protected:
529  /**
530  Creates only an item tree node, without attempting to rewrite row
531  constructors.
532  @see create()
533  */
534  virtual Item_bool_func *create_scalar_predicate(Item *a, Item *b) const = 0;
535 
536  /// Combines a list of conditions <code>exp op exp</code>.
537  virtual Item_bool_func *combine(List<Item> list) const = 0;
538 };
539 
541  public:
542  virtual const char *symbol(bool invert) const { return invert ? "<>" : "="; }
543 
544  protected:
545  virtual Item_bool_func *create_scalar_predicate(Item *a, Item *b) const;
546  virtual Item_bool_func *combine(List<Item> list) const;
547 };
548 
550  public:
551  virtual const char *symbol(bool invert MY_ATTRIBUTE((unused))) const {
552  // This will never be called with true.
553  DBUG_ASSERT(!invert);
554  return "<=>";
555  }
556 
557  protected:
558  virtual Item_bool_func *create_scalar_predicate(Item *a, Item *b) const;
559  virtual Item_bool_func *combine(List<Item> list) const;
560 };
561 
563  public:
564  virtual const char *symbol(bool invert) const { return invert ? "=" : "<>"; }
565 
566  protected:
567  virtual Item_bool_func *create_scalar_predicate(Item *a, Item *b) const;
568  virtual Item_bool_func *combine(List<Item> list) const;
569 };
570 
571 class Gt_creator : public Comp_creator {
572  public:
573  virtual Item_bool_func *create(Item *a, Item *b) const;
574  virtual const char *symbol(bool invert) const { return invert ? "<=" : ">"; }
575  virtual bool eqne_op() const { return false; }
576  virtual bool l_op() const { return false; }
577 };
578 
579 class Lt_creator : public Comp_creator {
580  public:
581  virtual Item_bool_func *create(Item *a, Item *b) const;
582  virtual const char *symbol(bool invert) const { return invert ? ">=" : "<"; }
583  virtual bool eqne_op() const { return false; }
584  virtual bool l_op() const { return true; }
585 };
586 
587 class Ge_creator : public Comp_creator {
588  public:
589  virtual Item_bool_func *create(Item *a, Item *b) const;
590  virtual const char *symbol(bool invert) const { return invert ? "<" : ">="; }
591  virtual bool eqne_op() const { return false; }
592  virtual bool l_op() const { return false; }
593 };
594 
595 class Le_creator : public Comp_creator {
596  public:
597  virtual Item_bool_func *create(Item *a, Item *b) const;
598  virtual const char *symbol(bool invert) const { return invert ? ">" : "<="; }
599  virtual bool eqne_op() const { return false; }
600  virtual bool l_op() const { return true; }
601 };
602 
603 class Item_bool_func2 : public Item_bool_func { /* Bool with 2 string args */
604  private:
605  bool convert_constant_arg(THD *thd, Item *field, Item **item,
606  bool *converted);
607 
608  protected:
611 
612  public:
614  : Item_bool_func(a, b), cmp(tmp_arg, tmp_arg + 1), abort_on_null(false) {}
615 
616  Item_bool_func2(const POS &pos, Item *a, Item *b)
617  : Item_bool_func(pos, a, b),
618  cmp(tmp_arg, tmp_arg + 1),
619  abort_on_null(false) {}
620 
621  bool resolve_type(THD *) override;
622  bool set_cmp_func() {
623  return cmp.set_cmp_func(this, tmp_arg, tmp_arg + 1, true);
624  }
625  /**
626  When comparing strings, compare at most max_str_length bytes.
627  @param max_str_length how much to compare
628  */
629  void set_max_str_length(size_t max_str_length) {
630  return cmp.set_max_str_length(max_str_length);
631  }
632  optimize_type select_optimize(const THD *) override { return OPTIMIZE_OP; }
633  /// @returns an operator REV_OP so that "B REV_OP A" is equivalent to
634  /// "A this_operator B".
635  virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; }
636  bool have_rev_func() const override { return rev_functype() != UNKNOWN_FUNC; }
637 
638  void print(const THD *thd, String *str,
639  enum_query_type query_type) const override {
640  Item_func::print_op(thd, str, query_type);
641  }
642 
643  bool is_null() override { return args[0]->is_null() || args[1]->is_null(); }
644  const CHARSET_INFO *compare_collation() const override {
645  return cmp.cmp_collation.collation;
646  }
647  Item_result compare_type() const { return cmp.get_compare_type(); }
648  void apply_is_true() override { abort_on_null = true; }
649  /// Treat UNKNOWN result like FALSE because callers see no difference
650  bool ignore_unknown() const { return abort_on_null; }
651  void cleanup() override {
653  cmp.cleanup();
654  }
655  const Arg_comparator *get_comparator() const { return &cmp; }
656  Item *replace_scalar_subquery(uchar *) override;
657  friend class Arg_comparator;
658 };
659 
660 /**
661  Item_func_comparison is a class for comparison functions that take two
662  arguments and return a boolean result.
663  It is a common class for the regular comparison operators (=, <>, <, <=,
664  >, >=) as well as the special <=> equality operator.
665 */
667  public:
669  allowed_arg_cols = 0; // Fetch this value from first argument
670  }
672  : Item_bool_func2(pos, a, b) {
673  allowed_arg_cols = 0; // Fetch this value from first argument
674  }
675 
676  Item *truth_transformer(THD *, Bool_test) override;
677  virtual Item *negated_item();
678  bool subst_argument_checker(uchar **) override { return true; }
679  bool is_null() override;
680 
681  bool cast_incompatible_args(uchar *) override;
682  bool contains_only_equi_join_condition() const override;
683 };
684 
685 /**
686  XOR inherits from Item_bool_func2 because it is not optimized yet.
687  Later, when XOR is optimized, it needs to inherit from
688  Item_cond instead. See WL#5800.
689 */
692 
693  public:
694  Item_func_xor(Item *i1, Item *i2) : Item_bool_func2(i1, i2) {}
695  Item_func_xor(const POS &pos, Item *i1, Item *i2)
696  : Item_bool_func2(pos, i1, i2) {}
697 
698  enum Functype functype() const override { return XOR_FUNC; }
699  const char *func_name() const override { return "xor"; }
700  bool itemize(Parse_context *pc, Item **res) override;
701  longlong val_int() override;
702  void apply_is_true() override {}
703  Item *truth_transformer(THD *, Bool_test) override;
704 
705  float get_filtering_effect(THD *thd, table_map filter_for_table,
706  table_map read_tables,
707  const MY_BITMAP *fields_to_ignore,
708  double rows_in_table) override;
709 };
710 
712  public:
714  Item_func_not(const POS &pos, Item *a) : Item_bool_func(pos, a) {}
715 
716  longlong val_int() override;
717  enum Functype functype() const override { return NOT_FUNC; }
718  const char *func_name() const override { return "not"; }
719  Item *truth_transformer(THD *, Bool_test) override;
720  void print(const THD *thd, String *str,
721  enum_query_type query_type) const override;
722 
723  float get_filtering_effect(THD *thd, table_map filter_for_table,
724  table_map read_tables,
725  const MY_BITMAP *fields_to_ignore,
726  double rows_in_table) override;
727 };
728 
729 /**
730  Wrapper class when MATCH function is used in WHERE clause.
731  The MATCH clause can be used as a function returning a floating point value
732  in the SELECT list or in the WHERE clause. However, it may also be used as
733  a boolean function in the WHERE clause, where it has different semantics than
734  when used together with a comparison operator. With a comparison operator,
735  the match operation is performed with ranking. To preserve this behavior,
736  the Item_func_match object is wrapped inside an object of class
737  Item_func_match_predicate, which effectively transforms the function into
738  a predicate. The overridden functions implemented in this class generally
739  forward all evaluation to the underlying object.
740 */
742  public:
744 
745  longlong val_int() override { return args[0]->val_int(); }
746  enum Functype functype() const override { return MATCH_FUNC; }
747  const char *func_name() const override { return "match"; }
748  void print(const THD *thd, String *str,
749  enum_query_type query_type) const override {
750  args[0]->print(thd, str, query_type);
751  }
752 
753  float get_filtering_effect(THD *thd, table_map filter_for_table,
754  table_map read_tables,
755  const MY_BITMAP *fields_to_ignore,
756  double rows_in_table) override {
757  return args[0]->get_filtering_effect(thd, filter_for_table, read_tables,
758  fields_to_ignore, rows_in_table);
759  }
760 };
762 class JOIN;
763 
764 /*
765  trigcond<param>(arg) ::= param? arg : true
766 
767  The class Item_func_trig_cond is used for guarded predicates
768  which are employed only for internal purposes.
769  A guarded predicate is an object consisting of an a regular or
770  a guarded predicate P and a pointer to a boolean guard variable g.
771  A guarded predicate P/g is evaluated to true if the value of the
772  guard g is false, otherwise it is evaluated to the same value that
773  the predicate P: val(P/g)= g ? val(P):true.
774  Guarded predicates allow us to include predicates into a conjunction
775  conditionally. Currently they are utilized for pushed down predicates
776  in queries with outer join operations.
777 
778  In the future, probably, it makes sense to extend this class to
779  the objects consisting of three elements: a predicate P, a pointer
780  to a variable g and a firing value s with following evaluation
781  rule: val(P/g,s)= g==s? val(P) : true. It will allow us to build only
782  one item for the objects of the form P/g1/g2...
783 
784  Objects of this class are built only for query execution after
785  the execution plan has been already selected. That's why this
786  class needs only val_int out of generic methods.
787 
788  Current uses of Item_func_trig_cond objects:
789  - To wrap selection conditions when executing outer joins
790  - To wrap condition that is pushed down into subquery
791 */
792 
794  public:
796  /**
797  This trigger type deactivates join conditions when a row has been
798  NULL-complemented. For example, in t1 LEFT JOIN t2, the join condition
799  can be tested on t2's row only if that row is not NULL-complemented.
800  */
802 
803  /**
804  This trigger type deactivates predicated from WHERE condition when no
805  row satisfying the join condition has been found. For Example, in t1
806  LEFT JOIN t2, the where condition pushed to t2 can be tested only after
807  at least one t2 row has been produced, which may be a NULL-complemented
808  row.
809  */
811 
812  /**
813  In IN->EXISTS subquery transformation, new predicates are added:
814  WHERE inner_field=outer_field OR inner_field IS NULL,
815  as well as
816  HAVING inner_field IS NOT NULL,
817  are disabled if outer_field is a NULL value
818  */
819  OUTER_FIELD_IS_NOT_NULL
820  };
821 
822  private:
823  /** Pointer to trigger variable */
824  bool *trig_var;
825  /// Optional: JOIN of table which is the source of trig_var
826  const JOIN *m_join;
827  /// Optional: if join!=NULL: index of table
829  /** Type of trig_var; for printing */
831 
832  public:
833  /**
834  @param a the item for @<condition@>
835  @param f pointer to trigger variable
836  @param join if a table's property is the source of 'f', JOIN
837  which owns this table; NULL otherwise.
838  @param idx if join!=NULL: index of this table in the
839  JOIN_TAB/QEP_TAB array. NO_PLAN_IDX otherwise.
840  @param trig_type_arg type of 'f'
841  */
842  Item_func_trig_cond(Item *a, bool *f, const JOIN *join, plan_idx idx,
843  enum_trig_type trig_type_arg)
844  : Item_bool_func(a),
845  trig_var(f),
846  m_join(join),
847  m_idx(idx),
848  trig_type(trig_type_arg) {}
849  longlong val_int() override;
850  enum Functype functype() const override { return TRIG_COND_FUNC; }
851  /// '@<if@>', to distinguish from the if() SQL function
852  const char *func_name() const override { return "<if>"; }
853  /// Get range of inner tables spanned by associated outer join operation
854  void get_table_range(TABLE_LIST **first_table, TABLE_LIST **last_table) const;
855  /// Get table_map of inner tables spanned by associated outer join operation
856  table_map get_inner_tables() const;
857  bool fix_fields(THD *thd, Item **ref) override {
858  if (Item_bool_func::fix_fields(thd, ref)) return true;
859  add_trig_func_tables();
860  return false;
861  }
863  if (trig_type == IS_NOT_NULL_COMPL || trig_type == FOUND_MATCH) {
864  DBUG_ASSERT(m_join != nullptr);
865  // Make this function dependent on the inner tables
866  used_tables_cache |= get_inner_tables();
867  } else if (trig_type == OUTER_FIELD_IS_NOT_NULL) {
868  used_tables_cache |= OUTER_REF_TABLE_BIT;
869  }
870  }
871  void update_used_tables() override {
873  add_trig_func_tables();
874  }
875  const JOIN *get_join() const { return m_join; }
876  enum enum_trig_type get_trig_type() const { return trig_type; }
877  bool *get_trig_var() { return trig_var; }
878  enum_trig_type get_trig_type() { return trig_type; }
879  void print(const THD *thd, String *str,
880  enum_query_type query_type) const override;
881  plan_idx idx() const { return m_idx; }
882 
883  bool contains_only_equi_join_condition() const override;
884 };
885 
887  /* allow to check presence of values in max/min optimization */
892 
893  public:
894  bool show;
895 
897  : Item_func_not(a),
898  test_sum_item(nullptr),
899  test_sub_item(nullptr),
900  subselect(nullptr),
901  abort_on_null(false),
902  show(false) {}
903  void apply_is_true() override { abort_on_null = true; }
904  /// Treat UNKNOWN result like FALSE because callers see no difference
905  bool ignore_unknown() const { return abort_on_null; }
906  longlong val_int() override;
907  enum Functype functype() const override { return NOT_ALL_FUNC; }
908  const char *func_name() const override { return "<not>"; }
909  void print(const THD *thd, String *str,
910  enum_query_type query_type) const override;
911  void set_sum_test(Item_sum_hybrid *item) { test_sum_item = item; }
912  void set_sub_test(Item_maxmin_subselect *item) { test_sub_item = item; }
913  void set_subselect(Item_subselect *item) { subselect = item; }
914  table_map not_null_tables() const override {
915  /*
916  See handling of not_null_tables_cache in
917  Item_in_optimizer::fix_fields().
918 
919  This item is the result of a transformation from an ALL clause
920  such as
921  left-expr < ALL(subquery)
922  into
923  <not>(left-expr >= ANY(subquery)
924 
925  An inequality usually rejects NULLs from both operands, so the
926  not_null_tables() of the inequality is the union of the
927  null-rejecting tables of both operands. However, since this is a
928  transformed ALL clause that should return true if the subquery
929  is empty (even if left-expr is NULL), it is not null rejecting
930  for left-expr. The not null tables mask for left-expr should be
931  removed, leaving only the null-rejecting tables of the
932  subquery. Item_subselect::not_null_tables() always returns 0 (no
933  null-rejecting tables). Therefore, always return 0.
934  */
935  return 0;
936  }
937  bool empty_underlying_subquery();
938  Item *truth_transformer(THD *, Bool_test) override;
939 };
940 
942  public:
944  longlong val_int() override;
945  const char *func_name() const override { return "<nop>"; }
946  table_map not_null_tables() const override { return not_null_tables_cache; }
947  Item *truth_transformer(THD *, Bool_test) override;
948 };
949 
950 /**
951  Implements the comparison operator equals (=)
952 */
954  public:
956  Item_func_eq(const POS &pos, Item *a, Item *b)
957  : Item_func_comparison(pos, a, b) {}
958  longlong val_int() override;
959  enum Functype functype() const override { return EQ_FUNC; }
960  enum Functype rev_functype() const override { return EQ_FUNC; }
961  cond_result eq_cmp_result() const override { return COND_TRUE; }
962  const char *func_name() const override { return "="; }
963  Item *negated_item() override;
964  bool equality_substitution_analyzer(uchar **) override { return true; }
965  Item *equality_substitution_transformer(uchar *arg) override;
966  bool gc_subst_analyzer(uchar **) override { return true; }
967 
968  float get_filtering_effect(THD *thd, table_map filter_for_table,
969  table_map read_tables,
970  const MY_BITMAP *fields_to_ignore,
971  double rows_in_table) override;
972 
973  /// Read the value from the join condition, and append it to the output vector
974  /// "join_key_buffer". The function will determine which side of the condition
975  /// to read the value from by using the bitmap "tables".
976  ///
977  /// @param thd the thread handler
978  /// @param tables a bitmap that marks the tables that are involved in the join
979  /// @param join_condition an isntance containing the join condition together
980  /// with some pre-calculated values
981  /// @param[out] join_key_buffer a buffer where the value from the join
982  /// condition will be appended
983  ///
984  /// @returns true if an SQL NULL was encountered, false otherwise
985  bool append_join_key_for_hash_join(THD *thd, table_map tables,
987  String *join_key_buffer) const;
988 
989  /// Wrap the argument in a typecast, if needed.
990  ///
991  /// When computing a hash of the join value during a hash join, we want to
992  /// create a hash value that is memcmp-able. This is quite straightforward
993  /// for most data types, but it can be tricky for some types. For the
994  /// straightforward cases, this function just returns the argument it was
995  /// given in. For the complex cases, the function returns the given argument,
996  /// wrapped in a typecast node. Which typecast node it is wrapped in is
997  /// determined by the comparison context of this equality condition. The
998  /// comparison context is given by the member "cmp"; a comparator class that
999  /// is set up during query resolving.
1000  ///
1001  /// @param mem_root the MEM_ROOT where the typecast node is allocated
1002  /// @param argument the argument that we might wrap in a typecast. This is
1003  /// either the left or the right side of the Item_func_eq
1004  ///
1005  /// @returns either the argument it was given, or the argument wrapped in a
1006  /// typecast
1007  Item *create_cast_if_needed(MEM_ROOT *mem_root, Item *argument) const;
1008 
1009  /// See if this is a condition where any of the arguments refers to a field
1010  /// that is outside the bits marked by 'left_side_tables' and
1011  /// 'right_side_tables'.
1012  ///
1013  /// This is a situation that can happen during equality propagation in the
1014  /// optimization phase. Consider the following query:
1015  ///
1016  /// SELECT * FROM t1 LEFT JOIN
1017  /// (t2 LEFT JOIN t3 ON t3.i = t2.i) ON t2.i = t1.i;
1018  ///
1019  /// The optimizer will see that t1.i = t2.i = t3.i. Furthermore, it will
1020  /// replace one side of this condition with a field from a table that is as
1021  /// early in the join order as possible. However, this will break queries
1022  /// executed in the iterator executor. The above query will end up with
1023  /// something like this after optimization:
1024  ///
1025  /// Left hash join <--- t1.i = t2.i
1026  /// | |
1027  /// t1 Left hash join <--- t1.i = t3.i
1028  /// | |
1029  /// t2 t3
1030  ///
1031  /// Note that 't2.i = t3.i' has been rewritten to 't1.i = t3.i'. When
1032  /// evaluating the join between t2 and t3, t1 is outside our reach!
1033  /// To overcome this, we must reverse the changes done by the equality
1034  /// propagation. It is possible to do so because during equality propagation,
1035  /// we save a list of all of the fields that were considered equal.
1037  table_map right_side_tables);
1038 };
1039 
1040 /**
1041  The <=> operator evaluates the same as
1042 
1043  a IS NULL || b IS NULL ? a IS NULL == b IS NULL : a = b
1044 
1045  a <=> b is equivalent to the standard operation a IS NOT DISTINCT FROM b.
1046 
1047  Notice that the result is TRUE or FALSE, and never UNKNOWN.
1048 */
1050  public:
1052  null_on_null = false;
1053  }
1054  Item_func_equal(const POS &pos, Item *a, Item *b)
1055  : Item_func_comparison(pos, a, b) {
1056  null_on_null = false;
1057  }
1058  longlong val_int() override;
1059  bool resolve_type(THD *thd) override;
1060  enum Functype functype() const override { return EQUAL_FUNC; }
1061  enum Functype rev_functype() const override { return EQUAL_FUNC; }
1062  cond_result eq_cmp_result() const override { return COND_TRUE; }
1063  const char *func_name() const override { return "<=>"; }
1064  Item *truth_transformer(THD *, Bool_test) override { return nullptr; }
1065 
1066  float get_filtering_effect(THD *thd, table_map filter_for_table,
1067  table_map read_tables,
1068  const MY_BITMAP *fields_to_ignore,
1069  double rows_in_table) override;
1070 };
1071 
1072 /**
1073  Implements the comparison operator greater than or equals (>=)
1074 */
1076  public:
1078  longlong val_int() override;
1079  enum Functype functype() const override { return GE_FUNC; }
1080  enum Functype rev_functype() const override { return LE_FUNC; }
1081  cond_result eq_cmp_result() const override { return COND_TRUE; }
1082  const char *func_name() const override { return ">="; }
1083  Item *negated_item() override;
1084  bool gc_subst_analyzer(uchar **) override { return true; }
1085 
1086  float get_filtering_effect(THD *thd, table_map filter_for_table,
1087  table_map read_tables,
1088  const MY_BITMAP *fields_to_ignore,
1089  double rows_in_table) override;
1090 };
1091 
1092 /**
1093  Implements the comparison operator greater than (>)
1094 */
1096  public:
1098  longlong val_int() override;
1099  enum Functype functype() const override { return GT_FUNC; }
1100  enum Functype rev_functype() const override { return LT_FUNC; }
1101  cond_result eq_cmp_result() const override { return COND_FALSE; }
1102  const char *func_name() const override { return ">"; }
1103  Item *negated_item() override;
1104  bool gc_subst_analyzer(uchar **) override { return true; }
1105 
1106  float get_filtering_effect(THD *thd, table_map filter_for_table,
1107  table_map read_tables,
1108  const MY_BITMAP *fields_to_ignore,
1109  double rows_in_table) override;
1110 };
1111 
1112 /**
1113  Implements the comparison operator less than or equals (<=)
1114 */
1116  public:
1118  longlong val_int() override;
1119  enum Functype functype() const override { return LE_FUNC; }
1120  enum Functype rev_functype() const override { return GE_FUNC; }
1121  cond_result eq_cmp_result() const override { return COND_TRUE; }
1122  const char *func_name() const override { return "<="; }
1123  Item *negated_item() override;
1124  bool gc_subst_analyzer(uchar **) override { return true; }
1125 
1126  float get_filtering_effect(THD *thd, table_map filter_for_table,
1127  table_map read_tables,
1128  const MY_BITMAP *fields_to_ignore,
1129  double rows_in_table) override;
1130 };
1131 
1132 /**
1133  Implements the comparison operator less than (<)
1134 */
1136  public:
1138  longlong val_int() override;
1139  enum Functype functype() const override { return LT_FUNC; }
1140  enum Functype rev_functype() const override { return GT_FUNC; }
1141  cond_result eq_cmp_result() const override { return COND_FALSE; }
1142  const char *func_name() const override { return "<"; }
1143  Item *negated_item() override;
1144  bool gc_subst_analyzer(uchar **) override { return true; }
1145 
1146  float get_filtering_effect(THD *thd, table_map filter_for_table,
1147  table_map read_tables,
1148  const MY_BITMAP *fields_to_ignore,
1149  double rows_in_table) override;
1150 };
1151 
1152 /**
1153  Implements the comparison operator not equals (<>)
1154 */
1156  public:
1158  longlong val_int() override;
1159  enum Functype functype() const override { return NE_FUNC; }
1160  enum Functype rev_functype() const override { return NE_FUNC; }
1161  cond_result eq_cmp_result() const override { return COND_FALSE; }
1162  optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
1163  const char *func_name() const override { return "<>"; }
1164  Item *negated_item() override;
1165 
1166  float get_filtering_effect(THD *thd, table_map filter_for_table,
1167  table_map read_tables,
1168  const MY_BITMAP *fields_to_ignore,
1169  double rows_in_table) override;
1170 };
1171 
1172 /*
1173  The class Item_func_opt_neg is defined to factor out the functionality
1174  common for the classes Item_func_between and Item_func_in. The objects
1175  of these classes can express predicates or their negations.
1176  The alternative approach would be to create pairs Item_func_between,
1177  Item_func_notbetween and Item_func_in, Item_func_notin.
1178 
1179 */
1180 
1182  public:
1183  bool negated; /* <=> the item represents NOT <func> */
1184  bool pred_level; /* <=> [NOT] <func> is used on a predicate level */
1185  public:
1186  Item_func_opt_neg(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
1187  : Item_int_func(pos, a, b, c), negated(false), pred_level(false) {
1188  if (is_negation) negate();
1189  }
1190  Item_func_opt_neg(const POS &pos, PT_item_list *list, bool is_negation)
1191  : Item_int_func(pos, list), negated(false), pred_level(false) {
1192  if (is_negation) negate();
1193  }
1194 
1195  public:
1196  inline void negate() { negated = !negated; }
1197  inline void apply_is_true() override { pred_level = true; }
1198  bool ignore_unknown() const { return pred_level; }
1199  Item *truth_transformer(THD *, Bool_test test) override {
1200  if (test != BOOL_NEGATED) return nullptr;
1201  negated = !negated;
1202  return this;
1203  }
1204  bool eq(const Item *item, bool binary_cmp) const override;
1205  bool subst_argument_checker(uchar **) override { return true; }
1206 };
1207 
1210 
1211  public:
1213  String value0, value1, value2;
1214  /* true <=> arguments will be compared as dates. */
1218 
1219  /* Comparators used for DATE/DATETIME comparison. */
1221  Item_func_between(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
1222  : Item_func_opt_neg(pos, a, b, c, is_negation),
1223  compare_as_dates_with_strings(false),
1224  compare_as_temporal_dates(false),
1225  compare_as_temporal_times(false) {}
1226  longlong val_int() override;
1227  optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
1228  enum Functype functype() const override { return BETWEEN; }
1229  const char *func_name() const override { return "between"; }
1230  bool fix_fields(THD *, Item **) override;
1231  void fix_after_pullout(SELECT_LEX *parent_select,
1232  SELECT_LEX *removed_select) override;
1233  bool resolve_type(THD *) override;
1234  void print(const THD *thd, String *str,
1235  enum_query_type query_type) const override;
1236  bool is_bool_func() const override { return true; }
1237  const CHARSET_INFO *compare_collation() const override {
1238  return cmp_collation.collation;
1239  }
1240  uint decimal_precision() const override { return 1; }
1241  bool gc_subst_analyzer(uchar **) override { return true; }
1242 
1243  float get_filtering_effect(THD *thd, table_map filter_for_table,
1244  table_map read_tables,
1245  const MY_BITMAP *fields_to_ignore,
1246  double rows_in_table) override;
1247  void update_used_tables() override;
1248 
1250  // not_null_tables_cache == union(T1(e),T1(e1),T1(e2))
1251  if (pred_level && !negated) return;
1252 
1253  /// not_null_tables_cache == union(T1(e), intersection(T1(e1),T1(e2)))
1254  not_null_tables_cache =
1255  args[0]->not_null_tables() |
1256  (args[1]->not_null_tables() & args[2]->not_null_tables());
1257  }
1258 };
1259 
1261  public:
1263  : Item_bool_func2(pos, a, b) {}
1264  longlong val_int() override;
1265  optimize_type select_optimize(const THD *) override { return OPTIMIZE_NONE; }
1266  const char *func_name() const override { return "strcmp"; }
1267  enum Functype functype() const override { return STRCMP_FUNC; }
1268 
1269  void print(const THD *thd, String *str,
1270  enum_query_type query_type) const override {
1271  Item_func::print(thd, str, query_type);
1272  }
1273  bool resolve_type(THD *thd) override {
1274  if (Item_bool_func2::resolve_type(thd)) return true;
1275  fix_char_length(2); // returns "1" or "0" or "-1"
1276  return false;
1277  }
1278 };
1279 
1282  double dbl;
1284 };
1285 
1288 
1292 
1293  public:
1295  Item *expr2, class PT_item_list *opt_expr_list = nullptr)
1296  : super(pos, alloc_row(pos, mem_root, expr1, expr2, opt_expr_list)),
1297  row(down_cast<Item_row *>(args[0])),
1298  intervals(nullptr) {
1299  allowed_arg_cols = 0; // Fetch this value from first argument
1300  }
1301 
1302  bool itemize(Parse_context *pc, Item **res) override;
1303  longlong val_int() override;
1304  bool resolve_type(THD *) override;
1305  const char *func_name() const override { return "interval"; }
1306  uint decimal_precision() const override { return 2; }
1307  void print(const THD *thd, String *str,
1308  enum_query_type query_type) const override;
1309  void update_used_tables() override;
1310 
1311  private:
1312  // Runs in CTOR init list, cannot access *this as Item_func_interval
1313  static Item_row *alloc_row(const POS &pos, MEM_ROOT *mem_root, Item *expr1,
1314  Item *expr2, class PT_item_list *opt_expr_list);
1315 };
1316 
1318  protected:
1320  : Item_func_numhybrid(pos, a, b) {
1321  null_on_null = false;
1322  }
1324  null_on_null = false;
1325  }
1326 
1327  public:
1329  : Item_func_numhybrid(pos, list) {
1330  null_on_null = false;
1331  }
1332  double real_op() override;
1333  longlong int_op() override;
1334  String *str_op(String *) override;
1335  /**
1336  Get the result of COALESCE as a JSON value.
1337  @param[in,out] wr the result value holder
1338  */
1339  bool val_json(Json_wrapper *wr) override;
1340  bool date_op(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1341  bool time_op(MYSQL_TIME *ltime) override;
1342  my_decimal *decimal_op(my_decimal *) override;
1343  bool resolve_type(THD *) override;
1344  void set_numeric_type() override {}
1345  enum Item_result result_type() const override { return hybrid_type; }
1346  const char *func_name() const override { return "coalesce"; }
1347  enum Functype functype() const override { return COALESCE_FUNC; }
1348 };
1349 
1351  protected:
1353 
1354  public:
1356  : Item_func_coalesce(pos, a, b) {}
1357  double real_op() override;
1358  longlong int_op() override;
1359  String *str_op(String *str) override;
1360  bool date_op(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1361  bool time_op(MYSQL_TIME *ltime) override;
1362  my_decimal *decimal_op(my_decimal *) override;
1363  bool val_json(Json_wrapper *result) override;
1364  const char *func_name() const override { return "ifnull"; }
1365  Field *tmp_table_field(TABLE *table) override;
1366  uint decimal_precision() const override;
1367 };
1368 
1369 /**
1370  ANY_VALUE(expr) is like expr except that it is not checked by
1371  aggregate_check logic. It serves as a solution for users who want to
1372  bypass this logic.
1373 */
1375  public:
1377  const char *func_name() const override { return "any_value"; }
1378  bool aggregate_check_group(uchar *arg) override;
1379  bool aggregate_check_distinct(uchar *arg) override;
1380 };
1381 
1382 class Item_func_if final : public Item_func {
1383  enum Item_result cached_result_type;
1384 
1385  public:
1387  : Item_func(a, b, c), cached_result_type(INT_RESULT) {
1388  null_on_null = false;
1389  }
1390  Item_func_if(const POS &pos, Item *a, Item *b, Item *c)
1391  : Item_func(pos, a, b, c), cached_result_type(INT_RESULT) {
1392  null_on_null = false;
1393  }
1394 
1395  double val_real() override;
1396  longlong val_int() override;
1397  String *val_str(String *str) override;
1398  my_decimal *val_decimal(my_decimal *) override;
1399  bool val_json(Json_wrapper *wr) override;
1400  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1401  bool get_time(MYSQL_TIME *ltime) override;
1402  enum Item_result result_type() const override { return cached_result_type; }
1403  bool fix_fields(THD *, Item **) override;
1404  bool resolve_type(THD *) override;
1405  void fix_after_pullout(SELECT_LEX *parent_select,
1406  SELECT_LEX *removed_select) override;
1407  uint decimal_precision() const override;
1408  const char *func_name() const override { return "if"; }
1409  enum Functype functype() const override { return IF_FUNC; }
1410  void update_used_tables() override;
1411 
1412  ///< T1(IF(e,e1,e2)) = intersection(T1(e1),T1(e2))
1414  not_null_tables_cache =
1415  (args[1]->not_null_tables() & args[2]->not_null_tables());
1416  }
1417 };
1418 
1420  enum Item_result cached_result_type;
1421 
1422  public:
1424  : Item_bool_func2(pos, a, b), cached_result_type(INT_RESULT) {
1425  null_on_null = false;
1426  }
1427  double val_real() override;
1428  longlong val_int() override;
1429  String *val_str(String *str) override;
1430  my_decimal *val_decimal(my_decimal *) override;
1431  bool val_json(Json_wrapper *wr) override;
1432  Item_result result_type() const override { return cached_result_type; }
1433  bool resolve_type(THD *thd) override;
1434  uint decimal_precision() const override {
1435  return args[0]->decimal_precision();
1436  }
1437  const char *func_name() const override { return "nullif"; }
1438  enum Functype functype() const override { return NULLIF_FUNC; }
1439 
1440  void print(const THD *thd, String *str,
1441  enum_query_type query_type) const override {
1442  Item_func::print(thd, str, query_type);
1443  }
1444 
1445  bool is_null() override;
1446  /**
1447  This is a workaround for the broken inheritance hierarchy: this should
1448  inherit from Item_func instead of Item_bool_func2
1449  */
1450  bool is_bool_func() const override { return false; }
1451 };
1452 
1453 /* Functions to handle the optimized IN */
1454 
1455 /* A vector of values of some type */
1456 
1457 class in_vector {
1458  private:
1459  const uint count; ///< Original size of the vector
1460  public:
1461  uint used_count; ///< The actual size of the vector (NULL may be ignored)
1462 
1463  /**
1464  See Item_func_in::resolve_type() for why we need both
1465  count and used_count.
1466  */
1467  explicit in_vector(uint elements) : count(elements), used_count(elements) {}
1468 
1469  virtual ~in_vector() {}
1470 
1471  /**
1472  Calls item->val_int() or item->val_str() etc.
1473  and then does binary_search if the value is non-null.
1474  @param item to evaluate, and lookup in the IN-list.
1475  @return true if evaluated value of the item was found.
1476  */
1477  virtual bool find_item(Item *item) = 0;
1478 
1479  /**
1480  Create an instance of Item_{type} (e.g. Item_decimal) constant object
1481  which type allows it to hold an element of this vector without any
1482  conversions.
1483  The purpose of this function is to be able to get elements of this
1484  vector in form of Item_xxx constants without creating Item_xxx object
1485  for every array element you get (i.e. this implements "FlyWeight" pattern)
1486 
1487  @param mem_root Where to allocate the Item.
1488  */
1489  virtual Item_basic_constant *create_item(MEM_ROOT *mem_root) const = 0;
1490 
1491  /**
1492  Store the value at position #pos into provided item object
1493 
1494  @param pos Index of value to store
1495  @param item Constant item to store value into. The item must be of the same
1496  type that create_item() returns.
1497  */
1498  virtual void value_to_item(uint pos, Item_basic_constant *item) const = 0;
1499 
1500  /** Compare values number pos1 and pos2 for equality */
1501  virtual bool compare_elems(uint pos1, uint pos2) const = 0;
1502 
1503  virtual bool is_row_result() const { return false; }
1504 
1505  /**
1506  Fill the vector by evaluating the items passed as arguments.
1507  Note that null values are skipped so the vector may end up containing
1508  fewer elements than the number of items.
1509  The vector is sorted so that it can be used for binary search.
1510 
1511  @param items Items to evaluate
1512  @param item_count Number of items
1513 
1514  @return true if any null values was found, false otherwise.
1515  */
1516  bool fill(Item **items, uint item_count);
1517 
1518  private:
1519  virtual void set(uint pos, Item *item) = 0;
1520 
1521  /**
1522  Resize and then sort the IN-list array, so we can do efficient lookup with
1523  binary_search.
1524  */
1525  virtual void resize_and_sort() = 0;
1526 };
1527 
1528 class in_string final : public in_vector {
1532  // String objects are not sortable, sort pointers instead.
1535 
1536  public:
1537  in_string(MEM_ROOT *mem_root, uint elements, const CHARSET_INFO *cs);
1539  return new (mem_root) Item_string(collation);
1540  }
1541  void value_to_item(uint pos, Item_basic_constant *item) const override {
1542  item->set_str_value(base_pointers[pos]);
1543  }
1544  bool find_item(Item *item) override;
1545  bool compare_elems(uint pos1, uint pos2) const override;
1546 
1547  private:
1548  void set(uint pos, Item *item) override;
1549  void resize_and_sort() override;
1550 };
1551 
1552 class in_longlong : public in_vector {
1553  public:
1557  };
1558 
1559  protected:
1561 
1562  public:
1564  : in_vector(elements), base(mem_root, elements) {}
1566  /*
1567  We've created a signed INT, this may not be correct in the
1568  general case (see BUG#19342).
1569  */
1570  return new (mem_root) Item_int(0LL);
1571  }
1572  void value_to_item(uint pos, Item_basic_constant *item) const override {
1573  down_cast<Item_int *>(item)->value = base[pos].val;
1574  item->unsigned_flag = base[pos].unsigned_flag;
1575  }
1576  bool find_item(Item *item) override;
1577  bool compare_elems(uint pos1, uint pos2) const override;
1578 
1579  private:
1580  void set(uint pos, Item *item) override { val_item(item, &base[pos]); }
1581  void resize_and_sort() override;
1582  virtual void val_item(Item *item, packed_longlong *result);
1583 };
1584 
1586  public:
1588  : in_longlong(mem_root, elements) {}
1590  return new (mem_root) Item_temporal(MYSQL_TYPE_DATETIME, 0LL);
1591  }
1592 
1593  private:
1594  void val_item(Item *item, packed_longlong *result) override;
1595 };
1596 
1598  public:
1600  : in_longlong(mem_root, elements) {}
1602  return new (mem_root) Item_temporal(MYSQL_TYPE_TIME, 0LL);
1603  }
1604 
1605  private:
1606  void val_item(Item *item, packed_longlong *result) override;
1607 };
1608 
1609 /*
1610  Class to represent a vector of constant DATE/DATETIME values.
1611  Values are obtained with help of the get_datetime_value() function.
1612  If the left item is a constant one then its value is cached in the
1613  lval_cache variable.
1614 */
1616  /* An item used to issue warnings. */
1618  /* Cache for the left item. */
1620 
1621  public:
1622  in_datetime(MEM_ROOT *mem_root, Item *warn_item_arg, uint elements)
1623  : in_longlong(mem_root, elements),
1624  warn_item(warn_item_arg),
1625  lval_cache(nullptr) {}
1627  return new (mem_root) Item_temporal(MYSQL_TYPE_DATETIME, 0LL);
1628  }
1629 
1630  private:
1631  void set(uint pos, Item *item) override;
1632  void val_item(Item *item, packed_longlong *result) override;
1633 };
1634 
1635 class in_double final : public in_vector {
1637 
1638  public:
1640  : in_vector(elements), base(mem_root, elements) {}
1642  return new (mem_root) Item_float(0.0, 0);
1643  }
1644  void value_to_item(uint pos, Item_basic_constant *item) const override {
1645  down_cast<Item_float *>(item)->value = base[pos];
1646  }
1647  bool find_item(Item *item) override;
1648  bool compare_elems(uint pos1, uint pos2) const override;
1649 
1650  private:
1651  void set(uint pos, Item *item) override;
1652  void resize_and_sort() override;
1653 };
1654 
1655 class in_decimal final : public in_vector {
1657 
1658  public:
1660  : in_vector(elements), base(mem_root, elements) {}
1662  return new (mem_root) Item_decimal(0, false);
1663  }
1664  void value_to_item(uint pos, Item_basic_constant *item) const override {
1665  down_cast<Item_decimal *>(item)->set_decimal_value(&base[pos]);
1666  }
1667  bool find_item(Item *item) override;
1668  bool compare_elems(uint pos1, uint pos2) const override;
1669 
1670  private:
1671  void set(uint pos, Item *item) override;
1672  void resize_and_sort() override;
1673 };
1674 
1675 /*
1676 ** Classes for easy comparing of non const items
1677 */
1678 
1679 class cmp_item {
1680  public:
1682  virtual ~cmp_item() {}
1683  virtual void store_value(Item *item) = 0;
1684  /**
1685  @returns result (true, false or UNKNOWN) of
1686  "stored argument's value <> item's value"
1687  */
1688  virtual int cmp(Item *item) = 0;
1689  // for optimized IN with row
1690  virtual int compare(const cmp_item *item) const = 0;
1691 
1692  /**
1693  Find the appropriate comparator for the given type.
1694 
1695  @param result_type Used to find the appropriate comparator.
1696  @param item Item object used to distinguish temporal types.
1697  @param cs Charset
1698 
1699  @return
1700  New cmp_item_xxx object.
1701  */
1702  static cmp_item *get_comparator(Item_result result_type, const Item *item,
1703  const CHARSET_INFO *cs);
1704  virtual cmp_item *make_same() = 0;
1705  virtual void store_value_by_template(cmp_item *, Item *item) {
1706  store_value(item);
1707  }
1708 };
1709 
1710 /// cmp_item which stores a scalar (i.e. non-ROW).
1711 class cmp_item_scalar : public cmp_item {
1712  protected:
1713  bool m_null_value; ///< If stored value is NULL
1714  void set_null_value(bool nv) { m_null_value = nv; }
1715 };
1716 
1718  private:
1722 
1723  public:
1724  cmp_item_string(const CHARSET_INFO *cs) : value(cs), cmp_charset(cs) {}
1725 
1726  virtual int compare(const cmp_item *ci) const {
1727  const cmp_item_string *l_cmp = down_cast<const cmp_item_string *>(ci);
1728  return sortcmp(value_res, l_cmp->value_res, cmp_charset);
1729  }
1730 
1731  virtual void store_value(Item *item) {
1732  String *res = item->val_str(&value);
1733  if (res && (res != &value || !res->is_alloced())) {
1734  // 'res' may point in item's transient internal data, so make a copy
1735  value.copy(*res);
1736  }
1737  value_res = &value;
1738  set_null_value(item->null_value);
1739  }
1740 
1741  virtual int cmp(Item *arg) {
1742  StringBuffer<STRING_BUFFER_USUAL_SIZE> tmp(cmp_charset);
1743  String *res = arg->val_str(&tmp);
1744  if (m_null_value || arg->null_value) return UNKNOWN;
1745  if (value_res && res)
1746  return sortcmp(value_res, res, cmp_charset) != 0;
1747  else if (!value_res && !res)
1748  return false;
1749  else
1750  return true;
1751  }
1752  virtual cmp_item *make_same();
1753 };
1754 
1756  private:
1757  /// Cached JSON value to look up
1759  /// Cache for the value above
1761  /// String buffer
1763 
1764  public:
1765  /**
1766  Construct a cmp_item_json object.
1767  @param wrapper a Json_wrapper for holding the JSON value in the comparison
1768  @param holder pre-alloced memory for creating JSON scalar values without
1769  using the heap
1770  */
1773  ~cmp_item_json() override;
1774 
1775  int compare(const cmp_item *ci) const override;
1776  void store_value(Item *item) override;
1777  int cmp(Item *arg) override;
1778  cmp_item *make_same() override;
1779 };
1780 
1783 
1784  public:
1785  void store_value(Item *item) override {
1786  value = item->val_int();
1787  set_null_value(item->null_value);
1788  }
1789  int cmp(Item *arg) override {
1790  const bool rc = value != arg->val_int();
1791  return (m_null_value || arg->null_value) ? UNKNOWN : rc;
1792  }
1793  int compare(const cmp_item *ci) const override {
1794  const cmp_item_int *l_cmp = down_cast<const cmp_item_int *>(ci);
1795  return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
1796  }
1797  cmp_item *make_same() override;
1798 };
1799 
1800 /*
1801  Compare items of temporal type.
1802  Values are obtained with: get_datetime_value() (DATE/DATETIME/TIMESTAMP) and
1803  get_time_value() (TIME).
1804  If the left item is a constant one then its value is cached in the
1805  lval_cache variable.
1806 */
1809 
1810  public:
1811  /* Item used for issuing warnings. */
1812  const Item *warn_item;
1813  /* Cache for the left item. */
1815  /// Distinguish between DATE/DATETIME/TIMESTAMP and TIME
1816  bool has_date;
1817 
1818  cmp_item_datetime(const Item *warn_item_arg);
1819  void store_value(Item *item) override;
1820  int cmp(Item *arg) override;
1821  int compare(const cmp_item *ci) const override;
1822  cmp_item *make_same() override;
1823 };
1824 
1826  double value;
1827 
1828  public:
1829  void store_value(Item *item) override {
1830  value = item->val_real();
1831  set_null_value(item->null_value);
1832  }
1833  int cmp(Item *arg) override {
1834  const bool rc = value != arg->val_real();
1835  return (m_null_value || arg->null_value) ? UNKNOWN : rc;
1836  }
1837  int compare(const cmp_item *ci) const override {
1838  const cmp_item_real *l_cmp = down_cast<const cmp_item_real *>(ci);
1839  return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
1840  }
1841  cmp_item *make_same() override;
1842 };
1843 
1846 
1847  public:
1848  void store_value(Item *item);
1849  int cmp(Item *arg);
1850  int compare(const cmp_item *c) const;
1851  cmp_item *make_same();
1852 };
1853 
1854 /**
1855  CASE ... WHEN ... THEN ... END function implementation.
1856 
1857  When there is no expression between CASE and the first WHEN
1858  (the CASE expression) then this function simple checks all WHEN expressions
1859  one after another. When some WHEN expression evaluated to TRUE then the
1860  value of the corresponding THEN expression is returned.
1861 
1862  When the CASE expression is specified then it is compared to each WHEN
1863  expression individually. When an equal WHEN expression is found
1864  corresponding THEN expression is returned.
1865  In order to do correct comparisons several comparators are used. One for
1866  each result type. Different result types that are used in particular
1867  CASE ... END expression are collected in the resolve_type() member
1868  function and only comparators for there result types are used.
1869 */
1870 
1872  typedef Item_func super;
1873 
1874  int first_expr_num, else_expr_num;
1875  enum Item_result cached_result_type, left_result_type;
1880  cmp_item *cmp_items[5]; /* For all result types */
1882 
1883  public:
1884  Item_func_case(const POS &pos, List<Item> &list, Item *first_expr_arg,
1885  Item *else_expr_arg)
1886  : super(pos),
1887  first_expr_num(-1),
1888  else_expr_num(-1),
1889  cached_result_type(INT_RESULT),
1890  left_result_type(INT_RESULT),
1891  case_item(nullptr) {
1892  null_on_null = false;
1893  ncases = list.elements;
1894  if (first_expr_arg) {
1895  first_expr_num = list.elements;
1896  list.push_back(first_expr_arg);
1897  }
1898  if (else_expr_arg) {
1899  else_expr_num = list.elements;
1900  list.push_back(else_expr_arg);
1901  }
1902  set_arguments(list, true);
1903  memset(&cmp_items, 0, sizeof(cmp_items));
1904  }
1905  int get_first_expr_num() const { return first_expr_num; }
1906  int get_else_expr_num() const { return else_expr_num; }
1907  double val_real() override;
1908  longlong val_int() override;
1909  String *val_str(String *) override;
1910  my_decimal *val_decimal(my_decimal *) override;
1911  bool val_json(Json_wrapper *wr) override;
1912  bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1913  bool get_time(MYSQL_TIME *ltime) override;
1914  bool fix_fields(THD *thd, Item **ref) override;
1915  bool resolve_type(THD *) override;
1916  uint decimal_precision() const override;
1917  enum Item_result result_type() const override { return cached_result_type; }
1918  const char *func_name() const override { return "case"; }
1919  void print(const THD *thd, String *str,
1920  enum_query_type query_type) const override;
1921  Item *find_item(String *str);
1922  const CHARSET_INFO *compare_collation() const override {
1923  return cmp_collation.collation;
1924  }
1925  void cleanup() override;
1926  enum Functype functype() const override { return CASE_FUNC; }
1927 };
1928 
1929 /**
1930  in_expr [NOT] IN (in_value_list).
1931 
1932  The current implementation distinguishes 2 cases:
1933  1) all items in in_value_list are constants and have the same
1934  result type. This case is handled by in_vector class.
1935  2) otherwise Item_func_in employs several cmp_item objects to perform
1936  comparisons of in_expr and an item from in_value_list. One cmp_item
1937  object for each result type. Different result types are collected in the
1938  resolve_type() member function by means of collect_cmp_types() function.
1939 */
1941  public:
1942  /// An array of values, created when the bisection lookup method is used
1944  /**
1945  If there is some NULL among @<in value list@>, during a val_int() call; for
1946  example
1947  IN ( (1,(3,'col')), ... ), where 'col' is a column which evaluates to
1948  NULL.
1949  */
1951  /**
1952  Set to true by resolve_type() if the IN list contains a
1953  dependent subquery, in which case condition filtering will not be
1954  calculated for this item.
1955  */
1958  cmp_item *cmp_items[6]; /* One cmp_item for each result type */
1960 
1961  Item_func_in(const POS &pos, PT_item_list *list, bool is_negation)
1962  : Item_func_opt_neg(pos, list, is_negation),
1963  array(nullptr),
1964  have_null(false),
1965  dep_subq_in_list(false) {
1966  memset(&cmp_items, 0, sizeof(cmp_items));
1967  allowed_arg_cols = 0; // Fetch this value from first argument
1968  }
1969  longlong val_int() override;
1970  bool fix_fields(THD *, Item **) override;
1971  void fix_after_pullout(SELECT_LEX *parent_select,
1972  SELECT_LEX *removed_select) override;
1973  bool resolve_type(THD *) override;
1974  void update_used_tables() override;
1975  uint decimal_precision() const override { return 1; }
1976 
1977  /**
1978  Cleanup data and comparator arrays.
1979 
1980  @note Used during regular cleanup and to free arrays after GC substitution.
1981  @see substitute_gc().
1982  */
1984  uint i;
1985  destroy(array);
1986  array = nullptr;
1987  for (i = 0; i <= (uint)DECIMAL_RESULT + 1; i++) {
1988  destroy(cmp_items[i]);
1989  cmp_items[i] = nullptr;
1990  }
1991  }
1992 
1993  void cleanup() override {
1994  DBUG_TRACE;
1996  cleanup_arrays();
1997  return;
1998  }
1999  optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
2000  void print(const THD *thd, String *str,
2001  enum_query_type query_type) const override;
2002  enum Functype functype() const override { return IN_FUNC; }
2003  const char *func_name() const override { return " IN "; }
2004  bool is_bool_func() const override { return true; }
2005  const CHARSET_INFO *compare_collation() const override {
2006  return cmp_collation.collation;
2007  }
2008  bool gc_subst_analyzer(uchar **) override { return true; }
2009 
2010  float get_filtering_effect(THD *thd, table_map filter_for_table,
2011  table_map read_tables,
2012  const MY_BITMAP *fields_to_ignore,
2013  double rows_in_table) override;
2014 
2016  // not_null_tables_cache == union(T1(e),union(T1(ei)))
2017  if (pred_level && negated) return;
2018 
2019  not_null_tables_cache = ~(table_map)0;
2020 
2021  ///< not_null_tables_cache = union(T1(e),intersection(T1(ei)))
2022  Item **arg_end = args + arg_count;
2023  for (Item **arg = args + 1; arg != arg_end; arg++)
2024  not_null_tables_cache &= (*arg)->not_null_tables();
2025  not_null_tables_cache |= args[0]->not_null_tables();
2026  }
2027 
2028  private:
2029  /**
2030  Usable if @<in value list@> is made only of constants. Returns true if one
2031  of these constants contains a NULL. Example:
2032  IN ( (-5, (12,NULL)), ... ).
2033  */
2034  bool list_contains_null();
2035  /**
2036  Utility function to help calculate the total filtering effect of
2037  IN predicates. This function calculates the filtering effect from
2038  a single field (or field reference) on the left hand side of the
2039  expression.
2040 
2041  @param fieldref Field (or field reference) on left hand side of
2042  IN, i.e., this function should be called for
2043  each fi in "(f1,...,fn) IN (values)"
2044  @param filter_for_table The table we are calculating filter effect for
2045  @param fields_to_ignore Fields in 'filter_for_table' that should not
2046  be part of the filter calculation. The filtering
2047  effect of these fields are already part of the
2048  calculation somehow (e.g. because there is a
2049  predicate "col = <const>", and the optimizer
2050  has decided to do ref access on 'col').
2051  @param rows_in_table The number of rows in table 'filter_for_table'
2052 
2053  @return the filtering effect (between 0 and 1) 'the_field'
2054  participates with in this IN predicate.
2055  */
2056  float get_single_col_filtering_effect(Item_ident *fieldref,
2057  table_map filter_for_table,
2058  const MY_BITMAP *fields_to_ignore,
2059  double rows_in_table);
2060 };
2061 
2062 class cmp_item_row : public cmp_item {
2065 
2066  public:
2067  cmp_item_row() : comparators(nullptr), n(0) {}
2068  cmp_item_row(THD *thd, Item *item) : comparators(nullptr), n(item->cols()) {
2069  alloc_comparators(thd, item);
2070  }
2071  ~cmp_item_row();
2072 
2074  : comparators(other.comparators), n(other.n) {
2075  other.comparators = nullptr;
2076  other.n = 0;
2077  }
2078 
2079  void store_value(Item *item);
2080  int cmp(Item *arg);
2081  int compare(const cmp_item *arg) const;
2082  cmp_item *make_same();
2083  void store_value_by_template(cmp_item *tmpl, Item *);
2084  void set_comparator(uint col, cmp_item *comparator) {
2085  comparators[col] = comparator;
2086  }
2087 
2088  private:
2089  bool alloc_comparators(THD *thd, Item *item);
2090 };
2091 
2092 class in_row final : public in_vector {
2095  // Sort pointers, rather than objects.
2097 
2098  public:
2099  in_row(MEM_ROOT *mem_root, uint elements, cmp_item_row *cmp);
2100  bool is_row_result() const override { return true; }
2101  bool find_item(Item *item) override;
2102  bool compare_elems(uint pos1, uint pos2) const override;
2103  void set_comparator(uint col, cmp_item *comparator) {
2104  tmp->set_comparator(col, comparator);
2105  }
2107  DBUG_ASSERT(false);
2108  return nullptr;
2109  }
2110  void value_to_item(uint, Item_basic_constant *) const override {
2111  DBUG_ASSERT(false);
2112  }
2113 
2114  private:
2115  void set(uint pos, Item *item) override;
2116  void resize_and_sort() override;
2117 };
2118 
2119 /* Functions used by where clause */
2120 
2123 
2124  protected:
2126 
2127  public:
2128  Item_func_isnull(Item *a) : super(a) { null_on_null = false; }
2129  Item_func_isnull(const POS &pos, Item *a) : super(pos, a) {
2130  null_on_null = false;
2131  }
2132  longlong val_int() override;
2133  enum Functype functype() const override { return ISNULL_FUNC; }
2134  bool resolve_type(THD *thd) override;
2135  const char *func_name() const override { return "isnull"; }
2136  /* Optimize case of not_null_column IS NULL */
2137  void update_used_tables() override;
2138 
2139  float get_filtering_effect(THD *thd, table_map filter_for_table,
2140  table_map read_tables,
2141  const MY_BITMAP *fields_to_ignore,
2142  double rows_in_table) override;
2143  optimize_type select_optimize(const THD *) override { return OPTIMIZE_NULL; }
2144  Item *truth_transformer(THD *, Bool_test test) override;
2145  void print(const THD *thd, String *str,
2146  enum_query_type query_type) const override;
2147  const CHARSET_INFO *compare_collation() const override {
2148  return args[0]->collation.collation;
2149  }
2150  bool fix_fields(THD *thd, Item **ref) override;
2151 };
2152 
2153 /* Functions used by HAVING for rewriting IN subquery */
2154 
2155 /*
2156  This is like IS NOT NULL but it also remembers if it ever has
2157  encountered a NULL; it remembers this in the "was_null" property of the
2158  "owner" item.
2159 */
2162 
2163  public:
2165  : Item_func_isnull(a), owner(ow) {}
2166  enum Functype functype() const override { return ISNOTNULLTEST_FUNC; }
2167  longlong val_int() override;
2168  const char *func_name() const override { return "<is_not_null_test>"; }
2169  void update_used_tables() override;
2170  /**
2171  We add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE.
2172 
2173  @retval Always RAND_TABLE_BIT
2174  */
2176  return RAND_TABLE_BIT;
2177  }
2178  void print(const THD *thd, String *str,
2179  enum_query_type query_type) const override {
2180  Item_bool_func::print(thd, str, query_type);
2181  }
2182 };
2183 
2185  public:
2186  Item_func_isnotnull(Item *a) : Item_bool_func(a) { null_on_null = false; }
2188  null_on_null = false;
2189  }
2190 
2191  longlong val_int() override;
2192  enum Functype functype() const override { return ISNOTNULL_FUNC; }
2193  bool resolve_type(THD *) override {
2194  max_length = 1;
2195  maybe_null = false;
2196  return false;
2197  }
2198  const char *func_name() const override { return "isnotnull"; }
2199  optimize_type select_optimize(const THD *) override { return OPTIMIZE_NULL; }
2200  Item *truth_transformer(THD *, Bool_test test) override;
2201  void print(const THD *thd, String *str,
2202  enum_query_type query_type) const override;
2203  const CHARSET_INFO *compare_collation() const override {
2204  return args[0]->collation.collation;
2205  }
2206  void apply_is_true() override {
2207  null_on_null = true;
2208  } // Same logic as for Item_func_truth's function
2209  float get_filtering_effect(THD *thd, table_map filter_for_table,
2210  table_map read_tables,
2211  const MY_BITMAP *fields_to_ignore,
2212  double rows_in_table) override;
2213 };
2214 
2217 
2219 
2221 
2222  bool escape_evaluated; ///< Tells if the escape clause has been evaluated.
2223  bool eval_escape_clause(THD *thd);
2224 
2225  public:
2226  int escape;
2227 
2228  Item_func_like(Item *a, Item *b, Item *escape_arg, bool escape_used)
2229  : Item_bool_func2(a, b),
2230  escape_item(escape_arg),
2231  escape_used_in_parsing(escape_used),
2232  escape_evaluated(false) {}
2233  Item_func_like(const POS &pos, Item *a, Item *b, Item *opt_escape_arg)
2234  : super(pos, a, b),
2235  escape_item(opt_escape_arg),
2236  escape_used_in_parsing(opt_escape_arg != nullptr),
2237  escape_evaluated(false) {}
2238 
2239  bool itemize(Parse_context *pc, Item **res) override;
2240 
2241  longlong val_int() override;
2242  enum Functype functype() const override { return LIKE_FUNC; }
2243  optimize_type select_optimize(const THD *thd) override;
2244  cond_result eq_cmp_result() const override { return COND_TRUE; }
2245  const char *func_name() const override { return "like"; }
2246  bool fix_fields(THD *thd, Item **ref) override;
2247  bool resolve_type(THD *) override;
2248  void cleanup() override;
2249  Item *replace_scalar_subquery(uchar *) override;
2250  void update_used_tables() override;
2251  /**
2252  @retval true non default escape char specified
2253  using "expr LIKE pat ESCAPE 'escape_char'" syntax
2254  */
2255  bool escape_was_used_in_parsing() const { return escape_used_in_parsing; }
2256 
2257  /**
2258  Has the escape clause been evaluated? It only needs to be evaluated
2259  once per execution, since we require it to be constant during execution.
2260  The escape member has a valid value if and only if this function returns
2261  true.
2262  */
2263  bool escape_is_evaluated() const { return escape_evaluated; }
2264 
2265  float get_filtering_effect(THD *thd, table_map filter_for_table,
2266  table_map read_tables,
2267  const MY_BITMAP *fields_to_ignore,
2268  double rows_in_table) override;
2269 
2270  private:
2271  /**
2272  The method updates covering keys depending on the
2273  length of wild string prefix.
2274 
2275  @param thd Pointer to THD object.
2276 
2277  @retval true if error happens during wild string prefix claculation,
2278  false otherwise.
2279  */
2280  bool check_covering_prefix_keys(THD *thd);
2281 };
2282 
2283 class Item_cond : public Item_bool_func {
2285 
2286  protected:
2289 
2290  public:
2291  /* Item_cond() is only used to create top level items */
2292  Item_cond() : Item_bool_func(), abort_on_null(true) {}
2293  Item_cond(Item *i1, Item *i2) : Item_bool_func(), abort_on_null(false) {
2294  list.push_back(i1);
2295  list.push_back(i2);
2296  }
2297  Item_cond(const POS &pos, Item *i1, Item *i2)
2298  : Item_bool_func(pos), abort_on_null(false) {
2299  list.push_back(i1);
2300  list.push_back(i2);
2301  }
2302 
2303  Item_cond(THD *thd, Item_cond *item);
2305  : Item_bool_func(), list(nlist), abort_on_null(false) {}
2306  bool add(Item *item) {
2307  DBUG_ASSERT(item);
2308  return list.push_back(item);
2309  }
2310  bool add_at_head(Item *item) {
2311  DBUG_ASSERT(item);
2312  return list.push_front(item);
2313  }
2314  void add_at_head(List<Item> *nlist) {
2315  DBUG_ASSERT(nlist->elements);
2316  list.prepend(nlist);
2317  }
2318 
2319  bool itemize(Parse_context *pc, Item **res) override;
2320 
2321  bool fix_fields(THD *, Item **ref) override;
2322  void fix_after_pullout(SELECT_LEX *parent_select,
2323  SELECT_LEX *removed_select) override;
2324 
2325  Type type() const override { return COND_ITEM; }
2327  bool eq(const Item *item, bool binary_cmp) const override;
2328  table_map used_tables() const override { return used_tables_cache; }
2329  void update_used_tables() override;
2330  void print(const THD *thd, String *str,
2331  enum_query_type query_type) const override;
2332  void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2333  List<Item> &fields) override;
2334  void apply_is_true() override { abort_on_null = true; }
2335  void copy_andor_arguments(THD *thd, Item_cond *item);
2336  bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
2337  Item *transform(Item_transformer transformer, uchar *arg) override;
2338  void traverse_cond(Cond_traverser, void *arg, traverse_order order) override;
2339  bool truth_transform_arguments(THD *thd, Bool_test test);
2340  bool subst_argument_checker(uchar **) override { return true; }
2341  Item *compile(Item_analyzer analyzer, uchar **arg_p,
2342  Item_transformer transformer, uchar *arg_t) override;
2343  bool remove_const_conds(THD *thd, Item *item, Item **new_item);
2344  /// Treat UNKNOWN result like FALSE because callers see no difference
2345  bool ignore_unknown() const { return abort_on_null; }
2346  bool equality_substitution_analyzer(uchar **) override { return true; }
2347 };
2348 
2349 /*
2350  The class Item_equal is used to represent conjunctions of equality
2351  predicates of the form field1 = field2, and field=const in where
2352  conditions and on expressions.
2353 
2354  All equality predicates of the form field1=field2 contained in a
2355  conjunction are substituted for a sequence of items of this class.
2356  An item of this class Item_equal(f1,f2,...fk) represents a
2357  multiple equality f1=f2=...=fk.
2358 
2359  If a conjunction contains predicates f1=f2 and f2=f3, a new item of
2360  this class is created Item_equal(f1,f2,f3) representing the multiple
2361  equality f1=f2=f3 that substitutes the above equality predicates in
2362  the conjunction.
2363  A conjunction of the predicates f2=f1 and f3=f1 and f3=f2 will be
2364  substituted for the item representing the same multiple equality
2365  f1=f2=f3.
2366  An item Item_equal(f1,f2) can appear instead of a conjunction of
2367  f2=f1 and f1=f2, or instead of just the predicate f1=f2.
2368 
2369  An item of the class Item_equal inherits equalities from outer
2370  conjunctive levels.
2371 
2372  Suppose we have a where condition of the following form:
2373  WHERE f1=f2 AND f3=f4 AND f3=f5 AND ... AND (...OR (f1=f3 AND ...)).
2374  In this case:
2375  f1=f2 will be substituted for Item_equal(f1,f2);
2376  f3=f4 and f3=f5 will be substituted for Item_equal(f3,f4,f5);
2377  f1=f3 will be substituted for Item_equal(f1,f2,f3,f4,f5);
2378 
2379  An object of the class Item_equal can contain an optional constant
2380  item c. Then it represents a multiple equality of the form
2381  c=f1=...=fk.
2382 
2383  Objects of the class Item_equal are used for the following:
2384 
2385  1. An object Item_equal(t1.f1,...,tk.fk) allows us to consider any
2386  pair of tables ti and tj as joined by an equi-condition.
2387  Thus it provide us with additional access paths from table to table.
2388 
2389  2. An object Item_equal(t1.f1,...,tk.fk) is applied to deduce new
2390  SARGable predicates:
2391  f1=...=fk AND P(fi) => f1=...=fk AND P(fi) AND P(fj).
2392  It also can give us additional index scans and can allow us to
2393  improve selectivity estimates.
2394 
2395  3. An object Item_equal(t1.f1,...,tk.fk) is used to optimize the
2396  selected execution plan for the query: if table ti is accessed
2397  before the table tj then in any predicate P in the where condition
2398  the occurrence of tj.fj is substituted for ti.fi. This can allow
2399  an evaluation of the predicate at an earlier step.
2400 
2401  When feature 1 is supported they say that join transitive closure
2402  is employed.
2403  When feature 2 is supported they say that search argument transitive
2404  closure is employed.
2405  Both features are usually supported by preprocessing original query and
2406  adding additional predicates.
2407  We do not just add predicates, we rather dynamically replace some
2408  predicates that can not be used to access tables in the investigated
2409  plan for those, obtained by substitution of some fields for equal fields,
2410  that can be used.
2411 
2412  Prepared Statements/Stored Procedures note: instances of class
2413  Item_equal are created only at the time a PS/SP is executed and
2414  are deleted in the end of execution. All changes made to these
2415  objects need not be registered in the list of changes of the parse
2416  tree and do not harm PS/SP re-execution.
2417 
2418  Item equal objects are employed only at the optimize phase. Usually they are
2419  not supposed to be evaluated. Yet in some cases we call the method val_int()
2420  for them. We have to take care of restricting the predicate such an
2421  object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
2422 */
2424  List<Item_field> fields; /* list of equal field items */
2425  Item *const_item; /* optional constant item equal to fields items */
2430 
2431  public:
2432  inline Item_equal()
2433  : Item_bool_func(),
2434  const_item(nullptr),
2435  eval_item(nullptr),
2436  cond_false(false) {}
2437  Item_equal(Item_field *f1, Item_field *f2);
2438  Item_equal(Item *c, Item_field *f);
2439  Item_equal(Item_equal *item_equal);
2440  ~Item_equal() override { destroy(eval_item); }
2441 
2442  inline Item *get_const() { return const_item; }
2443  void set_const(Item *c) { const_item = c; }
2444  bool compare_const(THD *thd, Item *c);
2445  bool add(THD *thd, Item *c, Item_field *f);
2446  bool add(THD *thd, Item *c);
2447  void add(Item_field *f);
2448  uint members();
2449  bool contains(const Field *field) const;
2450  /**
2451  Get the first field of multiple equality, use for semantic checking.
2452 
2453  @retval First field in the multiple equality.
2454  */
2455  Item_field *get_first() { return fields.head(); }
2456  Item_field *get_subst_item(const Item_field *field);
2457  bool merge(THD *thd, Item_equal *item);
2458  bool update_const(THD *thd);
2459  enum Functype functype() const override { return MULT_EQUAL_FUNC; }
2460  longlong val_int() override;
2461  const char *func_name() const override { return "multiple equal"; }
2462  optimize_type select_optimize(const THD *) override { return OPTIMIZE_EQUAL; }
2463  virtual bool cast_incompatible_args(uchar *) override {
2464  // Multiple equality nodes (Item_equal) should have been
2465  // converted back to simple equalities (Item_func_eq) by
2466  // substitute_for_best_equal_field before cast nodes are injected.
2467  DBUG_ASSERT(false);
2468  return false;
2469  }
2470 
2471  /**
2472  Order field items in multiple equality according to a sorting criteria.
2473 
2474  The function perform ordering of the field items in the Item_equal
2475  object according to the criteria determined by the cmp callback parameter.
2476  If cmp(item_field1,item_field2,arg)<0 than item_field1 must be
2477  placed after item_field2.
2478 
2479  The function sorts field items by the exchange sort algorithm.
2480  The list of field items is looked through and whenever two neighboring
2481  members follow in a wrong order they are swapped. This is performed
2482  again and again until we get all members in a right order.
2483 
2484  @param compare function to compare field item
2485  */
2486  template <typename Node_cmp_func>
2487  void sort(Node_cmp_func compare) {
2488  fields.sort(compare);
2489  }
2490  friend class Item_equal_iterator;
2491  bool resolve_type(THD *) override;
2492  bool fix_fields(THD *thd, Item **ref) override;
2493  void update_used_tables() override;
2494  bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
2495  Item *transform(Item_transformer transformer, uchar *arg) override;
2496  void print(const THD *thd, String *str,
2497  enum_query_type query_type) const override;
2498  const CHARSET_INFO *compare_collation() const override {
2499  return fields.head()->collation.collation;
2500  }
2501 
2502  bool equality_substitution_analyzer(uchar **) override { return true; }
2503 
2504  Item *equality_substitution_transformer(uchar *arg) override;
2505 
2506  float get_filtering_effect(THD *thd, table_map filter_for_table,
2507  table_map read_tables,
2508  const MY_BITMAP *fields_to_ignore,
2509  double rows_in_table) override;
2510  Item *m_const_folding[2]; ///< temporary area used for constant folding
2511 
2512  private:
2513  void check_covering_prefix_keys();
2514 };
2515 
2516 class COND_EQUAL {
2517  public:
2518  uint max_members; /* max number of members the current level
2519  list and all lower level lists */
2520  COND_EQUAL *upper_levels; /* multiple equalities of upper and levels */
2521  List<Item_equal> current_level; /* list of multiple equalities of
2522  the current and level */
2523  COND_EQUAL() { upper_levels = nullptr; }
2524 };
2525 
2526 class Item_equal_iterator : public List_iterator_fast<Item_field> {
2527  public:
2528  inline Item_equal_iterator(Item_equal &item_equal)
2529  : List_iterator_fast<Item_field>(item_equal.fields) {}
2530  inline Item_field *operator++(int) {
2531  Item_field *item = (*(List_iterator_fast<Item_field> *)this)++;
2532  return item;
2533  }
2535 };
2536 
2538  public:
2539  COND_EQUAL cond_equal; /* contains list of Item_equal objects for
2540  the current and level and reference
2541  to multiple equalities of upper and levels */
2543 
2544  Item_cond_and(Item *i1, Item *i2) : Item_cond(i1, i2) {}
2545  Item_cond_and(const POS &pos, Item *i1, Item *i2) : Item_cond(pos, i1, i2) {}
2546 
2547  Item_cond_and(THD *thd, Item_cond_and *item) : Item_cond(thd, item) {}
2548  Item_cond_and(List<Item> &list_arg) : Item_cond(list_arg) {}
2549  enum Functype functype() const override { return COND_AND_FUNC; }
2550  longlong val_int() override;
2551  const char *func_name() const override { return "and"; }
2552  Item *copy_andor_structure(THD *thd) override {
2553  Item_cond_and *item;
2554  if ((item = new Item_cond_and(thd, this)))
2555  item->copy_andor_arguments(thd, this);
2556  return item;
2557  }
2558  Item *truth_transformer(THD *, Bool_test) override;
2559  bool gc_subst_analyzer(uchar **) override { return true; }
2560 
2561  float get_filtering_effect(THD *thd, table_map filter_for_table,
2562  table_map read_tables,
2563  const MY_BITMAP *fields_to_ignore,
2564  double rows_in_table) override;
2565 
2566  bool contains_only_equi_join_condition() const override;
2567 };
2568 
2569 class Item_cond_or final : public Item_cond {
2570  public:
2572 
2573  Item_cond_or(Item *i1, Item *i2) : Item_cond(i1, i2) {}
2574  Item_cond_or(const POS &pos, Item *i1, Item *i2) : Item_cond(pos, i1, i2) {}
2575 
2576  Item_cond_or(THD *thd, Item_cond_or *item) : Item_cond(thd, item) {}
2577  Item_cond_or(List<Item> &list_arg) : Item_cond(list_arg) {}
2578  enum Functype functype() const override { return COND_OR_FUNC; }
2579  longlong val_int() override;
2580  const char *func_name() const override { return "or"; }
2581  Item *copy_andor_structure(THD *thd) override {
2582  Item_cond_or *item;
2583  if ((item = new Item_cond_or(thd, this)))
2584  item->copy_andor_arguments(thd, this);
2585  return item;
2586  }
2587  Item *truth_transformer(THD *, Bool_test) override;
2588  bool gc_subst_analyzer(uchar **) override { return true; }
2589 
2590  float get_filtering_effect(THD *thd, table_map filter_for_table,
2591  table_map read_tables,
2592  const MY_BITMAP *fields_to_ignore,
2593  double rows_in_table) override;
2594 };
2595 
2596 /// Builds condition: (a AND b) IS TRUE
2597 inline Item *and_conds(Item *a, Item *b) {
2598  if (!b) return a;
2599  if (!a) return b;
2600 
2601  Item *item = new Item_cond_and(a, b);
2602  if (item == nullptr) return nullptr;
2603  item->apply_is_true();
2604  return item;
2605 }
2606 
2607 longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg,
2608  const Item *warn_item, bool *is_null);
2609 
2610 // TODO: the next two functions should be moved to sql_time.{h,cc}
2611 bool get_mysql_time_from_str_no_warn(THD *thd, String *str, MYSQL_TIME *l_time,
2613 
2614 bool get_mysql_time_from_str(THD *thd, String *str,
2615  enum_mysql_timestamp_type warn_type,
2616  const char *warn_name, MYSQL_TIME *l_time);
2617 /*
2618  These need definitions from this file but the variables are defined
2619  in mysqld.h. The variables really belong in this component, but for
2620  the time being we leave them in mysqld.cc to avoid merge problems.
2621 */
2622 extern Eq_creator eq_creator;
2624 extern Ne_creator ne_creator;
2625 extern Gt_creator gt_creator;
2626 extern Lt_creator lt_creator;
2627 extern Ge_creator ge_creator;
2628 extern Le_creator le_creator;
2629 
2630 #endif /* ITEM_CMPFUNC_INCLUDED */
virtual int cmp(Item *arg)
Definition: item_cmpfunc.h:1741
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1143
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:674
static int cmp(Bigint *a, Bigint *b)
Definition: dtoa.cc:1071
Definition: item_cmpfunc.h:2569
const CHARSET_INFO * cmp_charset
Definition: item_cmpfunc.h:1721
Item_result result_type() const override
Definition: item_cmpfunc.h:1432
Definition: result.h:29
Definition: item.h:3593
unsigned long long int ulonglong
Definition: my_inttypes.h:55
cmp_item_string(const CHARSET_INFO *cs)
Definition: item_cmpfunc.h:1724
not valid for UDFs
Definition: udf_registration_types.h:44
Item_result left_result_type
Definition: item_cmpfunc.h:1957
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2203
DTCollation cmp_collation
Definition: item_cmpfunc.h:1879
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2147
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:2244
const Item * warn_item
Definition: item_cmpfunc.h:1812
This file contains the field type.
Item_cond(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2297
in_expr [NOT] IN (in_value_list).
Definition: item_cmpfunc.h:1940
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:638
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:2346
virtual double val_real()=0
static void print(const char *key, int keylen, const char *val, int vallen)
Print the key value pair.
Definition: mcstat.c:106
Item_cond(List< Item > &nlist)
Definition: item_cmpfunc.h:2304
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:551
unsigned char uchar
Definition: my_inttypes.h:51
Item_func_eq * m_join_condition
Definition: item_cmpfunc.h:105
Item_func_interval(const POS &pos, MEM_ROOT *mem_root, Item *expr1, Item *expr2, class PT_item_list *opt_expr_list=nullptr)
Definition: item_cmpfunc.h:1294
Item_func_coalesce(const POS &pos, PT_item_list *list)
Definition: item_cmpfunc.h:1328
List< Item_field > fields
Definition: item_cmpfunc.h:2424
Definition: item.h:3354
Definition: sql_optimizer.h:119
Definition: item.h:4351
bool use_custom_value_extractors() const
Definition: item_cmpfunc.h:251
Our own string classes, used pervasively throughout the executor.
const char * func_name() const override
Definition: item_cmpfunc.h:363
Definition: item_cmpfunc.h:886
optimize_type
Definition: item_func.h:232
A predicate that is "always true" or "always false".
Definition: item_cmpfunc.h:338
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_cmpfunc.h:433
Item_func super
Definition: item_cmpfunc.h:1872
longlong value
Definition: item_cmpfunc.h:1782
const char * func_name() const override
Definition: item_cmpfunc.h:501
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:38
Definition: item_cmpfunc.h:587
Item_result compare_type() const
Definition: item_cmpfunc.h:647
const char * func_name() const override
Definition: item_cmpfunc.h:945
uint decimal_precision() const override
Definition: item_cmpfunc.h:1306
Item_in_optimizer(Item *a, Item_in_subselect *b)
Definition: item_cmpfunc.h:487
void add(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:69
const uint count
Original size of the vector.
Definition: item_cmpfunc.h:1459
Item_cond_or(List< Item > &list_arg)
Definition: item_cmpfunc.h:2577
Item_func_false(const POS &pos)
Definition: item_cmpfunc.h:377
Item * m_right_extractor
Definition: item_cmpfunc.h:107
uint decimal_precision() const override
Definition: item_cmpfunc.h:1240
Item_bool_func2 super
Definition: item_cmpfunc.h:691
Item_func_between(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
Definition: item_cmpfunc.h:1221
Item_func_false()
Definition: item_cmpfunc.h:376
uint used_count
The actual size of the vector (NULL may be ignored)
Definition: item_cmpfunc.h:1461
HashJoinCondition(Item_func_eq *join_condition, MEM_ROOT *mem_root)
Definition: item_cmpfunc.cc:7299
Arg_comparator(Item **left, Item **right)
Definition: item_cmpfunc.h:168
longlong val_int() override
Definition: item_cmpfunc.h:380
bool basic_const_item() const override
Returns true if this is a simple constant item like an integer, not a constant expression.
Definition: item_cmpfunc.h:353
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:966
void value_to_item(uint pos, Item_basic_constant *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1644
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2588
bool get_mysql_time_from_str(THD *thd, String *str, enum_mysql_timestamp_type warn_type, const char *warn_name, MYSQL_TIME *l_time)
Parse date provided in a string to a MYSQL_TIME.
Definition: item_cmpfunc.cc:876
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1084
Item_result cmp_type
Definition: item_cmpfunc.h:1212
cmp_item_row()
Definition: item_cmpfunc.h:2067
Item_cond_and(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2544
const table_map m_right_used_tables
Definition: item_cmpfunc.h:113
Item_func_in(const POS &pos, PT_item_list *list, bool is_negation)
Definition: item_cmpfunc.h:1961
Item_func_comparison is a class for comparison functions that take two arguments and return a boolean...
Definition: item_cmpfunc.h:666
Item_func_isnull(const POS &pos, Item *a)
Definition: item_cmpfunc.h:2129
Arg_comparator le_cmp
Definition: item_cmpfunc.h:1220
Item_bool_func super
Definition: item_cmpfunc.h:391
Definition: item_cmpfunc.h:1419
Definition: item.h:4282
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:2340
bool left_uses_any_table(table_map tables) const
Definition: item_cmpfunc.h:92
Item_func_gt(Item *a, Item *b)
Definition: item_cmpfunc.h:1097
Item_func_comparison(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:671
File containing constants that can be used throughout the server.
const char * func_name() const override
Definition: item_cmpfunc.h:2198
bool unsigned_flag
Definition: item.h:2962
Item_func_if(Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1386
Some integer typedefs for easier portability.
Definition: item_cmpfunc.h:1679
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1081
unique_ptr_destroy_only< Json_scalar_holder > m_holder
Cache for the value above.
Definition: item_cmpfunc.h:1760
bool ignore_unknown() const
Definition: item_cmpfunc.h:1198
bool is_bool_func() const override
Definition: item_cmpfunc.h:308
Item_func_nop_all(Item *a)
Definition: item_cmpfunc.h:943
void rewind(void)
Definition: sql_list.h:609
A wrapper class which provides array bounds checking.
Definition: sql_array.h:41
bool val_bool() override
Definition: item_cmpfunc.h:379
const char * func_name() const override
Definition: item_cmpfunc.h:1364
double value
Definition: item_cmpfunc.h:1826
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_cmpfunc.h:903
Gt_creator gt_creator
Definition: mysqld.cc:1552
Implements the comparison operator less than or equals (<=)
Definition: item_cmpfunc.h:1115
XOR inherits from Item_bool_func2 because it is not optimized yet.
Definition: item_cmpfunc.h:690
Item_row * row
Definition: item_cmpfunc.h:1289
virtual void apply_is_true()
Apply the IS TRUE truth property, meaning that an UNKNOWN result and a FALSE result are treated the s...
Definition: item.h:1999
in_vector(uint elements)
See Item_func_in::resolve_type() for why we need both count and used_count.
Definition: item_cmpfunc.h:1467
Item_field * get_first()
Get the first field of multiple equality, use for semantic checking.
Definition: item_cmpfunc.h:2455
uint ncases
Definition: item_cmpfunc.h:1877
bool copy()
Definition: sql_string.cc:189
A class that is capable of holding objects of any sub-type of Json_scalar.
Definition: json_dom.h:1879
bool compare_as_dates_with_strings
Definition: item_cmpfunc.h:1215
Eq_creator eq_creator
Definition: mysqld.cc:1549
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_cmpfunc.h:1273
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2199
Item_cond_or(THD *thd, Item_cond_or *item)
Definition: item_cmpfunc.h:2576
Definition: item_cmpfunc.h:595
Item_cond_and(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2545
bool(Item::* Item_analyzer)(uchar **argp)
Definition: item.h:665
float get_filtering_effect(THD *thd, table_map filter_for_table, table_map read_tables, const MY_BITMAP *fields_to_ignore, double rows_in_table) override
Calculate the filter contribution that is relevant for table &#39;filter_for_table&#39; for this item...
Definition: item_cmpfunc.h:753
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1241
bool escape_used_in_parsing
Definition: item_cmpfunc.h:2220
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1001
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1565
String value2
Definition: item_cmpfunc.h:1213
Implements the comparison operator greater than (>)
Definition: item_cmpfunc.h:1095
Definition: field.h:694
in_longlong(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1563
const char * func_name() const override
Definition: item_cmpfunc.h:2135
Item_equal()
Definition: item_cmpfunc.h:2432
Definition: item_func.h:84
int compare(const cmp_item *ci) const override
Definition: item_cmpfunc.h:1793
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:2178
Definition: item.h:5995
Definition: field_types.h:68
virtual bool l_op() const
Definition: item_cmpfunc.h:576
in_double(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1639
Definition: item.h:4495
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:961
Implements the comparison operator equals (=)
Definition: item_cmpfunc.h:953
Definition: item_cmpfunc.h:1382
const char * func_name() const override
Definition: item_cmpfunc.h:1163
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2143
Definition: item_cmpfunc.h:603
Item_equal_iterator(Item_equal &item_equal)
Definition: item_cmpfunc.h:2528
Definition: item_cmpfunc.h:474
const char * func_name() const override
Definition: item_cmpfunc.h:2245
virtual table_map not_null_tables() const
Definition: item.h:1855
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1161
virtual longlong val_int()=0
Definition: item_cmpfunc.h:2283
int escape
Definition: item_cmpfunc.h:2226
int result_for_null_param
Definition: item_cmpfunc.h:484
Item_bool_func(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:302
virtual bool l_op() const
Definition: item_cmpfunc.h:600
COND_EQUAL * upper_levels
Definition: item_cmpfunc.h:2520
const char * func_name() const override
Definition: item_cmpfunc.h:2580
Item_func_le(Item *a, Item *b)
Definition: item_cmpfunc.h:1117
const char * func_name() const override
Definition: item_cmpfunc.h:1082
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_func.cc:464
Item * truth_transformer(THD *, Bool_test test) override
Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implemen...
Definition: item_cmpfunc.h:398
bool is_bool_func() const override
Definition: item_cmpfunc.h:1236
void set_sub_test(Item_maxmin_subselect *item)
Definition: item_cmpfunc.h:912
A predicate that is "always false".
Definition: item_cmpfunc.h:374
bool add(Item *item)
Definition: item_cmpfunc.h:2306
const char * func_name() const override
Definition: item_cmpfunc.h:1063
Item_func_isnull(Item *a)
Definition: item_cmpfunc.h:2128
Item_result type
Definition: item_cmpfunc.h:1281
const char * func_name() const override
Definition: item_cmpfunc.h:2551
Lt_creator lt_creator
Definition: mysqld.cc:1553
Item_subselect * subselect
Definition: item_cmpfunc.h:890
Item_func_like(Item *a, Item *b, Item *escape_arg, bool escape_used)
Definition: item_cmpfunc.h:2228
Definition: item_cmpfunc.h:1807
Item * lval_cache
Definition: item_cmpfunc.h:1619
bool cond_false
Definition: item_cmpfunc.h:2428
void value_to_item(uint pos, Item_basic_constant *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1541
virtual bool l_op() const
Definition: item_cmpfunc.h:526
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
virtual ~Comp_creator()
Definition: item_cmpfunc.h:512
int get_else_expr_num() const
Definition: item_cmpfunc.h:1906
bool add_at_head(Item *item)
Definition: item_cmpfunc.h:2310
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1626
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1124
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2559
List< Item > * argument_list()
Definition: item_cmpfunc.h:2326
bool escape_was_used_in_parsing() const
Definition: item_cmpfunc.h:2255
Item * m_left_extractor
Definition: item_cmpfunc.h:106
class udf_list * list
void set_str_value(String *str)
Definition: item.h:3094
const CHARSET_INFO * collation
Definition: item_cmpfunc.h:1534
longlong val_int() override
Definition: item_cmpfunc.h:365
Item * right_extractor() const
Definition: item_cmpfunc.h:91
in_vector * array
An array of values, created when the bisection lookup method is used.
Definition: item_cmpfunc.h:1943
bool right_uses_any_table(table_map tables) const
Definition: item_cmpfunc.h:96
This trigger type deactivates join conditions when a row has been NULL-complemented.
Definition: item_cmpfunc.h:801
#define RAND_TABLE_BIT
Definition: sql_const.h:110
enum_walk
Enumeration for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:435
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:574
void set_numeric_type() override
Definition: item_cmpfunc.h:1344
const char * func_name() const override
Definition: item_cmpfunc.h:1377
DTCollation cmp_collation
Definition: item_cmpfunc.h:162
void value_to_item(uint, Item_basic_constant *) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:2110
Arg_comparator * get_child_comparators() const
Definition: item_cmpfunc.h:247
Item_bool_func(Item *a)
Definition: item_cmpfunc.h:296
arg_cmp_func func
Definition: item_cmpfunc.h:133
cmp_item_row(cmp_item_row &&other)
Definition: item_cmpfunc.h:2073
Wrapper class for an Item list head, used to allocate Item lists in the parser in a context-independe...
Definition: parse_tree_helpers.h:99
const char * func_name() const override
Definition: item_cmpfunc.h:1437
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1162
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2005
Definition: item_subselect.h:69
void add_trig_func_tables()
Definition: item_cmpfunc.h:862
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:30
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1101
int compare()
Definition: item_cmpfunc.h:209
Definition: item_cmpfunc.h:1528
bool m_created_by_in2exists
True <=> this item was added by IN->EXISTS subquery transformation, and should thus be deleted if we ...
Definition: item_cmpfunc.h:329
void store_value(Item *item) override
Definition: item_cmpfunc.h:1829
const char * func_name() const override
Definition: item_cmpfunc.h:2461
void set_null_value(bool nv)
Definition: item_cmpfunc.h:1714
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:164
bool escape_evaluated
Tells if the escape clause has been evaluated.
Definition: item_cmpfunc.h:2222
enum_trig_type get_trig_type()
Definition: item_cmpfunc.h:878
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_cmpfunc.h:2334
StringBuffer< STRING_BUFFER_USUAL_SIZE > value
Definition: item_cmpfunc.h:1720
const char * func_name() const override
Definition: item_cmpfunc.h:1122
in_datetime(MEM_ROOT *mem_root, Item *warn_item_arg, uint elements)
Definition: item_cmpfunc.h:1622
const char * func_name() const override
Definition: item_cmpfunc.h:1102
const char * func_name() const override
Definition: item_cmpfunc.h:1142
int get_first_expr_num() const
Definition: item_cmpfunc.h:1905
Definition: item_cmpfunc.h:1825
Item_field ** ref(void)
Definition: sql_list.h:602
DTCollation cmp_collation
Definition: item_cmpfunc.h:1209
interval_range * intervals
Definition: item_cmpfunc.h:1291
Definition: table.h:1313
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_cmpfunc.h:1197
Item * truth_transformer(THD *, Bool_test test) override
Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implemen...
Definition: item_cmpfunc.h:1199
table_map used_tables() const override
Definition: item_cmpfunc.h:2328
enum_trig_type
Definition: item_cmpfunc.h:795
void value_to_item(uint pos, Item_basic_constant *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1572
Definition: item_cmpfunc.h:2092
String value2
Definition: item_cmpfunc.h:164
Structure to return status from str_to_datetime(), str_to_time(), number_to_datetime(), number_to_time()
Definition: my_time.h:158
cond_result
Definition: item.h:810
Item * const_item
Definition: item_cmpfunc.h:2425
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:678
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:542
Mem_root_array< cmp_item_row > base_objects
Definition: item_cmpfunc.h:2094
Item_func_match_predicate(Item *a)
Definition: item_cmpfunc.h:743
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1121
Definition: item_cmpfunc.h:549
Item_func_xor(Item *i1, Item *i2)
Definition: item_cmpfunc.h:694
virtual ~cmp_item()
Definition: item_cmpfunc.h:1682
Ge_creator ge_creator
Definition: mysqld.cc:1554
virtual void store_value(Item *item)
Definition: item_cmpfunc.h:1731
Item_func_ne(Item *a, Item *b)
Definition: item_cmpfunc.h:1157
cmp_item * case_item
Definition: item_cmpfunc.h:1881
int8 plan_idx
This represents the index of a JOIN_TAB/QEP_TAB in an array.
Definition: sql_opt_exec_shared.h:39
Item * lval_cache
Definition: item_cmpfunc.h:1814
const table_map m_left_used_tables
Definition: item_cmpfunc.h:112
Item_func_equal(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1054
A predicate that is "always true".
Definition: item_cmpfunc.h:359
bool fix_fields(THD *, Item **ref) override
Definition: item_func.cc:265
virtual bool l_op() const
Definition: item_cmpfunc.h:592
Definition: item_cmpfunc.h:290
Item_func_like(const POS &pos, Item *a, Item *b, Item *opt_escape_arg)
Definition: item_cmpfunc.h:2233
longlong val_int() override
Definition: item_cmpfunc.h:745
enum_trig_type trig_type
Type of trig_var; for printing.
Definition: item_cmpfunc.h:830
#define DBUG_ASSERT(A)
Definition: my_dbug.h:199
in_decimal(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1659
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_cmpfunc.h:2193
bool is_alloced() const
Definition: sql_string.h:412
Item_bool_func(const POS &pos, Item *a)
Definition: item_cmpfunc.h:297
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2462
Definition: item_cmpfunc.h:130
Definition: item_cmpfunc.h:2423
Item_cache ** get_cache()
Definition: item_cmpfunc.h:502
Item_func_truth(const POS &pos, Item *a, Bool_test truth_test)
Definition: item_cmpfunc.h:407
plan_idx idx() const
Definition: item_cmpfunc.h:881
Item_func_any_value(const POS &pos, Item *a)
Definition: item_cmpfunc.h:1376
unique_ptr_destroy_only< Json_wrapper > m_value
Cached JSON value to look up.
Definition: item_cmpfunc.h:1758
virtual bool eqne_op() const
Definition: item_cmpfunc.h:591
Definition: item.h:3071
Mem_root_array< String > base_objects
Definition: item_cmpfunc.h:1531
bool set_cmp_func()
Definition: item_cmpfunc.h:622
bool append(const String &s)
Definition: sql_string.cc:443
Definition: item_cmpfunc.h:1554
const Arg_comparator * get_comparator() const
Definition: item_cmpfunc.h:655
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:366
Mem_root_array< double > base
Definition: item_cmpfunc.h:1636
char * pos
Definition: do_ctype.cc:76
A class that represents a join condition in a hash join.
Definition: item_cmpfunc.h:84
Definition: item.h:4397
static void ensure_multi_equality_fields_are_available(Item **args, int arg_idx, table_map available_tables)
Definition: item_cmpfunc.cc:7343
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:564
const char * func_name() const override
Definition: item_cmpfunc.h:747
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:964
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:590
Implements the comparison operator not equals (<>)
Definition: item_cmpfunc.h:1155
Item_bool_func()
Definition: item_cmpfunc.h:292
int compare(const cmp_item *ci) const override
Definition: item_cmpfunc.h:1837
Bison "location" class.
Definition: parse_location.h:43
Item_func_eq(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:956
Bool_test truth_test
The value we&#39;re testing for.
Definition: item_cmpfunc.h:449
Item_func_eq * join_condition() const
Definition: item_cmpfunc.h:88
Item_func_opt_neg(const POS &pos, PT_item_list *list, bool is_negation)
Definition: item_cmpfunc.h:1190
Item * warn_item
Definition: item_cmpfunc.h:1617
const char * func_name() const override
Definition: item_cmpfunc.h:1305
Definition: item_cmpfunc.h:1717
Item_func_opt_neg(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
Definition: item_cmpfunc.h:1186
Item_func_comparison(Item *a, Item *b)
Definition: item_cmpfunc.h:668
Item * get_const()
Definition: item_cmpfunc.h:2442
Item * make_condition(Parse_context *pc, Item *item)
Ensure that all expressions involved in conditions are boolean functions.
Definition: item_cmpfunc.cc:5035
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it...
Definition: item_cmpfunc.h:643
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_cmpfunc.cc:631
Item_bool_func2(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:616
virtual int compare(const cmp_item *ci) const
Definition: item_cmpfunc.h:1726
Item class, to represent X IS [NOT] (TRUE | FALSE) boolean predicates.
Definition: item_cmpfunc.h:390
Definition: item_cmpfunc.h:1181
virtual bool eqne_op() const
Definition: item_cmpfunc.h:599
Definition: my_bitmap.h:41
Item_cond_or(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2573
cmp_item()
Definition: item_cmpfunc.h:1681
void set_max_str_length(size_t max_str_length)
When comparing strings, compare at most max_str_length bytes.
Definition: item_cmpfunc.h:629
Item_func_strcmp(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1262
Item_field * operator++(int)
Definition: item_cmpfunc.h:2530
uint n
Definition: item_cmpfunc.h:2064
my_decimal class limits &#39;decimal_t&#39; type to what we need in MySQL.
Definition: my_decimal.h:91
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:2502
Item_func_coalesce(const POS &pos, Item *a)
Definition: item_cmpfunc.h:1323
Definition: item_cmpfunc.h:2215
Functype
Definition: item_func.h:122
Definition: item_cmpfunc.h:2160
Definition: udf_registration_types.h:39
cmp_item_row(THD *thd, Item *item)
Definition: item_cmpfunc.h:2068
void update_not_null_tables()
Definition: item_cmpfunc.h:1249
double
Definition: udf_registration_types.h:42
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:1205
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1062
bool unsigned_flag
Definition: item_cmpfunc.h:1556
List< Item_equal > current_level
Definition: item_cmpfunc.h:2521
Implements the comparison operator greater than or equals (>=)
Definition: item_cmpfunc.h:1075
dberr_t create() noexcept
Create the dblwr data structures in the system tablespace.
Definition: buf0dblwr.cc:1835
Definition: item_cmpfunc.h:1635
void set_created_by_in2exists()
Definition: item_cmpfunc.h:315
Header for compiler-dependent features.
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:510
void update_not_null_tables()
Definition: item_cmpfunc.h:1413
Definition: item_cmpfunc.h:1350
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2008
Item_is_not_null_test(Item_in_subselect *ow, Item *a)
Definition: item_cmpfunc.h:2164
Definition: item_cmpfunc.h:1286
uint16_t uint16
Definition: my_inttypes.h:64
Item_bool_func(THD *thd, Item_bool_func *item)
Definition: item_cmpfunc.h:305
Definition: item.h:741
unsigned int uint
Definition: uca-dump.cc:29
#define final(a, b, c)
Definition: hash.c:109
Item_cond_or()
Definition: item_cmpfunc.h:2571
virtual bool is_row_result() const
Definition: item_cmpfunc.h:1503
Definition: item_cmpfunc.h:793
bool null_value
True if item is null.
Definition: item.h:2961
plan_idx m_idx
Optional: if join!=NULL: index of table.
Definition: item_cmpfunc.h:828
#define true
Definition: config_static.h:44
void(* Cond_traverser)(const Item *item, void *arg)
Definition: item.h:675
void copy_andor_arguments(THD *thd, Item_cond *item)
Definition: item_cmpfunc.cc:5077
bool field_type_defined
Definition: item_cmpfunc.h:1352
long long int longlong
Definition: my_inttypes.h:54
virtual ~in_vector()
Definition: item_cmpfunc.h:1469
Definition: item_cmpfunc.h:711
COND_EQUAL()
Definition: item_cmpfunc.h:2523
void cleanup() override
Definition: item.cc:9813
const char * func_name() const override
Definition: item_cmpfunc.h:2168
int first_expr_num
Definition: item_cmpfunc.h:1874
Type
Definition: item.h:777
Definition: item.h:169
const CHARSET_INFO * collation
Definition: item.h:171
void sort(Node_cmp_func cmp)
Sort the list.
Definition: sql_list.h:539
List< Item > list
Definition: item_cmpfunc.h:2287
Item_bool_func2 super
Definition: item_cmpfunc.h:2216
void set_comparator(uint col, cmp_item *comparator)
Definition: item_cmpfunc.h:2103
Item_func_ifnull(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1355
const char * func_name() const override
Definition: item_cmpfunc.h:718
COND_EQUAL cond_equal
Definition: item_cmpfunc.h:2539
const char * func_name() const override
Definition: item_cmpfunc.h:1346
Item_int_func super
Definition: item_cmpfunc.h:1287
table_map not_null_tables() const override
Definition: item_cmpfunc.h:946
Bool_test
< Modifier for result transformation
Definition: item.h:824
Le_creator le_creator
Definition: mysqld.cc:1555
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:632
const char * func_name() const override
Definition: item_cmpfunc.h:1918
It is interface module to fixed precision decimals library.
double precision
Definition: item_cmpfunc.h:137
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1227
Definition: item_func.h:837
bool get_mysql_time_from_str_no_warn(THD *thd, String *str, MYSQL_TIME *l_time, MYSQL_TIME_STATUS *status)
A minion of get_mysql_time_from_str, see its description.
Definition: item_cmpfunc.cc:845
Item_func_ge(Item *a, Item *b)
Definition: item_cmpfunc.h:1077
Item_func_eq(Item *a, Item *b)
Definition: item_cmpfunc.h:955
Definition: m_ctype.h:359
Item_func_isnotnull(Item *a)
Definition: item_cmpfunc.h:2186
virtual String * val_str(String *str)=0
Definition: item_cmpfunc.h:2526
Item which stores (x,y,...) and ROW(x,y,...).
Definition: item_row.h:50
Item_func_case(const POS &pos, List< Item > &list, Item *first_expr_arg, Item *else_expr_arg)
Definition: item_cmpfunc.h:1884
int sortcmp(const String *a, const String *b, const CHARSET_INFO *cs)
Definition: sql_string.cc:718
bool fix_fields(THD *thd, Item **ref) override
Definition: item_cmpfunc.h:857
int compare_datetime()
Compare item values as dates.
Definition: item_cmpfunc.cc:1585
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree...
Definition: item_cmpfunc.h:871
Item_basic_constant * create_item(MEM_ROOT *) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:2106
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:1922
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:99
Definition: item_cmpfunc.h:562
#define OUTER_REF_TABLE_BIT
Definition: sql_const.h:109
virtual bool l_op() const
Definition: item_cmpfunc.h:584
bool show
Definition: item_cmpfunc.h:894
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:650
Arg_comparator cmp
Definition: item_cmpfunc.h:2427
bool is_bool_func() const override
This is a workaround for the broken inheritance hierarchy: this should inherit from Item_func instead...
Definition: item_cmpfunc.h:1450
void cleanup() override
Definition: item_cmpfunc.h:651
Item * copy_andor_structure(THD *thd) override
Definition: item_cmpfunc.h:2581
void sort(Node_cmp_func compare)
Order field items in multiple equality according to a sorting criteria.
Definition: item_cmpfunc.h:2487
Definition: item_cmpfunc.h:1457
Item * left_extractor() const
Definition: item_cmpfunc.h:90
Definition: item_func.h:687
Item_func_coalesce(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1319
DBUG_TRACE
Definition: do_ctype.cc:46
virtual bool eqne_op() const
Definition: item_cmpfunc.h:575
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:582
CASE ...
Definition: item_cmpfunc.h:1871
Item_func_not(const POS &pos, Item *a)
Definition: item_cmpfunc.h:714
table_map get_initial_pseudo_tables() const override
We add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE.
Definition: item_cmpfunc.h:2175
Definition: sql_executor.h:279
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1265
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:408
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_cmpfunc.h:702
Item_func_true()
Definition: item_cmpfunc.h:361
Item_func_not(Item *a)
Definition: item_cmpfunc.h:713
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Definition: item_cmpfunc.h:579
String tmp_value
Definition: item_cmpfunc.h:1876
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1999
cmp_item which stores a scalar (i.e. non-ROW).
Definition: item_cmpfunc.h:1711
virtual bool cast_incompatible_args(uchar *) override
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item_cmpfunc.h:2463
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1104
Definition: item_cmpfunc.h:2184
Type type() const override
Definition: item_cmpfunc.h:2325
Item_cache * cache
Definition: item_cmpfunc.h:476
Item_func_xor(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:695
bool(Item::* Item_processor)(uchar *arg)
Processor type for {Item,SELECT_LEX[_UNIT],Table_function}walk.
Definition: sql_const.h:453
Item_cond()
Definition: item_cmpfunc.h:2292
unsigned int my_time_flags_t
Flags to str_to_datetime and number_to_datetime.
Definition: my_time.h:82
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1589
const JOIN * m_join
Optional: JOIN of table which is the source of trig_var.
Definition: item_cmpfunc.h:826
Definition: item_cmpfunc.h:1280
Mem_root_array< packed_longlong > base
Definition: item_cmpfunc.h:1560
Item_maxmin_subselect * test_sub_item
Definition: item_cmpfunc.h:889
void store_value(Item *item) override
Definition: item_cmpfunc.h:1785
bool set_cmp_func(Item_result_field *owner_arg, Item **left, Item **right, Item_result type)
Sets compare functions for various datatypes.
Definition: item_cmpfunc.cc:1113
Definition: item_cmpfunc.h:1755
Abstract base class for the comparison operators =, <> and <=>.
Definition: item_cmpfunc.h:522
bool use_decimal_comparison
Definition: item_cmpfunc.h:1290
Item_result_field * owner
Definition: item_cmpfunc.h:134
bool escape_is_evaluated() const
Has the escape clause been evaluated? It only needs to be evaluated once per execution, since we require it to be constant during execution.
Definition: item_cmpfunc.h:2263
virtual bool eqne_op() const
Definition: item_cmpfunc.h:583
traverse_order
Definition: item.h:812
Definition: item_cmpfunc.h:1585
Item_bool_func(Item *a, Item *b)
Definition: item_cmpfunc.h:300
Definition: item_cmpfunc.h:1615
Item_func_isnotnull(const POS &pos, Item *a)
Definition: item_cmpfunc.h:2187
bool save_cache
Definition: item_cmpfunc.h:477
Arg_comparator cmp
Definition: item_cmpfunc.h:609
const char * func_name() const override
Definition: item_cmpfunc.h:1266
ANY_VALUE(expr) is like expr except that it is not checked by aggregate_check logic.
Definition: item_cmpfunc.h:1374
Definition: item_cmpfunc.h:1655
bool fix_fields(THD *, Item **) override
Definition: item_cmpfunc.h:352
Definition: mysql_time.h:81
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:748
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:381
virtual bool eqne_op() const
Definition: item_cmpfunc.h:525
bool m_store_full_sort_key
Definition: item_cmpfunc.h:127
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1601
void value_to_item(uint pos, Item_basic_constant *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1664
const char * func_name() const override
Definition: item_cmpfunc.h:378
enum_mysql_timestamp_type
Definition: mysql_time.h:44
Mem_root_array< my_decimal > base
Definition: item_cmpfunc.h:1656
void cleanup() override
Definition: item_cmpfunc.h:354
Item_result get_compare_type() const
Definition: item_cmpfunc.h:243
uint decimal_precision() const override
Definition: item_cmpfunc.h:1434
Wrapper class when MATCH function is used in WHERE clause.
Definition: item_cmpfunc.h:741
const char * func_name() const override
Definition: item_cmpfunc.h:962
Equal_creator equal_creator
Definition: mysqld.cc:1551
int(Arg_comparator::* arg_cmp_func)()
Definition: item_cmpfunc.h:71
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree...
Definition: item_func.cc:452
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:2865
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_cmpfunc.h:648
in_time_as_longlong(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1599
Mem_root_array< cmp_item_row * > base_pointers
Definition: item_cmpfunc.h:2096
Definition: item_cmpfunc.h:1781
const String * value_res
Definition: item_cmpfunc.h:1719
uint elements
Definition: sql_list.h:135
Item_func_if(const POS &pos, Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1390
table_map not_null_tables() const override
Definition: item_cmpfunc.h:914
my_decimal dec
Definition: item_cmpfunc.h:1283
bool is_row_result() const override
Definition: item_cmpfunc.h:2100
bool compare_as_temporal_times
Definition: item_cmpfunc.h:1217
longlong val
Definition: item_cmpfunc.h:1555
Item * copy_andor_structure(THD *thd) override
Definition: item_cmpfunc.h:2552
Definition: item_cmpfunc.h:2516
Item * and_conds(Item *a, Item *b)
Builds condition: (a AND b) IS TRUE.
Definition: item_cmpfunc.h:2597
DTCollation cmp_collation
Definition: item_cmpfunc.h:1959
bool abort_on_null
Definition: item_cmpfunc.h:610
Item_func_bool_const(const POS &pos)
Definition: item_cmpfunc.h:346
Definition: sql_list.h:596
uint max_members
Definition: item_cmpfunc.h:2518
void update_not_null_tables()
Definition: item_cmpfunc.h:2015
void get_date(char *to, int flag, time_t date)
Store textual representation of date in a character array.
Definition: my_systime.cc:107
Item_func_true(const POS &pos)
Definition: item_cmpfunc.h:362
void prepend(List< T > *list)
Definition: sql_list.h:473
Item_bool_func super
Definition: item_cmpfunc.h:2122
void print_op(const THD *thd, String *str, enum_query_type query_type) const
Definition: item_func.cc:480
Item_bool_func(const POS &pos)
Definition: item_cmpfunc.h:293
Ne_creator ne_creator
Definition: mysqld.cc:1550
void destroy(T *ptr)
Definition: my_alloc.h:381
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1641
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1141
Definition: item.h:4160
Definition: field_types.h:69
void set_max_str_length(size_t max_length)
When comparing strings, compare at most max_length bytes.
Definition: item_cmpfunc.h:208
if(!(yy_init))
Definition: lexyy.cc:1144
longlong cached_value
Definition: item_cmpfunc.h:2125
Definition: item_cmpfunc.h:1597
bool created_by_in2exists() const override
Whether this Item was created by the IN->EXISTS subquery transformation.
Definition: item_cmpfunc.h:314
Time declarations shared between the server and client API: you should not add anything to this heade...
Item with result field.
Definition: item.h:4861
const char * func_name() const override
Definition: item_cmpfunc.h:402
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:1237
Item_func_equal(Item *a, Item *b)
Definition: item_cmpfunc.h:1051
Mem_root_array< String * > base_pointers
Definition: item_cmpfunc.h:1533
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_cmpfunc.h:2206
double dbl
Definition: item_cmpfunc.h:1282
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:2345
void set_cmp_context_for_datetime()
Definition: item_cmpfunc.h:237
bool store_full_sort_key() const
Definition: item_cmpfunc.h:102
unique_ptr_destroy_only< cmp_item_row > tmp
Definition: item_cmpfunc.h:2093
void negate()
Definition: item_cmpfunc.h:1196
Definition: item_cmpfunc.h:1317
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2498
uint get_child_comparator_count() const
Definition: item_cmpfunc.h:245
Implements the comparison operator less than (<)
Definition: item_cmpfunc.h:1135
Target down_cast(Source *arg)
Casts from one pointer type to another in a type hierarchy.
Definition: template_utils.h:94
Item_cond(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2293
uint64_t table_map
Definition: my_table_map.h:30
Definition: item_cmpfunc.h:2121
void set_comparator(uint col, cmp_item *comparator)
Definition: item_cmpfunc.h:2084
Definition: item_cmpfunc.h:1844
Definition: item_subselect.h:360
void set_const(Item *c)
Definition: item_cmpfunc.h:2443
bool * trig_var
Pointer to trigger variable.
Definition: item_cmpfunc.h:824
bool * get_trig_var()
Definition: item_cmpfunc.h:877
Definition: item_cmpfunc.h:941
const string value("\alue\)
Item * truth_transformer(THD *, Bool_test) override
Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implemen...
Definition: item_cmpfunc.h:1064
const size_t m_max_character_length
Definition: item_cmpfunc.h:119
~Item_equal() override
Definition: item_cmpfunc.h:2440
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:1440
Definition: item_cmpfunc.h:2062
static STATUS status
Definition: mysql.cc:198
Interface for low level time utilities.
Item_func_lt(Item *a, Item *b)
Definition: item_cmpfunc.h:1137
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)". ...
Definition: item_subselect.h:512
static bool contains(const std::vector< std::string > &container, const std::string &file)
Definition: config_files.cc:42
const char * func_name() const override
Definition: item_cmpfunc.h:908
bool have_null
If there is some NULL among <in value list>, during a val_int() call; for example IN ( (1...
Definition: item_cmpfunc.h:1950
int cmp(Item *arg) override
Definition: item_cmpfunc.h:1833
bool has_date
Distinguish between DATE/DATETIME/TIMESTAMP and TIME.
Definition: item_cmpfunc.h:1816
void cleanup_arrays()
Cleanup data and comparator arrays.
Definition: item_cmpfunc.h:1983
Abstract base class for the MIN and MAX aggregate functions.
Definition: item_sum.h:1523
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
bool is_bool_func() const override
Definition: item_cmpfunc.h:2004
bool val_bool() override
Definition: item_cmpfunc.h:364
bool compare_as_dates
Definition: item_cmpfunc.h:2429
longlong get_datetime_value(THD *thd, Item ***item_arg, Item **cache_arg, const Item *warn_item, bool *is_null)
Definition: item_cmpfunc.cc:1486
Definition: table.h:2494
Item_cond_or(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2574
#define STRING_BUFFER_USUAL_SIZE
Definition: sql_const.h:126
bool push_back(T *a)
Definition: sql_list.h:452
int cmp(Item *arg) override
Definition: item_cmpfunc.h:1789
Item_func_trig_cond(Item *a, bool *f, const JOIN *join, plan_idx idx, enum_trig_type trig_type_arg)
Definition: item_cmpfunc.h:842
void cleanup() override
Definition: item_cmpfunc.h:1993
uint decimal_precision() const override
Definition: item_cmpfunc.h:313
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:1269
Definition: item_cmpfunc.h:571
Item_sum_hybrid * test_sum_item
Definition: item_cmpfunc.h:888
bool have_rev_func() const override
Definition: item_cmpfunc.h:636
Item_func_truth(Item *a, Bool_test truth_test)
Definition: item_cmpfunc.h:420
cmp_item * eval_item
Definition: item_cmpfunc.h:2426
const char * func_name() const override
Definition: item_cmpfunc.h:1229
const char * func_name() const override
Definition: item_cmpfunc.h:2003
bool dep_subq_in_list
Set to true by resolve_type() if the IN list contains a dependent subquery, in which case condition f...
Definition: item_cmpfunc.h:1956
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1538
void set_subselect(Item_subselect *item)
Definition: item_cmpfunc.h:913
bool abort_on_null
Definition: item_cmpfunc.h:891
const JOIN * get_join() const
Definition: item_cmpfunc.h:875
void set_sum_test(Item_sum_hybrid *item)
Definition: item_cmpfunc.h:911
Definition: item_cmpfunc.h:1208
bool abort_on_null
Definition: item_cmpfunc.h:2288
my_decimal value
Definition: item_cmpfunc.h:1845
T * head()
Definition: sql_list.h:464
longlong value
Definition: item_cmpfunc.h:1808
uint decimal_precision() const override
Definition: item_cmpfunc.h:1975
bool m_null_value
If stored value is NULL.
Definition: item_cmpfunc.h:1713
String tmp
Definition: item_cmpfunc.h:1530
#define false
Definition: config_static.h:43
virtual const char * symbol(bool invert) const
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:598
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size...
Definition: item_cmpfunc.h:309
Definition: item_cmpfunc.h:540
bool pred_level
Definition: item_cmpfunc.h:1184
Definition: item_cmpfunc.h:1552
void rewind(void)
Definition: item_cmpfunc.h:2534
void add_at_head(List< Item > *nlist)
Definition: item_cmpfunc.h:2314
bool compare_as_temporal_dates
Definition: item_cmpfunc.h:1216
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:103
Definition: item_cmpfunc.h:2537
const char * func_name() const override
Definition: item_cmpfunc.h:699
Item_cond_and(THD *thd, Item_cond_and *item)
Definition: item_cmpfunc.h:2547
Item_func_not_all(Item *a)
Definition: item_cmpfunc.h:896
bool transform(const dd::Spatial_reference_system *source_srs, const Geometry &in, const dd::Spatial_reference_system *target_srs, const char *func_name, std::unique_ptr< Geometry > *out) noexcept
Transforms a geometry from one SRS to another.
Definition: transform.cc:228
void cleanup()
Definition: item_cmpfunc.cc:720
Definition: items.h:34
Item_result cmp_type
Definition: item_cmpfunc.h:1878
Item_in_subselect * owner
Definition: item_cmpfunc.h:2161
size_t max_character_length() const
Definition: item_cmpfunc.h:100
const char * func_name() const override
Definition: item_cmpfunc.h:1408
Item_basic_constant * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1661
Definition: item_cmpfunc.h:1260
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:644
String m_str_value
String buffer.
Definition: item_cmpfunc.h:1762
This trigger type deactivates predicated from WHERE condition when no row satisfying the join conditi...
Definition: item_cmpfunc.h:810
Item_func_bool_const()
Definition: item_cmpfunc.h:340
Item_func_nullif(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1423
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:905
The <=> operator evaluates the same as.
Definition: item_cmpfunc.h:1049
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:799
Item_bool_func super
Definition: item_cmpfunc.h:2284
Dialog Client Authentication nullptr
Definition: dialog.cc:353
Item * escape_item
Definition: item_cmpfunc.h:2218
in_datetime_as_longlong(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1587
bool push_front(T *a)
Definition: sql_list.h:458
const char * func_name() const override
&#39;<if>&#39;, to distinguish from the if() SQL function
Definition: item_cmpfunc.h:852
Item_cond_and()
Definition: item_cmpfunc.h:2542
Item_cond_and(List< Item > &list_arg)
Definition: item_cmpfunc.h:2548
Item_bool_func2(Item *a, Item *b)
Definition: item_cmpfunc.h:613
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1144
cmp_item ** comparators
Definition: item_cmpfunc.h:2063
virtual void store_value_by_template(cmp_item *, Item *item)
Definition: item_cmpfunc.h:1705
bool negated
Definition: item_cmpfunc.h:1183