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