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