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