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