MySQL 26.7.0
Source Code Documentation
item.h
Go to the documentation of this file.
1#ifndef ITEM_INCLUDED
2#define ITEM_INCLUDED
3
4/* Copyright (c) 2000, 2026, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <sys/types.h>
28
29#include <cassert>
30#include <cfloat>
31#include <climits>
32#include <cmath>
33#include <cstdio>
34#include <cstring>
35#include <memory>
36#include <new>
37#include <optional>
38#include <string>
39#include <type_traits>
40#include <vector>
41
42#include "decimal.h"
43#include "field_types.h" // enum_field_types
44#include "lex_string.h"
45#include "memory_debugging.h"
46#include "my_alloc.h"
47#include "my_bitmap.h"
48#include "my_compiler.h"
49#include "my_dbug.h"
50#include "my_double2ulonglong.h"
51#include "my_inttypes.h"
52#include "my_sys.h"
53#include "my_table_map.h"
54#include "my_temporal.h"
55#include "my_time.h"
56#include "mysql/strings/dtoa.h"
60#include "mysql_com.h"
61#include "mysql_time.h"
62#include "mysqld_error.h"
63#include "nulls.h"
64#include "sql-common/my_decimal.h" // my_decimal
65#include "sql/auth/auth_acls.h" // Access_bitmask
66#include "sql/enum_query_type.h"
67#include "sql/field.h" // Derivation
68#include "sql/mem_root_array.h"
69#include "sql/parse_location.h" // POS
70#include "sql/parse_tree_node_base.h" // Parse_tree_node
71#include "sql/sql_array.h" // Bounds_checked_array
72#include "sql/sql_const.h"
73#include "sql/sql_list.h"
74#include "sql/table.h"
75#include "sql/table_trigger_field_support.h" // Table_trigger_field_support
76#include "sql/thr_malloc.h"
77#include "sql/trigger_def.h" // enum_trigger_variable_type
78#include "sql_string.h"
79#include "string_with_len.h"
80#include "template_utils.h"
81
82class Item;
83class Item_cache;
85class Item_field;
86class Item_func;
87class Item_multi_eq;
89class Item_sum;
90class Json_wrapper;
91class Protocol;
92class Query_block;
94class sp_head;
95class sp_rcontext;
96class THD;
97class user_var_entry;
98struct COND_EQUAL;
99struct TYPELIB;
100
102
103void item_init(void); /* Init item functions */
104
105/**
106 Default condition filtering (selectivity) values used by
107 get_filtering_effect() and friends when better estimates
108 (statistics) are not available for a predicate.
109*/
110/**
111 For predicates that are always satisfied. Must be 1.0 or the filter
112 calculation logic will break down.
113*/
114constexpr float COND_FILTER_ALLPASS{1.0f};
115/// Filtering effect for equalities: col1 = col2
116constexpr float COND_FILTER_EQUALITY{0.1f};
117/// Filtering effect for inequalities: col1 > col2
118constexpr float COND_FILTER_INEQUALITY{0.3333f};
119/// Filtering effect for between: col1 BETWEEN a AND b
120constexpr float COND_FILTER_BETWEEN{0.1111f};
121/**
122 Value is out-of-date, will need recalculation.
123 This is used by post-greedy-search logic which changes the access method and
124 thus makes obsolete the filtering value calculated by best_access_path(). For
125 example, test_if_skip_sort_order().
126*/
127constexpr float COND_FILTER_STALE{-1.0f};
128/**
129 A special subcase of the above:
130 - if this is table/index/range scan, and
131 - rows_fetched is how many rows we will examine, and
132 - rows_fetched is less than the number of rows in the table (as determined
133 by test_if_cheaper_ordering() and test_if_skip_sort_order()).
134 Unlike the ordinary case where rows_fetched:
135 - is set by calculate_scan_cost(), and
136 - is how many rows pass the constant condition (so, less than we will
137 examine), and
138 - the actual rows_fetched to show in EXPLAIN is the number of rows in the
139 table (== rows which we will examine), and
140 - the constant condition's effect has to be moved to filter_effect for
141 EXPLAIN.
142*/
143constexpr float COND_FILTER_STALE_NO_CONST{-2.0f};
144
145static inline uint32 char_to_byte_length_safe(uint32 char_length_arg,
146 uint32 mbmaxlen_arg) {
147 const ulonglong tmp = ((ulonglong)char_length_arg) * mbmaxlen_arg;
148 return (tmp > UINT_MAX32) ? (uint32)UINT_MAX32 : (uint32)tmp;
149}
150
152 Item_result result_type,
153 uint8 decimals) {
154 if (is_temporal_type(real_type_to_type(data_type)))
155 return decimals ? DECIMAL_RESULT : INT_RESULT;
156 if (result_type == STRING_RESULT) return REAL_RESULT;
157 return result_type;
158}
159
160/*
161 "Declared Type Collation"
162 A combination of collation and its derivation.
163
164 Flags for collation aggregation modes:
165 MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
166 MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
167 (i.e. constant).
168 MY_COLL_ALLOW_NUMERIC_CONV - if all items were numbers, convert to
169 @@character_set_connection
170 MY_COLL_ALLOW_NONE - allow return DERIVATION_NONE
171 (e.g. when aggregating for string result)
172 MY_COLL_CMP_CONV - for comparison: Allow SUPERSET and COERCIBLE
173 conversion, disallow NONE.
174*/
175
176#define MY_COLL_ALLOW_SUPERSET_CONV 1
177#define MY_COLL_ALLOW_COERCIBLE_CONV 2
178#define MY_COLL_ALLOW_NONE 4
179#define MY_COLL_ALLOW_NUMERIC_CONV 8
180
181#define MY_COLL_CMP_CONV \
182 (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
183
185 public:
189
193 }
198 }
199 DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg) {
200 collation = collation_arg;
201 derivation = derivation_arg;
202 set_repertoire_from_charset(collation_arg);
203 }
204 void set(const DTCollation &dt) {
205 collation = dt.collation;
208 }
209 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg) {
210 collation = collation_arg;
211 derivation = derivation_arg;
212 set_repertoire_from_charset(collation_arg);
213 }
214 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg,
215 uint repertoire_arg) {
216 collation = collation_arg;
217 derivation = derivation_arg;
218 repertoire = repertoire_arg;
219 }
220 void set_numeric() {
224 }
225 void set(const CHARSET_INFO *collation_arg) {
226 collation = collation_arg;
227 set_repertoire_from_charset(collation_arg);
228 }
229 void set(Derivation derivation_arg) { derivation = derivation_arg; }
230 void set_repertoire(uint repertoire_arg) { repertoire = repertoire_arg; }
231 bool aggregate(DTCollation &dt, uint flags = 0);
232 bool set(DTCollation &dt1, DTCollation &dt2, uint flags = 0) {
233 set(dt1);
234 return aggregate(dt2, flags);
235 }
236 const char *derivation_name() const {
237 switch (derivation) {
239 return "NUMERIC";
240 case DERIVATION_NULL:
241 return "NULL";
243 return "COERCIBLE";
245 return "IMPLICIT";
247 return "SYSCONST";
249 return "EXPLICIT";
250 case DERIVATION_NONE:
251 return "NONE";
252 default:
253 return "UNKNOWN";
254 }
255 }
256};
257
258/**
259 Class used as argument to Item::walk() together with mark_field_in_map()
260*/
262 public:
265
266 /**
267 If == NULL, update map of any table.
268 If <> NULL, update map of only this table.
269 */
270 TABLE *const table;
271 /// How to mark the map.
273};
274
275/**
276 Class used as argument to Item::walk() together with used_tables_for_level()
277*/
279 public:
281
282 Query_block *const select; ///< Level for which data is accumulated
283 table_map used_tables; ///< Accumulated used tables data
284};
285
286/*************************************************************************/
287
288/**
289 Storage for name strings.
290 Enpowers Simple_cstring with allocation routines from the sql_strmake family.
291
292 This class must stay as small as possible as we often
293 pass it into functions using call-by-value evaluation.
294
295 Don't add new members or virtual methods into this class!
296*/
298 private:
299 void set_or_copy(const char *str, size_t length, bool is_null_terminated) {
300 if (is_null_terminated)
301 set(str, length);
302 else
303 copy(str, length);
304 }
305
306 public:
308 /*
309 Please do NOT add constructor Name_string(const char *str) !
310 It will involve hidden strlen() call, which can affect
311 performance negatively. Use Name_string(str, len) instead.
312 */
313 Name_string(const char *str, size_t length) : Simple_cstring(str, length) {}
316 Name_string(const char *str, size_t length, bool is_null_terminated)
317 : Simple_cstring() {
318 set_or_copy(str, length, is_null_terminated);
319 }
320 Name_string(const LEX_STRING str, bool is_null_terminated)
321 : Simple_cstring() {
322 set_or_copy(str.str, str.length, is_null_terminated);
323 }
324 /**
325 Allocate space using sql_strmake() or sql_strmake_with_convert().
326 */
327 void copy(const char *str, size_t length, const CHARSET_INFO *cs);
328 /**
329 Variants for copy(), for various argument combinations.
330 */
331 void copy(const char *str, size_t length) {
333 }
334 void copy(const char *str) {
335 copy(str, (str ? strlen(str) : 0), system_charset_info);
336 }
337 void copy(const LEX_STRING lex) { copy(lex.str, lex.length); }
338 void copy(const LEX_STRING *lex) { copy(lex->str, lex->length); }
339 void copy(const Name_string str) { copy(str.ptr(), str.length()); }
340 /**
341 Compare name to another name in C string, case insensitively.
342 */
343 bool eq(const char *str) const {
344 assert(str && ptr());
345 return my_strcasecmp(system_charset_info, ptr(), str) == 0;
346 }
347 bool eq_safe(const char *str) const { return is_set() && str && eq(str); }
348 /**
349 Compare name to another name in Name_string, case insensitively.
350 */
351 bool eq(const Name_string name) const { return eq(name.ptr()); }
352 bool eq_safe(const Name_string name) const {
353 return is_set() && name.is_set() && eq(name);
354 }
355};
356
357#define NAME_STRING(x) Name_string(STRING_WITH_LEN(x))
358
359/**
360 Max length of an Item string for its use in an error message.
361 This should be kept in sync with MYSQL_ERRMSG_SIZE (which should
362 not be exceeded).
363*/
364#define ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT (300)
365
366extern const Name_string null_name_string;
367
368/**
369 Storage for Item names.
370 Adds "autogenerated" flag and warning functionality to Name_string.
371*/
373 private:
374 bool m_is_autogenerated; /* indicates if name of this Item
375 was autogenerated or set by user */
376 public:
380 /**
381 Set m_is_autogenerated flag to the given value.
382 */
385 }
386 /**
387 Return the auto-generated flag.
388 */
389 bool is_autogenerated() const { return m_is_autogenerated; }
390 using Name_string::copy;
391 /**
392 Copy name together with autogenerated flag.
393 Produce a warning if name was cut.
394 */
395 void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg,
396 bool is_autogenerated_arg);
397};
398
399/**
400 Instances of Name_resolution_context store the information necessary for
401 name resolution of Items and other context analysis of a query made in
402 fix_fields().
403
404 This structure is a part of Query_block, a pointer to this structure is
405 assigned when an item is created (which happens mostly during parsing
406 (sql_yacc.yy)), but the structure itself will be initialized after parsing
407 is complete
408
409 @todo move subquery of INSERT ... SELECT and CREATE ... SELECT to
410 separate Query_block which allow to remove tricks of changing this
411 structure before and after INSERT/CREATE and its SELECT to make correct
412 field name resolution.
413*/
415 /**
416 The name resolution context to search in when an Item cannot be
417 resolved in this context (the context of an outer select)
418 */
420 /// Link to next name res context with the same query block as the base
422
423 /**
424 List of tables used to resolve the items of this context. Usually these
425 are tables from the FROM clause of SELECT statement. The exceptions are
426 INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
427 subquery is not moved to a separate Query_block. For these types of
428 statements we have to change this member dynamically to ensure correct
429 name resolution of different parts of the statement.
430 */
432 /**
433 In most cases the two table references below replace 'table_list' above
434 for the purpose of name resolution. The first and last name resolution
435 table references allow us to search only in a sub-tree of the nested
436 join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
437 and JOIN ... ON.
438 */
440 /**
441 Last table to search in the list of leaf table references that begins
442 with first_name_resolution_table.
443 */
445
446 /**
447 Query_block item belong to, in case of merged VIEW it can differ from
448 Query_block where item was created, so we can't use table_list/field_list
449 from there
450 */
452
453 /*
454 Processor of errors caused during Item name resolving, now used only to
455 hide underlying tables in errors about views (i.e. it substitute some
456 errors for views)
457 */
460
461 /**
462 When true, items are resolved in this context against
463 Query_block::item_list, SELECT_lex::group_list and
464 this->table_list. If false, items are resolved only against
465 this->table_list.
466
467 @see Query_block::item_list, Query_block::group_list
468 */
470
471 /**
472 Security context of this name resolution context. It's used for views
473 and is non-zero only if the view is defined with SQL SECURITY DEFINER.
474 */
476
480 }
481};
482
483/**
484 Struct used to pass around arguments to/from
485 check_function_as_value_generator
486*/
490 : err_code(default_error_code), source(val_gen_src) {}
491 /// the order of the column in table
492 int col_index{-1};
493 /// the error code found during check(if any)
495 /*
496 If it is a generated column, default expression or check constraint
497 expression value generator.
498 */
500 /// the name of the function which is not allowed
501 const char *banned_function_name{nullptr};
502
503 /// Return the correct error code, based on whether or not if we are checking
504 /// for disallowed functions in generated column expressions, in default
505 /// value expressions or in check constraint expression.
507 return ((source == VGS_GENERATED_COLUMN)
508 ? ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
510 ? ER_DEFAULT_VAL_GENERATED_FUNCTION_IS_NOT_ALLOWED
511 : ER_CHECK_CONSTRAINT_FUNCTION_IS_NOT_ALLOWED);
512 }
513};
514/*
515 Store and restore the current state of a name resolution context.
516*/
517
519 private:
525
526 public:
527 /* Save the state of a name resolution context. */
528 void save_state(Name_resolution_context *context, Table_ref *table_list) {
529 save_table_list = context->table_list;
532 save_next_local = table_list->next_local;
534 }
535
536 /* Restore a name resolution context from saved state. */
537 void restore_state(Name_resolution_context *context, Table_ref *table_list) {
538 table_list->next_local = save_next_local;
540 context->table_list = save_table_list;
543 }
544
545 void update_next_local(Table_ref *table_list) {
546 save_next_local = table_list;
547 }
548
551 }
552};
553
554/*
555 This enum is used to report information about monotonicity of function
556 represented by Item* tree.
557 Monotonicity is defined only for Item* trees that represent table
558 partitioning expressions (i.e. have no subqueries/user vars/dynamic parameters
559 etc etc). An Item* tree is assumed to have the same monotonicity properties
560 as its corresponding function F:
561
562 [signed] longlong F(field1, field2, ...) {
563 put values of field_i into table record buffer;
564 return item->val_int();
565 }
566
567 NOTE
568 At the moment function monotonicity is not well defined (and so may be
569 incorrect) for Item trees with parameters/return types that are different
570 from INT_RESULT, may be NULL, or are unsigned.
571 It will be possible to address this issue once the related partitioning bugs
572 (BUG#16002, BUG#15447, BUG#13436) are fixed.
573
574 The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns
575 NULL which puts those rows into the NULL partition, but
576 '2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed
577 for this (see Bug#20577).
578*/
579
580typedef enum monotonicity_info {
581 NON_MONOTONIC, /* none of the below holds */
582 MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
583 MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */
584 MONOTONIC_STRICT_INCREASING, /* F() is unary and (x < y) => (F(x) < F(y)) */
585 MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */
587
588/**
589 A type for SQL-like 3-valued Booleans: true/false/unknown.
590*/
591class Bool3 {
592 public:
593 /// @returns an instance set to "FALSE"
594 static const Bool3 false3() { return Bool3(v_FALSE); }
595 /// @returns an instance set to "UNKNOWN"
596 static const Bool3 unknown3() { return Bool3(v_UNKNOWN); }
597 /// @returns an instance set to "TRUE"
598 static const Bool3 true3() { return Bool3(v_TRUE); }
599
600 bool is_true() const { return m_val == v_TRUE; }
601 bool is_unknown() const { return m_val == v_UNKNOWN; }
602 bool is_false() const { return m_val == v_FALSE; }
603
604 private:
606 /// This is private; instead, use false3()/etc.
607 Bool3(value v) : m_val(v) {}
608
610 /*
611 No operator to convert Bool3 to bool (or int) - intentionally: how
612 would you map unknown3 to true/false?
613 It is because we want to block such conversions that Bool3 is a class
614 instead of a plain enum.
615 */
616};
617
618/**
619 Type properties, used to collect type information for later assignment
620 to an Item object. The object stores attributes signedness, max length
621 and collation. However, precision and scale (for decimal numbers) and
622 fractional second precision (for time and datetime) are not stored,
623 since any type derived from this object will have default values for these
624 attributes.
625*/
627 public:
628 /// Constructor for any signed numeric type or date type
629 /// Defaults are provided for attributes like signedness and max length
631 : m_type(type_arg),
632 m_unsigned_flag(false),
633 m_max_length(0),
635 assert(type_arg != MYSQL_TYPE_VARCHAR && type_arg != MYSQL_TYPE_JSON);
636 }
637 /// Constructor for any numeric type, with explicit signedness
638 Type_properties(enum_field_types type_arg, bool unsigned_arg)
639 : m_type(type_arg),
640 m_unsigned_flag(unsigned_arg),
641 m_max_length(0),
643 assert(is_numeric_type(type_arg) || type_arg == MYSQL_TYPE_BIT ||
644 type_arg == MYSQL_TYPE_YEAR);
645 }
646 /// Constructor for character type, with explicit character set.
647 /// Default length/max length is provided.
649 : m_type(type_arg),
650 m_unsigned_flag(false),
651 m_max_length(0),
653 /// Constructor for Item
654 Type_properties(Item &item);
656 const bool m_unsigned_flag;
659};
660
661/*************************************************************************/
662
664 public:
666 virtual ~Settable_routine_parameter() = default;
667 /**
668 Set required privileges for accessing the parameter.
669
670 @param privilege The required privileges for this field, with the
671 following alternatives:
672 MODE_IN - SELECT_ACL
673 MODE_OUT - UPDATE_ACL
674 MODE_INOUT - SELECT_ACL | UPDATE_ACL
675 */
677 [[maybe_unused]]) {}
678
679 /*
680 Set parameter value.
681
682 SYNOPSIS
683 set_value()
684 thd thread handle
685 ctx context to which parameter belongs (if it is local
686 variable).
687 it item which represents new value
688
689 RETURN
690 false if parameter value has been set,
691 true if error has occurred.
692 */
693 virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it) = 0;
694
695 virtual void set_out_param_info(Send_field *info [[maybe_unused]]) {}
696
697 virtual const Send_field *get_out_param_info() const { return nullptr; }
698};
699
700/*
701 Analyzer function
702 SYNOPSIS
703 argp in/out IN: Analysis parameter
704 OUT: Parameter to be passed to the transformer
705
706 RETURN
707 true Invoke the transformer
708 false Don't do it
709
710*/
711typedef bool (Item::*Item_analyzer)(uchar **argp);
712
713/**
714 Type for transformers used by Item::transform and Item::compile
715 @param arg Argument used by the transformer. Really a typeless pointer
716 in spite of the uchar type (historical reasons). The
717 transformer needs to cast this to the desired pointer type
718 @returns The transformed item
719*/
720typedef Item *(Item::*Item_transformer)(uchar *arg);
721typedef void (*Cond_traverser)(const Item *item, void *arg);
722
723/**
724 Utility mixin class to be able to walk() only parts of item trees.
725
726 Used with PREFIX+POSTFIX walk: in the prefix call of the Item
727 processor, we process the item X, may decide that its children should not
728 be processed (just like if they didn't exist): processor calls stop_at(X)
729 for that. Then walk() goes to a child Y; the processor tests is_stopped(Y)
730 which returns true, so processor sees that it must not do any processing
731 and returns immediately. Finally, the postfix call to the processor on X
732 tests is_stopped(X) which returns "true" and understands that the
733 not-to-be-processed children have been skipped so calls restart(). Thus,
734 any sibling of X, any part of the Item tree not under X, can then be
735 processed.
736*/
738 protected:
743
744 /// Stops walking children of this item
745 void stop_at(const Item *i) {
746 assert(stopped_at_item == nullptr);
747 stopped_at_item = i;
748 }
749
750 /**
751 @returns if we are stopped. If item 'i' is where we stopped, restarts the
752 walk for next items.
753 */
754 bool is_stopped(const Item *i) {
755 if (stopped_at_item != nullptr) {
756 /*
757 Walking was disabled for a tree part rooted a one ancestor of 'i' or
758 rooted at 'i'.
759 */
760 if (stopped_at_item == i) {
761 /*
762 Walking was disabled for the tree part rooted at 'i'; we have now just
763 returned back to this root (POSTFIX call), left the tree part:
764 enable the walk again, for other tree parts.
765 */
766 stopped_at_item = nullptr;
767 }
768 // No further processing to do for this item:
769 return true;
770 }
771 return false;
772 }
773
774 private:
775 const Item *stopped_at_item{nullptr};
776};
777
778/// Increment *num if it is less than its maximal value.
779template <typename T>
780void SafeIncrement(T *num) {
781 if (*num < std::numeric_limits<T>::max()) {
782 *num += 1;
783 }
784}
785
786/**
787 This class represents the cost of evaluating an Item. @see SortPredicates
788 to see how this is used.
789*/
790class CostOfItem final {
791 public:
792 /// Set '*this' to represent the cost of 'item'.
793 void Compute(const Item &item) {
794 if (!m_computed) {
795 ComputeInternal(item);
796 }
797 }
798
800 assert(!m_computed);
801 m_is_expensive = true;
802 }
803
804 /// Add the cost of accessing a Field_str.
806 assert(!m_computed);
808 }
809
810 /// Add the cost of accessing any other Field.
812 assert(!m_computed);
814 }
815
816 bool IsExpensive() const {
817 assert(m_computed);
818 return m_is_expensive;
819 }
820
821 /**
822 Get the cost of field access when evaluating the Item associated with this
823 object. The cost unit is arbitrary, but the relative cost of different
824 items reflect the fact that operating on Field_str is more expensive than
825 other Field subclasses.
826 */
827 double FieldCost() const {
828 assert(m_computed);
830 }
831
832 private:
833 /// The cost of accessing a Field_str, relative to other Field types.
834 /// (The value was determined using benchmarks.)
835 static constexpr double kStrFieldCost = 1.8;
836
837 /// The cost of accessing a Field other than Field_str. 1.0 by definition.
838 static constexpr double kOtherFieldCost = 1.0;
839
840 /// True if 'ComputeInternal()' has been called.
841 bool m_computed{false};
842
843 /// True if the associated Item calls user defined functions or stored
844 /// procedures.
845 bool m_is_expensive{false};
846
847 /// The number of Field_str objects accessed by the associated Item.
849
850 /// The number of other Field objects accessed by the associated Item.
852
853 /// Compute the cost of 'root' and its descendants.
854 void ComputeInternal(const Item &root);
855};
856
857/**
858 This class represents a subquery contained in some subclass of
859 Item_subselect, @see FindContainedSubqueries().
860*/
862 /// The strategy for executing the subquery.
863 enum class Strategy : char {
864 /**
865 An independent subquery that is materialized, e.g.:
866 "SELECT * FROM tab WHERE field IN <independent subquery>".
867 where 'independent subquery' does not depend on any fields in 'tab'.
868 (This corresponds to the Item_in_subselect class.)
869 */
871
872 /**
873 A subquery that is reevaluated for each row, e.g.:
874 "SELECT * FROM tab WHERE field IN <dependent subquery>" or
875 "SELECT * FROM tab WHERE field = <dependent subquery>".
876 where 'dependent subquery' depends on at least one field in 'tab'.
877 Alternatively, the subquery may be independent of 'tab', but contain
878 a non-deterministic function such as 'rand()'. Such subqueries are also
879 required to be reevaluated for each row.
880 */
882
883 /**
884 An independent single-row subquery that is evaluated once, e.g.:
885 "SELECT * FROM tab WHERE field = <independent single-row subquery>".
886 (This corresponds to the Item_singlerow_subselect class.)
887 */
889 };
890
891 /// The root path of the subquery.
893
894 /// The strategy for executing the subquery.
896
897 /// The width (in bytes) of the subquery's rows. For variable-sized values we
898 /// use Item.max_length (but cap it at kMaxItemLengthEstimate).
899 /// @see kMaxItemLengthEstimate and
900 /// @see Item_in_subselect::get_contained_subquery().
902};
903
904/**
905 Base class that is used to represent any kind of expression in a
906 relational query. The class provides subclasses for simple components, like
907 literal (constant) values, column references and variable references,
908 as well as more complex expressions like comparison predicates,
909 arithmetic and string functions, row objects, function references and
910 subqueries.
911
912 The lifetime of an Item class object is often the same as a relational
913 statement, which may be used for several executions, but in some cases
914 it may also be generated for an optimized statement and thus be valid
915 only for one execution.
916
917 For Item objects with longer lifespan than one execution, we must take
918 special precautions when referencing objects with shorter lifespan.
919 For example, TABLE and Field objects against most tables are valid only for
920 one execution. For such objects, Item classes should rather reference
921 Table_ref and Item_field objects instead of TABLE and Field, because
922 these classes support dynamic rebinding of objects before each execution.
923 See Item::bind_fields() which binds new objects per execution and
924 Item::cleanup() that deletes references to such objects.
925
926 These mechanisms can also be used to handle other objects with shorter
927 lifespan, such as function references and variable references.
928*/
929class Item : public Parse_tree_node {
931
932 friend class udf_handler;
933
934 protected:
935 /**
936 Sets the result value of the function an empty string, using the current
937 character set. No memory is allocated.
938 @retval A pointer to the str_value member.
939 */
942 return &str_value;
943 }
944
945 public:
946 Item(const Item &) = delete;
947 void operator=(Item &) = delete;
948 static void *operator new(size_t size) noexcept {
949 return (*THR_MALLOC)->Alloc(size);
950 }
951 static void *operator new(size_t size, MEM_ROOT *mem_root,
952 const std::nothrow_t &arg
953 [[maybe_unused]] = std::nothrow) noexcept {
954 return mem_root->Alloc(size);
955 }
956
957 static void operator delete(void *ptr [[maybe_unused]],
958 size_t size [[maybe_unused]]) {
959 TRASH(ptr, size);
960 }
961 static void operator delete(void *, MEM_ROOT *,
962 const std::nothrow_t &) noexcept {}
963
964 enum Type {
966 FIELD_ITEM, ///< A reference to a field (column) in a table.
967 FUNC_ITEM, ///< A function call reference.
968 SUM_FUNC_ITEM, ///< A grouped aggregate function, or window function.
969 AGGR_FIELD_ITEM, ///< A special field for certain aggregate operations.
970 STRING_ITEM, ///< A string literal value.
971 INT_ITEM, ///< An integer literal value.
972 DECIMAL_ITEM, ///< A decimal literal value.
973 REAL_ITEM, ///< A floating-point literal value.
974 JSON_ITEM, ///< A JSON literal value.
975 NULL_ITEM, ///< A NULL value.
976 HEX_BIN_ITEM, ///< A hexadecimal or binary literal value.
977 DEFAULT_VALUE_ITEM, ///< A default value for a column.
978 COND_ITEM, ///< An AND or OR condition.
979 REF_ITEM, ///< An indirect reference to another item.
980 INSERT_VALUE_ITEM, ///< A value from a VALUES function (deprecated).
981 SUBQUERY_ITEM, ///< A subquery or predicate referencing a subquery.
982 ROW_ITEM, ///< A row of other items.
983 CACHE_ITEM, ///< An internal item used to cache values.
984 TYPE_HOLDER_ITEM, ///< An internal item used to help aggregate a type.
985 PARAM_ITEM, ///< A dynamic parameter used in a prepared statement.
986 ROUTINE_FIELD_ITEM, ///< A variable inside a routine (proc, func, trigger)
987 TRIGGER_FIELD_ITEM, ///< An OLD or NEW field, used in trigger definitions.
988 XPATH_NODESET_ITEM, ///< Used in XPATH expressions.
989 VALUES_COLUMN_ITEM, ///< A value from a VALUES clause.
990 NAME_CONST_ITEM ///< A NAME_CONST expression
991 };
992
994
996
997 /// How to cache constant JSON data
999 /// Don't cache
1001 /// Source data is a JSON string, parse and cache result
1003 /// Source data is SQL scalar, convert and cache result
1006
1007 enum Bool_test ///< Modifier for result transformation
1008 {
1019 };
1020
1021 // Return the default data type for a given result type
1023 switch (result) {
1024 case INT_RESULT:
1025 return MYSQL_TYPE_LONGLONG;
1026 case DECIMAL_RESULT:
1027 return MYSQL_TYPE_NEWDECIMAL;
1028 case REAL_RESULT:
1029 return MYSQL_TYPE_DOUBLE;
1030 case STRING_RESULT:
1031 return MYSQL_TYPE_VARCHAR;
1032 case INVALID_RESULT:
1033 return MYSQL_TYPE_INVALID;
1034 case ROW_RESULT:
1035 default:
1036 assert(false);
1037 }
1038 return MYSQL_TYPE_INVALID;
1039 }
1040
1041 // Return the default result type for a given data type
1043 switch (type) {
1044 case MYSQL_TYPE_TINY:
1045 case MYSQL_TYPE_SHORT:
1046 case MYSQL_TYPE_INT24:
1047 case MYSQL_TYPE_LONG:
1049 case MYSQL_TYPE_BOOL:
1050 case MYSQL_TYPE_BIT:
1051 case MYSQL_TYPE_YEAR:
1052 return INT_RESULT;
1054 case MYSQL_TYPE_DECIMAL:
1055 return DECIMAL_RESULT;
1056 case MYSQL_TYPE_FLOAT:
1057 case MYSQL_TYPE_DOUBLE:
1058 return REAL_RESULT;
1059 case MYSQL_TYPE_VARCHAR:
1061 case MYSQL_TYPE_STRING:
1065 case MYSQL_TYPE_BLOB:
1066 case MYSQL_TYPE_VECTOR:
1068 case MYSQL_TYPE_JSON:
1069 case MYSQL_TYPE_ENUM:
1070 case MYSQL_TYPE_SET:
1071 return STRING_RESULT;
1073 case MYSQL_TYPE_DATE:
1074 case MYSQL_TYPE_TIME:
1076 case MYSQL_TYPE_NEWDATE:
1079 case MYSQL_TYPE_TIME2:
1080 return STRING_RESULT;
1081 case MYSQL_TYPE_INVALID:
1082 return INVALID_RESULT;
1083 case MYSQL_TYPE_NULL:
1084 return STRING_RESULT;
1086 break;
1087 }
1088 assert(false);
1089 return INVALID_RESULT;
1090 }
1091
1092 /**
1093 Provide data type for a user or system variable, based on the type of
1094 the item that is assigned to the variable.
1095
1096 @note MYSQL_TYPE_VARCHAR is returned for all string types, but must be
1097 further adjusted based on maximum string length by the caller.
1098
1099 @param src_type Source type that variable's type is derived from
1100 */
1102 switch (src_type) {
1103 case MYSQL_TYPE_BOOL:
1104 case MYSQL_TYPE_TINY:
1105 case MYSQL_TYPE_SHORT:
1106 case MYSQL_TYPE_INT24:
1107 case MYSQL_TYPE_LONG:
1109 case MYSQL_TYPE_BIT:
1110 return MYSQL_TYPE_LONGLONG;
1111 case MYSQL_TYPE_DECIMAL:
1113 return MYSQL_TYPE_NEWDECIMAL;
1114 case MYSQL_TYPE_FLOAT:
1115 case MYSQL_TYPE_DOUBLE:
1116 return MYSQL_TYPE_DOUBLE;
1117 case MYSQL_TYPE_VARCHAR:
1119 case MYSQL_TYPE_STRING:
1120 return MYSQL_TYPE_VARCHAR;
1121 case MYSQL_TYPE_YEAR:
1122 return MYSQL_TYPE_LONGLONG;
1124 case MYSQL_TYPE_DATE:
1125 case MYSQL_TYPE_TIME:
1127 case MYSQL_TYPE_NEWDATE:
1130 case MYSQL_TYPE_TIME2:
1131 case MYSQL_TYPE_JSON:
1132 case MYSQL_TYPE_ENUM:
1133 case MYSQL_TYPE_SET:
1135 case MYSQL_TYPE_NULL:
1137 case MYSQL_TYPE_BLOB:
1138 case MYSQL_TYPE_VECTOR:
1141 return MYSQL_TYPE_VARCHAR;
1142 case MYSQL_TYPE_INVALID:
1144 return MYSQL_TYPE_INVALID;
1145 }
1146 assert(false);
1147 return MYSQL_TYPE_NULL;
1148 }
1149
1150 /// Item constructor for general use.
1151 Item();
1152
1153 /**
1154 Constructor used by Item_field, Item_ref & aggregate functions.
1155 Used for duplicating lists in processing queries with temporary tables.
1156
1157 Also used for Item_cond_and/Item_cond_or for creating top AND/OR structure
1158 of WHERE clause to protect it of optimisation changes in prepared statements
1159 */
1160 Item(THD *thd, const Item *item);
1161
1162 /**
1163 Parse-time context-independent constructor.
1164
1165 This constructor and caller constructors of child classes must not
1166 access/change thd->lex (including thd->lex->current_query_block(),
1167 thd->m_parser_state etc structures).
1168
1169 If we need to finalize the construction of the object, then we move
1170 all context-sensitive code to the itemize() virtual function.
1171
1172 The POS parameter marks this constructor and other context-independent
1173 constructors of child classes for easy recognition/separation from other
1174 (context-dependent) constructors.
1175 */
1176 explicit Item(const POS &);
1177
1178#ifdef EXTRA_DEBUG
1179 ~Item() override { item_name.set(0); }
1180#else
1181 ~Item() override = default;
1182#endif
1183
1184 private:
1185 /*
1186 Hide the contextualize*() functions: call/override the itemize()
1187 in Item class tree instead.
1188 */
1190 assert(0);
1191 return true;
1192 }
1193
1194 protected:
1195 /**
1196 Helper function to skip itemize() for grammar-allocated items
1197
1198 @param [out] res pointer to "this"
1199
1200 @retval true can skip itemize()
1201 @retval false can't skip: the item is allocated directly by the parser
1202 */
1203 bool skip_itemize(Item **res) {
1204 *res = this;
1205 return !is_parser_item;
1206 }
1207
1208 /*
1209 Checks if the function should return binary result based on the items
1210 provided as parameter.
1211 Function should only be used by Item_bit_func*
1212
1213 @param a item to check
1214 @param b item to check, may be nullptr
1215
1216 @returns true if binary result.
1217 */
1218 static bool bit_func_returns_binary(const Item *a, const Item *b);
1219
1220 /**
1221 The core function that does the actual itemization. itemize() is just a
1222 wrapper over this.
1223 */
1224 virtual bool do_itemize(Parse_context *pc, Item **res);
1225
1226 public:
1227 /**
1228 The same as contextualize() but with additional parameter
1229
1230 This function finalize the construction of Item objects (see the Item(POS)
1231 constructor): we can access/change parser contexts from the itemize()
1232 function.
1233
1234 Derived classes should not override this. If needed, they should
1235 override do_itemize().
1236
1237 @param pc current parse context
1238 @param [out] res pointer to "this" or to a newly allocated
1239 replacement object to use in the Item tree instead
1240
1241 @retval false success
1242 @retval true syntax/OOM/etc error
1243 */
1244 // Visual Studio with MSVC_CPPCHECK=ON gives warning C26435:
1245 // Function <fun> should specify exactly one of
1246 // 'virtual', 'override', or 'final'
1249 virtual bool itemize(Parse_context *pc, Item **res) final {
1250 // For condition#2 below ... If position is empty, this item was not
1251 // created in the parser; so don't show it in the parse tree.
1252 if (pc->m_show_parse_tree == nullptr || this->m_pos.is_empty())
1253 return do_itemize(pc, res);
1254
1255 Show_parse_tree *tree = pc->m_show_parse_tree.get();
1256
1257 if (begin_parse_tree(tree)) return true;
1258
1259 if (do_itemize(pc, res)) return true;
1260
1261 if (end_parse_tree(tree)) return true;
1262
1263 return false;
1264 }
1266
1267 void rename(char *new_name);
1268 void init_make_field(Send_field *tmp_field, enum enum_field_types type);
1269 /**
1270 Called for every Item after use (preparation and execution).
1271 Release all allocated resources, such as dynamic memory.
1272 Prepare for new execution by clearing cached values.
1273 Do not remove values allocated during preparation, destructor handles this.
1274 */
1275 virtual void cleanup() { marker = MARKER_NONE; }
1276 /**
1277 Called when an item has been removed, can be used to notify external
1278 objects about the removal, e.g subquery predicates that are part of
1279 the sj_candidates container.
1280 */
1281 virtual void notify_removal() {}
1282 virtual void make_field(Send_field *field);
1283 virtual Field *make_string_field(TABLE *table) const;
1284 virtual bool fix_fields(THD *, Item **);
1285 /**
1286 Fix after tables have been moved from one query_block level to the parent
1287 level, e.g by semijoin conversion.
1288 Basically re-calculate all attributes dependent on the tables.
1289
1290 @param parent_query_block query_block that tables are moved to.
1291 @param removed_query_block query_block that tables are moved away from,
1292 child of parent_query_block.
1293 */
1294 virtual void fix_after_pullout(Query_block *parent_query_block
1295 [[maybe_unused]],
1296 Query_block *removed_query_block
1297 [[maybe_unused]]) {}
1298 /*
1299 should be used in case where we are sure that we do not need
1300 complete fix_fields() procedure.
1301 */
1302 inline void quick_fix_field() { fixed = true; }
1303 virtual void set_can_use_prefix_key() {}
1304
1305 /**
1306 Propagate data type specifications into parameters and user variables.
1307 If item has descendants, propagate type recursively into these.
1308
1309 @param thd thread handler
1310 @param type Data type properties that are propagated
1311
1312 @returns false if success, true if error
1313 */
1314 virtual bool propagate_type(THD *thd [[maybe_unused]],
1315 const Type_properties &type [[maybe_unused]]) {
1316 return false;
1317 }
1318
1319 /**
1320 Wrapper for easier calling of propagate_type(const Type_properties &).
1321 @param thd thread handler
1322 @param def type to make Type_properties object
1323 @param pin if true: also mark the type as pinned
1324 @param inherit if true: also mark the type as inherited
1325
1326 @returns false if success, true if error
1327 */
1329 bool pin = false, bool inherit = false) {
1330 /*
1331 Propagate supplied type if types have not yet been assigned to expression,
1332 or type is pinned, in which case the supplied type overrides the
1333 actual type of parameters. Note we do not support "pinning" of
1334 expressions containing parameters, only standalone parameters,
1335 but this is a very minor problem.
1336 */
1337 if (data_type() != MYSQL_TYPE_INVALID && !(pin && type() == PARAM_ITEM))
1338 return false;
1339 if (propagate_type(thd, (def == MYSQL_TYPE_VARCHAR)
1341 : (def == MYSQL_TYPE_JSON)
1343 : Type_properties(def)))
1344 return true;
1345 if (pin) pin_data_type();
1346 if (inherit) set_data_type_inherited();
1347
1348 return false;
1349 }
1350
1351 /**
1352 For Items with data type JSON, mark that a string argument is treated
1353 as a scalar JSON value. Only relevant for the Item_param class.
1354 */
1355 virtual void mark_json_as_scalar() {}
1356
1357 /**
1358 If this item represents a IN/ALL/ANY/comparison_operator
1359 subquery, return that (along with data on how it will be executed).
1360 (These subqueries correspond to
1361 @see Item_in_subselect and @see Item_singlerow_subselect .) Also,
1362 @see FindContainedSubqueries() for context.
1363 @param outer_query_block the Query_block to which 'this' belongs.
1364 @returns The subquery that 'this' represents, if there is one.
1365 */
1366 virtual std::optional<ContainedSubquery> get_contained_subquery(
1367 const Query_block *outer_query_block [[maybe_unused]]) {
1368 return std::nullopt;
1369 }
1370
1371 protected:
1372 /**
1373 Helper function which does all of the work for
1374 save_in_field(Field*, bool), except some error checking common to
1375 all subclasses, which is performed by save_in_field() itself.
1376
1377 Subclasses that need to specialize the behaviour of
1378 save_in_field(), should override this function instead of
1379 save_in_field().
1380
1381 @param[in,out] field the field to save the item into
1382 @param no_conversions whether or not to allow conversions of the value
1383
1384 @return the status from saving into the field
1385 @retval TYPE_OK item saved without any errors or warnings
1386 @retval != TYPE_OK there were errors or warnings when saving the item
1387 */
1389 bool no_conversions);
1390
1391 public:
1392 /**
1393 Save the item into a field but do not emit any warnings.
1394
1395 @param field field to save the item into
1396 @param no_conversions whether or not to allow conversions of the value
1397
1398 @return the status from saving into the field
1399 @retval TYPE_OK item saved without any issues
1400 @retval != TYPE_OK there were issues saving the item
1401 */
1403 bool no_conversions);
1404 /**
1405 Save a temporal value in packed longlong format into a Field.
1406 Used in optimizer.
1407
1408 Subclasses that need to specialize this function, should override
1409 save_in_field_inner().
1410
1411 @param[in,out] field the field to save the item into
1412 @param no_conversions whether or not to allow conversions of the value
1413
1414 @return the status from saving into the field
1415 @retval TYPE_OK item saved without any errors or warnings
1416 @retval != TYPE_OK there were errors or warnings when saving the item
1417 */
1418 type_conversion_status save_in_field(Field *field, bool no_conversions);
1419
1420 /**
1421 A slightly faster value of save_in_field() that returns no error value
1422 (you will need to check thd->is_error() yourself), and does not support
1423 saving into hidden fields for functional indexes. Used by copy_funcs(),
1424 to avoid the functional call overhead and RAII setup of save_in_field().
1425 */
1426 void save_in_field_no_error_check(Field *field, bool no_conversions) {
1427 assert(!field->is_field_for_functional_index());
1428 save_in_field_inner(field, no_conversions);
1429 }
1430
1431 virtual void save_org_in_field(Field *field) { save_in_field(field, true); }
1432
1433 virtual bool send(Protocol *protocol, String *str);
1434 bool evaluate(THD *thd, String *str);
1435 /**
1436 Compare this item with another item for equality.
1437 If both pointers are the same, the items are equal.
1438 Both items must be of same type.
1439 For literal values, metadata must be the same and the values must be equal.
1440 Strings are compared with the embedded collation.
1441 For column references, table references and column names must be the same.
1442 For functions, the function type, function properties and arguments must
1443 be equal. Otherwise, see specific implementations.
1444 @todo: Current implementation requires that cache objects, ref objects
1445 and rollup wrappers are stripped away. This should be eliminated.
1446 */
1447 virtual bool eq(const Item *) const;
1448
1449 const Item *unwrap_for_eq() const;
1450
1451 virtual Item_result result_type() const { return REAL_RESULT; }
1452 /**
1453 Result type when an item appear in a numeric context.
1454 See Field::numeric_context_result_type() for more comments.
1455 */
1458 }
1459 /**
1460 Similar to result_type() but makes DATE, DATETIME, TIMESTAMP
1461 pretend to be numbers rather than strings.
1462 */
1465 : result_type();
1466 }
1467
1468 /**
1469 Set data type for item as inherited.
1470 Non-empty implementation only for dynamic parameters.
1471 */
1472 virtual void set_data_type_inherited() {}
1473
1474 /**
1475 Pin the data type for the item.
1476 Non-empty implementation only for dynamic parameters.
1477 */
1478 virtual void pin_data_type() {}
1479
1480 /// Retrieve the derived data type of the Item.
1482 return static_cast<enum_field_types>(m_data_type);
1483 }
1484
1485 /**
1486 Retrieve actual data type for an item. Equal to data_type() for
1487 all items, except parameters.
1488 */
1489 virtual enum_field_types actual_data_type() const { return data_type(); }
1490
1491 /**
1492 Get the default data (output) type for the specific item.
1493 Important for some SQL functions that may deliver multiple result types,
1494 and is used to determine data type for function's parameters that cannot
1495 be type-resolved by looking at the context.
1496 An example of such function is '+', which may return INT, DECIMAL,
1497 DOUBLE, depending on arguments.
1498 On the contrary, many other functions have a fixed output type, usually
1499 set with set_data_type_XXX(), which overrides the value of
1500 default_data_type(). For example, COS always returns DOUBLE,
1501 */
1503 // If data type has been set, the information returned here is irrelevant:
1504 assert(data_type() == MYSQL_TYPE_INVALID);
1505 return MYSQL_TYPE_VARCHAR;
1506 }
1507 /**
1508 Set the data type of the current Item. It is however recommended to
1509 use one of the type-specific setters if possible.
1510
1511 @param data_type The data type of this Item.
1512 */
1514 m_data_type = static_cast<uint8>(data_type);
1515 }
1516
1517 inline void set_data_type_null() {
1520 max_length = 0;
1521 set_nullable(true);
1522 }
1523
1524 inline void set_data_type_bool() {
1527 decimals = 0;
1528 max_length = 1;
1529 }
1530
1531 /**
1532 Set the data type of the Item to be a specific integer type
1533
1534 @param type Integer type
1535 @param unsigned_prop Whether the integer is signed or not
1536 @param max_width Maximum width of field in number of digits
1537 */
1538 inline void set_data_type_int(enum_field_types type, bool unsigned_prop,
1539 uint32 max_width) {
1540 assert(type == MYSQL_TYPE_TINY || type == MYSQL_TYPE_SHORT ||
1545 unsigned_flag = unsigned_prop;
1546 decimals = 0;
1547 fix_char_length(max_width);
1548 }
1549
1550 /**
1551 Set the data type of the Item to be longlong.
1552 Maximum display width is set to be the maximum of a 64-bit integer,
1553 but it may be adjusted later. The unsigned property is not affected.
1554 */
1558 decimals = 0;
1559 fix_char_length(21);
1560 }
1561
1562 /**
1563 Set the data type of the Item to be decimal.
1564 The unsigned property must have been set before calling this function.
1565
1566 @param precision Number of digits of precision
1567 @param scale Number of digits after decimal point.
1568 */
1569 inline void set_data_type_decimal(uint8 precision, uint8 scale) {
1572 assert(precision <= DECIMAL_MAX_PRECISION);
1573 decimals = scale;
1575 precision, scale, unsigned_flag));
1576 }
1577
1578 /// Set the data type of the Item to be double precision floating point.
1579 inline void set_data_type_double() {
1584 }
1585
1586 /// Set the data type of the Item to be single precision floating point.
1587 inline void set_data_type_float() {
1592 }
1593
1594 /**
1595 Set the Item to be variable length string. Actual type is determined from
1596 maximum string size. Collation must have been set before calling function.
1597
1598 @param max_l Maximum number of characters in string
1599 */
1600 inline void set_data_type_string(uint32 max_l) {
1607 else
1609 }
1610
1611 /**
1612 Set the Item to be variable length string. Like function above, but with
1613 larger string length precision.
1614
1615 @param max_char_length_arg Maximum number of characters in string
1616 */
1617 inline void set_data_type_string(ulonglong max_char_length_arg) {
1618 ulonglong max_result_length =
1619 max_char_length_arg * collation.collation->mbmaxlen;
1620 if (max_result_length > MAX_BLOB_WIDTH) {
1621 max_result_length = MAX_BLOB_WIDTH;
1622 m_nullable = true;
1623 }
1625 uint32(max_result_length / collation.collation->mbmaxlen));
1626 }
1627
1628 /**
1629 Set the Item to be variable length string. Like function above, but will
1630 also set character set and collation.
1631
1632 @param max_l Maximum number of characters in string
1633 @param cs Pointer to character set and collation struct
1634 */
1635 inline void set_data_type_string(uint32 max_l, const CHARSET_INFO *cs) {
1637 set_data_type_string(max_l);
1638 }
1639
1640 /**
1641 Set the Item to be variable length string. Like function above, but will
1642 also set full collation information.
1643
1644 @param max_l Maximum number of characters in string
1645 @param coll Ref to collation data, including derivation and repertoire
1646 */
1647 inline void set_data_type_string(uint32 max_l, const DTCollation &coll) {
1648 collation.set(coll);
1649 set_data_type_string(max_l);
1650 }
1651
1652 /**
1653 Set the Item to be fixed length string. Collation must have been set
1654 before calling function.
1655
1656 @param max_l Number of characters in string
1657 */
1658 inline void set_data_type_char(uint32 max_l) {
1659 assert(max_l <= MAX_CHAR_WIDTH);
1663 }
1664
1665 /**
1666 Set the Item to be fixed length string. Like function above, but will
1667 also set character set and collation.
1668
1669 @param max_l Maximum number of characters in string
1670 @param cs Pointer to character set and collation struct
1671 */
1672 inline void set_data_type_char(uint32 max_l, const CHARSET_INFO *cs) {
1674 set_data_type_char(max_l);
1675 }
1676
1677 /**
1678 Set the Item to be of BLOB type.
1679
1680 @param type Actual blob data type
1681 @param max_l Maximum number of characters in data type
1682 */
1687 ulonglong max_width = max_l * collation.collation->mbmaxlen;
1688 if (max_width > Field::MAX_LONG_BLOB_WIDTH) {
1689 max_width = Field::MAX_LONG_BLOB_WIDTH;
1690 }
1691 max_length = max_width;
1693 }
1694
1695 /// Set all type properties for Item of DATE type.
1696 inline void set_data_type_date() {
1699 decimals = 0;
1701 }
1702
1703 /**
1704 Set all type properties for Item of TIME type.
1705
1706 @param fsp Fractional seconds precision
1707 */
1708 inline void set_data_type_time(uint8 fsp) {
1709 assert(fsp <= DATETIME_MAX_DECIMALS);
1712 decimals = fsp;
1713 max_length = MAX_TIME_WIDTH + fsp + (fsp > 0 ? 1 : 0);
1714 }
1715
1716 /**
1717 Set all properties for Item of DATETIME type.
1718
1719 @param fsp Fractional seconds precision
1720 */
1722 assert(fsp <= DATETIME_MAX_DECIMALS);
1725 decimals = fsp;
1726 max_length = MAX_DATETIME_WIDTH + fsp + (fsp > 0 ? 1 : 0);
1727 }
1728
1729 /**
1730 Set all properties for Item of TIMESTAMP type.
1731
1732 @param fsp Fractional seconds precision
1733 */
1735 assert(fsp <= DATETIME_MAX_DECIMALS);
1738 decimals = fsp;
1739 max_length = MAX_DATETIME_WIDTH + fsp + (fsp > 0 ? 1 : 0);
1740 }
1741
1742 /**
1743 Set the data type of the Item to be VECTOR.
1744 */
1749 max_length = max_l;
1750 }
1751
1752 /**
1753 Set the data type of the Item to be GEOMETRY.
1754 */
1760 }
1761 /**
1762 Set the data type of the Item to be JSON.
1763 */
1769 }
1770
1771 /**
1772 Set the data type of the Item to be YEAR.
1773 */
1777 decimals = 0;
1778 fix_char_length(4); // YYYY
1779 unsigned_flag = true;
1780 }
1781
1782 /**
1783 Set the data type of the Item to be bit.
1784
1785 @param max_bits Maximum number of bits to store in this field.
1786 */
1787 void set_data_type_bit(uint32 max_bits) {
1790 max_length = max_bits;
1791 unsigned_flag = true;
1792 }
1793
1794 /**
1795 Set data type properties of the item from the properties of another item.
1796
1797 @param item Item to set data type properties from.
1798 */
1799 inline void set_data_type_from_item(const Item *item) {
1800 set_data_type(item->data_type());
1801 collation = item->collation;
1802 max_length = item->max_length;
1803 decimals = item->decimals;
1805 }
1806
1807 /**
1808 Determine correct string field type, based on string length
1809
1810 @param max_bytes Maximum string size, in number of bytes
1811 */
1813 if (max_bytes > Field::MAX_MEDIUM_BLOB_WIDTH)
1814 return MYSQL_TYPE_LONG_BLOB;
1815 else if (max_bytes > Field::MAX_VARCHAR_WIDTH)
1817 else
1818 return MYSQL_TYPE_VARCHAR;
1819 }
1820
1821 /// Get the typelib information for an item of type set or enum
1822 virtual TYPELIB *get_typelib() const { return nullptr; }
1823
1824 virtual Item_result cast_to_int_type() const { return result_type(); }
1825 virtual enum Type type() const = 0;
1826
1827 bool aggregate_type(const char *name, Item **items, uint count);
1828
1829 /*
1830 Return information about function monotonicity. See comment for
1831 enum_monotonicity_info for details. This function can only be called
1832 after fix_fields() call.
1833 */
1835 return NON_MONOTONIC;
1836 }
1837
1838 /*
1839 Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$
1840 const2"
1841
1842 SYNOPSIS
1843 val_int_endpoint()
1844 left_endp false <=> The interval is "x < const" or "x <= const"
1845 true <=> The interval is "x > const" or "x >= const"
1846
1847 incl_endp IN false <=> the comparison is '<' or '>'
1848 true <=> the comparison is '<=' or '>='
1849 OUT The same but for the "F(x) $CMP$ F(const)" comparison
1850
1851 DESCRIPTION
1852 This function is defined only for unary monotonic functions. The caller
1853 supplies the source half-interval
1854
1855 x $CMP$ const
1856
1857 The value of const is supplied implicitly as the value of this item's
1858 argument, the form of $CMP$ comparison is specified through the
1859 function's arguments. The call returns the result interval
1860
1861 F(x) $CMP2$ F(const)
1862
1863 passing back F(const) as the return value, and the form of $CMP2$
1864 through the out parameter. NULL values are assumed to be comparable and
1865 be less than any non-NULL values.
1866
1867 RETURN
1868 The output range bound, which equal to the value of val_int()
1869 - If the value of the function is NULL then the bound is the
1870 smallest possible value of LLONG_MIN
1871 */
1872 virtual longlong val_int_endpoint(bool left_endp [[maybe_unused]],
1873 bool *incl_endp [[maybe_unused]]) {
1874 assert(0);
1875 return 0;
1876 }
1877
1878 /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
1879 /*
1880 Return double precision floating point representation of item.
1881
1882 SYNOPSIS
1883 val_real()
1884
1885 RETURN
1886 In case of NULL value return 0.0 and set null_value flag to true.
1887 If value is not null null_value flag will be reset to false.
1888 */
1889 virtual double val_real() = 0;
1890 /*
1891 Return integer representation of item.
1892
1893 SYNOPSIS
1894 val_int()
1895
1896 RETURN
1897 In case of NULL value return 0 and set null_value flag to true.
1898 If value is not null null_value flag will be reset to false.
1899 */
1900 virtual longlong val_int() = 0;
1901 /**
1902 Return date value of item in packed longlong format.
1903 */
1904 virtual longlong val_date_temporal();
1905
1906 /**
1907 Produces a key suitable for filesort. Most of the time, val_int() would
1908 suffice, but for temporal values, the packed value (as sent to the handler)
1909 is called for. It is also necessary that the value is in UTC. This function
1910 supplies just that.
1911
1912 @return A sort key value.
1913 */
1915 if (data_type() == MYSQL_TYPE_TIME) {
1916 Time_val time;
1917 if (val_time(&time)) return 0;
1918 return time.for_comparison();
1919 } else if (data_type() == MYSQL_TYPE_DATE) {
1920 Date_val date;
1921 if (val_date(&date, 0)) return 0;
1922 return date.for_comparison();
1923 } else if (is_temporal_with_date()) {
1924 return val_date_temporal_at_utc();
1925 } else {
1926 return val_int();
1927 }
1928 }
1929
1930 /**
1931 Get date or time value in packed longlong format.
1932 Before conversion from MYSQL_TIME to packed format,
1933 the MYSQL_TIME value is rounded to "dec" fractional digits.
1934 */
1936
1937 /*
1938 This is just a shortcut to avoid the cast. You should still use
1939 unsigned_flag to check the sign of the item.
1940 */
1941 inline ulonglong val_uint() { return (ulonglong)val_int(); }
1942 /*
1943 Return string representation of this item object.
1944
1945 SYNOPSIS
1946 val_str()
1947 str an allocated buffer this or any nested Item object can use to
1948 store return value of this method.
1949
1950 NOTE
1951 Buffer passed via argument should only be used if the item itself
1952 doesn't have an own String buffer. In case when the item maintains
1953 it's own string buffer, it's preferable to return it instead to
1954 minimize number of mallocs/memcpys.
1955 The caller of this method can modify returned string, but only in case
1956 when it was allocated on heap, (is_alloced() is true). This allows
1957 the caller to efficiently use a buffer allocated by a child without
1958 having to allocate a buffer of it's own. The buffer, given to
1959 val_str() as argument, belongs to the caller and is later used by the
1960 caller at it's own choosing.
1961 A few implications from the above:
1962 - unless you return a string object which only points to your buffer
1963 but doesn't manages it you should be ready that it will be
1964 modified.
1965 - even for not allocated strings (is_alloced() == false) the caller
1966 can change charset (see Item_func_{typecast/binary}. XXX: is this
1967 a bug?
1968 - still you should try to minimize data copying and return internal
1969 object whenever possible.
1970
1971 RETURN
1972 In case of NULL value or error, return error_str() as this function will
1973 check if the return value may be null, and it will either set null_value
1974 to true and return nullptr or to false and it will return empty string.
1975 If value is not null set null_value flag to false before returning it.
1976 */
1977 virtual String *val_str(String *str) = 0;
1978
1979 /*
1980 Returns string representation of this item in ASCII format.
1981
1982 SYNOPSIS
1983 val_str_ascii()
1984 str - similar to val_str();
1985
1986 NOTE
1987 This method is introduced for performance optimization purposes.
1988
1989 1. val_str() result of some Items in string context
1990 depends on @@character_set_results.
1991 @@character_set_results can be set to a "real multibyte" character
1992 set like UCS2, UTF16, UTF32. (We'll use only UTF32 in the examples
1993 below for convenience.)
1994
1995 So the default string result of such functions
1996 in these circumstances is real multi-byte character set, like UTF32.
1997
1998 For example, all numbers in string context
1999 return result in @@character_set_results:
2000
2001 SELECT CONCAT(20010101); -> UTF32
2002
2003 We do sprintf() first (to get ASCII representation)
2004 and then convert to UTF32;
2005
2006 So these kind "data sources" can use ASCII representation
2007 internally, but return multi-byte data only because
2008 @@character_set_results wants so.
2009 Therefore, conversion from ASCII to UTF32 is applied internally.
2010
2011
2012 2. Some other functions need in fact ASCII input.
2013
2014 For example,
2015 inet_aton(), GeometryFromText(), Convert_TZ(), GET_FORMAT().
2016
2017 Similar, fields of certain type, like DATE, TIME,
2018 when you insert string data into them, expect in fact ASCII input.
2019 If they get non-ASCII input, for example UTF32, they
2020 convert input from UTF32 to ASCII, and then use ASCII
2021 representation to do further processing.
2022
2023
2024 3. Now imagine we pass result of a data source of the first type
2025 to a data destination of the second type.
2026
2027 What happens:
2028 a. data source converts data from ASCII to UTF32, because
2029 @@character_set_results wants so and passes the result to
2030 data destination.
2031 b. data destination gets UTF32 string.
2032 c. data destination converts UTF32 string to ASCII,
2033 because it needs ASCII representation to be able to handle data
2034 correctly.
2035
2036 As a result we get two steps of unnecessary conversion:
2037 From ASCII to UTF32, then from UTF32 to ASCII.
2038
2039 A better way to handle these situations is to pass ASCII
2040 representation directly from the source to the destination.
2041
2042 This is why val_str_ascii() introduced.
2043
2044 RETURN
2045 Similar to val_str()
2046 */
2047 virtual String *val_str_ascii(String *str);
2048
2049 /**
2050 Evaluate item and return result as a decimal value.
2051
2052 @param decimal_buffer buffer which can be used by Item for returning value
2053 (but need not be)
2054
2055 @note
2056 Returned value should not be changed if it is not the same as the one
2057 passed via argument.
2058
2059 @note Example implementation for Item with two arguments:
2060
2061 my_decimal *Item_func_<x>::decimal_op(my_decimal *decimal_value) {
2062 assert(fixed);
2063 my_decimal value1, value2;
2064 null_value = false; // Initialize null_value
2065 // First, process the first argument completely
2066 my_decimal *val1 = args[0]->val_decimal(&value1);
2067 if (val1 == nullptr) { // Handle error or NULL value
2068 null_value = args[0]->null_value; // Propagate NULL value
2069 return nullptr;
2070 }
2071 // Next, process the second argument completely
2072 my_decimal *val2 = args[1]->val_decimal(&value2);
2073 if (val2 == nullptr) { // Handle error or NULL value
2074 null_value = args[1]->null_value; // Propagate NULL value
2075 return nullptr;
2076 }
2077 // Evaluate result into decimal_value, possibly set nullptr or error
2078 if (evaluate(val1, val2) {
2079 return nullptr;
2080 }
2081 return decimal_value; // Return non-NULL result
2082 }
2083
2084 @note Example implementation that converts from other data type
2085
2086 my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value) {
2087 Date_val date;
2088 if (val_date(&date, 0)) { // Evaluate date, possibly with error or NULL
2089 return nullptr; // No NULL value propagation necessary here
2090 }
2091 if (date_to_decimal(date, decimal_value) == nullptr) {
2092 return nullptr; // In case conversion caused an error
2093 }
2094 return decimal_value;
2095 }
2096
2097 @returns pointer to my_decimal value if evaluation was successful
2098 nullptr is returned if evaluation ended in error, or a NULL value
2099 was generated. Unless error is returned, null_value indicates
2100 whether NULL value is returned or not.
2101 */
2102 virtual my_decimal *val_decimal(my_decimal *decimal_buffer) = 0;
2103 /*
2104 Return boolean value of item.
2105
2106 RETURN
2107 false value is false or NULL
2108 true value is true (not equal to 0)
2109 */
2110 virtual bool val_bool();
2111
2112 /**
2113 Get a JSON value from an Item.
2114
2115 All subclasses that can return a JSON value, should override this
2116 function. The function in the base class is not expected to be
2117 called. If it is called, it most likely means that some subclass
2118 is missing an override of val_json().
2119
2120 @param[in,out] result The resulting Json_wrapper.
2121
2122 @return false if successful, true on failure
2123 */
2124 /* purecov: begin deadcode */
2125 virtual bool val_json(Json_wrapper *result [[maybe_unused]]) {
2126 assert(false);
2127 my_error(ER_NOT_SUPPORTED_YET, MYF(0), "item type for JSON");
2128 return error_json();
2129 }
2130 /* purecov: end */
2131
2132 /**
2133 Calculate the filter contribution that is relevant for table
2134 'filter_for_table' for this item.
2135
2136 @param thd Thread handler
2137 @param filter_for_table The table we are calculating filter effect for
2138 @param read_tables Tables earlier in the join sequence.
2139 Predicates for table 'filter_for_table' that
2140 rely on values from these tables can be part of
2141 the filter effect.
2142 @param fields_to_ignore Fields in 'filter_for_table' that should not
2143 be part of the filter calculation. The filtering
2144 effect of these fields is already part of the
2145 calculation somehow (e.g. because there is a
2146 predicate "col = <const>", and the optimizer
2147 has decided to do ref access on 'col').
2148 @param rows_in_table The number of rows in table 'filter_for_table'
2149
2150 @return the filtering effect (between 0 and 1) this
2151 Item contributes with.
2152 */
2153 virtual float get_filtering_effect(THD *thd [[maybe_unused]],
2154 table_map filter_for_table
2155 [[maybe_unused]],
2156 table_map read_tables [[maybe_unused]],
2157 const MY_BITMAP *fields_to_ignore
2158 [[maybe_unused]],
2159 double rows_in_table [[maybe_unused]]) {
2160 // Filtering effect cannot be calculated for a table already read.
2161 assert((read_tables & filter_for_table) == 0);
2162 return COND_FILTER_ALLPASS;
2163 }
2164
2165 /**
2166 Get the value to return from val_json() in case of errors.
2167
2168 @see Item::error_bool
2169
2170 @return The value val_json() should return, which is true.
2171 */
2172 bool error_json() {
2174 return true;
2175 }
2176
2177 /**
2178 Convert a non-temporal type to date
2179 */
2181
2182 /**
2183 Convert a non-temporal type to time
2184 */
2186 /**
2187 Convert a non-temporal type to datetime
2188 */
2190
2191 protected:
2192 /* Helper functions, see item_sum.cc */
2210 double val_real_from_decimal();
2211 double val_real_from_string();
2212
2213 /**
2214 Get the value to return from val_bool() in case of errors.
2215
2216 This function is called from val_bool() when an error has occurred
2217 and we need to return something to abort evaluation of the
2218 item. The expected pattern in val_bool() is
2219
2220 if (@<error condition@>)
2221 {
2222 my_error(...)
2223 return error_bool();
2224 }
2225
2226 @return The value val_bool() should return.
2227 */
2228 bool error_bool() {
2230 return false;
2231 }
2232
2233 /**
2234 Get the value to return from val_int() in case of errors.
2235
2236 @see Item::error_bool
2237
2238 @return The value val_int() should return.
2239 */
2242 return 0;
2243 }
2244
2245 /**
2246 Get the value to return from val_real() in case of errors.
2247
2248 @see Item::error_bool
2249
2250 @return The value val_real() should return.
2251 */
2252 double error_real() {
2254 return 0.0;
2255 }
2256
2257 /**
2258 Get the value to return from val_date() in case of errors.
2259
2260 @see Item::error_bool
2261
2262 @return The true: the function failed.
2263 */
2264 bool error_date() {
2266 return true;
2267 }
2268
2269 /**
2270 Get the value to return from val_time() in case of errors.
2271
2272 @see Item::error_bool
2273
2274 @return The true: the function failed.
2275 */
2276 bool error_time() {
2278 return true;
2279 }
2280
2281 public:
2282 /**
2283 Get the value to return from val_str() in case of error or NULL value.
2284
2285 @see Item::error_bool
2286
2287 @return The value val_str() should return.
2288 */
2292 }
2293
2294 protected:
2295 /**
2296 Gets the value to return from val_str() when returning a NULL value.
2297 @return The value val_str() should return.
2298 */
2300 assert(m_nullable);
2301 null_value = true;
2302 return nullptr;
2303 }
2304
2305 /**
2306 Convert val_str() to date
2307 */
2309 /**
2310 Convert val_real() to date
2311 */
2313 /**
2314 Convert val_decimal() to date
2315 */
2317 /**
2318 Convert val_int() to date
2319 */
2321 /**
2322 Convert val_time() to date
2323 */
2324 bool get_date_from_time(Date_val *date);
2325 /**
2326 Convert val_datetime() to date
2327 */
2329 /**
2330 Convert a numeric type to date
2331 */
2333
2334 /**
2335 Convert val_str() to datetime
2336 */
2338 /**
2339 Convert val_real() to datetime
2340 */
2342 /**
2343 Convert val_decimal() to datetime
2344 */
2346 /**
2347 Convert val_int() to datetime
2348 */
2350 /**
2351 Convert val_time() to datetime
2352 */
2354 /**
2355 Convert val_date() to datetime
2356 */
2358
2359 /**
2360 Convert a numeric type to datetime
2361 */
2363
2364 /**
2365 Convert val_str() to time
2366 */
2367 bool get_time_from_string(Time_val *time);
2368 /**
2369 Convert val_real() to time
2370 */
2371 bool get_time_from_real(Time_val *time);
2372 /**
2373 Convert val_decimal() to time
2374 */
2375 bool get_time_from_decimal(Time_val *time);
2376 /**
2377 Convert val_int() to time
2378 */
2379 bool get_time_from_int(Time_val *time);
2380 /**
2381 Convert date to time
2382 */
2383 bool get_time_from_date(Time_val *time);
2384 /**
2385 Convert datetime to time
2386 */
2387 bool get_time_from_datetime(Time_val *time);
2388
2389 /**
2390 Convert a numeric type to time
2391 */
2392 bool get_time_from_numeric(Time_val *time);
2393
2395
2396 public:
2401
2402 /**
2403 If this Item is being materialized into a temporary table, returns the
2404 field that is being materialized into. (Typically, this is the
2405 “result_field” members for items that have one.)
2406 */
2408 DBUG_TRACE;
2409 return nullptr;
2410 }
2411 /* This is also used to create fields in CREATE ... SELECT: */
2412 virtual Field *tmp_table_field(TABLE *) { return nullptr; }
2413 virtual const char *full_name() const {
2414 return item_name.is_set() ? item_name.ptr() : "???";
2415 }
2416
2417 /* bit map of tables used by item */
2418 virtual table_map used_tables() const { return (table_map)0L; }
2419
2420 /**
2421 Return table map of tables that can't be NULL tables (tables that are
2422 used in a context where if they would contain a NULL row generated
2423 by a LEFT or RIGHT join, the item would not be true).
2424 This expression is used on WHERE item to determinate if a LEFT JOIN can be
2425 converted to a normal join.
2426 Generally this function should return used_tables() if the function
2427 would return null if any of the arguments are null
2428 As this is only used in the beginning of optimization, the value don't
2429 have to be updated in update_used_tables()
2430 */
2431 virtual table_map not_null_tables() const { return used_tables(); }
2432
2433 /**
2434 Returns true if this is a simple constant item like an integer, not
2435 a constant expression. Used in the optimizer to propagate basic constants.
2436 It is assumed that val_xxx() does not modify the item's state for
2437 such items. It is also assumed that val_str() can be called with nullptr
2438 as argument as val_str() will return an internally cached const string.
2439 */
2440 virtual bool basic_const_item() const { return false; }
2441 /**
2442 @returns true when a const item may be evaluated during resolving.
2443 Only const items that are basic const items are evaluated when
2444 resolving CREATE VIEW statements. For other statements, all
2445 const items may be evaluated during resolving.
2446 */
2447 bool may_eval_const_item(const THD *thd) const;
2448 /**
2449 @return cloned item if it is constant
2450 @retval nullptr if this is not const
2451 */
2452 virtual Item *clone_item() const { return nullptr; }
2453 virtual cond_result eq_cmp_result() const { return COND_OK; }
2454 inline uint float_length(uint decimals_par) const {
2455 return decimals != DECIMAL_NOT_SPECIFIED ? (DBL_DIG + 2 + decimals_par)
2456 : DBL_DIG + 8;
2457 }
2458 virtual uint decimal_precision() const;
2459 inline int decimal_int_part() const {
2461 }
2462 /**
2463 TIME precision of the item: 0..6
2464 */
2465 virtual uint time_precision();
2466 /**
2467 DATETIME precision of the item: 0..6
2468 */
2469 virtual uint datetime_precision();
2470 /**
2471 Returns true if item is constant, regardless of query evaluation state.
2472 An expression is constant if it:
2473 - refers no tables.
2474 - refers no subqueries that refers any tables.
2475 - refers no non-deterministic functions.
2476 - refers no statement parameters.
2477 - contains no group expression under rollup
2478 */
2479 bool const_item() const { return (used_tables() == 0); }
2480 /**
2481 Returns true if item is constant during one query execution.
2482 If const_for_execution() is true but const_item() is false, value is
2483 not available before tables have been locked and parameters have been
2484 assigned values. This applies to
2485 - statement parameters
2486 - non-dependent subqueries
2487 - deterministic stored functions that contain SQL code.
2488 For items where the default implementation of used_tables() and
2489 const_item() are effective, const_item() will always return true.
2490 */
2491 bool const_for_execution() const {
2492 return !(used_tables() & ~INNER_TABLE_BIT);
2493 }
2494
2495 /**
2496 Return true if this is a const item that may be evaluated in
2497 the current phase of statement processing.
2498 - No evaluation is performed when analyzing a view, otherwise:
2499 - Items that have the const_item() property can always be evaluated.
2500 - Items that have the const_for_execution() property can be evaluated when
2501 tables are locked (ie during optimization or execution).
2502
2503 This function should be used in the following circumstances:
2504 - during preparation to check whether an item can be permanently transformed
2505 - to check that an item is constant in functions that may be used in both
2506 the preparation and optimization phases.
2507
2508 This function should not be used by code that is called during optimization
2509 and/or execution only. Use const_for_execution() in this case.
2510 */
2511 bool may_evaluate_const(const THD *thd) const;
2512
2513 /**
2514 @returns true if this item is non-deterministic, which means that a
2515 has a component that must be evaluated once per row in
2516 execution of a JOIN query.
2517 */
2519
2520 /**
2521 @returns true if this item is an outer reference, usually this means that
2522 it references a column that contained in a table located in
2523 the FROM clause of an outer query block.
2524 */
2525 bool is_outer_reference() const {
2527 }
2528
2529 /**
2530 This method is used for to:
2531 - to generate a view definition query (SELECT-statement);
2532 - to generate a SQL-query for EXPLAIN EXTENDED;
2533 - to generate a SQL-query to be shown in INFORMATION_SCHEMA;
2534 - to generate a SQL-query that looks like a prepared statement for
2535 query_rewrite
2536 - debug.
2537
2538 For more information about view definition query, INFORMATION_SCHEMA
2539 query and why they should be generated from the Item-tree, @see
2540 mysql_register_view().
2541 */
2542 virtual void print(const THD *, String *str, enum_query_type) const {
2543 str->append(full_name());
2544 }
2545
2546 /**
2547 Generate hash unique to an item depending on its attributes. When overriding
2548 this function, care must be taken to properly handle and fix possible hash
2549 collisions, either due to missing attributes or other reasons.
2550
2551 If a unique hash cannot be generated for the Item (e.g. due to lack of
2552 available information), the NULL hash value should be returned (0).
2553 */
2554 virtual uint64_t hash() { return 0; }
2555
2556 void print_item_w_name(const THD *thd, String *,
2557 enum_query_type query_type) const;
2558 /**
2559 Prints the item when it's part of ORDER BY and GROUP BY.
2560 @param thd Thread handle
2561 @param str String to print to
2562 @param query_type How to format the item
2563 @param used_alias The alias with which this item was referenced, or
2564 nullptr if it was not referenced with an alias.
2565 */
2566 void print_for_order(const THD *thd, String *str, enum_query_type query_type,
2567 const char *used_alias) const;
2568
2569 /**
2570 Updates used tables, not null tables information and accumulates
2571 properties up the item tree, cf. used_tables_cache, not_null_tables_cache
2572 and m_accum_properties.
2573
2574 TODO(sgunders): Consider just removing these caches; it causes a lot of bugs
2575 (cache invalidation is known to be a complex problem), and the performance
2576 benefits are dubious.
2577 */
2578 virtual void update_used_tables() {}
2579
2581 return false;
2582 }
2583 /* Called for items that really have to be split */
2584 bool split_sum_func2(THD *thd, Ref_item_array ref_item_array,
2585 mem_root_deque<Item *> *fields, Item **ref,
2586 bool skip_registered);
2587 /**
2588 Evaluate the item and return result as a date value
2589
2590 @param[out] date Returned date value
2591 @param flags Limit the value returned according to TIME_NO_ZERO_IN_DATE,
2592 TIME_NO_ZERO_DATE, TIME_NO_INVALID_DATES.
2593
2594 @returns false if successful and non-NULL, true otherwise
2595 */
2596 virtual bool val_date(Date_val *date, my_time_flags_t flags) = 0;
2597 /**
2598 Evaluate the item and return result as a time value.
2599
2600 @param[out] time Returned time value.
2601
2602 @returns false if successful and non-NULL, true otherwise
2603 */
2604 virtual bool val_time(Time_val *time) = 0;
2605
2606 /**
2607 Evaluate the item and return result as a datetime value
2608
2609 @param[out] dt Returned datetime value
2610 @param flags Limit the value returned according to TIME_NO_ZERO_IN_DATE,
2611 TIME_NO_ZERO_DATE, TIME_NO_INVALID_DATES.
2612
2613 @returns false if successful and non-NULL, true otherwise
2614 true return means that the result is either a NULL value,
2615 or an error.
2616 */
2618 /**
2619 Get timestamp in "struct timeval" format.
2620 @retval false on success
2621 @retval true on error
2622 */
2623 virtual bool get_timeval(my_timeval *tm, int *warnings);
2624 /**
2625 The method allows to determine nullness of a complex expression
2626 without fully evaluating it, instead of calling val*() then
2627 checking null_value. Used in Item_func_isnull/Item_func_isnotnull
2628 and Item_sum_count/Item_sum_count_distinct.
2629 Any item which can be NULL must implement this method.
2630
2631 @retval false if the expression is not NULL.
2632 @retval true if the expression is NULL, or evaluation caused an error.
2633 The null_value member is set according to the return value.
2634 */
2635 virtual bool is_null() { return false; }
2636
2637 /**
2638 Make sure the null_value member has a correct value.
2639 null_value is set true also when evaluation causes error.
2640
2641 @returns false if success, true if error
2642 */
2643 bool update_null_value();
2644
2645 /**
2646 Apply the IS TRUE truth property, meaning that an UNKNOWN result and a
2647 FALSE result are treated the same.
2648
2649 This property is applied e.g to all conditions in WHERE, HAVING and ON
2650 clauses, and is recursively applied to operands of AND, OR
2651 operators. Some items (currently AND and subquery predicates) may enable
2652 special optimizations when they have this property.
2653 */
2654 virtual void apply_is_true() {}
2655 /*
2656 set field of temporary table for Item which can be switched on temporary
2657 table during query processing (grouping and so on). @see
2658 Item_result_field.
2659 */
2660 virtual void set_result_field(Field *) {}
2661 virtual bool is_result_field() const { return false; }
2662 virtual Field *get_result_field() const { return nullptr; }
2663 virtual bool is_bool_func() const { return false; }
2664 /*
2665 Set value of aggregate function in case of no rows for grouping were found.
2666 Also used for subqueries with outer references in SELECT list.
2667 */
2668 virtual void no_rows_in_result() {}
2669 virtual Item *copy_or_same(THD *) { return this; }
2670 virtual Item *copy_andor_structure(THD *) { return this; }
2671 /**
2672 @returns the "real item" underlying the owner object. Used to strip away
2673 Item_ref objects.
2674 @note remember to implement both real_item() functions in sub classes!
2675 */
2676 virtual Item *real_item() { return this; }
2677 virtual const Item *real_item() const { return this; }
2678 /**
2679 If an Item is materialized in a temporary table, a different Item may have
2680 to be used in the part of the query that runs after the materialization.
2681 For instance, if the Item was an Item_field, the new Item_field needs to
2682 point into the temporary table instead of the original one, but if, on the
2683 other hand, the Item was a literal constant, it can be reused as-is.
2684 This function encapsulates these policies for the different kinds of Items.
2685 See also get_tmp_table_field().
2686
2687 TODO: Document how aggregate functions (Item_sum) are handled.
2688 */
2689 virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
2690
2691 static const CHARSET_INFO *default_charset();
2692 virtual const CHARSET_INFO *compare_collation() const { return nullptr; }
2693
2694 /*
2695 For backward compatibility, to make numeric
2696 data types return "binary" charset in client-side metadata.
2697 */
2701 : &my_charset_bin;
2702 }
2703
2704 /**
2705 Traverses a tree of Items in prefix and/or postfix order.
2706 Optionally walks into subqueries.
2707
2708 @param processor processor function to be invoked per item
2709 returns true to abort traversal, false to continue
2710 @param walk controls how to traverse the item tree
2711 enum_walk::PREFIX: call processor before invoking
2712 children enum_walk::POSTFIX: call processor after invoking children
2713 enum_walk::SUBQUERY go down into subqueries
2714 walk values are bit-coded and may be combined.
2715 Omitting both enum_walk::PREFIX and enum_walk::POSTFIX
2716 is undefined behaviour.
2717 @param arg Optional pointer to a walk-specific object
2718
2719 @retval false walk succeeded
2720 @retval true walk aborted
2721 by agreement, an error may have been reported
2722 */
2723
2724 virtual bool walk(Item_processor processor, enum_walk walk [[maybe_unused]],
2725 uchar *arg) {
2726 return ((walk & enum_walk::PREFIX) && (this->*processor)(arg)) ||
2727 ((walk & enum_walk::POSTFIX) && (this->*processor)(arg));
2728 }
2729
2730 /** @see WalkItem, CompileItem, TransformItem */
2731 template <class T>
2733 return (*reinterpret_cast<std::remove_reference_t<T> *>(arg))(this);
2734 }
2735
2736 /** See CompileItem */
2737 template <class T>
2739 return (*reinterpret_cast<std::remove_reference_t<T> *>(*arg))(this);
2740 }
2741
2742 /**
2743 Perform a generic transformation of the Item tree, by adding zero or
2744 more additional Item objects to it.
2745
2746 @param transformer Transformer function
2747 @param[in,out] arg Pointer to struct used by transformer function
2748
2749 @returns Returned item tree after transformation, NULL if error
2750
2751 Transformation is performed as follows:
2752
2753 @code
2754 transform()
2755 {
2756 transform children if any;
2757 return this->*some_transformer(...);
2758 }
2759 @endcode
2760
2761 Note that unlike Item::compile(), transform() does not support an analyzer
2762 function, ie. all children are unconditionally invoked.
2763
2764 Item::transform() should handle all transformations during preparation.
2765 Notice that all transformations are permanent; they are not rolled back.
2766
2767 Use Item::compile() to perform transformations during optimization.
2768 */
2769 virtual Item *transform(Item_transformer transformer, uchar *arg);
2770
2771 /**
2772 Perform a generic "compilation" of the Item tree, ie transform the Item tree
2773 by adding zero or more Item objects to it.
2774
2775 @param analyzer Analyzer function, see details section
2776 @param[in,out] arg_p Pointer to struct used by analyzer function
2777 @param transformer Transformer function, see details section
2778 @param[in,out] arg_t Pointer to struct used by transformer function
2779
2780 @returns Returned item tree after transformation, NULL if error
2781
2782 The process of this transformation is assumed to be as follows:
2783
2784 @code
2785 compile()
2786 {
2787 if (this->*some_analyzer(...))
2788 {
2789 compile children if any;
2790 return this->*some_transformer(...);
2791 }
2792 else
2793 return this;
2794 }
2795 @endcode
2796
2797 i.e. analysis is performed top-down while transformation is done
2798 bottom-up. If no transformation is applied, the item is returned unchanged.
2799 A transformation error is indicated by returning a NULL pointer. Notice
2800 that the analyzer function should never cause an error.
2801
2802 The function is supposed to be used during the optimization stage of
2803 query execution. All new allocations are recorded using
2804 THD::change_item_tree() so that they can be rolled back after execution.
2805
2806 @todo Pass THD to compile() function, thus no need to use current_thd.
2807 */
2808 virtual Item *compile(Item_analyzer analyzer, uchar **arg_p,
2809 Item_transformer transformer, uchar *arg_t) {
2810 if ((this->*analyzer)(arg_p)) return ((this->*transformer)(arg_t));
2811 return this;
2812 }
2813
2814 virtual void traverse_cond(Cond_traverser traverser, void *arg,
2816 (*traverser)(this, arg);
2817 }
2818
2819 /*
2820 This is used to get the most recent version of any function in
2821 an item tree. The version is the version where a MySQL function
2822 was introduced in. So any function which is added should use
2823 this function and set the int_arg to maximum of the input data
2824 and their own version info.
2825 */
2826 virtual bool intro_version(uchar *) { return false; }
2827
2828 /// cleanup() item if it is resolved ('fixed').
2830 if (fixed) cleanup();
2831 return false;
2832 }
2834 return *(pointer_cast<Item **>(arg)) == this;
2835 }
2836 virtual bool collect_item_field_processor(uchar *) { return false; }
2837 virtual bool collect_item_field_or_ref_processor(uchar *) { return false; }
2838 virtual bool collect_outer_field_processor(uchar *) { return false; }
2839
2841 public:
2844 : m_items(fields_or_refs) {}
2847 const Collect_item_fields_or_refs &) = delete;
2848
2849 friend class Item_sum;
2850 friend class Item_field;
2851 friend class Item_ref;
2852 };
2853
2855 public:
2858 /// Used to compute \c Item_field's \c m_protected_by_any_value. Pushed and
2859 /// popped when walking arguments of \c Item_func_any_value.a
2862 Query_block *transformed_block)
2863 : m_item_fields_or_view_refs(fields_or_vr),
2864 m_transformed_block(transformed_block) {}
2866 delete;
2868 const Collect_item_fields_or_view_refs &) = delete;
2869
2870 friend class Item_sum;
2871 friend class Item_field;
2873 friend class Item_view_ref;
2874 };
2875
2876 /**
2877 Collects fields and view references that have the qualifying table
2878 in the specified query block.
2879 */
2881 return false;
2882 }
2883
2884 /**
2885 Item::walk function. Set bit in table->tmp_set for all fields in
2886 table 'arg' that are referred to by the Item.
2887 */
2888 virtual bool add_field_to_set_processor(uchar *) { return false; }
2889
2890 /// A processor to handle the select lex visitor framework.
2891 virtual bool visitor_processor(uchar *arg);
2892
2893 /**
2894 Item::walk function. Set bit in table->cond_set for all fields of
2895 all tables that are referred to by the Item.
2896 */
2897 virtual bool add_field_to_cond_set_processor(uchar *) { return false; }
2898
2899 /**
2900 Visitor interface for removing all column expressions (Item_field) in
2901 this expression tree from a bitmap. @see walk()
2902
2903 @param arg A MY_BITMAP* cast to unsigned char*, where the bits represent
2904 Field::field_index values.
2905 */
2906 virtual bool remove_column_from_bitmap(uchar *arg [[maybe_unused]]) {
2907 return false;
2908 }
2909 virtual bool find_item_in_field_list_processor(uchar *) { return false; }
2910 virtual bool change_context_processor(uchar *) { return false; }
2911 virtual bool find_item_processor(uchar *arg) { return this == (void *)arg; }
2913 return !basic_const_item();
2914 }
2915 /// Is this an Item_field which references the given Field argument?
2916 virtual bool find_field_processor(uchar *) { return false; }
2917 /// Wrap incompatible arguments in CAST nodes to the expected data types
2918 virtual bool cast_incompatible_args(uchar *) { return false; }
2919 /**
2920 Mark underlying field in read or write map of a table.
2921
2922 @param arg Mark_field object
2923 */
2924 virtual bool mark_field_in_map(uchar *arg [[maybe_unused]]) { return false; }
2925
2926 protected:
2927 /**
2928 Helper function for mark_field_in_map(uchar *arg).
2929
2930 @param mark_field Mark_field object
2931 @param field Field to be marked for read/write
2932 */
2933 static inline bool mark_field_in_map(Mark_field *mark_field, Field *field) {
2934 TABLE *table = mark_field->table;
2935 if (table != nullptr && table != field->table) return false;
2936
2937 table = field->table;
2938 table->mark_column_used(field, mark_field->mark);
2939
2940 return false;
2941 }
2942
2943 public:
2944 /**
2945 Reset execution state for such window function types
2946 as determined by arg
2947
2948 @param arg pointing to a bool which, if true, says to reset state
2949 for framing window function, else for non-framing
2950 */
2951 virtual bool reset_wf_state(uchar *arg [[maybe_unused]]) { return false; }
2952
2953 /**
2954 Return used table information for the specified query block (level).
2955 For a field that is resolved from this query block, return the table number.
2956 For a field that is resolved from a query block outer to the specified one,
2957 return OUTER_REF_TABLE_BIT
2958
2959 @param[in,out] arg pointer to an instance of class Used_tables, which is
2960 constructed with the query block as argument.
2961 The used tables information is accumulated in the field
2962 used_tables in this class.
2963
2964 @note This function is used to update used tables information after
2965 merging a query block (a subquery) with its parent.
2966 */
2967 virtual bool used_tables_for_level(uchar *arg [[maybe_unused]]) {
2968 return false;
2969 }
2970 /**
2971 Check privileges.
2972
2973 @param thd thread handle
2974 */
2975 virtual bool check_column_privileges(uchar *thd [[maybe_unused]]) {
2976 return false;
2977 }
2978 virtual bool inform_item_in_cond_of_tab(uchar *) { return false; }
2979 /**
2980 Bind objects from the current execution context to field objects in
2981 item trees. Typically used to bind Field objects from TABLEs to
2982 Item_field objects.
2983 */
2984 virtual void bind_fields() {}
2985
2986 /**
2987 Context object for (functions that override)
2988 Item::clean_up_after_removal().
2989 */
2991 public:
2993 assert(root != nullptr);
2994 }
2995
2997
2998 private:
2999 /**
3000 Pointer to Cleanup_after_removal_context containing from which
3001 select the walk started, i.e., the Query_block that contained the clause
3002 that was removed.
3003 */
3005
3006 friend class Item;
3007 friend class Item_func_eq;
3008 friend class Item_sum;
3009 friend class Item_subselect;
3010 friend class Item_ref;
3011 };
3012 /**
3013 Clean up after removing the item from the item tree.
3014
3015 param arg pointer to a Cleanup_after_removal_context object
3016 @todo: If class ORDER is refactored so that all indirect
3017 grouping/ordering expressions are represented with Item_ref
3018 objects, all implementations of cleanup_after_removal() except
3019 the one for Item_ref can be removed.
3020 */
3021 virtual bool clean_up_after_removal(uchar *arg);
3022
3023 /// @see Distinct_check::check_query()
3024 virtual bool aggregate_check_distinct(uchar *) { return false; }
3025 /// @see Group_check::check_query()
3026 virtual bool aggregate_check_group(uchar *) { return false; }
3027 /// @see Group_check::analyze_conjunct()
3028 virtual bool is_strong_side_column_not_in_fd(uchar *) { return false; }
3029 /// @see Group_check::is_in_fd_of_underlying()
3030 virtual bool is_column_not_in_fd(uchar *) { return false; }
3031 virtual Bool3 local_column(const Query_block *) const {
3032 return Bool3::false3();
3033 }
3034
3035 /**
3036 Minion class under \c Collect_scalar_subquery_info ("Css"). Information
3037 about one scalar subquery being considered for transformation
3038 */
3039 struct Css_info {
3040 /// set of locations
3042 /// the scalar subquery
3045 /// Where did we find item above? Used when \c m_location == \c L_JOIN_COND,
3046 /// nullptr for other locations.
3048 /// If true, we can forego cardinality checking of the derived table
3050 /// If true, add a COALESCE around replaced subquery: used for implicitly
3051 /// grouped COUNT() in subquery select list when subquery is correlated
3052 bool m_add_coalesce{false};
3053 /// Set iff \c m_add_coalesce is true: we may get a NULL anyway even for
3054 /// COUNT if a HAVING clause is false in the subquery.
3056 /// Index of the having expression copied to select list
3058 };
3059
3060 /**
3061 Context struct used by walk method collect_scalar_subqueries to
3062 accumulate information about scalar subqueries found.
3063
3064 In: m_location of expression walked, m_join_condition_context
3065 Out: m_list
3066 */
3068 enum Location { L_SELECT = 1, L_WHERE = 2, L_HAVING = 4, L_JOIN_COND = 8 };
3069 /// accumulated all scalar subqueries found
3070 std::vector<Css_info> m_list;
3071 /// we are currently looking at this kind of clause, cf. enum Location
3076 friend class Item_sum;
3078 };
3079
3080 virtual bool collect_scalar_subqueries(uchar *) { return false; }
3081 virtual bool collect_grouped_aggregates(uchar *) { return false; }
3082 virtual bool collect_subqueries(uchar *) { return false; }
3083 virtual bool update_depended_from(uchar *) { return false; }
3084 /**
3085 Check if an aggregate is referenced from within the GROUP BY
3086 clause of the query block in which it is aggregated. Such
3087 references will be rejected.
3088 @see Item_ref::fix_fields()
3089 @retval true if this is an aggregate which is referenced from
3090 the GROUP BY clause of the aggregating query block
3091 @retval false otherwise
3092 */
3093 virtual bool has_aggregate_ref_in_group_by(uchar *) { return false; }
3094
3095 bool visit_all_analyzer(uchar **) { return true; }
3096 virtual bool cache_const_expr_analyzer(uchar **cache_item);
3098
3099 virtual bool equality_substitution_analyzer(uchar **) { return false; }
3100
3101 virtual Item *equality_substitution_transformer(uchar *) { return this; }
3102
3103 /**
3104 Check if a partition function is allowed.
3105
3106 @return whether a partition function is not accepted
3107
3108 @details
3109 check_partition_func_processor is used to check if a partition function
3110 uses an allowed function. An allowed function will always ensure that
3111 X=Y guarantees that also part_function(X)=part_function(Y) where X is
3112 a set of partition fields and so is Y. The problems comes mainly from
3113 character sets where two equal strings can be quite unequal. E.g. the
3114 german character for double s is equal to 2 s.
3115
3116 The default is that an item is not allowed
3117 in a partition function. Allowed functions
3118 can never depend on server version, they cannot depend on anything
3119 related to the environment. They can also only depend on a set of
3120 fields in the table itself. They cannot depend on other tables and
3121 cannot contain any queries and cannot contain udf's or similar.
3122 If a new Item class is defined and it inherits from a class that is
3123 allowed in a partition function then it is very important to consider
3124 whether this should be inherited to the new class. If not the function
3125 below should be defined in the new Item class.
3126
3127 The general behaviour is that most integer functions are allowed.
3128 If the partition function contains any multi-byte collations then
3129 the function check_part_func_fields will report an error on the
3130 partition function independent of what functions are used. So the
3131 only character sets allowed are single character collation and
3132 even for those only a limited set of functions are allowed. The
3133 problem with multi-byte collations is that almost every string
3134 function has the ability to change things such that two strings
3135 that are equal will not be equal after manipulated by a string
3136 function. E.g. two strings one contains a double s, there is a
3137 special german character that is equal to two s. Now assume a
3138 string function removes one character at this place, then in
3139 one the double s will be removed and in the other there will
3140 still be one s remaining and the strings are no longer equal
3141 and thus the partition function will not sort equal strings into
3142 the same partitions.
3143
3144 So the check if a partition function is valid is two steps. First
3145 check that the field types are valid, next check that the partition
3146 function is valid. The current set of partition functions valid
3147 assumes that there are no multi-byte collations amongst the partition
3148 fields.
3149 */
3150 virtual bool check_partition_func_processor(uchar *) { return true; }
3151 virtual bool subst_argument_checker(uchar **arg) {
3152 if (*arg) *arg = nullptr;
3153 return true;
3154 }
3155 virtual bool explain_subquery_checker(uchar **) { return true; }
3156 virtual Item *explain_subquery_propagator(uchar *) { return this; }
3157
3158 virtual Item *equal_fields_propagator(uchar *) { return this; }
3159 // Mark the item to not be part of substitution.
3160 virtual bool disable_constant_propagation(uchar *) { return false; }
3161
3163 // Stack of pointers to enclosing functions
3165 };
3166 virtual Item *replace_equal_field(uchar *) { return this; }
3167 virtual bool replace_equal_field_checker(uchar **) { return true; }
3168 /*
3169 Check if an expression value has allowed arguments, like DATE/DATETIME
3170 for date functions. Also used by partitioning code to reject
3171 timezone-dependent expressions in a (sub)partitioning function.
3172 */
3173 virtual bool check_valid_arguments_processor(uchar *) { return false; }
3174
3175 /**
3176 Check if this item is allowed for a virtual column or inside a
3177 default expression. Should be overridden in child classes.
3178
3179 @param[in,out] args Due to the limitation of Item::walk()
3180 it is declared as a pointer to uchar, underneath there's a actually a
3181 structure of type Check_function_as_value_generator_parameters.
3182 It is used mainly in Item_field.
3183
3184 @returns true if function is not accepted
3185 */
3186 virtual bool check_function_as_value_generator(uchar *args);
3187
3188 /**
3189 Check if a generated expression depends on DEFAULT function with
3190 specific column name as argument.
3191
3192 @param[in] args Name of column used as DEFAULT function argument.
3193
3194 @returns false if the function is not DEFAULT(args), otherwise true.
3195 */
3197 [[maybe_unused]]) {
3198 return false;
3199 }
3200 /**
3201 Check if all the columns present in this expression are from the
3202 derived table. Used in determining if a condition can be pushed
3203 down to derived table.
3204 */
3205 virtual bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) {
3206 // A generic item cannot be pushed down unless it's a constant
3207 // which does not have a subquery.
3208 return !const_item() || has_subquery();
3209 }
3210
3211 /**
3212 Check if all the columns present in this expression are present
3213 in PARTITION clause of window functions of the derived table.
3214 Used in checking if a condition can be pushed down to derived table.
3215 */
3216 virtual bool check_column_in_window_functions(uchar *arg [[maybe_unused]]) {
3217 return false;
3218 }
3219 /**
3220 Check if all the columns present in this expression are present
3221 in GROUP BY clause of the derived table. Used in checking if
3222 a condition can be pushed down to derived table.
3223 */
3224 virtual bool check_column_in_group_by(uchar *arg [[maybe_unused]]) {
3225 return false;
3226 }
3227 /**
3228 Assuming this expression is part of a condition that would be pushed to the
3229 WHERE clause of a materialized derived table, replace, in this expression,
3230 each derived table's column with a clone of the expression lying under it
3231 in the derived table's definition. We replace with a clone, because the
3232 condition can be pushed further down in case of nested derived tables.
3233 */
3234 virtual Item *replace_with_derived_expr(uchar *arg [[maybe_unused]]) {
3235 return this;
3236 }
3237 /**
3238 Assuming this expression is part of a condition that would be pushed to the
3239 HAVING clause of a materialized derived table, replace, in this expression,
3240 each derived table's column with a reference to the expression lying under
3241 it in the derived table's definition. Unlike replace_with_derived_expr, a
3242 clone is not used because HAVING condition will not be pushed further
3243 down in case of nested derived tables.
3244 */
3245 virtual Item *replace_with_derived_expr_ref(uchar *arg [[maybe_unused]]) {
3246 return this;
3247 }
3248 /**
3249 Assuming this expression is part of a condition that would be pushed to a
3250 materialized derived table, replace, in this expression, each view reference
3251 with a clone of the expression in merged derived table's definition.
3252 We replace with a clone, because the referenced item in a view reference
3253 is shared by all the view references to that expression.
3254 */
3255 virtual Item *replace_view_refs_with_clone(uchar *arg [[maybe_unused]]) {
3256 return this;
3257 }
3258 /*
3259 For SP local variable returns pointer to Item representing its
3260 current value and pointer to current Item otherwise.
3261 */
3262 virtual Item *this_item() { return this; }
3263 virtual const Item *this_item() const { return this; }
3264
3265 /*
3266 For SP local variable returns address of pointer to Item representing its
3267 current value and pointer passed via parameter otherwise.
3268 */
3269 virtual Item **this_item_addr(THD *, Item **addr_arg) { return addr_arg; }
3270
3271 // Row emulation
3272 virtual uint cols() const { return 1; }
3273 virtual Item *element_index(uint) { return this; }
3274 virtual Item **addr(uint) { return nullptr; }
3275 virtual bool check_cols(uint c);
3276 // It is not row => null inside is impossible
3277 virtual bool null_inside() { return false; }
3278 // used in row subselects to get value of elements
3279 virtual void bring_value() {}
3280
3281 Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length) const;
3282 virtual Item_field *field_for_view_update() { return nullptr; }
3283 /**
3284 Informs an item that it is wrapped in a truth test, in case it wants to
3285 transforms itself to implement this test by itself.
3286 @param thd Thread handle
3287 @param test Truth test
3288 */
3289 virtual Item *truth_transformer(THD *thd [[maybe_unused]],
3290 Bool_test test [[maybe_unused]]) {
3291 return nullptr;
3292 }
3293 virtual Item *update_value_transformer(uchar *) { return this; }
3294
3296 Query_block *m_trans_block; ///< Transformed query block
3297 Query_block *m_curr_block; ///< Transformed query block or a contained
3298 ///< subquery. Pushed when diving into
3299 ///< subqueries.
3300 Item_replacement(Query_block *transformed_block, Query_block *current_block)
3301 : m_trans_block(transformed_block), m_curr_block(current_block) {}
3302 };
3304 Field *m_target; ///< The field to be replaced
3305 Item_field *m_item; ///< The replacement field
3306 ///< replacement field iff outer ref
3308 enum class Mode {
3309 CONFLATE, // include both Item_field and Item_default_value
3310 FIELD, // ignore Item_default_value
3311 DEFAULT_VALUE // ignore Item_field
3312 };
3315 Mode default_value = Mode::CONFLATE)
3316 : Item_replacement(select, select),
3317 m_target(target),
3318 m_item(item),
3319 m_default_value(default_value) {}
3320 };
3321
3323 Item_func *m_target; ///< The function call to be replaced
3324 Item_field *m_item; ///< The replacement field
3326 Query_block *select)
3327 : Item_replacement(select, select),
3328 m_target(func_target),
3329 m_item(item) {}
3330 };
3331
3333 Item *m_target; ///< The item identifying the view_ref to be replaced
3334 Field *m_field; ///< The replacement field
3335 Item_field *m_outer_field{nullptr}; ///< replacement field if outer ref
3336 ///< subquery. Pushed when diving into
3337 ///< subqueries.
3339 : Item_replacement(select, select), m_target(target), m_field(field) {}
3340 };
3341
3346 : m_target(target), m_replacement(replacement) {}
3347 };
3348
3349 /**
3350 When walking the item tree seeing an Item_singlerow_subselect matching
3351 a target, replace it with a substitute field used when transforming
3352 scalar subqueries into derived tables. Cf.
3353 Query_block::transform_scalar_subqueries_to_join_with_derived.
3354 */
3355 virtual Item *replace_scalar_subquery(uchar *) { return this; }
3356
3357 /**
3358 Transform processor used by Query_block::transform_grouped_to_derived
3359 to replace fields which used to be at the transformed query block
3360 with corresponding fields in the new derived table containing the grouping
3361 operation of the original transformed query block.
3362 */
3363 virtual Item *replace_item_field(uchar *) { return this; }
3364 virtual Item *replace_func_call(uchar *) { return this; }
3365 virtual Item *replace_item_view_ref(uchar *) { return this; }
3366 virtual Item *replace_aggregate(uchar *) { return this; }
3367 virtual Item *replace_outer_ref(uchar *) { return this; }
3368
3373 : m_target(target), m_owner(owner) {}
3374 };
3375
3376 /**
3377 A walker processor overridden by Item_aggregate_ref, q.v.
3378 */
3379 virtual bool update_aggr_refs(uchar *) { return false; }
3380
3381 /**
3382 Convert constant string in this object into the specified character set.
3383
3384 @param thd thread handler
3385 @param tocs target character set
3386 @param ignore_errors if true, ignore errors in conversion
3387
3388 @returns pointer to new Item containing converted character string
3389 = NULL: If conversion failed
3390 */
3391 Item *convert_charset(THD *thd, const CHARSET_INFO *tocs,
3392 bool ignore_errors = false);
3393
3394 /**
3395 Delete this item.
3396 Note that item must have been cleanup up by calling Item::cleanup().
3397 */
3398 void delete_self() { delete this; }
3399
3400 /** @return whether the item is local to a stored procedure */
3401 virtual bool is_splocal() const { return false; }
3402
3403 /*
3404 Return Settable_routine_parameter interface of the Item. Return 0
3405 if this Item is not Settable_routine_parameter.
3406 */
3408 return nullptr;
3409 }
3410 inline bool is_temporal_with_date() const {
3412 }
3415 }
3416 inline bool is_temporal_with_time() const {
3418 }
3419 inline bool is_temporal() const {
3421 }
3422 /**
3423 Check whether this and the given item has compatible comparison context.
3424 Used by the equality propagation. See Item_field::equal_fields_propagator.
3425
3426 @return
3427 true if the context is the same or if fields could be
3428 compared as DATETIME values by the Arg_comparator.
3429 false otherwise.
3430 */
3431 inline bool has_compatible_context(Item *item) const {
3432 // If no explicit context has been set, assume the same type as the item
3433 const Item_result this_context =
3435 const Item_result other_context = item->cmp_context == INVALID_RESULT
3436 ? item->result_type()
3437 : item->cmp_context;
3438
3439 // Check if both items have the same context
3440 if (this_context == other_context) {
3441 return true;
3442 }
3443 /* DATETIME comparison context. */
3445 return item->is_temporal_with_date() || other_context == STRING_RESULT;
3446 if (item->is_temporal_with_date())
3447 return is_temporal_with_date() || this_context == STRING_RESULT;
3448 return false;
3449 }
3451 return Field::GEOM_GEOMETRY;
3452 }
3453 String *check_well_formed_result(String *str, bool send_error, bool truncate);
3454 bool eq_by_collation(Item *item, const CHARSET_INFO *cs);
3455
3457 m_cost.Compute(*this);
3458 return m_cost;
3459 }
3460
3461 /**
3462 @return maximum number of characters that this Item can store
3463 If Item is of string or blob type, return max string length in bytes
3464 divided by bytes per character, otherwise return max_length.
3465 @todo - check if collation for other types should have mbmaxlen = 1
3466 */
3468 /*
3469 Length of e.g. 5.5e5 in an expression such as GREATEST(5.5e5, '5') is 5
3470 (length of that string) although length of the actual value is 6.
3471 Return MAX_DOUBLE_STR_LENGTH to prevent truncation of data without having
3472 to evaluate the value of the item.
3473 */
3474 const uint32 max_len =
3476 if (result_type() == STRING_RESULT)
3477 return max_len / collation.collation->mbmaxlen;
3478 return max_len;
3479 }
3480
3482 if (cs == &my_charset_bin && result_type() == STRING_RESULT) {
3483 return max_length;
3484 }
3485 return max_char_length();
3486 }
3487
3488 inline void fix_char_length(uint32 max_char_length_arg) {
3489 max_length = char_to_byte_length_safe(max_char_length_arg,
3491 }
3492
3493 /*
3494 Return true if the item points to a column of an outer-joined table.
3495 */
3496 virtual bool is_outer_field() const {
3497 assert(fixed);
3498 return false;
3499 }
3500
3501 /**
3502 Check if an item either is a blob field, or will be represented as a BLOB
3503 field if a field is created based on this item.
3504
3505 @retval true If a field based on this item will be a BLOB field,
3506 @retval false Otherwise.
3507 */
3508 bool is_blob_field() const;
3509
3510 /// @returns number of references to an item.
3511 uint reference_count() const { return m_ref_count; }
3512
3513 /// Increment reference count
3515 assert(!m_abandoned);
3516 ++m_ref_count;
3517 }
3518
3519 /// Decrement reference count
3521 assert(m_ref_count > 0);
3522 if (--m_ref_count == 0) m_abandoned = true;
3523 return m_ref_count;
3524 }
3525
3526 protected:
3527 /// Set accumulated properties for an Item
3528 void set_accum_properties(const Item *item) {
3530 }
3531
3532 /// Add more accumulated properties to an Item
3533 void add_accum_properties(const Item *item) {
3535 }
3536
3537 /// Set the "has subquery" property
3539
3540 /// Set the "has stored program" property
3542
3543 public:
3544 /// @return true if this item or any of its descendants contains a subquery.
3546
3547 /// @return true if this item or any of its descendants refers a stored func.
3548 bool has_stored_program() const {
3550 }
3551
3552 /// @return true if this item or any of its descendants is an aggregated func.
3554
3555 /// Set the "has aggregation" property
3557
3558 /// Reset the "has aggregation" property
3559 void reset_aggregation() { m_accum_properties &= ~PROP_AGGREGATION; }
3560
3561 /// @return true if this item or any of its descendants is a window func.
3563
3564 /// Set the "has window function" property
3566
3567 /**
3568 @return true if this item or any of its descendants within the same query
3569 has a reference to a GROUP BY modifier (such as ROLLUP)
3570 */
3573 }
3574
3575 /**
3576 Set the property: this item (tree) contains a reference to a GROUP BY
3577 modifier (such as ROLLUP)
3578 */
3581 }
3582
3583 /**
3584 @return true if this item or any of underlying items is a GROUPING function
3585 */
3586 bool has_grouping_func() const {
3588 }
3589
3590 /// Set the property: this item is a call to GROUPING
3592
3593 /// Whether this Item was created by the IN->EXISTS subquery transformation
3594 virtual bool created_by_in2exists() const { return false; }
3595
3597 if (has_subquery())
3599 }
3600
3601 /**
3602 Analyzer function for GC substitution. @see substitute_gc()
3603 */
3604 virtual bool gc_subst_analyzer(uchar **) { return false; }
3605 /**
3606 Transformer function for GC substitution. @see substitute_gc()
3607 */
3608 virtual Item *gc_subst_transformer(uchar *) { return this; }
3609
3610 /**
3611 A processor that replaces any Fields with a Create_field_wrapper. This
3612 will allow us to resolve functions during CREATE TABLE, where we only have
3613 Create_field available and not Field. Used for functional index
3614 implementation.
3615 */
3616 virtual bool replace_field_processor(uchar *) { return false; }
3617 /**
3618 Check if this item is of a type that is eligible for GC
3619 substitution. All items that belong to subclasses of Item_func are
3620 eligible for substitution. @see substitute_gc()
3621 Item_fields can also be eligible if they are given as an argument to
3622 a function that takes an array (the field can be substituted with a
3623 generated column that backs a multi-valued index on that field).
3624
3625 @param array true if the item is an argument to a function that takes an
3626 array, or false otherwise
3627 @return true if the expression is eligible for substitution, false otherwise
3628 */
3629 bool can_be_substituted_for_gc(bool array = false) const;
3630
3632 uint nitems);
3633 void aggregate_decimal_properties(Item **items, uint nitems);
3635 uint nitems);
3637 Item **items, uint nitems);
3638 void aggregate_bit_properties(Item **items, uint nitems);
3639
3640 /**
3641 This function applies only to Item_field objects referred to by an Item_ref
3642 object that has been marked as a const_item.
3643
3644 @param arg Keep track of whether an Item_ref refers to an Item_field.
3645 */
3646 virtual bool repoint_const_outer_ref(uchar *arg [[maybe_unused]]) {
3647 return false;
3648 }
3649 virtual bool strip_db_table_name_processor(uchar *) { return false; }
3650
3651 /**
3652 Compute the cost of evaluating this Item.
3653 @param root_cost The cost object to which the cost should be added.
3654 */
3655 virtual void compute_cost(CostOfItem *root_cost [[maybe_unused]]) const {}
3656
3657 bool is_abandoned() const { return m_abandoned; }
3658
3659 private:
3660 virtual bool subq_opt_away_processor(uchar *) { return false; }
3661
3662 public: // Start of data fields
3663 /**
3664 Intrusive list pointer for free list. If not null, points to the next
3665 Item on some Query_arena's free list. For instance, stored procedures
3666 have their own Query_arena's.
3667
3668 @see Query_arena::free_list
3669 */
3670 Item *next_free{nullptr};
3671
3672 protected:
3673 /// str_values's main purpose is to cache the value in save_in_field
3675
3676 public:
3677 /**
3678 Character set and collation properties assigned for this Item.
3679 Used if Item represents a character string expression.
3680 */
3682 Item_name_string item_name; ///< Name from query
3683 Item_name_string orig_name; ///< Original item name (if it was renamed)
3684 /**
3685 Maximum length of result of evaluating this item, in number of bytes.
3686 - For character or blob data types, max char length multiplied by max
3687 character size (collation.mbmaxlen).
3688 - For decimal type, it is the precision in digits plus sign (unless
3689 unsigned) plus decimal point (unless it has zero decimals).
3690 - For other numeric types, the default or specific display length.
3691 - For date/time types, the display length (10 for DATE, 10 + optional FSP
3692 for TIME, 19 + optional fsp for datetime/timestamp).
3693 - For bit, the number of bits.
3694 - For enum, the string length of the widest enum element.
3695 - For set, the sum of the string length of each set element plus separators.
3696 - For geometry, the maximum size of a BLOB (it's underlying storage type).
3697 - For json, the maximum size of a BLOB (it's underlying storage type).
3698 */
3699 uint32 max_length; ///< Maximum length, in bytes
3700 enum item_marker ///< Values for member 'marker'
3701 {
3703 /// When contextualization or itemization adds an implicit comparison '0<>'
3704 /// (see make_condition()), to record that this Item_func_ne was created for
3705 /// this purpose; this value is tested during resolution.
3707 /// When doing constant propagation (e.g. change_cond_ref_to_const(), to
3708 /// remember that we have already processed the item.
3710 /// When creating an internal temporary table: marking group by
3711 /// fields
3713 /// When analyzing functional dependencies for only_full_group_by (says
3714 /// whether a nullable column can be treated at not nullable).
3716 /// When we change DISTINCT to GROUP BY: used for book-keeping of
3717 /// fields.
3719 /// When pushing conditions down to derived table: it says a condition
3720 /// contains only derived table's columns.
3722 /// Used during traversal to avoid deleting an item twice.
3724 /// When pushing index conditions: it says whether a condition uses only
3725 /// indexed columns.
3728 /**
3729 This member has several successive meanings, depending on the phase we're
3730 in (@see item_marker).
3731 The important property is that a phase must have a value (or few values)
3732 which is reserved for this phase. If it wants to set "marked", it assigns
3733 the value; it it wants to test if it is marked, it tests marker !=
3734 value. If the value has been assigned and the phase wants to cancel it can
3735 set marker to MARKER_NONE, which is a magic number which no phase
3736 reserves.
3737 A phase can expect 'marker' to be MARKER_NONE at the start of execution of
3738 a normal statement, at the start of preparation of a PS, and at the start
3739 of execution of a PS.
3740 A phase should not expect marker's value to survive after the phase's
3741 end - as a following phase may change it.
3742 */
3744 Item_result cmp_context; ///< Comparison context
3745 private:
3746 /**
3747 Number of references to this item. It is used for two purposes:
3748 1. When eliminating redundant expressions, the reference count is used
3749 to tell how many Item_ref objects that point to an item. When a
3750 sub-tree of items is eliminated, it is traversed and any item that
3751 is referenced from an Item_ref has its reference count decremented.
3752 Only when the reference count reaches zero is the item actually deleted.
3753 2. Keeping track of unused expressions selected from merged derived tables.
3754 An item that is added to the select list of a query block has its
3755 reference count set to 1. Any references from outer query blocks are
3756 through Item_ref objects, thus they will cause the reference count
3757 to be incremented. At end of resolving, the reference counts of all
3758 items in select list of merged derived tables are decremented, thus
3759 if the reference count becomes zero, the expression is known to
3760 be unused and can be removed.
3761 */
3763 bool m_abandoned{false}; ///< true if item has been fully de-referenced
3764 const bool is_parser_item; ///< true if allocated directly by parser
3765 uint8 m_data_type; ///< Data type assigned to Item
3766
3767 /**
3768 The cost of evaluating this item. This is only needed for predicates,
3769 therefore we use lazy evaluation.
3770 */
3772
3773 public:
3774 bool fixed; ///< True if item has been resolved
3775 /**
3776 Number of decimals in result when evaluating this item
3777 - For integer type, always zero.
3778 - For decimal type, number of decimals.
3779 - For float type, it may be DECIMAL_NOT_SPECIFIED
3780 - For time, datetime and timestamp, number of decimals in fractional second
3781 - For string types, may be decimals of cast source or DECIMAL_NOT_SPECIFIED
3782 */
3784
3785 bool is_nullable() const { return m_nullable; }
3786 void set_nullable(bool nullable) { m_nullable = nullable; }
3787
3788 private:
3789 /**
3790 True if this item may hold the NULL value(if null_value may be set to true).
3791
3792 For items that represent rows, it is true if one of the columns
3793 may be null.
3794
3795 For items that represent scalar or row subqueries, it is true if
3796 one of the returned columns could be null, or if the subquery
3797 could return zero rows.
3798
3799 It is worth noting that this information is correct only until
3800 equality propagation has been run by the optimization phase.
3801 Indeed, consider:
3802 select * from t1, t2,t3 where t1.pk=t2.a and t1.pk+1...
3803 the '+' is not nullable as t1.pk is not nullable;
3804 but if the optimizer chooses plan is t2-t3-t1, then, due to equality
3805 propagation it will replace t1.pk in '+' with t2.a (as t2 is before t1
3806 in plan), making the '+' capable of returning NULL when t2.a is NULL.
3807 */
3809
3810 public:
3811 bool null_value; ///< True if item is null
3813 bool m_is_window_function; ///< True if item represents window func
3814 /**
3815 If the item is in a SELECT list (Query_block::fields) and hidden is true,
3816 the item wasn't actually in the list as given by the user (it was added
3817 by the optimizer, to e.g. make sure it was part of a given
3818 materialization), and should not be returned in the actual result.
3819
3820 If the item is not in a SELECT list, the value is irrelevant.
3821 */
3822 bool hidden{false};
3823 /**
3824 True if item is a top most element in the expression being
3825 evaluated for a check constraint.
3826 */
3828
3829 protected:
3830 /**
3831 Set of properties that are calculated by accumulation from underlying items.
3832 Computed by constructors and fix_fields() and updated by
3833 update_used_tables(). The properties are accumulated up to the root of the
3834 current item tree, except they are not accumulated across subqueries and
3835 functions.
3836 */
3837 static constexpr uint8 PROP_SUBQUERY = 0x01;
3838 static constexpr uint8 PROP_STORED_PROGRAM = 0x02;
3839 static constexpr uint8 PROP_AGGREGATION = 0x04;
3840 static constexpr uint8 PROP_WINDOW_FUNCTION = 0x08;
3841 /**
3842 Set if the item or one or more of the underlying items contains a
3843 GROUP BY modifier (such as ROLLUP).
3844 */
3845 static constexpr uint8 PROP_HAS_GROUPING_SET_DEP = 0x10;
3846 /**
3847 Set if the item or one or more of the underlying items is a GROUPING
3848 function.
3849 */
3850 static constexpr uint8 PROP_GROUPING_FUNC = 0x20;
3851
3853
3854 public:
3855 /**
3856 Apply column masking policy to this item if applicable.
3857
3858 @param thd Thread handle.
3859 @return Item to use after masking (possibly this or a new Item), or
3860 nullptr on error.
3861 */
3862 virtual Item *apply_masking_policy(THD *thd [[maybe_unused]]) { return this; }
3863
3864 /**
3865 Disable application of the masking policy to this item. This is used to
3866 prevent replacing an Item_field with a masking expression when resolving
3867 target columns of INSERT, UPDATE or REPLACE, as these statements would still
3868 need to be able to write to these columns, even though they should be masked
3869 when being read.
3870 */
3871 virtual void disable_masking_policy() {}
3872
3873 /**
3874 Mark this expression as a masking expression for some other expression.
3875 @param masked_item The item that should be masked by this expression.
3876 */
3877 virtual void set_masking_expression_for(const Item_field *masked_item
3878 [[maybe_unused]]) {
3879 // Only expected to be called on the top-level item of the masking policy
3880 // expression as specified in a CREATE MASKING POLICY statement. At the time
3881 // of writing, this has to be an Item_func_case.
3882 assert(false);
3883 }
3884
3885 /**
3886 Check if this expression can be used for partial update of a given
3887 JSON column.
3888
3889 For example, the expression `JSON_REPLACE(col, '$.foo', 'bar')`
3890 can be used to partially update the column `col`.
3891
3892 @param field the JSON column that is being updated
3893 @return true if this expression can be used for partial update,
3894 false otherwise
3895 */
3896 virtual bool supports_partial_update(const Field_json *field
3897 [[maybe_unused]]) const {
3898 return false;
3899 }
3900
3901 /**
3902 Whether the item returns array of its data type
3903 */
3904 virtual bool returns_array() const { return false; }
3905
3906 /**
3907 A helper function to ensure proper usage of CAST(.. AS .. ARRAY)
3908 */
3909 virtual void allow_array_cast() {}
3910};
3911
3912/**
3913 Descriptor of what and how to cache for
3914 Item::cache_const_expr_transformer/analyzer.
3915
3916*/
3917
3919 /// Path from the expression's top to the current item in item tree
3920 /// used to track parent of current item for caching JSON data
3922 /// Item to cache. Used as a binary flag, but kept as Item* for assertion
3923 Item *cache_item{nullptr};
3924 /// How to cache JSON data. @see Item::enum_const_item_cache
3926};
3927
3928/**
3929 A helper class to give in a functor to Item::walk(). Use as e.g.:
3930
3931 bool result = WalkItem(root_item, enum_walk::POSTFIX, [](Item *item) { ... });
3932
3933 TODO: Make Item::walk() just take in a functor in the first place, instead of
3934 a pointer-to-member and an opaque argument.
3935 */
3936template <class T>
3937inline bool WalkItem(Item *item, enum_walk walk, T &&functor) {
3938 return item->walk(&Item::walk_helper_thunk<T>, walk,
3939 reinterpret_cast<uchar *>(&functor));
3940}
3941
3942/**
3943 Overload for const 'item' and functor taking 'const Item*' argument.
3944*/
3945template <class T>
3946inline bool WalkItem(const Item *item, enum_walk walk, T &&functor) {
3947 auto to_const = [&](const Item *descendant) { return functor(descendant); };
3948 return WalkItem(const_cast<Item *>(item), walk, to_const);
3949}
3950
3951/**
3952 Same as WalkItem, but for Item::compile(). Use as e.g.:
3953
3954 Item *item = CompileItem(root_item,
3955 [](Item *item) { return true; }, // Analyzer.
3956 [](Item *item) { return item; }); // Transformer.
3957 */
3958template <class T, class U>
3959inline Item *CompileItem(Item *item, T &&analyzer, U &&transformer) {
3960 uchar *analyzer_ptr = reinterpret_cast<uchar *>(&analyzer);
3961 return item->compile(&Item::analyze_helper_thunk<T>, &analyzer_ptr,
3962 &Item::walk_helper_thunk<U>,
3963 reinterpret_cast<uchar *>(&transformer));
3964}
3965
3966/**
3967 Same as WalkItem, but for Item::transform(). Use as e.g.:
3968
3969 Item *item = TransformItem(root_item, [](Item *item) { return item; });
3970 */
3971template <class T>
3972Item *TransformItem(Item *item, T &&transformer) {
3973 return item->transform(&Item::walk_helper_thunk<T>,
3974 pointer_cast<uchar *>(&transformer));
3975}
3976
3979
3980 public:
3982 explicit Item_basic_constant(const POS &pos) : Item(pos), used_table_map(0) {}
3983
3984 /// @todo add implementation of basic_const_item
3985 /// and remove from subclasses as appropriate.
3986
3988 table_map used_tables() const override { return used_table_map; }
3989 bool check_function_as_value_generator(uchar *) override { return false; }
3990 /* to prevent drop fixed flag (no need parent cleanup call) */
3991 void cleanup() override {
3992 // @todo We should ensure we never change "basic constant" nodes.
3993 // We should then be able to add this assert:
3994 // assert(marker == MARKER_NONE);
3995 // and remove the call to Item::cleanup()
3996 Item::cleanup();
3997 }
3998 bool basic_const_item() const override { return true; }
3999 /**
4000 Note that str_value.ptr() will now point to a string owned by some
4001 other object.
4002 */
4004 str_value.set(str->ptr(), str->length(), str->charset());
4005 }
4006};
4007
4008/*****************************************************************************
4009 The class is a base class for representation of stored routine variables in
4010 the Item-hierarchy. There are the following kinds of SP-vars:
4011 - local variables (Item_splocal);
4012 - CASE expression (Item_case_expr);
4013*****************************************************************************/
4014
4015class Item_sp_variable : public Item {
4016 public:
4018
4019 public:
4020#ifndef NDEBUG
4021 /*
4022 Routine to which this Item_splocal belongs. Used for checking if correct
4023 runtime context is used for variable handling.
4024 */
4025 sp_head *m_sp{nullptr};
4026#endif
4027
4028 public:
4029 Item_sp_variable(const Name_string sp_var_name);
4030
4031 table_map used_tables() const override { return INNER_TABLE_BIT; }
4032 bool fix_fields(THD *thd, Item **) override;
4033
4034 double val_real() override;
4035 longlong val_int() override;
4036 String *val_str(String *sp) override;
4037 my_decimal *val_decimal(my_decimal *decimal_value) override;
4038 bool val_json(Json_wrapper *result) override;
4039 bool val_date(Date_val *date, my_time_flags_t flags) override;
4040 bool val_time(Time_val *time) override;
4041 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
4042 bool is_null() override;
4043
4044 public:
4045 inline void make_field(Send_field *field) override;
4046 bool send(Protocol *protocol, String *str) override {
4047 // Need to override send() in case this_item() is an Item_field with a
4048 // ZEROFILL attribute.
4049 return this_item()->send(protocol, str);
4050 }
4051 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
4052 // It is ok to push down a condition like "column > SP_variable"
4053 return false;
4054 }
4055
4056 protected:
4058 Field *field, bool no_conversions) override;
4059};
4060
4061/*****************************************************************************
4062 Item_sp_variable inline implementation.
4063*****************************************************************************/
4064
4066 Item *it = this_item();
4068 it->make_field(field);
4069}
4070
4072 Field *field, bool no_conversions) {
4073 return this_item()->save_in_field(field, no_conversions);
4074}
4075
4076/*****************************************************************************
4077 A reference to local SP variable (incl. reference to SP parameter), used in
4078 runtime.
4079*****************************************************************************/
4080
4081class Item_splocal final : public Item_sp_variable,
4084
4085 public:
4086 /*
4087 If this variable is a parameter in LIMIT clause.
4088 Used only during NAME_CONST substitution, to not append
4089 NAME_CONST to the resulting query and thus not break
4090 the slave.
4091 */
4093 /*
4094 Position of this reference to SP variable in the statement (the
4095 statement itself is in sp_instr_stmt::m_query).
4096 This is valid only for references to SP variables in statements,
4097 excluding DECLARE CURSOR statement. It is used to replace references to SP
4098 variables with NAME_CONST calls when putting statements into the binary
4099 log.
4100 Value of 0 means that this object doesn't corresponding to reference to
4101 SP variable in query text.
4102 */
4104 /*
4105 Byte length of SP variable name in the statement (see pos_in_query).
4106 The value of this field may differ from the name_length value because
4107 name_length contains byte length of UTF8-encoded item name, but
4108 the query string (see sp_instr_stmt::m_query) is currently stored with
4109 a charset from the SET NAMES statement.
4110 */
4112
4113 Item_splocal(const Name_string sp_var_name, uint sp_var_idx,
4114 enum_field_types sp_var_type, uint pos_in_q = 0,
4115 uint len_in_q = 0);
4116
4117 bool is_splocal() const override { return true; }
4118
4119 Item *this_item() override;
4120 const Item *this_item() const override;
4121 Item **this_item_addr(THD *thd, Item **) override;
4122
4123 void print(const THD *thd, String *str,
4124 enum_query_type query_type) const override;
4125
4126 uint64_t hash() override;
4127
4128 public:
4129 uint get_var_idx() const { return m_var_idx; }
4130
4131 Type type() const override { return ROUTINE_FIELD_ITEM; }
4132 Item_result result_type() const override {
4133 return type_to_result(data_type());
4134 }
4135 bool val_json(Json_wrapper *result) override;
4136
4137 private:
4138 bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override;
4139
4140 public:
4142 return this;
4143 }
4144};
4145
4146/*****************************************************************************
4147 A reference to case expression in SP, used in runtime.
4148*****************************************************************************/
4149
4150class Item_case_expr final : public Item_sp_variable {
4151 public:
4152 Item_case_expr(uint case_expr_id);
4153
4154 public:
4155 Item *this_item() override;
4156 const Item *this_item() const override;
4157 Item **this_item_addr(THD *thd, Item **) override;
4158
4159 Type type() const override { return this_item()->type(); }
4160 Item_result result_type() const override {
4161 return this_item()->result_type();
4162 }
4163 /*
4164 NOTE: print() is intended to be used from views and for debug.
4165 Item_case_expr can not occur in views, so here it is only for debug
4166 purposes.
4167 */
4168 void print(const THD *thd, String *str,
4169 enum_query_type query_type) const override;
4170
4171 uint64_t hash() override;
4172
4173 private:
4175};
4176
4177/*
4178 NAME_CONST(given_name, const_value).
4179 This 'function' has all properties of the supplied const_value (which is
4180 assumed to be a literal constant), and the name given_name.
4181
4182 This is used to replace references to SP variables when we write PROCEDURE
4183 statements into the binary log.
4184
4185 TODO
4186 Together with Item_splocal and Item::this_item() we can actually extract
4187 common a base of this class and Item_splocal. Maybe it is possible to
4188 extract a common base with class Item_ref, too.
4189*/
4190
4191class Item_name_const final : public Item {
4192 typedef Item super;
4193
4197
4198 public:
4199 Item_name_const(const POS &pos, Item *name_arg, Item *val);
4200
4201 bool do_itemize(Parse_context *pc, Item **res) override;
4202 bool fix_fields(THD *, Item **) override;
4203
4204 enum Type type() const override { return NAME_CONST_ITEM; }
4205 double val_real() override;
4206 longlong val_int() override;
4207 String *val_str(String *sp) override;
4208 my_decimal *val_decimal(my_decimal *) override;
4209 bool val_date(Date_val *date, my_time_flags_t flags) override;
4210 bool val_time(Time_val *time) override;
4211 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
4212 bool is_null() override;
4213 void print(const THD *thd, String *str,
4214 enum_query_type query_type) const override;
4215
4216 uint64_t hash() override;
4217
4218 Item_result result_type() const override { return value_item->result_type(); }
4219
4221 // Item_name_const always wraps a literal, so there is no need to cache it.
4222 return false;
4223 }
4224
4225 protected:
4227 bool no_conversions) override {
4228 return value_item->save_in_field(field, no_conversions);
4229 }
4230};
4231
4232bool convert_const_strings(DTCollation &coll, Item **args, uint nargs);
4234 Item **items, uint nitems);
4235bool agg_item_charsets(DTCollation &c, const char *name, Item **items,
4236 uint nitems, uint flags);
4238 const char *name, Item **items,
4239 uint nitems) {
4242 return agg_item_charsets(c, name, items, nitems, flags);
4243}
4245 Item **items, uint nitems) {
4247 return agg_item_charsets(c, name, items, nitems, flags);
4248}
4249
4252
4253 public:
4255 explicit Item_num(const POS &pos) : super(pos) { collation.set_numeric(); }
4256
4257 virtual Item_num *neg() = 0;
4258 bool check_partition_func_processor(uchar *) override { return false; }
4259};
4260
4261inline constexpr uint16 NO_FIELD_INDEX((uint16)(-1));
4262
4263class Item_ident : public Item {
4264 typedef Item super;
4265
4266 /** To cache the hash value of this item, populated upon hash() invocation. */
4267 uint64_t m_hash_val{0};
4268
4269 protected:
4270 /**
4271 The fields m_orig_db_name, m_orig_table_name and m_orig_field_name are
4272 maintained so that we can provide information about the origin of a
4273 column that may have been renamed within the query, e.g. as required by
4274 connectors.
4275
4276 Names the original schema of the table that is the source of the field.
4277 If field is from
4278 - a non-aliased base table, the same as db_name.
4279 - an aliased base table, the name of the schema of the base table.
4280 - an expression (including aggregation), a NULL pointer.
4281 - a derived table, the name of the schema of the underlying base table.
4282 - a view, the name of the schema of the underlying base table.
4283 - a temporary table (in optimization stage), the name of the schema of
4284 the source base table.
4285 */
4286 const char *m_orig_db_name;
4287 /**
4288 Names the original table that is the source of the field. If field is from
4289 - a non-aliased base table, the same as table_name.
4290 - an aliased base table, the name of the base table.
4291 - an expression (including aggregation), a NULL pointer.
4292 - a derived table, the name of the underlying base table.
4293 - a view, the name of the underlying base table.
4294 - a temporary table (in optimization stage), the name of the source base tbl
4295 */
4297 /**
4298 Names the field in the source base table. If field is from
4299 - an expression, a NULL pointer.
4300 - a view or base table and is not aliased, the same as field_name.
4301 - a view or base table and is aliased, the column name of the view or
4302 base table.
4303 - a derived table, the column name of the underlying base table.
4304 - a temporary table (in optimization stage), the name of the source column.
4305 */
4307 bool m_alias_of_expr; ///< if this Item's name is alias of SELECT expression
4308
4309 public:
4310 /**
4311 For regularly resolved column references, 'context' points to a name
4312 resolution context object belonging to the query block which simply
4313 contains the reference. To further clarify, in
4314 SELECT (SELECT t.a) FROM t;
4315 t.a is an Item_ident whose 'context' belongs to the subquery
4316 (context->query_block == that of the subquery).
4317 For column references that are part of a generated column expression,
4318 'context' points to a temporary name resolution context object during
4319 resolving, but is set to nullptr after resolving is done. Note that
4320 Item_ident::local_column() depends on that.
4321 */
4323 /**
4324 Schema name of the base table or view the column is part of.
4325 If an expression, a NULL pointer.
4326 If from a derived table, a NULL pointer.
4327 */
4328 const char *db_name;
4329 /**
4330 If column is from a non-aliased base table or view, name of base table or
4331 view.
4332 If column is from an aliased base table or view, the alias name.
4333 If column is from a derived table, the name of the derived table.
4334 If column is from an expression, a NULL pointer.
4335 */
4336 const char *table_name;
4337 /**
4338 If column is aliased, the column alias name.
4339 If column is from a non-aliased base table or view, the name of the
4340 column in that base table or view.
4341 If column is from an expression, a string generated from that expression.
4342
4343 Notice that a column can be aliased in two ways:
4344 1. With an explicit column alias, or @<as clause@>, or
4345 2. With only a column name specified, which differs from the table's
4346 column name due to case insensitivity.
4347 In both cases field_name will differ from m_orig_field_name.
4348 field_name is normally identical to Item::item_name.
4349 */
4350 const char *field_name;
4351 /**
4352 Points to the Table_ref object of the table or view that the column or
4353 reference is resolved against (only valid after resolving).
4354 Notice that for the following types of "tables", no Table_ref object is
4355 assigned and hence m_table_ref is NULL:
4356 - Temporary tables assigned by join optimizer for sorting and aggregation.
4357 - Stored procedure dummy tables.
4358 For fields referencing such tables, table number is always 0, and other
4359 uses of m_table_ref is not needed.
4360 */
4362 /**
4363 For a column or reference that is an outer reference, depended_from points
4364 to the qualifying query block, otherwise it is NULL
4365 (only valid after resolving).
4366 */
4368
4369 Item_ident(Name_resolution_context *context_arg, const char *db_name_arg,
4370 const char *table_name_arg, const char *field_name_arg)
4371 : m_orig_db_name(db_name_arg),
4372 m_orig_table_name(table_name_arg),
4373 m_orig_field_name(field_name_arg),
4374 m_alias_of_expr(false),
4375 context(context_arg),
4376 db_name(db_name_arg),
4377 table_name(table_name_arg),
4378 field_name(field_name_arg) {
4379 item_name.set(field_name_arg);
4380 }
4381
4382 Item_ident(const POS &pos, const char *db_name_arg,
4383 const char *table_name_arg, const char *field_name_arg)
4384 : super(pos),
4385 m_orig_db_name(db_name_arg),
4386 m_orig_table_name(table_name_arg),
4387 m_orig_field_name(field_name_arg),
4388 m_alias_of_expr(false),
4389 db_name(db_name_arg),
4390 table_name(table_name_arg),
4391 field_name(field_name_arg) {
4392 item_name.set(field_name_arg);
4393 }
4394
4395 /// Constructor used by Item_field & Item_*_ref (see Item comment)
4396
4398 : Item(thd, item),
4403 context(item->context),
4404 db_name(item->db_name),
4405 table_name(item->table_name),
4406 field_name(item->field_name),
4407 m_table_ref(item->m_table_ref),
4409
4410 bool do_itemize(Parse_context *pc, Item **res) override;
4411
4412 const char *full_name() const override;
4413 void set_orignal_db_name(const char *name_arg) { m_orig_db_name = name_arg; }
4414 void set_original_table_name(const char *name_arg) {
4415 m_orig_table_name = name_arg;
4416 }
4417 void set_original_field_name(const char *name_arg) {
4418 m_orig_field_name = name_arg;
4419 }
4420 const char *original_db_name() const { return m_orig_db_name; }
4421 const char *original_table_name() const { return m_orig_table_name; }
4422 const char *original_field_name() const { return m_orig_field_name; }
4423 void fix_after_pullout(Query_block *parent_query_block,
4424 Query_block *removed_query_block) override;
4425 bool aggregate_check_distinct(uchar *arg) override;
4426 bool aggregate_check_group(uchar *arg) override;
4427 Bool3 local_column(const Query_block *sl) const override;
4428
4429 void print(const THD *thd, String *str,
4430 enum_query_type query_type) const override {
4431 print(thd, str, query_type, db_name, table_name);
4432 }
4433 uint64_t hash() override;
4434
4435 protected:
4436 /**
4437 Function to print column name for a table
4438
4439 To print a column for a permanent table (picks up database and table from
4440 Item_ident object):
4441
4442 item->print(str, qt)
4443
4444 To print a column for a temporary table:
4445
4446 item->print(str, qt, specific_db, specific_table)
4447
4448 Items of temporary table fields have empty/NULL values of table_name and
4449 db_name. To print column names in a 3D form (`database`.`table`.`column`),
4450 this function prints db_name_arg and table_name_arg parameters instead of
4451 this->db_name and this->table_name respectively.
4452
4453 @param thd Thread handle.
4454 @param [out] str Output string buffer.
4455 @param query_type Bitmap to control printing details.
4456 @param db_name_arg String to output as a column database name.
4457 @param table_name_arg String to output as a column table name.
4458 */
4459 void print(const THD *thd, String *str, enum_query_type query_type,
4460 const char *db_name_arg, const char *table_name_arg) const;
4461
4462 uint64_t hash(const char *db_name_arg, const char *table_name_arg);
4463
4464 public:
4465 ///< Argument object to change_context_processor
4469 };
4470 bool change_context_processor(uchar *arg) override {
4471 context = reinterpret_cast<Change_context *>(arg)->m_context;
4472 return false;
4473 }
4474
4475 /// @returns true if this Item's name is alias of SELECT expression
4476 bool is_alias_of_expr() const { return m_alias_of_expr; }
4477 /// Marks that this Item's name is alias of SELECT expression
4479
4480 /**
4481 Argument structure for walk processor Item::update_depended_from
4482 */
4484 Query_block *old_depended_from; // the transformed query block
4485 Query_block *new_depended_from; // the new derived table for grouping
4486 };
4487
4488 bool update_depended_from(uchar *) override;
4489
4490 /**
4491 @returns true if a part of this Item's full name (name or table name) is
4492 an alias.
4493 */
4494 virtual bool alias_name_used() const { return m_alias_of_expr; }
4496 const char *db_name, const char *table_name,
4498 bool any_privileges);
4499 bool is_strong_side_column_not_in_fd(uchar *arg) override;
4500 bool is_column_not_in_fd(uchar *arg) override;
4501};
4502
4503class Item_ident_for_show final : public Item {
4504 public:
4506 const char *db_name;
4507 const char *table_name;
4508
4509 Item_ident_for_show(Field *par_field, const char *db_arg,
4510 const char *table_name_arg)
4511 : field(par_field), db_name(db_arg), table_name(table_name_arg) {}
4512
4513 enum Type type() const override { return FIELD_ITEM; }
4514 bool fix_fields(THD *thd, Item **ref) override;
4515 double val_real() override { return field->val_real(); }
4516 longlong val_int() override { return field->val_int(); }
4517 String *val_str(String *str) override { return field->val_str(str); }
4519 return field->val_decimal(dec);
4520 }
4521 bool val_date(Date_val *date, my_time_flags_t flags) override {
4522 return field->val_date(date, flags);
4523 }
4524 bool val_time(Time_val *time) override { return field->val_time(time); }
4526 return field->val_datetime(dt, flags);
4527 }
4528 void make_field(Send_field *tmp_field) override;
4530 return field->charset_for_protocol();
4531 }
4532};
4533
4534class Item_field : public Item_ident {
4536
4537 protected:
4538 void set_field(Field *field);
4539 void fix_after_pullout(Query_block *parent_query_block,
4540 Query_block *removed_query_block) override {
4541 super::fix_after_pullout(parent_query_block, removed_query_block);
4542
4543 // Update nullability information, as the table may have taken over
4544 // null_row status from the derived table it was part of.
4546 field->table->is_nullable());
4547 }
4549 bool no_conversions) override;
4550
4551 public:
4552 /// Source field
4553 Field *field{nullptr};
4554
4555 private:
4556 /// Result field
4558
4559 // save_in_field() and save_org_in_field() are often called repeatedly
4560 // with the same destination field (although the destination for the
4561 // two are distinct, thus two distinct caches). We detect this case by
4562 // storing the last destination, and whether it was of a compatible type
4563 // that we can memcpy into (see fields_are_memcpyable()). This saves time
4564 // doing the same type checking over and over again.
4565 //
4566 // The _memcpyable fields are uint32_t(-1) if the fields are not memcpyable,
4567 // and pack_length() (ie., the amount of bytes to copy) if they are.
4568 // See field_conv_with_cache(), where this logic is encapsulated.
4573
4574 /**
4575 If this field is derived from another field, e.g. it is reading a column
4576 from a temporary table which is populated from a base table, this member
4577 points to the field used to populate the temporary table column.
4578 */
4580
4581 /**
4582 State used for transforming scalar subqueries to JOINs with derived tables,
4583 cf. \c transform_grouped_to_derived. Has accessor.
4584 */
4586
4587 /**
4588 Holds a list of items whose values must be equal to the value of
4589 this field, during execution.
4590
4591 Used during optimization to perform multiple equality analysis,
4592 this analysis should be performed during preparation instead, so that
4593 Item_field can be const after preparation.
4594 */
4596
4597 /**
4598 Indicates whether this field should be treated as an outer reference due to
4599 being the result of inlining a local variable within a stored program
4600 (currently applicable only to stored functions).
4601 */
4603
4604 /// apply_masking_policy() is a no-op if this flag is true.
4606
4607 public:
4608 /**
4609 Index for this field in table->field array. Holds NO_FIELD_INDEX
4610 if index value is not known.
4611 */
4614
4616 assert(item_equal != nullptr);
4617 item_equal_all_join_nests = item_equal;
4618 }
4619
4620 /**
4621 Sets m_was_sp_local_variable to true.
4622 */
4624
4625 // A list of fields that are considered "equal" to this field. E.g., a query
4626 // on the form "a JOIN b ON a.i = b.i JOIN c ON b.i = c.i" would consider
4627 // a.i, b.i and c.i equal due to equality propagation. This is the same as
4628 // "item_equal" above, except that "item_equal" will only contain fields from
4629 // the same join nest. This is used by hash join and BKA when they need to
4630 // undo multi-equality propagation done by the optimizer. (The optimizer may
4631 // generate join conditions that references unreachable fields for said
4632 // iterators.) The split is done because NDB expects the list to only
4633 // contain fields from the same join nest.
4635 /// If true, the optimizer's constant propagation will not replace this item
4636 /// with an equal constant.
4638 /*
4639 if any_privileges set to true then here real effective privileges will
4640 be stored
4641 */
4643 /* field need any privileges (for VIEW creation) */
4644 bool any_privileges{false};
4645 /*
4646 if this field is used in a context where covering prefix keys
4647 are supported.
4648 */
4650 Item_field(Name_resolution_context *context_arg, const char *db_arg,
4651 const char *table_name_arg, const char *field_name_arg);
4652 Item_field(const POS &pos, const char *db_arg, const char *table_name_arg,
4653 const char *field_name_arg);
4654 Item_field(THD *thd, Item_field *item);
4655 Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
4657
4658 bool do_itemize(Parse_context *pc, Item **res) override;
4659
4660 enum Type type() const override { return FIELD_ITEM; }
4661 bool eq(const Item *item) const override;
4662 double val_real() override;
4663 longlong val_int() override;
4664 longlong val_date_temporal() override;
4666 my_decimal *val_decimal(my_decimal *) override;
4667 String *val_str(String *) override;
4668 bool val_json(Json_wrapper *result) override;
4669 bool send(Protocol *protocol, String *str_arg) override;
4670 void reset_field(Field *f);
4671 bool fix_fields(THD *, Item **) override;
4672 void make_field(Send_field *tmp_field) override;
4673 void save_org_in_field(Field *field) override;
4674 table_map used_tables() const override;
4675 Item_result result_type() const override { return field->result_type(); }
4678 }
4679 TYPELIB *get_typelib() const override;
4681 return field->cast_to_int_type();
4682 }
4685 }
4686 longlong val_int_endpoint(bool left_endp, bool *incl_endp) override;
4687 void set_result_field(Field *field_arg) override { result_field = field_arg; }
4689 Field *tmp_table_field(TABLE *) override { return result_field; }
4692 item->base_item_field() != nullptr ? item->base_item_field() : item;
4693 }
4695 return m_base_item_field ? m_base_item_field : this;
4696 }
4697 bool val_date(Date_val *date, my_time_flags_t flags) override;
4698 bool val_time(Time_val *time) override;
4699 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
4700 bool get_timeval(my_timeval *tm, int *warnings) override;
4701 bool is_null() override {
4702 // NOTE: May return true even if maybe_null is not set!
4703 // This can happen if the underlying TABLE did not have a NULL row
4704 // at set_field() time (ie., table->is_null_row() was false),
4705 // but does now.
4706 return field->is_null();
4707 }
4708 Item *get_tmp_table_item(THD *thd) override;
4709 bool collect_item_field_processor(uchar *arg) override;
4710 bool collect_item_field_or_ref_processor(uchar *arg) override;
4712 bool collect_outer_field_processor(uchar *arg) override;
4713 bool add_field_to_set_processor(uchar *arg) override;
4714 bool add_field_to_cond_set_processor(uchar *) override;
4715 bool remove_column_from_bitmap(uchar *arg) override;
4716 bool find_item_in_field_list_processor(uchar *arg) override;
4717 bool find_field_processor(uchar *arg) override {
4718 return pointer_cast<Field *>(arg) == field;
4719 }
4720 bool check_function_as_value_generator(uchar *args) override;
4721 bool mark_field_in_map(uchar *arg) override {
4722 auto mark_field = pointer_cast<Mark_field *>(arg);
4723 bool rc = Item::mark_field_in_map(mark_field, field);
4725 rc |= Item::mark_field_in_map(mark_field, result_field);
4726 return rc;
4727 }
4728 bool used_tables_for_level(uchar *arg) override;
4729 bool check_column_privileges(uchar *arg) override;
4730 bool check_partition_func_processor(uchar *) override { return false; }
4731 void bind_fields() override;
4732 bool is_valid_for_pushdown(uchar *arg) override;
4733 bool check_column_in_window_functions(uchar *arg) override;
4734 bool check_column_in_group_by(uchar *arg) override;
4735 Item *replace_with_derived_expr(uchar *arg) override;
4737 void cleanup() override;
4738 void reset_field();
4739 Item_multi_eq *find_multi_equality(COND_EQUAL *cond_equal) const;
4740 bool subst_argument_checker(uchar **arg) override;
4741 Item *equal_fields_propagator(uchar *arg) override;
4742 Item *replace_item_field(uchar *) override;
4745 return false;
4746 }
4747 Item *replace_equal_field(uchar *) override;
4749 Item_field *field_for_view_update() override { return this; }
4750 bool fix_outer_field(THD *thd, Field **field, Item_ident **ref_field,
4751 bool *complete);
4752 Item *update_value_transformer(uchar *select_arg) override;
4753 void print(const THD *thd, String *str,
4754 enum_query_type query_type) const override;
4755 bool is_outer_field() const override {
4756 assert(fixed);
4758 }
4760 assert(data_type() == MYSQL_TYPE_GEOMETRY);
4761 return field->get_geometry_type();
4762 }
4763 const CHARSET_INFO *charset_for_protocol(void) override {
4764 return field->charset_for_protocol();
4765 }
4766
4767#ifndef NDEBUG
4768 void dbug_print() const {
4769 fprintf(DBUG_FILE, "<field ");
4770 if (field) {
4771 fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
4772 field->dbug_print();
4773 } else
4774 fprintf(DBUG_FILE, "NULL");
4775
4776 fprintf(DBUG_FILE, ", result_field: ");
4777 if (result_field) {
4778 fprintf(DBUG_FILE, "'%s.%s': ", result_field->table->alias,
4781 } else
4782 fprintf(DBUG_FILE, "NULL");
4783 fprintf(DBUG_FILE, ">\n");
4784 }
4785#endif
4786
4787 float get_filtering_effect(THD *thd, table_map filter_for_table,
4788 table_map read_tables,
4789 const MY_BITMAP *fields_to_ignore,
4790 double rows_in_table) override;
4791
4792 /**
4793 Returns the probability for the predicate "col OP <val>" to be
4794 true for a row in the case where no index statistics or range
4795 estimates are available for 'col'.
4796
4797 The probability depends on the number of rows in the table: it is by
4798 default 'default_filter', but never lower than 1/max_distinct_values
4799 (e.g. number of rows in the table, or the number of distinct values
4800 possible for the datatype if the field provides that kind of
4801 information).
4802
4803 @param max_distinct_values The maximum number of distinct values,
4804 typically the number of rows in the table
4805 @param default_filter The default filter for the predicate
4806
4807 @return the estimated filtering effect for this predicate
4808 */
4809
4810 float get_cond_filter_default_probability(double max_distinct_values,
4811 float default_filter) const;
4812
4813 /**
4814 @note that field->table->alias_name_used is reliable only if
4815 thd->lex->need_correct_ident() is true.
4816 */
4817 bool alias_name_used() const override {
4818 return m_alias_of_expr ||
4819 // maybe the qualifying table was given an alias ("t1 AS foo"):
4821 }
4822
4823 bool repoint_const_outer_ref(uchar *arg) override;
4824 bool returns_array() const override { return field && field->is_array(); }
4825 Item *apply_masking_policy(THD *thd) override;
4827
4828 void set_can_use_prefix_key() override { can_use_prefix_key = true; }
4829
4830 bool replace_field_processor(uchar *arg) override;
4831 bool strip_db_table_name_processor(uchar *) override;
4832
4833 /**
4834 Checks if the current object represents an asterisk select list item
4835
4836 @returns false if a regular column reference, true if an asterisk
4837 select list item.
4838 */
4839 virtual bool is_asterisk() const { return false; }
4840 /// See \c m_protected_by_any_value
4842
4843 void compute_cost(CostOfItem *root_cost) const override {
4844 field->add_to_cost(root_cost);
4845 }
4846};
4847
4848/**
4849 Represents [schema.][table.]* in a select list
4850
4851 Item_asterisk is used to insert placeholder objects for the special
4852 select list item * (asterisk) into AST.
4853 Those placeholder objects are to be substituted later with e.g. a list of real
4854 table columns by a resolver (@see setup_wild).
4855
4856 @todo The parent class Item_field is redundant. Refactor setup_wild() to
4857 replace Item_field with a simpler one.
4858*/
4861
4862 public:
4863 /**
4864 Constructor
4865
4866 @param pos Location of the * (asterisk) lexeme.
4867 @param opt_schema_name Schema name or nullptr.
4868 @param opt_table_name Table name or nullptr.
4869 */
4870 Item_asterisk(const POS &pos, const char *opt_schema_name,
4871 const char *opt_table_name)
4872 : super(pos, opt_schema_name, opt_table_name, "*") {}
4873
4874 bool do_itemize(Parse_context *pc, Item **res) override;
4875 bool fix_fields(THD *, Item **) override {
4876 assert(false); // should never happen: see setup_wild()
4877 return true;
4878 }
4879 bool is_asterisk() const override { return true; }
4880};
4881
4882// See if the provided item points to a reachable field (one that belongs to a
4883// table within 'reachable_tables'). If not, go through the list of 'equal'
4884// items in the item and see if we have a field that is reachable. If any such
4885// field is found, set "found" to true and create a new Item_field that points
4886// to this reachable field and return it if we are asked to "replace". If the
4887// provided item is already reachable, or if we cannot find a reachable field,
4888// return the provided item unchanged and set "found" to false. This is used
4889// when creating a hash join iterator, where the join condition may point to a
4890// non-reachable field due to multi-equality propagation during optimization.
4891// (Ideally, the optimizer should not set up such condition in the first place.
4892// This is difficult, if not impossible, to accomplish, given that the plan
4893// created by the optimizer does not map 100% to the iterator executor.) Note
4894// that if the field is not reachable, and we cannot find a reachable field, we
4895// provided field is returned unchanged. The effect is that the hash join will
4896// degrade into a nested loop.
4897Item_field *FindEqualField(Item_field *item_field, table_map reachable_tables,
4898 bool replace, bool *found);
4899
4902
4903 void init() {
4905 null_value = true;
4906 fixed = true;
4907 }
4908
4909 protected:
4911 bool no_conversions) override;
4912
4913 public:
4915 init();
4916 item_name = NAME_STRING("NULL");
4917 }
4918 explicit Item_null(const POS &pos) : super(pos) {
4919 init();
4920 item_name = NAME_STRING("NULL");
4921 }
4922
4923 Item_null(const Name_string &name_par) {
4924 init();
4925 item_name = name_par;
4926 }
4927
4928 enum Type type() const override { return NULL_ITEM; }
4929 bool eq(const Item *item) const override;
4930 double val_real() override;
4931 longlong val_int() override;
4932 longlong val_date_temporal() override { return val_int(); }
4933 String *val_str(String *str) override;
4934 my_decimal *val_decimal(my_decimal *) override;
4935 bool val_date(Date_val *, my_time_flags_t) override { return true; }
4936 bool val_time(Time_val *) override { return true; }
4937 bool val_datetime(Datetime_val *, my_time_flags_t) override { return true; }
4938 bool val_json(Json_wrapper *wr) override;
4939 bool send(Protocol *protocol, String *str) override;
4940 Item_result result_type() const override { return STRING_RESULT; }
4941 Item *clone_item() const override { return new Item_null(item_name); }
4942 bool is_null() override { return true; }
4943
4944 void print(const THD *, String *str,
4945 enum_query_type query_type) const override {
4946 str->append(query_type == QT_NORMALIZED_FORMAT ? "?" : "NULL");
4947 }
4948 uint64_t hash() override;
4949
4950 bool check_partition_func_processor(uchar *) override { return false; }
4951};
4952
4953/// Dynamic parameters used as placeholders ('?') inside prepared statements
4954
4955class Item_param final : public Item, private Settable_routine_parameter {
4956 typedef Item super;
4957
4958 protected:
4960 bool no_conversions) override;
4961
4962 public:
4975
4977 m_param_state = state;
4978 }
4979
4981
4982 void mark_json_as_scalar() override { m_json_as_scalar = true; }
4983
4984 /*
4985 A buffer for string and long data values. Historically all allocated
4986 values returned from val_str() were treated as eligible to
4987 modification. I. e. in some cases Item_func_concat can append it's
4988 second argument to return value of the first one. Because of that we
4989 can't return the original buffer holding string data from val_str(),
4990 and have to have one buffer for data and another just pointing to
4991 the data. This is the latter one and it's returned from val_str().
4992 Can not be declared inside the union as it's not a POD type.
4993 */
4999 union {
5001 double real;
5003
5004 private:
5005 /**
5006 True if type of parameter is inherited from parent object (like a typecast).
5007 Reprepare of statement will not change this type.
5008 E.g, we have CAST(? AS DOUBLE), the parameter gets data type
5009 MYSQL_TYPE_DOUBLE and m_type_inherited is set true.
5010 */
5011 bool m_type_inherited{false};
5012 /**
5013 True if type of parameter has been pinned, attempt to use an incompatible
5014 actual type will cause error (no repreparation occurs), and value is
5015 subject to range check. This is used when the parameter is in a context
5016 where its type is imposed. For example, in LIMIT ?, we assign
5017 data_type() == integer, unsigned; and the provided value must be
5018 convertible to unsigned integer: passing a DOUBLE, instead of causing a
5019 repreparation as for an ordinary parameter, will cause an error; passing
5020 integer '-1' will also cause an error.
5021 */
5022 bool m_type_pinned{false};
5023 /**
5024 Parameter objects have a rather complex handling of data type, in order
5025 to consistently handle required type conversion semantics. There are
5026 three data type properties involved:
5027
5028 1. The data_type() property contains the desired type of the parameter
5029 value, as defined by an explicit CAST, the operation the parameter
5030 is part of, and/or the context given by other values and expressions.
5031 After implicit repreparation it may also be assigned from provided
5032 parameter values.
5033
5034 2. The data_type_source() property is the data type of the parameter value,
5035 as given by the supplied user variable or from the protocol buffer.
5036
5037 3. The data_type_actual() property is the data type of the parameter value,
5038 after possible conversion from the source data type.
5039 Conversions may involve
5040 - Character set conversion of string value.
5041 - Conversion from string or number into temporal value, if the
5042 resolved data type is a temporal.
5043 - Conversion from string to number, if the resolved data type is numeric.
5044
5045 In addition, each data type property may have extra attributes to enforce
5046 correct character set, collation and signedness of integers.
5047 */
5048 /**
5049 The "source" data type of the provided parameter.
5050 Used when the parameter comes through protocol buffers.
5051 Notice that signedness of integers is stored in m_unsigned_actual.
5052 */
5054 /**
5055 The actual data type of the parameter value provided by the user.
5056 For example:
5057
5058 PREPARE s FROM "SELECT ?=3e0";
5059
5060 makes Item_param->data_type() be MYSQL_TYPE_DOUBLE ; then:
5061
5062 SET @a='1';
5063 EXECUTE s USING @a;
5064
5065 data_type() is still MYSQL_TYPE_DOUBLE, while data_type_source() is
5066 MYSQL_TYPE_VARCHAR and data_type_actual() is MYSQL_TYPE_VARCHAR.
5067 Compatibility of data_type() and data_type_actual() is later tested
5068 in check_parameter_types().
5069 Only a limited set of field types are possible values:
5070 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_DOUBLE,
5071 MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
5072 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NULL, MYSQL_TYPE_INVALID
5073 */
5075 /// Used when actual value is integer to indicate whether value is unsigned
5077 /**
5078 The character set and collation of the source parameter value.
5079 Ignored if not a string value.
5080 - If parameter value is sent over the protocol: the client collation
5081 - If parameter value is a user variable: the variable's collation
5082 */
5084 /**
5085 The character set and collation of the value stored in str_value, possibly
5086 after being converted from the m_collation_source collation.
5087 Ignored if not a string value.
5088 - If the derived collation is binary, the connection collation.
5089 - Otherwise, the derived collation (@see Item::collation).
5090 */
5092 /// Result type of parameter. @todo replace with type_to_result(data_type()
5094 /**
5095 m_param_state is used to indicate that no parameter value is available
5096 with NO_VALUE, or a NULL value is available (NULL_VALUE), or the actual
5097 type of the provided parameter value. Usually, this matches m_actual_type,
5098 but in the case of pinned data types, this is matching the resolved data
5099 type of the parameter. m_param_state reflects the type of the value stored
5100 in Item_param::value.
5101 */
5103
5104 /**
5105 If true, when retrieving JSON data, attempt to interpret a string value as
5106 a scalar JSON value, otherwise interpret it as a JSON object.
5107 */
5108 bool m_json_as_scalar{false};
5109
5110 /*
5111 data_type() is used when this item is used in a temporary table.
5112 This is NOT placeholder metadata sent to client, as this value
5113 is assigned after sending metadata (in setup_one_conversion_function).
5114 For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
5115 in result set and placeholders metadata, no matter what type you will
5116 supply for this placeholder in mysql_stmt_execute.
5117 */
5118
5119 public:
5120 /*
5121 Offset of placeholder inside statement text. Used to create
5122 no-placeholders version of this statement for the binary log.
5123 */
5125
5126 Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg);
5127
5128 bool do_itemize(Parse_context *pc, Item **item) override;
5129
5130 Item_result result_type() const override { return m_result_type; }
5131 enum Type type() const override { return PARAM_ITEM; }
5132
5133 /// Set the currently resolved data type for this parameter as inherited
5134 void set_data_type_inherited() override { m_type_inherited = true; }
5135
5136 /// @returns true if data type for this parameter is inherited.
5137 bool is_type_inherited() const { return m_type_inherited; }
5138
5139 /// Pin the currently resolved data type for this parameter.
5140 void pin_data_type() override { m_type_pinned = true; }
5141
5142 /// @returns true if data type for this parameter is pinned.
5143 bool is_type_pinned() const { return m_type_pinned; }
5144
5145 /// @returns true if actual data value (integer) is unsigned
5146 bool is_unsigned_actual() const { return m_unsigned_actual; }
5147
5150 m_collation_source = coll;
5151 }
5154 m_collation_actual = coll;
5155 }
5156 /// @returns the source collation of the supplied string parameter
5158
5159 /// @returns the actual collation of the supplied string parameter
5162 return m_collation_actual;
5163 }
5164 bool fix_fields(THD *thd, Item **ref) override;
5165
5166 bool propagate_type(THD *thd, const Type_properties &type) override;
5167
5168 double val_real() override;
5169 longlong val_int() override;
5170 my_decimal *val_decimal(my_decimal *) override;
5171 String *val_str(String *) override;
5172 bool val_json(Json_wrapper *result) override;
5173 bool val_date(Date_val *date, my_time_flags_t flags) override;
5174 bool val_time(Time_val *time) override;
5175 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
5178 m_unsigned_actual = unsigned_val;
5179 }
5180 // For use with non-integer field types only
5183 }
5184 /// For use with all field types, especially integer types
5187 m_unsigned_actual = unsigned_val;
5188 }
5190
5192
5194 return data_type_actual();
5195 }
5196
5197 void set_null();
5198 void set_int(longlong i);
5199 void set_int(ulonglong i);
5200 void set_double(double i);
5201 void set_decimal(const char *str, ulong length);
5202 void set_decimal(const my_decimal *dv);
5203 bool set_str(const char *str, size_t length);
5204 bool set_longdata(const char *str, ulong length);
5206 void set_time(Time_val time);
5207 void set_date(Date_val date);
5208 void set_datetime(Datetime_val dt);
5209 bool set_from_user_var(THD *thd, const user_var_entry *entry);
5211 void reset();
5212
5213 const String *query_val_str(const THD *thd, String *str) const;
5214
5215 bool convert_value();
5216
5217 /*
5218 Parameter is treated as constant during execution, thus it will not be
5219 evaluated during preparation.
5220 */
5221 table_map used_tables() const override { return INNER_TABLE_BIT; }
5222 void print(const THD *thd, String *str,
5223 enum_query_type query_type) const override;
5224 uint64_t hash() override;
5225 bool is_null() override {
5226 assert(m_param_state != NO_VALUE);
5227 return m_param_state == NULL_VALUE;
5228 }
5229
5230 Item *clone_item() const override;
5231 /*
5232 Implement by-value equality evaluation if parameter value
5233 is set and is a basic constant (integer, real or string).
5234 Otherwise return false.
5235 */
5236 bool eq(const Item *item) const override;
5238 bool is_non_const_over_literals(uchar *) override { return true; }
5239 /**
5240 This should be called after any modification done to this Item, to
5241 propagate the said modification to all its clones.
5242 */
5243 void sync_clones();
5244 bool add_clone(Item_param *i) { return m_clones.push_back(i); }
5245
5246 private:
5248 return this;
5249 }
5250
5251 bool set_value(THD *, sp_rcontext *, Item **it) override;
5252
5253 void set_out_param_info(Send_field *info) override;
5254
5255 public:
5256 const Send_field *get_out_param_info() const override;
5257
5258 void make_field(Send_field *field) override;
5259
5262 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5263 func_arg->err_code = func_arg->get_unnamed_function_error_code();
5264 return true;
5265 }
5266 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
5267 // It is ok to push down a condition like "column > PS_parameter".
5268 return false;
5269 }
5270
5271 private:
5273 /**
5274 If a query expression's text QT or text of a condition (CT) that is pushed
5275 down to a derived table, containing a parameter, is internally duplicated
5276 and parsed twice (@see reparse_common_table_expression, parse_expression),
5277 the first parsing will create an Item_param I, and the re-parsing, which
5278 parses a forged "(QT)" parse-this-CTE type of statement or parses a
5279 forged condition "(CT)", will create an Item_param J. J should not exist:
5280 - from the point of view of logging: it is not in the original query so it
5281 should not be substituted in the query written to logs (in insert_params()
5282 if with_log is true).
5283 - from the POV of the user:
5284 * user provides one single value for I, not one for I and one for J.
5285 * user expects mysql_stmt_param_count() to return 1, not 2 (count is
5286 sent by the server in send_prep_stmt()).
5287 That is why J is part neither of LEX::param_list, nor of param_array; it
5288 is considered an inferior clone of I; I::m_clones contains J.
5289 The connection between I and J is made once, by comparing their
5290 byte position in the statement, in Item_param::itemize().
5291 J gets its value from I: @see Item_param::sync_clones.
5292 */
5294};
5295
5296class Item_int : public Item_num {
5298
5299 public:
5300 static Item_int *narrow(Item *item);
5301
5304 : value((longlong)i) {
5307 fixed = true;
5308 }
5310 : super(pos), value((longlong)i) {
5313 fixed = true;
5314 }
5318 fixed = true;
5319 }
5321 : value((longlong)i) {
5323 unsigned_flag = true;
5325 fixed = true;
5326 }
5327 Item_int(const Item_int *item_arg) {
5328 set_data_type(item_arg->data_type());
5329 value = item_arg->value;
5330 item_name = item_arg->item_name;
5331 max_length = item_arg->max_length;
5332 fixed = true;
5333 }
5334 Item_int(const Name_string &name_arg, longlong i, uint length) : value(i) {
5337 item_name = name_arg;
5338 fixed = true;
5339 }
5340 Item_int(const POS &pos, const Name_string &name_arg, longlong i, uint length)
5341 : super(pos), value(i) {
5344 item_name = name_arg;
5345 fixed = true;
5346 }
5347 Item_int(const char *str_arg, uint length) {
5349 init(str_arg, length);
5350 }
5351 Item_int(const POS &pos, const char *str_arg, uint length) : super(pos) {
5353 init(str_arg, length);
5354 }
5355
5356 Item_int(const POS &pos, const LEX_STRING &num, int dummy_error = 0)
5357 : Item_int(pos, num, my_strtoll10(num.str, nullptr, &dummy_error),
5358 static_cast<uint>(num.length)) {}
5359
5360 private:
5361 void init(const char *str_arg, uint length);
5364 if (!unsigned_flag && value >= 0) max_length++;
5365 }
5366
5367 protected:
5369 bool no_conversions) override;
5370
5371 public:
5372 enum Type type() const override { return INT_ITEM; }
5373 Item_result result_type() const override { return INT_RESULT; }
5374 longlong val_int() override {
5375 assert(fixed);
5376 return value;
5377 }
5378 double val_real() override {
5379 assert(fixed);
5380 return static_cast<double>(value);
5381 }
5382 my_decimal *val_decimal(my_decimal *) override;
5383 String *val_str(String *) override;
5384 bool val_date(Date_val *date, my_time_flags_t flags) override {
5385 return get_date_from_int(date, flags);
5386 }
5387 bool val_time(Time_val *time) override { return get_time_from_int(time); }
5389 return get_datetime_from_int(dt, flags);
5390 }
5391 Item *clone_item() const override { return new Item_int(this); }
5392 void print(const THD *thd, String *str,
5393 enum_query_type query_type) const override;
5394 uint64_t hash() override;
5395 Item_num *neg() override {
5396 value = -value;
5397 return this;
5398 }
5399 uint decimal_precision() const override {
5400 return static_cast<uint>(max_length - 1);
5401 }
5402 bool eq(const Item *item) const override;
5403 bool check_partition_func_processor(uchar *) override { return false; }
5404 bool check_function_as_value_generator(uchar *) override { return false; }
5405};
5406
5407/**
5408 Item_int with value==0 and length==1
5409*/
5410class Item_int_0 final : public Item_int {
5411 public:
5413 explicit Item_int_0(const POS &pos) : Item_int(pos, NAME_STRING("0"), 0, 1) {}
5414};
5415
5416/*
5417 Item_temporal is used to store numeric representation
5418 of datetime values for queries like:
5419
5420 WHERE datetime_column NOT IN
5421 ('2006-04-25 10:00:00','2006-04-25 10:02:00', ...);
5422
5423 and for SHOW/INFORMATION_SCHEMA purposes (see sql_show.cc)
5424
5425 TS-TODO: Can't we use Item_time_literal, Item_date_literal,
5426 TS-TODO: and Item_datetime_literal for this purpose?
5427*/
5428class Item_temporal final : public Item_int {
5429 protected:
5431 bool no_conversions) override;
5432
5433 public:
5435 assert(is_temporal_type(field_type_arg));
5436 assert(field_type_arg != MYSQL_TYPE_TIME &&
5437 field_type_arg != MYSQL_TYPE_DATE);
5438 set_data_type(field_type_arg);
5439 }
5440 Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg,
5441 longlong i, uint length)
5442 : Item_int(i) {
5443 assert(is_temporal_type(field_type_arg));
5444 assert(field_type_arg != MYSQL_TYPE_TIME &&
5445 field_type_arg != MYSQL_TYPE_DATE);
5446 set_data_type(field_type_arg);
5448 item_name = name_arg;
5449 fixed = true;
5450 }
5451 Item *clone_item() const override {
5452 return new Item_temporal(data_type(), value);
5453 }
5454 longlong val_date_temporal() override { return val_int(); }
5456 assert(false);
5457 return false;
5458 }
5459 bool val_time(Time_val *) override {
5460 assert(false);
5461 return false;
5462 }
5464 assert(false);
5465 return false;
5466 }
5467};
5468
5469class Item_uint : public Item_int {
5470 protected:
5472 bool no_conversions) override;
5473
5474 public:
5475 Item_uint(const char *str_arg, uint length) : Item_int(str_arg, length) {
5476 unsigned_flag = true;
5477 }
5478 Item_uint(const POS &pos, const char *str_arg, uint length)
5479 : Item_int(pos, str_arg, length) {
5480 unsigned_flag = true;
5481 }
5482
5484 Item_uint(const Name_string &name_arg, longlong i, uint length)
5485 : Item_int(name_arg, i, length) {
5486 unsigned_flag = true;
5487 }
5488 double val_real() override {
5489 assert(fixed);
5490 return ulonglong2double(static_cast<ulonglong>(value));
5491 }
5492 String *val_str(String *) override;
5493
5494 Item *clone_item() const override {
5495 return new Item_uint(item_name, value, max_length);
5496 }
5497 void print(const THD *thd, String *str,
5498 enum_query_type query_type) const override;
5499 uint64_t hash() override;
5500 Item_num *neg() override;
5501 uint decimal_precision() const override { return max_length; }
5502};
5503
5504/* decimal (fixed point) constant */
5505class Item_decimal : public Item_num {
5507
5508 protected:
5511 bool no_conversions) override;
5512
5513 public:
5514 Item_decimal(const POS &pos, const char *str_arg, uint length,
5515 const CHARSET_INFO *charset);
5516 Item_decimal(const Name_string &name_arg, const my_decimal *val_arg,
5517 uint decimal_par, uint length);
5518 Item_decimal(my_decimal *value_par);
5519 Item_decimal(longlong val, bool unsig);
5520 Item_decimal(double val);
5521 Item_decimal(const uchar *bin, int precision, int scale);
5522
5523 enum Type type() const override { return DECIMAL_ITEM; }
5524 Item_result result_type() const override { return DECIMAL_RESULT; }
5525 longlong val_int() override;
5526 double val_real() override;
5527 String *val_str(String *) override;
5529 bool val_date(Date_val *date, my_time_flags_t flags) override {
5530 return get_date_from_decimal(date, flags);
5531 }
5532 bool val_time(Time_val *time) override { return get_time_from_decimal(time); }
5534 return get_datetime_from_decimal(dt, flags);
5535 }
5536 Item *clone_item() const override {
5538 }
5539 void print(const THD *thd, String *str,
5540 enum_query_type query_type) const override;
5541 uint64_t hash() override;
5542 Item_num *neg() override {
5545 return this;
5546 }
5547 uint decimal_precision() const override { return decimal_value.precision(); }
5548 bool eq(const Item *item) const override;
5549 void set_decimal_value(const my_decimal *value_par);
5550 bool check_partition_func_processor(uchar *) override { return false; }
5551};
5552
5553class Item_float : public Item_num {
5555
5557
5558 public:
5559 double value;
5560 // Item_real() :value(0) {}
5561 Item_float(const char *str_arg, uint length) { init(str_arg, length); }
5562 Item_float(const POS &pos, const char *str_arg, uint length) : super(pos) {
5563 init(str_arg, length);
5564 }
5565
5566 Item_float(const Name_string name_arg, double val_arg, uint decimal_par,
5567 uint length)
5568 : value(val_arg) {
5569 presentation = name_arg;
5570 item_name = name_arg;
5572 decimals = (uint8)decimal_par;
5574 fixed = true;
5575 }
5576 Item_float(const POS &pos, const Name_string name_arg, double val_arg,
5577 uint decimal_par, uint length)
5578 : super(pos), value(val_arg) {
5579 presentation = name_arg;
5580 item_name = name_arg;
5582 decimals = (uint8)decimal_par;
5584 fixed = true;
5585 }
5586
5587 Item_float(double value_par, uint decimal_par) : value(value_par) {
5589 decimals = (uint8)decimal_par;
5590 max_length = float_length(decimal_par);
5591 fixed = true;
5592 }
5593
5594 private:
5595 void init(const char *str_arg, uint length);
5596
5597 protected:
5599 bool no_conversions) override;
5600
5601 public:
5602 enum Type type() const override { return REAL_ITEM; }
5603 double val_real() override {
5604 assert(fixed);
5605 return value;
5606 }
5607 longlong val_int() override {
5608 assert(fixed);
5609 if (value <= LLONG_MIN) {
5610 return LLONG_MIN;
5611 } else if (value > LLONG_MAX_DOUBLE) {
5612 return LLONG_MAX;
5613 }
5614 return (longlong)rint(value);
5615 }
5616 String *val_str(String *) override;
5617 my_decimal *val_decimal(my_decimal *) override;
5618 bool val_date(Date_val *date, my_time_flags_t flags) override {
5619 return get_date_from_real(date, flags);
5620 }
5621 bool val_time(Time_val *time) override { return get_time_from_real(time); }
5623 return get_datetime_from_real(dt, flags);
5624 }
5625 Item *clone_item() const override {
5627 }
5628 Item_num *neg() override {
5629 value = -value;
5630 return this;
5631 }
5632 void print(const THD *thd, String *str,
5633 enum_query_type query_type) const override;
5634 uint64_t hash() override;
5635 bool eq(const Item *item) const override;
5636};
5637
5638class Item_func_pi : public Item_float {
5640
5641 public:
5642 Item_func_pi(const POS &pos)
5643 : Item_float(pos, null_name_string, M_PI, 6, 8),
5644 func_name(NAME_STRING("pi()")) {}
5645
5646 void print(const THD *, String *str, enum_query_type) const override {
5647 str->append(func_name);
5648 }
5649};
5650
5653
5654 protected:
5655 explicit Item_string(const POS &pos) : super(pos), m_cs_specified(false) {
5657 }
5658
5659 void init(const char *str, size_t length, const CHARSET_INFO *cs,
5660 Derivation dv, uint repertoire) {
5663 collation.set(cs, dv, repertoire);
5664 /*
5665 We have to have a different max_length than 'length' here to
5666 ensure that we get the right length if we do use the item
5667 to create a new table. In this case max_length must be the maximum
5668 number of chars for a string of this type because we in Create_field::
5669 divide the max_length with mbmaxlen).
5670 */
5671 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5674 // it is constant => can be used without fix_fields (and frequently used)
5675 fixed = true;
5676 /*
5677 Check if the string has any character that can't be
5678 interpreted using the relevant charset.
5679 */
5680 check_well_formed_result(&str_value, false, false);
5681 }
5683 bool no_conversions) override;
5684
5685 public:
5686 /* Create from a string, set name from the string itself. */
5687 Item_string(const char *str, size_t length, const CHARSET_INFO *cs,
5689 uint repertoire = MY_REPERTOIRE_UNICODE30)
5690 : m_cs_specified(false) {
5691 init(str, length, cs, dv, repertoire);
5692 }
5693 Item_string(const POS &pos, const char *str, size_t length,
5695 uint repertoire = MY_REPERTOIRE_UNICODE30)
5696 : super(pos), m_cs_specified(false) {
5697 init(str, length, cs, dv, repertoire);
5698 }
5699
5700 /* Just create an item and do not fill string representation */
5702 : m_cs_specified(false) {
5703 collation.set(cs, dv);
5705 max_length = 0;
5707 fixed = true;
5708 }
5709
5710 /* Create from the given name and string. */
5711 Item_string(const Name_string name_par, const char *str, size_t length,
5713 uint repertoire = MY_REPERTOIRE_UNICODE30)
5714 : m_cs_specified(false) {
5716 collation.set(cs, dv, repertoire);
5718 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5719 item_name = name_par;
5721 // it is constant => can be used without fix_fields (and frequently used)
5722 fixed = true;
5723 }
5724 Item_string(const POS &pos, const Name_string name_par, const char *str,
5725 size_t length, const CHARSET_INFO *cs,
5727 uint repertoire = MY_REPERTOIRE_UNICODE30)
5728 : super(pos), m_cs_specified(false) {
5730 collation.set(cs, dv, repertoire);
5732 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5733 item_name = name_par;
5735 // it is constant => can be used without fix_fields (and frequently used)
5736 fixed = true;
5737 }
5738
5739 /* Create from the given name and string. */
5740 Item_string(const POS &pos, const Name_string name_par,
5741 const LEX_CSTRING &literal, const CHARSET_INFO *cs,
5743 uint repertoire = MY_REPERTOIRE_UNICODE30)
5744 : super(pos), m_cs_specified(false) {
5745 str_value.set_or_copy_aligned(literal.str ? literal.str : "",
5746 literal.str ? literal.length : 0, cs);
5747 collation.set(cs, dv, repertoire);
5749 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5750 item_name = name_par;
5752 // it is constant => can be used without fix_fields (and frequently used)
5753 fixed = true;
5754 }
5755
5756 /*
5757 This is used in stored procedures to avoid memory leaks and
5758 does a deep copy of its argument.
5759 */
5760 void set_str_with_copy(const char *str_arg, uint length_arg) {
5761 str_value.copy(str_arg, length_arg, collation.collation);
5762 max_length = static_cast<uint32>(str_value.numchars() *
5764 }
5765 bool set_str_with_copy(const char *str_arg, uint length_arg,
5766 const CHARSET_INFO *from_cs);
5767 /// Update collation of string value to be according to item's collation
5769
5773 }
5774 enum Type type() const override { return STRING_ITEM; }
5775 double val_real() override;
5776 longlong val_int() override;
5777 String *val_str(String *) override {
5778 assert(fixed);
5779 return &str_value;
5780 }
5781 my_decimal *val_decimal(my_decimal *) override;
5782 bool val_date(Date_val *date, my_time_flags_t flags) override {
5783 return get_date_from_string(date, flags);
5784 }
5785 bool val_time(Time_val *time) override { return get_time_from_string(time); }
5787 return get_datetime_from_string(dt, flags);
5788 }
5789 Item_result result_type() const override { return STRING_RESULT; }
5790 bool eq(const Item *item) const override;
5791 bool eq_binary(const Item_string *item) const {
5792 return !stringcmp(&str_value, &item->str_value);
5793 }
5794 Item *clone_item() const override {
5795 return new Item_string(static_cast<Name_string>(item_name), str_value.ptr(),
5797 }
5798 inline void append(char *str, size_t length) {
5800 max_length = static_cast<uint32>(str_value.numchars() *
5802 }
5803 void print(const THD *thd, String *str,
5804 enum_query_type query_type) const override;
5805 uint64_t hash() override;
5806 bool check_partition_func_processor(uchar *) override { return false; }
5807
5808 /**
5809 Return true if character-set-introducer was explicitly specified in the
5810 original query for this item (text literal).
5811
5812 This operation is to be called from Item_string::print(). The idea is
5813 that when a query is generated (re-constructed) from the Item-tree,
5814 character-set-introducers should appear only for those literals, where
5815 they were explicitly specified by the user. Otherwise, that may lead to
5816 loss collation information (character set introducers implies default
5817 collation for the literal).
5818
5819 Basically, that makes sense only for views and hopefully will be gone
5820 one day when we start using original query as a view definition.
5821
5822 @return This operation returns the value of m_cs_specified attribute.
5823 @retval true if character set introducer was explicitly specified in
5824 the original query.
5825 @retval false otherwise.
5826 */
5827 inline bool is_cs_specified() const { return m_cs_specified; }
5828
5829 /**
5830 Set the value of m_cs_specified attribute.
5831
5832 m_cs_specified attribute shows whether character-set-introducer was
5833 explicitly specified in the original query for this text literal or
5834 not. The attribute makes sense (is used) only for views.
5835
5836 This operation is to be called from the parser during parsing an input
5837 query.
5838 */
5839 inline void set_cs_specified(bool cs_specified) {
5840 m_cs_specified = cs_specified;
5841 }
5842
5844
5845 private:
5847};
5848
5850 const char *cptr, const char *end,
5851 int unsigned_target);
5852double double_from_string_with_check(const CHARSET_INFO *cs, const char *cptr,
5853 const char *end);
5854
5857
5858 public:
5859 Item_static_string_func(const Name_string &name_par, const char *str,
5860 size_t length, const CHARSET_INFO *cs,
5863 func_name(name_par) {}
5864 Item_static_string_func(const POS &pos, const Name_string &name_par,
5865 const char *str, size_t length,
5866 const CHARSET_INFO *cs,
5868 : Item_string(pos, null_name_string, str, length, cs, dv),
5869 func_name(name_par) {}
5870
5871 void print(const THD *, String *str, enum_query_type) const override {
5872 str->append(func_name);
5873 }
5874 uint64_t hash() override;
5875 bool check_partition_func_processor(uchar *) override { return true; }
5878 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5879 func_arg->banned_function_name = func_name.ptr();
5880 return true;
5881 }
5882};
5883
5884/* for show tables */
5886 public:
5888 const CHARSET_INFO *cs = nullptr)
5889 : Item_string(name, NullS, 0, cs) {
5890 max_length = static_cast<uint32>(length);
5891 }
5892};
5893
5895 public:
5896 Item_blob(const char *name, size_t length)
5898 &my_charset_bin) {
5900 }
5901 enum Type type() const override { return STRING_ITEM; }
5904 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5905 func_arg->err_code = func_arg->get_unnamed_function_error_code();
5906 return true;
5907 }
5908};
5909
5910/**
5911 Item_empty_string -- is a utility class to put an item into List<Item>
5912 which is then used in protocol.send_result_set_metadata() when sending SHOW
5913 output to the client.
5914*/
5915
5917 public:
5918 Item_empty_string(const char *header, size_t length,
5919 const CHARSET_INFO *cs = nullptr)
5921 Name_string(header, strlen(header)), 0,
5924 }
5925 void make_field(Send_field *field) override;
5926};
5927
5929 public:
5930 Item_return_int(const char *name_arg, uint length,
5931 enum_field_types field_type_arg, longlong value_arg = 0)
5932 : Item_int(Name_string(name_arg, name_arg ? strlen(name_arg) : 0),
5933 value_arg, length) {
5934 set_data_type(field_type_arg);
5935 unsigned_flag = true;
5936 }
5937};
5938
5941
5942 protected:
5944 bool no_conversions) override;
5945
5946 public:
5948 explicit Item_hex_string(const POS &pos) : super(pos) {
5950 }
5951
5952 Item_hex_string(const POS &pos, const LEX_STRING &literal);
5953
5954 enum Type type() const override { return HEX_BIN_ITEM; }
5955 double val_real() override {
5956 assert(fixed);
5957 return (double)(ulonglong)Item_hex_string::val_int();
5958 }
5959 longlong val_int() override;
5960 Item *clone_item() const override;
5961
5962 String *val_str(String *) override {
5963 assert(fixed);
5964 return &str_value;
5965 }
5966 my_decimal *val_decimal(my_decimal *) override;
5967 bool val_date(Date_val *date, my_time_flags_t flags) override {
5968 return get_date_from_string(date, flags);
5969 }
5970 bool val_time(Time_val *time) override { return get_time_from_string(time); }
5972 return get_datetime_from_string(dt, flags);
5973 }
5974 Item_result result_type() const override { return STRING_RESULT; }
5976 return INT_RESULT;
5977 }
5978 Item_result cast_to_int_type() const override { return INT_RESULT; }
5979 void print(const THD *thd, String *str,
5980 enum_query_type query_type) const override;
5981 uint64_t hash() override;
5982 bool eq(const Item *item) const override;
5983 bool check_partition_func_processor(uchar *) override { return false; }
5984 static LEX_CSTRING make_hex_str(const char *str, size_t str_length);
5985 uint decimal_precision() const override;
5986
5987 private:
5988 void hex_string_init(const char *str, uint str_length);
5989};
5990
5991class Item_bin_string final : public Item_hex_string {
5993
5994 public:
5995 Item_bin_string(const char *str, size_t str_length) {
5996 bin_string_init(str, str_length);
5997 }
5998 Item_bin_string(const POS &pos, const LEX_STRING &literal) : super(pos) {
5999 bin_string_init(literal.str, literal.length);
6000 }
6001
6002 static LEX_CSTRING make_bin_str(const char *str, size_t str_length);
6003
6004 private:
6005 void bin_string_init(const char *str, size_t str_length);
6006};
6007
6008/**
6009 Item with result field.
6010
6011 It adds to an Item a "result_field" Field member. This is for an item which
6012 may have a result (e.g. Item_func), and may store this result into a field;
6013 usually this field is a column of an internal temporary table. So the
6014 function may be evaluated by save_in_field(), storing result into
6015 result_field in tmp table. Then this result can be copied from tmp table to
6016 a following tmp table (e.g. GROUP BY table then ORDER BY table), or to a row
6017 buffer and back, as we want to avoid multiple evaluations of the Item, first
6018 because of performance, second because that evaluation may have side
6019 effects, e.g. SLEEP, GET_LOCK, RAND, window functions doing
6020 accumulations...
6021 Item_field and Item_ref also have a "result_field" for a similar goal.
6022 Literals don't need such "result_field" as their value is readily
6023 available.
6024*/
6025class Item_result_field : public Item {
6026 protected:
6027 Field *result_field{nullptr}; /* Save result here */
6028 public:
6030 explicit Item_result_field(const POS &pos) : Item(pos) {}
6031
6032 // Constructor used for Item_sum/Item_cond_and/or (see Item comment)
6034 : Item(thd, item), result_field(item->result_field) {}
6036 Field *tmp_table_field(TABLE *) override { return result_field; }
6037 table_map used_tables() const override { return 1; }
6038
6039 /**
6040 Resolve type-related information for this item, such as result field type,
6041 maximum size, precision, signedness, character set and collation.
6042 Also check compatibility of argument types and return error when applicable.
6043 Also adjust nullability when applicable.
6044
6045 @param thd thread handler
6046 @returns false if success, true if error
6047 */
6048 virtual bool resolve_type(THD *thd) = 0;
6049
6050 void set_result_field(Field *field) override { result_field = field; }
6051 bool is_result_field() const override { return true; }
6052 Field *get_result_field() const override { return result_field; }
6053
6054 void cleanup() override;
6055 bool check_function_as_value_generator(uchar *) override { return false; }
6056 bool mark_field_in_map(uchar *arg) override {
6057 bool rc = Item::mark_field_in_map(arg);
6058 if (result_field) // most likely result_field will be read too
6059 rc |= Item::mark_field_in_map(pointer_cast<Mark_field *>(arg),
6060 result_field);
6061 return rc;
6062 }
6063
6065 if (realval < LLONG_MIN || realval > LLONG_MAX_DOUBLE) {
6067 return error_int();
6068 }
6069 return llrint(realval);
6070 }
6071
6072 void raise_numeric_overflow(const char *type_name);
6073
6075 raise_numeric_overflow("DOUBLE");
6076 return 0.0;
6077 }
6078
6080 raise_numeric_overflow(unsigned_flag ? "BIGINT UNSIGNED" : "BIGINT");
6081 return 0;
6082 }
6083
6085 raise_numeric_overflow(unsigned_flag ? "DECIMAL UNSIGNED" : "DECIMAL");
6086 return E_DEC_OVERFLOW;
6087 }
6088};
6089
6090class Item_ref : public Item_ident {
6091 protected:
6092 void set_properties();
6094 bool no_conversions) override;
6095
6096 public:
6098 // If true, depended_from information of this ref was pushed down to
6099 // underlying field.
6101
6102 private:
6103 Field *result_field{nullptr}; /* Save result here */
6104
6105 protected:
6106 /// Indirect pointer to the referenced item.
6107 Item **m_ref_item{nullptr};
6108
6109 public:
6110 Item_ref(const POS &pos, const char *db_name_arg, const char *table_name_arg,
6111 const char *field_name_arg)
6112 : Item_ident(pos, db_name_arg, table_name_arg, field_name_arg) {}
6113
6114 /*
6115 This constructor is used in two scenarios:
6116 A) *item = NULL
6117 No initialization is performed, fix_fields() call will be necessary.
6118
6119 B) *item points to an Item this Item_ref will refer to. This is
6120 used for GROUP BY. fix_fields() will not be called in this case,
6121 so we call set_properties to make this item "fixed". set_properties
6122 performs a subset of action Item_ref::fix_fields does, and this subset
6123 is enough for Item_ref's used in GROUP BY.
6124
6125 TODO we probably fix a superset of problems like in BUG#6658. Check this
6126 with Bar, and if we have a more broader set of problems like this.
6127 */
6128 Item_ref(Name_resolution_context *context_arg, Item **item,
6129 const char *db_name_arg, const char *table_name_arg,
6130 const char *field_name_arg, bool alias_of_expr_arg = false);
6131 Item_ref(Name_resolution_context *context_arg, Item **item,
6132 const char *field_name_arg);
6133
6134 /* Constructor need to process subselect with temporary tables (see Item) */
6135 Item_ref(THD *thd, Item_ref *item)
6136 : Item_ident(thd, item),
6138 m_ref_item(item->m_ref_item) {}
6139
6140 /// @returns the item referenced by this object
6141 Item *ref_item() const { return *m_ref_item; }
6142
6143 /// @returns the pointer to the item referenced by this object
6144 Item **ref_pointer() const { return m_ref_item; }
6145
6147
6148 enum Type type() const override { return REF_ITEM; }
6149 bool eq(const Item *item) const override {
6150 const Item *it = item->real_item();
6151 // May search for a referenced item that is not yet resolved:
6152 if (m_ref_item == nullptr) return false;
6153 return ref_item()->eq(it);
6154 }
6155 double val_real() override;
6156 longlong val_int() override;
6157 longlong val_date_temporal() override;
6158 my_decimal *val_decimal(my_decimal *) override;
6159 bool val_bool() override;
6160 String *val_str(String *tmp) override;
6161 bool val_json(Json_wrapper *result) override;
6162 bool is_null() override;
6163 bool val_date(Date_val *date, my_time_flags_t flags) override;
6164 bool val_time(Time_val *time) override;
6165 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
6166 bool send(Protocol *prot, String *tmp) override;
6167 void make_field(Send_field *field) override;
6168 bool fix_fields(THD *, Item **) override;
6169 void fix_after_pullout(Query_block *parent_query_block,
6170 Query_block *removed_query_block) override;
6171
6172 Item_result result_type() const override { return ref_item()->result_type(); }
6173
6174 TYPELIB *get_typelib() const override { return ref_item()->get_typelib(); }
6175
6177 return result_field != nullptr ? result_field
6179 }
6180 Item *get_tmp_table_item(THD *thd) override;
6181 table_map used_tables() const override {
6182 if (depended_from != nullptr) return OUTER_REF_TABLE_BIT;
6183 const table_map map = ref_item()->used_tables();
6184 if (map != 0) return map;
6185 // rollup constant: ensure it is non-constant by returning RAND_TABLE_BIT
6187 return 0;
6188 }
6189 void update_used_tables() override {
6190 if (depended_from == nullptr) ref_item()->update_used_tables();
6191 /*
6192 Reset all flags except GROUP BY modifier, since we do not mark the rollup
6193 expression itself.
6194 */
6197 }
6198
6199 table_map not_null_tables() const override {
6200 /*
6201 It can happen that our 'depended_from' member is set but the
6202 'depended_from' member of the referenced item is not (example: if a
6203 field in a subquery belongs to an outer merged view), so we first test
6204 ours:
6205 */
6206 return depended_from != nullptr ? OUTER_REF_TABLE_BIT
6208 }
6209 void set_result_field(Field *field) override { result_field = field; }
6210 bool is_result_field() const override { return true; }
6211 Field *get_result_field() const override { return result_field; }
6212 Item *real_item() override {
6213 // May look into unresolved Item_ref objects
6214 if (m_ref_item == nullptr) return this;
6215 return ref_item()->real_item();
6216 }
6217 const Item *real_item() const override {
6218 // May look into unresolved Item_ref objects
6219 if (m_ref_item == nullptr) return this;
6220 return ref_item()->real_item();
6221 }
6222
6223 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override {
6224 // Unresolved items may have m_ref_item = nullptr
6225 return ((walk & enum_walk::PREFIX) && (this->*processor)(arg)) ||
6226 (m_ref_item != nullptr ? ref_item()->walk(processor, walk, arg)
6227 : false) ||
6228 ((walk & enum_walk::POSTFIX) && (this->*processor)(arg));
6229 }
6230 Item *transform(Item_transformer, uchar *arg) override;
6231 Item *compile(Item_analyzer analyzer, uchar **arg_p,
6232 Item_transformer transformer, uchar *arg_t) override;
6233 void traverse_cond(Cond_traverser traverser, void *arg,
6234 traverse_order order) override {
6235 assert(ref_item() != nullptr);
6236 if (order == PREFIX) (*traverser)(this, arg);
6237 ref_item()->traverse_cond(traverser, arg, order);
6238 if (order == POSTFIX) (*traverser)(this, arg);
6239 }
6241 /*
6242 Always return false: we don't need to go deeper into referenced
6243 expression tree since we have to mark aliased subqueries at
6244 their original places (select list, derived tables), not by
6245 references from other expression (order by etc).
6246 */
6247 return false;
6248 }
6249 bool clean_up_after_removal(uchar *arg) override;
6250 void print(const THD *thd, String *str,
6251 enum_query_type query_type) const override;
6252 uint64_t hash() override;
6253 void cleanup() override;
6255 return ref_item()->field_for_view_update();
6256 }
6257 virtual Ref_Type ref_type() const { return REF; }
6258
6259 // Row emulation: forwarding of ROW-related calls to ref
6260 uint cols() const override {
6261 assert(m_ref_item != nullptr);
6262 return result_type() == ROW_RESULT ? ref_item()->cols() : 1;
6263 }
6264 Item *element_index(uint i) override {
6265 assert(m_ref_item != nullptr);
6266 return result_type() == ROW_RESULT ? ref_item()->element_index(i) : this;
6267 }
6268 Item **addr(uint i) override {
6269 assert(m_ref_item != nullptr);
6270 return result_type() == ROW_RESULT ? ref_item()->addr(i) : nullptr;
6271 }
6272 bool check_cols(uint c) override {
6273 assert(m_ref_item != nullptr);
6274 return result_type() == ROW_RESULT ? ref_item()->check_cols(c)
6275 : Item::check_cols(c);
6276 }
6277 bool null_inside() override {
6278 assert(m_ref_item != nullptr);
6279 return result_type() == ROW_RESULT ? ref_item()->null_inside() : false;
6280 }
6281 void bring_value() override {
6282 assert(m_ref_item != nullptr);
6284 }
6285
6286 bool basic_const_item() const override { return false; }
6287
6288 bool is_outer_field() const override {
6289 assert(fixed);
6290 assert(ref_item());
6291 return ref_item()->is_outer_field();
6292 }
6293
6294 bool created_by_in2exists() const override {
6295 return ref_item()->created_by_in2exists();
6296 }
6297
6298 bool repoint_const_outer_ref(uchar *arg) override;
6299 bool is_non_const_over_literals(uchar *) override { return true; }
6302 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6303 func_arg->err_code = func_arg->get_unnamed_function_error_code();
6304 return true;
6305 }
6307 return ref_item()->cast_to_int_type();
6308 }
6309 bool is_valid_for_pushdown(uchar *arg) override {
6310 return ref_item()->is_valid_for_pushdown(arg);
6311 }
6314 }
6315 bool check_column_in_group_by(uchar *arg) override {
6316 return ref_item()->check_column_in_group_by(arg);
6317 }
6318 bool collect_item_field_or_ref_processor(uchar *arg) override;
6319};
6320
6321/**
6322 Class for fields from derived tables and views.
6323 The same as Item_ref, but call fix_fields() of reference if
6324 not called yet.
6325*/
6326class Item_view_ref final : public Item_ref {
6328
6329 public:
6331 const char *db_name_arg, const char *alias_name_arg,
6332 const char *table_name_arg, const char *field_name_arg,
6333 Table_ref *tr)
6334 : Item_ref(context_arg, item, db_name_arg, alias_name_arg,
6335 field_name_arg),
6337 if (tr->is_view()) {
6338 m_orig_db_name = db_name_arg;
6339 m_orig_table_name = table_name_arg;
6340 } else {
6341 assert(db_name_arg == nullptr);
6342 m_orig_table_name = table_name_arg;
6343 }
6344 m_table_ref = tr;
6346 set_nullable(true);
6348 }
6349 }
6350
6351 /*
6352 We share one underlying Item_field, so we have to disable
6353 build_equal_items_for_cond().
6354 TODO: Implement multiple equality optimization for views.
6355 */
6356 bool subst_argument_checker(uchar **) override { return false; }
6357
6358 bool fix_fields(THD *, Item **) override;
6359
6360 table_map used_tables() const override;
6361
6362 bool eq(const Item *item) const override;
6363 Item *get_tmp_table_item(THD *thd) override {
6364 DBUG_TRACE;
6366 item->item_name = item_name;
6367 return item;
6368 }
6369 Ref_Type ref_type() const override { return VIEW_REF; }
6370
6371 bool check_column_privileges(uchar *arg) override;
6372 bool mark_field_in_map(uchar *arg) override {
6373 /*
6374 If this referenced column is marked as used, flag underlying
6375 selected item from a derived table/view as used.
6376 */
6377 auto mark_field = (Mark_field *)arg;
6378 return get_result_field()
6380 : false;
6381 }
6382 longlong val_int() override;
6383 double val_real() override;
6385 String *val_str(String *str) override;
6386 bool val_date(Date_val *date, my_time_flags_t flags) override;
6387 bool val_time(Time_val *time) override;
6388 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
6389 bool val_bool() override;
6390 bool val_json(Json_wrapper *wr) override;
6391 bool is_null() override;
6392 bool send(Protocol *prot, String *tmp) override;
6394 Item *replace_item_view_ref(uchar *arg) override;
6395 Item *replace_view_refs_with_clone(uchar *arg) override;
6397
6398 protected:
6400 bool no_conversions) override;
6401
6402 private:
6403 /// @return true if item is from a null-extended row from an outer join
6404 bool has_null_row() const {
6406 }
6407
6408 /**
6409 If this column belongs to a view that is an inner table of an outer join,
6410 then this field points to the first leaf table of the view, otherwise NULL.
6411 */
6413};
6414
6415/*
6416 Class for outer fields.
6417 An object of this class is created when the select where the outer field was
6418 resolved is a grouping one. After it has been fixed the ref field will point
6419 to an Item_ref object which will be used to access the field.
6420 The ref field may also point to an Item_field instance.
6421 See also comments of the Item_field::fix_outer_field() function.
6422*/
6423
6424class Item_outer_ref final : public Item_ref {
6426
6427 private:
6428 /**
6429 Qualifying query of this outer ref (i.e. query block which owns FROM of
6430 table which this Item references).
6431 */
6433
6434 public:
6436 /* The aggregate function under which this outer ref is used, if any. */
6438 /*
6439 true <=> that the outer_ref is already present in the select list
6440 of the outer select.
6441 */
6445 : Item_ref(context_arg, nullptr, ident_arg->db_name,
6446 ident_arg->table_name, ident_arg->field_name, false),
6448 outer_ref(ident_arg),
6450 found_in_select_list(false) {
6454 // keep any select list alias:
6455 item_name = ident_arg->item_name;
6456 fixed = false;
6457 }
6459 const char *db_name_arg, const char *table_name_arg,
6460 const char *field_name_arg, bool alias_of_expr_arg,
6462 : Item_ref(context_arg, item, db_name_arg, table_name_arg, field_name_arg,
6463 alias_of_expr_arg),
6467 found_in_select_list(true) {}
6468 bool fix_fields(THD *, Item **) override;
6469 void fix_after_pullout(Query_block *parent_query_block,
6470 Query_block *removed_query_block) override;
6471 table_map used_tables() const override {
6472 return ref_item()->used_tables() == 0 ? 0 : OUTER_REF_TABLE_BIT;
6473 }
6474 table_map not_null_tables() const override { return 0; }
6475
6476 Ref_Type ref_type() const override { return OUTER_REF; }
6477 Item *replace_outer_ref(uchar *) override;
6478};
6479
6480/*
6481 An object of this class is like Item_ref, and
6482 sets owner->was_null=true if it has returned a NULL value from any
6483 val_XXX() function. This allows to inject an Item_ref_null_helper
6484 object into subquery and then check if the subquery has produced a row
6485 with NULL value.
6486*/
6487
6488class Item_ref_null_helper final : public Item_ref {
6490
6491 protected:
6493
6494 public:
6496 Item_in_subselect *master, Item **item)
6497 : super(context_arg, item, "", "", ""), owner(master) {}
6498 Item_ref_null_helper(const Item_ref_null_helper &ref_null_helper, Item **item)
6499 : Item_ref_null_helper(ref_null_helper.context, ref_null_helper.owner,
6500 item) {}
6501 double val_real() override;
6502 longlong val_int() override;
6503 longlong val_date_temporal() override;
6504 String *val_str(String *s) override;
6505 my_decimal *val_decimal(my_decimal *) override;
6506 bool val_bool() override;
6507 bool val_time(Time_val *time) override;
6508 bool val_date(Date_val *date, my_time_flags_t flags) override;
6509 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
6510 void print(const THD *thd, String *str,
6511 enum_query_type query_type) const override;
6512 Ref_Type ref_type() const override { return NULL_HELPER_REF; }
6513 /*
6514 we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
6515 */
6516 table_map used_tables() const override {
6519 }
6520};
6521
6522/*
6523 The following class is used to optimize comparing of bigint columns.
6524 We need to save the original item ('ref') to be able to call
6525 ref->save_in_field(). This is used to create index search keys.
6526
6527 An instance of Item_int_with_ref may have signed or unsigned integer value.
6528
6529*/
6530
6532 protected:
6535 bool no_conversions) override {
6536 return ref->save_in_field(field, no_conversions);
6537 }
6538
6539 public:
6541 bool unsigned_arg)
6542 : Item_int(i), ref(ref_arg) {
6543 set_data_type(field_type);
6544 unsigned_flag = unsigned_arg;
6545 }
6546 Item *clone_item() const override;
6547 uint64_t hash() override;
6548 Item *real_item() override { return ref; }
6549 const Item *real_item() const override { return ref; }
6550};
6551
6552/*
6553 Similar to Item_int_with_ref, but to optimize comparing of temporal columns.
6554*/
6556 public:
6557 Item_temporal_with_ref(enum_field_types field_type_arg, uint8 decimals_arg,
6558 longlong i, Item *ref_arg, bool unsigned_arg)
6559 : Item_int_with_ref(field_type_arg, i, ref_arg, unsigned_arg) {
6560 decimals = decimals_arg;
6561 }
6562 void print(const THD *thd, String *str,
6563 enum_query_type query_type) const override;
6564
6566 assert(false);
6567 return true;
6568 }
6569 bool val_time(Time_val *time) override {
6570 bool rc = ref->val_time(time);
6572 return rc;
6573 }
6574};
6575
6576/*
6577 Item_datetime_with_ref is used to optimize queries like:
6578 SELECT ... FROM t1 WHERE date_or_datetime_column = 20110101101010;
6579 The numeric constant is replaced to Item_datetime_with_ref
6580 by convert_constant_item().
6581*/
6583 public:
6584 /**
6585 Constructor for Item_datetime_with_ref.
6586 @param field_type_arg Data type: MYSQL_TYPE_DATE or MYSQL_TYPE_DATETIME
6587 @param decimals_arg Number of fractional digits.
6588 @param i Temporal value in packed format.
6589 @param ref_arg Pointer to the original numeric Item.
6590 */
6591 Item_datetime_with_ref(enum_field_types field_type_arg, uint8 decimals_arg,
6592 longlong i, Item *ref_arg)
6593 : Item_temporal_with_ref(field_type_arg, decimals_arg, i, ref_arg, true) {
6594 }
6595 Item *clone_item() const override;
6596 longlong val_date_temporal() override { return val_int(); }
6597};
6598
6599/**
6600 This is used for segregating rows in groups (e.g. GROUP BY, windows), to
6601 detect boundaries of groups.
6602 It caches a value, which is representative of the group, and can compare it
6603 to another row, and update its value when entering a new group.
6604*/
6606 protected:
6607 Item *item; ///< The item whose value to cache.
6608 explicit Cached_item(Item *i) : item(i) {}
6609
6610 public:
6611 bool null_value{true};
6612 virtual ~Cached_item() = default;
6613 /**
6614 Compare the value associated with the item with the stored value.
6615 If they are different, update the stored value with item's value and
6616 return true.
6617
6618 @returns true if item's value and stored value are different.
6619 Notice that first call is to establish an initial value and
6620 return value should be ignored.
6621 */
6622 virtual bool cmp() = 0;
6623 Item *get_item() const { return item; }
6624 Item **get_item_ptr() { return &item; }
6625};
6626
6628 // Make sure value.ptr() is never nullptr, as not all collation functions
6629 // are prepared for that (even with empty strings).
6632
6633 public:
6634 explicit Cached_item_str(Item *arg) : Cached_item(arg) {}
6635 bool cmp() override;
6636};
6637
6638/// Cached_item subclass for JSON values.
6640 Json_wrapper *m_value; ///< The cached JSON value.
6641 public:
6642 explicit Cached_item_json(Item *item);
6643 ~Cached_item_json() override;
6644 bool cmp() override;
6645};
6646
6648 double value{0.0};
6649
6650 public:
6651 explicit Cached_item_real(Item *item_par) : Cached_item(item_par) {}
6652 bool cmp() override;
6653};
6654
6657
6658 public:
6659 explicit Cached_item_int(Item *item_par) : Cached_item(item_par) {}
6660 bool cmp() override;
6661};
6662
6664 public:
6665 explicit Cached_item_time(Item *item_par) : Cached_item(item_par) {}
6666 bool cmp() override;
6667
6668 private:
6670};
6671
6673 public:
6674 explicit Cached_item_date(Item *item_par) : Cached_item(item_par) {}
6675 bool cmp() override;
6676
6677 private:
6679};
6680
6683
6684 public:
6685 explicit Cached_item_temporal(Item *item_par) : Cached_item(item_par) {}
6686 bool cmp() override;
6687};
6688
6691
6692 public:
6693 explicit Cached_item_decimal(Item *item_par) : Cached_item(item_par) {}
6694 bool cmp() override;
6695};
6696
6697class Item_default_value final : public Item_field {
6699
6700 protected:
6702 bool no_conversions) override;
6703
6704 public:
6705 Item_default_value(const POS &pos, Item *a = nullptr)
6706 : super(pos, nullptr, nullptr, nullptr), arg(a) {}
6707 bool do_itemize(Parse_context *pc, Item **res) override;
6708 enum Type type() const override { return DEFAULT_VALUE_ITEM; }
6709 bool eq(const Item *item) const override;
6710 bool fix_fields(THD *, Item **) override;
6711 void bind_fields() override;
6712 void cleanup() override;
6713 void print(const THD *thd, String *str,
6714 enum_query_type query_type) const override;
6715 uint64_t hash() override;
6716 table_map used_tables() const override { return 0; }
6717 Item *get_tmp_table_item(THD *thd) override { return copy_or_same(thd); }
6719 Item *replace_item_field(uchar *) override;
6720
6721 /*
6722 No additional privilege check for default values, as the walk() function
6723 checks privileges for the underlying column through the argument.
6724 */
6725 bool check_column_privileges(uchar *) override { return false; }
6726
6727 bool walk(Item_processor processor, enum_walk walk, uchar *args) override {
6728 return ((walk & enum_walk::PREFIX) && (this->*processor)(args)) ||
6729 (arg && arg->walk(processor, walk, args)) ||
6730 ((walk & enum_walk::POSTFIX) && (this->*processor)(args));
6731 }
6732
6735 reinterpret_cast<char *>(args));
6736 }
6737
6738 Item *transform(Item_transformer transformer, uchar *args) override;
6739 Item *argument() const { return arg; }
6740
6741 private:
6742 /// The argument for this function
6744 /// Pointer to row buffer that was used to calculate field value offset
6746};
6747
6748/*
6749 Item_insert_value -- an implementation of VALUES() function.
6750 You can use the VALUES(col_name) function in the UPDATE clause
6751 to refer to column values from the INSERT portion of the INSERT
6752 ... UPDATE statement. In other words, VALUES(col_name) in the
6753 UPDATE clause refers to the value of col_name that would be
6754 inserted, had no duplicate-key conflict occurred.
6755 In all other places this function returns NULL.
6756*/
6757
6758class Item_insert_value final : public Item_field {
6759 protected:
6761 bool no_conversions) override {
6762 return Item_field::save_in_field_inner(field_arg, no_conversions);
6763 }
6764
6765 public:
6766 /**
6767 Constructs an Item_insert_value that represents a call to the deprecated
6768 VALUES function.
6769 */
6772 arg(a),
6773 m_is_values_function(true) {}
6774
6775 /**
6776 Constructs an Item_insert_value that represents a derived table that wraps a
6777 table value constructor.
6778 */
6780 : Item_field(context_arg, nullptr, nullptr, nullptr),
6781 arg(a),
6782 m_is_values_function(false) {}
6783
6784 bool do_itemize(Parse_context *pc, Item **res) override {
6785 if (skip_itemize(res)) return false;
6786 return Item_field::do_itemize(pc, res) || arg->itemize(pc, &arg);
6787 }
6788
6789 enum Type type() const override { return INSERT_VALUE_ITEM; }
6790 bool eq(const Item *item) const override;
6791 bool fix_fields(THD *, Item **) override;
6792 void bind_fields() override;
6793 void cleanup() override;
6794 void print(const THD *thd, String *str,
6795 enum_query_type query_type) const override;
6796 uint64_t hash() override;
6797 /*
6798 We use RAND_TABLE_BIT to prevent Item_insert_value from
6799 being treated as a constant and precalculated before execution
6800 */
6801 table_map used_tables() const override { return RAND_TABLE_BIT; }
6802
6803 bool walk(Item_processor processor, enum_walk walk, uchar *args) override {
6804 return ((walk & enum_walk::PREFIX) && (this->*processor)(args)) ||
6805 arg->walk(processor, walk, args) ||
6806 ((walk & enum_walk::POSTFIX) && (this->*processor)(args));
6807 }
6810 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6811 func_arg->banned_function_name = "values";
6812 return true;
6813 }
6814
6815 private:
6816 /// The argument for this function
6818 /// Pointer to row buffer that was used to calculate field value offset
6820 /**
6821 This flag is true if the item represents a call to the deprecated VALUES
6822 function. It is false if the item represents a derived table that wraps a
6823 table value constructor.
6824 */
6826};
6827
6828/**
6829 Represents NEW/OLD version of field of row which is
6830 changed/read in trigger.
6831
6832 Note: For this item main part of actual binding to Field object happens
6833 not during fix_fields() call (like for Item_field) but right after
6834 parsing of trigger definition, when table is opened, with special
6835 setup_field() call. On fix_fields() stage we simply choose one of
6836 two Field instances representing either OLD or NEW version of this
6837 field.
6838*/
6839class Item_trigger_field final : public Item_field,
6841 public:
6842 /* Is this item represents row from NEW or OLD row ? */
6844 /* Next in list of all Item_trigger_field's in trigger */
6846 /*
6847 Next list of Item_trigger_field's in "sp_head::
6848 m_list_of_trig_fields_item_lists".
6849 */
6851 /* Index of the field in the TABLE::field array */
6853 /* Pointer to an instance of Table_trigger_field_support interface */
6855
6857 enum_trigger_variable_type trigger_var_type_arg,
6858 const char *field_name_arg, Access_bitmask priv,
6859 const bool ro)
6860 : Item_field(context_arg, nullptr, nullptr, field_name_arg),
6861 trigger_var_type(trigger_var_type_arg),
6863 field_idx((uint)-1),
6864 want_privilege(priv),
6866 read_only(ro) {}
6868 enum_trigger_variable_type trigger_var_type_arg,
6869 const char *field_name_arg, Access_bitmask priv,
6870 const bool ro)
6871 : Item_field(pos, nullptr, nullptr, field_name_arg),
6872 trigger_var_type(trigger_var_type_arg),
6873 field_idx((uint)-1),
6874 want_privilege(priv),
6876 read_only(ro) {}
6877 void setup_field(Table_trigger_field_support *table_triggers,
6878 GRANT_INFO *table_grant_info);
6879 enum Type type() const override { return TRIGGER_FIELD_ITEM; }
6880 bool eq(const Item *item) const override;
6881 bool fix_fields(THD *, Item **) override;
6882 void bind_fields() override;
6883 bool check_column_privileges(uchar *arg) override;
6884 void print(const THD *thd, String *str,
6885 enum_query_type query_type) const override;
6886 table_map used_tables() const override { return INNER_TABLE_BIT; }
6887 Field *get_tmp_table_field() override { return nullptr; }
6888 Item *copy_or_same(THD *) override { return this; }
6889 Item *get_tmp_table_item(THD *thd) override { return copy_or_same(thd); }
6890 void cleanup() override;
6891 void set_required_privilege(Access_bitmask privilege) override {
6892 want_privilege = privilege;
6893 }
6894
6897 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6898 func_arg->err_code = func_arg->get_unnamed_function_error_code();
6899 return true;
6900 }
6901
6902 bool is_valid_for_pushdown(uchar *args [[maybe_unused]]) override {
6903 return true;
6904 }
6905
6906 private:
6907 bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override;
6908
6909 public:
6911 return (read_only ? nullptr : this);
6912 }
6913
6914 bool set_value(THD *thd, Item **it) {
6915 const bool ret = set_value(thd, nullptr, it);
6916 if (!ret)
6918 field_idx);
6919 return ret;
6920 }
6921
6922 private:
6923 /*
6924 'want_privilege' holds privileges required to perform operation on
6925 this trigger field (SELECT_ACL if we are going to read it and
6926 UPDATE_ACL if we are going to update it). It is initialized at
6927 parse time but can be updated later if this trigger field is used
6928 as OUT or INOUT parameter of stored routine (in this case
6929 set_required_privilege() is called to appropriately update
6930 want_privilege).
6931 */
6934 /*
6935 Trigger field is read-only unless it belongs to the NEW row in a
6936 BEFORE INSERT of BEFORE UPDATE trigger.
6937 */
6939};
6940
6942 protected:
6943 Item *example{nullptr};
6945 /**
6946 Field that this object will get value from. This is used by
6947 index-based subquery engines to detect and remove the equality injected
6948 by IN->EXISTS transformation.
6949 */
6951 /*
6952 true <=> cache holds value of the last stored item (i.e actual value).
6953 store() stores item to be cached and sets this flag to false.
6954 On the first call of val_xxx function if this flag is set to false the
6955 cache_value() will be called to actually cache value of saved item.
6956 cache_value() will set this flag to true.
6957 */
6958 bool value_cached{false};
6959
6960 friend bool has_rollup_result(Item *item);
6962 THD *thd, Query_block *select, Item *item_arg);
6963
6964 public:
6966 fixed = true;
6967 set_nullable(true);
6968 null_value = true;
6969 }
6971 set_data_type(field_type_arg);
6972 fixed = true;
6973 set_nullable(true);
6974 null_value = true;
6975 }
6976
6977 void fix_after_pullout(Query_block *parent_query_block,
6978 Query_block *removed_query_block) override {
6979 if (example == nullptr) return;
6980 example->fix_after_pullout(parent_query_block, removed_query_block);
6982 }
6983
6984 virtual bool allocate(uint) { return false; }
6985 virtual bool setup(Item *item) {
6986 example = item;
6987 max_length = item->max_length;
6988 decimals = item->decimals;
6989 collation.set(item->collation);
6992 if (item->type() == FIELD_ITEM) {
6993 cached_field = down_cast<Item_field *>(item);
6994 if (cached_field->m_table_ref != nullptr)
6996 } else {
6997 used_table_map = item->used_tables();
6998 }
6999 return false;
7000 }
7001 enum Type type() const override { return CACHE_ITEM; }
7002 static Item_cache *get_cache(const Item *item);
7003 static Item_cache *get_cache(const Item *item, const Item_result type);
7004 table_map used_tables() const override { return used_table_map; }
7005 void print(const THD *thd, String *str,
7006 enum_query_type query_type) const override;
7007 uint64_t hash() override;
7008 bool eq_def(const Field *field) {
7009 return cached_field != nullptr && cached_field->field->eq_def(field);
7010 }
7011 bool eq(const Item *item) const override { return this == item; }
7012 /**
7013 Check if saved item has a non-NULL value.
7014 Will cache value of saved item if not already done.
7015 @return true if cached value is non-NULL.
7016 */
7017 bool has_value();
7018
7019 /**
7020 If this item caches a field value, return pointer to underlying field.
7021
7022 @return Pointer to field, or NULL if this is not a cache for a field value.
7023 */
7025
7026 /**
7027 Assigns to the cache the expression to be cached. Does not evaluate it.
7028 @param item the expression to be cached
7029 */
7030 virtual void store(Item *item);
7031
7032 /**
7033 Force an item to be null. Used for empty subqueries to avoid attempts to
7034 evaluate expressions which could have uninitialized columns due to
7035 bypassing the subquery exec.
7036 */
7037 void store_null() {
7038 assert(is_nullable());
7039 value_cached = true;
7040 null_value = true;
7041 }
7042
7043 virtual bool cache_value() = 0;
7044 bool store_and_cache(Item *item) {
7045 store(item);
7046 return cache_value();
7047 }
7048 void cleanup() override;
7049 bool basic_const_item() const override {
7050 return (example != nullptr && example->basic_const_item());
7051 }
7052 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
7053 virtual void clear() {
7054 null_value = true;
7055 value_cached = false;
7056 }
7057 bool is_null() override {
7058 return value_cached ? null_value : example->is_null();
7059 }
7060 bool is_non_const_over_literals(uchar *) override { return true; }
7063 pointer_cast<Check_function_as_value_generator_parameters *>(args);
7064 func_arg->banned_function_name = "cached item";
7065 // This should not happen as SELECT statements are not allowed.
7066 assert(false);
7067 return true;
7068 }
7069 Item_result result_type() const override {
7070 if (!example) return INT_RESULT;
7072 }
7073 Item *get_example() const { return example; }
7075};
7076
7078 public:
7081 : Item_cache(field_type_arg), value(0) {}
7082
7083 /**
7084 Unlike store(), this stores an explicitly provided value, not the one of
7085 'item'; however, NULLness is still taken from 'item'.
7086 */
7087 void store_value(Item *item, longlong val_arg);
7088 double val_real() override;
7089 longlong val_int() override;
7090 longlong val_date_temporal() override { return val_int(); }
7091 String *val_str(String *str) override;
7092 my_decimal *val_decimal(my_decimal *) override;
7093 bool val_date(Date_val *date, my_time_flags_t flags) override {
7094 return get_date_from_int(date, flags);
7095 }
7096 bool val_time(Time_val *time) override { return get_time_from_int(time); }
7098 return get_datetime_from_int(dt, flags);
7099 }
7100 Item_result result_type() const override { return INT_RESULT; }
7101 bool cache_value() override;
7102
7103 protected:
7105};
7106
7107/**
7108 Cache class for BIT type expressions. The BIT data type behaves like unsigned
7109 integer numbers in all situations, except when formatted as a string, where
7110 it is directly interpreted as a byte string, possibly right-extended with
7111 zero-bits.
7112*/
7113class Item_cache_bit final : public Item_cache_int {
7114 public:
7116 : Item_cache_int(field_type_arg) {
7117 assert(field_type_arg == MYSQL_TYPE_BIT);
7118 }
7119
7120 /**
7121 Transform the result Item_cache_int::value in bit format. The process is
7122 similar to Field_bit_as_char::store().
7123 */
7124 String *val_str(String *str) override;
7125 uint string_length() { return ((max_length + 7) / 8); }
7126};
7127
7128class Item_cache_real final : public Item_cache {
7129 public:
7131
7132 double val_real() override;
7133 longlong val_int() override;
7134 String *val_str(String *str) override;
7135 my_decimal *val_decimal(my_decimal *) override;
7136 bool val_date(Date_val *date, my_time_flags_t flags) override {
7137 return get_date_from_real(date, flags);
7138 }
7139 bool val_time(Time_val *time) override { return get_time_from_real(time); }
7141 return get_datetime_from_real(dt, flags);
7142 }
7143 Item_result result_type() const override { return REAL_RESULT; }
7144 bool cache_value() override;
7145 void store_value(Item *expr, double value);
7146
7147 private:
7148 double value{0};
7149};
7150
7151class Item_cache_decimal final : public Item_cache {
7152 public:
7154
7155 double val_real() override;
7156 longlong val_int() override;
7157 String *val_str(String *str) override;
7158 my_decimal *val_decimal(my_decimal *) override;
7159 bool val_date(Date_val *date, my_time_flags_t flags) override {
7160 return get_date_from_decimal(date, flags);
7161 }
7162 bool val_time(Time_val *time) override { return get_time_from_decimal(time); }
7164 return get_datetime_from_decimal(dt, flags);
7165 }
7166 Item_result result_type() const override { return DECIMAL_RESULT; }
7167 bool cache_value() override;
7168 void store_value(Item *expr, my_decimal *d);
7169
7170 private:
7172};
7173
7174class Item_cache_str final : public Item_cache {
7178
7179 protected:
7181 bool no_conversions) override;
7182
7183 public:
7185 : Item_cache(item->data_type()),
7186 value(nullptr),
7187 is_varbinary(item->type() == FIELD_ITEM &&
7189 !((const Item_field *)item)->field->has_charset()) {
7190 collation.set(item->collation);
7191 }
7192 double val_real() override;
7193 longlong val_int() override;
7194 String *val_str(String *) override;
7195 my_decimal *val_decimal(my_decimal *) override;
7196 bool val_date(Date_val *date, my_time_flags_t flags) override {
7197 return get_date_from_string(date, flags);
7198 }
7199 bool val_time(Time_val *time) override { return get_time_from_string(time); }
7201 return get_datetime_from_string(dt, flags);
7202 }
7203 Item_result result_type() const override { return STRING_RESULT; }
7204 const CHARSET_INFO *charset() const { return value->charset(); }
7205 bool cache_value() override;
7206 void store_value(Item *expr, String &s);
7207};
7208
7209class Item_cache_row final : public Item_cache {
7210 public:
7212
7213 /**
7214 'allocate' is only used in Item_cache_row::setup()
7215 */
7216 bool allocate(uint num) override;
7217 /*
7218 'setup' is needed only by row => it not called by simple row subselect
7219 (only by IN subselect (in subselect optimizer))
7220 */
7221 bool setup(Item *item) override;
7222 void store(Item *item) override;
7223 void illegal_method_call(const char *) const MY_ATTRIBUTE((cold));
7224 void make_field(Send_field *) override { illegal_method_call("make_field"); }
7225 double val_real() override {
7226 illegal_method_call("val_real");
7227 return 0;
7228 }
7229 longlong val_int() override {
7230 illegal_method_call("val_int");
7231 return 0;
7232 }
7233 String *val_str(String *) override {
7234 illegal_method_call("val_str");
7235 return nullptr;
7236 }
7238 illegal_method_call("val_decimal");
7239 return nullptr;
7240 }
7242 illegal_method_call("val_date");
7243 return true;
7244 }
7245 bool val_time(Time_val *) override {
7246 illegal_method_call("val_time");
7247 return true;
7248 }
7250 illegal_method_call("val_datetime");
7251 return true;
7252 }
7253 Item_result result_type() const override { return ROW_RESULT; }
7254
7255 uint cols() const override { return item_count; }
7256 Item *element_index(uint i) override { return values[i]; }
7257 Item **addr(uint i) override { return (Item **)(values + i); }
7258 bool check_cols(uint c) override;
7259 bool null_inside() override;
7260 void bring_value() override;
7261 void cleanup() override { Item_cache::cleanup(); }
7262 bool cache_value() override;
7263
7264 private:
7265 Item_cache **values{nullptr};
7266 uint item_count{2};
7267};
7268
7270 public:
7273 }
7274
7275 void store(Item *item) override;
7276 double val_real() override;
7277 longlong val_int() override;
7278 longlong val_date_temporal() override;
7279 String *val_str(String *str) override;
7280 my_decimal *val_decimal(my_decimal *) override;
7281 bool val_date(Date_val *date, my_time_flags_t flags) override;
7282 bool val_time(Time_val *time) override;
7283 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7284 Item_result result_type() const override { return STRING_RESULT; }
7285 bool cache_value() override;
7286 /**
7287 Cache a single non-NULL time value. Requires that "example" is not set.
7288
7289 @param time Time value to cache
7290 */
7291 void store_value(Time_val time);
7292
7293 private:
7295};
7296
7298 public:
7301 }
7302
7303 void store(Item *item) override;
7304 double val_real() override;
7305 longlong val_int() override;
7306 longlong val_date_temporal() override;
7307 String *val_str(String *str) override;
7308 my_decimal *val_decimal(my_decimal *) override;
7309 bool val_date(Date_val *date, my_time_flags_t flags) override;
7310 bool val_time(Time_val *time) override;
7311 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7312 Item_result result_type() const override { return STRING_RESULT; }
7313 bool cache_value() override;
7314 /**
7315 Cache a single non-NULL date value. Requires that "example" is not set.
7316
7317 @param date Date value to cache
7318 */
7319 void store_value(Date_val date);
7320
7321 private:
7323};
7324
7326 public:
7328 : Item_cache(field_type_arg), int_value(0), str_value_cached(false) {
7329 assert(field_type_arg != MYSQL_TYPE_TIME &&
7330 field_type_arg != MYSQL_TYPE_DATE);
7332 }
7333
7334 void store_value(Item *item, longlong val_arg);
7335 void store(Item *item) override;
7336 double val_real() override;
7337 longlong val_int() override;
7338 longlong val_date_temporal() override;
7339 String *val_str(String *str) override;
7340 my_decimal *val_decimal(my_decimal *) override;
7341 bool val_date(Date_val *date, my_time_flags_t flags) override;
7342 bool val_time(Time_val *time) override;
7343 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7344 Item_result result_type() const override { return STRING_RESULT; }
7345 /*
7346 In order to avoid INT <-> STRING conversion of a DATETIME value
7347 two cache_value functions are introduced. One (cache_value) caches STRING
7348 value, another (cache_value_int) - INT value. Thus this cache item
7349 completely relies on the ability of the underlying item to do the
7350 correct conversion.
7351 */
7352 bool cache_value_int();
7353 bool cache_value() override;
7354 void clear() override {
7356 str_value_cached = false;
7357 }
7358
7359 private:
7360 /// Used for DATETIME values
7362 /// Used when required in a string context
7364 /// If true, cached_string contains a valid value
7365 bool str_value_cached{false};
7366};
7367
7368/// An item cache for values of type JSON.
7370 /// Cached value
7372 /// Whether the cached value is array and it is sorted
7374
7375 public:
7377 ~Item_cache_json() override;
7378 bool cache_value() override;
7379 void store_value(Item *expr, Json_wrapper *wr);
7380 bool val_json(Json_wrapper *wr) override;
7381 longlong val_int() override;
7382 String *val_str(String *str) override;
7383 Item_result result_type() const override { return STRING_RESULT; }
7384
7385 double val_real() override;
7386 my_decimal *val_decimal(my_decimal *val) override;
7387 bool val_date(Date_val *date, my_time_flags_t flags) override;
7388 bool val_time(Time_val *time) override;
7389 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7390 /// Sort cached data. Only arrays are affected.
7391 void sort();
7392 /// Returns true when cached value is array and it's sorted
7393 bool is_sorted() { return m_is_sorted; }
7394};
7395
7396/**
7397 Interface for storing an aggregation of type and type specification of
7398 multiple Item objects.
7399
7400 This is useful for cases where a field is an amalgamation of multiple types,
7401 such as in UNION where type conversions must be done to a common denominator.
7402*/
7404 protected:
7405 /// Typelib information, only used for data type ENUM and SET.
7407 /// Geometry type, only used for data type GEOMETRY.
7409
7410 void set_typelib(Item *item);
7411
7412 public:
7414
7415 double val_real() override = 0;
7416 longlong val_int() override = 0;
7418 String *val_str(String *) override = 0;
7419 bool val_date(Date_val *, my_time_flags_t) override = 0;
7420 bool val_time(Time_val *time) override = 0;
7422 Item_result result_type() const override;
7423 bool unify_types(Item *item);
7424 bool unify_types(const char *op_string, Item **items, size_t count);
7425 Field *make_field_by_type(TABLE *table, bool strict);
7426 static uint32 display_length(Item *item);
7428 return geometry_type;
7429 }
7430 void make_field(Send_field *field) override {
7431 Item::make_field(field);
7432 // Item_type_holder is used for unions and effectively sends Fields
7433 field->field = true;
7434 }
7437 pointer_cast<Check_function_as_value_generator_parameters *>(args);
7438 func_arg->err_code = func_arg->get_unnamed_function_error_code();
7439 return true;
7440 }
7441};
7442
7443/**
7444 Item_type_holder stores an aggregation of name, type and type specification of
7445 UNIONS and derived tables.
7446*/
7449
7450 public:
7451 /// @todo Consider giving Item_type_holder objects default names from the item
7452 /// they are initialized by. This would ensure that
7453 /// Query_expression::get_unit_column_types() always contains named items.
7454 Item_type_holder(THD *thd, Item *item) : super(thd, item) {}
7455
7456 enum Type type() const override { return TYPE_HOLDER_ITEM; }
7457
7458 /**
7459 Class is used in type aggregation only - this is needed to ensure
7460 that it is not attempted to be evaluated as a const value.
7461 */
7462 table_map used_tables() const override { return RAND_TABLE_BIT; }
7463
7464 double val_real() override;
7465 longlong val_int() override;
7466 my_decimal *val_decimal(my_decimal *) override;
7467 String *val_str(String *) override;
7468 bool val_date(Date_val *date, my_time_flags_t flags) override;
7469 bool val_time(Time_val *time) override;
7470 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7471};
7472
7473/**
7474 Reference item that encapsulates both the type and the contained items of a
7475 single column of a VALUES ROW query expression.
7476
7477 During execution, the item that will be output for the current iteration is
7478 contained in m_value_ref. The type of the column and the referenced item may
7479 differ in cases where a column of a VALUES clause contains different types
7480 across different rows, and must therefore do type conversions to their common
7481 denominator (e.g. a column containing both 10 and "10", of which the types
7482 will be aggregated into VARCHAR).
7483
7484 See the class comment for TableValueConstructorIterator for info on how
7485 Item_values_column is used as an indirection to iterate over the rows of a
7486 table value constructor (i.e. VALUES ROW expressions).
7487*/
7490
7491 private:
7493 /*
7494 Even if a table value constructor contains only constant values, we
7495 still need to identify individual rows within it. Set RAND_TABLE_BIT
7496 to ensure that all rows are scanned, and that the whole VALUES clause
7497 is never substituted with a const value or row.
7498 */
7500
7502 bool no_conversions) override;
7503
7504 public:
7506
7507 bool eq(const Item *item) const override;
7508 double val_real() override;
7509 longlong val_int() override;
7510 my_decimal *val_decimal(my_decimal *) override;
7511 bool val_bool() override;
7512 String *val_str(String *tmp) override;
7513 bool val_json(Json_wrapper *result) override;
7514 bool is_null() override;
7515 bool val_date(Date_val *date, my_time_flags_t flags) override;
7516 bool val_time(Time_val *time) override;
7517 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7518 enum Type type() const override { return VALUES_COLUMN_ITEM; }
7519 void set_value(Item *new_value) { m_value_ref = new_value; }
7521 void add_used_tables(Item *value);
7522};
7523
7524/// A class that represents a constant JSON value.
7525class Item_json final : public Item_basic_constant {
7527
7528 public:
7530 const Item_name_string &name);
7531 ~Item_json() override;
7532 enum Type type() const override { return JSON_ITEM; }
7533 void print(const THD *, String *str, enum_query_type) const override;
7534 uint64_t hash() override;
7535 bool val_json(Json_wrapper *result) override;
7536 Item_result result_type() const override { return STRING_RESULT; }
7537 double val_real() override;
7538 longlong val_int() override;
7539 String *val_str(String *str) override;
7541 bool val_date(Date_val *date, my_time_flags_t flags) override;
7542 bool val_time(Time_val *time) override;
7543 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7544 Item *clone_item() const override;
7545};
7546
7547extern Cached_item *new_Cached_item(THD *thd, Item *item);
7549extern bool resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
7550extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item);
7551extern bool is_null_on_empty_table(THD *thd, Item_field *i);
7552
7553extern const String my_null_string;
7554void convert_and_print(const String *from_str, String *to_str,
7555 const CHARSET_INFO *to_cs);
7556
7557std::string ItemToString(const Item *item, enum_query_type q_type);
7558std::string ItemToString(const Item *item);
7559
7560std::string ItemToQuerySubstrNoCharLimit(const Item *item);
7561std::string ItemToQuerySubstr(
7562 const Item *item, const LEX *lex = nullptr,
7564
7565inline size_t CountVisibleFields(const mem_root_deque<Item *> &fields) {
7566 return std::count_if(fields.begin(), fields.end(),
7567 [](Item *item) { return !item->hidden; });
7568}
7569
7570inline size_t CountHiddenFields(const mem_root_deque<Item *> &fields) {
7571 return std::count_if(fields.begin(), fields.end(),
7572 [](Item *item) { return item->hidden; });
7573}
7574
7576 size_t index) {
7577 for (Item *item : fields) {
7578 if (item->hidden) continue;
7579 if (index-- == 0) return item;
7580 }
7581 assert(false);
7582 return nullptr;
7583}
7584
7585/**
7586 Returns true iff the two items are equal, as in a->eq(b),
7587 after unwrapping refs and Item_cache objects.
7588 */
7589bool ItemsAreEqual(const Item *a, const Item *b);
7590
7591/**
7592 Returns true iff all items in the two arrays (which must be of the same size)
7593 are equal, as in a->eq(b), after unwrapping refs and Item_cache objects.
7594 */
7595bool AllItemsAreEqual(const Item *const *a, const Item *const *b,
7596 int num_items);
7597
7598#endif /* ITEM_INCLUDED */
uint32_t Access_bitmask
Definition: auth_acls.h:34
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
A type for SQL-like 3-valued Booleans: true/false/unknown.
Definition: item.h:591
value
Definition: item.h:605
@ v_UNKNOWN
Definition: item.h:605
@ v_FALSE
Definition: item.h:605
@ v_TRUE
Definition: item.h:605
Bool3(value v)
This is private; instead, use false3()/etc.
Definition: item.h:607
static const Bool3 true3()
Definition: item.h:598
static const Bool3 unknown3()
Definition: item.h:596
static const Bool3 false3()
Definition: item.h:594
bool is_true() const
Definition: item.h:600
value m_val
Definition: item.h:609
bool is_unknown() const
Definition: item.h:601
bool is_false() const
Definition: item.h:602
Definition: item.h:6672
Cached_item_date(Item *item_par)
Definition: item.h:6674
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:198
Date_val m_date
Definition: item.h:6678
Definition: item.h:6689
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:242
Cached_item_decimal(Item *item_par)
Definition: item.h:6693
my_decimal value
Definition: item.h:6690
Definition: item.h:6655
longlong value
Definition: item.h:6656
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:164
Cached_item_int(Item *item_par)
Definition: item.h:6659
Cached_item subclass for JSON values.
Definition: item.h:6639
Json_wrapper * m_value
The cached JSON value.
Definition: item.h:6640
~Cached_item_json() override
Definition: item_buff.cc:110
Cached_item_json(Item *item)
Definition: item_buff.cc:107
bool cmp() override
Compare the new JSON value in member 'item' with the previous value.
Definition: item_buff.cc:120
Definition: item.h:6647
Cached_item_real(Item *item_par)
Definition: item.h:6651
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:148
double value
Definition: item.h:6648
Definition: item.h:6627
String tmp_value
Definition: item.h:6631
Cached_item_str(Item *arg)
Definition: item.h:6634
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:84
String value
Definition: item.h:6630
Definition: item.h:6681
Cached_item_temporal(Item *item_par)
Definition: item.h:6685
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:215
longlong value
Definition: item.h:6682
Definition: item.h:6663
Cached_item_time(Item *item_par)
Definition: item.h:6665
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:181
Time_val m_time
Definition: item.h:6669
This is used for segregating rows in groups (e.g.
Definition: item.h:6605
Item ** get_item_ptr()
Definition: item.h:6624
Item * item
The item whose value to cache.
Definition: item.h:6607
virtual ~Cached_item()=default
Item * get_item() const
Definition: item.h:6623
virtual bool cmp()=0
Compare the value associated with the item with the stored value.
Cached_item(Item *i)
Definition: item.h:6608
bool null_value
Definition: item.h:6611
This class represents the cost of evaluating an Item.
Definition: item.h:790
bool m_is_expensive
True if the associated Item calls user defined functions or stored procedures.
Definition: item.h:845
double FieldCost() const
Get the cost of field access when evaluating the Item associated with this object.
Definition: item.h:827
uint8 m_other_fields
The number of other Field objects accessed by the associated Item.
Definition: item.h:851
void Compute(const Item &item)
Set '*this' to represent the cost of 'item'.
Definition: item.h:793
static constexpr double kStrFieldCost
The cost of accessing a Field_str, relative to other Field types.
Definition: item.h:835
uint8 m_str_fields
The number of Field_str objects accessed by the associated Item.
Definition: item.h:848
bool IsExpensive() const
Definition: item.h:816
void AddFieldCost()
Add the cost of accessing any other Field.
Definition: item.h:811
bool m_computed
True if 'ComputeInternal()' has been called.
Definition: item.h:841
void ComputeInternal(const Item &root)
Compute the cost of 'root' and its descendants.
Definition: item.cc:139
static constexpr double kOtherFieldCost
The cost of accessing a Field other than Field_str. 1.0 by definition.
Definition: item.h:838
void AddStrFieldCost()
Add the cost of accessing a Field_str.
Definition: item.h:805
void MarkExpensive()
Definition: item.h:799
Definition: item.h:184
void set(Derivation derivation_arg)
Definition: item.h:229
DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
Definition: item.h:199
void set_repertoire_from_charset(const CHARSET_INFO *cs)
Definition: item.h:190
bool aggregate(DTCollation &dt, uint flags=0)
Aggregate two collations together taking into account their coercibility (aka derivation).
Definition: item.cc:2756
void set(const DTCollation &dt)
Definition: item.h:204
DTCollation()
Definition: item.h:194
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg, uint repertoire_arg)
Definition: item.h:214
bool set(DTCollation &dt1, DTCollation &dt2, uint flags=0)
Definition: item.h:232
void set_numeric()
Definition: item.h:220
void set_repertoire(uint repertoire_arg)
Definition: item.h:230
const CHARSET_INFO * collation
Definition: item.h:186
Derivation derivation
Definition: item.h:187
const char * derivation_name() const
Definition: item.h:236
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
Definition: item.h:209
uint repertoire
Definition: item.h:188
void set(const CHARSET_INFO *collation_arg)
Definition: item.h:225
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
int32_t for_comparison() const
Definition: my_temporal.h:461
Definition: my_temporal.h:341
A field that stores a JSON value.
Definition: field.h:3908
Definition: field.h:573
const CHARSET_INFO * charset_for_protocol() const
Definition: field.h:1619
virtual Item_result cast_to_int_type() const
Definition: field.h:1038
static constexpr size_t MAX_LONG_BLOB_WIDTH
Definition: field.h:735
virtual bool is_array() const
Whether the field is a typed array.
Definition: field.h:1826
static constexpr size_t MAX_VARCHAR_WIDTH
Definition: field.h:729
const char * field_name
Definition: field.h:684
virtual void add_to_cost(CostOfItem *cost) const
Update '*cost' with the fact that this Field is accessed.
Definition: field.cc:1403
virtual uint32 max_display_length() const =0
TABLE * table
Pointer to TABLE object that owns this field.
Definition: field.h:679
bool is_null(ptrdiff_t row_offset=0) const
Check whether the full table's row is NULL or the Field has value NULL.
Definition: field.h:1218
virtual my_decimal * val_decimal(my_decimal *) const =0
bool is_tmp_nullable() const
Definition: field.h:924
virtual double val_real() const =0
virtual bool val_date(Date_val *date, my_time_flags_t flags) const
Retrieve field value and return the result as a date.
Definition: field.cc:2304
virtual longlong val_int() const =0
virtual Item_result numeric_context_result_type() const
Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + ...
Definition: field.h:1034
virtual bool eq_def(const Field *field) const
Definition: field.cc:8529
geometry_type
Definition: field.h:716
@ GEOM_GEOMETRY
Definition: field.h:717
virtual bool val_time(Time_val *time) const
Retrieve field value and return the result as a time.
Definition: field.cc:2320
virtual Item_result result_type() const =0
bool is_nullable() const
Definition: field.h:1291
virtual bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const
Retrieve field value and return the result as a datetime/timestamp.
Definition: field.cc:2312
virtual geometry_type get_geometry_type() const
Definition: field.h:1702
static Item_result result_merge_type(enum_field_types)
Detect Item_result by given field type of UNION merge result.
Definition: field.cc:1522
String * val_str(String *str) const
Definition: field.h:1003
bool is_field_for_functional_index() const
Definition: field.h:890
static constexpr size_t MAX_MEDIUM_BLOB_WIDTH
Definition: field.h:734
void dbug_print() const
Definition: field.h:1709
Context object for (functions that override) Item::clean_up_after_removal().
Definition: item.h:2990
Query_block *const m_root
Pointer to Cleanup_after_removal_context containing from which select the walk started,...
Definition: item.h:3004
Cleanup_after_removal_context(Query_block *root)
Definition: item.h:2992
Query_block * get_root()
Definition: item.h:2996
Definition: item.h:2840
List< Item > * m_items
Definition: item.h:2842
Collect_item_fields_or_refs(List< Item > *fields_or_refs)
Definition: item.h:2843
Collect_item_fields_or_refs(const Collect_item_fields_or_refs &)=delete
Collect_item_fields_or_refs & operator=(const Collect_item_fields_or_refs &)=delete
Collect_item_fields_or_view_refs(const Collect_item_fields_or_view_refs &)=delete
Query_block * m_transformed_block
Definition: item.h:2857
List< Item > * m_item_fields_or_view_refs
Definition: item.h:2856
Collect_item_fields_or_view_refs(List< Item > *fields_or_vr, Query_block *transformed_block)
Definition: item.h:2861
uint m_any_value_level
Used to compute Item_field's m_protected_by_any_value.
Definition: item.h:2860
Collect_item_fields_or_view_refs & operator=(const Collect_item_fields_or_view_refs &)=delete
Interface for storing an aggregation of type and type specification of multiple Item objects.
Definition: item.h:7403
longlong val_int() override=0
Item_result result_type() const override
Return expression type of Item_aggregate_type.
Definition: item.cc:11218
bool val_date(Date_val *, my_time_flags_t) override=0
Evaluate the item and return result as a date value.
my_decimal * val_decimal(my_decimal *) override=0
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override=0
Evaluate the item and return result as a datetime value.
void set_typelib(Item *item)
Set typelib information for an aggregated enum/set field.
Definition: item.cc:11491
Item_aggregate_type(THD *, Item *)
Definition: item.cc:11199
String * val_str(String *) override=0
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:7435
static uint32 display_length(Item *item)
Calculate length for merging result for given Item type.
Definition: item.cc:11373
bool val_time(Time_val *time) override=0
Evaluate the item and return result as a time value.
void make_field(Send_field *field) override
Definition: item.h:7430
Field * make_field_by_type(TABLE *table, bool strict)
Make temporary table field according collected information about type of UNION result.
Definition: item.cc:11436
double val_real() override=0
Field::geometry_type get_geometry_type() const override
Definition: item.h:7427
TYPELIB * m_typelib
Typelib information, only used for data type ENUM and SET.
Definition: item.h:7406
bool unify_types(Item *item)
Unify type from given item with the type in the current item.
Definition: item.cc:11332
Field::geometry_type geometry_type
Geometry type, only used for data type GEOMETRY.
Definition: item.h:7408
Represents [schema.
Definition: item.h:4859
bool is_asterisk() const override
Checks if the current object represents an asterisk select list item.
Definition: item.h:4879
Item_asterisk(const POS &pos, const char *opt_schema_name, const char *opt_table_name)
Constructor.
Definition: item.h:4870
Item_field super
Definition: item.h:4860
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.h:4875
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:11929
Definition: item.h:3977
Item_basic_constant(const POS &pos)
Definition: item.h:3982
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:3991
void set_str_value(String *str)
Note that str_value.ptr() will now point to a string owned by some other object.
Definition: item.h:4003
bool basic_const_item() const override
Returns true if this is a simple constant item like an integer, not a constant expression.
Definition: item.h:3998
void set_used_tables(table_map map)
Definition: item.h:3987
table_map used_table_map
Definition: item.h:3978
bool check_function_as_value_generator(uchar *) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:3989
Item_basic_constant()
Definition: item.h:3981
table_map used_tables() const override
Definition: item.h:3988
Definition: item.h:5991
Item_bin_string(const char *str, size_t str_length)
Definition: item.h:5995
void bin_string_init(const char *str, size_t str_length)
Definition: item.cc:7856
static LEX_CSTRING make_bin_str(const char *str, size_t str_length)
Definition: item.cc:7826
Item_hex_string super
Definition: item.h:5992
Item_bin_string(const POS &pos, const LEX_STRING &literal)
Definition: item.h:5998
Definition: item.h:5894
Item_blob(const char *name, size_t length)
Definition: item.h:5896
enum Type type() const override
Definition: item.h:5901
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:5902
Cache class for BIT type expressions.
Definition: item.h:7113
Item_cache_bit(enum_field_types field_type_arg)
Definition: item.h:7115
uint string_length()
Definition: item.h:7125
String * val_str(String *str) override
Transform the result Item_cache_int::value in bit format.
Definition: item.cc:10444
Definition: item.h:7297
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10571
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10620
bool cache_value() override
Definition: item.cc:10541
double val_real() override
Definition: item.cc:10616
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10580
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10573
String * val_str(String *str) override
Definition: item.cc:10557
Date_val m_date
Definition: item.h:7322
Item_cache_date()
Definition: item.h:7299
Item_result result_type() const override
Definition: item.h:7312
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10604
longlong val_int() override
Definition: item.cc:10614
void store_value(Date_val date)
Cache a single non-NULL date value.
Definition: item.cc:10550
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10592
Definition: item.h:7325
longlong val_int() override
Definition: item.cc:10797
longlong int_value
Used for DATETIME values.
Definition: item.h:7361
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10788
bool cache_value() override
Definition: item.cc:10645
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10704
void store_value(Item *item, longlong val_arg)
Definition: item.cc:10662
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10761
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10723
String * val_str(String *str) override
Definition: item.cc:10675
bool str_value_cached
If true, cached_string contains a valid value.
Definition: item.h:7365
Item_result result_type() const override
Definition: item.h:7344
void clear() override
Definition: item.h:7354
String cached_string
Used when required in a string context.
Definition: item.h:7363
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10670
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10731
bool cache_value_int()
Definition: item.cc:10629
Item_cache_datetime(enum_field_types field_type_arg)
Definition: item.h:7327
double val_real() override
Definition: item.cc:10786
Definition: item.h:7151
double val_real() override
Definition: item.cc:10996
my_decimal decimal_value
Definition: item.h:7171
bool cache_value() override
Definition: item.cc:10972
longlong val_int() override
Definition: item.cc:11004
Item_cache_decimal()
Definition: item.h:7153
String * val_str(String *str) override
Definition: item.cc:11012
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7159
void store_value(Item *expr, my_decimal *d)
Definition: item.cc:10989
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11021
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7163
Item_result result_type() const override
Definition: item.h:7166
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7162
Definition: item.h:7077
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7096
double val_real() override
Definition: item.cc:10431
longlong val_int() override
Definition: item.cc:10438
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7093
longlong value
Definition: item.h:7104
Item_cache_int(enum_field_types field_type_arg)
Definition: item.h:7080
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:7090
Item_result result_type() const override
Definition: item.h:7100
Item_cache_int()
Definition: item.h:7079
bool cache_value() override
Definition: item.cc:10400
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10424
void store_value(Item *item, longlong val_arg)
Unlike store(), this stores an explicitly provided value, not the one of 'item'; however,...
Definition: item.cc:10409
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7097
String * val_str(String *str) override
Definition: item.cc:10417
An item cache for values of type JSON.
Definition: item.h:7369
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10880
Item_result result_type() const override
Definition: item.h:7383
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10904
my_decimal * val_decimal(my_decimal *val) override
Definition: item.cc:10870
bool m_is_sorted
Whether the cached value is array and it is sorted.
Definition: item.h:7373
Json_wrapper * m_value
Cached value.
Definition: item.h:7371
bool cache_value() override
Read the JSON value and cache it.
Definition: item.cc:10812
Item_cache_json()
Definition: item.cc:10799
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10892
~Item_cache_json() override
Definition: item.cc:10804
bool val_json(Json_wrapper *wr) override
Copy the cached JSON value into a wrapper.
Definition: item.cc:10845
bool is_sorted()
Returns true when cached value is array and it's sorted.
Definition: item.h:7393
void store_value(Item *expr, Json_wrapper *wr)
Definition: item.cc:10829
double val_real() override
Definition: item.cc:10860
String * val_str(String *str) override
Definition: item.cc:10850
void sort()
Sort cached data. Only arrays are affected.
Definition: item.cc:10924
longlong val_int() override
Definition: item.cc:10915
Definition: item.h:7128
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7136
Item_cache_real()
Definition: item.h:7130
void store_value(Item *expr, double value)
Definition: item.cc:10940
double value
Definition: item.h:7148
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7139
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7140
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10965
bool cache_value() override
Definition: item.cc:10932
Item_result result_type() const override
Definition: item.h:7143
double val_real() override
Definition: item.cc:10946
String * val_str(String *str) override
Definition: item.cc:10958
longlong val_int() override
Definition: item.cc:10952
Definition: item.h:7209
Item * element_index(uint i) override
Definition: item.h:7256
longlong val_int() override
Definition: item.h:7229
bool val_datetime(Datetime_val *, my_time_flags_t) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7249
double val_real() override
Definition: item.h:7225
bool null_inside() override
Definition: item.cc:11181
Item_result result_type() const override
Definition: item.h:7253
Item ** addr(uint i) override
Definition: item.h:7257
bool allocate(uint num) override
'allocate' is only used in Item_cache_row::setup()
Definition: item.cc:11111
Item_cache_row()
Definition: item.h:7211
void bring_value() override
Definition: item.cc:11192
my_decimal * val_decimal(my_decimal *) override
Definition: item.h:7237
void make_field(Send_field *) override
Definition: item.h:7224
void illegal_method_call(const char *) const
Definition: item.cc:11165
uint item_count
Definition: item.h:7266
bool check_cols(uint c) override
Definition: item.cc:11173
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:7241
bool cache_value() override
Definition: item.cc:11142
uint cols() const override
Definition: item.h:7255
bool setup(Item *item) override
Definition: item.cc:11118
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:11131
bool val_time(Time_val *) override
Evaluate the item and return result as a time value.
Definition: item.h:7245
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:7261
Item_cache ** values
Definition: item.h:7265
String * val_str(String *) override
Definition: item.h:7233
Definition: item.h:7174
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:11097
bool cache_value() override
Definition: item.cc:11027
Item_result result_type() const override
Definition: item.h:7203
void store_value(Item *expr, String &s)
Definition: item.cc:11049
String value_buff
Definition: item.h:7176
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11087
const CHARSET_INFO * charset() const
Definition: item.h:7204
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7196
double val_real() override
Definition: item.cc:11059
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7200
String * val_str(String *) override
Definition: item.cc:11081
longlong val_int() override
Definition: item.cc:11070
char buffer[STRING_BUFFER_USUAL_SIZE]
Definition: item.h:7175
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7199
String * value
Definition: item.h:7176
bool is_varbinary
Definition: item.h:7177
Item_cache_str(const Item *item)
Definition: item.h:7184
Definition: item.h:7269
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10520
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10499
Item_cache_time()
Definition: item.h:7271
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10489
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10509
bool cache_value() override
Definition: item.cc:10460
Item_result result_type() const override
Definition: item.h:7284
Time_val time_value
Definition: item.h:7294
void store_value(Time_val time)
Cache a single non-NULL time value.
Definition: item.cc:10469
String * val_str(String *str) override
Definition: item.cc:10476
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10533
longlong val_int() override
Definition: item.cc:10529
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10491
double val_real() override
Definition: item.cc:10531
Definition: item.h:6941
bool walk(Item_processor processor, enum_walk walk, uchar *arg) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item.cc:10371
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:10389
Field * field()
If this item caches a field value, return pointer to underlying field.
Definition: item.h:7024
Item * get_example() const
Definition: item.h:7073
bool eq_def(const Field *field)
Definition: item.h:7008
Item_field * cached_field
Field that this object will get value from.
Definition: item.h:6950
virtual bool allocate(uint)
Definition: item.h:6984
Item ** get_example_ptr()
Definition: item.h:7074
bool is_non_const_over_literals(uchar *) override
Definition: item.h:7060
bool has_value()
Check if saved item has a non-NULL value.
Definition: item.cc:10377
Item_result result_type() const override
Definition: item.h:7069
friend bool has_rollup_result(Item *item)
Checks if an item has a ROLLUP NULL which needs to be written to temp table.
Definition: sql_executor.cc:371
bool basic_const_item() const override
Returns true if this is a simple constant item like an integer, not a constant expression.
Definition: item.h:7049
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:10364
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.h:7011
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.h:6977
virtual bool cache_value()=0
void store_null()
Force an item to be null.
Definition: item.h:7037
Item_cache(enum_field_types field_type_arg)
Definition: item.h:6970
table_map used_table_map
Definition: item.h:6944
enum Type type() const override
Definition: item.h:7001
Item_cache()
Definition: item.h:6965
virtual void store(Item *item)
Assigns to the cache the expression to be cached.
Definition: item.cc:10340
virtual bool setup(Item *item)
Definition: item.h:6985
bool value_cached
Definition: item.h:6958
table_map used_tables() const override
Definition: item.h:7004
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:7057
virtual void clear()
Definition: item.h:7053
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:7061
Item * example
Definition: item.h:6943
friend bool replace_contents_of_rollup_wrappers_with_tmp_fields(THD *thd, Query_block *select, Item *item_arg)
For each rollup wrapper below the given item, replace its argument with a temporary field,...
Definition: sql_executor.cc:4582
static Item_cache * get_cache(const Item *item)
Definition: item.cc:10291
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:10354
bool store_and_cache(Item *item)
Definition: item.h:7044
Definition: item.h:4150
uint m_case_expr_id
Definition: item.h:4174
Type type() const override
Definition: item.h:4159
Item * this_item() override
Definition: item.cc:2117
Item_case_expr(uint case_expr_id)
Definition: item.cc:2113
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:2142
Item ** this_item_addr(THD *thd, Item **) override
Definition: item.cc:2129
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2135
Item_result result_type() const override
Definition: item.h:4160
Definition: item.h:6582
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:6596
Item_datetime_with_ref(enum_field_types field_type_arg, uint8 decimals_arg, longlong i, Item *ref_arg)
Constructor for Item_datetime_with_ref.
Definition: item.h:6591
Item * clone_item() const override
Definition: item.cc:7496
Definition: item.h:5505
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3793
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5533
uint decimal_precision() const override
Definition: item.h:5547
String * val_str(String *) override
Definition: item.cc:3763
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3769
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3795
Item_result result_type() const override
Definition: item.h:5524
longlong val_int() override
Definition: item.cc:3751
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5529
enum Type type() const override
Definition: item.h:5523
my_decimal * val_decimal(my_decimal *) override
Definition: item.h:5528
my_decimal decimal_value
Definition: item.h:5509
double val_real() override
Definition: item.cc:3757
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5550
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:7465
Item_num super
Definition: item.h:5506
Item_decimal(const POS &pos, const char *str_arg, uint length, const CHARSET_INFO *charset)
Definition: item.cc:3692
Item * clone_item() const override
Definition: item.h:5536
Item_num * neg() override
Definition: item.h:5542
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5532
void set_decimal_value(const my_decimal *value_par)
Definition: item.cc:3810
Definition: item.h:6697
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:9705
Item * transform(Item_transformer transformer, uchar *args) override
Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to ...
Definition: item.cc:9754
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:9710
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9694
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:9599
Item_default_value(const POS &pos, Item *a=nullptr)
Definition: item.h:6705
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9680
bool walk(Item_processor processor, enum_walk walk, uchar *args) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item.h:6727
Item_field super
Definition: item.h:6698
bool check_column_privileges(uchar *) override
Check privileges of base table column.
Definition: item.h:6725
table_map used_tables() const override
Definition: item.h:6716
bool check_gcol_depend_default_processor(uchar *args) override
Check if a generated expression depends on DEFAULT function with specific column name as argument.
Definition: item.h:6733
Item * arg
The argument for this function.
Definition: item.h:6743
bool collect_item_field_or_view_ref_processor(uchar *arg) override
Collects fields and view references that have the qualifying table in the specified query block.
Definition: item.cc:6740
Item * argument() const
Definition: item.h:6739
uchar * m_rowbuffer_saved
Pointer to row buffer that was used to calculate field value offset.
Definition: item.h:6745
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9620
enum Type type() const override
Definition: item.h:6708
Item * replace_item_field(uchar *) override
If this default value is the target of replacement, replace it with the info object's item or,...
Definition: item.cc:6764
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.h:6717
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9615
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9670
Item_empty_string – is a utility class to put an item into List<Item> which is then used in protocol....
Definition: item.h:5916
void make_field(Send_field *field) override
Definition: item.cc:6869
Item_empty_string(const char *header, size_t length, const CHARSET_INFO *cs=nullptr)
Definition: item.h:5918
Definition: item.h:4534
Item * replace_equal_field(uchar *) override
Replace an Item_field for an equal Item_field that evaluated earlier (if any).
Definition: item.cc:6810
bool protected_by_any_value() const
See m_protected_by_any_value.
Definition: item.h:4841
bool check_column_privileges(uchar *arg) override
Check privileges of base table column.
Definition: item.cc:1414
bool collect_outer_field_processor(uchar *arg) override
Definition: item.cc:1014
bool collect_item_field_or_ref_processor(uchar *arg) override
When collecting information about columns when transforming correlated scalar subqueries using derive...
Definition: item.cc:1046
bool check_column_in_window_functions(uchar *arg) override
Check if this column is found in PARTITION clause of all the window functions.
Definition: item.cc:1227
bool find_field_processor(uchar *arg) override
Is this an Item_field which references the given Field argument?
Definition: item.h:4717
bool alias_name_used() const override
Definition: item.h:4817
bool any_privileges
Definition: item.h:4644
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4730
void set_item_equal_all_join_nests(Item_multi_eq *item_equal)
Definition: item.h:4615
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:3451
enum Type type() const override
Definition: item.h:4660
Item * apply_masking_policy(THD *thd) override
Apply column masking policy to this item if applicable.
Definition: item.cc:11956
bool add_field_to_cond_set_processor(uchar *) override
Item::walk function.
Definition: item.cc:1093
Item_result numeric_context_result_type() const override
Result type when an item appear in a numeric context.
Definition: item.h:4676
Item_multi_eq * multi_equality() const
Definition: item.h:4613
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:3441
void set_field(Field *field)
Definition: item.cc:3230
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:3434
Item_result cast_to_int_type() const override
Definition: item.h:4680
void set_item_was_sp_local_variable()
Sets m_was_sp_local_variable to true.
Definition: item.h:4623
const Item_field * base_item_field() const
Definition: item.h:4694
bool collect_item_field_processor(uchar *arg) override
Store the pointer to this item field into a list if not already there.
Definition: item.cc:1002
Item_multi_eq * find_multi_equality(COND_EQUAL *cond_equal) const
Find a field among specified multiple equalities.
Definition: item.cc:6569
Item * replace_with_derived_expr_ref(uchar *arg) override
Assuming this expression is part of a condition that would be pushed to the HAVING clause of a materi...
Definition: item.cc:1291
uint16 field_index
Index for this field in table->field array.
Definition: item.h:4612
const CHARSET_INFO * charset_for_protocol(void) override
Definition: item.h:4763
bool subst_argument_checker(uchar **arg) override
Check whether a field can be substituted by an equal item.
Definition: item.cc:6613
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:8554
Field * result_field
Result field.
Definition: item.h:4557
void disable_masking_policy() override
Disable application of the masking policy to this item.
Definition: item.h:4826
Item_multi_eq * item_equal_all_join_nests
Definition: item.h:4634
Item_result result_type() const override
Definition: item.h:4675
uint32 max_disp_length()
Definition: item.h:4748
void dbug_print() const
Definition: item.h:4768
double val_real() override
Definition: item.cc:3404
bool find_item_in_field_list_processor(uchar *arg) override
Check if an Item_field references some field from a list of fields.
Definition: item.cc:1122
void save_org_in_field(Field *field) override
Set a field's value from a item.
Definition: item.cc:7170
void make_field(Send_field *tmp_field) override
Definition: item.cc:7116
void set_base_item_field(const Item_field *item)
Definition: item.h:4690
bool get_timeval(my_timeval *tm, int *warnings) override
Get timestamp in "struct timeval" format.
Definition: item.cc:3461
enum_monotonicity_info get_monotonicity_info() const override
Definition: item.h:4683
float get_cond_filter_default_probability(double max_distinct_values, float default_filter) const
Returns the probability for the predicate "col OP <val>" to be true for a row in the case where no in...
Definition: item.cc:8596
Item_field * field_for_view_update() override
Definition: item.h:4749
const Item_field * m_base_item_field
If this field is derived from another field, e.g.
Definition: item.h:4579
void set_result_field(Field *field_arg) override
Definition: item.h:4687
bool send(Protocol *protocol, String *str_arg) override
This is only called from items that is not of type item_field.
Definition: item.cc:8519
table_map used_tables() const override
Definition: item.cc:3505
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:4701
void reset_field()
Reset all aspect of a field object, so that it can be re-resolved.
Definition: item.cc:6541
Field * field
Source field.
Definition: item.h:4553
void compute_cost(CostOfItem *root_cost) const override
Compute the cost of evaluating this Item.
Definition: item.h:4843
Item_multi_eq * m_multi_equality
Holds a list of items whose values must be equal to the value of this field, during execution.
Definition: item.h:4595
Item * update_value_transformer(uchar *select_arg) override
Add the field to the select list and substitute it for the reference to the field.
Definition: item.cc:8540
bool check_column_in_group_by(uchar *arg) override
Check if this column is found in GROUP BY.
Definition: item.cc:1261
uint32_t last_org_destination_field_memcpyable
Definition: item.h:4571
bool returns_array() const override
Whether the item returns array of its data type.
Definition: item.h:4824
Item * replace_item_field(uchar *) override
If this field is the target is the target of replacement, replace it with the info object's item or,...
Definition: item.cc:6714
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:3416
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:6475
void set_can_use_prefix_key() override
Definition: item.h:4828
uint32_t last_destination_field_memcpyable
Definition: item.h:4572
Item * equal_fields_propagator(uchar *arg) override
If field matches a multiple equality, set a pointer to that object in the field.
Definition: item.cc:6670
bool fix_outer_field(THD *thd, Field **field, Item_ident **ref_field, bool *complete)
Resolve the name of a column that may be an outer reference.
Definition: item.cc:5844
String * val_str(String *) override
Definition: item.cc:3389
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.cc:3596
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3428
Field::geometry_type get_geometry_type() const override
Definition: item.h:4759
Access_bitmask have_privileges
Definition: item.h:4642
bool add_field_to_set_processor(uchar *arg) override
Item::walk function.
Definition: item.cc:1084
Item * replace_with_derived_expr(uchar *arg) override
Assuming this expression is part of a condition that would be pushed to the WHERE clause of a materia...
Definition: item.cc:1274
bool strip_db_table_name_processor(uchar *) override
Generated fields don't need db/table names.
Definition: item.cc:11834
bool remove_column_from_bitmap(uchar *arg) override
Visitor interface for removing all column expressions (Item_field) in this expression tree from a bit...
Definition: item.cc:1100
bool is_outer_field() const override
Definition: item.h:4755
bool repoint_const_outer_ref(uchar *arg) override
If this object is the real_item of an Item_ref, repoint the result_field to field.
Definition: item.cc:11823
bool no_constant_propagation
If true, the optimizer's constant propagation will not replace this item with an equal constant.
Definition: item.h:4637
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:3396
bool collect_item_field_or_view_ref_processor(uchar *arg) override
Collects fields and view references that have the qualifying table in the specified query block.
Definition: item.cc:1062
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:3126
bool is_valid_for_pushdown(uchar *arg) override
Check if all the columns present in this expression are from the derived table.
Definition: item.cc:1133
Item_ident super
Definition: item.h:4535
virtual bool is_asterisk() const
Checks if the current object represents an asterisk select list item.
Definition: item.h:4839
Field * tmp_table_field(TABLE *) override
Definition: item.h:4689
bool can_use_prefix_key
Definition: item.h:4649
bool m_protected_by_any_value
State used for transforming scalar subqueries to JOINs with derived tables, cf.
Definition: item.h:4585
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.h:4539
Item_field(Name_resolution_context *context_arg, const char *db_arg, const char *table_name_arg, const char *field_name_arg)
Constructor used for internal information queries.
Definition: item.cc:3102
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:7185
longlong val_date_temporal_at_utc() override
Definition: item.cc:3422
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:6504
bool m_masking_policy_disabled
apply_masking_policy() is a no-op if this flag is true.
Definition: item.h:4605
longlong val_int() override
Definition: item.cc:3410
bool m_was_sp_local_variable
Indicates whether this field should be treated as an outer reference due to being the result of inlin...
Definition: item.h:4602
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 condition filtering effect for "WHERE field", which implicitly means "WHERE field <> 0".
Definition: item.cc:8584
Field * last_org_destination_field
Definition: item.h:4569
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3467
bool used_tables_for_level(uchar *arg) override
Return used table information for the specified query block (level).
Definition: item.cc:3511
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item.cc:3385
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:4721
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.cc:1325
bool disable_constant_propagation(uchar *) override
Definition: item.h:4743
bool replace_field_processor(uchar *arg) override
A processor that replaces any Fields with a Create_field_wrapper.
Definition: sql_table.cc:7858
Field * last_destination_field
Definition: item.h:4570
Field * get_tmp_table_field() override
If this Item is being materialized into a temporary table, returns the field that is being materializ...
Definition: item.h:4688
longlong val_int_endpoint(bool left_endp, bool *incl_endp) override
Definition: item.cc:3607
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:6255
Definition: item.h:5553
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5621
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5618
Item_num super
Definition: item.h:5554
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7614
longlong val_int() override
Definition: item.h:5607
Name_string presentation
Definition: item.h:5556
Item_float(double value_par, uint decimal_par)
Definition: item.h:5587
Item_float(const POS &pos, const Name_string name_arg, double val_arg, uint decimal_par, uint length)
Definition: item.h:5576
Item * clone_item() const override
Definition: item.h:5625
void init(const char *str_arg, uint length)
This function is only called during parsing:
Definition: item.cc:7573
Item_float(const char *str_arg, uint length)
Definition: item.h:5561
double val_real() override
Definition: item.h:5603
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:7590
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7598
Item_num * neg() override
Definition: item.h:5628
String * val_str(String *) override
Definition: item.cc:3818
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3824
double value
Definition: item.h:5559
Item_float(const Name_string name_arg, double val_arg, uint decimal_par, uint length)
Definition: item.h:5566
Item_float(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5562
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7622
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5622
enum Type type() const override
Definition: item.h:5602
Implements the comparison operator equals (=)
Definition: item_cmpfunc.h:1111
Definition: item.h:5638
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item.h:5646
const Name_string func_name
Definition: item.h:5639
Item_func_pi(const POS &pos)
Definition: item.h:5642
Definition: item_func.h:101
Definition: item.h:5939
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5970
uint decimal_precision() const override
Definition: item.cc:7674
Item_result result_type() const override
Definition: item.h:5974
Item_result cast_to_int_type() const override
Definition: item.h:5978
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:7749
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7809
void hex_string_init(const char *str, uint str_length)
Definition: item.cc:7700
Item_result numeric_context_result_type() const override
Result type when an item appear in a numeric context.
Definition: item.h:5975
enum Type type() const override
Definition: item.h:5954
Item_hex_string()
Definition: item.cc:7640
longlong val_int() override
Definition: item.cc:7710
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5971
Item_basic_constant super
Definition: item.h:5940
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5967
Item * clone_item() const override
Definition: item.cc:7647
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7811
static LEX_CSTRING make_hex_str(const char *str, size_t str_length)
Definition: item.cc:7658
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:7756
double val_real() override
Definition: item.h:5955
String * val_str(String *) override
Definition: item.h:5962
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7787
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5983
Item_hex_string(const POS &pos)
Definition: item.h:5948
Definition: item.h:4503
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:4521
my_decimal * val_decimal(my_decimal *dec) override
Definition: item.h:4518
const CHARSET_INFO * charset_for_protocol() override
Definition: item.h:4529
Item_ident_for_show(Field *par_field, const char *db_arg, const char *table_name_arg)
Definition: item.h:4509
const char * table_name
Definition: item.h:4507
enum Type type() const override
Definition: item.h:4513
longlong val_int() override
Definition: item.h:4516
double val_real() override
Definition: item.h:4515
Field * field
Definition: item.h:4505
String * val_str(String *str) override
Definition: item.h:4517
bool fix_fields(THD *thd, Item **ref) override
Definition: item.cc:3052
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:4524
void make_field(Send_field *tmp_field) override
Definition: item.cc:3039
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:4525
const char * db_name
Definition: item.h:4506
Definition: item.h:4263
bool m_alias_of_expr
if this Item's name is alias of SELECT expression
Definition: item.h:4307
uint64_t m_hash_val
To cache the hash value of this item, populated upon hash() invocation.
Definition: item.h:4267
virtual bool alias_name_used() const
Definition: item.h:4494
const char * original_db_name() const
Definition: item.h:4420
void set_alias_of_expr()
Marks that this Item's name is alias of SELECT expression.
Definition: item.h:4478
bool is_strong_side_column_not_in_fd(uchar *arg) override
Definition: item.cc:11798
Item_ident(Name_resolution_context *context_arg, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:4369
bool is_alias_of_expr() const
Definition: item.h:4476
Item_ident(THD *thd, Item_ident *item)
Constructor used by Item_field & Item_*_ref (see Item comment)
Definition: item.h:4397
Query_block * depended_from
For a column or reference that is an outer reference, depended_from points to the qualifying query bl...
Definition: item.h:4367
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.cc:3530
const char * m_orig_field_name
Names the field in the source base table.
Definition: item.h:4306
void set_original_field_name(const char *name_arg)
Definition: item.h:4417
const char * m_orig_table_name
Names the original table that is the source of the field.
Definition: item.h:4296
const char * original_table_name() const
Definition: item.h:4421
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.h:4429
Item_ident(const POS &pos, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:4382
bool update_depended_from(uchar *) override
Definition: item.cc:977
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:957
Table_ref * m_table_ref
Points to the Table_ref object of the table or view that the column or reference is resolved against ...
Definition: item.h:4361
const char * table_name
If column is from a non-aliased base table or view, name of base table or view.
Definition: item.h:4336
Name_resolution_context * context
For regularly resolved column references, 'context' points to a name resolution context object belong...
Definition: item.h:4322
friend bool insert_fields(THD *thd, Name_resolution_context *context, const char *db_name, const char *table_name, mem_root_deque< Item * >::iterator *it, bool any_privileges)
const char * db_name
Schema name of the base table or view the column is part of.
Definition: item.h:4328
const char * full_name() const override
Definition: item.cc:3286
bool aggregate_check_group(uchar *arg) override
Definition: item.cc:11793
bool is_column_not_in_fd(uchar *arg) override
Definition: item.cc:11806
const char * field_name
If column is aliased, the column alias name.
Definition: item.h:4350
uint64_t hash(const char *db_name_arg, const char *table_name_arg)
void set_orignal_db_name(const char *name_arg)
Definition: item.h:4413
const char * original_field_name() const
Definition: item.h:4422
bool change_context_processor(uchar *arg) override
Definition: item.h:4470
void set_original_table_name(const char *name_arg)
Definition: item.h:4414
Item super
Definition: item.h:4264
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3358
const char * m_orig_db_name
The fields m_orig_db_name, m_orig_table_name and m_orig_field_name are maintained so that we can prov...
Definition: item.h:4286
bool aggregate_check_distinct(uchar *arg) override
Definition: item.cc:11745
Bool3 local_column(const Query_block *sl) const override
Tells if this is a column of a table whose qualifying query block is 'sl'.
Definition: item.cc:11712
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:608
Definition: item.h:6758
Item_insert_value(Name_resolution_context *context_arg, Item *a)
Constructs an Item_insert_value that represents a derived table that wraps a table value constructor.
Definition: item.h:6779
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:6808
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9772
Item_insert_value(const POS &pos, Item *a)
Constructs an Item_insert_value that represents a call to the deprecated VALUES function.
Definition: item.h:6770
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.h:6784
uchar * m_rowbuffer_saved
Pointer to row buffer that was used to calculate field value offset.
Definition: item.h:6819
const bool m_is_values_function
This flag is true if the item represents a call to the deprecated VALUES function.
Definition: item.h:6825
type_conversion_status save_in_field_inner(Field *field_arg, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.h:6760
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9767
Item * arg
The argument for this function.
Definition: item.h:6817
bool walk(Item_processor processor, enum_walk walk, uchar *args) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item.h:6803
table_map used_tables() const override
Definition: item.h:6801
enum Type type() const override
Definition: item.h:6789
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9855
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9883
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:9890
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9877
Item_int with value==0 and length==1.
Definition: item.h:5410
Item_int_0()
Definition: item.h:5412
Item_int_0(const POS &pos)
Definition: item.h:5413
Definition: item.h:6531
Item * clone_item() const override
Definition: item.cc:7485
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store this item's int-value in a field.
Definition: item.h:6534
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7517
const Item * real_item() const override
Definition: item.h:6549
Item_int_with_ref(enum_field_types field_type, longlong i, Item *ref_arg, bool unsigned_arg)
Definition: item.h:6540
Item * ref
Definition: item.h:6533
Item * real_item() override
Definition: item.h:6548
Definition: item.h:5296
Item_result result_type() const override
Definition: item.h:5373
Item_int(const POS &pos, const LEX_STRING &num, int dummy_error=0)
Definition: item.h:5356
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3650
Item_int(longlong i, uint length=MY_INT64_NUM_DECIMAL_DIGITS)
Definition: item.h:5315
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3638
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5388
bool check_function_as_value_generator(uchar *) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:5404
double val_real() override
Definition: item.h:5378
Item_int(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5351
Item * clone_item() const override
Definition: item.h:5391
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5403
Item_int(const POS &pos, const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5340
longlong value
Definition: item.h:5302
Item_int(int32 i, uint length=MY_INT32_NUM_DECIMAL_DIGITS)
Definition: item.h:5303
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store this item's int-value in a field.
Definition: item.cc:7446
void init(const char *str_arg, uint length)
Init an item from a string we KNOW points to a valid longlong.
Definition: item.cc:3629
uint decimal_precision() const override
Definition: item.h:5399
Item_int(const POS &pos, int32 i, uint length=MY_INT32_NUM_DECIMAL_DIGITS)
Definition: item.h:5309
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5384
Item_int(const Item_int *item_arg)
Definition: item.h:5327
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3672
Item_int(const char *str_arg, uint length)
Definition: item.h:5347
void set_max_size(uint length)
Definition: item.h:5362
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5387
static Item_int * narrow(Item *item)
Definition: item.cc:3612
String * val_str(String *) override
Definition: item.cc:3643
Item_num super
Definition: item.h:5297
enum Type type() const override
Definition: item.h:5372
Item_int(ulonglong i, uint length=MY_INT64_NUM_DECIMAL_DIGITS)
Definition: item.h:5320
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7472
Item_int(const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5334
Item_num * neg() override
Definition: item.h:5395
longlong val_int() override
Definition: item.h:5374
A class that represents a constant JSON value.
Definition: item.h:7525
unique_ptr_destroy_only< Json_wrapper > m_value
Definition: item.h:7526
longlong val_int() override
Definition: item.cc:7910
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:7925
Item_result result_type() const override
Definition: item.h:7536
~Item_json() override
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7887
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:7939
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item.cc:7881
Item * clone_item() const override
Definition: item.cc:7944
Item_json(unique_ptr_destroy_only< Json_wrapper > value, const Item_name_string &name)
Definition: item.cc:7872
my_decimal * val_decimal(my_decimal *buf) override
Definition: item.cc:7921
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:7894
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:7932
double val_real() override
Definition: item.cc:7906
String * val_str(String *str) override
Definition: item.cc:7914
enum Type type() const override
Definition: item.h:7532
The class Item_multi_eq is used to represent conjunctions of equality predicates of the form field1 =...
Definition: item_cmpfunc.h:2715
Definition: item.h:4191
Item * value_item
Definition: item.h:4194
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:2184
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:2179
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.h:4226
Item * name_item
Definition: item.h:4195
Item_result result_type() const override
Definition: item.h:4218
bool fix_fields(THD *, Item **) override
Definition: item.cc:2248
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:2194
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:2283
bool valid_args
Definition: item.h:4196
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:2172
bool cache_const_expr_analyzer(uchar **) override
Check if an item is a constant one and can be cached.
Definition: item.h:4220
longlong val_int() override
Definition: item.cc:2158
double val_real() override
Definition: item.cc:2151
Item_name_const(const POS &pos, Item *name_arg, Item *val)
Definition: item.cc:2196
Item super
Definition: item.h:4192
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2274
enum Type type() const override
Definition: item.h:4204
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:2189
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:2201
String * val_str(String *sp) override
Definition: item.cc:2165
Storage for Item names.
Definition: item.h:372
void set_autogenerated(bool is_autogenerated)
Set m_is_autogenerated flag to the given value.
Definition: item.h:383
bool is_autogenerated() const
Return the auto-generated flag.
Definition: item.h:389
void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg, bool is_autogenerated_arg)
Copy name together with autogenerated flag.
Definition: item.cc:1500
Item_name_string()
Definition: item.h:377
Item_name_string(const Name_string name)
Definition: item.h:378
bool m_is_autogenerated
Definition: item.h:374
Definition: item.h:4900
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store null in field.
Definition: item.cc:7227
Item_null()
Definition: item.h:4914
bool send(Protocol *protocol, String *str) override
Pack data in buffer for sending.
Definition: item.cc:7868
void print(const THD *, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.h:4944
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3992
Item_basic_constant super
Definition: item.h:4901
bool val_time(Time_val *) override
Evaluate the item and return result as a time value.
Definition: item.h:4936
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3994
Item_result result_type() const override
Definition: item.h:4940
Item_null(const POS &pos)
Definition: item.h:4918
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4950
Item * clone_item() const override
Definition: item.h:4941
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:4932
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:4942
double val_real() override
Definition: item.cc:3996
longlong val_int() override
Definition: item.cc:4002
bool val_datetime(Datetime_val *, my_time_flags_t) override
Evaluate the item and return result as a datetime value.
Definition: item.h:4937
Item_null(const Name_string &name_par)
Definition: item.h:4923
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item.cc:4018
String * val_str(String *str) override
Definition: item.cc:4009
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:4016
enum Type type() const override
Definition: item.h:4928
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:4935
void init()
Definition: item.h:4903
Definition: item.h:4250
virtual Item_num * neg()=0
Item_basic_constant super
Definition: item.h:4251
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4258
Item_num()
Definition: item.h:4254
Item_num(const POS &pos)
Definition: item.h:4255
Definition: item.h:6424
bool fix_fields(THD *, Item **) override
Prepare referenced outer field then call usual Item_ref::fix_fields.
Definition: item.cc:9334
Item * replace_outer_ref(uchar *) override
Definition: item.cc:9396
Query_block * qualifying
Qualifying query of this outer ref (i.e.
Definition: item.h:6432
bool found_in_select_list
Definition: item.h:6442
Ref_Type ref_type() const override
Definition: item.h:6476
Item * outer_ref
Definition: item.h:6435
Item_outer_ref(Name_resolution_context *context_arg, Item_ident *ident_arg, Query_block *qualifying)
Definition: item.h:6443
Item_ref super
Definition: item.h:6425
Item_outer_ref(Name_resolution_context *context_arg, Item **item, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg, bool alias_of_expr_arg, Query_block *qualifying)
Definition: item.h:6458
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.h:6474
table_map used_tables() const override
Definition: item.h:6471
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.cc:9385
Item_sum * in_sum_func
Definition: item.h:6437
Dynamic parameters used as placeholders ('?') inside prepared statements.
Definition: item.h:4955
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:4627
void set_data_type_actual(enum_field_types data_type, bool unsigned_val)
For use with all field types, especially integer types.
Definition: item.h:5185
union Item_param::@61 value
enum_field_types data_type_source() const
Definition: item.h:5189
void reset()
Resets parameter after execution.
Definition: item.cc:4562
void set_null()
Definition: item.cc:4259
bool set_value(THD *, sp_rcontext *, Item **it) override
This operation is intended to store some item value in Item_param to be used later.
Definition: item.cc:5365
Time_val m_time
Definition: item.h:4997
void set_time(Datetime_val *dt, enum_mysql_timestamp_type type)
Set parameter value from MYSQL_TIME value.
Definition: item.cc:4369
const String * query_val_str(const THD *thd, String *str) const
Return Param item values in string format, for generating the dynamic query used in update/binary log...
Definition: item.cc:4898
bool m_json_as_scalar
If true, when retrieving JSON data, attempt to interpret a string value as a scalar JSON value,...
Definition: item.h:5108
bool is_type_inherited() const
Definition: item.h:5137
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:4762
double real
Definition: item.h:5001
void set_param_state(enum enum_item_param_state state)
Definition: item.h:4976
bool is_type_pinned() const
Definition: item.h:5143
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:5265
Mem_root_array< Item_param * > m_clones
If a query expression's text QT or text of a condition (CT) that is pushed down to a derived table,...
Definition: item.h:5293
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:4575
String * val_str(String *) override
Definition: item.cc:4793
void sync_clones()
This should be called after any modification done to this Item, to propagate the said modification to...
Definition: item.cc:4228
void set_collation_actual(const CHARSET_INFO *coll)
Definition: item.h:5152
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:4835
void set_out_param_info(Send_field *info) override
Setter of Item_param::m_out_param_info.
Definition: item.cc:5428
Date_val m_date
Definition: item.h:4996
bool set_from_user_var(THD *thd, const user_var_entry *entry)
Set parameter value from user variable value.
Definition: item.cc:4470
Item_result m_result_type
Result type of parameter.
Definition: item.h:5093
uint pos_in_query
Definition: item.h:5124
bool is_unsigned_actual() const
Definition: item.h:5146
void set_data_type_source(enum_field_types data_type, bool unsigned_val)
Definition: item.h:5176
bool add_clone(Item_param *i)
Definition: item.h:5244
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:5225
longlong integer
Definition: item.h:5000
void pin_data_type() override
Pin the currently resolved data type for this parameter.
Definition: item.h:5140
const CHARSET_INFO * m_collation_source
The character set and collation of the source parameter value.
Definition: item.h:5083
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:4662
bool is_non_const_over_literals(uchar *) override
Definition: item.h:5238
String str_value_ptr
Definition: item.h:4994
const Send_field * get_out_param_info() const override
Getter of Item_param::m_out_param_info.
Definition: item.cc:5447
enum_field_types data_type_actual() const
Definition: item.h:5191
my_decimal decimal_value
Definition: item.h:4995
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:5247
Item_result result_type() const override
Definition: item.h:5130
enum_field_types m_data_type_actual
The actual data type of the parameter value provided by the user.
Definition: item.h:5074
void set_decimal(const char *str, ulong length)
Set decimal parameter value from string.
Definition: item.cc:4303
void make_field(Send_field *field) override
Fill meta-data information for the corresponding column in a result set.
Definition: item.cc:5459
bool is_valid_for_pushdown(uchar *arg) override
Check if all the columns present in this expression are from the derived table.
Definition: item.h:5266
enum_item_param_state
Definition: item.h:4963
@ STRING_VALUE
Definition: item.h:4968
@ DECIMAL_VALUE
Definition: item.h:4973
@ NO_VALUE
Definition: item.h:4964
@ REAL_VALUE
Definition: item.h:4967
@ TIME_VALUE
Definition: item.h:4969
@ LONG_DATA_VALUE
Definition: item.h:4972
@ INT_VALUE
Definition: item.h:4966
@ DATETIME_VALUE
Definition: item.h:4971
@ NULL_VALUE
Definition: item.h:4965
@ DATE_VALUE
Definition: item.h:4970
Datetime_val m_datetime
Definition: item.h:4998
enum_field_types m_data_type_source
Parameter objects have a rather complex handling of data type, in order to consistently handle requir...
Definition: item.h:5053
enum Type type() const override
Definition: item.h:5131
enum_item_param_state m_param_state
m_param_state is used to indicate that no parameter value is available with NO_VALUE,...
Definition: item.h:5102
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:5260
void set_int(longlong i)
Definition: item.cc:4268
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:5252
bool convert_value()
Convert value according to the following rules:
Definition: item.cc:4981
void set_data_type_inherited() override
Set the currently resolved data type for this parameter as inherited.
Definition: item.h:5134
const CHARSET_INFO * collation_actual() const
Definition: item.h:5160
bool fix_fields(THD *thd, Item **ref) override
Definition: item.cc:4096
void set_date(Date_val date)
Set parameter value from date value.
Definition: item.cc:4338
Send_field * m_out_param_info
Definition: item.h:5272
void set_datetime(Datetime_val dt)
Set parameter value from datetime value.
Definition: item.cc:4352
bool do_itemize(Parse_context *pc, Item **item) override
The core function that does the actual itemization.
Definition: item.cc:4032
void set_collation_source(const CHARSET_INFO *coll)
Definition: item.h:5148
const CHARSET_INFO * collation_source() const
Definition: item.h:5157
longlong val_int() override
Definition: item.cc:4725
bool set_str(const char *str, size_t length)
Definition: item.cc:4401
bool m_unsigned_actual
Used when actual value is integer to indicate whether value is unsigned.
Definition: item.h:5076
bool m_type_inherited
True if type of parameter is inherited from parent object (like a typecast).
Definition: item.h:5011
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:5248
double val_real() override
Definition: item.cc:4684
enum_field_types actual_data_type() const override
Retrieve actual data type for an item.
Definition: item.h:5193
enum enum_item_param_state param_state() const
Definition: item.h:4980
Item * clone_item() const override
Definition: item.cc:5224
const CHARSET_INFO * m_collation_actual
The character set and collation of the value stored in str_value, possibly after being converted from...
Definition: item.h:5091
void set_param_type_and_swap_value(Item_param *from)
Preserve the original parameter types and values when re-preparing a prepared statement.
Definition: item.cc:5335
bool m_type_pinned
True if type of parameter has been pinned, attempt to use an incompatible actual type will cause erro...
Definition: item.h:5022
bool propagate_type(THD *thd, const Type_properties &type) override
Propagate data type specifications into parameters and user variables.
Definition: item.cc:4150
void set_double(double i)
Definition: item.cc:4284
void mark_json_as_scalar() override
For Items with data type JSON, mark that a string argument is treated as a scalar JSON value.
Definition: item.h:4982
bool set_longdata(const char *str, ulong length)
Definition: item.cc:4429
void copy_param_actual_type(Item_param *from)
Definition: item.cc:4846
Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg)
Definition: item.cc:4025
table_map used_tables() const override
Definition: item.h:5221
void set_data_type_actual(enum_field_types data_type)
Definition: item.h:5181
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:4605
Item super
Definition: item.h:4956
Definition: item.h:5885
Item_partition_func_safe_string(const Name_string name, size_t length, const CHARSET_INFO *cs=nullptr)
Definition: item.h:5887
Definition: item.h:6488
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:5531
Item_ref_null_helper(const Item_ref_null_helper &ref_null_helper, Item **item)
Definition: item.h:6498
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:5543
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:5513
bool val_bool() override
Definition: item.cc:5519
String * val_str(String *s) override
Definition: item.cc:5525
Item_in_subselect * owner
Definition: item.h:6492
Item_ref_null_helper(Name_resolution_context *context_arg, Item_in_subselect *master, Item **item)
Definition: item.h:6495
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:5507
longlong val_int() override
Definition: item.cc:5501
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9206
Item_ref super
Definition: item.h:6489
double val_real() override
Definition: item.cc:5495
Ref_Type ref_type() const override
Definition: item.h:6512
table_map used_tables() const override
Definition: item.h:6516
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:5537
Definition: item.h:6090
Item * compile(Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t) override
Compile an Item_ref object with a processor and a transformer callback function.
Definition: item.cc:9038
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item.h:6189
bool created_by_in2exists() const override
Whether this Item was created by the IN->EXISTS subquery transformation.
Definition: item.h:6294
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:9128
bool collect_item_field_or_ref_processor(uchar *arg) override
Definition: item.cc:9217
bool is_result_field() const override
Definition: item.h:6210
void set_properties()
Definition: item.cc:8972
table_map used_tables() const override
Definition: item.h:6181
Item_field * field_for_view_update() override
Definition: item.h:6254
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:9135
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.h:6149
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:9162
Item_ref(THD *thd, Item_ref *item)
Definition: item.h:6135
Item ** addr(uint i) override
Definition: item.h:6268
void traverse_cond(Cond_traverser traverser, void *arg, traverse_order order) override
Definition: item.h:6233
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.cc:9186
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the item from the item tree.
Definition: item.cc:8647
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:8730
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:6300
bool is_valid_for_pushdown(uchar *arg) override
Check if all the columns present in this expression are from the derived table.
Definition: item.h:6309
Item_result result_type() const override
Definition: item.h:6172
void make_field(Send_field *field) override
Definition: item.cc:9170
void bring_value() override
Definition: item.h:6281
uint cols() const override
Definition: item.h:6260
Item ** ref_pointer() const
Definition: item.h:6144
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:9121
bool val_bool() override
Definition: item.cc:9107
bool is_outer_field() const override
Definition: item.h:6288
bool null_inside() override
Definition: item.h:6277
void set_result_field(Field *field) override
Definition: item.h:6209
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9055
Item * real_item() override
Definition: item.h:6212
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:9099
Field * get_tmp_table_field() override
If this Item is being materialized into a temporary table, returns the field that is being materializ...
Definition: item.h:6176
Item_result cast_to_int_type() const override
Definition: item.h:6306
Ref_Type
Definition: item.h:6097
@ NULL_HELPER_REF
Definition: item.h:6097
@ VIEW_REF
Definition: item.h:6097
@ REF
Definition: item.h:6097
@ AGGREGATE_REF
Definition: item.h:6097
@ OUTER_REF
Definition: item.h:6097
String * val_str(String *tmp) override
Definition: item.cc:9114
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:9070
Field * result_field
Definition: item.h:6103
bool explain_subquery_checker(uchar **) override
Definition: item.h:6240
void link_referenced_item()
Definition: item.h:6146
bool check_column_in_window_functions(uchar *arg) override
Check if all the columns present in this expression are present in PARTITION clause of window functio...
Definition: item.h:6312
bool is_non_const_over_literals(uchar *) override
Definition: item.h:6299
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:8992
const Item * real_item() const override
Definition: item.h:6217
Item_ref(const POS &pos, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:6110
Field * get_result_field() const override
Definition: item.h:6211
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item.h:6174
bool walk(Item_processor processor, enum_walk walk, uchar *arg) override
Traverses a tree of Items in prefix and/or postfix order.
Definition: item.h:6223
enum Type type() const override
Definition: item.h:6148
bool send(Protocol *prot, String *tmp) override
This is only called from items that is not of type item_field.
Definition: item.cc:9081
bool pusheddown_depended_from
Definition: item.h:6100
bool check_column_in_group_by(uchar *arg) override
Check if all the columns present in this expression are present in GROUP BY clause of the derived tab...
Definition: item.h:6315
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.cc:9402
virtual Ref_Type ref_type() const
Definition: item.h:6257
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:9142
bool basic_const_item() const override
Returns true if this is a simple constant item like an integer, not a constant expression.
Definition: item.h:6286
Item * transform(Item_transformer, uchar *arg) override
Transform an Item_ref object with a transformer callback function.
Definition: item.cc:9008
bool repoint_const_outer_ref(uchar *arg) override
The aim here is to find a real_item() which is of type Item_field.
Definition: item.cc:11814
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.h:6199
Item * element_index(uint i) override
Definition: item.h:6264
bool check_cols(uint c) override
Definition: item.h:6272
Item ** m_ref_item
Indirect pointer to the referenced item.
Definition: item.h:6107
longlong val_int() override
Definition: item.cc:9092
Item * ref_item() const
Definition: item.h:6141
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:9156
double val_real() override
Definition: item.cc:9085
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:9149
Item with result field.
Definition: item.h:6025
Item_result_field(const POS &pos)
Definition: item.h:6030
Field * tmp_table_field(TABLE *) override
Definition: item.h:6036
Field * result_field
Definition: item.h:6027
int raise_decimal_overflow()
Definition: item.h:6084
longlong raise_integer_overflow()
Definition: item.h:6079
Field * get_tmp_table_field() override
If this Item is being materialized into a temporary table, returns the field that is being materializ...
Definition: item.h:6035
Item_result_field(THD *thd, const Item_result_field *item)
Definition: item.h:6033
virtual bool resolve_type(THD *thd)=0
Resolve type-related information for this item, such as result field type, maximum size,...
longlong llrint_with_overflow_check(double realval)
Definition: item.h:6064
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:6056
bool check_function_as_value_generator(uchar *) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:6055
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:11653
void raise_numeric_overflow(const char *type_name)
Definition: item.cc:11659
Item_result_field()=default
double raise_float_overflow()
Definition: item.h:6074
bool is_result_field() const override
Definition: item.h:6051
table_map used_tables() const override
Definition: item.h:6037
void set_result_field(Field *field) override
Definition: item.h:6050
Field * get_result_field() const override
Definition: item.h:6052
Definition: item.h:5928
Item_return_int(const char *name_arg, uint length, enum_field_types field_type_arg, longlong value_arg=0)
Definition: item.h:5930
Class that represents scalar subquery and row subquery.
Definition: item_subselect.h:283
Definition: item.h:4015
bool is_valid_for_pushdown(uchar *arg) override
Check if all the columns present in this expression are from the derived table.
Definition: item.h:4051
Item_sp_variable(const Name_string sp_var_name)
Definition: item.cc:1935
Name_string m_name
Definition: item.h:4017
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:2018
String * val_str(String *sp) override
Definition: item.cc:1977
bool fix_fields(THD *thd, Item **) override
Definition: item.cc:1938
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:2026
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item.cc:2010
void make_field(Send_field *field) override
Definition: item.h:4065
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:2032
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.h:4071
double val_real() override
Definition: item.cc:1961
longlong val_int() override
Definition: item.cc:1969
table_map used_tables() const override
Definition: item.h:4031
bool send(Protocol *protocol, String *str) override
This is only called from items that is not of type item_field.
Definition: item.h:4046
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:2038
sp_head * m_sp
Definition: item.h:4025
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:2044
Definition: item.h:4082
bool limit_clause_param
Definition: item.h:4092
Item_result result_type() const override
Definition: item.h:4132
bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override
Definition: item.cc:2105
uint len_in_query
Definition: item.h:4111
bool is_splocal() const override
Definition: item.h:4117
uint get_var_idx() const
Definition: item.h:4129
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:2081
uint m_var_idx
Definition: item.h:4083
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:4141
uint pos_in_query
Definition: item.h:4103
Item * this_item() override
Definition: item.cc:2063
Item_splocal(const Name_string sp_var_name, uint sp_var_idx, enum_field_types sp_var_type, uint pos_in_q=0, uint len_in_q=0)
Definition: item.cc:2050
Type type() const override
Definition: item.h:4131
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:2100
Item ** this_item_addr(THD *thd, Item **) override
Definition: item.cc:2075
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2088
Definition: item.h:5855
void print(const THD *, String *str, enum_query_type) const override
Definition: item.h:5871
Item_static_string_func(const Name_string &name_par, const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE)
Definition: item.h:5859
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5875
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:5876
const Name_string func_name
Definition: item.h:5856
Item_static_string_func(const POS &pos, const Name_string &name_par, const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE)
Definition: item.h:5864
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3987
Definition: item.h:5651
Item_string(const POS &pos, const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5693
String * val_str(String *) override
Definition: item.h:5777
Item_string(const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5687
void set_cs_specified(bool cs_specified)
Set the value of m_cs_specified attribute.
Definition: item.h:5839
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:1595
bool is_cs_specified() const
Return true if character-set-introducer was explicitly specified in the original query for this item ...
Definition: item.h:5827
Item_string(const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE)
Definition: item.h:5701
Item_string(const POS &pos)
Definition: item.h:5655
void append(char *str, size_t length)
Definition: item.h:5798
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5786
void init(const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv, uint repertoire)
Definition: item.h:5659
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5806
Item_string(const POS &pos, const Name_string name_par, const LEX_CSTRING &literal, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5740
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5782
void mark_result_as_const()
Definition: item.h:5843
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:7396
Item_result result_type() const override
Definition: item.h:5789
Item * clone_item() const override
Definition: item.h:5794
bool m_cs_specified
Definition: item.h:5846
void print(const THD *thd, String *str, enum_query_type query_type) const override
Definition: item.cc:3853
void set_value_collation()
Update collation of string value to be according to item's collation.
Definition: item.h:5768
Item_string(const Name_string name_par, const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5711
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3909
Item_basic_constant super
Definition: item.h:5652
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5785
void set_str_with_copy(const char *str_arg, uint length_arg)
Definition: item.h:5760
double val_real() override
Definition: item.cc:3927
Item_string(const POS &pos, const Name_string name_par, const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5724
void set_repertoire_from_value()
Definition: item.h:5770
longlong val_int() override
Definition: item.cc:3976
bool eq_binary(const Item_string *item) const
Definition: item.h:5791
enum Type type() const override
Definition: item.h:5774
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3983
Base class that is common to all subqueries and subquery predicates.
Definition: item_subselect.h:80
Class Item_sum is the base class used for special expressions that SQL calls 'set functions'.
Definition: item_sum.h:399
Definition: item.h:6555
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:6565
Item_temporal_with_ref(enum_field_types field_type_arg, uint8 decimals_arg, longlong i, Item *ref_arg, bool unsigned_arg)
Definition: item.h:6557
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7506
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:6569
Definition: item.h:5428
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store this item's int-value in a field.
Definition: item.cc:7452
Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5440
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:5455
Item * clone_item() const override
Definition: item.h:5451
Item_temporal(enum_field_types field_type_arg, longlong i)
Definition: item.h:5434
bool val_datetime(Datetime_val *, my_time_flags_t) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5463
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:5454
bool val_time(Time_val *) override
Evaluate the item and return result as a time value.
Definition: item.h:5459
Utility mixin class to be able to walk() only parts of item trees.
Definition: item.h:737
bool is_stopped(const Item *i)
Definition: item.h:754
const Item * stopped_at_item
Definition: item.h:775
void stop_at(const Item *i)
Stops walking children of this item.
Definition: item.h:745
Item_tree_walker(const Item_tree_walker &)=delete
Item_tree_walker()
Definition: item.h:739
Item_tree_walker & operator=(const Item_tree_walker &)=delete
~Item_tree_walker()
Definition: item.h:740
Represents NEW/OLD version of field of row which is changed/read in trigger.
Definition: item.h:6840
SQL_I_List< Item_trigger_field > * next_trig_field_list
Definition: item.h:6850
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:10033
void setup_field(Table_trigger_field_support *table_triggers, GRANT_INFO *table_grant_info)
Find index of Field object which will be appropriate for item representing field of row being changed...
Definition: item.cc:9917
uint field_idx
Definition: item.h:6852
GRANT_INFO * table_grants
Definition: item.h:6933
bool check_column_privileges(uchar *arg) override
Check privileges of base table column.
Definition: item.cc:10022
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.h:6889
Item_trigger_field(const POS &pos, enum_trigger_variable_type trigger_var_type_arg, const char *field_name_arg, Access_bitmask priv, const bool ro)
Definition: item.h:6867
bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override
Definition: item.cc:9938
Item_trigger_field(Name_resolution_context *context_arg, enum_trigger_variable_type trigger_var_type_arg, const char *field_name_arg, Access_bitmask priv, const bool ro)
Definition: item.h:6856
bool set_value(THD *thd, Item **it)
Definition: item.h:6914
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9929
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:6910
Item_trigger_field * next_trg_field
Definition: item.h:6845
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:10040
Access_bitmask want_privilege
Definition: item.h:6932
enum Type type() const override
Definition: item.h:6879
Item * copy_or_same(THD *) override
Definition: item.h:6888
Table_trigger_field_support * triggers
Definition: item.h:6854
Field * get_tmp_table_field() override
If this Item is being materialized into a temporary table, returns the field that is being materializ...
Definition: item.h:6887
enum_trigger_variable_type trigger_var_type
Definition: item.h:6843
table_map used_tables() const override
Definition: item.h:6886
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9965
bool read_only
Definition: item.h:6938
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:10001
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:6895
bool is_valid_for_pushdown(uchar *args) override
Check if all the columns present in this expression are from the derived table.
Definition: item.h:6902
void set_required_privilege(Access_bitmask privilege) override
Set required privileges for accessing the parameter.
Definition: item.h:6891
Item_type_holder stores an aggregation of name, type and type specification of UNIONS and derived tab...
Definition: item.h:7447
Item_aggregate_type super
Definition: item.h:7448
enum Type type() const override
Definition: item.h:7456
table_map used_tables() const override
Class is used in type aggregation only - this is needed to ensure that it is not attempted to be eval...
Definition: item.h:7462
Item_type_holder(THD *thd, Item *item)
Definition: item.h:7454
String * val_str(String *) override
Definition: item.cc:11520
longlong val_int() override
Definition: item.cc:11510
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:11530
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:11525
double val_real() override
Definition: item.cc:11505
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11515
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:11535
Definition: item.h:5469
uint decimal_precision() const override
Definition: item.h:5501
Item * clone_item() const override
Definition: item.h:5494
Item_num * neg() override
Definition: item.cc:7524
Item_uint(const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5484
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3681
Item_uint(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5478
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store this item's int-value in a field.
Definition: item.cc:7402
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3690
double val_real() override
Definition: item.h:5488
String * val_str(String *) override
Definition: item.cc:3674
Item_uint(const char *str_arg, uint length)
Definition: item.h:5475
Item_uint(ulonglong i)
Definition: item.h:5483
Reference item that encapsulates both the type and the contained items of a single column of a VALUES...
Definition: item.h:7488
Item_values_column(THD *thd, Item *ref)
Definition: item.cc:11548
void set_value(Item *new_value)
Definition: item.h:7519
Item * m_value_ref
Definition: item.h:7492
table_map used_tables() const override
Definition: item.h:7520
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:11627
Item_aggregate_type super
Definition: item.h:7489
longlong val_int() override
Definition: item.cc:11563
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:11540
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11570
bool is_null() override
Item_values_column is dualistic in nature: It represents both a set of values, and,...
Definition: item.cc:11612
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:11552
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:11586
enum Type type() const override
Definition: item.h:7518
String * val_str(String *tmp) override
Definition: item.cc:11595
void add_used_tables(Item *value)
Definition: item.cc:11649
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:11641
double val_real() override
Definition: item.cc:11556
bool val_bool() override
Definition: item.cc:11578
table_map m_aggregated_used_tables
Definition: item.h:7499
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:11634
Class for fields from derived tables and views.
Definition: item.h:6326
Ref_Type ref_type() const override
Definition: item.h:6369
Table_ref * first_inner_table
If this column belongs to a view that is an inner table of an outer join, then this field points to t...
Definition: item.h:6412
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:6372
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.h:6363
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:9501
Item_view_ref(Name_resolution_context *context_arg, Item **item, const char *db_name_arg, const char *alias_name_arg, const char *table_name_arg, const char *field_name_arg, Table_ref *tr)
Definition: item.h:6330
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:9461
bool collect_item_field_or_view_ref_processor(uchar *arg) override
Collects fields and view references that have the qualifying table in the specified query block.
Definition: item.cc:9520
bool has_null_row() const
Definition: item.h:6404
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:9512
double val_real() override
Definition: item.cc:9437
bool send(Protocol *prot, String *tmp) override
This is only called from items that is not of type item_field.
Definition: item.cc:9507
bool fix_fields(THD *, Item **) override
Prepare referenced field then call usual Item_ref::fix_fields .
Definition: item.cc:9237
bool val_bool() override
Definition: item.cc:9485
Item * replace_item_view_ref(uchar *arg) override
Definition: item.cc:9542
longlong val_int() override
Definition: item.cc:9429
Item_ref super
Definition: item.h:6327
bool subst_argument_checker(uchar **) override
Definition: item.h:6356
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:9469
Table_ref * get_first_inner_table() const
Definition: item.h:6396
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item.cc:9493
table_map used_tables() const override
Return the set of tables this view column logically depends on.
Definition: item.cc:9285
String * val_str(String *str) override
Definition: item.cc:9453
bool check_column_privileges(uchar *arg) override
Check privileges of view column.
Definition: item.cc:1436
Item * replace_view_refs_with_clone(uchar *arg) override
Assuming this expression is part of a condition that would be pushed to a materialized derived table,...
Definition: item.cc:9576
my_decimal * val_decimal(my_decimal *dec) override
Definition: item.cc:9445
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:9477
bool eq(const Item *item) const override
Compare two view column references for equality.
Definition: item.cc:9418
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:929
void increment_ref_count()
Increment reference count.
Definition: item.h:3514
virtual double val_real()=0
uint32 max_char_length() const
Definition: item.h:3467
String * make_empty_result()
Sets the result value of the function an empty string, using the current character set.
Definition: item.h:940
virtual const CHARSET_INFO * compare_collation() const
Definition: item.h:2692
virtual float get_filtering_effect(THD *thd, table_map filter_for_table, table_map read_tables, const MY_BITMAP *fields_to_ignore, double rows_in_table)
Calculate the filter contribution that is relevant for table 'filter_for_table' for this item.
Definition: item.h:2153
virtual Field::geometry_type get_geometry_type() const
Definition: item.h:3450
String str_value
str_values's main purpose is to cache the value in save_in_field
Definition: item.h:3674
bool skip_itemize(Item **res)
Helper function to skip itemize() for grammar-allocated items.
Definition: item.h:1203
void set_nullable(bool nullable)
Definition: item.h:3786
bool get_datetime_from_numeric(Datetime_val *dt, my_time_flags_t flags)
Convert a numeric type to datetime.
Definition: item.cc:1717
virtual bool change_context_processor(uchar *)
Definition: item.h:2910
void set_data_type_date()
Set all type properties for Item of DATE type.
Definition: item.h:1696
void set_data_type_blob(enum_field_types type, uint32 max_l)
Set the Item to be of BLOB type.
Definition: item.h:1683
virtual bool check_column_in_group_by(uchar *arg)
Check if all the columns present in this expression are present in GROUP BY clause of the derived tab...
Definition: item.h:3224
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3681
ulonglong val_uint()
Definition: item.h:1941
bool has_subquery() const
Definition: item.h:3545
virtual bool subst_argument_checker(uchar **arg)
Definition: item.h:3151
CostOfItem cost() const
Definition: item.h:3456
bool contains_item(uchar *arg)
Definition: item.h:2833
my_decimal * val_decimal_from_datetime(my_decimal *decimal_value)
Definition: item.cc:429
void set_data_type_bool()
Definition: item.h:1524
longlong val_int_from_decimal()
Definition: item.cc:500
bool has_stored_program() const
Definition: item.h:3548
String * val_string_from_int(String *str)
Definition: item.cc:315
int error_int()
Get the value to return from val_int() in case of errors.
Definition: item.h:2240
bool get_time_from_datetime(Time_val *time)
Convert datetime to time.
Definition: item.cc:1810
virtual bool subq_opt_away_processor(uchar *)
Definition: item.h:3660
bool get_date_from_int(Date_val *date, my_time_flags_t flags)
Convert val_int() to date.
Definition: item.cc:1653
void set_data_type(enum_field_types data_type)
Set the data type of the current Item.
Definition: item.h:1513
bool error_date()
Get the value to return from val_date() in case of errors.
Definition: item.h:2264
virtual bool collect_item_field_or_view_ref_processor(uchar *)
Collects fields and view references that have the qualifying table in the specified query block.
Definition: item.h:2880
bool has_aggregation() const
Definition: item.h:3553
virtual bool find_field_processor(uchar *)
Is this an Item_field which references the given Field argument?
Definition: item.h:2916
longlong val_int_from_datetime()
Definition: item.cc:527
void set_data_type_string(ulonglong max_char_length_arg)
Set the Item to be variable length string.
Definition: item.h:1617
my_decimal * val_decimal_from_string(my_decimal *decimal_value)
Definition: item.cc:390
void aggregate_float_properties(enum_field_types type, Item **items, uint nitems)
Set max_length and decimals of function if function is floating point and result length/precision dep...
Definition: item.cc:8274
bool is_nullable() const
Definition: item.h:3785
void set_data_type_geometry()
Set the data type of the Item to be GEOMETRY.
Definition: item.h:1755
double error_real()
Get the value to return from val_real() in case of errors.
Definition: item.h:2252
virtual bool do_itemize(Parse_context *pc, Item **res)
The core function that does the actual itemization.
Definition: item.cc:807
void save_in_field_no_error_check(Field *field, bool no_conversions)
A slightly faster value of save_in_field() that returns no error value (you will need to check thd->i...
Definition: item.h:1426
virtual enum_field_types actual_data_type() const
Retrieve actual data type for an item.
Definition: item.h:1489
static const CHARSET_INFO * default_charset()
Definition: item.cc:1880
virtual bool split_sum_func(THD *, Ref_item_array, mem_root_deque< Item * > *)
Definition: item.h:2580
void init_make_field(Send_field *tmp_field, enum enum_field_types type)
Definition: item.cc:6844
virtual bool propagate_type(THD *thd, const Type_properties &type)
Propagate data type specifications into parameters and user variables.
Definition: item.h:1314
virtual Item * replace_func_call(uchar *)
Definition: item.h:3364
String * val_string_from_date(String *str)
Definition: item.cc:346
bool is_non_deterministic() const
Definition: item.h:2518
void set_subquery()
Set the "has subquery" property.
Definition: item.h:3538
void fix_char_length(uint32 max_char_length_arg)
Definition: item.h:3488
void operator=(Item &)=delete
virtual bool is_bool_func() const
Definition: item.h:2663
void mark_subqueries_optimized_away()
Definition: item.h:3596
String * null_return_str()
Gets the value to return from val_str() when returning a NULL value.
Definition: item.h:2299
double val_real_from_decimal()
Definition: item.cc:480
virtual bool disable_constant_propagation(uchar *)
Definition: item.h:3160
Item()
Item constructor for general use.
Definition: item.cc:163
bool has_grouping_set_dep() const
Definition: item.h:3571
uint8 m_data_type
Data type assigned to Item.
Definition: item.h:3765
bool get_time_from_decimal(Time_val *time)
Convert val_decimal() to time.
Definition: item.cc:1789
void set_data_type_float()
Set the data type of the Item to be single precision floating point.
Definition: item.h:1587
void reset_aggregation()
Reset the "has aggregation" property.
Definition: item.h:3559
virtual Item * this_item()
Definition: item.h:3262
void print_for_order(const THD *thd, String *str, enum_query_type query_type, const char *used_alias) const
Prints the item when it's part of ORDER BY and GROUP BY.
Definition: item.cc:914
bool is_temporal_with_date() const
Definition: item.h:3410
virtual bool strip_db_table_name_processor(uchar *)
Definition: item.h:3649
static Item_result type_to_result(enum_field_types type)
Definition: item.h:1042
virtual table_map used_tables() const
Definition: item.h:2418
String * val_string_from_datetime(String *str)
Definition: item.cc:333
virtual bool equality_substitution_analyzer(uchar **)
Definition: item.h:3099
virtual bool find_item_in_field_list_processor(uchar *)
Definition: item.h:2909
virtual longlong val_date_temporal_at_utc()
Definition: item.h:2394
bool get_datetime_from_non_temporal(Datetime_val *dt, my_time_flags_t flags)
Convert a non-temporal type to datetime.
Definition: item.cc:1738
virtual bool val_date(Date_val *date, my_time_flags_t flags)=0
Evaluate the item and return result as a date value.
virtual bool created_by_in2exists() const
Whether this Item was created by the IN->EXISTS subquery transformation.
Definition: item.h:3594
static enum_field_types string_field_type(uint32 max_bytes)
Determine correct string field type, based on string length.
Definition: item.h:1812
bool error_json()
Get the value to return from val_json() in case of errors.
Definition: item.h:2172
virtual void cleanup()
Called for every Item after use (preparation and execution).
Definition: item.h:1275
virtual Item * real_item()
Definition: item.h:2676
virtual Item * equality_substitution_transformer(uchar *)
Definition: item.h:3101
void set_stored_program()
Set the "has stored program" property.
Definition: item.h:3541
virtual bool eq(const Item *) const
Compare this item with another item for equality.
Definition: item.cc:1526
virtual bool supports_partial_update(const Field_json *field) const
Check if this expression can be used for partial update of a given JSON column.
Definition: item.h:3896
virtual enum_field_types default_data_type() const
Get the default data (output) type for the specific item.
Definition: item.h:1502
void set_data_type_string(uint32 max_l, const CHARSET_INFO *cs)
Set the Item to be variable length string.
Definition: item.h:1635
virtual bool explain_subquery_checker(uchar **)
Definition: item.h:3155
bool get_datetime_from_time(Datetime_val *dt)
Convert val_time() to datetime.
Definition: item.cc:1681
uint m_ref_count
Number of references to this item.
Definition: item.h:3762
virtual Field * make_string_field(TABLE *table) const
Create a field to hold a string value from an item.
Definition: item.cc:6966
virtual bool replace_equal_field_checker(uchar **)
Definition: item.h:3167
virtual my_decimal * val_decimal(my_decimal *decimal_buffer)=0
void add_accum_properties(const Item *item)
Add more accumulated properties to an Item.
Definition: item.h:3533
virtual bool check_valid_arguments_processor(uchar *)
Definition: item.h:3173
longlong val_int_from_date()
Definition: item.cc:520
virtual Settable_routine_parameter * get_settable_routine_parameter()
Definition: item.h:3407
virtual Item * equal_fields_propagator(uchar *)
Definition: item.h:3158
bool error_bool()
Get the value to return from val_bool() in case of errors.
Definition: item.h:2228
virtual type_conversion_status save_in_field_inner(Field *field, bool no_conversions)
Helper function which does all of the work for save_in_field(Field*, bool), except some error checkin...
Definition: item.cc:7264
virtual bool remove_column_from_bitmap(uchar *arg)
Visitor interface for removing all column expressions (Item_field) in this expression tree from a bit...
Definition: item.h:2906
virtual bool update_depended_from(uchar *)
Definition: item.h:3083
void set_data_type_double()
Set the data type of the Item to be double precision floating point.
Definition: item.h:1579
my_decimal * val_decimal_from_int(my_decimal *decimal_value)
Definition: item.cc:381
void set_data_type_year()
Set the data type of the Item to be YEAR.
Definition: item.h:1774
virtual uint decimal_precision() const
Definition: item.cc:827
Item_result cmp_context
Comparison context.
Definition: item.h:3744
virtual void allow_array_cast()
A helper function to ensure proper usage of CAST(.
Definition: item.h:3909
virtual Item * truth_transformer(THD *thd, Bool_test test)
Informs an item that it is wrapped in a truth test, in case it wants to transforms itself to implemen...
Definition: item.h:3289
bool get_time_from_date(Time_val *time)
Convert date to time.
Definition: item.cc:1802
Item(const Item &)=delete
type_conversion_status save_datetime_in_field(Field *field)
Definition: item.cc:569
virtual Item * replace_equal_field(uchar *)
Definition: item.h:3166
virtual Item * element_index(uint)
Definition: item.h:3273
virtual bool check_function_as_value_generator(uchar *args)
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.cc:964
virtual void traverse_cond(Cond_traverser traverser, void *arg, traverse_order)
Definition: item.h:2814
bool get_time_from_numeric(Time_val *time)
Convert a numeric type to time.
Definition: item.cc:1819
uint float_length(uint decimals_par) const
Definition: item.h:2454
Field * tmp_table_field_from_field_type(TABLE *table, bool fixed_length) const
Create a field based on field_type of argument.
Definition: item.cc:7001
virtual Item * copy_andor_structure(THD *)
Definition: item.h:2670
virtual bool val_json(Json_wrapper *result)
Get a JSON value from an Item.
Definition: item.h:2125
virtual longlong val_int()=0
virtual Item_field * field_for_view_update()
Definition: item.h:3282
static constexpr uint8 PROP_GROUPING_FUNC
Set if the item or one or more of the underlying items is a GROUPING function.
Definition: item.h:3850
virtual void print(const THD *, String *str, enum_query_type) const
This method is used for to:
Definition: item.h:2542
enum_field_types data_type() const
Retrieve the derived data type of the Item.
Definition: item.h:1481
virtual bool collect_outer_field_processor(uchar *)
Definition: item.h:2838
static constexpr uint8 PROP_SUBQUERY
Set of properties that are calculated by accumulation from underlying items.
Definition: item.h:3837
Item_name_string item_name
Name from query.
Definition: item.h:3682
void set_data_type_int(enum_field_types type, bool unsigned_prop, uint32 max_width)
Set the data type of the Item to be a specific integer type.
Definition: item.h:1538
const Item * unwrap_for_eq() const
Unwrap an Item argument so that Item::eq() can see the "real" item, and not just the wrapper.
Definition: item.cc:1542
bool eq_by_collation(Item *item, const CHARSET_INFO *cs)
Compare two items using a given collation.
Definition: item.cc:6939
void print_item_w_name(const THD *thd, String *, enum_query_type query_type) const
Definition: item.cc:884
virtual String * val_str_ascii(String *str)
Definition: item.cc:275
virtual Item * get_tmp_table_item(THD *thd)
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.h:2689
~Item() override=default
virtual bool fix_fields(THD *, Item **)
Definition: item.cc:5486
virtual bool check_column_privileges(uchar *thd)
Check privileges.
Definition: item.h:2975
bool fixed
True if item has been resolved.
Definition: item.h:3774
static bool bit_func_returns_binary(const Item *a, const Item *b)
Definition: item_func.cc:3442
enum_const_item_cache
How to cache constant JSON data.
Definition: item.h:998
@ CACHE_NONE
Don't cache.
Definition: item.h:1000
@ CACHE_JSON_VALUE
Source data is a JSON string, parse and cache result.
Definition: item.h:1002
@ CACHE_JSON_ATOM
Source data is SQL scalar, convert and cache result.
Definition: item.h:1004
virtual Item_result result_type() const
Definition: item.h:1451
bool const_item() const
Returns true if item is constant, regardless of query evaluation state.
Definition: item.h:2479
longlong val_int_from_time()
Definition: item.cc:511
bool null_value
True if item is null.
Definition: item.h:3811
virtual Item * apply_masking_policy(THD *thd)
Apply column masking policy to this item if applicable.
Definition: item.h:3862
Type
Definition: item.h:964
@ SUBQUERY_ITEM
A subquery or predicate referencing a subquery.
Definition: item.h:981
@ ROW_ITEM
A row of other items.
Definition: item.h:982
@ INVALID_ITEM
Definition: item.h:965
@ JSON_ITEM
A JSON literal value.
Definition: item.h:974
@ INSERT_VALUE_ITEM
A value from a VALUES function (deprecated).
Definition: item.h:980
@ CACHE_ITEM
An internal item used to cache values.
Definition: item.h:983
@ REAL_ITEM
A floating-point literal value.
Definition: item.h:973
@ TRIGGER_FIELD_ITEM
An OLD or NEW field, used in trigger definitions.
Definition: item.h:987
@ SUM_FUNC_ITEM
A grouped aggregate function, or window function.
Definition: item.h:968
@ TYPE_HOLDER_ITEM
An internal item used to help aggregate a type.
Definition: item.h:984
@ NAME_CONST_ITEM
A NAME_CONST expression.
Definition: item.h:990
@ REF_ITEM
An indirect reference to another item.
Definition: item.h:979
@ FIELD_ITEM
A reference to a field (column) in a table.
Definition: item.h:966
@ INT_ITEM
An integer literal value.
Definition: item.h:971
@ FUNC_ITEM
A function call reference.
Definition: item.h:967
@ COND_ITEM
An AND or OR condition.
Definition: item.h:978
@ XPATH_NODESET_ITEM
Used in XPATH expressions.
Definition: item.h:988
@ PARAM_ITEM
A dynamic parameter used in a prepared statement.
Definition: item.h:985
@ ROUTINE_FIELD_ITEM
A variable inside a routine (proc, func, trigger)
Definition: item.h:986
@ DECIMAL_ITEM
A decimal literal value.
Definition: item.h:972
@ VALUES_COLUMN_ITEM
A value from a VALUES clause.
Definition: item.h:989
@ HEX_BIN_ITEM
A hexadecimal or binary literal value.
Definition: item.h:976
@ NULL_ITEM
A NULL value.
Definition: item.h:975
@ AGGR_FIELD_ITEM
A special field for certain aggregate operations.
Definition: item.h:969
@ DEFAULT_VALUE_ITEM
A default value for a column.
Definition: item.h:977
@ STRING_ITEM
A string literal value.
Definition: item.h:970
void set_data_type_bit(uint32 max_bits)
Set the data type of the Item to be bit.
Definition: item.h:1787
virtual bool collect_scalar_subqueries(uchar *)
Definition: item.h:3080
virtual Field * tmp_table_field(TABLE *)
Definition: item.h:2412
virtual uint64_t hash()
Generate hash unique to an item depending on its attributes.
Definition: item.h:2554
virtual bool check_cols(uint c)
Definition: item.cc:1462
virtual bool itemize(Parse_context *pc, Item **res) final
The same as contextualize() but with additional parameter.
Definition: item.h:1249
const bool is_parser_item
true if allocated directly by parser
Definition: item.h:3764
bool is_temporal_with_time() const
Definition: item.h:3416
bool get_datetime_from_string(Datetime_val *dt, my_time_flags_t flags)
Convert val_str() to datetime.
Definition: item.cc:1605
virtual bool visitor_processor(uchar *arg)
A processor to handle the select lex visitor framework.
Definition: item.cc:933
Parse_tree_node super
Definition: item.h:930
virtual Item * replace_item_view_ref(uchar *)
Definition: item.h:3365
bool cleanup_processor(uchar *)
cleanup() item if it is resolved ('fixed').
Definition: item.h:2829
void set_data_type_datetime(uint8 fsp)
Set all properties for Item of DATETIME type.
Definition: item.h:1721
virtual void set_masking_expression_for(const Item_field *masked_item)
Mark this expression as a masking expression for some other expression.
Definition: item.h:3877
virtual Item * replace_with_derived_expr_ref(uchar *arg)
Assuming this expression is part of a condition that would be pushed to the HAVING clause of a materi...
Definition: item.h:3245
virtual const CHARSET_INFO * charset_for_protocol()
Definition: item.h:2698
void set_aggregation()
Set the "has aggregation" property.
Definition: item.h:3556
virtual uint time_precision()
TIME precision of the item: 0..6.
Definition: item.cc:852
void delete_self()
Delete this item.
Definition: item.h:3398
bool m_in_check_constraint_exec_ctx
True if item is a top most element in the expression being evaluated for a check constraint.
Definition: item.h:3827
virtual uint datetime_precision()
DATETIME precision of the item: 0..6.
Definition: item.cc:867
virtual bool send(Protocol *protocol, String *str)
This is only called from items that is not of type item_field.
Definition: item.cc:7956
bool has_compatible_context(Item *item) const
Check whether this and the given item has compatible comparison context.
Definition: item.h:3431
virtual Item * replace_view_refs_with_clone(uchar *arg)
Assuming this expression is part of a condition that would be pushed to a materialized derived table,...
Definition: item.h:3255
virtual void pin_data_type()
Pin the data type for the item.
Definition: item.h:1478
virtual bool cache_const_expr_analyzer(uchar **cache_item)
Check if an item is a constant one and can be cached.
Definition: item.cc:8144
bool get_datetime_from_int(Datetime_val *dt, my_time_flags_t flags)
Convert val_int() to datetime.
Definition: item.cc:1647
virtual void apply_is_true()
Apply the IS TRUE truth property, meaning that an UNKNOWN result and a FALSE result are treated the s...
Definition: item.h:2654
Item * next_free
Intrusive list pointer for free list.
Definition: item.h:3670
virtual bool collect_item_field_or_ref_processor(uchar *)
Definition: item.h:2837
virtual bool val_bool()
Definition: item.cc:247
String * error_str()
Get the value to return from val_str() in case of error or NULL value.
Definition: item.h:2289
static enum_field_types type_for_variable(enum_field_types src_type)
Provide data type for a user or system variable, based on the type of the item that is assigned to th...
Definition: item.h:1101
uint8 m_accum_properties
Definition: item.h:3852
type_conversion_status save_str_value_in_field(Field *field, String *result)
Definition: item.cc:598
virtual bool check_column_in_window_functions(uchar *arg)
Check if all the columns present in this expression are present in PARTITION clause of window functio...
Definition: item.h:3216
void set_data_type_vector(uint32 max_l)
Set the data type of the Item to be VECTOR.
Definition: item.h:1745
virtual Item * update_value_transformer(uchar *)
Definition: item.h:3293
virtual Item * replace_outer_ref(uchar *)
Definition: item.h:3367
virtual bool reset_wf_state(uchar *arg)
Reset execution state for such window function types as determined by arg.
Definition: item.h:2951
void set_accum_properties(const Item *item)
Set accumulated properties for an Item.
Definition: item.h:3528
virtual bool repoint_const_outer_ref(uchar *arg)
This function applies only to Item_field objects referred to by an Item_ref object that has been mark...
Definition: item.h:3646
virtual bool cast_incompatible_args(uchar *)
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item.h:2918
bool get_datetime_from_real(Datetime_val *dt, my_time_flags_t flags)
Convert val_real() to datetime.
Definition: item.cc:1627
virtual longlong val_date_temporal()
Return date value of item in packed longlong format.
Definition: item.cc:437
bool visit_all_analyzer(uchar **)
Definition: item.h:3095
virtual table_map not_null_tables() const
Return table map of tables that can't be NULL tables (tables that are used in a context where if they...
Definition: item.h:2431
virtual Item_result numeric_context_result_type() const
Result type when an item appear in a numeric context.
Definition: item.h:1456
my_decimal * val_decimal_from_date(my_decimal *decimal_value)
Definition: item.cc:410
longlong val_temporal_with_round(enum_field_types type, uint8 dec)
Get date or time value in packed longlong format.
Definition: item.cc:449
virtual void compute_cost(CostOfItem *root_cost) const
Compute the cost of evaluating this Item.
Definition: item.h:3655
bool can_be_substituted_for_gc(bool array=false) const
Check if this item is of a type that is eligible for GC substitution.
Definition: item.cc:8224
virtual Item * compile(Item_analyzer analyzer, uchar **arg_p, Item_transformer transformer, uchar *arg_t)
Perform a generic "compilation" of the Item tree, ie transform the Item tree by adding zero or more I...
Definition: item.h:2808
type_conversion_status save_in_field_no_warnings(Field *field, bool no_conversions)
Save the item into a field but do not emit any warnings.
Definition: item.cc:1892
bool error_time()
Get the value to return from val_time() in case of errors.
Definition: item.h:2276
virtual TYPELIB * get_typelib() const
Get the typelib information for an item of type set or enum.
Definition: item.h:1822
bool has_wf() const
Definition: item.h:3562
my_decimal * val_decimal_from_real(my_decimal *decimal_value)
Definition: item.cc:371
virtual bool collect_subqueries(uchar *)
Definition: item.h:3082
void aggregate_bit_properties(Item **items, uint nitems)
Set data type and properties of a BIT column.
Definition: item.cc:8442
void set_group_by_modifier()
Set the property: this item (tree) contains a reference to a GROUP BY modifier (such as ROLLUP)
Definition: item.h:3579
virtual void fix_after_pullout(Query_block *parent_query_block, Query_block *removed_query_block)
Fix after tables have been moved from one query_block level to the parent level, e....
Definition: item.h:1294
void set_data_type_char(uint32 max_l)
Set the Item to be fixed length string.
Definition: item.h:1658
bool get_date_from_real(Date_val *date, my_time_flags_t flags)
Convert val_real() to date.
Definition: item.cc:1621
virtual bool null_inside()
Definition: item.h:3277
bool get_time_from_int(Time_val *time)
Convert val_int() to time.
Definition: item.cc:1796
void set_data_type_json()
Set the data type of the Item to be JSON.
Definition: item.h:1764
bool unsigned_flag
Definition: item.h:3812
virtual bool aggregate_check_group(uchar *)
Definition: item.h:3026
bool propagate_type(THD *thd, enum_field_types def=MYSQL_TYPE_VARCHAR, bool pin=false, bool inherit=false)
Wrapper for easier calling of propagate_type(const Type_properties &).
Definition: item.h:1328
bool is_blob_field() const
Check if an item either is a blob field, or will be represented as a BLOB field if a field is created...
Definition: item.cc:1920
bool is_outer_reference() const
Definition: item.h:2525
bool get_date_from_string(Date_val *date, my_time_flags_t flags)
Convert val_str() to date.
Definition: item.cc:1613
virtual bool is_null()
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:2635
bool const_for_execution() const
Returns true if item is constant during one query execution.
Definition: item.h:2491
void aggregate_temporal_properties(enum_field_types type, Item **items, uint nitems)
Set data type and fractional seconds precision for temporal functions.
Definition: item.cc:8328
longlong val_int_from_string()
Definition: item.cc:541
item_marker
< Values for member 'marker'
Definition: item.h:3701
@ MARKER_FUNC_DEP_NOT_NULL
When analyzing functional dependencies for only_full_group_by (says whether a nullable column can be ...
Definition: item.h:3715
@ MARKER_GROUP_BY_BIT
When creating an internal temporary table: marking group by fields.
Definition: item.h:3712
@ MARKER_TRAVERSAL
Used during traversal to avoid deleting an item twice.
Definition: item.h:3723
@ MARKER_DISTINCT_GROUP
When we change DISTINCT to GROUP BY: used for book-keeping of fields.
Definition: item.h:3718
@ MARKER_IMPLICIT_NE_ZERO
When contextualization or itemization adds an implicit comparison '0<>' (see make_condition()),...
Definition: item.h:3706
@ MARKER_NONE
Definition: item.h:3702
@ MARKER_COND_DERIVED_TABLE
When pushing conditions down to derived table: it says a condition contains only derived table's colu...
Definition: item.h:3721
@ MARKER_CONST_PROPAG
When doing constant propagation (e.g.
Definition: item.h:3709
@ MARKER_ICP_COND_USES_INDEX_ONLY
When pushing index conditions: it says whether a condition uses only indexed columns.
Definition: item.h:3726
virtual bool is_valid_for_pushdown(uchar *arg)
Check if all the columns present in this expression are from the derived table.
Definition: item.h:3205
virtual Item * copy_or_same(THD *)
Definition: item.h:2669
Item_name_string orig_name
Original item name (if it was renamed)
Definition: item.h:3683
virtual bool collect_grouped_aggregates(uchar *)
Definition: item.h:3081
virtual bool clean_up_after_removal(uchar *arg)
Clean up after removing the item from the item tree.
Definition: item.cc:8211
virtual cond_result eq_cmp_result() const
Definition: item.h:2453
bool get_time_from_non_temporal(Time_val *time)
Convert a non-temporal type to time.
Definition: item.cc:1842
uint32 max_char_length(const CHARSET_INFO *cs) const
Definition: item.h:3481
virtual Item * explain_subquery_propagator(uchar *)
Definition: item.h:3156
virtual void update_used_tables()
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item.h:2578
virtual bool aggregate_check_distinct(uchar *)
Definition: item.h:3024
bool evaluate(THD *thd, String *str)
Evaluate scalar item, possibly using the supplied buffer.
Definition: item.cc:8064
void set_wf()
Set the "has window function" property.
Definition: item.h:3565
virtual bool returns_array() const
Whether the item returns array of its data type.
Definition: item.h:3904
virtual void make_field(Send_field *field)
Definition: item.cc:6865
virtual Field * get_tmp_table_field()
If this Item is being materialized into a temporary table, returns the field that is being materializ...
Definition: item.h:2407
virtual bool is_outer_field() const
Definition: item.h:3496
void set_grouping_func()
Set the property: this item is a call to GROUPING.
Definition: item.h:3591
virtual void set_result_field(Field *)
Definition: item.h:2660
bool is_abandoned() const
Definition: item.h:3657
cond_result
Definition: item.h:993
@ COND_UNDEF
Definition: item.h:993
@ COND_TRUE
Definition: item.h:993
@ COND_FALSE
Definition: item.h:993
@ COND_OK
Definition: item.h:993
virtual bool walk(Item_processor processor, enum_walk walk, uchar *arg)
Traverses a tree of Items in prefix and/or postfix order.
Definition: item.h:2724
type_conversion_status save_time_in_field(Field *field)
Definition: item.cc:551
item_marker marker
This member has several successive meanings, depending on the phase we're in (.
Definition: item.h:3743
Item_result temporal_with_date_as_number_result_type() const
Similar to result_type() but makes DATE, DATETIME, TIMESTAMP pretend to be numbers rather than string...
Definition: item.h:1463
traverse_order
Definition: item.h:995
@ POSTFIX
Definition: item.h:995
@ PREFIX
Definition: item.h:995
virtual bool is_strong_side_column_not_in_fd(uchar *)
Definition: item.h:3028
virtual bool intro_version(uchar *)
Definition: item.h:2826
bool m_abandoned
true if item has been fully de-referenced
Definition: item.h:3763
virtual bool inform_item_in_cond_of_tab(uchar *)
Definition: item.h:2978
bool get_datetime_from_date(Datetime_val *dt, my_time_flags_t flags)
Convert val_date() to datetime.
Definition: item.cc:1691
static constexpr uint8 PROP_STORED_PROGRAM
Definition: item.h:3838
virtual const Item * real_item() const
Definition: item.h:2677
bool is_temporal() const
Definition: item.h:3419
bool is_temporal_with_date_and_time() const
Definition: item.h:3413
virtual const char * full_name() const
Definition: item.h:2413
auto walk_helper_thunk(uchar *arg)
Definition: item.h:2732
void set_data_type_null()
Definition: item.h:1517
uint8 decimals
Number of decimals in result when evaluating this item.
Definition: item.h:3783
virtual bool val_datetime(Datetime_val *dt, my_time_flags_t flags)=0
Evaluate the item and return result as a datetime value.
virtual Item ** addr(uint)
Definition: item.h:3274
virtual Item * clone_item() const
Definition: item.h:2452
void set_data_type_string(uint32 max_l)
Set the Item to be variable length string.
Definition: item.h:1600
virtual void set_can_use_prefix_key()
Definition: item.h:1303
void set_data_type_timestamp(uint8 fsp)
Set all properties for Item of TIMESTAMP type.
Definition: item.h:1734
bool do_contextualize(Parse_context *) override
Definition: item.h:1189
void set_data_type_string(uint32 max_l, const DTCollation &coll)
Set the Item to be variable length string.
Definition: item.h:1647
virtual std::optional< ContainedSubquery > get_contained_subquery(const Query_block *outer_query_block)
If this item represents a IN/ALL/ANY/comparison_operator subquery, return that (along with data on ho...
Definition: item.h:1366
uint decrement_ref_count()
Decrement reference count.
Definition: item.h:3520
Item * convert_charset(THD *thd, const CHARSET_INFO *tocs, bool ignore_errors=false)
Convert constant string in this object into the specified character set.
Definition: item.cc:1560
virtual bool find_item_processor(uchar *arg)
Definition: item.h:2911
virtual void no_rows_in_result()
Definition: item.h:2668
virtual bool add_field_to_set_processor(uchar *)
Item::walk function.
Definition: item.h:2888
virtual bool add_field_to_cond_set_processor(uchar *)
Item::walk function.
Definition: item.h:2897
virtual Item * replace_with_derived_expr(uchar *arg)
Assuming this expression is part of a condition that would be pushed to the WHERE clause of a materia...
Definition: item.h:3234
uint reference_count() const
Definition: item.h:3511
bool get_time_from_real(Time_val *time)
Convert val_real() to time.
Definition: item.cc:1783
static enum_field_types result_to_type(Item_result result)
Definition: item.h:1022
virtual Item * replace_scalar_subquery(uchar *)
When walking the item tree seeing an Item_singlerow_subselect matching a target, replace it with a su...
Definition: item.h:3355
type_conversion_status save_in_field(Field *field, bool no_conversions)
Save a temporal value in packed longlong format into a Field.
Definition: item.cc:7232
virtual bool check_gcol_depend_default_processor(uchar *args)
Check if a generated expression depends on DEFAULT function with specific column name as argument.
Definition: item.h:3196
virtual bool is_splocal() const
Definition: item.h:3401
virtual bool val_time(Time_val *time)=0
Evaluate the item and return result as a time value.
Bool_test
< Modifier for result transformation
Definition: item.h:1008
@ BOOL_NOT_FALSE
Definition: item.h:1013
@ BOOL_IS_UNKNOWN
Definition: item.h:1011
@ BOOL_NOT_TRUE
Definition: item.h:1012
@ BOOL_IS_TRUE
Definition: item.h:1009
@ BOOL_ALWAYS_FALSE
Definition: item.h:1018
@ BOOL_NOT_UNKNOWN
Definition: item.h:1014
@ BOOL_ALWAYS_TRUE
Definition: item.h:1017
@ BOOL_IS_FALSE
Definition: item.h:1010
@ BOOL_IDENTITY
Definition: item.h:1015
@ BOOL_NEGATED
Definition: item.h:1016
String * check_well_formed_result(String *str, bool send_error, bool truncate)
Verifies that the input string is well-formed according to its character set.
Definition: item.cc:6888
virtual bool replace_field_processor(uchar *)
A processor that replaces any Fields with a Create_field_wrapper.
Definition: item.h:3616
virtual bool update_aggr_refs(uchar *)
A walker processor overridden by Item_aggregate_ref, q.v.
Definition: item.h:3379
virtual void disable_masking_policy()
Disable application of the masking policy to this item.
Definition: item.h:3871
bool get_date_from_time(Date_val *date)
Convert val_time() to date.
Definition: item.cc:1659
virtual void notify_removal()
Called when an item has been removed, can be used to notify external objects about the removal,...
Definition: item.h:1281
bool may_evaluate_const(const THD *thd) const
Return true if this is a const item that may be evaluated in the current phase of statement processin...
Definition: item.cc:1454
bool aggregate_type(const char *name, Item **items, uint count)
Aggregates data types from array of items into current item.
Definition: item.cc:639
virtual Item * replace_aggregate(uchar *)
Definition: item.h:3366
virtual String * val_str(String *str)=0
bool m_nullable
True if this item may hold the NULL value(if null_value may be set to true).
Definition: item.h:3808
virtual Item * replace_item_field(uchar *)
Transform processor used by Query_block::transform_grouped_to_derived to replace fields which used to...
Definition: item.h:3363
virtual bool mark_field_in_map(uchar *arg)
Mark underlying field in read or write map of a table.
Definition: item.h:2924
virtual bool basic_const_item() const
Returns true if this is a simple constant item like an integer, not a constant expression.
Definition: item.h:2440
bool hidden
If the item is in a SELECT list (Query_block::fields) and hidden is true, the item wasn't actually in...
Definition: item.h:3822
virtual bool get_timeval(my_timeval *tm, int *warnings)
Get timestamp in "struct timeval" format.
Definition: item.cc:1865
bool m_is_window_function
True if item represents window func.
Definition: item.h:3813
bool may_eval_const_item(const THD *thd) const
Definition: item.cc:238
void set_data_type_from_item(const Item *item)
Set data type properties of the item from the properties of another item.
Definition: item.h:1799
bool get_datetime_from_decimal(Datetime_val *dt, my_time_flags_t flags)
Convert val_decimal() to datetime.
Definition: item.cc:1640
static bool mark_field_in_map(Mark_field *mark_field, Field *field)
Helper function for mark_field_in_map(uchar *arg).
Definition: item.h:2933
bool get_date_from_datetime(Date_val *date, my_time_flags_t flags)
Convert val_datetime() to date.
Definition: item.cc:1669
Item * cache_const_expr_transformer(uchar *item)
Cache item if needed.
Definition: item.cc:8459
String * val_string_from_time(String *str)
Definition: item.cc:360
virtual Item ** this_item_addr(THD *, Item **addr_arg)
Definition: item.h:3269
virtual bool is_result_field() const
Definition: item.h:2661
virtual const Item * this_item() const
Definition: item.h:3263
void aggregate_decimal_properties(Item **items, uint nitems)
Set data type, precision and scale of item of type decimal from list of items.
Definition: item.cc:8308
virtual Item * transform(Item_transformer transformer, uchar *arg)
Perform a generic transformation of the Item tree, by adding zero or more additional Item objects to ...
Definition: item.cc:953
virtual enum_monotonicity_info get_monotonicity_info() const
Definition: item.h:1834
virtual bool collect_item_field_processor(uchar *)
Definition: item.h:2836
virtual bool has_aggregate_ref_in_group_by(uchar *)
Check if an aggregate is referenced from within the GROUP BY clause of the query block in which it is...
Definition: item.h:3093
uint32 max_length
Maximum length of result of evaluating this item, in number of bytes.
Definition: item.h:3699
bool get_date_from_numeric(Date_val *date, my_time_flags_t flags)
Convert a numeric type to date.
Definition: item.cc:1701
bool get_date_from_decimal(Date_val *date, my_time_flags_t flags)
Convert val_decimal() to date.
Definition: item.cc:1633
void set_data_type_longlong()
Set the data type of the Item to be longlong.
Definition: item.h:1555
static constexpr uint8 PROP_WINDOW_FUNCTION
Definition: item.h:3840
auto analyze_helper_thunk(uchar **arg)
See CompileItem.
Definition: item.h:2738
double val_real_from_string()
Definition: item.cc:491
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:8045
virtual bool gc_subst_analyzer(uchar **)
Analyzer function for GC substitution.
Definition: item.h:3604
void rename(char *new_name)
rename item (used for views, cleanup() return original name).
Definition: item.cc:944
bool aggregate_string_properties(enum_field_types type, const char *name, Item **items, uint nitems)
Aggregate string properties (character set, collation and maximum length) for string function.
Definition: item.cc:8384
virtual bool is_column_not_in_fd(uchar *)
Definition: item.h:3030
virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp)
Definition: item.h:1872
virtual enum Type type() const =0
virtual uint cols() const
Definition: item.h:3272
virtual Item * gc_subst_transformer(uchar *)
Transformer function for GC substitution.
Definition: item.h:3608
virtual Bool3 local_column(const Query_block *) const
Definition: item.h:3031
virtual void bring_value()
Definition: item.h:3279
void set_data_type_time(uint8 fsp)
Set all type properties for Item of TIME type.
Definition: item.h:1708
void set_data_type_decimal(uint8 precision, uint8 scale)
Set the data type of the Item to be decimal.
Definition: item.h:1569
CostOfItem m_cost
The cost of evaluating this item.
Definition: item.h:3771
void quick_fix_field()
Definition: item.h:1302
virtual bool used_tables_for_level(uchar *arg)
Return used table information for the specified query block (level).
Definition: item.h:2967
my_decimal * val_decimal_from_time(my_decimal *decimal_value)
Definition: item.cc:421
virtual Item_result cast_to_int_type() const
Definition: item.h:1824
type_conversion_status save_date_in_field(Field *field)
Definition: item.cc:560
bool split_sum_func2(THD *thd, Ref_item_array ref_item_array, mem_root_deque< Item * > *fields, Item **ref, bool skip_registered)
Definition: item.cc:2472
bool get_time_from_string(Time_val *time)
Convert val_str() to time.
Definition: item.cc:1775
String * val_string_from_real(String *str)
Definition: item.cc:292
virtual bool is_non_const_over_literals(uchar *)
Definition: item.h:2912
virtual void mark_json_as_scalar()
For Items with data type JSON, mark that a string argument is treated as a scalar JSON value.
Definition: item.h:1355
void set_data_type_char(uint32 max_l, const CHARSET_INFO *cs)
Set the Item to be fixed length string.
Definition: item.h:1672
bool has_grouping_func() const
Definition: item.h:3586
virtual void save_org_in_field(Field *field)
Definition: item.h:1431
static constexpr uint8 PROP_AGGREGATION
Definition: item.h:3839
virtual Field * get_result_field() const
Definition: item.h:2662
longlong int_sort_key()
Produces a key suitable for filesort.
Definition: item.h:1914
int decimal_int_part() const
Definition: item.h:2459
virtual void set_data_type_inherited()
Set data type for item as inherited.
Definition: item.h:1472
String * val_string_from_decimal(String *str)
Definition: item.cc:322
virtual bool check_partition_func_processor(uchar *)
Check if a partition function is allowed.
Definition: item.h:3150
static constexpr uint8 PROP_HAS_GROUPING_SET_DEP
Set if the item or one or more of the underlying items contains a GROUP BY modifier (such as ROLLUP).
Definition: item.h:3845
virtual void bind_fields()
Bind objects from the current execution context to field objects in item trees.
Definition: item.h:2984
bool get_date_from_non_temporal(Date_val *date, my_time_flags_t flags)
Convert a non-temporal type to date.
Definition: item.cc:1757
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1268
Definition: sql_list.h:494
Class used as argument to Item::walk() together with mark_field_in_map()
Definition: item.h:261
Mark_field(TABLE *table, enum_mark_columns mark)
Definition: item.h:263
Mark_field(enum_mark_columns mark)
Definition: item.h:264
TABLE *const table
If == NULL, update map of any table.
Definition: item.h:270
const enum_mark_columns mark
How to mark the map.
Definition: item.h:272
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Definition: item.h:518
Table_ref * save_next_local
Definition: item.h:524
void save_state(Name_resolution_context *context, Table_ref *table_list)
Definition: item.h:528
Table_ref * save_next_name_resolution_table
Definition: item.h:522
void update_next_local(Table_ref *table_list)
Definition: item.h:545
Table_ref * get_first_name_resolution_table()
Definition: item.h:549
Table_ref * save_table_list
Definition: item.h:520
bool save_resolve_in_select_list
Definition: item.h:523
Table_ref * save_first_name_resolution_table
Definition: item.h:521
void restore_state(Name_resolution_context *context, Table_ref *table_list)
Definition: item.h:537
Storage for name strings.
Definition: item.h:297
void copy(const char *str)
Definition: item.h:334
Name_string(const char *str, size_t length)
Definition: item.h:313
void copy(const LEX_STRING lex)
Definition: item.h:337
void set_or_copy(const char *str, size_t length, bool is_null_terminated)
Definition: item.h:299
bool eq_safe(const Name_string name) const
Definition: item.h:352
Name_string(const LEX_STRING str, bool is_null_terminated)
Definition: item.h:320
bool eq_safe(const char *str) const
Definition: item.h:347
Name_string(const LEX_STRING str)
Definition: item.h:314
Name_string()
Definition: item.h:307
bool eq(const char *str) const
Compare name to another name in C string, case insensitively.
Definition: item.h:343
void copy(const char *str, size_t length)
Variants for copy(), for various argument combinations.
Definition: item.h:331
Name_string(const LEX_CSTRING str)
Definition: item.h:315
Name_string(const char *str, size_t length, bool is_null_terminated)
Definition: item.h:316
void copy(const char *str, size_t length, const CHARSET_INFO *cs)
Allocate space using sql_strmake() or sql_strmake_with_convert().
Definition: item.cc:1472
bool eq(const Name_string name) const
Compare name to another name in Name_string, case insensitively.
Definition: item.h:351
void copy(const Name_string str)
Definition: item.h:339
void copy(const LEX_STRING *lex)
Definition: item.h:338
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:231
bool end_parse_tree(Show_parse_tree *tree)
Definition: parse_tree_node_base.h:400
bool begin_parse_tree(Show_parse_tree *tree)
Definition: parse_tree_node_base.h:385
Definition: protocol.h:33
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1198
Simple intrusive linked list.
Definition: sql_list.h:48
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:54
Definition: field.h:4555
bool field
Definition: field.h:4568
Definition: item.h:663
virtual void set_out_param_info(Send_field *info)
Definition: item.h:695
virtual ~Settable_routine_parameter()=default
Settable_routine_parameter()=default
virtual void set_required_privilege(Access_bitmask privilege)
Set required privileges for accessing the parameter.
Definition: item.h:676
virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)=0
virtual const Send_field * get_out_param_info() const
Definition: item.h:697
Holds the json parse tree being generated by the SHOW PARSE_TREE command.
Definition: parse_tree_node_base.h:140
A wrapper class for null-terminated constant strings.
Definition: sql_string.h:74
const char * ptr() const
Return string buffer.
Definition: sql_string.h:105
bool is_set() const
Check if m_ptr is set.
Definition: sql_string.h:109
size_t length() const
Return name length.
Definition: sql_string.h:113
void set(const char *str_arg, size_t length_arg)
Initialize from a C string whose length is already known.
Definition: sql_string.h:83
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
bool append(const String &s)
Definition: sql_string.cc:419
const CHARSET_INFO * charset() const
Definition: sql_string.h:242
void set_charset(const CHARSET_INFO *charset_arg)
Definition: sql_string.h:241
const char * ptr() const
Definition: sql_string.h:251
bool set_or_copy_aligned(const char *s, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.cc:332
void mark_as_const()
Definition: sql_string.h:249
size_t length() const
Definition: sql_string.h:243
size_t numchars() const
Definition: sql_string.cc:538
bool copy()
Definition: sql_string.cc:198
void set(String &str, size_t offset, size_t arg_length)
Definition: sql_string.h:304
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2958
Table_ref * outer_join_nest() const
Returns the outer join nest that this Table_ref belongs to, if any.
Definition: table.h:3564
table_map map() const
Return table map derived from table number.
Definition: table.h:4153
bool is_view() const
Return true if this represents a named view.
Definition: table.h:3220
bool is_inner_table_of_outer_join() const
Return true if this table is an inner table of some outer join.
Definition: table.h:3579
bool outer_join
True if right argument of LEFT JOIN; false in other cases (i.e.
Definition: table.h:3974
Table_ref * next_local
Definition: table.h:3664
Table_ref * any_outer_leaf_table()
Return any leaf table that is not an inner table of an outer join.
Definition: table.h:3405
TABLE * table
Definition: table.h:3747
Table_ref * next_name_resolution_table
Definition: table.h:3744
This is an interface to be used from Item_trigger_field to access information about table trigger fie...
Definition: table_trigger_field_support.h:44
virtual TABLE * get_subject_table()=0
Time_val is a temporal type that represents only time.
Definition: my_temporal.h:57
int64_t for_comparison() const
Definition: my_temporal.h:118
Type properties, used to collect type information for later assignment to an Item object.
Definition: item.h:626
const uint32 m_max_length
Definition: item.h:657
const bool m_unsigned_flag
Definition: item.h:656
const DTCollation m_collation
Definition: item.h:658
Type_properties(enum_field_types type_arg)
Constructor for any signed numeric type or date type Defaults are provided for attributes like signed...
Definition: item.h:630
Type_properties(enum_field_types type_arg, const CHARSET_INFO *charset)
Constructor for character type, with explicit character set.
Definition: item.h:648
Type_properties(enum_field_types type_arg, bool unsigned_arg)
Constructor for any numeric type, with explicit signedness.
Definition: item.h:638
const enum_field_types m_type
Definition: item.h:655
Class used as argument to Item::walk() together with used_tables_for_level()
Definition: item.h:278
Used_tables(Query_block *select)
Definition: item.h:280
table_map used_tables
Accumulated used tables data.
Definition: item.h:283
Query_block *const select
Level for which data is accumulated.
Definition: item.h:282
Definition: item_cmpfunc.h:1924
Definition: mem_root_deque.h:366
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:172
iterator begin()
Definition: mem_root_deque.h:517
iterator end()
Definition: mem_root_deque.h:518
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:97
uint precision() const
Definition: my_decimal.h:135
bool sign() const
Definition: my_decimal.h:133
sp_head represents one instance of a stored program.
Definition: sp_head.h:389
Definition: sp_rcontext.h:77
Definition: sql_udf.h:83
Definition: item_func.h:3167
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
#define L
Definition: ctype-tis620.cc:74
#define U
Definition: ctype-tis620.cc:73
#define E_DEC_OVERFLOW
Definition: decimal.h:149
static constexpr int DECIMAL_NOT_SPECIFIED
Definition: dtoa.h:54
enum_query_type
Query type constants (usable as bitmap flags).
Definition: enum_query_type.h:31
@ QT_NORMALIZED_FORMAT
Change all Item_basic_constant to ? (used by query rewrite to compute digest.) Un-resolved hints will...
Definition: enum_query_type.h:69
bool is_temporal_type_with_time(enum_field_types type)
Tests if field type is temporal and has time part, i.e.
Definition: field_common_properties.h:161
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:139
bool is_string_type(enum_field_types type)
Tests if field type is a string type.
Definition: field_common_properties.h:89
bool is_numeric_type(enum_field_types type)
Tests if field type is a numeric type.
Definition: field_common_properties.h:65
bool is_temporal_type_with_date(enum_field_types type)
Tests if field type is temporal and has date part, i.e.
Definition: field_common_properties.h:180
bool is_temporal_type_with_date_and_time(enum_field_types type)
Tests if field type is temporal and has date and time parts, i.e.
Definition: field_common_properties.h:201
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:56
@ MYSQL_TYPE_BOOL
Currently just a placeholder.
Definition: field_types.h:80
@ MYSQL_TYPE_TIME2
Internal to MySQL.
Definition: field_types.h:76
@ MYSQL_TYPE_VARCHAR
Definition: field_types.h:72
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:65
@ MYSQL_TYPE_LONG_BLOB
Definition: field_types.h:87
@ MYSQL_TYPE_VAR_STRING
Definition: field_types.h:89
@ MYSQL_TYPE_BLOB
Definition: field_types.h:88
@ MYSQL_TYPE_TINY
Definition: field_types.h:58
@ MYSQL_TYPE_TIME
Definition: field_types.h:68
@ MYSQL_TYPE_SET
Definition: field_types.h:84
@ MYSQL_TYPE_NEWDATE
Internal to MySQL.
Definition: field_types.h:71
@ MYSQL_TYPE_VECTOR
Definition: field_types.h:78
@ MYSQL_TYPE_JSON
Definition: field_types.h:81
@ MYSQL_TYPE_STRING
Definition: field_types.h:90
@ MYSQL_TYPE_NULL
Definition: field_types.h:63
@ MYSQL_TYPE_ENUM
Definition: field_types.h:83
@ MYSQL_TYPE_TINY_BLOB
Definition: field_types.h:85
@ MYSQL_TYPE_LONG
Definition: field_types.h:60
@ MYSQL_TYPE_BIT
Definition: field_types.h:73
@ MYSQL_TYPE_INVALID
Definition: field_types.h:79
@ MYSQL_TYPE_GEOMETRY
Definition: field_types.h:91
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:82
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:57
@ MYSQL_TYPE_TYPED_ARRAY
Used for replication only.
Definition: field_types.h:77
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:62
@ MYSQL_TYPE_MEDIUM_BLOB
Definition: field_types.h:86
@ MYSQL_TYPE_DATETIME2
Internal to MySQL.
Definition: field_types.h:75
@ MYSQL_TYPE_SHORT
Definition: field_types.h:59
@ MYSQL_TYPE_DATE
Definition: field_types.h:67
@ MYSQL_TYPE_FLOAT
Definition: field_types.h:61
@ MYSQL_TYPE_TIMESTAMP
Definition: field_types.h:64
@ MYSQL_TYPE_INT24
Definition: field_types.h:66
@ MYSQL_TYPE_DATETIME
Definition: field_types.h:69
@ MYSQL_TYPE_TIMESTAMP2
Definition: field_types.h:74
@ MYSQL_TYPE_YEAR
Definition: field_types.h:70
static const std::string dec("DECRYPTION")
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:217
static int flags[50]
Definition: hp_test1.cc:40
enum_mysql_timestamp_type
Definition: mysql_time.h:45
#define MY_COLL_ALLOW_SUPERSET_CONV
Definition: item.h:176
const Name_string null_name_string
monotonicity_info
Definition: item.h:580
@ NON_MONOTONIC
Definition: item.h:581
@ MONOTONIC_STRICT_INCREASING
Definition: item.h:584
@ MONOTONIC_INCREASING_NOT_NULL
Definition: item.h:583
@ MONOTONIC_INCREASING
Definition: item.h:582
@ MONOTONIC_STRICT_INCREASING_NOT_NULL
Definition: item.h:585
Item * GetNthVisibleField(const mem_root_deque< Item * > &fields, size_t index)
Definition: item.h:7575
constexpr float COND_FILTER_STALE_NO_CONST
A special subcase of the above:
Definition: item.h:143
constexpr uint16 NO_FIELD_INDEX((uint16)(-1))
std::string ItemToString(const Item *item, enum_query_type q_type)
Definition: item.cc:11840
bool agg_item_charsets(DTCollation &c, const char *name, Item **items, uint nitems, uint flags)
Definition: item.cc:3033
longlong longlong_from_string_with_check(const CHARSET_INFO *cs, const char *cptr, const char *end, int unsigned_target)
Converts a string to a longlong integer, with warnings.
Definition: item.cc:3943
Bounds_checked_array< Item * > Ref_item_array
Definition: item.h:99
Item * TransformItem(Item *item, T &&transformer)
Same as WalkItem, but for Item::transform().
Definition: item.h:3972
#define MY_COLL_ALLOW_NONE
Definition: item.h:178
#define ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT
Max length of an Item string for its use in an error message.
Definition: item.h:364
Item_result numeric_context_result_type(enum_field_types data_type, Item_result result_type, uint8 decimals)
Definition: item.h:151
bool WalkItem(Item *item, enum_walk walk, T &&functor)
A helper class to give in a functor to Item::walk().
Definition: item.h:3937
Cached_item * new_Cached_item(THD *thd, Item *item)
Create right type of Cached_item for an item.
Definition: item_buff.cc:55
bool agg_item_charsets_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems)
Definition: item.h:4244
Item * CompileItem(Item *item, T &&analyzer, U &&transformer)
Same as WalkItem, but for Item::compile().
Definition: item.h:3959
bool ItemsAreEqual(const Item *a, const Item *b)
Returns true iff the two items are equal, as in a->eq(b), after unwrapping refs and Item_cache object...
Definition: item.cc:11942
bool agg_item_charsets_for_string_result(DTCollation &c, const char *name, Item **items, uint nitems)
Definition: item.h:4237
size_t CountHiddenFields(const mem_root_deque< Item * > &fields)
Definition: item.h:7570
constexpr float COND_FILTER_EQUALITY
Filtering effect for equalities: col1 = col2.
Definition: item.h:116
static uint32 char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg)
Definition: item.h:145
void convert_and_print(const String *from_str, String *to_str, const CHARSET_INFO *to_cs)
Helper method: Convert string to the given charset, then print.
Definition: item.cc:11675
bool(Item::* Item_analyzer)(uchar **argp)
Definition: item.h:711
Item_field * FindEqualField(Item_field *item_field, table_map reachable_tables, bool replace, bool *found)
Definition: item.cc:11893
enum monotonicity_info enum_monotonicity_info
void item_init(void)
Init all special items.
Definition: item.cc:158
size_t CountVisibleFields(const mem_root_deque< Item * > &fields)
Definition: item.h:7565
constexpr float COND_FILTER_STALE
Value is out-of-date, will need recalculation.
Definition: item.h:127
bool convert_const_strings(DTCollation &coll, Item **args, uint nargs)
Convert constant strings according to a specific character set/collation.
Definition: item.cc:2947
bool agg_item_collations_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems)
Aggregate collations for items used in a comparison operations.
Definition: item.cc:2927
Item_result item_cmp_type(Item_result a, Item_result b)
Definition: item.cc:10050
void(* Cond_traverser)(const Item *item, void *arg)
Definition: item.h:721
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:720
std::string ItemToQuerySubstrNoCharLimit(const Item *item)
#define NAME_STRING(x)
Definition: item.h:357
bool is_null_on_empty_table(THD *thd, Item_field *i)
Check if the column reference that is currently being resolved, will be set to NULL if its qualifying...
Definition: item.cc:6140
constexpr float COND_FILTER_BETWEEN
Filtering effect for between: col1 BETWEEN a AND b.
Definition: item.h:120
constexpr float COND_FILTER_ALLPASS
Default condition filtering (selectivity) values used by get_filtering_effect() and friends when bett...
Definition: item.h:114
const String my_null_string
void SafeIncrement(T *num)
Increment *num if it is less than its maximal value.
Definition: item.h:780
bool AllItemsAreEqual(const Item *const *a, const Item *const *b, int num_items)
Returns true iff all items in the two arrays (which must be of the same size) are equal,...
Definition: item.cc:11946
double double_from_string_with_check(const CHARSET_INFO *cs, const char *cptr, const char *end)
Definition: item.cc:3911
#define MY_COLL_ALLOW_NUMERIC_CONV
Definition: item.h:179
constexpr float COND_FILTER_INEQUALITY
Filtering effect for inequalities: col1 > col2.
Definition: item.h:118
int stored_field_cmp_to_item(THD *thd, Field *field, Item *item)
Compare the value stored in field with the expression from the query.
Definition: item.cc:10211
#define MY_COLL_ALLOW_COERCIBLE_CONV
Definition: item.h:177
bool resolve_const_item(THD *thd, Item **ref, Item *cmp_item)
Substitute a const item with a simpler const item, if possible.
Definition: item.cc:10075
std::string ItemToQuerySubstr(const Item *item, const LEX *lex=nullptr, uint32 char_limit=ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT)
Definition: item.cc:11882
#define T
Definition: jit_executor_value.cc:373
constexpr int default_error_code
Definition: logger_stream.h:42
A better implementation of the UNIX ctype(3) library.
static constexpr uint32_t MY_CS_PUREASCII
Definition: m_ctype.h:140
int my_strcasecmp(const CHARSET_INFO *cs, const char *s1, const char *s2)
Definition: m_ctype.h:651
static constexpr uint32_t MY_REPERTOIRE_UNICODE30
Definition: m_ctype.h:156
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:499
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb4_bin
Definition: ctype-utf8.cc:7813
MYSQL_STRINGS_EXPORT unsigned my_string_repertoire(const CHARSET_INFO *cs, const char *str, size_t len)
Definition: ctype.cc:799
static constexpr uint32_t MY_REPERTOIRE_ASCII
Definition: m_ctype.h:152
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb3_general_ci
Definition: ctype-utf8.cc:5785
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1580
Various macros useful for communicating with memory debuggers, such as Valgrind.
void TRASH(void *ptr, size_t length)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:71
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:480
static void bitmap_set_bit(MY_BITMAP *map, uint bit)
Definition: my_bitmap.h:80
Header for compiler-dependent features.
#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
Definition: my_compiler.h:247
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:277
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:278
#define DBUG_FILE
Definition: my_dbug.h:194
#define DBUG_TRACE
Definition: my_dbug.h:146
It is interface module to fixed precision decimals library.
int my_decimal_int_part(uint precision, uint decimals)
Definition: my_decimal.h:85
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:338
static constexpr int DECIMAL_MAX_PRECISION
maximum guaranteed precision of number in decimal digits (number of our digits * number of decimal di...
Definition: my_decimal.h:71
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:193
Utility functions for converting between ulonglong and double.
static constexpr double LLONG_MAX_DOUBLE
Definition: my_double2ulonglong.h:57
#define ulonglong2double(A)
Definition: my_double2ulonglong.h:46
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
uint8_t uint8
Definition: my_inttypes.h:63
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
int8_t int8
Definition: my_inttypes.h:62
#define MY_INT32_NUM_DECIMAL_DIGITS
Definition: my_inttypes.h:100
#define MYF(v)
Definition: my_inttypes.h:97
int32_t int32
Definition: my_inttypes.h:66
uint16_t uint16
Definition: my_inttypes.h:65
#define MY_INT64_NUM_DECIMAL_DIGITS
Definition: my_inttypes.h:103
uint32_t uint32
Definition: my_inttypes.h:67
#define UINT_MAX32
Definition: my_inttypes.h:79
MYSQL_STRINGS_EXPORT long long my_strtoll10(const char *nptr, const char **endptr, int *error)
Definition: my_strtoll10.cc:87
Common header for many mysys elements.
uint64_t table_map
Definition: my_table_map.h:30
Server classes for temporal handling (DATE, TIME, DATETIME)
Interface for low level time utilities.
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:146
unsigned int my_time_flags_t
Flags to str_to_datetime and int_to_datetime.
Definition: my_time.h:87
static int count
Definition: myisam_ftdump.cc:45
Common definition between mysql server & client.
#define MAX_BLOB_WIDTH
Default width for blob in bytes.
Definition: mysql_com.h:907
#define MAX_CHAR_WIDTH
Max width for a CHAR column, in number of characters.
Definition: mysql_com.h:905
static bool ignore_errors
Definition: mysqlcheck.cc:62
static bool replace
Definition: mysqlimport.cc:70
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
const std::string charset("charset")
Definition: applier_version.h:27
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
std::string_view type_name()
Return the name of the given type (not demangled).
Definition: object_lifetime_tracker.h:57
size_t size(const char *const c)
Definition: base64.h:46
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
std::string truncate(const std::string &str, const size_t max_length)
Truncates the given string to max_length code points.
Definition: utils_string.cc:600
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2742
#define NullS
Definition of the null string (a null pointer of type char *), used in some of our string handling co...
Definition: nulls.h:33
type_conversion_status
Status when storing a value in a field or converting from one datatype to another.
Definition: field.h:200
#define MY_REPERTOIRE_NUMERIC
Definition: field.h:256
enum_field_types real_type_to_type(enum_field_types real_type)
Convert temporal real types as returned by field->real_type() to field type as returned by field->typ...
Definition: field.h:391
Value_generator_source
Enum to indicate source for which value generator is used.
Definition: field.h:471
@ VGS_DEFAULT_EXPRESSION
Definition: field.h:473
@ VGS_GENERATED_COLUMN
Definition: field.h:472
#define my_charset_numeric
Definition: field.h:255
Derivation
For use.
Definition: field.h:176
@ DERIVATION_COERCIBLE
Definition: field.h:180
@ DERIVATION_SYSCONST
Definition: field.h:181
@ DERIVATION_EXPLICIT
Definition: field.h:184
@ DERIVATION_NONE
Definition: field.h:177
@ DERIVATION_NUMERIC
Definition: field.h:179
@ DERIVATION_NULL
Definition: field.h:178
@ DERIVATION_IMPLICIT
Definition: field.h:182
File containing constants that can be used throughout the server.
constexpr const table_map RAND_TABLE_BIT
Definition: sql_const.h:113
constexpr const int MAX_TIME_WIDTH
-838:59:59
Definition: sql_const.h:70
constexpr const int MAX_DATE_WIDTH
YYYY-MM-DD.
Definition: sql_const.h:68
constexpr const size_t STRING_BUFFER_USUAL_SIZE
Definition: sql_const.h:126
constexpr const table_map OUTER_REF_TABLE_BIT
Definition: sql_const.h:112
constexpr const int MAX_DOUBLE_STR_LENGTH
-[digits].E+###
Definition: sql_const.h:158
enum_walk
Enumeration for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:289
bool(Item::*)(unsigned char *) Item_processor
Processor type for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:307
constexpr const table_map INNER_TABLE_BIT
Definition: sql_const.h:111
constexpr const int MAX_DATETIME_WIDTH
YYYY-MM-DD HH:MM:SS.
Definition: sql_const.h:76
enum_mark_columns
Definition: sql_const.h:232
int stringcmp(const String *s, const String *t)
Definition: sql_string.cc:712
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:29
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:243
Definition: m_ctype.h:421
unsigned mbmaxlen
Definition: m_ctype.h:445
Definition: item_cmpfunc.h:2869
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:487
int err_code
the error code found during check(if any)
Definition: item.h:494
int col_index
the order of the column in table
Definition: item.h:492
const char * banned_function_name
the name of the function which is not allowed
Definition: item.h:501
Value_generator_source source
Definition: item.h:499
int get_unnamed_function_error_code() const
Return the correct error code, based on whether or not if we are checking for disallowed functions in...
Definition: item.h:506
Check_function_as_value_generator_parameters(int default_error_code, Value_generator_source val_gen_src)
Definition: item.h:488
This class represents a subquery contained in some subclass of Item_subselect,.
Definition: item.h:861
Strategy strategy
The strategy for executing the subquery.
Definition: item.h:895
Strategy
The strategy for executing the subquery.
Definition: item.h:863
@ kMaterializable
An independent subquery that is materialized, e.g.
@ kIndependentSingleRow
An independent single-row subquery that is evaluated once, e.g.
@ kNonMaterializable
A subquery that is reevaluated for each row, e.g.
AccessPath * path
The root path of the subquery.
Definition: item.h:892
int row_width
The width (in bytes) of the subquery's rows.
Definition: item.h:901
The current state of the privilege checking process for the current user, SQL statement and SQL objec...
Definition: table.h:384
Definition: item.h:3369
Aggregate_ref_update(Item_sum *target, Query_block *owner)
Definition: item.h:3372
Query_block * m_owner
Definition: item.h:3371
Item_sum * m_target
Definition: item.h:3370
Definition: item.h:3342
Aggregate_replacement(Item_sum *target, Item_field *replacement)
Definition: item.h:3345
Item_field * m_replacement
Definition: item.h:3344
Item_sum * m_target
Definition: item.h:3343
Context struct used by walk method collect_scalar_subqueries to accumulate information about scalar s...
Definition: item.h:3067
Item * m_join_condition_context
Definition: item.h:3073
Location
Definition: item.h:3068
@ L_JOIN_COND
Definition: item.h:3068
@ L_HAVING
Definition: item.h:3068
@ L_SELECT
Definition: item.h:3068
@ L_WHERE
Definition: item.h:3068
bool m_collect_unconditionally
Definition: item.h:3074
int8 m_location
we are currently looking at this kind of clause, cf. enum Location
Definition: item.h:3072
std::vector< Css_info > m_list
accumulated all scalar subqueries found
Definition: item.h:3070
Minion class under Collect_scalar_subquery_info ("Css").
Definition: item.h:3039
int8 m_locations
set of locations
Definition: item.h:3041
Item * m_join_condition
Where did we find item above? Used when m_location == L_JOIN_COND, nullptr for other locations.
Definition: item.h:3047
bool m_add_coalesce
If true, add a COALESCE around replaced subquery: used for implicitly grouped COUNT() in subquery sel...
Definition: item.h:3052
table_map m_correlation_map
Definition: item.h:3044
uint m_having_idx
Index of the having expression copied to select list.
Definition: item.h:3057
Item_singlerow_subselect * item
the scalar subquery
Definition: item.h:3043
bool m_add_having_compensation
Set iff m_add_coalesce is true: we may get a NULL anyway even for COUNT if a HAVING clause is false i...
Definition: item.h:3055
bool m_implicitly_grouped_and_no_union
If true, we can forego cardinality checking of the derived table.
Definition: item.h:3049
Definition: item.h:3303
Mode m_default_value
Definition: item.h:3313
Item_field * m_outer_field
Definition: item.h:3307
Field * m_target
The field to be replaced.
Definition: item.h:3304
Item_field_replacement(Field *target, Item_field *item, Query_block *select, Mode default_value=Mode::CONFLATE)
Definition: item.h:3314
Mode
Definition: item.h:3308
Item_field * m_item
The replacement field replacement field iff outer ref.
Definition: item.h:3305
Definition: item.h:3322
Item_func * m_target
The function call to be replaced.
Definition: item.h:3323
Item_func_call_replacement(Item_func *func_target, Item_field *item, Query_block *select)
Definition: item.h:3325
Item_field * m_item
The replacement field.
Definition: item.h:3324
Definition: item.h:3295
Item_replacement(Query_block *transformed_block, Query_block *current_block)
Definition: item.h:3300
Query_block * m_curr_block
Transformed query block or a contained.
Definition: item.h:3297
Query_block * m_trans_block
Transformed query block.
Definition: item.h:3296
Definition: item.h:3332
Item * m_target
The item identifying the view_ref to be replaced.
Definition: item.h:3333
Field * m_field
The replacement field.
Definition: item.h:3334
Item_view_ref_replacement(Item *target, Field *field, Query_block *select)
Definition: item.h:3338
Item_field * m_outer_field
replacement field if outer ref
Definition: item.h:3335
Definition: item.h:3162
List< Item_func > stack
Definition: item.h:3164
< Argument object to change_context_processor
Definition: item.h:4466
Name_resolution_context * m_context
Definition: item.h:4467
Change_context(Name_resolution_context *context)
Definition: item.h:4468
Argument structure for walk processor Item::update_depended_from.
Definition: item.h:4483
Query_block * old_depended_from
Definition: item.h:4484
Query_block * new_depended_from
Definition: item.h:4485
The LEX object currently serves three different purposes:
Definition: sql_lex.h:4021
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
void * Alloc(size_t length)
Allocate memory.
Definition: my_alloc.h:145
Definition: mysql_lex_string.h:40
const char * str
Definition: mysql_lex_string.h:41
size_t length
Definition: mysql_lex_string.h:42
Definition: mysql_lex_string.h:35
char * str
Definition: mysql_lex_string.h:36
size_t length
Definition: mysql_lex_string.h:37
Definition: my_bitmap.h:43
Bison "location" class.
Definition: parse_location.h:43
Instances of Name_resolution_context store the information necessary for name resolution of Items and...
Definition: item.h:414
Name_resolution_context * next_context
Link to next name res context with the same query block as the base.
Definition: item.h:421
Table_ref * view_error_handler_arg
Definition: item.h:459
Name_resolution_context * outer_context
The name resolution context to search in when an Item cannot be resolved in this context (the context...
Definition: item.h:419
Security_context * security_ctx
Security context of this name resolution context.
Definition: item.h:475
Table_ref * first_name_resolution_table
In most cases the two table references below replace 'table_list' above for the purpose of name resol...
Definition: item.h:439
Table_ref * last_name_resolution_table
Last table to search in the list of leaf table references that begins with first_name_resolution_tabl...
Definition: item.h:444
Query_block * query_block
Query_block item belong to, in case of merged VIEW it can differ from Query_block where item was crea...
Definition: item.h:451
bool resolve_in_select_list
When true, items are resolved in this context against Query_block::item_list, SELECT_lex::group_list ...
Definition: item.h:469
bool view_error_handler
Definition: item.h:458
Table_ref * table_list
List of tables used to resolve the items of this context.
Definition: item.h:431
void resolve_in_table_list_only(Table_ref *tables)
Definition: item.h:477
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:422
Definition: table.h:1456
const char * alias
alias or table name
Definition: table.h:1708
bool has_null_row() const
Definition: table.h:2228
MY_BITMAP * fields_set_during_insert
A pointer to the bitmap of table fields (columns), which are explicitly set in the INSERT INTO statem...
Definition: table.h:1791
bool alias_name_used
Definition: table.h:1917
bool is_nullable() const
Return whether table is nullable.
Definition: table.h:2130
Definition: typelib.h:35
Definition: completion_hash.h:35
Descriptor of what and how to cache for Item::cache_const_expr_transformer/analyzer.
Definition: item.h:3918
Item * cache_item
Item to cache. Used as a binary flag, but kept as Item* for assertion.
Definition: item.h:3923
List< Item > stack
Path from the expression's top to the current item in item tree used to track parent of current item ...
Definition: item.h:3921
Item::enum_const_item_cache cache_arg
How to cache JSON data.
Definition: item.h:3925
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
Definition: result.h:30
This file defines all base public constants related to triggers in MySQL.
enum_trigger_variable_type
Enum constants to designate NEW and OLD trigger pseudo-variables.
Definition: trigger_def.h:73
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39
@ STRING_RESULT
not valid for UDFs
Definition: udf_registration_types.h:41
@ DECIMAL_RESULT
not valid for UDFs
Definition: udf_registration_types.h:45
@ REAL_RESULT
char *
Definition: udf_registration_types.h:42
@ INT_RESULT
double
Definition: udf_registration_types.h:43
@ INVALID_RESULT
Definition: udf_registration_types.h:40
@ ROW_RESULT
long long
Definition: udf_registration_types.h:44
Definition: dtoa.cc:595