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