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