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