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