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