MySQL 9.7.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, 2026, 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 <cassert>
30#include <cfloat>
31#include <climits>
32#include <cmath>
33#include <cstdio>
34#include <cstring>
35#include <memory>
36#include <new>
37#include <optional>
38#include <string>
39#include <type_traits>
40#include <vector>
41
42#include "decimal.h"
43#include "field_types.h" // enum_field_types
44#include "lex_string.h"
45#include "memory_debugging.h"
46#include "my_alloc.h"
47#include "my_bitmap.h"
48#include "my_compiler.h"
49#include "my_dbug.h"
50#include "my_double2ulonglong.h"
51#include "my_inttypes.h"
52#include "my_sys.h"
53#include "my_table_map.h"
54#include "my_temporal.h"
55#include "my_time.h"
56#include "mysql/strings/dtoa.h"
60#include "mysql_com.h"
61#include "mysql_time.h"
62#include "mysqld_error.h"
63#include "nulls.h"
64#include "sql-common/my_decimal.h" // my_decimal
65#include "sql/auth/auth_acls.h" // Access_bitmask
66#include "sql/enum_query_type.h"
67#include "sql/field.h" // Derivation
68#include "sql/mem_root_array.h"
69#include "sql/parse_location.h" // POS
70#include "sql/parse_tree_node_base.h" // Parse_tree_node
71#include "sql/sql_array.h" // Bounds_checked_array
72#include "sql/sql_const.h"
73#include "sql/sql_list.h"
74#include "sql/table.h"
75#include "sql/table_trigger_field_support.h" // Table_trigger_field_support
76#include "sql/thr_malloc.h"
77#include "sql/trigger_def.h" // enum_trigger_variable_type
78#include "sql_string.h"
79#include "string_with_len.h"
80#include "template_utils.h"
81
82class Item;
83class Item_cache;
85class Item_field;
86class Item_func;
87class Item_multi_eq;
89class Item_sum;
90class Json_wrapper;
91class Protocol;
92class Query_block;
94class sp_head;
95class sp_rcontext;
96class THD;
97class user_var_entry;
98struct COND_EQUAL;
99struct TYPELIB;
100
102
103void item_init(void); /* Init item functions */
104
105/**
106 Default condition filtering (selectivity) values used by
107 get_filtering_effect() and friends when better estimates
108 (statistics) are not available for a predicate.
109*/
110/**
111 For predicates that are always satisfied. Must be 1.0 or the filter
112 calculation logic will break down.
113*/
114constexpr float COND_FILTER_ALLPASS{1.0f};
115/// Filtering effect for equalities: col1 = col2
116constexpr float COND_FILTER_EQUALITY{0.1f};
117/// Filtering effect for inequalities: col1 > col2
118constexpr float COND_FILTER_INEQUALITY{0.3333f};
119/// Filtering effect for between: col1 BETWEEN a AND b
120constexpr float COND_FILTER_BETWEEN{0.1111f};
121/**
122 Value is out-of-date, will need recalculation.
123 This is used by post-greedy-search logic which changes the access method and
124 thus makes obsolete the filtering value calculated by best_access_path(). For
125 example, test_if_skip_sort_order().
126*/
127constexpr float COND_FILTER_STALE{-1.0f};
128/**
129 A special subcase of the above:
130 - if this is table/index/range scan, and
131 - rows_fetched is how many rows we will examine, and
132 - rows_fetched is less than the number of rows in the table (as determined
133 by test_if_cheaper_ordering() and test_if_skip_sort_order()).
134 Unlike the ordinary case where rows_fetched:
135 - is set by calculate_scan_cost(), and
136 - is how many rows pass the constant condition (so, less than we will
137 examine), and
138 - the actual rows_fetched to show in EXPLAIN is the number of rows in the
139 table (== rows which we will examine), and
140 - the constant condition's effect has to be moved to filter_effect for
141 EXPLAIN.
142*/
143constexpr float COND_FILTER_STALE_NO_CONST{-2.0f};
144
145static inline uint32 char_to_byte_length_safe(uint32 char_length_arg,
146 uint32 mbmaxlen_arg) {
147 const ulonglong tmp = ((ulonglong)char_length_arg) * mbmaxlen_arg;
148 return (tmp > UINT_MAX32) ? (uint32)UINT_MAX32 : (uint32)tmp;
149}
150
152 Item_result result_type,
153 uint8 decimals) {
154 if (is_temporal_type(real_type_to_type(data_type)))
155 return decimals ? DECIMAL_RESULT : INT_RESULT;
156 if (result_type == STRING_RESULT) return REAL_RESULT;
157 return result_type;
158}
159
160/*
161 "Declared Type Collation"
162 A combination of collation and its derivation.
163
164 Flags for collation aggregation modes:
165 MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
166 MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
167 (i.e. constant).
168 MY_COLL_ALLOW_NUMERIC_CONV - if all items were numbers, convert to
169 @@character_set_connection
170 MY_COLL_ALLOW_NONE - allow return DERIVATION_NONE
171 (e.g. when aggregating for string result)
172 MY_COLL_CMP_CONV - for comparison: Allow SUPERSET and COERCIBLE
173 conversion, disallow NONE.
174*/
175
176#define MY_COLL_ALLOW_SUPERSET_CONV 1
177#define MY_COLL_ALLOW_COERCIBLE_CONV 2
178#define MY_COLL_ALLOW_NONE 4
179#define MY_COLL_ALLOW_NUMERIC_CONV 8
180
181#define MY_COLL_CMP_CONV \
182 (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
183
185 public:
189
193 }
198 }
199 DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg) {
200 collation = collation_arg;
201 derivation = derivation_arg;
202 set_repertoire_from_charset(collation_arg);
203 }
204 void set(const DTCollation &dt) {
205 collation = dt.collation;
208 }
209 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg) {
210 collation = collation_arg;
211 derivation = derivation_arg;
212 set_repertoire_from_charset(collation_arg);
213 }
214 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg,
215 uint repertoire_arg) {
216 collation = collation_arg;
217 derivation = derivation_arg;
218 repertoire = repertoire_arg;
219 }
220 void set_numeric() {
224 }
225 void set(const CHARSET_INFO *collation_arg) {
226 collation = collation_arg;
227 set_repertoire_from_charset(collation_arg);
228 }
229 void set(Derivation derivation_arg) { derivation = derivation_arg; }
230 void set_repertoire(uint repertoire_arg) { repertoire = repertoire_arg; }
231 bool aggregate(DTCollation &dt, uint flags = 0);
232 bool set(DTCollation &dt1, DTCollation &dt2, uint flags = 0) {
233 set(dt1);
234 return aggregate(dt2, flags);
235 }
236 const char *derivation_name() const {
237 switch (derivation) {
239 return "NUMERIC";
240 case DERIVATION_NULL:
241 return "NULL";
243 return "COERCIBLE";
245 return "IMPLICIT";
247 return "SYSCONST";
249 return "EXPLICIT";
250 case DERIVATION_NONE:
251 return "NONE";
252 default:
253 return "UNKNOWN";
254 }
255 }
256};
257
258/**
259 Class used as argument to Item::walk() together with mark_field_in_map()
260*/
262 public:
265
266 /**
267 If == NULL, update map of any table.
268 If <> NULL, update map of only this table.
269 */
270 TABLE *const table;
271 /// How to mark the map.
273};
274
275/**
276 Class used as argument to Item::walk() together with used_tables_for_level()
277*/
279 public:
281
282 Query_block *const select; ///< Level for which data is accumulated
283 table_map used_tables; ///< Accumulated used tables data
284};
285
286/*************************************************************************/
287
288/**
289 Storage for name strings.
290 Enpowers Simple_cstring with allocation routines from the sql_strmake family.
291
292 This class must stay as small as possible as we often
293 pass it into functions using call-by-value evaluation.
294
295 Don't add new members or virtual methods into this class!
296*/
298 private:
299 void set_or_copy(const char *str, size_t length, bool is_null_terminated) {
300 if (is_null_terminated)
301 set(str, length);
302 else
303 copy(str, length);
304 }
305
306 public:
308 /*
309 Please do NOT add constructor Name_string(const char *str) !
310 It will involve hidden strlen() call, which can affect
311 performance negatively. Use Name_string(str, len) instead.
312 */
313 Name_string(const char *str, size_t length) : Simple_cstring(str, length) {}
316 Name_string(const char *str, size_t length, bool is_null_terminated)
317 : Simple_cstring() {
318 set_or_copy(str, length, is_null_terminated);
319 }
320 Name_string(const LEX_STRING str, bool is_null_terminated)
321 : Simple_cstring() {
322 set_or_copy(str.str, str.length, is_null_terminated);
323 }
324 /**
325 Allocate space using sql_strmake() or sql_strmake_with_convert().
326 */
327 void copy(const char *str, size_t length, const CHARSET_INFO *cs);
328 /**
329 Variants for copy(), for various argument combinations.
330 */
331 void copy(const char *str, size_t length) {
333 }
334 void copy(const char *str) {
335 copy(str, (str ? strlen(str) : 0), system_charset_info);
336 }
337 void copy(const LEX_STRING lex) { copy(lex.str, lex.length); }
338 void copy(const LEX_STRING *lex) { copy(lex->str, lex->length); }
339 void copy(const Name_string str) { copy(str.ptr(), str.length()); }
340 /**
341 Compare name to another name in C string, case insensitively.
342 */
343 bool eq(const char *str) const {
344 assert(str && ptr());
345 return my_strcasecmp(system_charset_info, ptr(), str) == 0;
346 }
347 bool eq_safe(const char *str) const { return is_set() && str && eq(str); }
348 /**
349 Compare name to another name in Name_string, case insensitively.
350 */
351 bool eq(const Name_string name) const { return eq(name.ptr()); }
352 bool eq_safe(const Name_string name) const {
353 return is_set() && name.is_set() && eq(name);
354 }
355};
356
357#define NAME_STRING(x) Name_string(STRING_WITH_LEN(x))
358
359/**
360 Max length of an Item string for its use in an error message.
361 This should be kept in sync with MYSQL_ERRMSG_SIZE (which should
362 not be exceeded).
363*/
364#define ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT (300)
365
366extern const Name_string null_name_string;
367
368/**
369 Storage for Item names.
370 Adds "autogenerated" flag and warning functionality to Name_string.
371*/
373 private:
374 bool m_is_autogenerated; /* indicates if name of this Item
375 was autogenerated or set by user */
376 public:
380 /**
381 Set m_is_autogenerated flag to the given value.
382 */
385 }
386 /**
387 Return the auto-generated flag.
388 */
389 bool is_autogenerated() const { return m_is_autogenerated; }
390 using Name_string::copy;
391 /**
392 Copy name together with autogenerated flag.
393 Produce a warning if name was cut.
394 */
395 void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg,
396 bool is_autogenerated_arg);
397};
398
399/**
400 Instances of Name_resolution_context store the information necessary for
401 name resolution of Items and other context analysis of a query made in
402 fix_fields().
403
404 This structure is a part of Query_block, a pointer to this structure is
405 assigned when an item is created (which happens mostly during parsing
406 (sql_yacc.yy)), but the structure itself will be initialized after parsing
407 is complete
408
409 @todo move subquery of INSERT ... SELECT and CREATE ... SELECT to
410 separate Query_block which allow to remove tricks of changing this
411 structure before and after INSERT/CREATE and its SELECT to make correct
412 field name resolution.
413*/
415 /**
416 The name resolution context to search in when an Item cannot be
417 resolved in this context (the context of an outer select)
418 */
420 /// Link to next name res context with the same query block as the base
422
423 /**
424 List of tables used to resolve the items of this context. Usually these
425 are tables from the FROM clause of SELECT statement. The exceptions are
426 INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
427 subquery is not moved to a separate Query_block. For these types of
428 statements we have to change this member dynamically to ensure correct
429 name resolution of different parts of the statement.
430 */
432 /**
433 In most cases the two table references below replace 'table_list' above
434 for the purpose of name resolution. The first and last name resolution
435 table references allow us to search only in a sub-tree of the nested
436 join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
437 and JOIN ... ON.
438 */
440 /**
441 Last table to search in the list of leaf table references that begins
442 with first_name_resolution_table.
443 */
445
446 /**
447 Query_block item belong to, in case of merged VIEW it can differ from
448 Query_block where item was created, so we can't use table_list/field_list
449 from there
450 */
452
453 /*
454 Processor of errors caused during Item name resolving, now used only to
455 hide underlying tables in errors about views (i.e. it substitute some
456 errors for views)
457 */
460
461 /**
462 When true, items are resolved in this context against
463 Query_block::item_list, SELECT_lex::group_list and
464 this->table_list. If false, items are resolved only against
465 this->table_list.
466
467 @see Query_block::item_list, Query_block::group_list
468 */
470
471 /**
472 Security context of this name resolution context. It's used for views
473 and is non-zero only if the view is defined with SQL SECURITY DEFINER.
474 */
476
480 }
481};
482
483/**
484 Struct used to pass around arguments to/from
485 check_function_as_value_generator
486*/
489 int default_error_code, Value_generator_source val_gen_src)
490 : err_code(default_error_code), source(val_gen_src) {}
491 /// the order of the column in table
492 int col_index{-1};
493 /// the error code found during check(if any)
495 /*
496 If it is a generated column, default expression or check constraint
497 expression value generator.
498 */
500 /// the name of the function which is not allowed
501 const char *banned_function_name{nullptr};
502
503 /// Return the correct error code, based on whether or not if we are checking
504 /// for disallowed functions in generated column expressions, in default
505 /// value expressions or in check constraint expression.
507 return ((source == VGS_GENERATED_COLUMN)
508 ? ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED
510 ? ER_DEFAULT_VAL_GENERATED_FUNCTION_IS_NOT_ALLOWED
511 : ER_CHECK_CONSTRAINT_FUNCTION_IS_NOT_ALLOWED);
512 }
513};
514/*
515 Store and restore the current state of a name resolution context.
516*/
517
519 private:
525
526 public:
527 /* Save the state of a name resolution context. */
528 void save_state(Name_resolution_context *context, Table_ref *table_list) {
529 save_table_list = context->table_list;
532 save_next_local = table_list->next_local;
534 }
535
536 /* Restore a name resolution context from saved state. */
537 void restore_state(Name_resolution_context *context, Table_ref *table_list) {
538 table_list->next_local = save_next_local;
540 context->table_list = save_table_list;
543 }
544
545 void update_next_local(Table_ref *table_list) {
546 save_next_local = table_list;
547 }
548
551 }
552};
553
554/*
555 This enum is used to report information about monotonicity of function
556 represented by Item* tree.
557 Monotonicity is defined only for Item* trees that represent table
558 partitioning expressions (i.e. have no subqueries/user vars/dynamic parameters
559 etc etc). An Item* tree is assumed to have the same monotonicity properties
560 as its corresponding function F:
561
562 [signed] longlong F(field1, field2, ...) {
563 put values of field_i into table record buffer;
564 return item->val_int();
565 }
566
567 NOTE
568 At the moment function monotonicity is not well defined (and so may be
569 incorrect) for Item trees with parameters/return types that are different
570 from INT_RESULT, may be NULL, or are unsigned.
571 It will be possible to address this issue once the related partitioning bugs
572 (BUG#16002, BUG#15447, BUG#13436) are fixed.
573
574 The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns
575 NULL which puts those rows into the NULL partition, but
576 '2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed
577 for this (see Bug#20577).
578*/
579
580typedef enum monotonicity_info {
581 NON_MONOTONIC, /* none of the below holds */
582 MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
583 MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */
584 MONOTONIC_STRICT_INCREASING, /* F() is unary and (x < y) => (F(x) < F(y)) */
585 MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */
587
588/**
589 A type for SQL-like 3-valued Booleans: true/false/unknown.
590*/
591class Bool3 {
592 public:
593 /// @returns an instance set to "FALSE"
594 static const Bool3 false3() { return Bool3(v_FALSE); }
595 /// @returns an instance set to "UNKNOWN"
596 static const Bool3 unknown3() { return Bool3(v_UNKNOWN); }
597 /// @returns an instance set to "TRUE"
598 static const Bool3 true3() { return Bool3(v_TRUE); }
599
600 bool is_true() const { return m_val == v_TRUE; }
601 bool is_unknown() const { return m_val == v_UNKNOWN; }
602 bool is_false() const { return m_val == v_FALSE; }
603
604 private:
606 /// This is private; instead, use false3()/etc.
607 Bool3(value v) : m_val(v) {}
608
610 /*
611 No operator to convert Bool3 to bool (or int) - intentionally: how
612 would you map unknown3 to true/false?
613 It is because we want to block such conversions that Bool3 is a class
614 instead of a plain enum.
615 */
616};
617
618/**
619 Type properties, used to collect type information for later assignment
620 to an Item object. The object stores attributes signedness, max length
621 and collation. However, precision and scale (for decimal numbers) and
622 fractional second precision (for time and datetime) are not stored,
623 since any type derived from this object will have default values for these
624 attributes.
625*/
627 public:
628 /// Constructor for any signed numeric type or date type
629 /// Defaults are provided for attributes like signedness and max length
631 : m_type(type_arg),
632 m_unsigned_flag(false),
633 m_max_length(0),
635 assert(type_arg != MYSQL_TYPE_VARCHAR && type_arg != MYSQL_TYPE_JSON);
636 }
637 /// Constructor for any numeric type, with explicit signedness
638 Type_properties(enum_field_types type_arg, bool unsigned_arg)
639 : m_type(type_arg),
640 m_unsigned_flag(unsigned_arg),
641 m_max_length(0),
643 assert(is_numeric_type(type_arg) || type_arg == MYSQL_TYPE_BIT ||
644 type_arg == MYSQL_TYPE_YEAR);
645 }
646 /// Constructor for character type, with explicit character set.
647 /// Default length/max length is provided.
649 : m_type(type_arg),
650 m_unsigned_flag(false),
651 m_max_length(0),
653 /// Constructor for Item
654 Type_properties(Item &item);
656 const bool m_unsigned_flag;
659};
660
661/*************************************************************************/
662
664 public:
666 virtual ~Settable_routine_parameter() = default;
667 /**
668 Set required privileges for accessing the parameter.
669
670 @param privilege The required privileges for this field, with the
671 following alternatives:
672 MODE_IN - SELECT_ACL
673 MODE_OUT - UPDATE_ACL
674 MODE_INOUT - SELECT_ACL | UPDATE_ACL
675 */
677 [[maybe_unused]]) {}
678
679 /*
680 Set parameter value.
681
682 SYNOPSIS
683 set_value()
684 thd thread handle
685 ctx context to which parameter belongs (if it is local
686 variable).
687 it item which represents new value
688
689 RETURN
690 false if parameter value has been set,
691 true if error has occurred.
692 */
693 virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it) = 0;
694
695 virtual void set_out_param_info(Send_field *info [[maybe_unused]]) {}
696
697 virtual const Send_field *get_out_param_info() const { return nullptr; }
698};
699
700/*
701 Analyzer function
702 SYNOPSIS
703 argp in/out IN: Analysis parameter
704 OUT: Parameter to be passed to the transformer
705
706 RETURN
707 true Invoke the transformer
708 false Don't do it
709
710*/
711typedef bool (Item::*Item_analyzer)(uchar **argp);
712
713/**
714 Type for transformers used by Item::transform and Item::compile
715 @param arg Argument used by the transformer. Really a typeless pointer
716 in spite of the uchar type (historical reasons). The
717 transformer needs to cast this to the desired pointer type
718 @returns The transformed item
719*/
720typedef Item *(Item::*Item_transformer)(uchar *arg);
721typedef void (*Cond_traverser)(const Item *item, void *arg);
722
723/**
724 Utility mixin class to be able to walk() only parts of item trees.
725
726 Used with PREFIX+POSTFIX walk: in the prefix call of the Item
727 processor, we process the item X, may decide that its children should not
728 be processed (just like if they didn't exist): processor calls stop_at(X)
729 for that. Then walk() goes to a child Y; the processor tests is_stopped(Y)
730 which returns true, so processor sees that it must not do any processing
731 and returns immediately. Finally, the postfix call to the processor on X
732 tests is_stopped(X) which returns "true" and understands that the
733 not-to-be-processed children have been skipped so calls restart(). Thus,
734 any sibling of X, any part of the Item tree not under X, can then be
735 processed.
736*/
738 protected:
743
744 /// Stops walking children of this item
745 void stop_at(const Item *i) {
746 assert(stopped_at_item == nullptr);
747 stopped_at_item = i;
748 }
749
750 /**
751 @returns if we are stopped. If item 'i' is where we stopped, restarts the
752 walk for next items.
753 */
754 bool is_stopped(const Item *i) {
755 if (stopped_at_item != nullptr) {
756 /*
757 Walking was disabled for a tree part rooted a one ancestor of 'i' or
758 rooted at 'i'.
759 */
760 if (stopped_at_item == i) {
761 /*
762 Walking was disabled for the tree part rooted at 'i'; we have now just
763 returned back to this root (POSTFIX call), left the tree part:
764 enable the walk again, for other tree parts.
765 */
766 stopped_at_item = nullptr;
767 }
768 // No further processing to do for this item:
769 return true;
770 }
771 return false;
772 }
773
774 private:
775 const Item *stopped_at_item{nullptr};
776};
777
778/// Increment *num if it is less than its maximal value.
779template <typename T>
780void SafeIncrement(T *num) {
781 if (*num < std::numeric_limits<T>::max()) {
782 *num += 1;
783 }
784}
785
786/**
787 This class represents the cost of evaluating an Item. @see SortPredicates
788 to see how this is used.
789*/
790class CostOfItem final {
791 public:
792 /// Set '*this' to represent the cost of 'item'.
793 void Compute(const Item &item) {
794 if (!m_computed) {
795 ComputeInternal(item);
796 }
797 }
798
800 assert(!m_computed);
801 m_is_expensive = true;
802 }
803
804 /// Add the cost of accessing a Field_str.
806 assert(!m_computed);
808 }
809
810 /// Add the cost of accessing any other Field.
812 assert(!m_computed);
814 }
815
816 bool IsExpensive() const {
817 assert(m_computed);
818 return m_is_expensive;
819 }
820
821 /**
822 Get the cost of field access when evaluating the Item associated with this
823 object. The cost unit is arbitrary, but the relative cost of different
824 items reflect the fact that operating on Field_str is more expensive than
825 other Field subclasses.
826 */
827 double FieldCost() const {
828 assert(m_computed);
830 }
831
832 private:
833 /// The cost of accessing a Field_str, relative to other Field types.
834 /// (The value was determined using benchmarks.)
835 static constexpr double kStrFieldCost = 1.8;
836
837 /// The cost of accessing a Field other than Field_str. 1.0 by definition.
838 static constexpr double kOtherFieldCost = 1.0;
839
840 /// True if 'ComputeInternal()' has been called.
841 bool m_computed{false};
842
843 /// True if the associated Item calls user defined functions or stored
844 /// procedures.
845 bool m_is_expensive{false};
846
847 /// The number of Field_str objects accessed by the associated Item.
849
850 /// The number of other Field objects accessed by the associated Item.
852
853 /// Compute the cost of 'root' and its descendants.
854 void ComputeInternal(const Item &root);
855};
856
857/**
858 This class represents a subquery contained in some subclass of
859 Item_subselect, @see FindContainedSubqueries().
860*/
862 /// The strategy for executing the subquery.
863 enum class Strategy : char {
864 /**
865 An independent subquery that is materialized, e.g.:
866 "SELECT * FROM tab WHERE field IN <independent subquery>".
867 where 'independent subquery' does not depend on any fields in 'tab'.
868 (This corresponds to the Item_in_subselect class.)
869 */
871
872 /**
873 A subquery that is reevaluated for each row, e.g.:
874 "SELECT * FROM tab WHERE field IN <dependent subquery>" or
875 "SELECT * FROM tab WHERE field = <dependent subquery>".
876 where 'dependent subquery' depends on at least one field in 'tab'.
877 Alternatively, the subquery may be independent of 'tab', but contain
878 a non-deterministic function such as 'rand()'. Such subqueries are also
879 required to be reevaluated for each row.
880 */
882
883 /**
884 An independent single-row subquery that is evaluated once, e.g.:
885 "SELECT * FROM tab WHERE field = <independent single-row subquery>".
886 (This corresponds to the Item_singlerow_subselect class.)
887 */
889 };
890
891 /// The root path of the subquery.
893
894 /// The strategy for executing the subquery.
896
897 /// The width (in bytes) of the subquery's rows. For variable-sized values we
898 /// use Item.max_length (but cap it at kMaxItemLengthEstimate).
899 /// @see kMaxItemLengthEstimate and
900 /// @see Item_in_subselect::get_contained_subquery().
902};
903
904/**
905 Base class that is used to represent any kind of expression in a
906 relational query. The class provides subclasses for simple components, like
907 literal (constant) values, column references and variable references,
908 as well as more complex expressions like comparison predicates,
909 arithmetic and string functions, row objects, function references and
910 subqueries.
911
912 The lifetime of an Item class object is often the same as a relational
913 statement, which may be used for several executions, but in some cases
914 it may also be generated for an optimized statement and thus be valid
915 only for one execution.
916
917 For Item objects with longer lifespan than one execution, we must take
918 special precautions when referencing objects with shorter lifespan.
919 For example, TABLE and Field objects against most tables are valid only for
920 one execution. For such objects, Item classes should rather reference
921 Table_ref and Item_field objects instead of TABLE and Field, because
922 these classes support dynamic rebinding of objects before each execution.
923 See Item::bind_fields() which binds new objects per execution and
924 Item::cleanup() that deletes references to such objects.
925
926 These mechanisms can also be used to handle other objects with shorter
927 lifespan, such as function references and variable references.
928*/
929class Item : public Parse_tree_node {
931
932 friend class udf_handler;
933
934 protected:
935 /**
936 Sets the result value of the function an empty string, using the current
937 character set. No memory is allocated.
938 @retval A pointer to the str_value member.
939 */
942 return &str_value;
943 }
944
945 public:
946 Item(const Item &) = delete;
947 void operator=(Item &) = delete;
948 static void *operator new(size_t size) noexcept {
949 return (*THR_MALLOC)->Alloc(size);
950 }
951 static void *operator new(size_t size, MEM_ROOT *mem_root,
952 const std::nothrow_t &arg
953 [[maybe_unused]] = std::nothrow) noexcept {
954 return mem_root->Alloc(size);
955 }
956
957 static void operator delete(void *ptr [[maybe_unused]],
958 size_t size [[maybe_unused]]) {
959 TRASH(ptr, size);
960 }
961 static void operator delete(void *, MEM_ROOT *,
962 const std::nothrow_t &) noexcept {}
963
964 enum Type {
966 FIELD_ITEM, ///< A reference to a field (column) in a table.
967 FUNC_ITEM, ///< A function call reference.
968 SUM_FUNC_ITEM, ///< A grouped aggregate function, or window function.
969 AGGR_FIELD_ITEM, ///< A special field for certain aggregate operations.
970 STRING_ITEM, ///< A string literal value.
971 INT_ITEM, ///< An integer literal value.
972 DECIMAL_ITEM, ///< A decimal literal value.
973 REAL_ITEM, ///< A floating-point literal value.
974 JSON_ITEM, ///< A JSON 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 /**
1907 Produces a key suitable for filesort. Most of the time, val_int() would
1908 suffice, but for temporal values, the packed value (as sent to the handler)
1909 is called for. It is also necessary that the value is in UTC. This function
1910 supplies just that.
1911
1912 @return A sort key value.
1913 */
1915 if (data_type() == MYSQL_TYPE_TIME) {
1916 Time_val time;
1917 if (val_time(&time)) return 0;
1918 return time.for_comparison();
1919 } else if (data_type() == MYSQL_TYPE_DATE) {
1920 Date_val date;
1921 if (val_date(&date, 0)) return 0;
1922 return date.for_comparison();
1923 } else if (is_temporal_with_date()) {
1924 return val_date_temporal_at_utc();
1925 } else {
1926 return val_int();
1927 }
1928 }
1929
1930 /**
1931 Get date or time value in packed longlong format.
1932 Before conversion from MYSQL_TIME to packed format,
1933 the MYSQL_TIME value is rounded to "dec" fractional digits.
1934 */
1936
1937 /*
1938 This is just a shortcut to avoid the cast. You should still use
1939 unsigned_flag to check the sign of the item.
1940 */
1941 inline ulonglong val_uint() { return (ulonglong)val_int(); }
1942 /*
1943 Return string representation of this item object.
1944
1945 SYNOPSIS
1946 val_str()
1947 str an allocated buffer this or any nested Item object can use to
1948 store return value of this method.
1949
1950 NOTE
1951 Buffer passed via argument should only be used if the item itself
1952 doesn't have an own String buffer. In case when the item maintains
1953 it's own string buffer, it's preferable to return it instead to
1954 minimize number of mallocs/memcpys.
1955 The caller of this method can modify returned string, but only in case
1956 when it was allocated on heap, (is_alloced() is true). This allows
1957 the caller to efficiently use a buffer allocated by a child without
1958 having to allocate a buffer of it's own. The buffer, given to
1959 val_str() as argument, belongs to the caller and is later used by the
1960 caller at it's own choosing.
1961 A few implications from the above:
1962 - unless you return a string object which only points to your buffer
1963 but doesn't manages it you should be ready that it will be
1964 modified.
1965 - even for not allocated strings (is_alloced() == false) the caller
1966 can change charset (see Item_func_{typecast/binary}. XXX: is this
1967 a bug?
1968 - still you should try to minimize data copying and return internal
1969 object whenever possible.
1970
1971 RETURN
1972 In case of NULL value or error, return error_str() as this function will
1973 check if the return value may be null, and it will either set null_value
1974 to true and return nullptr or to false and it will return empty string.
1975 If value is not null set null_value flag to false before returning it.
1976 */
1977 virtual String *val_str(String *str) = 0;
1978
1979 /*
1980 Returns string representation of this item in ASCII format.
1981
1982 SYNOPSIS
1983 val_str_ascii()
1984 str - similar to val_str();
1985
1986 NOTE
1987 This method is introduced for performance optimization purposes.
1988
1989 1. val_str() result of some Items in string context
1990 depends on @@character_set_results.
1991 @@character_set_results can be set to a "real multibyte" character
1992 set like UCS2, UTF16, UTF32. (We'll use only UTF32 in the examples
1993 below for convenience.)
1994
1995 So the default string result of such functions
1996 in these circumstances is real multi-byte character set, like UTF32.
1997
1998 For example, all numbers in string context
1999 return result in @@character_set_results:
2000
2001 SELECT CONCAT(20010101); -> UTF32
2002
2003 We do sprintf() first (to get ASCII representation)
2004 and then convert to UTF32;
2005
2006 So these kind "data sources" can use ASCII representation
2007 internally, but return multi-byte data only because
2008 @@character_set_results wants so.
2009 Therefore, conversion from ASCII to UTF32 is applied internally.
2010
2011
2012 2. Some other functions need in fact ASCII input.
2013
2014 For example,
2015 inet_aton(), GeometryFromText(), Convert_TZ(), GET_FORMAT().
2016
2017 Similar, fields of certain type, like DATE, TIME,
2018 when you insert string data into them, expect in fact ASCII input.
2019 If they get non-ASCII input, for example UTF32, they
2020 convert input from UTF32 to ASCII, and then use ASCII
2021 representation to do further processing.
2022
2023
2024 3. Now imagine we pass result of a data source of the first type
2025 to a data destination of the second type.
2026
2027 What happens:
2028 a. data source converts data from ASCII to UTF32, because
2029 @@character_set_results wants so and passes the result to
2030 data destination.
2031 b. data destination gets UTF32 string.
2032 c. data destination converts UTF32 string to ASCII,
2033 because it needs ASCII representation to be able to handle data
2034 correctly.
2035
2036 As a result we get two steps of unnecessary conversion:
2037 From ASCII to UTF32, then from UTF32 to ASCII.
2038
2039 A better way to handle these situations is to pass ASCII
2040 representation directly from the source to the destination.
2041
2042 This is why val_str_ascii() introduced.
2043
2044 RETURN
2045 Similar to val_str()
2046 */
2047 virtual String *val_str_ascii(String *str);
2048
2049 /**
2050 Evaluate item and return result as a decimal value.
2051
2052 @param decimal_buffer buffer which can be used by Item for returning value
2053 (but need not be)
2054
2055 @note
2056 Returned value should not be changed if it is not the same as the one
2057 passed via argument.
2058
2059 @note Example implementation for Item with two arguments:
2060
2061 my_decimal *Item_func_<x>::decimal_op(my_decimal *decimal_value) {
2062 assert(fixed);
2063 my_decimal value1, value2;
2064 null_value = false; // Initialize null_value
2065 // First, process the first argument completely
2066 my_decimal *val1 = args[0]->val_decimal(&value1);
2067 if (val1 == nullptr) { // Handle error or NULL value
2068 null_value = args[0]->null_value; // Propagate NULL value
2069 return nullptr;
2070 }
2071 // Next, process the second argument completely
2072 my_decimal *val2 = args[1]->val_decimal(&value2);
2073 if (val2 == nullptr) { // Handle error or NULL value
2074 null_value = args[1]->null_value; // Propagate NULL value
2075 return nullptr;
2076 }
2077 // Evaluate result into decimal_value, possibly set nullptr or error
2078 if (evaluate(val1, val2) {
2079 return nullptr;
2080 }
2081 return decimal_value; // Return non-NULL result
2082 }
2083
2084 @note Example implementation that converts from other data type
2085
2086 my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value) {
2087 Date_val date;
2088 if (val_date(&date, 0)) { // Evaluate date, possibly with error or NULL
2089 return nullptr; // No NULL value propagation necessary here
2090 }
2091 if (date_to_decimal(date, decimal_value) == nullptr) {
2092 return nullptr; // In case conversion caused an error
2093 }
2094 return decimal_value;
2095 }
2096
2097 @returns pointer to my_decimal value if evaluation was successful
2098 nullptr is returned if evaluation ended in error, or a NULL value
2099 was generated. Unless error is returned, null_value indicates
2100 whether NULL value is returned or not.
2101 */
2102 virtual my_decimal *val_decimal(my_decimal *decimal_buffer) = 0;
2103 /*
2104 Return boolean value of item.
2105
2106 RETURN
2107 false value is false or NULL
2108 true value is true (not equal to 0)
2109 */
2110 virtual bool val_bool();
2111
2112 /**
2113 Get a JSON value from an Item.
2114
2115 All subclasses that can return a JSON value, should override this
2116 function. The function in the base class is not expected to be
2117 called. If it is called, it most likely means that some subclass
2118 is missing an override of val_json().
2119
2120 @param[in,out] result The resulting Json_wrapper.
2121
2122 @return false if successful, true on failure
2123 */
2124 /* purecov: begin deadcode */
2125 virtual bool val_json(Json_wrapper *result [[maybe_unused]]) {
2126 assert(false);
2127 my_error(ER_NOT_SUPPORTED_YET, MYF(0), "item type for JSON");
2128 return error_json();
2129 }
2130 /* purecov: end */
2131
2132 /**
2133 Calculate the filter contribution that is relevant for table
2134 'filter_for_table' for this item.
2135
2136 @param thd Thread handler
2137 @param filter_for_table The table we are calculating filter effect for
2138 @param read_tables Tables earlier in the join sequence.
2139 Predicates for table 'filter_for_table' that
2140 rely on values from these tables can be part of
2141 the filter effect.
2142 @param fields_to_ignore Fields in 'filter_for_table' that should not
2143 be part of the filter calculation. The filtering
2144 effect of these fields is already part of the
2145 calculation somehow (e.g. because there is a
2146 predicate "col = <const>", and the optimizer
2147 has decided to do ref access on 'col').
2148 @param rows_in_table The number of rows in table 'filter_for_table'
2149
2150 @return the filtering effect (between 0 and 1) this
2151 Item contributes with.
2152 */
2153 virtual float get_filtering_effect(THD *thd [[maybe_unused]],
2154 table_map filter_for_table
2155 [[maybe_unused]],
2156 table_map read_tables [[maybe_unused]],
2157 const MY_BITMAP *fields_to_ignore
2158 [[maybe_unused]],
2159 double rows_in_table [[maybe_unused]]) {
2160 // Filtering effect cannot be calculated for a table already read.
2161 assert((read_tables & filter_for_table) == 0);
2162 return COND_FILTER_ALLPASS;
2163 }
2164
2165 /**
2166 Get the value to return from val_json() in case of errors.
2167
2168 @see Item::error_bool
2169
2170 @return The value val_json() should return, which is true.
2171 */
2172 bool error_json() {
2174 return true;
2175 }
2176
2177 /**
2178 Convert a non-temporal type to date
2179 */
2181
2182 /**
2183 Convert a non-temporal type to time
2184 */
2186 /**
2187 Convert a non-temporal type to datetime
2188 */
2190
2191 protected:
2192 /* Helper functions, see item_sum.cc */
2210 double val_real_from_decimal();
2211 double val_real_from_string();
2212
2213 /**
2214 Get the value to return from val_bool() in case of errors.
2215
2216 This function is called from val_bool() when an error has occurred
2217 and we need to return something to abort evaluation of the
2218 item. The expected pattern in val_bool() is
2219
2220 if (@<error condition@>)
2221 {
2222 my_error(...)
2223 return error_bool();
2224 }
2225
2226 @return The value val_bool() should return.
2227 */
2228 bool error_bool() {
2230 return false;
2231 }
2232
2233 /**
2234 Get the value to return from val_int() in case of errors.
2235
2236 @see Item::error_bool
2237
2238 @return The value val_int() should return.
2239 */
2242 return 0;
2243 }
2244
2245 /**
2246 Get the value to return from val_real() in case of errors.
2247
2248 @see Item::error_bool
2249
2250 @return The value val_real() should return.
2251 */
2252 double error_real() {
2254 return 0.0;
2255 }
2256
2257 /**
2258 Get the value to return from val_date() in case of errors.
2259
2260 @see Item::error_bool
2261
2262 @return The true: the function failed.
2263 */
2264 bool error_date() {
2266 return true;
2267 }
2268
2269 /**
2270 Get the value to return from val_time() in case of errors.
2271
2272 @see Item::error_bool
2273
2274 @return The true: the function failed.
2275 */
2276 bool error_time() {
2278 return true;
2279 }
2280
2281 public:
2282 /**
2283 Get the value to return from val_str() in case of error or NULL value.
2284
2285 @see Item::error_bool
2286
2287 @return The value val_str() should return.
2288 */
2292 }
2293
2294 protected:
2295 /**
2296 Gets the value to return from val_str() when returning a NULL value.
2297 @return The value val_str() should return.
2298 */
2300 assert(m_nullable);
2301 null_value = true;
2302 return nullptr;
2303 }
2304
2305 /**
2306 Convert val_str() to date
2307 */
2309 /**
2310 Convert val_real() to date
2311 */
2313 /**
2314 Convert val_decimal() to date
2315 */
2317 /**
2318 Convert val_int() to date
2319 */
2321 /**
2322 Convert val_time() to date
2323 */
2324 bool get_date_from_time(Date_val *date);
2325 /**
2326 Convert a numeric type to date
2327 */
2329
2330 /**
2331 Convert val_str() to datetime
2332 */
2334 /**
2335 Convert val_real() to datetime
2336 */
2338 /**
2339 Convert val_decimal() to datetime
2340 */
2342 /**
2343 Convert val_int() to datetime
2344 */
2346 /**
2347 Convert val_time() to datetime
2348 */
2350 /**
2351 Convert val_date() to datetime
2352 */
2354
2355 /**
2356 Convert a numeric type to datetime
2357 */
2359
2360 /**
2361 Convert val_str() to time
2362 */
2363 bool get_time_from_string(Time_val *time);
2364 /**
2365 Convert val_real() to time
2366 */
2367 bool get_time_from_real(Time_val *time);
2368 /**
2369 Convert val_decimal() to time
2370 */
2371 bool get_time_from_decimal(Time_val *time);
2372 /**
2373 Convert val_int() to time
2374 */
2375 bool get_time_from_int(Time_val *time);
2376 /**
2377 Convert date to time
2378 */
2379 bool get_time_from_date(Time_val *time);
2380 /**
2381 Convert datetime to time
2382 */
2383 bool get_time_from_datetime(Time_val *time);
2384
2385 /**
2386 Convert a numeric type to time
2387 */
2388 bool get_time_from_numeric(Time_val *time);
2389
2391
2392 public:
2397
2398 /**
2399 If this Item is being materialized into a temporary table, returns the
2400 field that is being materialized into. (Typically, this is the
2401 “result_field” members for items that have one.)
2402 */
2404 DBUG_TRACE;
2405 return nullptr;
2406 }
2407 /* This is also used to create fields in CREATE ... SELECT: */
2408 virtual Field *tmp_table_field(TABLE *) { return nullptr; }
2409 virtual const char *full_name() const {
2410 return item_name.is_set() ? item_name.ptr() : "???";
2411 }
2412
2413 /* bit map of tables used by item */
2414 virtual table_map used_tables() const { return (table_map)0L; }
2415
2416 /**
2417 Return table map of tables that can't be NULL tables (tables that are
2418 used in a context where if they would contain a NULL row generated
2419 by a LEFT or RIGHT join, the item would not be true).
2420 This expression is used on WHERE item to determinate if a LEFT JOIN can be
2421 converted to a normal join.
2422 Generally this function should return used_tables() if the function
2423 would return null if any of the arguments are null
2424 As this is only used in the beginning of optimization, the value don't
2425 have to be updated in update_used_tables()
2426 */
2427 virtual table_map not_null_tables() const { return used_tables(); }
2428
2429 /**
2430 Returns true if this is a simple constant item like an integer, not
2431 a constant expression. Used in the optimizer to propagate basic constants.
2432 It is assumed that val_xxx() does not modify the item's state for
2433 such items. It is also assumed that val_str() can be called with nullptr
2434 as argument as val_str() will return an internally cached const string.
2435 */
2436 virtual bool basic_const_item() const { return false; }
2437 /**
2438 @returns true when a const item may be evaluated during resolving.
2439 Only const items that are basic const items are evaluated when
2440 resolving CREATE VIEW statements. For other statements, all
2441 const items may be evaluated during resolving.
2442 */
2443 bool may_eval_const_item(const THD *thd) const;
2444 /**
2445 @return cloned item if it is constant
2446 @retval nullptr if this is not const
2447 */
2448 virtual Item *clone_item() const { return nullptr; }
2449 virtual cond_result eq_cmp_result() const { return COND_OK; }
2450 inline uint float_length(uint decimals_par) const {
2451 return decimals != DECIMAL_NOT_SPECIFIED ? (DBL_DIG + 2 + decimals_par)
2452 : DBL_DIG + 8;
2453 }
2454 virtual uint decimal_precision() const;
2455 inline int decimal_int_part() const {
2457 }
2458 /**
2459 TIME precision of the item: 0..6
2460 */
2461 virtual uint time_precision();
2462 /**
2463 DATETIME precision of the item: 0..6
2464 */
2465 virtual uint datetime_precision();
2466 /**
2467 Returns true if item is constant, regardless of query evaluation state.
2468 An expression is constant if it:
2469 - refers no tables.
2470 - refers no subqueries that refers any tables.
2471 - refers no non-deterministic functions.
2472 - refers no statement parameters.
2473 - contains no group expression under rollup
2474 */
2475 bool const_item() const { return (used_tables() == 0); }
2476 /**
2477 Returns true if item is constant during one query execution.
2478 If const_for_execution() is true but const_item() is false, value is
2479 not available before tables have been locked and parameters have been
2480 assigned values. This applies to
2481 - statement parameters
2482 - non-dependent subqueries
2483 - deterministic stored functions that contain SQL code.
2484 For items where the default implementation of used_tables() and
2485 const_item() are effective, const_item() will always return true.
2486 */
2487 bool const_for_execution() const {
2488 return !(used_tables() & ~INNER_TABLE_BIT);
2489 }
2490
2491 /**
2492 Return true if this is a const item that may be evaluated in
2493 the current phase of statement processing.
2494 - No evaluation is performed when analyzing a view, otherwise:
2495 - Items that have the const_item() property can always be evaluated.
2496 - Items that have the const_for_execution() property can be evaluated when
2497 tables are locked (ie during optimization or execution).
2498
2499 This function should be used in the following circumstances:
2500 - during preparation to check whether an item can be permanently transformed
2501 - to check that an item is constant in functions that may be used in both
2502 the preparation and optimization phases.
2503
2504 This function should not be used by code that is called during optimization
2505 and/or execution only. Use const_for_execution() in this case.
2506 */
2507 bool may_evaluate_const(const THD *thd) const;
2508
2509 /**
2510 @returns true if this item is non-deterministic, which means that a
2511 has a component that must be evaluated once per row in
2512 execution of a JOIN query.
2513 */
2515
2516 /**
2517 @returns true if this item is an outer reference, usually this means that
2518 it references a column that contained in a table located in
2519 the FROM clause of an outer query block.
2520 */
2521 bool is_outer_reference() const {
2523 }
2524
2525 /**
2526 This method is used for to:
2527 - to generate a view definition query (SELECT-statement);
2528 - to generate a SQL-query for EXPLAIN EXTENDED;
2529 - to generate a SQL-query to be shown in INFORMATION_SCHEMA;
2530 - to generate a SQL-query that looks like a prepared statement for
2531 query_rewrite
2532 - debug.
2533
2534 For more information about view definition query, INFORMATION_SCHEMA
2535 query and why they should be generated from the Item-tree, @see
2536 mysql_register_view().
2537 */
2538 virtual void print(const THD *, String *str, enum_query_type) const {
2539 str->append(full_name());
2540 }
2541
2542 /**
2543 Generate hash unique to an item depending on its attributes. When overriding
2544 this function, care must be taken to properly handle and fix possible hash
2545 collisions, either due to missing attributes or other reasons.
2546
2547 If a unique hash cannot be generated for the Item (e.g. due to lack of
2548 available information), the NULL hash value should be returned (0).
2549 */
2550 virtual uint64_t hash() { return 0; }
2551
2552 void print_item_w_name(const THD *thd, String *,
2553 enum_query_type query_type) const;
2554 /**
2555 Prints the item when it's part of ORDER BY and GROUP BY.
2556 @param thd Thread handle
2557 @param str String to print to
2558 @param query_type How to format the item
2559 @param used_alias The alias with which this item was referenced, or
2560 nullptr if it was not referenced with an alias.
2561 */
2562 void print_for_order(const THD *thd, String *str, enum_query_type query_type,
2563 const char *used_alias) const;
2564
2565 /**
2566 Updates used tables, not null tables information and accumulates
2567 properties up the item tree, cf. used_tables_cache, not_null_tables_cache
2568 and m_accum_properties.
2569
2570 TODO(sgunders): Consider just removing these caches; it causes a lot of bugs
2571 (cache invalidation is known to be a complex problem), and the performance
2572 benefits are dubious.
2573 */
2574 virtual void update_used_tables() {}
2575
2577 return false;
2578 }
2579 /* Called for items that really have to be split */
2580 bool split_sum_func2(THD *thd, Ref_item_array ref_item_array,
2581 mem_root_deque<Item *> *fields, Item **ref,
2582 bool skip_registered);
2583 /**
2584 Evaluate the item and return result as a date value
2585
2586 @param[out] date Returned date value
2587 @param flags Limit the value returned according to TIME_NO_ZERO_IN_DATE,
2588 TIME_NO_ZERO_DATE, TIME_NO_INVALID_DATES.
2589
2590 @returns false if successful and non-NULL, true otherwise
2591 */
2592 virtual bool val_date(Date_val *date, my_time_flags_t flags) = 0;
2593 /**
2594 Evaluate the item and return result as a time value.
2595
2596 @param[out] time Returned time value.
2597
2598 @returns false if successful and non-NULL, true otherwise
2599 */
2600 virtual bool val_time(Time_val *time) = 0;
2601
2602 /**
2603 Evaluate the item and return result as a datetime value
2604
2605 @param[out] dt Returned datetime value
2606 @param flags Limit the value returned according to TIME_NO_ZERO_IN_DATE,
2607 TIME_NO_ZERO_DATE, TIME_NO_INVALID_DATES.
2608
2609 @returns false if successful and non-NULL, true otherwise
2610 true return means that the result is either a NULL value,
2611 or an error.
2612 */
2614 /**
2615 Get timestamp in "struct timeval" format.
2616 @retval false on success
2617 @retval true on error
2618 */
2619 virtual bool get_timeval(my_timeval *tm, int *warnings);
2620 /**
2621 The method allows to determine nullness of a complex expression
2622 without fully evaluating it, instead of calling val*() then
2623 checking null_value. Used in Item_func_isnull/Item_func_isnotnull
2624 and Item_sum_count/Item_sum_count_distinct.
2625 Any item which can be NULL must implement this method.
2626
2627 @retval false if the expression is not NULL.
2628 @retval true if the expression is NULL, or evaluation caused an error.
2629 The null_value member is set according to the return value.
2630 */
2631 virtual bool is_null() { return false; }
2632
2633 /**
2634 Make sure the null_value member has a correct value.
2635 null_value is set true also when evaluation causes error.
2636
2637 @returns false if success, true if error
2638 */
2639 bool update_null_value();
2640
2641 /**
2642 Apply the IS TRUE truth property, meaning that an UNKNOWN result and a
2643 FALSE result are treated the same.
2644
2645 This property is applied e.g to all conditions in WHERE, HAVING and ON
2646 clauses, and is recursively applied to operands of AND, OR
2647 operators. Some items (currently AND and subquery predicates) may enable
2648 special optimizations when they have this property.
2649 */
2650 virtual void apply_is_true() {}
2651 /*
2652 set field of temporary table for Item which can be switched on temporary
2653 table during query processing (grouping and so on). @see
2654 Item_result_field.
2655 */
2656 virtual void set_result_field(Field *) {}
2657 virtual bool is_result_field() const { return false; }
2658 virtual Field *get_result_field() const { return nullptr; }
2659 virtual bool is_bool_func() const { return false; }
2660 /*
2661 Set value of aggregate function in case of no rows for grouping were found.
2662 Also used for subqueries with outer references in SELECT list.
2663 */
2664 virtual void no_rows_in_result() {}
2665 virtual Item *copy_or_same(THD *) { return this; }
2666 virtual Item *copy_andor_structure(THD *) { return this; }
2667 /**
2668 @returns the "real item" underlying the owner object. Used to strip away
2669 Item_ref objects.
2670 @note remember to implement both real_item() functions in sub classes!
2671 */
2672 virtual Item *real_item() { return this; }
2673 virtual const Item *real_item() const { return this; }
2674 /**
2675 If an Item is materialized in a temporary table, a different Item may have
2676 to be used in the part of the query that runs after the materialization.
2677 For instance, if the Item was an Item_field, the new Item_field needs to
2678 point into the temporary table instead of the original one, but if, on the
2679 other hand, the Item was a literal constant, it can be reused as-is.
2680 This function encapsulates these policies for the different kinds of Items.
2681 See also get_tmp_table_field().
2682
2683 TODO: Document how aggregate functions (Item_sum) are handled.
2684 */
2685 virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); }
2686
2687 static const CHARSET_INFO *default_charset();
2688 virtual const CHARSET_INFO *compare_collation() const { return nullptr; }
2689
2690 /*
2691 For backward compatibility, to make numeric
2692 data types return "binary" charset in client-side metadata.
2693 */
2696 : &my_charset_bin;
2697 }
2698
2699 /**
2700 Traverses a tree of Items in prefix and/or postfix order.
2701 Optionally walks into subqueries.
2702
2703 @param processor processor function to be invoked per item
2704 returns true to abort traversal, false to continue
2705 @param walk controls how to traverse the item tree
2706 enum_walk::PREFIX: call processor before invoking
2707 children enum_walk::POSTFIX: call processor after invoking children
2708 enum_walk::SUBQUERY go down into subqueries
2709 walk values are bit-coded and may be combined.
2710 Omitting both enum_walk::PREFIX and enum_walk::POSTFIX
2711 is undefined behaviour.
2712 @param arg Optional pointer to a walk-specific object
2713
2714 @retval false walk succeeded
2715 @retval true walk aborted
2716 by agreement, an error may have been reported
2717 */
2718
2719 virtual bool walk(Item_processor processor, enum_walk walk [[maybe_unused]],
2720 uchar *arg) {
2721 return ((walk & enum_walk::PREFIX) && (this->*processor)(arg)) ||
2722 ((walk & enum_walk::POSTFIX) && (this->*processor)(arg));
2723 }
2724
2725 /** @see WalkItem, CompileItem, TransformItem */
2726 template <class T>
2728 return (*reinterpret_cast<std::remove_reference_t<T> *>(arg))(this);
2729 }
2730
2731 /** See CompileItem */
2732 template <class T>
2734 return (*reinterpret_cast<std::remove_reference_t<T> *>(*arg))(this);
2735 }
2736
2737 /**
2738 Perform a generic transformation of the Item tree, by adding zero or
2739 more additional Item objects to it.
2740
2741 @param transformer Transformer function
2742 @param[in,out] arg Pointer to struct used by transformer function
2743
2744 @returns Returned item tree after transformation, NULL if error
2745
2746 Transformation is performed as follows:
2747
2748 @code
2749 transform()
2750 {
2751 transform children if any;
2752 return this->*some_transformer(...);
2753 }
2754 @endcode
2755
2756 Note that unlike Item::compile(), transform() does not support an analyzer
2757 function, ie. all children are unconditionally invoked.
2758
2759 Item::transform() should handle all transformations during preparation.
2760 Notice that all transformations are permanent; they are not rolled back.
2761
2762 Use Item::compile() to perform transformations during optimization.
2763 */
2764 virtual Item *transform(Item_transformer transformer, uchar *arg);
2765
2766 /**
2767 Perform a generic "compilation" of the Item tree, ie transform the Item tree
2768 by adding zero or more Item objects to it.
2769
2770 @param analyzer Analyzer function, see details section
2771 @param[in,out] arg_p Pointer to struct used by analyzer function
2772 @param transformer Transformer function, see details section
2773 @param[in,out] arg_t Pointer to struct used by transformer function
2774
2775 @returns Returned item tree after transformation, NULL if error
2776
2777 The process of this transformation is assumed to be as follows:
2778
2779 @code
2780 compile()
2781 {
2782 if (this->*some_analyzer(...))
2783 {
2784 compile children if any;
2785 return this->*some_transformer(...);
2786 }
2787 else
2788 return this;
2789 }
2790 @endcode
2791
2792 i.e. analysis is performed top-down while transformation is done
2793 bottom-up. If no transformation is applied, the item is returned unchanged.
2794 A transformation error is indicated by returning a NULL pointer. Notice
2795 that the analyzer function should never cause an error.
2796
2797 The function is supposed to be used during the optimization stage of
2798 query execution. All new allocations are recorded using
2799 THD::change_item_tree() so that they can be rolled back after execution.
2800
2801 @todo Pass THD to compile() function, thus no need to use current_thd.
2802 */
2803 virtual Item *compile(Item_analyzer analyzer, uchar **arg_p,
2804 Item_transformer transformer, uchar *arg_t) {
2805 if ((this->*analyzer)(arg_p)) return ((this->*transformer)(arg_t));
2806 return this;
2807 }
2808
2809 virtual void traverse_cond(Cond_traverser traverser, void *arg,
2811 (*traverser)(this, arg);
2812 }
2813
2814 /*
2815 This is used to get the most recent version of any function in
2816 an item tree. The version is the version where a MySQL function
2817 was introduced in. So any function which is added should use
2818 this function and set the int_arg to maximum of the input data
2819 and their own version info.
2820 */
2821 virtual bool intro_version(uchar *) { return false; }
2822
2823 /// cleanup() item if it is resolved ('fixed').
2825 if (fixed) cleanup();
2826 return false;
2827 }
2829 return *(pointer_cast<Item **>(arg)) == this;
2830 }
2831 virtual bool collect_item_field_processor(uchar *) { return false; }
2832 virtual bool collect_item_field_or_ref_processor(uchar *) { return false; }
2833 virtual bool collect_outer_field_processor(uchar *) { return false; }
2834
2836 public:
2839 : m_items(fields_or_refs) {}
2842 const Collect_item_fields_or_refs &) = delete;
2843
2844 friend class Item_sum;
2845 friend class Item_field;
2846 friend class Item_ref;
2847 };
2848
2850 public:
2853 /// Used to compute \c Item_field's \c m_protected_by_any_value. Pushed and
2854 /// popped when walking arguments of \c Item_func_any_value.a
2857 Query_block *transformed_block)
2858 : m_item_fields_or_view_refs(fields_or_vr),
2859 m_transformed_block(transformed_block) {}
2861 delete;
2863 const Collect_item_fields_or_view_refs &) = delete;
2864
2865 friend class Item_sum;
2866 friend class Item_field;
2868 friend class Item_view_ref;
2869 };
2870
2871 /**
2872 Collects fields and view references that have the qualifying table
2873 in the specified query block.
2874 */
2876 return false;
2877 }
2878
2879 /**
2880 Item::walk function. Set bit in table->tmp_set for all fields in
2881 table 'arg' that are referred to by the Item.
2882 */
2883 virtual bool add_field_to_set_processor(uchar *) { return false; }
2884
2885 /// A processor to handle the select lex visitor framework.
2886 virtual bool visitor_processor(uchar *arg);
2887
2888 /**
2889 Item::walk function. Set bit in table->cond_set for all fields of
2890 all tables that are referred to by the Item.
2891 */
2892 virtual bool add_field_to_cond_set_processor(uchar *) { return false; }
2893
2894 /**
2895 Visitor interface for removing all column expressions (Item_field) in
2896 this expression tree from a bitmap. @see walk()
2897
2898 @param arg A MY_BITMAP* cast to unsigned char*, where the bits represent
2899 Field::field_index values.
2900 */
2901 virtual bool remove_column_from_bitmap(uchar *arg [[maybe_unused]]) {
2902 return false;
2903 }
2904 virtual bool find_item_in_field_list_processor(uchar *) { return false; }
2905 virtual bool change_context_processor(uchar *) { return false; }
2906 virtual bool find_item_processor(uchar *arg) { return this == (void *)arg; }
2908 return !basic_const_item();
2909 }
2910 /// Is this an Item_field which references the given Field argument?
2911 virtual bool find_field_processor(uchar *) { return false; }
2912 /// Wrap incompatible arguments in CAST nodes to the expected data types
2913 virtual bool cast_incompatible_args(uchar *) { return false; }
2914 /**
2915 Mark underlying field in read or write map of a table.
2916
2917 @param arg Mark_field object
2918 */
2919 virtual bool mark_field_in_map(uchar *arg [[maybe_unused]]) { return false; }
2920
2921 protected:
2922 /**
2923 Helper function for mark_field_in_map(uchar *arg).
2924
2925 @param mark_field Mark_field object
2926 @param field Field to be marked for read/write
2927 */
2928 static inline bool mark_field_in_map(Mark_field *mark_field, Field *field) {
2929 TABLE *table = mark_field->table;
2930 if (table != nullptr && table != field->table) return false;
2931
2932 table = field->table;
2933 table->mark_column_used(field, mark_field->mark);
2934
2935 return false;
2936 }
2937
2938 public:
2939 /**
2940 Reset execution state for such window function types
2941 as determined by arg
2942
2943 @param arg pointing to a bool which, if true, says to reset state
2944 for framing window function, else for non-framing
2945 */
2946 virtual bool reset_wf_state(uchar *arg [[maybe_unused]]) { return false; }
2947
2948 /**
2949 Return used table information for the specified query block (level).
2950 For a field that is resolved from this query block, return the table number.
2951 For a field that is resolved from a query block outer to the specified one,
2952 return OUTER_REF_TABLE_BIT
2953
2954 @param[in,out] arg pointer to an instance of class Used_tables, which is
2955 constructed with the query block as argument.
2956 The used tables information is accumulated in the field
2957 used_tables in this class.
2958
2959 @note This function is used to update used tables information after
2960 merging a query block (a subquery) with its parent.
2961 */
2962 virtual bool used_tables_for_level(uchar *arg [[maybe_unused]]) {
2963 return false;
2964 }
2965 /**
2966 Check privileges.
2967
2968 @param thd thread handle
2969 */
2970 virtual bool check_column_privileges(uchar *thd [[maybe_unused]]) {
2971 return false;
2972 }
2973 virtual bool inform_item_in_cond_of_tab(uchar *) { return false; }
2974 /**
2975 Bind objects from the current execution context to field objects in
2976 item trees. Typically used to bind Field objects from TABLEs to
2977 Item_field objects.
2978 */
2979 virtual void bind_fields() {}
2980
2981 /**
2982 Context object for (functions that override)
2983 Item::clean_up_after_removal().
2984 */
2986 public:
2988 assert(root != nullptr);
2989 }
2990
2992
2993 private:
2994 /**
2995 Pointer to Cleanup_after_removal_context containing from which
2996 select the walk started, i.e., the Query_block that contained the clause
2997 that was removed.
2998 */
3000
3001 friend class Item;
3002 friend class Item_func_eq;
3003 friend class Item_sum;
3004 friend class Item_subselect;
3005 friend class Item_ref;
3006 };
3007 /**
3008 Clean up after removing the item from the item tree.
3009
3010 param arg pointer to a Cleanup_after_removal_context object
3011 @todo: If class ORDER is refactored so that all indirect
3012 grouping/ordering expressions are represented with Item_ref
3013 objects, all implementations of cleanup_after_removal() except
3014 the one for Item_ref can be removed.
3015 */
3016 virtual bool clean_up_after_removal(uchar *arg);
3017
3018 /// @see Distinct_check::check_query()
3019 virtual bool aggregate_check_distinct(uchar *) { return false; }
3020 /// @see Group_check::check_query()
3021 virtual bool aggregate_check_group(uchar *) { return false; }
3022 /// @see Group_check::analyze_conjunct()
3023 virtual bool is_strong_side_column_not_in_fd(uchar *) { return false; }
3024 /// @see Group_check::is_in_fd_of_underlying()
3025 virtual bool is_column_not_in_fd(uchar *) { return false; }
3026 virtual Bool3 local_column(const Query_block *) const {
3027 return Bool3::false3();
3028 }
3029
3030 /**
3031 Minion class under \c Collect_scalar_subquery_info ("Css"). Information
3032 about one scalar subquery being considered for transformation
3033 */
3034 struct Css_info {
3035 /// set of locations
3037 /// the scalar subquery
3040 /// Where did we find item above? Used when \c m_location == \c L_JOIN_COND,
3041 /// nullptr for other locations.
3043 /// If true, we can forego cardinality checking of the derived table
3045 /// If true, add a COALESCE around replaced subquery: used for implicitly
3046 /// grouped COUNT() in subquery select list when subquery is correlated
3047 bool m_add_coalesce{false};
3048 /// Set iff \c m_add_coalesce is true: we may get a NULL anyway even for
3049 /// COUNT if a HAVING clause is false in the subquery.
3051 /// Index of the having expression copied to select list
3053 };
3054
3055 /**
3056 Context struct used by walk method collect_scalar_subqueries to
3057 accumulate information about scalar subqueries found.
3058
3059 In: m_location of expression walked, m_join_condition_context
3060 Out: m_list
3061 */
3063 enum Location { L_SELECT = 1, L_WHERE = 2, L_HAVING = 4, L_JOIN_COND = 8 };
3064 /// accumulated all scalar subqueries found
3065 std::vector<Css_info> m_list;
3066 /// we are currently looking at this kind of clause, cf. enum Location
3071 friend class Item_sum;
3073 };
3074
3075 virtual bool collect_scalar_subqueries(uchar *) { return false; }
3076 virtual bool collect_grouped_aggregates(uchar *) { return false; }
3077 virtual bool collect_subqueries(uchar *) { return false; }
3078 virtual bool update_depended_from(uchar *) { return false; }
3079 /**
3080 Check if an aggregate is referenced from within the GROUP BY
3081 clause of the query block in which it is aggregated. Such
3082 references will be rejected.
3083 @see Item_ref::fix_fields()
3084 @retval true if this is an aggregate which is referenced from
3085 the GROUP BY clause of the aggregating query block
3086 @retval false otherwise
3087 */
3088 virtual bool has_aggregate_ref_in_group_by(uchar *) { return false; }
3089
3090 bool visit_all_analyzer(uchar **) { return true; }
3091 virtual bool cache_const_expr_analyzer(uchar **cache_item);
3093
3094 virtual bool equality_substitution_analyzer(uchar **) { return false; }
3095
3096 virtual Item *equality_substitution_transformer(uchar *) { return this; }
3097
3098 /**
3099 Check if a partition function is allowed.
3100
3101 @return whether a partition function is not accepted
3102
3103 @details
3104 check_partition_func_processor is used to check if a partition function
3105 uses an allowed function. An allowed function will always ensure that
3106 X=Y guarantees that also part_function(X)=part_function(Y) where X is
3107 a set of partition fields and so is Y. The problems comes mainly from
3108 character sets where two equal strings can be quite unequal. E.g. the
3109 german character for double s is equal to 2 s.
3110
3111 The default is that an item is not allowed
3112 in a partition function. Allowed functions
3113 can never depend on server version, they cannot depend on anything
3114 related to the environment. They can also only depend on a set of
3115 fields in the table itself. They cannot depend on other tables and
3116 cannot contain any queries and cannot contain udf's or similar.
3117 If a new Item class is defined and it inherits from a class that is
3118 allowed in a partition function then it is very important to consider
3119 whether this should be inherited to the new class. If not the function
3120 below should be defined in the new Item class.
3121
3122 The general behaviour is that most integer functions are allowed.
3123 If the partition function contains any multi-byte collations then
3124 the function check_part_func_fields will report an error on the
3125 partition function independent of what functions are used. So the
3126 only character sets allowed are single character collation and
3127 even for those only a limited set of functions are allowed. The
3128 problem with multi-byte collations is that almost every string
3129 function has the ability to change things such that two strings
3130 that are equal will not be equal after manipulated by a string
3131 function. E.g. two strings one contains a double s, there is a
3132 special german character that is equal to two s. Now assume a
3133 string function removes one character at this place, then in
3134 one the double s will be removed and in the other there will
3135 still be one s remaining and the strings are no longer equal
3136 and thus the partition function will not sort equal strings into
3137 the same partitions.
3138
3139 So the check if a partition function is valid is two steps. First
3140 check that the field types are valid, next check that the partition
3141 function is valid. The current set of partition functions valid
3142 assumes that there are no multi-byte collations amongst the partition
3143 fields.
3144 */
3145 virtual bool check_partition_func_processor(uchar *) { return true; }
3146 virtual bool subst_argument_checker(uchar **arg) {
3147 if (*arg) *arg = nullptr;
3148 return true;
3149 }
3150 virtual bool explain_subquery_checker(uchar **) { return true; }
3151 virtual Item *explain_subquery_propagator(uchar *) { return this; }
3152
3153 virtual Item *equal_fields_propagator(uchar *) { return this; }
3154 // Mark the item to not be part of substitution.
3155 virtual bool disable_constant_propagation(uchar *) { return false; }
3156
3158 // Stack of pointers to enclosing functions
3160 };
3161 virtual Item *replace_equal_field(uchar *) { return this; }
3162 virtual bool replace_equal_field_checker(uchar **) { return true; }
3163 /*
3164 Check if an expression value has allowed arguments, like DATE/DATETIME
3165 for date functions. Also used by partitioning code to reject
3166 timezone-dependent expressions in a (sub)partitioning function.
3167 */
3168 virtual bool check_valid_arguments_processor(uchar *) { return false; }
3169
3170 /**
3171 Check if this item is allowed for a virtual column or inside a
3172 default expression. Should be overridden in child classes.
3173
3174 @param[in,out] args Due to the limitation of Item::walk()
3175 it is declared as a pointer to uchar, underneath there's a actually a
3176 structure of type Check_function_as_value_generator_parameters.
3177 It is used mainly in Item_field.
3178
3179 @returns true if function is not accepted
3180 */
3181 virtual bool check_function_as_value_generator(uchar *args);
3182
3183 /**
3184 Check if a generated expression depends on DEFAULT function with
3185 specific column name as argument.
3186
3187 @param[in] args Name of column used as DEFAULT function argument.
3188
3189 @returns false if the function is not DEFAULT(args), otherwise true.
3190 */
3192 [[maybe_unused]]) {
3193 return false;
3194 }
3195 /**
3196 Check if all the columns present in this expression are from the
3197 derived table. Used in determining if a condition can be pushed
3198 down to derived table.
3199 */
3200 virtual bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) {
3201 // A generic item cannot be pushed down unless it's a constant
3202 // which does not have a subquery.
3203 return !const_item() || has_subquery();
3204 }
3205
3206 /**
3207 Check if all the columns present in this expression are present
3208 in PARTITION clause of window functions of the derived table.
3209 Used in checking if a condition can be pushed down to derived table.
3210 */
3211 virtual bool check_column_in_window_functions(uchar *arg [[maybe_unused]]) {
3212 return false;
3213 }
3214 /**
3215 Check if all the columns present in this expression are present
3216 in GROUP BY clause of the derived table. Used in checking if
3217 a condition can be pushed down to derived table.
3218 */
3219 virtual bool check_column_in_group_by(uchar *arg [[maybe_unused]]) {
3220 return false;
3221 }
3222 /**
3223 Assuming this expression is part of a condition that would be pushed to the
3224 WHERE clause of a materialized derived table, replace, in this expression,
3225 each derived table's column with a clone of the expression lying under it
3226 in the derived table's definition. We replace with a clone, because the
3227 condition can be pushed further down in case of nested derived tables.
3228 */
3229 virtual Item *replace_with_derived_expr(uchar *arg [[maybe_unused]]) {
3230 return this;
3231 }
3232 /**
3233 Assuming this expression is part of a condition that would be pushed to the
3234 HAVING clause of a materialized derived table, replace, in this expression,
3235 each derived table's column with a reference to the expression lying under
3236 it in the derived table's definition. Unlike replace_with_derived_expr, a
3237 clone is not used because HAVING condition will not be pushed further
3238 down in case of nested derived tables.
3239 */
3240 virtual Item *replace_with_derived_expr_ref(uchar *arg [[maybe_unused]]) {
3241 return this;
3242 }
3243 /**
3244 Assuming this expression is part of a condition that would be pushed to a
3245 materialized derived table, replace, in this expression, each view reference
3246 with a clone of the expression in merged derived table's definition.
3247 We replace with a clone, because the referenced item in a view reference
3248 is shared by all the view references to that expression.
3249 */
3250 virtual Item *replace_view_refs_with_clone(uchar *arg [[maybe_unused]]) {
3251 return this;
3252 }
3253 /*
3254 For SP local variable returns pointer to Item representing its
3255 current value and pointer to current Item otherwise.
3256 */
3257 virtual Item *this_item() { return this; }
3258 virtual const Item *this_item() const { return this; }
3259
3260 /*
3261 For SP local variable returns address of pointer to Item representing its
3262 current value and pointer passed via parameter otherwise.
3263 */
3264 virtual Item **this_item_addr(THD *, Item **addr_arg) { return addr_arg; }
3265
3266 // Row emulation
3267 virtual uint cols() const { return 1; }
3268 virtual Item *element_index(uint) { return this; }
3269 virtual Item **addr(uint) { return nullptr; }
3270 virtual bool check_cols(uint c);
3271 // It is not row => null inside is impossible
3272 virtual bool null_inside() { return false; }
3273 // used in row subselects to get value of elements
3274 virtual void bring_value() {}
3275
3276 Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length) const;
3277 virtual Item_field *field_for_view_update() { return nullptr; }
3278 /**
3279 Informs an item that it is wrapped in a truth test, in case it wants to
3280 transforms itself to implement this test by itself.
3281 @param thd Thread handle
3282 @param test Truth test
3283 */
3284 virtual Item *truth_transformer(THD *thd [[maybe_unused]],
3285 Bool_test test [[maybe_unused]]) {
3286 return nullptr;
3287 }
3288 virtual Item *update_value_transformer(uchar *) { return this; }
3289
3291 Query_block *m_trans_block; ///< Transformed query block
3292 Query_block *m_curr_block; ///< Transformed query block or a contained
3293 ///< subquery. Pushed when diving into
3294 ///< subqueries.
3295 Item_replacement(Query_block *transformed_block, Query_block *current_block)
3296 : m_trans_block(transformed_block), m_curr_block(current_block) {}
3297 };
3299 Field *m_target; ///< The field to be replaced
3300 Item_field *m_item; ///< The replacement field
3301 ///< replacement field iff outer ref
3303 enum class Mode {
3304 CONFLATE, // include both Item_field and Item_default_value
3305 FIELD, // ignore Item_default_value
3306 DEFAULT_VALUE // ignore Item_field
3307 };
3310 Mode default_value = Mode::CONFLATE)
3311 : Item_replacement(select, select),
3312 m_target(target),
3313 m_item(item),
3314 m_default_value(default_value) {}
3315 };
3316
3318 Item_func *m_target; ///< The function call to be replaced
3319 Item_field *m_item; ///< The replacement field
3321 Query_block *select)
3322 : Item_replacement(select, select),
3323 m_target(func_target),
3324 m_item(item) {}
3325 };
3326
3328 Item *m_target; ///< The item identifying the view_ref to be replaced
3329 Field *m_field; ///< The replacement field
3330 Item_field *m_outer_field{nullptr}; ///< replacement field if outer ref
3331 ///< subquery. Pushed when diving into
3332 ///< subqueries.
3334 : Item_replacement(select, select), m_target(target), m_field(field) {}
3335 };
3336
3341 : m_target(target), m_replacement(replacement) {}
3342 };
3343
3344 /**
3345 When walking the item tree seeing an Item_singlerow_subselect matching
3346 a target, replace it with a substitute field used when transforming
3347 scalar subqueries into derived tables. Cf.
3348 Query_block::transform_scalar_subqueries_to_join_with_derived.
3349 */
3350 virtual Item *replace_scalar_subquery(uchar *) { return this; }
3351
3352 /**
3353 Transform processor used by Query_block::transform_grouped_to_derived
3354 to replace fields which used to be at the transformed query block
3355 with corresponding fields in the new derived table containing the grouping
3356 operation of the original transformed query block.
3357 */
3358 virtual Item *replace_item_field(uchar *) { return this; }
3359 virtual Item *replace_func_call(uchar *) { return this; }
3360 virtual Item *replace_item_view_ref(uchar *) { return this; }
3361 virtual Item *replace_aggregate(uchar *) { return this; }
3362 virtual Item *replace_outer_ref(uchar *) { return this; }
3363
3368 : m_target(target), m_owner(owner) {}
3369 };
3370
3371 /**
3372 A walker processor overridden by Item_aggregate_ref, q.v.
3373 */
3374 virtual bool update_aggr_refs(uchar *) { return false; }
3375
3376 /**
3377 Convert constant string in this object into the specified character set.
3378
3379 @param thd thread handler
3380 @param tocs target character set
3381 @param ignore_errors if true, ignore errors in conversion
3382
3383 @returns pointer to new Item containing converted character string
3384 = NULL: If conversion failed
3385 */
3386 Item *convert_charset(THD *thd, const CHARSET_INFO *tocs,
3387 bool ignore_errors = false);
3388
3389 /**
3390 Delete this item.
3391 Note that item must have been cleanup up by calling Item::cleanup().
3392 */
3393 void delete_self() { delete this; }
3394
3395 /** @return whether the item is local to a stored procedure */
3396 virtual bool is_splocal() const { return false; }
3397
3398 /*
3399 Return Settable_routine_parameter interface of the Item. Return 0
3400 if this Item is not Settable_routine_parameter.
3401 */
3403 return nullptr;
3404 }
3405 inline bool is_temporal_with_date() const {
3407 }
3410 }
3411 inline bool is_temporal_with_time() const {
3413 }
3414 inline bool is_temporal() const {
3416 }
3417 /**
3418 Check whether this and the given item has compatible comparison context.
3419 Used by the equality propagation. See Item_field::equal_fields_propagator.
3420
3421 @return
3422 true if the context is the same or if fields could be
3423 compared as DATETIME values by the Arg_comparator.
3424 false otherwise.
3425 */
3426 inline bool has_compatible_context(Item *item) const {
3427 // If no explicit context has been set, assume the same type as the item
3428 const Item_result this_context =
3430 const Item_result other_context = item->cmp_context == INVALID_RESULT
3431 ? item->result_type()
3432 : item->cmp_context;
3433
3434 // Check if both items have the same context
3435 if (this_context == other_context) {
3436 return true;
3437 }
3438 /* DATETIME comparison context. */
3440 return item->is_temporal_with_date() || other_context == STRING_RESULT;
3441 if (item->is_temporal_with_date())
3442 return is_temporal_with_date() || this_context == STRING_RESULT;
3443 return false;
3444 }
3446 return Field::GEOM_GEOMETRY;
3447 }
3448 String *check_well_formed_result(String *str, bool send_error, bool truncate);
3449 bool eq_by_collation(Item *item, const CHARSET_INFO *cs);
3450
3452 m_cost.Compute(*this);
3453 return m_cost;
3454 }
3455
3456 /**
3457 @return maximum number of characters that this Item can store
3458 If Item is of string or blob type, return max string length in bytes
3459 divided by bytes per character, otherwise return max_length.
3460 @todo - check if collation for other types should have mbmaxlen = 1
3461 */
3463 /*
3464 Length of e.g. 5.5e5 in an expression such as GREATEST(5.5e5, '5') is 5
3465 (length of that string) although length of the actual value is 6.
3466 Return MAX_DOUBLE_STR_LENGTH to prevent truncation of data without having
3467 to evaluate the value of the item.
3468 */
3469 const uint32 max_len =
3471 if (result_type() == STRING_RESULT)
3472 return max_len / collation.collation->mbmaxlen;
3473 return max_len;
3474 }
3475
3477 if (cs == &my_charset_bin && result_type() == STRING_RESULT) {
3478 return max_length;
3479 }
3480 return max_char_length();
3481 }
3482
3483 inline void fix_char_length(uint32 max_char_length_arg) {
3484 max_length = char_to_byte_length_safe(max_char_length_arg,
3486 }
3487
3488 /*
3489 Return true if the item points to a column of an outer-joined table.
3490 */
3491 virtual bool is_outer_field() const {
3492 assert(fixed);
3493 return false;
3494 }
3495
3496 /**
3497 Check if an item either is a blob field, or will be represented as a BLOB
3498 field if a field is created based on this item.
3499
3500 @retval true If a field based on this item will be a BLOB field,
3501 @retval false Otherwise.
3502 */
3503 bool is_blob_field() const;
3504
3505 /// @returns number of references to an item.
3506 uint reference_count() const { return m_ref_count; }
3507
3508 /// Increment reference count
3510 assert(!m_abandoned);
3511 ++m_ref_count;
3512 }
3513
3514 /// Decrement reference count
3516 assert(m_ref_count > 0);
3517 if (--m_ref_count == 0) m_abandoned = true;
3518 return m_ref_count;
3519 }
3520
3521 protected:
3522 /// Set accumulated properties for an Item
3523 void set_accum_properties(const Item *item) {
3525 }
3526
3527 /// Add more accumulated properties to an Item
3528 void add_accum_properties(const Item *item) {
3530 }
3531
3532 /// Set the "has subquery" property
3534
3535 /// Set the "has stored program" property
3537
3538 public:
3539 /// @return true if this item or any of its descendants contains a subquery.
3541
3542 /// @return true if this item or any of its descendants refers a stored func.
3543 bool has_stored_program() const {
3545 }
3546
3547 /// @return true if this item or any of its descendants is an aggregated func.
3549
3550 /// Set the "has aggregation" property
3552
3553 /// Reset the "has aggregation" property
3554 void reset_aggregation() { m_accum_properties &= ~PROP_AGGREGATION; }
3555
3556 /// @return true if this item or any of its descendants is a window func.
3558
3559 /// Set the "has window function" property
3561
3562 /**
3563 @return true if this item or any of its descendants within the same query
3564 has a reference to a GROUP BY modifier (such as ROLLUP)
3565 */
3568 }
3569
3570 /**
3571 Set the property: this item (tree) contains a reference to a GROUP BY
3572 modifier (such as ROLLUP)
3573 */
3576 }
3577
3578 /**
3579 @return true if this item or any of underlying items is a GROUPING function
3580 */
3581 bool has_grouping_func() const {
3583 }
3584
3585 /// Set the property: this item is a call to GROUPING
3587
3588 /// Whether this Item was created by the IN->EXISTS subquery transformation
3589 virtual bool created_by_in2exists() const { return false; }
3590
3592 if (has_subquery())
3594 }
3595
3596 /**
3597 Analyzer function for GC substitution. @see substitute_gc()
3598 */
3599 virtual bool gc_subst_analyzer(uchar **) { return false; }
3600 /**
3601 Transformer function for GC substitution. @see substitute_gc()
3602 */
3603 virtual Item *gc_subst_transformer(uchar *) { return this; }
3604
3605 /**
3606 A processor that replaces any Fields with a Create_field_wrapper. This
3607 will allow us to resolve functions during CREATE TABLE, where we only have
3608 Create_field available and not Field. Used for functional index
3609 implementation.
3610 */
3611 virtual bool replace_field_processor(uchar *) { return false; }
3612 /**
3613 Check if this item is of a type that is eligible for GC
3614 substitution. All items that belong to subclasses of Item_func are
3615 eligible for substitution. @see substitute_gc()
3616 Item_fields can also be eligible if they are given as an argument to
3617 a function that takes an array (the field can be substituted with a
3618 generated column that backs a multi-valued index on that field).
3619
3620 @param array true if the item is an argument to a function that takes an
3621 array, or false otherwise
3622 @return true if the expression is eligible for substitution, false otherwise
3623 */
3624 bool can_be_substituted_for_gc(bool array = false) const;
3625
3627 uint nitems);
3628 void aggregate_decimal_properties(Item **items, uint nitems);
3630 uint nitems);
3632 Item **items, uint nitems);
3633 void aggregate_bit_properties(Item **items, uint nitems);
3634
3635 /**
3636 This function applies only to Item_field objects referred to by an Item_ref
3637 object that has been marked as a const_item.
3638
3639 @param arg Keep track of whether an Item_ref refers to an Item_field.
3640 */
3641 virtual bool repoint_const_outer_ref(uchar *arg [[maybe_unused]]) {
3642 return false;
3643 }
3644 virtual bool strip_db_table_name_processor(uchar *) { return false; }
3645
3646 /**
3647 Compute the cost of evaluating this Item.
3648 @param root_cost The cost object to which the cost should be added.
3649 */
3650 virtual void compute_cost(CostOfItem *root_cost [[maybe_unused]]) const {}
3651
3652 bool is_abandoned() const { return m_abandoned; }
3653
3654 private:
3655 virtual bool subq_opt_away_processor(uchar *) { return false; }
3656
3657 public: // Start of data fields
3658 /**
3659 Intrusive list pointer for free list. If not null, points to the next
3660 Item on some Query_arena's free list. For instance, stored procedures
3661 have their own Query_arena's.
3662
3663 @see Query_arena::free_list
3664 */
3665 Item *next_free{nullptr};
3666
3667 protected:
3668 /// str_values's main purpose is to cache the value in save_in_field
3670
3671 public:
3672 /**
3673 Character set and collation properties assigned for this Item.
3674 Used if Item represents a character string expression.
3675 */
3677 Item_name_string item_name; ///< Name from query
3678 Item_name_string orig_name; ///< Original item name (if it was renamed)
3679 /**
3680 Maximum length of result of evaluating this item, in number of bytes.
3681 - For character or blob data types, max char length multiplied by max
3682 character size (collation.mbmaxlen).
3683 - For decimal type, it is the precision in digits plus sign (unless
3684 unsigned) plus decimal point (unless it has zero decimals).
3685 - For other numeric types, the default or specific display length.
3686 - For date/time types, the display length (10 for DATE, 10 + optional FSP
3687 for TIME, 19 + optional fsp for datetime/timestamp).
3688 - For bit, the number of bits.
3689 - For enum, the string length of the widest enum element.
3690 - For set, the sum of the string length of each set element plus separators.
3691 - For geometry, the maximum size of a BLOB (it's underlying storage type).
3692 - For json, the maximum size of a BLOB (it's underlying storage type).
3693 */
3694 uint32 max_length; ///< Maximum length, in bytes
3695 enum item_marker ///< Values for member 'marker'
3696 {
3698 /// When contextualization or itemization adds an implicit comparison '0<>'
3699 /// (see make_condition()), to record that this Item_func_ne was created for
3700 /// this purpose; this value is tested during resolution.
3702 /// When doing constant propagation (e.g. change_cond_ref_to_const(), to
3703 /// remember that we have already processed the item.
3705 /// When creating an internal temporary table: marking group by
3706 /// fields
3708 /// When analyzing functional dependencies for only_full_group_by (says
3709 /// whether a nullable column can be treated at not nullable).
3711 /// When we change DISTINCT to GROUP BY: used for book-keeping of
3712 /// fields.
3714 /// When pushing conditions down to derived table: it says a condition
3715 /// contains only derived table's columns.
3717 /// Used during traversal to avoid deleting an item twice.
3719 /// When pushing index conditions: it says whether a condition uses only
3720 /// indexed columns.
3723 /**
3724 This member has several successive meanings, depending on the phase we're
3725 in (@see item_marker).
3726 The important property is that a phase must have a value (or few values)
3727 which is reserved for this phase. If it wants to set "marked", it assigns
3728 the value; it it wants to test if it is marked, it tests marker !=
3729 value. If the value has been assigned and the phase wants to cancel it can
3730 set marker to MARKER_NONE, which is a magic number which no phase
3731 reserves.
3732 A phase can expect 'marker' to be MARKER_NONE at the start of execution of
3733 a normal statement, at the start of preparation of a PS, and at the start
3734 of execution of a PS.
3735 A phase should not expect marker's value to survive after the phase's
3736 end - as a following phase may change it.
3737 */
3739 Item_result cmp_context; ///< Comparison context
3740 private:
3741 /**
3742 Number of references to this item. It is used for two purposes:
3743 1. When eliminating redundant expressions, the reference count is used
3744 to tell how many Item_ref objects that point to an item. When a
3745 sub-tree of items is eliminated, it is traversed and any item that
3746 is referenced from an Item_ref has its reference count decremented.
3747 Only when the reference count reaches zero is the item actually deleted.
3748 2. Keeping track of unused expressions selected from merged derived tables.
3749 An item that is added to the select list of a query block has its
3750 reference count set to 1. Any references from outer query blocks are
3751 through Item_ref objects, thus they will cause the reference count
3752 to be incremented. At end of resolving, the reference counts of all
3753 items in select list of merged derived tables are decremented, thus
3754 if the reference count becomes zero, the expression is known to
3755 be unused and can be removed.
3756 */
3758 bool m_abandoned{false}; ///< true if item has been fully de-referenced
3759 const bool is_parser_item; ///< true if allocated directly by parser
3760 uint8 m_data_type; ///< Data type assigned to Item
3761
3762 /**
3763 The cost of evaluating this item. This is only needed for predicates,
3764 therefore we use lazy evaluation.
3765 */
3767
3768 public:
3769 bool fixed; ///< True if item has been resolved
3770 /**
3771 Number of decimals in result when evaluating this item
3772 - For integer type, always zero.
3773 - For decimal type, number of decimals.
3774 - For float type, it may be DECIMAL_NOT_SPECIFIED
3775 - For time, datetime and timestamp, number of decimals in fractional second
3776 - For string types, may be decimals of cast source or DECIMAL_NOT_SPECIFIED
3777 */
3779
3780 bool is_nullable() const { return m_nullable; }
3781 void set_nullable(bool nullable) { m_nullable = nullable; }
3782
3783 private:
3784 /**
3785 True if this item may hold the NULL value(if null_value may be set to true).
3786
3787 For items that represent rows, it is true if one of the columns
3788 may be null.
3789
3790 For items that represent scalar or row subqueries, it is true if
3791 one of the returned columns could be null, or if the subquery
3792 could return zero rows.
3793
3794 It is worth noting that this information is correct only until
3795 equality propagation has been run by the optimization phase.
3796 Indeed, consider:
3797 select * from t1, t2,t3 where t1.pk=t2.a and t1.pk+1...
3798 the '+' is not nullable as t1.pk is not nullable;
3799 but if the optimizer chooses plan is t2-t3-t1, then, due to equality
3800 propagation it will replace t1.pk in '+' with t2.a (as t2 is before t1
3801 in plan), making the '+' capable of returning NULL when t2.a is NULL.
3802 */
3804
3805 public:
3806 bool null_value; ///< True if item is null
3808 bool m_is_window_function; ///< True if item represents window func
3809 /**
3810 If the item is in a SELECT list (Query_block::fields) and hidden is true,
3811 the item wasn't actually in the list as given by the user (it was added
3812 by the optimizer, to e.g. make sure it was part of a given
3813 materialization), and should not be returned in the actual result.
3814
3815 If the item is not in a SELECT list, the value is irrelevant.
3816 */
3817 bool hidden{false};
3818 /**
3819 True if item is a top most element in the expression being
3820 evaluated for a check constraint.
3821 */
3823
3824 protected:
3825 /**
3826 Set of properties that are calculated by accumulation from underlying items.
3827 Computed by constructors and fix_fields() and updated by
3828 update_used_tables(). The properties are accumulated up to the root of the
3829 current item tree, except they are not accumulated across subqueries and
3830 functions.
3831 */
3832 static constexpr uint8 PROP_SUBQUERY = 0x01;
3833 static constexpr uint8 PROP_STORED_PROGRAM = 0x02;
3834 static constexpr uint8 PROP_AGGREGATION = 0x04;
3835 static constexpr uint8 PROP_WINDOW_FUNCTION = 0x08;
3836 /**
3837 Set if the item or one or more of the underlying items contains a
3838 GROUP BY modifier (such as ROLLUP).
3839 */
3840 static constexpr uint8 PROP_HAS_GROUPING_SET_DEP = 0x10;
3841 /**
3842 Set if the item or one or more of the underlying items is a GROUPING
3843 function.
3844 */
3845 static constexpr uint8 PROP_GROUPING_FUNC = 0x20;
3846
3848
3849 public:
3850 /**
3851 Apply column masking policy to this item if applicable.
3852
3853 @param thd Thread handle.
3854 @return Item to use after masking (possibly this or a new Item), or
3855 nullptr on error.
3856 */
3857 virtual Item *apply_masking_policy(THD *thd [[maybe_unused]]) { return this; }
3858
3859 /**
3860 Disable application of the masking policy to this item. This is used to
3861 prevent replacing an Item_field with a masking expression when resolving
3862 target columns of INSERT, UPDATE or REPLACE, as these statements would still
3863 need to be able to write to these columns, even though they should be masked
3864 when being read.
3865 */
3866 virtual void disable_masking_policy() {}
3867
3868 /**
3869 Mark this expression as a masking expression for some other expression.
3870 @param masked_item The item that should be masked by this expression.
3871 */
3872 virtual void set_masking_expression_for(const Item_field *masked_item
3873 [[maybe_unused]]) {
3874 // Only expected to be called on the top-level item of the masking policy
3875 // expression as specified in a CREATE MASKING POLICY statement. At the time
3876 // of writing, this has to be an Item_func_case.
3877 assert(false);
3878 }
3879
3880 /**
3881 Check if this expression can be used for partial update of a given
3882 JSON column.
3883
3884 For example, the expression `JSON_REPLACE(col, '$.foo', 'bar')`
3885 can be used to partially update the column `col`.
3886
3887 @param field the JSON column that is being updated
3888 @return true if this expression can be used for partial update,
3889 false otherwise
3890 */
3891 virtual bool supports_partial_update(const Field_json *field
3892 [[maybe_unused]]) const {
3893 return false;
3894 }
3895
3896 /**
3897 Whether the item returns array of its data type
3898 */
3899 virtual bool returns_array() const { return false; }
3900
3901 /**
3902 A helper function to ensure proper usage of CAST(.. AS .. ARRAY)
3903 */
3904 virtual void allow_array_cast() {}
3905};
3906
3907/**
3908 Descriptor of what and how to cache for
3909 Item::cache_const_expr_transformer/analyzer.
3910
3911*/
3912
3914 /// Path from the expression's top to the current item in item tree
3915 /// used to track parent of current item for caching JSON data
3917 /// Item to cache. Used as a binary flag, but kept as Item* for assertion
3918 Item *cache_item{nullptr};
3919 /// How to cache JSON data. @see Item::enum_const_item_cache
3921};
3922
3923/**
3924 A helper class to give in a functor to Item::walk(). Use as e.g.:
3925
3926 bool result = WalkItem(root_item, enum_walk::POSTFIX, [](Item *item) { ... });
3927
3928 TODO: Make Item::walk() just take in a functor in the first place, instead of
3929 a pointer-to-member and an opaque argument.
3930 */
3931template <class T>
3932inline bool WalkItem(Item *item, enum_walk walk, T &&functor) {
3933 return item->walk(&Item::walk_helper_thunk<T>, walk,
3934 reinterpret_cast<uchar *>(&functor));
3935}
3936
3937/**
3938 Overload for const 'item' and functor taking 'const Item*' argument.
3939*/
3940template <class T>
3941inline bool WalkItem(const Item *item, enum_walk walk, T &&functor) {
3942 auto to_const = [&](const Item *descendant) { return functor(descendant); };
3943 return WalkItem(const_cast<Item *>(item), walk, to_const);
3944}
3945
3946/**
3947 Same as WalkItem, but for Item::compile(). Use as e.g.:
3948
3949 Item *item = CompileItem(root_item,
3950 [](Item *item) { return true; }, // Analyzer.
3951 [](Item *item) { return item; }); // Transformer.
3952 */
3953template <class T, class U>
3954inline Item *CompileItem(Item *item, T &&analyzer, U &&transformer) {
3955 uchar *analyzer_ptr = reinterpret_cast<uchar *>(&analyzer);
3956 return item->compile(&Item::analyze_helper_thunk<T>, &analyzer_ptr,
3957 &Item::walk_helper_thunk<U>,
3958 reinterpret_cast<uchar *>(&transformer));
3959}
3960
3961/**
3962 Same as WalkItem, but for Item::transform(). Use as e.g.:
3963
3964 Item *item = TransformItem(root_item, [](Item *item) { return item; });
3965 */
3966template <class T>
3967Item *TransformItem(Item *item, T &&transformer) {
3968 return item->transform(&Item::walk_helper_thunk<T>,
3969 pointer_cast<uchar *>(&transformer));
3970}
3971
3974
3975 public:
3977 explicit Item_basic_constant(const POS &pos) : Item(pos), used_table_map(0) {}
3978
3979 /// @todo add implementation of basic_const_item
3980 /// and remove from subclasses as appropriate.
3981
3983 table_map used_tables() const override { return used_table_map; }
3984 bool check_function_as_value_generator(uchar *) override { return false; }
3985 /* to prevent drop fixed flag (no need parent cleanup call) */
3986 void cleanup() override {
3987 // @todo We should ensure we never change "basic constant" nodes.
3988 // We should then be able to add this assert:
3989 // assert(marker == MARKER_NONE);
3990 // and remove the call to Item::cleanup()
3991 Item::cleanup();
3992 }
3993 bool basic_const_item() const override { return true; }
3994 /**
3995 Note that str_value.ptr() will now point to a string owned by some
3996 other object.
3997 */
3999 str_value.set(str->ptr(), str->length(), str->charset());
4000 }
4001};
4002
4003/*****************************************************************************
4004 The class is a base class for representation of stored routine variables in
4005 the Item-hierarchy. There are the following kinds of SP-vars:
4006 - local variables (Item_splocal);
4007 - CASE expression (Item_case_expr);
4008*****************************************************************************/
4009
4010class Item_sp_variable : public Item {
4011 public:
4013
4014 public:
4015#ifndef NDEBUG
4016 /*
4017 Routine to which this Item_splocal belongs. Used for checking if correct
4018 runtime context is used for variable handling.
4019 */
4020 sp_head *m_sp{nullptr};
4021#endif
4022
4023 public:
4024 Item_sp_variable(const Name_string sp_var_name);
4025
4026 table_map used_tables() const override { return INNER_TABLE_BIT; }
4027 bool fix_fields(THD *thd, Item **) override;
4028
4029 double val_real() override;
4030 longlong val_int() override;
4031 String *val_str(String *sp) override;
4032 my_decimal *val_decimal(my_decimal *decimal_value) override;
4033 bool val_json(Json_wrapper *result) override;
4034 bool val_date(Date_val *date, my_time_flags_t flags) override;
4035 bool val_time(Time_val *time) override;
4036 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
4037 bool is_null() override;
4038
4039 public:
4040 inline void make_field(Send_field *field) override;
4041 bool send(Protocol *protocol, String *str) override {
4042 // Need to override send() in case this_item() is an Item_field with a
4043 // ZEROFILL attribute.
4044 return this_item()->send(protocol, str);
4045 }
4046 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
4047 // It is ok to push down a condition like "column > SP_variable"
4048 return false;
4049 }
4050
4051 protected:
4053 Field *field, bool no_conversions) override;
4054};
4055
4056/*****************************************************************************
4057 Item_sp_variable inline implementation.
4058*****************************************************************************/
4059
4061 Item *it = this_item();
4063 it->make_field(field);
4064}
4065
4067 Field *field, bool no_conversions) {
4068 return this_item()->save_in_field(field, no_conversions);
4069}
4070
4071/*****************************************************************************
4072 A reference to local SP variable (incl. reference to SP parameter), used in
4073 runtime.
4074*****************************************************************************/
4075
4076class Item_splocal final : public Item_sp_variable,
4079
4080 public:
4081 /*
4082 If this variable is a parameter in LIMIT clause.
4083 Used only during NAME_CONST substitution, to not append
4084 NAME_CONST to the resulting query and thus not break
4085 the slave.
4086 */
4088 /*
4089 Position of this reference to SP variable in the statement (the
4090 statement itself is in sp_instr_stmt::m_query).
4091 This is valid only for references to SP variables in statements,
4092 excluding DECLARE CURSOR statement. It is used to replace references to SP
4093 variables with NAME_CONST calls when putting statements into the binary
4094 log.
4095 Value of 0 means that this object doesn't corresponding to reference to
4096 SP variable in query text.
4097 */
4099 /*
4100 Byte length of SP variable name in the statement (see pos_in_query).
4101 The value of this field may differ from the name_length value because
4102 name_length contains byte length of UTF8-encoded item name, but
4103 the query string (see sp_instr_stmt::m_query) is currently stored with
4104 a charset from the SET NAMES statement.
4105 */
4107
4108 Item_splocal(const Name_string sp_var_name, uint sp_var_idx,
4109 enum_field_types sp_var_type, uint pos_in_q = 0,
4110 uint len_in_q = 0);
4111
4112 bool is_splocal() const override { return true; }
4113
4114 Item *this_item() override;
4115 const Item *this_item() const override;
4116 Item **this_item_addr(THD *thd, Item **) override;
4117
4118 void print(const THD *thd, String *str,
4119 enum_query_type query_type) const override;
4120
4121 uint64_t hash() override;
4122
4123 public:
4124 uint get_var_idx() const { return m_var_idx; }
4125
4126 Type type() const override { return ROUTINE_FIELD_ITEM; }
4127 Item_result result_type() const override {
4128 return type_to_result(data_type());
4129 }
4130 bool val_json(Json_wrapper *result) override;
4131
4132 private:
4133 bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override;
4134
4135 public:
4137 return this;
4138 }
4139};
4140
4141/*****************************************************************************
4142 A reference to case expression in SP, used in runtime.
4143*****************************************************************************/
4144
4145class Item_case_expr final : public Item_sp_variable {
4146 public:
4147 Item_case_expr(uint case_expr_id);
4148
4149 public:
4150 Item *this_item() override;
4151 const Item *this_item() const override;
4152 Item **this_item_addr(THD *thd, Item **) override;
4153
4154 Type type() const override { return this_item()->type(); }
4155 Item_result result_type() const override {
4156 return this_item()->result_type();
4157 }
4158 /*
4159 NOTE: print() is intended to be used from views and for debug.
4160 Item_case_expr can not occur in views, so here it is only for debug
4161 purposes.
4162 */
4163 void print(const THD *thd, String *str,
4164 enum_query_type query_type) const override;
4165
4166 uint64_t hash() override;
4167
4168 private:
4170};
4171
4172/*
4173 NAME_CONST(given_name, const_value).
4174 This 'function' has all properties of the supplied const_value (which is
4175 assumed to be a literal constant), and the name given_name.
4176
4177 This is used to replace references to SP variables when we write PROCEDURE
4178 statements into the binary log.
4179
4180 TODO
4181 Together with Item_splocal and Item::this_item() we can actually extract
4182 common a base of this class and Item_splocal. Maybe it is possible to
4183 extract a common base with class Item_ref, too.
4184*/
4185
4186class Item_name_const final : public Item {
4187 typedef Item super;
4188
4192
4193 public:
4194 Item_name_const(const POS &pos, Item *name_arg, Item *val);
4195
4196 bool do_itemize(Parse_context *pc, Item **res) override;
4197 bool fix_fields(THD *, Item **) override;
4198
4199 enum Type type() const override { return NAME_CONST_ITEM; }
4200 double val_real() override;
4201 longlong val_int() override;
4202 String *val_str(String *sp) override;
4203 my_decimal *val_decimal(my_decimal *) override;
4204 bool val_date(Date_val *date, my_time_flags_t flags) override;
4205 bool val_time(Time_val *time) override;
4206 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
4207 bool is_null() override;
4208 void print(const THD *thd, String *str,
4209 enum_query_type query_type) const override;
4210
4211 uint64_t hash() override;
4212
4213 Item_result result_type() const override { return value_item->result_type(); }
4214
4216 // Item_name_const always wraps a literal, so there is no need to cache it.
4217 return false;
4218 }
4219
4220 protected:
4222 bool no_conversions) override {
4223 return value_item->save_in_field(field, no_conversions);
4224 }
4225};
4226
4227bool convert_const_strings(DTCollation &coll, Item **args, uint nargs);
4229 Item **items, uint nitems);
4230bool agg_item_charsets(DTCollation &c, const char *name, Item **items,
4231 uint nitems, uint flags);
4233 const char *name, Item **items,
4234 uint nitems) {
4237 return agg_item_charsets(c, name, items, nitems, flags);
4238}
4240 Item **items, uint nitems) {
4242 return agg_item_charsets(c, name, items, nitems, flags);
4243}
4244
4247
4248 public:
4250 explicit Item_num(const POS &pos) : super(pos) { collation.set_numeric(); }
4251
4252 virtual Item_num *neg() = 0;
4253 bool check_partition_func_processor(uchar *) override { return false; }
4254};
4255
4256inline constexpr uint16 NO_FIELD_INDEX((uint16)(-1));
4257
4258class Item_ident : public Item {
4259 typedef Item super;
4260
4261 /** To cache the hash value of this item, populated upon hash() invocation. */
4262 uint64_t m_hash_val{0};
4263
4264 protected:
4265 /**
4266 The fields m_orig_db_name, m_orig_table_name and m_orig_field_name are
4267 maintained so that we can provide information about the origin of a
4268 column that may have been renamed within the query, e.g. as required by
4269 connectors.
4270
4271 Names the original schema of the table that is the source of the field.
4272 If field is from
4273 - a non-aliased base table, the same as db_name.
4274 - an aliased base table, the name of the schema of the base table.
4275 - an expression (including aggregation), a NULL pointer.
4276 - a derived table, the name of the schema of the underlying base table.
4277 - a view, the name of the schema of the underlying base table.
4278 - a temporary table (in optimization stage), the name of the schema of
4279 the source base table.
4280 */
4281 const char *m_orig_db_name;
4282 /**
4283 Names the original table that is the source of the field. If field is from
4284 - a non-aliased base table, the same as table_name.
4285 - an aliased base table, the name of the base table.
4286 - an expression (including aggregation), a NULL pointer.
4287 - a derived table, the name of the underlying base table.
4288 - a view, the name of the underlying base table.
4289 - a temporary table (in optimization stage), the name of the source base tbl
4290 */
4292 /**
4293 Names the field in the source base table. If field is from
4294 - an expression, a NULL pointer.
4295 - a view or base table and is not aliased, the same as field_name.
4296 - a view or base table and is aliased, the column name of the view or
4297 base table.
4298 - a derived table, the column name of the underlying base table.
4299 - a temporary table (in optimization stage), the name of the source column.
4300 */
4302 bool m_alias_of_expr; ///< if this Item's name is alias of SELECT expression
4303
4304 public:
4305 /**
4306 For regularly resolved column references, 'context' points to a name
4307 resolution context object belonging to the query block which simply
4308 contains the reference. To further clarify, in
4309 SELECT (SELECT t.a) FROM t;
4310 t.a is an Item_ident whose 'context' belongs to the subquery
4311 (context->query_block == that of the subquery).
4312 For column references that are part of a generated column expression,
4313 'context' points to a temporary name resolution context object during
4314 resolving, but is set to nullptr after resolving is done. Note that
4315 Item_ident::local_column() depends on that.
4316 */
4318 /**
4319 Schema name of the base table or view the column is part of.
4320 If an expression, a NULL pointer.
4321 If from a derived table, a NULL pointer.
4322 */
4323 const char *db_name;
4324 /**
4325 If column is from a non-aliased base table or view, name of base table or
4326 view.
4327 If column is from an aliased base table or view, the alias name.
4328 If column is from a derived table, the name of the derived table.
4329 If column is from an expression, a NULL pointer.
4330 */
4331 const char *table_name;
4332 /**
4333 If column is aliased, the column alias name.
4334 If column is from a non-aliased base table or view, the name of the
4335 column in that base table or view.
4336 If column is from an expression, a string generated from that expression.
4337
4338 Notice that a column can be aliased in two ways:
4339 1. With an explicit column alias, or @<as clause@>, or
4340 2. With only a column name specified, which differs from the table's
4341 column name due to case insensitivity.
4342 In both cases field_name will differ from m_orig_field_name.
4343 field_name is normally identical to Item::item_name.
4344 */
4345 const char *field_name;
4346 /**
4347 Points to the Table_ref object of the table or view that the column or
4348 reference is resolved against (only valid after resolving).
4349 Notice that for the following types of "tables", no Table_ref object is
4350 assigned and hence m_table_ref is NULL:
4351 - Temporary tables assigned by join optimizer for sorting and aggregation.
4352 - Stored procedure dummy tables.
4353 For fields referencing such tables, table number is always 0, and other
4354 uses of m_table_ref is not needed.
4355 */
4357 /**
4358 For a column or reference that is an outer reference, depended_from points
4359 to the qualifying query block, otherwise it is NULL
4360 (only valid after resolving).
4361 */
4363
4364 Item_ident(Name_resolution_context *context_arg, const char *db_name_arg,
4365 const char *table_name_arg, const char *field_name_arg)
4366 : m_orig_db_name(db_name_arg),
4367 m_orig_table_name(table_name_arg),
4368 m_orig_field_name(field_name_arg),
4369 m_alias_of_expr(false),
4370 context(context_arg),
4371 db_name(db_name_arg),
4372 table_name(table_name_arg),
4373 field_name(field_name_arg) {
4374 item_name.set(field_name_arg);
4375 }
4376
4377 Item_ident(const POS &pos, const char *db_name_arg,
4378 const char *table_name_arg, const char *field_name_arg)
4379 : super(pos),
4380 m_orig_db_name(db_name_arg),
4381 m_orig_table_name(table_name_arg),
4382 m_orig_field_name(field_name_arg),
4383 m_alias_of_expr(false),
4384 db_name(db_name_arg),
4385 table_name(table_name_arg),
4386 field_name(field_name_arg) {
4387 item_name.set(field_name_arg);
4388 }
4389
4390 /// Constructor used by Item_field & Item_*_ref (see Item comment)
4391
4393 : Item(thd, item),
4398 context(item->context),
4399 db_name(item->db_name),
4400 table_name(item->table_name),
4401 field_name(item->field_name),
4402 m_table_ref(item->m_table_ref),
4404
4405 bool do_itemize(Parse_context *pc, Item **res) override;
4406
4407 const char *full_name() const override;
4408 void set_orignal_db_name(const char *name_arg) { m_orig_db_name = name_arg; }
4409 void set_original_table_name(const char *name_arg) {
4410 m_orig_table_name = name_arg;
4411 }
4412 void set_original_field_name(const char *name_arg) {
4413 m_orig_field_name = name_arg;
4414 }
4415 const char *original_db_name() const { return m_orig_db_name; }
4416 const char *original_table_name() const { return m_orig_table_name; }
4417 const char *original_field_name() const { return m_orig_field_name; }
4418 void fix_after_pullout(Query_block *parent_query_block,
4419 Query_block *removed_query_block) override;
4420 bool aggregate_check_distinct(uchar *arg) override;
4421 bool aggregate_check_group(uchar *arg) override;
4422 Bool3 local_column(const Query_block *sl) const override;
4423
4424 void print(const THD *thd, String *str,
4425 enum_query_type query_type) const override {
4426 print(thd, str, query_type, db_name, table_name);
4427 }
4428 uint64_t hash() override;
4429
4430 protected:
4431 /**
4432 Function to print column name for a table
4433
4434 To print a column for a permanent table (picks up database and table from
4435 Item_ident object):
4436
4437 item->print(str, qt)
4438
4439 To print a column for a temporary table:
4440
4441 item->print(str, qt, specific_db, specific_table)
4442
4443 Items of temporary table fields have empty/NULL values of table_name and
4444 db_name. To print column names in a 3D form (`database`.`table`.`column`),
4445 this function prints db_name_arg and table_name_arg parameters instead of
4446 this->db_name and this->table_name respectively.
4447
4448 @param thd Thread handle.
4449 @param [out] str Output string buffer.
4450 @param query_type Bitmap to control printing details.
4451 @param db_name_arg String to output as a column database name.
4452 @param table_name_arg String to output as a column table name.
4453 */
4454 void print(const THD *thd, String *str, enum_query_type query_type,
4455 const char *db_name_arg, const char *table_name_arg) const;
4456
4457 uint64_t hash(const char *db_name_arg, const char *table_name_arg);
4458
4459 public:
4460 ///< Argument object to change_context_processor
4464 };
4465 bool change_context_processor(uchar *arg) override {
4466 context = reinterpret_cast<Change_context *>(arg)->m_context;
4467 return false;
4468 }
4469
4470 /// @returns true if this Item's name is alias of SELECT expression
4471 bool is_alias_of_expr() const { return m_alias_of_expr; }
4472 /// Marks that this Item's name is alias of SELECT expression
4474
4475 /**
4476 Argument structure for walk processor Item::update_depended_from
4477 */
4479 Query_block *old_depended_from; // the transformed query block
4480 Query_block *new_depended_from; // the new derived table for grouping
4481 };
4482
4483 bool update_depended_from(uchar *) override;
4484
4485 /**
4486 @returns true if a part of this Item's full name (name or table name) is
4487 an alias.
4488 */
4489 virtual bool alias_name_used() const { return m_alias_of_expr; }
4491 const char *db_name, const char *table_name,
4493 bool any_privileges);
4494 bool is_strong_side_column_not_in_fd(uchar *arg) override;
4495 bool is_column_not_in_fd(uchar *arg) override;
4496};
4497
4498class Item_ident_for_show final : public Item {
4499 public:
4501 const char *db_name;
4502 const char *table_name;
4503
4504 Item_ident_for_show(Field *par_field, const char *db_arg,
4505 const char *table_name_arg)
4506 : field(par_field), db_name(db_arg), table_name(table_name_arg) {}
4507
4508 enum Type type() const override { return FIELD_ITEM; }
4509 bool fix_fields(THD *thd, Item **ref) override;
4510 double val_real() override { return field->val_real(); }
4511 longlong val_int() override { return field->val_int(); }
4512 String *val_str(String *str) override { return field->val_str(str); }
4514 return field->val_decimal(dec);
4515 }
4516 bool val_date(Date_val *date, my_time_flags_t flags) override {
4517 return field->val_date(date, flags);
4518 }
4519 bool val_time(Time_val *time) override { return field->val_time(time); }
4521 return field->val_datetime(dt, flags);
4522 }
4523 void make_field(Send_field *tmp_field) override;
4525 return field->charset_for_protocol();
4526 }
4527};
4528
4529class Item_field : public Item_ident {
4531
4532 protected:
4533 void set_field(Field *field);
4534 void fix_after_pullout(Query_block *parent_query_block,
4535 Query_block *removed_query_block) override {
4536 super::fix_after_pullout(parent_query_block, removed_query_block);
4537
4538 // Update nullability information, as the table may have taken over
4539 // null_row status from the derived table it was part of.
4541 field->table->is_nullable());
4542 }
4544 bool no_conversions) override;
4545
4546 public:
4547 /// Source field
4548 Field *field{nullptr};
4549
4550 private:
4551 /// Result field
4553
4554 // save_in_field() and save_org_in_field() are often called repeatedly
4555 // with the same destination field (although the destination for the
4556 // two are distinct, thus two distinct caches). We detect this case by
4557 // storing the last destination, and whether it was of a compatible type
4558 // that we can memcpy into (see fields_are_memcpyable()). This saves time
4559 // doing the same type checking over and over again.
4560 //
4561 // The _memcpyable fields are uint32_t(-1) if the fields are not memcpyable,
4562 // and pack_length() (ie., the amount of bytes to copy) if they are.
4563 // See field_conv_with_cache(), where this logic is encapsulated.
4568
4569 /**
4570 If this field is derived from another field, e.g. it is reading a column
4571 from a temporary table which is populated from a base table, this member
4572 points to the field used to populate the temporary table column.
4573 */
4575
4576 /**
4577 State used for transforming scalar subqueries to JOINs with derived tables,
4578 cf. \c transform_grouped_to_derived. Has accessor.
4579 */
4581
4582 /**
4583 Holds a list of items whose values must be equal to the value of
4584 this field, during execution.
4585
4586 Used during optimization to perform multiple equality analysis,
4587 this analysis should be performed during preparation instead, so that
4588 Item_field can be const after preparation.
4589 */
4591
4592 /**
4593 Indicates whether this field should be treated as an outer reference due to
4594 being the result of inlining a local variable within a stored program
4595 (currently applicable only to stored functions).
4596 */
4598
4599 /// apply_masking_policy() is a no-op if this flag is true.
4601
4602 public:
4603 /**
4604 Index for this field in table->field array. Holds NO_FIELD_INDEX
4605 if index value is not known.
4606 */
4609
4611 assert(item_equal != nullptr);
4612 item_equal_all_join_nests = item_equal;
4613 }
4614
4615 /**
4616 Sets m_was_sp_local_variable to true.
4617 */
4619
4620 // A list of fields that are considered "equal" to this field. E.g., a query
4621 // on the form "a JOIN b ON a.i = b.i JOIN c ON b.i = c.i" would consider
4622 // a.i, b.i and c.i equal due to equality propagation. This is the same as
4623 // "item_equal" above, except that "item_equal" will only contain fields from
4624 // the same join nest. This is used by hash join and BKA when they need to
4625 // undo multi-equality propagation done by the optimizer. (The optimizer may
4626 // generate join conditions that references unreachable fields for said
4627 // iterators.) The split is done because NDB expects the list to only
4628 // contain fields from the same join nest.
4630 /// If true, the optimizer's constant propagation will not replace this item
4631 /// with an equal constant.
4633 /*
4634 if any_privileges set to true then here real effective privileges will
4635 be stored
4636 */
4638 /* field need any privileges (for VIEW creation) */
4639 bool any_privileges{false};
4640 /*
4641 if this field is used in a context where covering prefix keys
4642 are supported.
4643 */
4645 Item_field(Name_resolution_context *context_arg, const char *db_arg,
4646 const char *table_name_arg, const char *field_name_arg);
4647 Item_field(const POS &pos, const char *db_arg, const char *table_name_arg,
4648 const char *field_name_arg);
4649 Item_field(THD *thd, Item_field *item);
4650 Item_field(THD *thd, Name_resolution_context *context_arg, Field *field);
4652
4653 bool do_itemize(Parse_context *pc, Item **res) override;
4654
4655 enum Type type() const override { return FIELD_ITEM; }
4656 bool eq(const Item *item) const override;
4657 double val_real() override;
4658 longlong val_int() override;
4659 longlong val_date_temporal() override;
4661 my_decimal *val_decimal(my_decimal *) override;
4662 String *val_str(String *) override;
4663 bool val_json(Json_wrapper *result) override;
4664 bool send(Protocol *protocol, String *str_arg) override;
4665 void reset_field(Field *f);
4666 bool fix_fields(THD *, Item **) override;
4667 void make_field(Send_field *tmp_field) override;
4668 void save_org_in_field(Field *field) override;
4669 table_map used_tables() const override;
4670 Item_result result_type() const override { return field->result_type(); }
4673 }
4674 TYPELIB *get_typelib() const override;
4676 return field->cast_to_int_type();
4677 }
4680 }
4681 longlong val_int_endpoint(bool left_endp, bool *incl_endp) override;
4682 void set_result_field(Field *field_arg) override { result_field = field_arg; }
4684 Field *tmp_table_field(TABLE *) override { return result_field; }
4687 item->base_item_field() != nullptr ? item->base_item_field() : item;
4688 }
4690 return m_base_item_field ? m_base_item_field : this;
4691 }
4692 bool val_date(Date_val *date, my_time_flags_t flags) override;
4693 bool val_time(Time_val *time) override;
4694 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
4695 bool get_timeval(my_timeval *tm, int *warnings) override;
4696 bool is_null() override {
4697 // NOTE: May return true even if maybe_null is not set!
4698 // This can happen if the underlying TABLE did not have a NULL row
4699 // at set_field() time (ie., table->is_null_row() was false),
4700 // but does now.
4701 return field->is_null();
4702 }
4703 Item *get_tmp_table_item(THD *thd) override;
4704 bool collect_item_field_processor(uchar *arg) override;
4705 bool collect_item_field_or_ref_processor(uchar *arg) override;
4707 bool collect_outer_field_processor(uchar *arg) override;
4708 bool add_field_to_set_processor(uchar *arg) override;
4709 bool add_field_to_cond_set_processor(uchar *) override;
4710 bool remove_column_from_bitmap(uchar *arg) override;
4711 bool find_item_in_field_list_processor(uchar *arg) override;
4712 bool find_field_processor(uchar *arg) override {
4713 return pointer_cast<Field *>(arg) == field;
4714 }
4715 bool check_function_as_value_generator(uchar *args) override;
4716 bool mark_field_in_map(uchar *arg) override {
4717 auto mark_field = pointer_cast<Mark_field *>(arg);
4718 bool rc = Item::mark_field_in_map(mark_field, field);
4720 rc |= Item::mark_field_in_map(mark_field, result_field);
4721 return rc;
4722 }
4723 bool used_tables_for_level(uchar *arg) override;
4724 bool check_column_privileges(uchar *arg) override;
4725 bool check_partition_func_processor(uchar *) override { return false; }
4726 void bind_fields() override;
4727 bool is_valid_for_pushdown(uchar *arg) override;
4728 bool check_column_in_window_functions(uchar *arg) override;
4729 bool check_column_in_group_by(uchar *arg) override;
4730 Item *replace_with_derived_expr(uchar *arg) override;
4732 void cleanup() override;
4733 void reset_field();
4734 Item_multi_eq *find_multi_equality(COND_EQUAL *cond_equal) const;
4735 bool subst_argument_checker(uchar **arg) override;
4736 Item *equal_fields_propagator(uchar *arg) override;
4737 Item *replace_item_field(uchar *) override;
4740 return false;
4741 }
4742 Item *replace_equal_field(uchar *) override;
4744 Item_field *field_for_view_update() override { return this; }
4745 bool fix_outer_field(THD *thd, Field **field, Item_ident **ref_field,
4746 bool *complete);
4747 Item *update_value_transformer(uchar *select_arg) override;
4748 void print(const THD *thd, String *str,
4749 enum_query_type query_type) const override;
4750 bool is_outer_field() const override {
4751 assert(fixed);
4753 }
4755 assert(data_type() == MYSQL_TYPE_GEOMETRY);
4756 return field->get_geometry_type();
4757 }
4758 const CHARSET_INFO *charset_for_protocol(void) override {
4759 return field->charset_for_protocol();
4760 }
4761
4762#ifndef NDEBUG
4763 void dbug_print() const {
4764 fprintf(DBUG_FILE, "<field ");
4765 if (field) {
4766 fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name);
4767 field->dbug_print();
4768 } else
4769 fprintf(DBUG_FILE, "NULL");
4770
4771 fprintf(DBUG_FILE, ", result_field: ");
4772 if (result_field) {
4773 fprintf(DBUG_FILE, "'%s.%s': ", result_field->table->alias,
4776 } else
4777 fprintf(DBUG_FILE, "NULL");
4778 fprintf(DBUG_FILE, ">\n");
4779 }
4780#endif
4781
4782 float get_filtering_effect(THD *thd, table_map filter_for_table,
4783 table_map read_tables,
4784 const MY_BITMAP *fields_to_ignore,
4785 double rows_in_table) override;
4786
4787 /**
4788 Returns the probability for the predicate "col OP <val>" to be
4789 true for a row in the case where no index statistics or range
4790 estimates are available for 'col'.
4791
4792 The probability depends on the number of rows in the table: it is by
4793 default 'default_filter', but never lower than 1/max_distinct_values
4794 (e.g. number of rows in the table, or the number of distinct values
4795 possible for the datatype if the field provides that kind of
4796 information).
4797
4798 @param max_distinct_values The maximum number of distinct values,
4799 typically the number of rows in the table
4800 @param default_filter The default filter for the predicate
4801
4802 @return the estimated filtering effect for this predicate
4803 */
4804
4805 float get_cond_filter_default_probability(double max_distinct_values,
4806 float default_filter) const;
4807
4808 /**
4809 @note that field->table->alias_name_used is reliable only if
4810 thd->lex->need_correct_ident() is true.
4811 */
4812 bool alias_name_used() const override {
4813 return m_alias_of_expr ||
4814 // maybe the qualifying table was given an alias ("t1 AS foo"):
4816 }
4817
4818 bool repoint_const_outer_ref(uchar *arg) override;
4819 bool returns_array() const override { return field && field->is_array(); }
4820 Item *apply_masking_policy(THD *thd) override;
4822
4823 void set_can_use_prefix_key() override { can_use_prefix_key = true; }
4824
4825 bool replace_field_processor(uchar *arg) override;
4826 bool strip_db_table_name_processor(uchar *) override;
4827
4828 /**
4829 Checks if the current object represents an asterisk select list item
4830
4831 @returns false if a regular column reference, true if an asterisk
4832 select list item.
4833 */
4834 virtual bool is_asterisk() const { return false; }
4835 /// See \c m_protected_by_any_value
4837
4838 void compute_cost(CostOfItem *root_cost) const override {
4839 field->add_to_cost(root_cost);
4840 }
4841};
4842
4843/**
4844 Represents [schema.][table.]* in a select list
4845
4846 Item_asterisk is used to insert placeholder objects for the special
4847 select list item * (asterisk) into AST.
4848 Those placeholder objects are to be substituted later with e.g. a list of real
4849 table columns by a resolver (@see setup_wild).
4850
4851 @todo The parent class Item_field is redundant. Refactor setup_wild() to
4852 replace Item_field with a simpler one.
4853*/
4856
4857 public:
4858 /**
4859 Constructor
4860
4861 @param pos Location of the * (asterisk) lexeme.
4862 @param opt_schema_name Schema name or nullptr.
4863 @param opt_table_name Table name or nullptr.
4864 */
4865 Item_asterisk(const POS &pos, const char *opt_schema_name,
4866 const char *opt_table_name)
4867 : super(pos, opt_schema_name, opt_table_name, "*") {}
4868
4869 bool do_itemize(Parse_context *pc, Item **res) override;
4870 bool fix_fields(THD *, Item **) override {
4871 assert(false); // should never happen: see setup_wild()
4872 return true;
4873 }
4874 bool is_asterisk() const override { return true; }
4875};
4876
4877// See if the provided item points to a reachable field (one that belongs to a
4878// table within 'reachable_tables'). If not, go through the list of 'equal'
4879// items in the item and see if we have a field that is reachable. If any such
4880// field is found, set "found" to true and create a new Item_field that points
4881// to this reachable field and return it if we are asked to "replace". If the
4882// provided item is already reachable, or if we cannot find a reachable field,
4883// return the provided item unchanged and set "found" to false. This is used
4884// when creating a hash join iterator, where the join condition may point to a
4885// non-reachable field due to multi-equality propagation during optimization.
4886// (Ideally, the optimizer should not set up such condition in the first place.
4887// This is difficult, if not impossible, to accomplish, given that the plan
4888// created by the optimizer does not map 100% to the iterator executor.) Note
4889// that if the field is not reachable, and we cannot find a reachable field, we
4890// provided field is returned unchanged. The effect is that the hash join will
4891// degrade into a nested loop.
4892Item_field *FindEqualField(Item_field *item_field, table_map reachable_tables,
4893 bool replace, bool *found);
4894
4897
4898 void init() {
4900 null_value = true;
4901 fixed = true;
4902 }
4903
4904 protected:
4906 bool no_conversions) override;
4907
4908 public:
4910 init();
4911 item_name = NAME_STRING("NULL");
4912 }
4913 explicit Item_null(const POS &pos) : super(pos) {
4914 init();
4915 item_name = NAME_STRING("NULL");
4916 }
4917
4918 Item_null(const Name_string &name_par) {
4919 init();
4920 item_name = name_par;
4921 }
4922
4923 enum Type type() const override { return NULL_ITEM; }
4924 bool eq(const Item *item) const override;
4925 double val_real() override;
4926 longlong val_int() override;
4927 longlong val_date_temporal() override { return val_int(); }
4928 String *val_str(String *str) override;
4929 my_decimal *val_decimal(my_decimal *) override;
4930 bool val_date(Date_val *, my_time_flags_t) override { return true; }
4931 bool val_time(Time_val *) override { return true; }
4932 bool val_datetime(Datetime_val *, my_time_flags_t) override { return true; }
4933 bool val_json(Json_wrapper *wr) override;
4934 bool send(Protocol *protocol, String *str) override;
4935 Item_result result_type() const override { return STRING_RESULT; }
4936 Item *clone_item() const override { return new Item_null(item_name); }
4937 bool is_null() override { return true; }
4938
4939 void print(const THD *, String *str,
4940 enum_query_type query_type) const override {
4941 str->append(query_type == QT_NORMALIZED_FORMAT ? "?" : "NULL");
4942 }
4943 uint64_t hash() override;
4944
4945 bool check_partition_func_processor(uchar *) override { return false; }
4946};
4947
4948/// Dynamic parameters used as placeholders ('?') inside prepared statements
4949
4950class Item_param final : public Item, private Settable_routine_parameter {
4951 typedef Item super;
4952
4953 protected:
4955 bool no_conversions) override;
4956
4957 public:
4970
4972 m_param_state = state;
4973 }
4974
4976
4977 void mark_json_as_scalar() override { m_json_as_scalar = true; }
4978
4979 /*
4980 A buffer for string and long data values. Historically all allocated
4981 values returned from val_str() were treated as eligible to
4982 modification. I. e. in some cases Item_func_concat can append it's
4983 second argument to return value of the first one. Because of that we
4984 can't return the original buffer holding string data from val_str(),
4985 and have to have one buffer for data and another just pointing to
4986 the data. This is the latter one and it's returned from val_str().
4987 Can not be declared inside the union as it's not a POD type.
4988 */
4994 union {
4996 double real;
4998
4999 private:
5000 /**
5001 True if type of parameter is inherited from parent object (like a typecast).
5002 Reprepare of statement will not change this type.
5003 E.g, we have CAST(? AS DOUBLE), the parameter gets data type
5004 MYSQL_TYPE_DOUBLE and m_type_inherited is set true.
5005 */
5006 bool m_type_inherited{false};
5007 /**
5008 True if type of parameter has been pinned, attempt to use an incompatible
5009 actual type will cause error (no repreparation occurs), and value is
5010 subject to range check. This is used when the parameter is in a context
5011 where its type is imposed. For example, in LIMIT ?, we assign
5012 data_type() == integer, unsigned; and the provided value must be
5013 convertible to unsigned integer: passing a DOUBLE, instead of causing a
5014 repreparation as for an ordinary parameter, will cause an error; passing
5015 integer '-1' will also cause an error.
5016 */
5017 bool m_type_pinned{false};
5018 /**
5019 Parameter objects have a rather complex handling of data type, in order
5020 to consistently handle required type conversion semantics. There are
5021 three data type properties involved:
5022
5023 1. The data_type() property contains the desired type of the parameter
5024 value, as defined by an explicit CAST, the operation the parameter
5025 is part of, and/or the context given by other values and expressions.
5026 After implicit repreparation it may also be assigned from provided
5027 parameter values.
5028
5029 2. The data_type_source() property is the data type of the parameter value,
5030 as given by the supplied user variable or from the protocol buffer.
5031
5032 3. The data_type_actual() property is the data type of the parameter value,
5033 after possible conversion from the source data type.
5034 Conversions may involve
5035 - Character set conversion of string value.
5036 - Conversion from string or number into temporal value, if the
5037 resolved data type is a temporal.
5038 - Conversion from string to number, if the resolved data type is numeric.
5039
5040 In addition, each data type property may have extra attributes to enforce
5041 correct character set, collation and signedness of integers.
5042 */
5043 /**
5044 The "source" data type of the provided parameter.
5045 Used when the parameter comes through protocol buffers.
5046 Notice that signedness of integers is stored in m_unsigned_actual.
5047 */
5049 /**
5050 The actual data type of the parameter value provided by the user.
5051 For example:
5052
5053 PREPARE s FROM "SELECT ?=3e0";
5054
5055 makes Item_param->data_type() be MYSQL_TYPE_DOUBLE ; then:
5056
5057 SET @a='1';
5058 EXECUTE s USING @a;
5059
5060 data_type() is still MYSQL_TYPE_DOUBLE, while data_type_source() is
5061 MYSQL_TYPE_VARCHAR and data_type_actual() is MYSQL_TYPE_VARCHAR.
5062 Compatibility of data_type() and data_type_actual() is later tested
5063 in check_parameter_types().
5064 Only a limited set of field types are possible values:
5065 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_DOUBLE,
5066 MYSQL_TYPE_DATE, MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME,
5067 MYSQL_TYPE_VARCHAR, MYSQL_TYPE_NULL, MYSQL_TYPE_INVALID
5068 */
5070 /// Used when actual value is integer to indicate whether value is unsigned
5072 /**
5073 The character set and collation of the source parameter value.
5074 Ignored if not a string value.
5075 - If parameter value is sent over the protocol: the client collation
5076 - If parameter value is a user variable: the variable's collation
5077 */
5079 /**
5080 The character set and collation of the value stored in str_value, possibly
5081 after being converted from the m_collation_source collation.
5082 Ignored if not a string value.
5083 - If the derived collation is binary, the connection collation.
5084 - Otherwise, the derived collation (@see Item::collation).
5085 */
5087 /// Result type of parameter. @todo replace with type_to_result(data_type()
5089 /**
5090 m_param_state is used to indicate that no parameter value is available
5091 with NO_VALUE, or a NULL value is available (NULL_VALUE), or the actual
5092 type of the provided parameter value. Usually, this matches m_actual_type,
5093 but in the case of pinned data types, this is matching the resolved data
5094 type of the parameter. m_param_state reflects the type of the value stored
5095 in Item_param::value.
5096 */
5098
5099 /**
5100 If true, when retrieving JSON data, attempt to interpret a string value as
5101 a scalar JSON value, otherwise interpret it as a JSON object.
5102 */
5103 bool m_json_as_scalar{false};
5104
5105 /*
5106 data_type() is used when this item is used in a temporary table.
5107 This is NOT placeholder metadata sent to client, as this value
5108 is assigned after sending metadata (in setup_one_conversion_function).
5109 For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both
5110 in result set and placeholders metadata, no matter what type you will
5111 supply for this placeholder in mysql_stmt_execute.
5112 */
5113
5114 public:
5115 /*
5116 Offset of placeholder inside statement text. Used to create
5117 no-placeholders version of this statement for the binary log.
5118 */
5120
5121 Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg);
5122
5123 bool do_itemize(Parse_context *pc, Item **item) override;
5124
5125 Item_result result_type() const override { return m_result_type; }
5126 enum Type type() const override { return PARAM_ITEM; }
5127
5128 /// Set the currently resolved data type for this parameter as inherited
5129 void set_data_type_inherited() override { m_type_inherited = true; }
5130
5131 /// @returns true if data type for this parameter is inherited.
5132 bool is_type_inherited() const { return m_type_inherited; }
5133
5134 /// Pin the currently resolved data type for this parameter.
5135 void pin_data_type() override { m_type_pinned = true; }
5136
5137 /// @returns true if data type for this parameter is pinned.
5138 bool is_type_pinned() const { return m_type_pinned; }
5139
5140 /// @returns true if actual data value (integer) is unsigned
5141 bool is_unsigned_actual() const { return m_unsigned_actual; }
5142
5145 m_collation_source = coll;
5146 }
5149 m_collation_actual = coll;
5150 }
5151 /// @returns the source collation of the supplied string parameter
5153
5154 /// @returns the actual collation of the supplied string parameter
5157 return m_collation_actual;
5158 }
5159 bool fix_fields(THD *thd, Item **ref) override;
5160
5161 bool propagate_type(THD *thd, const Type_properties &type) override;
5162
5163 double val_real() override;
5164 longlong val_int() override;
5165 my_decimal *val_decimal(my_decimal *) override;
5166 String *val_str(String *) override;
5167 bool val_json(Json_wrapper *result) override;
5168 bool val_date(Date_val *date, my_time_flags_t flags) override;
5169 bool val_time(Time_val *time) override;
5170 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
5173 m_unsigned_actual = unsigned_val;
5174 }
5175 // For use with non-integer field types only
5178 }
5179 /// For use with all field types, especially integer types
5182 m_unsigned_actual = unsigned_val;
5183 }
5185
5187
5189 return data_type_actual();
5190 }
5191
5192 void set_null();
5193 void set_int(longlong i);
5194 void set_int(ulonglong i);
5195 void set_double(double i);
5196 void set_decimal(const char *str, ulong length);
5197 void set_decimal(const my_decimal *dv);
5198 bool set_str(const char *str, size_t length);
5199 bool set_longdata(const char *str, ulong length);
5201 void set_time(Time_val time);
5202 void set_date(Date_val date);
5203 void set_datetime(Datetime_val dt);
5204 bool set_from_user_var(THD *thd, const user_var_entry *entry);
5206 void reset();
5207
5208 const String *query_val_str(const THD *thd, String *str) const;
5209
5210 bool convert_value();
5211
5212 /*
5213 Parameter is treated as constant during execution, thus it will not be
5214 evaluated during preparation.
5215 */
5216 table_map used_tables() const override { return INNER_TABLE_BIT; }
5217 void print(const THD *thd, String *str,
5218 enum_query_type query_type) const override;
5219 uint64_t hash() override;
5220 bool is_null() override {
5221 assert(m_param_state != NO_VALUE);
5222 return m_param_state == NULL_VALUE;
5223 }
5224
5225 Item *clone_item() const override;
5226 /*
5227 Implement by-value equality evaluation if parameter value
5228 is set and is a basic constant (integer, real or string).
5229 Otherwise return false.
5230 */
5231 bool eq(const Item *item) const override;
5233 bool is_non_const_over_literals(uchar *) override { return true; }
5234 /**
5235 This should be called after any modification done to this Item, to
5236 propagate the said modification to all its clones.
5237 */
5238 void sync_clones();
5239 bool add_clone(Item_param *i) { return m_clones.push_back(i); }
5240
5241 private:
5243 return this;
5244 }
5245
5246 bool set_value(THD *, sp_rcontext *, Item **it) override;
5247
5248 void set_out_param_info(Send_field *info) override;
5249
5250 public:
5251 const Send_field *get_out_param_info() const override;
5252
5253 void make_field(Send_field *field) override;
5254
5257 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5258 func_arg->err_code = func_arg->get_unnamed_function_error_code();
5259 return true;
5260 }
5261 bool is_valid_for_pushdown(uchar *arg [[maybe_unused]]) override {
5262 // It is ok to push down a condition like "column > PS_parameter".
5263 return false;
5264 }
5265
5266 private:
5268 /**
5269 If a query expression's text QT or text of a condition (CT) that is pushed
5270 down to a derived table, containing a parameter, is internally duplicated
5271 and parsed twice (@see reparse_common_table_expression, parse_expression),
5272 the first parsing will create an Item_param I, and the re-parsing, which
5273 parses a forged "(QT)" parse-this-CTE type of statement or parses a
5274 forged condition "(CT)", will create an Item_param J. J should not exist:
5275 - from the point of view of logging: it is not in the original query so it
5276 should not be substituted in the query written to logs (in insert_params()
5277 if with_log is true).
5278 - from the POV of the user:
5279 * user provides one single value for I, not one for I and one for J.
5280 * user expects mysql_stmt_param_count() to return 1, not 2 (count is
5281 sent by the server in send_prep_stmt()).
5282 That is why J is part neither of LEX::param_list, nor of param_array; it
5283 is considered an inferior clone of I; I::m_clones contains J.
5284 The connection between I and J is made once, by comparing their
5285 byte position in the statement, in Item_param::itemize().
5286 J gets its value from I: @see Item_param::sync_clones.
5287 */
5289};
5290
5291class Item_int : public Item_num {
5293
5294 public:
5295 static Item_int *narrow(Item *item);
5296
5299 : value((longlong)i) {
5302 fixed = true;
5303 }
5305 : super(pos), value((longlong)i) {
5308 fixed = true;
5309 }
5313 fixed = true;
5314 }
5316 : value((longlong)i) {
5318 unsigned_flag = true;
5320 fixed = true;
5321 }
5322 Item_int(const Item_int *item_arg) {
5323 set_data_type(item_arg->data_type());
5324 value = item_arg->value;
5325 item_name = item_arg->item_name;
5326 max_length = item_arg->max_length;
5327 fixed = true;
5328 }
5329 Item_int(const Name_string &name_arg, longlong i, uint length) : value(i) {
5332 item_name = name_arg;
5333 fixed = true;
5334 }
5335 Item_int(const POS &pos, const Name_string &name_arg, longlong i, uint length)
5336 : super(pos), value(i) {
5339 item_name = name_arg;
5340 fixed = true;
5341 }
5342 Item_int(const char *str_arg, uint length) {
5344 init(str_arg, length);
5345 }
5346 Item_int(const POS &pos, const char *str_arg, uint length) : super(pos) {
5348 init(str_arg, length);
5349 }
5350
5351 Item_int(const POS &pos, const LEX_STRING &num, int dummy_error = 0)
5352 : Item_int(pos, num, my_strtoll10(num.str, nullptr, &dummy_error),
5353 static_cast<uint>(num.length)) {}
5354
5355 private:
5356 void init(const char *str_arg, uint length);
5359 if (!unsigned_flag && value >= 0) max_length++;
5360 }
5361
5362 protected:
5364 bool no_conversions) override;
5365
5366 public:
5367 enum Type type() const override { return INT_ITEM; }
5368 Item_result result_type() const override { return INT_RESULT; }
5369 longlong val_int() override {
5370 assert(fixed);
5371 return value;
5372 }
5373 double val_real() override {
5374 assert(fixed);
5375 return static_cast<double>(value);
5376 }
5377 my_decimal *val_decimal(my_decimal *) override;
5378 String *val_str(String *) override;
5379 bool val_date(Date_val *date, my_time_flags_t flags) override {
5380 return get_date_from_int(date, flags);
5381 }
5382 bool val_time(Time_val *time) override { return get_time_from_int(time); }
5384 return get_datetime_from_int(dt, flags);
5385 }
5386 Item *clone_item() const override { return new Item_int(this); }
5387 void print(const THD *thd, String *str,
5388 enum_query_type query_type) const override;
5389 uint64_t hash() override;
5390 Item_num *neg() override {
5391 value = -value;
5392 return this;
5393 }
5394 uint decimal_precision() const override {
5395 return static_cast<uint>(max_length - 1);
5396 }
5397 bool eq(const Item *item) const override;
5398 bool check_partition_func_processor(uchar *) override { return false; }
5399 bool check_function_as_value_generator(uchar *) override { return false; }
5400};
5401
5402/**
5403 Item_int with value==0 and length==1
5404*/
5405class Item_int_0 final : public Item_int {
5406 public:
5408 explicit Item_int_0(const POS &pos) : Item_int(pos, NAME_STRING("0"), 0, 1) {}
5409};
5410
5411/*
5412 Item_temporal is used to store numeric representation
5413 of datetime values for queries like:
5414
5415 WHERE datetime_column NOT IN
5416 ('2006-04-25 10:00:00','2006-04-25 10:02:00', ...);
5417
5418 and for SHOW/INFORMATION_SCHEMA purposes (see sql_show.cc)
5419
5420 TS-TODO: Can't we use Item_time_literal, Item_date_literal,
5421 TS-TODO: and Item_datetime_literal for this purpose?
5422*/
5423class Item_temporal final : public Item_int {
5424 protected:
5426 bool no_conversions) override;
5427
5428 public:
5430 assert(is_temporal_type(field_type_arg));
5431 assert(field_type_arg != MYSQL_TYPE_TIME &&
5432 field_type_arg != MYSQL_TYPE_DATE);
5433 set_data_type(field_type_arg);
5434 }
5435 Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg,
5436 longlong i, uint length)
5437 : Item_int(i) {
5438 assert(is_temporal_type(field_type_arg));
5439 assert(field_type_arg != MYSQL_TYPE_TIME &&
5440 field_type_arg != MYSQL_TYPE_DATE);
5441 set_data_type(field_type_arg);
5443 item_name = name_arg;
5444 fixed = true;
5445 }
5446 Item *clone_item() const override {
5447 return new Item_temporal(data_type(), value);
5448 }
5449 longlong val_date_temporal() override { return val_int(); }
5451 assert(false);
5452 return false;
5453 }
5454 bool val_time(Time_val *) override {
5455 assert(false);
5456 return false;
5457 }
5459 assert(false);
5460 return false;
5461 }
5462};
5463
5464class Item_uint : public Item_int {
5465 protected:
5467 bool no_conversions) override;
5468
5469 public:
5470 Item_uint(const char *str_arg, uint length) : Item_int(str_arg, length) {
5471 unsigned_flag = true;
5472 }
5473 Item_uint(const POS &pos, const char *str_arg, uint length)
5474 : Item_int(pos, str_arg, length) {
5475 unsigned_flag = true;
5476 }
5477
5479 Item_uint(const Name_string &name_arg, longlong i, uint length)
5480 : Item_int(name_arg, i, length) {
5481 unsigned_flag = true;
5482 }
5483 double val_real() override {
5484 assert(fixed);
5485 return ulonglong2double(static_cast<ulonglong>(value));
5486 }
5487 String *val_str(String *) override;
5488
5489 Item *clone_item() const override {
5490 return new Item_uint(item_name, value, max_length);
5491 }
5492 void print(const THD *thd, String *str,
5493 enum_query_type query_type) const override;
5494 uint64_t hash() override;
5495 Item_num *neg() override;
5496 uint decimal_precision() const override { return max_length; }
5497};
5498
5499/* decimal (fixed point) constant */
5500class Item_decimal : public Item_num {
5502
5503 protected:
5506 bool no_conversions) override;
5507
5508 public:
5509 Item_decimal(const POS &pos, const char *str_arg, uint length,
5510 const CHARSET_INFO *charset);
5511 Item_decimal(const Name_string &name_arg, const my_decimal *val_arg,
5512 uint decimal_par, uint length);
5513 Item_decimal(my_decimal *value_par);
5514 Item_decimal(longlong val, bool unsig);
5515 Item_decimal(double val);
5516 Item_decimal(const uchar *bin, int precision, int scale);
5517
5518 enum Type type() const override { return DECIMAL_ITEM; }
5519 Item_result result_type() const override { return DECIMAL_RESULT; }
5520 longlong val_int() override;
5521 double val_real() override;
5522 String *val_str(String *) override;
5524 bool val_date(Date_val *date, my_time_flags_t flags) override {
5525 return get_date_from_decimal(date, flags);
5526 }
5527 bool val_time(Time_val *time) override { return get_time_from_decimal(time); }
5529 return get_datetime_from_decimal(dt, flags);
5530 }
5531 Item *clone_item() const override {
5533 }
5534 void print(const THD *thd, String *str,
5535 enum_query_type query_type) const override;
5536 uint64_t hash() override;
5537 Item_num *neg() override {
5540 return this;
5541 }
5542 uint decimal_precision() const override { return decimal_value.precision(); }
5543 bool eq(const Item *item) const override;
5544 void set_decimal_value(const my_decimal *value_par);
5545 bool check_partition_func_processor(uchar *) override { return false; }
5546};
5547
5548class Item_float : public Item_num {
5550
5552
5553 public:
5554 double value;
5555 // Item_real() :value(0) {}
5556 Item_float(const char *str_arg, uint length) { init(str_arg, length); }
5557 Item_float(const POS &pos, const char *str_arg, uint length) : super(pos) {
5558 init(str_arg, length);
5559 }
5560
5561 Item_float(const Name_string name_arg, double val_arg, uint decimal_par,
5562 uint length)
5563 : value(val_arg) {
5564 presentation = name_arg;
5565 item_name = name_arg;
5567 decimals = (uint8)decimal_par;
5569 fixed = true;
5570 }
5571 Item_float(const POS &pos, const Name_string name_arg, double val_arg,
5572 uint decimal_par, uint length)
5573 : super(pos), value(val_arg) {
5574 presentation = name_arg;
5575 item_name = name_arg;
5577 decimals = (uint8)decimal_par;
5579 fixed = true;
5580 }
5581
5582 Item_float(double value_par, uint decimal_par) : value(value_par) {
5584 decimals = (uint8)decimal_par;
5585 max_length = float_length(decimal_par);
5586 fixed = true;
5587 }
5588
5589 private:
5590 void init(const char *str_arg, uint length);
5591
5592 protected:
5594 bool no_conversions) override;
5595
5596 public:
5597 enum Type type() const override { return REAL_ITEM; }
5598 double val_real() override {
5599 assert(fixed);
5600 return value;
5601 }
5602 longlong val_int() override {
5603 assert(fixed);
5604 if (value <= LLONG_MIN) {
5605 return LLONG_MIN;
5606 } else if (value > LLONG_MAX_DOUBLE) {
5607 return LLONG_MAX;
5608 }
5609 return (longlong)rint(value);
5610 }
5611 String *val_str(String *) override;
5612 my_decimal *val_decimal(my_decimal *) override;
5613 bool val_date(Date_val *date, my_time_flags_t flags) override {
5614 return get_date_from_real(date, flags);
5615 }
5616 bool val_time(Time_val *time) override { return get_time_from_real(time); }
5618 return get_datetime_from_real(dt, flags);
5619 }
5620 Item *clone_item() const override {
5622 }
5623 Item_num *neg() override {
5624 value = -value;
5625 return this;
5626 }
5627 void print(const THD *thd, String *str,
5628 enum_query_type query_type) const override;
5629 uint64_t hash() override;
5630 bool eq(const Item *item) const override;
5631};
5632
5633class Item_func_pi : public Item_float {
5635
5636 public:
5637 Item_func_pi(const POS &pos)
5638 : Item_float(pos, null_name_string, M_PI, 6, 8),
5639 func_name(NAME_STRING("pi()")) {}
5640
5641 void print(const THD *, String *str, enum_query_type) const override {
5642 str->append(func_name);
5643 }
5644};
5645
5648
5649 protected:
5650 explicit Item_string(const POS &pos) : super(pos), m_cs_specified(false) {
5652 }
5653
5654 void init(const char *str, size_t length, const CHARSET_INFO *cs,
5655 Derivation dv, uint repertoire) {
5658 collation.set(cs, dv, repertoire);
5659 /*
5660 We have to have a different max_length than 'length' here to
5661 ensure that we get the right length if we do use the item
5662 to create a new table. In this case max_length must be the maximum
5663 number of chars for a string of this type because we in Create_field::
5664 divide the max_length with mbmaxlen).
5665 */
5666 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5669 // it is constant => can be used without fix_fields (and frequently used)
5670 fixed = true;
5671 /*
5672 Check if the string has any character that can't be
5673 interpreted using the relevant charset.
5674 */
5675 check_well_formed_result(&str_value, false, false);
5676 }
5678 bool no_conversions) override;
5679
5680 public:
5681 /* Create from a string, set name from the string itself. */
5682 Item_string(const char *str, size_t length, const CHARSET_INFO *cs,
5684 uint repertoire = MY_REPERTOIRE_UNICODE30)
5685 : m_cs_specified(false) {
5686 init(str, length, cs, dv, repertoire);
5687 }
5688 Item_string(const POS &pos, const char *str, size_t length,
5690 uint repertoire = MY_REPERTOIRE_UNICODE30)
5691 : super(pos), m_cs_specified(false) {
5692 init(str, length, cs, dv, repertoire);
5693 }
5694
5695 /* Just create an item and do not fill string representation */
5697 : m_cs_specified(false) {
5698 collation.set(cs, dv);
5700 max_length = 0;
5702 fixed = true;
5703 }
5704
5705 /* Create from the given name and string. */
5706 Item_string(const Name_string name_par, const char *str, size_t length,
5708 uint repertoire = MY_REPERTOIRE_UNICODE30)
5709 : m_cs_specified(false) {
5711 collation.set(cs, dv, repertoire);
5713 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5714 item_name = name_par;
5716 // it is constant => can be used without fix_fields (and frequently used)
5717 fixed = true;
5718 }
5719 Item_string(const POS &pos, const Name_string name_par, const char *str,
5720 size_t length, const CHARSET_INFO *cs,
5722 uint repertoire = MY_REPERTOIRE_UNICODE30)
5723 : super(pos), m_cs_specified(false) {
5725 collation.set(cs, dv, repertoire);
5727 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5728 item_name = name_par;
5730 // it is constant => can be used without fix_fields (and frequently used)
5731 fixed = true;
5732 }
5733
5734 /* Create from the given name and string. */
5735 Item_string(const POS &pos, const Name_string name_par,
5736 const LEX_CSTRING &literal, const CHARSET_INFO *cs,
5738 uint repertoire = MY_REPERTOIRE_UNICODE30)
5739 : super(pos), m_cs_specified(false) {
5740 str_value.set_or_copy_aligned(literal.str ? literal.str : "",
5741 literal.str ? literal.length : 0, cs);
5742 collation.set(cs, dv, repertoire);
5744 max_length = static_cast<uint32>(str_value.numchars() * cs->mbmaxlen);
5745 item_name = name_par;
5747 // it is constant => can be used without fix_fields (and frequently used)
5748 fixed = true;
5749 }
5750
5751 /*
5752 This is used in stored procedures to avoid memory leaks and
5753 does a deep copy of its argument.
5754 */
5755 void set_str_with_copy(const char *str_arg, uint length_arg) {
5756 str_value.copy(str_arg, length_arg, collation.collation);
5757 max_length = static_cast<uint32>(str_value.numchars() *
5759 }
5760 bool set_str_with_copy(const char *str_arg, uint length_arg,
5761 const CHARSET_INFO *from_cs);
5762 /// Update collation of string value to be according to item's collation
5764
5768 }
5769 enum Type type() const override { return STRING_ITEM; }
5770 double val_real() override;
5771 longlong val_int() override;
5772 String *val_str(String *) override {
5773 assert(fixed);
5774 return &str_value;
5775 }
5776 my_decimal *val_decimal(my_decimal *) override;
5777 bool val_date(Date_val *date, my_time_flags_t flags) override {
5778 return get_date_from_string(date, flags);
5779 }
5780 bool val_time(Time_val *time) override { return get_time_from_string(time); }
5782 return get_datetime_from_string(dt, flags);
5783 }
5784 Item_result result_type() const override { return STRING_RESULT; }
5785 bool eq(const Item *item) const override;
5786 bool eq_binary(const Item_string *item) const {
5787 return !stringcmp(&str_value, &item->str_value);
5788 }
5789 Item *clone_item() const override {
5790 return new Item_string(static_cast<Name_string>(item_name), str_value.ptr(),
5792 }
5793 inline void append(char *str, size_t length) {
5795 max_length = static_cast<uint32>(str_value.numchars() *
5797 }
5798 void print(const THD *thd, String *str,
5799 enum_query_type query_type) const override;
5800 uint64_t hash() override;
5801 bool check_partition_func_processor(uchar *) override { return false; }
5802
5803 /**
5804 Return true if character-set-introducer was explicitly specified in the
5805 original query for this item (text literal).
5806
5807 This operation is to be called from Item_string::print(). The idea is
5808 that when a query is generated (re-constructed) from the Item-tree,
5809 character-set-introducers should appear only for those literals, where
5810 they were explicitly specified by the user. Otherwise, that may lead to
5811 loss collation information (character set introducers implies default
5812 collation for the literal).
5813
5814 Basically, that makes sense only for views and hopefully will be gone
5815 one day when we start using original query as a view definition.
5816
5817 @return This operation returns the value of m_cs_specified attribute.
5818 @retval true if character set introducer was explicitly specified in
5819 the original query.
5820 @retval false otherwise.
5821 */
5822 inline bool is_cs_specified() const { return m_cs_specified; }
5823
5824 /**
5825 Set the value of m_cs_specified attribute.
5826
5827 m_cs_specified attribute shows whether character-set-introducer was
5828 explicitly specified in the original query for this text literal or
5829 not. The attribute makes sense (is used) only for views.
5830
5831 This operation is to be called from the parser during parsing an input
5832 query.
5833 */
5834 inline void set_cs_specified(bool cs_specified) {
5835 m_cs_specified = cs_specified;
5836 }
5837
5839
5840 private:
5842};
5843
5845 const char *cptr, const char *end,
5846 int unsigned_target);
5847double double_from_string_with_check(const CHARSET_INFO *cs, const char *cptr,
5848 const char *end);
5849
5852
5853 public:
5854 Item_static_string_func(const Name_string &name_par, const char *str,
5855 size_t length, const CHARSET_INFO *cs,
5858 func_name(name_par) {}
5859 Item_static_string_func(const POS &pos, const Name_string &name_par,
5860 const char *str, size_t length,
5861 const CHARSET_INFO *cs,
5863 : Item_string(pos, null_name_string, str, length, cs, dv),
5864 func_name(name_par) {}
5865
5866 void print(const THD *, String *str, enum_query_type) const override {
5867 str->append(func_name);
5868 }
5869 uint64_t hash() override;
5870 bool check_partition_func_processor(uchar *) override { return true; }
5873 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5874 func_arg->banned_function_name = func_name.ptr();
5875 return true;
5876 }
5877};
5878
5879/* for show tables */
5881 public:
5883 const CHARSET_INFO *cs = nullptr)
5884 : Item_string(name, NullS, 0, cs) {
5885 max_length = static_cast<uint32>(length);
5886 }
5887};
5888
5890 public:
5891 Item_blob(const char *name, size_t length)
5893 &my_charset_bin) {
5895 }
5896 enum Type type() const override { return STRING_ITEM; }
5899 pointer_cast<Check_function_as_value_generator_parameters *>(args);
5900 func_arg->err_code = func_arg->get_unnamed_function_error_code();
5901 return true;
5902 }
5903};
5904
5905/**
5906 Item_empty_string -- is a utility class to put an item into List<Item>
5907 which is then used in protocol.send_result_set_metadata() when sending SHOW
5908 output to the client.
5909*/
5910
5912 public:
5913 Item_empty_string(const char *header, size_t length,
5914 const CHARSET_INFO *cs = nullptr)
5916 Name_string(header, strlen(header)), 0,
5919 }
5920 void make_field(Send_field *field) override;
5921};
5922
5924 public:
5925 Item_return_int(const char *name_arg, uint length,
5926 enum_field_types field_type_arg, longlong value_arg = 0)
5927 : Item_int(Name_string(name_arg, name_arg ? strlen(name_arg) : 0),
5928 value_arg, length) {
5929 set_data_type(field_type_arg);
5930 unsigned_flag = true;
5931 }
5932};
5933
5936
5937 protected:
5939 bool no_conversions) override;
5940
5941 public:
5943 explicit Item_hex_string(const POS &pos) : super(pos) {
5945 }
5946
5947 Item_hex_string(const POS &pos, const LEX_STRING &literal);
5948
5949 enum Type type() const override { return HEX_BIN_ITEM; }
5950 double val_real() override {
5951 assert(fixed);
5952 return (double)(ulonglong)Item_hex_string::val_int();
5953 }
5954 longlong val_int() override;
5955 Item *clone_item() const override;
5956
5957 String *val_str(String *) override {
5958 assert(fixed);
5959 return &str_value;
5960 }
5961 my_decimal *val_decimal(my_decimal *) override;
5962 bool val_date(Date_val *date, my_time_flags_t flags) override {
5963 return get_date_from_string(date, flags);
5964 }
5965 bool val_time(Time_val *time) override { return get_time_from_string(time); }
5967 return get_datetime_from_string(dt, flags);
5968 }
5969 Item_result result_type() const override { return STRING_RESULT; }
5971 return INT_RESULT;
5972 }
5973 Item_result cast_to_int_type() const override { return INT_RESULT; }
5974 void print(const THD *thd, String *str,
5975 enum_query_type query_type) const override;
5976 uint64_t hash() override;
5977 bool eq(const Item *item) const override;
5978 bool check_partition_func_processor(uchar *) override { return false; }
5979 static LEX_CSTRING make_hex_str(const char *str, size_t str_length);
5980 uint decimal_precision() const override;
5981
5982 private:
5983 void hex_string_init(const char *str, uint str_length);
5984};
5985
5986class Item_bin_string final : public Item_hex_string {
5988
5989 public:
5990 Item_bin_string(const char *str, size_t str_length) {
5991 bin_string_init(str, str_length);
5992 }
5993 Item_bin_string(const POS &pos, const LEX_STRING &literal) : super(pos) {
5994 bin_string_init(literal.str, literal.length);
5995 }
5996
5997 static LEX_CSTRING make_bin_str(const char *str, size_t str_length);
5998
5999 private:
6000 void bin_string_init(const char *str, size_t str_length);
6001};
6002
6003/**
6004 Item with result field.
6005
6006 It adds to an Item a "result_field" Field member. This is for an item which
6007 may have a result (e.g. Item_func), and may store this result into a field;
6008 usually this field is a column of an internal temporary table. So the
6009 function may be evaluated by save_in_field(), storing result into
6010 result_field in tmp table. Then this result can be copied from tmp table to
6011 a following tmp table (e.g. GROUP BY table then ORDER BY table), or to a row
6012 buffer and back, as we want to avoid multiple evaluations of the Item, first
6013 because of performance, second because that evaluation may have side
6014 effects, e.g. SLEEP, GET_LOCK, RAND, window functions doing
6015 accumulations...
6016 Item_field and Item_ref also have a "result_field" for a similar goal.
6017 Literals don't need such "result_field" as their value is readily
6018 available.
6019*/
6020class Item_result_field : public Item {
6021 protected:
6022 Field *result_field{nullptr}; /* Save result here */
6023 public:
6025 explicit Item_result_field(const POS &pos) : Item(pos) {}
6026
6027 // Constructor used for Item_sum/Item_cond_and/or (see Item comment)
6029 : Item(thd, item), result_field(item->result_field) {}
6031 Field *tmp_table_field(TABLE *) override { return result_field; }
6032 table_map used_tables() const override { return 1; }
6033
6034 /**
6035 Resolve type-related information for this item, such as result field type,
6036 maximum size, precision, signedness, character set and collation.
6037 Also check compatibility of argument types and return error when applicable.
6038 Also adjust nullability when applicable.
6039
6040 @param thd thread handler
6041 @returns false if success, true if error
6042 */
6043 virtual bool resolve_type(THD *thd) = 0;
6044
6045 void set_result_field(Field *field) override { result_field = field; }
6046 bool is_result_field() const override { return true; }
6047 Field *get_result_field() const override { return result_field; }
6048
6049 void cleanup() override;
6050 bool check_function_as_value_generator(uchar *) override { return false; }
6051 bool mark_field_in_map(uchar *arg) override {
6052 bool rc = Item::mark_field_in_map(arg);
6053 if (result_field) // most likely result_field will be read too
6054 rc |= Item::mark_field_in_map(pointer_cast<Mark_field *>(arg),
6055 result_field);
6056 return rc;
6057 }
6058
6060 if (realval < LLONG_MIN || realval > LLONG_MAX_DOUBLE) {
6062 return error_int();
6063 }
6064 return llrint(realval);
6065 }
6066
6067 void raise_numeric_overflow(const char *type_name);
6068
6070 raise_numeric_overflow("DOUBLE");
6071 return 0.0;
6072 }
6073
6075 raise_numeric_overflow(unsigned_flag ? "BIGINT UNSIGNED" : "BIGINT");
6076 return 0;
6077 }
6078
6080 raise_numeric_overflow(unsigned_flag ? "DECIMAL UNSIGNED" : "DECIMAL");
6081 return E_DEC_OVERFLOW;
6082 }
6083};
6084
6085class Item_ref : public Item_ident {
6086 protected:
6087 void set_properties();
6089 bool no_conversions) override;
6090
6091 public:
6093 // If true, depended_from information of this ref was pushed down to
6094 // underlying field.
6096
6097 private:
6098 Field *result_field{nullptr}; /* Save result here */
6099
6100 protected:
6101 /// Indirect pointer to the referenced item.
6102 Item **m_ref_item{nullptr};
6103
6104 public:
6105 Item_ref(const POS &pos, const char *db_name_arg, const char *table_name_arg,
6106 const char *field_name_arg)
6107 : Item_ident(pos, db_name_arg, table_name_arg, field_name_arg) {}
6108
6109 /*
6110 This constructor is used in two scenarios:
6111 A) *item = NULL
6112 No initialization is performed, fix_fields() call will be necessary.
6113
6114 B) *item points to an Item this Item_ref will refer to. This is
6115 used for GROUP BY. fix_fields() will not be called in this case,
6116 so we call set_properties to make this item "fixed". set_properties
6117 performs a subset of action Item_ref::fix_fields does, and this subset
6118 is enough for Item_ref's used in GROUP BY.
6119
6120 TODO we probably fix a superset of problems like in BUG#6658. Check this
6121 with Bar, and if we have a more broader set of problems like this.
6122 */
6123 Item_ref(Name_resolution_context *context_arg, Item **item,
6124 const char *db_name_arg, const char *table_name_arg,
6125 const char *field_name_arg, bool alias_of_expr_arg = false);
6126 Item_ref(Name_resolution_context *context_arg, Item **item,
6127 const char *field_name_arg);
6128
6129 /* Constructor need to process subselect with temporary tables (see Item) */
6130 Item_ref(THD *thd, Item_ref *item)
6131 : Item_ident(thd, item),
6133 m_ref_item(item->m_ref_item) {}
6134
6135 /// @returns the item referenced by this object
6136 Item *ref_item() const { return *m_ref_item; }
6137
6138 /// @returns the pointer to the item referenced by this object
6139 Item **ref_pointer() const { return m_ref_item; }
6140
6142
6143 enum Type type() const override { return REF_ITEM; }
6144 bool eq(const Item *item) const override {
6145 const Item *it = item->real_item();
6146 // May search for a referenced item that is not yet resolved:
6147 if (m_ref_item == nullptr) return false;
6148 return ref_item()->eq(it);
6149 }
6150 double val_real() override;
6151 longlong val_int() override;
6152 longlong val_date_temporal() override;
6153 my_decimal *val_decimal(my_decimal *) override;
6154 bool val_bool() override;
6155 String *val_str(String *tmp) override;
6156 bool val_json(Json_wrapper *result) override;
6157 bool is_null() override;
6158 bool val_date(Date_val *date, my_time_flags_t flags) override;
6159 bool val_time(Time_val *time) override;
6160 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
6161 bool send(Protocol *prot, String *tmp) override;
6162 void make_field(Send_field *field) override;
6163 bool fix_fields(THD *, Item **) override;
6164 void fix_after_pullout(Query_block *parent_query_block,
6165 Query_block *removed_query_block) override;
6166
6167 Item_result result_type() const override { return ref_item()->result_type(); }
6168
6169 TYPELIB *get_typelib() const override { return ref_item()->get_typelib(); }
6170
6172 return result_field != nullptr ? result_field
6174 }
6175 Item *get_tmp_table_item(THD *thd) override;
6176 table_map used_tables() const override {
6177 if (depended_from != nullptr) return OUTER_REF_TABLE_BIT;
6178 const table_map map = ref_item()->used_tables();
6179 if (map != 0) return map;
6180 // rollup constant: ensure it is non-constant by returning RAND_TABLE_BIT
6182 return 0;
6183 }
6184 void update_used_tables() override {
6185 if (depended_from == nullptr) ref_item()->update_used_tables();
6186 /*
6187 Reset all flags except GROUP BY modifier, since we do not mark the rollup
6188 expression itself.
6189 */
6192 }
6193
6194 table_map not_null_tables() const override {
6195 /*
6196 It can happen that our 'depended_from' member is set but the
6197 'depended_from' member of the referenced item is not (example: if a
6198 field in a subquery belongs to an outer merged view), so we first test
6199 ours:
6200 */
6201 return depended_from != nullptr ? OUTER_REF_TABLE_BIT
6203 }
6204 void set_result_field(Field *field) override { result_field = field; }
6205 bool is_result_field() const override { return true; }
6206 Field *get_result_field() const override { return result_field; }
6207 Item *real_item() override {
6208 // May look into unresolved Item_ref objects
6209 if (m_ref_item == nullptr) return this;
6210 return ref_item()->real_item();
6211 }
6212 const Item *real_item() const override {
6213 // May look into unresolved Item_ref objects
6214 if (m_ref_item == nullptr) return this;
6215 return ref_item()->real_item();
6216 }
6217
6218 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override {
6219 // Unresolved items may have m_ref_item = nullptr
6220 return ((walk & enum_walk::PREFIX) && (this->*processor)(arg)) ||
6221 (m_ref_item != nullptr ? ref_item()->walk(processor, walk, arg)
6222 : false) ||
6223 ((walk & enum_walk::POSTFIX) && (this->*processor)(arg));
6224 }
6225 Item *transform(Item_transformer, uchar *arg) override;
6226 Item *compile(Item_analyzer analyzer, uchar **arg_p,
6227 Item_transformer transformer, uchar *arg_t) override;
6228 void traverse_cond(Cond_traverser traverser, void *arg,
6229 traverse_order order) override {
6230 assert(ref_item() != nullptr);
6231 if (order == PREFIX) (*traverser)(this, arg);
6232 ref_item()->traverse_cond(traverser, arg, order);
6233 if (order == POSTFIX) (*traverser)(this, arg);
6234 }
6236 /*
6237 Always return false: we don't need to go deeper into referenced
6238 expression tree since we have to mark aliased subqueries at
6239 their original places (select list, derived tables), not by
6240 references from other expression (order by etc).
6241 */
6242 return false;
6243 }
6244 bool clean_up_after_removal(uchar *arg) override;
6245 void print(const THD *thd, String *str,
6246 enum_query_type query_type) const override;
6247 uint64_t hash() override;
6248 void cleanup() override;
6250 return ref_item()->field_for_view_update();
6251 }
6252 virtual Ref_Type ref_type() const { return REF; }
6253
6254 // Row emulation: forwarding of ROW-related calls to ref
6255 uint cols() const override {
6256 assert(m_ref_item != nullptr);
6257 return result_type() == ROW_RESULT ? ref_item()->cols() : 1;
6258 }
6259 Item *element_index(uint i) override {
6260 assert(m_ref_item != nullptr);
6261 return result_type() == ROW_RESULT ? ref_item()->element_index(i) : this;
6262 }
6263 Item **addr(uint i) override {
6264 assert(m_ref_item != nullptr);
6265 return result_type() == ROW_RESULT ? ref_item()->addr(i) : nullptr;
6266 }
6267 bool check_cols(uint c) override {
6268 assert(m_ref_item != nullptr);
6269 return result_type() == ROW_RESULT ? ref_item()->check_cols(c)
6270 : Item::check_cols(c);
6271 }
6272 bool null_inside() override {
6273 assert(m_ref_item != nullptr);
6274 return result_type() == ROW_RESULT ? ref_item()->null_inside() : false;
6275 }
6276 void bring_value() override {
6277 assert(m_ref_item != nullptr);
6279 }
6280
6281 bool basic_const_item() const override { return false; }
6282
6283 bool is_outer_field() const override {
6284 assert(fixed);
6285 assert(ref_item());
6286 return ref_item()->is_outer_field();
6287 }
6288
6289 bool created_by_in2exists() const override {
6290 return ref_item()->created_by_in2exists();
6291 }
6292
6293 bool repoint_const_outer_ref(uchar *arg) override;
6294 bool is_non_const_over_literals(uchar *) override { return true; }
6297 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6298 func_arg->err_code = func_arg->get_unnamed_function_error_code();
6299 return true;
6300 }
6302 return ref_item()->cast_to_int_type();
6303 }
6304 bool is_valid_for_pushdown(uchar *arg) override {
6305 return ref_item()->is_valid_for_pushdown(arg);
6306 }
6309 }
6310 bool check_column_in_group_by(uchar *arg) override {
6311 return ref_item()->check_column_in_group_by(arg);
6312 }
6313 bool collect_item_field_or_ref_processor(uchar *arg) override;
6314};
6315
6316/**
6317 Class for fields from derived tables and views.
6318 The same as Item_ref, but call fix_fields() of reference if
6319 not called yet.
6320*/
6321class Item_view_ref final : public Item_ref {
6323
6324 public:
6326 const char *db_name_arg, const char *alias_name_arg,
6327 const char *table_name_arg, const char *field_name_arg,
6328 Table_ref *tr)
6329 : Item_ref(context_arg, item, db_name_arg, alias_name_arg,
6330 field_name_arg),
6332 if (tr->is_view()) {
6333 m_orig_db_name = db_name_arg;
6334 m_orig_table_name = table_name_arg;
6335 } else {
6336 assert(db_name_arg == nullptr);
6337 m_orig_table_name = table_name_arg;
6338 }
6339 m_table_ref = tr;
6341 set_nullable(true);
6343 }
6344 }
6345
6346 /*
6347 We share one underlying Item_field, so we have to disable
6348 build_equal_items_for_cond().
6349 TODO: Implement multiple equality optimization for views.
6350 */
6351 bool subst_argument_checker(uchar **) override { return false; }
6352
6353 bool fix_fields(THD *, Item **) override;
6354
6355 /**
6356 Takes into account whether an Item in a derived table / view is part of an
6357 inner table of an outer join.
6358 */
6359 table_map used_tables() const override {
6360 const Item_ref *inner_ref = this;
6361 const Item *inner_item;
6362 /*
6363 Check whether any of the inner expressions is an outer reference,
6364 and if it is, return OUTER_REF_TABLE_BIT.
6365 */
6366 while (true) {
6367 if (inner_ref->depended_from != nullptr) {
6368 return OUTER_REF_TABLE_BIT;
6369 }
6370 inner_item = inner_ref->ref_item();
6371 if (inner_item->type() != REF_ITEM) break;
6372 inner_ref = down_cast<const Item_ref *>(inner_item);
6373 }
6374
6375 const Item_field *field = inner_item->type() == FIELD_ITEM
6376 ? down_cast<const Item_field *>(inner_item)
6377 : nullptr;
6378
6379 // If the field is an outer reference, return OUTER_REF_TABLE_BIT
6380 if (field != nullptr && field->depended_from != nullptr) {
6381 return OUTER_REF_TABLE_BIT;
6382 }
6383 /*
6384 View references with expressions that are not deemed constant during
6385 execution, or when they are constants but the merged view/derived table
6386 was not from the inner side of an outer join, simply return the used
6387 tables of the underlying item. A "const" field that comes from an inner
6388 side of an outer join is not constant, since NULL values are issued
6389 when there are no matching rows in the inner table(s).
6390 */
6391 if (!inner_item->const_for_execution() || first_inner_table == nullptr) {
6392 return inner_item->used_tables();
6393 }
6394 /*
6395 This is a const expression on the inner side of an outer join.
6396 Augment its used table information with the map of an inner table from
6397 the outer join nest. field can be nullptr if it is from a const table.
6398 In this case, returning the table's original table map is required by
6399 the join optimizer.
6400 */
6401 return field != nullptr
6402 ? field->m_table_ref->map()
6403 : inner_item->used_tables() | first_inner_table->map();
6404 }
6405
6406 bool eq(const Item *item) const override;
6407 Item *get_tmp_table_item(THD *thd) override {
6408 DBUG_TRACE;
6410 item->item_name = item_name;
6411 return item;
6412 }
6413 Ref_Type ref_type() const override { return VIEW_REF; }
6414
6415 bool check_column_privileges(uchar *arg) override;
6416 bool mark_field_in_map(uchar *arg) override {
6417 /*
6418 If this referenced column is marked as used, flag underlying
6419 selected item from a derived table/view as used.
6420 */
6421 auto mark_field = (Mark_field *)arg;
6422 return get_result_field()
6424 : false;
6425 }
6426 longlong val_int() override;
6427 double val_real() override;
6429 String *val_str(String *str) override;
6430 bool val_date(Date_val *date, my_time_flags_t flags) override;
6431 bool val_time(Time_val *time) override;
6432 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
6433 bool val_bool() override;
6434 bool val_json(Json_wrapper *wr) override;
6435 bool is_null() override;
6436 bool send(Protocol *prot, String *tmp) override;
6438 Item *replace_item_view_ref(uchar *arg) override;
6439 Item *replace_view_refs_with_clone(uchar *arg) override;
6441
6442 protected:
6444 bool no_conversions) override;
6445
6446 private:
6447 /// @return true if item is from a null-extended row from an outer join
6448 bool has_null_row() const {
6450 }
6451
6452 /**
6453 If this column belongs to a view that is an inner table of an outer join,
6454 then this field points to the first leaf table of the view, otherwise NULL.
6455 */
6457};
6458
6459/*
6460 Class for outer fields.
6461 An object of this class is created when the select where the outer field was
6462 resolved is a grouping one. After it has been fixed the ref field will point
6463 to an Item_ref object which will be used to access the field.
6464 The ref field may also point to an Item_field instance.
6465 See also comments of the Item_field::fix_outer_field() function.
6466*/
6467
6468class Item_outer_ref final : public Item_ref {
6470
6471 private:
6472 /**
6473 Qualifying query of this outer ref (i.e. query block which owns FROM of
6474 table which this Item references).
6475 */
6477
6478 public:
6480 /* The aggregate function under which this outer ref is used, if any. */
6482 /*
6483 true <=> that the outer_ref is already present in the select list
6484 of the outer select.
6485 */
6489 : Item_ref(context_arg, nullptr, ident_arg->db_name,
6490 ident_arg->table_name, ident_arg->field_name, false),
6492 outer_ref(ident_arg),
6494 found_in_select_list(false) {
6498 // keep any select list alias:
6499 item_name = ident_arg->item_name;
6500 fixed = false;
6501 }
6503 const char *db_name_arg, const char *table_name_arg,
6504 const char *field_name_arg, bool alias_of_expr_arg,
6506 : Item_ref(context_arg, item, db_name_arg, table_name_arg, field_name_arg,
6507 alias_of_expr_arg),
6511 found_in_select_list(true) {}
6512 bool fix_fields(THD *, Item **) override;
6513 void fix_after_pullout(Query_block *parent_query_block,
6514 Query_block *removed_query_block) override;
6515 table_map used_tables() const override {
6516 return ref_item()->used_tables() == 0 ? 0 : OUTER_REF_TABLE_BIT;
6517 }
6518 table_map not_null_tables() const override { return 0; }
6519
6520 Ref_Type ref_type() const override { return OUTER_REF; }
6521 Item *replace_outer_ref(uchar *) override;
6522};
6523
6524/*
6525 An object of this class is like Item_ref, and
6526 sets owner->was_null=true if it has returned a NULL value from any
6527 val_XXX() function. This allows to inject an Item_ref_null_helper
6528 object into subquery and then check if the subquery has produced a row
6529 with NULL value.
6530*/
6531
6532class Item_ref_null_helper final : public Item_ref {
6534
6535 protected:
6537
6538 public:
6540 Item_in_subselect *master, Item **item)
6541 : super(context_arg, item, "", "", ""), owner(master) {}
6542 Item_ref_null_helper(const Item_ref_null_helper &ref_null_helper, Item **item)
6543 : Item_ref_null_helper(ref_null_helper.context, ref_null_helper.owner,
6544 item) {}
6545 double val_real() override;
6546 longlong val_int() override;
6547 longlong val_date_temporal() override;
6548 String *val_str(String *s) override;
6549 my_decimal *val_decimal(my_decimal *) override;
6550 bool val_bool() override;
6551 bool val_time(Time_val *time) override;
6552 bool val_date(Date_val *date, my_time_flags_t flags) override;
6553 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
6554 void print(const THD *thd, String *str,
6555 enum_query_type query_type) const override;
6556 Ref_Type ref_type() const override { return NULL_HELPER_REF; }
6557 /*
6558 we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE
6559 */
6560 table_map used_tables() const override {
6563 }
6564};
6565
6566/*
6567 The following class is used to optimize comparing of bigint columns.
6568 We need to save the original item ('ref') to be able to call
6569 ref->save_in_field(). This is used to create index search keys.
6570
6571 An instance of Item_int_with_ref may have signed or unsigned integer value.
6572
6573*/
6574
6576 protected:
6579 bool no_conversions) override {
6580 return ref->save_in_field(field, no_conversions);
6581 }
6582
6583 public:
6585 bool unsigned_arg)
6586 : Item_int(i), ref(ref_arg) {
6587 set_data_type(field_type);
6588 unsigned_flag = unsigned_arg;
6589 }
6590 Item *clone_item() const override;
6591 uint64_t hash() override;
6592 Item *real_item() override { return ref; }
6593 const Item *real_item() const override { return ref; }
6594};
6595
6596/*
6597 Similar to Item_int_with_ref, but to optimize comparing of temporal columns.
6598*/
6600 public:
6601 Item_temporal_with_ref(enum_field_types field_type_arg, uint8 decimals_arg,
6602 longlong i, Item *ref_arg, bool unsigned_arg)
6603 : Item_int_with_ref(field_type_arg, i, ref_arg, unsigned_arg) {
6604 decimals = decimals_arg;
6605 }
6606 void print(const THD *thd, String *str,
6607 enum_query_type query_type) const override;
6608
6610 assert(false);
6611 return true;
6612 }
6613 bool val_time(Time_val *time) override {
6614 bool rc = ref->val_time(time);
6616 return rc;
6617 }
6618};
6619
6620/*
6621 Item_datetime_with_ref is used to optimize queries like:
6622 SELECT ... FROM t1 WHERE date_or_datetime_column = 20110101101010;
6623 The numeric constant is replaced to Item_datetime_with_ref
6624 by convert_constant_item().
6625*/
6627 public:
6628 /**
6629 Constructor for Item_datetime_with_ref.
6630 @param field_type_arg Data type: MYSQL_TYPE_DATE or MYSQL_TYPE_DATETIME
6631 @param decimals_arg Number of fractional digits.
6632 @param i Temporal value in packed format.
6633 @param ref_arg Pointer to the original numeric Item.
6634 */
6635 Item_datetime_with_ref(enum_field_types field_type_arg, uint8 decimals_arg,
6636 longlong i, Item *ref_arg)
6637 : Item_temporal_with_ref(field_type_arg, decimals_arg, i, ref_arg, true) {
6638 }
6639 Item *clone_item() const override;
6640 longlong val_date_temporal() override { return val_int(); }
6641};
6642
6643/**
6644 This is used for segregating rows in groups (e.g. GROUP BY, windows), to
6645 detect boundaries of groups.
6646 It caches a value, which is representative of the group, and can compare it
6647 to another row, and update its value when entering a new group.
6648*/
6650 protected:
6651 Item *item; ///< The item whose value to cache.
6652 explicit Cached_item(Item *i) : item(i) {}
6653
6654 public:
6655 bool null_value{true};
6656 virtual ~Cached_item() = default;
6657 /**
6658 Compare the value associated with the item with the stored value.
6659 If they are different, update the stored value with item's value and
6660 return true.
6661
6662 @returns true if item's value and stored value are different.
6663 Notice that first call is to establish an initial value and
6664 return value should be ignored.
6665 */
6666 virtual bool cmp() = 0;
6667 Item *get_item() const { return item; }
6668 Item **get_item_ptr() { return &item; }
6669};
6670
6672 // Make sure value.ptr() is never nullptr, as not all collation functions
6673 // are prepared for that (even with empty strings).
6676
6677 public:
6678 explicit Cached_item_str(Item *arg) : Cached_item(arg) {}
6679 bool cmp() override;
6680};
6681
6682/// Cached_item subclass for JSON values.
6684 Json_wrapper *m_value; ///< The cached JSON value.
6685 public:
6686 explicit Cached_item_json(Item *item);
6687 ~Cached_item_json() override;
6688 bool cmp() override;
6689};
6690
6692 double value{0.0};
6693
6694 public:
6695 explicit Cached_item_real(Item *item_par) : Cached_item(item_par) {}
6696 bool cmp() override;
6697};
6698
6701
6702 public:
6703 explicit Cached_item_int(Item *item_par) : Cached_item(item_par) {}
6704 bool cmp() override;
6705};
6706
6708 public:
6709 explicit Cached_item_time(Item *item_par) : Cached_item(item_par) {}
6710 bool cmp() override;
6711
6712 private:
6714};
6715
6717 public:
6718 explicit Cached_item_date(Item *item_par) : Cached_item(item_par) {}
6719 bool cmp() override;
6720
6721 private:
6723};
6724
6727
6728 public:
6729 explicit Cached_item_temporal(Item *item_par) : Cached_item(item_par) {}
6730 bool cmp() override;
6731};
6732
6735
6736 public:
6737 explicit Cached_item_decimal(Item *item_par) : Cached_item(item_par) {}
6738 bool cmp() override;
6739};
6740
6741class Item_default_value final : public Item_field {
6743
6744 protected:
6746 bool no_conversions) override;
6747
6748 public:
6749 Item_default_value(const POS &pos, Item *a = nullptr)
6750 : super(pos, nullptr, nullptr, nullptr), arg(a) {}
6751 bool do_itemize(Parse_context *pc, Item **res) override;
6752 enum Type type() const override { return DEFAULT_VALUE_ITEM; }
6753 bool eq(const Item *item) const override;
6754 bool fix_fields(THD *, Item **) override;
6755 void bind_fields() override;
6756 void cleanup() override;
6757 void print(const THD *thd, String *str,
6758 enum_query_type query_type) const override;
6759 uint64_t hash() override;
6760 table_map used_tables() const override { return 0; }
6761 Item *get_tmp_table_item(THD *thd) override { return copy_or_same(thd); }
6763 Item *replace_item_field(uchar *) override;
6764
6765 /*
6766 No additional privilege check for default values, as the walk() function
6767 checks privileges for the underlying column through the argument.
6768 */
6769 bool check_column_privileges(uchar *) override { return false; }
6770
6771 bool walk(Item_processor processor, enum_walk walk, uchar *args) override {
6772 return ((walk & enum_walk::PREFIX) && (this->*processor)(args)) ||
6773 (arg && arg->walk(processor, walk, args)) ||
6774 ((walk & enum_walk::POSTFIX) && (this->*processor)(args));
6775 }
6776
6779 reinterpret_cast<char *>(args));
6780 }
6781
6782 Item *transform(Item_transformer transformer, uchar *args) override;
6783 Item *argument() const { return arg; }
6784
6785 private:
6786 /// The argument for this function
6788 /// Pointer to row buffer that was used to calculate field value offset
6790};
6791
6792/*
6793 Item_insert_value -- an implementation of VALUES() function.
6794 You can use the VALUES(col_name) function in the UPDATE clause
6795 to refer to column values from the INSERT portion of the INSERT
6796 ... UPDATE statement. In other words, VALUES(col_name) in the
6797 UPDATE clause refers to the value of col_name that would be
6798 inserted, had no duplicate-key conflict occurred.
6799 In all other places this function returns NULL.
6800*/
6801
6802class Item_insert_value final : public Item_field {
6803 protected:
6805 bool no_conversions) override {
6806 return Item_field::save_in_field_inner(field_arg, no_conversions);
6807 }
6808
6809 public:
6810 /**
6811 Constructs an Item_insert_value that represents a call to the deprecated
6812 VALUES function.
6813 */
6816 arg(a),
6817 m_is_values_function(true) {}
6818
6819 /**
6820 Constructs an Item_insert_value that represents a derived table that wraps a
6821 table value constructor.
6822 */
6824 : Item_field(context_arg, nullptr, nullptr, nullptr),
6825 arg(a),
6826 m_is_values_function(false) {}
6827
6828 bool do_itemize(Parse_context *pc, Item **res) override {
6829 if (skip_itemize(res)) return false;
6830 return Item_field::do_itemize(pc, res) || arg->itemize(pc, &arg);
6831 }
6832
6833 enum Type type() const override { return INSERT_VALUE_ITEM; }
6834 bool eq(const Item *item) const override;
6835 bool fix_fields(THD *, Item **) override;
6836 void bind_fields() override;
6837 void cleanup() override;
6838 void print(const THD *thd, String *str,
6839 enum_query_type query_type) const override;
6840 uint64_t hash() override;
6841 /*
6842 We use RAND_TABLE_BIT to prevent Item_insert_value from
6843 being treated as a constant and precalculated before execution
6844 */
6845 table_map used_tables() const override { return RAND_TABLE_BIT; }
6846
6847 bool walk(Item_processor processor, enum_walk walk, uchar *args) override {
6848 return ((walk & enum_walk::PREFIX) && (this->*processor)(args)) ||
6849 arg->walk(processor, walk, args) ||
6850 ((walk & enum_walk::POSTFIX) && (this->*processor)(args));
6851 }
6854 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6855 func_arg->banned_function_name = "values";
6856 return true;
6857 }
6858
6859 private:
6860 /// The argument for this function
6862 /// Pointer to row buffer that was used to calculate field value offset
6864 /**
6865 This flag is true if the item represents a call to the deprecated VALUES
6866 function. It is false if the item represents a derived table that wraps a
6867 table value constructor.
6868 */
6870};
6871
6872/**
6873 Represents NEW/OLD version of field of row which is
6874 changed/read in trigger.
6875
6876 Note: For this item main part of actual binding to Field object happens
6877 not during fix_fields() call (like for Item_field) but right after
6878 parsing of trigger definition, when table is opened, with special
6879 setup_field() call. On fix_fields() stage we simply choose one of
6880 two Field instances representing either OLD or NEW version of this
6881 field.
6882*/
6883class Item_trigger_field final : public Item_field,
6885 public:
6886 /* Is this item represents row from NEW or OLD row ? */
6888 /* Next in list of all Item_trigger_field's in trigger */
6890 /*
6891 Next list of Item_trigger_field's in "sp_head::
6892 m_list_of_trig_fields_item_lists".
6893 */
6895 /* Index of the field in the TABLE::field array */
6897 /* Pointer to an instance of Table_trigger_field_support interface */
6899
6901 enum_trigger_variable_type trigger_var_type_arg,
6902 const char *field_name_arg, Access_bitmask priv,
6903 const bool ro)
6904 : Item_field(context_arg, nullptr, nullptr, field_name_arg),
6905 trigger_var_type(trigger_var_type_arg),
6907 field_idx((uint)-1),
6908 want_privilege(priv),
6910 read_only(ro) {}
6912 enum_trigger_variable_type trigger_var_type_arg,
6913 const char *field_name_arg, Access_bitmask priv,
6914 const bool ro)
6915 : Item_field(pos, nullptr, nullptr, field_name_arg),
6916 trigger_var_type(trigger_var_type_arg),
6917 field_idx((uint)-1),
6918 want_privilege(priv),
6920 read_only(ro) {}
6921 void setup_field(Table_trigger_field_support *table_triggers,
6922 GRANT_INFO *table_grant_info);
6923 enum Type type() const override { return TRIGGER_FIELD_ITEM; }
6924 bool eq(const Item *item) const override;
6925 bool fix_fields(THD *, Item **) override;
6926 void bind_fields() override;
6927 bool check_column_privileges(uchar *arg) override;
6928 void print(const THD *thd, String *str,
6929 enum_query_type query_type) const override;
6930 table_map used_tables() const override { return INNER_TABLE_BIT; }
6931 Field *get_tmp_table_field() override { return nullptr; }
6932 Item *copy_or_same(THD *) override { return this; }
6933 Item *get_tmp_table_item(THD *thd) override { return copy_or_same(thd); }
6934 void cleanup() override;
6935 void set_required_privilege(Access_bitmask privilege) override {
6936 want_privilege = privilege;
6937 }
6938
6941 pointer_cast<Check_function_as_value_generator_parameters *>(args);
6942 func_arg->err_code = func_arg->get_unnamed_function_error_code();
6943 return true;
6944 }
6945
6946 bool is_valid_for_pushdown(uchar *args [[maybe_unused]]) override {
6947 return true;
6948 }
6949
6950 private:
6951 bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override;
6952
6953 public:
6955 return (read_only ? nullptr : this);
6956 }
6957
6958 bool set_value(THD *thd, Item **it) {
6959 const bool ret = set_value(thd, nullptr, it);
6960 if (!ret)
6962 field_idx);
6963 return ret;
6964 }
6965
6966 private:
6967 /*
6968 'want_privilege' holds privileges required to perform operation on
6969 this trigger field (SELECT_ACL if we are going to read it and
6970 UPDATE_ACL if we are going to update it). It is initialized at
6971 parse time but can be updated later if this trigger field is used
6972 as OUT or INOUT parameter of stored routine (in this case
6973 set_required_privilege() is called to appropriately update
6974 want_privilege).
6975 */
6978 /*
6979 Trigger field is read-only unless it belongs to the NEW row in a
6980 BEFORE INSERT of BEFORE UPDATE trigger.
6981 */
6983};
6984
6986 protected:
6987 Item *example{nullptr};
6989 /**
6990 Field that this object will get value from. This is used by
6991 index-based subquery engines to detect and remove the equality injected
6992 by IN->EXISTS transformation.
6993 */
6995 /*
6996 true <=> cache holds value of the last stored item (i.e actual value).
6997 store() stores item to be cached and sets this flag to false.
6998 On the first call of val_xxx function if this flag is set to false the
6999 cache_value() will be called to actually cache value of saved item.
7000 cache_value() will set this flag to true.
7001 */
7002 bool value_cached{false};
7003
7004 friend bool has_rollup_result(Item *item);
7006 THD *thd, Query_block *select, Item *item_arg);
7007
7008 public:
7010 fixed = true;
7011 set_nullable(true);
7012 null_value = true;
7013 }
7015 set_data_type(field_type_arg);
7016 fixed = true;
7017 set_nullable(true);
7018 null_value = true;
7019 }
7020
7021 void fix_after_pullout(Query_block *parent_query_block,
7022 Query_block *removed_query_block) override {
7023 if (example == nullptr) return;
7024 example->fix_after_pullout(parent_query_block, removed_query_block);
7026 }
7027
7028 virtual bool allocate(uint) { return false; }
7029 virtual bool setup(Item *item) {
7030 example = item;
7031 max_length = item->max_length;
7032 decimals = item->decimals;
7033 collation.set(item->collation);
7036 if (item->type() == FIELD_ITEM) {
7037 cached_field = down_cast<Item_field *>(item);
7038 if (cached_field->m_table_ref != nullptr)
7040 } else {
7041 used_table_map = item->used_tables();
7042 }
7043 return false;
7044 }
7045 enum Type type() const override { return CACHE_ITEM; }
7046 static Item_cache *get_cache(const Item *item);
7047 static Item_cache *get_cache(const Item *item, const Item_result type);
7048 table_map used_tables() const override { return used_table_map; }
7049 void print(const THD *thd, String *str,
7050 enum_query_type query_type) const override;
7051 uint64_t hash() override;
7052 bool eq_def(const Field *field) {
7053 return cached_field != nullptr && cached_field->field->eq_def(field);
7054 }
7055 bool eq(const Item *item) const override { return this == item; }
7056 /**
7057 Check if saved item has a non-NULL value.
7058 Will cache value of saved item if not already done.
7059 @return true if cached value is non-NULL.
7060 */
7061 bool has_value();
7062
7063 /**
7064 If this item caches a field value, return pointer to underlying field.
7065
7066 @return Pointer to field, or NULL if this is not a cache for a field value.
7067 */
7069
7070 /**
7071 Assigns to the cache the expression to be cached. Does not evaluate it.
7072 @param item the expression to be cached
7073 */
7074 virtual void store(Item *item);
7075
7076 /**
7077 Force an item to be null. Used for empty subqueries to avoid attempts to
7078 evaluate expressions which could have uninitialized columns due to
7079 bypassing the subquery exec.
7080 */
7081 void store_null() {
7082 assert(is_nullable());
7083 value_cached = true;
7084 null_value = true;
7085 }
7086
7087 virtual bool cache_value() = 0;
7088 bool store_and_cache(Item *item) {
7089 store(item);
7090 return cache_value();
7091 }
7092 void cleanup() override;
7093 bool basic_const_item() const override {
7094 return (example != nullptr && example->basic_const_item());
7095 }
7096 bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
7097 virtual void clear() {
7098 null_value = true;
7099 value_cached = false;
7100 }
7101 bool is_null() override {
7102 return value_cached ? null_value : example->is_null();
7103 }
7104 bool is_non_const_over_literals(uchar *) override { return true; }
7107 pointer_cast<Check_function_as_value_generator_parameters *>(args);
7108 func_arg->banned_function_name = "cached item";
7109 // This should not happen as SELECT statements are not allowed.
7110 assert(false);
7111 return true;
7112 }
7113 Item_result result_type() const override {
7114 if (!example) return INT_RESULT;
7116 }
7117 Item *get_example() const { return example; }
7119};
7120
7122 public:
7125 : Item_cache(field_type_arg), value(0) {}
7126
7127 /**
7128 Unlike store(), this stores an explicitly provided value, not the one of
7129 'item'; however, NULLness is still taken from 'item'.
7130 */
7131 void store_value(Item *item, longlong val_arg);
7132 double val_real() override;
7133 longlong val_int() override;
7134 longlong val_date_temporal() override { return val_int(); }
7135 String *val_str(String *str) override;
7136 my_decimal *val_decimal(my_decimal *) override;
7137 bool val_date(Date_val *date, my_time_flags_t flags) override {
7138 return get_date_from_int(date, flags);
7139 }
7140 bool val_time(Time_val *time) override { return get_time_from_int(time); }
7142 return get_datetime_from_int(dt, flags);
7143 }
7144 Item_result result_type() const override { return INT_RESULT; }
7145 bool cache_value() override;
7146
7147 protected:
7149};
7150
7151/**
7152 Cache class for BIT type expressions. The BIT data type behaves like unsigned
7153 integer numbers in all situations, except when formatted as a string, where
7154 it is directly interpreted as a byte string, possibly right-extended with
7155 zero-bits.
7156*/
7157class Item_cache_bit final : public Item_cache_int {
7158 public:
7160 : Item_cache_int(field_type_arg) {
7161 assert(field_type_arg == MYSQL_TYPE_BIT);
7162 }
7163
7164 /**
7165 Transform the result Item_cache_int::value in bit format. The process is
7166 similar to Field_bit_as_char::store().
7167 */
7168 String *val_str(String *str) override;
7169 uint string_length() { return ((max_length + 7) / 8); }
7170};
7171
7172class Item_cache_real final : public Item_cache {
7173 public:
7175
7176 double val_real() override;
7177 longlong val_int() override;
7178 String *val_str(String *str) override;
7179 my_decimal *val_decimal(my_decimal *) override;
7180 bool val_date(Date_val *date, my_time_flags_t flags) override {
7181 return get_date_from_real(date, flags);
7182 }
7183 bool val_time(Time_val *time) override { return get_time_from_real(time); }
7185 return get_datetime_from_real(dt, flags);
7186 }
7187 Item_result result_type() const override { return REAL_RESULT; }
7188 bool cache_value() override;
7189 void store_value(Item *expr, double value);
7190
7191 private:
7192 double value{0};
7193};
7194
7195class Item_cache_decimal final : public Item_cache {
7196 public:
7198
7199 double val_real() override;
7200 longlong val_int() override;
7201 String *val_str(String *str) override;
7202 my_decimal *val_decimal(my_decimal *) override;
7203 bool val_date(Date_val *date, my_time_flags_t flags) override {
7204 return get_date_from_decimal(date, flags);
7205 }
7206 bool val_time(Time_val *time) override { return get_time_from_decimal(time); }
7208 return get_datetime_from_decimal(dt, flags);
7209 }
7210 Item_result result_type() const override { return DECIMAL_RESULT; }
7211 bool cache_value() override;
7212 void store_value(Item *expr, my_decimal *d);
7213
7214 private:
7216};
7217
7218class Item_cache_str final : public Item_cache {
7222
7223 protected:
7225 bool no_conversions) override;
7226
7227 public:
7229 : Item_cache(item->data_type()),
7230 value(nullptr),
7231 is_varbinary(item->type() == FIELD_ITEM &&
7233 !((const Item_field *)item)->field->has_charset()) {
7234 collation.set(item->collation);
7235 }
7236 double val_real() override;
7237 longlong val_int() override;
7238 String *val_str(String *) override;
7239 my_decimal *val_decimal(my_decimal *) override;
7240 bool val_date(Date_val *date, my_time_flags_t flags) override {
7241 return get_date_from_string(date, flags);
7242 }
7243 bool val_time(Time_val *time) override { return get_time_from_string(time); }
7245 return get_datetime_from_string(dt, flags);
7246 }
7247 Item_result result_type() const override { return STRING_RESULT; }
7248 const CHARSET_INFO *charset() const { return value->charset(); }
7249 bool cache_value() override;
7250 void store_value(Item *expr, String &s);
7251};
7252
7253class Item_cache_row final : public Item_cache {
7254 public:
7256
7257 /**
7258 'allocate' is only used in Item_cache_row::setup()
7259 */
7260 bool allocate(uint num) override;
7261 /*
7262 'setup' is needed only by row => it not called by simple row subselect
7263 (only by IN subselect (in subselect optimizer))
7264 */
7265 bool setup(Item *item) override;
7266 void store(Item *item) override;
7267 void illegal_method_call(const char *) const MY_ATTRIBUTE((cold));
7268 void make_field(Send_field *) override { illegal_method_call("make_field"); }
7269 double val_real() override {
7270 illegal_method_call("val_real");
7271 return 0;
7272 }
7273 longlong val_int() override {
7274 illegal_method_call("val_int");
7275 return 0;
7276 }
7277 String *val_str(String *) override {
7278 illegal_method_call("val_str");
7279 return nullptr;
7280 }
7282 illegal_method_call("val_decimal");
7283 return nullptr;
7284 }
7286 illegal_method_call("val_date");
7287 return true;
7288 }
7289 bool val_time(Time_val *) override {
7290 illegal_method_call("val_time");
7291 return true;
7292 }
7294 illegal_method_call("val_datetime");
7295 return true;
7296 }
7297 Item_result result_type() const override { return ROW_RESULT; }
7298
7299 uint cols() const override { return item_count; }
7300 Item *element_index(uint i) override { return values[i]; }
7301 Item **addr(uint i) override { return (Item **)(values + i); }
7302 bool check_cols(uint c) override;
7303 bool null_inside() override;
7304 void bring_value() override;
7305 void cleanup() override { Item_cache::cleanup(); }
7306 bool cache_value() override;
7307
7308 private:
7309 Item_cache **values{nullptr};
7310 uint item_count{2};
7311};
7312
7314 public:
7317 }
7318
7319 void store(Item *item) override;
7320 double val_real() override;
7321 longlong val_int() override;
7322 longlong val_date_temporal() override;
7323 String *val_str(String *str) override;
7324 my_decimal *val_decimal(my_decimal *) override;
7325 bool val_date(Date_val *date, my_time_flags_t flags) override;
7326 bool val_time(Time_val *time) override;
7327 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7328 Item_result result_type() const override { return STRING_RESULT; }
7329 bool cache_value() override;
7330 /**
7331 Cache a single non-NULL time value. Requires that "example" is not set.
7332
7333 @param time Time value to cache
7334 */
7335 void store_value(Time_val time);
7336
7337 private:
7339};
7340
7342 public:
7345 }
7346
7347 void store(Item *item) override;
7348 double val_real() override;
7349 longlong val_int() override;
7350 longlong val_date_temporal() override;
7351 String *val_str(String *str) override;
7352 my_decimal *val_decimal(my_decimal *) override;
7353 bool val_date(Date_val *date, my_time_flags_t flags) override;
7354 bool val_time(Time_val *time) override;
7355 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7356 Item_result result_type() const override { return STRING_RESULT; }
7357 bool cache_value() override;
7358 /**
7359 Cache a single non-NULL date value. Requires that "example" is not set.
7360
7361 @param date Date value to cache
7362 */
7363 void store_value(Date_val date);
7364
7365 private:
7367};
7368
7370 public:
7372 : Item_cache(field_type_arg), int_value(0), str_value_cached(false) {
7373 assert(field_type_arg != MYSQL_TYPE_TIME &&
7374 field_type_arg != MYSQL_TYPE_DATE);
7376 }
7377
7378 void store_value(Item *item, longlong val_arg);
7379 void store(Item *item) override;
7380 double val_real() override;
7381 longlong val_int() override;
7382 longlong val_date_temporal() override;
7383 String *val_str(String *str) override;
7384 my_decimal *val_decimal(my_decimal *) override;
7385 bool val_date(Date_val *date, my_time_flags_t flags) override;
7386 bool val_time(Time_val *time) override;
7387 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7388 Item_result result_type() const override { return STRING_RESULT; }
7389 /*
7390 In order to avoid INT <-> STRING conversion of a DATETIME value
7391 two cache_value functions are introduced. One (cache_value) caches STRING
7392 value, another (cache_value_int) - INT value. Thus this cache item
7393 completely relies on the ability of the underlying item to do the
7394 correct conversion.
7395 */
7396 bool cache_value_int();
7397 bool cache_value() override;
7398 void clear() override {
7400 str_value_cached = false;
7401 }
7402
7403 private:
7404 /// Used for DATETIME values
7406 /// Used when required in a string context
7408 /// If true, cached_string contains a valid value
7409 bool str_value_cached{false};
7410};
7411
7412/// An item cache for values of type JSON.
7414 /// Cached value
7416 /// Whether the cached value is array and it is sorted
7418
7419 public:
7421 ~Item_cache_json() override;
7422 bool cache_value() override;
7423 void store_value(Item *expr, Json_wrapper *wr);
7424 bool val_json(Json_wrapper *wr) override;
7425 longlong val_int() override;
7426 String *val_str(String *str) override;
7427 Item_result result_type() const override { return STRING_RESULT; }
7428
7429 double val_real() override;
7430 my_decimal *val_decimal(my_decimal *val) override;
7431 bool val_date(Date_val *date, my_time_flags_t flags) override;
7432 bool val_time(Time_val *time) override;
7433 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7434 /// Sort cached data. Only arrays are affected.
7435 void sort();
7436 /// Returns true when cached value is array and it's sorted
7437 bool is_sorted() { return m_is_sorted; }
7438};
7439
7440/**
7441 Interface for storing an aggregation of type and type specification of
7442 multiple Item objects.
7443
7444 This is useful for cases where a field is an amalgamation of multiple types,
7445 such as in UNION where type conversions must be done to a common denominator.
7446*/
7448 protected:
7449 /// Typelib information, only used for data type ENUM and SET.
7451 /// Geometry type, only used for data type GEOMETRY.
7453
7454 void set_typelib(Item *item);
7455
7456 public:
7458
7459 double val_real() override = 0;
7460 longlong val_int() override = 0;
7462 String *val_str(String *) override = 0;
7463 bool val_date(Date_val *, my_time_flags_t) override = 0;
7464 bool val_time(Time_val *time) override = 0;
7466 Item_result result_type() const override;
7467 bool unify_types(Item *item);
7468 bool unify_types(const char *op_string, Item **items, size_t count);
7469 Field *make_field_by_type(TABLE *table, bool strict);
7470 static uint32 display_length(Item *item);
7472 return geometry_type;
7473 }
7474 void make_field(Send_field *field) override {
7475 Item::make_field(field);
7476 // Item_type_holder is used for unions and effectively sends Fields
7477 field->field = true;
7478 }
7481 pointer_cast<Check_function_as_value_generator_parameters *>(args);
7482 func_arg->err_code = func_arg->get_unnamed_function_error_code();
7483 return true;
7484 }
7485};
7486
7487/**
7488 Item_type_holder stores an aggregation of name, type and type specification of
7489 UNIONS and derived tables.
7490*/
7493
7494 public:
7495 /// @todo Consider giving Item_type_holder objects default names from the item
7496 /// they are initialized by. This would ensure that
7497 /// Query_expression::get_unit_column_types() always contains named items.
7498 Item_type_holder(THD *thd, Item *item) : super(thd, item) {}
7499
7500 enum Type type() const override { return TYPE_HOLDER_ITEM; }
7501
7502 /**
7503 Class is used in type aggregation only - this is needed to ensure
7504 that it is not attempted to be evaluated as a const value.
7505 */
7506 table_map used_tables() const override { return RAND_TABLE_BIT; }
7507
7508 double val_real() override;
7509 longlong val_int() override;
7510 my_decimal *val_decimal(my_decimal *) override;
7511 String *val_str(String *) override;
7512 bool val_date(Date_val *date, my_time_flags_t flags) override;
7513 bool val_time(Time_val *time) override;
7514 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7515};
7516
7517/**
7518 Reference item that encapsulates both the type and the contained items of a
7519 single column of a VALUES ROW query expression.
7520
7521 During execution, the item that will be output for the current iteration is
7522 contained in m_value_ref. The type of the column and the referenced item may
7523 differ in cases where a column of a VALUES clause contains different types
7524 across different rows, and must therefore do type conversions to their common
7525 denominator (e.g. a column containing both 10 and "10", of which the types
7526 will be aggregated into VARCHAR).
7527
7528 See the class comment for TableValueConstructorIterator for info on how
7529 Item_values_column is used as an indirection to iterate over the rows of a
7530 table value constructor (i.e. VALUES ROW expressions).
7531*/
7534
7535 private:
7537 /*
7538 Even if a table value constructor contains only constant values, we
7539 still need to identify individual rows within it. Set RAND_TABLE_BIT
7540 to ensure that all rows are scanned, and that the whole VALUES clause
7541 is never substituted with a const value or row.
7542 */
7544
7546 bool no_conversions) override;
7547
7548 public:
7550
7551 bool eq(const Item *item) const override;
7552 double val_real() override;
7553 longlong val_int() override;
7554 my_decimal *val_decimal(my_decimal *) override;
7555 bool val_bool() override;
7556 String *val_str(String *tmp) override;
7557 bool val_json(Json_wrapper *result) override;
7558 bool is_null() override;
7559 bool val_date(Date_val *date, my_time_flags_t flags) override;
7560 bool val_time(Time_val *time) override;
7561 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7562 enum Type type() const override { return VALUES_COLUMN_ITEM; }
7563 void set_value(Item *new_value) { m_value_ref = new_value; }
7565 void add_used_tables(Item *value);
7566};
7567
7568/// A class that represents a constant JSON value.
7569class Item_json final : public Item_basic_constant {
7571
7572 public:
7574 const Item_name_string &name);
7575 ~Item_json() override;
7576 enum Type type() const override { return JSON_ITEM; }
7577 void print(const THD *, String *str, enum_query_type) const override;
7578 uint64_t hash() override;
7579 bool val_json(Json_wrapper *result) override;
7580 Item_result result_type() const override { return STRING_RESULT; }
7581 double val_real() override;
7582 longlong val_int() override;
7583 String *val_str(String *str) override;
7585 bool val_date(Date_val *date, my_time_flags_t flags) override;
7586 bool val_time(Time_val *time) override;
7587 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override;
7588 Item *clone_item() const override;
7589};
7590
7591extern Cached_item *new_Cached_item(THD *thd, Item *item);
7593extern bool resolve_const_item(THD *thd, Item **ref, Item *cmp_item);
7594extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item);
7595extern bool is_null_on_empty_table(THD *thd, Item_field *i);
7596
7597extern const String my_null_string;
7598void convert_and_print(const String *from_str, String *to_str,
7599 const CHARSET_INFO *to_cs);
7600
7601std::string ItemToString(const Item *item, enum_query_type q_type);
7602std::string ItemToString(const Item *item);
7603
7604std::string ItemToQuerySubstrNoCharLimit(const Item *item);
7605std::string ItemToQuerySubstr(
7606 const Item *item, const LEX *lex = nullptr,
7608
7609inline size_t CountVisibleFields(const mem_root_deque<Item *> &fields) {
7610 return std::count_if(fields.begin(), fields.end(),
7611 [](Item *item) { return !item->hidden; });
7612}
7613
7614inline size_t CountHiddenFields(const mem_root_deque<Item *> &fields) {
7615 return std::count_if(fields.begin(), fields.end(),
7616 [](Item *item) { return item->hidden; });
7617}
7618
7620 size_t index) {
7621 for (Item *item : fields) {
7622 if (item->hidden) continue;
7623 if (index-- == 0) return item;
7624 }
7625 assert(false);
7626 return nullptr;
7627}
7628
7629/**
7630 Returns true iff the two items are equal, as in a->eq(b),
7631 after unwrapping refs and Item_cache objects.
7632 */
7633bool ItemsAreEqual(const Item *a, const Item *b);
7634
7635/**
7636 Returns true iff all items in the two arrays (which must be of the same size)
7637 are equal, as in a->eq(b), after unwrapping refs and Item_cache objects.
7638 */
7639bool AllItemsAreEqual(const Item *const *a, const Item *const *b,
7640 int num_items);
7641
7642#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:591
value
Definition: item.h:605
@ v_UNKNOWN
Definition: item.h:605
@ v_FALSE
Definition: item.h:605
@ v_TRUE
Definition: item.h:605
Bool3(value v)
This is private; instead, use false3()/etc.
Definition: item.h:607
static const Bool3 true3()
Definition: item.h:598
static const Bool3 unknown3()
Definition: item.h:596
static const Bool3 false3()
Definition: item.h:594
bool is_true() const
Definition: item.h:600
value m_val
Definition: item.h:609
bool is_unknown() const
Definition: item.h:601
bool is_false() const
Definition: item.h:602
Definition: item.h:6716
Cached_item_date(Item *item_par)
Definition: item.h:6718
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:195
Date_val m_date
Definition: item.h:6722
Definition: item.h:6733
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:239
Cached_item_decimal(Item *item_par)
Definition: item.h:6737
my_decimal value
Definition: item.h:6734
Definition: item.h:6699
longlong value
Definition: item.h:6700
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:161
Cached_item_int(Item *item_par)
Definition: item.h:6703
Cached_item subclass for JSON values.
Definition: item.h:6683
Json_wrapper * m_value
The cached JSON value.
Definition: item.h:6684
~Cached_item_json() override
Definition: item_buff.cc:107
Cached_item_json(Item *item)
Definition: item_buff.cc:104
bool cmp() override
Compare the new JSON value in member 'item' with the previous value.
Definition: item_buff.cc:117
Definition: item.h:6691
Cached_item_real(Item *item_par)
Definition: item.h:6695
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:145
double value
Definition: item.h:6692
Definition: item.h:6671
String tmp_value
Definition: item.h:6675
Cached_item_str(Item *arg)
Definition: item.h:6678
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:84
String value
Definition: item.h:6674
Definition: item.h:6725
Cached_item_temporal(Item *item_par)
Definition: item.h:6729
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:212
longlong value
Definition: item.h:6726
Definition: item.h:6707
Cached_item_time(Item *item_par)
Definition: item.h:6709
bool cmp() override
Compare the value associated with the item with the stored value.
Definition: item_buff.cc:178
Time_val m_time
Definition: item.h:6713
This is used for segregating rows in groups (e.g.
Definition: item.h:6649
Item ** get_item_ptr()
Definition: item.h:6668
Item * item
The item whose value to cache.
Definition: item.h:6651
virtual ~Cached_item()=default
Item * get_item() const
Definition: item.h:6667
virtual bool cmp()=0
Compare the value associated with the item with the stored value.
Cached_item(Item *i)
Definition: item.h:6652
bool null_value
Definition: item.h:6655
This class represents the cost of evaluating an Item.
Definition: item.h:790
bool m_is_expensive
True if the associated Item calls user defined functions or stored procedures.
Definition: item.h:845
double FieldCost() const
Get the cost of field access when evaluating the Item associated with this object.
Definition: item.h:827
uint8 m_other_fields
The number of other Field objects accessed by the associated Item.
Definition: item.h:851
void Compute(const Item &item)
Set '*this' to represent the cost of 'item'.
Definition: item.h:793
static constexpr double kStrFieldCost
The cost of accessing a Field_str, relative to other Field types.
Definition: item.h:835
uint8 m_str_fields
The number of Field_str objects accessed by the associated Item.
Definition: item.h:848
bool IsExpensive() const
Definition: item.h:816
void AddFieldCost()
Add the cost of accessing any other Field.
Definition: item.h:811
bool m_computed
True if 'ComputeInternal()' has been called.
Definition: item.h:841
void ComputeInternal(const Item &root)
Compute the cost of 'root' and its descendants.
Definition: item.cc:139
static constexpr double kOtherFieldCost
The cost of accessing a Field other than Field_str. 1.0 by definition.
Definition: item.h:838
void AddStrFieldCost()
Add the cost of accessing a Field_str.
Definition: item.h:805
void MarkExpensive()
Definition: item.h:799
Definition: item.h:184
void set(Derivation derivation_arg)
Definition: item.h:229
DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
Definition: item.h:199
void set_repertoire_from_charset(const CHARSET_INFO *cs)
Definition: item.h:190
bool aggregate(DTCollation &dt, uint flags=0)
Aggregate two collations together taking into account their coercibility (aka derivation).
Definition: item.cc:2734
void set(const DTCollation &dt)
Definition: item.h:204
DTCollation()
Definition: item.h:194
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg, uint repertoire_arg)
Definition: item.h:214
bool set(DTCollation &dt1, DTCollation &dt2, uint flags=0)
Definition: item.h:232
void set_numeric()
Definition: item.h:220
void set_repertoire(uint repertoire_arg)
Definition: item.h:230
const CHARSET_INFO * collation
Definition: item.h:186
Derivation derivation
Definition: item.h:187
const char * derivation_name() const
Definition: item.h:236
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
Definition: item.h:209
uint repertoire
Definition: item.h:188
void set(const CHARSET_INFO *collation_arg)
Definition: item.h:225
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
int32_t for_comparison() const
Definition: my_temporal.h:461
Definition: my_temporal.h:341
A field that stores a JSON value.
Definition: field.h:3908
Definition: field.h:573
const CHARSET_INFO * charset_for_protocol() const
Definition: field.h:1619
virtual Item_result cast_to_int_type() const
Definition: field.h:1038
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:1826
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:1403
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:1218
virtual my_decimal * val_decimal(my_decimal *) const =0
bool is_tmp_nullable() const
Definition: field.h:924
virtual double val_real() const =0
virtual bool val_date(Date_val *date, my_time_flags_t flags) const
Retrieve field value and return the result as a date.
Definition: field.cc:2304
virtual longlong val_int() const =0
virtual Item_result numeric_context_result_type() const
Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + ...
Definition: field.h:1034
virtual bool eq_def(const Field *field) const
Definition: field.cc:8519
geometry_type
Definition: field.h:716
@ GEOM_GEOMETRY
Definition: field.h:717
virtual bool val_time(Time_val *time) const
Retrieve field value and return the result as a time.
Definition: field.cc:2320
virtual Item_result result_type() const =0
bool is_nullable() const
Definition: field.h:1291
virtual bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const
Retrieve field value and return the result as a datetime/timestamp.
Definition: field.cc:2312
virtual geometry_type get_geometry_type() const
Definition: field.h:1702
static Item_result result_merge_type(enum_field_types)
Detect Item_result by given field type of UNION merge result.
Definition: field.cc:1522
String * val_str(String *str) const
Definition: field.h:1003
bool is_field_for_functional_index() const
Definition: field.h:890
static constexpr size_t MAX_MEDIUM_BLOB_WIDTH
Definition: field.h:734
void dbug_print() const
Definition: field.h:1709
Context object for (functions that override) Item::clean_up_after_removal().
Definition: item.h:2985
Query_block *const m_root
Pointer to Cleanup_after_removal_context containing from which select the walk started,...
Definition: item.h:2999
Cleanup_after_removal_context(Query_block *root)
Definition: item.h:2987
Query_block * get_root()
Definition: item.h:2991
Definition: item.h:2835
List< Item > * m_items
Definition: item.h:2837
Collect_item_fields_or_refs(List< Item > *fields_or_refs)
Definition: item.h:2838
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:2852
List< Item > * m_item_fields_or_view_refs
Definition: item.h:2851
Collect_item_fields_or_view_refs(List< Item > *fields_or_vr, Query_block *transformed_block)
Definition: item.h:2856
uint m_any_value_level
Used to compute Item_field's m_protected_by_any_value.
Definition: item.h:2855
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:7447
longlong val_int() override=0
Item_result result_type() const override
Return expression type of Item_aggregate_type.
Definition: item.cc:11145
bool val_date(Date_val *, my_time_flags_t) override=0
Evaluate the item and return result as a date value.
my_decimal * val_decimal(my_decimal *) override=0
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override=0
Evaluate the item and return result as a datetime value.
void set_typelib(Item *item)
Set typelib information for an aggregated enum/set field.
Definition: item.cc:11418
Item_aggregate_type(THD *, Item *)
Definition: item.cc:11126
String * val_str(String *) override=0
bool check_function_as_value_generator(uchar *args) override
Check if this item is allowed for a virtual column or inside a default expression.
Definition: item.h:7479
static uint32 display_length(Item *item)
Calculate length for merging result for given Item type.
Definition: item.cc:11300
bool val_time(Time_val *time) override=0
Evaluate the item and return result as a time value.
void make_field(Send_field *field) override
Definition: item.h:7474
Field * make_field_by_type(TABLE *table, bool strict)
Make temporary table field according collected information about type of UNION result.
Definition: item.cc:11363
double val_real() override=0
Field::geometry_type get_geometry_type() const override
Definition: item.h:7471
TYPELIB * m_typelib
Typelib information, only used for data type ENUM and SET.
Definition: item.h:7450
bool unify_types(Item *item)
Unify type from given item with the type in the current item.
Definition: item.cc:11259
Field::geometry_type geometry_type
Geometry type, only used for data type GEOMETRY.
Definition: item.h:7452
Represents [schema.
Definition: item.h:4854
bool is_asterisk() const override
Checks if the current object represents an asterisk select list item.
Definition: item.h:4874
Item_asterisk(const POS &pos, const char *opt_schema_name, const char *opt_table_name)
Constructor.
Definition: item.h:4865
Item_field super
Definition: item.h:4855
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.h:4870
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:11856
Definition: item.h:3972
Item_basic_constant(const POS &pos)
Definition: item.h:3977
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:3986
void set_str_value(String *str)
Note that str_value.ptr() will now point to a string owned by some other object.
Definition: item.h:3998
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:3993
void set_used_tables(table_map map)
Definition: item.h:3982
table_map used_table_map
Definition: item.h:3973
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:3984
Item_basic_constant()
Definition: item.h:3976
table_map used_tables() const override
Definition: item.h:3983
Definition: item.h:5986
Item_bin_string(const char *str, size_t str_length)
Definition: item.h:5990
void bin_string_init(const char *str, size_t str_length)
Definition: item.cc:7834
static LEX_CSTRING make_bin_str(const char *str, size_t str_length)
Definition: item.cc:7804
Item_hex_string super
Definition: item.h:5987
Item_bin_string(const POS &pos, const LEX_STRING &literal)
Definition: item.h:5993
Definition: item.h:5889
Item_blob(const char *name, size_t length)
Definition: item.h:5891
enum Type type() const override
Definition: item.h:5896
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:5897
Cache class for BIT type expressions.
Definition: item.h:7157
Item_cache_bit(enum_field_types field_type_arg)
Definition: item.h:7159
uint string_length()
Definition: item.h:7169
String * val_str(String *str) override
Transform the result Item_cache_int::value in bit format.
Definition: item.cc:10371
Definition: item.h:7341
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10498
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10547
bool cache_value() override
Definition: item.cc:10468
double val_real() override
Definition: item.cc:10543
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10507
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10500
String * val_str(String *str) override
Definition: item.cc:10484
Date_val m_date
Definition: item.h:7366
Item_cache_date()
Definition: item.h:7343
Item_result result_type() const override
Definition: item.h:7356
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10531
longlong val_int() override
Definition: item.cc:10541
void store_value(Date_val date)
Cache a single non-NULL date value.
Definition: item.cc:10477
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10519
Definition: item.h:7369
longlong val_int() override
Definition: item.cc:10724
longlong int_value
Used for DATETIME values.
Definition: item.h:7405
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10715
bool cache_value() override
Definition: item.cc:10572
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10631
void store_value(Item *item, longlong val_arg)
Definition: item.cc:10589
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10688
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10650
String * val_str(String *str) override
Definition: item.cc:10602
bool str_value_cached
If true, cached_string contains a valid value.
Definition: item.h:7409
Item_result result_type() const override
Definition: item.h:7388
void clear() override
Definition: item.h:7398
String cached_string
Used when required in a string context.
Definition: item.h:7407
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10597
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10658
bool cache_value_int()
Definition: item.cc:10556
Item_cache_datetime(enum_field_types field_type_arg)
Definition: item.h:7371
double val_real() override
Definition: item.cc:10713
Definition: item.h:7195
double val_real() override
Definition: item.cc:10923
my_decimal decimal_value
Definition: item.h:7215
bool cache_value() override
Definition: item.cc:10899
longlong val_int() override
Definition: item.cc:10931
Item_cache_decimal()
Definition: item.h:7197
String * val_str(String *str) override
Definition: item.cc:10939
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7203
void store_value(Item *expr, my_decimal *d)
Definition: item.cc:10916
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10948
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7207
Item_result result_type() const override
Definition: item.h:7210
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7206
Definition: item.h:7121
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7140
double val_real() override
Definition: item.cc:10358
longlong val_int() override
Definition: item.cc:10365
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7137
longlong value
Definition: item.h:7148
Item_cache_int(enum_field_types field_type_arg)
Definition: item.h:7124
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:7134
Item_result result_type() const override
Definition: item.h:7144
Item_cache_int()
Definition: item.h:7123
bool cache_value() override
Definition: item.cc:10327
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10351
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:10336
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7141
String * val_str(String *str) override
Definition: item.cc:10344
An item cache for values of type JSON.
Definition: item.h:7413
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10807
Item_result result_type() const override
Definition: item.h:7427
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10831
my_decimal * val_decimal(my_decimal *val) override
Definition: item.cc:10797
bool m_is_sorted
Whether the cached value is array and it is sorted.
Definition: item.h:7417
Json_wrapper * m_value
Cached value.
Definition: item.h:7415
bool cache_value() override
Read the JSON value and cache it.
Definition: item.cc:10739
Item_cache_json()
Definition: item.cc:10726
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10819
~Item_cache_json() override
Definition: item.cc:10731
bool val_json(Json_wrapper *wr) override
Copy the cached JSON value into a wrapper.
Definition: item.cc:10772
bool is_sorted()
Returns true when cached value is array and it's sorted.
Definition: item.h:7437
void store_value(Item *expr, Json_wrapper *wr)
Definition: item.cc:10756
double val_real() override
Definition: item.cc:10787
String * val_str(String *str) override
Definition: item.cc:10777
void sort()
Sort cached data. Only arrays are affected.
Definition: item.cc:10851
longlong val_int() override
Definition: item.cc:10842
Definition: item.h:7172
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7180
Item_cache_real()
Definition: item.h:7174
void store_value(Item *expr, double value)
Definition: item.cc:10867
double value
Definition: item.h:7192
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7183
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7184
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10892
bool cache_value() override
Definition: item.cc:10859
Item_result result_type() const override
Definition: item.h:7187
double val_real() override
Definition: item.cc:10873
String * val_str(String *str) override
Definition: item.cc:10885
longlong val_int() override
Definition: item.cc:10879
Definition: item.h:7253
Item * element_index(uint i) override
Definition: item.h:7300
longlong val_int() override
Definition: item.h:7273
bool val_datetime(Datetime_val *, my_time_flags_t) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7293
double val_real() override
Definition: item.h:7269
bool null_inside() override
Definition: item.cc:11108
Item_result result_type() const override
Definition: item.h:7297
Item ** addr(uint i) override
Definition: item.h:7301
bool allocate(uint num) override
'allocate' is only used in Item_cache_row::setup()
Definition: item.cc:11038
Item_cache_row()
Definition: item.h:7255
void bring_value() override
Definition: item.cc:11119
my_decimal * val_decimal(my_decimal *) override
Definition: item.h:7281
void make_field(Send_field *) override
Definition: item.h:7268
void illegal_method_call(const char *) const
Definition: item.cc:11092
uint item_count
Definition: item.h:7310
bool check_cols(uint c) override
Definition: item.cc:11100
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:7285
bool cache_value() override
Definition: item.cc:11069
uint cols() const override
Definition: item.h:7299
bool setup(Item *item) override
Definition: item.cc:11045
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:11058
bool val_time(Time_val *) override
Evaluate the item and return result as a time value.
Definition: item.h:7289
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.h:7305
Item_cache ** values
Definition: item.h:7309
String * val_str(String *) override
Definition: item.h:7277
Definition: item.h:7218
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:11024
bool cache_value() override
Definition: item.cc:10954
Item_result result_type() const override
Definition: item.h:7247
void store_value(Item *expr, String &s)
Definition: item.cc:10976
String value_buff
Definition: item.h:7220
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11014
const CHARSET_INFO * charset() const
Definition: item.h:7248
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:7240
double val_real() override
Definition: item.cc:10986
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:7244
String * val_str(String *) override
Definition: item.cc:11008
longlong val_int() override
Definition: item.cc:10997
char buffer[STRING_BUFFER_USUAL_SIZE]
Definition: item.h:7219
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:7243
String * value
Definition: item.h:7220
bool is_varbinary
Definition: item.h:7221
Item_cache_str(const Item *item)
Definition: item.h:7228
Definition: item.h:7313
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:10447
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:10426
Item_cache_time()
Definition: item.h:7315
void store(Item *item) override
Assigns to the cache the expression to be cached.
Definition: item.cc:10416
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:10436
bool cache_value() override
Definition: item.cc:10387
Item_result result_type() const override
Definition: item.h:7328
Time_val time_value
Definition: item.h:7338
void store_value(Time_val time)
Cache a single non-NULL time value.
Definition: item.cc:10396
String * val_str(String *str) override
Definition: item.cc:10403
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:10460
longlong val_int() override
Definition: item.cc:10456
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:10418
double val_real() override
Definition: item.cc:10458
Definition: item.h:6985
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:10298
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:10316
Field * field()
If this item caches a field value, return pointer to underlying field.
Definition: item.h:7068
Item * get_example() const
Definition: item.h:7117
bool eq_def(const Field *field)
Definition: item.h:7052
Item_field * cached_field
Field that this object will get value from.
Definition: item.h:6994
virtual bool allocate(uint)
Definition: item.h:7028
Item ** get_example_ptr()
Definition: item.h:7118
bool is_non_const_over_literals(uchar *) override
Definition: item.h:7104
bool has_value()
Check if saved item has a non-NULL value.
Definition: item.cc:10304
Item_result result_type() const override
Definition: item.h:7113
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:7093
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:10291
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.h:7055
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:7021
virtual bool cache_value()=0
void store_null()
Force an item to be null.
Definition: item.h:7081
Item_cache(enum_field_types field_type_arg)
Definition: item.h:7014
table_map used_table_map
Definition: item.h:6988
enum Type type() const override
Definition: item.h:7045
Item_cache()
Definition: item.h:7009
virtual void store(Item *item)
Assigns to the cache the expression to be cached.
Definition: item.cc:10267
virtual bool setup(Item *item)
Definition: item.h:7029
bool value_cached
Definition: item.h:7002
table_map used_tables() const override
Definition: item.h:7048
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:7101
virtual void clear()
Definition: item.h:7097
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:7105
Item * example
Definition: item.h:6987
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:10218
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:10281
bool store_and_cache(Item *item)
Definition: item.h:7088
Definition: item.h:4145
uint m_case_expr_id
Definition: item.h:4169
Type type() const override
Definition: item.h:4154
Item * this_item() override
Definition: item.cc:2105
Item_case_expr(uint case_expr_id)
Definition: item.cc:2101
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:2130
Item ** this_item_addr(THD *thd, Item **) override
Definition: item.cc:2117
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2123
Item_result result_type() const override
Definition: item.h:4155
Definition: item.h:6626
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:6640
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:6635
Item * clone_item() const override
Definition: item.cc:7474
Definition: item.h:5500
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3771
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5528
uint decimal_precision() const override
Definition: item.h:5542
String * val_str(String *) override
Definition: item.cc:3741
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3747
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3773
Item_result result_type() const override
Definition: item.h:5519
longlong val_int() override
Definition: item.cc:3729
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5524
enum Type type() const override
Definition: item.h:5518
my_decimal * val_decimal(my_decimal *) override
Definition: item.h:5523
my_decimal decimal_value
Definition: item.h:5504
double val_real() override
Definition: item.cc:3735
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5545
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:7443
Item_num super
Definition: item.h:5501
Item_decimal(const POS &pos, const char *str_arg, uint length, const CHARSET_INFO *charset)
Definition: item.cc:3670
Item * clone_item() const override
Definition: item.h:5531
Item_num * neg() override
Definition: item.h:5537
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5527
void set_decimal_value(const my_decimal *value_par)
Definition: item.cc:3788
Definition: item.h:6741
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:9632
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:9681
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:9637
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9621
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:9526
Item_default_value(const POS &pos, Item *a=nullptr)
Definition: item.h:6749
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9607
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:6771
Item_field super
Definition: item.h:6742
bool check_column_privileges(uchar *) override
Check privileges of base table column.
Definition: item.h:6769
table_map used_tables() const override
Definition: item.h:6760
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:6777
Item * arg
The argument for this function.
Definition: item.h:6787
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:6718
Item * argument() const
Definition: item.h:6783
uchar * m_rowbuffer_saved
Pointer to row buffer that was used to calculate field value offset.
Definition: item.h:6789
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9547
enum Type type() const override
Definition: item.h:6752
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:6742
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:6761
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9542
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9597
Item_empty_string – is a utility class to put an item into List<Item> which is then used in protocol....
Definition: item.h:5911
void make_field(Send_field *field) override
Definition: item.cc:6847
Item_empty_string(const char *header, size_t length, const CHARSET_INFO *cs=nullptr)
Definition: item.h:5913
Definition: item.h:4529
Item * replace_equal_field(uchar *) override
Replace an Item_field for an equal Item_field that evaluated earlier (if any).
Definition: item.cc:6788
bool protected_by_any_value() const
See m_protected_by_any_value.
Definition: item.h:4836
bool check_column_privileges(uchar *arg) override
Check privileges of base table column.
Definition: item.cc:1414
bool collect_outer_field_processor(uchar *arg) override
Definition: item.cc:1014
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:1046
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:1227
bool find_field_processor(uchar *arg) override
Is this an Item_field which references the given Field argument?
Definition: item.h:4712
bool alias_name_used() const override
Definition: item.h:4812
bool any_privileges
Definition: item.h:4639
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4725
void set_item_equal_all_join_nests(Item_multi_eq *item_equal)
Definition: item.h:4610
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:3429
enum Type type() const override
Definition: item.h:4655
Item * apply_masking_policy(THD *thd) override
Apply column masking policy to this item if applicable.
Definition: item.cc:11883
bool add_field_to_cond_set_processor(uchar *) override
Item::walk function.
Definition: item.cc:1093
Item_result numeric_context_result_type() const override
Result type when an item appear in a numeric context.
Definition: item.h:4671
Item_multi_eq * multi_equality() const
Definition: item.h:4608
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:3419
void set_field(Field *field)
Definition: item.cc:3208
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:3412
Item_result cast_to_int_type() const override
Definition: item.h:4675
void set_item_was_sp_local_variable()
Sets m_was_sp_local_variable to true.
Definition: item.h:4618
const Item_field * base_item_field() const
Definition: item.h:4689
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:1002
Item_multi_eq * find_multi_equality(COND_EQUAL *cond_equal) const
Find a field among specified multiple equalities.
Definition: item.cc:6547
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:1291
uint16 field_index
Index for this field in table->field array.
Definition: item.h:4607
const CHARSET_INFO * charset_for_protocol(void) override
Definition: item.h:4758
bool subst_argument_checker(uchar **arg) override
Check whether a field can be substituted by an equal item.
Definition: item.cc:6591
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:8530
Field * result_field
Result field.
Definition: item.h:4552
void disable_masking_policy() override
Disable application of the masking policy to this item.
Definition: item.h:4821
Item_multi_eq * item_equal_all_join_nests
Definition: item.h:4629
Item_result result_type() const override
Definition: item.h:4670
uint32 max_disp_length()
Definition: item.h:4743
void dbug_print() const
Definition: item.h:4763
double val_real() override
Definition: item.cc:3382
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:1122
void save_org_in_field(Field *field) override
Set a field's value from a item.
Definition: item.cc:7148
void make_field(Send_field *tmp_field) override
Definition: item.cc:7094
void set_base_item_field(const Item_field *item)
Definition: item.h:4685
bool get_timeval(my_timeval *tm, int *warnings) override
Get timestamp in "struct timeval" format.
Definition: item.cc:3439
enum_monotonicity_info get_monotonicity_info() const override
Definition: item.h:4678
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:8572
Item_field * field_for_view_update() override
Definition: item.h:4744
const Item_field * m_base_item_field
If this field is derived from another field, e.g.
Definition: item.h:4574
void set_result_field(Field *field_arg) override
Definition: item.h:4682
bool send(Protocol *protocol, String *str_arg) override
This is only called from items that is not of type item_field.
Definition: item.cc:8495
table_map used_tables() const override
Definition: item.cc:3483
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:4696
void reset_field()
Reset all aspect of a field object, so that it can be re-resolved.
Definition: item.cc:6519
Field * field
Source field.
Definition: item.h:4548
void compute_cost(CostOfItem *root_cost) const override
Compute the cost of evaluating this Item.
Definition: item.h:4838
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:4590
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:8516
bool check_column_in_group_by(uchar *arg) override
Check if this column is found in GROUP BY.
Definition: item.cc:1261
uint32_t last_org_destination_field_memcpyable
Definition: item.h:4566
bool returns_array() const override
Whether the item returns array of its data type.
Definition: item.h:4819
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:6692
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:3394
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:6453
void set_can_use_prefix_key() override
Definition: item.h:4823
uint32_t last_destination_field_memcpyable
Definition: item.h:4567
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:6648
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:5822
String * val_str(String *) override
Definition: item.cc:3367
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:3574
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3406
Field::geometry_type get_geometry_type() const override
Definition: item.h:4754
Access_bitmask have_privileges
Definition: item.h:4637
bool add_field_to_set_processor(uchar *arg) override
Item::walk function.
Definition: item.cc:1084
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:1274
bool strip_db_table_name_processor(uchar *) override
Generated fields don't need db/table names.
Definition: item.cc:11761
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:1100
bool is_outer_field() const override
Definition: item.h:4750
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:11750
bool no_constant_propagation
If true, the optimizer's constant propagation will not replace this item with an equal constant.
Definition: item.h:4632
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:3374
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:1062
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:3104
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:1133
Item_ident super
Definition: item.h:4530
virtual bool is_asterisk() const
Checks if the current object represents an asterisk select list item.
Definition: item.h:4834
Field * tmp_table_field(TABLE *) override
Definition: item.h:4684
bool can_use_prefix_key
Definition: item.h:4644
bool m_protected_by_any_value
State used for transforming scalar subqueries to JOINs with derived tables, cf.
Definition: item.h:4580
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:4534
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:3080
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:7163
longlong val_date_temporal_at_utc() override
Definition: item.cc:3400
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:6482
bool m_masking_policy_disabled
apply_masking_policy() is a no-op if this flag is true.
Definition: item.h:4600
longlong val_int() override
Definition: item.cc:3388
bool m_was_sp_local_variable
Indicates whether this field should be treated as an outer reference due to being the result of inlin...
Definition: item.h:4597
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:8560
Field * last_org_destination_field
Definition: item.h:4564
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3445
bool used_tables_for_level(uchar *arg) override
Return used table information for the specified query block (level).
Definition: item.cc:3489
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item.cc:3363
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:4716
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:1325
bool disable_constant_propagation(uchar *) override
Definition: item.h:4738
bool replace_field_processor(uchar *arg) override
A processor that replaces any Fields with a Create_field_wrapper.
Definition: sql_table.cc:7859
Field * last_destination_field
Definition: item.h:4565
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:4683
longlong val_int_endpoint(bool left_endp, bool *incl_endp) override
Definition: item.cc:3585
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:6233
Definition: item.h:5548
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5616
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5613
Item_num super
Definition: item.h:5549
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7592
longlong val_int() override
Definition: item.h:5602
Name_string presentation
Definition: item.h:5551
Item_float(double value_par, uint decimal_par)
Definition: item.h:5582
Item_float(const POS &pos, const Name_string name_arg, double val_arg, uint decimal_par, uint length)
Definition: item.h:5571
Item * clone_item() const override
Definition: item.h:5620
void init(const char *str_arg, uint length)
This function is only called during parsing:
Definition: item.cc:7551
Item_float(const char *str_arg, uint length)
Definition: item.h:5556
double val_real() override
Definition: item.h:5598
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:7568
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7576
Item_num * neg() override
Definition: item.h:5623
String * val_str(String *) override
Definition: item.cc:3796
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3802
double value
Definition: item.h:5554
Item_float(const Name_string name_arg, double val_arg, uint decimal_par, uint length)
Definition: item.h:5561
Item_float(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5557
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7600
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5617
enum Type type() const override
Definition: item.h:5597
Implements the comparison operator equals (=)
Definition: item_cmpfunc.h:1111
Definition: item.h:5633
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item.h:5641
const Name_string func_name
Definition: item.h:5634
Item_func_pi(const POS &pos)
Definition: item.h:5637
Definition: item_func.h:101
Definition: item.h:5934
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5965
uint decimal_precision() const override
Definition: item.cc:7652
Item_result result_type() const override
Definition: item.h:5969
Item_result cast_to_int_type() const override
Definition: item.h:5973
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:7727
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7787
void hex_string_init(const char *str, uint str_length)
Definition: item.cc:7678
Item_result numeric_context_result_type() const override
Result type when an item appear in a numeric context.
Definition: item.h:5970
enum Type type() const override
Definition: item.h:5949
Item_hex_string()
Definition: item.cc:7618
longlong val_int() override
Definition: item.cc:7688
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5966
Item_basic_constant super
Definition: item.h:5935
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5962
Item * clone_item() const override
Definition: item.cc:7625
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7789
static LEX_CSTRING make_hex_str(const char *str, size_t str_length)
Definition: item.cc:7636
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:7734
double val_real() override
Definition: item.h:5950
String * val_str(String *) override
Definition: item.h:5957
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7765
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5978
Item_hex_string(const POS &pos)
Definition: item.h:5943
Definition: item.h:4498
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:4516
my_decimal * val_decimal(my_decimal *dec) override
Definition: item.h:4513
const CHARSET_INFO * charset_for_protocol() override
Definition: item.h:4524
Item_ident_for_show(Field *par_field, const char *db_arg, const char *table_name_arg)
Definition: item.h:4504
const char * table_name
Definition: item.h:4502
enum Type type() const override
Definition: item.h:4508
longlong val_int() override
Definition: item.h:4511
double val_real() override
Definition: item.h:4510
Field * field
Definition: item.h:4500
String * val_str(String *str) override
Definition: item.h:4512
bool fix_fields(THD *thd, Item **ref) override
Definition: item.cc:3030
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:4519
void make_field(Send_field *tmp_field) override
Definition: item.cc:3017
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:4520
const char * db_name
Definition: item.h:4501
Definition: item.h:4258
bool m_alias_of_expr
if this Item's name is alias of SELECT expression
Definition: item.h:4302
uint64_t m_hash_val
To cache the hash value of this item, populated upon hash() invocation.
Definition: item.h:4262
virtual bool alias_name_used() const
Definition: item.h:4489
const char * original_db_name() const
Definition: item.h:4415
void set_alias_of_expr()
Marks that this Item's name is alias of SELECT expression.
Definition: item.h:4473
bool is_strong_side_column_not_in_fd(uchar *arg) override
Definition: item.cc:11725
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:4364
bool is_alias_of_expr() const
Definition: item.h:4471
Item_ident(THD *thd, Item_ident *item)
Constructor used by Item_field & Item_*_ref (see Item comment)
Definition: item.h:4392
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:4362
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:3508
const char * m_orig_field_name
Names the field in the source base table.
Definition: item.h:4301
void set_original_field_name(const char *name_arg)
Definition: item.h:4412
const char * m_orig_table_name
Names the original table that is the source of the field.
Definition: item.h:4291
const char * original_table_name() const
Definition: item.h:4416
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.h:4424
Item_ident(const POS &pos, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:4377
bool update_depended_from(uchar *) override
Definition: item.cc:977
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:957
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:4356
const char * table_name
If column is from a non-aliased base table or view, name of base table or view.
Definition: item.h:4331
Name_resolution_context * context
For regularly resolved column references, 'context' points to a name resolution context object belong...
Definition: item.h:4317
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:4323
const char * full_name() const override
Definition: item.cc:3264
bool aggregate_check_group(uchar *arg) override
Definition: item.cc:11720
bool is_column_not_in_fd(uchar *arg) override
Definition: item.cc:11733
const char * field_name
If column is aliased, the column alias name.
Definition: item.h:4345
uint64_t hash(const char *db_name_arg, const char *table_name_arg)
void set_orignal_db_name(const char *name_arg)
Definition: item.h:4408
const char * original_field_name() const
Definition: item.h:4417
bool change_context_processor(uchar *arg) override
Definition: item.h:4465
void set_original_table_name(const char *name_arg)
Definition: item.h:4409
Item super
Definition: item.h:4259
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3336
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:4281
bool aggregate_check_distinct(uchar *arg) override
Definition: item.cc:11672
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:11639
Representation of IN subquery predicates of the form "left_expr IN (SELECT ...)".
Definition: item_subselect.h:608
Definition: item.h:6802
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:6823
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:6852
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9699
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:6814
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.h:6828
uchar * m_rowbuffer_saved
Pointer to row buffer that was used to calculate field value offset.
Definition: item.h:6863
const bool m_is_values_function
This flag is true if the item represents a call to the deprecated VALUES function.
Definition: item.h:6869
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:6804
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9694
Item * arg
The argument for this function.
Definition: item.h:6861
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:6847
table_map used_tables() const override
Definition: item.h:6845
enum Type type() const override
Definition: item.h:6833
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9782
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9810
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:9817
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9804
Item_int with value==0 and length==1.
Definition: item.h:5405
Item_int_0()
Definition: item.h:5407
Item_int_0(const POS &pos)
Definition: item.h:5408
Definition: item.h:6575
Item * clone_item() const override
Definition: item.cc:7463
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:6578
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7495
const Item * real_item() const override
Definition: item.h:6593
Item_int_with_ref(enum_field_types field_type, longlong i, Item *ref_arg, bool unsigned_arg)
Definition: item.h:6584
Item * ref
Definition: item.h:6577
Item * real_item() override
Definition: item.h:6592
Definition: item.h:5291
Item_result result_type() const override
Definition: item.h:5368
Item_int(const POS &pos, const LEX_STRING &num, int dummy_error=0)
Definition: item.h:5351
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3628
Item_int(longlong i, uint length=MY_INT64_NUM_DECIMAL_DIGITS)
Definition: item.h:5310
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3616
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5383
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:5399
double val_real() override
Definition: item.h:5373
Item_int(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5346
Item * clone_item() const override
Definition: item.h:5386
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5398
Item_int(const POS &pos, const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5335
longlong value
Definition: item.h:5297
Item_int(int32 i, uint length=MY_INT32_NUM_DECIMAL_DIGITS)
Definition: item.h:5298
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:7424
void init(const char *str_arg, uint length)
Init an item from a string we KNOW points to a valid longlong.
Definition: item.cc:3607
uint decimal_precision() const override
Definition: item.h:5394
Item_int(const POS &pos, int32 i, uint length=MY_INT32_NUM_DECIMAL_DIGITS)
Definition: item.h:5304
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5379
Item_int(const Item_int *item_arg)
Definition: item.h:5322
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3650
Item_int(const char *str_arg, uint length)
Definition: item.h:5342
void set_max_size(uint length)
Definition: item.h:5357
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5382
static Item_int * narrow(Item *item)
Definition: item.cc:3590
String * val_str(String *) override
Definition: item.cc:3621
Item_num super
Definition: item.h:5292
enum Type type() const override
Definition: item.h:5367
Item_int(ulonglong i, uint length=MY_INT64_NUM_DECIMAL_DIGITS)
Definition: item.h:5315
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:7450
Item_int(const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5329
Item_num * neg() override
Definition: item.h:5390
longlong val_int() override
Definition: item.h:5369
A class that represents a constant JSON value.
Definition: item.h:7569
unique_ptr_destroy_only< Json_wrapper > m_value
Definition: item.h:7570
longlong val_int() override
Definition: item.cc:7888
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:7903
Item_result result_type() const override
Definition: item.h:7580
~Item_json() override
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:7865
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:7915
void print(const THD *, String *str, enum_query_type) const override
This method is used for to:
Definition: item.cc:7859
Item * clone_item() const override
Definition: item.cc:7920
Item_json(unique_ptr_destroy_only< Json_wrapper > value, const Item_name_string &name)
Definition: item.cc:7850
my_decimal * val_decimal(my_decimal *buf) override
Definition: item.cc:7899
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:7872
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:7909
double val_real() override
Definition: item.cc:7884
String * val_str(String *str) override
Definition: item.cc:7892
enum Type type() const override
Definition: item.h:7576
The class Item_multi_eq is used to represent conjunctions of equality predicates of the form field1 =...
Definition: item_cmpfunc.h:2712
Definition: item.h:4186
Item * value_item
Definition: item.h:4189
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:2172
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:2167
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:4221
Item * name_item
Definition: item.h:4190
Item_result result_type() const override
Definition: item.h:4213
bool fix_fields(THD *, Item **) override
Definition: item.cc:2236
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:2182
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:2271
bool valid_args
Definition: item.h:4191
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:2160
bool cache_const_expr_analyzer(uchar **) override
Check if an item is a constant one and can be cached.
Definition: item.h:4215
longlong val_int() override
Definition: item.cc:2146
double val_real() override
Definition: item.cc:2139
Item_name_const(const POS &pos, Item *name_arg, Item *val)
Definition: item.cc:2184
Item super
Definition: item.h:4187
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2262
enum Type type() const override
Definition: item.h:4199
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:2177
bool do_itemize(Parse_context *pc, Item **res) override
The core function that does the actual itemization.
Definition: item.cc:2189
String * val_str(String *sp) override
Definition: item.cc:2153
Storage for Item names.
Definition: item.h:372
void set_autogenerated(bool is_autogenerated)
Set m_is_autogenerated flag to the given value.
Definition: item.h:383
bool is_autogenerated() const
Return the auto-generated flag.
Definition: item.h:389
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:1500
Item_name_string()
Definition: item.h:377
Item_name_string(const Name_string name)
Definition: item.h:378
bool m_is_autogenerated
Definition: item.h:374
Definition: item.h:4895
type_conversion_status save_in_field_inner(Field *field, bool no_conversions) override
Store null in field.
Definition: item.cc:7205
Item_null()
Definition: item.h:4909
bool send(Protocol *protocol, String *str) override
Pack data in buffer for sending.
Definition: item.cc:7846
void print(const THD *, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.h:4939
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:3970
Item_basic_constant super
Definition: item.h:4896
bool val_time(Time_val *) override
Evaluate the item and return result as a time value.
Definition: item.h:4931
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3972
Item_result result_type() const override
Definition: item.h:4935
Item_null(const POS &pos)
Definition: item.h:4913
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4945
Item * clone_item() const override
Definition: item.h:4936
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:4927
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:4937
double val_real() override
Definition: item.cc:3974
longlong val_int() override
Definition: item.cc:3980
bool val_datetime(Datetime_val *, my_time_flags_t) override
Evaluate the item and return result as a datetime value.
Definition: item.h:4932
Item_null(const Name_string &name_par)
Definition: item.h:4918
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item.cc:3996
String * val_str(String *str) override
Definition: item.cc:3987
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3994
enum Type type() const override
Definition: item.h:4923
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:4930
void init()
Definition: item.h:4898
Definition: item.h:4245
virtual Item_num * neg()=0
Item_basic_constant super
Definition: item.h:4246
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:4253
Item_num()
Definition: item.h:4249
Item_num(const POS &pos)
Definition: item.h:4250
Definition: item.h:6468
bool fix_fields(THD *, Item **) override
Prepare referenced outer field then call usual Item_ref::fix_fields.
Definition: item.cc:9261
Item * replace_outer_ref(uchar *) override
Definition: item.cc:9323
Query_block * qualifying
Qualifying query of this outer ref (i.e.
Definition: item.h:6476
bool found_in_select_list
Definition: item.h:6486
Ref_Type ref_type() const override
Definition: item.h:6520
Item * outer_ref
Definition: item.h:6479
Item_outer_ref(Name_resolution_context *context_arg, Item_ident *ident_arg, Query_block *qualifying)
Definition: item.h:6487
Item_ref super
Definition: item.h:6469
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:6502
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:6518
table_map used_tables() const override
Definition: item.h:6515
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:9312
Item_sum * in_sum_func
Definition: item.h:6481
Dynamic parameters used as placeholders ('?') inside prepared statements.
Definition: item.h:4950
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:4605
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:5180
union Item_param::@61 value
enum_field_types data_type_source() const
Definition: item.h:5184
void reset()
Resets parameter after execution.
Definition: item.cc:4540
void set_null()
Definition: item.cc:4237
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:5343
Time_val m_time
Definition: item.h:4992
void set_time(Datetime_val *dt, enum_mysql_timestamp_type type)
Set parameter value from MYSQL_TIME value.
Definition: item.cc:4347
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:4876
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:5103
bool is_type_inherited() const
Definition: item.h:5132
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:4740
double real
Definition: item.h:4996
void set_param_state(enum enum_item_param_state state)
Definition: item.h:4971
bool is_type_pinned() const
Definition: item.h:5138
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:5243
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:5288
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:4553
String * val_str(String *) override
Definition: item.cc:4771
void sync_clones()
This should be called after any modification done to this Item, to propagate the said modification to...
Definition: item.cc:4206
void set_collation_actual(const CHARSET_INFO *coll)
Definition: item.h:5147
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:4813
void set_out_param_info(Send_field *info) override
Setter of Item_param::m_out_param_info.
Definition: item.cc:5406
Date_val m_date
Definition: item.h:4991
bool set_from_user_var(THD *thd, const user_var_entry *entry)
Set parameter value from user variable value.
Definition: item.cc:4448
Item_result m_result_type
Result type of parameter.
Definition: item.h:5088
uint pos_in_query
Definition: item.h:5119
bool is_unsigned_actual() const
Definition: item.h:5141
void set_data_type_source(enum_field_types data_type, bool unsigned_val)
Definition: item.h:5171
bool add_clone(Item_param *i)
Definition: item.h:5239
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:5220
longlong integer
Definition: item.h:4995
void pin_data_type() override
Pin the currently resolved data type for this parameter.
Definition: item.h:5135
const CHARSET_INFO * m_collation_source
The character set and collation of the source parameter value.
Definition: item.h:5078
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:4640
bool is_non_const_over_literals(uchar *) override
Definition: item.h:5233
String str_value_ptr
Definition: item.h:4989
const Send_field * get_out_param_info() const override
Getter of Item_param::m_out_param_info.
Definition: item.cc:5425
enum_field_types data_type_actual() const
Definition: item.h:5186
my_decimal decimal_value
Definition: item.h:4990
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:5242
Item_result result_type() const override
Definition: item.h:5125
enum_field_types m_data_type_actual
The actual data type of the parameter value provided by the user.
Definition: item.h:5069
void set_decimal(const char *str, ulong length)
Set decimal parameter value from string.
Definition: item.cc:4281
void make_field(Send_field *field) override
Fill meta-data information for the corresponding column in a result set.
Definition: item.cc:5437
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:5261
enum_item_param_state
Definition: item.h:4958
@ STRING_VALUE
Definition: item.h:4963
@ DECIMAL_VALUE
Definition: item.h:4968
@ NO_VALUE
Definition: item.h:4959
@ REAL_VALUE
Definition: item.h:4962
@ TIME_VALUE
Definition: item.h:4964
@ LONG_DATA_VALUE
Definition: item.h:4967
@ INT_VALUE
Definition: item.h:4961
@ DATETIME_VALUE
Definition: item.h:4966
@ NULL_VALUE
Definition: item.h:4960
@ DATE_VALUE
Definition: item.h:4965
Datetime_val m_datetime
Definition: item.h:4993
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:5048
enum Type type() const override
Definition: item.h:5126
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:5097
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:5255
void set_int(longlong i)
Definition: item.cc:4246
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:5230
bool convert_value()
Convert value according to the following rules:
Definition: item.cc:4959
void set_data_type_inherited() override
Set the currently resolved data type for this parameter as inherited.
Definition: item.h:5129
const CHARSET_INFO * collation_actual() const
Definition: item.h:5155
bool fix_fields(THD *thd, Item **ref) override
Definition: item.cc:4074
void set_date(Date_val date)
Set parameter value from date value.
Definition: item.cc:4316
Send_field * m_out_param_info
Definition: item.h:5267
void set_datetime(Datetime_val dt)
Set parameter value from datetime value.
Definition: item.cc:4330
bool do_itemize(Parse_context *pc, Item **item) override
The core function that does the actual itemization.
Definition: item.cc:4010
void set_collation_source(const CHARSET_INFO *coll)
Definition: item.h:5143
const CHARSET_INFO * collation_source() const
Definition: item.h:5152
longlong val_int() override
Definition: item.cc:4703
bool set_str(const char *str, size_t length)
Definition: item.cc:4379
bool m_unsigned_actual
Used when actual value is integer to indicate whether value is unsigned.
Definition: item.h:5071
bool m_type_inherited
True if type of parameter is inherited from parent object (like a typecast).
Definition: item.h:5006
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:5226
double val_real() override
Definition: item.cc:4662
enum_field_types actual_data_type() const override
Retrieve actual data type for an item.
Definition: item.h:5188
enum enum_item_param_state param_state() const
Definition: item.h:4975
Item * clone_item() const override
Definition: item.cc:5202
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:5086
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:5313
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:5017
bool propagate_type(THD *thd, const Type_properties &type) override
Propagate data type specifications into parameters and user variables.
Definition: item.cc:4128
void set_double(double i)
Definition: item.cc:4262
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:4977
bool set_longdata(const char *str, ulong length)
Definition: item.cc:4407
void copy_param_actual_type(Item_param *from)
Definition: item.cc:4824
Item_param(const POS &pos, MEM_ROOT *root, uint pos_in_query_arg)
Definition: item.cc:4003
table_map used_tables() const override
Definition: item.h:5216
void set_data_type_actual(enum_field_types data_type)
Definition: item.h:5176
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:4583
Item super
Definition: item.h:4951
Definition: item.h:5880
Item_partition_func_safe_string(const Name_string name, size_t length, const CHARSET_INFO *cs=nullptr)
Definition: item.h:5882
Definition: item.h:6532
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:5509
Item_ref_null_helper(const Item_ref_null_helper &ref_null_helper, Item **item)
Definition: item.h:6542
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:5521
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:5491
bool val_bool() override
Definition: item.cc:5497
String * val_str(String *s) override
Definition: item.cc:5503
Item_in_subselect * owner
Definition: item.h:6536
Item_ref_null_helper(Name_resolution_context *context_arg, Item_in_subselect *master, Item **item)
Definition: item.h:6539
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:5485
longlong val_int() override
Definition: item.cc:5479
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9182
Item_ref super
Definition: item.h:6533
double val_real() override
Definition: item.cc:5473
Ref_Type ref_type() const override
Definition: item.h:6556
table_map used_tables() const override
Definition: item.h:6560
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:5515
Definition: item.h:6085
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:9014
void update_used_tables() override
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item.h:6184
bool created_by_in2exists() const override
Whether this Item was created by the IN->EXISTS subquery transformation.
Definition: item.h:6289
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:9104
bool collect_item_field_or_ref_processor(uchar *arg) override
Definition: item.cc:9193
bool is_result_field() const override
Definition: item.h:6205
void set_properties()
Definition: item.cc:8948
table_map used_tables() const override
Definition: item.h:6176
Item_field * field_for_view_update() override
Definition: item.h:6249
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:9111
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.h:6144
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:9138
Item_ref(THD *thd, Item_ref *item)
Definition: item.h:6130
Item ** addr(uint i) override
Definition: item.h:6263
void traverse_cond(Cond_traverser traverser, void *arg, traverse_order order) override
Definition: item.h:6228
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:9162
bool clean_up_after_removal(uchar *arg) override
Clean up after removing the item from the item tree.
Definition: item.cc:8623
bool fix_fields(THD *, Item **) override
Resolve the name of a reference to a column reference.
Definition: item.cc:8706
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:6295
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:6304
Item_result result_type() const override
Definition: item.h:6167
void make_field(Send_field *field) override
Definition: item.cc:9146
void bring_value() override
Definition: item.h:6276
uint cols() const override
Definition: item.h:6255
Item ** ref_pointer() const
Definition: item.h:6139
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:9097
bool val_bool() override
Definition: item.cc:9083
bool is_outer_field() const override
Definition: item.h:6283
bool null_inside() override
Definition: item.h:6272
void set_result_field(Field *field) override
Definition: item.h:6204
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9031
Item * real_item() override
Definition: item.h:6207
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.cc:9075
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:6171
Item_result cast_to_int_type() const override
Definition: item.h:6301
Ref_Type
Definition: item.h:6092
@ NULL_HELPER_REF
Definition: item.h:6092
@ VIEW_REF
Definition: item.h:6092
@ REF
Definition: item.h:6092
@ AGGREGATE_REF
Definition: item.h:6092
@ OUTER_REF
Definition: item.h:6092
String * val_str(String *tmp) override
Definition: item.cc:9090
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:9046
Field * result_field
Definition: item.h:6098
bool explain_subquery_checker(uchar **) override
Definition: item.h:6235
void link_referenced_item()
Definition: item.h:6141
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:6307
bool is_non_const_over_literals(uchar *) override
Definition: item.h:6294
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:8968
const Item * real_item() const override
Definition: item.h:6212
Item_ref(const POS &pos, const char *db_name_arg, const char *table_name_arg, const char *field_name_arg)
Definition: item.h:6105
Field * get_result_field() const override
Definition: item.h:6206
TYPELIB * get_typelib() const override
Get the typelib information for an item of type set or enum.
Definition: item.h:6169
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:6218
enum Type type() const override
Definition: item.h:6143
bool send(Protocol *prot, String *tmp) override
This is only called from items that is not of type item_field.
Definition: item.cc:9057
bool pusheddown_depended_from
Definition: item.h:6095
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:6310
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:9329
virtual Ref_Type ref_type() const
Definition: item.h:6252
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:9118
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:6281
Item * transform(Item_transformer, uchar *arg) override
Transform an Item_ref object with a transformer callback function.
Definition: item.cc:8984
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:11741
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:6194
Item * element_index(uint i) override
Definition: item.h:6259
bool check_cols(uint c) override
Definition: item.h:6267
Item ** m_ref_item
Indirect pointer to the referenced item.
Definition: item.h:6102
longlong val_int() override
Definition: item.cc:9068
Item * ref_item() const
Definition: item.h:6136
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:9132
double val_real() override
Definition: item.cc:9061
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:9125
Item with result field.
Definition: item.h:6020
Item_result_field(const POS &pos)
Definition: item.h:6025
Field * tmp_table_field(TABLE *) override
Definition: item.h:6031
Field * result_field
Definition: item.h:6022
int raise_decimal_overflow()
Definition: item.h:6079
longlong raise_integer_overflow()
Definition: item.h:6074
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:6030
Item_result_field(THD *thd, const Item_result_field *item)
Definition: item.h:6028
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:6059
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:6051
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:6050
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:11580
void raise_numeric_overflow(const char *type_name)
Definition: item.cc:11586
Item_result_field()=default
double raise_float_overflow()
Definition: item.h:6069
bool is_result_field() const override
Definition: item.h:6046
table_map used_tables() const override
Definition: item.h:6032
void set_result_field(Field *field) override
Definition: item.h:6045
Field * get_result_field() const override
Definition: item.h:6047
Definition: item.h:5923
Item_return_int(const char *name_arg, uint length, enum_field_types field_type_arg, longlong value_arg=0)
Definition: item.h:5925
Class that represents scalar subquery and row subquery.
Definition: item_subselect.h:283
Definition: item.h:4010
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:4046
Item_sp_variable(const Name_string sp_var_name)
Definition: item.cc:1923
Name_string m_name
Definition: item.h:4012
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:2006
String * val_str(String *sp) override
Definition: item.cc:1965
bool fix_fields(THD *thd, Item **) override
Definition: item.cc:1926
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:2014
my_decimal * val_decimal(my_decimal *decimal_value) override
Definition: item.cc:1998
void make_field(Send_field *field) override
Definition: item.h:4060
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:2020
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:4066
double val_real() override
Definition: item.cc:1949
longlong val_int() override
Definition: item.cc:1957
table_map used_tables() const override
Definition: item.h:4026
bool send(Protocol *protocol, String *str) override
This is only called from items that is not of type item_field.
Definition: item.h:4041
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:2026
sp_head * m_sp
Definition: item.h:4020
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:2032
Definition: item.h:4077
bool limit_clause_param
Definition: item.h:4087
Item_result result_type() const override
Definition: item.h:4127
bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override
Definition: item.cc:2093
uint len_in_query
Definition: item.h:4106
bool is_splocal() const override
Definition: item.h:4112
uint get_var_idx() const
Definition: item.h:4124
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:2069
uint m_var_idx
Definition: item.h:4078
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:4136
uint pos_in_query
Definition: item.h:4098
Item * this_item() override
Definition: item.cc:2051
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:2038
Type type() const override
Definition: item.h:4126
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:2088
Item ** this_item_addr(THD *thd, Item **) override
Definition: item.cc:2063
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:2076
Definition: item.h:5850
void print(const THD *, String *str, enum_query_type) const override
Definition: item.h:5866
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:5854
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5870
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:5871
const Name_string func_name
Definition: item.h:5851
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:5859
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3965
Definition: item.h:5646
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:5688
String * val_str(String *) override
Definition: item.h:5772
Item_string(const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE, uint repertoire=MY_REPERTOIRE_UNICODE30)
Definition: item.h:5682
void set_cs_specified(bool cs_specified)
Set the value of m_cs_specified attribute.
Definition: item.h:5834
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:1595
bool is_cs_specified() const
Return true if character-set-introducer was explicitly specified in the original query for this item ...
Definition: item.h:5822
Item_string(const CHARSET_INFO *cs, Derivation dv=DERIVATION_COERCIBLE)
Definition: item.h:5696
Item_string(const POS &pos)
Definition: item.h:5650
void append(char *str, size_t length)
Definition: item.h:5793
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5781
void init(const char *str, size_t length, const CHARSET_INFO *cs, Derivation dv, uint repertoire)
Definition: item.h:5654
bool check_partition_func_processor(uchar *) override
Check if a partition function is allowed.
Definition: item.h:5801
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:5735
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.h:5777
void mark_result_as_const()
Definition: item.h:5838
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:7374
Item_result result_type() const override
Definition: item.h:5784
Item * clone_item() const override
Definition: item.h:5789
bool m_cs_specified
Definition: item.h:5841
void print(const THD *thd, String *str, enum_query_type query_type) const override
Definition: item.cc:3831
void set_value_collation()
Update collation of string value to be according to item's collation.
Definition: item.h:5763
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:5706
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3887
Item_basic_constant super
Definition: item.h:5647
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:5780
void set_str_with_copy(const char *str_arg, uint length_arg)
Definition: item.h:5755
double val_real() override
Definition: item.cc:3905
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:5719
void set_repertoire_from_value()
Definition: item.h:5765
longlong val_int() override
Definition: item.cc:3954
bool eq_binary(const Item_string *item) const
Definition: item.h:5786
enum Type type() const override
Definition: item.h:5769
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:3961
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:6599
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:6609
Item_temporal_with_ref(enum_field_types field_type_arg, uint8 decimals_arg, longlong i, Item *ref_arg, bool unsigned_arg)
Definition: item.h:6601
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:7484
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.h:6613
Definition: item.h:5423
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:7430
Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5435
bool val_date(Date_val *, my_time_flags_t) override
Evaluate the item and return result as a date value.
Definition: item.h:5450
Item * clone_item() const override
Definition: item.h:5446
Item_temporal(enum_field_types field_type_arg, longlong i)
Definition: item.h:5429
bool val_datetime(Datetime_val *, my_time_flags_t) override
Evaluate the item and return result as a datetime value.
Definition: item.h:5458
longlong val_date_temporal() override
Return date value of item in packed longlong format.
Definition: item.h:5449
bool val_time(Time_val *) override
Evaluate the item and return result as a time value.
Definition: item.h:5454
Utility mixin class to be able to walk() only parts of item trees.
Definition: item.h:737
bool is_stopped(const Item *i)
Definition: item.h:754
const Item * stopped_at_item
Definition: item.h:775
void stop_at(const Item *i)
Stops walking children of this item.
Definition: item.h:745
Item_tree_walker(const Item_tree_walker &)=delete
Item_tree_walker()
Definition: item.h:739
Item_tree_walker & operator=(const Item_tree_walker &)=delete
~Item_tree_walker()
Definition: item.h:740
Represents NEW/OLD version of field of row which is changed/read in trigger.
Definition: item.h:6884
SQL_I_List< Item_trigger_field > * next_trig_field_list
Definition: item.h:6894
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:9960
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:9844
uint field_idx
Definition: item.h:6896
GRANT_INFO * table_grants
Definition: item.h:6977
bool check_column_privileges(uchar *arg) override
Check privileges of base table column.
Definition: item.cc:9949
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:6933
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:6911
bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override
Definition: item.cc:9865
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:6900
bool set_value(THD *thd, Item **it)
Definition: item.h:6958
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:9856
Settable_routine_parameter * get_settable_routine_parameter() override
Definition: item.h:6954
Item_trigger_field * next_trg_field
Definition: item.h:6889
void cleanup() override
Called for every Item after use (preparation and execution).
Definition: item.cc:9967
Access_bitmask want_privilege
Definition: item.h:6976
enum Type type() const override
Definition: item.h:6923
Item * copy_or_same(THD *) override
Definition: item.h:6932
Table_trigger_field_support * triggers
Definition: item.h:6898
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:6931
enum_trigger_variable_type trigger_var_type
Definition: item.h:6887
table_map used_tables() const override
Definition: item.h:6930
bool fix_fields(THD *, Item **) override
Resolve the name of a column reference.
Definition: item.cc:9892
bool read_only
Definition: item.h:6982
void bind_fields() override
Bind objects from the current execution context to field objects in item trees.
Definition: item.cc:9928
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:6939
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:6946
void set_required_privilege(Access_bitmask privilege) override
Set required privileges for accessing the parameter.
Definition: item.h:6935
Item_type_holder stores an aggregation of name, type and type specification of UNIONS and derived tab...
Definition: item.h:7491
Item_aggregate_type super
Definition: item.h:7492
enum Type type() const override
Definition: item.h:7500
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:7506
Item_type_holder(THD *thd, Item *item)
Definition: item.h:7498
String * val_str(String *) override
Definition: item.cc:11447
longlong val_int() override
Definition: item.cc:11437
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:11457
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:11452
double val_real() override
Definition: item.cc:11432
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11442
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:11462
Definition: item.h:5464
uint decimal_precision() const override
Definition: item.h:5496
Item * clone_item() const override
Definition: item.h:5489
Item_num * neg() override
Definition: item.cc:7502
Item_uint(const Name_string &name_arg, longlong i, uint length)
Definition: item.h:5479
void print(const THD *thd, String *str, enum_query_type query_type) const override
This method is used for to:
Definition: item.cc:3659
Item_uint(const POS &pos, const char *str_arg, uint length)
Definition: item.h:5473
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:7380
uint64_t hash() override
Generate hash unique to an item depending on its attributes.
Definition: item.cc:3668
double val_real() override
Definition: item.h:5483
String * val_str(String *) override
Definition: item.cc:3652
Item_uint(const char *str_arg, uint length)
Definition: item.h:5470
Item_uint(ulonglong i)
Definition: item.h:5478
Reference item that encapsulates both the type and the contained items of a single column of a VALUES...
Definition: item.h:7532
Item_values_column(THD *thd, Item *ref)
Definition: item.cc:11475
void set_value(Item *new_value)
Definition: item.h:7563
Item * m_value_ref
Definition: item.h:7536
table_map used_tables() const override
Definition: item.h:7564
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:11554
Item_aggregate_type super
Definition: item.h:7533
longlong val_int() override
Definition: item.cc:11490
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:11467
my_decimal * val_decimal(my_decimal *) override
Definition: item.cc:11497
bool is_null() override
Item_values_column is dualistic in nature: It represents both a set of values, and,...
Definition: item.cc:11539
bool eq(const Item *item) const override
Compare this item with another item for equality.
Definition: item.cc:11479
bool val_json(Json_wrapper *result) override
Get a JSON value from an Item.
Definition: item.cc:11513
enum Type type() const override
Definition: item.h:7562
String * val_str(String *tmp) override
Definition: item.cc:11522
void add_used_tables(Item *value)
Definition: item.cc:11576
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:11568
double val_real() override
Definition: item.cc:11483
bool val_bool() override
Definition: item.cc:11505
table_map m_aggregated_used_tables
Definition: item.h:7543
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:11561
Class for fields from derived tables and views.
Definition: item.h:6321
Ref_Type ref_type() const override
Definition: item.h:6413
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:6456
bool mark_field_in_map(uchar *arg) override
Mark underlying field in read or write map of a table.
Definition: item.h:6416
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:6407
bool is_null() override
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.cc:9428
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:6325
bool val_date(Date_val *date, my_time_flags_t flags) override
Evaluate the item and return result as a date value.
Definition: item.cc:9388
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:9447
bool has_null_row() const
Definition: item.h:6448
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:9439
double val_real() override
Definition: item.cc:9364
bool send(Protocol *prot, String *tmp) override
This is only called from items that is not of type item_field.
Definition: item.cc:9434
bool fix_fields(THD *, Item **) override
Prepare referenced field then call usual Item_ref::fix_fields .
Definition: item.cc:9213
bool val_bool() override
Definition: item.cc:9412
Item * replace_item_view_ref(uchar *arg) override
Definition: item.cc:9469
longlong val_int() override
Definition: item.cc:9356
Item_ref super
Definition: item.h:6322
bool subst_argument_checker(uchar **) override
Definition: item.h:6351
bool val_time(Time_val *time) override
Evaluate the item and return result as a time value.
Definition: item.cc:9396
Table_ref * get_first_inner_table() const
Definition: item.h:6440
bool val_json(Json_wrapper *wr) override
Get a JSON value from an Item.
Definition: item.cc:9420
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:6359
String * val_str(String *str) override
Definition: item.cc:9380
bool check_column_privileges(uchar *arg) override
Check privileges of view column.
Definition: item.cc:1436
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:9503
my_decimal * val_decimal(my_decimal *dec) override
Definition: item.cc:9372
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) override
Evaluate the item and return result as a datetime value.
Definition: item.cc:9404
bool eq(const Item *item) const override
Compare two view column references for equality.
Definition: item.cc:9345
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:929
void increment_ref_count()
Increment reference count.
Definition: item.h:3509
virtual double val_real()=0
uint32 max_char_length() const
Definition: item.h:3462
String * make_empty_result()
Sets the result value of the function an empty string, using the current character set.
Definition: item.h:940
virtual const CHARSET_INFO * compare_collation() const
Definition: item.h:2688
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:2153
virtual Field::geometry_type get_geometry_type() const
Definition: item.h:3445
String str_value
str_values's main purpose is to cache the value in save_in_field
Definition: item.h:3669
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:3781
bool get_datetime_from_numeric(Datetime_val *dt, my_time_flags_t flags)
Convert a numeric type to datetime.
Definition: item.cc:1705
virtual bool change_context_processor(uchar *)
Definition: item.h:2905
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:3219
DTCollation collation
Character set and collation properties assigned for this Item.
Definition: item.h:3676
ulonglong val_uint()
Definition: item.h:1941
bool has_subquery() const
Definition: item.h:3540
virtual bool subst_argument_checker(uchar **arg)
Definition: item.h:3146
CostOfItem cost() const
Definition: item.h:3451
bool contains_item(uchar *arg)
Definition: item.h:2828
my_decimal * val_decimal_from_datetime(my_decimal *decimal_value)
Definition: item.cc:429
void set_data_type_bool()
Definition: item.h:1524
longlong val_int_from_decimal()
Definition: item.cc:500
bool has_stored_program() const
Definition: item.h:3543
String * val_string_from_int(String *str)
Definition: item.cc:315
int error_int()
Get the value to return from val_int() in case of errors.
Definition: item.h:2240
bool get_time_from_datetime(Time_val *time)
Convert datetime to time.
Definition: item.cc:1798
virtual bool subq_opt_away_processor(uchar *)
Definition: item.h:3655
bool get_date_from_int(Date_val *date, my_time_flags_t flags)
Convert val_int() to date.
Definition: item.cc:1653
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 val_date() in case of errors.
Definition: item.h:2264
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:2875
bool has_aggregation() const
Definition: item.h:3548
virtual bool find_field_processor(uchar *)
Is this an Item_field which references the given Field argument?
Definition: item.h:2911
longlong val_int_from_datetime()
Definition: item.cc:527
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:390
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:8250
bool is_nullable() const
Definition: item.h:3780
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:2252
virtual bool do_itemize(Parse_context *pc, Item **res)
The core function that does the actual itemization.
Definition: item.cc:807
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
static const CHARSET_INFO * default_charset()
Definition: item.cc:1868
virtual bool split_sum_func(THD *, Ref_item_array, mem_root_deque< Item * > *)
Definition: item.h:2576
void init_make_field(Send_field *tmp_field, enum enum_field_types type)
Definition: item.cc:6822
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:3359
String * val_string_from_date(String *str)
Definition: item.cc:346
bool is_non_deterministic() const
Definition: item.h:2514
void set_subquery()
Set the "has subquery" property.
Definition: item.h:3533
void fix_char_length(uint32 max_char_length_arg)
Definition: item.h:3483
void operator=(Item &)=delete
virtual bool is_bool_func() const
Definition: item.h:2659
void mark_subqueries_optimized_away()
Definition: item.h:3591
String * null_return_str()
Gets the value to return from val_str() when returning a NULL value.
Definition: item.h:2299
double val_real_from_decimal()
Definition: item.cc:480
virtual bool disable_constant_propagation(uchar *)
Definition: item.h:3155
Item()
Item constructor for general use.
Definition: item.cc:163
bool has_grouping_set_dep() const
Definition: item.h:3566
uint8 m_data_type
Data type assigned to Item.
Definition: item.h:3760
bool get_time_from_decimal(Time_val *time)
Convert val_decimal() to time.
Definition: item.cc:1777
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:3554
virtual Item * this_item()
Definition: item.h:3257
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:914
bool is_temporal_with_date() const
Definition: item.h:3405
virtual bool strip_db_table_name_processor(uchar *)
Definition: item.h:3644
static Item_result type_to_result(enum_field_types type)
Definition: item.h:1042
virtual table_map used_tables() const
Definition: item.h:2414
String * val_string_from_datetime(String *str)
Definition: item.cc:333
virtual bool equality_substitution_analyzer(uchar **)
Definition: item.h:3094
virtual bool find_item_in_field_list_processor(uchar *)
Definition: item.h:2904
virtual longlong val_date_temporal_at_utc()
Definition: item.h:2390
bool get_datetime_from_non_temporal(Datetime_val *dt, my_time_flags_t flags)
Convert a non-temporal type to datetime.
Definition: item.cc:1726
virtual bool val_date(Date_val *date, my_time_flags_t flags)=0
Evaluate the item and return result as a date value.
virtual bool created_by_in2exists() const
Whether this Item was created by the IN->EXISTS subquery transformation.
Definition: item.h:3589
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:2172
virtual void cleanup()
Called for every Item after use (preparation and execution).
Definition: item.h:1275
virtual Item * real_item()
Definition: item.h:2672
virtual Item * equality_substitution_transformer(uchar *)
Definition: item.h:3096
void set_stored_program()
Set the "has stored program" property.
Definition: item.h:3536
virtual bool eq(const Item *) const
Compare this item with another item for equality.
Definition: item.cc:1526
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:3891
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:3150
bool get_datetime_from_time(Datetime_val *dt)
Convert val_time() to datetime.
Definition: item.cc:1669
uint m_ref_count
Number of references to this item.
Definition: item.h:3757
virtual Field * make_string_field(TABLE *table) const
Create a field to hold a string value from an item.
Definition: item.cc:6944
virtual bool replace_equal_field_checker(uchar **)
Definition: item.h:3162
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:3528
virtual bool check_valid_arguments_processor(uchar *)
Definition: item.h:3168
longlong val_int_from_date()
Definition: item.cc:520
virtual Settable_routine_parameter * get_settable_routine_parameter()
Definition: item.h:3402
virtual Item * equal_fields_propagator(uchar *)
Definition: item.h:3153
bool error_bool()
Get the value to return from val_bool() in case of errors.
Definition: item.h:2228
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:7242
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:2901
virtual bool update_depended_from(uchar *)
Definition: item.h:3078
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:381
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:827
Item_result cmp_context
Comparison context.
Definition: item.h:3739
virtual void allow_array_cast()
A helper function to ensure proper usage of CAST(.
Definition: item.h:3904
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:3284
bool get_time_from_date(Time_val *time)
Convert date to time.
Definition: item.cc:1790
Item(const Item &)=delete
type_conversion_status save_datetime_in_field(Field *field)
Definition: item.cc:569
virtual Item * replace_equal_field(uchar *)
Definition: item.h:3161
virtual Item * element_index(uint)
Definition: item.h:3268
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:964
virtual void traverse_cond(Cond_traverser traverser, void *arg, traverse_order)
Definition: item.h:2809
bool get_time_from_numeric(Time_val *time)
Convert a numeric type to time.
Definition: item.cc:1807
uint float_length(uint decimals_par) const
Definition: item.h:2450
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:6979
virtual Item * copy_andor_structure(THD *)
Definition: item.h:2666
virtual bool val_json(Json_wrapper *result)
Get a JSON value from an Item.
Definition: item.h:2125
virtual longlong val_int()=0
virtual Item_field * field_for_view_update()
Definition: item.h:3277
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:3845
virtual void print(const THD *, String *str, enum_query_type) const
This method is used for to:
Definition: item.h:2538
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:2833
static constexpr uint8 PROP_SUBQUERY
Set of properties that are calculated by accumulation from underlying items.
Definition: item.h:3832
Item_name_string item_name
Name from query.
Definition: item.h:3677
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:1542
bool eq_by_collation(Item *item, const CHARSET_INFO *cs)
Compare two items using a given collation.
Definition: item.cc:6917
void print_item_w_name(const THD *thd, String *, enum_query_type query_type) const
Definition: item.cc:884
virtual String * val_str_ascii(String *str)
Definition: item.cc:275
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:2685
~Item() override=default
virtual bool fix_fields(THD *, Item **)
Definition: item.cc:5464
virtual bool check_column_privileges(uchar *thd)
Check privileges.
Definition: item.h:2970
bool fixed
True if item has been resolved.
Definition: item.h:3769
static bool bit_func_returns_binary(const Item *a, const Item *b)
Definition: item_func.cc:3442
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:2475
longlong val_int_from_time()
Definition: item.cc:511
bool null_value
True if item is null.
Definition: item.h:3806
virtual Item * apply_masking_policy(THD *thd)
Apply column masking policy to this item if applicable.
Definition: item.h:3857
Type
Definition: item.h:964
@ 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:965
@ JSON_ITEM
A JSON literal value.
Definition: item.h:974
@ 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:973
@ 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:968
@ 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:966
@ INT_ITEM
An integer literal value.
Definition: item.h:971
@ FUNC_ITEM
A function call reference.
Definition: item.h:967
@ 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:972
@ 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:969
@ DEFAULT_VALUE_ITEM
A default value for a column.
Definition: item.h:977
@ STRING_ITEM
A string literal value.
Definition: item.h:970
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:3075
virtual Field * tmp_table_field(TABLE *)
Definition: item.h:2408
virtual uint64_t hash()
Generate hash unique to an item depending on its attributes.
Definition: item.h:2550
virtual bool check_cols(uint c)
Definition: item.cc:1462
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:3759
bool is_temporal_with_time() const
Definition: item.h:3411
bool get_datetime_from_string(Datetime_val *dt, my_time_flags_t flags)
Convert val_str() to datetime.
Definition: item.cc:1605
virtual bool visitor_processor(uchar *arg)
A processor to handle the select lex visitor framework.
Definition: item.cc:933
Parse_tree_node super
Definition: item.h:930
virtual Item * replace_item_view_ref(uchar *)
Definition: item.h:3360
bool cleanup_processor(uchar *)
cleanup() item if it is resolved ('fixed').
Definition: item.h:2824
void set_data_type_datetime(uint8 fsp)
Set all properties for Item of DATETIME type.
Definition: item.h:1721
virtual void set_masking_expression_for(const Item_field *masked_item)
Mark this expression as a masking expression for some other expression.
Definition: item.h:3872
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:3240
virtual const CHARSET_INFO * charset_for_protocol()
Definition: item.h:2694
void set_aggregation()
Set the "has aggregation" property.
Definition: item.h:3551
virtual uint time_precision()
TIME precision of the item: 0..6.
Definition: item.cc:852
void delete_self()
Delete this item.
Definition: item.h:3393
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:3822
virtual uint datetime_precision()
DATETIME precision of the item: 0..6.
Definition: item.cc:867
virtual bool send(Protocol *protocol, String *str)
This is only called from items that is not of type item_field.
Definition: item.cc:7932
bool has_compatible_context(Item *item) const
Check whether this and the given item has compatible comparison context.
Definition: item.h:3426
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:3250
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:8120
bool get_datetime_from_int(Datetime_val *dt, my_time_flags_t flags)
Convert val_int() to datetime.
Definition: item.cc:1647
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:2650
Item * next_free
Intrusive list pointer for free list.
Definition: item.h:3665
virtual bool collect_item_field_or_ref_processor(uchar *)
Definition: item.h:2832
virtual bool val_bool()
Definition: item.cc:247
String * error_str()
Get the value to return from val_str() in case of error or NULL value.
Definition: item.h:2289
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:3847
type_conversion_status save_str_value_in_field(Field *field, String *result)
Definition: item.cc:598
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:3211
void set_data_type_vector(uint32 max_l)
Set the data type of the Item to be VECTOR.
Definition: item.h:1745
virtual Item * update_value_transformer(uchar *)
Definition: item.h:3288
virtual Item * replace_outer_ref(uchar *)
Definition: item.h:3362
virtual bool reset_wf_state(uchar *arg)
Reset execution state for such window function types as determined by arg.
Definition: item.h:2946
void set_accum_properties(const Item *item)
Set accumulated properties for an Item.
Definition: item.h:3523
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:3641
virtual bool cast_incompatible_args(uchar *)
Wrap incompatible arguments in CAST nodes to the expected data types.
Definition: item.h:2913
bool get_datetime_from_real(Datetime_val *dt, my_time_flags_t flags)
Convert val_real() to datetime.
Definition: item.cc:1627
virtual longlong val_date_temporal()
Return date value of item in packed longlong format.
Definition: item.cc:437
bool visit_all_analyzer(uchar **)
Definition: item.h:3090
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:2427
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:410
longlong val_temporal_with_round(enum_field_types type, uint8 dec)
Get date or time value in packed longlong format.
Definition: item.cc:449
virtual void compute_cost(CostOfItem *root_cost) const
Compute the cost of evaluating this Item.
Definition: item.h:3650
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:8200
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:2803
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:1880
bool error_time()
Get the value to return from val_time() in case of errors.
Definition: item.h:2276
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:3557
my_decimal * val_decimal_from_real(my_decimal *decimal_value)
Definition: item.cc:371
virtual bool collect_subqueries(uchar *)
Definition: item.h:3077
void aggregate_bit_properties(Item **items, uint nitems)
Set data type and properties of a BIT column.
Definition: item.cc:8418
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:3574
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
bool get_date_from_real(Date_val *date, my_time_flags_t flags)
Convert val_real() to date.
Definition: item.cc:1621
virtual bool null_inside()
Definition: item.h:3272
bool get_time_from_int(Time_val *time)
Convert val_int() to time.
Definition: item.cc:1784
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:3807
virtual bool aggregate_check_group(uchar *)
Definition: item.h:3021
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
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:1908
bool is_outer_reference() const
Definition: item.h:2521
bool get_date_from_string(Date_val *date, my_time_flags_t flags)
Convert val_str() to date.
Definition: item.cc:1613
virtual bool is_null()
The method allows to determine nullness of a complex expression without fully evaluating it,...
Definition: item.h:2631
bool const_for_execution() const
Returns true if item is constant during one query execution.
Definition: item.h:2487
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:8304
longlong val_int_from_string()
Definition: item.cc:541
item_marker
< Values for member 'marker'
Definition: item.h:3696
@ MARKER_FUNC_DEP_NOT_NULL
When analyzing functional dependencies for only_full_group_by (says whether a nullable column can be ...
Definition: item.h:3710
@ MARKER_GROUP_BY_BIT
When creating an internal temporary table: marking group by fields.
Definition: item.h:3707
@ MARKER_TRAVERSAL
Used during traversal to avoid deleting an item twice.
Definition: item.h:3718
@ MARKER_DISTINCT_GROUP
When we change DISTINCT to GROUP BY: used for book-keeping of fields.
Definition: item.h:3713
@ MARKER_IMPLICIT_NE_ZERO
When contextualization or itemization adds an implicit comparison '0<>' (see make_condition()),...
Definition: item.h:3701
@ MARKER_NONE
Definition: item.h:3697
@ MARKER_COND_DERIVED_TABLE
When pushing conditions down to derived table: it says a condition contains only derived table's colu...
Definition: item.h:3716
@ MARKER_CONST_PROPAG
When doing constant propagation (e.g.
Definition: item.h:3704
@ MARKER_ICP_COND_USES_INDEX_ONLY
When pushing index conditions: it says whether a condition uses only indexed columns.
Definition: item.h:3721
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:3200
virtual Item * copy_or_same(THD *)
Definition: item.h:2665
Item_name_string orig_name
Original item name (if it was renamed)
Definition: item.h:3678
virtual bool collect_grouped_aggregates(uchar *)
Definition: item.h:3076
virtual bool clean_up_after_removal(uchar *arg)
Clean up after removing the item from the item tree.
Definition: item.cc:8187
virtual cond_result eq_cmp_result() const
Definition: item.h:2449
bool get_time_from_non_temporal(Time_val *time)
Convert a non-temporal type to time.
Definition: item.cc:1830
uint32 max_char_length(const CHARSET_INFO *cs) const
Definition: item.h:3476
virtual Item * explain_subquery_propagator(uchar *)
Definition: item.h:3151
virtual void update_used_tables()
Updates used tables, not null tables information and accumulates properties up the item tree,...
Definition: item.h:2574
virtual bool aggregate_check_distinct(uchar *)
Definition: item.h:3019
bool evaluate(THD *thd, String *str)
Evaluate scalar item, possibly using the supplied buffer.
Definition: item.cc:8040
void set_wf()
Set the "has window function" property.
Definition: item.h:3560
virtual bool returns_array() const
Whether the item returns array of its data type.
Definition: item.h:3899
virtual void make_field(Send_field *field)
Definition: item.cc:6843
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:2403
virtual bool is_outer_field() const
Definition: item.h:3491
void set_grouping_func()
Set the property: this item is a call to GROUPING.
Definition: item.h:3586
virtual void set_result_field(Field *)
Definition: item.h:2656
bool is_abandoned() const
Definition: item.h:3652
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:2719
type_conversion_status save_time_in_field(Field *field)
Definition: item.cc:551
item_marker marker
This member has several successive meanings, depending on the phase we're in (.
Definition: item.h:3738
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:3023
virtual bool intro_version(uchar *)
Definition: item.h:2821
bool m_abandoned
true if item has been fully de-referenced
Definition: item.h:3758
virtual bool inform_item_in_cond_of_tab(uchar *)
Definition: item.h:2973
bool get_datetime_from_date(Datetime_val *dt, my_time_flags_t flags)
Convert val_date() to datetime.
Definition: item.cc:1679
static constexpr uint8 PROP_STORED_PROGRAM
Definition: item.h:3833
virtual const Item * real_item() const
Definition: item.h:2673
bool is_temporal() const
Definition: item.h:3414
bool is_temporal_with_date_and_time() const
Definition: item.h:3408
virtual const char * full_name() const
Definition: item.h:2409
auto walk_helper_thunk(uchar *arg)
Definition: item.h:2727
void set_data_type_null()
Definition: item.h:1517
uint8 decimals
Number of decimals in result when evaluating this item.
Definition: item.h:3778
virtual bool val_datetime(Datetime_val *dt, my_time_flags_t flags)=0
Evaluate the item and return result as a datetime value.
virtual Item ** addr(uint)
Definition: item.h:3269
virtual Item * clone_item() const
Definition: item.h:2448
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 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:3515
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:1560
virtual bool find_item_processor(uchar *arg)
Definition: item.h:2906
virtual void no_rows_in_result()
Definition: item.h:2664
virtual bool add_field_to_set_processor(uchar *)
Item::walk function.
Definition: item.h:2883
virtual bool add_field_to_cond_set_processor(uchar *)
Item::walk function.
Definition: item.h:2892
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:3229
uint reference_count() const
Definition: item.h:3506
bool get_time_from_real(Time_val *time)
Convert val_real() to time.
Definition: item.cc:1771
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:3350
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:7210
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:3191
virtual bool is_splocal() const
Definition: item.h:3396
virtual bool val_time(Time_val *time)=0
Evaluate the item and return result as a time value.
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:6866
virtual bool replace_field_processor(uchar *)
A processor that replaces any Fields with a Create_field_wrapper.
Definition: item.h:3611
virtual bool update_aggr_refs(uchar *)
A walker processor overridden by Item_aggregate_ref, q.v.
Definition: item.h:3374
virtual void disable_masking_policy()
Disable application of the masking policy to this item.
Definition: item.h:3866
bool get_date_from_time(Date_val *date)
Convert val_time() to date.
Definition: item.cc:1659
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:1454
bool aggregate_type(const char *name, Item **items, uint count)
Aggregates data types from array of items into current item.
Definition: item.cc:639
virtual Item * replace_aggregate(uchar *)
Definition: item.h:3361
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:3803
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:3358
virtual bool mark_field_in_map(uchar *arg)
Mark underlying field in read or write map of a table.
Definition: item.h:2919
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:2436
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:3817
virtual bool get_timeval(my_timeval *tm, int *warnings)
Get timestamp in "struct timeval" format.
Definition: item.cc:1853
bool m_is_window_function
True if item represents window func.
Definition: item.h:3808
bool may_eval_const_item(const THD *thd) const
Definition: item.cc:238
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
bool get_datetime_from_decimal(Datetime_val *dt, my_time_flags_t flags)
Convert val_decimal() to datetime.
Definition: item.cc:1640
static bool mark_field_in_map(Mark_field *mark_field, Field *field)
Helper function for mark_field_in_map(uchar *arg).
Definition: item.h:2928
Item * cache_const_expr_transformer(uchar *item)
Cache item if needed.
Definition: item.cc:8435
String * val_string_from_time(String *str)
Definition: item.cc:360
virtual Item ** this_item_addr(THD *, Item **addr_arg)
Definition: item.h:3264
virtual bool is_result_field() const
Definition: item.h:2657
virtual const Item * this_item() const
Definition: item.h:3258
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:8284
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:953
virtual enum_monotonicity_info get_monotonicity_info() const
Definition: item.h:1834
virtual bool collect_item_field_processor(uchar *)
Definition: item.h:2831
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:3088
uint32 max_length
Maximum length of result of evaluating this item, in number of bytes.
Definition: item.h:3694
bool get_date_from_numeric(Date_val *date, my_time_flags_t flags)
Convert a numeric type to date.
Definition: item.cc:1689
bool get_date_from_decimal(Date_val *date, my_time_flags_t flags)
Convert val_decimal() to date.
Definition: item.cc:1633
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:3835
auto analyze_helper_thunk(uchar **arg)
See CompileItem.
Definition: item.h:2733
double val_real_from_string()
Definition: item.cc:491
bool update_null_value()
Make sure the null_value member has a correct value.
Definition: item.cc:8021
virtual bool gc_subst_analyzer(uchar **)
Analyzer function for GC substitution.
Definition: item.h:3599
void rename(char *new_name)
rename item (used for views, cleanup() return original name).
Definition: item.cc:944
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:8360
virtual bool is_column_not_in_fd(uchar *)
Definition: item.h:3025
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:3267
virtual Item * gc_subst_transformer(uchar *)
Transformer function for GC substitution.
Definition: item.h:3603
virtual Bool3 local_column(const Query_block *) const
Definition: item.h:3026
virtual void bring_value()
Definition: item.h:3274
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:3766
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:2962
my_decimal * val_decimal_from_time(my_decimal *decimal_value)
Definition: item.cc:421
virtual Item_result cast_to_int_type() const
Definition: item.h:1824
type_conversion_status save_date_in_field(Field *field)
Definition: item.cc:560
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:2460
bool get_time_from_string(Time_val *time)
Convert val_str() to time.
Definition: item.cc:1763
String * val_string_from_real(String *str)
Definition: item.cc:292
virtual bool is_non_const_over_literals(uchar *)
Definition: item.h:2907
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:3581
virtual void save_org_in_field(Field *field)
Definition: item.h:1431
static constexpr uint8 PROP_AGGREGATION
Definition: item.h:3834
virtual Field * get_result_field() const
Definition: item.h:2658
longlong int_sort_key()
Produces a key suitable for filesort.
Definition: item.h:1914
int decimal_int_part() const
Definition: item.h:2455
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:322
virtual bool check_partition_func_processor(uchar *)
Check if a partition function is allowed.
Definition: item.h:3145
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:3840
virtual void bind_fields()
Bind objects from the current execution context to field objects in item trees.
Definition: item.h:2979
bool get_date_from_non_temporal(Date_val *date, my_time_flags_t flags)
Convert a non-temporal type to date.
Definition: item.cc:1745
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1268
Definition: sql_list.h:494
Class used as argument to Item::walk() together with mark_field_in_map()
Definition: item.h:261
Mark_field(TABLE *table, enum_mark_columns mark)
Definition: item.h:263
Mark_field(enum_mark_columns mark)
Definition: item.h:264
TABLE *const table
If == NULL, update map of any table.
Definition: item.h:270
const enum_mark_columns mark
How to mark the map.
Definition: item.h:272
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:432
Definition: item.h:518
Table_ref * save_next_local
Definition: item.h:524
void save_state(Name_resolution_context *context, Table_ref *table_list)
Definition: item.h:528
Table_ref * save_next_name_resolution_table
Definition: item.h:522
void update_next_local(Table_ref *table_list)
Definition: item.h:545
Table_ref * get_first_name_resolution_table()
Definition: item.h:549
Table_ref * save_table_list
Definition: item.h:520
bool save_resolve_in_select_list
Definition: item.h:523
Table_ref * save_first_name_resolution_table
Definition: item.h:521
void restore_state(Name_resolution_context *context, Table_ref *table_list)
Definition: item.h:537
Storage for name strings.
Definition: item.h:297
void copy(const char *str)
Definition: item.h:334
Name_string(const char *str, size_t length)
Definition: item.h:313
void copy(const LEX_STRING lex)
Definition: item.h:337
void set_or_copy(const char *str, size_t length, bool is_null_terminated)
Definition: item.h:299
bool eq_safe(const Name_string name) const
Definition: item.h:352
Name_string(const LEX_STRING str, bool is_null_terminated)
Definition: item.h:320
bool eq_safe(const char *str) const
Definition: item.h:347
Name_string(const LEX_STRING str)
Definition: item.h:314
Name_string()
Definition: item.h:307
bool eq(const char *str) const
Compare name to another name in C string, case insensitively.
Definition: item.h:343
void copy(const char *str, size_t length)
Variants for copy(), for various argument combinations.
Definition: item.h:331
Name_string(const LEX_CSTRING str)
Definition: item.h:315
Name_string(const char *str, size_t length, bool is_null_terminated)
Definition: item.h:316
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:1472
bool eq(const Name_string name) const
Compare name to another name in Name_string, case insensitively.
Definition: item.h:351
void copy(const Name_string str)
Definition: item.h:339
void copy(const LEX_STRING *lex)
Definition: item.h:338
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:400
bool begin_parse_tree(Show_parse_tree *tree)
Definition: parse_tree_node_base.h:385
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:1179
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:4555
bool field
Definition: field.h:4568
Definition: item.h:663
virtual void set_out_param_info(Send_field *info)
Definition: item.h:695
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:676
virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)=0
virtual const Send_field * get_out_param_info() const
Definition: item.h:697
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:169
bool append(const String &s)
Definition: sql_string.cc:419
const CHARSET_INFO * charset() const
Definition: sql_string.h:242
void set_charset(const CHARSET_INFO *charset_arg)
Definition: sql_string.h:241
const char * ptr() const
Definition: sql_string.h:251
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:249
size_t length() const
Definition: sql_string.h:243
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:304
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:2958
Table_ref * outer_join_nest() const
Returns the outer join nest that this Table_ref belongs to, if any.
Definition: table.h:3564
table_map map() const
Return table map derived from table number.
Definition: table.h:4153
bool is_view() const
Return true if this represents a named view.
Definition: table.h:3220
bool is_inner_table_of_outer_join() const
Return true if this table is an inner table of some outer join.
Definition: table.h:3579
bool outer_join
True if right argument of LEFT JOIN; false in other cases (i.e.
Definition: table.h:3974
Table_ref * next_local
Definition: table.h:3664
Table_ref * any_outer_leaf_table()
Return any leaf table that is not an inner table of an outer join.
Definition: table.h:3405
TABLE * table
Definition: table.h:3747
Table_ref * next_name_resolution_table
Definition: table.h:3744
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
Time_val is a temporal type that represents only time.
Definition: my_temporal.h:57
int64_t for_comparison() const
Definition: my_temporal.h:118
Type properties, used to collect type information for later assignment to an Item object.
Definition: item.h:626
const uint32 m_max_length
Definition: item.h:657
const bool m_unsigned_flag
Definition: item.h:656
const DTCollation m_collation
Definition: item.h:658
Type_properties(enum_field_types type_arg)
Constructor for any signed numeric type or date type Defaults are provided for attributes like signed...
Definition: item.h:630
Type_properties(enum_field_types type_arg, const CHARSET_INFO *charset)
Constructor for character type, with explicit character set.
Definition: item.h:648
Type_properties(enum_field_types type_arg, bool unsigned_arg)
Constructor for any numeric type, with explicit signedness.
Definition: item.h:638
const enum_field_types m_type
Definition: item.h:655
Class used as argument to Item::walk() together with used_tables_for_level()
Definition: item.h:278
Used_tables(Query_block *select)
Definition: item.h:280
table_map used_tables
Accumulated used tables data.
Definition: item.h:283
Query_block *const select
Level for which data is accumulated.
Definition: item.h:282
Definition: item_cmpfunc.h:1921
Definition: mem_root_deque.h:366
A (partial) implementation of std::deque allocating its blocks on a MEM_ROOT.
Definition: mem_root_deque.h:172
iterator begin()
Definition: mem_root_deque.h:517
iterator end()
Definition: mem_root_deque.h:518
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:97
uint precision() const
Definition: my_decimal.h:135
bool sign() const
Definition: my_decimal.h:133
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:3167
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:149
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:161
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:139
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:180
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:201
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:217
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:580
@ NON_MONOTONIC
Definition: item.h:581
@ MONOTONIC_STRICT_INCREASING
Definition: item.h:584
@ MONOTONIC_INCREASING_NOT_NULL
Definition: item.h:583
@ MONOTONIC_INCREASING
Definition: item.h:582
@ MONOTONIC_STRICT_INCREASING_NOT_NULL
Definition: item.h:585
Item * GetNthVisibleField(const mem_root_deque< Item * > &fields, size_t index)
Definition: item.h:7619
constexpr float COND_FILTER_STALE_NO_CONST
A special subcase of the above:
Definition: item.h:143
constexpr uint16 NO_FIELD_INDEX((uint16)(-1))
std::string ItemToString(const Item *item, enum_query_type q_type)
Definition: item.cc:11767
bool agg_item_charsets(DTCollation &c, const char *name, Item **items, uint nitems, uint flags)
Definition: item.cc:3011
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:3921
Bounds_checked_array< Item * > Ref_item_array
Definition: item.h:99
Item * TransformItem(Item *item, T &&transformer)
Same as WalkItem, but for Item::transform().
Definition: item.h:3967
#define MY_COLL_ALLOW_NONE
Definition: item.h:178
#define ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT
Max length of an Item string for its use in an error message.
Definition: item.h:364
Item_result numeric_context_result_type(enum_field_types data_type, Item_result result_type, uint8 decimals)
Definition: item.h:151
bool WalkItem(Item *item, enum_walk walk, T &&functor)
A helper class to give in a functor to Item::walk().
Definition: item.h:3932
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_charsets_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems)
Definition: item.h:4239
Item * CompileItem(Item *item, T &&analyzer, U &&transformer)
Same as WalkItem, but for Item::compile().
Definition: item.h:3954
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:11869
bool agg_item_charsets_for_string_result(DTCollation &c, const char *name, Item **items, uint nitems)
Definition: item.h:4232
size_t CountHiddenFields(const mem_root_deque< Item * > &fields)
Definition: item.h:7614
constexpr float COND_FILTER_EQUALITY
Filtering effect for equalities: col1 = col2.
Definition: item.h:116
static uint32 char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg)
Definition: item.h:145
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:11602
bool(Item::* Item_analyzer)(uchar **argp)
Definition: item.h:711
Item_field * FindEqualField(Item_field *item_field, table_map reachable_tables, bool replace, bool *found)
Definition: item.cc:11820
enum monotonicity_info enum_monotonicity_info
void item_init(void)
Init all special items.
Definition: item.cc:158
size_t CountVisibleFields(const mem_root_deque< Item * > &fields)
Definition: item.h:7609
constexpr float COND_FILTER_STALE
Value is out-of-date, will need recalculation.
Definition: item.h:127
bool convert_const_strings(DTCollation &coll, Item **args, uint nargs)
Convert constant strings according to a specific character set/collation.
Definition: item.cc:2925
bool agg_item_collations_for_comparison(DTCollation &c, const char *name, Item **items, uint nitems)
Aggregate collations for items used in a comparison operations.
Definition: item.cc:2905
Item_result item_cmp_type(Item_result a, Item_result b)
Definition: item.cc:9977
void(* Cond_traverser)(const Item *item, void *arg)
Definition: item.h:721
Item *(Item::* Item_transformer)(uchar *arg)
Type for transformers used by Item::transform and Item::compile.
Definition: item.h:720
std::string ItemToQuerySubstrNoCharLimit(const Item *item)
#define NAME_STRING(x)
Definition: item.h:357
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:6118
constexpr float COND_FILTER_BETWEEN
Filtering effect for between: col1 BETWEEN a AND b.
Definition: item.h:120
constexpr float COND_FILTER_ALLPASS
Default condition filtering (selectivity) values used by get_filtering_effect() and friends when bett...
Definition: item.h:114
const String my_null_string
void SafeIncrement(T *num)
Increment *num if it is less than its maximal value.
Definition: item.h:780
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:11873
double double_from_string_with_check(const CHARSET_INFO *cs, const char *cptr, const char *end)
Definition: item.cc:3889
#define MY_COLL_ALLOW_NUMERIC_CONV
Definition: item.h:179
constexpr float COND_FILTER_INEQUALITY
Filtering effect for inequalities: col1 > col2.
Definition: item.h:118
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:10138
#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:10002
std::string ItemToQuerySubstr(const Item *item, const LEX *lex=nullptr, uint32 char_limit=ITEM_TO_QUERY_SUBSTRING_CHAR_LIMIT)
Definition: item.cc:11809
#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:799
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:1578
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:85
void my_decimal_neg(decimal_t *arg)
Definition: my_decimal.h:338
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:71
uint32 my_decimal_precision_to_length_no_truncation(uint precision, uint8 scale, bool unsigned_flag)
Definition: my_decimal.h:193
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
Server classes for temporal handling (DATE, TIME, DATETIME)
Interface for low level time utilities.
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:146
unsigned int my_time_flags_t
Flags to str_to_datetime and int_to_datetime.
Definition: my_time.h:87
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:1077
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:76
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
std::string_view type_name()
Return the name of the given type (not demangled).
Definition: object_lifetime_tracker.h:57
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::map< Key, Value, Compare, ut::allocator< std::pair< const Key, Value > > > map
Specialization of map which uses ut_allocator.
Definition: ut0new.h:2898
#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
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:176
@ DERIVATION_COERCIBLE
Definition: field.h:180
@ DERIVATION_SYSCONST
Definition: field.h:181
@ DERIVATION_EXPLICIT
Definition: field.h:184
@ DERIVATION_NONE
Definition: field.h:177
@ DERIVATION_NUMERIC
Definition: field.h:179
@ DERIVATION_NULL
Definition: field.h:178
@ DERIVATION_IMPLICIT
Definition: field.h:182
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:2866
Struct used to pass around arguments to/from check_function_as_value_generator.
Definition: item.h:487
int err_code
the error code found during check(if any)
Definition: item.h:494
int col_index
the order of the column in table
Definition: item.h:492
const char * banned_function_name
the name of the function which is not allowed
Definition: item.h:501
Value_generator_source source
Definition: item.h:499
int get_unnamed_function_error_code() const
Return the correct error code, based on whether or not if we are checking for disallowed functions in...
Definition: item.h:506
Check_function_as_value_generator_parameters(int default_error_code, Value_generator_source val_gen_src)
Definition: item.h:488
This class represents a subquery contained in some subclass of Item_subselect,.
Definition: item.h:861
Strategy strategy
The strategy for executing the subquery.
Definition: item.h:895
Strategy
The strategy for executing the subquery.
Definition: item.h:863
@ 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:892
int row_width
The width (in bytes) of the subquery's rows.
Definition: item.h:901
The current state of the privilege checking process for the current user, SQL statement and SQL objec...
Definition: table.h:384
Definition: item.h:3364
Aggregate_ref_update(Item_sum *target, Query_block *owner)
Definition: item.h:3367
Query_block * m_owner
Definition: item.h:3366
Item_sum * m_target
Definition: item.h:3365
Definition: item.h:3337
Aggregate_replacement(Item_sum *target, Item_field *replacement)
Definition: item.h:3340
Item_field * m_replacement
Definition: item.h:3339
Item_sum * m_target
Definition: item.h:3338
Context struct used by walk method collect_scalar_subqueries to accumulate information about scalar s...
Definition: item.h:3062
Item * m_join_condition_context
Definition: item.h:3068
Location
Definition: item.h:3063
@ L_JOIN_COND
Definition: item.h:3063
@ L_HAVING
Definition: item.h:3063
@ L_SELECT
Definition: item.h:3063
@ L_WHERE
Definition: item.h:3063
bool m_collect_unconditionally
Definition: item.h:3069
int8 m_location
we are currently looking at this kind of clause, cf. enum Location
Definition: item.h:3067
std::vector< Css_info > m_list
accumulated all scalar subqueries found
Definition: item.h:3065
Minion class under Collect_scalar_subquery_info ("Css").
Definition: item.h:3034
int8 m_locations
set of locations
Definition: item.h:3036
Item * m_join_condition
Where did we find item above? Used when m_location == L_JOIN_COND, nullptr for other locations.
Definition: item.h:3042
bool m_add_coalesce
If true, add a COALESCE around replaced subquery: used for implicitly grouped COUNT() in subquery sel...
Definition: item.h:3047
table_map m_correlation_map
Definition: item.h:3039
uint m_having_idx
Index of the having expression copied to select list.
Definition: item.h:3052
Item_singlerow_subselect * item
the scalar subquery
Definition: item.h:3038
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:3050
bool m_implicitly_grouped_and_no_union
If true, we can forego cardinality checking of the derived table.
Definition: item.h:3044
Definition: item.h:3298
Mode m_default_value
Definition: item.h:3308
Item_field * m_outer_field
Definition: item.h:3302
Field * m_target
The field to be replaced.
Definition: item.h:3299
Item_field_replacement(Field *target, Item_field *item, Query_block *select, Mode default_value=Mode::CONFLATE)
Definition: item.h:3309
Mode
Definition: item.h:3303
Item_field * m_item
The replacement field replacement field iff outer ref.
Definition: item.h:3300
Definition: item.h:3317
Item_func * m_target
The function call to be replaced.
Definition: item.h:3318
Item_func_call_replacement(Item_func *func_target, Item_field *item, Query_block *select)
Definition: item.h:3320
Item_field * m_item
The replacement field.
Definition: item.h:3319
Definition: item.h:3290
Item_replacement(Query_block *transformed_block, Query_block *current_block)
Definition: item.h:3295
Query_block * m_curr_block
Transformed query block or a contained.
Definition: item.h:3292
Query_block * m_trans_block
Transformed query block.
Definition: item.h:3291
Definition: item.h:3327
Item * m_target
The item identifying the view_ref to be replaced.
Definition: item.h:3328
Field * m_field
The replacement field.
Definition: item.h:3329
Item_view_ref_replacement(Item *target, Field *field, Query_block *select)
Definition: item.h:3333
Item_field * m_outer_field
replacement field if outer ref
Definition: item.h:3330
Definition: item.h:3157
List< Item_func > stack
Definition: item.h:3159
< Argument object to change_context_processor
Definition: item.h:4461
Name_resolution_context * m_context
Definition: item.h:4462
Change_context(Name_resolution_context *context)
Definition: item.h:4463
Argument structure for walk processor Item::update_depended_from.
Definition: item.h:4478
Query_block * old_depended_from
Definition: item.h:4479
Query_block * new_depended_from
Definition: item.h:4480
The LEX object currently serves three different purposes:
Definition: sql_lex.h:4002
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: 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:414
Name_resolution_context * next_context
Link to next name res context with the same query block as the base.
Definition: item.h:421
Table_ref * view_error_handler_arg
Definition: item.h:459
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:419
Security_context * security_ctx
Security context of this name resolution context.
Definition: item.h:475
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:439
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:444
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:451
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:469
bool view_error_handler
Definition: item.h:458
Table_ref * table_list
List of tables used to resolve the items of this context.
Definition: item.h:431
void resolve_in_table_list_only(Table_ref *tables)
Definition: item.h:477
Environment data for the contextualization phase.
Definition: parse_tree_node_base.h:422
Definition: table.h:1456
const char * alias
alias or table name
Definition: table.h:1708
bool has_null_row() const
Definition: table.h:2228
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:1791
bool alias_name_used
Definition: table.h:1917
bool is_nullable() const
Return whether table is nullable.
Definition: table.h:2130
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:3913
Item * cache_item
Item to cache. Used as a binary flag, but kept as Item* for assertion.
Definition: item.h:3918
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:3916
Item::enum_const_item_cache cache_arg
How to cache JSON data.
Definition: item.h:3920
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