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