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