MySQL 9.6.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 public:
1540 Item_func_ifnull(const POS &pos, Item *a, Item *b)
1541 : Item_func_coalesce(pos, a, b) {}
1542 double real_op() override;
1543 longlong int_op() override;
1544 String *str_op(String *str) override;
1545 bool date_op(Date_val *date, my_time_flags_t flags) override;
1546 bool datetime_op(Datetime_val *dt, my_time_flags_t flags) override;
1547 bool time_op(Time_val *time) override;
1548 my_decimal *decimal_op(my_decimal *) override;
1549 bool val_json(Json_wrapper *result) override;
1550 const char *func_name() const override { return "ifnull"; }
1551 Field *tmp_table_field(TABLE *table) override;
1552};
1553
1554/**
1555 ANY_VALUE(expr) is like expr except that it is not checked by
1556 aggregate_check logic. It serves as a solution for users who want to
1557 bypass this logic.
1558*/
1560 public:
1561 Item_func_any_value(const POS &pos, Item *a) : Item_func_coalesce(pos, a) {}
1563 const char *func_name() const override { return "any_value"; }
1564 bool aggregate_check_group(uchar *arg) override;
1565 bool aggregate_check_distinct(uchar *arg) override;
1567
1568 private:
1569 // used when walk'ing with collect_item_field_or_view_ref_processor
1570 bool m_phase_post{false};
1571};
1572
1573class Item_func_if final : public Item_func {
1575
1576 public:
1578 : Item_func(a, b, c), cached_result_type(INT_RESULT) {
1579 null_on_null = false;
1580 }
1581 Item_func_if(const POS &pos, Item *a, Item *b, Item *c)
1582 : Item_func(pos, a, b, c), cached_result_type(INT_RESULT) {
1583 null_on_null = false;
1584 }
1585
1586 double val_real() override;
1587 longlong val_int() override;
1588 String *val_str(String *str) override;
1589 my_decimal *val_decimal(my_decimal *) override;
1590 bool val_json(Json_wrapper *wr) override;
1591 bool val_date(Date_val *date, my_time_flags_t flags) override;
1592 bool val_time(Time_val *time) override;
1593 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
1594 enum Item_result result_type() const override { return cached_result_type; }
1595 bool fix_fields(THD *, Item **) override;
1597 return MYSQL_TYPE_VARCHAR;
1598 }
1599 bool resolve_type(THD *thd) override;
1600 bool resolve_type_inner(THD *thd) override;
1601 void fix_after_pullout(Query_block *parent_query_block,
1602 Query_block *removed_query_block) override;
1603 TYPELIB *get_typelib() const override;
1604 const char *func_name() const override { return "if"; }
1605 enum Functype functype() const override { return IF_FUNC; }
1606 void update_used_tables() override;
1607
1608 ///< T1(IF(e,e1,e2)) = intersection(T1(e1),T1(e2))
1611 (args[1]->not_null_tables() & args[2]->not_null_tables());
1612 }
1613};
1614
1615/**
1616 IF function with result fixed as boolean value.
1617 Result values must be constant boolean values.
1618 For internal use only.
1619*/
1620class Item_bool_if final : public Item_bool_func {
1621 public:
1622 Item_bool_if(Item *a, Item *b, Item *c) : Item_bool_func(a, b, c) {
1623 null_on_null = false;
1624 }
1625 longlong val_int() override {
1626 Item *val = args[0]->val_int() ? args[1] : args[2];
1627 longlong result = val->val_int();
1628 null_value = result ? false : val->null_value;
1629 return result;
1630 }
1631 bool resolve_type(THD *) override {
1632 assert(args[1]->const_item() && args[2]->const_item());
1633 return false;
1634 }
1635 const char *func_name() const override { return "if"; }
1636 enum Functype functype() const override { return BOOL_IF_FUNC; }
1637};
1638
1639class Item_func_nullif final : public Item_bool_func2 {
1641
1642 public:
1643 Item_func_nullif(const POS &pos, Item *a, Item *b)
1644 : Item_bool_func2(pos, a, b), cached_result_type(INT_RESULT) {
1645 null_on_null = false;
1646 }
1647 double val_real() override;
1648 longlong val_int() override;
1649 String *val_str(String *str) override;
1650 my_decimal *val_decimal(my_decimal *) override;
1651 bool val_json(Json_wrapper *wr) override;
1652 Item_result result_type() const override { return cached_result_type; }
1654 return MYSQL_TYPE_VARCHAR;
1655 }
1656 bool resolve_type(THD *thd) override;
1657 bool resolve_type_inner(THD *thd) override;
1658 TYPELIB *get_typelib() const override;
1659 const char *func_name() const override { return "nullif"; }
1660 enum Functype functype() const override { return NULLIF_FUNC; }
1661
1662 // No, we should NOT inherit from Item_bool_func2
1663 uint decimal_precision() const override { return Item::decimal_precision(); }
1664
1665 void print(const THD *thd, String *str,
1666 enum_query_type query_type) const override {
1667 Item_func::print(thd, str, query_type);
1668 }
1669 uint64 hash() override { return Item_func::hash(); }
1670
1671 bool is_null() override;
1672 /**
1673 This is a workaround for the broken inheritance hierarchy: this should
1674 inherit from Item_func instead of Item_bool_func2
1675 */
1676 bool is_bool_func() const override { return false; }
1677};
1678
1679/* Functions to handle the optimized IN */
1680
1681/* A vector of values of some type */
1682
1684 private:
1685 const uint m_size; ///< Size of the vector
1686 public:
1687 uint m_used_size{0}; ///< The actual size of the vector (NULL may be ignored)
1688
1689 /**
1690 See Item_func_in::resolve_type() for why we need both
1691 count and used_count.
1692 */
1693 explicit In_vector(uint elements) : m_size(elements) {}
1694
1695 virtual ~In_vector() = default;
1696
1697 /**
1698 Calls item->val_int() or item->val_str() etc.
1699 and then does binary_search if the value is non-null.
1700 @param item to evaluate, and lookup in the IN-list.
1701 @return true if evaluated value of the item was found.
1702 */
1703 virtual bool find_item(Item *item) = 0;
1704
1705 /**
1706 Create an instance of Item_{type} (e.g. Item_decimal) constant object
1707 which type allows it to hold an element of this vector without any
1708 conversions.
1709 The purpose of this function is to be able to get elements of this
1710 vector in form of Item_xxx constants without creating Item_xxx object
1711 for every array element you get (i.e. this implements "FlyWeight" pattern)
1712
1713 @param mem_root Where to allocate the Item.
1714 */
1715 virtual Item *create_item(MEM_ROOT *mem_root) const = 0;
1716
1717 /**
1718 Store the value at position #pos into provided item object
1719
1720 @param pos Index of value to store
1721 @param item Constant item to store value into. The item must be of the same
1722 type that create_item() returns.
1723 */
1724 virtual void value_to_item(uint pos, Item *item) const = 0;
1725
1726 /** Compare values number pos1 and pos2 for equality */
1727 virtual bool compare_elems(uint pos1, uint pos2) const = 0;
1728
1729 virtual bool is_row_result() const { return false; }
1730
1731 /**
1732 Fill the vector by evaluating the items passed as arguments.
1733 Note that null values are skipped so the vector may end up containing
1734 fewer elements than the number of items.
1735 The vector is sorted so that it can be used for binary search.
1736
1737 @param items Items to evaluate
1738 @param item_count Number of items
1739
1740 @return true if any null values was found, false otherwise.
1741 */
1742 bool fill(Item **items, uint item_count);
1743 virtual void cleanup() {}
1744
1745 private:
1746 /**
1747 Evaluate item and set value into element "pos" of the vector.
1748
1749 @param pos element number in vector
1750 @param item item to evaluate
1751
1752 @returns false if successful evaluation and not null value, true otherwise
1753 */
1754 virtual bool set(uint pos, Item *item) = 0;
1755
1756 /// Sort the IN-list array, so we can do efficient lookup with binary_search.
1757 virtual void sort_array() = 0;
1758};
1759
1760class In_vector_string final : public In_vector {
1764 // String objects are not sortable, sort pointers instead.
1767
1768 public:
1769 In_vector_string(MEM_ROOT *mem_root, uint elements, const CHARSET_INFO *cs);
1770 Item *create_item(MEM_ROOT *mem_root) const override {
1771 return new (mem_root) Item_string(collation);
1772 }
1773 void value_to_item(uint pos, Item *item) const override {
1774 down_cast<Item_basic_constant *>(item)->set_str_value(base_pointers[pos]);
1775 }
1776 bool find_item(Item *item) override;
1777 bool compare_elems(uint pos1, uint pos2) const override;
1778 void cleanup() override;
1779
1780 private:
1781 bool set(uint pos, Item *item) override;
1782 void sort_array() override;
1783};
1784
1785class In_vector_int : public In_vector {
1786 public:
1790 };
1791
1792 protected:
1794
1795 public:
1797 : In_vector(elements), base(mem_root, elements) {}
1798 Item *create_item(MEM_ROOT *mem_root) const override {
1799 /*
1800 We've created a signed INT, this may not be correct in the
1801 general case (see BUG#19342).
1802 */
1803 return new (mem_root) Item_int(0LL);
1804 }
1805 void value_to_item(uint pos, Item *item) const override {
1806 down_cast<Item_int *>(item)->value = base[pos].val;
1807 item->unsigned_flag = base[pos].unsigned_flag;
1808 }
1809 bool find_item(Item *item) override;
1810 bool compare_elems(uint pos1, uint pos2) const override;
1811
1812 private:
1813 bool set(uint pos, Item *item) override { return val_item(item, &base[pos]); }
1814 void sort_array() override;
1815 virtual bool val_item(Item *item, packed_longlong *result);
1816};
1817
1819 public:
1821 : In_vector_int(mem_root, elements) {}
1822 Item *create_item(MEM_ROOT *mem_root) const override {
1823 return new (mem_root) Item_temporal(MYSQL_TYPE_DATETIME, 0LL);
1824 }
1825
1826 private:
1827 bool val_item(Item *item, packed_longlong *result) override;
1828};
1829
1830class In_vector_time final : public In_vector {
1831 public:
1833 : In_vector(elements), base(mem_root, elements) {}
1834 Item *create_item(MEM_ROOT *mem_root) const override {
1835 return new (mem_root) Item_cache_time();
1836 }
1837 void value_to_item(uint pos, Item *item) const override {
1838 down_cast<Item_cache_time *>(item)->store_value(base[pos]);
1839 }
1840 bool find_item(Item *item) override;
1841 bool compare_elems(uint pos1, uint pos2) const override;
1842
1843 private:
1845
1846 bool set(uint pos, Item *item) override;
1847 void sort_array() override;
1848};
1849
1850/*
1851 Class to represent a vector of constant DATE/DATETIME values.
1852 Values are obtained with help of the get_datetime_value() function.
1853*/
1854class in_datetime final : public In_vector_int {
1855 /// An item used to issue warnings.
1857
1858 public:
1859 in_datetime(MEM_ROOT *mem_root, Item *warn_item_arg, uint elements)
1860 : In_vector_int(mem_root, elements), warn_item(warn_item_arg) {}
1861 Item *create_item(MEM_ROOT *mem_root) const override {
1862 return new (mem_root) Item_temporal(MYSQL_TYPE_DATETIME, 0LL);
1863 }
1864
1865 private:
1866 bool set(uint pos, Item *item) override;
1867 bool val_item(Item *item, packed_longlong *result) override;
1868};
1869
1870class In_vector_double final : public In_vector {
1872
1873 public:
1875 : In_vector(elements), base(mem_root, elements) {}
1876 Item *create_item(MEM_ROOT *mem_root) const override {
1877 return new (mem_root) Item_float(0.0, 0);
1878 }
1879 void value_to_item(uint pos, Item *item) const override {
1880 down_cast<Item_float *>(item)->value = base[pos];
1881 }
1882 bool find_item(Item *item) override;
1883 bool compare_elems(uint pos1, uint pos2) const override;
1884
1885 private:
1886 bool set(uint pos, Item *item) override;
1887 void sort_array() override;
1888};
1889
1890class In_vector_decimal final : public In_vector {
1892
1893 public:
1895 : In_vector(elements), base(mem_root, elements) {}
1896 Item *create_item(MEM_ROOT *mem_root) const override {
1897 return new (mem_root) Item_decimal(0, false);
1898 }
1899 void value_to_item(uint pos, Item *item) const override {
1900 down_cast<Item_decimal *>(item)->set_decimal_value(&base[pos]);
1901 }
1902 bool find_item(Item *item) override;
1903 bool compare_elems(uint pos1, uint pos2) const override;
1904
1905 private:
1906 bool set(uint pos, Item *item) override;
1907 void sort_array() override;
1908};
1909
1910/*
1911** Classes for easy comparing of non const items
1912*/
1913
1915 public:
1916 cmp_item() = default;
1917 virtual ~cmp_item() = default;
1918 /**
1919 Allocate comparator objects for each value object, based on the template
1920 comparator objects. Only implemented for derived class cmp_item_row.
1921
1922 @param mem_root mem_root for allocation.
1923 @param tmpl The template item object.
1924 @param arg The value item.
1925
1926 @returns false if success, true if error.
1927 */
1928 virtual bool allocate_value_comparators(MEM_ROOT *mem_root, cmp_item *tmpl,
1929 Item *arg);
1930 virtual void store_value(Item *item) = 0;
1931 /**
1932 @returns result (true, false or UNKNOWN) of
1933 "stored argument's value <> item's value"
1934 */
1935 virtual int cmp(Item *item) = 0;
1936 // for optimized IN with row
1937 virtual int compare(const cmp_item *item) const = 0;
1938
1939 /**
1940 Create an appropriate comparator for the given type.
1941
1942 @param thd Session handle.
1943 @param result_type Used to find the appropriate comparator.
1944 @param item Item object used to distinguish temporal types.
1945 @param cs Charset
1946
1947 @returns new cmp_item_xxx object, or nullptr if error.
1948 */
1949 static cmp_item *new_comparator(THD *thd, Item_result result_type, Item *item,
1950 const CHARSET_INFO *cs);
1951 virtual cmp_item *make_same() = 0;
1952 virtual void store_value_by_template(cmp_item *, Item *item) {
1953 store_value(item);
1954 }
1955 virtual void set_null_value(bool nv) = 0;
1956};
1957
1958/// cmp_item which stores a scalar (i.e. non-ROW).
1960 protected:
1961 bool m_null_value; ///< If stored value is NULL
1962 void set_null_value(bool nv) override { m_null_value = nv; }
1963};
1964
1965class cmp_item_string final : public cmp_item_scalar {
1966 private:
1970
1971 public:
1972 cmp_item_string(const CHARSET_INFO *cs) : value(cs), cmp_charset(cs) {}
1973
1974 int compare(const cmp_item *ci) const override {
1975 const cmp_item_string *l_cmp = down_cast<const cmp_item_string *>(ci);
1976 return sortcmp(value_res, l_cmp->value_res, cmp_charset);
1977 }
1978
1979 void store_value(Item *item) override {
1980 String *res = eval_string_arg(cmp_charset, item, &value);
1981 if (res && (res != &value || !res->is_alloced())) {
1982 // 'res' may point in item's transient internal data, so make a copy
1983 value.copy(*res);
1984 }
1985 value_res = &value;
1986 set_null_value(item->null_value);
1987 }
1988
1989 int cmp(Item *arg) override;
1990 cmp_item *make_same() override;
1991};
1992
1993class cmp_item_json final : public cmp_item_scalar {
1994 private:
1995 /// Cached JSON value to look up
1997 /// Cache for the value above
1999 /// String buffer
2001
2002 public:
2003 /**
2004 Construct a cmp_item_json object.
2005 @param wrapper a Json_wrapper for holding the JSON value in the comparison
2006 @param holder pre-alloced memory for creating JSON scalar values without
2007 using the heap
2008 */
2011 ~cmp_item_json() override;
2012
2013 int compare(const cmp_item *ci) const override;
2014 void store_value(Item *item) override;
2015 int cmp(Item *arg) override;
2016 cmp_item *make_same() override;
2017};
2018
2019class cmp_item_int final : public cmp_item_scalar {
2021
2022 public:
2023 void store_value(Item *item) override {
2024 value = item->val_int();
2025 set_null_value(item->null_value);
2026 }
2027 int cmp(Item *arg) override {
2028 const bool rc = value != arg->val_int();
2029 return (m_null_value || arg->null_value) ? UNKNOWN : rc;
2030 }
2031 int compare(const cmp_item *ci) const override {
2032 const cmp_item_int *l_cmp = down_cast<const cmp_item_int *>(ci);
2033 return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
2034 }
2035 cmp_item *make_same() override;
2036};
2037
2038/*
2039 Compare items of temporal type.
2040 Values are obtained with: get_datetime_value() (DATE/DATETIME/TIMESTAMP) and
2041 get_time_value() (TIME).
2042*/
2045
2046 public:
2047 /* Item used for issuing warnings. */
2049 /// Distinguish between DATE/DATETIME/TIMESTAMP and TIME
2051
2052 cmp_item_datetime(const Item *warn_item_arg);
2053 void store_value(Item *item) override;
2054 int cmp(Item *arg) override;
2055 int compare(const cmp_item *ci) const override;
2056 cmp_item *make_same() override;
2057};
2058
2060 double value;
2061
2062 public:
2063 void store_value(Item *item) override {
2064 value = item->val_real();
2065 set_null_value(item->null_value);
2066 }
2067 int cmp(Item *arg) override {
2068 const bool rc = value != arg->val_real();
2069 return (m_null_value || arg->null_value) ? UNKNOWN : rc;
2070 }
2071 int compare(const cmp_item *ci) const override {
2072 const cmp_item_real *l_cmp = down_cast<const cmp_item_real *>(ci);
2073 return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
2074 }
2075 cmp_item *make_same() override;
2076};
2077
2080
2081 public:
2082 void store_value(Item *item) override;
2083 int cmp(Item *arg) override;
2084 int compare(const cmp_item *c) const override;
2085 cmp_item *make_same() override;
2086};
2087
2088/**
2089 CASE ... WHEN ... THEN ... END function implementation.
2090
2091 When there is no expression between CASE and the first WHEN
2092 (the CASE expression) then this function simple checks all WHEN expressions
2093 one after another. When some WHEN expression evaluated to TRUE then the
2094 value of the corresponding THEN expression is returned.
2095
2096 When the CASE expression is specified then it is compared to each WHEN
2097 expression individually. When an equal WHEN expression is found
2098 corresponding THEN expression is returned.
2099 In order to do correct comparisons several comparators are used. One for
2100 each result type. Different result types that are used in particular
2101 CASE ... END expression are collected in the resolve_type() member
2102 function and only comparators for there result types are used.
2103*/
2104
2105class Item_func_case final : public Item_func {
2107
2108 int first_expr_num, else_expr_num;
2109 enum Item_result cached_result_type, left_result_type;
2114 cmp_item *cmp_items[5]; /* For all result types */
2116
2117 protected:
2118 void add_json_info(Json_object *obj) override {
2119 obj->add_alias("has_case_expression",
2120 create_dom_ptr<Json_boolean>(get_first_expr_num() != -1));
2121 }
2122
2123 public:
2125 Item *first_expr_arg, Item *else_expr_arg)
2126 : super(pos),
2127 first_expr_num(-1),
2128 else_expr_num(-1),
2129 cached_result_type(INT_RESULT),
2130 left_result_type(INT_RESULT),
2131 case_item(nullptr) {
2132 null_on_null = false;
2133 ncases = list->size();
2134 if (first_expr_arg) {
2135 first_expr_num = list->size();
2136 list->push_back(first_expr_arg);
2137 }
2138 if (else_expr_arg) {
2139 else_expr_num = list->size();
2140 list->push_back(else_expr_arg);
2141 }
2142 set_arguments(list, true);
2143 memset(&cmp_items, 0, sizeof(cmp_items));
2144 }
2145 ~Item_func_case() override;
2146 int get_first_expr_num() const { return first_expr_num; }
2147 int get_else_expr_num() const { return else_expr_num; }
2148 double val_real() override;
2149 longlong val_int() override;
2150 String *val_str(String *) override;
2151 my_decimal *val_decimal(my_decimal *) override;
2152 bool val_json(Json_wrapper *wr) override;
2153 bool val_date(Date_val *date, my_time_flags_t flags) override;
2154 bool val_time(Time_val *time) override;
2155 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
2156 bool fix_fields(THD *thd, Item **ref) override;
2158 return MYSQL_TYPE_VARCHAR;
2159 }
2160 bool resolve_type(THD *thd) override;
2161 bool resolve_type_inner(THD *thd) override;
2162 TYPELIB *get_typelib() const override;
2163 enum Item_result result_type() const override { return cached_result_type; }
2164 const char *func_name() const override { return "case"; }
2165 void print(const THD *thd, String *str,
2166 enum_query_type query_type) const override;
2167 uint64 hash() override;
2168 Item *find_item(String *str);
2169 const CHARSET_INFO *compare_collation() const override {
2170 return cmp_collation.collation;
2171 }
2172 enum Functype functype() const override { return CASE_FUNC; }
2173};
2174
2175/**
2176 in_expr [NOT] IN (in_value_list).
2177
2178 The current implementation distinguishes 2 cases:
2179 1) all items in in_value_list are constants and have the same
2180 result type. This case is handled by In_vector class.
2181 2) otherwise Item_func_in employs several cmp_item objects to perform
2182 comparisons of in_expr and an item from in_value_list. One cmp_item
2183 object for each result type. Different result types are collected in the
2184 resolve_type() member function by means of collect_cmp_types() function.
2185*/
2186class Item_func_in final : public Item_func_opt_neg {
2187 public:
2188 /// An array of const values, created when the bisection lookup method is used
2189 In_vector *m_const_array{nullptr};
2190 /**
2191 If there is some NULL among @<in value list@>, during a val_int() call; for
2192 example
2193 IN ( (1,(3,'col')), ... ), where 'col' is a column which evaluates to
2194 NULL.
2195 */
2196 bool have_null{false};
2197 /// Set to true when values in const array are populated
2198 bool m_populated{false};
2199
2200 private:
2201 /// Set to true if all values in IN-list are const
2202 bool m_values_are_const{true};
2203 /// Set to true if const array must be repopulated per execution.
2204 bool m_need_populate{false};
2205 /**
2206 Set to true by resolve_type() if the IN list contains a
2207 dependent subquery, in which case condition filtering will not be
2208 calculated for this item.
2209 */
2210 bool dep_subq_in_list{false};
2211 /// True until start of 2nd call to resolve_type()
2212 bool first_resolve_call{true};
2213
2215 cmp_item *cmp_items[6]; /* One cmp_item for each result type */
2217
2218 public:
2219 Item_func_in(const POS &pos, PT_item_list *list, bool is_negation)
2220 : Item_func_opt_neg(pos, list, is_negation) {
2221 memset(&cmp_items, 0, sizeof(cmp_items));
2222 allowed_arg_cols = 0; // Fetch this value from first argument
2223 }
2224 ~Item_func_in() override;
2225 longlong val_int() override;
2226 bool fix_fields(THD *, Item **) override;
2227 void fix_after_pullout(Query_block *parent_query_block,
2228 Query_block *removed_query_block) override;
2229 bool resolve_type(THD *) override;
2230 void update_used_tables() override;
2231 uint decimal_precision() const override { return 1; }
2232
2233 /**
2234 Populate values for bisection with fresh values, should be called once
2235 per execution.
2236
2237 @param thd Thread handler
2238
2239 @returns false if success, true if error
2240 */
2241 bool populate_bisection(THD *thd);
2242 void cleanup() override;
2243 optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
2244 void print(const THD *thd, String *str,
2245 enum_query_type query_type) const override;
2246 uint64 hash() override;
2247 enum Functype functype() const override { return IN_FUNC; }
2248 const char *func_name() const override { return " IN "; }
2249 bool is_bool_func() const override { return true; }
2250 const CHARSET_INFO *compare_collation() const override {
2251 return cmp_collation.collation;
2252 }
2253 bool gc_subst_analyzer(uchar **) override { return true; }
2254
2255 float get_filtering_effect(THD *thd, table_map filter_for_table,
2256 table_map read_tables,
2257 const MY_BITMAP *fields_to_ignore,
2258 double rows_in_table) override;
2259
2261 // not_null_tables_cache == union(T1(e),union(T1(ei)))
2262 if (pred_level && negated) return;
2263
2265
2266 ///< not_null_tables_cache = union(T1(e),intersection(T1(ei)))
2267 Item **arg_end = args + arg_count;
2268 for (Item **arg = args + 1; arg != arg_end; arg++)
2269 not_null_tables_cache &= (*arg)->not_null_tables();
2271 }
2272
2273 // Disable constant propagation.
2274 void set_no_constant_propagation();
2275
2276 private:
2277 /**
2278 Usable if @<in value list@> is made only of constants. Returns true if one
2279 of these constants contains a NULL. Example:
2280 IN ( (-5, (12,NULL)), ... ).
2281 */
2282 bool list_contains_null();
2283 /**
2284 Utility function to help calculate the total filtering effect of
2285 IN predicates. This function calculates the filtering effect from
2286 a single field (or field reference) on the left hand side of the
2287 expression.
2288
2289 @param fieldref Field (or field reference) on left hand side of
2290 IN, i.e., this function should be called for
2291 each fi in "(f1,...,fn) IN (values)"
2292 @param filter_for_table The table we are calculating filter effect for
2293 @param fields_to_ignore Fields in 'filter_for_table' that should not
2294 be part of the filter calculation. The filtering
2295 effect of these fields are already part of the
2296 calculation somehow (e.g. because there is a
2297 predicate "col = <const>", and the optimizer
2298 has decided to do ref access on 'col').
2299 @param rows_in_table The number of rows in table 'filter_for_table'
2300
2301 @return the filtering effect (between 0 and 1) 'the_field'
2302 participates with in this IN predicate.
2303 */
2304 float get_single_col_filtering_effect(Item_ident *fieldref,
2305 table_map filter_for_table,
2306 const MY_BITMAP *fields_to_ignore,
2307 double rows_in_table);
2308 void cleanup_arrays(); ///< Helper function for this common task
2309};
2310
2311class cmp_item_row : public cmp_item {
2312 cmp_item **comparators{nullptr};
2313 uint n{0};
2314
2315 public:
2316 // Only used for Mem_root_array::resize()
2317 cmp_item_row() = default;
2318
2319 cmp_item_row(THD *thd, Item *item) : n(item->cols()) {
2320 allocate_template_comparators(thd, item);
2321 }
2322 ~cmp_item_row() override;
2323
2325 : comparators(other.comparators), n(other.n) {
2326 other.comparators = nullptr;
2327 other.n = 0;
2328 }
2329
2330 bool allocate_value_comparators(MEM_ROOT *mem_root, cmp_item *tmpl,
2331 Item *arg) override;
2332 void store_value(Item *item) override;
2333 int cmp(Item *arg) override;
2334 int compare(const cmp_item *arg) const override;
2335 cmp_item *make_same() override;
2336 void store_value_by_template(cmp_item *tmpl, Item *) override;
2337 void set_null_value(bool nv) override {
2338 for (uint i = 0; i < n; i++) {
2339 comparators[i]->set_null_value(nv);
2340 }
2341 }
2342
2343 private:
2344 /**
2345 Allocate comparator objects for the LHS argument to IN, used as template
2346 for the value comparators.
2347
2348 @param thd Session handle
2349 @param item Item to allocate comparator objects for, left-hand IN operand
2350
2351 @returns false if success, true if error.
2352 */
2353 bool allocate_template_comparators(THD *thd, Item *item);
2354};
2355
2356class in_row final : public In_vector {
2359 // Sort pointers, rather than objects.
2361
2362 public:
2363 in_row(MEM_ROOT *mem_root, uint elements, cmp_item_row *cmp);
2364 bool is_row_result() const override { return true; }
2365 /**
2366 Allocate extra objects for evaluation
2367
2368 @param mem_root Memory root for allocation.
2369 @param lhs The left-hand side object of the IN predicate.
2370 @param arg_count Number of arguments on the right-hand side of the predicate
2371
2372 @returns false if success, true if error.
2373 */
2374 bool allocate(MEM_ROOT *mem_root, Item *lhs, uint arg_count);
2375 bool find_item(Item *item) override;
2376 bool compare_elems(uint pos1, uint pos2) const override;
2377
2378 Item *create_item(MEM_ROOT *) const override {
2379 assert(false);
2380 return nullptr;
2381 }
2382 void value_to_item(uint, Item *) const override { assert(false); }
2383
2384 private:
2385 bool set(uint pos, Item *item) override;
2386 void sort_array() override;
2387};
2388
2389/* Functions used by where clause */
2390
2393
2394 bool cache_used = false;
2396
2397 public:
2399 Item_func_isnull(const POS &pos, Item *a) : super(pos, a) {
2400 null_on_null = false;
2401 }
2402 longlong val_int() override;
2403 enum Functype functype() const override { return ISNULL_FUNC; }
2404 bool resolve_type(THD *thd) override;
2405 const char *func_name() const override { return "isnull"; }
2406 /* Optimize case of not_null_column IS NULL */
2407 void update_used_tables() override;
2408
2409 float get_filtering_effect(THD *thd, table_map filter_for_table,
2410 table_map read_tables,
2411 const MY_BITMAP *fields_to_ignore,
2412 double rows_in_table) override;
2413 optimize_type select_optimize(const THD *) override { return OPTIMIZE_NULL; }
2414 Item *truth_transformer(THD *, Bool_test test) override;
2415 void print(const THD *thd, String *str,
2416 enum_query_type query_type) const override;
2417 uint64 hash() override;
2418 const CHARSET_INFO *compare_collation() const override {
2419 return args[0]->collation.collation;
2420 }
2421 bool fix_fields(THD *thd, Item **ref) override;
2422};
2423
2424/* Functions used by HAVING for rewriting IN subquery */
2425
2426/*
2427 This is like IS NOT NULL but it also remembers if it ever has
2428 encountered a NULL; it remembers this in the "was_null" property of the
2429 "owner" item.
2430*/
2433
2434 public:
2436 : Item_func_isnull(a), owner(ow) {}
2437 enum Functype functype() const override { return ISNOTNULLTEST_FUNC; }
2438 longlong val_int() override;
2439 const char *func_name() const override { return "<is_not_null_test>"; }
2440 bool resolve_type(THD *thd) override;
2441 void update_used_tables() override;
2442 /**
2443 We add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE.
2444
2445 @retval Always RAND_TABLE_BIT
2446 */
2448 return RAND_TABLE_BIT;
2449 }
2450 void print(const THD *thd, String *str,
2451 enum_query_type query_type) const override {
2452 Item_bool_func::print(thd, str, query_type);
2453 }
2454};
2455
2457 public:
2459 Item_func_isnotnull(const POS &pos, Item *a) : Item_bool_func(pos, a) {
2460 null_on_null = false;
2461 }
2462
2463 longlong val_int() override;
2464 enum Functype functype() const override { return ISNOTNULL_FUNC; }
2465 bool resolve_type(THD *thd) override {
2466 set_nullable(false);
2467 return Item_bool_func::resolve_type(thd);
2468 }
2469 const char *func_name() const override { return "isnotnull"; }
2470 optimize_type select_optimize(const THD *) override { return OPTIMIZE_NULL; }
2471 Item *truth_transformer(THD *, Bool_test test) override;
2472 void print(const THD *thd, String *str,
2473 enum_query_type query_type) const override;
2474 uint64 hash() override;
2475 const CHARSET_INFO *compare_collation() const override {
2476 return args[0]->collation.collation;
2477 }
2478 void apply_is_true() override {
2479 null_on_null = true;
2480 } // Same logic as for Item_func_truth's function
2481 float get_filtering_effect(THD *thd, table_map filter_for_table,
2482 table_map read_tables,
2483 const MY_BITMAP *fields_to_ignore,
2484 double rows_in_table) override;
2485};
2486
2487class Item_func_like final : public Item_bool_func2 {
2488 /// True if escape clause is const (a literal)
2489 bool escape_is_const = false;
2490 /// Tells if the escape clause has been evaluated.
2491 bool escape_evaluated = false;
2492 bool eval_escape_clause(THD *thd);
2493 /// The escape character (0 if no escape character).
2495
2496 public:
2498 Item_func_like(Item *a, Item *b, Item *escape_arg)
2499 : Item_bool_func2(a, b, escape_arg) {
2500 assert(escape_arg != nullptr);
2501 }
2502 Item_func_like(const POS &pos, Item *a, Item *b, Item *escape_arg)
2503 : Item_bool_func2(pos, a, b, escape_arg) {
2504 assert(escape_arg != nullptr);
2505 }
2506 Item_func_like(const POS &pos, Item *a, Item *b)
2507 : Item_bool_func2(pos, a, b) {}
2508
2509 longlong val_int() override;
2510 enum Functype functype() const override { return LIKE_FUNC; }
2511 optimize_type select_optimize(const THD *thd) override;
2512 /// Result may be not equal with equal inputs if ESCAPE character is present
2513 cond_result eq_cmp_result() const override { return COND_OK; }
2514 const char *func_name() const override { return "like"; }
2515 bool fix_fields(THD *thd, Item **ref) override;
2516 bool resolve_type(THD *) override;
2517 void cleanup() override;
2518 Item *replace_scalar_subquery(uchar *) override;
2519 // Overridden because Item_bool_func2::print() doesn't print the ESCAPE
2520 // clause.
2521 void print(const THD *thd, String *str,
2522 enum_query_type query_type) const override;
2523 uint64 hash() override;
2524 /**
2525 @retval true non default escape char specified
2526 using "expr LIKE pat ESCAPE 'escape_char'" syntax
2527 */
2528 bool escape_was_used_in_parsing() const { return arg_count > 2; }
2529
2530 /// Returns the escape character.
2531 int escape() const {
2532 assert(escape_is_evaluated());
2533 return m_escape;
2534 }
2535
2536 /**
2537 Has the escape clause been evaluated? It only needs to be evaluated
2538 once per execution, since we require it to be constant during execution.
2539 The escape member has a valid value if and only if this function returns
2540 true.
2541 */
2542 bool escape_is_evaluated() const { return escape_evaluated; }
2543
2544 float get_filtering_effect(THD *thd, table_map filter_for_table,
2545 table_map read_tables,
2546 const MY_BITMAP *fields_to_ignore,
2547 double rows_in_table) override;
2548
2549 private:
2550 /**
2551 The method updates covering keys depending on the
2552 length of wild string prefix.
2553
2554 @param thd Pointer to THD object.
2555
2556 @retval true if error happens during wild string prefix calculation,
2557 false otherwise.
2558 */
2559 bool check_covering_prefix_keys(THD *thd);
2560};
2561
2564
2565 protected:
2568
2569 public:
2570 /* Item_cond() is only used to create top level items */
2573 list.push_back(i1);
2574 list.push_back(i2);
2575 }
2576 Item_cond(const POS &pos, Item *i1, Item *i2)
2577 : Item_bool_func(pos), abort_on_null(false) {
2578 list.push_back(i1);
2579 list.push_back(i2);
2580 }
2581
2582 Item_cond(THD *thd, Item_cond *item);
2584 : Item_bool_func(), list(nlist), abort_on_null(false) {}
2585 Item_cond(const POS &pos, List<Item> &nlist)
2586 : Item_bool_func(pos), list(nlist), abort_on_null(false) {}
2587 bool add(Item *item) {
2588 assert(item);
2589 return list.push_back(item);
2590 }
2591 bool add_at_head(Item *item) {
2592 assert(item);
2593 return list.push_front(item);
2594 }
2596 assert(nlist->elements);
2597 list.prepend(nlist);
2598 }
2599
2600 bool do_itemize(Parse_context *pc, Item **res) override;
2601
2602 bool fix_fields(THD *, Item **ref) override;
2603 void fix_after_pullout(Query_block *parent_query_block,
2604 Query_block *removed_query_block) override;
2605
2606 Type type() const override { return COND_ITEM; }
2608 bool eq(const Item *item) const override;
2609 table_map used_tables() const override { return used_tables_cache; }
2610 void update_used_tables() override;
2611 void print(const THD *thd, String *str,
2612 enum_query_type query_type) const override;
2613 uint64 hash() override;
2614 bool split_sum_func(THD *thd, Ref_item_array ref_item_array,
2615 mem_root_deque<Item *> *fields) override;
2616 void apply_is_true() override { abort_on_null = true; }
2617 void copy_andor_arguments(THD *thd, Item_cond *item);
2618 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
2619 Item *transform(Item_transformer transformer, uchar *arg) override;
2620 void traverse_cond(Cond_traverser, void *arg, traverse_order order) override;
2621 bool truth_transform_arguments(THD *thd, Bool_test test);
2622 bool subst_argument_checker(uchar **) override { return true; }
2623 Item *compile(Item_analyzer analyzer, uchar **arg_p,
2624 Item_transformer transformer, uchar *arg_t) override;
2625 bool remove_const_conds(THD *thd, Item *item, Item **new_item);
2626 /// Treat UNKNOWN result like FALSE because callers see no difference
2627 bool ignore_unknown() const { return abort_on_null; }
2628 bool equality_substitution_analyzer(uchar **) override { return true; }
2629};
2630
2631/**
2632 The class Item_multi_eq is used to represent conjunctions of equality
2633 predicates of the form field1 = field2, and field = const in where
2634 conditions and on join conditions.
2635
2636 All equality predicates of the form field1=field2 contained in a
2637 conjunction are substituted for a sequence of items of this class.
2638 An item of this class Item_multi_eq(f1,f2,...fk) represents a
2639 multiple equality f1=f2=...=fk.
2640
2641 If a conjunction contains predicates f1=f2 and f2=f3, a new item of
2642 this class is created Item_multi_eq(f1,f2,f3) representing the multiple
2643 equality f1=f2=f3 that substitutes the above equality predicates in
2644 the conjunction.
2645 A conjunction of the predicates f2=f1 and f3=f1 and f3=f2 will be
2646 substituted for the item representing the same multiple equality
2647 f1=f2=f3.
2648 An item Item_multi_eq(f1,f2) can appear instead of a conjunction of
2649 f2=f1 and f1=f2, or instead of just the predicate f1=f2.
2650
2651 An item of the class Item_multi_eq inherits equalities from outer
2652 conjunctive levels.
2653
2654 Suppose we have a where condition of the following form:
2655 WHERE f1=f2 AND f3=f4 AND f3=f5 AND ... AND (...OR (f1=f3 AND ...)).
2656 In this case:
2657 f1=f2 will be substituted for Item_multi_eq(f1,f2);
2658 f3=f4 and f3=f5 will be substituted for Item_multi_eq(f3,f4,f5);
2659 f1=f3 will be substituted for Item_multi_eq(f1,f2,f3,f4,f5);
2660
2661 An object of the class Item_multi_eq can contain an optional constant
2662 item c. Then it represents a multiple equality of the form
2663 c=f1=...=fk.
2664
2665 Objects of the class Item_multi_eq are used for the following:
2666
2667 1. An object Item_multi_eq(t1.f1,...,tk.fk) allows us to consider any
2668 pair of tables ti and tj as joined by an equi-condition.
2669 Thus it provide us with additional access paths from table to table.
2670
2671 2. An object Item_multi_eq(t1.f1,...,tk.fk) is applied to deduce new
2672 SARGable predicates:
2673 f1=...=fk AND P(fi) => f1=...=fk AND P(fi) AND P(fj).
2674 It also can give us additional index scans and can allow us to
2675 improve selectivity estimates.
2676
2677 3. An object Item_multi_eq(t1.f1,...,tk.fk) is used to optimize the
2678 selected execution plan for the query: if table ti is accessed
2679 before the table tj then in any predicate P in the where condition
2680 the occurrence of tj.fj is substituted for ti.fi. This can allow
2681 an evaluation of the predicate at an earlier step.
2682
2683 When feature 1 is supported they say that join transitive closure
2684 is employed.
2685 When feature 2 is supported they say that search argument transitive
2686 closure is employed.
2687 Both features are usually supported by preprocessing original query and
2688 adding additional predicates.
2689 We do not just add predicates, we rather dynamically replace some
2690 predicates that can not be used to access tables in the investigated
2691 plan for those, obtained by substitution of some fields for equal fields,
2692 that can be used.
2693
2694 Multiple equality objects are employed only at the optimize phase. Usually
2695 they are not supposed to be evaluated. Yet in some cases we call the method
2696 val_int() for them. We have to take care of restricting the predicate such an
2697 object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
2698*/
2699class Item_multi_eq final : public Item_bool_func {
2700 /// List of equal field items.
2702 /// Optional constant item equal to all the field items.
2703 Item *m_const_arg{nullptr};
2704 /// Helper for comparing the fields.
2705 cmp_item *eval_item{nullptr};
2706 /// Helper for comparing constants.
2708 /// Flag set to true if the equality is known to be always false.
2709 bool m_always_false{false};
2710 /// Should constants be compared as datetimes?
2711 bool compare_as_dates{false};
2712 /// Checks if the current constant value m_const_arg (that each field
2713 /// in fields needs to be equal to during execution) is the same as
2714 /// the provided constant item. If that's not the case, it sets
2715 /// m_always_false to true as a field cannot be equal to different
2716 /// constant values at the same time.
2717 /// @returns false on success, true on error.
2718 bool compare_const(THD *thd, Item *const_item);
2719
2720 public:
2721 ~Item_multi_eq() override;
2722
2723 Item_multi_eq(Item_field *lhs_field, Item_field *rhs_field);
2725 explicit Item_multi_eq(Item_multi_eq *item_multi_eq);
2726
2727 Item_multi_eq(const Item_multi_eq &) = delete;
2729 Item_multi_eq(const Item_multi_eq &&) = delete;
2731
2732 /// Returns the constant Item that this multi equality is equal to(if any).
2733 Item *const_arg() const { return m_const_arg; }
2734 void set_const_arg(Item *const_item) { m_const_arg = const_item; }
2735 bool add(THD *thd, Item *const_item, Item_field *field);
2736 bool add(THD *thd, Item *const_item);
2737 void add(Item_field *field);
2738 uint members();
2739 bool contains(const Item_field *field) const;
2740 /**
2741 Get the first field of multiple equality, use for semantic checking.
2742
2743 @retval First field in the multiple equality.
2744 */
2745 Item_field *get_first() { return fields.head(); }
2746 Item_field *get_subst_item(const Item_field *field);
2747 bool merge(THD *thd, Item_multi_eq *item);
2748 bool update_const(THD *thd);
2749 enum Functype functype() const override { return MULTI_EQ_FUNC; }
2750 longlong val_int() override;
2751 const char *func_name() const override { return "multiple equal"; }
2752 optimize_type select_optimize(const THD *) override { return OPTIMIZE_EQUAL; }
2754 // Multiple equality nodes (Item_multi_eq) should have been
2755 // converted back to simple equalities (Item_func_eq) by
2756 // substitute_for_best_equal_field before cast nodes are injected.
2757 assert(false);
2758 return false;
2759 }
2761 return const_arg() == nullptr;
2762 }
2763
2764 /**
2765 Order field items in multiple equality according to a sorting criteria.
2766
2767 The function perform ordering of the field items in the Item_multi_eq
2768 object according to the criteria determined by the cmp callback parameter.
2769 If cmp(item_field1,item_field2,arg)<0 than item_field1 must be
2770 placed after item_field2.
2771
2772 The function sorts field items by the exchange sort algorithm.
2773 The list of field items is looked through and whenever two neighboring
2774 members follow in a wrong order they are swapped. This is performed
2775 again and again until we get all members in a right order.
2776
2777 @param compare function to compare field item
2778 */
2779 template <typename Node_cmp_func>
2780 void sort(Node_cmp_func compare) {
2781 fields.sort(compare);
2782 }
2783
2784 // A class to iterate over fields without exposing fields directly.
2786 public:
2787 explicit FieldProxy(Item_multi_eq *item) : m_fields(&item->fields) {}
2788 List_STL_Iterator<Item_field> begin() { return m_fields->begin(); }
2789 List_STL_Iterator<Item_field> end() { return m_fields->end(); }
2791 return m_fields->cbegin();
2792 }
2793 List_STL_Iterator<const Item_field> end() const { return m_fields->cend(); }
2795 return m_fields->cbegin();
2796 }
2798 return m_fields->cend();
2799 }
2800
2801 private:
2803 };
2805 public:
2806 explicit ConstFieldProxy(const Item_multi_eq *item)
2807 : m_fields(&item->fields) {}
2809 return m_fields->cbegin();
2810 }
2811 List_STL_Iterator<const Item_field> end() const { return m_fields->cend(); }
2813 return m_fields->cbegin();
2814 }
2816 return m_fields->cend();
2817 }
2818 size_t size() const { return m_fields->size(); }
2819
2820 private:
2822 };
2825
2826 bool resolve_type(THD *) override;
2827 bool fix_fields(THD *thd, Item **ref) override;
2828 void update_used_tables() override;
2829 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
2830 void print(const THD *thd, String *str,
2831 enum_query_type query_type) const override;
2832 uint64 hash() override;
2833 bool eq_specific(const Item *item) const override;
2834 const CHARSET_INFO *compare_collation() const override {
2835 return fields.head()->collation.collation;
2836 }
2837
2838 bool equality_substitution_analyzer(uchar **) override { return true; }
2839
2841
2842 float get_filtering_effect(THD *thd, table_map filter_for_table,
2843 table_map read_tables,
2844 const MY_BITMAP *fields_to_ignore,
2845 double rows_in_table) override;
2846 ///< temporary area used for constant folding
2847 Item *m_const_folding[2]{nullptr, nullptr};
2848
2849 private:
2851};
2852
2854 /// Reference to the multiple equalities of outer level.
2855 COND_EQUAL *upper_levels{nullptr};
2856 /// List of multiple equalities in the current conjunction.
2858};
2859
2860class Item_cond_and final : public Item_cond {
2861 public:
2862 /// Contains list of Item_multi_eq objects for the current conjunction
2863 /// and references to multiple equalities of outer levels.
2866
2867 Item_cond_and(Item *i1, Item *i2) : Item_cond(i1, i2) {}
2868 Item_cond_and(const POS &pos, Item *i1, Item *i2) : Item_cond(pos, i1, i2) {}
2869
2870 Item_cond_and(THD *thd, Item_cond_and *item) : Item_cond(thd, item) {}
2871 Item_cond_and(List<Item> &list_arg) : Item_cond(list_arg) {}
2872 Item_cond_and(const POS &pos, List<Item> &list_arg)
2873 : Item_cond(pos, list_arg) {}
2874 enum Functype functype() const override { return COND_AND_FUNC; }
2875 longlong val_int() override;
2876 uint64_t hash() override { return Item_func::hash(true); }
2877 const char *func_name() const override { return "and"; }
2879 Item_cond_and *item;
2880 if ((item = new Item_cond_and(thd, this)))
2881 item->copy_andor_arguments(thd, this);
2882 return item;
2883 }
2884 Item *truth_transformer(THD *, Bool_test) override;
2885 bool gc_subst_analyzer(uchar **) override { return true; }
2886
2887 float get_filtering_effect(THD *thd, table_map filter_for_table,
2888 table_map read_tables,
2889 const MY_BITMAP *fields_to_ignore,
2890 double rows_in_table) override;
2891
2892 bool contains_only_equi_join_condition() const override;
2893};
2894
2895class Item_cond_or final : public Item_cond {
2896 public:
2898
2899 Item_cond_or(Item *i1, Item *i2) : Item_cond(i1, i2) {}
2900 Item_cond_or(const POS &pos, Item *i1, Item *i2) : Item_cond(pos, i1, i2) {}
2901
2902 Item_cond_or(THD *thd, Item_cond_or *item) : Item_cond(thd, item) {}
2903 Item_cond_or(List<Item> &list_arg) : Item_cond(list_arg) {}
2904 Item_cond_or(const POS &pos, List<Item> &list_arg)
2905 : Item_cond(pos, list_arg) {}
2906 enum Functype functype() const override { return COND_OR_FUNC; }
2907 longlong val_int() override;
2908 const char *func_name() const override { return "or"; }
2910 Item_cond_or *item;
2911 if ((item = new Item_cond_or(thd, this)))
2912 item->copy_andor_arguments(thd, this);
2913 return item;
2914 }
2915 Item *truth_transformer(THD *, Bool_test) override;
2916 bool gc_subst_analyzer(uchar **) override { return true; }
2917
2918 float get_filtering_effect(THD *thd, table_map filter_for_table,
2919 table_map read_tables,
2920 const MY_BITMAP *fields_to_ignore,
2921 double rows_in_table) override;
2922};
2923
2924/// Builds condition: (a AND b) IS TRUE
2925inline Item *and_conds(Item *a, Item *b) {
2926 if (!b) return a;
2927 if (!a) return b;
2928
2929 Item *item = new Item_cond_and(a, b);
2930 if (item == nullptr) return nullptr;
2931 item->apply_is_true();
2932 return item;
2933}
2934
2935longlong get_datetime_value(THD *thd, Item ***item_arg, Item ** /* cache_arg */,
2936 const Item *warn_item, bool *is_null);
2937
2938longlong get_time_value(THD *thd, Item ***item_arg, Item ** /* cache_arg */,
2939 const Item *warn_item, bool *is_null);
2940
2941// TODO: the next two functions should be moved to sql_time.{h,cc}
2944
2946 enum_mysql_timestamp_type warn_type,
2947 const char *warn_name, MYSQL_TIME *l_time);
2948
2949// Helper function to ensure_multi_equality_fields_are_available().
2950// Finds and adjusts (if "replace" is set to true) an "Item_field" in a
2951// function with an equal field in the available tables. For more
2952// details look at FindEqualField().
2953void find_and_adjust_equal_fields(Item *item, table_map available_tables,
2954 bool replace, bool *found);
2955
2956/*
2957 These need definitions from this file but the variables are defined
2958 in mysqld.h. The variables really belong in this component, but for
2959 the time being we leave them in mysqld.cc to avoid merge problems.
2960*/
2961extern Eq_creator eq_creator;
2963extern Ne_creator ne_creator;
2964extern Gt_creator gt_creator;
2965extern Lt_creator lt_creator;
2966extern Ge_creator ge_creator;
2967extern Le_creator le_creator;
2968
2969/// Returns true if the item is a conjunction.
2970inline bool IsAnd(const Item *item) {
2971 return item->type() == Item::COND_ITEM &&
2972 down_cast<const Item_cond *>(item)->functype() ==
2974}
2975
2976/**
2977 Calls "func" on each term in "condition" if it's a conjunction (and
2978 recursively on any conjunction directly contained in it, thereby flattening
2979 nested AND structures). Otherwise, calls "func" on "condition". It aborts and
2980 returns true as soon as a call to "func" returns true.
2981 */
2982template <class Func>
2983bool WalkConjunction(Item *condition, Func func) {
2984 if (condition == nullptr) {
2985 return false;
2986 } else if (IsAnd(condition)) {
2987 for (Item &item : *down_cast<Item_cond_and *>(condition)->argument_list()) {
2988 if (WalkConjunction(&item, func)) {
2989 return true;
2990 }
2991 }
2992 return false;
2993 } else {
2994 return func(condition);
2995 }
2996}
2997
2998#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:1502
void cleanup()
Definition: item_cmpfunc.cc:878
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:2127
int compare_time()
Compare TIME values.
Definition: item_cmpfunc.cc:2063
String value1
Definition: item_cmpfunc.h:173
bool set_compare_func(Item_func *owner, Item_result type)
Definition: item_cmpfunc.cc:896
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:2148
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:1191
double precision
Definition: item_cmpfunc.h:152
int compare_datetime()
Compare item values as dates.
Definition: item_cmpfunc.cc:1807
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:2037
int compare_binary_string()
Compare strings byte by byte.
Definition: item_cmpfunc.cc:1966
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:1268
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:1899
int compare_real()
Definition: item_cmpfunc.cc:1984
void set_datetime_cmp_func(Item_func *owner_arg, Item **a1, Item **b1)
Definition: item_cmpfunc.cc:1660
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:1117
bool try_year_cmp_func(Item_result type)
Definition: item_cmpfunc.cc:1603
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:2019
longlong extract_value_from_argument(THD *thd, Item *item, bool left_argument, bool *is_null) const
Definition: item_cmpfunc.cc:8448
int compare_string()
Definition: item_cmpfunc.cc:1934
int compare_decimal()
Definition: item_cmpfunc.cc:2002
int compare_row()
Definition: item_cmpfunc.cc:2166
bool compare_null_values()
Compare NULL values for two arguments.
Definition: item_cmpfunc.cc:2278
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:2100
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:414
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:408
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:424
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:418
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:446
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:438
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:8413
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:1890
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1896
Mem_root_array< my_decimal > base
Definition: item_cmpfunc.h:1891
void value_to_item(uint pos, Item *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1899
In_vector_decimal(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1894
Definition: item_cmpfunc.h:1870
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1876
Mem_root_array< double > base
Definition: item_cmpfunc.h:1871
In_vector_double(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1874
void value_to_item(uint pos, Item *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1879
Definition: item_cmpfunc.h:1785
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1798
Mem_root_array< packed_longlong > base
Definition: item_cmpfunc.h:1793
In_vector_int(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1796
void value_to_item(uint pos, Item *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1805
bool set(uint pos, Item *item) override
Evaluate item and set value into element "pos" of the vector.
Definition: item_cmpfunc.h:1813
Definition: item_cmpfunc.h:1760
String tmp
Definition: item_cmpfunc.h:1762
const CHARSET_INFO * collation
Definition: item_cmpfunc.h:1766
Mem_root_array< String * > base_pointers
Definition: item_cmpfunc.h:1765
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1770
Mem_root_array< String > base_objects
Definition: item_cmpfunc.h:1763
void value_to_item(uint pos, Item *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1773
Definition: item_cmpfunc.h:1830
Mem_root_array< Time_val > base
Definition: item_cmpfunc.h:1844
In_vector_time(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1832
void value_to_item(uint pos, Item *item) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:1837
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1834
Definition: item_cmpfunc.h:1683
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:1685
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:1729
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:1743
In_vector(uint elements)
See Item_func_in::resolve_type() for why we need both count and used_count.
Definition: item_cmpfunc.h:1693
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:726
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:744
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:871
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:2285
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:1620
enum Functype functype() const override
Definition: item_cmpfunc.h:1636
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.h:1631
Item_bool_if(Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1622
const char * func_name() const override
Definition: item_cmpfunc.h:1635
longlong val_int() override
Definition: item_cmpfunc.h:1625
Definition: item.h:7228
Definition: item.h:6900
Definition: item_cmpfunc.h:2860
Item_cond_and(const POS &pos, List< Item > &list_arg)
Definition: item_cmpfunc.h:2872
Item * copy_andor_structure(THD *thd) override
Definition: item_cmpfunc.h:2878
Item_cond_and(List< Item > &list_arg)
Definition: item_cmpfunc.h:2871
COND_EQUAL cond_equal
Contains list of Item_multi_eq objects for the current conjunction and references to multiple equalit...
Definition: item_cmpfunc.h:2864
const char * func_name() const override
Definition: item_cmpfunc.h:2877
enum Functype functype() const override
Definition: item_cmpfunc.h:2874
Item_cond_and()
Definition: item_cmpfunc.h:2865
Item_cond_and(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2868
Item_cond_and(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2867
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2885
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item_cmpfunc.h:2876
Item_cond_and(THD *thd, Item_cond_and *item)
Definition: item_cmpfunc.h:2870
Definition: item_cmpfunc.h:2895
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2916
Item_cond_or(const POS &pos, List< Item > &list_arg)
Definition: item_cmpfunc.h:2904
enum Functype functype() const override
Definition: item_cmpfunc.h:2906
Item_cond_or(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2899
Item * copy_andor_structure(THD *thd) override
Definition: item_cmpfunc.h:2909
Item_cond_or(List< Item > &list_arg)
Definition: item_cmpfunc.h:2903
Item_cond_or(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2900
Item_cond_or()
Definition: item_cmpfunc.h:2897
const char * func_name() const override
Definition: item_cmpfunc.h:2908
Item_cond_or(THD *thd, Item_cond_or *item)
Definition: item_cmpfunc.h:2902
Definition: item_cmpfunc.h:2562
void add_at_head(List< Item > *nlist)
Definition: item_cmpfunc.h:2595
bool add_at_head(Item *item)
Definition: item_cmpfunc.h:2591
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:2616
Item_cond(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2572
Item_bool_func super
Definition: item_cmpfunc.h:2563
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:2627
void copy_andor_arguments(THD *thd, Item_cond *item)
Definition: item_cmpfunc.cc:6007
table_map used_tables() const override
Definition: item_cmpfunc.h:2609
Item_cond(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2576
Item_cond(List< Item > &nlist)
Definition: item_cmpfunc.h:2583
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:2622
List< Item > * argument_list()
Definition: item_cmpfunc.h:2607
Type type() const override
Definition: item_cmpfunc.h:2606
Item_cond()
Definition: item_cmpfunc.h:2571
List< Item > list
Definition: item_cmpfunc.h:2566
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:2628
bool add(Item *item)
Definition: item_cmpfunc.h:2587
Item_cond(const POS &pos, List< Item > &nlist)
Definition: item_cmpfunc.h:2585
bool abort_on_null
Definition: item_cmpfunc.h:2567
Definition: item.h:5427
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:7999
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:8385
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:8359
Definition: item.h:4467
Definition: item.h:5475
ANY_VALUE(expr) is like expr except that it is not checked by aggregate_check logic.
Definition: item_cmpfunc.h:1559
const char * func_name() const override
Definition: item_cmpfunc.h:1563
Item_func_any_value(const POS &pos, Item *a)
Definition: item_cmpfunc.h:1561
Item_func_any_value(Item *a)
Definition: item_cmpfunc.h:1562
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:2105
Item_result cmp_type
Definition: item_cmpfunc.h:2112
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:2157
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2169
cmp_item * case_item
Definition: item_cmpfunc.h:2115
int else_expr_num
Definition: item_cmpfunc.h:2108
DTCollation cmp_collation
Definition: item_cmpfunc.h:2113
Item_func super
Definition: item_cmpfunc.h:2106
Item_func_case(const POS &pos, mem_root_deque< Item * > *list, Item *first_expr_arg, Item *else_expr_arg)
Definition: item_cmpfunc.h:2124
int get_first_expr_num() const
Definition: item_cmpfunc.h:2146
const char * func_name() const override
Definition: item_cmpfunc.h:2164
enum Item_result result_type() const override
Definition: item_cmpfunc.h:2163
enum Item_result cached_result_type left_result_type
Definition: item_cmpfunc.h:2109
uint ncases
Definition: item_cmpfunc.h:2111
void add_json_info(Json_object *obj) override
Add all the node-specific json fields.
Definition: item_cmpfunc.h:2118
String tmp_value
Definition: item_cmpfunc.h:2110
enum Functype functype() const override
Definition: item_cmpfunc.h:2172
int get_else_expr_num() const
Definition: item_cmpfunc.h:2147
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:7220
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:2940
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:7125
bool cast_incompatible_args(uchar *) override
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item_cmpfunc.cc:7235
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:1573
Item_func_if(Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1577
enum Functype functype() const override
Definition: item_cmpfunc.h:1605
enum Item_result result_type() const override
Definition: item_cmpfunc.h:1594
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:1596
const char * func_name() const override
Definition: item_cmpfunc.h:1604
void update_not_null_tables()
Definition: item_cmpfunc.h:1609
enum Item_result cached_result_type
Definition: item_cmpfunc.h:1574
Item_func_if(const POS &pos, Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1581
Definition: item_cmpfunc.h:1538
Item_func_ifnull(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1540
const char * func_name() const override
Definition: item_cmpfunc.h:1550
in_expr [NOT] IN (in_value_list).
Definition: item_cmpfunc.h:2186
DTCollation cmp_collation
Definition: item_cmpfunc.h:2216
Item_func_in(const POS &pos, PT_item_list *list, bool is_negation)
Definition: item_cmpfunc.h:2219
enum Functype functype() const override
Definition: item_cmpfunc.h:2247
const char * func_name() const override
Definition: item_cmpfunc.h:2248
Item_result left_result_type
Definition: item_cmpfunc.h:2214
bool is_bool_func() const override
Definition: item_cmpfunc.h:2249
uint decimal_precision() const override
Definition: item_cmpfunc.h:2231
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2250
void update_not_null_tables()
Definition: item_cmpfunc.h:2260
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2243
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2253
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:2456
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2475
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:2478
const char * func_name() const override
Definition: item_cmpfunc.h:2469
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2470
Item_func_isnotnull(Item *a)
Definition: item_cmpfunc.h:2458
enum Functype functype() const override
Definition: item_cmpfunc.h:2464
Item_func_isnotnull(const POS &pos, Item *a)
Definition: item_cmpfunc.h:2459
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.h:2465
Definition: item_cmpfunc.h:2391
Item_func_isnull(Item *a)
Definition: item_cmpfunc.h:2398
Item_func_isnull(const POS &pos, Item *a)
Definition: item_cmpfunc.h:2399
const char * func_name() const override
Definition: item_cmpfunc.h:2405
Item_bool_func super
Definition: item_cmpfunc.h:2392
enum Functype functype() const override
Definition: item_cmpfunc.h:2403
bool cached_value
Definition: item_cmpfunc.h:2395
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2418
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2413
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:2487
Item_func_like(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:2506
int escape() const
Returns the escape character.
Definition: item_cmpfunc.h:2531
int m_escape
The escape character (0 if no escape character).
Definition: item_cmpfunc.h:2494
enum Functype functype() const override
Definition: item_cmpfunc.h:2510
bool escape_was_used_in_parsing() const
Definition: item_cmpfunc.h:2528
Item_func_like(Item *a, Item *b, Item *escape_arg)
Definition: item_cmpfunc.h:2498
Item_func_like(Item *a, Item *b)
Definition: item_cmpfunc.h:2497
cond_result eq_cmp_result() const override
Result may be not equal with equal inputs if ESCAPE character is present.
Definition: item_cmpfunc.h:2513
const char * func_name() const override
Definition: item_cmpfunc.h:2514
bool escape_is_evaluated() const
Has the escape clause been evaluated? It only needs to be evaluated once per execution,...
Definition: item_cmpfunc.h:2542
Item_func_like(const POS &pos, Item *a, Item *b, Item *escape_arg)
Definition: item_cmpfunc.h:2502
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:7641
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:568
Definition: item_cmpfunc.h:970
bool empty_underlying_subquery()
Definition: item_cmpfunc.cc:530
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:551
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:516
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:508
Item * truth_transformer(THD *, Bool_test) override
Apply NOT transformation to the item and return a new one.
Definition: item_cmpfunc.cc:7119
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:480
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:454
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:501
Item_func_not(const POS &pos, Item *a)
Definition: item_cmpfunc.h:792
Definition: item_cmpfunc.h:1639
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:1653
enum Functype functype() const override
Definition: item_cmpfunc.h:1660
Item_result result_type() const override
Definition: item_cmpfunc.h:1652
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:1676
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:1665
enum Item_result cached_result_type
Definition: item_cmpfunc.h:1640
uint64 hash() override
Generate hash unique to an item depending on its attributes.
Definition: item_cmpfunc.h:1669
Item_func_nullif(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1643
const char * func_name() const override
Definition: item_cmpfunc.h:1659
uint decimal_precision() const override
Definition: item_cmpfunc.h:1663
Definition: item_func.h:883
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:8039
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:7687
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:7707
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:7666
uint64 hash() override
Generate hash unique to an item depending on its attributes.
Definition: item_cmpfunc.cc:7748
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:7652
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:2354
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:2344
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:2338
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:7078
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:7040
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:7137
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item_cmpfunc.cc:7025
Definition: item_func.h:101
my_decimal * val_decimal(my_decimal *) override
Definition: item_func.cc:871
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:800
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:798
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:726
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_func.cc:765
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:829
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item_func.cc:813
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:4196
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:2472
uint64 hash() override
Generate hash unique to an item depending on its attributes.
Definition: item_cmpfunc.cc:2495
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_cmpfunc.cc:2676
bool fix_left(THD *thd)
Definition: item_cmpfunc.cc:2387
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:2577
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:2461
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:2681
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_cmpfunc.cc:2663
Item_cache ** get_cache()
Definition: item_cmpfunc.h:541
bool fix_fields(THD *, Item **) override
Definition: item_cmpfunc.cc:2429
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:2484
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:608
Definition: item_func.h:1046
String * val_str(String *str) override
Definition: item_func.cc:1507
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:1098
double val_real() override
Definition: item_func.cc:1501
enum Item_result result_type() const override
Definition: item_func.h:1101
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:1094
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item_func.h:1097
Definition: item.h:5220
Definition: item_cmpfunc.h:2431
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:2450
Item_in_subselect * owner
Definition: item_cmpfunc.h:2432
const char * func_name() const override
Definition: item_cmpfunc.h:2439
Item_is_not_null_test(Item_in_subselect *ow, Item *a)
Definition: item_cmpfunc.h:2435
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:2447
enum Functype functype() const override
Definition: item_cmpfunc.h:2437
Definition: item_subselect.h:404
Definition: item_cmpfunc.h:2804
size_t size() const
Definition: item_cmpfunc.h:2818
const List< Item_field > * m_fields
Definition: item_cmpfunc.h:2821
List_STL_Iterator< const Item_field > cend() const
Definition: item_cmpfunc.h:2815
ConstFieldProxy(const Item_multi_eq *item)
Definition: item_cmpfunc.h:2806
List_STL_Iterator< const Item_field > end() const
Definition: item_cmpfunc.h:2811
List_STL_Iterator< const Item_field > begin() const
Definition: item_cmpfunc.h:2808
List_STL_Iterator< const Item_field > cbegin() const
Definition: item_cmpfunc.h:2812
Definition: item_cmpfunc.h:2785
FieldProxy(Item_multi_eq *item)
Definition: item_cmpfunc.h:2787
List_STL_Iterator< Item_field > begin()
Definition: item_cmpfunc.h:2788
List_STL_Iterator< const Item_field > cbegin() const
Definition: item_cmpfunc.h:2794
List_STL_Iterator< const Item_field > end() const
Definition: item_cmpfunc.h:2793
List< Item_field > * m_fields
Definition: item_cmpfunc.h:2802
List_STL_Iterator< const Item_field > cend() const
Definition: item_cmpfunc.h:2797
List_STL_Iterator< const Item_field > begin() const
Definition: item_cmpfunc.h:2790
List_STL_Iterator< Item_field > end()
Definition: item_cmpfunc.h:2789
The class Item_multi_eq is used to represent conjunctions of equality predicates of the form field1 =...
Definition: item_cmpfunc.h:2699
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:2838
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:2780
const char * func_name() const override
Definition: item_cmpfunc.h:2751
ConstFieldProxy get_fields() const
Definition: item_cmpfunc.h:2824
FieldProxy get_fields()
Definition: item_cmpfunc.h:2823
Item_multi_eq(const Item_multi_eq &&)=delete
List< Item_field > fields
List of equal field items.
Definition: item_cmpfunc.h:2701
void set_const_arg(Item *const_item)
Definition: item_cmpfunc.h:2734
bool cast_incompatible_args(uchar *) override
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item_cmpfunc.h:2753
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2834
enum Functype functype() const override
Definition: item_cmpfunc.h:2749
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2752
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:2760
Item * const_arg() const
Returns the constant Item that this multi equality is equal to(if any).
Definition: item_cmpfunc.h:2733
Item_field * get_first()
Get the first field of multiple equality, use for semantic checking.
Definition: item_cmpfunc.h:2745
Arg_comparator cmp
Helper for comparing constants.
Definition: item_cmpfunc.h:2707
Field * result_field
Definition: item.h:5949
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:5573
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:5352
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:2111
void set_nullable(bool nullable)
Definition: item.h:3749
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3644
void set_data_type_bool()
Definition: item.h:1523
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:2843
bool is_nullable() const
Definition: item.h:3748
void set_subquery()
Set the "has subquery" property.
Definition: item.h:3501
void fix_char_length(uint32 max_char_length_arg)
Definition: item.h:3451
virtual Item * equality_substitution_transformer(uchar *)
Definition: item.h:3064
void add_accum_properties(const Item *item)
Add more accumulated properties to an Item.
Definition: item.h:3496
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:2083
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:2504
bool fixed
True if item has been resolved.
Definition: item.h:3737
bool const_item() const
Returns true if item is constant, regardless of query evaluation state.
Definition: item.h:2441
bool null_value
True if item is null.
Definition: item.h:3774
Type
Definition: item.h:963
@ COND_ITEM
An AND or OR condition.
Definition: item.h:977
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:2618
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:2393
virtual TYPELIB * get_typelib() const
Get the typelib information for an item of type set or enum.
Definition: item.h:1821
bool unsigned_flag
Definition: item.h:3775
virtual bool aggregate_check_group(uchar *)
Definition: item.h:2989
virtual bool is_null()
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:2599
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:2987
cond_result
Definition: item.h:992
@ COND_TRUE
Definition: item.h:992
@ COND_FALSE
Definition: item.h:992
@ COND_OK
Definition: item.h:992
traverse_order
Definition: item.h:994
Bool_test
< Modifier for result transformation
Definition: item.h:1007
@ BOOL_NOT_FALSE
Definition: item.h:1012
@ BOOL_NOT_TRUE
Definition: item.h:1011
@ BOOL_IS_TRUE
Definition: item.h:1008
@ BOOL_IS_FALSE
Definition: item.h:1009
@ BOOL_NEGATED
Definition: item.h:1015
uint32 max_length
Maximum length of result of evaluating this item, in number of bytes.
Definition: item.h:3662
virtual enum Type type() const =0
virtual uint cols() const
Definition: item.h:3235
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:450
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:442
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:428
Item_bool_func * combine(const POS &pos, List< Item > list) const override
Combines a list of conditions exp op exp.
Definition: item_cmpfunc.cc:434
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:2952
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:2043
longlong value
Definition: item_cmpfunc.h:2044
bool has_date
Distinguish between DATE/DATETIME/TIMESTAMP and TIME.
Definition: item_cmpfunc.h:2050
const Item * warn_item
Definition: item_cmpfunc.h:2048
Definition: item_cmpfunc.h:2078
my_decimal value
Definition: item_cmpfunc.h:2079
Definition: item_cmpfunc.h:2019
longlong value
Definition: item_cmpfunc.h:2020
void store_value(Item *item) override
Definition: item_cmpfunc.h:2023
int cmp(Item *arg) override
Definition: item_cmpfunc.h:2027
int compare(const cmp_item *ci) const override
Definition: item_cmpfunc.h:2031
Definition: item_cmpfunc.h:1993
unique_ptr_destroy_only< Json_wrapper > m_value
Cached JSON value to look up.
Definition: item_cmpfunc.h:1996
~cmp_item_json() override
String m_str_value
String buffer.
Definition: item_cmpfunc.h:2000
unique_ptr_destroy_only< Json_scalar_holder > m_holder
Cache for the value above.
Definition: item_cmpfunc.h:1998
Definition: item_cmpfunc.h:2059
int cmp(Item *arg) override
Definition: item_cmpfunc.h:2067
double value
Definition: item_cmpfunc.h:2060
void store_value(Item *item) override
Definition: item_cmpfunc.h:2063
int compare(const cmp_item *ci) const override
Definition: item_cmpfunc.h:2071
Definition: item_cmpfunc.h:2311
cmp_item_row(cmp_item_row &&other)
Definition: item_cmpfunc.h:2324
void set_null_value(bool nv) override
Definition: item_cmpfunc.h:2337
cmp_item_row(THD *thd, Item *item)
Definition: item_cmpfunc.h:2319
cmp_item_row()=default
cmp_item which stores a scalar (i.e. non-ROW).
Definition: item_cmpfunc.h:1959
bool m_null_value
If stored value is NULL.
Definition: item_cmpfunc.h:1961
void set_null_value(bool nv) override
Definition: item_cmpfunc.h:1962
Definition: item_cmpfunc.h:1965
const String * value_res
Definition: item_cmpfunc.h:1967
int compare(const cmp_item *ci) const override
Definition: item_cmpfunc.h:1974
cmp_item_string(const CHARSET_INFO *cs)
Definition: item_cmpfunc.h:1972
void store_value(Item *item) override
Definition: item_cmpfunc.h:1979
const CHARSET_INFO * cmp_charset
Definition: item_cmpfunc.h:1969
StringBuffer< STRING_BUFFER_USUAL_SIZE > value
Definition: item_cmpfunc.h:1968
Definition: item_cmpfunc.h:1914
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:1952
Definition: item_cmpfunc.h:1818
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1822
in_datetime_as_longlong(MEM_ROOT *mem_root, uint elements)
Definition: item_cmpfunc.h:1820
Definition: item_cmpfunc.h:1854
Item * create_item(MEM_ROOT *mem_root) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:1861
Item * warn_item
An item used to issue warnings.
Definition: item_cmpfunc.h:1856
in_datetime(MEM_ROOT *mem_root, Item *warn_item_arg, uint elements)
Definition: item_cmpfunc.h:1859
Definition: item_cmpfunc.h:2356
Mem_root_array< cmp_item_row * > base_pointers
Definition: item_cmpfunc.h:2360
Mem_root_array< cmp_item_row > base_objects
Definition: item_cmpfunc.h:2358
void value_to_item(uint, Item *) const override
Store the value at position pos into provided item object.
Definition: item_cmpfunc.h:2382
unique_ptr_destroy_only< cmp_item_row > tmp
Definition: item_cmpfunc.h:2357
bool is_row_result() const override
Definition: item_cmpfunc.h:2364
Item * create_item(MEM_ROOT *) const override
Create an instance of Item_{type} (e.g.
Definition: item_cmpfunc.h:2378
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:8485
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:1408
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:1683
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:1452
Eq_creator eq_creator
Definition: mysqld.cc:1556
Ge_creator ge_creator
Definition: mysqld.cc:1561
Item * make_condition(Parse_context *pc, Item *item)
Ensure that all expressions involved in conditions are boolean functions.
Definition: item_cmpfunc.cc:5966
void find_and_adjust_equal_fields(Item *item, table_map available_tables, bool replace, bool *found)
Definition: item_cmpfunc.cc:8466
Lt_creator lt_creator
Definition: mysqld.cc:1560
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:1003
Gt_creator gt_creator
Definition: mysqld.cc:1559
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:2970
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:1470
Ne_creator ne_creator
Definition: mysqld.cc:1557
Equal_creator equal_creator
Definition: mysqld.cc:1558
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:2983
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:1034
Le_creator le_creator
Definition: mysqld.cc:1562
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:1716
Item * and_conds(Item *a, Item *b)
Builds condition: (a AND b) IS TRUE.
Definition: item_cmpfunc.h:2925
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:1077
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:2853
List< Item_multi_eq > current_level
List of multiple equalities in the current conjunction.
Definition: item_cmpfunc.h:2857
Definition: item_cmpfunc.h:1787
bool unsigned_flag
Definition: item_cmpfunc.h:1789
longlong val
Definition: item_cmpfunc.h:1788
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:1450
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:95
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:74
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