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