MySQL 8.0.30
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 raising 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 enum Functype functype() const override { return FALSE_FUNC; }
395};
396
397/**
398 Item class, to represent <code>X IS [NOT] (TRUE | FALSE)</code>
399 boolean predicates.
400*/
401class Item_func_truth final : public Item_bool_func {
403
404 public:
405 longlong val_int() override;
406 bool resolve_type(THD *) override;
407 void print(const THD *thd, String *str,
408 enum_query_type query_type) const override;
409 Item *truth_transformer(THD *, Bool_test test) override {
411 return this;
412 }
413 const char *func_name() const override {
415 }
416 enum Functype functype() const override { return ISTRUTH_FUNC; }
417
420 null_on_null = false;
421 switch (truth_test) {
422 case BOOL_IS_TRUE:
423 case BOOL_IS_FALSE:
424 case BOOL_NOT_TRUE:
425 case BOOL_NOT_FALSE:
426 break;
427 default:
428 assert(false);
429 }
430 }
433 null_on_null = false;
434 switch (truth_test) {
435 case BOOL_IS_TRUE:
436 case BOOL_IS_FALSE:
437 case BOOL_NOT_TRUE:
438 case BOOL_NOT_FALSE:
439 break;
440 default:
441 assert(false);
442 }
443 }
444 void apply_is_true() override {
445 /*
446 This item cannot produce NULL result. But, if the upper item confuses
447 NULL and FALSE, we can do as if NULL input caused a NULL result when it
448 actually causes a FALSE result.
449 */
450 switch (truth_test) {
451 case BOOL_IS_TRUE:
452 case BOOL_IS_FALSE:
453 null_on_null = true;
454 default:
455 break;
456 }
457 }
458
459 protected:
460 Bool_test truth_test; ///< The value we're testing for.
461};
462
463static const int UNKNOWN = -1;
464
465/*
466 Item_in_optimizer(left_expr, Item_in_subselect(...))
467
468 Item_in_optimizer is used to wrap an instance of Item_in_subselect. This
469 class does the following:
470 - Evaluate the left expression and store it in Item_cache_* object (to
471 avoid re-evaluating it many times during subquery execution)
472 - Shortcut the evaluation of "NULL IN (...)" to NULL in the cases where we
473 don't care if the result is NULL or FALSE.
474
475 args[1] keeps a reference to the Item_in_subselect object.
476
477 args[0] is a copy of Item_in_subselect's left expression and should be
478 kept equal also after resolving.
479
480 NOTE
481 It is not quite clear why the above listed functionality should be
482 placed into a separate class called 'Item_in_optimizer'.
483*/
484
485class Item_in_optimizer final : public Item_bool_func {
486 private:
487 Item_cache *cache{nullptr};
488 /// Required to restore original "left" pointer after execution
490 /**
491 Stores the value of "NULL IN (SELECT ...)" for uncorrelated subqueries:
492 UNKNOWN - "NULL in (SELECT ...)" has not yet been evaluated
493 FALSE - result is FALSE
494 TRUE - result is NULL
495 */
497
498 public:
500 : Item_bool_func(a, pointer_cast<Item *>(b)) {
501 set_subquery();
502 }
503 bool fix_fields(THD *, Item **) override;
504 bool fix_left(THD *thd, Item **ref);
505 void fix_after_pullout(Query_block *parent_query_block,
506 Query_block *removed_query_block) override;
507 bool is_null() override;
508 longlong val_int() override;
509 void cleanup() override;
510 const char *func_name() const override { return "<in_optimizer>"; }
511 Item_cache **get_cache() { return &cache; }
513 Item *transform(Item_transformer transformer, uchar *arg) override;
514 Item *compile(Item_analyzer analyzer, uchar **arg_p,
515 Item_transformer transformer, uchar *arg_t) override;
516 void set_arg_resolve(THD *thd, uint i, Item *newp) override;
517 void update_used_tables() override;
518};
519
520/// Abstract factory interface for creating comparison predicates.
522 public:
523 virtual ~Comp_creator() = default;
524 virtual Item_bool_func *create(Item *a, Item *b) const = 0;
525
526 /// This interface is only used by Item_allany_subselect.
527 virtual const char *symbol(bool invert) const = 0;
528 virtual bool eqne_op() const = 0;
529 virtual bool l_op() const = 0;
530};
531
532/// Abstract base class for the comparison operators =, <> and <=>.
534 public:
535 Item_bool_func *create(Item *a, Item *b) const override;
536 bool eqne_op() const override { return true; }
537 bool l_op() const override { return false; }
538
539 protected:
540 /**
541 Creates only an item tree node, without attempting to rewrite row
542 constructors.
543 @see create()
544 */
546
547 /// Combines a list of conditions <code>exp op exp</code>.
549};
550
552 public:
553 const char *symbol(bool invert) const override { return invert ? "<>" : "="; }
554
555 protected:
556 Item_bool_func *create_scalar_predicate(Item *a, Item *b) const override;
557 Item_bool_func *combine(List<Item> list) const override;
558};
559
561 public:
562 const char *symbol(bool invert [[maybe_unused]]) const override {
563 // This will never be called with true.
564 assert(!invert);
565 return "<=>";
566 }
567
568 protected:
569 Item_bool_func *create_scalar_predicate(Item *a, Item *b) const override;
570 Item_bool_func *combine(List<Item> list) const override;
571};
572
574 public:
575 const char *symbol(bool invert) const override { return invert ? "=" : "<>"; }
576
577 protected:
578 Item_bool_func *create_scalar_predicate(Item *a, Item *b) const override;
579 Item_bool_func *combine(List<Item> list) const override;
580};
581
582class Gt_creator : public Comp_creator {
583 public:
584 Item_bool_func *create(Item *a, Item *b) const override;
585 const char *symbol(bool invert) const override { return invert ? "<=" : ">"; }
586 bool eqne_op() const override { return false; }
587 bool l_op() const override { return false; }
588};
589
590class Lt_creator : public Comp_creator {
591 public:
592 Item_bool_func *create(Item *a, Item *b) const override;
593 const char *symbol(bool invert) const override { return invert ? ">=" : "<"; }
594 bool eqne_op() const override { return false; }
595 bool l_op() const override { return true; }
596};
597
598class Ge_creator : public Comp_creator {
599 public:
600 Item_bool_func *create(Item *a, Item *b) const override;
601 const char *symbol(bool invert) const override { return invert ? "<" : ">="; }
602 bool eqne_op() const override { return false; }
603 bool l_op() const override { return false; }
604};
605
606class Le_creator : public Comp_creator {
607 public:
608 Item_bool_func *create(Item *a, Item *b) const override;
609 const char *symbol(bool invert) const override { return invert ? ">" : "<="; }
610 bool eqne_op() const override { return false; }
611 bool l_op() const override { return true; }
612};
613
614/// Base class for functions that usually take two arguments, which are possibly
615/// strings, and perform some kind of comparison on the two arguments and return
616/// a boolean. The functions may take more than two arguments (for example, LIKE
617/// takes an optional third argument in the ESCAPE clause), but all of the
618/// functions perform a comparison between the first two arguments, and extra
619/// arguments are modifiers that affect how the comparison is performed.
621 private:
622 bool convert_constant_arg(THD *thd, Item *field, Item **item,
623 bool *converted);
624
625 protected:
627 bool abort_on_null{false};
628
630 : Item_bool_func(a, b), cmp(args, args + 1) {}
631
633 : Item_bool_func(a, b, c), cmp(args, args + 1) {}
634
636 : Item_bool_func(pos, a, b), cmp(args, args + 1) {}
637
638 Item_bool_func2(const POS &pos, Item *a, Item *b, Item *c)
639 : Item_bool_func(pos, a, b, c), cmp(args, args + 1) {}
640
641 public:
642 bool resolve_type(THD *) override;
643 /// Sets up a comparator of the correct type based on the type of the
644 /// function's arguments. Also sets up caches to hold constant values
645 /// converted to the type expected by the comparator. See
646 /// Arg_comparator::set_cmp_func().
647 virtual bool set_cmp_func() {
648 return cmp.set_cmp_func(this, args, args + 1, is_nullable());
649 }
650 optimize_type select_optimize(const THD *) override { return OPTIMIZE_OP; }
651 /// @returns an operator REV_OP so that "B REV_OP A" is equivalent to
652 /// "A this_operator B".
653 virtual enum Functype rev_functype() const { return UNKNOWN_FUNC; }
654 bool have_rev_func() const override { return rev_functype() != UNKNOWN_FUNC; }
655
656 void print(const THD *thd, String *str,
657 enum_query_type query_type) const override {
658 Item_func::print_op(thd, str, query_type);
659 }
660
661 bool is_null() override { return args[0]->is_null() || args[1]->is_null(); }
662 const CHARSET_INFO *compare_collation() const override {
664 }
666 void apply_is_true() override { abort_on_null = true; }
667 /// Treat UNKNOWN result like FALSE because callers see no difference
668 bool ignore_unknown() const { return abort_on_null; }
669 void cleanup() override {
671 cmp.cleanup();
672 }
673 const Arg_comparator *get_comparator() const { return &cmp; }
675 friend class Arg_comparator;
676};
677
678/**
679 Item_func_comparison is a class for comparison functions that take two
680 arguments and return a boolean result.
681 It is a common class for the regular comparison operators (=, <>, <, <=,
682 >, >=) as well as the special <=> equality operator.
683*/
685 public:
687 allowed_arg_cols = 0; // Fetch this value from first argument
688 }
690 : Item_bool_func2(pos, a, b) {
691 allowed_arg_cols = 0; // Fetch this value from first argument
692 }
693
694 Item *truth_transformer(THD *, Bool_test) override;
695 virtual Item *negated_item();
696 bool subst_argument_checker(uchar **) override { return true; }
697 bool is_null() override;
698
699 bool cast_incompatible_args(uchar *) override;
700 bool contains_only_equi_join_condition() const override;
701};
702
703/**
704 XOR inherits from Item_bool_func2 because it is not optimized yet.
705 Later, when XOR is optimized, it needs to inherit from
706 Item_cond instead. See WL#5800.
707*/
708class Item_func_xor final : public Item_bool_func2 {
710
711 public:
712 Item_func_xor(Item *i1, Item *i2) : Item_bool_func2(i1, i2) {}
713 Item_func_xor(const POS &pos, Item *i1, Item *i2)
714 : Item_bool_func2(pos, i1, i2) {}
715
716 enum Functype functype() const override { return XOR_FUNC; }
717 const char *func_name() const override { return "xor"; }
718 bool itemize(Parse_context *pc, Item **res) override;
719 longlong val_int() override;
720 void apply_is_true() override {}
721 Item *truth_transformer(THD *, Bool_test) override;
722
723 float get_filtering_effect(THD *thd, table_map filter_for_table,
724 table_map read_tables,
725 const MY_BITMAP *fields_to_ignore,
726 double rows_in_table) override;
727};
728
730 public:
733
734 longlong val_int() override;
735 enum Functype functype() const override { return NOT_FUNC; }
736 const char *func_name() const override { return "not"; }
737 Item *truth_transformer(THD *, Bool_test) override;
738 void print(const THD *thd, String *str,
739 enum_query_type query_type) const override;
740
741 float get_filtering_effect(THD *thd, table_map filter_for_table,
742 table_map read_tables,
743 const MY_BITMAP *fields_to_ignore,
744 double rows_in_table) override;
745};
746
747/**
748 Wrapper class when MATCH function is used in WHERE clause.
749 The MATCH clause can be used as a function returning a floating point value
750 in the SELECT list or in the WHERE clause. However, it may also be used as
751 a boolean function in the WHERE clause, where it has different semantics than
752 when used together with a comparison operator. With a comparison operator,
753 the match operation is performed with ranking. To preserve this behavior,
754 the Item_func_match object is wrapped inside an object of class
755 Item_func_match_predicate, which effectively transforms the function into
756 a predicate. The overridden functions implemented in this class generally
757 forward all evaluation to the underlying object.
758*/
760 public:
762
763 longlong val_int() override { return args[0]->val_int(); }
764 enum Functype functype() const override { return MATCH_FUNC; }
765 const char *func_name() const override { return "match"; }
766 void print(const THD *thd, String *str,
767 enum_query_type query_type) const override {
768 args[0]->print(thd, str, query_type);
769 }
770
771 float get_filtering_effect(THD *thd, table_map filter_for_table,
772 table_map read_tables,
773 const MY_BITMAP *fields_to_ignore,
774 double rows_in_table) override {
775 return args[0]->get_filtering_effect(thd, filter_for_table, read_tables,
776 fields_to_ignore, rows_in_table);
777 }
778};
780class JOIN;
781
782/*
783 trigcond<param>(arg) ::= param? arg : true
784
785 The class Item_func_trig_cond is used for guarded predicates
786 which are employed only for internal purposes.
787 A guarded predicate is an object consisting of an a regular or
788 a guarded predicate P and a pointer to a boolean guard variable g.
789 A guarded predicate P/g is evaluated to true if the value of the
790 guard g is false, otherwise it is evaluated to the same value that
791 the predicate P: val(P/g)= g ? val(P):true.
792 Guarded predicates allow us to include predicates into a conjunction
793 conditionally. Currently they are utilized for pushed down predicates
794 in queries with outer join operations.
795
796 In the future, probably, it makes sense to extend this class to
797 the objects consisting of three elements: a predicate P, a pointer
798 to a variable g and a firing value s with following evaluation
799 rule: val(P/g,s)= g==s? val(P) : true. It will allow us to build only
800 one item for the objects of the form P/g1/g2...
801
802 Objects of this class are built only for query execution after
803 the execution plan has been already selected. That's why this
804 class needs only val_int out of generic methods.
805
806 Current uses of Item_func_trig_cond objects:
807 - To wrap selection conditions when executing outer joins
808 - To wrap condition that is pushed down into subquery
809*/
810
812 public:
814 /**
815 This trigger type deactivates join conditions when a row has been
816 NULL-complemented. For example, in t1 LEFT JOIN t2, the join condition
817 can be tested on t2's row only if that row is not NULL-complemented.
818 */
820
821 /**
822 This trigger type deactivates predicated from WHERE condition when no
823 row satisfying the join condition has been found. For Example, in t1
824 LEFT JOIN t2, the where condition pushed to t2 can be tested only after
825 at least one t2 row has been produced, which may be a NULL-complemented
826 row.
827 */
829
830 /**
831 In IN->EXISTS subquery transformation, new predicates are added:
832 WHERE inner_field=outer_field OR inner_field IS NULL,
833 as well as
834 HAVING inner_field IS NOT NULL,
835 are disabled if outer_field is a NULL value
836 */
838 };
839
840 private:
841 /** Pointer to trigger variable */
842 bool *trig_var;
843 /// Optional: JOIN of table which is the source of trig_var
844 const JOIN *m_join;
845 /// Optional: if join!=NULL: index of table
847 /** Type of trig_var; for printing */
849
850 public:
851 /**
852 @param a the item for @<condition@>
853 @param f pointer to trigger variable
854 @param join if a table's property is the source of 'f', JOIN
855 which owns this table; NULL otherwise.
856 @param idx if join!=NULL: index of this table in the
857 JOIN_TAB/QEP_TAB array. NO_PLAN_IDX otherwise.
858 @param trig_type_arg type of 'f'
859 */
861 enum_trig_type trig_type_arg)
862 : Item_bool_func(a),
863 trig_var(f),
864 m_join(join),
865 m_idx(idx),
866 trig_type(trig_type_arg) {}
867 longlong val_int() override;
868 enum Functype functype() const override { return TRIG_COND_FUNC; }
869 /// '@<if@>', to distinguish from the if() SQL function
870 const char *func_name() const override { return "<if>"; }
871 /// Get range of inner tables spanned by associated outer join operation
872 void get_table_range(TABLE_LIST **first_table, TABLE_LIST **last_table) const;
873 /// Get table_map of inner tables spanned by associated outer join operation
875 bool fix_fields(THD *thd, Item **ref) override {
876 if (Item_bool_func::fix_fields(thd, ref)) return true;
878 return false;
879 }
882 assert(m_join != nullptr);
883 // Make this function dependent on the inner tables
885 } else if (trig_type == OUTER_FIELD_IS_NOT_NULL) {
887 }
888 }
889 void update_used_tables() override {
892 }
893 void fix_after_pullout(Query_block *parent_query_block,
894 Query_block *removed_query_block) override {
895 Item_bool_func::fix_after_pullout(parent_query_block, removed_query_block);
897 }
898 const JOIN *get_join() const { return m_join; }
899 enum enum_trig_type get_trig_type() const { return trig_type; }
900 bool *get_trig_var() { return trig_var; }
902 void print(const THD *thd, String *str,
903 enum_query_type query_type) const override;
904 plan_idx idx() const { return m_idx; }
905
906 bool contains_only_equi_join_condition() const override;
907};
908
910 /* allow to check presence of values in max/min optimization */
915
916 public:
917 bool show;
918
920 : Item_func_not(a),
924 abort_on_null(false),
925 show(false) {}
926 void apply_is_true() override { abort_on_null = true; }
927 /// Treat UNKNOWN result like FALSE because callers see no difference
928 bool ignore_unknown() const { return abort_on_null; }
929 longlong val_int() override;
930 enum Functype functype() const override { return NOT_ALL_FUNC; }
931 const char *func_name() const override { return "<not>"; }
932 void print(const THD *thd, String *str,
933 enum_query_type query_type) const override;
936 void set_subselect(Item_subselect *item) { subselect = item; }
937 table_map not_null_tables() const override {
938 /*
939 See handling of not_null_tables_cache in
940 Item_in_optimizer::fix_fields().
941
942 This item is the result of a transformation from an ALL clause
943 such as
944 left-expr < ALL(subquery)
945 into
946 <not>(left-expr >= ANY(subquery)
947
948 An inequality usually rejects NULLs from both operands, so the
949 not_null_tables() of the inequality is the union of the
950 null-rejecting tables of both operands. However, since this is a
951 transformed ALL clause that should return true if the subquery
952 is empty (even if left-expr is NULL), it is not null rejecting
953 for left-expr. The not null tables mask for left-expr should be
954 removed, leaving only the null-rejecting tables of the
955 subquery. Item_subselect::not_null_tables() always returns 0 (no
956 null-rejecting tables). Therefore, always return 0.
957 */
958 return 0;
959 }
961 Item *truth_transformer(THD *, Bool_test) override;
962};
963
965 public:
967 longlong val_int() override;
968 const char *func_name() const override { return "<nop>"; }
970 Item *truth_transformer(THD *, Bool_test) override;
971};
972
973/**
974 Implements the comparison operator equals (=)
975*/
977 public:
979 Item_func_eq(const POS &pos, Item *a, Item *b)
980 : Item_func_comparison(pos, a, b) {}
981 longlong val_int() override;
982 enum Functype functype() const override { return EQ_FUNC; }
983 enum Functype rev_functype() const override { return EQ_FUNC; }
984 cond_result eq_cmp_result() const override { return COND_TRUE; }
985 const char *func_name() const override { return "="; }
986 Item *negated_item() override;
987 bool equality_substitution_analyzer(uchar **) override { return true; }
989 bool gc_subst_analyzer(uchar **) override { return true; }
990
991 float get_filtering_effect(THD *thd, table_map filter_for_table,
992 table_map read_tables,
993 const MY_BITMAP *fields_to_ignore,
994 double rows_in_table) override;
995
996 /// Read the value from the join condition, and append it to the output vector
997 /// "join_key_buffer". The function will determine which side of the condition
998 /// to read the value from by using the bitmap "tables".
999 ///
1000 /// @param thd the thread handler
1001 /// @param tables a bitmap that marks the tables that are involved in the join
1002 /// @param join_condition an instance containing the join condition together
1003 /// with some pre-calculated values
1004 /// @param[out] join_key_buffer a buffer where the value from the join
1005 /// condition will be appended
1006 /// @param is_multi_column_key true if the hash join key has multiple columns
1007 /// (that is, the hash join condition is a conjunction)
1008 ///
1009 /// @returns true if an SQL NULL was encountered, false otherwise
1011 const HashJoinCondition &join_condition,
1012 bool is_multi_column_key,
1013 String *join_key_buffer) const;
1014
1015 /// Wrap the argument in a typecast, if needed.
1016 ///
1017 /// When computing a hash of the join value during a hash join, we want to
1018 /// create a hash value that is memcmp-able. This is quite straightforward
1019 /// for most data types, but it can be tricky for some types. For the
1020 /// straightforward cases, this function just returns the argument it was
1021 /// given in. For the complex cases, the function returns the given argument,
1022 /// wrapped in a typecast node. Which typecast node it is wrapped in is
1023 /// determined by the comparison context of this equality condition. The
1024 /// comparison context is given by the member "cmp"; a comparator class that
1025 /// is set up during query resolving.
1026 ///
1027 /// @param mem_root the MEM_ROOT where the typecast node is allocated
1028 /// @param argument the argument that we might wrap in a typecast. This is
1029 /// either the left or the right side of the Item_func_eq
1030 ///
1031 /// @returns either the argument it was given, or the argument wrapped in a
1032 /// typecast
1033 Item *create_cast_if_needed(MEM_ROOT *mem_root, Item *argument) const;
1034
1035 /// See if this is a condition where any of the arguments refers to a field
1036 /// that is outside the bits marked by 'left_side_tables' and
1037 /// 'right_side_tables'.
1038 ///
1039 /// This is a situation that can happen during equality propagation in the
1040 /// optimization phase. Consider the following query:
1041 ///
1042 /// SELECT * FROM t1 LEFT JOIN
1043 /// (t2 LEFT JOIN t3 ON t3.i = t2.i) ON t2.i = t1.i;
1044 ///
1045 /// The optimizer will see that t1.i = t2.i = t3.i. Furthermore, it will
1046 /// replace one side of this condition with a field from a table that is as
1047 /// early in the join order as possible. However, this will break queries
1048 /// executed in the iterator executor. The above query will end up with
1049 /// something like this after optimization:
1050 ///
1051 /// Left hash join <--- t1.i = t2.i
1052 /// | |
1053 /// t1 Left hash join <--- t1.i = t3.i
1054 /// | |
1055 /// t2 t3
1056 ///
1057 /// Note that 't2.i = t3.i' has been rewritten to 't1.i = t3.i'. When
1058 /// evaluating the join between t2 and t3, t1 is outside our reach!
1059 /// To overcome this, we must reverse the changes done by the equality
1060 /// propagation. It is possible to do so because during equality propagation,
1061 /// we save a list of all of the fields that were considered equal.
1062 /// If we are asked to replace ("replace" set to true), arguments of this
1063 /// function are replaced with an equal field. If we are not replacing, we
1064 /// set "found" to "true" if an equal field is found, "false" otherwise.
1066 table_map right_side_tables,
1067 bool replace, bool *found);
1068
1069 // If this equality originally came from a multi-equality, this documents
1070 // which one it came from (otherwise nullptr). It is used during planning:
1071 // For selectivity estimates and for not pushing down the same multi-equality
1072 // to the same join more than once (see IsBadJoinForCondition()).
1073 //
1074 // This is used only in the hypergraph optimizer; the pre-hypergraph optimizer
1075 // uses COND_EQUAL to find this instead.
1077};
1078
1079/**
1080 The <=> operator evaluates the same as
1081
1082 a IS NULL || b IS NULL ? a IS NULL == b IS NULL : a = b
1083
1084 a <=> b is equivalent to the standard operation a IS NOT DISTINCT FROM b.
1085
1086 Notice that the result is TRUE or FALSE, and never UNKNOWN.
1087*/
1089 public:
1091 null_on_null = false;
1092 }
1094 : Item_func_comparison(pos, a, b) {
1095 null_on_null = false;
1096 }
1097 // Needs null value propagated to parent, even though operator is not nullable
1098 bool set_cmp_func() override {
1099 return cmp.set_cmp_func(this, args, args + 1, true);
1100 }
1101 longlong val_int() override;
1102 bool resolve_type(THD *thd) override;
1103 enum Functype functype() const override { return EQUAL_FUNC; }
1104 enum Functype rev_functype() const override { return EQUAL_FUNC; }
1105 cond_result eq_cmp_result() const override { return COND_TRUE; }
1106 const char *func_name() const override { return "<=>"; }
1107 Item *truth_transformer(THD *, Bool_test) override { return nullptr; }
1108 bool is_null() override { return false; }
1109
1110 float get_filtering_effect(THD *thd, table_map filter_for_table,
1111 table_map read_tables,
1112 const MY_BITMAP *fields_to_ignore,
1113 double rows_in_table) override;
1114};
1115
1116/**
1117 Implements the comparison operator greater than or equals (>=)
1118*/
1120 public:
1122 longlong val_int() override;
1123 enum Functype functype() const override { return GE_FUNC; }
1124 enum Functype rev_functype() const override { return LE_FUNC; }
1125 cond_result eq_cmp_result() const override { return COND_TRUE; }
1126 const char *func_name() const override { return ">="; }
1127 Item *negated_item() override;
1128 bool gc_subst_analyzer(uchar **) override { return true; }
1129
1130 float get_filtering_effect(THD *thd, table_map filter_for_table,
1131 table_map read_tables,
1132 const MY_BITMAP *fields_to_ignore,
1133 double rows_in_table) override;
1134};
1135
1136/**
1137 Implements the comparison operator greater than (>)
1138*/
1140 public:
1142 longlong val_int() override;
1143 enum Functype functype() const override { return GT_FUNC; }
1144 enum Functype rev_functype() const override { return LT_FUNC; }
1145 cond_result eq_cmp_result() const override { return COND_FALSE; }
1146 const char *func_name() const override { return ">"; }
1147 Item *negated_item() override;
1148 bool gc_subst_analyzer(uchar **) override { return true; }
1149
1150 float get_filtering_effect(THD *thd, table_map filter_for_table,
1151 table_map read_tables,
1152 const MY_BITMAP *fields_to_ignore,
1153 double rows_in_table) override;
1154};
1155
1156/**
1157 Implements the comparison operator less than or equals (<=)
1158*/
1160 public:
1162 longlong val_int() override;
1163 enum Functype functype() const override { return LE_FUNC; }
1164 enum Functype rev_functype() const override { return GE_FUNC; }
1165 cond_result eq_cmp_result() const override { return COND_TRUE; }
1166 const char *func_name() const override { return "<="; }
1167 Item *negated_item() override;
1168 bool gc_subst_analyzer(uchar **) override { return true; }
1169
1170 float get_filtering_effect(THD *thd, table_map filter_for_table,
1171 table_map read_tables,
1172 const MY_BITMAP *fields_to_ignore,
1173 double rows_in_table) override;
1174};
1175
1176/**
1177 Internal function used by subquery to derived transformation to check
1178 if a subquery is scalar. We model it to check if the count is greater than
1179 1 using Item_func_gt.
1180*/
1181
1183 public:
1185 longlong val_int() override;
1186 const char *func_name() const override { return "reject_if"; }
1187 /// Redefine to avoid pushing into derived table
1188 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
1189 return true;
1190 }
1191 float get_filtering_effect(THD *thd, table_map filter_for_table,
1192 table_map read_tables,
1193 const MY_BITMAP *fields_to_ignore,
1194 double rows_in_table) override;
1195 /**
1196 We add RAND_TABLE_BIT to prevent moving this item from the JOIN condition:
1197 it might raise an error too early: only if the join condition succeeds is
1198 it relevant and should be evaluated. Cf.
1199 Query_block::decorrelate_derived_scalar_subquery_post
1200
1201 @return Always RAND_TABLE_BIT
1202 */
1204 return RAND_TABLE_BIT;
1205 }
1206};
1207
1208/**
1209 Implements the comparison operator less than (<)
1210*/
1212 public:
1214 longlong val_int() override;
1215 enum Functype functype() const override { return LT_FUNC; }
1216 enum Functype rev_functype() const override { return GT_FUNC; }
1217 cond_result eq_cmp_result() const override { return COND_FALSE; }
1218 const char *func_name() const override { return "<"; }
1219 Item *negated_item() override;
1220 bool gc_subst_analyzer(uchar **) override { return true; }
1221
1222 float get_filtering_effect(THD *thd, table_map filter_for_table,
1223 table_map read_tables,
1224 const MY_BITMAP *fields_to_ignore,
1225 double rows_in_table) override;
1226};
1227
1228/**
1229 Implements the comparison operator not equals (<>)
1230*/
1232 public:
1234 longlong val_int() override;
1235 enum Functype functype() const override { return NE_FUNC; }
1236 enum Functype rev_functype() const override { return NE_FUNC; }
1237 cond_result eq_cmp_result() const override { return COND_FALSE; }
1238 optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
1239 const char *func_name() const override { return "<>"; }
1240 Item *negated_item() override;
1241
1242 float get_filtering_effect(THD *thd, table_map filter_for_table,
1243 table_map read_tables,
1244 const MY_BITMAP *fields_to_ignore,
1245 double rows_in_table) override;
1246};
1247
1248/*
1249 The class Item_func_opt_neg is defined to factor out the functionality
1250 common for the classes Item_func_between and Item_func_in. The objects
1251 of these classes can express predicates or their negations.
1252 The alternative approach would be to create pairs Item_func_between,
1253 Item_func_notbetween and Item_func_in, Item_func_notin.
1254
1255*/
1256
1258 public:
1259 bool negated; /* <=> the item represents NOT <func> */
1260 bool pred_level; /* <=> [NOT] <func> is used on a predicate level */
1261 public:
1262 Item_func_opt_neg(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
1263 : Item_int_func(pos, a, b, c), negated(false), pred_level(false) {
1264 if (is_negation) negate();
1265 }
1266 Item_func_opt_neg(const POS &pos, PT_item_list *list, bool is_negation)
1267 : Item_int_func(pos, list), negated(false), pred_level(false) {
1268 if (is_negation) negate();
1269 }
1270
1271 public:
1272 inline void negate() { negated = !negated; }
1273 inline void apply_is_true() override { pred_level = true; }
1274 bool ignore_unknown() const { return pred_level; }
1276 if (test != BOOL_NEGATED) return nullptr;
1277 negated = !negated;
1278 return this;
1279 }
1280 bool eq(const Item *item, bool binary_cmp) const override;
1281 bool subst_argument_checker(uchar **) override { return true; }
1282};
1283
1286
1287 public:
1290 /* true <=> arguments will be compared as dates. */
1294
1295 /* Comparators used for DATE/DATETIME comparison. */
1297 Item_func_between(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
1298 : Item_func_opt_neg(pos, a, b, c, is_negation),
1302 longlong val_int() override;
1303 optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
1304 enum Functype functype() const override { return BETWEEN; }
1305 const char *func_name() const override { return "between"; }
1306 bool fix_fields(THD *, Item **) override;
1307 void fix_after_pullout(Query_block *parent_query_block,
1308 Query_block *removed_query_block) override;
1309 bool resolve_type(THD *) override;
1310 void print(const THD *thd, String *str,
1311 enum_query_type query_type) const override;
1312 bool is_bool_func() const override { return true; }
1313 const CHARSET_INFO *compare_collation() const override {
1314 return cmp_collation.collation;
1315 }
1316 uint decimal_precision() const override { return 1; }
1317 bool gc_subst_analyzer(uchar **) override { return true; }
1318
1319 float get_filtering_effect(THD *thd, table_map filter_for_table,
1320 table_map read_tables,
1321 const MY_BITMAP *fields_to_ignore,
1322 double rows_in_table) override;
1323 void update_used_tables() override;
1324
1326 // not_null_tables_cache == union(T1(e),T1(e1),T1(e2))
1327 if (pred_level && !negated) return;
1328
1329 /// not_null_tables_cache == union(T1(e), intersection(T1(e1),T1(e2)))
1331 args[0]->not_null_tables() |
1332 (args[1]->not_null_tables() & args[2]->not_null_tables());
1333 }
1334};
1335
1336class Item_func_strcmp final : public Item_bool_func2 {
1337 public:
1339 : Item_bool_func2(pos, a, b) {}
1340 longlong val_int() override;
1341 optimize_type select_optimize(const THD *) override { return OPTIMIZE_NONE; }
1342 const char *func_name() const override { return "strcmp"; }
1343 enum Functype functype() const override { return STRCMP_FUNC; }
1344
1345 void print(const THD *thd, String *str,
1346 enum_query_type query_type) const override {
1347 Item_func::print(thd, str, query_type);
1348 }
1349 // We derive (indirectly) from Item_bool_func, but this is not a true boolean.
1350 // Override length and unsigned_flag set by set_data_type_bool().
1351 bool resolve_type(THD *thd) override {
1352 if (Item_bool_func2::resolve_type(thd)) return true;
1353 fix_char_length(2); // returns "1" or "0" or "-1"
1354 unsigned_flag = false;
1355 return false;
1356 }
1357};
1358
1361 double dbl;
1363};
1364
1365class Item_func_interval final : public Item_int_func {
1367
1371
1372 public:
1374 Item *expr2, class PT_item_list *opt_expr_list = nullptr)
1375 : super(pos, alloc_row(pos, mem_root, expr1, expr2, opt_expr_list)),
1376 row(down_cast<Item_row *>(args[0])),
1378 allowed_arg_cols = 0; // Fetch this value from first argument
1379 }
1380
1381 bool itemize(Parse_context *pc, Item **res) override;
1382 longlong val_int() override;
1383 bool resolve_type(THD *) override;
1384 const char *func_name() const override { return "interval"; }
1385 uint decimal_precision() const override { return 2; }
1386 void print(const THD *thd, String *str,
1387 enum_query_type query_type) const override;
1388 void update_used_tables() override;
1389
1390 private:
1391 // Runs in CTOR init list, cannot access *this as Item_func_interval
1392 static Item_row *alloc_row(const POS &pos, MEM_ROOT *mem_root, Item *expr1,
1393 Item *expr2, class PT_item_list *opt_expr_list);
1394};
1395
1397 protected:
1399 : Item_func_numhybrid(pos, a, b) {
1400 null_on_null = false;
1401 }
1403 null_on_null = false;
1404 }
1406
1407 public:
1410 null_on_null = false;
1411 }
1413 return MYSQL_TYPE_VARCHAR;
1414 }
1416 null_on_null = false;
1417 }
1418 TYPELIB *get_typelib() const override;
1419 double real_op() override;
1420 longlong int_op() override;
1421 String *str_op(String *) override;
1422 /**
1423 Get the result of COALESCE as a JSON value.
1424 @param[in,out] wr the result value holder
1425 */
1426 bool val_json(Json_wrapper *wr) override;
1427 bool date_op(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1428 bool time_op(MYSQL_TIME *ltime) override;
1429 my_decimal *decimal_op(my_decimal *) override;
1430 bool resolve_type(THD *thd) override;
1431 bool resolve_type_inner(THD *thd) override;
1432 void set_numeric_type() override {}
1433 enum Item_result result_type() const override { return hybrid_type; }
1434 const char *func_name() const override { return "coalesce"; }
1435 enum Functype functype() const override { return COALESCE_FUNC; }
1436};
1437
1439 protected:
1441
1442 public:
1444 : Item_func_coalesce(pos, a, b) {}
1445 double real_op() override;
1446 longlong int_op() override;
1447 String *str_op(String *str) override;
1448 bool date_op(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1449 bool time_op(MYSQL_TIME *ltime) override;
1450 my_decimal *decimal_op(my_decimal *) override;
1451 bool val_json(Json_wrapper *result) override;
1452 const char *func_name() const override { return "ifnull"; }
1453 Field *tmp_table_field(TABLE *table) override;
1454};
1455
1456/**
1457 ANY_VALUE(expr) is like expr except that it is not checked by
1458 aggregate_check logic. It serves as a solution for users who want to
1459 bypass this logic.
1460*/
1462 public:
1465 const char *func_name() const override { return "any_value"; }
1466 bool aggregate_check_group(uchar *arg) override;
1467 bool aggregate_check_distinct(uchar *arg) override;
1468};
1469
1470class Item_func_if final : public Item_func {
1472
1473 public:
1476 null_on_null = false;
1477 }
1478 Item_func_if(const POS &pos, Item *a, Item *b, Item *c)
1480 null_on_null = false;
1481 }
1482
1483 double val_real() override;
1484 longlong val_int() override;
1485 String *val_str(String *str) override;
1486 my_decimal *val_decimal(my_decimal *) override;
1487 bool val_json(Json_wrapper *wr) override;
1488 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1489 bool get_time(MYSQL_TIME *ltime) override;
1490 enum Item_result result_type() const override { return cached_result_type; }
1491 bool fix_fields(THD *, Item **) override;
1493 return MYSQL_TYPE_VARCHAR;
1494 }
1495 bool resolve_type(THD *thd) override;
1496 bool resolve_type_inner(THD *thd) override;
1497 void fix_after_pullout(Query_block *parent_query_block,
1498 Query_block *removed_query_block) override;
1499 TYPELIB *get_typelib() const override;
1500 const char *func_name() const override { return "if"; }
1501 enum Functype functype() const override { return IF_FUNC; }
1502 void update_used_tables() override;
1503
1504 ///< T1(IF(e,e1,e2)) = intersection(T1(e1),T1(e2))
1507 (args[1]->not_null_tables() & args[2]->not_null_tables());
1508 }
1509};
1510
1511class Item_func_nullif final : public Item_bool_func2 {
1513
1514 public:
1517 null_on_null = false;
1518 }
1519 double val_real() override;
1520 longlong val_int() override;
1521 String *val_str(String *str) override;
1522 my_decimal *val_decimal(my_decimal *) override;
1523 bool val_json(Json_wrapper *wr) override;
1524 Item_result result_type() const override { return cached_result_type; }
1526 return MYSQL_TYPE_VARCHAR;
1527 }
1528 bool resolve_type(THD *thd) override;
1529 bool resolve_type_inner(THD *thd) override;
1530 const char *func_name() const override { return "nullif"; }
1531 enum Functype functype() const override { return NULLIF_FUNC; }
1532
1533 // No, we should NOT inherit from Item_bool_func2
1534 uint decimal_precision() const override { return Item::decimal_precision(); }
1535
1536 void print(const THD *thd, String *str,
1537 enum_query_type query_type) const override {
1538 Item_func::print(thd, str, query_type);
1539 }
1540
1541 bool is_null() override;
1542 /**
1543 This is a workaround for the broken inheritance hierarchy: this should
1544 inherit from Item_func instead of Item_bool_func2
1545 */
1546 bool is_bool_func() const override { return false; }
1547};
1548
1549/* Functions to handle the optimized IN */
1550
1551/* A vector of values of some type */
1552
1554 private:
1555 const uint count; ///< Original size of the vector
1556 public:
1557 uint used_count; ///< The actual size of the vector (NULL may be ignored)
1558
1559 /**
1560 See Item_func_in::resolve_type() for why we need both
1561 count and used_count.
1562 */
1563 explicit in_vector(uint elements) : count(elements), used_count(elements) {}
1564
1565 virtual ~in_vector() = default;
1566
1567 /**
1568 Calls item->val_int() or item->val_str() etc.
1569 and then does binary_search if the value is non-null.
1570 @param item to evaluate, and lookup in the IN-list.
1571 @return true if evaluated value of the item was found.
1572 */
1573 virtual bool find_item(Item *item) = 0;
1574
1575 /**
1576 Create an instance of Item_{type} (e.g. Item_decimal) constant object
1577 which type allows it to hold an element of this vector without any
1578 conversions.
1579 The purpose of this function is to be able to get elements of this
1580 vector in form of Item_xxx constants without creating Item_xxx object
1581 for every array element you get (i.e. this implements "FlyWeight" pattern)
1582
1583 @param mem_root Where to allocate the Item.
1584 */
1586
1587 /**
1588 Store the value at position #pos into provided item object
1589
1590 @param pos Index of value to store
1591 @param item Constant item to store value into. The item must be of the same
1592 type that create_item() returns.
1593 */
1594 virtual void value_to_item(uint pos, Item_basic_constant *item) const = 0;
1595
1596 /** Compare values number pos1 and pos2 for equality */
1597 virtual bool compare_elems(uint pos1, uint pos2) const = 0;
1598
1599 virtual bool is_row_result() const { return false; }
1600
1601 /**
1602 Fill the vector by evaluating the items passed as arguments.
1603 Note that null values are skipped so the vector may end up containing
1604 fewer elements than the number of items.
1605 The vector is sorted so that it can be used for binary search.
1606
1607 @param items Items to evaluate
1608 @param item_count Number of items
1609
1610 @return true if any null values was found, false otherwise.
1611 */
1612 bool fill(Item **items, uint item_count);
1613
1614 private:
1615 virtual void set(uint pos, Item *item) = 0;
1616
1617 /**
1618 Resize and then sort the IN-list array, so we can do efficient lookup with
1619 binary_search.
1620 */
1621 virtual void resize_and_sort() = 0;
1622};
1623
1624class in_string final : public in_vector {
1628 // String objects are not sortable, sort pointers instead.
1631
1632 public:
1633 in_string(MEM_ROOT *mem_root, uint elements, const CHARSET_INFO *cs);
1635 return new (mem_root) Item_string(collation);
1636 }
1637 void value_to_item(uint pos, Item_basic_constant *item) const override {
1639 }
1640 bool find_item(Item *item) override;
1641 bool compare_elems(uint pos1, uint pos2) const override;
1642
1643 private:
1644 void set(uint pos, Item *item) override;
1645 void resize_and_sort() override;
1646};
1647
1648class in_longlong : public in_vector {
1649 public:
1653 };
1654
1655 protected:
1657
1658 public:
1660 : in_vector(elements), base(mem_root, elements) {}
1662 /*
1663 We've created a signed INT, this may not be correct in the
1664 general case (see BUG#19342).
1665 */
1666 return new (mem_root) Item_int(0LL);
1667 }
1668 void value_to_item(uint pos, Item_basic_constant *item) const override {
1669 down_cast<Item_int *>(item)->value = base[pos].val;
1670 item->unsigned_flag = base[pos].unsigned_flag;
1671 }
1672 bool find_item(Item *item) override;
1673 bool compare_elems(uint pos1, uint pos2) const override;
1674
1675 private:
1676 void set(uint pos, Item *item) override { val_item(item, &base[pos]); }
1677 void resize_and_sort() override;
1678 virtual void val_item(Item *item, packed_longlong *result);
1679};
1680
1682 public:
1684 : in_longlong(mem_root, elements) {}
1686 return new (mem_root) Item_temporal(MYSQL_TYPE_DATETIME, 0LL);
1687 }
1688
1689 private:
1690 void val_item(Item *item, packed_longlong *result) override;
1691};
1692
1693class in_time_as_longlong final : public in_longlong {
1694 public:
1696 : in_longlong(mem_root, elements) {}
1698 return new (mem_root) Item_temporal(MYSQL_TYPE_TIME, 0LL);
1699 }
1700
1701 private:
1702 void val_item(Item *item, packed_longlong *result) override;
1703};
1704
1705/*
1706 Class to represent a vector of constant DATE/DATETIME values.
1707 Values are obtained with help of the get_datetime_value() function.
1708*/
1709class in_datetime final : public in_longlong {
1710 /// An item used to issue warnings.
1712
1713 public:
1714 in_datetime(MEM_ROOT *mem_root, Item *warn_item_arg, uint elements)
1715 : in_longlong(mem_root, elements), warn_item(warn_item_arg) {}
1717 return new (mem_root) Item_temporal(MYSQL_TYPE_DATETIME, 0LL);
1718 }
1719
1720 private:
1721 void set(uint pos, Item *item) override;
1722 void val_item(Item *item, packed_longlong *result) override;
1723};
1724
1725class in_double final : public in_vector {
1727
1728 public:
1730 : in_vector(elements), base(mem_root, elements) {}
1732 return new (mem_root) Item_float(0.0, 0);
1733 }
1734 void value_to_item(uint pos, Item_basic_constant *item) const override {
1735 down_cast<Item_float *>(item)->value = base[pos];
1736 }
1737 bool find_item(Item *item) override;
1738 bool compare_elems(uint pos1, uint pos2) const override;
1739
1740 private:
1741 void set(uint pos, Item *item) override;
1742 void resize_and_sort() override;
1743};
1744
1745class in_decimal final : public in_vector {
1747
1748 public:
1750 : in_vector(elements), base(mem_root, elements) {}
1752 return new (mem_root) Item_decimal(0, false);
1753 }
1754 void value_to_item(uint pos, Item_basic_constant *item) const override {
1755 down_cast<Item_decimal *>(item)->set_decimal_value(&base[pos]);
1756 }
1757 bool find_item(Item *item) override;
1758 bool compare_elems(uint pos1, uint pos2) const override;
1759
1760 private:
1761 void set(uint pos, Item *item) override;
1762 void resize_and_sort() override;
1763};
1764
1765/*
1766** Classes for easy comparing of non const items
1767*/
1768
1770 public:
1771 cmp_item() = default;
1772 virtual ~cmp_item() = default;
1773 virtual void store_value(Item *item) = 0;
1774 /**
1775 @returns result (true, false or UNKNOWN) of
1776 "stored argument's value <> item's value"
1777 */
1778 virtual int cmp(Item *item) = 0;
1779 // for optimized IN with row
1780 virtual int compare(const cmp_item *item) const = 0;
1781
1782 /**
1783 Find the appropriate comparator for the given type.
1784
1785 @param result_type Used to find the appropriate comparator.
1786 @param item Item object used to distinguish temporal types.
1787 @param cs Charset
1788
1789 @return
1790 New cmp_item_xxx object.
1791 */
1792 static cmp_item *get_comparator(Item_result result_type, Item *item,
1793 const CHARSET_INFO *cs);
1794 virtual cmp_item *make_same() = 0;
1795 virtual void store_value_by_template(cmp_item *, Item *item) {
1796 store_value(item);
1797 }
1798};
1799
1800/// cmp_item which stores a scalar (i.e. non-ROW).
1802 protected:
1803 bool m_null_value; ///< If stored value is NULL
1804 void set_null_value(bool nv) { m_null_value = nv; }
1805};
1806
1807class cmp_item_string final : public cmp_item_scalar {
1808 private:
1812
1813 public:
1815
1816 int compare(const cmp_item *ci) const override {
1817 const cmp_item_string *l_cmp = down_cast<const cmp_item_string *>(ci);
1818 return sortcmp(value_res, l_cmp->value_res, cmp_charset);
1819 }
1820
1821 void store_value(Item *item) override {
1822 String *res = eval_string_arg(cmp_charset, item, &value);
1823 if (res && (res != &value || !res->is_alloced())) {
1824 // 'res' may point in item's transient internal data, so make a copy
1825 value.copy(*res);
1826 }
1827 value_res = &value;
1829 }
1830
1831 int cmp(Item *arg) override;
1832 cmp_item *make_same() override;
1833};
1834
1835class cmp_item_json final : public cmp_item_scalar {
1836 private:
1837 /// Cached JSON value to look up
1839 /// Cache for the value above
1841 /// String buffer
1843
1844 public:
1845 /**
1846 Construct a cmp_item_json object.
1847 @param wrapper a Json_wrapper for holding the JSON value in the comparison
1848 @param holder pre-alloced memory for creating JSON scalar values without
1849 using the heap
1850 */
1853 ~cmp_item_json() override;
1854
1855 int compare(const cmp_item *ci) const override;
1856 void store_value(Item *item) override;
1857 int cmp(Item *arg) override;
1858 cmp_item *make_same() override;
1859};
1860
1861class cmp_item_int final : public cmp_item_scalar {
1863
1864 public:
1865 void store_value(Item *item) override {
1866 value = item->val_int();
1868 }
1869 int cmp(Item *arg) override {
1870 const bool rc = value != arg->val_int();
1871 return (m_null_value || arg->null_value) ? UNKNOWN : rc;
1872 }
1873 int compare(const cmp_item *ci) const override {
1874 const cmp_item_int *l_cmp = down_cast<const cmp_item_int *>(ci);
1875 return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
1876 }
1877 cmp_item *make_same() override;
1878};
1879
1880/*
1881 Compare items of temporal type.
1882 Values are obtained with: get_datetime_value() (DATE/DATETIME/TIMESTAMP) and
1883 get_time_value() (TIME).
1884*/
1887
1888 public:
1889 /* Item used for issuing warnings. */
1891 /// Distinguish between DATE/DATETIME/TIMESTAMP and TIME
1893
1894 cmp_item_datetime(const Item *warn_item_arg);
1895 void store_value(Item *item) override;
1896 int cmp(Item *arg) override;
1897 int compare(const cmp_item *ci) const override;
1898 cmp_item *make_same() override;
1899};
1900
1902 double value;
1903
1904 public:
1905 void store_value(Item *item) override {
1906 value = item->val_real();
1908 }
1909 int cmp(Item *arg) override {
1910 const bool rc = value != arg->val_real();
1911 return (m_null_value || arg->null_value) ? UNKNOWN : rc;
1912 }
1913 int compare(const cmp_item *ci) const override {
1914 const cmp_item_real *l_cmp = down_cast<const cmp_item_real *>(ci);
1915 return (value < l_cmp->value) ? -1 : ((value == l_cmp->value) ? 0 : 1);
1916 }
1917 cmp_item *make_same() override;
1918};
1919
1922
1923 public:
1924 void store_value(Item *item) override;
1925 int cmp(Item *arg) override;
1926 int compare(const cmp_item *c) const override;
1927 cmp_item *make_same() override;
1928};
1929
1930/**
1931 CASE ... WHEN ... THEN ... END function implementation.
1932
1933 When there is no expression between CASE and the first WHEN
1934 (the CASE expression) then this function simple checks all WHEN expressions
1935 one after another. When some WHEN expression evaluated to TRUE then the
1936 value of the corresponding THEN expression is returned.
1937
1938 When the CASE expression is specified then it is compared to each WHEN
1939 expression individually. When an equal WHEN expression is found
1940 corresponding THEN expression is returned.
1941 In order to do correct comparisons several comparators are used. One for
1942 each result type. Different result types that are used in particular
1943 CASE ... END expression are collected in the resolve_type() member
1944 function and only comparators for there result types are used.
1945*/
1946
1947class Item_func_case final : public Item_func {
1949
1951 enum Item_result cached_result_type, left_result_type;
1956 cmp_item *cmp_items[5]; /* For all result types */
1958
1959 public:
1961 Item *first_expr_arg, Item *else_expr_arg)
1962 : super(pos),
1963 first_expr_num(-1),
1964 else_expr_num(-1),
1965 cached_result_type(INT_RESULT),
1968 null_on_null = false;
1969 ncases = list->size();
1970 if (first_expr_arg) {
1971 first_expr_num = list->size();
1972 list->push_back(first_expr_arg);
1973 }
1974 if (else_expr_arg) {
1975 else_expr_num = list->size();
1976 list->push_back(else_expr_arg);
1977 }
1978 set_arguments(list, true);
1979 memset(&cmp_items, 0, sizeof(cmp_items));
1980 }
1981 ~Item_func_case() override;
1982 int get_first_expr_num() const { return first_expr_num; }
1983 int get_else_expr_num() const { return else_expr_num; }
1984 double val_real() override;
1985 longlong val_int() override;
1986 String *val_str(String *) override;
1987 my_decimal *val_decimal(my_decimal *) override;
1988 bool val_json(Json_wrapper *wr) override;
1989 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
1990 bool get_time(MYSQL_TIME *ltime) override;
1991 bool fix_fields(THD *thd, Item **ref) override;
1993 return MYSQL_TYPE_VARCHAR;
1994 }
1995 bool resolve_type(THD *thd) override;
1996 bool resolve_type_inner(THD *thd) override;
1997 TYPELIB *get_typelib() const override;
1998 enum Item_result result_type() const override { return cached_result_type; }
1999 const char *func_name() const override { return "case"; }
2000 void print(const THD *thd, String *str,
2001 enum_query_type query_type) const override;
2003 const CHARSET_INFO *compare_collation() const override {
2004 return cmp_collation.collation;
2005 }
2006 enum Functype functype() const override { return CASE_FUNC; }
2007};
2008
2009/**
2010 in_expr [NOT] IN (in_value_list).
2011
2012 The current implementation distinguishes 2 cases:
2013 1) all items in in_value_list are constants and have the same
2014 result type. This case is handled by in_vector class.
2015 2) otherwise Item_func_in employs several cmp_item objects to perform
2016 comparisons of in_expr and an item from in_value_list. One cmp_item
2017 object for each result type. Different result types are collected in the
2018 resolve_type() member function by means of collect_cmp_types() function.
2019*/
2020class Item_func_in final : public Item_func_opt_neg {
2021 public:
2022 /// An array of values, created when the bisection lookup method is used
2023 in_vector *array{nullptr};
2024 /**
2025 If there is some NULL among @<in value list@>, during a val_int() call; for
2026 example
2027 IN ( (1,(3,'col')), ... ), where 'col' is a column which evaluates to
2028 NULL.
2029 */
2030 bool have_null{false};
2031 /// Set to true when bisection values are populated
2032 bool populated{false};
2033
2034 private:
2035 /// Set to true if the values arguments are const
2037 /**
2038 Set to true by resolve_type() if the IN list contains a
2039 dependent subquery, in which case condition filtering will not be
2040 calculated for this item.
2041 */
2042 bool dep_subq_in_list{false};
2043 /// True until start of 2nd call to resolve_type()
2045
2047 cmp_item *cmp_items[6]; /* One cmp_item for each result type */
2049
2050 public:
2051 Item_func_in(const POS &pos, PT_item_list *list, bool is_negation)
2052 : Item_func_opt_neg(pos, list, is_negation) {
2053 memset(&cmp_items, 0, sizeof(cmp_items));
2054 allowed_arg_cols = 0; // Fetch this value from first argument
2055 }
2056 ~Item_func_in() override;
2057 longlong val_int() override;
2058 bool fix_fields(THD *, Item **) override;
2059 void fix_after_pullout(Query_block *parent_query_block,
2060 Query_block *removed_query_block) override;
2061 bool resolve_type(THD *) override;
2062 void update_used_tables() override;
2063 uint decimal_precision() const override { return 1; }
2064
2065 /**
2066 Populate values for bisection with fresh values, should be called once
2067 per execution.
2068
2069 @param thd Thread handler
2070
2071 @returns false if success, true if error
2072 */
2073 bool populate_bisection(THD *thd);
2074 void cleanup() override;
2075 optimize_type select_optimize(const THD *) override { return OPTIMIZE_KEY; }
2076 void print(const THD *thd, String *str,
2077 enum_query_type query_type) const override;
2078 enum Functype functype() const override { return IN_FUNC; }
2079 const char *func_name() const override { return " IN "; }
2080 bool is_bool_func() const override { return true; }
2081 const CHARSET_INFO *compare_collation() const override {
2082 return cmp_collation.collation;
2083 }
2084 bool gc_subst_analyzer(uchar **) override { return true; }
2085
2086 float get_filtering_effect(THD *thd, table_map filter_for_table,
2087 table_map read_tables,
2088 const MY_BITMAP *fields_to_ignore,
2089 double rows_in_table) override;
2090
2092 // not_null_tables_cache == union(T1(e),union(T1(ei)))
2093 if (pred_level && negated) return;
2094
2096
2097 ///< not_null_tables_cache = union(T1(e),intersection(T1(ei)))
2098 Item **arg_end = args + arg_count;
2099 for (Item **arg = args + 1; arg != arg_end; arg++)
2100 not_null_tables_cache &= (*arg)->not_null_tables();
2102 }
2103
2104 private:
2105 /**
2106 Usable if @<in value list@> is made only of constants. Returns true if one
2107 of these constants contains a NULL. Example:
2108 IN ( (-5, (12,NULL)), ... ).
2109 */
2110 bool list_contains_null();
2111 /**
2112 Utility function to help calculate the total filtering effect of
2113 IN predicates. This function calculates the filtering effect from
2114 a single field (or field reference) on the left hand side of the
2115 expression.
2116
2117 @param fieldref Field (or field reference) on left hand side of
2118 IN, i.e., this function should be called for
2119 each fi in "(f1,...,fn) IN (values)"
2120 @param filter_for_table The table we are calculating filter effect for
2121 @param fields_to_ignore Fields in 'filter_for_table' that should not
2122 be part of the filter calculation. The filtering
2123 effect of these fields are already part of the
2124 calculation somehow (e.g. because there is a
2125 predicate "col = <const>", and the optimizer
2126 has decided to do ref access on 'col').
2127 @param rows_in_table The number of rows in table 'filter_for_table'
2128
2129 @return the filtering effect (between 0 and 1) 'the_field'
2130 participates with in this IN predicate.
2131 */
2133 table_map filter_for_table,
2134 const MY_BITMAP *fields_to_ignore,
2135 double rows_in_table);
2136 void cleanup_arrays(); ///< Helper function for this common task
2137};
2138
2139class cmp_item_row : public cmp_item {
2142
2143 // Only used for Mem_root_array::resize()
2145
2146 friend class Mem_root_array_YY<cmp_item_row>;
2147
2148 public:
2149 cmp_item_row(THD *thd, Item *item) : comparators(nullptr), n(item->cols()) {
2150 alloc_comparators(thd, item);
2151 }
2152 ~cmp_item_row() override;
2153
2155 : comparators(other.comparators), n(other.n) {
2156 other.comparators = nullptr;
2157 other.n = 0;
2158 }
2159
2160 void store_value(Item *item) override;
2161 int cmp(Item *arg) override;
2162 int compare(const cmp_item *arg) const override;
2163 cmp_item *make_same() override;
2164 void store_value_by_template(cmp_item *tmpl, Item *) override;
2165
2166 private:
2167 bool alloc_comparators(THD *thd, Item *item);
2168};
2169
2170class in_row final : public in_vector {
2173 // Sort pointers, rather than objects.
2175
2176 public:
2178 bool is_row_result() const override { return true; }
2179 bool find_item(Item *item) override;
2180 bool compare_elems(uint pos1, uint pos2) const override;
2181
2183 assert(false);
2184 return nullptr;
2185 }
2186 void value_to_item(uint, Item_basic_constant *) const override {
2187 assert(false);
2188 }
2189
2190 private:
2191 void set(uint pos, Item *item) override;
2192 void resize_and_sort() override;
2193};
2194
2195/* Functions used by where clause */
2196
2199
2200 bool cache_used = false;
2202
2203 public:
2205 Item_func_isnull(const POS &pos, Item *a) : super(pos, a) {
2206 null_on_null = false;
2207 }
2208 longlong val_int() override;
2209 enum Functype functype() const override { return ISNULL_FUNC; }
2210 bool resolve_type(THD *thd) override;
2211 const char *func_name() const override { return "isnull"; }
2212 /* Optimize case of not_null_column IS NULL */
2213 void update_used_tables() override;
2214
2215 float get_filtering_effect(THD *thd, table_map filter_for_table,
2216 table_map read_tables,
2217 const MY_BITMAP *fields_to_ignore,
2218 double rows_in_table) override;
2219 optimize_type select_optimize(const THD *) override { return OPTIMIZE_NULL; }
2220 Item *truth_transformer(THD *, Bool_test test) override;
2221 void print(const THD *thd, String *str,
2222 enum_query_type query_type) const override;
2223 const CHARSET_INFO *compare_collation() const override {
2224 return args[0]->collation.collation;
2225 }
2226 bool fix_fields(THD *thd, Item **ref) override;
2227};
2228
2229/* Functions used by HAVING for rewriting IN subquery */
2230
2231/*
2232 This is like IS NOT NULL but it also remembers if it ever has
2233 encountered a NULL; it remembers this in the "was_null" property of the
2234 "owner" item.
2235*/
2238
2239 public:
2241 : Item_func_isnull(a), owner(ow) {}
2242 enum Functype functype() const override { return ISNOTNULLTEST_FUNC; }
2243 longlong val_int() override;
2244 const char *func_name() const override { return "<is_not_null_test>"; }
2245 bool resolve_type(THD *thd) override;
2246 void update_used_tables() override;
2247 /**
2248 We add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE.
2249
2250 @retval Always RAND_TABLE_BIT
2251 */
2253 return RAND_TABLE_BIT;
2254 }
2255 void print(const THD *thd, String *str,
2256 enum_query_type query_type) const override {
2257 Item_bool_func::print(thd, str, query_type);
2258 }
2259};
2260
2262 public:
2265 null_on_null = false;
2266 }
2267
2268 longlong val_int() override;
2269 enum Functype functype() const override { return ISNOTNULL_FUNC; }
2270 bool resolve_type(THD *thd) override {
2271 set_nullable(false);
2272 return Item_bool_func::resolve_type(thd);
2273 }
2274 const char *func_name() const override { return "isnotnull"; }
2275 optimize_type select_optimize(const THD *) override { return OPTIMIZE_NULL; }
2276 Item *truth_transformer(THD *, Bool_test test) override;
2277 void print(const THD *thd, String *str,
2278 enum_query_type query_type) const override;
2279 const CHARSET_INFO *compare_collation() const override {
2280 return args[0]->collation.collation;
2281 }
2282 void apply_is_true() override {
2283 null_on_null = true;
2284 } // Same logic as for Item_func_truth's function
2285 float get_filtering_effect(THD *thd, table_map filter_for_table,
2286 table_map read_tables,
2287 const MY_BITMAP *fields_to_ignore,
2288 double rows_in_table) override;
2289};
2290
2291class Item_func_like final : public Item_bool_func2 {
2292 /// True if escape clause is const (a literal)
2293 bool escape_is_const = false;
2294 /// Tells if the escape clause has been evaluated.
2295 bool escape_evaluated = false;
2296 bool eval_escape_clause(THD *thd);
2297 /// The escape character (0 if no escape character).
2299
2300 public:
2302 Item_func_like(Item *a, Item *b, Item *escape_arg)
2303 : Item_bool_func2(a, b, escape_arg) {
2304 assert(escape_arg != nullptr);
2305 }
2306 Item_func_like(const POS &pos, Item *a, Item *b, Item *escape_arg)
2307 : Item_bool_func2(pos, a, b, escape_arg) {
2308 assert(escape_arg != nullptr);
2309 }
2311 : Item_bool_func2(pos, a, b) {}
2312
2313 longlong val_int() override;
2314 enum Functype functype() const override { return LIKE_FUNC; }
2315 optimize_type select_optimize(const THD *thd) override;
2316 /// Result may be not equal with equal inputs if ESCAPE character is present
2317 cond_result eq_cmp_result() const override { return COND_OK; }
2318 const char *func_name() const override { return "like"; }
2319 bool fix_fields(THD *thd, Item **ref) override;
2320 bool resolve_type(THD *) override;
2321 void cleanup() override;
2322 Item *replace_scalar_subquery(uchar *) override;
2323 // Overridden because Item_bool_func2::print() doesn't print the ESCAPE
2324 // clause.
2325 void print(const THD *thd, String *str,
2326 enum_query_type query_type) const override;
2327 /**
2328 @retval true non default escape char specified
2329 using "expr LIKE pat ESCAPE 'escape_char'" syntax
2330 */
2331 bool escape_was_used_in_parsing() const { return arg_count > 2; }
2332
2333 /// Returns the escape character.
2334 int escape() const {
2335 assert(escape_is_evaluated());
2336 return m_escape;
2337 }
2338
2339 /**
2340 Has the escape clause been evaluated? It only needs to be evaluated
2341 once per execution, since we require it to be constant during execution.
2342 The escape member has a valid value if and only if this function returns
2343 true.
2344 */
2345 bool escape_is_evaluated() const { return escape_evaluated; }
2346
2347 float get_filtering_effect(THD *thd, table_map filter_for_table,
2348 table_map read_tables,
2349 const MY_BITMAP *fields_to_ignore,
2350 double rows_in_table) override;
2351
2352 private:
2353 /**
2354 The method updates covering keys depending on the
2355 length of wild string prefix.
2356
2357 @param thd Pointer to THD object.
2358
2359 @retval true if error happens during wild string prefix calculation,
2360 false otherwise.
2361 */
2363};
2364
2367
2368 protected:
2371
2372 public:
2373 /* Item_cond() is only used to create top level items */
2376 list.push_back(i1);
2377 list.push_back(i2);
2378 }
2379 Item_cond(const POS &pos, Item *i1, Item *i2)
2380 : Item_bool_func(pos), abort_on_null(false) {
2381 list.push_back(i1);
2382 list.push_back(i2);
2383 }
2384
2385 Item_cond(THD *thd, Item_cond *item);
2387 : Item_bool_func(), list(nlist), abort_on_null(false) {}
2388 bool add(Item *item) {
2389 assert(item);
2390 return list.push_back(item);
2391 }
2392 bool add_at_head(Item *item) {
2393 assert(item);
2394 return list.push_front(item);
2395 }
2397 assert(nlist->elements);
2398 list.prepend(nlist);
2399 }
2400
2401 bool itemize(Parse_context *pc, Item **res) override;
2402
2403 bool fix_fields(THD *, Item **ref) override;
2404 void fix_after_pullout(Query_block *parent_query_block,
2405 Query_block *removed_query_block) override;
2406
2407 Type type() const override { return COND_ITEM; }
2409 bool eq(const Item *item, bool binary_cmp) const override;
2410 table_map used_tables() const override { return used_tables_cache; }
2411 void update_used_tables() override;
2412 void print(const THD *thd, String *str,
2413 enum_query_type query_type) const override;
2414 void split_sum_func(THD *thd, Ref_item_array ref_item_array,
2415 mem_root_deque<Item *> *fields) override;
2416 void apply_is_true() override { abort_on_null = true; }
2417 void copy_andor_arguments(THD *thd, Item_cond *item);
2418 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
2419 Item *transform(Item_transformer transformer, uchar *arg) override;
2420 void traverse_cond(Cond_traverser, void *arg, traverse_order order) override;
2421 bool truth_transform_arguments(THD *thd, Bool_test test);
2422 bool subst_argument_checker(uchar **) override { return true; }
2423 Item *compile(Item_analyzer analyzer, uchar **arg_p,
2424 Item_transformer transformer, uchar *arg_t) override;
2425 bool remove_const_conds(THD *thd, Item *item, Item **new_item);
2426 /// Treat UNKNOWN result like FALSE because callers see no difference
2427 bool ignore_unknown() const { return abort_on_null; }
2428 bool equality_substitution_analyzer(uchar **) override { return true; }
2429};
2430
2431/*
2432 The class Item_equal is used to represent conjunctions of equality
2433 predicates of the form field1 = field2, and field=const in where
2434 conditions and on expressions.
2435
2436 All equality predicates of the form field1=field2 contained in a
2437 conjunction are substituted for a sequence of items of this class.
2438 An item of this class Item_equal(f1,f2,...fk) represents a
2439 multiple equality f1=f2=...=fk.
2440
2441 If a conjunction contains predicates f1=f2 and f2=f3, a new item of
2442 this class is created Item_equal(f1,f2,f3) representing the multiple
2443 equality f1=f2=f3 that substitutes the above equality predicates in
2444 the conjunction.
2445 A conjunction of the predicates f2=f1 and f3=f1 and f3=f2 will be
2446 substituted for the item representing the same multiple equality
2447 f1=f2=f3.
2448 An item Item_equal(f1,f2) can appear instead of a conjunction of
2449 f2=f1 and f1=f2, or instead of just the predicate f1=f2.
2450
2451 An item of the class Item_equal inherits equalities from outer
2452 conjunctive levels.
2453
2454 Suppose we have a where condition of the following form:
2455 WHERE f1=f2 AND f3=f4 AND f3=f5 AND ... AND (...OR (f1=f3 AND ...)).
2456 In this case:
2457 f1=f2 will be substituted for Item_equal(f1,f2);
2458 f3=f4 and f3=f5 will be substituted for Item_equal(f3,f4,f5);
2459 f1=f3 will be substituted for Item_equal(f1,f2,f3,f4,f5);
2460
2461 An object of the class Item_equal can contain an optional constant
2462 item c. Then it represents a multiple equality of the form
2463 c=f1=...=fk.
2464
2465 Objects of the class Item_equal are used for the following:
2466
2467 1. An object Item_equal(t1.f1,...,tk.fk) allows us to consider any
2468 pair of tables ti and tj as joined by an equi-condition.
2469 Thus it provide us with additional access paths from table to table.
2470
2471 2. An object Item_equal(t1.f1,...,tk.fk) is applied to deduce new
2472 SARGable predicates:
2473 f1=...=fk AND P(fi) => f1=...=fk AND P(fi) AND P(fj).
2474 It also can give us additional index scans and can allow us to
2475 improve selectivity estimates.
2476
2477 3. An object Item_equal(t1.f1,...,tk.fk) is used to optimize the
2478 selected execution plan for the query: if table ti is accessed
2479 before the table tj then in any predicate P in the where condition
2480 the occurrence of tj.fj is substituted for ti.fi. This can allow
2481 an evaluation of the predicate at an earlier step.
2482
2483 When feature 1 is supported they say that join transitive closure
2484 is employed.
2485 When feature 2 is supported they say that search argument transitive
2486 closure is employed.
2487 Both features are usually supported by preprocessing original query and
2488 adding additional predicates.
2489 We do not just add predicates, we rather dynamically replace some
2490 predicates that can not be used to access tables in the investigated
2491 plan for those, obtained by substitution of some fields for equal fields,
2492 that can be used.
2493
2494 Prepared Statements/Stored Procedures note: instances of class
2495 Item_equal are created only at the time a PS/SP is executed and
2496 are deleted in the end of execution. All changes made to these
2497 objects need not be registered in the list of changes of the parse
2498 tree and do not harm PS/SP re-execution.
2499
2500 Item equal objects are employed only at the optimize phase. Usually they are
2501 not supposed to be evaluated. Yet in some cases we call the method val_int()
2502 for them. We have to take care of restricting the predicate such an
2503 object represents f1=f2= ...=fn to the projection of known fields fi1=...=fik.
2504*/
2505class Item_equal final : public Item_bool_func {
2506 List<Item_field> fields; /* list of equal field items */
2507 Item *const_item; /* optional constant item equal to fields items */
2512
2513 public:
2514 inline Item_equal()
2515 : Item_bool_func(),
2518 cond_false(false) {}
2520 Item_equal(Item *c, Item_field *f);
2521 Item_equal(Item_equal *item_equal);
2522
2523 Item *get_const() const { return const_item; }
2524 void set_const(Item *c) { const_item = c; }
2525 bool compare_const(THD *thd, Item *c);
2526 bool add(THD *thd, Item *c, Item_field *f);
2527 bool add(THD *thd, Item *c);
2528 void add(Item_field *f);
2529 uint members();
2530 bool contains(const Field *field) const;
2531 /**
2532 Get the first field of multiple equality, use for semantic checking.
2533
2534 @retval First field in the multiple equality.
2535 */
2536 Item_field *get_first() { return fields.head(); }
2537 Item_field *get_subst_item(const Item_field *field);
2538 bool merge(THD *thd, Item_equal *item);
2539 bool update_const(THD *thd);
2540 enum Functype functype() const override { return MULT_EQUAL_FUNC; }
2541 longlong val_int() override;
2542 const char *func_name() const override { return "multiple equal"; }
2543 optimize_type select_optimize(const THD *) override { return OPTIMIZE_EQUAL; }
2545 // Multiple equality nodes (Item_equal) should have been
2546 // converted back to simple equalities (Item_func_eq) by
2547 // substitute_for_best_equal_field before cast nodes are injected.
2548 assert(false);
2549 return false;
2550 }
2552 return get_const() == nullptr;
2553 }
2554
2555 /**
2556 Order field items in multiple equality according to a sorting criteria.
2557
2558 The function perform ordering of the field items in the Item_equal
2559 object according to the criteria determined by the cmp callback parameter.
2560 If cmp(item_field1,item_field2,arg)<0 than item_field1 must be
2561 placed after item_field2.
2562
2563 The function sorts field items by the exchange sort algorithm.
2564 The list of field items is looked through and whenever two neighboring
2565 members follow in a wrong order they are swapped. This is performed
2566 again and again until we get all members in a right order.
2567
2568 @param compare function to compare field item
2569 */
2570 template <typename Node_cmp_func>
2571 void sort(Node_cmp_func compare) {
2572 fields.sort(compare);
2573 }
2574
2575 // A class to iterate over fields without exposing fields directly.
2577 public:
2578 explicit FieldProxy(Item_equal *item) : m_fields(&item->fields) {}
2582 return m_fields->cbegin();
2583 }
2586 return m_fields->cbegin();
2587 }
2589 return m_fields->cend();
2590 }
2591
2592 private:
2594 };
2596 public:
2597 explicit ConstFieldProxy(const Item_equal *item)
2598 : m_fields(&item->fields) {}
2600 return m_fields->cbegin();
2601 }
2604 return m_fields->cbegin();
2605 }
2607 return m_fields->cend();
2608 }
2609 size_t size() const { return m_fields->size(); }
2610
2611 private:
2613 };
2616
2617 bool resolve_type(THD *) override;
2618 bool fix_fields(THD *thd, Item **ref) override;
2619 void update_used_tables() override;
2620 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
2621 void print(const THD *thd, String *str,
2622 enum_query_type query_type) const override;
2623 bool eq(const Item *item, bool binary_cmp) const override;
2624 const CHARSET_INFO *compare_collation() const override {
2625 return fields.head()->collation.collation;
2626 }
2627
2628 bool equality_substitution_analyzer(uchar **) override { return true; }
2629
2631
2632 float get_filtering_effect(THD *thd, table_map filter_for_table,
2633 table_map read_tables,
2634 const MY_BITMAP *fields_to_ignore,
2635 double rows_in_table) override;
2636 Item *m_const_folding[2]; ///< temporary area used for constant folding
2637
2638 private:
2640};
2641
2643 public:
2644 uint max_members; /* max number of members the current level
2645 list and all lower level lists */
2646 COND_EQUAL *upper_levels; /* multiple equalities of upper and levels */
2647 List<Item_equal> current_level; /* list of multiple equalities of
2648 the current and level */
2649 COND_EQUAL() { upper_levels = nullptr; }
2650};
2651
2652class Item_cond_and final : public Item_cond {
2653 public:
2654 COND_EQUAL cond_equal; /* contains list of Item_equal objects for
2655 the current and level and reference
2656 to multiple equalities of upper and levels */
2658
2659 Item_cond_and(Item *i1, Item *i2) : Item_cond(i1, i2) {}
2660 Item_cond_and(const POS &pos, Item *i1, Item *i2) : Item_cond(pos, i1, i2) {}
2661
2662 Item_cond_and(THD *thd, Item_cond_and *item) : Item_cond(thd, item) {}
2663 Item_cond_and(List<Item> &list_arg) : Item_cond(list_arg) {}
2664 enum Functype functype() const override { return COND_AND_FUNC; }
2665 longlong val_int() override;
2666 const char *func_name() const override { return "and"; }
2668 Item_cond_and *item;
2669 if ((item = new Item_cond_and(thd, this)))
2670 item->copy_andor_arguments(thd, this);
2671 return item;
2672 }
2673 Item *truth_transformer(THD *, Bool_test) override;
2674 bool gc_subst_analyzer(uchar **) override { return true; }
2675
2676 float get_filtering_effect(THD *thd, table_map filter_for_table,
2677 table_map read_tables,
2678 const MY_BITMAP *fields_to_ignore,
2679 double rows_in_table) override;
2680
2681 bool contains_only_equi_join_condition() const override;
2682};
2683
2684class Item_cond_or final : public Item_cond {
2685 public:
2687
2688 Item_cond_or(Item *i1, Item *i2) : Item_cond(i1, i2) {}
2689 Item_cond_or(const POS &pos, Item *i1, Item *i2) : Item_cond(pos, i1, i2) {}
2690
2691 Item_cond_or(THD *thd, Item_cond_or *item) : Item_cond(thd, item) {}
2692 Item_cond_or(List<Item> &list_arg) : Item_cond(list_arg) {}
2693 enum Functype functype() const override { return COND_OR_FUNC; }
2694 longlong val_int() override;
2695 const char *func_name() const override { return "or"; }
2697 Item_cond_or *item;
2698 if ((item = new Item_cond_or(thd, this)))
2699 item->copy_andor_arguments(thd, this);
2700 return item;
2701 }
2702 Item *truth_transformer(THD *, Bool_test) override;
2703 bool gc_subst_analyzer(uchar **) override { return true; }
2704
2705 float get_filtering_effect(THD *thd, table_map filter_for_table,
2706 table_map read_tables,
2707 const MY_BITMAP *fields_to_ignore,
2708 double rows_in_table) override;
2709};
2710
2711/// Builds condition: (a AND b) IS TRUE
2712inline Item *and_conds(Item *a, Item *b) {
2713 if (!b) return a;
2714 if (!a) return b;
2715
2716 Item *item = new Item_cond_and(a, b);
2717 if (item == nullptr) return nullptr;
2718 item->apply_is_true();
2719 return item;
2720}
2721
2722longlong get_datetime_value(THD *thd, Item ***item_arg, Item ** /* cache_arg */,
2723 const Item *warn_item, bool *is_null);
2724
2725// TODO: the next two functions should be moved to sql_time.{h,cc}
2728
2730 enum_mysql_timestamp_type warn_type,
2731 const char *warn_name, MYSQL_TIME *l_time);
2732
2733// Helper function to ensure_multi_equality_fields_are_available().
2734// Finds and adjusts (if "replace" is set to true) an "Item_field" in a
2735// function with an equal field in the available tables. For more
2736// details look at FindEqualField().
2737void find_and_adjust_equal_fields(Item *item, table_map available_tables,
2738 bool replace, bool *found);
2739
2740/*
2741 These need definitions from this file but the variables are defined
2742 in mysqld.h. The variables really belong in this component, but for
2743 the time being we leave them in mysqld.cc to avoid merge problems.
2744*/
2745extern Eq_creator eq_creator;
2747extern Ne_creator ne_creator;
2748extern Gt_creator gt_creator;
2749extern Lt_creator lt_creator;
2750extern Ge_creator ge_creator;
2751extern Le_creator le_creator;
2752
2753#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:7863
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:2642
uint max_members
Definition: item_cmpfunc.h:2644
COND_EQUAL * upper_levels
Definition: item_cmpfunc.h:2646
List< Item_equal > current_level
Definition: item_cmpfunc.h:2647
COND_EQUAL()
Definition: item_cmpfunc.h:2649
Abstract factory interface for creating comparison predicates.
Definition: item_cmpfunc.h:521
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:551
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:553
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:560
const char * symbol(bool invert) const override
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:562
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:598
Item_bool_func * create(Item *a, Item *b) const override
Definition: item_cmpfunc.cc:314
bool l_op() const override
Definition: item_cmpfunc.h:603
bool eqne_op() const override
Definition: item_cmpfunc.h:602
const char * symbol(bool invert) const override
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:601
Definition: item_cmpfunc.h:582
bool l_op() const override
Definition: item_cmpfunc.h:587
Item_bool_func * create(Item *a, Item *b) const override
Definition: item_cmpfunc.cc:306
bool eqne_op() const override
Definition: item_cmpfunc.h:586
const char * symbol(bool invert) const override
This interface is only used by Item_allany_subselect.
Definition: item_cmpfunc.h:585
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:7831
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:3483
void set_str_value(String *str)
Definition: item.h:3505
Base class for functions that usually take two arguments, which are possibly strings,...
Definition: item_cmpfunc.h:620
bool have_rev_func() const override
Definition: item_cmpfunc.h:654
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:650
bool abort_on_null
Definition: item_cmpfunc.h:627
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:666
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:665
Arg_comparator cmp
Definition: item_cmpfunc.h:626
Item_bool_func2(const POS &pos, Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:638
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:632
Item_bool_func2(Item *a, Item *b)
Definition: item_cmpfunc.h:629
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:647
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:662
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_cmpfunc.h:661
Item_bool_func2(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:635
virtual enum Functype rev_functype() const
Definition: item_cmpfunc.h:653
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:668
const Arg_comparator * get_comparator() const
Definition: item_cmpfunc.h:673
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:656
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:669
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:2652
Item * copy_andor_structure(THD *thd) override
Definition: item_cmpfunc.h:2667
Item_cond_and(List< Item > &list_arg)
Definition: item_cmpfunc.h:2663
COND_EQUAL cond_equal
Definition: item_cmpfunc.h:2654
bool contains_only_equi_join_condition() const override
Whether this Item is an equi-join condition.
Definition: item_cmpfunc.cc:7425
longlong val_int() override
Evaluation of AND(expr, expr, expr ...).
Definition: item_cmpfunc.cc:5957
const char * func_name() const override
Definition: item_cmpfunc.h:2666
enum Functype functype() const override
Definition: item_cmpfunc.h:2664
Item_cond_and()
Definition: item_cmpfunc.h:2657
Item_cond_and(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2660
Item_cond_and(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2659
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2674
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:6641
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:5917
Item_cond_and(THD *thd, Item_cond_and *item)
Definition: item_cmpfunc.h:2662
Definition: item_cmpfunc.h:2684
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:6650
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2703
enum Functype functype() const override
Definition: item_cmpfunc.h:2693
Item_cond_or(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2688
Item * copy_andor_structure(THD *thd) override
Definition: item_cmpfunc.h:2696
Item_cond_or(List< Item > &list_arg)
Definition: item_cmpfunc.h:2692
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:5972
Item_cond_or(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2689
Item_cond_or()
Definition: item_cmpfunc.h:2686
longlong val_int() override
Definition: item_cmpfunc.cc:6001
const char * func_name() const override
Definition: item_cmpfunc.h:2695
Item_cond_or(THD *thd, Item_cond_or *item)
Definition: item_cmpfunc.h:2691
Definition: item_cmpfunc.h:2365
Item * transform(Item_transformer transformer, uchar *arg) override
Transform an Item_cond object with a transformer callback function.
Definition: item_cmpfunc.cc:5771
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:5863
void add_at_head(List< Item > *nlist)
Definition: item_cmpfunc.h:2396
bool add_at_head(Item *item)
Definition: item_cmpfunc.h:2392
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:5749
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:2416
Item_cond(Item *i1, Item *i2)
Definition: item_cmpfunc.h:2375
bool eq(const Item *item, bool binary_cmp) const override
Definition: item_cmpfunc.cc:5733
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:5855
Item_bool_func super
Definition: item_cmpfunc.h:2366
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:5886
bool remove_const_conds(THD *thd, Item *item, Item **new_item)
Remove constant conditions over literals.
Definition: item_cmpfunc.cc:5672
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:2427
void copy_andor_arguments(THD *thd, Item_cond *item)
Definition: item_cmpfunc.cc:5462
table_map used_tables() const override
Definition: item_cmpfunc.h:2410
bool truth_transform_arguments(THD *thd, Bool_test test)
Definition: item_cmpfunc.cc:5902
Item_cond(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:2379
Item_cond(List< Item > &nlist)
Definition: item_cmpfunc.h:2386
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:2422
List< Item > * argument_list()
Definition: item_cmpfunc.h:2408
Type type() const override
Definition: item_cmpfunc.h:2407
Item_cond()
Definition: item_cmpfunc.h:2374
List< Item > list
Definition: item_cmpfunc.h:2369
bool itemize(Parse_context *pc, Item **res) override
Contextualization for Item_cond functional items.
Definition: item_cmpfunc.cc:5445
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:2428
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:5711
bool add(Item *item)
Definition: item_cmpfunc.h:2388
bool abort_on_null
Definition: item_cmpfunc.h:2370
void traverse_cond(Cond_traverser, void *arg, traverse_order order) override
Definition: item_cmpfunc.cc:5817
bool fix_fields(THD *, Item **ref) override
Definition: item_cmpfunc.cc:5470
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:5796
Definition: item.h:4981
Definition: item_cmpfunc.h:2595
ConstFieldProxy(const Item_equal *item)
Definition: item_cmpfunc.h:2597
List_STL_Iterator< const Item_field > cbegin() const
Definition: item_cmpfunc.h:2603
List_STL_Iterator< const Item_field > cend() const
Definition: item_cmpfunc.h:2606
List_STL_Iterator< const Item_field > begin() const
Definition: item_cmpfunc.h:2599
size_t size() const
Definition: item_cmpfunc.h:2609
const List< Item_field > * m_fields
Definition: item_cmpfunc.h:2612
List_STL_Iterator< const Item_field > end() const
Definition: item_cmpfunc.h:2602
Definition: item_cmpfunc.h:2576
List_STL_Iterator< Item_field > begin()
Definition: item_cmpfunc.h:2579
List_STL_Iterator< Item_field > end()
Definition: item_cmpfunc.h:2580
List< Item_field > * m_fields
Definition: item_cmpfunc.h:2593
List_STL_Iterator< const Item_field > begin() const
Definition: item_cmpfunc.h:2581
List_STL_Iterator< const Item_field > cbegin() const
Definition: item_cmpfunc.h:2585
List_STL_Iterator< const Item_field > cend() const
Definition: item_cmpfunc.h:2588
List_STL_Iterator< const Item_field > end() const
Definition: item_cmpfunc.h:2584
FieldProxy(Item_equal *item)
Definition: item_cmpfunc.h:2578
Definition: item_cmpfunc.h:2505
Item * get_const() const
Definition: item_cmpfunc.h:2523
ConstFieldProxy get_fields() const
Definition: item_cmpfunc.h:2615
bool contains_only_equi_join_condition() const override
Whether this Item is an equi-join condition.
Definition: item_cmpfunc.h:2551
bool fix_fields(THD *thd, Item **ref) override
Definition: item_cmpfunc.cc:6904
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:2544
bool eq(const Item *item, bool binary_cmp) const override
Definition: item_cmpfunc.cc:7111
longlong val_int() override
Definition: item_cmpfunc.cc:7049
bool add(THD *thd, Item *c, Item_field *f)
Definition: item_cmpfunc.cc:6788
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:6936
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2624
void sort(Node_cmp_func compare)
Order field items in multiple equality according to a sorting criteria.
Definition: item_cmpfunc.h:2571
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:7067
bool update_const(THD *thd)
Check appearance of new constant items in the multiple equality object.
Definition: item_cmpfunc.cc:6878
Arg_comparator cmp
Definition: item_cmpfunc.h:2509
Item_field * get_first()
Get the first field of multiple equality, use for semantic checking.
Definition: item_cmpfunc.h:2536
const char * func_name() const override
Definition: item_cmpfunc.h:2542
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2543
List< Item_field > fields
Definition: item_cmpfunc.h:2506
bool compare_as_dates
Definition: item_cmpfunc.h:2511
bool cond_false
Definition: item_cmpfunc.h:2510
FieldProxy get_fields()
Definition: item_cmpfunc.h:2614
Item * const_item
Definition: item_cmpfunc.h:2507
enum Functype functype() const override
Definition: item_cmpfunc.h:2540
void set_const(Item *c)
Definition: item_cmpfunc.h:2524
bool merge(THD *thd, Item_equal *item)
Join members of another Item_equal object.
Definition: item_cmpfunc.cc:6847
bool compare_const(THD *thd, Item *c)
Definition: item_cmpfunc.cc:6771
Item * m_const_folding[2]
temporary area used for constant folding
Definition: item_cmpfunc.h:2636
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:7339
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:2628
uint members()
Definition: item_cmpfunc.cc:6810
Item_equal()
Definition: item_cmpfunc.h:2514
cmp_item * eval_item
Definition: item_cmpfunc.h:2508
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:7095
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:7083
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:7034
bool contains(const Field *field) const
Check whether a field is referred in the multiple equality.
Definition: item_cmpfunc.cc:6825
Item_field * get_subst_item(const Item_field *field)
Get item that can be substituted for the supplied item.
Definition: item_cmpfunc.cc:7254
Definition: item.h:4033
Definition: item.h:5027
ANY_VALUE(expr) is like expr except that it is not checked by aggregate_check logic.
Definition: item_cmpfunc.h:1461
bool aggregate_check_group(uchar *arg) override
Definition: item_cmpfunc.cc:7411
const char * func_name() const override
Definition: item_cmpfunc.h:1465
Item_func_any_value(const POS &pos, Item *a)
Definition: item_cmpfunc.h:1463
Item_func_any_value(Item *a)
Definition: item_cmpfunc.h:1464
bool aggregate_check_distinct(uchar *arg) override
Definition: item_cmpfunc.cc:7418
Definition: item_cmpfunc.h:1284
Arg_comparator ge_cmp
Definition: item_cmpfunc.h:1296
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1303
bool compare_as_dates_with_strings
Definition: item_cmpfunc.h:1291
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:2985
bool is_bool_func() const override
Definition: item_cmpfunc.h:1312
String value1
Definition: item_cmpfunc.h:1289
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:3102
Item_func_between(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
Definition: item_cmpfunc.h:1297
Item_result cmp_type
Definition: item_cmpfunc.h:1288
String value2
Definition: item_cmpfunc.h:1289
bool compare_as_temporal_dates
Definition: item_cmpfunc.h:1292
longlong val_int() override
Definition: item_cmpfunc.cc:3224
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:1313
Arg_comparator le_cmp
Definition: item_cmpfunc.h:1296
String value0
Definition: item_cmpfunc.h:1289
const char * func_name() const override
Definition: item_cmpfunc.h:1305
void update_not_null_tables()
Definition: item_cmpfunc.h:1325
uint decimal_precision() const override
Definition: item_cmpfunc.h:1316
bool fix_fields(THD *, Item **) override
Perform context analysis of a BETWEEN item tree.
Definition: item_cmpfunc.cc:2959
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:3107
DTCollation cmp_collation
Definition: item_cmpfunc.h:1285
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1317
bool compare_as_temporal_times
Definition: item_cmpfunc.h:1293
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:3317
enum Functype functype() const override
Definition: item_cmpfunc.h:1304
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:2979
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:1947
my_decimal * val_decimal(my_decimal *) override
Definition: item_cmpfunc.cc:3796
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_cmpfunc.cc:3813
double val_real() override
Definition: item_cmpfunc.cc:3780
Item_result cmp_type
Definition: item_cmpfunc.h:1954
cmp_item * cmp_items[5]
Definition: item_cmpfunc.h:1956
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:1992
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2003
cmp_item * case_item
Definition: item_cmpfunc.h:1957
bool fix_fields(THD *thd, Item **ref) override
Definition: item_cmpfunc.cc:3852
bool resolve_type_inner(THD *thd) override
Resolve type of function after all arguments have had their data types resolved.
Definition: item_cmpfunc.cc:3941
int else_expr_num
Definition: item_cmpfunc.h:1950
int first_expr_num
Definition: item_cmpfunc.h:1950
DTCollation cmp_collation
Definition: item_cmpfunc.h:1955
Item_func super
Definition: item_cmpfunc.h:1948
Item_func_case(const POS &pos, mem_root_deque< Item * > *list, Item *first_expr_arg, Item *else_expr_arg)
Definition: item_cmpfunc.h:1960
int get_first_expr_num() const
Definition: item_cmpfunc.h:1982
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:3709
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:3889
~Item_func_case() override
Definition: item_cmpfunc.cc:4108
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_cmpfunc.cc:3834
const char * func_name() const override
Definition: item_cmpfunc.h:1999
String * val_str(String *) override
Definition: item_cmpfunc.cc:3738
enum Item_result result_type() const override
Definition: item_cmpfunc.h:1998
bool get_time(MYSQL_TIME *ltime) override
Definition: item_cmpfunc.cc:3843
longlong val_int() override
Definition: item_cmpfunc.cc:3764
enum Item_result cached_result_type left_result_type
Definition: item_cmpfunc.h:1951
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_cmpfunc.cc:4065
uint ncases
Definition: item_cmpfunc.h:1953
String tmp_value
Definition: item_cmpfunc.h:1952
void print(const THD *thd, String *str, enum_query_type query_type) const override
Definition: item_cmpfunc.cc:4086
enum Functype functype() const override
Definition: item_cmpfunc.h:2006
int get_else_expr_num() const
Definition: item_cmpfunc.h:1983
Definition: item_cmpfunc.h:1396
Item_func_coalesce(const POS &pos, Item *a)
Definition: item_cmpfunc.h:1402
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:4177
bool resolve_type_inner(THD *thd) override
Resolve type of function after all arguments have had their data types resolved.
Definition: item_cmpfunc.cc:4202
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_cmpfunc.cc:4221
Item_func_coalesce(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1398
enum Item_result result_type() const override
Definition: item_cmpfunc.h:1433
bool val_json(Json_wrapper *wr) override
Get the result of COALESCE as a JSON value.
Definition: item_cmpfunc.cc:4130
Item_func_coalesce(Item *a, Item *b)
Definition: item_cmpfunc.h:1415
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:4193
const char * func_name() const override
Definition: item_cmpfunc.h:1434
my_decimal * decimal_op(my_decimal *) override
Performs the operation that this functions implements when the result type is DECIMAL.
Definition: item_cmpfunc.cc:4166
longlong int_op() override
Performs the operation that this functions implements when the result type is INT.
Definition: item_cmpfunc.cc:4144
String * str_op(String *) override
Coalesce - return first not NULL argument.
Definition: item_cmpfunc.cc:4119
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:1412
double real_op() override
Performs the operation that this functions implements when the result type is REAL.
Definition: item_cmpfunc.cc:4155
Item_func_coalesce(Item *a)
Definition: item_cmpfunc.h:1405
bool time_op(MYSQL_TIME *ltime) override
Definition: item_cmpfunc.cc:4185
Item_func_coalesce(const POS &pos, PT_item_list *list)
Definition: item_cmpfunc.h:1408
enum Functype functype() const override
Definition: item_cmpfunc.h:1435
void set_numeric_type() override
Definition: item_cmpfunc.h:1432
Item_func_comparison is a class for comparison functions that take two arguments and return a boolean...
Definition: item_cmpfunc.h:684
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:696
Item_func_comparison(Item *a, Item *b)
Definition: item_cmpfunc.h:686
bool contains_only_equi_join_condition() const override
Whether this Item is an equi-join condition.
Definition: item_cmpfunc.cc:7440
Item_func_comparison(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:689
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_cmpfunc.cc:6723
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:6598
virtual Item * negated_item()
just fake method, should never be called.
Definition: item_cmpfunc.cc:6718
bool cast_incompatible_args(uchar *) override
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item_cmpfunc.cc:6738
Implements the comparison operator equals (=)
Definition: item_cmpfunc.h:976
enum Functype functype() const override
Definition: item_cmpfunc.h:982
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:989
void ensure_multi_equality_fields_are_available(table_map left_side_tables, table_map right_side_tables, bool replace, bool *found)
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:7917
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:7780
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:984
Item_equal * source_multiple_equality
Definition: item_cmpfunc.h:1076
Item_func_eq(Item *a, Item *b)
Definition: item_cmpfunc.h:978
longlong val_int() override
Definition: item_cmpfunc.cc:2488
Item_func_eq(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:979
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:983
const char * func_name() const override
Definition: item_cmpfunc.h:985
Item * negated_item() override
just fake method, should never be called.
Definition: item_cmpfunc.cc:6681
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:7393
Item * create_cast_if_needed(MEM_ROOT *mem_root, Item *argument) const
Wrap the argument in a typecast, if needed.
Definition: item_cmpfunc.cc:7803
bool equality_substitution_analyzer(uchar **) override
Definition: item_cmpfunc.h:987
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:7374
The <=> operator evaluates the same as.
Definition: item_cmpfunc.h:1088
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:1107
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:1098
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1105
enum Functype functype() const override
Definition: item_cmpfunc.h:1103
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:1104
longlong val_int() override
Definition: item_cmpfunc.cc:2503
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:2538
bool resolve_type(THD *thd) override
Same as Item_func_eq, but NULL = NULL.
Definition: item_cmpfunc.cc:2496
const char * func_name() const override
Definition: item_cmpfunc.h:1106
Item_func_equal(Item *a, Item *b)
Definition: item_cmpfunc.h:1090
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_cmpfunc.h:1108
Item_func_equal(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1093
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
enum Functype functype() const override
Definition: item_cmpfunc.h:394
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:1119
longlong val_int() override
Definition: item_cmpfunc.cc:2679
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1128
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:1124
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1125
Item * negated_item() override
just fake method, should never be called.
Definition: item_cmpfunc.cc:6700
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:2550
Item_func_ge(Item *a, Item *b)
Definition: item_cmpfunc.h:1121
const char * func_name() const override
Definition: item_cmpfunc.h:1126
enum Functype functype() const override
Definition: item_cmpfunc.h:1123
Implements the comparison operator greater than (>)
Definition: item_cmpfunc.h:1139
Item * negated_item() override
just fake method, should never be called.
Definition: item_cmpfunc.cc:6705
longlong val_int() override
Definition: item_cmpfunc.cc:2685
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1148
Item_func_gt(Item *a, Item *b)
Definition: item_cmpfunc.h:1141
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:2641
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1145
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:1144
const char * func_name() const override
Definition: item_cmpfunc.h:1146
enum Functype functype() const override
Definition: item_cmpfunc.h:1143
Definition: item_cmpfunc.h:1470
bool get_time(MYSQL_TIME *ltime) override
Definition: item_cmpfunc.cc:3568
bool fix_fields(THD *, Item **) override
Perform context analysis of an IF item tree.
Definition: item_cmpfunc.cc:3436
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_cmpfunc.cc:3551
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item_cmpfunc.cc:3562
Item_func_if(Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1474
double val_real() override
Definition: item_cmpfunc.cc:3498
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:3447
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:3458
enum Functype functype() const override
Definition: item_cmpfunc.h:1501
enum Item_result result_type() const override
Definition: item_cmpfunc.h:1490
my_decimal * val_decimal(my_decimal *) override
Definition: item_cmpfunc.cc:3542
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:1492
longlong val_int() override
Definition: item_cmpfunc.cc:3507
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item_cmpfunc.cc:3491
const char * func_name() const override
Definition: item_cmpfunc.h:1500
void update_used_tables() override
T1(IF(e,e1,e2)) = intersection(T1(e1),T1(e2))
Definition: item_cmpfunc.cc:3453
void update_not_null_tables()
Definition: item_cmpfunc.h:1505
String * val_str(String *str) override
Definition: item_cmpfunc.cc:3516
bool resolve_type_inner(THD *thd) override
Resolve type of function after all arguments have had their data types resolved.
Definition: item_cmpfunc.cc:3472
enum Item_result cached_result_type
Definition: item_cmpfunc.h:1471
Item_func_if(const POS &pos, Item *a, Item *b, Item *c)
Definition: item_cmpfunc.h:1478
Definition: item_cmpfunc.h:1438
bool field_type_defined
Definition: item_cmpfunc.h:1440
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:3384
Item_func_ifnull(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1443
my_decimal * decimal_op(my_decimal *) override
Performs the operation that this functions implements when the result type is DECIMAL.
Definition: item_cmpfunc.cc:3357
String * str_op(String *str) override
Coalesce - return first not NULL argument.
Definition: item_cmpfunc.cc:3396
double real_op() override
Performs the operation that this functions implements when the result type is REAL.
Definition: item_cmpfunc.cc:3333
const char * func_name() const override
Definition: item_cmpfunc.h:1452
longlong int_op() override
Performs the operation that this functions implements when the result type is INT.
Definition: item_cmpfunc.cc:3345
Field * tmp_table_field(TABLE *table) override
Definition: item_cmpfunc.cc:3329
bool val_json(Json_wrapper *result) override
Get the result of COALESCE as a JSON value.
Definition: item_cmpfunc.cc:3369
bool time_op(MYSQL_TIME *ltime) override
Definition: item_cmpfunc.cc:3390
in_expr [NOT] IN (in_value_list).
Definition: item_cmpfunc.h:2020
DTCollation cmp_collation
Definition: item_cmpfunc.h:2048
bool values_are_const
Set to true if the values arguments are const.
Definition: item_cmpfunc.h:2036
~Item_func_in() override
Definition: item_cmpfunc.cc:5397
Item_func_in(const POS &pos, PT_item_list *list, bool is_negation)
Definition: item_cmpfunc.h:2051
enum Functype functype() const override
Definition: item_cmpfunc.h:2078
const char * func_name() const override
Definition: item_cmpfunc.h:2079
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:4989
longlong val_int() override
Definition: item_cmpfunc.cc:5310
in_vector * array
An array of values, created when the bisection lookup method is used.
Definition: item_cmpfunc.h:2023
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:5270
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:4808
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:2042
bool populate_bisection(THD *thd)
Populate values for bisection with fresh values, should be called once per execution.
Definition: item_cmpfunc.cc:5359
bool fix_fields(THD *, Item **) override
Perform context analysis of an IN item tree.
Definition: item_cmpfunc.cc:4983
cmp_item * cmp_items[6]
Definition: item_cmpfunc.h:2047
bool populated
Set to true when bisection values are populated.
Definition: item_cmpfunc.h:2032
Item_result left_result_type
Definition: item_cmpfunc.h:2046
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:2030
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:4995
bool is_bool_func() const override
Definition: item_cmpfunc.h:2080
uint decimal_precision() const override
Definition: item_cmpfunc.h:2063
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:4829
void cleanup_arrays()
Helper function for this common task.
Definition: item_cmpfunc.cc:5366
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2081
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_cmpfunc.cc:5376
bool list_contains_null()
Usable if <in value list> is made only of constants.
Definition: item_cmpfunc.cc:4947
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:5275
void update_not_null_tables()
Definition: item_cmpfunc.h:2091
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2075
bool first_resolve_call
True until start of 2nd call to resolve_type()
Definition: item_cmpfunc.h:2044
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:2084
Definition: item_cmpfunc.h:1365
bool resolve_type(THD *) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:2771
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_cmpfunc.cc:2750
Item_row * row
Definition: item_cmpfunc.h:1368
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:2759
bool use_decimal_comparison
Definition: item_cmpfunc.h:1369
const char * func_name() const override
Definition: item_cmpfunc.h:1384
longlong val_int() override
Execute Item_func_interval().
Definition: item_cmpfunc.cc:2868
interval_range * intervals
Definition: item_cmpfunc.h:1370
uint decimal_precision() const override
Definition: item_cmpfunc.h:1385
Item_int_func super
Definition: item_cmpfunc.h:1366
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:2848
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:2829
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:1373
Definition: item_cmpfunc.h:2261
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2279
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:6234
Item * truth_transformer(THD *, Bool_test test) override
a IS NOT NULL -> a IS NULL.
Definition: item_cmpfunc.cc:6637
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:2282
const char * func_name() const override
Definition: item_cmpfunc.h:2274
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:6212
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2275
Item_func_isnotnull(Item *a)
Definition: item_cmpfunc.h:2263
enum Functype functype() const override
Definition: item_cmpfunc.h:2269
Item_func_isnotnull(const POS &pos, Item *a)
Definition: item_cmpfunc.h:2264
longlong val_int() override
Definition: item_cmpfunc.cc:6229
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.h:2270
Definition: item_cmpfunc.h:2197
Item_func_isnull(Item *a)
Definition: item_cmpfunc.h:2204
Item_func_isnull(const POS &pos, Item *a)
Definition: item_cmpfunc.h:2205
const char * func_name() const override
Definition: item_cmpfunc.h:2211
Item * truth_transformer(THD *, Bool_test test) override
a IS NULL -> a IS NOT NULL.
Definition: item_cmpfunc.cc:6630
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:6141
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.cc:6017
Item_bool_func super
Definition: item_cmpfunc.h:2198
enum Functype functype() const override
Definition: item_cmpfunc.h:2209
bool cache_used
Definition: item_cmpfunc.h:2200
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:6174
longlong val_int() override
Definition: item_cmpfunc.cc:6168
bool cached_value
Definition: item_cmpfunc.h:2201
const CHARSET_INFO * compare_collation() const override
Definition: item_cmpfunc.h:2223
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:6033
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:2219
bool fix_fields(THD *thd, Item **ref) override
Definition: item_cmpfunc.cc:6056
Implements the comparison operator less than or equals (<=)
Definition: item_cmpfunc.h:1159
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1168
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1165
longlong val_int() override
Definition: item_cmpfunc.cc:2691
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:1164
Item_func_le(Item *a, Item *b)
Definition: item_cmpfunc.h:1161
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:2611
const char * func_name() const override
Definition: item_cmpfunc.h:1166
enum Functype functype() const override
Definition: item_cmpfunc.h:1163
Item * negated_item() override
just fake method, should never be called.
Definition: item_cmpfunc.cc:6710
Definition: item_cmpfunc.h:2291
Item_func_like(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:2310
optimize_type select_optimize(const THD *thd) override
We can optimize a where if first character isn't a wildcard.
Definition: item_cmpfunc.cc:6300
int escape() const
Returns the escape character.
Definition: item_cmpfunc.h:2334
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:6485
int m_escape
The escape character (0 if no escape character).
Definition: item_cmpfunc.h:2298
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item_cmpfunc.cc:6388
longlong val_int() override
Definition: item_cmpfunc.cc:6268
bool check_covering_prefix_keys(THD *thd)
The method updates covering keys depending on the length of wild string prefix.
Definition: item_cmpfunc.cc:6323
enum Functype functype() const override
Definition: item_cmpfunc.h:2314
bool escape_is_const
True if escape clause is const (a literal)
Definition: item_cmpfunc.h:2293
bool escape_was_used_in_parsing() const
Definition: item_cmpfunc.h:2331
Item_func_like(Item *a, Item *b, Item *escape_arg)
Definition: item_cmpfunc.h:2302
bool eval_escape_clause(THD *thd)
Evaluate the expression in the escape clause.
Definition: item_cmpfunc.cc:6399
Item_func_like(Item *a, Item *b)
Definition: item_cmpfunc.h:2301
bool fix_fields(THD *thd, Item **ref) override
Definition: item_cmpfunc.cc:6350
cond_result eq_cmp_result() const override
Result may be not equal with equal inputs if ESCAPE character is present.
Definition: item_cmpfunc.h:2317
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:6241
const char * func_name() const override
Definition: item_cmpfunc.h:2318
bool escape_is_evaluated() const
Has the escape clause been evaluated? It only needs to be evaluated once per execution,...
Definition: item_cmpfunc.h:2345
Item_func_like(const POS &pos, Item *a, Item *b, Item *escape_arg)
Definition: item_cmpfunc.h:2306
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:2295
Implements the comparison operator less than (<)
Definition: item_cmpfunc.h:1211
Item_func_lt(Item *a, Item *b)
Definition: item_cmpfunc.h:1213
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1217
enum Functype functype() const override
Definition: item_cmpfunc.h:1215
bool gc_subst_analyzer(uchar **) override
Analyzer function for GC substitution.
Definition: item_cmpfunc.h:1220
longlong val_int() override
Definition: item_cmpfunc.cc:2711
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:1216
Item * negated_item() override
just fake method, should never be called.
Definition: item_cmpfunc.cc:6695
const char * func_name() const override
Definition: item_cmpfunc.h:1218
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:2581
Wrapper class when MATCH function is used in WHERE clause.
Definition: item_cmpfunc.h:759
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:771
Item_func_match_predicate(Item *a)
Definition: item_cmpfunc.h:761
const char * func_name() const override
Definition: item_cmpfunc.h:765
longlong val_int() override
Definition: item_cmpfunc.h:763
enum Functype functype() const override
Definition: item_cmpfunc.h:764
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:766
Implements the comparison operator not equals (<>)
Definition: item_cmpfunc.h:1231
enum Functype rev_functype() const override
Definition: item_cmpfunc.h:1236
cond_result eq_cmp_result() const override
Definition: item_cmpfunc.h:1237
const char * func_name() const override
Definition: item_cmpfunc.h:1239
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:2514
Item * negated_item() override
just fake method, should never be called.
Definition: item_cmpfunc.cc:6688
longlong val_int() override
Definition: item_cmpfunc.cc:2532
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1238
Item_func_ne(Item *a, Item *b)
Definition: item_cmpfunc.h:1233
enum Functype functype() const override
Definition: item_cmpfunc.h:1235
Definition: item_cmpfunc.h:964
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:969
Item * truth_transformer(THD *, Bool_test) override
Apply NOT transformation to the item and return a new one.
Definition: item_cmpfunc.cc:6659
Item_func_nop_all(Item *a)
Definition: item_cmpfunc.h:966
const char * func_name() const override
Definition: item_cmpfunc.h:968
longlong val_int() override
Special NOP (No OPeration) for ALL subquery.
Definition: item_cmpfunc.cc:430
Definition: item_cmpfunc.h:909
bool empty_underlying_subquery()
Definition: item_cmpfunc.cc:394
bool abort_on_null
Definition: item_cmpfunc.h:914
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:931
Item_subselect * subselect
Definition: item_cmpfunc.h:913
Item * truth_transformer(THD *, Bool_test) override
Apply NOT transformation to the item and return a new one.
Definition: item_cmpfunc.cc:6670
longlong val_int() override
special NOT for ALL subquery.
Definition: item_cmpfunc.cc:380
void set_subselect(Item_subselect *item)
Definition: item_cmpfunc.h:936
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:937
void set_sum_test(Item_sum_hybrid *item)
Definition: item_cmpfunc.h:934
bool show
Definition: item_cmpfunc.h:917
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:926
enum Functype functype() const override
Definition: item_cmpfunc.h:930
void set_sub_test(Item_maxmin_subselect *item)
Definition: item_cmpfunc.h:935
bool ignore_unknown() const
Treat UNKNOWN result like FALSE because callers see no difference.
Definition: item_cmpfunc.h:928
Item_sum_hybrid * test_sum_item
Definition: item_cmpfunc.h:911
Item_func_not_all(Item *a)
Definition: item_cmpfunc.h:919
Item_maxmin_subselect * test_sub_item
Definition: item_cmpfunc.h:912
Definition: item_cmpfunc.h:729
Item * truth_transformer(THD *, Bool_test) override
Apply NOT transformation to the item and return a new one.
Definition: item_cmpfunc.cc:6592
enum Functype functype() const override
Definition: item_cmpfunc.h:735
const char * func_name() const override
Definition: item_cmpfunc.h:736
longlong val_int() override
Definition: item_cmpfunc.cc:348
Item_func_not(Item *a)
Definition: item_cmpfunc.h:731
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:732
Definition: item_cmpfunc.h:1511
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.cc:3574
my_decimal * val_decimal(my_decimal *) override
Definition: item_cmpfunc.cc:3651
String * val_str(String *str) override
Definition: item_cmpfunc.cc:3638
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_cmpfunc.cc:3679
enum_field_types default_data_type() const override
Get the default data (output) type for the specific item.
Definition: item_cmpfunc.h:1525
enum Functype functype() const override
Definition: item_cmpfunc.h:1531
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item_cmpfunc.cc:3663
double val_real() override
Definition: item_cmpfunc.cc:3614
Item_result result_type() const override
Definition: item_cmpfunc.h:1524
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:1546
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:1536
enum Item_result cached_result_type
Definition: item_cmpfunc.h:1512
Item_func_nullif(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1515
const char * func_name() const override
Definition: item_cmpfunc.h:1530
longlong val_int() override
Definition: item_cmpfunc.cc:3626
bool resolve_type_inner(THD *thd) override
Resolve type of function after all arguments have had their data types resolved.
Definition: item_cmpfunc.cc:3588
uint decimal_precision() const override
Definition: item_cmpfunc.h:1534
Definition: item_func.h:775
Item_result hybrid_type
Definition: item_func.h:777
Definition: item_cmpfunc.h:1257
void negate()
Definition: item_cmpfunc.h:1272
bool ignore_unknown() const
Definition: item_cmpfunc.h:1274
bool subst_argument_checker(uchar **) override
Definition: item_cmpfunc.h:1281
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:1275
bool eq(const Item *item, bool binary_cmp) const override
Definition: item_cmpfunc.cc:2738
bool pred_level
Definition: item_cmpfunc.h:1260
Item_func_opt_neg(const POS &pos, Item *a, Item *b, Item *c, bool is_negation)
Definition: item_cmpfunc.h:1262
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:1273
Item_func_opt_neg(const POS &pos, PT_item_list *list, bool is_negation)
Definition: item_cmpfunc.h:1266
bool negated
Definition: item_cmpfunc.h:1259
Internal function used by subquery to derived transformation to check if a subquery is scalar.
Definition: item_cmpfunc.h:1182
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:1203
const char * func_name() const override
Definition: item_cmpfunc.h:1186
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:2704
bool is_valid_for_pushdown(uchar *arg) override
Redefine to avoid pushing into derived table.
Definition: item_cmpfunc.h:1188
longlong val_int() override
Definition: item_cmpfunc.cc:2697
Item_func_reject_if(Item *a)
Definition: item_cmpfunc.h:1184
Definition: item_cmpfunc.h:1336
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.h:1345
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_cmpfunc.h:1351
const char * func_name() const override
Definition: item_cmpfunc.h:1342
Item_func_strcmp(const POS &pos, Item *a, Item *b)
Definition: item_cmpfunc.h:1338
longlong val_int() override
Definition: item_cmpfunc.cc:2717
enum Functype functype() const override
Definition: item_cmpfunc.h:1343
optimize_type select_optimize(const THD *) override
Definition: item_cmpfunc.h:1341
Definition: item_cmpfunc.h:811
bool fix_fields(THD *thd, Item **ref) override
Definition: item_cmpfunc.h:875
enum_trig_type
Definition: item_cmpfunc.h:813
@ FOUND_MATCH
This trigger type deactivates predicated from WHERE condition when no row satisfying the join conditi...
Definition: item_cmpfunc.h:828
@ IS_NOT_NULL_COMPL
This trigger type deactivates join conditions when a row has been NULL-complemented.
Definition: item_cmpfunc.h:819
@ 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:837
const char * func_name() const override
'<if>', to distinguish from the if() SQL function
Definition: item_cmpfunc.h:870
void add_trig_func_tables()
Definition: item_cmpfunc.h:880
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item_cmpfunc.h:889
enum enum_trig_type get_trig_type() const
Definition: item_cmpfunc.h:899
bool contains_only_equi_join_condition() const override
Whether this Item is an equi-join condition.
Definition: item_cmpfunc.cc:7481
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:7151
Item_func_trig_cond(Item *a, bool *f, const JOIN *join, plan_idx idx, enum_trig_type trig_type_arg)
Definition: item_cmpfunc.h:860
table_map get_inner_tables() const
Get table_map of inner tables spanned by associated outer join operation.
Definition: item_cmpfunc.cc:7172
const JOIN * get_join() const
Definition: item_cmpfunc.h:898
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item_cmpfunc.cc:7192
bool * get_trig_var()
Definition: item_cmpfunc.h:900
plan_idx idx() const
Definition: item_cmpfunc.h:904
plan_idx m_idx
Optional: if join!=NULL: index of table.
Definition: item_cmpfunc.h:846
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Fix after tables have been moved from one query_block level to the parent level, e....
Definition: item_cmpfunc.h:893
longlong val_int() override
Definition: item_cmpfunc.cc:7137
enum_trig_type trig_type
Type of trig_var; for printing.
Definition: item_cmpfunc.h:848
enum Functype functype() const override
Definition: item_cmpfunc.h:868
bool * trig_var
Pointer to trigger variable.
Definition: item_cmpfunc.h:842
enum_trig_type get_trig_type()
Definition: item_cmpfunc.h:901
const JOIN * m_join
Optional: JOIN of table which is the source of trig_var.
Definition: item_cmpfunc.h:844
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:401
Bool_test truth_test
The value we're testing for.
Definition: item_cmpfunc.h:460
Item_bool_func super
Definition: item_cmpfunc.h:402
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:444
enum Functype functype() const override
Definition: item_cmpfunc.h:416
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:418
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:409
Item_func_truth(Item *a, Bool_test truth_test)
Definition: item_cmpfunc.h:431
const char * func_name() const override
Definition: item_cmpfunc.h:413
XOR inherits from Item_bool_func2 because it is not optimized yet.
Definition: item_cmpfunc.h:708
Item_bool_func2 super
Definition: item_cmpfunc.h:709
const char * func_name() const override
Definition: item_cmpfunc.h:717
longlong val_int() override
Make a logical XOR of the arguments.
Definition: item_cmpfunc.cc:6551
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:6513
bool itemize(Parse_context *pc, Item **res) override
The same as contextualize() but with additional parameter.
Definition: item_cmpfunc.cc:6498
enum Functype functype() const override
Definition: item_cmpfunc.h:716
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:720
Item_func_xor(const POS &pos, Item *i1, Item *i2)
Definition: item_cmpfunc.h:713
Item_func_xor(Item *i1, Item *i2)
Definition: item_cmpfunc.h:712
Item * truth_transformer(THD *, Bool_test) override
XOR can be negated by negating one of the operands:
Definition: item_cmpfunc.cc:6610
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:221
@ NOT_ALL_FUNC
Definition: item_func.h:218
@ LIKE_FUNC
Definition: item_func.h:189
@ FALSE_FUNC
Definition: item_func.h:298
@ NULLIF_FUNC
Definition: item_func.h:260
@ 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:297
@ 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:259
@ STRCMP_FUNC
Definition: item_func.h:296
@ 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:261
@ COALESCE_FUNC
Definition: item_func.h:290
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:300
@ OPTIMIZE_NONE
Definition: item_func.h:301
@ OPTIMIZE_EQUAL
Definition: item_func.h:305
@ OPTIMIZE_NULL
Definition: item_func.h:304
@ OPTIMIZE_KEY
Definition: item_func.h:302
@ OPTIMIZE_OP
Definition: item_func.h:303
bool resolve_type(THD *thd) override
Resolve type-related information for this item, such as result field type, maximum size,...
Definition: item_func.h:620
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
void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block) override
Fix after tables have been moved from one query_block level to the parent level, e....
Definition: item_func.cc:448
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:3761
Definition: item_cmpfunc.h:485
Item * transform(Item_transformer transformer, uchar *arg) override
Transform an Item_in_optimizer and its arguments with a callback function.
Definition: item_cmpfunc.cc:2387
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item_cmpfunc.cc:2368
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:2429
void keep_top_level_cache()
Item_cache * cache
Definition: item_cmpfunc.h:487
const char * func_name() const override
Definition: item_cmpfunc.h:510
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:496