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