MySQL 9.4.0
Source Code Documentation
item.h
Go to the documentation of this file.
1#ifndef ITEM_INCLUDED
2#define ITEM_INCLUDED
3
4/* Copyright (c) 2000, 2025, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <sys/types.h>
28
29#include <cfloat>
30#include <climits>
31#include <cmath>
32#include <cstdio>
33#include <cstring>
34#include <memory>
35#include <new>
36#include <optional>
37#include <string>
38#include <type_traits>
39#include <vector>
40
41#include "decimal.h"
42#include "field_types.h" // enum_field_types
43#include "lex_string.h"
44#include "memory_debugging.h"
45#include "my_alloc.h"
46#include "my_bitmap.h"
47#include "my_compiler.h"
48#include "my_dbug.h"
49#include "my_double2ulonglong.h"
50#include "my_inttypes.h"
51#include "my_sys.h"
52#include "my_table_map.h"
53#include "my_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_NUMERIC_CONV - if all items were numbers, convert to
167 @@character_set_connection
168 MY_COLL_ALLOW_NONE - allow return DERIVATION_NONE
169 (e.g. when aggregating for string result)
170 MY_COLL_CMP_CONV - for comparison: Allow SUPERSET and COERCIBLE
171 conversion, disallow NONE.
172*/
173
174#define MY_COLL_ALLOW_SUPERSET_CONV 1
175#define MY_COLL_ALLOW_COERCIBLE_CONV 2
176#define MY_COLL_ALLOW_NONE 4
177#define MY_COLL_ALLOW_NUMERIC_CONV 8
178
179#define MY_COLL_CMP_CONV \
180 (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
181
183 public:
187
191 }
196 }
197 DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg) {
198 collation = collation_arg;
199 derivation = derivation_arg;
200 set_repertoire_from_charset(collation_arg);
201 }
202 void set(const DTCollation &dt) {
203 collation = dt.collation;
206 }
207 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg) {
208 collation = collation_arg;
209 derivation = derivation_arg;
210 set_repertoire_from_charset(collation_arg);
211 }
212 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg,
213 uint repertoire_arg) {
214 collation = collation_arg;
215 derivation = derivation_arg;
216 repertoire = repertoire_arg;
217 }
218 void set_numeric() {
222 }
223 void set(const CHARSET_INFO *collation_arg) {
224 collation = collation_arg;
225 set_repertoire_from_charset(collation_arg);
226 }
227 void set(Derivation derivation_arg) { derivation = derivation_arg; }
228 void set_repertoire(uint repertoire_arg) { repertoire = repertoire_arg; }
229 bool aggregate(DTCollation &dt, uint flags = 0);
230 bool set(DTCollation &dt1, DTCollation &dt2, uint flags = 0) {
231 set(dt1);
232 return aggregate(dt2, flags);
233 }
234 const char *derivation_name() const {
235 switch (derivation) {
237 return "NUMERIC";
238 case DERIVATION_NULL:
239 return "NULL";
241 return "COERCIBLE";
243 return "IMPLICIT";
245 return "SYSCONST";
247 return "EXPLICIT";
248 case DERIVATION_NONE:
249 return "NONE";
250 default:
251 return "UNKNOWN";
252 }
253 }
254};
255
256/**
257 Class used as argument to Item::walk() together with mark_field_in_map()
258*/
260 public:
263
264 /**
265 If == NULL, update map of any table.
266 If <> NULL, update map of only this table.
267 */
268 TABLE *const table;
269 /// How to mark the map.
271};
272
273/**
274 Class used as argument to Item::walk() together with used_tables_for_level()
275*/
277 public:
279
280 Query_block *const select; ///< Level for which data is accumulated
281 table_map used_tables; ///< Accumulated used tables data
282};
283
284/*************************************************************************/
285
286/**
287 Storage for name strings.
288 Enpowers Simple_cstring with allocation routines from the sql_strmake family.
289
290 This class must stay as small as possible as we often
291 pass it into functions using call-by-value evaluation.
292
293 Don't add new members or virtual methods into this class!
294*/
296 private:
297 void set_or_copy(const char *str, size_t length, bool is_null_terminated) {
298 if (is_null_terminated)
299 set(str, length);
300 else
301 copy(str, length);
302 }
303
304 public:
306 /*
307 Please do NOT add constructor Name_string(const char *str) !
308 It will involve hidden strlen() call, which can affect
309 performance negatively. Use Name_string(str, len) instead.
310 */
311 Name_string(const char *str, size_t length) : Simple_cstring(str, length) {}
314 Name_string(const char *str, size_t length, bool is_null_terminated)
315 : Simple_cstring() {
316 set_or_copy(str, length, is_null_terminated);
317 }
318 Name_string(const LEX_STRING str, bool is_null_terminated)
319 : Simple_cstring() {
320 set_or_copy(str.str, str.length, is_null_terminated);
321 }
322 /**
323 Allocate space using sql_strmake() or sql_strmake_with_convert().
324 */
325 void copy(const char *str, size_t length, const CHARSET_INFO *cs);
326 /**
327 Variants for copy(), for various argument combinations.
328 */
329 void copy(const char *str, size_t length) {
331 }
332 void copy(const char *str) {
333 copy(str, (str ? strlen(str) : 0), system_charset_info);
334 }
335 void copy(const LEX_STRING lex) { copy(lex.str, lex.length); }
336 void copy(const LEX_STRING *lex) { copy(lex->str, lex->length); }
337 void copy(const Name_string str) { copy(str.ptr(), str.length()); }
338 /**
339 Compare name to another name in C string, case insensitively.
340 */
341 bool eq(const char *str) const {
342 assert(str && ptr());
343 return my_strcasecmp(system_charset_info, ptr(), str) == 0;
344 }
345 bool eq_safe(const char *str) const { return is_set() && str && eq(str); }
346 /**
347 Compare name to another name in Name_string, case insensitively.
348 */
349 bool eq(const Name_string name) const { return eq(name.ptr()); }
350 bool eq_safe(const Name_string name) const {
351 return is_set() && name.is_set() && eq(name);
352 }
353};
354
355#define NAME_STRING(x) Name_string(STRING_WITH_LEN(x))
356
357/**
358 Max length of an Item string for its use in an error message.
359 This should be kept in sync with MYSQL_ERRMSG_SIZE (which should
360 not be exceeded).
361*/
362#define ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT (300)
363
364extern const Name_string null_name_string;
365
366/**
367 Storage for Item names.
368 Adds "autogenerated" flag and warning functionality to Name_string.
369*/
371 private:
372 bool m_is_autogenerated; /* indicates if name of this Item
373 was autogenerated or set by user */
374 public:
378 /**
379 Set m_is_autogenerated flag to the given value.
380 */
383 }
384 /**
385 Return the auto-generated flag.
386 */
387 bool is_autogenerated() const { return m_is_autogenerated; }
388 using Name_string::copy;
389 /**
390 Copy name together with autogenerated flag.
391 Produce a warning if name was cut.
392 */
393 void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg,
394 bool is_autogenerated_arg);
395};
396
397/**
398 Instances of Name_resolution_context store the information necessary for
399 name resolution of Items and other context analysis of a query made in
400 fix_fields().
401
402 This structure is a part of Query_block, a pointer to this structure is
403 assigned when an item is created (which happens mostly during parsing
404 (sql_yacc.yy)), but the structure itself will be initialized after parsing
405 is complete
406
407 @todo move subquery of INSERT ... SELECT and CREATE ... SELECT to
408 separate Query_block which allow to remove tricks of changing this
409 structure before and after INSERT/CREATE and its SELECT to make correct
410 field name resolution.
411*/
413 /**
414 The name resolution context to search in when an Item cannot be
415 resolved in this context (the context of an outer select)
416 */
418 /// Link to next name res context with the same query block as the base
420
421 /**
422 List of tables used to resolve the items of this context. Usually these
423 are tables from the FROM clause of SELECT statement. The exceptions are
424 INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
425 subquery is not moved to a separate Query_block. For these types of
426 statements we have to change this member dynamically to ensure correct
427 name resolution of different parts of the statement.
428 */
430 /**
431 In most cases the two table references below replace 'table_list' above
432 for the purpose of name resolution. The first and last name resolution
433 table references allow us to search only in a sub-tree of the nested
434 join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
435 and JOIN ... ON.
436 */
438 /**
439 Last table to search in the list of leaf table references that begins
440 with first_name_resolution_table.
441 */
443
444 /**
445 Query_block item belong to, in case of merged VIEW it can differ from
446 Query_block where item was created, so we can't use table_list/field_list
447 from there
448 */
450
451 /*
452 Processor of errors caused during Item name resolving, now used only to
453 hide underlying tables in errors about views (i.e. it substitute some
454 errors for views)
455 */
458
459 /**
460 When true, items are resolved in this context against
461 Query_block::item_list, SELECT_lex::group_list and
462 this->table_list. If false, items are resolved only against
463 this->table_list.
464
465 @see Query_block::item_list, Query_block::group_list
466 */
468
469 /**
470 Security context of this name resolution context. It's used for views
471 and is non-zero only if the view is defined with SQL SECURITY DEFINER.
472 */
474
478 }
479};
480
481/**
482 Struct used to pass around arguments to/from
483 check_function_as_value_generator
484*/
487 int default_error_code, Value_generator_source val_gen_src)
488 : err_code(default_error_code), source(val_gen_src) {}
489 /// the order of the column in table
490 int col_index{-1};
491 /// the error code found during check(if any)
493 /*
494 If it is a generated column, default expression or check constraint
495 expression value generator.
496 */
498 /// the name of the function which is not allowed
499 const char *banned_function_name{nullptr};
500
501 /// Return the correct error code, based on whether or not if we are checking
502 /// for disallowed functions in generated column expressions, in default
503 /// value expressions or in check constraint expression.
505 return ((source == VGS_GENERATED_COLUMN)
506 ? ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
508 ? ER_DEFAULT_VAL_GENERATED_FUNCTION_IS_NOT_ALLOWED
509 : ER_CHECK_CONSTRAINT_FUNCTION_IS_NOT_ALLOWED);
510 }
511};
512/*
513 Store and restore the current state of a name resolution context.
514*/
515
517 private:
523
524 public:
525 /* Save the state of a name resolution context. */
526 void save_state(Name_resolution_context *context, Table_ref *table_list) {
527 save_table_list = context->table_list;
530 save_next_local = table_list->next_local;
532 }
533
534 /* Restore a name resolution context from saved state. */
535 void restore_state(Name_resolution_context *context, Table_ref *table_list) {
536 table_list->next_local = save_next_local;
538 context->table_list = save_table_list;
541 }
542
543 void update_next_local(Table_ref *table_list) {
544 save_next_local = table_list;
545 }
546
549 }
550};
551
552/*
553 This enum is used to report information about monotonicity of function
554 represented by Item* tree.
555 Monotonicity is defined only for Item* trees that represent table
556 partitioning expressions (i.e. have no subqueries/user vars/dynamic parameters
557 etc etc). An Item* tree is assumed to have the same monotonicity properties
558 as its corresponding function F:
559
560 [signed] longlong F(field1, field2, ...) {
561 put values of field_i into table record buffer;
562 return item->val_int();
563 }
564
565 NOTE
566 At the moment function monotonicity is not well defined (and so may be
567 incorrect) for Item trees with parameters/return types that are different
568 from INT_RESULT, may be NULL, or are unsigned.
569 It will be possible to address this issue once the related partitioning bugs
570 (BUG#16002, BUG#15447, BUG#13436) are fixed.
571
572 The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns
573 NULL which puts those rows into the NULL partition, but
574 '2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed
575 for this (see Bug#20577).
576*/
577
578typedef enum monotonicity_info {
579 NON_MONOTONIC, /* none of the below holds */
580 MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
581 MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */
582 MONOTONIC_STRICT_INCREASING, /* F() is unary and (x < y) => (F(x) < F(y)) */
583 MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */
585
586/**
587 A type for SQL-like 3-valued Booleans: true/false/unknown.
588*/
589class Bool3 {
590 public:
591 /// @returns an instance set to "FALSE"
592 static const Bool3 false3() { return Bool3(v_FALSE); }
593 /// @returns an instance set to "UNKNOWN"
594 static const Bool3 unknown3() { return Bool3(v_UNKNOWN); }
595 /// @returns an instance set to "TRUE"
596 static const Bool3 true3() { return Bool3(v_TRUE); }
597
598 bool is_true() const { return m_val == v_TRUE; }
599 bool is_unknown() const { return m_val == v_UNKNOWN; }
600 bool is_false() const { return m_val == v_FALSE; }
601
602 private:
604 /// This is private; instead, use false3()/etc.
605 Bool3(value v) : m_val(v) {}
606
608 /*
609 No operator to convert Bool3 to bool (or int) - intentionally: how
610 would you map unknown3 to true/false?
611 It is because we want to block such conversions that Bool3 is a class
612 instead of a plain enum.
613 */
614};
615
616/**
617 Type properties, used to collect type information for later assignment
618 to an Item object. The object stores attributes signedness, max length
619 and collation. However, precision and scale (for decimal numbers) and
620 fractional second precision (for time and datetime) are not stored,
621 since any type derived from this object will have default values for these
622 attributes.
623*/
625 public:
626 /// Constructor for any signed numeric type or date type
627 /// Defaults are provided for attributes like signedness and max length
629 : m_type(type_arg),
630 m_unsigned_flag(false),
631 m_max_length(0),
633 assert(type_arg != MYSQL_TYPE_VARCHAR && type_arg != MYSQL_TYPE_JSON);
634 }
635 /// Constructor for any numeric type, with explicit signedness
636 Type_properties(enum_field_types type_arg, bool unsigned_arg)
637 : m_type(type_arg),
638 m_unsigned_flag(unsigned_arg),
639 m_max_length(0),
641 assert(is_numeric_type(type_arg) || type_arg == MYSQL_TYPE_BIT ||
642 type_arg == MYSQL_TYPE_YEAR);
643 }
644 /// Constructor for character type, with explicit character set.
645 /// Default length/max length is provided.
647 : m_type(type_arg),
648 m_unsigned_flag(false),
649 m_max_length(0),
651 /// Constructor for Item
652 Type_properties(Item &item);
654 const bool m_unsigned_flag;
657};
658
659/*************************************************************************/
660
662 public:
664 virtual ~Settable_routine_parameter() = default;
665 /**
666 Set required privileges for accessing the parameter.
667
668 @param privilege The required privileges for this field, with the
669 following alternatives:
670 MODE_IN - SELECT_ACL
671 MODE_OUT - UPDATE_ACL
672 MODE_INOUT - SELECT_ACL | UPDATE_ACL
673 */
675 [[maybe_unused]]) {}
676
677 /*
678 Set parameter value.
679
680 SYNOPSIS
681 set_value()
682 thd thread handle
683 ctx context to which parameter belongs (if it is local
684 variable).
685 it item which represents new value
686
687 RETURN
688 false if parameter value has been set,
689 true if error has occurred.
690 */
691 virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it) = 0;
692
693 virtual void set_out_param_info(Send_field *info [[maybe_unused]]) {}
694
695 virtual const Send_field *get_out_param_info() const { return nullptr; }
696};
697
698/*
699 Analyzer function
700 SYNOPSIS
701 argp in/out IN: Analysis parameter
702 OUT: Parameter to be passed to the transformer
703
704 RETURN
705 true Invoke the transformer
706 false Don't do it
707
708*/
709typedef bool (Item::*Item_analyzer)(uchar **argp);
710
711/**
712 Type for transformers used by Item::transform and Item::compile
713 @param arg Argument used by the transformer. Really a typeless pointer
714 in spite of the uchar type (historical reasons). The
715 transformer needs to cast this to the desired pointer type
716 @returns The transformed item
717*/
718typedef Item *(Item::*Item_transformer)(uchar *arg);
719typedef void (*Cond_traverser)(const Item *item, void *arg);
720
721/**
722 Utility mixin class to be able to walk() only parts of item trees.
723
724 Used with PREFIX+POSTFIX walk: in the prefix call of the Item
725 processor, we process the item X, may decide that its children should not
726 be processed (just like if they didn't exist): processor calls stop_at(X)
727 for that. Then walk() goes to a child Y; the processor tests is_stopped(Y)
728 which returns true, so processor sees that it must not do any processing
729 and returns immediately. Finally, the postfix call to the processor on X
730 tests is_stopped(X) which returns "true" and understands that the
731 not-to-be-processed children have been skipped so calls restart(). Thus,
732 any sibling of X, any part of the Item tree not under X, can then be
733 processed.
734*/
736 protected:
741
742 /// Stops walking children of this item
743 void stop_at(const Item *i) {
744 assert(stopped_at_item == nullptr);
745 stopped_at_item = i;
746 }
747
748 /**
749 @returns if we are stopped. If item 'i' is where we stopped, restarts the
750 walk for next items.
751 */
752 bool is_stopped(const Item *i) {
753 if (stopped_at_item != nullptr) {
754 /*
755 Walking was disabled for a tree part rooted a one ancestor of 'i' or
756 rooted at 'i'.
757 */
758 if (stopped_at_item == i) {
759 /*
760 Walking was disabled for the tree part rooted at 'i'; we have now just
761 returned back to this root (POSTFIX call), left the tree part:
762 enable the walk again, for other tree parts.
763 */
764 stopped_at_item = nullptr;
765 }
766 // No further processing to do for this item:
767 return true;
768 }
769 return false;
770 }
771
772 private:
773 const Item *stopped_at_item{nullptr};
774};
775
776/// Increment *num if it is less than its maximal value.
777template <typename T>
778void SafeIncrement(T *num) {
779 if (*num < std::numeric_limits<T>::max()) {
780 *num += 1;
781 }
782}
783
784/**
785 This class represents the cost of evaluating an Item. @see SortPredicates
786 to see how this is used.
787*/
788class CostOfItem final {
789 public:
790 /// Set '*this' to represent the cost of 'item'.
791 void Compute(const Item &item) {
792 if (!m_computed) {
793 ComputeInternal(item);
794 }
795 }
796
798 assert(!m_computed);
799 m_is_expensive = true;
800 }
801
802 /// Add the cost of accessing a Field_str.
804 assert(!m_computed);
806 }
807
808 /// Add the cost of accessing any other Field.
810 assert(!m_computed);
812 }
813
814 bool IsExpensive() const {
815 assert(m_computed);
816 return m_is_expensive;
817 }
818
819 /**
820 Get the cost of field access when evaluating the Item associated with this
821 object. The cost unit is arbitrary, but the relative cost of different
822 items reflect the fact that operating on Field_str is more expensive than
823 other Field subclasses.
824 */
825 double FieldCost() const {
826 assert(m_computed);
828 }
829
830 private:
831 /// The cost of accessing a Field_str, relative to other Field types.
832 /// (The value was determined using benchmarks.)
833 static constexpr double kStrFieldCost = 1.8;
834
835 /// The cost of accessing a Field other than Field_str. 1.0 by definition.
836 static constexpr double kOtherFieldCost = 1.0;
837
838 /// True if 'ComputeInternal()' has been called.
839 bool m_computed{false};
840
841 /// True if the associated Item calls user defined functions or stored
842 /// procedures.
843 bool m_is_expensive{false};
844
845 /// The number of Field_str objects accessed by the associated Item.
847
848 /// The number of other Field objects accessed by the associated Item.
850
851 /// Compute the cost of 'root' and its descendants.
852 void ComputeInternal(const Item &root);
853};
854
855/**
856 This class represents a subquery contained in some subclass of
857 Item_subselect, @see FindContainedSubqueries().
858*/
860 /// The strategy for executing the subquery.
861 enum class Strategy : char {
862 /**
863 An independent subquery that is materialized, e.g.:
864 "SELECT * FROM tab WHERE field IN <independent subquery>".
865 where 'independent subquery' does not depend on any fields in 'tab'.
866 (This corresponds to the Item_in_subselect class.)
867 */
869
870 /**
871 A subquery that is reevaluated for each row, e.g.:
872 "SELECT * FROM tab WHERE field IN <dependent subquery>" or
873 "SELECT * FROM tab WHERE field = <dependent subquery>".
874 where 'dependent subquery' depends on at least one field in 'tab'.
875 Alternatively, the subquery may be independent of 'tab', but contain
876 a non-deterministic function such as 'rand()'. Such subqueries are also
877 required to be reevaluated for each row.
878 */
880
881 /**
882 An independent single-row subquery that is evaluated once, e.g.:
883 "SELECT * FROM tab WHERE field = <independent single-row subquery>".
884 (This corresponds to the Item_singlerow_subselect class.)
885 */
887 };
888
889 /// The root path of the subquery.
891
892 /// The strategy for executing the subquery.
894
895 /// The width (in bytes) of the subquery's rows. For variable-sized values we
896 /// use Item.max_length (but cap it at kMaxItemLengthEstimate).
897 /// @see kMaxItemLengthEstimate and
898 /// @see Item_in_subselect::get_contained_subquery().
900};
901
902/**
903 Base class that is used to represent any kind of expression in a
904 relational query. The class provides subclasses for simple components, like
905 literal (constant) values, column references and variable references,
906 as well as more complex expressions like comparison predicates,
907 arithmetic and string functions, row objects, function references and
908 subqueries.
909
910 The lifetime of an Item class object is often the same as a relational
911 statement, which may be used for several executions, but in some cases
912 it may also be generated for an optimized statement and thus be valid
913 only for one execution.
914
915 For Item objects with longer lifespan than one execution, we must take
916 special precautions when referencing objects with shorter lifespan.
917 For example, TABLE and Field objects against most tables are valid only for
918 one execution. For such objects, Item classes should rather reference
919 Table_ref and Item_field objects instead of TABLE and Field, because
920 these classes support dynamic rebinding of objects before each execution.
921 See Item::bind_fields() which binds new objects per execution and
922 Item::cleanup() that deletes references to such objects.
923
924 These mechanisms can also be used to handle other objects with shorter
925 lifespan, such as function references and variable references.
926*/
927class Item : public Parse_tree_node {
929
930 friend class udf_handler;
931
932 protected:
933 /**
934 Sets the result value of the function an empty string, using the current
935 character set. No memory is allocated.
936 @retval A pointer to the str_value member.
937 */
940 return &str_value;
941 }
942
943 public:
944 Item(const Item &) = delete;
945 void operator=(Item &) = delete;
946 static void *operator new(size_t size) noexcept {
947 return (*THR_MALLOC)->Alloc(size);
948 }
949 static void *operator new(size_t size, MEM_ROOT *mem_root,
950 const std::nothrow_t &arg
951 [[maybe_unused]] = std::nothrow) noexcept {
952 return mem_root->Alloc(size);
953 }
954
955 static void operator delete(void *ptr [[maybe_unused]],
956 size_t size [[maybe_unused]]) {
957 TRASH(ptr, size);
958 }
959 static void operator delete(void *, MEM_ROOT *,
960 const std::nothrow_t &) noexcept {}
961
962 enum Type {
964 FIELD_ITEM, ///< A reference to a field (column) in a table.
965 FUNC_ITEM, ///< A function call reference.
966 SUM_FUNC_ITEM, ///< A grouped aggregate function, or window function.
967 AGGR_FIELD_ITEM, ///< A special field for certain aggregate operations.
968 STRING_ITEM, ///< A string literal value.
969 INT_ITEM, ///< An integer literal value.
970 DECIMAL_ITEM, ///< A decimal literal value.
971 REAL_ITEM, ///< A floating-point literal value.
972 NULL_ITEM, ///< A NULL value.
973 HEX_BIN_ITEM, ///< A hexadecimal or binary literal value.
974 DEFAULT_VALUE_ITEM, ///< A default value for a column.
975 COND_ITEM, ///< An AND or OR condition.
976 REF_ITEM, ///< An indirect reference to another item.
977 INSERT_VALUE_ITEM, ///< A value from a VALUES function (deprecated).
978 SUBQUERY_ITEM, ///< A subquery or predicate referencing a subquery.
979 ROW_ITEM, ///< A row of other items.
980 CACHE_ITEM, ///< An internal item used to cache values.
981 TYPE_HOLDER_ITEM, ///< An internal item used to help aggregate a type.
982 PARAM_ITEM, ///< A dynamic parameter used in a prepared statement.
983 ROUTINE_FIELD_ITEM, ///< A variable inside a routine (proc, func, trigger)
984 TRIGGER_FIELD_ITEM, ///< An OLD or NEW field, used in trigger definitions.
985 XPATH_NODESET_ITEM, ///< Used in XPATH expressions.
986 VALUES_COLUMN_ITEM, ///< A value from a VALUES clause.
987 NAME_CONST_ITEM ///< A NAME_CONST expression
988 };
989
991
993
994 /// How to cache constant JSON data
996 /// Don't cache
998 /// Source data is a JSON string, parse and cache result
1000 /// Source data is SQL scalar, convert and cache result
1003
1004 enum Bool_test ///< Modifier for result transformation
1005 {
1016 };
1017
1018 // Return the default data type for a given result type
1020 switch (result) {
1021 case INT_RESULT:
1022 return MYSQL_TYPE_LONGLONG;
1023 case DECIMAL_RESULT:
1024 return MYSQL_TYPE_NEWDECIMAL;
1025 case REAL_RESULT:
1026 return MYSQL_TYPE_DOUBLE;
1027 case STRING_RESULT:
1028 return MYSQL_TYPE_VARCHAR;
1029 case INVALID_RESULT:
1030 return MYSQL_TYPE_INVALID;
1031 case ROW_RESULT:
1032 default:
1033 assert(false);
1034 }
1035 return MYSQL_TYPE_INVALID;
1036 }
1037
1038 // Return the default result type for a given data type
1040 switch (type) {
1041 case MYSQL_TYPE_TINY:
1042 case MYSQL_TYPE_SHORT:
1043 case MYSQL_TYPE_INT24:
1044 case MYSQL_TYPE_LONG:
1046 case MYSQL_TYPE_BOOL:
1047 case MYSQL_TYPE_BIT:
1048 case MYSQL_TYPE_YEAR:
1049 return INT_RESULT;
1051 case MYSQL_TYPE_DECIMAL:
1052 return DECIMAL_RESULT;
1053 case MYSQL_TYPE_FLOAT:
1054 case MYSQL_TYPE_DOUBLE:
1055 return REAL_RESULT;
1056 case MYSQL_TYPE_VARCHAR:
1058 case MYSQL_TYPE_STRING:
1062 case MYSQL_TYPE_BLOB:
1063 case MYSQL_TYPE_VECTOR:
1065 case MYSQL_TYPE_JSON:
1066 case MYSQL_TYPE_ENUM:
1067 case MYSQL_TYPE_SET:
1068 return STRING_RESULT;
1070 case MYSQL_TYPE_DATE:
1071 case MYSQL_TYPE_TIME:
1073 case MYSQL_TYPE_NEWDATE:
1076 case MYSQL_TYPE_TIME2:
1077 return STRING_RESULT;
1078 case MYSQL_TYPE_INVALID:
1079 return INVALID_RESULT;
1080 case MYSQL_TYPE_NULL:
1081 return STRING_RESULT;
1083 break;
1084 }
1085 assert(false);
1086 return INVALID_RESULT;
1087 }
1088
1089 /**
1090 Provide data type for a user or system variable, based on the type of
1091 the item that is assigned to the variable.
1092
1093 @note MYSQL_TYPE_VARCHAR is returned for all string types, but must be
1094 further adjusted based on maximum string length by the caller.
1095
1096 @param src_type Source type that variable's type is derived from
1097 */
1099 switch (src_type) {
1100 case MYSQL_TYPE_BOOL:
1101 case MYSQL_TYPE_TINY:
1102 case MYSQL_TYPE_SHORT:
1103 case MYSQL_TYPE_INT24:
1104 case MYSQL_TYPE_LONG:
1106 case MYSQL_TYPE_BIT:
1107 return MYSQL_TYPE_LONGLONG;
1108 case MYSQL_TYPE_DECIMAL:
1110 return MYSQL_TYPE_NEWDECIMAL;
1111 case MYSQL_TYPE_FLOAT:
1112 case MYSQL_TYPE_DOUBLE:
1113 return MYSQL_TYPE_DOUBLE;
1114 case MYSQL_TYPE_VARCHAR:
1116 case MYSQL_TYPE_STRING:
1117 return MYSQL_TYPE_VARCHAR;
1118 case MYSQL_TYPE_YEAR:
1119 return MYSQL_TYPE_LONGLONG;
1121 case MYSQL_TYPE_DATE:
1122 case MYSQL_TYPE_TIME:
1124 case MYSQL_TYPE_NEWDATE:
1127 case MYSQL_TYPE_TIME2:
1128 case MYSQL_TYPE_JSON:
1129 case MYSQL_TYPE_ENUM:
1130 case MYSQL_TYPE_SET:
1132 case MYSQL_TYPE_NULL:
1134 case MYSQL_TYPE_BLOB:
1135 case MYSQL_TYPE_VECTOR:
1138 return MYSQL_TYPE_VARCHAR;
1139 case MYSQL_TYPE_INVALID:
1141 return MYSQL_TYPE_INVALID;
1142 }
1143 assert(false);
1144 return MYSQL_TYPE_NULL;
1145 }
1146
1147 /// Item constructor for general use.
1148 Item();
1149
1150 /**
1151 Constructor used by Item_field, Item_ref & aggregate functions.
1152 Used for duplicating lists in processing queries with temporary tables.
1153
1154 Also used for Item_cond_and/Item_cond_or for creating top AND/OR structure
1155 of WHERE clause to protect it of optimisation changes in prepared statements
1156 */
1157 Item(THD *thd, const Item *item);
1158
1159 /**
1160 Parse-time context-independent constructor.
1161
1162 This constructor and caller constructors of child classes must not
1163 access/change thd->lex (including thd->lex->current_query_block(),
1164 thd->m_parser_state etc structures).
1165
1166 If we need to finalize the construction of the object, then we move
1167 all context-sensitive code to the itemize() virtual function.
1168
1169 The POS parameter marks this constructor and other context-independent
1170 constructors of child classes for easy recognition/separation from other
1171 (context-dependent) constructors.
1172 */
1173 explicit Item(const POS &);
1174
1175#ifdef EXTRA_DEBUG
1176 ~Item() override { item_name.set(0); }
1177#else
1178 ~Item() override = default;
1179#endif
1180
1181 private:
1182 /*
1183 Hide the contextualize*() functions: call/override the itemize()
1184 in Item class tree instead.
1185 */
1187 assert(0);
1188 return true;
1189 }
1190
1191 protected:
1192 /**
1193 Helper function to skip itemize() for grammar-allocated items
1194
1195 @param [out] res pointer to "this"
1196
1197 @retval true can skip itemize()
1198 @retval false can't skip: the item is allocated directly by the parser
1199 */
1200 bool skip_itemize(Item **res) {
1201 *res = this;
1202 return !is_parser_item;
1203 }
1204
1205 /*
1206 Checks if the function should return binary result based on the items
1207 provided as parameter.
1208 Function should only be used by Item_bit_func*
1209
1210 @param a item to check
1211 @param b item to check, may be nullptr
1212
1213 @returns true if binary result.
1214 */
1215 static bool bit_func_returns_binary(const Item *a, const Item *b);
1216
1217 /**
1218 The core function that does the actual itemization. itemize() is just a
1219 wrapper over this.
1220 */
1221 virtual bool do_itemize(Parse_context *pc, Item **res);
1222
1223 public:
1224 /**
1225 The same as contextualize() but with additional parameter
1226
1227 This function finalize the construction of Item objects (see the Item(POS)
1228 constructor): we can access/change parser contexts from the itemize()
1229 function.
1230
1231 Derived classes should not override this. If needed, they should
1232 override do_itemize().
1233
1234 @param pc current parse context
1235 @param [out] res pointer to "this" or to a newly allocated
1236 replacement object to use in the Item tree instead
1237
1238 @retval false success
1239 @retval true syntax/OOM/etc error
1240 */
1241 // Visual Studio with MSVC_CPPCHECK=ON gives warning C26435:
1242 // Function <fun> should specify exactly one of
1243 // 'virtual', 'override', or 'final'
1246 virtual bool itemize(Parse_context *pc, Item **res) final {
1247 // For condition#2 below ... If position is empty, this item was not
1248 // created in the parser; so don't show it in the parse tree.
1249 if (pc->m_show_parse_tree == nullptr || this->m_pos.is_empty())
1250 return do_itemize(pc, res);
1251
1252 Show_parse_tree *tree = pc->m_show_parse_tree.get();
1253
1254 if (begin_parse_tree(tree)) return true;
1255
1256 if (do_itemize(pc, res)) return true;
1257
1258 if (end_parse_tree(tree)) return true;
1259
1260 return false;
1261 }
1263
1264 void rename(char *new_name);
1265 void init_make_field(Send_field *tmp_field, enum enum_field_types type);
1266 /**
1267 Called for every Item after use (preparation and execution).
1268 Release all allocated resources, such as dynamic memory.
1269 Prepare for new execution by clearing cached values.
1270 Do not remove values allocated during preparation, destructor handles this.
1271 */
1272 virtual void cleanup() { marker = MARKER_NONE; }
1273 /**
1274 Called when an item has been removed, can be used to notify external
1275 objects about the removal, e.g subquery predicates that are part of
1276 the sj_candidates container.
1277 */
1278 virtual void notify_removal() {}
1279 virtual void make_field(Send_field *field);
1280 virtual Field *make_string_field(TABLE *table) const;
1281 virtual bool fix_fields(THD *, Item **);
1282 /**
1283 Fix after tables have been moved from one query_block level to the parent
1284 level, e.g by semijoin conversion.
1285 Basically re-calculate all attributes dependent on the tables.
1286
1287 @param parent_query_block query_block that tables are moved to.
1288 @param removed_query_block query_block that tables are moved away from,
1289 child of parent_query_block.
1290 */
1291 virtual void fix_after_pullout(Query_block *parent_query_block
1292 [[maybe_unused]],
1293 Query_block *removed_query_block
1294 [[maybe_unused]]) {}
1295 /*
1296 should be used in case where we are sure that we do not need
1297 complete fix_fields() procedure.
1298 */
1299 inline void quick_fix_field() { fixed = true; }
1300 virtual void set_can_use_prefix_key() {}
1301
1302 /**
1303 Propagate data type specifications into parameters and user variables.
1304 If item has descendants, propagate type recursively into these.
1305
1306 @param thd thread handler
1307 @param type Data type properties that are propagated
1308
1309 @returns false if success, true if error
1310 */
1311 virtual bool propagate_type(THD *thd [[maybe_unused]],
1312 const Type_properties &type [[maybe_unused]]) {
1313 return false;
1314 }
1315
1316 /**
1317 Wrapper for easier calling of propagate_type(const Type_properties &).
1318 @param thd thread handler
1319 @param def type to make Type_properties object
1320 @param pin if true: also mark the type as pinned
1321 @param inherit if true: also mark the type as inherited
1322
1323 @returns false if success, true if error
1324 */
1326 bool pin = false, bool inherit = false) {
1327 /*
1328 Propagate supplied type if types have not yet been assigned to expression,
1329 or type is pinned, in which case the supplied type overrides the
1330 actual type of parameters. Note we do not support "pinning" of
1331 expressions containing parameters, only standalone parameters,
1332 but this is a very minor problem.
1333 */
1334 if (data_type() != MYSQL_TYPE_INVALID && !(pin && type() == PARAM_ITEM))
1335 return false;
1336 if (propagate_type(thd, (def == MYSQL_TYPE_VARCHAR)
1338 : (def == MYSQL_TYPE_JSON)
1340 : Type_properties(def)))
1341 return true;
1342 if (pin) pin_data_type();
1343 if (inherit) set_data_type_inherited();
1344
1345 return false;
1346 }
1347
1348 /**
1349 For Items with data type JSON, mark that a string argument is treated
1350 as a scalar JSON value. Only relevant for the Item_param class.
1351 */
1352 virtual void mark_json_as_scalar() {}
1353
1354 /**
1355 If this item represents a IN/ALL/ANY/comparison_operator
1356 subquery, return that (along with data on how it will be executed).
1357 (These subqueries correspond to
1358 @see Item_in_subselect and @see Item_singlerow_subselect .) Also,
1359 @see FindContainedSubqueries() for context.
1360 @param outer_query_block the Query_block to which 'this' belongs.
1361 @returns The subquery that 'this' represents, if there is one.
1362 */
1363 virtual std::optional<ContainedSubquery> get_contained_subquery(
1364 const Query_block *outer_query_block [[maybe_unused]]) {
1365 return std::nullopt;
1366 }
1367
1368 protected:
1369 /**
1370 Helper function which does all of the work for
1371 save_in_field(Field*, bool), except some error checking common to
1372 all subclasses, which is performed by save_in_field() itself.
1373
1374 Subclasses that need to specialize the behaviour of
1375 save_in_field(), should override this function instead of
1376 save_in_field().
1377
1378 @param[in,out] field the field to save the item into
1379 @param no_conversions whether or not to allow conversions of the value
1380
1381 @return the status from saving into the field
1382 @retval TYPE_OK item saved without any errors or warnings
1383 @retval != TYPE_OK there were errors or warnings when saving the item
1384 */
1386 bool no_conversions);
1387
1388 public:
1389 /**
1390 Save the item into a field but do not emit any warnings.
1391
1392 @param field field to save the item into
1393 @param no_conversions whether or not to allow conversions of the value
1394
1395 @return the status from saving into the field
1396 @retval TYPE_OK item saved without any issues
1397 @retval != TYPE_OK there were issues saving the item
1398 */
1400 bool no_conversions);
1401 /**
1402 Save a temporal value in packed longlong format into a Field.
1403 Used in optimizer.
1404
1405 Subclasses that need to specialize this function, should override
1406 save_in_field_inner().
1407
1408 @param[in,out] field the field to save the item into
1409 @param no_conversions whether or not to allow conversions of the value
1410
1411 @return the status from saving into the field
1412 @retval TYPE_OK item saved without any errors or warnings
1413 @retval != TYPE_OK there were errors or warnings when saving the item
1414 */
1415 type_conversion_status save_in_field(Field *field, bool no_conversions);
1416
1417 /**
1418 A slightly faster value of save_in_field() that returns no error value
1419 (you will need to check thd->is_error() yourself), and does not support
1420 saving into hidden fields for functional indexes. Used by copy_funcs(),
1421 to avoid the functional call overhead and RAII setup of save_in_field().
1422 */
1423 void save_in_field_no_error_check(Field *field, bool no_conversions) {
1424 assert(!field->is_field_for_functional_index());
1425 save_in_field_inner(field, no_conversions);
1426 }
1427
1428 virtual void save_org_in_field(Field *field) { save_in_field(field, true); }
1429
1430 virtual bool send(Protocol *protocol, String *str);
1431 bool evaluate(THD *thd, String *str);
1432 /**
1433 Compare this item with another item for equality.
1434 If both pointers are the same, the items are equal.
1435 Both items must be of same type.
1436 For literal values, metadata must be the same and the values must be equal.
1437 Strings are compared with the embedded collation.
1438 For column references, table references and column names must be the same.
1439 For functions, the function type, function properties and arguments must
1440 be equal. Otherwise, see specific implementations.
1441 @todo: Current implementation requires that cache objects, ref objects
1442 and rollup wrappers are stripped away. This should be eliminated.
1443 */
1444 virtual bool eq(const Item *) const;
1445
1446 const Item *unwrap_for_eq() const;
1447
1448 virtual Item_result result_type() const { return REAL_RESULT; }
1449 /**
1450 Result type when an item appear in a numeric context.
1451 See Field::numeric_context_result_type() for more comments.
1452 */
1455 }
1456 /**
1457 Similar to result_type() but makes DATE, DATETIME, TIMESTAMP
1458 pretend to be numbers rather than strings.
1459 */
1462 : result_type();
1463 }
1464
1465 /**
1466 Set data type for item as inherited.
1467 Non-empty implementation only for dynamic parameters.
1468 */
1469 virtual void set_data_type_inherited() {}
1470
1471 /**
1472 Pin the data type for the item.
1473 Non-empty implementation only for dynamic parameters.
1474 */
1475 virtual void pin_data_type() {}
1476
1477 /// Retrieve the derived data type of the Item.
1479 return static_cast<enum_field_types>(m_data_type);
1480 }
1481
1482 /**
1483 Retrieve actual data type for an item. Equal to data_type() for
1484 all items, except parameters.
1485 */
1486 virtual enum_field_types actual_data_type() const { return data_type(); }
1487
1488 /**
1489 Get the default data (output) type for the specific item.
1490 Important for some SQL functions that may deliver multiple result types,
1491 and is used to determine data type for function's parameters that cannot
1492 be type-resolved by looking at the context.
1493 An example of such function is '+', which may return INT, DECIMAL,
1494 DOUBLE, depending on arguments.
1495 On the contrary, many other functions have a fixed output type, usually
1496 set with set_data_type_XXX(), which overrides the value of
1497 default_data_type(). For example, COS always returns DOUBLE,
1498 */
1500 // If data type has been set, the information returned here is irrelevant:
1501 assert(data_type() == MYSQL_TYPE_INVALID);
1502 return MYSQL_TYPE_VARCHAR;
1503 }
1504 /**
1505 Set the data type of the current Item. It is however recommended to
1506 use one of the type-specific setters if possible.
1507
1508 @param data_type The data type of this Item.
1509 */
1511 m_data_type = static_cast<uint8>(data_type);
1512 }
1513
1514 inline void set_data_type_null() {
1517 max_length = 0;
1518 set_nullable(true);
1519 }
1520
1521 inline void set_data_type_bool() {
1524 decimals = 0;
1525 max_length = 1;
1526 }
1527
1528 /**
1529 Set the data type of the Item to be a specific integer type
1530
1531 @param type Integer type
1532 @param unsigned_prop Whether the integer is signed or not
1533 @param max_width Maximum width of field in number of digits
1534 */
1535 inline void set_data_type_int(enum_field_types type, bool unsigned_prop,
1536 uint32 max_width) {
1537 assert(type == MYSQL_TYPE_TINY || type == MYSQL_TYPE_SHORT ||
1542 unsigned_flag = unsigned_prop;
1543 decimals = 0;
1544 fix_char_length(max_width);
1545 }
1546
1547 /**
1548 Set the data type of the Item to be longlong.
1549 Maximum display width is set to be the maximum of a 64-bit integer,
1550 but it may be adjusted later. The unsigned property is not affected.
1551 */
1555 decimals = 0;
1556 fix_char_length(21);
1557 }
1558
1559 /**
1560 Set the data type of the Item to be decimal.
1561 The unsigned property must have been set before calling this function.
1562
1563 @param precision Number of digits of precision
1564 @param scale Number of digits after decimal point.
1565 */
1566 inline void set_data_type_decimal(uint8 precision, uint8 scale) {
1569 assert(precision <= DECIMAL_MAX_PRECISION);
1570 decimals = scale;
1572 precision, scale, unsigned_flag));
1573 }
1574
1575 /// Set the data type of the Item to be double precision floating point.
1576 inline void set_data_type_double() {
1581 }
1582
1583 /// Set the data type of the Item to be single precision floating point.
1584 inline void set_data_type_float() {
1589 }
1590
1591 /**
1592 Set the Item to be variable length string. Actual type is determined from
1593 maximum string size. Collation must have been set before calling function.
1594
1595 @param max_l Maximum number of characters in string
1596 */
1597 inline void set_data_type_string(uint32 max_l) {
1604 else
1606 }
1607
1608 /**
1609 Set the Item to be variable length string. Like function above, but with
1610 larger string length precision.
1611
1612 @param max_char_length_arg Maximum number of characters in string
1613 */
1614 inline void set_data_type_string(ulonglong max_char_length_arg) {
1615 ulonglong max_result_length =
1616 max_char_length_arg * collation.collation->mbmaxlen;
1617 if (max_result_length > MAX_BLOB_WIDTH) {
1618 max_result_length = MAX_BLOB_WIDTH;
1619 m_nullable = true;
1620 }
1622 uint32(max_result_length / collation.collation->mbmaxlen));
1623 }
1624
1625 /**
1626 Set the Item to be variable length string. Like function above, but will
1627 also set character set and collation.
1628
1629 @param max_l Maximum number of characters in string
1630 @param cs Pointer to character set and collation struct
1631 */
1632 inline void set_data_type_string(uint32 max_l, const CHARSET_INFO *cs) {
1634 set_data_type_string(max_l);
1635 }
1636
1637 /**
1638 Set the Item to be variable length string. Like function above, but will
1639 also set full collation information.
1640
1641 @param max_l Maximum number of characters in string
1642 @param coll Ref to collation data, including derivation and repertoire
1643 */
1644 inline void set_data_type_string(uint32 max_l, const DTCollation &coll) {
1645 collation.set(coll);
1646 set_data_type_string(max_l);
1647 }
1648
1649 /**
1650 Set the Item to be fixed length string. Collation must have been set
1651 before calling function.
1652
1653 @param max_l Number of characters in string
1654 */
1655 inline void set_data_type_char(uint32 max_l) {
1656 assert(max_l <= MAX_CHAR_WIDTH);
1660 }
1661
1662 /**
1663 Set the Item to be fixed length string. Like function above, but will
1664 also set character set and collation.
1665
1666 @param max_l Maximum number of characters in string
1667 @param cs Pointer to character set and collation struct
1668 */
1669 inline void set_data_type_char(uint32 max_l, const CHARSET_INFO *cs) {
1671 set_data_type_char(max_l);
1672 }
1673
1674 /**
1675 Set the Item to be of BLOB type.
1676
1677 @param type Actual blob data type
1678 @param max_l Maximum number of characters in data type
1679 */
1684 ulonglong max_width = max_l * collation.collation->mbmaxlen;
1685 if (max_width > Field::MAX_LONG_BLOB_WIDTH) {
1686 max_width = Field::MAX_LONG_BLOB_WIDTH;
1687 }
1688 max_length = max_width;
1690 }
1691
1692 /// Set all type properties for Item of DATE type.
1693 inline void set_data_type_date() {
1696 decimals = 0;
1698 }
1699
1700 /**
1701 Set all type properties for Item of TIME type.
1702
1703 @param fsp Fractional seconds precision
1704 */
1705 inline void set_data_type_time(uint8 fsp) {
1706 assert(fsp <= DATETIME_MAX_DECIMALS);
1709 decimals = fsp;
1710 max_length = MAX_TIME_WIDTH + fsp + (fsp > 0 ? 1 : 0);
1711 }
1712
1713 /**
1714 Set all properties for Item of DATETIME type.
1715
1716 @param fsp Fractional seconds precision
1717 */
1719 assert(fsp <= DATETIME_MAX_DECIMALS);
1722 decimals = fsp;
1723 max_length = MAX_DATETIME_WIDTH + fsp + (fsp > 0 ? 1 : 0);
1724 }
1725
1726 /**
1727 Set all properties for Item of TIMESTAMP type.
1728
1729 @param fsp Fractional seconds precision
1730 */
1732 assert(fsp <= DATETIME_MAX_DECIMALS);
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 }
2737 return *(pointer_cast<Item **>(arg)) == this;
2738 }
2739 virtual bool collect_item_field_processor(uchar *) { return false; }
2740 virtual bool collect_item_field_or_ref_processor(uchar *) { return false; }
2741 virtual bool collect_outer_field_processor(uchar *) { return false; }
2742
2744 public:
2747 : m_items(fields_or_refs) {}
2750 const Collect_item_fields_or_refs &) = delete;
2751
2752 friend class Item_sum;
2753 friend class Item_field;
2754 friend class Item_ref;
2755 };
2756
2758 public:
2761 /// Used to compute \c Item_field's \c m_protected_by_any_value. Pushed and
2762 /// popped when walking arguments of \c Item_func_any_value.a
2765 Query_block *transformed_block)
2766 : m_item_fields_or_view_refs(fields_or_vr),
2767 m_transformed_block(transformed_block) {}
2769 delete;
2771 const Collect_item_fields_or_view_refs &) = delete;
2772
2773 friend class Item_sum;
2774 friend class Item_field;
2776 friend class Item_view_ref;
2777 };
2778
2779 /**
2780 Collects fields and view references that have the qualifying table
2781 in the specified query block.
2782 */
2784 return false;
2785 }
2786
2787 /**
2788 Item::walk function. Set bit in table->tmp_set for all fields in
2789 table 'arg' that are referred to by the Item.
2790 */
2791 virtual bool add_field_to_set_processor(uchar *) { return false; }
2792
2793 /// A processor to handle the select lex visitor framework.
2794 virtual bool visitor_processor(uchar *arg);
2795
2796 /**
2797 Item::walk function. Set bit in table->cond_set for all fields of
2798 all tables that are referred to by the Item.
2799 */
2800 virtual bool add_field_to_cond_set_processor(uchar *) { return false; }
2801
2802 /**
2803 Visitor interface for removing all column expressions (Item_field) in
2804 this expression tree from a bitmap. @see walk()
2805
2806 @param arg A MY_BITMAP* cast to unsigned char*, where the bits represent
2807 Field::field_index values.
2808 */
2809 virtual bool remove_column_from_bitmap(uchar *arg [[maybe_unused]]) {
2810 return false;
2811 }
2812 virtual bool find_item_in_field_list_processor(uchar *) { return false; }
2813 virtual bool change_context_processor(uchar *) { return false; }
2814 virtual bool find_item_processor(uchar *arg) { return this == (void *)arg; }
2816 return !basic_const_item();
2817 }
2818 /// Is this an Item_field which references the given Field argument?
2819 virtual bool find_field_processor(uchar *) { return false; }
2820 /// Wrap incompatible arguments in CAST nodes to the expected data types
2821 virtual bool cast_incompatible_args(uchar *) { return false; }
2822 /**
2823 Mark underlying field in read or write map of a table.
2824
2825 @param arg Mark_field object
2826 */
2827 virtual bool mark_field_in_map(uchar *arg [[maybe_unused]]) { return false; }
2828
2829 protected:
2830 /**
2831 Helper function for mark_field_in_map(uchar *arg).
2832
2833 @param mark_field Mark_field object
2834 @param field Field to be marked for read/write
2835 */
2836 static inline bool mark_field_in_map(Mark_field *mark_field, Field *field) {
2837 TABLE *table = mark_field->table;
2838 if (table != nullptr && table != field->table) return false;
2839
2840 table = field->table;
2841 table->mark_column_used(field, mark_field->mark);
2842
2843 return false;
2844 }
2845
2846 public:
2847 /**
2848 Reset execution state for such window function types
2849 as determined by arg
2850
2851 @param arg pointing to a bool which, if true, says to reset state
2852 for framing window function, else for non-framing
2853 */
2854 virtual bool reset_wf_state(uchar *arg [[maybe_unused]]) { return false; }
2855
2856 /**
2857 Return used table information for the specified query block (level).
2858 For a field that is resolved from this query block, return the table number.
2859 For a field that is resolved from a query block outer to the specified one,
2860 return OUTER_REF_TABLE_BIT
2861
2862 @param[in,out] arg pointer to an instance of class Used_tables, which is
2863 constructed with the query block as argument.
2864 The used tables information is accumulated in the field
2865 used_tables in this class.
2866
2867 @note This function is used to update used tables information after
2868 merging a query block (a subquery) with its parent.
2869 */
2870 virtual bool used_tables_for_level(uchar *arg [[maybe_unused]]) {
2871 return false;
2872 }
2873 /**
2874 Check privileges.
2875
2876 @param thd thread handle
2877 */
2878 virtual bool check_column_privileges(uchar *thd [[maybe_unused]]) {
2879 return false;
2880 }
2881 virtual bool inform_item_in_cond_of_tab(uchar *) { return false; }
2882 /**
2883 Bind objects from the current execution context to field objects in
2884 item trees. Typically used to bind Field objects from TABLEs to
2885 Item_field objects.
2886 */
2887 virtual void bind_fields() {}
2888
2889 /**
2890 Context object for (functions that override)
2891 Item::clean_up_after_removal().
2892 */
2894 public:
2896 assert(root != nullptr);
2897 }
2898
2900
2901 private:
2902 /**
2903 Pointer to Cleanup_after_removal_context containing from which
2904 select the walk started, i.e., the Query_block that contained the clause
2905 that was removed.
2906 */
2908
2909 friend class Item;
2910 friend class Item_func_eq;
2911 friend class Item_sum;
2912 friend class Item_subselect;
2913 friend class Item_ref;
2914 };
2915 /**
2916 Clean up after removing the item from the item tree.
2917
2918 param arg pointer to a Cleanup_after_removal_context object
2919 @todo: If class ORDER is refactored so that all indirect
2920 grouping/ordering expressions are represented with Item_ref
2921 objects, all implementations of cleanup_after_removal() except
2922 the one for Item_ref can be removed.
2923 */
2924 virtual bool clean_up_after_removal(uchar *arg);
2925
2926 /// @see Distinct_check::check_query()
2927 virtual bool aggregate_check_distinct(uchar *) { return false; }
2928 /// @see Group_check::check_query()
2929 virtual bool aggregate_check_group(uchar *) { return false; }
2930 /// @see Group_check::analyze_conjunct()
2931 virtual bool is_strong_side_column_not_in_fd(uchar *) { return false; }
2932 /// @see Group_check::is_in_fd_of_underlying()
2933 virtual bool is_column_not_in_fd(uchar *) { return false; }
2934 virtual Bool3 local_column(const Query_block *) const {
2935 return Bool3::false3();
2936 }
2937
2938 /**
2939 Minion class under \c Collect_scalar_subquery_info ("Css"). Information
2940 about one scalar subquery being considered for transformation
2941 */
2942 struct Css_info {
2943 /// set of locations
2945 /// the scalar subquery
2948 /// Where did we find item above? Used when \c m_location == \c L_JOIN_COND,
2949 /// nullptr for other locations.
2951 /// If true, we can forego cardinality checking of the derived table
2953 /// If true, add a COALESCE around replaced subquery: used for implicitly
2954 /// grouped COUNT() in subquery select list when subquery is correlated
2955 bool m_add_coalesce{false};
2956 /// Set iff \c m_add_coalesce is true: we may get a NULL anyway even for
2957 /// COUNT if a HAVING clause is false in the subquery.
2959 /// Index of the having expression copied to select list
2961 };
2962
2963 /**
2964 Context struct used by walk method collect_scalar_subqueries to
2965 accumulate information about scalar subqueries found.
2966
2967 In: m_location of expression walked, m_join_condition_context
2968 Out: m_list
2969 */
2971 enum Location { L_SELECT = 1, L_WHERE = 2, L_HAVING = 4, L_JOIN_COND = 8 };
2972 /// accumulated all scalar subqueries found
2973 std::vector<Css_info> m_list;
2974 /// we are currently looking at this kind of clause, cf. enum Location
2979 friend class Item_sum;
2981 };
2982
2983 virtual bool collect_scalar_subqueries(uchar *) { return false; }
2984 virtual bool collect_grouped_aggregates(uchar *) { return false; }
2985 virtual bool collect_subqueries(uchar *) { return false; }
2986 virtual bool update_depended_from(uchar *) { return false; }
2987 /**
2988 Check if an aggregate is referenced from within the GROUP BY
2989 clause of the query block in which it is aggregated. Such
2990 references will be rejected.
2991 @see Item_ref::fix_fields()
2992 @retval true if this is an aggregate which is referenced from
2993 the GROUP BY clause of the aggregating query block
2994 @retval false otherwise
2995 */
2996 virtual bool has_aggregate_ref_in_group_by(uchar *) { return false; }
2997
2998 bool visit_all_analyzer(uchar **) { return true; }
2999 virtual bool cache_const_expr_analyzer(uchar **cache_item);
3001
3002 virtual bool equality_substitution_analyzer(uchar **) { return false; }
3003
3004 virtual Item *equality_substitution_transformer(uchar *) { return this; }
3005
3006 /**
3007 Check if a partition function is allowed.
3008
3009 @return whether a partition function is not accepted
3010
3011 @details
3012 check_partition_func_processor is used to check if a partition function
3013 uses an allowed function. An allowed function will always ensure that
3014 X=Y guarantees that also part_function(X)=part_function(Y) where X is
3015 a set of partition fields and so is Y. The problems comes mainly from
3016 character sets where two equal strings can be quite unequal. E.g. the
3017 german character for double s is equal to 2 s.
3018
3019 The default is that an item is not allowed
3020 in a partition function. Allowed functions
3021 can never depend on server version, they cannot depend on anything
3022 related to the environment. They can also only depend on a set of
3023 fields in the table itself. They cannot depend on other tables and
3024 cannot contain any queries and cannot contain udf's or similar.
3025 If a new Item class is defined and it inherits from a class that is
3026 allowed in a partition function then it is very important to consider
3027 whether this should be inherited to the new class. If not the function
3028 below should be defined in the new Item class.
3029
3030 The general behaviour is that most integer functions are allowed.
3031 If the partition function contains any multi-byte collations then
3032 the function check_part_func_fields will report an error on the
3033 partition function independent of what functions are used. So the
3034 only character sets allowed are single character collation and
3035 even for those only a limited set of functions are allowed. The
3036 problem with multi-byte collations is that almost every string
3037 function has the ability to change things such that two strings
3038 that are equal will not be equal after manipulated by a string
3039 function. E.g. two strings one contains a double s, there is a
3040 special german character that is equal to two s. Now assume a
3041 string function removes one character at this place, then in
3042 one the double s will be removed and in the other there will
3043 still be one s remaining and the strings are no longer equal
3044 and thus the partition function will not sort equal strings into
3045 the same partitions.
3046
3047 So the check if a partition function is valid is two steps. First
3048 check that the field types are valid, next check that the partition
3049 function is valid. The current set of partition functions valid
3050 assumes that there are no multi-byte collations amongst the partition
3051 fields.
3052 */
3053 virtual bool check_partition_func_processor(uchar *) { return true; }
3054 virtual bool subst_argument_checker(uchar **arg) {
3055 if (*arg) *arg = nullptr;
3056 return true;
3057 }
3058 virtual bool explain_subquery_checker(uchar **) { return true; }
3059 virtual Item *explain_subquery_propagator(uchar *) { return this; }
3060
3061 virtual Item *equal_fields_propagator(uchar *) { return this; }
3062 // Mark the item to not be part of substitution.
3063 virtual bool disable_constant_propagation(uchar *) { return false; }
3064
3066 // Stack of pointers to enclosing functions
3068 };
3069 virtual Item *replace_equal_field(uchar *) { return this; }
3070 virtual bool replace_equal_field_checker(uchar **) { return true; }
3071 /*
3072 Check if an expression value has allowed arguments, like DATE/DATETIME
3073 for date functions. Also used by partitioning code to reject
3074 timezone-dependent expressions in a (sub)partitioning function.
3075 */
3076 virtual bool check_valid_arguments_processor(uchar *) { return false; }
3077
3078 /**
3079 Check if this item is allowed for a virtual column or inside a
3080 default expression. Should be overridden in child classes.
3081
3082 @param[in,out] args Due to the limitation of Item::walk()
3083 it is declared as a pointer to uchar, underneath there's a actually a
3084 structure of type Check_function_as_value_generator_parameters.
3085 It is used mainly in Item_field.
3086
3087 @returns true if function is not accepted
3088 */
3089 virtual bool check_function_as_value_generator(uchar *args);
3090
3091 /**
3092 Check if a generated expression depends on DEFAULT function with
3093 specific column name as argument.
3094
3095 @param[in] args Name of column used as DEFAULT function argument.
3096
3097 @returns false if the function is not DEFAULT(args), otherwise true.
3098 */
3100 [[maybe_unused]]) {
3101 return false;
3102 }
3103 /**
3104 Check if all the columns present in this expression are from the
3105 derived table. Used in determining if a condition can be pushed
3106 down to derived table.
3107 */
3108 virtual bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) {
3109 // A generic item cannot be pushed down unless it's a constant
3110 // which does not have a subquery.
3111 return !const_item() || has_subquery();
3112 }
3113
3114 /**
3115 Check if all the columns present in this expression are present
3116 in PARTITION clause of window functions of the derived table.
3117 Used in checking if a condition can be pushed down to derived table.
3118 */
3119 virtual bool check_column_in_window_functions(uchar *arg [[maybe_unused]]) {
3120 return false;
3121 }
3122 /**
3123 Check if all the columns present in this expression are present
3124 in GROUP BY clause of the derived table. Used in checking if
3125 a condition can be pushed down to derived table.
3126 */
3127 virtual bool check_column_in_group_by(uchar *arg [[maybe_unused]]) {
3128 return false;
3129 }
3130 /**
3131 Assuming this expression is part of a condition that would be pushed to the
3132 WHERE clause of a materialized derived table, replace, in this expression,
3133 each derived table's column with a clone of the expression lying under it
3134 in the derived table's definition. We replace with a clone, because the
3135 condition can be pushed further down in case of nested derived tables.
3136 */
3137 virtual Item *replace_with_derived_expr(uchar *arg [[maybe_unused]]) {
3138 return this;
3139 }
3140 /**
3141 Assuming this expression is part of a condition that would be pushed to the
3142 HAVING clause of a materialized derived table, replace, in this expression,
3143 each derived table's column with a reference to the expression lying under
3144 it in the derived table's definition. Unlike replace_with_derived_expr, a
3145 clone is not used because HAVING condition will not be pushed further
3146 down in case of nested derived tables.
3147 */
3148 virtual Item *replace_with_derived_expr_ref(uchar *arg [[maybe_unused]]) {
3149 return this;
3150 }
3151 /**
3152 Assuming this expression is part of a condition that would be pushed to a
3153 materialized derived table, replace, in this expression, each view reference
3154 with a clone of the expression in merged derived table's definition.
3155 We replace with a clone, because the referenced item in a view reference
3156 is shared by all the view references to that expression.
3157 */
3158 virtual Item *replace_view_refs_with_clone(uchar *arg [[maybe_unused]]) {
3159 return this;
3160 }
3161 /*
3162 For SP local variable returns pointer to Item representing its
3163 current value and pointer to current Item otherwise.
3164 */
3165 virtual Item *this_item() { return this; }
3166 virtual const Item *this_item() const { return this; }
3167
3168 /*
3169 For SP local variable returns address of pointer to Item representing its
3170 current value and pointer passed via parameter otherwise.
3171 */
3172 virtual Item **this_item_addr(THD *, Item **addr_arg) { return addr_arg; }
3173
3174 // Row emulation
3175 virtual uint cols() const { return 1; }
3176 virtual Item *element_index(uint) { return this; }
3177 virtual Item **addr(uint) { return nullptr; }
3178 virtual bool check_cols(uint c);
3179 // It is not row => null inside is impossible
3180 virtual bool null_inside() { return false; }
3181 // used in row subselects to get value of elements
3182 virtual void bring_value() {}
3183
3184 Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length) const;
3185 virtual Item_field *field_for_view_update() { return nullptr; }
3186 /**
3187 Informs an item that it is wrapped in a truth test, in case it wants to
3188 transforms itself to implement this test by itself.
3189 @param thd Thread handle
3190 @param test Truth test
3191 */
3192 virtual Item *truth_transformer(THD *thd [[maybe_unused]],
3193 Bool_test test [[maybe_unused]]) {
3194 return nullptr;
3195 }
3196 virtual Item *update_value_transformer(uchar *) { return this; }
3197
3199 Query_block *m_trans_block; ///< Transformed query block
3200 Query_block *m_curr_block; ///< Transformed query block or a contained
3201 ///< subquery. Pushed when diving into
3202 ///< subqueries.
3203 Item_replacement(Query_block *transformed_block, Query_block *current_block)
3204 : m_trans_block(transformed_block), m_curr_block(current_block) {}
3205 };
3207 Field *m_target; ///< The field to be replaced
3208 Item_field *m_item; ///< The replacement field
3209 ///< replacement field iff outer ref
3211 enum class Mode {
3212 CONFLATE, // include both Item_field and Item_default_value
3213 FIELD, // ignore Item_default_value
3214 DEFAULT_VALUE // ignore Item_field
3215 };
3218 Mode default_value = Mode::CONFLATE)
3219 : Item_replacement(select, select),
3220 m_target(target),
3221 m_item(item),
3222 m_default_value(default_value) {}
3223 };
3224
3226 Item_func *m_target; ///< The function call to be replaced
3227 Item_field *m_item; ///< The replacement field
3229 Query_block *select)
3230 : Item_replacement(select, select),
3231 m_target(func_target),
3232 m_item(item) {}
3233 };
3234
3236 Item *m_target; ///< The item identifying the view_ref to be replaced
3237 Field *m_field; ///< The replacement field
3238 ///< subquery. Pushed when diving into
3239 ///< subqueries.
3241 : Item_replacement(select, select), m_target(target), m_field(field) {}
3242 };
3243
3248 : m_target(target), m_replacement(replacement) {}
3249 };
3250
3251 /**
3252 When walking the item tree seeing an Item_singlerow_subselect matching
3253 a target, replace it with a substitute field used when transforming
3254 scalar subqueries into derived tables. Cf.
3255 Query_block::transform_scalar_subqueries_to_join_with_derived.
3256 */
3257 virtual Item *replace_scalar_subquery(uchar *) { return this; }
3258
3259 /**
3260 Transform processor used by Query_block::transform_grouped_to_derived
3261 to replace fields which used to be at the transformed query block
3262 with corresponding fields in the new derived table containing the grouping
3263 operation of the original transformed query block.
3264 */
3265 virtual Item *replace_item_field(uchar *) { return this; }
3266 virtual Item *replace_func_call(uchar *) { return this; }
3267 virtual Item *replace_item_view_ref(uchar *) { return this; }
3268 virtual Item *replace_aggregate(uchar *) { return this; }
3269 virtual Item *replace_outer_ref(uchar *) { return this; }
3270
3275 : m_target(target), m_owner(owner) {}
3276 };
3277
3278 /**
3279 A walker processor overridden by Item_aggregate_ref, q.v.
3280 */
3281 virtual bool update_aggr_refs(uchar *) { return false; }
3282
3283 /**
3284 Convert constant string in this object into the specified character set.
3285
3286 @param thd thread handler
3287 @param tocs target character set
3288 @param ignore_errors if true, ignore errors in conversion
3289
3290 @returns pointer to new Item containing converted character string
3291 = NULL: If conversion failed
3292 */
3293 Item *convert_charset(THD *thd, const CHARSET_INFO *tocs,
3294 bool ignore_errors = false);
3295
3296 /**
3297 Delete this item.
3298 Note that item must have been cleanup up by calling Item::cleanup().
3299 */
3300 void delete_self() { delete this; }
3301
3302 /** @return whether the item is local to a stored procedure */
3303 virtual bool is_splocal() const { return false; }
3304
3305 /*
3306 Return Settable_routine_parameter interface of the Item. Return 0
3307 if this Item is not Settable_routine_parameter.
3308 */
3310 return nullptr;
3311 }
3312 inline bool is_temporal_with_date() const {
3314 }
3317 }
3318 inline bool is_temporal_with_time() const {
3320 }
3321 inline bool is_temporal() const {
3323 }
3324 /**
3325 Check whether this and the given item has compatible comparison context.
3326 Used by the equality propagation. See Item_field::equal_fields_propagator.
3327
3328 @return
3329 true if the context is the same or if fields could be
3330 compared as DATETIME values by the Arg_comparator.
3331 false otherwise.
3332 */
3333 inline bool has_compatible_context(Item *item) const {
3334 // If no explicit context has been set, assume the same type as the item
3335 const Item_result this_context =
3337 const Item_result other_context = item->cmp_context == INVALID_RESULT
3338 ? item->result_type()
3339 : item->cmp_context;
3340
3341 // Check if both items have the same context
3342 if (this_context == other_context) {
3343 return true;
3344 }
3345 /* DATETIME comparison context. */
3347 return item->is_temporal_with_date() || other_context == STRING_RESULT;
3348 if (item->is_temporal_with_date())
3349 return is_temporal_with_date() || this_context == STRING_RESULT;
3350 return false;
3351 }
3353 return Field::GEOM_GEOMETRY;
3354 }
3355 String *check_well_formed_result(String *str, bool send_error, bool truncate);
3356 bool eq_by_collation(Item *item, const CHARSET_INFO *cs);
3357
3359 m_cost.Compute(*this);
3360 return m_cost;
3361 }
3362
3363 /**
3364 @return maximum number of characters that this Item can store
3365 If Item is of string or blob type, return max string length in bytes
3366 divided by bytes per character, otherwise return max_length.
3367 @todo - check if collation for other types should have mbmaxlen = 1
3368 */
3370 /*
3371 Length of e.g. 5.5e5 in an expression such as GREATEST(5.5e5, '5') is 5
3372 (length of that string) although length of the actual value is 6.
3373 Return MAX_DOUBLE_STR_LENGTH to prevent truncation of data without having
3374 to evaluate the value of the item.
3375 */
3376 const uint32 max_len =
3378 if (result_type() == STRING_RESULT)
3379 return max_len / collation.collation->mbmaxlen;
3380 return max_len;
3381 }
3382
3384 if (cs == &my_charset_bin && result_type() == STRING_RESULT) {
3385 return max_length;
3386 }
3387 return max_char_length();
3388 }
3389
3390 inline void fix_char_length(uint32 max_char_length_arg) {
3391 max_length = char_to_byte_length_safe(max_char_length_arg,
3393 }
3394
3395 /*
3396 Return true if the item points to a column of an outer-joined table.
3397 */
3398 virtual bool is_outer_field() const {
3399 assert(fixed);
3400 return false;
3401 }
3402
3403 /**
3404 Check if an item either is a blob field, or will be represented as a BLOB
3405 field if a field is created based on this item.
3406
3407 @retval true If a field based on this item will be a BLOB field,
3408 @retval false Otherwise.
3409 */
3410 bool is_blob_field() const;
3411
3412 /// @returns number of references to an item.
3413 uint reference_count() const { return m_ref_count; }
3414
3415 /// Increment reference count
3417 assert(!m_abandoned);
3418 ++m_ref_count;
3419 }
3420
3421 /// Decrement reference count
3423 assert(m_ref_count > 0);
3424 if (--m_ref_count == 0) m_abandoned = true;
3425 return m_ref_count;
3426 }
3427
3428 protected:
3429 /// Set accumulated properties for an Item
3430 void set_accum_properties(const Item *item) {
3432 }
3433
3434 /// Add more accumulated properties to an Item
3435 void add_accum_properties(const Item *item) {
3437 }
3438
3439 /// Set the "has subquery" property
3441
3442 /// Set the "has stored program" property
3444
3445 public:
3446 /// @return true if this item or any of its descendants contains a subquery.
3448
3449 /// @return true if this item or any of its descendants refers a stored func.
3450 bool has_stored_program() const {
3452 }
3453
3454 /// @return true if this item or any of its descendants is an aggregated func.
3456
3457 /// Set the "has aggregation" property
3459
3460 /// Reset the "has aggregation" property
3461 void reset_aggregation() { m_accum_properties &= ~PROP_AGGREGATION; }
3462
3463 /// @return true if this item or any of its descendants is a window func.
3465
3466 /// Set the "has window function" property
3468
3469 /**
3470 @return true if this item or any of its descendants within the same query
3471 has a reference to a GROUP BY modifier (such as ROLLUP)
3472 */
3475 }
3476
3477 /**
3478 Set the property: this item (tree) contains a reference to a GROUP BY
3479 modifier (such as ROLLUP)
3480 */
3483 }
3484
3485 /**
3486 @return true if this item or any of underlying items is a GROUPING function
3487 */
3488 bool has_grouping_func() const {
3490 }
3491
3492 /// Set the property: this item is a call to GROUPING
3494
3495 /// Whether this Item was created by the IN->EXISTS subquery transformation
3496 virtual bool created_by_in2exists() const { return false; }
3497
3499 if (has_subquery())
3501 }
3502
3503 /**
3504 Analyzer function for GC substitution. @see substitute_gc()
3505 */
3506 virtual bool gc_subst_analyzer(uchar **) { return false; }
3507 /**
3508 Transformer function for GC substitution. @see substitute_gc()
3509 */
3510 virtual Item *gc_subst_transformer(uchar *) { return this; }
3511
3512 /**
3513 A processor that replaces any Fields with a Create_field_wrapper. This
3514 will allow us to resolve functions during CREATE TABLE, where we only have
3515 Create_field available and not Field. Used for functional index
3516 implementation.
3517 */
3518 virtual bool replace_field_processor(uchar *) { return false; }
3519 /**
3520 Check if this item is of a type that is eligible for GC
3521 substitution. All items that belong to subclasses of Item_func are
3522 eligible for substitution. @see substitute_gc()
3523 Item_fields can also be eligible if they are given as an argument to
3524 a function that takes an array (the field can be substituted with a
3525 generated column that backs a multi-valued index on that field).
3526
3527 @param array true if the item is an argument to a function that takes an
3528 array, or false otherwise
3529 @return true if the expression is eligible for substitution, false otherwise
3530 */
3531 bool can_be_substituted_for_gc(bool array = false) const;
3532
3534 uint nitems);
3535 void aggregate_decimal_properties(Item **items, uint nitems);
3537 uint nitems);
3539 Item **items, uint nitems);
3540 void aggregate_bit_properties(Item **items, uint nitems);
3541
3542 /**
3543 This function applies only to Item_field objects referred to by an Item_ref
3544 object that has been marked as a const_item.
3545
3546 @param arg Keep track of whether an Item_ref refers to an Item_field.
3547 */
3548 virtual bool repoint_const_outer_ref(uchar *arg [[maybe_unused]]) {
3549 return false;
3550 }
3551 virtual bool strip_db_table_name_processor(uchar *) { return false; }
3552
3553 /**
3554 Compute the cost of evaluating this Item.
3555 @param root_cost The cost object to which the cost should be added.
3556 */
3557 virtual void compute_cost(CostOfItem *root_cost [[maybe_unused]]) const {}
3558
3559 bool is_abandoned() const { return m_abandoned; }
3560
3561 private:
3562 virtual bool subq_opt_away_processor(uchar *) { return false; }
3563
3564 public: // Start of data fields
3565 /**
3566 Intrusive list pointer for free list. If not null, points to the next
3567 Item on some Query_arena's free list. For instance, stored procedures
3568 have their own Query_arena's.
3569
3570 @see Query_arena::free_list
3571 */
3572 Item *next_free{nullptr};
3573
3574 protected:
3575 /// str_values's main purpose is to cache the value in save_in_field
3577
3578 public:
3579 /**
3580 Character set and collation properties assigned for this Item.
3581 Used if Item represents a character string expression.
3582 */
3584 Item_name_string item_name; ///< Name from query
3585 Item_name_string orig_name; ///< Original item name (if it was renamed)
3586 /**
3587 Maximum length of result of evaluating this item, in number of bytes.
3588 - For character or blob data types, max char length multiplied by max
3589 character size (collation.mbmaxlen).
3590 - For decimal type, it is the precision in digits plus sign (unless
3591 unsigned) plus decimal point (unless it has zero decimals).
3592 - For other numeric types, the default or specific display length.
3593 - For date/time types, the display length (10 for DATE, 10 + optional FSP
3594 for TIME, 19 + optional fsp for datetime/timestamp).
3595 - For bit, the number of bits.
3596 - For enum, the string length of the widest enum element.
3597 - For set, the sum of the string length of each set element plus separators.
3598 - For geometry, the maximum size of a BLOB (it's underlying storage type).
3599 - For json, the maximum size of a BLOB (it's underlying storage type).
3600 */
3601 uint32 max_length; ///< Maximum length, in bytes
3602 enum item_marker ///< Values for member 'marker'
3603 {
3605 /// When contextualization or itemization adds an implicit comparison '0<>'
3606 /// (see make_condition()), to record that this Item_func_ne was created for
3607 /// this purpose; this value is tested during resolution.
3609 /// When doing constant propagation (e.g. change_cond_ref_to_const(), to
3610 /// remember that we have already processed the item.
3612 /// When creating an internal temporary table: marking group by
3613 /// fields
3615 /// When analyzing functional dependencies for only_full_group_by (says
3616 /// whether a nullable column can be treated at not nullable).
3618 /// When we change DISTINCT to GROUP BY: used for book-keeping of
3619 /// fields.
3621 /// When pushing conditions down to derived table: it says a condition
3622 /// contains only derived table's columns.
3624 /// Used during traversal to avoid deleting an item twice.
3626 /// When pushing index conditions: it says whether a condition uses only
3627 /// indexed columns.
3630 /**
3631 This member has several successive meanings, depending on the phase we're
3632 in (@see item_marker).
3633 The important property is that a phase must have a value (or few values)
3634 which is reserved for this phase. If it wants to set "marked", it assigns
3635 the value; it it wants to test if it is marked, it tests marker !=
3636 value. If the value has been assigned and the phase wants to cancel it can
3637 set marker to MARKER_NONE, which is a magic number which no phase
3638 reserves.
3639 A phase can expect 'marker' to be MARKER_NONE at the start of execution of
3640 a normal statement, at the start of preparation of a PS, and at the start
3641 of execution of a PS.
3642 A phase should not expect marker's value to survive after the phase's
3643 end - as a following phase may change it.
3644 */
3646 Item_result cmp_context; ///< Comparison context
3647 private:
3648 /**
3649 Number of references to this item. It is used for two purposes:
3650 1. When eliminating redundant expressions, the reference count is used
3651 to tell how many Item_ref objects that point to an item. When a
3652 sub-tree of items is eliminated, it is traversed and any item that
3653 is referenced from an Item_ref has its reference count decremented.
3654 Only when the reference count reaches zero is the item actually deleted.
3655 2. Keeping track of unused expressions selected from merged derived tables.
3656 An item that is added to the select list of a query block has its
3657 reference count set to 1. Any references from outer query blocks are
3658 through Item_ref objects, thus they will cause the reference count
3659 to be incremented. At end of resolving, the reference counts of all
3660 items in select list of merged derived tables are decremented, thus
3661 if the reference count becomes zero, the expression is known to
3662 be unused and can be removed.
3663 */
3665 bool m_abandoned{false}; ///< true if item has been fully de-referenced
3666 const bool is_parser_item; ///< true if allocated directly by parser
3667 uint8 m_data_type; ///< Data type assigned to Item
3668
3669 /**
3670 The cost of evaluating this item. This is only needed for predicates,
3671 therefore we use lazy evaluation.
3672 */
3674
3675 public:
3676 bool fixed; ///< True if item has been resolved
3677 /**
3678 Number of decimals in result when evaluating this item
3679 - For integer type, always zero.
3680 - For decimal type, number of decimals.
3681 - For float type, it may be DECIMAL_NOT_SPECIFIED
3682 - For time, datetime and timestamp, number of decimals in fractional second
3683 - For string types, may be decimals of cast source or DECIMAL_NOT_SPECIFIED
3684 */
3686
3687 bool is_nullable() const { return m_nullable; }
3688 void set_nullable(bool nullable) { m_nullable = nullable; }
3689
3690 private:
3691 /**
3692 True if this item may hold the NULL value(if null_value may be set to true).
3693
3694 For items that represent rows, it is true if one of the columns
3695 may be null.
3696
3697 For items that represent scalar or row subqueries, it is true if
3698 one of the returned columns could be null, or if the subquery
3699 could return zero rows.
3700
3701 It is worth noting that this information is correct only until
3702 equality propagation has been run by the optimization phase.
3703 Indeed, consider:
3704 select * from t1, t2,t3 where t1.pk=t2.a and t1.pk+1...
3705 the '+' is not nullable as t1.pk is not nullable;
3706 but if the optimizer chooses plan is t2-t3-t1, then, due to equality
3707 propagation it will replace t1.pk in '+' with t2.a (as t2 is before t1
3708 in plan), making the '+' capable of returning NULL when t2.a is NULL.
3709 */
3711
3712 public:
3713 bool null_value; ///< True if item is null
3715 bool m_is_window_function; ///< True if item represents window func
3716 /**
3717 If the item is in a SELECT list (Query_block::fields) and hidden is true,
3718 the item wasn't actually in the list as given by the user (it was added
3719 by the optimizer, to e.g. make sure it was part of a given
3720 materialization), and should not be returned in the actual result.
3721
3722 If the item is not in a SELECT list, the value is irrelevant.
3723 */
3724 bool hidden{false};
3725 /**
3726 True if item is a top most element in the expression being
3727 evaluated for a check constraint.
3728 */
3730
3731 protected:
3732 /**
3733 Set of properties that are calculated by accumulation from underlying items.
3734 Computed by constructors and fix_fields() and updated by
3735 update_used_tables(). The properties are accumulated up to the root of the
3736 current item tree, except they are not accumulated across subqueries and
3737 functions.
3738 */
3739 static constexpr uint8 PROP_SUBQUERY = 0x01;
3740 static constexpr uint8 PROP_STORED_PROGRAM = 0x02;
3741 static constexpr uint8 PROP_AGGREGATION = 0x04;
3742 static constexpr uint8 PROP_WINDOW_FUNCTION = 0x08;
3743 /**
3744 Set if the item or one or more of the underlying items contains a
3745 GROUP BY modifier (such as ROLLUP).
3746 */
3747 static constexpr uint8 PROP_HAS_GROUPING_SET_DEP = 0x10;
3748 /**
3749 Set if the item or one or more of the underlying items is a GROUPING
3750 function.
3751 */
3752 static constexpr uint8 PROP_GROUPING_FUNC = 0x20;
3753
3755
3756 public:
3757 /**
3758 Check if this expression can be used for partial update of a given
3759 JSON column.
3760
3761 For example, the expression `JSON_REPLACE(col, '$.foo', 'bar')`
3762 can be used to partially update the column `col`.
3763
3764 @param field the JSON column that is being updated
3765 @return true if this expression can be used for partial update,
3766 false otherwise
3767 */
3768 virtual bool supports_partial_update(const Field_json *field
3769 [[maybe_unused]]) const {
3770 return false;
3771 }
3772
3773 /**
3774 Whether the item returns array of its data type
3775 */
3776 virtual bool returns_array() const { return false; }
3777
3778 /**
3779 A helper function to ensure proper usage of CAST(.. AS .. ARRAY)
3780 */
3781 virtual void allow_array_cast() {}
3782};
3783
3784/**
3785 Descriptor of what and how to cache for
3786 Item::cache_const_expr_transformer/analyzer.
3787
3788*/
3789
3791 /// Path from the expression's top to the current item in item tree
3792 /// used to track parent of current item for caching JSON data
3794 /// Item to cache. Used as a binary flag, but kept as Item* for assertion
3795 Item *cache_item{nullptr};
3796 /// How to cache JSON data. @see Item::enum_const_item_cache
3798};
3799
3800/**
3801 A helper class to give in a functor to Item::walk(). Use as e.g.:
3802
3803 bool result = WalkItem(root_item, enum_walk::POSTFIX, [](Item *item) { ... });
3804
3805 TODO: Make Item::walk() just take in a functor in the first place, instead of
3806 a pointer-to-member and an opaque argument.
3807 */
3808template <class T>
3809inline bool WalkItem(Item *item, enum_walk walk, T &&functor) {
3810 return item->walk(&Item::walk_helper_thunk<T>, walk,
3811 reinterpret_cast<uchar *>(&functor));
3812}
3813
3814/**
3815 Overload for const 'item' and functor taking 'const Item*' argument.
3816*/
3817template <class T>
3818inline bool WalkItem(const Item *item, enum_walk walk, T &&functor) {
3819 auto to_const = [&](const Item *descendant) { return functor(descendant); };
3820 return WalkItem(const_cast<Item *>(item), walk, to_const);
3821}
3822
3823/**
3824 Same as WalkItem, but for Item::compile(). Use as e.g.:
3825
3826 Item *item = CompileItem(root_item,
3827 [](Item *item) { return true; }, // Analyzer.
3828 [](Item *item) { return item; }); // Transformer.
3829 */
3830template <class T, class U>
3831inline Item *CompileItem(Item *item, T &&analyzer, U &&transformer) {
3832 uchar *analyzer_ptr = reinterpret_cast<uchar *>(&analyzer);
3833 return item->compile(&Item::analyze_helper_thunk<T>, &analyzer_ptr,
3834 &Item::walk_helper_thunk<U>,
3835 reinterpret_cast<uchar *>(&transformer));
3836}
3837
3838/**
3839 Same as WalkItem, but for Item::transform(). Use as e.g.:
3840
3841 Item *item = TransformItem(root_item, [](Item *item) { return item; });
3842 */
3843template <class T>
3844Item *TransformItem(Item *item, T &&transformer) {
3845 return item->transform(&Item::walk_helper_thunk<T>,
3846 pointer_cast<uchar *>(&transformer));
3847}
3848
3851
3852 public:
3854 explicit Item_basic_constant(const POS &pos) : Item(pos), used_table_map(0) {}
3855
3856 /// @todo add implementation of basic_const_item
3857 /// and remove from subclasses as appropriate.
3858
3860 table_map used_tables() const override { return used_table_map; }
3861 bool check_function_as_value_generator(uchar *) override { return false; }
3862 /* to prevent drop fixed flag (no need parent cleanup call) */
3863 void cleanup() override {
3864 // @todo We should ensure we never change "basic constant" nodes.
3865 // We should then be able to add this assert:
3866 // assert(marker == MARKER_NONE);
3867 // and remove the call to Item::cleanup()
3868 Item::cleanup();
3869 }
3870 bool basic_const_item() const override { return true; }
3871 /**
3872 Note that str_value.ptr() will now point to a string owned by some
3873 other object.
3874 */
3876 str_value.set(str->ptr(), str->length(), str->charset());
3877 }
3878};
3879
3880/*****************************************************************************
3881 The class is a base class for representation of stored routine variables in
3882 the Item-hierarchy. There are the following kinds of SP-vars:
3883 - local variables (Item_splocal);
3884 - CASE expression (Item_case_expr);
3885*****************************************************************************/
3886
3887class Item_sp_variable : public Item {
3888 public:
3890
3891 public:
3892#ifndef NDEBUG
3893 /*
3894 Routine to which this Item_splocal belongs. Used for checking if correct
3895 runtime context is used for variable handling.
3896 */
3897 sp_head *m_sp{nullptr};
3898#endif
3899
3900 public:
3901 Item_sp_variable(const Name_string sp_var_name);
3902
3903 table_map used_tables() const override { return INNER_TABLE_BIT; }
3904 bool fix_fields(THD *thd, Item **) override;
3905
3906 double val_real() override;
3907 longlong val_int() override;
3908 String *val_str(String *sp) override;
3909 my_decimal *val_decimal(my_decimal *decimal_value) override;
3910 bool val_json(Json_wrapper *result) override;
3911 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
3912 bool get_time(MYSQL_TIME *ltime) override;
3913 bool is_null() override;
3914
3915 public:
3916 inline void make_field(Send_field *field) override;
3917 bool send(Protocol *protocol, String *str) override {
3918 // Need to override send() in case this_item() is an Item_field with a
3919 // ZEROFILL attribute.
3920 return this_item()->send(protocol, str);
3921 }
3922 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
3923 // It is ok to push down a condition like "column > SP_variable"
3924 return false;
3925 }
3926
3927 protected:
3929 Field *field, bool no_conversions) override;
3930};
3931
3932/*****************************************************************************
3933 Item_sp_variable inline implementation.
3934*****************************************************************************/
3935
3937 Item *it = this_item();
3939 it->make_field(field);
3940}
3941
3943 Field *field, bool no_conversions) {
3944 return this_item()->save_in_field(field, no_conversions);
3945}
3946
3947/*****************************************************************************
3948 A reference to local SP variable (incl. reference to SP parameter), used in
3949 runtime.
3950*****************************************************************************/
3951
3952class Item_splocal final : public Item_sp_variable,
3955
3956 public:
3957 /*
3958 If this variable is a parameter in LIMIT clause.
3959 Used only during NAME_CONST substitution, to not append
3960 NAME_CONST to the resulting query and thus not break
3961 the slave.
3962 */
3964 /*
3965 Position of this reference to SP variable in the statement (the
3966 statement itself is in sp_instr_stmt::m_query).
3967 This is valid only for references to SP variables in statements,
3968 excluding DECLARE CURSOR statement. It is used to replace references to SP
3969 variables with NAME_CONST calls when putting statements into the binary
3970 log.
3971 Value of 0 means that this object doesn't corresponding to reference to
3972 SP variable in query text.
3973 */
3975 /*
3976 Byte length of SP variable name in the statement (see pos_in_query).
3977 The value of this field may differ from the name_length value because
3978 name_length contains byte length of UTF8-encoded item name, but
3979 the query string (see sp_instr_stmt::m_query) is currently stored with
3980 a charset from the SET NAMES statement.
3981 */
3983
3984 Item_splocal(const Name_string sp_var_name, uint sp_var_idx,
3985 enum_field_types sp_var_type, uint pos_in_q = 0,
3986 uint len_in_q = 0);
3987
3988 bool is_splocal() const override { return true; }
3989
3990 Item *this_item() override;
3991 const Item *this_item() const override;
3992 Item **this_item_addr(THD *thd, Item **) override;
3993
3994 void print(const THD *thd, String *str,
3995 enum_query_type query_type) const override;
3996
3997 public:
3998 uint get_var_idx() const { return m_var_idx; }
3999
4000 Type type() const override { return ROUTINE_FIELD_ITEM; }
4001 Item_result result_type() const override {
4002 return type_to_result(data_type());
4003 }
4004 bool val_json(Json_wrapper *result) override;
4005
4006 private:
4007 bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override;
4008
4009 public:
4011 return this;
4012 }
4013};
4014
4015/*****************************************************************************
4016 A reference to case expression in SP, used in runtime.
4017*****************************************************************************/
4018
4019class Item_case_expr final : public Item_sp_variable {
4020 public:
4021 Item_case_expr(uint case_expr_id);
4022
4023 public:
4024 Item *this_item() override;
4025 const Item *this_item() const override;
4026 Item **this_item_addr(THD *thd, Item **) override;
4027
4028 Type type() const override { return this_item()->type(); }
4029 Item_result result_type() const override {
4030 return this_item()->result_type();
4031 }
4032 /*
4033 NOTE: print() is intended to be used from views and for debug.
4034 Item_case_expr can not occur in views, so here it is only for debug
4035 purposes.
4036 */
4037 void print(const THD *thd, String *str,
4038 enum_query_type query_type) const override;
4039
4040 private:
4042};
4043
4044/*
4045 NAME_CONST(given_name, const_value).
4046 This 'function' has all properties of the supplied const_value (which is
4047 assumed to be a literal constant), and the name given_name.
4048
4049 This is used to replace references to SP variables when we write PROCEDURE
4050 statements into the binary log.
4051
4052 TODO
4053 Together with Item_splocal and Item::this_item() we can actually extract
4054 common a base of this class and Item_splocal. Maybe it is possible to
4055 extract a common base with class Item_ref, too.
4056*/
4057
4058class Item_name_const final : public Item {
4059 typedef Item super;
4060
4064
4065 public:
4066 Item_name_const(const POS &pos, Item *name_arg, Item *val);
4067
4068 bool do_itemize(Parse_context *pc, Item **res) override;
4069 bool fix_fields(THD *, Item **) override;
4070
4071 enum Type type() const override { return NAME_CONST_ITEM; }
4072 double val_real() override;
4073 longlong val_int() override;
4074 String *val_str(String *sp) override;
4075 my_decimal *val_decimal(my_decimal *) override;
4076 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
4077 bool get_time(MYSQL_TIME *ltime) override;
4078 bool is_null() override;
4079 void print(const THD *thd, String *str,
4080 enum_query_type query_type) const override;
4081
4082 Item_result result_type() const override { return value_item->result_type(); }
4083
4085 // Item_name_const always wraps a literal, so there is no need to cache it.
4086 return false;
4087 }
4088
4089 protected:
4091 bool no_conversions) override {
4092 return value_item->save_in_field(field, no_conversions);
4093 }
4094};
4095
4096bool convert_const_strings(DTCollation &coll, Item **args, uint nargs);
4098 Item **items, uint nitems);
4099bool agg_item_charsets(DTCollation &c, const char *name, Item **items,
4100 uint nitems, uint flags);
4102 const char *name, Item **items,
4103 uint nitems) {
4106 return agg_item_charsets(c, name, items, nitems, flags);
4107}
4109 Item **items, uint nitems) {
4111 return agg_item_charsets(c, name, items, nitems, flags);
4112}
4113
4116
4117 public:
4119 explicit Item_num(const POS &pos) : super(pos) { collation.set_numeric(); }
4120
4121 virtual Item_num *neg() = 0;
4122 bool check_partition_func_processor(uchar *) override { return false; }
4123};
4124
4125inline constexpr uint16 NO_FIELD_INDEX((uint16)(-1));
4126
4127class Item_ident : public Item {
4128 typedef Item super;
4129
4130 protected:
4131 /**
4132 The fields m_orig_db_name, m_orig_table_name and m_orig_field_name are
4133 maintained so that we can provide information about the origin of a
4134 column that may have been renamed within the query, e.g. as required by
4135 connectors.
4136
4137 Names the original schema of the table that is the source of the field.
4138 If field is from
4139 - a non-aliased base table, the same as db_name.
4140 - an aliased base table, the name of the schema of the base table.
4141 - an expression (including aggregation), a NULL pointer.
4142 - a derived table, the name of the schema of the underlying base table.
4143 - a view, the name of the schema of the underlying base table.
4144 - a temporary table (in optimization stage), the name of the schema of
4145 the source base table.
4146 */
4147 const char *m_orig_db_name;
4148 /**
4149 Names the original table that is the source of the field. If field is from
4150 - a non-aliased base table, the same as table_name.
4151 - an aliased base table, the name of the base table.
4152 - an expression (including aggregation), a NULL pointer.
4153 - a derived table, the name of the underlying base table.
4154 - a view, the name of the underlying base table.
4155 - a temporary table (in optimization stage), the name of the source base tbl
4156 */
4158 /**
4159 Names the field in the source base table. If field is from
4160 - an expression, a NULL pointer.
4161 - a view or base table and is not aliased, the same as field_name.
4162 - a view or base table and is aliased, the column name of the view or
4163 base table.
4164 - a derived table, the column name of the underlying base table.
4165 - a temporary table (in optimization stage), the name of the source column.
4166 */
4168 bool m_alias_of_expr; ///< if this Item's name is alias of SELECT expression
4169
4170 public:
4171 /**
4172 For regularly resolved column references, 'context' points to a name
4173 resolution context object belonging to the query block which simply
4174 contains the reference. To further clarify, in
4175 SELECT (SELECT t.a) FROM t;
4176 t.a is an Item_ident whose 'context' belongs to the subquery
4177 (context->query_block == that of the subquery).
4178 For column references that are part of a generated column expression,
4179 'context' points to a temporary name resolution context object during
4180 resolving, but is set to nullptr after resolving is done. Note that
4181 Item_ident::local_column() depends on that.
4182 */
4184 /**
4185 Schema name of the base table or view the column is part of.
4186 If an expression, a NULL pointer.
4187 If from a derived table, a NULL pointer.
4188 */
4189 const char *db_name;
4190 /**
4191 If column is from a non-aliased base table or view, name of base table or
4192 view.
4193 If column is from an aliased base table or view, the alias name.
4194 If column is from a derived table, the name of the derived table.
4195 If column is from an expression, a NULL pointer.
4196 */
4197 const char *table_name;
4198 /**
4199 If column is aliased, the column alias name.
4200 If column is from a non-aliased base table or view, the name of the
4201 column in that base table or view.
4202 If column is from an expression, a string generated from that expression.
4203
4204 Notice that a column can be aliased in two ways:
4205 1. With an explicit column alias, or @<as clause@>, or
4206 2. With only a column name specified, which differs from the table's
4207 column name due to case insensitivity.
4208 In both cases field_name will differ from m_orig_field_name.
4209 field_name is normally identical to Item::item_name.
4210 */
4211 const char *field_name;
4212 /**
4213 Points to the Table_ref object of the table or view that the column or
4214 reference is resolved against (only valid after resolving).
4215 Notice that for the following types of "tables", no Table_ref object is
4216 assigned and hence m_table_ref is NULL:
4217 - Temporary tables assigned by join optimizer for sorting and aggregation.
4218 - Stored procedure dummy tables.
4219 For fields referencing such tables, table number is always 0, and other
4220 uses of m_table_ref is not needed.
4221 */
4223 /**
4224 For a column or reference that is an outer reference, depended_from points
4225 to the qualifying query block, otherwise it is NULL
4226 (only valid after resolving).
4227 */
4229
4230 Item_ident(Name_resolution_context *context_arg, const char *db_name_arg,
4231 const char *table_name_arg, const char *field_name_arg)
4232 : m_orig_db_name(db_name_arg),
4233 m_orig_table_name(table_name_arg),
4234 m_orig_field_name(field_name_arg),
4235 m_alias_of_expr(false),
4236 context(context_arg),
4237 db_name(db_name_arg),
4238 table_name(table_name_arg),
4239 field_name(field_name_arg) {
4240 item_name.set(field_name_arg);
4241 }
4242
4243 Item_ident(const POS &pos, const char *db_name_arg,
4244 const char *table_name_arg, const char *field_name_arg)
4245 : super(pos),
4246 m_orig_db_name(db_name_arg),
4247 m_orig_table_name(table_name_arg),
4248 m_orig_field_name(field_name_arg),
4249 m_alias_of_expr(false),
4250 db_name(db_name_arg),
4251 table_name(table_name_arg),
4252 field_name(field_name_arg) {
4253 item_name.set(field_name_arg);
4254 }
4255
4256 /// Constructor used by Item_field & Item_*_ref (see Item comment)
4257
4259 : Item(thd, item),
4264 context(item->context),
4265 db_name(item->db_name),
4266 table_name(item->table_name),
4267 field_name(item->field_name),
4268 m_table_ref(item->m_table_ref),
4270
4271 bool do_itemize(Parse_context *pc, Item **res) override;
4272
4273 const char *full_name() const override;
4274 void set_orignal_db_name(const char *name_arg) { m_orig_db_name = name_arg; }
4275 void set_original_table_name(const char *name_arg) {
4276 m_orig_table_name = name_arg;
4277 }
4278 void set_original_field_name(const char *name_arg) {
4279 m_orig_field_name = name_arg;
4280 }
4281 const char *original_db_name() const { return m_orig_db_name; }
4282 const char *original_table_name() const { return m_orig_table_name; }
4283 const char *original_field_name() const { return m_orig_field_name; }
4284 void fix_after_pullout(Query_block *parent_query_block,
4285 Query_block *removed_query_block) override;
4286 bool aggregate_check_distinct(uchar *arg) override;
4287 bool aggregate_check_group(uchar *arg) override;
4288 Bool3 local_column(const Query_block *sl) const override;
4289
4290 void print(const THD *thd, String *str,
4291 enum_query_type query_type) const override {
4292 print(thd, str, query_type, db_name, table_name);
4293 }
4294
4295 protected:
4296 /**
4297 Function to print column name for a table
4298
4299 To print a column for a permanent table (picks up database and table from
4300 Item_ident object):
4301
4302 item->print(str, qt)
4303
4304 To print a column for a temporary table:
4305
4306 item->print(str, qt, specific_db, specific_table)
4307
4308 Items of temporary table fields have empty/NULL values of table_name and
4309 db_name. To print column names in a 3D form (`database`.`table`.`column`),
4310 this function prints db_name_arg and table_name_arg parameters instead of
4311 this->db_name and this->table_name respectively.
4312
4313 @param thd Thread handle.
4314 @param [out] str Output string buffer.
4315 @param query_type Bitmap to control printing details.
4316 @param db_name_arg String to output as a column database name.
4317 @param table_name_arg String to output as a column table name.
4318 */
4319 void print(const THD *thd, String *str, enum_query_type query_type,
4320 const char *db_name_arg, const char *table_name_arg) const;
4321
4322 public:
4323 ///< Argument object to change_context_processor
4327 };
4328 bool change_context_processor(uchar *arg) override {
4329 context = reinterpret_cast<Change_context *>(arg)->m_context;
4330 return false;
4331 }
4332
4333 /// @returns true if this Item's name is alias of SELECT expression
4334 bool is_alias_of_expr() const { return m_alias_of_expr; }
4335 /// Marks that this Item's name is alias of SELECT expression
4337
4338 /**
4339 Argument structure for walk processor Item::update_depended_from
4340 */
4342 Query_block *old_depended_from; // the transformed query block
4343 Query_block *new_depended_from; // the new derived table for grouping
4344 };
4345
4346 bool update_depended_from(uchar *) override;
4347
4348 /**
4349 @returns true if a part of this Item's full name (name or table name) is
4350 an alias.
4351 */
4352 virtual bool alias_name_used() const { return m_alias_of_expr; }
4354 const char *db_name, const char *table_name,
4356 bool any_privileges);
4357 bool is_strong_side_column_not_in_fd(uchar *arg) override;
4358 bool is_column_not_in_fd(uchar *arg) override;
4359};
4360
4361class Item_ident_for_show final : public Item {
4362 public:
4364 const char *db_name;
4365 const char *table_name;
4366
4367 Item_ident_for_show(Field *par_field, const char *db_arg,
4368 const char *table_name_arg)
4369 : field(par_field), db_name(db_arg), table_name(table_name_arg) {}
4370
4371 enum Type type() const override { return FIELD_ITEM; }
4372 bool fix_fields(THD *thd, Item **ref) override;
4373 double val_real() override { return field->val_real(); }
4374 longlong val_int() override { return field->val_int(); }
4375 String *val_str(String *str) override { return field->val_str(str); }
4377 return field->val_decimal(dec);
4378 }
4379 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
4380 return field->get_date(ltime, fuzzydate);
4381 }
4382 bool get_time(MYSQL_TIME *ltime) override { return field->get_time(ltime); }
4383 void make_field(Send_field *tmp_field) override;
4385 return field->charset_for_protocol();
4386 }
4387};
4388
4389class Item_field : public Item_ident {
4391
4392 protected:
4393 void set_field(Field *field);
4394 void fix_after_pullout(Query_block *parent_query_block,
4395 Query_block *removed_query_block) override {
4396 super::fix_after_pullout(parent_query_block, removed_query_block);
4397
4398 // Update nullability information, as the table may have taken over
4399 // null_row status from the derived table it was part of.
4401 field->table->is_nullable());
4402 }
4404 bool no_conversions) override;
4405
4406 public:
4407 /// Source field
4408 Field *field{nullptr};
4409
4410 private:
4411 /// Result field
4413
4414 // save_in_field() and save_org_in_field() are often called repeatedly
4415 // with the same destination field (although the destination for the
4416 // two are distinct, thus two distinct caches). We detect this case by
4417 // storing the last destination, and whether it was of a compatible type
4418 // that we can memcpy into (see fields_are_memcpyable()). This saves time
4419 // doing the same type checking over and over again.
4420 //
4421 // The _memcpyable fields are uint32_t(-1) if the fields are not memcpyable,
4422 // and pack_length() (ie., the amount of bytes to copy) if they are.
4423 // See field_conv_with_cache(), where this logic is encapsulated.
4428
4429 /**
4430 If this field is derived from another field, e.g. it is reading a column
4431 from a temporary table which is populated from a base table, this member
4432 points to the field used to populate the temporary table column.
4433 */
4435
4436 /**
4437 State used for transforming scalar subqueries to JOINs with derived tables,
4438 cf. \c transform_grouped_to_derived. Has accessor.
4439 */
4441
4442 /**
4443 Holds a list of items whose values must be equal to the value of
4444 this field, during execution.
4445
4446 Used during optimization to perform multiple equality analysis,
4447 this analysis should be performed during preparation instead, so that
4448 Item_field can be const after preparation.
4449 */
4451
4452 public:
4453 /**
4454 Index for this field in table->field array. Holds NO_FIELD_INDEX
4455 if index value is not known.
4456 */
4459
4461 assert(item_equal != nullptr);
4462 item_equal_all_join_nests = item_equal;
4463 }
4464
4465 // A list of fields that are considered "equal" to this field. E.g., a query
4466 // on the form "a JOIN b ON a.i = b.i JOIN c ON b.i = c.i" would consider
4467 // a.i, b.i and c.i equal due to equality propagation. This is the same as
4468 // "item_equal" above, except that "item_equal" will only contain fields from
4469 // the same join nest. This is used by hash join and BKA when they need to
4470 // undo multi-equality propagation done by the optimizer. (The optimizer may
4471 // generate join conditions that references unreachable fields for said
4472 // iterators.) The split is done because NDB expects the list to only
4473 // contain fields from the same join nest.
4475 /// If true, the optimizer's constant propagation will not replace this item
4476 /// with an equal constant.
4478 /*
4479 if any_privileges set to true then here real effective privileges will
4480 be stored
4481 */
4483 /* field need any privileges (for VIEW creation) */
4484 bool any_privileges{false};
4485 /*
4486 if this field is used in a context where covering prefix keys
4487 are supported.
4488 */
4490 Item_field(Name_resolution_context *context_arg, const char *db_arg,
4491 const char *table_name_arg, const char *field_name_arg);
4492 Item_field(const POS &pos, const char *db_arg, const char *table_name_arg,
4493 const char *field_name_arg);
4494 Item_field(THD *thd, Item_field *item);
4495 Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
4497
4498 bool do_itemize(Parse_context *pc, Item **res) override;
4499
4500 enum Type type() const override { return FIELD_ITEM; }
4501 bool eq(const Item *item) const override;
4502 double val_real() override;
4503 longlong val_int() override;
4504 longlong val_time_temporal() override;
4505 longlong val_date_temporal() override;
4508 my_decimal *val_decimal(my_decimal *) override;
4509 String *val_str(String *) override;
4510 bool val_json(Json_wrapper *result) override;
4511 bool send(Protocol *protocol, String *str_arg) override;
4512 void reset_field(Field *f);
4513 bool fix_fields(THD *, Item **) override;
4514 void make_field(Send_field *tmp_field) override;
4515 void save_org_in_field(Field *field) override;
4516 table_map used_tables() const override;
4517 Item_result result_type() const override { return field->result_type(); }
4520 }
4521 TYPELIB *get_typelib() const override;
4523 return field->cast_to_int_type();
4524 }
4527 }
4528 longlong val_int_endpoint(bool left_endp, bool *incl_endp) override;
4529 void set_result_field(Field *field_arg) override { result_field = field_arg; }
4531 Field *tmp_table_field(TABLE *) override { return result_field; }
4534 item->base_item_field() != nullptr ? item->base_item_field() : item;
4535 }
4537 return m_base_item_field ? m_base_item_field : this;
4538 }
4539 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
4540 bool get_time(MYSQL_TIME *ltime) override;
4541 bool get_timeval(my_timeval *tm, int *warnings) override;
4542 bool is_null() override {
4543 // NOTE: May return true even if maybe_null is not set!
4544 // This can happen if the underlying TABLE did not have a NULL row
4545 // at set_field() time (ie., table->is_null_row() was false),
4546 // but does now.
4547 return field->is_null();
4548 }
4549 Item *get_tmp_table_item(THD *thd) override;
4550 bool collect_item_field_processor(uchar *arg) override;
4551 bool collect_item_field_or_ref_processor(uchar *arg) override;
4553 bool collect_outer_field_processor(uchar *arg) override;
4554 bool add_field_to_set_processor(uchar *arg) override;
4555 bool add_field_to_cond_set_processor(uchar *) override;
4556 bool remove_column_from_bitmap(uchar *arg) override;
4557 bool find_item_in_field_list_processor(uchar *arg) override;
4558 bool find_field_processor(uchar *arg) override {
4559 return pointer_cast<Field *>(arg) == field;
4560 }
4561 bool check_function_as_value_generator(uchar *args) override;
4562 bool mark_field_in_map(uchar *arg) override {
4563 auto mark_field = pointer_cast<Mark_field *>(arg);
4564 bool rc = Item::mark_field_in_map(mark_field, field);
4566 rc |= Item::mark_field_in_map(mark_field, result_field);
4567 return rc;
4568 }
4569 bool used_tables_for_level(uchar *arg) override;
4570 bool check_column_privileges(uchar *arg) override;
4571 bool check_partition_func_processor(uchar *) override { return false; }
4572 void bind_fields() override;
4573 bool is_valid_for_pushdown(uchar *arg) override;
4574 bool check_column_in_window_functions(uchar *arg) override;
4575 bool check_column_in_group_by(uchar *arg) override;
4576 Item *replace_with_derived_expr(uchar *arg) override;
4578 void cleanup() override;
4579 void reset_field();
4580 Item_multi_eq *find_multi_equality(COND_EQUAL *cond_equal) const;
4581 bool subst_argument_checker(uchar **arg) override;
4582 Item *equal_fields_propagator(uchar *arg) override;
4583 Item *replace_item_field(uchar *) override;
4586 return false;
4587 }
4588 Item *replace_equal_field(uchar *) override;
4590 Item_field *field_for_view_update() override { return this; }
4591 bool fix_outer_field(THD *thd, Field **field, Item_ident **ref_field,
4592 bool *complete);
4593 Item *update_value_transformer(uchar *select_arg) override;
4594 void print(const THD *thd, String *str,
4595 enum_query_type query_type) const override;
4596 bool is_outer_field() const override {
4597 assert(fixed);
4599 }
4601 assert(data_type() == MYSQL_TYPE_GEOMETRY);
4602 return field->get_geometry_type();
4603 }
4604 const CHARSET_INFO *charset_for_protocol(void) override {
4605 return field->charset_for_protocol();
4606 }
4607
4608#ifndef NDEBUG
4609 void dbug_print() const {
4610 fprintf(DBUG_FILE, "<field ");
4611 if (field) {
4612 fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
4613 field->dbug_print();
4614 } else
4615 fprintf(DBUG_FILE, "NULL");
4616
4617 fprintf(DBUG_FILE, ", result_field: ");
4618 if (result_field) {
4619 fprintf(DBUG_FILE, "'%s.%s': ", result_field->table->alias,
4622 } else
4623 fprintf(DBUG_FILE, "NULL");
4624 fprintf(DBUG_FILE, ">\n");
4625 }
4626#endif
4627
4628 float get_filtering_effect(THD *thd, table_map filter_for_table,
4629 table_map read_tables,
4630 const MY_BITMAP *fields_to_ignore,
4631 double rows_in_table) override;
4632
4633 /**
4634 Returns the probability for the predicate "col OP <val>" to be
4635 true for a row in the case where no index statistics or range
4636 estimates are available for 'col'.
4637
4638 The probability depends on the number of rows in the table: it is by
4639 default 'default_filter', but never lower than 1/max_distinct_values
4640 (e.g. number of rows in the table, or the number of distinct values
4641 possible for the datatype if the field provides that kind of
4642 information).
4643
4644 @param max_distinct_values The maximum number of distinct values,
4645 typically the number of rows in the table
4646 @param default_filter The default filter for the predicate
4647
4648 @return the estimated filtering effect for this predicate
4649 */
4650
4651 float get_cond_filter_default_probability(double max_distinct_values,
4652 float default_filter) const;
4653
4654 /**
4655 @note that field->table->alias_name_used is reliable only if
4656 thd->lex->need_correct_ident() is true.
4657 */
4658 bool alias_name_used() const override {
4659 return m_alias_of_expr ||
4660 // maybe the qualifying table was given an alias ("t1 AS foo"):
4662 }
4663
4664 bool repoint_const_outer_ref(uchar *arg) override;
4665 bool returns_array() const override { return field && field->is_array(); }
4666
4667 void set_can_use_prefix_key() override { can_use_prefix_key = true; }
4668
4669 bool replace_field_processor(uchar *arg) override;
4670 bool strip_db_table_name_processor(uchar *) override;
4671
4672 /**
4673 Checks if the current object represents an asterisk select list item
4674
4675 @returns false if a regular column reference, true if an asterisk
4676 select list item.
4677 */
4678 virtual bool is_asterisk() const { return false; }
4679 /// See \c m_protected_by_any_value
4681
4682 void compute_cost(CostOfItem *root_cost) const override {
4683 field->add_to_cost(root_cost);
4684 }
4685};
4686
4687/**
4688 Represents [schema.][table.]* in a select list
4689
4690 Item_asterisk is used to insert placeholder objects for the special
4691 select list item * (asterisk) into AST.
4692 Those placeholder objects are to be substituted later with e.g. a list of real
4693 table columns by a resolver (@see setup_wild).
4694
4695 @todo The parent class Item_field is redundant. Refactor setup_wild() to
4696 replace Item_field with a simpler one.
4697*/
4700
4701 public:
4702 /**
4703 Constructor
4704
4705 @param pos Location of the * (asterisk) lexeme.
4706 @param opt_schema_name Schema name or nullptr.
4707 @param opt_table_name Table name or nullptr.
4708 */
4709 Item_asterisk(const POS &pos, const char *opt_schema_name,
4710 const char *opt_table_name)
4711 : super(pos, opt_schema_name, opt_table_name, "*") {}
4712
4713 bool do_itemize(Parse_context *pc, Item **res) override;
4714 bool fix_fields(THD *, Item **) override {
4715 assert(false); // should never happen: see setup_wild()
4716 return true;
4717 }
4718 bool is_asterisk() const override { return true; }
4719};
4720
4721// See if the provided item points to a reachable field (one that belongs to a
4722// table within 'reachable_tables'). If not, go through the list of 'equal'
4723// items in the item and see if we have a field that is reachable. If any such
4724// field is found, set "found" to true and create a new Item_field that points
4725// to this reachable field and return it if we are asked to "replace". If the
4726// provided item is already reachable, or if we cannot find a reachable field,
4727// return the provided item unchanged and set "found" to false. This is used
4728// when creating a hash join iterator, where the join condition may point to a
4729// non-reachable field due to multi-equality propagation during optimization.
4730// (Ideally, the optimizer should not set up such condition in the first place.
4731// This is difficult, if not impossible, to accomplish, given that the plan
4732// created by the optimizer does not map 100% to the iterator executor.) Note
4733// that if the field is not reachable, and we cannot find a reachable field, we
4734// provided field is returned unchanged. The effect is that the hash join will
4735// degrade into a nested loop.
4736Item_field *FindEqualField(Item_field *item_field, table_map reachable_tables,
4737 bool replace, bool *found);
4738
4741
4742 void init() {
4744 null_value = true;
4745 fixed = true;
4746 }
4747
4748 protected:
4750 bool no_conversions) override;
4751
4752 public:
4754 init();
4755 item_name = NAME_STRING("NULL");
4756 }
4757 explicit Item_null(const POS &pos) : super(pos) {
4758 init();
4759 item_name = NAME_STRING("NULL");
4760 }
4761
4762 Item_null(const Name_string &name_par) {
4763 init();
4764 item_name = name_par;
4765 }
4766
4767 enum Type type() const override { return NULL_ITEM; }
4768 bool eq(const Item *item) const override;
4769 double val_real() override;
4770 longlong val_int() override;
4771 longlong val_time_temporal() override { return val_int(); }
4772 longlong val_date_temporal() override { return val_int(); }
4773 String *val_str(String *str) override;
4774 my_decimal *val_decimal(my_decimal *) override;
4775 bool get_date(MYSQL_TIME *, my_time_flags_t) override { return true; }
4776 bool get_time(MYSQL_TIME *) override { return true; }
4777 bool val_json(Json_wrapper *wr) override;
4778 bool send(Protocol *protocol, String *str) override;
4779 Item_result result_type() const override { return STRING_RESULT; }
4780 Item *clone_item() const override { return new Item_null(item_name); }
4781 bool is_null() override { return true; }
4782
4783 void print(const THD *, String *str,
4784 enum_query_type query_type) const override {
4785 str->append(query_type == QT_NORMALIZED_FORMAT ? "?" : "NULL");
4786 }
4787
4788 bool check_partition_func_processor(uchar *) override { return false; }
4789};
4790
4791/// Dynamic parameters used as placeholders ('?') inside prepared statements
4792
4793class Item_param final : public Item, private Settable_routine_parameter {
4794 typedef Item super;
4795
4796 protected:
4798 bool no_conversions) override;
4799
4800 public:
4807 TIME_VALUE, ///< holds TIME, DATE, DATETIME
4811
4813 m_param_state = state;
4814 }
4815
4817
4818 void mark_json_as_scalar() override { m_json_as_scalar = true; }
4819
4820 /*
4821 A buffer for string and long data values. Historically all allocated
4822 values returned from val_str() were treated as eligible to
4823 modification. I. e. in some cases Item_func_concat can append it's
4824 second argument to return value of the first one. Because of that we
4825 can't return the original buffer holding string data from val_str(),
4826 and have to have one buffer for data and another just pointing to
4827 the data. This is the latter one and it's returned from val_str().
4828 Can not be declared inside the union as it's not a POD type.
4829 */
4832 union {
4834 double real;
4837
4838 private:
4839 /**
4840 True if type of parameter is inherited from parent object (like a typecast).
4841 Reprepare of statement will not change this type.
4842 E.g, we have CAST(? AS DOUBLE), the parameter gets data type
4843 MYSQL_TYPE_DOUBLE and m_type_inherited is set true.
4844 */
4845 bool m_type_inherited{false};
4846 /**
4847 True if type of parameter has been pinned, attempt to use an incompatible
4848 actual type will cause error (no repreparation occurs), and value is
4849 subject to range check. This is used when the parameter is in a context
4850 where its type is imposed. For example, in LIMIT ?, we assign
4851 data_type() == integer, unsigned; and the provided value must be
4852 convertible to unsigned integer: passing a DOUBLE, instead of causing a
4853 repreparation as for an ordinary parameter, will cause an error; passing
4854 integer '-1' will also cause an error.
4855 */
4856 bool m_type_pinned{false};
4857 /**
4858 Parameter objects have a rather complex handling of data type, in order
4859 to consistently handle required type conversion semantics. There are
4860 three data type properties involved:
4861
4862 1. The data_type() property contains the desired type of the parameter
4863 value, as defined by an explicit CAST, the operation the parameter
4864 is part of, and/or the context given by other values and expressions.
4865 After implicit repreparation it may also be assigned from provided
4866 parameter values.
4867
4868 2. The data_type_source() property is the data type of the parameter value,
4869 as given by the supplied user variable or from the protocol buffer.
4870
4871 3. The data_type_actual() property is the data type of the parameter value,
4872 after possible conversion from the source data type.
4873 Conversions may involve
4874 - Character set conversion of string value.
4875 - Conversion from string or number into temporal value, if the
4876 resolved data type is a temporal.
4877 - Conversion from string to number, if the resolved data type is numeric.
4878
4879 In addition, each data type property may have extra attributes to enforce
4880 correct character set, collation and signedness of integers.
4881 */
4882 /**
4883 The "source" data type of the provided parameter.
4884 Used when the parameter comes through protocol buffers.
4885 Notice that signedness of integers is stored in m_unsigned_actual.
4886 */
4888 /**
4889 The actual data type of the parameter value provided by the user.
4890 For example:
4891
4892 PREPARE s FROM "SELECT ?=3e0";
4893
4894 makes Item_param->data_type() be MYSQL_TYPE_DOUBLE ; then:
4895
4896 SET @a='1';
4897 EXECUTE s USING @a;
4898
4899 data_type() is still MYSQL_TYPE_DOUBLE, while data_type_source() is
4900 MYSQL_TYPE_VARCHAR and data_type_actual() is MYSQL_TYPE_VARCHAR.
4901 Compatibility of data_type() and data_type_actual() is later tested
4902 in check_parameter_types().
4903 Only a limited set of field types are possible values:
4904 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_DOUBLE,
4905 MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
4906 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NULL, MYSQL_TYPE_INVALID
4907 */
4909 /// Used when actual value is integer to indicate whether value is unsigned
4911 /**
4912 The character set and collation of the source parameter value.
4913 Ignored if not a string value.
4914 - If parameter value is sent over the protocol: the client collation
4915 - If parameter value is a user variable: the variable's collation
4916 */
4918 /**
4919 The character set and collation of the value stored in str_value, possibly
4920 after being converted from the m_collation_source collation.
4921 Ignored if not a string value.
4922 - If the derived collation is binary, the connection collation.
4923 - Otherwise, the derived collation (@see Item::collation).
4924 */
4926 /// Result type of parameter. @todo replace with type_to_result(data_type()
4928 /**
4929 m_param_state is used to indicate that no parameter value is available
4930 with NO_VALUE, or a NULL value is available (NULL_VALUE), or the actual
4931 type of the provided parameter value. Usually, this matches m_actual_type,
4932 but in the case of pinned data types, this is matching the resolved data
4933 type of the parameter. m_param_state reflects the type of the value stored
4934 in Item_param::value.
4935 */
4937
4938 /**
4939 If true, when retrieving JSON data, attempt to interpret a string value as
4940 a scalar JSON value, otherwise interpret it as a JSON object.
4941 */
4942 bool m_json_as_scalar{false};
4943
4944 /*
4945 data_type() is used when this item is used in a temporary table.
4946 This is NOT placeholder metadata sent to client, as this value
4947 is assigned after sending metadata (in setup_one_conversion_function).
4948 For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
4949 in result set and placeholders metadata, no matter what type you will
4950 supply for this placeholder in mysql_stmt_execute.
4951 */
4952
4953 public:
4954 /*
4955 Offset of placeholder inside statement text. Used to create
4956 no-placeholders version of this statement for the binary log.
4957 */
4959
4960 Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg);
4961
4962 bool do_itemize(Parse_context *pc, Item **item) override;
4963
4964 Item_result result_type() const override { return m_result_type; }
4965 enum Type type() const override { return PARAM_ITEM; }
4966
4967 /// Set the currently resolved data type for this parameter as inherited
4968 void set_data_type_inherited() override { m_type_inherited = true; }
4969
4970 /// @returns true if data type for this parameter is inherited.
4971 bool is_type_inherited() const { return m_type_inherited; }
4972
4973 /// Pin the currently resolved data type for this parameter.
4974 void pin_data_type() override { m_type_pinned = true; }
4975
4976 /// @returns true if data type for this parameter is pinned.
4977 bool is_type_pinned() const { return m_type_pinned; }
4978
4979 /// @returns true if actual data value (integer) is unsigned
4980 bool is_unsigned_actual() const { return m_unsigned_actual; }
4981
4984 m_collation_source = coll;
4985 }
4988 m_collation_actual = coll;
4989 }
4990 /// @returns the source collation of the supplied string parameter
4992
4993 /// @returns the actual collation of the supplied string parameter
4996 return m_collation_actual;
4997 }
4998 bool fix_fields(THD *thd, Item **ref) override;
4999
5000 bool propagate_type(THD *thd, const Type_properties &type) override;
5001
5002 double val_real() override;
5003 longlong val_int() override;
5004 my_decimal *val_decimal(my_decimal *) override;
5005 String *val_str(String *) override;
5006 bool val_json(Json_wrapper *result) override;
5007 bool get_time(MYSQL_TIME *tm) override;
5008 bool get_date(MYSQL_TIME *tm, my_time_flags_t fuzzydate) override;
5009
5012 m_unsigned_actual = unsigned_val;
5013 }
5014 // For use with non-integer field types only
5017 }
5018 /// For use with all field types, especially integer types
5021 m_unsigned_actual = unsigned_val;
5022 }
5024
5026
5028 return data_type_actual();
5029 }
5030
5031 void set_null();
5032 void set_int(longlong i);
5033 void set_int(ulonglong i);
5034 void set_double(double i);
5035 void set_decimal(const char *str, ulong length);
5036 void set_decimal(const my_decimal *dv);
5037 bool set_str(const char *str, size_t length);
5038 bool set_longdata(const char *str, ulong length);
5040 bool set_from_user_var(THD *thd, const user_var_entry *entry);
5042 void reset();
5043
5044 const String *query_val_str(const THD *thd, String *str) const;
5045
5046 bool convert_value();
5047
5048 /*
5049 Parameter is treated as constant during execution, thus it will not be
5050 evaluated during preparation.
5051 */
5052 table_map used_tables() const override { return INNER_TABLE_BIT; }
5053 void print(const THD *thd, String *str,
5054 enum_query_type query_type) const override;
5055 bool is_null() override {
5056 assert(m_param_state != NO_VALUE);
5057 return m_param_state == NULL_VALUE;
5058 }
5059
5060 Item *clone_item() const override;
5061 /*
5062 Implement by-value equality evaluation if parameter value
5063 is set and is a basic constant (integer, real or string).
5064 Otherwise return false.
5065 */
5066 bool eq(const Item *item) const override;
5068 bool is_non_const_over_literals(uchar *) override { return true; }
5069 /**
5070 This should be called after any modification done to this Item, to
5071 propagate the said modification to all its clones.
5072 */
5073 void sync_clones();
5074 bool add_clone(Item_param *i) { return m_clones.push_back(i); }
5075
5076 private:
5078 return this;
5079 }
5080
5081 bool set_value(THD *, sp_rcontext *, Item **it) override;
5082
5083 void set_out_param_info(Send_field *info) override;
5084
5085 public:
5086 const Send_field *get_out_param_info() const override;
5087
5088 void make_field(Send_field *field) override;
5089
5092 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5093 func_arg->err_code = func_arg->get_unnamed_function_error_code();
5094 return true;
5095 }
5096 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
5097 // It is ok to push down a condition like "column > PS_parameter".
5098 return false;
5099 }
5100
5101 private:
5103 /**
5104 If a query expression's text QT or text of a condition (CT) that is pushed
5105 down to a derived table, containing a parameter, is internally duplicated
5106 and parsed twice (@see reparse_common_table_expression, parse_expression),
5107 the first parsing will create an Item_param I, and the re-parsing, which
5108 parses a forged "(QT)" parse-this-CTE type of statement or parses a
5109 forged condition "(CT)", will create an Item_param J. J should not exist:
5110 - from the point of view of logging: it is not in the original query so it
5111 should not be substituted in the query written to logs (in insert_params()
5112 if with_log is true).
5113 - from the POV of the user:
5114 * user provides one single value for I, not one for I and one for J.
5115 * user expects mysql_stmt_param_count() to return 1, not 2 (count is
5116 sent by the server in send_prep_stmt()).
5117 That is why J is part neither of LEX::param_list, nor of param_array; it
5118 is considered an inferior clone of I; I::m_clones contains J.
5119 The connection between I and J is made once, by comparing their
5120 byte position in the statement, in Item_param::itemize().
5121 J gets its value from I: @see Item_param::sync_clones.
5122 */
5124};
5125
5126class Item_int : public Item_num {
5128
5129 public:
5132 : value((longlong)i) {
5135 fixed = true;
5136 }
5138 : super(pos), value((longlong)i) {
5141 fixed = true;
5142 }
5146 fixed = true;
5147 }
5149 : value((longlong)i) {
5151 unsigned_flag = true;
5153 fixed = true;
5154 }
5155 Item_int(const Item_int *item_arg) {
5156 set_data_type(item_arg->data_type());
5157 value = item_arg->value;
5158 item_name = item_arg->item_name;
5159 max_length = item_arg->max_length;
5160 fixed = true;
5161 }
5162 Item_int(const Name_string &name_arg, longlong i, uint length) : value(i) {
5165 item_name = name_arg;
5166 fixed = true;
5167 }
5168 Item_int(const POS &pos, const Name_string &name_arg, longlong i, uint length)
5169 : super(pos), value(i) {
5172 item_name = name_arg;
5173 fixed = true;
5174 }
5175 Item_int(const char *str_arg, uint length) {
5177 init(str_arg, length);
5178 }
5179 Item_int(const POS &pos, const char *str_arg, uint length) : super(pos) {
5181 init(str_arg, length);
5182 }
5183
5184 Item_int(const POS &pos, const LEX_STRING &num, int dummy_error = 0)
5185 : Item_int(pos, num, my_strtoll10(num.str, nullptr, &dummy_error),
5186 static_cast<uint>(num.length)) {}
5187
5188 private:
5189 void init(const char *str_arg, uint length);
5192 if (!unsigned_flag && value >= 0) max_length++;
5193 }
5194
5195 protected:
5197 bool no_conversions) override;
5198
5199 public:
5200 enum Type type() const override { return INT_ITEM; }
5201 Item_result result_type() const override { return INT_RESULT; }
5202 longlong val_int() override {
5203 assert(fixed);
5204 return value;
5205 }
5206 double val_real() override {
5207 assert(fixed);
5208 return static_cast<double>(value);
5209 }
5210 my_decimal *val_decimal(my_decimal *) override;
5211 String *val_str(String *) override;
5212 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
5213 return get_date_from_int(ltime, fuzzydate);
5214 }
5215 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
5216 Item *clone_item() const override { return new Item_int(this); }
5217 void print(const THD *thd, String *str,
5218 enum_query_type query_type) const override;
5219 Item_num *neg() override {
5220 value = -value;
5221 return this;
5222 }
5223 uint decimal_precision() const override {
5224 return static_cast<uint>(max_length - 1);
5225 }
5226 bool eq(const Item *item) const override;
5227 bool check_partition_func_processor(uchar *) override { return false; }
5228 bool check_function_as_value_generator(uchar *) override { return false; }
5229};
5230
5231/**
5232 Item_int with value==0 and length==1
5233*/
5234class Item_int_0 final : public Item_int {
5235 public:
5237 explicit Item_int_0(const POS &pos) : Item_int(pos, NAME_STRING("0"), 0, 1) {}
5238};
5239
5240/*
5241 Item_temporal is used to store numeric representation
5242 of time/date/datetime values for queries like:
5243
5244 WHERE datetime_column NOT IN
5245 ('2006-04-25 10:00:00','2006-04-25 10:02:00', ...);
5246
5247 and for SHOW/INFORMATION_SCHEMA purposes (see sql_show.cc)
5248
5249 TS-TODO: Can't we use Item_time_literal, Item_date_literal,
5250 TS-TODO: and Item_datetime_literal for this purpose?
5251*/
5252class Item_temporal final : public Item_int {
5253 protected:
5255 bool no_conversions) override;
5256
5257 public:
5259 assert(is_temporal_type(field_type_arg));
5260 set_data_type(field_type_arg);
5261 }
5262 Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg,
5263 longlong i, uint length)
5264 : Item_int(i) {
5265 assert(is_temporal_type(field_type_arg));
5266 set_data_type(field_type_arg);
5268 item_name = name_arg;
5269 fixed = true;
5270 }
5271 Item *clone_item() const override {
5272 return new Item_temporal(data_type(), value);
5273 }
5274 longlong val_time_temporal() override { return val_int(); }
5275 longlong val_date_temporal() override { return val_int(); }
5277 assert(0);
5278 return false;
5279 }
5280 bool get_time(MYSQL_TIME *) override {
5281 assert(0);
5282 return false;
5283 }
5284};
5285
5286class Item_uint : public Item_int {
5287 protected:
5289 bool no_conversions) override;
5290
5291 public:
5292 Item_uint(const char *str_arg, uint length) : Item_int(str_arg, length) {
5293 unsigned_flag = true;
5294 }
5295 Item_uint(const POS &pos, const char *str_arg, uint length)
5296 : Item_int(pos, str_arg, length) {
5297 unsigned_flag = true;
5298 }
5299
5301 Item_uint(const Name_string &name_arg, longlong i, uint length)
5302 : Item_int(name_arg, i, length) {
5303 unsigned_flag = true;
5304 }
5305 double val_real() override {
5306 assert(fixed);
5307 return ulonglong2double(static_cast<ulonglong>(value));
5308 }
5309 String *val_str(String *) override;
5310
5311 Item *clone_item() const override {
5312 return new Item_uint(item_name, value, max_length);
5313 }
5314 void print(const THD *thd, String *str,
5315 enum_query_type query_type) const override;
5316 Item_num *neg() override;
5317 uint decimal_precision() const override { return max_length; }
5318};
5319
5320/* decimal (fixed point) constant */
5321class Item_decimal : public Item_num {
5323
5324 protected:
5327 bool no_conversions) override;
5328
5329 public:
5330 Item_decimal(const POS &pos, const char *str_arg, uint length,
5331 const CHARSET_INFO *charset);
5332 Item_decimal(const Name_string &name_arg, const my_decimal *val_arg,
5333 uint decimal_par, uint length);
5334 Item_decimal(my_decimal *value_par);
5335 Item_decimal(longlong val, bool unsig);
5336 Item_decimal(double val);
5337 Item_decimal(const uchar *bin, int precision, int scale);
5338
5339 enum Type type() const override { return DECIMAL_ITEM; }
5340 Item_result result_type() const override { return DECIMAL_RESULT; }
5341 longlong val_int() override;
5342 double val_real() override;
5343 String *val_str(String *) override;
5345 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
5346 return get_date_from_decimal(ltime, fuzzydate);
5347 }
5348 bool get_time(MYSQL_TIME *ltime) override {
5349 return get_time_from_decimal(ltime);
5350 }
5351 Item *clone_item() const override {
5353 }
5354 void print(const THD *thd, String *str,
5355 enum_query_type query_type) const override;
5356 Item_num *neg() override {
5359 return this;
5360 }
5361 uint decimal_precision() const override { return decimal_value.precision(); }
5362 bool eq(const Item *item) const override;
5363 void set_decimal_value(const my_decimal *value_par);
5364 bool check_partition_func_processor(uchar *) override { return false; }
5365};
5366
5367class Item_float : public Item_num {
5369
5371
5372 public:
5373 double value;
5374 // Item_real() :value(0) {}
5375 Item_float(const char *str_arg, uint length) { init(str_arg, length); }
5376 Item_float(const POS &pos, const char *str_arg, uint length) : super(pos) {
5377 init(str_arg, length);
5378 }
5379
5380 Item_float(const Name_string name_arg, double val_arg, uint decimal_par,
5381 uint length)
5382 : value(val_arg) {
5383 presentation = name_arg;
5384 item_name = name_arg;
5386 decimals = (uint8)decimal_par;
5388 fixed = true;
5389 }
5390 Item_float(const POS &pos, const Name_string name_arg, double val_arg,
5391 uint decimal_par, uint length)
5392 : super(pos), value(val_arg) {
5393 presentation = name_arg;
5394 item_name = name_arg;
5396 decimals = (uint8)decimal_par;
5398 fixed = true;
5399 }
5400
5401 Item_float(double value_par, uint decimal_par) : value(value_par) {
5403 decimals = (uint8)decimal_par;
5404 max_length = float_length(decimal_par);
5405 fixed = true;
5406 }
5407
5408 private:
5409 void init(const char *str_arg, uint length);
5410
5411 protected:
5413 bool no_conversions) override;
5414
5415 public:
5416 enum Type type() const override { return REAL_ITEM; }
5417 double val_real() override {
5418 assert(fixed);
5419 return value;
5420 }
5421 longlong val_int() override {
5422 assert(fixed);
5423 if (value <= LLONG_MIN) {
5424 return LLONG_MIN;
5425 } else if (value > LLONG_MAX_DOUBLE) {
5426 return LLONG_MAX;
5427 }
5428 return (longlong)rint(value);
5429 }
5430 String *val_str(String *) override;
5431 my_decimal *val_decimal(my_decimal *) override;
5432 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
5433 return get_date_from_real(ltime, fuzzydate);
5434 }
5435 bool get_time(MYSQL_TIME *ltime) override {
5436 return get_time_from_real(ltime);
5437 }
5438 Item *clone_item() const override {
5440 }
5441 Item_num *neg() override {
5442 value = -value;
5443 return this;
5444 }
5445 void print(const THD *thd, String *str,
5446 enum_query_type query_type) const override;
5447 bool eq(const Item *item) const override;
5448};
5449
5450class Item_func_pi : public Item_float {
5452
5453 public:
5454 Item_func_pi(const POS &pos)
5455 : Item_float(pos, null_name_string, M_PI, 6, 8),
5456 func_name(NAME_STRING("pi()")) {}
5457
5458 void print(const THD *, String *str, enum_query_type) const override {
5459 str->append(func_name);
5460 }
5461};
5462
5465
5466 protected:
5467 explicit Item_string(const POS &pos) : super(pos), m_cs_specified(false) {
5469 }
5470
5471 void init(const char *str, size_t length, const CHARSET_INFO *cs,
5472 Derivation dv, uint repertoire) {
5475 collation.set(cs, dv, repertoire);
5476 /*
5477 We have to have a different max_length than 'length' here to
5478 ensure that we get the right length if we do use the item
5479 to create a new table. In this case max_length must be the maximum
5480 number of chars for a string of this type because we in Create_field::
5481 divide the max_length with mbmaxlen).
5482 */
5483 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5486 // it is constant => can be used without fix_fields (and frequently used)
5487 fixed = true;
5488 /*
5489 Check if the string has any character that can't be
5490 interpreted using the relevant charset.
5491 */
5492 check_well_formed_result(&str_value, false, false);
5493 }
5495 bool no_conversions) override;
5496
5497 public:
5498 /* Create from a string, set name from the string itself. */
5499 Item_string(const char *str, size_t length, const CHARSET_INFO *cs,
5501 uint repertoire = MY_REPERTOIRE_UNICODE30)
5502 : m_cs_specified(false) {
5503 init(str, length, cs, dv, repertoire);
5504 }
5505 Item_string(const POS &pos, const char *str, size_t length,
5507 uint repertoire = MY_REPERTOIRE_UNICODE30)
5508 : super(pos), m_cs_specified(false) {
5509 init(str, length, cs, dv, repertoire);
5510 }
5511
5512 /* Just create an item and do not fill string representation */
5514 : m_cs_specified(false) {
5515 collation.set(cs, dv);
5517 max_length = 0;
5519 fixed = true;
5520 }
5521
5522 /* Create from the given name and string. */
5523 Item_string(const Name_string name_par, const char *str, size_t length,
5525 uint repertoire = MY_REPERTOIRE_UNICODE30)
5526 : m_cs_specified(false) {
5528 collation.set(cs, dv, repertoire);
5530 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5531 item_name = name_par;
5533 // it is constant => can be used without fix_fields (and frequently used)
5534 fixed = true;
5535 }
5536 Item_string(const POS &pos, const Name_string name_par, const char *str,
5537 size_t length, const CHARSET_INFO *cs,
5539 uint repertoire = MY_REPERTOIRE_UNICODE30)
5540 : super(pos), m_cs_specified(false) {
5542 collation.set(cs, dv, repertoire);
5544 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5545 item_name = name_par;
5547 // it is constant => can be used without fix_fields (and frequently used)
5548 fixed = true;
5549 }
5550
5551 /* Create from the given name and string. */
5552 Item_string(const POS &pos, const Name_string name_par,
5553 const LEX_CSTRING &literal, const CHARSET_INFO *cs,
5555 uint repertoire = MY_REPERTOIRE_UNICODE30)
5556 : super(pos), m_cs_specified(false) {
5557 str_value.set_or_copy_aligned(literal.str ? literal.str : "",
5558 literal.str ? literal.length : 0, cs);
5559 collation.set(cs, dv, repertoire);
5561 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5562 item_name = name_par;
5564 // it is constant => can be used without fix_fields (and frequently used)
5565 fixed = true;
5566 }
5567
5568 /*
5569 This is used in stored procedures to avoid memory leaks and
5570 does a deep copy of its argument.
5571 */
5572 void set_str_with_copy(const char *str_arg, uint length_arg) {
5573 str_value.copy(str_arg, length_arg, collation.collation);
5574 max_length = static_cast<uint32>(str_value.numchars() *
5576 }
5577 bool set_str_with_copy(const char *str_arg, uint length_arg,
5578 const CHARSET_INFO *from_cs);
5579 /// Update collation of string value to be according to item's collation
5581
5585 }
5586 enum Type type() const override { return STRING_ITEM; }
5587 double val_real() override;
5588 longlong val_int() override;
5589 String *val_str(String *) override {
5590 assert(fixed);
5591 return &str_value;
5592 }
5593 my_decimal *val_decimal(my_decimal *) override;
5594 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
5595 return get_date_from_string(ltime, fuzzydate);
5596 }
5597 bool get_time(MYSQL_TIME *ltime) override {
5598 return get_time_from_string(ltime);
5599 }
5600 Item_result result_type() const override { return STRING_RESULT; }
5601 bool eq(const Item *item) const override;
5602 bool eq_binary(const Item_string *item) const {
5603 return !stringcmp(&str_value, &item->str_value);
5604 }
5605 Item *clone_item() const override {
5606 return new Item_string(static_cast<Name_string>(item_name), str_value.ptr(),
5608 }
5609 inline void append(char *str, size_t length) {
5611 max_length = static_cast<uint32>(str_value.numchars() *
5613 }
5614 void print(const THD *thd, String *str,
5615 enum_query_type query_type) const override;
5616 bool check_partition_func_processor(uchar *) override { return false; }
5617
5618 /**
5619 Return true if character-set-introducer was explicitly specified in the
5620 original query for this item (text literal).
5621
5622 This operation is to be called from Item_string::print(). The idea is
5623 that when a query is generated (re-constructed) from the Item-tree,
5624 character-set-introducers should appear only for those literals, where
5625 they were explicitly specified by the user. Otherwise, that may lead to
5626 loss collation information (character set introducers implies default
5627 collation for the literal).
5628
5629 Basically, that makes sense only for views and hopefully will be gone
5630 one day when we start using original query as a view definition.
5631
5632 @return This operation returns the value of m_cs_specified attribute.
5633 @retval true if character set introducer was explicitly specified in
5634 the original query.
5635 @retval false otherwise.
5636 */
5637 inline bool is_cs_specified() const { return m_cs_specified; }
5638
5639 /**
5640 Set the value of m_cs_specified attribute.
5641
5642 m_cs_specified attribute shows whether character-set-introducer was
5643 explicitly specified in the original query for this text literal or
5644 not. The attribute makes sense (is used) only for views.
5645
5646 This operation is to be called from the parser during parsing an input
5647 query.
5648 */
5649 inline void set_cs_specified(bool cs_specified) {
5650 m_cs_specified = cs_specified;
5651 }
5652
5654
5655 private:
5657};
5658
5660 const char *cptr, const char *end,
5661 int unsigned_target);
5662double double_from_string_with_check(const CHARSET_INFO *cs, const char *cptr,
5663 const char *end);
5664
5667
5668 public:
5669 Item_static_string_func(const Name_string &name_par, const char *str,
5670 size_t length, const CHARSET_INFO *cs,
5673 func_name(name_par) {}
5674 Item_static_string_func(const POS &pos, const Name_string &name_par,
5675 const char *str, size_t length,
5676 const CHARSET_INFO *cs,
5678 : Item_string(pos, null_name_string, str, length, cs, dv),
5679 func_name(name_par) {}
5680
5681 void print(const THD *, String *str, enum_query_type) const override {
5682 str->append(func_name);
5683 }
5684
5685 bool check_partition_func_processor(uchar *) override { return true; }
5688 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5689 func_arg->banned_function_name = func_name.ptr();
5690 return true;
5691 }
5692};
5693
5694/* for show tables */
5696 public:
5698 const CHARSET_INFO *cs = nullptr)
5699 : Item_string(name, NullS, 0, cs) {
5700 max_length = static_cast<uint32>(length);
5701 }
5702};
5703
5705 public:
5706 Item_blob(const char *name, size_t length)
5708 &my_charset_bin) {
5710 }
5711 enum Type type() const override { return STRING_ITEM; }
5714 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5715 func_arg->err_code = func_arg->get_unnamed_function_error_code();
5716 return true;
5717 }
5718};
5719
5720/**
5721 Item_empty_string -- is a utility class to put an item into List<Item>
5722 which is then used in protocol.send_result_set_metadata() when sending SHOW
5723 output to the client.
5724*/
5725
5727 public:
5728 Item_empty_string(const char *header, size_t length,
5729 const CHARSET_INFO *cs = nullptr)
5731 Name_string(header, strlen(header)), 0,
5734 }
5735 void make_field(Send_field *field) override;
5736};
5737
5739 public:
5740 Item_return_int(const char *name_arg, uint length,
5741 enum_field_types field_type_arg, longlong value_arg = 0)
5742 : Item_int(Name_string(name_arg, name_arg ? strlen(name_arg) : 0),
5743 value_arg, length) {
5744 set_data_type(field_type_arg);
5745 unsigned_flag = true;
5746 }
5747};
5748
5751
5752 protected:
5754 bool no_conversions) override;
5755
5756 public:
5758 explicit Item_hex_string(const POS &pos) : super(pos) {
5760 }
5761
5762 Item_hex_string(const POS &pos, const LEX_STRING &literal);
5763
5764 enum Type type() const override { return HEX_BIN_ITEM; }
5765 double val_real() override {
5766 assert(fixed);
5767 return (double)(ulonglong)Item_hex_string::val_int();
5768 }
5769 longlong val_int() override;
5770 Item *clone_item() const override;
5771
5772 String *val_str(String *) override {
5773 assert(fixed);
5774 return &str_value;
5775 }
5776 my_decimal *val_decimal(my_decimal *) override;
5777 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
5778 return get_date_from_string(ltime, fuzzydate);
5779 }
5780 bool get_time(MYSQL_TIME *ltime) override {
5781 return get_time_from_string(ltime);
5782 }
5783 Item_result result_type() const override { return STRING_RESULT; }
5785 return INT_RESULT;
5786 }
5787 Item_result cast_to_int_type() const override { return INT_RESULT; }
5788 void print(const THD *thd, String *str,
5789 enum_query_type query_type) const override;
5790 bool eq(const Item *item) const override;
5791 bool check_partition_func_processor(uchar *) override { return false; }
5792 static LEX_CSTRING make_hex_str(const char *str, size_t str_length);
5793 uint decimal_precision() const override;
5794
5795 private:
5796 void hex_string_init(const char *str, uint str_length);
5797};
5798
5799class Item_bin_string final : public Item_hex_string {
5801
5802 public:
5803 Item_bin_string(const char *str, size_t str_length) {
5804 bin_string_init(str, str_length);
5805 }
5806 Item_bin_string(const POS &pos, const LEX_STRING &literal) : super(pos) {
5807 bin_string_init(literal.str, literal.length);
5808 }
5809
5810 static LEX_CSTRING make_bin_str(const char *str, size_t str_length);
5811
5812 private:
5813 void bin_string_init(const char *str, size_t str_length);
5814};
5815
5816/**
5817 Item with result field.
5818
5819 It adds to an Item a "result_field" Field member. This is for an item which
5820 may have a result (e.g. Item_func), and may store this result into a field;
5821 usually this field is a column of an internal temporary table. So the
5822 function may be evaluated by save_in_field(), storing result into
5823 result_field in tmp table. Then this result can be copied from tmp table to
5824 a following tmp table (e.g. GROUP BY table then ORDER BY table), or to a row
5825 buffer and back, as we want to avoid multiple evaluations of the Item, first
5826 because of performance, second because that evaluation may have side
5827 effects, e.g. SLEEP, GET_LOCK, RAND, window functions doing
5828 accumulations...
5829 Item_field and Item_ref also have a "result_field" for a similar goal.
5830 Literals don't need such "result_field" as their value is readily
5831 available.
5832*/
5833class Item_result_field : public Item {
5834 protected:
5835 Field *result_field{nullptr}; /* Save result here */
5836 public:
5838 explicit Item_result_field(const POS &pos) : Item(pos) {}
5839
5840 // Constructor used for Item_sum/Item_cond_and/or (see Item comment)
5842 : Item(thd, item), result_field(item->result_field) {}
5844 Field *tmp_table_field(TABLE *) override { return result_field; }
5845 table_map used_tables() const override { return 1; }
5846
5847 /**
5848 Resolve type-related information for this item, such as result field type,
5849 maximum size, precision, signedness, character set and collation.
5850 Also check compatibility of argument types and return error when applicable.
5851 Also adjust nullability when applicable.
5852
5853 @param thd thread handler
5854 @returns false if success, true if error
5855 */
5856 virtual bool resolve_type(THD *thd) = 0;
5857
5858 void set_result_field(Field *field) override { result_field = field; }
5859 bool is_result_field() const override { return true; }
5860 Field *get_result_field() const override { return result_field; }
5861
5862 void cleanup() override;
5863 bool check_function_as_value_generator(uchar *) override { return false; }
5864 bool mark_field_in_map(uchar *arg) override {
5865 bool rc = Item::mark_field_in_map(arg);
5866 if (result_field) // most likely result_field will be read too
5867 rc |= Item::mark_field_in_map(pointer_cast<Mark_field *>(arg),
5868 result_field);
5869 return rc;
5870 }
5871
5873 if (realval < LLONG_MIN || realval > LLONG_MAX_DOUBLE) {
5875 return error_int();
5876 }
5877 return llrint(realval);
5878 }
5879
5880 void raise_numeric_overflow(const char *type_name);
5881
5883 raise_numeric_overflow("DOUBLE");
5884 return 0.0;
5885 }
5886
5888 raise_numeric_overflow(unsigned_flag ? "BIGINT UNSIGNED" : "BIGINT");
5889 return 0;
5890 }
5891
5893 raise_numeric_overflow(unsigned_flag ? "DECIMAL UNSIGNED" : "DECIMAL");
5894 return E_DEC_OVERFLOW;
5895 }
5896};
5897
5898class Item_ref : public Item_ident {
5899 protected:
5900 void set_properties();
5902 bool no_conversions) override;
5903
5904 public:
5906 // If true, depended_from information of this ref was pushed down to
5907 // underlying field.
5909
5910 private:
5911 Field *result_field{nullptr}; /* Save result here */
5912
5913 protected:
5914 /// Indirect pointer to the referenced item.
5915 Item **m_ref_item{nullptr};
5916
5917 public:
5918 Item_ref(const POS &pos, const char *db_name_arg, const char *table_name_arg,
5919 const char *field_name_arg)
5920 : Item_ident(pos, db_name_arg, table_name_arg, field_name_arg) {}
5921
5922 /*
5923 This constructor is used in two scenarios:
5924 A) *item = NULL
5925 No initialization is performed, fix_fields() call will be necessary.
5926
5927 B) *item points to an Item this Item_ref will refer to. This is
5928 used for GROUP BY. fix_fields() will not be called in this case,
5929 so we call set_properties to make this item "fixed". set_properties
5930 performs a subset of action Item_ref::fix_fields does, and this subset
5931 is enough for Item_ref's used in GROUP BY.
5932
5933 TODO we probably fix a superset of problems like in BUG#6658. Check this
5934 with Bar, and if we have a more broader set of problems like this.
5935 */
5936 Item_ref(Name_resolution_context *context_arg, Item **item,
5937 const char *db_name_arg, const char *table_name_arg,
5938 const char *field_name_arg, bool alias_of_expr_arg = false);
5939 Item_ref(Name_resolution_context *context_arg, Item **item,
5940 const char *field_name_arg);
5941
5942 /* Constructor need to process subselect with temporary tables (see Item) */
5943 Item_ref(THD *thd, Item_ref *item)
5944 : Item_ident(thd, item),
5946 m_ref_item(item->m_ref_item) {}
5947
5948 /// @returns the item referenced by this object
5949 Item *ref_item() const { return *m_ref_item; }
5950
5951 /// @returns the pointer to the item referenced by this object
5952 Item **ref_pointer() const { return m_ref_item; }
5953
5955
5956 enum Type type() const override { return REF_ITEM; }
5957 bool eq(const Item *item) const override {
5958 const Item *it = item->real_item();
5959 // May search for a referenced item that is not yet resolved:
5960 if (m_ref_item == nullptr) return false;
5961 return ref_item()->eq(it);
5962 }
5963 double val_real() override;
5964 longlong val_int() override;
5965 longlong val_time_temporal() override;
5966 longlong val_date_temporal() override;
5967 my_decimal *val_decimal(my_decimal *) override;
5968 bool val_bool() override;
5969 String *val_str(String *tmp) override;
5970 bool val_json(Json_wrapper *result) override;
5971 bool is_null() override;
5972 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
5973 bool send(Protocol *prot, String *tmp) override;
5974 void make_field(Send_field *field) override;
5975 bool fix_fields(THD *, Item **) override;
5976 void fix_after_pullout(Query_block *parent_query_block,
5977 Query_block *removed_query_block) override;
5978
5979 Item_result result_type() const override { return ref_item()->result_type(); }
5980
5981 TYPELIB *get_typelib() const override { return ref_item()->get_typelib(); }
5982
5984 return result_field != nullptr ? result_field
5986 }
5987 Item *get_tmp_table_item(THD *thd) override;
5988 table_map used_tables() const override {
5989 if (depended_from != nullptr) return OUTER_REF_TABLE_BIT;
5990 const table_map map = ref_item()->used_tables();
5991 if (map != 0) return map;
5992 // rollup constant: ensure it is non-constant by returning RAND_TABLE_BIT
5994 return 0;
5995 }
5996 void update_used_tables() override {
5997 if (depended_from == nullptr) ref_item()->update_used_tables();
5998 /*
5999 Reset all flags except GROUP BY modifier, since we do not mark the rollup
6000 expression itself.
6001 */
6004 }
6005
6006 table_map not_null_tables() const override {
6007 /*
6008 It can happen that our 'depended_from' member is set but the
6009 'depended_from' member of the referenced item is not (example: if a
6010 field in a subquery belongs to an outer merged view), so we first test
6011 ours:
6012 */
6013 return depended_from != nullptr ? OUTER_REF_TABLE_BIT
6015 }
6016 void set_result_field(Field *field) override { result_field = field; }
6017 bool is_result_field() const override { return true; }
6018 Field *get_result_field() const override { return result_field; }
6019 Item *real_item() override {
6020 // May look into unresolved Item_ref objects
6021 if (m_ref_item == nullptr) return this;
6022 return ref_item()->real_item();
6023 }
6024 const Item *real_item() const override {
6025 // May look into unresolved Item_ref objects
6026 if (m_ref_item == nullptr) return this;
6027 return ref_item()->real_item();
6028 }
6029
6030 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override {
6031 // Unresolved items may have m_ref_item = nullptr
6032 return ((walk & enum_walk::PREFIX) && (this->*processor)(arg)) ||
6033 (m_ref_item != nullptr ? ref_item()->walk(processor, walk, arg)
6034 : false) ||
6035 ((walk & enum_walk::POSTFIX) && (this->*processor)(arg));
6036 }
6037 Item *transform(Item_transformer, uchar *arg) override;
6038 Item *compile(Item_analyzer analyzer, uchar **arg_p,
6039 Item_transformer transformer, uchar *arg_t) override;
6040 void traverse_cond(Cond_traverser traverser, void *arg,
6041 traverse_order order) override {
6042 assert(ref_item() != nullptr);
6043 if (order == PREFIX) (*traverser)(this, arg);
6044 ref_item()->traverse_cond(traverser, arg, order);
6045 if (order == POSTFIX) (*traverser)(this, arg);
6046 }
6048 /*
6049 Always return false: we don't need to go deeper into referenced
6050 expression tree since we have to mark aliased subqueries at
6051 their original places (select list, derived tables), not by
6052 references from other expression (order by etc).
6053 */
6054 return false;
6055 }
6056 bool clean_up_after_removal(uchar *arg) override;
6057 void print(const THD *thd, String *str,
6058 enum_query_type query_type) const override;
6059 void cleanup() override;
6061 return ref_item()->field_for_view_update();
6062 }
6063 virtual Ref_Type ref_type() const { return REF; }
6064
6065 // Row emulation: forwarding of ROW-related calls to ref
6066 uint cols() const override {
6067 assert(m_ref_item != nullptr);
6068 return result_type() == ROW_RESULT ? ref_item()->cols() : 1;
6069 }
6070 Item *element_index(uint i) override {
6071 assert(m_ref_item != nullptr);
6072 return result_type() == ROW_RESULT ? ref_item()->element_index(i) : this;
6073 }
6074 Item **addr(uint i) override {
6075 assert(m_ref_item != nullptr);
6076 return result_type() == ROW_RESULT ? ref_item()->addr(i) : nullptr;
6077 }
6078 bool check_cols(uint c) override {
6079 assert(m_ref_item != nullptr);
6080 return result_type() == ROW_RESULT ? ref_item()->check_cols(c)
6081 : Item::check_cols(c);
6082 }
6083 bool null_inside() override {
6084 assert(m_ref_item != nullptr);
6085 return result_type() == ROW_RESULT ? ref_item()->null_inside() : false;
6086 }
6087 void bring_value() override {
6088 assert(m_ref_item != nullptr);
6090 }
6091 bool get_time(MYSQL_TIME *ltime) override {
6092 assert(fixed);
6093 const bool result = ref_item()->get_time(ltime);
6095 return result;
6096 }
6097
6098 bool basic_const_item() const override { return false; }
6099
6100 bool is_outer_field() const override {
6101 assert(fixed);
6102 assert(ref_item());
6103 return ref_item()->is_outer_field();
6104 }
6105
6106 bool created_by_in2exists() const override {
6107 return ref_item()->created_by_in2exists();
6108 }
6109
6110 bool repoint_const_outer_ref(uchar *arg) override;
6111 bool is_non_const_over_literals(uchar *) override { return true; }
6114 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6115 func_arg->err_code = func_arg->get_unnamed_function_error_code();
6116 return true;
6117 }
6119 return ref_item()->cast_to_int_type();
6120 }
6121 bool is_valid_for_pushdown(uchar *arg) override {
6122 return ref_item()->is_valid_for_pushdown(arg);
6123 }
6126 }
6127 bool check_column_in_group_by(uchar *arg) override {
6128 return ref_item()->check_column_in_group_by(arg);
6129 }
6130 bool collect_item_field_or_ref_processor(uchar *arg) override;
6131};
6132
6133/**
6134 Class for fields from derived tables and views.
6135 The same as Item_ref, but call fix_fields() of reference if
6136 not called yet.
6137*/
6138class Item_view_ref final : public Item_ref {
6140
6141 public:
6143 const char *db_name_arg, const char *alias_name_arg,
6144 const char *table_name_arg, const char *field_name_arg,
6145 Table_ref *tr)
6146 : Item_ref(context_arg, item, db_name_arg, alias_name_arg,
6147 field_name_arg),
6149 if (tr->is_view()) {
6150 m_orig_db_name = db_name_arg;
6151 m_orig_table_name = table_name_arg;
6152 } else {
6153 assert(db_name_arg == nullptr);
6154 m_orig_table_name = table_name_arg;
6155 }
6156 m_table_ref = tr;
6158 set_nullable(true);
6160 }
6161 }
6162
6163 /*
6164 We share one underlying Item_field, so we have to disable
6165 build_equal_items_for_cond().
6166 TODO: Implement multiple equality optimization for views.
6167 */
6168 bool subst_argument_checker(uchar **) override { return false; }
6169
6170 bool fix_fields(THD *, Item **) override;
6171
6172 /**
6173 Takes into account whether an Item in a derived table / view is part of an
6174 inner table of an outer join.
6175 */
6176 table_map used_tables() const override {
6177 const Item_ref *inner_ref = this;
6178 const Item *inner_item;
6179 /*
6180 Check whether any of the inner expressions is an outer reference,
6181 and if it is, return OUTER_REF_TABLE_BIT.
6182 */
6183 while (true) {
6184 if (inner_ref->depended_from != nullptr) {
6185 return OUTER_REF_TABLE_BIT;
6186 }
6187 inner_item = inner_ref->ref_item();
6188 if (inner_item->type() != REF_ITEM) break;
6189 inner_ref = down_cast<const Item_ref *>(inner_item);
6190 }
6191
6192 const Item_field *field = inner_item->type() == FIELD_ITEM
6193 ? down_cast<const Item_field *>(inner_item)
6194 : nullptr;
6195
6196 // If the field is an outer reference, return OUTER_REF_TABLE_BIT
6197 if (field != nullptr && field->depended_from != nullptr) {
6198 return OUTER_REF_TABLE_BIT;
6199 }
6200 /*
6201 View references with expressions that are not deemed constant during
6202 execution, or when they are constants but the merged view/derived table
6203 was not from the inner side of an outer join, simply return the used
6204 tables of the underlying item. A "const" field that comes from an inner
6205 side of an outer join is not constant, since NULL values are issued
6206 when there are no matching rows in the inner table(s).
6207 */
6208 if (!inner_item->const_for_execution() || first_inner_table == nullptr) {
6209 return inner_item->used_tables();
6210 }
6211 /*
6212 This is a const expression on the inner side of an outer join.
6213 Augment its used table information with the map of an inner table from
6214 the outer join nest. field can be nullptr if it is from a const table.
6215 In this case, returning the table's original table map is required by
6216 the join optimizer.
6217 */
6218 return field != nullptr
6219 ? field->m_table_ref->map()
6220 : inner_item->used_tables() | first_inner_table->map();
6221 }
6222
6223 bool eq(const Item *item) const override;
6224 Item *get_tmp_table_item(THD *thd) override {
6225 DBUG_TRACE;
6227 item->item_name = item_name;
6228 return item;
6229 }
6230 Ref_Type ref_type() const override { return VIEW_REF; }
6231
6232 bool check_column_privileges(uchar *arg) override;
6233 bool mark_field_in_map(uchar *arg) override {
6234 /*
6235 If this referenced column is marked as used, flag underlying
6236 selected item from a derived table/view as used.
6237 */
6238 auto mark_field = (Mark_field *)arg;
6239 return get_result_field()
6241 : false;
6242 }
6243 longlong val_int() override;
6244 double val_real() override;
6246 String *val_str(String *str) override;
6247 bool val_bool() override;
6248 bool val_json(Json_wrapper *wr) override;
6249 bool is_null() override;
6250 bool send(Protocol *prot, String *tmp) override;
6252 Item *replace_item_view_ref(uchar *arg) override;
6253 Item *replace_view_refs_with_clone(uchar *arg) override;
6255
6256 protected:
6258 bool no_conversions) override;
6259
6260 private:
6261 /// @return true if item is from a null-extended row from an outer join
6262 bool has_null_row() const {
6264 }
6265
6266 /**
6267 If this column belongs to a view that is an inner table of an outer join,
6268 then this field points to the first leaf table of the view, otherwise NULL.
6269 */
6271};
6272
6273/*
6274 Class for outer fields.
6275 An object of this class is created when the select where the outer field was
6276 resolved is a grouping one. After it has been fixed the ref field will point
6277 to an Item_ref object which will be used to access the field.
6278 The ref field may also point to an Item_field instance.
6279 See also comments of the Item_field::fix_outer_field() function.
6280*/
6281
6282class Item_outer_ref final : public Item_ref {
6284
6285 private:
6286 /**
6287 Qualifying query of this outer ref (i.e. query block which owns FROM of
6288 table which this Item references).
6289 */
6291
6292 public:
6294 /* The aggregate function under which this outer ref is used, if any. */
6296 /*
6297 true <=> that the outer_ref is already present in the select list
6298 of the outer select.
6299 */
6303 : Item_ref(context_arg, nullptr, ident_arg->db_name,
6304 ident_arg->table_name, ident_arg->field_name, false),
6306 outer_ref(ident_arg),
6308 found_in_select_list(false) {
6312 // keep any select list alias:
6313 item_name = ident_arg->item_name;
6314 fixed = false;
6315 }
6317 const char *db_name_arg, const char *table_name_arg,
6318 const char *field_name_arg, bool alias_of_expr_arg,
6320 : Item_ref(context_arg, item, db_name_arg, table_name_arg, field_name_arg,
6321 alias_of_expr_arg),
6325 found_in_select_list(true) {}
6326 bool fix_fields(THD *, Item **) override;
6327 void fix_after_pullout(Query_block *parent_query_block,
6328 Query_block *removed_query_block) override;
6329 table_map used_tables() const override {
6330 return ref_item()->used_tables() == 0 ? 0 : OUTER_REF_TABLE_BIT;
6331 }
6332 table_map not_null_tables() const override { return 0; }
6333
6334 Ref_Type ref_type() const override { return OUTER_REF; }
6335 Item *replace_outer_ref(uchar *) override;
6336};
6337
6338/*
6339 An object of this class is like Item_ref, and
6340 sets owner->was_null=true if it has returned a NULL value from any
6341 val_XXX() function. This allows to inject an Item_ref_null_helper
6342 object into subquery and then check if the subquery has produced a row
6343 with NULL value.
6344*/
6345
6346class Item_ref_null_helper final : public Item_ref {
6348
6349 protected:
6351
6352 public:
6354 Item_in_subselect *master, Item **item)
6355 : super(context_arg, item, "", "", ""), owner(master) {}
6356 Item_ref_null_helper(const Item_ref_null_helper &ref_null_helper, Item **item)
6357 : Item_ref_null_helper(ref_null_helper.context, ref_null_helper.owner,
6358 item) {}
6359 double val_real() override;
6360 longlong val_int() override;
6361 longlong val_time_temporal() override;
6362 longlong val_date_temporal() override;
6363 String *val_str(String *s) override;
6364 my_decimal *val_decimal(my_decimal *) override;
6365 bool val_bool() override;
6366 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
6367 void print(const THD *thd, String *str,
6368 enum_query_type query_type) const override;
6369 Ref_Type ref_type() const override { return NULL_HELPER_REF; }
6370 /*
6371 we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
6372 */
6373 table_map used_tables() const override {
6376 }
6377};
6378
6379/*
6380 The following class is used to optimize comparing of bigint columns.
6381 We need to save the original item ('ref') to be able to call
6382 ref->save_in_field(). This is used to create index search keys.
6383
6384 An instance of Item_int_with_ref may have signed or unsigned integer value.
6385
6386*/
6387
6389 protected:
6392 bool no_conversions) override {
6393 return ref->save_in_field(field, no_conversions);
6394 }
6395
6396 public:
6398 bool unsigned_arg)
6399 : Item_int(i), ref(ref_arg) {
6400 set_data_type(field_type);
6401 unsigned_flag = unsigned_arg;
6402 }
6403 Item *clone_item() const override;
6404 Item *real_item() override { return ref; }
6405 const Item *real_item() const override { return ref; }
6406};
6407
6408/*
6409 Similar to Item_int_with_ref, but to optimize comparing of temporal columns.
6410*/
6412 public:
6413 Item_temporal_with_ref(enum_field_types field_type_arg, uint8 decimals_arg,
6414 longlong i, Item *ref_arg, bool unsigned_arg)
6415 : Item_int_with_ref(field_type_arg, i, ref_arg, unsigned_arg) {
6416 decimals = decimals_arg;
6417 }
6418 void print(const THD *thd, String *str,
6419 enum_query_type query_type) const override;
6421 assert(0);
6422 return true;
6423 }
6424 bool get_time(MYSQL_TIME *) override {
6425 assert(0);
6426 return true;
6427 }
6428};
6429
6430/*
6431 Item_datetime_with_ref is used to optimize queries like:
6432 SELECT ... FROM t1 WHERE date_or_datetime_column = 20110101101010;
6433 The numeric constant is replaced to Item_datetime_with_ref
6434 by convert_constant_item().
6435*/
6437 public:
6438 /**
6439 Constructor for Item_datetime_with_ref.
6440 @param field_type_arg Data type: MYSQL_TYPE_DATE or MYSQL_TYPE_DATETIME
6441 @param decimals_arg Number of fractional digits.
6442 @param i Temporal value in packed format.
6443 @param ref_arg Pointer to the original numeric Item.
6444 */
6445 Item_datetime_with_ref(enum_field_types field_type_arg, uint8 decimals_arg,
6446 longlong i, Item *ref_arg)
6447 : Item_temporal_with_ref(field_type_arg, decimals_arg, i, ref_arg, true) {
6448 }
6449 Item *clone_item() const override;
6450 longlong val_date_temporal() override { return val_int(); }
6452 assert(0);
6453 return val_int();
6454 }
6455};
6456
6457/*
6458 Item_time_with_ref is used to optimize queries like:
6459 SELECT ... FROM t1 WHERE time_column = 20110101101010;
6460 The numeric constant is replaced to Item_time_with_ref
6461 by convert_constant_item().
6462*/
6464 public:
6465 /**
6466 Constructor for Item_time_with_ref.
6467 @param decimals_arg Number of fractional digits.
6468 @param i Temporal value in packed format.
6469 @param ref_arg Pointer to the original numeric Item.
6470 */
6471 Item_time_with_ref(uint8 decimals_arg, longlong i, Item *ref_arg)
6472 : Item_temporal_with_ref(MYSQL_TYPE_TIME, decimals_arg, i, ref_arg,
6473 false) {}
6474 Item *clone_item() const override;
6475 longlong val_time_temporal() override { return val_int(); }
6477 assert(0);
6478 return val_int();
6479 }
6480};
6481
6482/**
6483 This is used for segregating rows in groups (e.g. GROUP BY, windows), to
6484 detect boundaries of groups.
6485 It caches a value, which is representative of the group, and can compare it
6486 to another row, and update its value when entering a new group.
6487*/
6489 protected:
6490 Item *item; ///< The item whose value to cache.
6491 explicit Cached_item(Item *i) : item(i) {}
6492
6493 public:
6494 bool null_value{true};
6495 virtual ~Cached_item() = default;
6496 /**
6497 Compare the value associated with the item with the stored value.
6498 If they are different, update the stored value with item's value and
6499 return true.
6500
6501 @returns true if item's value and stored value are different.
6502 Notice that first call is to establish an initial value and
6503 return value should be ignored.
6504 */
6505 virtual bool cmp() = 0;
6506 Item *get_item() const { return item; }
6507 Item **get_item_ptr() { return &item; }
6508};
6509
6511 // Make sure value.ptr() is never nullptr, as not all collation functions
6512 // are prepared for that (even with empty strings).
6515
6516 public:
6517 explicit Cached_item_str(Item *arg) : Cached_item(arg) {}
6518 bool cmp() override;
6519};
6520
6521/// Cached_item subclass for JSON values.
6523 Json_wrapper *m_value; ///< The cached JSON value.
6524 public:
6525 explicit Cached_item_json(Item *item);
6526 ~Cached_item_json() override;
6527 bool cmp() override;
6528};
6529
6531 double value{0.0};
6532
6533 public:
6534 explicit Cached_item_real(Item *item_par) : Cached_item(item_par) {}
6535 bool cmp() override;
6536};
6537
6540
6541 public:
6542 explicit Cached_item_int(Item *item_par) : Cached_item(item_par) {}
6543 bool cmp() override;
6544};
6545
6548
6549 public:
6550 explicit Cached_item_temporal(Item *item_par) : Cached_item(item_par) {}
6551 bool cmp() override;
6552};
6553
6556
6557 public:
6558 explicit Cached_item_decimal(Item *item_par) : Cached_item(item_par) {}
6559 bool cmp() override;
6560};
6561
6562class Item_default_value final : public Item_field {
6564
6565 protected:
6567 bool no_conversions) override;
6568
6569 public:
6570 Item_default_value(const POS &pos, Item *a = nullptr)
6571 : super(pos, nullptr, nullptr, nullptr), arg(a) {}
6572 bool do_itemize(Parse_context *pc, Item **res) override;
6573 enum Type type() const override { return DEFAULT_VALUE_ITEM; }
6574 bool eq(const Item *item) const override;
6575 bool fix_fields(THD *, Item **) override;
6576 void bind_fields() override;
6577 void cleanup() override { Item::cleanup(); }
6578 void print(const THD *thd, String *str,
6579 enum_query_type query_type) const override;
6580 table_map used_tables() const override { return 0; }
6581 Item *get_tmp_table_item(THD *thd) override { return copy_or_same(thd); }
6583 Item *replace_item_field(uchar *) override;
6584
6585 /*
6586 No additional privilege check for default values, as the walk() function
6587 checks privileges for the underlying column through the argument.
6588 */
6589 bool check_column_privileges(uchar *) override { return false; }
6590
6591 bool walk(Item_processor processor, enum_walk walk, uchar *args) override {
6592 return ((walk & enum_walk::PREFIX) && (this->*processor)(args)) ||
6593 (arg && arg->walk(processor, walk, args)) ||
6594 ((walk & enum_walk::POSTFIX) && (this->*processor)(args));
6595 }
6596
6599 reinterpret_cast<char *>(args));
6600 }
6601
6602 Item *transform(Item_transformer transformer, uchar *args) override;
6603 Item *argument() const { return arg; }
6604
6605 private:
6606 /// The argument for this function
6608 /// Pointer to row buffer that was used to calculate field value offset
6610};
6611
6612/*
6613 Item_insert_value -- an implementation of VALUES() function.
6614 You can use the VALUES(col_name) function in the UPDATE clause
6615 to refer to column values from the INSERT portion of the INSERT
6616 ... UPDATE statement. In other words, VALUES(col_name) in the
6617 UPDATE clause refers to the value of col_name that would be
6618 inserted, had no duplicate-key conflict occurred.
6619 In all other places this function returns NULL.
6620*/
6621
6622class Item_insert_value final : public Item_field {
6623 protected:
6625 bool no_conversions) override {
6626 return Item_field::save_in_field_inner(field_arg, no_conversions);
6627 }
6628
6629 public:
6630 /**
6631 Constructs an Item_insert_value that represents a call to the deprecated
6632 VALUES function.
6633 */
6636 arg(a),
6637 m_is_values_function(true) {}
6638
6639 /**
6640 Constructs an Item_insert_value that represents a derived table that wraps a
6641 table value constructor.
6642 */
6644 : Item_field(context_arg, nullptr, nullptr, nullptr),
6645 arg(a),
6646 m_is_values_function(false) {}
6647
6648 bool do_itemize(Parse_context *pc, Item **res) override {
6649 if (skip_itemize(res)) return false;
6650 return Item_field::do_itemize(pc, res) || arg->itemize(pc, &arg);
6651 }
6652
6653 enum Type type() const override { return INSERT_VALUE_ITEM; }
6654 bool eq(const Item *item) const override;
6655 bool fix_fields(THD *, Item **) override;
6656 void bind_fields() override;
6657 void cleanup() override;
6658 void print(const THD *thd, String *str,
6659 enum_query_type query_type) const override;
6660 /*
6661 We use RAND_TABLE_BIT to prevent Item_insert_value from
6662 being treated as a constant and precalculated before execution
6663 */
6664 table_map used_tables() const override { return RAND_TABLE_BIT; }
6665
6666 bool walk(Item_processor processor, enum_walk walk, uchar *args) override {
6667 return ((walk & enum_walk::PREFIX) && (this->*processor)(args)) ||
6668 arg->walk(processor, walk, args) ||
6669 ((walk & enum_walk::POSTFIX) && (this->*processor)(args));
6670 }
6673 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6674 func_arg->banned_function_name = "values";
6675 return true;
6676 }
6677
6678 private:
6679 /// The argument for this function
6681 /// Pointer to row buffer that was used to calculate field value offset
6683 /**
6684 This flag is true if the item represents a call to the deprecated VALUES
6685 function. It is false if the item represents a derived table that wraps a
6686 table value constructor.
6687 */
6689};
6690
6691/**
6692 Represents NEW/OLD version of field of row which is
6693 changed/read in trigger.
6694
6695 Note: For this item main part of actual binding to Field object happens
6696 not during fix_fields() call (like for Item_field) but right after
6697 parsing of trigger definition, when table is opened, with special
6698 setup_field() call. On fix_fields() stage we simply choose one of
6699 two Field instances representing either OLD or NEW version of this
6700 field.
6701*/
6702class Item_trigger_field final : public Item_field,
6704 public:
6705 /* Is this item represents row from NEW or OLD row ? */
6707 /* Next in list of all Item_trigger_field's in trigger */
6709 /*
6710 Next list of Item_trigger_field's in "sp_head::
6711 m_list_of_trig_fields_item_lists".
6712 */
6714 /* Index of the field in the TABLE::field array */
6716 /* Pointer to an instance of Table_trigger_field_support interface */
6718
6720 enum_trigger_variable_type trigger_var_type_arg,
6721 const char *field_name_arg, Access_bitmask priv,
6722 const bool ro)
6723 : Item_field(context_arg, nullptr, nullptr, field_name_arg),
6724 trigger_var_type(trigger_var_type_arg),
6726 field_idx((uint)-1),
6727 want_privilege(priv),
6729 read_only(ro) {}
6731 enum_trigger_variable_type trigger_var_type_arg,
6732 const char *field_name_arg, Access_bitmask priv,
6733 const bool ro)
6734 : Item_field(pos, nullptr, nullptr, field_name_arg),
6735 trigger_var_type(trigger_var_type_arg),
6736 field_idx((uint)-1),
6737 want_privilege(priv),
6739 read_only(ro) {}
6740 void setup_field(Table_trigger_field_support *table_triggers,
6741 GRANT_INFO *table_grant_info);
6742 enum Type type() const override { return TRIGGER_FIELD_ITEM; }
6743 bool eq(const Item *item) const override;
6744 bool fix_fields(THD *, Item **) override;
6745 void bind_fields() override;
6746 bool check_column_privileges(uchar *arg) override;
6747 void print(const THD *thd, String *str,
6748 enum_query_type query_type) const override;
6749 table_map used_tables() const override { return INNER_TABLE_BIT; }
6750 Field *get_tmp_table_field() override { return nullptr; }
6751 Item *copy_or_same(THD *) override { return this; }
6752 Item *get_tmp_table_item(THD *thd) override { return copy_or_same(thd); }
6753 void cleanup() override;
6754 void set_required_privilege(Access_bitmask privilege) override {
6755 want_privilege = privilege;
6756 }
6757
6760 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6761 func_arg->err_code = func_arg->get_unnamed_function_error_code();
6762 return true;
6763 }
6764
6765 bool is_valid_for_pushdown(uchar *args [[maybe_unused]]) override {
6766 return true;
6767 }
6768
6769 private:
6770 bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override;
6771
6772 public:
6774 return (read_only ? nullptr : this);
6775 }
6776
6777 bool set_value(THD *thd, Item **it) {
6778 const bool ret = set_value(thd, nullptr, it);
6779 if (!ret)
6781 field_idx);
6782 return ret;
6783 }
6784
6785 private:
6786 /*
6787 'want_privilege' holds privileges required to perform operation on
6788 this trigger field (SELECT_ACL if we are going to read it and
6789 UPDATE_ACL if we are going to update it). It is initialized at
6790 parse time but can be updated later if this trigger field is used
6791 as OUT or INOUT parameter of stored routine (in this case
6792 set_required_privilege() is called to appropriately update
6793 want_privilege).
6794 */
6797 /*
6798 Trigger field is read-only unless it belongs to the NEW row in a
6799 BEFORE INSERT of BEFORE UPDATE trigger.
6800 */
6802};
6803
6805 protected:
6806 Item *example{nullptr};
6808 /**
6809 Field that this object will get value from. This is used by
6810 index-based subquery engines to detect and remove the equality injected
6811 by IN->EXISTS transformation.
6812 */
6814 /*
6815 true <=> cache holds value of the last stored item (i.e actual value).
6816 store() stores item to be cached and sets this flag to false.
6817 On the first call of val_xxx function if this flag is set to false the
6818 cache_value() will be called to actually cache value of saved item.
6819 cache_value() will set this flag to true.
6820 */
6821 bool value_cached{false};
6822
6823 friend bool has_rollup_result(Item *item);
6825 THD *thd, Query_block *select, Item *item_arg);
6826
6827 public:
6829 fixed = true;
6830 set_nullable(true);
6831 null_value = true;
6832 }
6834 set_data_type(field_type_arg);
6835 fixed = true;
6836 set_nullable(true);
6837 null_value = true;
6838 }
6839
6840 void fix_after_pullout(Query_block *parent_query_block,
6841 Query_block *removed_query_block) override {
6842 if (example == nullptr) return;
6843 example->fix_after_pullout(parent_query_block, removed_query_block);
6845 }
6846
6847 virtual bool allocate(uint) { return false; }
6848 virtual bool setup(Item *item) {
6849 example = item;
6850 max_length = item->max_length;
6851 decimals = item->decimals;
6852 collation.set(item->collation);
6855 if (item->type() == FIELD_ITEM) {
6856 cached_field = down_cast<Item_field *>(item);
6857 if (cached_field->m_table_ref != nullptr)
6859 } else {
6860 used_table_map = item->used_tables();
6861 }
6862 return false;
6863 }
6864 enum Type type() const override { return CACHE_ITEM; }
6865 static Item_cache *get_cache(const Item *item);
6866 static Item_cache *get_cache(const Item *item, const Item_result type);
6867 table_map used_tables() const override { return used_table_map; }
6868 void print(const THD *thd, String *str,
6869 enum_query_type query_type) const override;
6870 bool eq_def(const Field *field) {
6871 return cached_field != nullptr && cached_field->field->eq_def(field);
6872 }
6873 bool eq(const Item *item) const override { return this == item; }
6874 /**
6875 Check if saved item has a non-NULL value.
6876 Will cache value of saved item if not already done.
6877 @return true if cached value is non-NULL.
6878 */
6879 bool has_value();
6880
6881 /**
6882 If this item caches a field value, return pointer to underlying field.
6883
6884 @return Pointer to field, or NULL if this is not a cache for a field value.
6885 */
6887
6888 /**
6889 Assigns to the cache the expression to be cached. Does not evaluate it.
6890 @param item the expression to be cached
6891 */
6892 virtual void store(Item *item);
6893
6894 /**
6895 Force an item to be null. Used for empty subqueries to avoid attempts to
6896 evaluate expressions which could have uninitialized columns due to
6897 bypassing the subquery exec.
6898 */
6899 void store_null() {
6900 assert(is_nullable());
6901 value_cached = true;
6902 null_value = true;
6903 }
6904
6905 virtual bool cache_value() = 0;
6906 bool store_and_cache(Item *item) {
6907 store(item);
6908 return cache_value();
6909 }
6910 void cleanup() override;
6911 bool basic_const_item() const override {
6912 return (example != nullptr && example->basic_const_item());
6913 }
6914 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
6915 virtual void clear() {
6916 null_value = true;
6917 value_cached = false;
6918 }
6919 bool is_null() override {
6920 return value_cached ? null_value : example->is_null();
6921 }
6922 bool is_non_const_over_literals(uchar *) override { return true; }
6925 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6926 func_arg->banned_function_name = "cached item";
6927 // This should not happen as SELECT statements are not allowed.
6928 assert(false);
6929 return true;
6930 }
6931 Item_result result_type() const override {
6932 if (!example) return INT_RESULT;
6934 }
6935 Item *get_example() const { return example; }
6937};
6938
6940 protected:
6942
6943 public:
6946 : Item_cache(field_type_arg), value(0) {}
6947
6948 /**
6949 Unlike store(), this stores an explicitly provided value, not the one of
6950 'item'; however, NULLness is still taken from 'item'.
6951 */
6952 void store_value(Item *item, longlong val_arg);
6953 double val_real() override;
6954 longlong val_int() override;
6955 longlong val_time_temporal() override { return val_int(); }
6956 longlong val_date_temporal() override { return val_int(); }
6957 String *val_str(String *str) override;
6958 my_decimal *val_decimal(my_decimal *) override;
6959 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
6960 return get_date_from_int(ltime, fuzzydate);
6961 }
6962 bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
6963 Item_result result_type() const override { return INT_RESULT; }
6964 bool cache_value() override;
6965};
6966
6967/**
6968 Cache class for BIT type expressions. The BIT data type behaves like unsigned
6969 integer numbers in all situations, except when formatted as a string, where
6970 it is directly interpreted as a byte string, possibly right-extended with
6971 zero-bits.
6972*/
6973class Item_cache_bit final : public Item_cache_int {
6974 public:
6976 : Item_cache_int(field_type_arg) {
6977 assert(field_type_arg == MYSQL_TYPE_BIT);
6978 }
6979
6980 /**
6981 Transform the result Item_cache_int::value in bit format. The process is
6982 similar to Field_bit_as_char::store().
6983 */
6984 String *val_str(String *str) override;
6985 uint string_length() { return ((max_length + 7) / 8); }
6986};
6987
6988class Item_cache_real final : public Item_cache {
6989 double value;
6990
6991 public:
6993
6994 double val_real() override;
6995 longlong val_int() override;
6996 String *val_str(String *str) override;
6997 my_decimal *val_decimal(my_decimal *) override;
6998 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
6999 return get_date_from_real(ltime, fuzzydate);
7000 }
7001 bool get_time(MYSQL_TIME *ltime) override {
7002 return get_time_from_real(ltime);
7003 }
7004 Item_result result_type() const override { return REAL_RESULT; }
7005 bool cache_value() override;
7006 void store_value(Item *expr, double value);
7007};
7008
7009class Item_cache_decimal final : public Item_cache {
7010 protected:
7012
7013 public:
7015
7016 double val_real() override;
7017 longlong val_int() override;
7018 String *val_str(String *str) override;
7019 my_decimal *val_decimal(my_decimal *) override;
7020 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
7021 return get_date_from_decimal(ltime, fuzzydate);
7022 }
7023 bool get_time(MYSQL_TIME *ltime) override {
7024 return get_time_from_decimal(ltime);
7025 }
7026 Item_result result_type() const override { return DECIMAL_RESULT; }
7027 bool cache_value() override;
7028 void store_value(Item *expr, my_decimal *d);
7029};
7030
7031class Item_cache_str final : public Item_cache {
7035
7036 protected:
7038 bool no_conversions) override;
7039
7040 public:
7042 : Item_cache(item->data_type()),
7043 value(nullptr),
7044 is_varbinary(item->type() == FIELD_ITEM &&
7046 !((const Item_field *)item)->field->has_charset()) {
7047 collation.set(item->collation);
7048 }
7049 double val_real() override;
7050 longlong val_int() override;
7051 String *val_str(String *) override;
7052 my_decimal *val_decimal(my_decimal *) override;
7053 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
7054 return get_date_from_string(ltime, fuzzydate);
7055 }
7056 bool get_time(MYSQL_TIME *ltime) override {
7057 return get_time_from_string(ltime);
7058 }
7059 Item_result result_type() const override { return STRING_RESULT; }
7060 const CHARSET_INFO *charset() const { return value->charset(); }
7061 bool cache_value() override;
7062 void store_value(Item *expr, String &s);
7063};
7064
7065class Item_cache_row final : public Item_cache {
7068
7069 public:
7071
7072 /**
7073 'allocate' is only used in Item_cache_row::setup()
7074 */
7075 bool allocate(uint num) override;
7076 /*
7077 'setup' is needed only by row => it not called by simple row subselect
7078 (only by IN subselect (in subselect optimizer))
7079 */
7080 bool setup(Item *item) override;
7081 void store(Item *item) override;
7082 void illegal_method_call(const char *) const MY_ATTRIBUTE((cold));
7083 void make_field(Send_field *) override { illegal_method_call("make_field"); }
7084 double val_real() override {
7085 illegal_method_call("val_real");
7086 return 0;
7087 }
7088 longlong val_int() override {
7089 illegal_method_call("val_int");
7090 return 0;
7091 }
7092 String *val_str(String *) override {
7093 illegal_method_call("val_str");
7094 return nullptr;
7095 }
7097 illegal_method_call("val_decimal");
7098 return nullptr;
7099 }
7101 illegal_method_call("get_date");
7102 return true;
7103 }
7104 bool get_time(MYSQL_TIME *) override {
7105 illegal_method_call("get_time");
7106 return true;
7107 }
7108
7109 Item_result result_type() const override { return ROW_RESULT; }
7110
7111 uint cols() const override { return item_count; }
7112 Item *element_index(uint i) override { return values[i]; }
7113 Item **addr(uint i) override { return (Item **)(values + i); }
7114 bool check_cols(uint c) override;
7115 bool null_inside() override;
7116 void bring_value() override;
7117 void cleanup() override { Item_cache::cleanup(); }
7118 bool cache_value() override;
7119};
7120
7123
7124 protected:
7127
7128 public:
7130 : Item_cache(field_type_arg), int_value(0), str_value_cached(false) {
7132 }
7133
7134 void store_value(Item *item, longlong val_arg);
7135 void store(Item *item) override;
7136 double val_real() override;
7137 longlong val_int() override;
7138 longlong val_time_temporal() override;
7139 longlong val_date_temporal() override;
7140 String *val_str(String *str) override;
7141 my_decimal *val_decimal(my_decimal *) override;
7142 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
7143 bool get_time(MYSQL_TIME *ltime) override;
7144 Item_result result_type() const override { return STRING_RESULT; }
7145 /*
7146 In order to avoid INT <-> STRING conversion of a DATETIME value
7147 two cache_value functions are introduced. One (cache_value) caches STRING
7148 value, another (cache_value_int) - INT value. Thus this cache item
7149 completely relies on the ability of the underlying item to do the
7150 correct conversion.
7151 */
7152 bool cache_value_int();
7153 bool cache_value() override;
7154 void clear() override {
7156 str_value_cached = false;
7157 }
7158};
7159
7160/// An item cache for values of type JSON.
7162 /// Cached value
7164 /// Whether the cached value is array and it is sorted
7166
7167 public:
7169 ~Item_cache_json() override;
7170 bool cache_value() override;
7171 void store_value(Item *expr, Json_wrapper *wr);
7172 bool val_json(Json_wrapper *wr) override;
7173 longlong val_int() override;
7174 String *val_str(String *str) override;
7175 Item_result result_type() const override { return STRING_RESULT; }
7176
7177 double val_real() override;
7178 my_decimal *val_decimal(my_decimal *val) override;
7179 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
7180 bool get_time(MYSQL_TIME *ltime) override;
7181 /// Sort cached data. Only arrays are affected.
7182 void sort();
7183 /// Returns true when cached value is array and it's sorted
7184 bool is_sorted() { return m_is_sorted; }
7185};
7186
7187/**
7188 Interface for storing an aggregation of type and type specification of
7189 multiple Item objects.
7190
7191 This is useful for cases where a field is an amalgamation of multiple types,
7192 such as in UNION where type conversions must be done to a common denominator.
7193*/
7195 protected:
7196 /// Typelib information, only used for data type ENUM and SET.
7198 /// Geometry type, only used for data type GEOMETRY.
7200
7201 void set_typelib(Item *item);
7202
7203 public:
7205
7206 double val_real() override = 0;
7207 longlong val_int() override = 0;
7209 String *val_str(String *) override = 0;
7210 bool get_date(MYSQL_TIME *, my_time_flags_t) override = 0;
7211 bool get_time(MYSQL_TIME *) override = 0;
7212
7213 Item_result result_type() const override;
7214 bool unify_types(Item *item);
7215 bool unify_types(const char *op_string, Item **items, size_t count);
7216 Field *make_field_by_type(TABLE *table, bool strict);
7217 static uint32 display_length(Item *item);
7219 return geometry_type;
7220 }
7221 void make_field(Send_field *field) override {
7222 Item::make_field(field);
7223 // Item_type_holder is used for unions and effectively sends Fields
7224 field->field = true;
7225 }
7228 pointer_cast<Check_function_as_value_generator_parameters *>(args);
7229 func_arg->err_code = func_arg->get_unnamed_function_error_code();
7230 return true;
7231 }
7232};
7233
7234/**
7235 Item_type_holder stores an aggregation of name, type and type specification of
7236 UNIONS and derived tables.
7237*/
7240
7241 public:
7242 /// @todo Consider giving Item_type_holder objects default names from the item
7243 /// they are initialized by. This would ensure that
7244 /// Query_expression::get_unit_column_types() always contains named items.
7245 Item_type_holder(THD *thd, Item *item) : super(thd, item) {}
7246
7247 enum Type type() const override { return TYPE_HOLDER_ITEM; }
7248
7249 /**
7250 Class is used in type aggregation only - this is needed to ensure
7251 that it is not attempted to be evaluated as a const value.
7252 */
7253 table_map used_tables() const override { return RAND_TABLE_BIT; }
7254
7255 double val_real() override;
7256 longlong val_int() override;
7257 my_decimal *val_decimal(my_decimal *) override;
7258 String *val_str(String *) override;
7259 bool get_date(MYSQL_TIME *, my_time_flags_t) override;
7260 bool get_time(MYSQL_TIME *) override;
7261};
7262
7263/**
7264 Reference item that encapsulates both the type and the contained items of a
7265 single column of a VALUES ROW query expression.
7266
7267 During execution, the item that will be output for the current iteration is
7268 contained in m_value_ref. The type of the column and the referenced item may
7269 differ in cases where a column of a VALUES clause contains different types
7270 across different rows, and must therefore do type conversions to their common
7271 denominator (e.g. a column containing both 10 and "10", of which the types
7272 will be aggregated into VARCHAR).
7273
7274 See the class comment for TableValueConstructorIterator for info on how
7275 Item_values_column is used as an indirection to iterate over the rows of a
7276 table value constructor (i.e. VALUES ROW expressions).
7277*/
7280
7281 private:
7283 /*
7284 Even if a table value constructor contains only constant values, we
7285 still need to identify individual rows within it. Set RAND_TABLE_BIT
7286 to ensure that all rows are scanned, and that the whole VALUES clause
7287 is never substituted with a const value or row.
7288 */
7290
7292 bool no_conversions) override;
7293
7294 public:
7296
7297 bool eq(const Item *item) const override;
7298 double val_real() override;
7299 longlong val_int() override;
7300 my_decimal *val_decimal(my_decimal *) override;
7301 bool val_bool() override;
7302 String *val_str(String *tmp) override;
7303 bool val_json(Json_wrapper *result) override;
7304 bool is_null() override;
7305 bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
7306 bool get_time(MYSQL_TIME *ltime) override;
7307
7308 enum Type type() const override { return VALUES_COLUMN_ITEM; }
7309 void set_value(Item *new_value) { m_value_ref = new_value; }
7311 void add_used_tables(Item *value);
7312};
7313
7314/// A class that represents a constant JSON value.
7315class Item_json final : public Item_basic_constant {
7317
7318 public:
7320 const Item_name_string &name);
7321 ~Item_json() override;
7322 enum Type type() const override { return STRING_ITEM; }
7323 void print(const THD *, String *str, enum_query_type) const override;
7324 bool val_json(Json_wrapper *result) override;
7325 Item_result result_type() const override { return STRING_RESULT; }
7326 double val_real() override;
7327 longlong val_int() override;
7328 String *val_str(String *str) override;
7330 bool get_date(MYSQL_TIME *ltime, my_time_flags_t) override;
7331 bool get_time(MYSQL_TIME *ltime) override;
7332 Item *clone_item() const override;
7333};
7334
7335extern Cached_item *new_Cached_item(THD *thd, Item *item);
7337extern bool resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
7338extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item);
7339extern bool is_null_on_empty_table(THD *thd, Item_field *i);
7340
7341extern const String my_null_string;
7342void convert_and_print(const String *from_str, String *to_str,
7343 const CHARSET_INFO *to_cs);
7344
7345std::string ItemToString(const Item *item, enum_query_type q_type);
7346std::string ItemToString(const Item *item);
7347
7348std::string ItemToQuerySubstrNoCharLimit(const Item *item);
7349std::string ItemToQuerySubstr(
7350 const Item *item, const LEX *lex = nullptr,
7352
7353inline size_t CountVisibleFields(const mem_root_deque<Item *> &fields) {
7354 return std::count_if(fields.begin(), fields.end(),
7355 [](Item *item) { return !item->hidden; });
7356}
7357
7358inline size_t CountHiddenFields(const mem_root_deque<Item *> &fields) {
7359 return std::count_if(fields.begin(), fields.end(),
7360 [](Item *item) { return item->hidden; });
7361}
7362
7364 size_t index) {
7365 for (Item *item : fields) {
7366 if (item->hidden) continue;
7367 if (index-- == 0) return item;
7368 }
7369 assert(false);
7370 return nullptr;
7371}
7372
7373/**
7374 Returns true iff the two items are equal, as in a->eq(b),
7375 after unwrapping refs and Item_cache objects.
7376 */
7377bool ItemsAreEqual(const Item *a, const Item *b);
7378
7379/**
7380 Returns true iff all items in the two arrays (which must be of the same size)
7381 are equal, as in a->eq(b), after unwrapping refs and Item_cache objects.
7382 */
7383bool AllItemsAreEqual(const Item *const *a, const Item *const *b,
7384 int num_items);
7385
7386#endif /* ITEM_INCLUDED */
uint32_t Access_bitmask
Definition: auth_acls.h:34
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
A type for SQL-like 3-valued Booleans: true/false/unknown.
Definition: item.h:589
value
Definition: item.h:603
@ v_UNKNOWN
Definition: item.h:603
@ v_FALSE
Definition: item.h:603
@ v_TRUE
Definition: item.h:603
Bool3(value v)
This is private; instead, use false3()/etc.
Definition: item.h:605
static const Bool3 true3()
Definition: item.h:596
static const Bool3 unknown3()
Definition: item.h:594
static const Bool3 false3()
Definition: item.h:592
bool is_true() const
Definition: item.h:598
value m_val
Definition: item.h:607
bool is_unknown() const
Definition: item.h:599
bool is_false() const
Definition: item.h:600
Definition: item.h:6554
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:6558
my_decimal value
Definition: item.h:6555
Definition: item.h:6538
longlong value
Definition: item.h:6539
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:6542
Cached_item subclass for JSON values.
Definition: item.h:6522
Json_wrapper * m_value
The cached JSON value.
Definition: item.h:6523
~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:6530
Cached_item_real(Item *item_par)
Definition: item.h:6534
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:137
double value
Definition: item.h:6531
Definition: item.h:6510
String tmp_value
Definition: item.h:6514
Cached_item_str(Item *arg)
Definition: item.h:6517
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:76
String value
Definition: item.h:6513
Definition: item.h:6546
Cached_item_temporal(Item *item_par)
Definition: item.h:6550
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:170
longlong value
Definition: item.h:6547
This is used for segregating rows in groups (e.g.
Definition: item.h:6488
Item ** get_item_ptr()
Definition: item.h:6507
Item * item
The item whose value to cache.
Definition: item.h:6490
virtual ~Cached_item()=default
Item * get_item() const
Definition: item.h:6506
virtual bool cmp()=0
Compare the value associated with the item with the stored value.
Cached_item(Item *i)
Definition: item.h:6491
bool null_value
Definition: item.h:6494
This class represents the cost of evaluating an Item.
Definition: item.h:788
bool m_is_expensive
True if the associated Item calls user defined functions or stored procedures.
Definition: item.h:843
double FieldCost() const
Get the cost of field access when evaluating the Item associated with this object.
Definition: item.h:825
uint8 m_other_fields
The number of other Field objects accessed by the associated Item.
Definition: item.h:849
void Compute(const Item &item)
Set '*this' to represent the cost of 'item'.
Definition: item.h:791
static constexpr double kStrFieldCost
The cost of accessing a Field_str, relative to other Field types.
Definition: item.h:833
uint8 m_str_fields
The number of Field_str objects accessed by the associated Item.
Definition: item.h:846
bool IsExpensive() const
Definition: item.h:814
void AddFieldCost()
Add the cost of accessing any other Field.
Definition: item.h:809
bool m_computed
True if 'ComputeInternal()' has been called.
Definition: item.h:839
void ComputeInternal(const Item &root)
Compute the cost of 'root' and its descendants.
Definition: item.cc:134
static constexpr double kOtherFieldCost
The cost of accessing a Field other than Field_str. 1.0 by definition.
Definition: item.h:836
void AddStrFieldCost()
Add the cost of accessing a Field_str.
Definition: item.h:803
void MarkExpensive()
Definition: item.h:797
Definition: item.h:182
void set(Derivation derivation_arg)
Definition: item.h:227
DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
Definition: item.h:197
void set_repertoire_from_charset(const CHARSET_INFO *cs)
Definition: item.h:188
bool aggregate(DTCollation &dt, uint flags=0)
Aggregate two collations together taking into account their coercibility (aka derivation).
Definition: item.cc:2592
void set(const DTCollation &dt)
Definition: item.h:202
DTCollation()
Definition: item.h:192
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg, uint repertoire_arg)
Definition: item.h:212
bool set(DTCollation &dt1, DTCollation &dt2, uint flags=0)
Definition: item.h:230
void set_numeric()
Definition: item.h:218
void set_repertoire(uint repertoire_arg)
Definition: item.h:228
const CHARSET_INFO * collation
Definition: item.h:184
Derivation derivation
Definition: item.h:185
const char * derivation_name() const
Definition: item.h:234
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
Definition: item.h:207
uint repertoire
Definition: item.h:186
void set(const CHARSET_INFO *collation_arg)
Definition: item.h:223
A field that stores a JSON value.
Definition: field.h:3840
Definition: field.h:569
const CHARSET_INFO * charset_for_protocol() const
Definition: field.h:1592
virtual Item_result cast_to_int_type() const
Definition: field.h:1041
static constexpr size_t MAX_LONG_BLOB_WIDTH
Definition: field.h:731
virtual bool is_array() const
Whether the field is a typed array.
Definition: field.h:1795
static constexpr size_t MAX_VARCHAR_WIDTH
Definition: field.h:725
const char * field_name
Definition: field.h:680
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:675
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:1221
virtual my_decimal * val_decimal(my_decimal *) const =0
bool is_tmp_nullable() const
Definition: field.h:905
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:1037
virtual bool eq_def(const Field *field) const
Definition: field.cc:8332
virtual bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const
Definition: field.cc:2262
geometry_type
Definition: field.h:712
@ GEOM_GEOMETRY
Definition: field.h:713
virtual Item_result result_type() const =0
bool is_nullable() const
Definition: field.h:1294
virtual geometry_type get_geometry_type() const
Definition: field.h:1675
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:1006
bool is_field_for_functional_index() const
Definition: field.h:871
virtual bool get_time(MYSQL_TIME *ltime) const
Definition: field.cc:2269
static constexpr size_t MAX_MEDIUM_BLOB_WIDTH
Definition: field.h:730
void dbug_print() const
Definition: field.h:1682
Context object for (functions that override) Item::clean_up_after_removal().
Definition: item.h:2893
Query_block *const m_root
Pointer to Cleanup_after_removal_context containing from which select the walk started,...
Definition: item.h:2907
Cleanup_after_removal_context(Query_block *root)
Definition: item.h:2895
Query_block * get_root()
Definition: item.h:2899
Definition: item.h:2743
List< Item > * m_items
Definition: item.h:2745
Collect_item_fields_or_refs(List< Item > *fields_or_refs)
Definition: item.h:2746
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:2760
List< Item > * m_item_fields_or_view_refs
Definition: item.h:2759
Collect_item_fields_or_view_refs(List< Item > *fields_or_vr, Query_block *transformed_block)
Definition: item.h:2764
uint m_any_value_level
Used to compute Item_field's m_protected_by_any_value.
Definition: item.h:2763
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:7194
longlong val_int() override=0
Item_result result_type() const override
Return expression type of Item_aggregate_type.
Definition: item.cc:10468
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:10741
bool get_time(MYSQL_TIME *) override=0
Item_aggregate_type(THD *, Item *)
Definition: item.cc:10449
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:7226
static uint32 display_length(Item *item)
Calculate length for merging result for given Item type.
Definition: item.cc:10623
void make_field(Send_field *field) override
Definition: item.h:7221
Field * make_field_by_type(TABLE *table, bool strict)
Make temporary table field according collected information about type of UNION result.
Definition: item.cc:10686
double val_real() override=0
Field::geometry_type get_geometry_type() const override
Definition: item.h:7218
TYPELIB * m_typelib
Typelib information, only used for data type ENUM and SET.
Definition: item.h:7197
bool unify_types(Item *item)
Unify type from given item with the type in the current item.
Definition: item.cc:10582
Field::geometry_type geometry_type
Geometry type, only used for data type GEOMETRY.
Definition: item.h:7199
Represents [schema.
Definition: item.h:4698
bool is_asterisk() const override
Checks if the current object represents an asterisk select list item.
Definition: item.h:4718
Item_asterisk(const POS &pos, const char *opt_schema_name, const char *opt_table_name)
Constructor.
Definition: item.h:4709
Item_field super
Definition: item.h:4699
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.h:4714
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:11159
Definition: item.h:3849
Item_basic_constant(const POS &pos)
Definition: item.h:3854
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:3863
void set_str_value(String *str)
Note that str_value.ptr() will now point to a string owned by some other object.
Definition: item.h:3875
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:3870
void set_used_tables(table_map map)
Definition: item.h:3859
table_map used_table_map
Definition: item.h:3850
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:3861
Item_basic_constant()
Definition: item.h:3853
table_map used_tables() const override
Definition: item.h:3860
Definition: item.h:5799
Item_bin_string(const char *str, size_t str_length)
Definition: item.h:5803
void bin_string_init(const char *str, size_t str_length)
Definition: item.cc:7436
static LEX_CSTRING make_bin_str(const char *str, size_t str_length)
Definition: item.cc:7406
Item_hex_string super
Definition: item.h:5800
Item_bin_string(const POS &pos, const LEX_STRING &literal)
Definition: item.h:5806
Definition: item.h:5704
Item_blob(const char *name, size_t length)
Definition: item.h:5706
enum Type type() const override
Definition: item.h:5711
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:5712
Cache class for BIT type expressions.
Definition: item.h:6973
Item_cache_bit(enum_field_types field_type_arg)
Definition: item.h:6975
uint string_length()
Definition: item.h:6985
String * val_str(String *str) override
Transform the result Item_cache_int::value in bit format.
Definition: item.cc:9864
Definition: item.h:7121
longlong val_int() override
Definition: item.cc:10060
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.cc:10035
longlong int_value
Definition: item.h:7125
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10048
bool cache_value() override
Definition: item.cc:9895
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:9952
void store_value(Item *item, longlong val_arg)
Definition: item.cc:9911
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:10007
String * val_str(String *str) override
Definition: item.cc:9924
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:9973
bool str_value_cached
Definition: item.h:7126
Item_result result_type() const override
Definition: item.h:7144
void clear() override
Definition: item.h:7154
String cached_string
Definition: item.h:7122
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:9919
bool cache_value_int()
Definition: item.cc:9880
Item_cache_datetime(enum_field_types field_type_arg)
Definition: item.h:7129
double val_real() override
Definition: item.cc:10033
Definition: item.h:7009
double val_real() override
Definition: item.cc:10245
my_decimal decimal_value
Definition: item.h:7011
bool cache_value() override
Definition: item.cc:10229
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:7020
longlong val_int() override
Definition: item.cc:10253
Item_cache_decimal()
Definition: item.h:7014
String * val_str(String *str) override
Definition: item.cc:10261
void store_value(Item *expr, my_decimal *d)
Definition: item.cc:10238
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10270
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:7023
Item_result result_type() const override
Definition: item.h:7026
Definition: item.h:6939
double val_real() override
Definition: item.cc:9851
longlong val_int() override
Definition: item.cc:9858
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:6959
longlong value
Definition: item.h:6941
Item_cache_int(enum_field_types field_type_arg)
Definition: item.h:6945
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:6956
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.h:6955
Item_result result_type() const override
Definition: item.h:6963
Item_cache_int()
Definition: item.h:6944
bool cache_value() override
Definition: item.cc:9820
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:6962
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:9844
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:9829
String * val_str(String *str) override
Definition: item.cc:9837
An item cache for values of type JSON.
Definition: item.h:7161
Item_result result_type() const override
Definition: item.h:7175
my_decimal * val_decimal(my_decimal *val) override
Definition: item.cc:10138
bool m_is_sorted
Whether the cached value is array and it is sorted.
Definition: item.h:7165
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:10149
Json_wrapper * m_value
Cached value.
Definition: item.h:7163
bool cache_value() override
Read the JSON value and cache it.
Definition: item.cc:10075
Item_cache_json()
Definition: item.cc:10062
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:10161
~Item_cache_json() override
Definition: item.cc:10067
bool val_json(Json_wrapper *wr) override
Copy the cached JSON value into a wrapper.
Definition: item.cc:10108
bool is_sorted()
Returns true when cached value is array and it's sorted.
Definition: item.h:7184
void store_value(Item *expr, Json_wrapper *wr)
Definition: item.cc:10092
double val_real() override
Definition: item.cc:10128
String * val_str(String *str) override
Definition: item.cc:10118
void sort()
Sort cached data. Only arrays are affected.
Definition: item.cc:10181
longlong val_int() override
Definition: item.cc:10172
Definition: item.h:6988
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:6998
Item_cache_real()
Definition: item.h:6992
void store_value(Item *expr, double value)
Definition: item.cc:10197
double value
Definition: item.h:6989
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10222
bool cache_value() override
Definition: item.cc:10189
Item_result result_type() const override
Definition: item.h:7004
double val_real() override
Definition: item.cc:10203
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:7001
String * val_str(String *str) override
Definition: item.cc:10215
longlong val_int() override
Definition: item.cc:10209
Definition: item.h:7065
Item * element_index(uint i) override
Definition: item.h:7112
longlong val_int() override
Definition: item.h:7088
double val_real() override
Definition: item.h:7084
bool null_inside() override
Definition: item.cc:10431
Item_result result_type() const override
Definition: item.h:7109
Item ** addr(uint i) override
Definition: item.h:7113
bool allocate(uint num) override
'allocate' is only used in Item_cache_row::setup()
Definition: item.cc:10361
Item_cache_row()
Definition: item.h:7070
void bring_value() override
Definition: item.cc:10442
bool get_time(MYSQL_TIME *) override
Definition: item.h:7104
my_decimal * val_decimal(my_decimal *) override
Definition: item.h:7096
void make_field(Send_field *) override
Definition: item.h:7083
void illegal_method_call(const char *) const
Definition: item.cc:10415
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item.h:7100
uint item_count
Definition: item.h:7067
bool check_cols(uint c) override
Definition: item.cc:10423
bool cache_value() override
Definition: item.cc:10392
uint cols() const override
Definition: item.h:7111
bool setup(Item *item) override
Definition: item.cc:10368
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10381
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:7117
Item_cache ** values
Definition: item.h:7066
String * val_str(String *) override
Definition: item.h:7092
Definition: item.h:7031
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:10347
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:7053
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:7056
bool cache_value() override
Definition: item.cc:10276
Item_result result_type() const override
Definition: item.h:7059
void store_value(Item *expr, String &s)
Definition: item.cc:10298
String value_buff
Definition: item.h:7033
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10336
const CHARSET_INFO * charset() const
Definition: item.h:7060
double val_real() override
Definition: item.cc:10308
String * val_str(String *) override
Definition: item.cc:10330
longlong val_int() override
Definition: item.cc:10319
char buffer[STRING_BUFFER_USUAL_SIZE]
Definition: item.h:7032
String * value
Definition: item.h:7033
bool is_varbinary
Definition: item.h:7034
Item_cache_str(const Item *item)
Definition: item.h:7041
Definition: item.h:6804
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:9791
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9809
Field * field()
If this item caches a field value, return pointer to underlying field.
Definition: item.h:6886
Item * get_example() const
Definition: item.h:6935
bool eq_def(const Field *field)
Definition: item.h:6870
Item_field * cached_field
Field that this object will get value from.
Definition: item.h:6813
virtual bool allocate(uint)
Definition: item.h:6847
Item ** get_example_ptr()
Definition: item.h:6936
bool is_non_const_over_literals(uchar *) override
Definition: item.h:6922
bool has_value()
Check if saved item has a non-NULL value.
Definition: item.cc:9797
Item_result result_type() const override
Definition: item.h:6931
friend bool has_rollup_result(Item *item)
Checks if an item has a ROLLUP NULL which needs to be written to temp table.
Definition: sql_executor.cc:371
bool basic_const_item() const override
Returns true if this is a simple constant item like an integer, not a constant expression.
Definition: item.h:6911
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.h:6873
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:6840
virtual bool cache_value()=0
void store_null()
Force an item to be null.
Definition: item.h:6899
Item_cache(enum_field_types field_type_arg)
Definition: item.h:6833
table_map used_table_map
Definition: item.h:6807
enum Type type() const override
Definition: item.h:6864
Item_cache()
Definition: item.h:6828
virtual void store(Item *item)
Assigns to the cache the expression to be cached.
Definition: item.cc:9772
virtual bool setup(Item *item)
Definition: item.h:6848
bool value_cached
Definition: item.h:6821
table_map used_tables() const override
Definition: item.h:6867
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:6919
virtual void clear()
Definition: item.h:6915
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:6923
Item * example
Definition: item.h:6806
friend bool replace_contents_of_rollup_wrappers_with_tmp_fields(THD *thd, Query_block *select, Item *item_arg)
For each rollup wrapper below the given item, replace its argument with a temporary field,...
Definition: sql_executor.cc:4557
static Item_cache * get_cache(const Item *item)
Definition: item.cc:9729
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9781
bool store_and_cache(Item *item)
Definition: item.h:6906
Definition: item.h:4019
uint m_case_expr_id
Definition: item.h:4041
Type type() const override
Definition: item.h:4028
Item * this_item() override
Definition: item.cc:1979
Item_case_expr(uint case_expr_id)
Definition: item.cc:1975
Item ** this_item_addr(THD *thd, Item **) override
Definition: item.cc:1991
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:1997
Item_result result_type() const override
Definition: item.h:4029
Definition: item.h:6436
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:6450
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:6445
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.h:6451
Item * clone_item() const override
Definition: item.cc:7086
Definition: item.h:5321
uint decimal_precision() const override
Definition: item.h:5361
String * val_str(String *) override
Definition: item.cc:3557
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3563
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3574
Item_result result_type() const override
Definition: item.h:5340
longlong val_int() override
Definition: item.cc:3545
enum Type type() const override
Definition: item.h:5339
my_decimal * val_decimal(my_decimal *) override
Definition: item.h:5344
my_decimal decimal_value
Definition: item.h:5325
double val_real() override
Definition: item.cc:3551
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:5345
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5364
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:7045
Item_num super
Definition: item.h:5322
Item_decimal(const POS &pos, const char *str_arg, uint length, const CHARSET_INFO *charset)
Definition: item.cc:3486
Item * clone_item() const override
Definition: item.h:5351
Item_num * neg() override
Definition: item.h:5356
void set_decimal_value(const my_decimal *value_par)
Definition: item.cc:3589
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:5348
Definition: item.h:6562
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:9205
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:9161
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9150
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:9069
Item_default_value(const POS &pos, Item *a=nullptr)
Definition: item.h:6570
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9140
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:6591
Item_field super
Definition: item.h:6563
bool check_column_privileges(uchar *) override
Check privileges of base table column.
Definition: item.h:6589
table_map used_tables() const override
Definition: item.h:6580
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:6597
Item * arg
The argument for this function.
Definition: item.h:6607
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:6339
Item * argument() const
Definition: item.h:6603
uchar * m_rowbuffer_saved
Pointer to row buffer that was used to calculate field value offset.
Definition: item.h:6609
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9090
enum Type type() const override
Definition: item.h:6573
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:6363
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:6581
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9085
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:6577
Item_empty_string – is a utility class to put an item into List<Item> which is then used in protocol....
Definition: item.h:5726
void make_field(Send_field *field) override
Definition: item.cc:6468
Item_empty_string(const char *header, size_t length, const CHARSET_INFO *cs=nullptr)
Definition: item.h:5728
Definition: item.h:4389
Item * replace_equal_field(uchar *) override
Replace an Item_field for an equal Item_field that evaluated earlier (if any).
Definition: item.cc:6409
bool protected_by_any_value() const
See m_protected_by_any_value.
Definition: item.h:4680
bool check_column_privileges(uchar *arg) override
Check privileges of base table column.
Definition: item.cc:1370
bool collect_outer_field_processor(uchar *arg) override
Definition: item.cc:991
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:1023
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:1204
bool find_field_processor(uchar *arg) override
Is this an Item_field which references the given Field argument?
Definition: item.h:4558
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:3255
bool alias_name_used() const override
Definition: item.h:4658
bool any_privileges
Definition: item.h:4484
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4571
void set_item_equal_all_join_nests(Item_multi_eq *item_equal)
Definition: item.h:4460
enum Type type() const override
Definition: item.h:4500
bool add_field_to_cond_set_processor(uchar *) override
Item::walk function.
Definition: item.cc:1070
Item_result numeric_context_result_type() const override
Result type when an item appear in a numeric context.
Definition: item.h:4518
Item_multi_eq * multi_equality() const
Definition: item.h:4458
void set_field(Field *field)
Definition: item.cc:3066
Item_result cast_to_int_type() const override
Definition: item.h:4522
const Item_field * base_item_field() const
Definition: item.h:4536
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:979
Item_multi_eq * find_multi_equality(COND_EQUAL *cond_equal) const
Find a field among specified multiple equalities.
Definition: item.cc:6168
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:1268
uint16 field_index
Index for this field in table->field array.
Definition: item.h:4457
const CHARSET_INFO * charset_for_protocol(void) override
Definition: item.h:4604
bool subst_argument_checker(uchar **arg) override
Check whether a field can be substituted by an equal item.
Definition: item.cc:6212
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:8114
Field * result_field
Result field.
Definition: item.h:4412
Item_multi_eq * item_equal_all_join_nests
Definition: item.h:4474
Item_result result_type() const override
Definition: item.h:4517
uint32 max_disp_length()
Definition: item.h:4589
void dbug_print() const
Definition: item.h:4609
double val_real() override
Definition: item.cc:3213
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:1099
void save_org_in_field(Field *field) override
Set a field's value from a item.
Definition: item.cc:6769
void make_field(Send_field *tmp_field) override
Definition: item.cc:6715
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:3263
void set_base_item_field(const Item_field *item)
Definition: item.h:4532
bool get_timeval(my_timeval *tm, int *warnings) override
Get timestamp in "struct timeval" format.
Definition: item.cc:3271
enum_monotonicity_info get_monotonicity_info() const override
Definition: item.h:4525
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:8155
Item_field * field_for_view_update() override
Definition: item.h:4590
const Item_field * m_base_item_field
If this field is derived from another field, e.g.
Definition: item.h:4434
void set_result_field(Field *field_arg) override
Definition: item.h:4529
bool send(Protocol *protocol, String *str_arg) override
This is only called from items that is not of type item_field.
Definition: item.cc:8079
table_map used_tables() const override
Definition: item.cc:3315
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:4542
void reset_field()
Reset all aspect of a field object, so that it can be re-resolved.
Definition: item.cc:6140
Field * field
Source field.
Definition: item.h:4408
void compute_cost(CostOfItem *root_cost) const override
Compute the cost of evaluating this Item.
Definition: item.h:4682
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:4450
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:8100
bool check_column_in_group_by(uchar *arg) override
Check if this column is found in GROUP BY.
Definition: item.cc:1238
uint32_t last_org_destination_field_memcpyable
Definition: item.h:4426
bool returns_array() const override
Whether the item returns array of its data type.
Definition: item.h:4665
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:6313
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:3231
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:6074
void set_can_use_prefix_key() override
Definition: item.h:4667
uint32_t last_destination_field_memcpyable
Definition: item.h:4427
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:6269
bool fix_outer_field(THD *thd, Field **field, Item_ident **ref_field, bool *complete)
Resolve the name of a column that may be an outer reference.
Definition: item.cc:5471
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.cc:3225
String * val_str(String *) override
Definition: item.cc:3198
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:3406
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3249
Field::geometry_type get_geometry_type() const override
Definition: item.h:4600
Access_bitmask have_privileges
Definition: item.h:4482
bool add_field_to_set_processor(uchar *arg) override
Item::walk function.
Definition: item.cc:1061
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:1251
bool strip_db_table_name_processor(uchar *) override
Generated fields don't need db/table names.
Definition: item.cc:11064
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:1077
bool is_outer_field() const override
Definition: item.h:4596
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:11053
bool no_constant_propagation
If true, the optimizer's constant propagation will not replace this item with an equal constant.
Definition: item.h:4477
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:3205
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:1039
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:2962
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:1110
Item_ident super
Definition: item.h:4390
virtual bool is_asterisk() const
Checks if the current object represents an asterisk select list item.
Definition: item.h:4678
Field * tmp_table_field(TABLE *) override
Definition: item.h:4531
bool can_use_prefix_key
Definition: item.h:4489
bool m_protected_by_any_value
State used for transforming scalar subqueries to JOINs with derived tables, cf.
Definition: item.h:4440
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:4394
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:2938
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:6784
longlong val_date_temporal_at_utc() override
Definition: item.cc:3243
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:6103
longlong val_int() override
Definition: item.cc:3219
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:8143
longlong val_time_temporal_at_utc() override
Definition: item.cc:3237
Field * last_org_destination_field
Definition: item.h:4424
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3277
bool used_tables_for_level(uchar *arg) override
Return used table information for the specified query block (level).
Definition: item.cc:3321
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item.cc:3194
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:4562
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:1302
bool disable_constant_propagation(uchar *) override
Definition: item.h:4584
bool replace_field_processor(uchar *arg) override
A processor that replaces any Fields with a Create_field_wrapper.
Definition: sql_table.cc:7810
Field * last_destination_field
Definition: item.h:4425
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:4530
longlong val_int_endpoint(bool left_endp, bool *incl_endp) override
Definition: item.cc:3417
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:5879
Definition: item.h:5367
Item_num super
Definition: item.h:5368
longlong val_int() override
Definition: item.h:5421
Name_string presentation
Definition: item.h:5370
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:5432
Item_float(double value_par, uint decimal_par)
Definition: item.h:5401
Item_float(const POS &pos, const Name_string name_arg, double val_arg, uint decimal_par, uint length)
Definition: item.h:5390
Item * clone_item() const override
Definition: item.h:5438
void init(const char *str_arg, uint length)
This function is only called during parsing:
Definition: item.cc:7156
Item_float(const char *str_arg, uint length)
Definition: item.h:5375
double val_real() override
Definition: item.h:5417
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:7173
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7181
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:5435
Item_num * neg() override
Definition: item.h:5441
String * val_str(String *) override
Definition: item.cc:3597
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3604
double value
Definition: item.h:5373
Item_float(const Name_string name_arg, double val_arg, uint decimal_par, uint length)
Definition: item.h:5380
Item_float(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5376
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7203
enum Type type() const override
Definition: item.h:5416
Implements the comparison operator equals (=)
Definition: item_cmpfunc.h:1101
Definition: item.h:5450
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item.h:5458
const Name_string func_name
Definition: item.h:5451
Item_func_pi(const POS &pos)
Definition: item.h:5454
Definition: item_func.h:100
Definition: item.h:5749
uint decimal_precision() const override
Definition: item.cc:7255
Item_result result_type() const override
Definition: item.h:5783
Item_result cast_to_int_type() const override
Definition: item.h:5787
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:7330
void hex_string_init(const char *str, uint str_length)
Definition: item.cc:7281
Item_result numeric_context_result_type() const override
Result type when an item appear in a numeric context.
Definition: item.h:5784
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:5780
enum Type type() const override
Definition: item.h:5764
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:5777
Item_hex_string()
Definition: item.cc:7221
longlong val_int() override
Definition: item.cc:7291
Item_basic_constant super
Definition: item.h:5750
Item * clone_item() const override
Definition: item.cc:7228
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7391
static LEX_CSTRING make_hex_str(const char *str, size_t str_length)
Definition: item.cc:7239
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:7338
double val_real() override
Definition: item.h:5765
String * val_str(String *) override
Definition: item.h:5772
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7369
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5791
Item_hex_string(const POS &pos)
Definition: item.h:5758
Definition: item.h:4361
my_decimal * val_decimal(my_decimal *dec) override
Definition: item.h:4376
const CHARSET_INFO * charset_for_protocol() override
Definition: item.h:4384
Item_ident_for_show(Field *par_field, const char *db_arg, const char *table_name_arg)
Definition: item.h:4367
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:4379
const char * table_name
Definition: item.h:4365
enum Type type() const override
Definition: item.h:4371
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:4382
longlong val_int() override
Definition: item.h:4374
double val_real() override
Definition: item.h:4373
Field * field
Definition: item.h:4363
String * val_str(String *str) override
Definition: item.h:4375
bool fix_fields(THD *thd, Item **ref) override
Definition: item.cc:2888
void make_field(Send_field *tmp_field) override
Definition: item.cc:2875
const char * db_name
Definition: item.h:4364
Definition: item.h:4127
bool m_alias_of_expr
if this Item's name is alias of SELECT expression
Definition: item.h:4168
virtual bool alias_name_used() const
Definition: item.h:4352
const char * original_db_name() const
Definition: item.h:4281
void set_alias_of_expr()
Marks that this Item's name is alias of SELECT expression.
Definition: item.h:4336
bool is_strong_side_column_not_in_fd(uchar *arg) override
Definition: item.cc:11028
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:4230
bool is_alias_of_expr() const
Definition: item.h:4334
Item_ident(THD *thd, Item_ident *item)
Constructor used by Item_field & Item_*_ref (see Item comment)
Definition: item.h:4258
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:4228
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:3340
const char * m_orig_field_name
Names the field in the source base table.
Definition: item.h:4167
void set_original_field_name(const char *name_arg)
Definition: item.h:4278
const char * m_orig_table_name
Names the original table that is the source of the field.
Definition: item.h:4157
const char * original_table_name() const
Definition: item.h:4282
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.h:4290
Item_ident(const POS &pos, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:4243
bool update_depended_from(uchar *) override
Definition: item.cc:954
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:934
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:4222
const char * table_name
If column is from a non-aliased base table or view, name of base table or view.
Definition: item.h:4197
Name_resolution_context * context
For regularly resolved column references, 'context' points to a name resolution context object belong...
Definition: item.h:4183
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:4189
const char * full_name() const override
Definition: item.cc:3122
bool aggregate_check_group(uchar *arg) override
Definition: item.cc:11023
bool is_column_not_in_fd(uchar *arg) override
Definition: item.cc:11036
const char * field_name
If column is aliased, the column alias name.
Definition: item.h:4211
void set_orignal_db_name(const char *name_arg)
Definition: item.h:4274
const char * original_field_name() const
Definition: item.h:4283
bool change_context_processor(uchar *arg) override
Definition: item.h:4328
void set_original_table_name(const char *name_arg)
Definition: item.h:4275
Item super
Definition: item.h:4128
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:4147
bool aggregate_check_distinct(uchar *arg) override
Definition: item.cc:10975
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:10942
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:604
Definition: item.h:6622
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:6643
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:6671
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9223
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:6634
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.h:6648
uchar * m_rowbuffer_saved
Pointer to row buffer that was used to calculate field value offset.
Definition: item.h:6682
const bool m_is_values_function
This flag is true if the item represents a call to the deprecated VALUES function.
Definition: item.h:6688
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:6624
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9218
Item * arg
The argument for this function.
Definition: item.h:6680
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:6666
table_map used_tables() const override
Definition: item.h:6664
enum Type type() const override
Definition: item.h:6653
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9306
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9334
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9328
Item_int with value==0 and length==1.
Definition: item.h:5234
Item_int_0()
Definition: item.h:5236
Item_int_0(const POS &pos)
Definition: item.h:5237
Definition: item.h:6388
Item * clone_item() const override
Definition: item.cc:7065
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:6391
const Item * real_item() const override
Definition: item.h:6405
Item_int_with_ref(enum_field_types field_type, longlong i, Item *ref_arg, bool unsigned_arg)
Definition: item.h:6397
Item * ref
Definition: item.h:6390
Item * real_item() override
Definition: item.h:6404
Definition: item.h:5126
Item_result result_type() const override
Definition: item.h:5201
Item_int(const POS &pos, const LEX_STRING &num, int dummy_error=0)
Definition: item.h:5184
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3448
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:5215
Item_int(longlong i, uint length=MY_INT64_NUM_DECIMAL_DIGITS)
Definition: item.h:5143
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3436
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:5228
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:5212
double val_real() override
Definition: item.h:5206
Item_int(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5179
Item * clone_item() const override
Definition: item.h:5216
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5227
Item_int(const POS &pos, const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5168
longlong value
Definition: item.h:5130
Item_int(int32 i, uint length=MY_INT32_NUM_DECIMAL_DIGITS)
Definition: item.h:5131
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:7028
void init(const char *str_arg, uint length)
Init an item from a string we KNOW points to a valid longlong.
Definition: item.cc:3427
uint decimal_precision() const override
Definition: item.h:5223
Item_int(const POS &pos, int32 i, uint length=MY_INT32_NUM_DECIMAL_DIGITS)
Definition: item.h:5137
Item_int(const Item_int *item_arg)
Definition: item.h:5155
Item_int(const char *str_arg, uint length)
Definition: item.h:5175
void set_max_size(uint length)
Definition: item.h:5190
String * val_str(String *) override
Definition: item.cc:3441
Item_num super
Definition: item.h:5127
enum Type type() const override
Definition: item.h:5200
Item_int(ulonglong i, uint length=MY_INT64_NUM_DECIMAL_DIGITS)
Definition: item.h:5148
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7052
Item_int(const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5162
Item_num * neg() override
Definition: item.h:5219
longlong val_int() override
Definition: item.h:5202
A class that represents a constant JSON value.
Definition: item.h:7315
unique_ptr_destroy_only< Json_wrapper > m_value
Definition: item.h:7316
longlong val_int() override
Definition: item.cc:7483
Item_result result_type() const override
Definition: item.h:7325
bool get_date(MYSQL_TIME *ltime, my_time_flags_t) override
Definition: item.cc:7498
~Item_json() override
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:7504
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item.cc:7461
Item * clone_item() const override
Definition: item.cc:7509
Item_json(unique_ptr_destroy_only< Json_wrapper > value, const Item_name_string &name)
Definition: item.cc:7452
my_decimal * val_decimal(my_decimal *buf) override
Definition: item.cc:7494
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:7467
double val_real() override
Definition: item.cc:7479
String * val_str(String *str) override
Definition: item.cc:7487
enum Type type() const override
Definition: item.h:7322
The class Item_multi_eq is used to represent conjunctions of equality predicates of the form field1 =...
Definition: item_cmpfunc.h:2664
Definition: item.h:4058
Item * value_item
Definition: item.h:4061
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:4090
Item * name_item
Definition: item.h:4062
Item_result result_type() const override
Definition: item.h:4082
bool fix_fields(THD *, Item **) override
Definition: item.cc:2100
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:2046
bool valid_args
Definition: item.h:4063
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:2029
bool cache_const_expr_analyzer(uchar **) override
Check if an item is a constant one and can be cached.
Definition: item.h:4084
longlong val_int() override
Definition: item.cc:2015
double val_real() override
Definition: item.cc:2008
Item_name_const(const POS &pos, Item *name_arg, Item *val)
Definition: item.cc:2048
Item super
Definition: item.h:4059
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2126
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:2041
enum Type type() const override
Definition: item.h:4071
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:2036
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:2053
String * val_str(String *sp) override
Definition: item.cc:2022
Storage for Item names.
Definition: item.h:370
void set_autogenerated(bool is_autogenerated)
Set m_is_autogenerated flag to the given value.
Definition: item.h:381
bool is_autogenerated() const
Return the auto-generated flag.
Definition: item.h:387
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:1456
Item_name_string()
Definition: item.h:375
Item_name_string(const Name_string name)
Definition: item.h:376
bool m_is_autogenerated
Definition: item.h:372
Definition: item.h:4739
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store null in field.
Definition: item.cc:6826
Item_null()
Definition: item.h:4753
bool send(Protocol *protocol, String *str) override
Pack data in buffer for sending.
Definition: item.cc:7448
void print(const THD *, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.h:4783
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3766
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item.h:4775
Item_basic_constant super
Definition: item.h:4740
Item_result result_type() const override
Definition: item.h:4779
Item_null(const POS &pos)
Definition: item.h:4757
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4788
Item * clone_item() const override
Definition: item.h:4780
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.h:4771
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:4772
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:4781
bool get_time(MYSQL_TIME *) override
Definition: item.h:4776
double val_real() override
Definition: item.cc:3768
longlong val_int() override
Definition: item.cc:3774
Item_null(const Name_string &name_par)
Definition: item.h:4762
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item.cc:3790
String * val_str(String *str) override
Definition: item.cc:3781
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3788
enum Type type() const override
Definition: item.h:4767
void init()
Definition: item.h:4742
Definition: item.h:4114
virtual Item_num * neg()=0
Item_basic_constant super
Definition: item.h:4115
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4122
Item_num()
Definition: item.h:4118
Item_num(const POS &pos)
Definition: item.h:4119
Definition: item.h:6282
bool fix_fields(THD *, Item **) override
Prepare referenced outer field then call usual Item_ref::fix_fields.
Definition: item.cc:8827
Item * replace_outer_ref(uchar *) override
Definition: item.cc:8889
Query_block * qualifying
Qualifying query of this outer ref (i.e.
Definition: item.h:6290
bool found_in_select_list
Definition: item.h:6300
Ref_Type ref_type() const override
Definition: item.h:6334
Item * outer_ref
Definition: item.h:6293
Item_outer_ref(Name_resolution_context *context_arg, Item_ident *ident_arg, Query_block *qualifying)
Definition: item.h:6301
Item_ref super
Definition: item.h:6283
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:6316
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:6332
table_map used_tables() const override
Definition: item.h:6329
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:8878
Item_sum * in_sum_func
Definition: item.h:6295
Dynamic parameters used as placeholders ('?') inside prepared statements.
Definition: item.h:4793
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:5019
enum_field_types data_type_source() const
Definition: item.h:5023
void reset()
Resets parameter after execution.
Definition: item.cc:4293
void set_null()
Definition: item.cc:4028
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:4997
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:4571
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:4942
bool is_type_inherited() const
Definition: item.h:4971
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:4443
double real
Definition: item.h:4834
void set_param_state(enum enum_item_param_state state)
Definition: item.h:4812
bool is_type_pinned() const
Definition: item.h:4977
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:5123
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:4306
String * val_str(String *) override
Definition: item.cc:4472
void sync_clones()
This should be called after any modification done to this Item, to propagate the said modification to...
Definition: item.cc:4000
void set_collation_actual(const CHARSET_INFO *coll)
Definition: item.h:4986
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:4508
void set_out_param_info(Send_field *info) override
Setter of Item_param::m_out_param_info.
Definition: item.cc:5061
bool set_from_user_var(THD *thd, const user_var_entry *entry)
Set parameter value from user variable value.
Definition: item.cc:4201
Item_result m_result_type
Result type of parameter.
Definition: item.h:4927
uint pos_in_query
Definition: item.h:4958
bool is_unsigned_actual() const
Definition: item.h:4980
void set_data_type_source(enum_field_types data_type, bool unsigned_val)
Definition: item.h:5010
bool add_clone(Item_param *i)
Definition: item.h:5074
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:5055
longlong integer
Definition: item.h:4833
void pin_data_type() override
Pin the currently resolved data type for this parameter.
Definition: item.h:4974
const CHARSET_INFO * m_collation_source
The character set and collation of the source parameter value.
Definition: item.h:4917
bool is_non_const_over_literals(uchar *) override
Definition: item.h:5068
String str_value_ptr
Definition: item.h:4830
MYSQL_TIME time
Definition: item.h:4835
const Send_field * get_out_param_info() const override
Getter of Item_param::m_out_param_info.
Definition: item.cc:5080
enum_field_types data_type_actual() const
Definition: item.h:5025
my_decimal decimal_value
Definition: item.h:4831
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:5077
Item_result result_type() const override
Definition: item.h:4964
enum_field_types m_data_type_actual
The actual data type of the parameter value provided by the user.
Definition: item.h:4908
void set_decimal(const char *str, ulong length)
Set decimal parameter value from string.
Definition: item.cc:4072
void make_field(Send_field *field) override
Fill meta-data information for the corresponding column in a result set.
Definition: item.cc:5092
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:5096
enum_item_param_state
Definition: item.h:4801
@ STRING_VALUE
Definition: item.h:4806
@ DECIMAL_VALUE
Definition: item.h:4809
@ NO_VALUE
Definition: item.h:4802
@ REAL_VALUE
Definition: item.h:4805
@ TIME_VALUE
holds TIME, DATE, DATETIME
Definition: item.h:4807
@ LONG_DATA_VALUE
Definition: item.h:4808
@ INT_VALUE
Definition: item.h:4804
@ NULL_VALUE
Definition: item.h:4803
bool get_date(MYSQL_TIME *tm, my_time_flags_t fuzzydate) override
Definition: item.cc:4352
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:4887
enum Type type() const override
Definition: item.h:4965
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:4936
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:5090
void set_int(longlong i)
Definition: item.cc:4037
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:4936
bool convert_value()
Convert value according to the following rules:
Definition: item.cc:4633
void set_data_type_inherited() override
Set the currently resolved data type for this parameter as inherited.
Definition: item.h:4968
const CHARSET_INFO * collation_actual() const
Definition: item.h:4994
bool fix_fields(THD *thd, Item **ref) override
Definition: item.cc:3868
bool get_time(MYSQL_TIME *tm) override
Definition: item.cc:4334
Send_field * m_out_param_info
Definition: item.h:5102
bool do_itemize(Parse_context *pc, Item **item) override
The core function that does the actual itemization.
Definition: item.cc:3804
void set_collation_source(const CHARSET_INFO *coll)
Definition: item.h:4982
const CHARSET_INFO * collation_source() const
Definition: item.h:4991
longlong val_int() override
Definition: item.cc:4409
bool set_str(const char *str, size_t length)
Definition: item.cc:4132
bool m_unsigned_actual
Used when actual value is integer to indicate whether value is unsigned.
Definition: item.h:4910
bool m_type_inherited
True if type of parameter is inherited from parent object (like a typecast).
Definition: item.h:4845
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:4932
double val_real() override
Definition: item.cc:4370
void set_time(MYSQL_TIME *tm, enum_mysql_timestamp_type type)
Set parameter value from MYSQL_TIME value.
Definition: item.cc:4100
enum_field_types actual_data_type() const override
Retrieve actual data type for an item.
Definition: item.h:5027
enum enum_item_param_state param_state() const
Definition: item.h:4816
union Item_param::@62 value
Item * clone_item() const override
Definition: item.cc:4908
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:4925
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:4970
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:4856
bool propagate_type(THD *thd, const Type_properties &type) override
Propagate data type specifications into parameters and user variables.
Definition: item.cc:3922
void set_double(double i)
Definition: item.cc:4053
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:4818
bool set_longdata(const char *str, ulong length)
Definition: item.cc:4160
void copy_param_actual_type(Item_param *from)
Definition: item.cc:4519
Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg)
Definition: item.cc:3797
table_map used_tables() const override
Definition: item.h:5052
void set_data_type_actual(enum_field_types data_type)
Definition: item.h:5015
Item super
Definition: item.h:4794
Definition: item.h:5695
Item_partition_func_safe_string(const Name_string name, size_t length, const CHARSET_INFO *cs=nullptr)
Definition: item.h:5697
Definition: item.h:6346
Item_ref_null_helper(const Item_ref_null_helper &ref_null_helper, Item **item)
Definition: item.h:6356
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:5152
bool val_bool() override
Definition: item.cc:5158
String * val_str(String *s) override
Definition: item.cc:5164
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:5170
Item_in_subselect * owner
Definition: item.h:6350
Item_ref_null_helper(Name_resolution_context *context_arg, Item_in_subselect *master, Item **item)
Definition: item.h:6353
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:5146
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.cc:5140
longlong val_int() override
Definition: item.cc:5134
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:8748
Item_ref super
Definition: item.h:6347
double val_real() override
Definition: item.cc:5128
Ref_Type ref_type() const override
Definition: item.h:6369
table_map used_tables() const override
Definition: item.h:6373
Definition: item.h:5898
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:8597
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item.h:5996
bool created_by_in2exists() const override
Whether this Item was created by the IN->EXISTS subquery transformation.
Definition: item.h:6106
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:8684
bool collect_item_field_or_ref_processor(uchar *arg) override
Definition: item.cc:8759
bool is_result_field() const override
Definition: item.h:6017
void set_properties()
Definition: item.cc:8531
table_map used_tables() const override
Definition: item.h:5988
Item_field * field_for_view_update() override
Definition: item.h:6060
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.cc:8647
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.h:5957
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:8704
Item_ref(THD *thd, Item_ref *item)
Definition: item.h:5943
Item ** addr(uint i) override
Definition: item.h:6074
void traverse_cond(Cond_traverser traverser, void *arg, traverse_order order) override
Definition: item.h:6040
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:8728
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the item from the item tree.
Definition: item.cc:8206
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:8289
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:6112
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:6121
Item_result result_type() const override
Definition: item.h:5979
void make_field(Send_field *field) override
Definition: item.cc:8712
void bring_value() override
Definition: item.h:6087
uint cols() const override
Definition: item.h:6066
Item ** ref_pointer() const
Definition: item.h:5952
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:8677
bool val_bool() override
Definition: item.cc:8663
bool is_outer_field() const override
Definition: item.h:6100
bool null_inside() override
Definition: item.h:6083
void set_result_field(Field *field) override
Definition: item.h:6016
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:6091
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:8614
Item * real_item() override
Definition: item.h:6019
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:8655
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:5983
Item_result cast_to_int_type() const override
Definition: item.h:6118
Ref_Type
Definition: item.h:5905
@ NULL_HELPER_REF
Definition: item.h:5905
@ VIEW_REF
Definition: item.h:5905
@ REF
Definition: item.h:5905
@ AGGREGATE_REF
Definition: item.h:5905
@ OUTER_REF
Definition: item.h:5905
String * val_str(String *tmp) override
Definition: item.cc:8670
Field * result_field
Definition: item.h:5911
bool explain_subquery_checker(uchar **) override
Definition: item.h:6047
void link_referenced_item()
Definition: item.h:5954
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:6124
bool is_non_const_over_literals(uchar *) override
Definition: item.h:6111
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:8551
const Item * real_item() const override
Definition: item.h:6024
Item_ref(const POS &pos, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:5918
Field * get_result_field() const override
Definition: item.h:6018
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item.h:5981
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:6030
enum Type type() const override
Definition: item.h:5956
bool send(Protocol *prot, String *tmp) override
This is only called from items that is not of type item_field.
Definition: item.cc:8629
bool pusheddown_depended_from
Definition: item.h:5908
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:6127
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:8895
virtual Ref_Type ref_type() const
Definition: item.h:6063
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:6098
Item * transform(Item_transformer, uchar *arg) override
Transform an Item_ref object with a transformer callback function.
Definition: item.cc:8567
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:11044
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:6006
Item * element_index(uint i) override
Definition: item.h:6070
bool check_cols(uint c) override
Definition: item.h:6078
Item ** m_ref_item
Indirect pointer to the referenced item.
Definition: item.h:5915
longlong val_int() override
Definition: item.cc:8640
Item * ref_item() const
Definition: item.h:5949
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:8698
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:8691
double val_real() override
Definition: item.cc:8633
Item with result field.
Definition: item.h:5833
Item_result_field(const POS &pos)
Definition: item.h:5838
Field * tmp_table_field(TABLE *) override
Definition: item.h:5844
Field * result_field
Definition: item.h:5835
int raise_decimal_overflow()
Definition: item.h:5892
longlong raise_integer_overflow()
Definition: item.h:5887
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:5843
Item_result_field(THD *thd, const Item_result_field *item)
Definition: item.h:5841
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:5872
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:5864
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:5863
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:10883
void raise_numeric_overflow(const char *type_name)
Definition: item.cc:10889
Item_result_field()=default
double raise_float_overflow()
Definition: item.h:5882
bool is_result_field() const override
Definition: item.h:5859
table_map used_tables() const override
Definition: item.h:5845
void set_result_field(Field *field) override
Definition: item.h:5858
Field * get_result_field() const override
Definition: item.h:5860
Definition: item.h:5738
Item_return_int(const char *name_arg, uint length, enum_field_types field_type_arg, longlong value_arg=0)
Definition: item.h:5740
Class that represents scalar subquery and row subquery.
Definition: item_subselect.h:283
Definition: item.h:3887
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:3922
Item_sp_variable(const Name_string sp_var_name)
Definition: item.cc:1815
Name_string m_name
Definition: item.h:3889
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:1899
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:1891
String * val_str(String *sp) override
Definition: item.cc:1850
bool fix_fields(THD *thd, Item **) override
Definition: item.cc:1818
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item.cc:1883
void make_field(Send_field *field) override
Definition: item.h:3936
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:3942
double val_real() override
Definition: item.cc:1834
longlong val_int() override
Definition: item.cc:1842
table_map used_tables() const override
Definition: item.h:3903
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:1905
bool send(Protocol *protocol, String *str) override
This is only called from items that is not of type item_field.
Definition: item.h:3917
sp_head * m_sp
Definition: item.h:3897
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:1911
Definition: item.h:3953
bool limit_clause_param
Definition: item.h:3963
Item_result result_type() const override
Definition: item.h:4001
bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override
Definition: item.cc:1967
uint len_in_query
Definition: item.h:3982
bool is_splocal() const override
Definition: item.h:3988
uint get_var_idx() const
Definition: item.h:3998
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:1948
uint m_var_idx
Definition: item.h:3954
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:4010
uint pos_in_query
Definition: item.h:3974
Item * this_item() override
Definition: item.cc:1930
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:1917
Type type() const override
Definition: item.h:4000
Item ** this_item_addr(THD *thd, Item **) override
Definition: item.cc:1942
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:1955
Definition: item.h:5665
void print(const THD *, String *str, enum_query_type) const override
Definition: item.h:5681
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:5669
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5685
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:5686
const Name_string func_name
Definition: item.h:5666
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:5674
Definition: item.h:5463
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:5505
String * val_str(String *) override
Definition: item.h:5589
Item_string(const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5499
void set_cs_specified(bool cs_specified)
Set the value of m_cs_specified attribute.
Definition: item.h:5649
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:1551
bool is_cs_specified() const
Return true if character-set-introducer was explicitly specified in the original query for this item ...
Definition: item.h:5637
Item_string(const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE)
Definition: item.h:5513
bool get_time(MYSQL_TIME *ltime) override
Definition: item.h:5597
Item_string(const POS &pos)
Definition: item.h:5467
void append(char *str, size_t length)
Definition: item.h:5609
void init(const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv, uint repertoire)
Definition: item.h:5471
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5616
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:5552
void mark_result_as_const()
Definition: item.h:5653
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:6978
Item_result result_type() const override
Definition: item.h:5600
Item * clone_item() const override
Definition: item.h:5605
bool m_cs_specified
Definition: item.h:5656
void print(const THD *thd, String *str, enum_query_type query_type) const override
Definition: item.cc:3634
void set_value_collation()
Update collation of string value to be according to item's collation.
Definition: item.h:5580
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:5523
Item_basic_constant super
Definition: item.h:5464
void set_str_with_copy(const char *str_arg, uint length_arg)
Definition: item.h:5572
double val_real() override
Definition: item.cc:3706
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:5536
void set_repertoire_from_value()
Definition: item.h:5582
longlong val_int() override
Definition: item.cc:3755
bool eq_binary(const Item_string *item) const
Definition: item.h:5602
enum Type type() const override
Definition: item.h:5586
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3762
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.h:5594
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:6411
Item_temporal_with_ref(enum_field_types field_type_arg, uint8 decimals_arg, longlong i, Item *ref_arg, bool unsigned_arg)
Definition: item.h:6413
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7096
bool get_time(MYSQL_TIME *) override
Definition: item.h:6424
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item.h:6420
Definition: item.h:5252
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:7034
bool get_time(MYSQL_TIME *) override
Definition: item.h:5280
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item.h:5276
Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5262
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.h:5274
Item * clone_item() const override
Definition: item.h:5271
Item_temporal(enum_field_types field_type_arg, longlong i)
Definition: item.h:5258
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:5275
Definition: item.h:6463
longlong val_time_temporal() override
Return time value of item in packed longlong format.
Definition: item.h:6475
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:6476
Item_time_with_ref(uint8 decimals_arg, longlong i, Item *ref_arg)
Constructor for Item_time_with_ref.
Definition: item.h:6471
Item * clone_item() const override
Definition: item.cc:7076
Utility mixin class to be able to walk() only parts of item trees.
Definition: item.h:735
bool is_stopped(const Item *i)
Definition: item.h:752
const Item * stopped_at_item
Definition: item.h:773
void stop_at(const Item *i)
Stops walking children of this item.
Definition: item.h:743
Item_tree_walker(const Item_tree_walker &)=delete
Item_tree_walker()
Definition: item.h:737
Item_tree_walker & operator=(const Item_tree_walker &)=delete
~Item_tree_walker()
Definition: item.h:738
Represents NEW/OLD version of field of row which is changed/read in trigger.
Definition: item.h:6703
SQL_I_List< Item_trigger_field > * next_trig_field_list
Definition: item.h:6713
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9479
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:9363
uint field_idx
Definition: item.h:6715
GRANT_INFO * table_grants
Definition: item.h:6796
bool check_column_privileges(uchar *arg) override
Check privileges of base table column.
Definition: item.cc:9468
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:6752
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:6730
bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override
Definition: item.cc:9384
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:6719
bool set_value(THD *thd, Item **it)
Definition: item.h:6777
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9375
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:6773
Item_trigger_field * next_trg_field
Definition: item.h:6708
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9486
Access_bitmask want_privilege
Definition: item.h:6795
enum Type type() const override
Definition: item.h:6742
Item * copy_or_same(THD *) override
Definition: item.h:6751
Table_trigger_field_support * triggers
Definition: item.h:6717
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:6750
enum_trigger_variable_type trigger_var_type
Definition: item.h:6706
table_map used_tables() const override
Definition: item.h:6749
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9411
bool read_only
Definition: item.h:6801
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9447
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:6758
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:6765
void set_required_privilege(Access_bitmask privilege) override
Set required privileges for accessing the parameter.
Definition: item.h:6754
Item_type_holder stores an aggregation of name, type and type specification of UNIONS and derived tab...
Definition: item.h:7238
Item_aggregate_type super
Definition: item.h:7239
enum Type type() const override
Definition: item.h:7247
table_map used_tables() const override
Class is used in type aggregation only - this is needed to ensure that it is not attempted to be eval...
Definition: item.h:7253
Item_type_holder(THD *thd, Item *item)
Definition: item.h:7245
String * val_str(String *) override
Definition: item.cc:10770
longlong val_int() override
Definition: item.cc:10760
bool get_date(MYSQL_TIME *, my_time_flags_t) override
Definition: item.cc:10775
bool get_time(MYSQL_TIME *) override
Definition: item.cc:10780
double val_real() override
Definition: item.cc:10755
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10765
Definition: item.h:5286
uint decimal_precision() const override
Definition: item.h:5317
Item * clone_item() const override
Definition: item.h:5311
Item_num * neg() override
Definition: item.cc:7107
Item_uint(const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5301
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3477
Item_uint(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5295
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:6984
double val_real() override
Definition: item.h:5305
String * val_str(String *) override
Definition: item.cc:3470
Item_uint(const char *str_arg, uint length)
Definition: item.h:5292
Item_uint(ulonglong i)
Definition: item.h:5300
Reference item that encapsulates both the type and the contained items of a single column of a VALUES...
Definition: item.h:7278
Item_values_column(THD *thd, Item *ref)
Definition: item.cc:10793
void set_value(Item *new_value)
Definition: item.h:7309
Item * m_value_ref
Definition: item.h:7282
table_map used_tables() const override
Definition: item.h:7310
Item_aggregate_type super
Definition: item.h:7279
longlong val_int() override
Definition: item.cc:10808
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:10785
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10815
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:10847
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:10797
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:10831
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override
Definition: item.cc:10863
enum Type type() const override
Definition: item.h:7308
String * val_str(String *tmp) override
Definition: item.cc:10840
void add_used_tables(Item *value)
Definition: item.cc:10879
bool get_time(MYSQL_TIME *ltime) override
Definition: item.cc:10871
double val_real() override
Definition: item.cc:10801
bool val_bool() override
Definition: item.cc:10823
table_map m_aggregated_used_tables
Definition: item.h:7289
Class for fields from derived tables and views.
Definition: item.h:6138
Ref_Type ref_type() const override
Definition: item.h:6230
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:6270
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:6233
Item * get_tmp_table_item(THD *thd) override
If an Item is materialized in a temporary table, a different Item may have to be used in the part of ...
Definition: item.h:6224
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:8970
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:6142
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:8989
bool has_null_row() const
Definition: item.h:6262
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:8981
double val_real() override
Definition: item.cc:8930
bool send(Protocol *prot, String *tmp) override
This is only called from items that is not of type item_field.
Definition: item.cc:8976
bool fix_fields(THD *, Item **) override
Prepare referenced field then call usual Item_ref::fix_fields .
Definition: item.cc:8779
bool val_bool() override
Definition: item.cc:8954
Item * replace_item_view_ref(uchar *arg) override
Definition: item.cc:9016
longlong val_int() override
Definition: item.cc:8922
Item_ref super
Definition: item.h:6139
bool subst_argument_checker(uchar **) override
Definition: item.h:6168
Table_ref * get_first_inner_table() const
Definition: item.h:6254
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item.cc:8962
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:6176
String * val_str(String *str) override
Definition: item.cc:8946
bool check_column_privileges(uchar *arg) override
Check privileges of view column.
Definition: item.cc:1392
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:9046
my_decimal * val_decimal(my_decimal *dec) override
Definition: item.cc:8938
bool eq(const Item *item) const override
Compare two view column references for equality.
Definition: item.cc:8911
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:927
void increment_ref_count()
Increment reference count.
Definition: item.h:3416
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:3369
String * make_empty_result()
Sets the result value of the function an empty string, using the current character set.
Definition: item.h:938
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:3352
String str_value
str_values's main purpose is to cache the value in save_in_field
Definition: item.h:3576
bool skip_itemize(Item **res)
Helper function to skip itemize() for grammar-allocated items.
Definition: item.h:1200
void set_nullable(bool nullable)
Definition: item.h:3688
virtual bool change_context_processor(uchar *)
Definition: item.h:2813
void set_data_type_date()
Set all type properties for Item of DATE type.
Definition: item.h:1693
void set_data_type_blob(enum_field_types type, uint32 max_l)
Set the Item to be of BLOB type.
Definition: item.h:1680
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:3127
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3583
bool get_time_from_decimal(MYSQL_TIME *ltime)
Convert val_decimal() to time in MYSQL_TIME.
Definition: item.cc:1667
ulonglong val_uint()
Definition: item.h:1942
bool has_subquery() const
Definition: item.h:3447
virtual bool subst_argument_checker(uchar **arg)
Definition: item.h:3054
CostOfItem cost() const
Definition: item.h:3358
bool contains_item(uchar *arg)
Definition: item.h:2736
void set_data_type_bool()
Definition: item.h:1521
longlong val_int_from_decimal()
Definition: item.cc:481
bool has_stored_program() const
Definition: item.h:3450
String * val_string_from_int(String *str)
Definition: item.cc:310
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:3562
void set_data_type(enum_field_types data_type)
Set the data type of the current Item.
Definition: item.h:1510
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:2783
bool has_aggregation() const
Definition: item.h:3455
virtual bool find_field_processor(uchar *)
Is this an Item_field which references the given Field argument?
Definition: item.h:2819
longlong val_int_from_datetime()
Definition: item.cc:512
void set_data_type_string(ulonglong max_char_length_arg)
Set the Item to be variable length string.
Definition: item.h:1614
my_decimal * val_decimal_from_string(my_decimal *decimal_value)
Definition: item.cc:369
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:7834
bool is_nullable() const
Definition: item.h:3687
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:783
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:1423
virtual enum_field_types actual_data_type() const
Retrieve actual data type for an item.
Definition: item.h:1486
bool get_time_from_string(MYSQL_TIME *ltime)
Convert val_str() to time in MYSQL_TIME.
Definition: item.cc:1648
static const CHARSET_INFO * default_charset()
Definition: item.cc:1760
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:6443
virtual bool propagate_type(THD *thd, const Type_properties &type)
Propagate data type specifications into parameters and user variables.
Definition: item.h:1311
virtual Item * replace_func_call(uchar *)
Definition: item.h:3266
String * val_string_from_date(String *str)
Definition: item.cc:335
bool is_non_deterministic() const
Definition: item.h:2461
void set_subquery()
Set the "has subquery" property.
Definition: item.h:3440
void fix_char_length(uint32 max_char_length_arg)
Definition: item.h:3390
void operator=(Item &)=delete
virtual bool is_bool_func() const
Definition: item.h:2567
void mark_subqueries_optimized_away()
Definition: item.h:3498
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:463
virtual bool disable_constant_propagation(uchar *)
Definition: item.h:3063
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:158
bool has_grouping_set_dep() const
Definition: item.h:3473
uint8 m_data_type
Data type assigned to Item.
Definition: item.h:3667
void set_data_type_float()
Set the data type of the Item to be single precision floating point.
Definition: item.h:1584
void reset_aggregation()
Reset the "has aggregation" property.
Definition: item.h:3461
virtual Item * this_item()
Definition: item.h:3165
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:891
bool is_temporal_with_date() const
Definition: item.h:3312
virtual bool strip_db_table_name_processor(uchar *)
Definition: item.h:3551
static Item_result type_to_result(enum_field_types type)
Definition: item.h:1039
virtual table_map used_tables() const
Definition: item.h:2361
String * val_string_from_datetime(String *str)
Definition: item.cc:325
bool get_time_from_real(MYSQL_TIME *ltime)
Convert val_real() to time in MYSQL_TIME.
Definition: item.cc:1658
virtual bool equality_substitution_analyzer(uchar **)
Definition: item.h:3002
virtual bool find_item_in_field_list_processor(uchar *)
Definition: item.h:2812
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:3496
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:1272
virtual Item * real_item()
Definition: item.h:2580
virtual Item * equality_substitution_transformer(uchar *)
Definition: item.h:3004
void set_stored_program()
Set the "has stored program" property.
Definition: item.h:3443
virtual bool eq(const Item *) const
Compare this item with another item for equality.
Definition: item.cc:1482
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:3768
bool get_date_from_decimal(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_decimal() to date in MYSQL_TIME.
Definition: item.cc:1580
virtual enum_field_types default_data_type() const
Get the default data (output) type for the specific item.
Definition: item.h:1499
void set_data_type_string(uint32 max_l, const CHARSET_INFO *cs)
Set the Item to be variable length string.
Definition: item.h:1632
virtual bool explain_subquery_checker(uchar **)
Definition: item.h:3058
bool get_date_from_time(MYSQL_TIME *ltime)
Convert get_time() from time to date in MYSQL_TIME.
Definition: item.cc:1598
bool get_time_from_datetime(MYSQL_TIME *ltime)
Convert datetime to time.
Definition: item.cc:1693
uint m_ref_count
Number of references to this item.
Definition: item.h:3664
virtual Field * make_string_field(TABLE *table) const
Create a field to hold a string value from an item.
Definition: item.cc:6565
virtual bool replace_equal_field_checker(uchar **)
Definition: item.h:3070
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:3435
virtual bool check_valid_arguments_processor(uchar *)
Definition: item.h:3076
longlong val_int_from_date()
Definition: item.cc:504
virtual Settable_routine_parameter * get_settable_routine_parameter()
Definition: item.h:3309
virtual Item * equal_fields_propagator(uchar *)
Definition: item.h:3061
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:6863
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:2809
virtual bool update_depended_from(uchar *)
Definition: item.h:2986
void set_data_type_double()
Set the data type of the Item to be double precision floating point.
Definition: item.h:1576
my_decimal * val_decimal_from_int(my_decimal *decimal_value)
Definition: item.cc:362
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:803
Item_result cmp_context
Comparison context.
Definition: item.h:3646
virtual void allow_array_cast()
A helper function to ensure proper usage of CAST(.
Definition: item.h:3781
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:3192
Item(const Item &)=delete
virtual Item * replace_equal_field(uchar *)
Definition: item.h:3069
virtual Item * element_index(uint)
Definition: item.h:3176
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:941
virtual void traverse_cond(Cond_traverser traverser, void *arg, traverse_order)
Definition: item.h:2717
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:6600
bool get_time_from_date(MYSQL_TIME *ltime)
Convert date to time.
Definition: item.cc:1685
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:3185
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:3752
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:1478
virtual bool collect_outer_field_processor(uchar *)
Definition: item.h:2741
static constexpr uint8 PROP_SUBQUERY
Set of properties that are calculated by accumulation from underlying items.
Definition: item.h:3739
Item_name_string item_name
Name from query.
Definition: item.h:3584
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:1535
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:1498
bool eq_by_collation(Item *item, const CHARSET_INFO *cs)
Compare two items using a given collation.
Definition: item.cc:6538
void print_item_w_name(const THD *thd, String *, enum_query_type query_type) const
Definition: item.cc:861
virtual String * val_str_ascii(String *str)
Definition: item.cc:270
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:5119
virtual bool check_column_privileges(uchar *thd)
Check privileges.
Definition: item.h:2878
bool fixed
True if item has been resolved.
Definition: item.h:3676
static bool bit_func_returns_binary(const Item *a, const Item *b)
Definition: item_func.cc:3298
enum_const_item_cache
How to cache constant JSON data.
Definition: item.h:995
@ CACHE_NONE
Don't cache.
Definition: item.h:997
@ CACHE_JSON_VALUE
Source data is a JSON string, parse and cache result.
Definition: item.h:999
@ CACHE_JSON_ATOM
Source data is SQL scalar, convert and cache result.
Definition: item.h:1001
virtual Item_result result_type() const
Definition: item.h:1448
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:490
bool null_value
True if item is null.
Definition: item.h:3713
virtual longlong val_time_temporal()
Return time value of item in packed longlong format.
Definition: item.cc:406
Type
Definition: item.h:962
@ SUBQUERY_ITEM
A subquery or predicate referencing a subquery.
Definition: item.h:978
@ ROW_ITEM
A row of other items.
Definition: item.h:979
@ INVALID_ITEM
Definition: item.h:963
@ INSERT_VALUE_ITEM
A value from a VALUES function (deprecated).
Definition: item.h:977
@ CACHE_ITEM
An internal item used to cache values.
Definition: item.h:980
@ REAL_ITEM
A floating-point literal value.
Definition: item.h:971
@ TRIGGER_FIELD_ITEM
An OLD or NEW field, used in trigger definitions.
Definition: item.h:984
@ SUM_FUNC_ITEM
A grouped aggregate function, or window function.
Definition: item.h:966
@ TYPE_HOLDER_ITEM
An internal item used to help aggregate a type.
Definition: item.h:981
@ NAME_CONST_ITEM
A NAME_CONST expression.
Definition: item.h:987
@ REF_ITEM
An indirect reference to another item.
Definition: item.h:976
@ FIELD_ITEM
A reference to a field (column) in a table.
Definition: item.h:964
@ INT_ITEM
An integer literal value.
Definition: item.h:969
@ FUNC_ITEM
A function call reference.
Definition: item.h:965
@ COND_ITEM
An AND or OR condition.
Definition: item.h:975
@ XPATH_NODESET_ITEM
Used in XPATH expressions.
Definition: item.h:985
@ PARAM_ITEM
A dynamic parameter used in a prepared statement.
Definition: item.h:982
@ ROUTINE_FIELD_ITEM
A variable inside a routine (proc, func, trigger)
Definition: item.h:983
@ DECIMAL_ITEM
A decimal literal value.
Definition: item.h:970
@ VALUES_COLUMN_ITEM
A value from a VALUES clause.
Definition: item.h:986
@ HEX_BIN_ITEM
A hexadecimal or binary literal value.
Definition: item.h:973
@ NULL_ITEM
A NULL value.
Definition: item.h:972
@ AGGR_FIELD_ITEM
A special field for certain aggregate operations.
Definition: item.h:967
@ DEFAULT_VALUE_ITEM
A default value for a column.
Definition: item.h:974
@ STRING_ITEM
A string literal value.
Definition: item.h:968
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:2983
virtual Field * tmp_table_field(TABLE *)
Definition: item.h:2355
virtual bool check_cols(uint c)
Definition: item.cc:1418
virtual bool itemize(Parse_context *pc, Item **res) final
The same as contextualize() but with additional parameter.
Definition: item.h:1246
const bool is_parser_item
true if allocated directly by parser
Definition: item.h:3666
bool is_temporal_with_time() const
Definition: item.h:3318
virtual bool visitor_processor(uchar *arg)
A processor to handle the select lex visitor framework.
Definition: item.cc:910
Parse_tree_node super
Definition: item.h:928
virtual Item * replace_item_view_ref(uchar *)
Definition: item.h:3267
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:1718
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:3148
virtual const CHARSET_INFO * charset_for_protocol()
Definition: item.h:2602
void set_aggregation()
Set the "has aggregation" property.
Definition: item.h:3458
bool get_time_from_non_temporal(MYSQL_TIME *ltime)
Convert a non-temporal type to time.
Definition: item.cc:1723
virtual uint time_precision()
TIME precision of the item: 0..6.
Definition: item.cc:828
void delete_self()
Delete this item.
Definition: item.h:3300
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:3729
virtual uint datetime_precision()
DATETIME precision of the item: 0..6.
Definition: item.cc:843
virtual bool send(Protocol *protocol, String *str)
This is only called from items that is not of type item_field.
Definition: item.cc:7521
bool has_compatible_context(Item *item) const
Check whether this and the given item has compatible comparison context.
Definition: item.h:3333
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:3158
virtual void pin_data_type()
Pin the data type for the item.
Definition: item.h:1475
virtual bool cache_const_expr_analyzer(uchar **cache_item)
Check if an item is a constant one and can be cached.
Definition: item.cc:7704
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:3572
virtual bool collect_item_field_or_ref_processor(uchar *)
Definition: item.h:2740
virtual bool val_bool()
Definition: item.cc:242
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:1098
uint8 m_accum_properties
Definition: item.h:3754
type_conversion_status save_str_value_in_field(Field *field, String *result)
Definition: item.cc:574
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:3119
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:1608
virtual Item * update_value_transformer(uchar *)
Definition: item.h:3196
virtual Item * replace_outer_ref(uchar *)
Definition: item.h:3269
virtual bool reset_wf_state(uchar *arg)
Reset execution state for such window function types as determined by arg.
Definition: item.h:2854
void set_accum_properties(const Item *item)
Set accumulated properties for an Item.
Definition: item.h:3430
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:3548
virtual bool cast_incompatible_args(uchar *)
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item.h:2821
virtual longlong val_date_temporal()
Return date value of item in packed longlong format.
Definition: item.cc:412
bool visit_all_analyzer(uchar **)
Definition: item.h:2998
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:1453
my_decimal * val_decimal_from_date(my_decimal *decimal_value)
Definition: item.cc:388
longlong val_temporal_with_round(enum_field_types type, uint8 dec)
Get date or time value in packed longlong format.
Definition: item.cc:424
virtual void compute_cost(CostOfItem *root_cost) const
Compute the cost of evaluating this Item.
Definition: item.h:3557
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:7784
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:1772
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:3464
my_decimal * val_decimal_from_real(my_decimal *decimal_value)
Definition: item.cc:354
virtual bool collect_subqueries(uchar *)
Definition: item.h:2985
void aggregate_bit_properties(Item **items, uint nitems)
Set data type and properties of a BIT column.
Definition: item.cc:8002
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:3481
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:1291
void set_data_type_char(uint32 max_l)
Set the Item to be fixed length string.
Definition: item.h:1655
virtual bool null_inside()
Definition: item.h:3180
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:3714
virtual bool aggregate_check_group(uchar *)
Definition: item.h:2929
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:1325
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:1800
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:7888
longlong val_int_from_string()
Definition: item.cc:526
item_marker
< Values for member 'marker'
Definition: item.h:3603
@ MARKER_FUNC_DEP_NOT_NULL
When analyzing functional dependencies for only_full_group_by (says whether a nullable column can be ...
Definition: item.h:3617
@ MARKER_GROUP_BY_BIT
When creating an internal temporary table: marking group by fields.
Definition: item.h:3614
@ MARKER_TRAVERSAL
Used during traversal to avoid deleting an item twice.
Definition: item.h:3625
@ MARKER_DISTINCT_GROUP
When we change DISTINCT to GROUP BY: used for book-keeping of fields.
Definition: item.h:3620
@ MARKER_IMPLICIT_NE_ZERO
When contextualization or itemization adds an implicit comparison '0<>' (see make_condition()),...
Definition: item.h:3608
@ MARKER_NONE
Definition: item.h:3604
@ MARKER_COND_DERIVED_TABLE
When pushing conditions down to derived table: it says a condition contains only derived table's colu...
Definition: item.h:3623
@ MARKER_CONST_PROPAG
When doing constant propagation (e.g.
Definition: item.h:3611
@ MARKER_ICP_COND_USES_INDEX_ONLY
When pushing index conditions: it says whether a condition uses only indexed columns.
Definition: item.h:3628
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:3108
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:3585
virtual bool collect_grouped_aggregates(uchar *)
Definition: item.h:2984
virtual bool clean_up_after_removal(uchar *arg)
Clean up after removing the item from the item tree.
Definition: item.cc:7771
virtual cond_result eq_cmp_result() const
Definition: item.h:2396
uint32 max_char_length(const CHARSET_INFO *cs) const
Definition: item.h:3383
virtual Item * explain_subquery_propagator(uchar *)
Definition: item.h:3059
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:2927
bool evaluate(THD *thd, String *str)
Evaluate scalar item, possibly using the supplied buffer.
Definition: item.cc:7625
bool get_date_from_string(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_str() to date in MYSQL_TIME.
Definition: item.cc:1561
void set_wf()
Set the "has window function" property.
Definition: item.h:3467
virtual bool returns_array() const
Whether the item returns array of its data type.
Definition: item.h:3776
virtual void make_field(Send_field *field)
Definition: item.cc:6464
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:3398
void set_grouping_func()
Set the property: this item is a call to GROUPING.
Definition: item.h:3493
virtual void set_result_field(Field *)
Definition: item.h:2564
bool is_abandoned() const
Definition: item.h:3559
cond_result
Definition: item.h:990
@ COND_UNDEF
Definition: item.h:990
@ COND_TRUE
Definition: item.h:990
@ COND_FALSE
Definition: item.h:990
@ COND_OK
Definition: item.h:990
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:535
item_marker marker
This member has several successive meanings, depending on the phase we're in (.
Definition: item.h:3645
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:1460
traverse_order
Definition: item.h:992
@ POSTFIX
Definition: item.h:992
@ PREFIX
Definition: item.h:992
virtual bool is_strong_side_column_not_in_fd(uchar *)
Definition: item.h:2931
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:1700
bool m_abandoned
true if item has been fully de-referenced
Definition: item.h:3665
virtual bool inform_item_in_cond_of_tab(uchar *)
Definition: item.h:2881
static constexpr uint8 PROP_STORED_PROGRAM
Definition: item.h:3740
virtual const Item * real_item() const
Definition: item.h:2581
bool is_temporal() const
Definition: item.h:3321
bool is_temporal_with_date_and_time() const
Definition: item.h:3315
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:1514
uint8 decimals
Number of decimals in result when evaluating this item.
Definition: item.h:3685
virtual Item ** addr(uint)
Definition: item.h:3177
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:1597
virtual void set_can_use_prefix_key()
Definition: item.h:1300
void set_data_type_timestamp(uint8 fsp)
Set all properties for Item of TIMESTAMP type.
Definition: item.h:1731
bool get_date_from_non_temporal(MYSQL_TIME *ltime, my_time_flags_t fuzzydate)
Convert a non-temporal type to date.
Definition: item.cc:1629
bool do_contextualize(Parse_context *) override
Definition: item.h:1186
void set_data_type_string(uint32 max_l, const DTCollation &coll)
Set the Item to be variable length string.
Definition: item.h:1644
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:1363
uint decrement_ref_count()
Decrement reference count.
Definition: item.h:3422
Item * convert_charset(THD *thd, const CHARSET_INFO *tocs, bool ignore_errors=false)
Convert constant string in this object into the specified character set.
Definition: item.cc:1516
virtual bool find_item_processor(uchar *arg)
Definition: item.h:2814
virtual void no_rows_in_result()
Definition: item.h:2572
virtual bool add_field_to_set_processor(uchar *)
Item::walk function.
Definition: item.h:2791
virtual bool add_field_to_cond_set_processor(uchar *)
Item::walk function.
Definition: item.h:2800
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:3137
uint reference_count() const
Definition: item.h:3413
static enum_field_types result_to_type(Item_result result)
Definition: item.h:1019
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:3257
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:6831
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:3099
virtual bool is_splocal() const
Definition: item.h:3303
Bool_test
< Modifier for result transformation
Definition: item.h:1005
@ BOOL_NOT_FALSE
Definition: item.h:1010
@ BOOL_IS_UNKNOWN
Definition: item.h:1008
@ BOOL_NOT_TRUE
Definition: item.h:1009
@ BOOL_IS_TRUE
Definition: item.h:1006
@ BOOL_ALWAYS_FALSE
Definition: item.h:1015
@ BOOL_NOT_UNKNOWN
Definition: item.h:1011
@ BOOL_ALWAYS_TRUE
Definition: item.h:1014
@ BOOL_IS_FALSE
Definition: item.h:1007
@ BOOL_IDENTITY
Definition: item.h:1012
@ BOOL_NEGATED
Definition: item.h:1013
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:6487
virtual bool replace_field_processor(uchar *)
A processor that replaces any Fields with a Create_field_wrapper.
Definition: item.h:3518
virtual bool update_aggr_refs(uchar *)
A walker processor overridden by Item_aggregate_ref, q.v.
Definition: item.h:3281
virtual void notify_removal()
Called when an item has been removed, can be used to notify external objects about the removal,...
Definition: item.h:1278
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:1410
bool aggregate_type(const char *name, Item **items, uint count)
Aggregates data types from array of items into current item.
Definition: item.cc:615
virtual Item * replace_aggregate(uchar *)
Definition: item.h:3268
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:3710
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:3265
virtual bool mark_field_in_map(uchar *arg)
Mark underlying field in read or write map of a table.
Definition: item.h:2827
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:3724
bool get_date_from_int(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_int() to date in MYSQL_TIME.
Definition: item.cc:1589
virtual bool get_timeval(my_timeval *tm, int *warnings)
Get timestamp in "struct timeval" format.
Definition: item.cc:1746
bool m_is_window_function
True if item represents window func.
Definition: item.h:3715
bool may_eval_const_item(const THD *thd) const
Definition: item.cc:233
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:2836
Item * cache_const_expr_transformer(uchar *item)
Cache item if needed.
Definition: item.cc:8019
String * val_string_from_time(String *str)
Definition: item.cc:345
virtual Item ** this_item_addr(THD *, Item **addr_arg)
Definition: item.h:3172
virtual bool is_result_field() const
Definition: item.h:2565
virtual const Item * this_item() const
Definition: item.h:3166
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:7868
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:930
virtual enum_monotonicity_info get_monotonicity_info() const
Definition: item.h:1831
virtual bool collect_item_field_processor(uchar *)
Definition: item.h:2739
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:2996
uint32 max_length
Maximum length of result of evaluating this item, in number of bytes.
Definition: item.h:3601
bool get_date_from_real(MYSQL_TIME *ltime, my_time_flags_t flags)
Convert val_real() to date in MYSQL_TIME.
Definition: item.cc:1571
void set_data_type_longlong()
Set the data type of the Item to be longlong.
Definition: item.h:1552
static constexpr uint8 PROP_WINDOW_FUNCTION
Definition: item.h:3742
auto analyze_helper_thunk(uchar **arg)
See CompileItem.
Definition: item.h:2641
double val_real_from_string()
Definition: item.cc:472
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:7610
virtual bool gc_subst_analyzer(uchar **)
Analyzer function for GC substitution.
Definition: item.h:3506
void rename(char *new_name)
rename item (used for views, cleanup() return original name).
Definition: item.cc:921
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:7944
virtual bool is_column_not_in_fd(uchar *)
Definition: item.h:2933
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:3175
virtual Item * gc_subst_transformer(uchar *)
Transformer function for GC substitution.
Definition: item.h:3510
virtual Bool3 local_column(const Query_block *) const
Definition: item.h:2934
virtual void bring_value()
Definition: item.h:3182
void set_data_type_time(uint8 fsp)
Set all type properties for Item of TIME type.
Definition: item.h:1705
void set_data_type_decimal(uint8 precision, uint8 scale)
Set the data type of the Item to be decimal.
Definition: item.h:1566
CostOfItem m_cost
The cost of evaluating this item.
Definition: item.h:3673
void quick_fix_field()
Definition: item.h:1299
virtual bool used_tables_for_level(uchar *arg)
Return used table information for the specified query block (level).
Definition: item.h:2870
my_decimal * val_decimal_from_time(my_decimal *decimal_value)
Definition: item.cc:397
virtual Item_result cast_to_int_type() const
Definition: item.h:1821
type_conversion_status save_date_in_field(Field *field)
Definition: item.cc:542
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:2318
String * val_string_from_real(String *str)
Definition: item.cc:287
virtual bool is_non_const_over_literals(uchar *)
Definition: item.h:2815
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:1352
void set_data_type_char(uint32 max_l, const CHARSET_INFO *cs)
Set the Item to be fixed length string.
Definition: item.h:1669
bool has_grouping_func() const
Definition: item.h:3488
virtual void save_org_in_field(Field *field)
Definition: item.h:1428
static constexpr uint8 PROP_AGGREGATION
Definition: item.h:3741
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:1676
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:1469
String * val_string_from_decimal(String *str)
Definition: item.cc:317
virtual bool check_partition_func_processor(uchar *)
Check if a partition function is allowed.
Definition: item.h:3053
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:3747
virtual void bind_fields()
Bind objects from the current execution context to field objects in item trees.
Definition: item.h:2887
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1160
Definition: sql_list.h:494
Class used as argument to Item::walk() together with mark_field_in_map()
Definition: item.h:259
Mark_field(TABLE *table, enum_mark_columns mark)
Definition: item.h:261
Mark_field(enum_mark_columns mark)
Definition: item.h:262
TABLE *const table
If == NULL, update map of any table.
Definition: item.h:268
const enum_mark_columns mark
How to mark the map.
Definition: item.h:270
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Definition: item.h:516
Table_ref * save_next_local
Definition: item.h:522
void save_state(Name_resolution_context *context, Table_ref *table_list)
Definition: item.h:526
Table_ref * save_next_name_resolution_table
Definition: item.h:520
void update_next_local(Table_ref *table_list)
Definition: item.h:543
Table_ref * get_first_name_resolution_table()
Definition: item.h:547
Table_ref * save_table_list
Definition: item.h:518
bool save_resolve_in_select_list
Definition: item.h:521
Table_ref * save_first_name_resolution_table
Definition: item.h:519
void restore_state(Name_resolution_context *context, Table_ref *table_list)
Definition: item.h:535
Storage for name strings.
Definition: item.h:295
void copy(const char *str)
Definition: item.h:332
Name_string(const char *str, size_t length)
Definition: item.h:311
void copy(const LEX_STRING lex)
Definition: item.h:335
void set_or_copy(const char *str, size_t length, bool is_null_terminated)
Definition: item.h:297
bool eq_safe(const Name_string name) const
Definition: item.h:350
Name_string(const LEX_STRING str, bool is_null_terminated)
Definition: item.h:318
bool eq_safe(const char *str) const
Definition: item.h:345
Name_string(const LEX_STRING str)
Definition: item.h:312
Name_string()
Definition: item.h:305
bool eq(const char *str) const
Compare name to another name in C string, case insensitively.
Definition: item.h:341
void copy(const char *str, size_t length)
Variants for copy(), for various argument combinations.
Definition: item.h:329
Name_string(const LEX_CSTRING str)
Definition: item.h:313
Name_string(const char *str, size_t length, bool is_null_terminated)
Definition: item.h:314
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:1428
bool eq(const Name_string name) const
Compare name to another name in Name_string, case insensitively.
Definition: item.h:349
void copy(const Name_string str)
Definition: item.h:337
void copy(const LEX_STRING *lex)
Definition: item.h:336
Base class for parse tree nodes (excluding the Parse_tree_root hierarchy)
Definition: parse_tree_node_base.h:231
bool end_parse_tree(Show_parse_tree *tree)
Definition: parse_tree_node_base.h:400
bool begin_parse_tree(Show_parse_tree *tree)
Definition: parse_tree_node_base.h:385
Definition: protocol.h:33
This class represents a query block, aka a query specification, which is a query consisting of a SELE...
Definition: sql_lex.h:1179
Simple intrusive linked list.
Definition: sql_list.h:48
A set of THD members describing the current authenticated user.
Definition: sql_security_ctx.h:54
Definition: field.h:4484
bool field
Definition: field.h:4497
Definition: item.h:661
virtual void set_out_param_info(Send_field *info)
Definition: item.h:693
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:674
virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)=0
virtual const Send_field * get_out_param_info() const
Definition: item.h:695
Holds the json parse tree being generated by the SHOW PARSE_TREE command.
Definition: parse_tree_node_base.h:140
A wrapper class for null-terminated constant strings.
Definition: sql_string.h:74
const char * ptr() const
Return string buffer.
Definition: sql_string.h:105
bool is_set() const
Check if m_ptr is set.
Definition: sql_string.h:109
size_t length() const
Return name length.
Definition: sql_string.h:113
void set(const char *str_arg, size_t length_arg)
Initialize from a C string whose length is already known.
Definition: sql_string.h:83
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
bool append(const String &s)
Definition: sql_string.cc:419
const CHARSET_INFO * charset() const
Definition: sql_string.h:242
void set_charset(const CHARSET_INFO *charset_arg)
Definition: sql_string.h:241
const char * ptr() const
Definition: sql_string.h:251
bool set_or_copy_aligned(const char *s, size_t arg_length, const CHARSET_INFO *cs)
Definition: sql_string.cc:332
void mark_as_const()
Definition: sql_string.h:249
size_t length() const
Definition: sql_string.h:243
size_t numchars() const
Definition: sql_string.cc:538
bool copy()
Definition: sql_string.cc:198
void set(String &str, size_t offset, size_t arg_length)
Definition: sql_string.h:304
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Definition: table.h:2931
Table_ref * outer_join_nest() const
Returns the outer join nest that this Table_ref belongs to, if any.
Definition: table.h:3532
table_map map() const
Return table map derived from table number.
Definition: table.h:4080
bool is_view() const
Return true if this represents a named view.
Definition: table.h:3193
bool is_inner_table_of_outer_join() const
Return true if this table is an inner table of some outer join.
Definition: table.h:3547
bool outer_join
True if right argument of LEFT JOIN; false in other cases (i.e.
Definition: table.h:3907
Table_ref * next_local
Definition: table.h:3632
Table_ref * any_outer_leaf_table()
Return any leaf table that is not an inner table of an outer join.
Definition: table.h:3373
TABLE * table
Definition: table.h:3715
Table_ref * next_name_resolution_table
Definition: table.h:3712
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:624
const uint32 m_max_length
Definition: item.h:655
const bool m_unsigned_flag
Definition: item.h:654
const DTCollation m_collation
Definition: item.h:656
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:628
Type_properties(enum_field_types type_arg, const CHARSET_INFO *charset)
Constructor for character type, with explicit character set.
Definition: item.h:646
Type_properties(enum_field_types type_arg, bool unsigned_arg)
Constructor for any numeric type, with explicit signedness.
Definition: item.h:636
const enum_field_types m_type
Definition: item.h:653
Class used as argument to Item::walk() together with used_tables_for_level()
Definition: item.h:276
Used_tables(Query_block *select)
Definition: item.h:278
table_map used_tables
Accumulated used tables data.
Definition: item.h:281
Query_block *const select
Level for which data is accumulated.
Definition: item.h:280
Definition: item_cmpfunc.h:1884
Definition: mem_root_deque.h:289
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:111
iterator begin()
Definition: mem_root_deque.h:440
iterator end()
Definition: mem_root_deque.h:441
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:96
uint precision() const
Definition: my_decimal.h:134
bool sign() const
Definition: my_decimal.h:132
sp_head represents one instance of a stored program.
Definition: sp_head.h:389
Definition: sp_rcontext.h:77
Definition: sql_udf.h:83
Definition: item_func.h:3092
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
#define L
Definition: ctype-tis620.cc:74
#define U
Definition: ctype-tis620.cc:73
#define E_DEC_OVERFLOW
Definition: decimal.h: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
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
enum_mysql_timestamp_type
Definition: mysql_time.h:45
#define MY_COLL_ALLOW_SUPERSET_CONV
Definition: item.h:174
const Name_string null_name_string
monotonicity_info
Definition: item.h:578
@ NON_MONOTONIC
Definition: item.h:579
@ MONOTONIC_STRICT_INCREASING
Definition: item.h:582
@ MONOTONIC_INCREASING_NOT_NULL
Definition: item.h:581
@ MONOTONIC_INCREASING
Definition: item.h:580
@ MONOTONIC_STRICT_INCREASING_NOT_NULL
Definition: item.h:583
Item * GetNthVisibleField(const mem_root_deque< Item * > &fields, size_t index)
Definition: item.h:7363
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:11070
bool agg_item_charsets(DTCollation &c, const char *name, Item **items, uint nitems, uint flags)
Definition: item.cc:2869
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:3722
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:3844
#define MY_COLL_ALLOW_NONE
Definition: item.h:176
#define ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT
Max length of an Item string for its use in an error message.
Definition: item.h:362
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:3809
Cached_item * new_Cached_item(THD *thd, Item *item)
Create right type of Cached_item for an item.
Definition: item_buff.cc:55
bool agg_item_charsets_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems)
Definition: item.h:4108
Item * CompileItem(Item *item, T &&analyzer, U &&transformer)
Same as WalkItem, but for Item::compile().
Definition: item.h:3831
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:11172
bool agg_item_charsets_for_string_result(DTCollation &c, const char *name, Item **items, uint nitems)
Definition: item.h:4101
size_t CountHiddenFields(const mem_root_deque< Item * > &fields)
Definition: item.h:7358
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:10905
bool(Item::* Item_analyzer)(uchar **argp)
Definition: item.h:709
Item_field * FindEqualField(Item_field *item_field, table_map reachable_tables, bool replace, bool *found)
Definition: item.cc:11123
enum monotonicity_info enum_monotonicity_info
void item_init(void)
Init all special items.
Definition: item.cc:153
size_t CountVisibleFields(const mem_root_deque< Item * > &fields)
Definition: item.h:7353
constexpr float COND_FILTER_STALE
Value is out-of-date, will need recalculation.
Definition: item.h:125
bool convert_const_strings(DTCollation &coll, Item **args, uint nargs)
Convert constant strings according to a specific character set/collation.
Definition: item.cc:2783
bool agg_item_collations_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems)
Aggregate collations for items used in a comparison operations.
Definition: item.cc:2763
Item_result item_cmp_type(Item_result a, Item_result b)
Definition: item.cc:9496
void(* Cond_traverser)(const Item *item, void *arg)
Definition: item.h:719
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:718
std::string ItemToQuerySubstrNoCharLimit(const Item *item)
#define NAME_STRING(x)
Definition: item.h:355
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:5766
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:778
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:11176
double double_from_string_with_check(const CHARSET_INFO *cs, const char *cptr, const char *end)
Definition: item.cc:3690
#define MY_COLL_ALLOW_NUMERIC_CONV
Definition: item.h:177
constexpr float COND_FILTER_INEQUALITY
Filtering effect for inequalities: col1 > col2.
Definition: item.h:116
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:9655
#define MY_COLL_ALLOW_COERCIBLE_CONV
Definition: item.h:175
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:9521
std::string ItemToQuerySubstr(const Item *item, const LEX *lex=nullptr, uint32 char_limit=ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT)
Definition: item.cc:11112
#define T
Definition: jit_executor_value.cc:373
A better implementation of the UNIX ctype(3) library.
static constexpr uint32_t MY_CS_PUREASCII
Definition: m_ctype.h:140
int my_strcasecmp(const CHARSET_INFO *cs, const char *s1, const char *s2)
Definition: m_ctype.h:651
static constexpr uint32_t MY_REPERTOIRE_UNICODE30
Definition: m_ctype.h:156
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:499
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb4_bin
Definition: ctype-utf8.cc:7813
MYSQL_STRINGS_EXPORT unsigned my_string_repertoire(const CHARSET_INFO *cs, const char *str, size_t len)
Definition: ctype.cc:798
static constexpr uint32_t MY_REPERTOIRE_ASCII
Definition: m_ctype.h:152
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb3_general_ci
Definition: ctype-utf8.cc:5785
MYSQL_PLUGIN_IMPORT CHARSET_INFO * system_charset_info
Definition: mysqld.cc:1566
Various macros useful for communicating with memory debuggers, such as Valgrind.
void TRASH(void *ptr, size_t length)
Put bad content in memory to be sure it will segfault if dereferenced.
Definition: memory_debugging.h:71
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:480
static void bitmap_set_bit(MY_BITMAP *map, uint bit)
Definition: my_bitmap.h:80
Header for compiler-dependent features.
#define MY_COMPILER_MSVC_DIAGNOSTIC_IGNORE(X)
Definition: my_compiler.h:247
#define MY_COMPILER_DIAGNOSTIC_PUSH()
save the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:277
#define MY_COMPILER_DIAGNOSTIC_POP()
restore the compiler's diagnostic (enabled warnings, errors, ...) state
Definition: my_compiler.h:278
#define DBUG_FILE
Definition: my_dbug.h:194
#define DBUG_TRACE
Definition: my_dbug.h:146
It is interface module to fixed precision decimals library.
int my_decimal_int_part(uint precision, uint decimals)
Definition: my_decimal.h:84
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:336
int my_decimal_set_zero(my_decimal *d)
Definition: my_decimal.h:258
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:70
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:192
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.
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:143
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:907
#define MAX_CHAR_WIDTH
Max width for a CHAR column, in number of characters.
Definition: mysql_com.h:905
static bool ignore_errors
Definition: mysqlcheck.cc:62
static bool replace
Definition: mysqlimport.cc:70
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1084
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
const std::string charset("charset")
Definition: commit_order_queue.h:34
PT & ref(PT *tp)
Definition: tablespace_impl.cc:359
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
size_t size(const char *const c)
Definition: base64.h:46
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
std::string truncate(const std::string &str, const size_t max_length)
Truncates the given string to max_length code points.
Definition: utils_string.cc:418
std::string type_name(Value_type type)
Definition: jit_executor_value.cc:830
std::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2894
#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
type_conversion_status
Status when storing a value in a field or converting from one datatype to another.
Definition: field.h:196
#define MY_REPERTOIRE_NUMERIC
Definition: field.h:252
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:387
Value_generator_source
Enum to indicate source for which value generator is used.
Definition: field.h:467
@ VGS_DEFAULT_EXPRESSION
Definition: field.h:469
@ VGS_GENERATED_COLUMN
Definition: field.h:468
#define my_charset_numeric
Definition: field.h:251
Derivation
For use.
Definition: field.h:172
@ DERIVATION_COERCIBLE
Definition: field.h:176
@ DERIVATION_SYSCONST
Definition: field.h:177
@ DERIVATION_EXPLICIT
Definition: field.h:180
@ DERIVATION_NONE
Definition: field.h:173
@ DERIVATION_NUMERIC
Definition: field.h:175
@ DERIVATION_NULL
Definition: field.h:174
@ DERIVATION_IMPLICIT
Definition: field.h:178
File containing constants that can be used throughout the server.
constexpr const table_map RAND_TABLE_BIT
Definition: sql_const.h:113
constexpr const int MAX_TIME_WIDTH
-838:59:59
Definition: sql_const.h:70
constexpr const int MAX_DATE_WIDTH
YYYY-MM-DD.
Definition: sql_const.h:68
constexpr const size_t STRING_BUFFER_USUAL_SIZE
Definition: sql_const.h:126
constexpr const table_map OUTER_REF_TABLE_BIT
Definition: sql_const.h:112
constexpr const int MAX_DOUBLE_STR_LENGTH
-[digits].E+###
Definition: sql_const.h:158
enum_walk
Enumeration for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:289
bool(Item::*)(unsigned char *) Item_processor
Processor type for {Item,Query_block[_UNIT],Table_function}walk.
Definition: sql_const.h:307
constexpr const table_map INNER_TABLE_BIT
Definition: sql_const.h:111
constexpr const int MAX_DATETIME_WIDTH
YYYY-MM-DD HH:MM:SS.
Definition: sql_const.h:76
enum_mark_columns
Definition: sql_const.h:232
int stringcmp(const String *s, const String *t)
Definition: sql_string.cc:712
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:29
Access paths are a query planning structure that correspond 1:1 to iterators, in that an access path ...
Definition: access_path.h:238
Definition: m_ctype.h:421
unsigned mbmaxlen
Definition: m_ctype.h:445
Definition: item_cmpfunc.h:2817
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:485
int err_code
the error code found during check(if any)
Definition: item.h:492
int col_index
the order of the column in table
Definition: item.h:490
const char * banned_function_name
the name of the function which is not allowed
Definition: item.h:499
Value_generator_source source
Definition: item.h:497
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:504
Check_function_as_value_generator_parameters(int default_error_code, Value_generator_source val_gen_src)
Definition: item.h:486
This class represents a subquery contained in some subclass of Item_subselect,.
Definition: item.h:859
Strategy strategy
The strategy for executing the subquery.
Definition: item.h:893
Strategy
The strategy for executing the subquery.
Definition: item.h:861
@ 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:890
int row_width
The width (in bytes) of the subquery's rows.
Definition: item.h:899
The current state of the privilege checking process for the current user, SQL statement and SQL objec...
Definition: table.h:384
Definition: item.h:3271
Aggregate_ref_update(Item_sum *target, Query_block *owner)
Definition: item.h:3274
Query_block * m_owner
Definition: item.h:3273
Item_sum * m_target
Definition: item.h:3272
Definition: item.h:3244
Aggregate_replacement(Item_sum *target, Item_field *replacement)
Definition: item.h:3247
Item_field * m_replacement
Definition: item.h:3246
Item_sum * m_target
Definition: item.h:3245
Context struct used by walk method collect_scalar_subqueries to accumulate information about scalar s...
Definition: item.h:2970
Item * m_join_condition_context
Definition: item.h:2976
Location
Definition: item.h:2971
@ L_JOIN_COND
Definition: item.h:2971
@ L_HAVING
Definition: item.h:2971
@ L_SELECT
Definition: item.h:2971
@ L_WHERE
Definition: item.h:2971
bool m_collect_unconditionally
Definition: item.h:2977
int8 m_location
we are currently looking at this kind of clause, cf. enum Location
Definition: item.h:2975
std::vector< Css_info > m_list
accumulated all scalar subqueries found
Definition: item.h:2973
Minion class under Collect_scalar_subquery_info ("Css").
Definition: item.h:2942
int8 m_locations
set of locations
Definition: item.h:2944
Item * m_join_condition
Where did we find item above? Used when m_location == L_JOIN_COND, nullptr for other locations.
Definition: item.h:2950
bool m_add_coalesce
If true, add a COALESCE around replaced subquery: used for implicitly grouped COUNT() in subquery sel...
Definition: item.h:2955
table_map m_correlation_map
Definition: item.h:2947
uint m_having_idx
Index of the having expression copied to select list.
Definition: item.h:2960
Item_singlerow_subselect * item
the scalar subquery
Definition: item.h:2946
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:2958
bool m_implicitly_grouped_and_no_union
If true, we can forego cardinality checking of the derived table.
Definition: item.h:2952
Definition: item.h:3206
Mode m_default_value
Definition: item.h:3216
Item_field * m_outer_field
Definition: item.h:3210
Field * m_target
The field to be replaced.
Definition: item.h:3207
Item_field_replacement(Field *target, Item_field *item, Query_block *select, Mode default_value=Mode::CONFLATE)
Definition: item.h:3217
Mode
Definition: item.h:3211
Item_field * m_item
The replacement field replacement field iff outer ref.
Definition: item.h:3208
Definition: item.h:3225
Item_func * m_target
The function call to be replaced.
Definition: item.h:3226
Item_func_call_replacement(Item_func *func_target, Item_field *item, Query_block *select)
Definition: item.h:3228
Item_field * m_item
The replacement field.
Definition: item.h:3227
Definition: item.h:3198
Item_replacement(Query_block *transformed_block, Query_block *current_block)
Definition: item.h:3203
Query_block * m_curr_block
Transformed query block or a contained.
Definition: item.h:3200
Query_block * m_trans_block
Transformed query block.
Definition: item.h:3199
Definition: item.h:3235
Item * m_target
The item identifying the view_ref to be replaced.
Definition: item.h:3236
Field * m_field
The replacement field.
Definition: item.h:3237
Item_view_ref_replacement(Item *target, Field *field, Query_block *select)
Definition: item.h:3240
Definition: item.h:3065
List< Item_func > stack
Definition: item.h:3067
< Argument object to change_context_processor
Definition: item.h:4324
Name_resolution_context * m_context
Definition: item.h:4325
Change_context(Name_resolution_context *context)
Definition: item.h:4326
Argument structure for walk processor Item::update_depended_from.
Definition: item.h:4341
Query_block * old_depended_from
Definition: item.h:4342
Query_block * new_depended_from
Definition: item.h:4343
The LEX object currently serves three different purposes:
Definition: sql_lex.h:3994
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:412
Name_resolution_context * next_context
Link to next name res context with the same query block as the base.
Definition: item.h:419
Table_ref * view_error_handler_arg
Definition: item.h:457
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:417
Security_context * security_ctx
Security context of this name resolution context.
Definition: item.h:473
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:437
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:442
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:449
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:467
bool view_error_handler
Definition: item.h:456
Table_ref * table_list
List of tables used to resolve the items of this context.
Definition: item.h:429
void resolve_in_table_list_only(Table_ref *tables)
Definition: item.h:475
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:422
Definition: table.h:1433
const char * alias
alias or table name
Definition: table.h:1685
bool has_null_row() const
Definition: table.h:2201
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:1764
bool alias_name_used
Definition: table.h:1890
bool is_nullable() const
Return whether table is nullable.
Definition: table.h:2103
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:3790
Item * cache_item
Item to cache. Used as a binary flag, but kept as Item* for assertion.
Definition: item.h:3795
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:3793
Item::enum_const_item_cache cache_arg
How to cache JSON data.
Definition: item.h:3797
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:45
Definition: result.h:30
This file defines all base public constants related to triggers in MySQL.
enum_trigger_variable_type
Enum constants to designate NEW and OLD trigger pseudo-variables.
Definition: trigger_def.h:73
Item_result
Type of the user defined function return slot and arguments.
Definition: udf_registration_types.h:39
@ STRING_RESULT
not valid for UDFs
Definition: udf_registration_types.h:41
@ DECIMAL_RESULT
not valid for UDFs
Definition: udf_registration_types.h:45
@ REAL_RESULT
char *
Definition: udf_registration_types.h:42
@ INT_RESULT
double
Definition: udf_registration_types.h:43
@ INVALID_RESULT
Definition: udf_registration_types.h:40
@ ROW_RESULT
long long
Definition: udf_registration_types.h:44
Definition: dtoa.cc:595