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