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