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