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