MySQL 9.7.0
Source Code Documentation
field.h
Go to the documentation of this file.
1#ifndef FIELD_INCLUDED
2#define FIELD_INCLUDED
3
4/* Copyright (c) 2000, 2026, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include <assert.h>
28#include <limits.h>
29#include <stddef.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33#include <sys/types.h>
34
35#include <algorithm>
36#include <optional>
37
38#include "decimal.h" // E_DEC_OOM
39#include "field_types.h" // enum_field_types
40#include "lex_string.h"
41#include "my_alloc.h"
42#include "my_base.h" // ha_storage_media
43#include "my_bitmap.h"
44#include "my_dbug.h"
45#include "my_double2ulonglong.h"
46#include "my_inttypes.h"
47#include "my_temporal.h"
48#include "my_time.h" // MYSQL_TIME_NOTE_TRUNCATED
49#include "mysql/binlog/event/export/binary_log_funcs.h" // my_time_binary_length
50#include "mysql/strings/dtoa.h"
53#include "mysql_com.h"
54#include "mysql_time.h"
55#include "sql/dd/types/column.h"
57#include "sql/gis/srid.h"
58#include "sql/sql_bitmap.h"
59#include "sql/sql_const.h"
60#include "sql/sql_error.h" // Sql_condition
61#include "sql/system_variables.h" // MODE_NO_ZERO_DATE, etc
62#include "sql/table.h"
63#include "sql_string.h" // String
64#include "template_utils.h"
65#include "vector-common/vector_constants.h" // max_dimensions
66
67using sql_mode_t = uint64_t;
68
69class Create_field;
70class CostOfItem;
71class Field;
72class Field_bit;
74class Field_blob;
75class Field_decimal;
76class Field_double;
77class Field_enum;
78class Field_float;
79class Field_json;
80class Field_long;
81class Field_longlong;
82class Field_medium;
84class Field_date;
85class Field_num;
86class Field_real;
87class Field_set;
88class Field_short;
89class Field_str;
90class Field_string;
91class Field_temporal;
94class Field_time;
95class Field_timestamp;
96class Field_tiny;
97class Field_varstring;
98class Field_year;
99class Item;
100class Item_field;
101class Json_array;
102class Json_diff_vector;
103class Json_wrapper;
104class KEY;
105class Protocol;
106class Relay_log_info;
107class Send_field;
108class THD;
109class Time_zone;
110class my_decimal;
111struct my_timeval;
112struct TYPELIB;
113
114/*
115 Inside an in-memory data record, memory pointers to pieces of the
116 record (like BLOBs) are stored in their native byte order and in
117 this amount of bytes.
118*/
119#define portable_sizeof_char_ptr 8
120
121/*
122
123Field class hierarchy
124
125
126Field (abstract)
127|
128+--Field_bit
129| +--Field_bit_as_char
130|
131+--Field_num (abstract)
132| | +--Field_real (abstract)
133| | +--Field_decimal
134| | +--Field_float
135| | +--Field_double
136| |
137| +--Field_new_decimal
138| +--Field_short
139| +--Field_medium
140| +--Field_long
141| +--Field_longlong
142| +--Field_tiny
143| +--Field_year
144|
145+--Field_str (abstract)
146| +--Field_longstr
147| | +--Field_string
148| | +--Field_varstring
149| | +--Field_blob
150| | +--Field_geom
151| | +--Field_json
152| | +--Field_typed_array
153| | +--Field_vector
154| |
155| +--Field_null
156| +--Field_enum
157| +--Field_set
158|
159+--Field_temporal (abstract)
160 +--Field_time
161 |
162 +--Field_temporal_with_date (abstract)
163 +--Field_date
164 +--Field_temporal_with_date_and_time (abstract)
165 +--Field_timestamp
166 +--Field_datetime
167*/
168
174
175/// For use @see DTCollation::aggregate()
183 DERIVATION_UNUSED = 1, // Avoids changes in COERCIBILITY() results
186
187/* Specifies data storage format for individual columns */
189 COLUMN_FORMAT_TYPE_DEFAULT = 0, /* Not specified (use engine default) */
190 COLUMN_FORMAT_TYPE_FIXED = 1, /* FIXED format */
191 COLUMN_FORMAT_TYPE_DYNAMIC = 2 /* DYNAMIC format */
193
194/**
195 Status when storing a value in a field or converting from one
196 datatype to another. The values should be listed in order of
197 increasing seriousness so that if two type_conversion_status
198 variables are compared, the bigger one is most serious.
199*/
201 /// Storage/conversion went fine.
203 /**
204 A minor problem when converting between temporal values, e.g.
205 if datetime is converted to date the time information is lost.
206 */
208 /**
209 Value was stored, but something was cut. What was cut is
210 considered insignificant enough to only issue a note. Example:
211 trying to store a number with 5 decimal places into a field that
212 can only store 3 decimals. The number rounded to 3 decimal places
213 should be stored. Another example: storing the string "foo " into
214 a VARCHAR(3). The string "foo" is stored in this case, so only
215 whitespace is cut.
216 */
218 /**
219 Value outside min/max limit of datatype. The min/max value is
220 stored by Field::store() instead (if applicable)
221 */
223 /**
224 Value was stored, but something was cut. What was cut is
225 considered significant enough to issue a warning. Example: storing
226 the string "foo" into a VARCHAR(2). The string "fo" is stored in
227 this case. Another example: storing the string "2010-01-01foo"
228 into a DATE. The garbage in the end of the string is cut in this
229 case.
230 */
232 /**
233 Value has invalid string data. When present in a predicate with
234 equality operator, range optimizer returns an impossible where.
235 */
237 /// Trying to store NULL in a NOT NULL field.
239 /**
240 Store/convert incompatible values, like converting "foo" to a
241 date.
242 */
244 /// Out of memory
247
248/*
249 Some defines for exit codes for ::is_equal class functions.
250*/
251#define IS_EQUAL_NO 0
252#define IS_EQUAL_YES 1
253#define IS_EQUAL_PACK_LENGTH 2
254
255#define my_charset_numeric my_charset_latin1
256#define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII
257
258/**
259 Check if one can copy from “from” to “to” with a simple memcpy(), with
260 pack_length() as the length. This is the case if the types of the two fields
261 are the same and we don't have special copying rules for the type
262 (e.g., blobs, which require allocation, or time functions that require
263 checking for special SQL modes).
264
265 You should never call this with to == from, as such copies are no-ops
266 and memcpy() has undefined behavior with overlapping memory areas.
267 */
268bool fields_are_memcpyable(const Field *to, const Field *from);
269
270/**
271 Copy the value in "from" (assumed to be non-NULL) to "to", doing any
272 required conversions in the process.
273
274 Note that you should only call this if fields_are_memcpyable() is false,
275 since it does an actual conversion on the slow path (and it is not properly
276 tested whether it gives the correct result in all cases if
277 fields_are_memcpyable() is true).
278
279 You should never call this with to == from, as they are no-ops.
280 */
282
283inline uint get_enum_pack_length(int elements) {
284 return elements < 256 ? 1 : 2;
285}
286
287inline uint get_set_pack_length(int elements) {
288 const uint len = (elements + 7) / 8;
289 return len > 4 ? 8 : len;
290}
291
293 if (dec_error & E_DEC_OOM) return TYPE_ERR_OOM;
294
295 if (dec_error & (E_DEC_DIV_ZERO | E_DEC_BAD_NUM)) return TYPE_ERR_BAD_VALUE;
296
297 if (dec_error & E_DEC_TRUNCATED) return TYPE_NOTE_TRUNCATED;
298
299 if (dec_error & E_DEC_OVERFLOW) return TYPE_WARN_OUT_OF_RANGE;
300
301 if (dec_error == E_DEC_OK) return TYPE_OK;
302
303 // impossible
304 assert(false);
305 return TYPE_ERR_BAD_VALUE;
306}
307
308/**
309 Convert warnings returned from str_to_time() and str_to_datetime()
310 to their corresponding type_conversion_status codes.
311*/
313 const int warn) {
315
317
319
321 return TYPE_ERR_BAD_VALUE;
322
324 // date was fine but pointed to daylight saving time switch gap
325 return TYPE_OK;
326
327 assert(!warn);
328 return TYPE_OK;
329}
330
331#define ASSERT_COLUMN_MARKED_FOR_READ \
332 assert(!table || \
333 (!table->read_set || bitmap_is_set(table->read_set, field_index())))
334#define ASSERT_COLUMN_MARKED_FOR_WRITE \
335 assert(!table || (!table->write_set || \
336 bitmap_is_set(table->write_set, field_index())))
337
338/**
339 Tests if field real type is temporal, i.e. represents
340 all existing implementations of
341 DATE, TIME, DATETIME or TIMESTAMP types in SQL.
342
343 @param type Field real type, as returned by field->real_type()
344 @retval true If field real type is temporal
345 @retval false If field real type is not temporal
346*/
348 switch (type) {
349 case MYSQL_TYPE_TIME2:
352 return true;
353 default:
354 return is_temporal_type(type);
355 }
356}
357
358/**
359 Tests if field real type can have "DEFAULT CURRENT_TIMESTAMP",
360 i.e. represents TIMESTAMP types in SQL.
361
362 @param type Field type, as returned by field->real_type().
363 @retval true If field real type can have "DEFAULT CURRENT_TIMESTAMP".
364 @retval false If field real type can not have "DEFAULT CURRENT_TIMESTAMP".
365*/
369}
370
371/**
372 Tests if field real type can have "ON UPDATE CURRENT_TIMESTAMP",
373 i.e. represents TIMESTAMP types in SQL.
374
375 @param type Field type, as returned by field->real_type().
376 @retval true If field real type can have "ON UPDATE CURRENT_TIMESTAMP".
377 @retval false If field real type can not have "ON UPDATE CURRENT_TIMESTAMP".
378*/
382}
383
384/**
385 Convert temporal real types as returned by field->real_type()
386 to field type as returned by field->type().
387
388 @param real_type Real type.
389 @retval Field type.
390*/
392 switch (real_type) {
393 case MYSQL_TYPE_TIME2:
394 return MYSQL_TYPE_TIME;
396 return MYSQL_TYPE_DATETIME;
400 return MYSQL_TYPE_DATE;
401 /* Note: NEWDECIMAL is a type, not only a real_type */
402 default:
403 return real_type;
404 }
405}
406
407/**
408 Return the appropriate MYSQL_TYPE_X_BLOB value based on the
409 pack_length.
410
411 @param pack_length pack_length for BLOB
412 @retval MYSQL_TYPE_X_BLOB corresponding to pack_length.
413*/
416 switch (pack_length) {
417 case 1:
419 case 2:
420 return MYSQL_TYPE_BLOB;
421 case 3:
423 case 4:
425 default:
426 assert(false);
428 }
429}
430
431/**
432 Copies an integer value to a format comparable with memcmp(). The
433 format is characterized by the following:
434
435 - The sign bit goes first and is unset for negative values.
436 - The representation is big endian.
437
438 The function template can be instantiated to copy from little or
439 big endian values.
440
441 @tparam Is_big_endian True if the source integer is big endian.
442
443 @param to Where to write the integer.
444 @param to_length Size in bytes of the destination buffer.
445 @param from Where to read the integer.
446 @param from_length Size in bytes of the source integer
447 @param is_unsigned True if the source integer is an unsigned value.
448*/
449template <bool Is_big_endian>
450void copy_integer(uchar *to, size_t to_length, const uchar *from,
451 size_t from_length, bool is_unsigned) {
452 if (to_length == 0) return;
453 if (Is_big_endian) {
454 std::copy(from, from + std::min(to_length, from_length), to);
455 if (!is_unsigned)
456 to[0] = static_cast<char>(to[0] ^ 128); // Reverse the sign bit.
457 } else {
458 const uchar *from_end = from + from_length;
459 const uchar *from_start = from_end - std::min(from_length, to_length);
460 std::reverse_copy(from_start, from_end, to);
461 if (!is_unsigned)
462 to[0] = static_cast<char>(to[0] ^ 128); // Reverse the sign bit.
463 }
464}
465
466/**
467 Enum to indicate source for which value generator is used. This is needed
468 while unpacking value generator expression and pre-validating the
469 expression for generated column, default expression or check constraint.
470*/
472 VGS_GENERATED_COLUMN = 0, // Value generator for GENERATED_COLUMN.
473 VGS_DEFAULT_EXPRESSION, // Value generator for Default expression.
474 VGS_CHECK_CONSTRAINT // Value generator for check constraints.
476
477/**
478 Used for storing information associated with generated column, default
479 values generated from expression or check constraint expression.
480*/
482 public:
483 /**
484 Item representing the generation expression.
485 This is non-NULL for every Field of a TABLE, if that field is a generated
486 column.
487 Contrast this with the Field of a TABLE_SHARE, which has expr_item==NULL
488 even if it's a generated column; that makes sense, as an Item tree cannot
489 be shared.
490 */
491 Item *expr_item{nullptr};
492 /**
493 Text of the expression. Used in only one case:
494 - the text read from the DD is put into the Value_generator::expr_str of
495 the Field of the TABLE_SHARE; then this expr_str is used as source
496 to produce expr_item for the Field of every TABLE derived from this
497 TABLE_SHARE.
498 */
499 LEX_STRING expr_str{nullptr, 0};
500
501 /**
502 Bit field indicating the type of statement for binary logging.
503 It needs to be saved because this is determined only once when it is parsed
504 but it needs to be set on the lex for each statement that uses this
505 value generator. And since unpacking is done once on table open, it will
506 be set for the rest of the statements in bind_value_generator_to_fields.
507 */
509
510 /// List of all items created when parsing and resolving generated expression
511 Item *item_list{nullptr};
512 /// Bitmap records base columns which a generated column depends on.
514
516
517 void set_field_type(enum_field_types fld_type) { field_type = fld_type; }
518
519 /**
520 Set the binary log flags in m_backup_binlog_stmt_flags
521 @param backup_binlog_stmt_flags the flags to be backed up
522 */
523 void backup_stmt_unsafe_flags(uint32 backup_binlog_stmt_flags) {
524 m_backup_binlog_stmt_flags = backup_binlog_stmt_flags;
525 }
526
527 /**
528 Get the binary log flags from m_backup_binlog_stmt_flags
529 @return the flags backed up by unpack_value_generator
530 */
532
533 bool get_field_stored() const { return stored_in_db; }
534 void set_field_stored(bool stored) { stored_in_db = stored; }
536 /**
537 Get the number of non virtual base columns that this generated
538 column needs.
539
540 @return number of non virtual base columns
541 */
543
544 /**
545 Duplicates a string into expr_str.
546
547 @param root MEM_ROOT to use for allocation
548 @param src source string
549 @param len length of 'src' in bytes
550 */
551 void dup_expr_str(MEM_ROOT *root, const char *src, size_t len);
552
553 /**
554 Writes the generation expression into a String with proper syntax.
555 @param thd THD
556 @param out output String
557 */
558 void print_expr(THD *thd, String *out);
559
560 /*
561 The following data is only updated by the parser and read
562 when a Create_field object is created/initialized.
563 */
564 private:
565 /// Real field type
567 /// Indicates if the field is physically stored in the database
568 bool stored_in_db{false};
569 /// How many non-virtual base columns in base_columns_map
571};
572
573class Field {
574 public:
575 /*
576 Field(const Item &) = delete;
577 The original intention was seemingly for Field to be non-copyable,
578 but due to a typo, this was never enforced, and now there's lots of
579 code that copies Field objects around. Thus, the default copy
580 constructor needs to stay (assignment is blocked off), but it's probably
581 better not to write code that depends on it.
582 */
583 Field(const Field &) = default;
584 void operator=(Field &) = delete;
585
586 /**
587 Checks if the field is marked as having a general expression to generate
588 default values.
589
590 @retval true The field has general expression as default
591 @retval false The field doesn't have any general expression as default
592 */
595 }
596
597 /**
598 Checks if the field is marked as having a datetime value expression to
599 generate default values on inserts.
600
601 @retval true The field has datetime expression as default
602 @retval false The field doesn't have a datime value expression as default
603 */
605 return auto_flags & DEFAULT_NOW;
606 }
607
608 /**
609 Checks if the field is marked as having a datetime value expression to
610 generate default values on updates.
611
612 @retval true The field has datetime expression as default for on update
613 @retval false The field doesn't have a datime value expression as default
614 for on update
615 */
617 return auto_flags & ON_UPDATE_NOW;
618 }
619
620 /**
621 Checks if the field is marked as having a constant expression to generate
622 default values. Relevant when re-creating a Create_field from a Field
623 during ALTER.
624
625 @retval true The field has a constant expression as default
626 @retval false The field doesn't have a constant expression as default
627 */
629 // For now this is true whenever neither GENERATED_FROM_EXPRESSION nor
630 // DEFAULT_NOW is set. If this changes in the future, we can add a separate
631 // flag for this.
633 }
634
635 protected:
636 /// Holds the position to the field in record
638
639 private:
641
642 /**
643 Byte where the @c NULL bit is stored inside a record. If this Field is a
644 @c NOT @c NULL field, this member is @c NULL.
645 */
647
648 /**
649 Flag: if the NOT-NULL field can be temporary NULL.
650 */
652
653 /**
654 This is a flag with the following semantics:
655 - it can be changed only when m_is_tmp_nullable is true;
656 - it specifies if this field in the first current record
657 (TABLE::record[0]) was set to NULL (temporary NULL).
658
659 This flag is used for trigger handling.
660 */
662
663 /**
664 The value of THD::check_for_truncated_fields at the moment of setting
665 m_is_tmp_null attribute.
666 */
668
669 protected:
670 /*
671 null_ptr buffer to be used for Fields that are nullable but
672 cannot store null. Typically used from create_tmp_field().
673 */
675
676 public:
678 /// Pointer to TABLE object that owns this field
680 /// Pointer to original database name, only non-NULL for a temporary table
681 const char *orig_db_name{nullptr};
682 /// Pointer to original table name, only non-NULL for a temporary table
683 const char *orig_table_name{nullptr};
684 const char **table_name, *field_name;
686 /* Field is part of the following keys */
687 Key_map key_start; /* Keys that starts with this field */
688 Key_map part_of_key; ///< Keys that includes this field
689 ///< except of prefix keys.
690 Key_map part_of_prefixkey; ///< Prefix keys
691 Key_map part_of_sortkey; /* ^ but only keys usable for sorting */
692 /**
693 All keys that include this field, but not extended by the storage engine to
694 include primary key columns.
695 */
697
698 /**
699 Flags for Field::auto_flags / Create_field::auto_flags bitmaps.
700
701 @note NEXT_NUMBER and DEFAULT_NOW/ON_UPDATE_NOW/GENERATED flags should
702 never be set at the same time. Also DEFAULT_NOW and GENERATED
703 should not be set at the same time.
704
705 @warning The values of this enum are used as bit masks for uchar
706 Field::auto_flags.
707 */
709 NONE = 0,
710 NEXT_NUMBER = 1, ///< AUTO_INCREMENT
711 DEFAULT_NOW = 2, ///< DEFAULT CURRENT_TIMESTAMP
712 ON_UPDATE_NOW = 4, ///< ON UPDATE CURRENT_TIMESTAMP
713 GENERATED_FROM_EXPRESSION = 8 ///< DEFAULT (expression)
714 };
715
725 };
727
728 // Max width for a VARCHAR column, in number of bytes
729 static constexpr size_t MAX_VARCHAR_WIDTH{65535};
730
731 // Maximum sizes of the four BLOB types, in number of bytes
732 static constexpr size_t MAX_TINY_BLOB_WIDTH{255};
733 static constexpr size_t MAX_SHORT_BLOB_WIDTH{65535};
734 static constexpr size_t MAX_MEDIUM_BLOB_WIDTH{16777215};
735 static constexpr size_t MAX_LONG_BLOB_WIDTH{4294967295};
736
737 // Length of field. Never write to this member directly; instead, use
738 // set_field_length().
741
742 /// Update '*cost' with the fact that this Field is accessed.
743 virtual void add_to_cost(CostOfItem *cost) const;
744
745 private:
747 uint16 m_field_index; // field number in fields array
748
749 public:
750 bool is_flag_set(unsigned flag) const { return flags & flag; }
751 void set_flag(unsigned flag) { flags |= flag; }
752 void clear_flag(unsigned flag) { flags &= ~flag; }
753 // Avoid using this function as it makes it harder to change the internal
754 // representation.
755 uint32 all_flags() const { return flags; }
756 uchar null_bit; // Bit used to test null bit
757 /**
758 Bitmap of flags indicating if field value is auto-generated by default
759 and/or on update, and in which way.
760
761 @sa Field::enum_auto_flags for possible options.
762
763 @sa Field::utype and Field::unireg_check in pre-8.0 versions of server
764 for historical perspective.
765 */
767 /**
768 If true, this field was created in create_tmp_field_from_item from a NULL
769 value. This means that the type of the field is just a guess, and the type
770 may be freely coerced to another type.
771
772 @see create_tmp_field_from_item
773 @see Item_type_holder::get_real_type
774
775 */
777 /**
778 If true, it's a Create_field_wrapper (a sub-class of Field used during
779 CREATE/ALTER that we mustn't cast to other sub-classes of Field that
780 aren't on a direct path of inheritance, e.g. Field_enum).
781
782 @see Create_field_wrapper::is_wrapper_field
783 */
784 virtual bool is_wrapper_field() const { return false; }
785
786 /**
787 True if this field belongs to some index (unlike part_of_key, the index
788 might have only a prefix).
789 */
791
794
795 private:
800 };
801
802 /*
803 Bitmask specifying which warnings have been already pushed in order
804 not to repeat the same warning for the collmn multiple times.
805 Uses values of enum_pushed_warnings to control pushed warnings.
806 */
807 unsigned int m_warnings_pushed;
808
809 /// Holds the name of the masking policy applied to the field.
811
812 public:
813 /* Generated column data */
815 /**
816 Indication that the field is physically stored in tables
817 rather than just generated on SQL queries.
818 As of now, false can only be set for virtual generated columns.
819 */
821 /**
822 Whether the field is signed or not. Meaningful only for numeric fields
823 and numeric arrays.
824 */
825 virtual bool is_unsigned() const { return false; }
826 bool is_gcol() const { return gcol_info; }
827 bool is_virtual_gcol() const { return gcol_info && !stored_in_db; }
828
829 /// Holds the expression to be used to generate default values.
831
832 /**
833 Sets the hidden type for this field.
834
835 @param hidden the new hidden type to set.
836 */
838
839 /// Sets the name of the masking policy to apply to this column.
842 }
843
844 /// Does this column have a masking policy?
845 bool has_masking_policy() const { return m_masking_policy.length != 0; }
846
847 /// Returns the name of the masking policy, or an empty string if no masking
848 /// policy is defined on this column.
850
851 /// @returns the hidden type for this field.
853
854 /**
855 @retval true if this field should be hidden away from users.
856 @retval false is this field is visible to the user.
857 */
858 bool is_hidden() const {
860 DBUG_EVALUATE_IF("show_hidden_columns", false, true);
861 }
862
863 /**
864 @retval true If this column is hidden either in the storage engine
865 or SQL layer. Either way, it is completely hidden from
866 the user.
867 @retval false Otherwise.
868 */
869 bool is_hidden_by_system() const {
872 DBUG_EVALUATE_IF("show_hidden_columns", false, true);
873 }
874
875 /**
876 @retval true If this column is hidden by the user.
877 @retval false otherwise.
878 */
879 bool is_hidden_by_user() const {
881 }
882
883 /**
884 @returns true if this is a hidden field that is used for implementing
885 functional indexes. Note that if we need different types of hidden
886 fields in the future (like invisible columns), this function needs
887 to be changed so it can distinguish between the different "types"
888 of hidden.
889 */
892 gcol_info != nullptr;
893 }
894
895 Field(uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg,
896 uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg);
897
898 virtual ~Field() = default;
899
901
902 /**
903 Turn on temporary nullability for the field.
904 */
906
907 /**
908 Turn off temporary nullability for the field.
909 */
911
912 /**
913 Reset temporary NULL value for field
914 */
915 void reset_tmp_null() { m_is_tmp_null = false; }
916
917 void set_tmp_null();
918
919 /**
920 @return temporary NULL-ability flag.
921 @retval true if NULL can be assigned temporary to the Field.
922 @retval false if NULL can not be assigned even temporary to the Field.
923 */
924 bool is_tmp_nullable() const { return m_is_tmp_nullable; }
925
926 /**
927 @return whether Field has temporary value NULL.
928 @retval true if the Field has temporary value NULL.
929 @retval false if the Field's value is NOT NULL, or if the temporary
930 NULL-ability flag is reset.
931 */
932 bool is_tmp_null() const { return is_tmp_nullable() && m_is_tmp_null; }
933
934 /* Store functions returns 1 on overflow and -1 on fatal error */
935 virtual type_conversion_status store(const char *to, size_t length,
936 const CHARSET_INFO *cs) = 0;
937 virtual type_conversion_status store(double nr) = 0;
938 virtual type_conversion_status store(longlong nr, bool unsigned_val) = 0;
939 virtual type_conversion_status store_time(Time_val time, uint8 dec_arg);
941
942 /**
943 Store a temporal value in packed longlong format into a field.
944 The packed value is compatible with TIME_to_longlong_datetime_packed().
945 Note, the value must be properly rounded or truncated according
946 according to field->decimals().
947
948 @param nr temporal value in packed longlong format.
949 @retval false on success
950 @retval true on error
951 */
953 return store(nr, false);
954 }
956 /**
957 Store MYSQL_TIME value with the given amount of decimal digits
958 into a field.
959
960 Note, the "dec" parameter represents number of digits of the Item
961 that previously created the MYSQL_TIME value. It's needed when we
962 store the value into a CHAR/VARCHAR/TEXT field to display
963 the proper amount of fractional digits.
964 For other field types the "dec" value does not matter and is ignored.
965
966 @param ltime Time, date or datetime value.
967 @param dec_arg Number of decimals in ltime.
968 @retval false on success
969 @retval true on error
970 */
971 virtual type_conversion_status store_time(MYSQL_TIME *ltime, uint8 dec_arg);
972 /**
973 Store MYSQL_TYPE value into a field when the number of fractional
974 digits is not important or is not know.
975
976 @param ltime Time, date or datetime value.
977 @retval false on success
978 @retval true on error
979 */
981 return store_time(ltime, 0);
982 }
983 type_conversion_status store(const char *to, size_t length,
984 const CHARSET_INFO *cs,
985 enum_check_fields check_level);
986 virtual double val_real() const = 0;
987 virtual longlong val_int() const = 0;
988 /**
989 Returns DATE/DATETIME value in packed longlong format.
990 This method should not be called for non-temporal types.
991 Temporal field types override the default method.
992 */
993 virtual longlong val_date_temporal() const {
994 assert(0);
995 return 0;
996 }
997
999 return val_date_temporal();
1000 }
1001
1002 virtual my_decimal *val_decimal(my_decimal *) const = 0;
1003 String *val_str(String *str) const { return val_str(str, str); }
1004 /*
1005 val_str(buf1, buf2) gets two buffers and should use them as follows:
1006 if it needs a temp buffer to convert result to string - use buf1
1007 example Field_tiny::val_str()
1008 if the value exists as a string already - use buf2
1009 example Field_string::val_str()
1010 consequently, buf2 may be created as 'String buf;' - no memory
1011 will be allocated for it. buf1 will be allocated to hold a
1012 value if it's too small. Using allocated buffer for buf2 may result in
1013 an unnecessary free (and later, may be an alloc).
1014 This trickery is used to decrease a number of malloc calls.
1015 */
1016 virtual String *val_str(String *, String *) const = 0;
1017 String *val_int_as_str(String *val_buffer, bool unsigned_flag) const;
1018 /*
1019 str_needs_quotes() returns true if the value returned by val_str() needs
1020 to be quoted when used in constructing an SQL query.
1021 */
1022 virtual bool str_needs_quotes() const { return false; }
1023 virtual Item_result result_type() const = 0;
1024 /**
1025 Returns Item_result type of a field when it appears
1026 in numeric context such as:
1027 SELECT time_column + 1;
1028 SELECT SUM(time_column);
1029 Examples:
1030 - a column of type TIME, DATETIME, TIMESTAMP act as INT.
1031 - a column of type TIME(1), DATETIME(1), TIMESTAMP(1)
1032 act as DECIMAL with 1 fractional digits.
1033 */
1035 return result_type();
1036 }
1037 virtual Item_result cmp_type() const { return result_type(); }
1038 virtual Item_result cast_to_int_type() const { return result_type(); }
1042 bool gcol_expr_is_equal(const Create_field *field) const;
1043 virtual bool eq(const Field *field) const {
1044 return (ptr == field->ptr && m_null_ptr == field->m_null_ptr &&
1045 null_bit == field->null_bit && field->type() == type());
1046 }
1047 virtual bool eq_def(const Field *field) const;
1048
1049 /*
1050 pack_length() returns size (in bytes) used to store field data in memory
1051 (i.e. it returns the maximum size of the field in a row of the table,
1052 which is located in RAM).
1053 */
1054 virtual uint32 pack_length() const { return (uint32)field_length; }
1055
1056 /*
1057 pack_length_in_rec() returns size (in bytes) used to store field data on
1058 storage (i.e. it returns the maximal size of the field in a row of the
1059 table, which is located on disk).
1060 */
1061 virtual uint32 pack_length_in_rec() const { return pack_length(); }
1062 virtual bool compatible_field_size(uint metadata, Relay_log_info *, uint16,
1063 int *order) const;
1064 virtual uint pack_length_from_metadata(uint field_metadata) const {
1065 DBUG_TRACE;
1066 return field_metadata;
1067 }
1068 virtual uint row_pack_length() const { return 0; }
1069 int save_field_metadata(uchar *first_byte) {
1070 return do_save_field_metadata(first_byte);
1071 }
1072
1073 /*
1074 data_length() return the "real size" of the data in memory.
1075 Useful only for variable length datatypes where it's overloaded.
1076 By default assume the length is constant.
1077 */
1078 virtual uint32 data_length(ptrdiff_t row_offset [[maybe_unused]] = 0) const {
1079 return pack_length();
1080 }
1081
1082 /**
1083 Get the maximum size of the data in packed format.
1084
1085 @return Maximum data length of the field when packed using the
1086 Field::pack() function.
1087 */
1088 virtual uint32 max_data_length() const { return pack_length(); }
1089
1091 memset(ptr, 0, pack_length());
1092 return TYPE_OK;
1093 }
1094 /**
1095 Returns a UTC component in `struct timeval` format. This interface
1096 makes any column appear to be `TIMESTAMP`, i.e. stored in UTC, and
1097 returns the UTC component in (optionally fractional) seconds. This means
1098 converting _to_ UTC from the current session's time zone for types other
1099 than `TIMESTAMP`.
1100
1101 This method was expressly written for `SELECT UNIX_TIMESTAMP(field)`
1102 to avoid conversion from timestamp to MYSQL_TIME and back.
1103 */
1104 virtual bool get_timestamp(my_timeval *tm, int *warnings) const;
1105 /**
1106 Stores a timestamp value in timeval format in a field.
1107
1108 @note
1109 - store_timestamp(), get_timestamp() and store_time() do not depend on
1110 timezone and always work "in UTC".
1111
1112 - The default implementation of this interface expects that storing the
1113 value will not fail. For most Field descendent classes, this is not the
1114 case. However, this interface is only used when the function
1115 CURRENT_TIMESTAMP is used as a column default expression, and currently we
1116 only allow TIMESTAMP and DATETIME columns to be declared with this as the
1117 column default. Hence it is enough that the classes implementing columns
1118 with these types either override this interface, or that
1119 store_time(MYSQL_TIME*, uint8) does not fail.
1120
1121 - The column types above interpret decimals() to mean the scale of the
1122 fractional seconds.
1123
1124 - We also have the limitation that the scale of a column must be the same as
1125 the scale of the CURRENT_TIMESTAMP. I.e. we only allow
1126
1127 @code
1128
1129 [ TIMESTAMP | DATETIME ] (n) [ DEFAULT | ON UPDATE ] CURRENT_TIMESTAMP (n)
1130
1131 @endcode
1132
1133 Since this interface relies on the caller to truncate the value according to
1134 this Field's scale, it will work with all constructs that we currently allow.
1135 */
1136 virtual void store_timestamp(const my_timeval *) { assert(false); }
1137
1138 virtual void set_default();
1139
1140 /**
1141 Evaluates the @c INSERT default function and stores the result in the
1142 field. If no such function exists for the column, or the function is not
1143 valid for the column's data type, invoking this function has no effect.
1144 */
1146
1147 /**
1148 Evaluates the @c UPDATE default function, if one exists, and stores the
1149 result in the record buffer. If no such function exists for the column,
1150 or the function is not valid for the column's data type, invoking this
1151 function has no effect.
1152 */
1154 virtual bool binary() const { return true; }
1155 virtual bool zero_pack() const { return true; }
1156 virtual enum ha_base_keytype key_type() const { return HA_KEYTYPE_BINARY; }
1157 virtual uint32 key_length() const { return pack_length(); }
1158 virtual enum_field_types type() const = 0;
1159 virtual enum_field_types real_type() const { return type(); }
1161 /*
1162 Binlog stores field->type() as type code by default.
1163 This puts MYSQL_TYPE_STRING in case of CHAR, VARCHAR, SET and ENUM,
1164 with extra data type details put into metadata.
1165
1166 We cannot store field->type() in case of temporal types with
1167 fractional seconds: TIME(n), DATETIME(n) and TIMESTAMP(n),
1168 because binlog records with MYSQL_TYPE_TIME, MYSQL_TYPE_DATETIME
1169 type codes do not have metadata.
1170 So for temporal data types with fractional seconds we'll store
1171 real_type() type codes instead, i.e.
1172 MYSQL_TYPE_TIME2, MYSQL_TYPE_DATETIME2, MYSQL_TYPE_TIMESTAMP2,
1173 and put precision into metatada.
1174
1175 Note: perhaps binlog should eventually be modified to store
1176 real_type() instead of type() for all column types.
1177 */
1178 return type();
1179 }
1180 int cmp(const uchar *str) const { return cmp(ptr, str); }
1181 virtual int cmp_max(const uchar *a, const uchar *b,
1182 uint max_len [[maybe_unused]]) const {
1183 return cmp(a, b);
1184 }
1185 virtual int cmp(const uchar *, const uchar *) const = 0;
1186 virtual int cmp_binary(const uchar *a, const uchar *b,
1187 uint32 max_length [[maybe_unused]] = ~0L) const {
1188 return memcmp(a, b, pack_length());
1189 }
1190 virtual int cmp_offset(ptrdiff_t row_offset) const {
1191 return cmp(ptr, ptr + row_offset);
1192 }
1193 virtual int cmp_binary_offset(ptrdiff_t row_offset) const {
1194 return cmp_binary(ptr, ptr + row_offset);
1195 }
1196 virtual int key_cmp(const uchar *a, const uchar *b) const {
1197 return cmp(a, b);
1198 }
1199 virtual int key_cmp(const uchar *str, uint length [[maybe_unused]]) const {
1200 return cmp(ptr, str);
1201 }
1202 virtual uint decimals() const { return 0; }
1203 virtual bool is_text_key_type() const { return false; }
1204
1205 /*
1206 Caller beware: sql_type can change str.Ptr, so check
1207 ptr() to see if it changed if you are using your own buffer
1208 in str and restore it with set() if needed
1209 */
1210 virtual void sql_type(String &str) const = 0;
1211
1212 /**
1213 Check whether the full table's row is NULL or the Field has value NULL.
1214
1215 @return true if the full table's row is NULL or the Field has value NULL
1216 false if neither table's row nor the Field has value NULL
1217 */
1218 bool is_null(ptrdiff_t row_offset = 0) const {
1219 /*
1220 if the field is NULLable, it returns NULLity based
1221 on m_null_ptr[row_offset] value. Otherwise it returns
1222 NULL flag depending on TABLE::has_null_row() value.
1223
1224 The table may have been marked as containing only NULL values
1225 for all fields if it is a NULL-complemented row of an OUTER JOIN
1226 or if the query is an implicitly grouped query (has aggregate
1227 functions but no GROUP BY clause) with no qualifying rows. If
1228 this is the case (in which TABLE::has_null_row() is true) and the
1229 field is not nullable, the field is considered to be NULL.
1230
1231 Do not change the order of testing. Fields may be associated
1232 with a TABLE object without being part of the current row.
1233 For NULL value check to work for these fields, they must
1234 have a valid m_null_ptr, and this pointer must be checked before
1235 TABLE::has_null_row().
1236 */
1237 if (is_nullable()) return (m_null_ptr[row_offset] & null_bit);
1238
1239 if (is_tmp_nullable()) return m_is_tmp_null;
1240
1241 return table->has_null_row();
1242 }
1243
1244 /**
1245 Check whether the Field has value NULL (temporary or actual).
1246
1247 @return true if the Field has value NULL (temporary or actual)
1248 false if the Field has value NOT NULL.
1249 */
1250 bool is_real_null(ptrdiff_t row_offset = 0) const {
1251 if (is_nullable()) return (m_null_ptr[row_offset] & null_bit);
1252
1253 if (is_tmp_nullable()) return m_is_tmp_null;
1254
1255 return false;
1256 }
1257
1258 /**
1259 Check if the Field has value NULL or the record specified by argument
1260 has value NULL for this Field.
1261
1262 @return true if the Field has value NULL or the record has value NULL
1263 for thois Field.
1264 */
1265 bool is_null_in_record(const uchar *record) const {
1266 if (is_nullable()) return (record[null_offset()] & null_bit);
1267
1268 return is_tmp_nullable() ? m_is_tmp_null : false;
1269 }
1270
1271 void set_null(ptrdiff_t row_offset = 0);
1272
1273 void set_notnull(ptrdiff_t row_offset = 0);
1274
1275 // Cannot be const as it calls set_warning
1277
1278 /**
1279 Remember the value of THD::check_for_truncated_fields to handle possible
1280 NOT-NULL constraint errors after BEFORE-trigger execution is finished.
1281 We should save the value of THD::check_for_truncated_fields before starting
1282 BEFORE-trigger processing since during triggers execution the
1283 value of THD::check_for_truncated_fields could be changed.
1284 */
1286 enum_check_fields check_for_truncated_fields) {
1287 m_check_for_truncated_fields_saved = check_for_truncated_fields;
1288 }
1289
1290 /// @return true if this field is NULL-able, false otherwise.
1291 bool is_nullable() const { return m_null_ptr != nullptr; }
1292
1293 uint null_offset(const uchar *record) const {
1294 return (uint)(m_null_ptr - record);
1295 }
1296
1297 uint null_offset() const;
1298
1299 void set_null_ptr(uchar *p_null_ptr, uint p_null_bit) {
1300 m_null_ptr = p_null_ptr;
1301 null_bit = p_null_bit;
1302 }
1303
1304 /**
1305 Populates a Send_field object with metadata about the column represented by
1306 this Field object. The Send_field object is used for sending column metadata
1307 to the client.
1308
1309 @param[out] send_field the Send_field object to populate
1310 */
1311 virtual void make_send_field(Send_field *send_field) const;
1312
1313 /**
1314 Writes a copy of the current value in the record buffer, suitable for
1315 sorting using byte-by-byte comparison. Integers are always in big-endian
1316 regardless of hardware architecture. At most length bytes are written
1317 into the buffer.
1318
1319 @param buff The buffer, assumed to be at least length bytes.
1320
1321 @param length Number of bytes to write.
1322
1323 @retval The number of bytes actually written.
1324
1325 @note This is now only used by replication; filesort makes its own
1326 sort keys based off of Items, not Fields.
1327 */
1328 virtual size_t make_sort_key(uchar *buff, size_t length) const = 0;
1329
1330 /**
1331 Writes a copy of the current value in the record buffer, suitable for
1332 sorting using byte-by-byte comparison. Integers are always in big-endian
1333 regardless of hardware architecture. At most length bytes are written
1334 into the buffer. Field_string, Field_varstring and Field_blob classes
1335 are truncated after pos number of characters.
1336
1337 @param buff The buffer, assumed to be at least length bytes.
1338
1339 @param length Number of bytes to write.
1340
1341 @param trunc_pos Number of characters which should be included before
1342 truncation.
1343
1344 @retval The number of bytes actually written.
1345
1346 @note This is now only used by replication; filesort makes its own
1347 sort keys based off of Items, not Fields.
1348 */
1349 virtual size_t make_sort_key(uchar *buff, size_t length,
1350 size_t trunc_pos [[maybe_unused]]) const {
1351 return make_sort_key(buff, length);
1352 }
1353
1354 /**
1355 Whether this field can be used for index range scans when in
1356 the given keypart of the given index.
1357 */
1358 virtual bool optimize_range(uint idx, uint part) const;
1359 /*
1360 This should be true for fields which, when compared with constant
1361 items, can be casted to longlong. In this case we will at 'fix_fields'
1362 stage cast the constant items to longlongs and at the execution stage
1363 use field->val_int() for comparison. Used to optimize clauses like
1364 'a_column BETWEEN date_const, date_const'.
1365 */
1366 virtual bool can_be_compared_as_longlong() const { return false; }
1367 virtual void mem_free() {}
1368
1369 virtual Field *new_field(MEM_ROOT *root, TABLE *new_table) const;
1370
1371 Field *new_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr,
1372 uchar *new_null_ptr, uint new_null_bit) const {
1373 Field *field = new_field(root, new_table);
1374 field->move_field(new_ptr, new_null_ptr, new_null_bit);
1375 return field;
1376 }
1377
1378 virtual Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr,
1379 uchar *new_null_ptr, uint new_null_bit) const;
1380
1381 Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr) const {
1382 return new_key_field(root, new_table, new_ptr, m_null_ptr, null_bit);
1383 }
1384
1385 /**
1386 Makes a shallow copy of the Field object.
1387
1388 @note This member function must be overridden in all concrete
1389 subclasses. Several of the Field subclasses are concrete even though they
1390 are not leaf classes, so the compiler will not always catch this.
1391
1392 @param mem_root MEM_ROOT to use for memory allocation.
1393 @retval NULL If memory allocation failed.
1394 */
1395 virtual Field *clone(MEM_ROOT *mem_root) const = 0;
1396
1397 void move_field(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg) {
1398 ptr = ptr_arg;
1399 m_null_ptr = null_ptr_arg;
1400 null_bit = null_bit_arg;
1401 }
1402
1403 virtual void move_field_offset(ptrdiff_t ptr_diff) {
1404 ptr += ptr_diff;
1405 if (is_nullable()) m_null_ptr += ptr_diff;
1406 }
1407
1408 virtual void get_image(uchar *buff, size_t length,
1409 const CHARSET_INFO *) const {
1410 memcpy(buff, ptr, length);
1411 }
1412
1413 virtual void set_image(const uchar *buff, size_t length,
1414 const CHARSET_INFO *) {
1415 memcpy(ptr, buff, length);
1416 }
1417
1418 /*
1419 Copy a field part into an output buffer.
1420
1421 SYNOPSIS
1422 Field::get_key_image()
1423 buff [out] output buffer
1424 length output buffer size
1425 type itMBR for geometry blobs, otherwise itRAW
1426
1427 DESCRIPTION
1428 This function makes a copy of field part of size equal to or
1429 less than "length" parameter value.
1430 For fields of string types (CHAR, VARCHAR, TEXT) the rest of buffer
1431 is padded by zero byte.
1432
1433 NOTES
1434 For variable length character fields (i.e. UTF-8) the "length"
1435 parameter means a number of output buffer bytes as if all field
1436 characters have maximal possible size (mbmaxlen). In the other words,
1437 "length" parameter is a number of characters multiplied by
1438 field_charset->mbmaxlen.
1439
1440 RETURN
1441 Number of copied bytes (excluding padded zero bytes -- see above).
1442 */
1443
1444 virtual size_t get_key_image(uchar *buff, size_t length,
1445 imagetype type [[maybe_unused]]) const {
1447 return length;
1448 }
1449 virtual void set_key_image(const uchar *buff, size_t length) {
1451 }
1452 longlong val_int_offset(ptrdiff_t row_offset) {
1453 ptr += row_offset;
1454 const longlong tmp = val_int();
1455 ptr -= row_offset;
1456 return tmp;
1457 }
1459 uchar *old_ptr = ptr;
1460 longlong return_value;
1461 ptr = new_ptr;
1462 return_value = val_int();
1463 ptr = old_ptr;
1464 return return_value;
1465 }
1467 uchar *old_ptr = ptr;
1468 ptr = new_ptr;
1469 val_str(str);
1470 ptr = old_ptr;
1471 return str;
1472 }
1473
1474 /**
1475 Send the value of this field over the protocol using the correct
1476 Protocol::store*() function which matches the type of the field.
1477 */
1478 virtual bool send_to_protocol(Protocol *protocol) const;
1479
1480 /**
1481 Pack the field into a format suitable for storage and transfer.
1482
1483 To implement packing functionality, only the virtual function
1484 should be overridden. The other functions are just convenience
1485 functions and hence should not be overridden.
1486
1487 The actual format is opaque and will vary between types of Field
1488 (it is meant to be unpacked by unpack(), but be aware that it is
1489 used among others in the replication log, so you cannot change it
1490 without incurring a format break.
1491
1492 @note The default implementation just copies the raw bytes
1493 of the record into the destination, but never more than
1494 <code>max_length</code> characters.
1495
1496 @param to
1497 Pointer to memory area where representation of field should be put.
1498
1499 @param from
1500 Pointer to memory area where record representation of field is
1501 stored, typically field->field_ptr().
1502
1503 @param max_length
1504 Available space in “to”, in bytes. pack() will not write more bytes than
1505 this; if the field is too short, the contents _are not unpackable by
1506 unpack()_. (It is nominally supposed to be a prefix of what would have
1507 been written with a full buffer, ie., the same as packing and then
1508 truncating the output, but not all Field classes follow this.)
1509
1510 @return The byte after the last byte in “to” written to. If the return
1511 value is equal to (to + max_length), it could either be that the value
1512 fit exactly, or that the buffer was too small; you cannot distinguish
1513 between the two cases based on the return value alone.
1514 */
1515 virtual uchar *pack(uchar *to, const uchar *from, size_t max_length) const;
1516
1517 uchar *pack(uchar *to) const { return pack(to, ptr, UINT_MAX); }
1518
1519 virtual const uchar *unpack(uchar *to, const uchar *from, uint param_data);
1520
1521 const uchar *unpack(const uchar *from) { return unpack(ptr, from, 0U); }
1522
1523 /**
1524 This function does the same thing as pack(), except for the difference
1525 that max_length does not mean the number of bytes in the output, but the
1526 maximum field length from the input (which must be exactly
1527 field->max_field_length()). The difference is currently only relevant for
1528 Field_blob, but can be summed up as follows:
1529
1530 - If the actual field length is longer than "max_length", by way of
1531 software bug or otherwise, the function may behave as if it were shorter,
1532 and write something that is still readable by unpack().
1533 - There is no bounds checking; the caller must verify that there is
1534 sufficient space in "to". Even in the case of truncation, "to" must
1535 be long enough to hold the untruncated field, as the return pointer
1536 would otherwise be invalid, causing undefined behavior as per the C++
1537 standard.
1538 */
1539 virtual uchar *pack_with_metadata_bytes(uchar *to, const uchar *from,
1540 uint max_length) const {
1541 return pack(to, from, max_length);
1542 }
1543
1544 /**
1545 Write the field for the binary log in diff format.
1546
1547 This should only write the field if the diff format is smaller
1548 than the full format. Otherwise it should leave the buffer
1549 untouched.
1550
1551 @param[in,out] to Pointer to buffer where the field will be
1552 written. This will be changed to point to the next byte after the
1553 last byte that was written.
1554
1555 @param value_options bitmap that indicates if full or partial
1556 JSON format is to be used.
1557
1558 @retval true The field was not written, either because the data
1559 type does not support it, or because it was disabled according to
1560 value_options, or because there was no diff information available
1561 from the optimizer, or because the the diff format was bigger than
1562 the full format. The 'to' parameter is unchanged in this case.
1563
1564 @retval false The field was written.
1565 */
1566 virtual bool pack_diff(uchar **to [[maybe_unused]],
1567 ulonglong value_options [[maybe_unused]]) const {
1568 return true;
1569 }
1570
1571 /**
1572 This is a wrapper around pack_length() used by filesort() to determine
1573 how many bytes we need for packing "addon fields".
1574 @returns maximum size of a row when stored in the filesort buffer.
1575 */
1576
1577 virtual uint max_packed_col_length() const { return pack_length(); }
1578
1579 uint offset(uchar *record) const { return (uint)(ptr - record); }
1580
1581 void copy_data(ptrdiff_t src_record_offset);
1582
1583 /**
1584 Retrieve field value and return the result as a date.
1585
1586 @param[out] date returned date value
1587 @param flags Limit the value returned according to TIME_NO_ZERO_IN_DATE,
1588 TIME_NO_ZERO_DATE, TIME_NO_INVALID_DATES.
1589
1590 @returns false retrieval was successful, date contains the result.
1591 true evaluation resulted in error, or a NULL value is returned.
1592 */
1593 virtual bool val_date(Date_val *date, my_time_flags_t flags) const;
1594
1595 /**
1596 Retrieve field value and return the result as a time.
1597
1598 @param[out] time returned time value
1599
1600 @returns false retrieval was successful, time contains the result.
1601 true evaluation resulted in error, or a NULL value is returned.
1602 */
1603 virtual bool val_time(Time_val *time) const;
1604
1605 /**
1606 Retrieve field value and return the result as a datetime/timestamp.
1607
1608 @param[out] dt returned datetime value
1609 @param flags Limit the value returned according to TIME_NO_ZERO_IN_DATE,
1610 TIME_NO_ZERO_DATE, TIME_NO_INVALID_DATES.
1611
1612 @returns false retrieval was successful, dt contains the result.
1613 true evaluation resulted in error, or a NULL value is returned.
1614 */
1615 virtual bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const;
1616
1617 virtual const CHARSET_INFO *charset() const { return &my_charset_bin; }
1618
1620 return binary() ? &my_charset_bin : charset();
1621 }
1622 virtual const CHARSET_INFO *sort_charset() const { return charset(); }
1623 virtual bool has_charset() const { return false; }
1624 /*
1625 match_collation_to_optimize_range() is to distinguish in
1626 range optimizer (see opt_range.cc) between real string types:
1627 CHAR, VARCHAR, TEXT
1628 and the other string-alike types with result_type() == STRING_RESULT:
1629 DATE, TIME, DATETIME, TIMESTAMP
1630 We need it to decide whether to test if collation of the operation
1631 matches collation of the field (needed only for real string types).
1632 QQ: shouldn't DATE/TIME types have their own XXX_RESULT types eventually?
1633 */
1634
1635 virtual bool match_collation_to_optimize_range() const { return false; }
1636 virtual enum Derivation derivation() const { return DERIVATION_IMPLICIT; }
1637 virtual uint repertoire() const { return MY_REPERTOIRE_UNICODE30; }
1638 virtual void set_derivation(enum Derivation) {}
1639
1640 /**
1641 Produce warning or note about data saved into field.
1642
1643 @param level - level of message (Note/Warning/Error)
1644 @param code - error code of message to be produced
1645 @param cut_increment - whenever we should increase cut fields count
1646
1647 @note
1648 This function won't produce warning and increase cut fields counter
1649 if check_for_truncated_fields == CHECK_FIELD_IGNORE for current thread.
1650
1651 if check_for_truncated_fields == CHECK_FIELD_IGNORE then we ignore notes.
1652 This allows us to avoid notes in optimization, like
1653 convert_constant_item().
1654
1655 @retval
1656 1 if check_for_truncated_fields == CHECK_FIELD_IGNORE and error level
1657 is not NOTE
1658 @retval
1659 0 otherwise
1660 */
1662 int cut_increment) {
1663 return set_warning(level, code, cut_increment, nullptr, nullptr);
1664 }
1665
1666 bool set_warning(Sql_condition::enum_severity_level level, uint code,
1667 int cut_increment, const char *view_db,
1668 const char *view_name);
1669
1670 bool warn_if_overflow(int op_result);
1671 virtual void init(TABLE *table_arg);
1672
1673 /* maximum possible display length */
1674 virtual uint32 max_display_length() const = 0;
1675
1676 /**
1677 Whether a field being created is type-compatible with an existing one.
1678
1679 Used by the ALTER TABLE code to evaluate whether the new definition
1680 of a table is compatible with the old definition so that it can
1681 determine if data needs to be copied over (table data change).
1682 Constraints and generation clause (default value, generation expression)
1683 are not checked by this function.
1684
1685 @param new_field new field definition from alter.
1686 @retval IS_EQUAL_YES if there is no change.
1687 @retval IS_EQUAL_PACK_LENGTH if the data are unchanged, but the length
1688 requirements have changed
1689 @retval IS_EQUAL_NO if there is an incompatible change requiring copy.
1690 */
1691
1692 virtual uint is_equal(const Create_field *new_field) const;
1693
1694 /* convert decimal to longlong with overflow check */
1695 longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag,
1696 bool *has_overflow);
1697 /* The max. number of characters */
1698 virtual uint32 char_length() const {
1699 return field_length / charset()->mbmaxlen;
1700 }
1701
1703 /* shouldn't get here. */
1704 assert(0);
1705 return GEOM_GEOMETRY;
1706 }
1707#ifndef NDEBUG
1708 /* Print field value into debug trace, in NULL-aware way. */
1709 void dbug_print() const {
1710 if (is_real_null())
1711 fprintf(DBUG_FILE, "NULL");
1712 else {
1713 char buf[256];
1714 String str(buf, sizeof(buf), &my_charset_bin);
1715 str.length(0);
1716 String *pstr;
1717 pstr = val_str(&str);
1718 fprintf(DBUG_FILE, "'%s'", pstr->c_ptr_safe());
1719 }
1720 }
1721#endif
1722
1725 }
1726
1727 void set_storage_type(ha_storage_media storage_type_arg) {
1728 assert(field_storage_type() == HA_SM_DEFAULT);
1729 flags |= (storage_type_arg << FIELD_FLAGS_STORAGE_MEDIA);
1730 }
1731
1734 }
1735
1736 void set_column_format(column_format_type column_format_arg) {
1738 flags |= (column_format_arg << FIELD_FLAGS_COLUMN_FORMAT);
1739 }
1740
1741 /**
1742 Validate the value stored in a field.
1743 Used to validate a default value against the current SQL mode,
1744 especially for temporal fields.
1745 */
1747 [[maybe_unused]]) {
1748 return TYPE_OK;
1749 }
1750
1751 /* Hash value */
1752 virtual void hash(ulong *nr, ulong *nr2) const;
1753
1754 /**
1755 Get the upper limit of the MySQL integral and floating-point type.
1756
1757 @return maximum allowed value for the field
1758 */
1760 assert(false);
1761 return 0ULL;
1762 }
1763
1764 /**
1765 Return a const pointer to the actual data in the record buffer.
1766
1767 For most fields, this is the same as field_ptr(), but BLOBs and VARCHARs
1768 it is not. Ideally this function should not be used as it makes it hard
1769 to change the internal representation of Field.
1770 */
1771 virtual const uchar *data_ptr() const { return ptr; }
1772
1773 /**
1774 Return a const pointer to where the field is stored in the record buffer.
1775
1776 Ideally this function should not be used as it makes it hard
1777 to change the internal representation of Field.
1778 */
1779 const uchar *field_ptr() const { return ptr; }
1780
1781 /**
1782 Return a pointer to where the field is stored in the record buffer.
1783
1784 Ideally this function should not be used as it makes it hard
1785 to change the internal representation of Field.
1786 */
1787 uchar *field_ptr() { return ptr; }
1788
1789 void set_field_ptr(uchar *ptr_arg) { ptr = ptr_arg; }
1790
1791 /**
1792 Checks whether a string field is part of write_set.
1793
1794 @return
1795 false - If field is not char/varchar/....
1796 - If field is char/varchar/.. and is not part of write set.
1797 true - If field is char/varchar/.. and is part of write set.
1798 */
1799 virtual bool is_updatable() const { return false; }
1800
1801 /**
1802 Check whether field is part of the index taking the index extensions flag
1803 into account. Index extensions are also not applicable to UNIQUE indexes
1804 for loose index scans.
1805
1806 @param[in] thd THD object
1807 @param[in] cur_index Index of the key
1808 @param[in] cur_index_info key_info object
1809
1810 @retval true Field is part of the key
1811 @retval false otherwise
1812
1813 */
1814
1815 bool is_part_of_actual_key(THD *thd, uint cur_index,
1816 KEY *cur_index_info) const;
1817
1818 /**
1819 Get covering prefix keys.
1820
1821 @retval covering prefix keys.
1822 */
1824
1825 /// Whether the field is a typed array
1826 virtual bool is_array() const { return false; }
1827
1828 /**
1829 Return number of bytes the field's length takes
1830
1831 Valid only for varchar and typed arrays of varchar
1832 */
1833 virtual uint32 get_length_bytes() const {
1834 assert(0);
1835 return 0;
1836 }
1837
1838 /**
1839 Whether field's old valued have to be handled.
1840
1841 @returns
1842 true if field is virtual an either one of BLOB types or typed array
1843 false otherwise
1844 */
1845 bool handle_old_value() const {
1846 return (is_flag_set(BLOB_FLAG) || is_array()) && is_virtual_gcol();
1847 }
1848
1849 /**
1850 Sets field index.
1851
1852 @param[in] field_index Field index.
1853 */
1856 }
1857
1858 /**
1859 Returns field index.
1860
1861 @returns Field index.
1862 */
1864
1865 private:
1866 /**
1867 Retrieve the field metadata for fields.
1868
1869 This default implementation returns 0 and saves 0 in the metadata_ptr
1870 value.
1871
1872 @param metadata_ptr First byte of field metadata
1873
1874 @returns 0 no bytes written.
1875 */
1876 virtual int do_save_field_metadata(uchar *metadata_ptr
1877 [[maybe_unused]]) const {
1878 return 0;
1879 }
1880
1881 protected:
1882 uchar *pack_int16(uchar *to, const uchar *from, size_t max_length) const;
1883
1884 const uchar *unpack_int16(uchar *to, const uchar *from) const;
1885
1886 uchar *pack_int24(uchar *to, const uchar *from, size_t max_length) const;
1887
1888 const uchar *unpack_int24(uchar *to, const uchar *from) const;
1889
1890 uchar *pack_int32(uchar *to, const uchar *from, size_t max_length) const;
1891
1892 const uchar *unpack_int32(uchar *to, const uchar *from) const;
1893
1894 uchar *pack_int64(uchar *to, const uchar *from, size_t max_length) const;
1895
1896 const uchar *unpack_int64(uchar *to, const uchar *from) const;
1897};
1898
1899/**
1900 This class is a substitute for the Field classes during CREATE TABLE
1901
1902 When adding a functional index at table creation, we need to resolve the
1903 expression we are indexing. All functions that references one or more
1904 columns expect a Field to be available. But during CREATE TABLE, we only
1905 have access to Create_field. So this class acts as a substitute for the
1906 Field classes so that expressions can be properly resolved. Thus, trying
1907 to call store or val_* on this class will cause an assertion.
1908*/
1909class Create_field_wrapper final : public Field {
1911
1912 public:
1914 Item_result result_type() const final;
1916 enum_field_types type() const final;
1917 uint32 max_display_length() const final;
1918
1919 const CHARSET_INFO *charset() const final;
1920
1921 uint32 pack_length() const final;
1922
1923 // Since it's not a real field, functions below shouldn't be used.
1924 /* purecov: begin deadcode */
1925 type_conversion_status store(const char *, size_t,
1926 const CHARSET_INFO *) final {
1927 assert(false);
1928 return TYPE_ERR_BAD_VALUE;
1929 }
1931 assert(false);
1932 return TYPE_ERR_BAD_VALUE;
1933 }
1935 assert(false);
1936 return TYPE_ERR_BAD_VALUE;
1937 }
1939 assert(false);
1940 return TYPE_ERR_BAD_VALUE;
1941 }
1943 assert(false);
1944 return TYPE_ERR_BAD_VALUE;
1945 }
1947 assert(false);
1948 return TYPE_ERR_BAD_VALUE;
1949 }
1951 assert(false);
1952 return TYPE_ERR_BAD_VALUE;
1953 }
1954 double val_real(void) const final {
1955 assert(false);
1956 return 0.0;
1957 }
1958 longlong val_int(void) const final {
1959 assert(false);
1960 return 0;
1961 }
1963 assert(false);
1964 return nullptr;
1965 }
1966 String *val_str(String *, String *) const final {
1967 assert(false);
1968 return nullptr;
1969 }
1970 int cmp(const uchar *, const uchar *) const final {
1971 assert(false);
1972 return -1;
1973 }
1974 void sql_type(String &) const final { assert(false); }
1976 size_t make_sort_key(uchar *, size_t) const final {
1977 assert(false);
1978 return 0;
1979 }
1980 Field *clone(MEM_ROOT *mem_root) const final {
1981 return new (mem_root) Create_field_wrapper(*this);
1982 }
1983 bool is_wrapper_field() const final { return true; }
1984 /* purecov: end */
1985};
1986
1987class Field_num : public Field {
1988 private:
1989 /**
1990 Whether the field is signed or not. Meaningful only for numeric fields
1991 and numeric arrays.
1992 */
1993 const bool unsigned_flag;
1994
1995 public:
1996 const uint8 dec;
1997 /**
1998 True if the column was declared with the ZEROFILL attribute. If it has the
1999 attribute, values should be zero-padded up to the declared display width
2000 when they are converted to strings.
2001 */
2002 bool zerofill; // Purify cannot handle bit fields
2003 Field_num(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2004 uchar null_bit_arg, uchar auto_flags_arg,
2005 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
2006 bool unsigned_arg);
2007 bool is_unsigned() const final { return unsigned_flag; }
2008 Item_result result_type() const override { return REAL_RESULT; }
2009 enum Derivation derivation() const final { return DERIVATION_NUMERIC; }
2010 uint repertoire() const final { return MY_REPERTOIRE_NUMERIC; }
2011 const CHARSET_INFO *charset() const final { return &my_charset_numeric; }
2012 void prepend_zeros(String *value) const;
2013 uint decimals() const final { return (uint)dec; }
2014 bool eq_def(const Field *field) const final;
2016 type_conversion_status store_time(Time_val time, uint8 dec_arg) override;
2019 my_decimal *val_decimal(my_decimal *) const override;
2020 bool val_date(Date_val *date, my_time_flags_t flags) const override;
2021 bool val_time(Time_val *time) const override;
2022 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const override;
2023 uint is_equal(const Create_field *new_field) const override;
2024 uint row_pack_length() const final { return pack_length(); }
2025 uint32 pack_length_from_metadata(uint) const override {
2026 return pack_length();
2027 }
2029 size_t length, const char *int_end,
2030 int error);
2031 type_conversion_status get_int(const CHARSET_INFO *cs, const char *from,
2032 size_t len, longlong *rnd,
2033 ulonglong unsigned_max, longlong signed_min,
2034 longlong signed_max);
2035};
2036
2037class Field_str : public Field {
2038 protected:
2041
2042 public:
2043 Field_str(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2044 uchar null_bit_arg, uchar auto_flags_arg,
2045 const char *field_name_arg, const CHARSET_INFO *charset);
2046 Item_result result_type() const override { return STRING_RESULT; }
2048 uint decimals() const override { return DECIMAL_NOT_SPECIFIED; }
2049 void make_send_field(Send_field *field) const override;
2050 type_conversion_status store(double nr) override;
2051 type_conversion_status store(longlong nr, bool unsigned_val) override = 0;
2053 type_conversion_status store(const char *to, size_t length,
2054 const CHARSET_INFO *cs) override = 0;
2055
2056 uint repertoire() const final { return my_charset_repertoire(field_charset); }
2057 const CHARSET_INFO *charset() const override { return field_charset; }
2058 void set_charset(const CHARSET_INFO *charset_arg) {
2059 field_charset = charset_arg;
2061 }
2065 }
2066 enum Derivation derivation() const final { return field_derivation; }
2067 void set_derivation(enum Derivation derivation_arg) final {
2068 field_derivation = derivation_arg;
2069 }
2070 bool binary() const override { return field_charset == &my_charset_bin; }
2071 uint32 max_display_length() const override { return field_length; }
2072 bool str_needs_quotes() const final { return true; }
2073 uint is_equal(const Create_field *new_field) const override;
2074
2075 void add_to_cost(CostOfItem *cost) const override;
2076
2077 // An always-updated cache of the result of char_length(), because
2078 // dividing by charset()->mbmaxlen can be surprisingly costly compared
2079 // to the rest of e.g. make_sort_key().
2081};
2082
2083/* base class for Field_string, Field_varstring and Field_blob */
2084
2085class Field_longstr : public Field_str {
2086 private:
2088 const char *end,
2089 bool count_spaces);
2090
2091 protected:
2093 const char *well_formed_error_pos, const char *cannot_convert_error_pos,
2094 const char *from_end_pos, const char *end, bool count_spaces,
2095 const CHARSET_INFO *from_cs, const CHARSET_INFO *to_cs);
2096
2097 public:
2098 Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2099 uchar null_bit_arg, uchar auto_flags_arg,
2100 const char *field_name_arg, const CHARSET_INFO *charset_arg)
2101 : Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2102 field_name_arg, charset_arg) {}
2103
2105 uint32 max_data_length() const override;
2106 bool is_updatable() const final;
2107};
2108
2109/* base class for float and double and decimal (old one) */
2110class Field_real : public Field_num {
2111 public:
2114 TR_OK = 0,
2115 TR_POSITIVE_OVERFLOW = 1,
2116 TR_NEGATIVE_OVERFLOW = 2
2118
2119 Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2120 uchar null_bit_arg, uchar auto_flags_arg,
2121 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
2122 bool unsigned_arg)
2123 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2124 field_name_arg, dec_arg, zero_arg, unsigned_arg),
2125 not_fixed(dec_arg >= DECIMAL_NOT_SPECIFIED) {}
2126 type_conversion_status store_time(Time_val time, uint8 dec_arg) final;
2130 my_decimal *val_decimal(my_decimal *) const final;
2131 bool val_date(Date_val *date, my_time_flags_t flags) const final;
2132 bool val_time(Time_val *time) const final;
2133 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const override;
2134 Truncate_result truncate(double *nr, double max_length);
2135 Truncate_result truncate(double *nr, double max_length) const;
2136 uint32 max_display_length() const final { return field_length; }
2137 const uchar *unpack(uchar *to, const uchar *from, uint param_data) override;
2138 uchar *pack(uchar *to, const uchar *from, size_t max_length) const override;
2139};
2140
2141class Field_decimal final : public Field_real {
2142 public:
2143 Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2144 uchar null_bit_arg, uchar auto_flags_arg,
2145 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
2146 bool unsigned_arg)
2147 : Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2148 field_name_arg, dec_arg, zero_arg, unsigned_arg) {}
2149 enum_field_types type() const final { return MYSQL_TYPE_DECIMAL; }
2150 enum ha_base_keytype key_type() const final {
2152 }
2153 type_conversion_status store(const char *to, size_t length,
2154 const CHARSET_INFO *charset) final;
2155 type_conversion_status store(double nr) final;
2156 type_conversion_status store(longlong nr, bool unsigned_val) final;
2157 double val_real() const final;
2158 longlong val_int() const final;
2159 String *val_str(String *, String *) const final;
2160 int cmp(const uchar *, const uchar *) const final;
2162 size_t make_sort_key(uchar *buff, size_t length) const final;
2163 void overflow(bool negative);
2164 bool zero_pack() const final { return false; }
2165 void sql_type(String &str) const final;
2167 assert(type() == MYSQL_TYPE_DECIMAL);
2168 return new (mem_root) Field_decimal(*this);
2169 }
2170 const uchar *unpack(uchar *to, const uchar *from, uint param_data) final {
2171 return Field::unpack(to, from, param_data);
2172 }
2173 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final {
2174 return Field::pack(to, from, max_length);
2175 }
2176};
2177
2178/* New decimal/numeric field which use fixed point arithmetic */
2180 private:
2181 /**
2182 Normally, the underlying decimal code will degrade values' excessive
2183 precision. E.g. value 0.0 stored as decimal(10,4) will be returned as
2184 decimal(4,4). This is fine for general purpose, but isn't usable for
2185 multi-valued index. Field_typed_array uses a field for conversion and it
2186 expects the value read from it to be exactly same as it would be stored
2187 in SE, i.e with preserved precision. Otherwise, SE won't be able to
2188 index it.
2189 TRUE here tells underlying DECIMAL reading code to keep the precision as
2190 is.
2191 */
2192 bool m_keep_precision{false};
2193 int do_save_field_metadata(uchar *first_byte) const final;
2194
2195 public:
2196 /* The maximum number of decimal digits can be stored */
2199 /*
2200 Constructors take max_length of the field as a parameter - not the
2201 precision as the number of decimal digits allowed.
2202 So for example we need to count length from precision handling
2203 CREATE TABLE ( DECIMAL(x,y))
2204 */
2205 Field_new_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2206 uchar null_bit_arg, uchar auto_flags_arg,
2207 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
2208 bool unsigned_arg);
2209 Field_new_decimal(uint32 len_arg, bool is_nullable_arg,
2210 const char *field_name_arg, uint8 dec_arg,
2211 bool unsigned_arg);
2213 enum ha_base_keytype key_type() const final { return HA_KEYTYPE_BINARY; }
2214 Item_result result_type() const final { return DECIMAL_RESULT; }
2216 type_conversion_status store_value(const my_decimal *decimal_value);
2217 void set_value_on_overflow(my_decimal *decimal_value, bool sign) const;
2218 type_conversion_status store(const char *to, size_t length,
2219 const CHARSET_INFO *charset) final;
2220 type_conversion_status store(double nr) final;
2221 type_conversion_status store(longlong nr, bool unsigned_val) final;
2222 type_conversion_status store_time(Time_val time, uint8 dec_arg) final;
2226 double val_real() const final;
2227 longlong val_int() const final;
2228 my_decimal *val_decimal(my_decimal *) const final;
2229 bool val_date(Date_val *date, my_time_flags_t flags) const final;
2230 bool val_time(Time_val *time) const final;
2231 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
2232 String *val_str(String *, String *) const final;
2233 int cmp(const uchar *, const uchar *) const final;
2234 using Field_num::make_sort_key;
2235 size_t make_sort_key(uchar *buff, size_t length) const final;
2236 bool zero_pack() const final { return false; }
2237 void sql_type(String &str) const final;
2238 uint32 max_display_length() const final { return field_length; }
2239 uint32 pack_length() const final { return (uint32)bin_size; }
2240 uint pack_length_from_metadata(uint field_metadata) const final;
2241 bool compatible_field_size(uint field_metadata, Relay_log_info *, uint16,
2242 int *order_var) const final;
2243 uint is_equal(const Create_field *new_field) const final;
2245 assert(type() == MYSQL_TYPE_NEWDECIMAL);
2246 return new (mem_root) Field_new_decimal(*this);
2247 }
2248 const uchar *unpack(uchar *to, const uchar *from, uint param_data) final;
2249 static Field *create_from_item(const Item *item);
2250 bool send_to_protocol(Protocol *protocol) const final;
2251 void set_keep_precision(bool arg) { m_keep_precision = arg; }
2252};
2253
2254class Field_tiny : public Field_num {
2255 public:
2256 Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2257 uchar null_bit_arg, uchar auto_flags_arg,
2258 const char *field_name_arg, bool zero_arg, bool unsigned_arg)
2259 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2260 field_name_arg, 0, zero_arg, unsigned_arg) {}
2261 Field_tiny(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2262 bool unsigned_arg)
2263 : Field_num(nullptr, len_arg,
2264 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2265 field_name_arg, 0, false, unsigned_arg) {}
2266 enum Item_result result_type() const final { return INT_RESULT; }
2267 enum_field_types type() const override { return MYSQL_TYPE_TINY; }
2268 enum ha_base_keytype key_type() const final {
2270 }
2271 type_conversion_status store(const char *to, size_t length,
2272 const CHARSET_INFO *charset) override;
2273 type_conversion_status store(double nr) override;
2274 type_conversion_status store(longlong nr, bool unsigned_val) override;
2275 double val_real() const override;
2276 longlong val_int() const override;
2277 String *val_str(String *, String *) const override;
2278 bool send_to_protocol(Protocol *protocol) const override;
2279 int cmp(const uchar *, const uchar *) const final;
2281 size_t make_sort_key(uchar *buff, size_t length) const final;
2282 uint32 pack_length() const final { return 1; }
2283 void sql_type(String &str) const override;
2284 uint32 max_display_length() const final { return 4; }
2285 Field_tiny *clone(MEM_ROOT *mem_root) const override {
2286 assert(type() == MYSQL_TYPE_TINY);
2287 return new (mem_root) Field_tiny(*this);
2288 }
2289 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final {
2290 if (max_length > 0) *to = *from;
2291 return to + 1;
2292 }
2293
2294 const uchar *unpack(uchar *to, const uchar *from,
2295 uint param_data [[maybe_unused]]) final {
2296 *to = *from;
2297 return from + 1;
2298 }
2299
2301 return is_unsigned() ? 0xFFULL : 0x7FULL;
2302 }
2303};
2304
2305class Field_short final : public Field_num {
2306 public:
2307 Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2308 uchar null_bit_arg, uchar auto_flags_arg,
2309 const char *field_name_arg, bool zero_arg, bool unsigned_arg)
2310 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2311 field_name_arg, 0, zero_arg, unsigned_arg) {}
2312 Field_short(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2313 bool unsigned_arg)
2314 : Field_num(nullptr, len_arg,
2315 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2316 field_name_arg, 0, false, unsigned_arg) {}
2317 Field_short(uint32 len_arg, const char *field_name_arg, bool unsigned_arg)
2318 : Field_short(len_arg, false, field_name_arg, unsigned_arg) {}
2319 enum Item_result result_type() const final { return INT_RESULT; }
2320 enum_field_types type() const final { return MYSQL_TYPE_SHORT; }
2321 enum ha_base_keytype key_type() const final {
2323 }
2324 type_conversion_status store(const char *to, size_t length,
2325 const CHARSET_INFO *charset) final;
2326 type_conversion_status store(double nr) final;
2327 type_conversion_status store(longlong nr, bool unsigned_val) final;
2328 double val_real() const final;
2329 longlong val_int() const final;
2330 String *val_str(String *, String *) const final;
2331 bool send_to_protocol(Protocol *protocol) const final;
2332 int cmp(const uchar *, const uchar *) const final;
2333 using Field_num::make_sort_key;
2334 size_t make_sort_key(uchar *buff, size_t length) const final;
2335 uint32 pack_length() const final { return 2; }
2336 void sql_type(String &str) const final;
2337 uint32 max_display_length() const final { return 6; }
2339 assert(type() == MYSQL_TYPE_SHORT);
2340 return new (mem_root) Field_short(*this);
2341 }
2342 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final {
2343 return pack_int16(to, from, max_length);
2344 }
2345
2346 const uchar *unpack(uchar *to, const uchar *from,
2347 uint param_data [[maybe_unused]]) final {
2348 return unpack_int16(to, from);
2349 }
2350
2352 return is_unsigned() ? 0xFFFFULL : 0x7FFFULL;
2353 }
2354};
2355
2356class Field_medium final : public Field_num {
2357 public:
2358 Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2359 uchar null_bit_arg, uchar auto_flags_arg,
2360 const char *field_name_arg, bool zero_arg, bool unsigned_arg)
2361 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2362 field_name_arg, 0, zero_arg, unsigned_arg) {}
2363 Field_medium(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2364 bool unsigned_arg)
2365 : Field_num(nullptr, len_arg,
2366 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2367 field_name_arg, 0, false, unsigned_arg) {}
2368 enum Item_result result_type() const final { return INT_RESULT; }
2369 enum_field_types type() const final { return MYSQL_TYPE_INT24; }
2370 enum ha_base_keytype key_type() const final {
2372 }
2373 type_conversion_status store(const char *to, size_t length,
2374 const CHARSET_INFO *charset) final;
2375 type_conversion_status store(double nr) final;
2376 type_conversion_status store(longlong nr, bool unsigned_val) final;
2377 double val_real() const final;
2378 longlong val_int() const final;
2379 String *val_str(String *, String *) const final;
2380 bool send_to_protocol(Protocol *protocol) const final;
2381 int cmp(const uchar *, const uchar *) const final;
2382 using Field_num::make_sort_key;
2383 size_t make_sort_key(uchar *buff, size_t length) const final;
2384 uint32 pack_length() const final { return 3; }
2385 void sql_type(String &str) const final;
2386 uint32 max_display_length() const final { return 8; }
2388 assert(type() == MYSQL_TYPE_INT24);
2389 return new (mem_root) Field_medium(*this);
2390 }
2392 return is_unsigned() ? 0xFFFFFFULL : 0x7FFFFFULL;
2393 }
2394};
2395
2396class Field_long : public Field_num {
2397 public:
2398 static const int PACK_LENGTH = 4;
2399
2400 Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2401 uchar null_bit_arg, uchar auto_flags_arg,
2402 const char *field_name_arg, bool zero_arg, bool unsigned_arg)
2403 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2404 field_name_arg, 0, zero_arg, unsigned_arg) {}
2405 Field_long(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2406 bool unsigned_arg)
2407 : Field_num(nullptr, len_arg,
2408 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2409 field_name_arg, 0, false, unsigned_arg) {}
2410 enum Item_result result_type() const final { return INT_RESULT; }
2411 enum_field_types type() const final { return MYSQL_TYPE_LONG; }
2412 enum ha_base_keytype key_type() const final {
2414 }
2415 type_conversion_status store(const char *to, size_t length,
2416 const CHARSET_INFO *charset) final;
2417 type_conversion_status store(double nr) final;
2418 type_conversion_status store(longlong nr, bool unsigned_val) override;
2419 double val_real() const final;
2420 longlong val_int() const final;
2421 bool send_to_protocol(Protocol *protocol) const final;
2422 String *val_str(String *, String *) const final;
2423 int cmp(const uchar *, const uchar *) const final;
2424 using Field_num::make_sort_key;
2425 size_t make_sort_key(uchar *buff, size_t length) const final;
2426 uint32 pack_length() const final { return PACK_LENGTH; }
2427 void sql_type(String &str) const final;
2430 }
2432 assert(type() == MYSQL_TYPE_LONG);
2433 return new (mem_root) Field_long(*this);
2434 }
2435 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final {
2436 return pack_int32(to, from, max_length);
2437 }
2438 const uchar *unpack(uchar *to, const uchar *from,
2439 uint param_data [[maybe_unused]]) final {
2440 return unpack_int32(to, from);
2441 }
2442
2444 return is_unsigned() ? 0xFFFFFFFFULL : 0x7FFFFFFFULL;
2445 }
2446};
2447
2449 public:
2450 static const int PACK_LENGTH = 8;
2451
2452 Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2453 uchar null_bit_arg, uchar auto_flags_arg,
2454 const char *field_name_arg, bool zero_arg, bool unsigned_arg)
2455 : Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2456 field_name_arg, 0, zero_arg, unsigned_arg) {}
2457 Field_longlong(uint32 len_arg, bool is_nullable_arg,
2458 const char *field_name_arg, bool unsigned_arg)
2459 : Field_num(nullptr, len_arg,
2460 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2461 field_name_arg, 0, false, unsigned_arg) {}
2462 enum Item_result result_type() const final { return INT_RESULT; }
2464 enum ha_base_keytype key_type() const final {
2466 }
2467 type_conversion_status store(const char *to, size_t length,
2468 const CHARSET_INFO *charset) final;
2469 type_conversion_status store(double nr) final;
2470 type_conversion_status store(longlong nr, bool unsigned_val) override;
2471 double val_real() const final;
2472 longlong val_int() const override;
2473 String *val_str(String *, String *) const final;
2474 bool send_to_protocol(Protocol *protocol) const final;
2475 int cmp(const uchar *, const uchar *) const final;
2476 using Field_num::make_sort_key;
2477 size_t make_sort_key(uchar *buff, size_t length) const final;
2478 uint32 pack_length() const final { return PACK_LENGTH; }
2479 void sql_type(String &str) const final;
2480 bool can_be_compared_as_longlong() const final { return true; }
2481 uint32 max_display_length() const final { return 20; }
2483 assert(type() == MYSQL_TYPE_LONGLONG);
2484 return new (mem_root) Field_longlong(*this);
2485 }
2486 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final {
2487 return pack_int64(to, from, max_length);
2488 }
2489 const uchar *unpack(uchar *to, const uchar *from,
2490 uint param_data [[maybe_unused]]) final {
2491 return unpack_int64(to, from);
2492 }
2493
2495 return is_unsigned() ? 0xFFFFFFFFFFFFFFFFULL : 0x7FFFFFFFFFFFFFFFULL;
2496 }
2497};
2498
2499class Field_float final : public Field_real {
2500 public:
2501 Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2502 uchar null_bit_arg, uchar auto_flags_arg,
2503 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
2504 bool unsigned_arg)
2505 : Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2506 field_name_arg, dec_arg, zero_arg, unsigned_arg) {}
2507 Field_float(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2508 uint8 dec_arg, bool unsigned_arg)
2509 : Field_real(nullptr, len_arg,
2510 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2511 field_name_arg, dec_arg, false, unsigned_arg) {}
2512 enum_field_types type() const final { return MYSQL_TYPE_FLOAT; }
2513 enum ha_base_keytype key_type() const final { return HA_KEYTYPE_FLOAT; }
2514 type_conversion_status store(const char *to, size_t length,
2515 const CHARSET_INFO *charset) final;
2516 type_conversion_status store(double nr) final;
2517 type_conversion_status store(longlong nr, bool unsigned_val) final;
2518 double val_real() const final;
2519 longlong val_int() const final;
2520 String *val_str(String *, String *) const final;
2521 bool send_to_protocol(Protocol *protocol) const final;
2522 int cmp(const uchar *, const uchar *) const final;
2524 size_t make_sort_key(uchar *buff, size_t length) const final;
2525 uint32 pack_length() const final { return sizeof(float); }
2526 void sql_type(String &str) const final;
2528 assert(type() == MYSQL_TYPE_FLOAT);
2529 return new (mem_root) Field_float(*this);
2530 }
2531
2533 /*
2534 We use the maximum as per IEEE754-2008 standard, 2^24
2535 */
2536 return 0x1000000ULL;
2537 }
2538
2539 private:
2540 int do_save_field_metadata(uchar *first_byte) const final;
2541};
2542
2543class Field_double final : public Field_real {
2544 public:
2545 Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
2546 uchar null_bit_arg, uchar auto_flags_arg,
2547 const char *field_name_arg, uint8 dec_arg, bool zero_arg,
2548 bool unsigned_arg)
2549 : Field_real(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2550 field_name_arg, dec_arg, zero_arg, unsigned_arg) {}
2551 Field_double(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2552 uint8 dec_arg)
2553 : Field_real(nullptr, len_arg,
2554 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2555 field_name_arg, dec_arg, false, false) {}
2556 Field_double(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2557 uint8 dec_arg, bool unsigned_arg)
2558 : Field_real(nullptr, len_arg,
2559 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2560 field_name_arg, dec_arg, false, unsigned_arg) {}
2561 Field_double(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
2562 uint8 dec_arg, bool unsigned_arg, bool not_fixed_arg)
2563 : Field_real(nullptr, len_arg,
2564 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
2565 field_name_arg, dec_arg, false, unsigned_arg) {
2566 not_fixed = not_fixed_arg;
2567 }
2568 enum_field_types type() const final { return MYSQL_TYPE_DOUBLE; }
2569 enum ha_base_keytype key_type() const final { return HA_KEYTYPE_DOUBLE; }
2570 type_conversion_status store(const char *to, size_t length,
2571 const CHARSET_INFO *charset) final;
2572 type_conversion_status store(double nr) final;
2573 type_conversion_status store(longlong nr, bool unsigned_val) final;
2574 double val_real() const final;
2575 longlong val_int() const final;
2576 String *val_str(String *, String *) const final;
2577 bool send_to_protocol(Protocol *protocol) const final;
2578 int cmp(const uchar *, const uchar *) const final;
2580 size_t make_sort_key(uchar *buff, size_t length) const final;
2581 uint32 pack_length() const final { return sizeof(double); }
2582 void sql_type(String &str) const final;
2584 assert(type() == MYSQL_TYPE_DOUBLE);
2585 return new (mem_root) Field_double(*this);
2586 }
2587
2589 /*
2590 We use the maximum as per IEEE754-2008 standard, 2^53
2591 */
2592 return 0x20000000000000ULL;
2593 }
2594
2595 private:
2596 int do_save_field_metadata(uchar *first_byte) const final;
2597};
2598
2599/* Everything saved in this will disappear. It will always return NULL */
2600
2601class Field_null final : public Field_str {
2602 public:
2603 Field_null(uchar *ptr_arg, uint32 len_arg, uchar auto_flags_arg,
2604 const char *field_name_arg, const CHARSET_INFO *cs)
2605 // (dummy_null_buffer & 32) is true, so is_null() always returns true.
2606 : Field_str(ptr_arg, len_arg, &dummy_null_buffer, 32, auto_flags_arg,
2607 field_name_arg, cs) {}
2608 enum_field_types type() const final { return MYSQL_TYPE_NULL; }
2609 type_conversion_status store(const char *, size_t,
2610 const CHARSET_INFO *) final {
2611 return TYPE_OK;
2612 }
2613 type_conversion_status store(double) final { return TYPE_OK; }
2616 return TYPE_OK;
2617 }
2619 double val_real() const final { return 0.0; }
2620 longlong val_int() const final { return 0; }
2621 my_decimal *val_decimal(my_decimal *) const final { return nullptr; }
2622 String *val_str(String *, String *value2) const final {
2623 value2->length(0);
2624 return value2;
2625 }
2626 int cmp(const uchar *, const uchar *) const final { return 0; }
2628 size_t make_sort_key(uchar *, size_t len) const final { return len; }
2629 uint32 pack_length() const final { return 0; }
2630 void sql_type(String &str) const final;
2631 uint32 max_display_length() const final { return 4; }
2633 assert(type() == MYSQL_TYPE_NULL);
2634 return new (mem_root) Field_null(*this);
2635 }
2636};
2637
2638/*
2639 Abstract class for TIME, DATE, DATETIME, TIMESTAMP
2640*/
2641class Field_temporal : public Field {
2642 protected:
2643 uint8 dec; // Number of fractional digits (N/A for DATE)
2644
2645 /**
2646 Adjust number of decimal digits from DECIMAL_NOT_SPECIFIED to
2647 DATETIME_MAX_DECIMALS
2648 */
2649 static uint8 normalize_dec(uint8 dec_arg) {
2650 return dec_arg == DECIMAL_NOT_SPECIFIED ? DATETIME_MAX_DECIMALS : dec_arg;
2651 }
2652
2653 /**
2654 Low level routine to store a MYSQL_TIME value into a field.
2655 The value must be already properly rounded or truncated
2656 and checked for being a valid DATETIME value.
2657
2658 @param[in] ltime MYSQL_TIME value.
2659 @param[out] error Error flag vector, set in case of error.
2660 @retval false In case of success.
2661 @retval true In case of error.
2662 */
2664 int *error) = 0;
2665
2666 /**
2667 Low level routine to store a MYSQL_TIME value into a field
2668 with rounding/truncation according to the field decimals() value and
2669 sql_mode.
2670
2671 @param[in] ltime MYSQL_TIME value.
2672 @param[out] warnings Error flag vector, set in case of error.
2673 @retval false In case of success.
2674 @retval true In case of error.
2675 */
2677 int *warnings) = 0;
2678
2679 /**
2680 Store a temporal value in lldiv_t into a field,
2681 with rounding according to the field decimals() value.
2682
2683 @param[in] lld Temporal value.
2684 @param[out] warning Warning flag vector.
2685 @retval false In case of success.
2686 @retval true In case of error.
2687 */
2688 type_conversion_status store_lldiv_t(const lldiv_t *lld, int *warning);
2689
2690 /**
2691 Convert a string to MYSQL_TIME, according to the field type.
2692
2693 @param[in] str String
2694 @param[in] len String length
2695 @param[in] cs String character set
2696 @param[out] ltime The value is stored here
2697 @param[out] status Conversion status
2698 @retval false Conversion went fine, ltime contains a valid time
2699 @retval true Conversion failed, ltime was reset and contains nothing
2700 */
2701 virtual bool convert_str_to_TIME(const char *str, size_t len,
2702 const CHARSET_INFO *cs, MYSQL_TIME *ltime,
2704 /**
2705 Convert a number with fractional part with nanosecond precision
2706 into MYSQL_TIME, according to the field type. Nanoseconds
2707 are rounded to milliseconds and added to ltime->second_part.
2708
2709 @param[in] val Number
2710 @param[in] unsigned_val SIGNED/UNSIGNED flag
2711 @param[in] nanoseconds Fractional part in nanoseconds
2712 @param[out] ltime The value is stored here
2713 @param[in,out] warning Warnings found during execution
2714
2715 @return Conversion status
2716 @retval false On success
2717 @retval true On error
2718 */
2720 bool unsigned_val,
2721 int nanoseconds,
2722 MYSQL_TIME *ltime,
2723 int *warning) = 0;
2724 /**
2725 Convert an integer number into MYSQL_TIME, according to the field type.
2726
2727 @param[in] val Number
2728 @param[in] unsigned_val SIGNED/UNSIGNED flag
2729 @param[out] ltime The value is stored here
2730 @param[in,out] warnings Warnings found during execution
2731
2732 @retval false On success
2733 @retval true On error
2734 */
2735 longlong convert_int_to_datetime(longlong val, bool unsigned_val,
2736 MYSQL_TIME *ltime, int *warnings);
2737
2738 /**
2739 Set warnings from a warning vector.
2740 Note, multiple warnings can be set at the same time.
2741 Every warning in the bit vector is set by an individual
2742 set_datetime_warning() call.
2743
2744 @param str Value.
2745 @param warnings Warning vector.
2746
2747 @retval false Function reported warning
2748 @retval true Function reported error
2749
2750 @note STRICT mode can convert warnings to error.
2751 */
2752 [[nodiscard]] bool set_warnings(const ErrConvString &str, int warnings);
2753
2754 /**
2755 Flags that are passed as "flag" argument to
2756 store functions, and to e.g. int_to_datetime(), str_to_datetime().
2757
2758 Flags depend on the session sql_mode settings, such as
2759 MODE_NO_ZERO_DATE, MODE_NO_ZERO_IN_DATE.
2760 Field_timestamp always add MODE_NO_ZERO_IN_DATE and MODE_NO_INVALID_DATES,
2761 as such values cannot be stored.
2762
2763 @param thd THD
2764
2765 @returns sql_mode flags mixed with the field type flags.
2766 */
2767 virtual my_time_flags_t date_flags(const THD *thd [[maybe_unused]]) const {
2768 return 0;
2769 }
2770
2771 /**
2772 Flags that are passed as "flag" argument to
2773 check_date(), int_to_datetime(), str_to_datetime().
2774 Similar to the above when we don't have a THD value.
2775 */
2776 my_time_flags_t date_flags() const;
2777
2778 /**
2779 Produce warning or note about double datetime data saved into field.
2780
2781 @param level level of message (Note/Warning/Error)
2782 @param code error code of message to be produced
2783 @param val error parameter (the value)
2784 @param ts_type type of datetime value (datetime/date/time)
2785 @param truncate_increment whether we should increase truncated fields count
2786
2787 @retval false Function reported warning
2788 @retval true Function reported error
2789
2790 @note
2791 This function will always produce some warning but won't increase
2792 truncated fields counter if check_for_truncated_fields == FIELD_CHECK_IGNORE
2793 for current thread.
2794 */
2795 [[nodiscard]] bool set_datetime_warning(
2796 Sql_condition::enum_severity_level level, uint code,
2797 const ErrConvString &val, enum_mysql_timestamp_type ts_type,
2798 int truncate_increment);
2799
2800 public:
2801 /**
2802 Constructor for Field_temporal
2803 @param ptr_arg See Field definition
2804 @param null_ptr_arg See Field definition
2805 @param null_bit_arg See Field definition
2806 @param auto_flags_arg See Field definition
2807 @param field_name_arg See Field definition
2808 @param len_arg Number of characters in the integer part.
2809 @param dec_arg Number of second fraction digits, 0..6.
2810 */
2811 Field_temporal(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
2812 uchar auto_flags_arg, const char *field_name_arg,
2813 uint32 len_arg, uint8 dec_arg)
2814 : Field(ptr_arg,
2815 len_arg +
2816 ((normalize_dec(dec_arg)) ? normalize_dec(dec_arg) + 1 : 0),
2817 null_ptr_arg, null_bit_arg, auto_flags_arg, field_name_arg) {
2819 dec = normalize_dec(dec_arg);
2820 }
2821 Item_result result_type() const final { return STRING_RESULT; }
2822 uint32 max_display_length() const final { return field_length; }
2823 bool str_needs_quotes() const final { return true; }
2824 uint is_equal(const Create_field *new_field) const final;
2826 return dec ? DECIMAL_RESULT : INT_RESULT;
2827 }
2828 enum Item_result cmp_type() const final { return INT_RESULT; }
2829 enum Derivation derivation() const final { return DERIVATION_NUMERIC; }
2830 uint repertoire() const final { return MY_REPERTOIRE_NUMERIC; }
2831 const CHARSET_INFO *charset() const final { return &my_charset_numeric; }
2832 bool can_be_compared_as_longlong() const final { return true; }
2833 bool binary() const final { return true; }
2834 type_conversion_status store(const char *str, size_t len,
2835 const CHARSET_INFO *cs) final;
2837 type_conversion_status store(longlong nr, bool unsigned_val) override;
2838 type_conversion_status store(double nr) final;
2839 double val_real() const override // FSP-enable types redefine it.
2840 {
2841 return (double)val_int();
2842 }
2843 [[nodiscard]] uint8 get_dec() const { return dec; }
2845 my_decimal *decimal_value) const override; // FSP types redefine it
2846
2848 return date_flags(thd);
2849 }
2850
2851 uint8 get_fractional_digits() const { return dec; }
2852
2853 /**
2854 Flags for evaluation of temporal values, based on current SQL mode.
2855
2856 @param mode current thd containing SQL mode and truncation mode.
2857
2858 @returns derived evaluation flags
2859 */
2861 return ((mode & MODE_INVALID_DATES) == 0 ? TIME_NO_INVALID_DATES : 0) |
2865 }
2866};
2867
2868/**
2869 Abstract class for types with date
2870 with optional time, with or without fractional part:
2871 DATE, DATETIME, DATETIME(N), TIMESTAMP, TIMESTAMP(N).
2872*/
2874 protected:
2875 /**
2876 Low level function to get value into MYSQL_TIME,
2877 without checking for being valid.
2878 */
2879 virtual bool get_date_internal(MYSQL_TIME *ltime) const = 0;
2880
2881 virtual bool get_date_internal_at_utc(MYSQL_TIME *ltime) const {
2882 return get_date_internal(ltime);
2883 }
2884
2885 /**
2886 Get value into MYSQL_TIME and check TIME_NO_ZERO_DATE flag.
2887 @retval True on error: we get a zero value but flags disallow zero dates.
2888 @retval False on success.
2889 */
2890 bool get_internal_check_zero(MYSQL_TIME *ltime,
2891 my_time_flags_t fuzzydate) const;
2892
2893 type_conversion_status convert_number_to_TIME(longlong val, bool unsigned_val,
2894 int nanoseconds,
2895 MYSQL_TIME *ltime,
2896 int *warning) final;
2897 bool convert_str_to_TIME(const char *str, size_t len, const CHARSET_INFO *cs,
2898 MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status) final;
2899
2900 type_conversion_status store_internal_adjust_frac(MYSQL_TIME *ltime,
2901 int *warnings) final;
2903
2904 public:
2905 /**
2906 Constructor for Field_temporal
2907 @param ptr_arg See Field definition
2908 @param null_ptr_arg See Field definition
2909 @param null_bit_arg See Field definition
2910 @param auto_flags_arg See Field definition
2911 @param field_name_arg See Field definition
2912 @param int_length_arg Number of characters in the integer part.
2913 @param dec_arg Number of second fraction digits, 0..6.
2914 */
2915 Field_temporal_with_date(uchar *ptr_arg, uchar *null_ptr_arg,
2916 uchar null_bit_arg, uchar auto_flags_arg,
2917 const char *field_name_arg, uint8 int_length_arg,
2918 uint8 dec_arg)
2919 : Field_temporal(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
2920 field_name_arg, int_length_arg, dec_arg) {}
2921 bool send_to_protocol(Protocol *protocol) const override;
2922 type_conversion_status store_time(Time_val time, uint8 dec_arg) override;
2924 String *val_str(String *, String *) const override;
2925 longlong val_date_temporal() const override;
2926 longlong val_date_temporal_at_utc() const override;
2927 bool val_time(Time_val *time) const final;
2929};
2930
2931/**
2932 Abstract class for types with date and time:
2933 DATETIME, DATETIME(N), TIMESTAMP, TIMESTAMP(N).
2934*/
2936 private:
2937 int do_save_field_metadata(uchar *metadata_ptr) const final {
2938 *metadata_ptr = decimals();
2939 return 1;
2940 }
2941
2942 public:
2943 /**
2944 Constructor for Field_temporal_with_date_and_time
2945 @param ptr_arg See Field definition
2946 @param null_ptr_arg See Field definition
2947 @param null_bit_arg See Field definition
2948 @param auto_flags_arg See Field definition
2949 @param field_name_arg See Field definition
2950 @param dec_arg Number of second fraction digits, 0..6.
2951 */
2953 uchar null_bit_arg, uchar auto_flags_arg,
2954 const char *field_name_arg, uint8 dec_arg)
2955 : Field_temporal_with_date(ptr_arg, null_ptr_arg, null_bit_arg,
2956 auto_flags_arg, field_name_arg,
2957 MAX_DATETIME_WIDTH, dec_arg) {}
2958
2959 uint decimals() const final { return dec; }
2960 const CHARSET_INFO *sort_charset() const final { return &my_charset_bin; }
2962 size_t make_sort_key(uchar *to, size_t length) const final {
2963 memcpy(to, ptr, length);
2964 return length;
2965 }
2966 int cmp(const uchar *a_ptr, const uchar *b_ptr) const final {
2967 return memcmp(a_ptr, b_ptr, pack_length());
2968 }
2969 uint row_pack_length() const final { return pack_length(); }
2970 double val_real() const final;
2971 longlong val_int() const final;
2972 my_decimal *val_decimal(my_decimal *decimal_value) const final;
2973
2974 void store_timestamp(const my_timeval *tm) override;
2975
2976 protected:
2977 /**
2978 Initialize flags for TIMESTAMP DEFAULT CURRENT_TIMESTAMP / ON UPDATE
2979 CURRENT_TIMESTAMP columns.
2980
2981 @todo get rid of TIMESTAMP_FLAG and ON_UPDATE_NOW_FLAG.
2982 */
2983 void init_timestamp_flags();
2984 /**
2985 Store "struct timeval" value into field.
2986 The value must be properly rounded or truncated according
2987 to the number of fractional second digits.
2988 */
2989 virtual void store_timestamp_internal(const my_timeval *tm) = 0;
2990 bool convert_TIME_to_timestamp(const MYSQL_TIME *ltime, const Time_zone &tz,
2991 my_timeval *tm, int *error);
2992};
2993
2994/*
2995 Field implementing TIMESTAMP(N) data type, where N=0..6.
2996*/
2998 protected:
2999 bool get_date_internal(MYSQL_TIME *ltime) const final;
3000 bool get_date_internal_at_utc(MYSQL_TIME *ltime) const final;
3001 type_conversion_status store_internal(const MYSQL_TIME *ltime,
3002 int *error) final;
3003 my_time_flags_t date_flags(const THD *thd) const final;
3004 void store_timestamp_internal(const my_timeval *tm) override;
3005
3006 public:
3007 /**
3008 Field_timestamp constructor
3009 @param ptr_arg See Field definition
3010 @param null_ptr_arg See Field definition
3011 @param null_bit_arg See Field definition
3012 @param auto_flags_arg See Field definition
3013 @param field_name_arg See Field definition
3014 @param dec_arg Number of fractional second digits, 0..6.
3015 */
3016 Field_timestamp(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3017 uchar auto_flags_arg, const char *field_name_arg,
3018 uint8 dec_arg);
3019 /**
3020 Field_timestamp constructor
3021 @param is_nullable_arg See Field definition
3022 @param field_name_arg See Field definition
3023 @param dec_arg Number of fractional second digits, 0..6.
3024 */
3025 Field_timestamp(bool is_nullable_arg, const char *field_name_arg,
3026 uint8 dec_arg);
3028 assert(type() == MYSQL_TYPE_TIMESTAMP);
3029 return new (mem_root) Field_timestamp(*this);
3030 }
3031
3035 bool zero_pack() const final { return false; }
3036
3038 uint pack_length_from_metadata(uint field_metadata) const final {
3039 DBUG_TRACE;
3040 const uint tmp = my_timestamp_binary_length(field_metadata);
3041 return tmp;
3042 }
3043
3045 bool val_date(Date_val *date, my_time_flags_t flags) const final;
3046 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
3047 void sql_type(String &str) const final;
3048
3049 bool get_timestamp(my_timeval *tm, int *warnings) const final;
3051
3052 private:
3053 /**
3054 Retrieves a value from a record, without checking fuzzy date flags.
3055
3056 @param tz The time zone to convert to
3057 @param[out] ltime The timestamp value in the time zone.
3058
3059 @retval true Means that the timestamp value read is 0. ltime is not touched
3060 in this case.
3061 @retval false If timestamp is non-zero.
3062 */
3063 bool get_date_internal_at(const Time_zone *tz, MYSQL_TIME *ltime) const;
3064};
3065
3066class Field_year final : public Field_tiny {
3067 public:
3068 enum Limits { MIN_YEAR = 1901, MAX_YEAR = 2155 };
3069 Field_year(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3070 uchar auto_flags_arg, const char *field_name_arg)
3071 : Field_tiny(ptr_arg, 4, null_ptr_arg, null_bit_arg, auto_flags_arg,
3072 field_name_arg, true, true) {}
3073 Field_year(bool is_nullable_arg, const char *field_name_arg)
3074 : Field_tiny(nullptr, 4, is_nullable_arg ? &dummy_null_buffer : nullptr,
3075 0, NONE, field_name_arg, true, true) {}
3076 enum_field_types type() const final { return MYSQL_TYPE_YEAR; }
3077 type_conversion_status store(const char *to, size_t length,
3078 const CHARSET_INFO *charset) final;
3079 type_conversion_status store(double nr) final;
3080 type_conversion_status store(longlong nr, bool unsigned_val) final;
3081 type_conversion_status store_time(Time_val time, uint8 dec_arg) final;
3084 double val_real() const final;
3085 longlong val_int() const final;
3086 String *val_str(String *, String *) const final;
3087 bool val_date(Date_val *date, my_time_flags_t flags) const final;
3088 bool val_time(Time_val *time) const final;
3089 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
3090 bool send_to_protocol(Protocol *protocol) const final;
3091 void sql_type(String &str) const final;
3092 bool can_be_compared_as_longlong() const final { return true; }
3094 assert(type() == MYSQL_TYPE_YEAR);
3095 return new (mem_root) Field_year(*this);
3096 }
3097};
3098
3100 protected:
3101 static const int PACK_LENGTH = 3;
3102 my_time_flags_t date_flags(const THD *thd) const final;
3103 bool get_date_internal(MYSQL_TIME *ltime) const final;
3104 type_conversion_status store_internal(const MYSQL_TIME *ltime,
3105 int *error) final;
3106
3107 public:
3108 Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3109 uchar auto_flags_arg, const char *field_name_arg)
3110 : Field_temporal_with_date(ptr_arg, null_ptr_arg, null_bit_arg,
3111 auto_flags_arg, field_name_arg, MAX_DATE_WIDTH,
3112 0) {}
3113 Field_date(bool is_nullable_arg, const char *field_name_arg)
3115 is_nullable_arg ? &dummy_null_buffer : nullptr,
3116 0, NONE, field_name_arg, MAX_DATE_WIDTH, 0) {}
3117 enum_field_types type() const final { return MYSQL_TYPE_DATE; }
3119 enum ha_base_keytype key_type() const final { return HA_KEYTYPE_UINT24; }
3121 longlong val_int() const final;
3122 longlong val_date_temporal() const final;
3123 String *val_str(String *, String *) const final;
3124 bool send_to_protocol(Protocol *protocol) const final;
3125 int cmp(const uchar *, const uchar *) const final;
3127 size_t make_sort_key(uchar *buff, size_t length) const final;
3128 uint32 pack_length() const final { return PACK_LENGTH; }
3129 void sql_type(String &str) const final;
3130 bool zero_pack() const final { return true; }
3131 bool val_date(Date_val *date, my_time_flags_t flags) const final;
3132 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
3134 assert(type() == MYSQL_TYPE_DATE);
3135 assert(real_type() == MYSQL_TYPE_NEWDATE);
3136 return new (mem_root) Field_date(*this);
3137 }
3138};
3139
3140/**
3141 Field implementing TIME(N) data type, where N=0..6.
3142*/
3143class Field_time final : public Field_temporal {
3144 private:
3145 int do_save_field_metadata(uchar *metadata_ptr) const final {
3146 *metadata_ptr = decimals();
3147 return 1;
3148 }
3149
3150 protected:
3151 type_conversion_status store_internal(const MYSQL_TIME *ltime,
3152 int *error) final;
3153
3154 bool convert_str_to_TIME(const char *str, size_t len, const CHARSET_INFO *cs,
3155 MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status) final;
3156 /**
3157 @todo: convert_number_to_TIME returns conversion status through
3158 two different interfaces: return value and warning. It should be
3159 refactored to only use return value.
3160 */
3161 type_conversion_status convert_number_to_TIME(longlong val, bool unsigned_val,
3162 int nanoseconds,
3163 MYSQL_TIME *ltime,
3164 int *warning) final;
3165 /**
3166 Function to store time value.
3167 The value is rounded/truncated according to decimals() and sql_mode.
3168 */
3169 type_conversion_status store_internal_adjust_frac(MYSQL_TIME *ltime,
3170 int *warnings) final;
3171
3172 my_time_flags_t date_flags(const THD *thd) const final;
3174
3175 public:
3176 /**
3177 Constructor for Field_time
3178 @param ptr_arg See Field definition
3179 @param null_ptr_arg See Field definition
3180 @param null_bit_arg See Field definition
3181 @param auto_flags_arg See Field definition
3182 @param field_name_arg See Field definition
3183 @param dec_arg Number of second fraction digits, 0..6.
3184 */
3185 Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3186 uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg)
3187 : Field_temporal(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
3188 field_name_arg, MAX_TIME_WIDTH, dec_arg) {}
3189 /**
3190 Constructor for Field_time
3191 @param is_nullable_arg See Field definition
3192 @param field_name_arg See Field definition
3193 @param dec_arg Number of second fraction digits, 0..6.
3194 */
3195 Field_time(bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg)
3196 : Field_temporal(nullptr, is_nullable_arg ? &dummy_null_buffer : nullptr,
3197 0, NONE, field_name_arg, MAX_TIME_WIDTH, dec_arg) {}
3199 assert(type() == MYSQL_TYPE_TIME);
3200 return new (mem_root) Field_time(*this);
3201 }
3202 uint decimals() const final { return dec; }
3203 enum_field_types type() const final { return MYSQL_TYPE_TIME; }
3207 type_conversion_status store_time(Time_val time, uint8 dec_arg) final;
3210 double val_real() const final;
3211 longlong val_int() const final;
3212 String *val_str(String *, String *) const final;
3213 bool val_date(Date_val *date, my_time_flags_t flags) const final;
3214 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
3215 longlong val_date_temporal() const final;
3216 bool send_to_protocol(Protocol *protocol) const final;
3217 bool val_time(Time_val *time) const final;
3218 my_decimal *val_decimal(my_decimal *) const final;
3219 uint32 pack_length() const final { return my_time_binary_length(dec); }
3220 uint pack_length_from_metadata(uint field_metadata) const final {
3221 DBUG_TRACE;
3222 const uint tmp = my_time_binary_length(field_metadata);
3223 return tmp;
3224 }
3225 uint row_pack_length() const final { return pack_length(); }
3226 void sql_type(String &str) const final;
3227 bool zero_pack() const final { return true; }
3228 const CHARSET_INFO *sort_charset() const final { return &my_charset_bin; }
3230 size_t make_sort_key(uchar *to, size_t length) const final {
3231 memcpy(to, ptr, length);
3232 return length;
3233 }
3234 int cmp(const uchar *a_ptr, const uchar *b_ptr) const final {
3235 return memcmp(a_ptr, b_ptr, pack_length());
3236 }
3237};
3238
3239/*
3240 Field implementing DATETIME(N) data type, where N=0..6.
3241*/
3243 protected:
3244 bool get_date_internal(MYSQL_TIME *ltime) const final;
3245 type_conversion_status store_internal(const MYSQL_TIME *ltime,
3246 int *error) final;
3247 my_time_flags_t date_flags(const THD *thd) const final;
3248 void store_timestamp_internal(const my_timeval *tm) final;
3249
3250 public:
3251 /**
3252 Constructor for Field_datetime
3253 @param ptr_arg See Field definition
3254 @param null_ptr_arg See Field definition
3255 @param null_bit_arg See Field definition
3256 @param auto_flags_arg See Field definition
3257 @param field_name_arg See Field definition
3258 @param dec_arg Number of second fraction digits, 0..6.
3259 */
3260 Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3261 uchar auto_flags_arg, const char *field_name_arg,
3262 uint8 dec_arg)
3263 : Field_temporal_with_date_and_time(ptr_arg, null_ptr_arg, null_bit_arg,
3264 auto_flags_arg, field_name_arg,
3265 dec_arg) {}
3266 /**
3267 Constructor for Field_datetime
3268 @param is_nullable_arg See Field definition
3269 @param field_name_arg See Field definition
3270 @param dec_arg Number of second fraction digits, 0..6.
3271 */
3272 Field_datetime(bool is_nullable_arg, const char *field_name_arg,
3273 uint8 dec_arg)
3275 nullptr, is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
3276 field_name_arg, dec_arg) {}
3277 Field_datetime(const char *field_name_arg)
3279 field_name_arg, 0) {}
3281 assert(type() == MYSQL_TYPE_DATETIME);
3282 return new (mem_root) Field_datetime(*this);
3283 }
3284
3289 uint pack_length_from_metadata(uint field_metadata) const final {
3290 DBUG_TRACE;
3291 const uint tmp = my_datetime_binary_length(field_metadata);
3292 return tmp;
3293 }
3294 bool zero_pack() const final { return true; }
3295
3298 longlong val_date_temporal() const final;
3299 bool val_date(Date_val *date, my_time_flags_t flags) const final;
3300 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
3301 void sql_type(String &str) const final;
3302};
3303
3305 public:
3306 Field_string(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
3307 uchar null_bit_arg, uchar auto_flags_arg,
3308 const char *field_name_arg, const CHARSET_INFO *cs)
3309 : Field_longstr(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
3310 auto_flags_arg, field_name_arg, cs) {}
3311 Field_string(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
3312 const CHARSET_INFO *cs)
3313 : Field_longstr(nullptr, len_arg,
3314 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
3315 field_name_arg, cs) {}
3316
3317 enum_field_types type() const final { return MYSQL_TYPE_STRING; }
3318 bool match_collation_to_optimize_range() const final { return true; }
3319 enum ha_base_keytype key_type() const final {
3321 }
3322 bool zero_pack() const final { return false; }
3324 charset()->cset->fill(charset(), (char *)ptr, field_length,
3325 (has_charset() ? ' ' : 0));
3326 return TYPE_OK;
3327 }
3328 type_conversion_status store(const char *to, size_t length,
3329 const CHARSET_INFO *charset) final;
3330 type_conversion_status store(longlong nr, bool unsigned_val) final;
3331 // Inherit the store() overloads that have not been overridden.
3333 double val_real() const final;
3334 longlong val_int() const final;
3335 String *val_str(String *, String *) const final;
3336 /**
3337 Get the C-string value, without using String class.
3338 @returns The C-string value of this field.
3339 */
3340 LEX_CSTRING val_str_quick() const {
3341 const char *string = pointer_cast<const char *>(ptr);
3342 return {string,
3344 }
3345 my_decimal *val_decimal(my_decimal *) const final;
3346 int cmp(const uchar *, const uchar *) const final;
3347 size_t make_sort_key(uchar *buff, size_t length) const final;
3348 size_t make_sort_key(uchar *to, size_t length, size_t trunc_pos) const final;
3349 void sql_type(String &str) const final;
3350 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final;
3351 const uchar *unpack(uchar *to, const uchar *from, uint param_data) final;
3352 uint pack_length_from_metadata(uint field_metadata) const final {
3353 DBUG_PRINT("debug", ("field_metadata: 0x%04x", field_metadata));
3354 if (field_metadata == 0) return row_pack_length();
3355 return (((field_metadata >> 4) & 0x300) ^ 0x300) +
3356 (field_metadata & 0x00ff);
3357 }
3358 bool compatible_field_size(uint field_metadata, Relay_log_info *rli,
3359 uint16 mflags, int *order_var) const final;
3360 uint row_pack_length() const final { return field_length; }
3361 uint max_packed_col_length() const final;
3363 bool has_charset() const final {
3364 return charset() == &my_charset_bin ? false : true;
3365 }
3367 assert(real_type() == MYSQL_TYPE_STRING);
3368 return new (mem_root) Field_string(*this);
3369 }
3370 size_t get_key_image(uchar *buff, size_t length, imagetype type) const final;
3371 bool is_text_key_type() const final { return binary() ? false : true; }
3372
3373 private:
3374 int do_save_field_metadata(uchar *first_byte) const final;
3375};
3376
3378 public:
3379 Field_varstring(uchar *ptr_arg, uint32 len_arg, uint length_bytes_arg,
3380 uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg,
3381 const char *field_name_arg, TABLE_SHARE *share,
3382 const CHARSET_INFO *cs);
3383 Field_varstring(uint32 len_arg, bool is_nullable_arg,
3384 const char *field_name_arg, TABLE_SHARE *share,
3385 const CHARSET_INFO *cs);
3386
3387 enum_field_types type() const final { return MYSQL_TYPE_VARCHAR; }
3388 bool match_collation_to_optimize_range() const final { return true; }
3389 enum ha_base_keytype key_type() const final;
3390 uint row_pack_length() const final { return field_length; }
3391 bool zero_pack() const final { return false; }
3392 uint32 pack_length() const final {
3393 return (uint32)field_length + length_bytes;
3394 }
3395 uint32 key_length() const final { return (uint32)field_length; }
3396 type_conversion_status store(const char *to, size_t length,
3397 const CHARSET_INFO *charset) override;
3398 type_conversion_status store(longlong nr, bool unsigned_val) final;
3399 // Inherit the store() overloads that have not been overridden.
3401 double val_real() const final;
3402 longlong val_int() const final;
3403 String *val_str(String *, String *) const override;
3404 my_decimal *val_decimal(my_decimal *) const final;
3405 int cmp_max(const uchar *, const uchar *, uint max_length) const final;
3406 int cmp(const uchar *a, const uchar *b) const final {
3407 return cmp_max(a, b, ~0U);
3408 }
3409 size_t make_sort_key(uchar *buff, size_t length) const final;
3410 size_t make_sort_key(uchar *to, size_t length, size_t trunc_pos) const final;
3411 size_t get_key_image(uchar *buff, size_t length, imagetype type) const final;
3412 void set_key_image(const uchar *buff, size_t length) final;
3413 void sql_type(String &str) const final;
3414 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final;
3415 const uchar *unpack(uchar *to, const uchar *from, uint param_data) final;
3416 int cmp_binary(const uchar *a, const uchar *b,
3417 uint32 max_length = ~0L) const final;
3418 int key_cmp(const uchar *, const uchar *) const final;
3419 int key_cmp(const uchar *str, uint length) const final;
3420
3421 uint32 data_length(ptrdiff_t row_offset = 0) const final;
3423 bool has_charset() const final {
3424 return charset() == &my_charset_bin ? false : true;
3425 }
3426 Field *new_field(MEM_ROOT *root, TABLE *new_table) const final;
3427 Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr,
3428 uchar *new_null_ptr, uint new_null_bit) const final;
3430 assert(type() == MYSQL_TYPE_VARCHAR);
3431 assert(real_type() == MYSQL_TYPE_VARCHAR);
3432 return new (mem_root) Field_varstring(*this);
3433 }
3434 uint is_equal(const Create_field *new_field) const final;
3435 void hash(ulong *nr, ulong *nr2) const final;
3436 const uchar *data_ptr() const final { return ptr + length_bytes; }
3437 bool is_text_key_type() const final { return binary() ? false : true; }
3438 uint32 get_length_bytes() const override { return length_bytes; }
3439
3440 private:
3441 /* Store number of bytes used to store length (1 or 2) */
3443
3444 int do_save_field_metadata(uchar *first_byte) const final;
3445};
3446
3448 virtual type_conversion_status store_internal(const char *from, size_t length,
3449 const CHARSET_INFO *cs);
3450 /**
3451 Copy value to memory storage.
3452 */
3453 type_conversion_status store_to_mem(const char *from, size_t length,
3454 const CHARSET_INFO *cs, size_t max_length,
3456
3457 protected:
3458 /**
3459 The number of bytes used to represent the length of the blob.
3460 */
3462
3463 /**
3464 The 'value'-object is a cache fronting the storage engine.
3465 */
3467
3468 private:
3469 /**
3470 In order to support update of virtual generated columns of blob type,
3471 we need to allocate the space blob needs on server for old_row and
3472 new_row respectively. This variable is used to record the
3473 allocated blob space for old_row.
3474 */
3476
3477 /**
3478 Whether we need to move the content of 'value' to 'old_value' before
3479 updating the BLOB stored in 'value'. This needs to be done for
3480 updates of BLOB columns that are virtual since the storage engine
3481 does not have its own copy of the old 'value'. This variable is set
3482 to true when we read the data into 'value'. It is reset when we move
3483 'value' to 'old_value'. The purpose of having this is to avoid that we
3484 do the move operation from 'value' to 'old_value' more than one time per
3485 record.
3486 Currently, this variable is introduced because the following call in
3487 sql_data_change.cc:
3488 \/\**
3489 @todo combine this call to update_generated_write_fields() with the one
3490 in fill_record() to avoid updating virtual generated fields twice.
3491 *\/
3492 if (table->has_gcol())
3493 update_generated_write_fields(table->write_set, table);
3494 When the @todo is done, m_keep_old_value can be deleted.
3495 */
3497
3498 /**
3499 Backup String for table's blob fields.
3500 UPDATE of a virtual field (for index update) requires two values to be
3501 kept at the same time - 'new' and 'old' since SE (InnoDB) doesn't know the
3502 latter. In the case when there was an indexed record, it got deleted and
3503 When INSERT inserts into an index a record that coincides with a
3504 previously deleted one, InnoDB needs to recalculate value that was
3505 deleted in order to properly insert the new one.
3506 When two above overlap, a field have to keep 3 different values at the
3507 same time - 'new', 'old' and 'deleted'.
3508 This backup_value is used by @see my_eval_gcolumn_expr_helper() to save
3509 'new' and provide space for 'deleted' to avoid thrashing the former.
3510 Unlike the old_value, backup_value is allocated once and reused for each
3511 new re-calculation, to avoid excessive [re-]allocations. It's freed at the
3512 end of statement. Since InnoDB consumes calculated values only after all
3513 needed table's virtual fields were calculated, we have to have such backup
3514 buffer for each field.
3515
3516 Also used for set operation hashing: we need to compare the new
3517 and the existing record with the same hash.
3518 */
3520
3521#ifndef NDEBUG
3522 /**
3523 Whether the field uses table's backup value storage. @see
3524 TABLE::m_blob_backup. Used only for debug.
3525 */
3526 bool m_uses_backup{false};
3527#endif
3528
3529 protected:
3530 /**
3531 Store ptr and length.
3532 */
3533 void store_ptr_and_length(const char *from, uint32 length) {
3534 store_length(length);
3535 memmove(ptr + packlength, &from, sizeof(char *));
3536 }
3537
3538 public:
3539 Field_blob(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg,
3540 uchar auto_flags_arg, const char *field_name_arg,
3541 TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO *cs);
3542
3543 Field_blob(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
3544 const CHARSET_INFO *cs, bool set_packlength)
3545 : Field_longstr(nullptr, len_arg,
3546 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
3547 field_name_arg, cs),
3548 packlength(4),
3549 m_keep_old_value(false) {
3551 if (set_packlength) {
3552 packlength = len_arg <= 255 ? 1
3553 : len_arg <= 65535 ? 2
3554 : len_arg <= 16777215 ? 3
3555 : 4;
3556 }
3557 }
3558
3559 /// Copy static information and reset dynamic information.
3561 : Field_longstr(field),
3562 packlength(field.packlength),
3563 value(),
3564 old_value(),
3565 m_keep_old_value(field.m_keep_old_value),
3566 m_blob_backup() {
3567#ifndef NDEBUG
3568 m_uses_backup = field.m_uses_backup;
3569#endif
3570 }
3571
3572 explicit Field_blob(uint32 packlength_arg);
3573
3574 /* Note that the default copy constructor is used, in clone() */
3575 enum_field_types type() const override { return MYSQL_TYPE_BLOB; }
3576 bool match_collation_to_optimize_range() const override { return true; }
3577 enum ha_base_keytype key_type() const override {
3579 }
3580 type_conversion_status store(const char *to, size_t length,
3581 const CHARSET_INFO *charset) override;
3582 type_conversion_status store(double nr) override;
3583 type_conversion_status store(longlong nr, bool unsigned_val) override;
3584 type_conversion_status store(const Field *from);
3585 double val_real() const override;
3586 longlong val_int() const override;
3587 String *val_str(String *, String *) const override;
3588 my_decimal *val_decimal(my_decimal *) const override;
3589 int cmp_max(const uchar *, const uchar *, uint max_length) const final;
3590 int cmp(const uchar *a, const uchar *b) const final {
3591 return cmp_max(a, b, ~0U);
3592 }
3593 int cmp(const uchar *a, uint32 a_length, const uchar *b,
3594 uint32 b_length) const; // No override.
3595 int cmp_binary(const uchar *a, const uchar *b,
3596 uint32 max_length = ~0L) const override;
3597 int key_cmp(const uchar *, const uchar *) const override;
3598 int key_cmp(const uchar *str, uint length) const override;
3599 uint32 key_length() const override { return 0; }
3600 size_t make_sort_key(uchar *buff, size_t length) const override;
3601 size_t make_sort_key(uchar *to, size_t length, size_t trunc_pos) const final;
3602 uint32 pack_length() const final {
3603 return (uint32)(packlength + portable_sizeof_char_ptr);
3604 }
3605
3606 /**
3607 Return the packed length without the pointer size added.
3608
3609 This is used to determine the size of the actual data in the row
3610 buffer.
3611
3612 @returns The length of the raw data itself without the pointer.
3613 */
3614 uint32 pack_length_no_ptr() const { return (uint32)(packlength); }
3615 uint row_pack_length() const final { return pack_length_no_ptr(); }
3616 uint32 max_data_length() const override {
3617 return (uint32)(((ulonglong)1 << (packlength * 8)) - 1);
3618 }
3619 size_t get_field_buffer_size() { return value.alloced_length(); }
3620 void store_length(uchar *i_ptr, uint i_packlength, uint32 i_number);
3621 inline void store_length(uint32 number) {
3622 store_length(ptr, packlength, number);
3623 }
3624 uint32 data_length(ptrdiff_t row_offset = 0) const final {
3625 return get_length(row_offset);
3626 }
3627 uint32 get_length(ptrdiff_t row_offset = 0) const;
3628 uint32 get_length(const uchar *ptr, uint packlength) const;
3629 uint32 get_length(const uchar *ptr_arg) const;
3630 /** Get a const pointer to the BLOB data of this field. */
3631 const uchar *get_blob_data() const { return get_blob_data(ptr + packlength); }
3632 /** Get a non-const pointer to the BLOB data of this field. */
3633 uchar *get_blob_data(ptrdiff_t row_offset = 0) {
3634 // row_offset is only used by NDB
3635 return get_blob_data(ptr + packlength + row_offset);
3636 }
3637 /** Get a const pointer to the BLOB data of this field. */
3638 const uchar *data_ptr() const final { return get_blob_data(); }
3639
3640 protected:
3641 /**
3642 Get the BLOB data pointer stored at the specified position in the record
3643 buffer.
3644 */
3645 static uchar *get_blob_data(const uchar *position) {
3646 uchar *data;
3647 memcpy(&data, position, sizeof(data));
3648 return data;
3649 }
3650
3651 public:
3652 void set_ptr(const uchar *length, const uchar *data) {
3653 memcpy(ptr, length, packlength);
3654 memcpy(ptr + packlength, &data, sizeof(char *));
3655 }
3656 void set_ptr_offset(ptrdiff_t ptr_diff, uint32 length, const uchar *data) {
3657 uchar *ptr_ofs = ptr + ptr_diff;
3658 store_length(ptr_ofs, packlength, length);
3659 memcpy(ptr_ofs + packlength, &data, sizeof(char *));
3660 }
3661 void set_ptr(uint32 length, const uchar *data) {
3662 set_ptr_offset(0, length, data);
3663 }
3664 size_t get_key_image(uchar *buff, size_t length,
3665 imagetype type) const override;
3666 void set_key_image(const uchar *buff, size_t length) final;
3667 void sql_type(String &str) const override;
3668 bool copy();
3669 Field_blob *clone(MEM_ROOT *mem_root) const override {
3670 assert(type() == MYSQL_TYPE_BLOB);
3671 return new (mem_root) Field_blob(*this);
3672 }
3673 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final;
3674 uchar *pack_with_metadata_bytes(uchar *to, const uchar *from,
3675 uint max_length) const final;
3676 const uchar *unpack(uchar *, const uchar *from, uint param_data) final;
3677 uint max_packed_col_length() const final;
3678 void mem_free() final {
3679 // Free all allocated space
3680 value.mem_free();
3681 old_value.mem_free();
3682 m_blob_backup.mem_free();
3683 }
3684 bool has_charset() const override {
3685 return charset() == &my_charset_bin ? false : true;
3686 }
3687 uint32 max_display_length() const final;
3688 uint32 char_length() const override;
3689 bool copy_blob_value(MEM_ROOT *mem_root);
3690 uint is_equal(const Create_field *new_field) const override;
3691 bool is_text_key_type() const final { return binary() ? false : true; }
3692
3693 /**
3694 Mark that the BLOB stored in value should be copied before updating it.
3695
3696 When updating virtual generated columns we need to keep the old
3697 'value' for BLOBs since this can be needed when the storage engine
3698 does the update. During read of the record the old 'value' for the
3699 BLOB is evaluated and stored in 'value'. This function is to be used
3700 to specify that we need to copy this BLOB 'value' into 'old_value'
3701 before we compute the new BLOB 'value'. For more information @see
3702 Field_blob::keep_old_value().
3703 */
3704 void set_keep_old_value(bool old_value_flag) {
3705 /*
3706 We should only need to keep a copy of the blob 'value' in the case
3707 where this is a virtual generated column (that is indexed).
3708 */
3709 assert(is_virtual_gcol());
3710
3711 /*
3712 If set to true, ensure that 'value' is copied to 'old_value' when
3713 keep_old_value() is called.
3714 */
3715 m_keep_old_value = old_value_flag;
3716 }
3717
3718 /**
3719 Save the current BLOB value to avoid that it gets overwritten.
3720
3721 This is used when updating virtual generated columns that are
3722 BLOBs. Some storage engines require that we have both the old and
3723 new BLOB value for virtual generated columns that are indexed in
3724 order for the storage engine to be able to maintain the index. This
3725 function will transfer the buffer storing the current BLOB value
3726 from 'value' to 'old_value'. This avoids that the current BLOB value
3727 is over-written when the new BLOB value is saved into this field.
3728
3729 The reason this requires special handling when updating/deleting
3730 virtual columns of BLOB type is that the BLOB value is not known to
3731 the storage engine. For stored columns, the "old" BLOB value is read
3732 by the storage engine, Field_blob is made to point to the engine's
3733 internal buffer; Field_blob's internal buffer (Field_blob::value)
3734 isn't used and remains available to store the "new" value. For
3735 virtual generated columns, the "old" value is written directly into
3736 Field_blob::value when reading the record to be
3737 updated/deleted. This is done in update_generated_read_fields().
3738 Since, in this case, the "old" value already occupies the place to
3739 store the "new" value, we must call this function before we write
3740 the "new" value into Field_blob::value object so that the "old"
3741 value does not get over-written. The table->record[1] buffer will
3742 have a pointer that points to the memory buffer inside
3743 old_value. The storage engine will use table->record[1] to read the
3744 old value for the BLOB and use table->record[0] to read the new
3745 value.
3746
3747 This function must be called before we store the new BLOB value in
3748 this field object.
3749 */
3751 /*
3752 We should only need to keep a copy of the blob value in the case
3753 where this is a virtual generated column (that is indexed).
3754 */
3755 assert(is_virtual_gcol());
3756
3757 // Transfer ownership of the current BLOB value to old_value
3758 if (m_keep_old_value) {
3759 old_value.takeover(value);
3760 m_keep_old_value = false;
3761 }
3762 }
3763
3764 /**
3765 Use to store the blob value into an allocated space.
3766 */
3767 void store_in_allocated_space(const char *from, uint32 length) {
3768 store_ptr_and_length(from, length);
3769 }
3770
3771 /**
3772 Backup data stored in 'value' into the backup_value
3773 @see Field_blob::backup_value
3774
3775 @returns
3776 true if backup fails
3777 false otherwise
3778 */
3779 bool backup_blob_field();
3780
3781 /**
3782 Restore backup value
3783 @see Field_blob::backup_value
3784 */
3785 void restore_blob_backup();
3786
3787 private:
3788 int do_save_field_metadata(uchar *first_byte) const override;
3789};
3790
3791class Field_vector : public Field_blob {
3792 public:
3793 static const uint32 max_dimensions = vector_constants::max_dimensions;
3794 static const uint32 precision = sizeof(float);
3795 static uint32 dimension_bytes(uint32 dimensions) {
3796 return precision * dimensions;
3797 }
3799 return get_dimensions(field_length, precision);
3800 }
3801
3802 Field_vector(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
3803 uchar null_bit_arg, uchar auto_flags_arg,
3804 const char *field_name_arg, TABLE_SHARE *share,
3805 uint blob_pack_length, const CHARSET_INFO *cs)
3806 : Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
3807 field_name_arg, share, blob_pack_length, cs) {
3808 set_field_length(len_arg);
3809 assert(packlength == 4);
3810 }
3811
3812 Field_vector(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
3813 const CHARSET_INFO *cs)
3814 : Field_blob(len_arg, is_nullable_arg, field_name_arg, cs, false) {
3815 set_field_length(len_arg);
3816 assert(packlength == 4);
3817 }
3818
3819 Field_vector(const Field_vector &field) : Field_blob(field) {
3820 assert(packlength == 4);
3821 }
3822
3823 void sql_type(String &res) const override {
3824 const CHARSET_INFO *cs = res.charset();
3825 size_t length =
3826 cs->cset->snprintf(cs, res.ptr(), res.alloced_length(), "%s(%u)",
3827 "vector", get_max_dimensions());
3828 res.length(length);
3829 }
3831 assert(type() == MYSQL_TYPE_VECTOR);
3832 return new (mem_root) Field_vector(*this);
3833 }
3834 uint32 max_data_length() const override { return field_length; }
3835 uint32 char_length() const override { return field_length; }
3836 enum_field_types type() const final { return MYSQL_TYPE_VECTOR; }
3838 void make_send_field(Send_field *field) const override;
3839 using Field_blob::store;
3840 type_conversion_status store(double nr) final;
3841 type_conversion_status store(longlong nr, bool unsigned_val) final;
3843 type_conversion_status store(const char *from, size_t length,
3844 const CHARSET_INFO *cs) final;
3845 bool eq_def(const Field *field) const override;
3846 uint is_equal(const Create_field *new_field) const override;
3847 String *val_str(String *, String *) const override;
3848};
3849
3850class Field_geom final : public Field_blob {
3851 private:
3852 const std::optional<gis::srid_t> m_srid;
3853
3854 type_conversion_status store_internal(const char *from, size_t length,
3855 const CHARSET_INFO *cs) final;
3856
3857 public:
3859
3860 Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
3861 uchar auto_flags_arg, const char *field_name_arg,
3862 TABLE_SHARE *share, uint blob_pack_length,
3863 enum geometry_type geom_type_arg, std::optional<gis::srid_t> srid)
3864 : Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
3865 field_name_arg, share, blob_pack_length, &my_charset_bin),
3866 m_srid(srid),
3867 geom_type(geom_type_arg) {}
3868 Field_geom(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
3869 enum geometry_type geom_type_arg, std::optional<gis::srid_t> srid)
3870 : Field_blob(len_arg, is_nullable_arg, field_name_arg, &my_charset_bin,
3871 false),
3872 m_srid(srid),
3873 geom_type(geom_type_arg) {}
3874 enum ha_base_keytype key_type() const final { return HA_KEYTYPE_VARBINARY2; }
3876 bool match_collation_to_optimize_range() const final { return false; }
3877 void sql_type(String &str) const final;
3878 using Field_blob::store;
3879 type_conversion_status store(double nr) final;
3880 type_conversion_status store(longlong nr, bool unsigned_val) final;
3882 type_conversion_status store(const char *from, size_t length,
3883 const CHARSET_INFO *cs) final;
3884
3885 /**
3886 Non-nullable GEOMETRY types cannot have defaults,
3887 but the underlying blob must still be reset.
3888 */
3891 if (res != TYPE_OK) return res;
3892 return (is_nullable() || table->is_nullable())
3893 ? TYPE_OK
3895 }
3896
3897 geometry_type get_geometry_type() const final { return geom_type; }
3899 assert(type() == MYSQL_TYPE_GEOMETRY);
3900 return new (mem_root) Field_geom(*this);
3901 }
3902 uint is_equal(const Create_field *new_field) const final;
3903
3904 std::optional<gis::srid_t> get_srid() const { return m_srid; }
3905};
3906
3907/// A field that stores a JSON value.
3908class Field_json : public Field_blob {
3909 type_conversion_status unsupported_conversion();
3910 type_conversion_status store_binary(const char *ptr, size_t length);
3911
3912 public:
3913 Field_json(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg,
3914 uchar auto_flags_arg, const char *field_name_arg,
3915 TABLE_SHARE *share, uint blob_pack_length)
3916 : Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
3917 field_name_arg, share, blob_pack_length, &my_charset_bin) {}
3918
3919 Field_json(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg)
3920 : Field_blob(len_arg, is_nullable_arg, field_name_arg, &my_charset_bin,
3921 false) {}
3922
3923 enum_field_types type() const override { return MYSQL_TYPE_JSON; }
3924 void sql_type(String &str) const override;
3925 /**
3926 Return a text charset so that string functions automatically
3927 convert the field value to string and treat it as a non-binary
3928 string.
3929 */
3930 const CHARSET_INFO *charset() const override {
3931 return &my_charset_utf8mb4_bin;
3932 }
3933 /**
3934 Sort should treat the field as binary and not attempt any
3935 conversions.
3936 */
3937 const CHARSET_INFO *sort_charset() const final { return field_charset; }
3938 /**
3939 JSON columns don't have an associated charset. Returning false
3940 here prevents SHOW CREATE TABLE from attaching a CHARACTER SET
3941 clause to the column.
3942 */
3943 bool has_charset() const final { return false; }
3944 type_conversion_status store(const char *to, size_t length,
3945 const CHARSET_INFO *charset) override;
3946 type_conversion_status store(double nr) override;
3947 type_conversion_status store(longlong nr, bool unsigned_val) override;
3949 type_conversion_status store_json(const Json_wrapper *json);
3950 type_conversion_status store_time(Time_val time, uint8 dec_arg) final;
3952 type_conversion_status store_time(MYSQL_TIME *ltime, uint8 dec_arg) final;
3954
3955 bool pack_diff(uchar **to, ulonglong value_options) const final;
3956 /**
3957 Return the length of this field, taking into consideration that it may be in
3958 partial format.
3959
3960 This is the format used when writing the binary log in row format
3961 and using a partial format according to
3962 @@session.binlog_row_value_options.
3963
3964 @param[in] value_options The value of binlog_row_value options.
3965
3966 @param[out] diff_vector_p If this is not NULL, the pointer it
3967 points to will be set to NULL if the field is to be stored in full
3968 format, or to the Json_diff_vector if the field is to be stored in
3969 partial format.
3970
3971 @return The number of bytes needed when writing to the binlog: the
3972 size of the full format if stored in full format and the size of
3973 the diffs if stored in partial format.
3974 */
3975 longlong get_diff_vector_and_length(
3976 ulonglong value_options,
3977 const Json_diff_vector **diff_vector_p = nullptr) const;
3978 /**
3979 Return true if the before-image and after-image for this field are
3980 equal.
3981 */
3982 bool is_before_image_equal_to_after_image() const;
3983 /**
3984 Read the binary diff from the given buffer, and apply it to this field.
3985
3986 @param[in,out] from Pointer to buffer where the binary diff is stored.
3987 This will be changed to point to the next byte after the field.
3988
3989 @retval false Success
3990 @retval true Error (e.g. failed to apply the diff). The error has
3991 been reported through my_error.
3992 */
3993 bool unpack_diff(const uchar **from);
3994
3995 /**
3996 Retrieve the field's value as a JSON wrapper. It
3997 there is an error, wr is not modified and we return
3998 false, else true.
3999
4000 @param[out] wr the JSON value
4001 @return true if a value is retrieved (or NULL), false if error
4002 */
4003 bool val_json(Json_wrapper *wr) const;
4004
4005 /**
4006 Retrieve the JSON as an int if possible. This requires a JSON scalar
4007 of suitable type.
4008
4009 @returns the JSON value as an int
4010 */
4011 longlong val_int() const final;
4012
4013 /**
4014 Retrieve the JSON as a double if possible. This requires a JSON scalar
4015 of suitable type.
4016
4017 @returns the JSON value as a double
4018 */
4019 double val_real() const final;
4020
4021 /**
4022 Retrieve the JSON value stored in this field as text
4023
4024 @param[in,out] buf1 string buffer for converting JSON value to string
4025 @param[in,out] buf2 unused
4026 */
4027 String *val_str(String *buf1, String *buf2) const final;
4028 my_decimal *val_decimal(my_decimal *m) const final;
4029 bool val_time(Time_val *time) const final;
4030 bool val_date(Date_val *date, my_time_flags_t flags) const final;
4031 bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const final;
4032 Field_json *clone(MEM_ROOT *mem_root) const override;
4033 uint is_equal(const Create_field *new_field) const final;
4034 Item_result cast_to_int_type() const final { return INT_RESULT; }
4035 int cmp_binary(const uchar *a, const uchar *b,
4036 uint32 max_length = ~0L) const final;
4038 size_t make_sort_key(uchar *to, size_t length) const override;
4039
4040 /**
4041 Make a hash key that can be used by sql_executor.cc/unique_hash
4042 in order to support SELECT DISTINCT
4043
4044 @param[in] hash_val An initial hash value.
4045 */
4046 ulonglong make_hash_key(ulonglong hash_val) const;
4047
4048 /**
4049 Get a read-only pointer to the binary representation of the JSON document
4050 in this field.
4051
4052 @param row_offset Field's data offset
4053 */
4054 const char *get_binary(ptrdiff_t row_offset = 0) const;
4055};
4056
4057/**
4058 Field that stores array of values of the same type.
4059
4060 This Field class is used together with Item_func_array_cast class
4061 (CAST( .. AS .. ARRAY) function) in implementation of multi-valued index.
4062 Effectively it's a JSON field that contains a single JSON array. When a
4063 JSON value is stored, it's checked to be either a scalar, or an array.
4064 All source values are converted using the internal conversion field and
4065 stored as an array. Field_typed_array ensures that all values stored
4066 in the array have the same type and precision - the one specified by user.
4067 This way InnoDB doesn't have to do the conversion on its own and can easily
4068 index them.
4069
4070 The Field_typed_array always reports type of its element and from this
4071 point of view it's undistinguishable from regular field having the same
4072 type. Due to that, fields are differentiated by is_array() property.
4073 Field_typed_array returns true, all other fields - false.
4074
4075 For conversion and index applicability tests, Field_typed_array employs a
4076 conversion field, which is a regular Field class of array's element type.
4077 It's stored in the m_conv_field. All Field_typed_array::store_*() methods
4078 store values to the conversion field. Conversion field and typed array
4079 field are sharing same field_index, to allow correct read/write_set
4080 checks. So the field always have to be marked for read in order to allow
4081 read of conversions' results.
4082
4083 @see Item_func_array_cast
4084*/
4085
4086class Field_typed_array final : public Field_json {
4087 /// Conversion item_field
4088 Item_field *m_conv_item{nullptr};
4089 /// The array element's real type.
4091 /// Element's decimals
4093 /// Element's charset
4095 const bool unsigned_flag;
4096
4097 public:
4098 /**
4099 Constructs a Field_typed_array that is a copy of another Field_typed_array.
4100 @param other the other Field_typed_array object
4101 */
4103 /**
4104 Constructs a Field_typed_array object.
4105 */
4106 Field_typed_array(enum_field_types elt_type, bool elt_is_unsigned,
4107 size_t elt_length, uint elt_decimals, uchar *ptr_arg,
4108 uchar *null_ptr_arg, uint null_bit_arg,
4109 uchar auto_flags_arg, const char *field_name_arg,
4110 TABLE_SHARE *share, uint blob_pack_length,
4111 const CHARSET_INFO *cs);
4112 uint32 char_length() const override {
4113 return field_length / charset()->mbmaxlen;
4114 }
4115 void init(TABLE *table_arg) override;
4116 enum_field_types type() const override {
4117 return real_type_to_type(m_elt_type);
4118 }
4119 enum_field_types real_type() const override { return m_elt_type; }
4122 }
4123 uint32 key_length() const override;
4124 Field_typed_array *clone(MEM_ROOT *mem_root) const override;
4125 bool is_unsigned() const final { return unsigned_flag; }
4126 bool is_array() const override { return true; }
4127 Item_result result_type() const override;
4128 uint decimals() const override { return m_elt_decimals; }
4129 bool binary() const override {
4130 return (m_elt_type != MYSQL_TYPE_VARCHAR ||
4131 m_elt_charset == &my_charset_bin);
4132 }
4133 const CHARSET_INFO *charset() const override { return m_elt_charset; }
4134 type_conversion_status store(const char *to, size_t length,
4135 const CHARSET_INFO *charset) override;
4136 type_conversion_status store(double nr) override;
4137 type_conversion_status store(longlong nr, bool unsigned_val) override;
4138 /**
4139 Store a value as an array.
4140 @param data the value to store as an array
4141 @param array scratch space for building the array to store
4142 @return the status of the operation
4143 */
4144 type_conversion_status store_array(const Json_wrapper *data,
4145 Json_array *array);
4146 size_t get_key_image(uchar *buff, size_t length,
4147 imagetype type) const override;
4148 Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr,
4149 uchar *, uint) const override;
4150 /**
4151 These methods are used by handler to prevent returning a row past the
4152 end_range during range access. Since there's no order defined for sorting
4153 set of arrays, always return -1 here, allowing all records fetched from
4154 SE to be returned to server. They will be filtered by WHERE condition later.
4155 */
4156 int key_cmp(const uchar *, const uchar *) const override { return -1; }
4157 /**
4158 * @brief This function will behave similarly to MEMBER OF json operation,
4159 * unlike regular key_cmp. In case of multi-valued indexes a record
4160 * not matching the MEMBER OF condition indicates out of range, so the
4161 * function returns 1 for not found.
4162 * This definition is used in descending ref index scans.
4163 * Descending index scan uses handler::ha_index_prev() function to read
4164 * from the storage engine which does not compare the index key with
4165 * the search key [unlike handler::ha_index_next_same()]. Hence each
4166 * retrieved record needs to be validated to find a stop point. Refer
4167 * key_cmp_if_same() and RefIterator<true>::Read() for more details.
4168 *
4169 * @param key_ptr Pointer to the key
4170 * @param key_length Key length
4171 * @return
4172 * 0 Key found in the record
4173 * 1 Key not found in the record
4174 */
4175 int key_cmp(const uchar *key_ptr, uint key_length) const override;
4176 /**
4177 Multi-valued index always works only as a pre-filter for actual
4178 condition check, and the latter always use binary collation, so no point
4179 to match collations in optimizer.
4180 */
4181 bool match_collation_to_optimize_range() const override { return false; }
4182
4183 /**
4184 Convert arbitrary JSON value to the array's type using the conversion field.
4185 If conversion fails and it's not a coercion test (no_error= false) then an
4186 error is thrown. The converted value is guaranteed to match the field's
4187 type and can be indexed by SE without any additional handling.
4188
4189 @param[in] wr Source data
4190 @param[in] no_error Whether an error should be thrown if value can't be
4191 coerced. Error should be thrown when inserting data
4192 into the index, and shouldn't be thrown when the range
4193 optimizer tests index applicability.
4194 @param[out] coerced The converted value. Can be nullptr if no_error is
4195 true.
4196
4197 @returns
4198 true conversion failed
4199 false conversion succeeded
4200 */
4201 bool coerce_json_value(const Json_wrapper *wr, bool no_error,
4202 Json_wrapper *coerced) const;
4203
4204 /**
4205 Get name of the index defined over this field.
4206
4207 Since typed array fields can be created only as an underlying GC field of
4208 a multi-valued functional index, there's always only one index defined
4209 over the field.
4210
4211 @returns
4212 name of the index defined over the field.
4213 */
4214 const char *get_index_name() const;
4215 uint32 get_length_bytes() const override {
4216 assert(m_elt_type == MYSQL_TYPE_VARCHAR);
4217 return field_length > 255 ? 2 : 1;
4218 }
4220 size_t make_sort_key(uchar *to, size_t max_len) const override {
4221 // Not supported yet
4222 assert(false);
4223 // Dummy
4224 return Field_json::make_sort_key(to, max_len);
4225 }
4226 /**
4227 Create sort key out of given JSON value according to array's element type
4228
4229 @param wr JSON value to create sort key from
4230 @param to buffer to create sort key in
4231 @param length buffer's length
4232
4233 @returns
4234 actual sort key length
4235 */
4236 size_t make_sort_key(Json_wrapper *wr, uchar *to, size_t length) const;
4237 /**
4238 Save the field metadata for typed array fields.
4239
4240 Saved metadata contains element type (1 byte) and up to 3 bytes of
4241 metadata - the same as each respective Field class saves
4242 (e.g Field_new_decimal for DECIMAL type). The only difference is that
4243 for VARCHAR type length is stored in 3 bytes. This allows to store longer
4244 strings, as its supported by JSON storage.
4245
4246 @param metadata_ptr First byte of field metadata
4247
4248 @returns number of bytes written to metadata_ptr
4249 */
4250 int do_save_field_metadata(uchar *metadata_ptr) const override;
4251 uint pack_length_from_metadata(uint) const override {
4252 return pack_length_no_ptr();
4253 }
4254 void sql_type(String &str) const final;
4255 void make_send_field(Send_field *field) const final;
4256 void set_field_index(uint16 f_index) final;
4257 Field *get_conv_field();
4258};
4259
4260class Field_enum : public Field_str {
4261 protected:
4263
4264 public:
4266 Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
4267 uchar null_bit_arg, uchar auto_flags_arg,
4268 const char *field_name_arg, uint packlength_arg,
4269 TYPELIB *typelib_arg, const CHARSET_INFO *charset_arg)
4270 : Field_str(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
4271 field_name_arg, charset_arg),
4272 packlength(packlength_arg),
4273 typelib(typelib_arg) {
4275 }
4276 Field_enum(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
4277 uint packlength_arg, TYPELIB *typelib_arg,
4278 const CHARSET_INFO *charset_arg)
4279 : Field_enum(nullptr, len_arg,
4280 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
4281 field_name_arg, packlength_arg, typelib_arg, charset_arg) {}
4282 Field *new_field(MEM_ROOT *root, TABLE *new_table) const final;
4283 enum_field_types type() const final { return MYSQL_TYPE_STRING; }
4284 bool match_collation_to_optimize_range() const final { return false; }
4285 enum Item_result cmp_type() const final { return INT_RESULT; }
4286 enum Item_result cast_to_int_type() const final { return INT_RESULT; }
4287 enum ha_base_keytype key_type() const final;
4288 type_conversion_status store(const char *to, size_t length,
4289 const CHARSET_INFO *charset) override;
4290 type_conversion_status store(double nr) override;
4291 type_conversion_status store(longlong nr, bool unsigned_val) override;
4292 double val_real() const final;
4293 my_decimal *val_decimal(my_decimal *decimal_value) const final;
4294 longlong val_int() const final;
4295 String *val_str(String *, String *) const override;
4296 int cmp(const uchar *, const uchar *) const final;
4297 using Field_str::make_sort_key;
4298 size_t make_sort_key(uchar *buff, size_t length) const final;
4299 uint32 pack_length() const final { return (uint32)packlength; }
4300 void store_type(ulonglong value);
4301 void sql_type(String &str) const override;
4302 enum_field_types real_type() const override { return MYSQL_TYPE_ENUM; }
4303 uint pack_length_from_metadata(uint field_metadata) const final {
4304 return (field_metadata & 0x00ff);
4305 }
4306 uint row_pack_length() const final { return pack_length(); }
4307 bool zero_pack() const override { return false; }
4308 bool optimize_range(uint, uint) const final { return false; }
4309 bool eq_def(const Field *field) const final;
4310 bool has_charset() const override { return true; }
4311 /* enum and set are sorted as integers */
4312 const CHARSET_INFO *sort_charset() const final { return &my_charset_bin; }
4313 Field_enum *clone(MEM_ROOT *mem_root) const override {
4314 assert(real_type() == MYSQL_TYPE_ENUM);
4315 return new (mem_root) Field_enum(*this);
4316 }
4317 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final;
4318 const uchar *unpack(uchar *to, const uchar *from, uint param_data) final;
4319
4320 private:
4321 int do_save_field_metadata(uchar *first_byte) const final;
4322 uint is_equal(const Create_field *new_field) const final;
4323};
4324
4325class Field_set final : public Field_enum {
4326 public:
4327 Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
4328 uchar null_bit_arg, uchar auto_flags_arg,
4329 const char *field_name_arg, uint32 packlength_arg,
4330 TYPELIB *typelib_arg, const CHARSET_INFO *charset_arg)
4331 : Field_enum(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, auto_flags_arg,
4332 field_name_arg, packlength_arg, typelib_arg, charset_arg) {
4335 }
4336 Field_set(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg,
4337 uint32 packlength_arg, TYPELIB *typelib_arg,
4338 const CHARSET_INFO *charset_arg)
4339 : Field_set(nullptr, len_arg,
4340 is_nullable_arg ? &dummy_null_buffer : nullptr, 0, NONE,
4341 field_name_arg, packlength_arg, typelib_arg, charset_arg) {}
4342 type_conversion_status store(const char *to, size_t length,
4343 const CHARSET_INFO *charset) final;
4345 if (nr < LLONG_MIN)
4346 return Field_set::store(static_cast<longlong>(LLONG_MIN), false);
4347 if (nr > LLONG_MAX_DOUBLE)
4348 return Field_set::store(static_cast<longlong>(LLONG_MAX), false);
4349 return Field_set::store(static_cast<longlong>(nr), false);
4350 }
4351 type_conversion_status store(longlong nr, bool unsigned_val) final;
4352 bool zero_pack() const final { return true; }
4353 String *val_str(String *, String *) const final;
4354 void sql_type(String &str) const final;
4356 bool has_charset() const final { return true; }
4358 assert(real_type() == MYSQL_TYPE_SET);
4359 return new (mem_root) Field_set(*this);
4360 }
4361};
4362
4363/*
4364 Note:
4365 To use Field_bit::cmp_binary() you need to copy the bits stored in
4366 the beginning of the record (the NULL bytes) to each memory you
4367 want to compare (where the arguments point).
4368
4369 This is the reason:
4370 - Field_bit::cmp_binary() is only implemented in the base class
4371 (Field::cmp_binary()).
4372 - Field::cmp_binary() currently uses pack_length() to calculate how
4373 long the data is.
4374 - pack_length() includes size of the bits stored in the NULL bytes
4375 of the record.
4376*/
4377class Field_bit : public Field {
4378 public:
4379 uchar *bit_ptr; // position in record where 'uneven' bits store
4380 uchar bit_ofs; // offset to 'uneven' high bits
4381 uint bit_len; // number of 'uneven' high bits
4383 Field_bit(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
4384 uchar null_bit_arg, uchar *bit_ptr_arg, uchar bit_ofs_arg,
4385 uchar auto_flags_arg, const char *field_name_arg);
4386 enum_field_types type() const final { return MYSQL_TYPE_BIT; }
4387 enum ha_base_keytype key_type() const override { return HA_KEYTYPE_BIT; }
4388 uint32 max_display_length() const final { return field_length; }
4389 Item_result result_type() const final { return INT_RESULT; }
4391 type_conversion_status store(const char *to, size_t length,
4392 const CHARSET_INFO *charset) override;
4393 type_conversion_status store(double nr) final;
4394 type_conversion_status store(longlong nr, bool unsigned_val) final;
4396 double val_real() const final;
4397 longlong val_int() const final;
4398 String *val_str(String *, String *) const final;
4399 bool str_needs_quotes() const final { return true; }
4400 my_decimal *val_decimal(my_decimal *) const final;
4401 int cmp(const uchar *a, const uchar *b) const final {
4402 assert(ptr == a || ptr == b);
4403 const uint cmp_len = bytes_in_rec + (bit_len != 0 ? 1 : 0);
4404 if (ptr == a)
4405 return Field_bit::key_cmp(b, cmp_len);
4406 else
4407 return -Field_bit::key_cmp(a, cmp_len);
4408 }
4409 int cmp_binary_offset(ptrdiff_t row_offset) const final {
4410 return cmp_offset(row_offset);
4411 }
4412 int cmp_max(const uchar *a, const uchar *b, uint max_length) const final;
4413 int key_cmp(const uchar *a, const uchar *b) const final {
4414 return cmp_binary(a, b);
4415 }
4416 int key_cmp(const uchar *str, uint length) const final;
4417 int cmp_offset(ptrdiff_t row_offset) const final;
4418 void get_image(uchar *buff, size_t length, const CHARSET_INFO *) const final {
4419 get_key_image(buff, length, itRAW);
4420 }
4421 void set_image(const uchar *buff, size_t length,
4422 const CHARSET_INFO *cs) final {
4423 Field_bit::store(pointer_cast<const char *>(buff), length, cs);
4424 }
4425 size_t get_key_image(uchar *buff, size_t length, imagetype type) const final;
4426 void set_key_image(const uchar *buff, size_t length) final {
4427 Field_bit::store(pointer_cast<const char *>(buff), length, &my_charset_bin);
4428 }
4430 size_t make_sort_key(uchar *buff, size_t length) const final {
4431 get_key_image(buff, length, itRAW);
4432 return length;
4433 }
4434 uint32 pack_length() const final { return (uint32)(field_length + 7) / 8; }
4435 uint32 pack_length_in_rec() const final { return bytes_in_rec; }
4436 uint pack_length_from_metadata(uint field_metadata) const final;
4437 uint row_pack_length() const final {
4438 return (bytes_in_rec + ((bit_len > 0) ? 1 : 0));
4439 }
4440 bool compatible_field_size(uint metadata, Relay_log_info *, uint16 mflags,
4441 int *order_var) const final;
4442 void sql_type(String &str) const override;
4443 uchar *pack(uchar *to, const uchar *from, size_t max_length) const final;
4444 const uchar *unpack(uchar *to, const uchar *from, uint param_data) final;
4445 void set_default() final;
4446
4447 Field *new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr,
4448 uchar *new_null_ptr, uint new_null_bit) const final;
4449 void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg) {
4450 bit_ptr = bit_ptr_arg;
4451 bit_ofs = bit_ofs_arg;
4452 }
4453 bool eq(const Field *field) const final {
4454 return (Field::eq(field) &&
4455 bit_ptr == down_cast<const Field_bit *>(field)->bit_ptr &&
4456 bit_ofs == down_cast<const Field_bit *>(field)->bit_ofs);
4457 }
4458 uint is_equal(const Create_field *new_field) const final;
4459 void move_field_offset(ptrdiff_t ptr_diff) final {
4460 Field::move_field_offset(ptr_diff);
4461 if (bit_ptr != nullptr) bit_ptr += ptr_diff;
4462 }
4463 void hash(ulong *nr, ulong *nr2) const final;
4464 Field_bit *clone(MEM_ROOT *mem_root) const override {
4465 assert(type() == MYSQL_TYPE_BIT);
4466 return new (mem_root) Field_bit(*this);
4467 }
4468
4469 private:
4470 int do_save_field_metadata(uchar *first_byte) const final;
4471};
4472
4473/**
4474 BIT field represented as chars for non-MyISAM tables.
4475
4476 @todo The inheritance relationship is backwards since Field_bit is
4477 an extended version of Field_bit_as_char and not the other way
4478 around. Hence, we should refactor it to fix the hierarchy order.
4479 */
4480class Field_bit_as_char final : public Field_bit {
4481 public:
4482 Field_bit_as_char(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg,
4483 uchar null_bit_arg, uchar auto_flags_arg,
4484 const char *field_name_arg);
4485 Field_bit_as_char(uint32 len_arg, bool is_nullable_arg,
4486 const char *field_name_arg)
4487 : Field_bit_as_char(nullptr, len_arg,
4488 is_nullable_arg ? &dummy_null_buffer : nullptr, 0,
4489 NONE, field_name_arg) {}
4490 enum ha_base_keytype key_type() const final { return HA_KEYTYPE_BINARY; }
4491 type_conversion_status store(const char *to, size_t length,
4492 const CHARSET_INFO *charset) final;
4493 // Inherit the store() overloads that have not been overridden.
4494 using Field_bit::store;
4495 void sql_type(String &str) const final;
4497 return new (mem_root) Field_bit_as_char(*this);
4498 }
4499};
4500
4501/// This function should only be called from legacy code.
4503 size_t field_length, uchar *null_pos, uchar null_bit,
4504 enum_field_types field_type,
4507 TYPELIB *interval, const char *field_name, bool is_nullable,
4508 bool is_zerofill, bool is_unsigned, uint decimals,
4509 bool treat_bit_as_char, uint pack_length_override,
4510 std::optional<gis::srid_t> srid, bool is_array);
4511
4512/**
4513 Instantiates a Field object with the given name and record buffer values.
4514 @param create_field The column meta data.
4515 @param share The table share object.
4516
4517 @param field_name Create_field::field_name is overridden with this value
4518 when instantiating the Field object.
4519 @param field_length Create_field::length is overridden with this value
4520 when instantiating the Field object.
4521
4522 @param ptr The address of the data bytes.
4523 @param null_pos The address of the null bytes.
4524 @param null_bit The position of the column's null bit within the row's null
4525 bytes.
4526*/
4527Field *make_field(const Create_field &create_field, TABLE_SHARE *share,
4528 const char *field_name, size_t field_length, uchar *ptr,
4529 uchar *null_pos, size_t null_bit);
4530
4531/**
4532 Instantiates a Field object with the given record buffer values.
4533 @param create_field The column meta data.
4534 @param share The table share object.
4535 @param ptr The start of the record buffer.
4536 @param null_pos The address of the null bytes.
4537
4538 @param null_bit The position of the column's null bit within the row's null
4539 bytes.
4540*/
4541Field *make_field(const Create_field &create_field, TABLE_SHARE *share,
4542 uchar *ptr, uchar *null_pos, size_t null_bit);
4543
4544/**
4545 Instantiates a Field object without a record buffer.
4546 @param create_field The column meta data.
4547 @param share The table share object.
4548*/
4549Field *make_field(const Create_field &create_field, TABLE_SHARE *share);
4550
4551/*
4552 A class for sending info to the client
4553*/
4554
4556 public:
4557 const char *db_name;
4559 const char *col_name, *org_col_name;
4560 ulong length;
4563 /*
4564 true <=> source item is an Item_field. Needed to workaround lack of
4565 architecture in legacy Protocol_text implementation. Needed only for
4566 Protocol_classic and descendants.
4567 */
4568 bool field;
4569 Send_field() = default;
4570};
4571
4573 /**
4574 Convenience definition of a copy function returned by
4575 get_copy_func. The parameters are:
4576 Copy_field* Instance of this class. Used for accessing 'tmp' and
4577 calling invoke_do_copy2().
4578 const Field* Field copying from.
4579 Field* Field copying to.
4580 Note that 'from' is 'm_to_field' if invoke_do_copy()
4581 is called with 'reverse' = true.
4582 */
4583 using Copy_func = void(Copy_field *, const Field *, Field *);
4584 Copy_func *get_copy_func();
4585
4586 public:
4587 String tmp; // For items
4588
4589 Copy_field() = default;
4590
4591 Copy_field(Field *to, Field *from) : Copy_field() { set(to, from); }
4592
4593 void set(Field *to, Field *from); // Field to field
4594
4595 private:
4596 void (*m_do_copy)(Copy_field *, const Field *, Field *);
4597 void (*m_do_copy2)(Copy_field *, const Field *,
4598 Field *); // Used to handle null values
4599
4600 Field *m_from_field{nullptr};
4601 Field *m_to_field{nullptr};
4602
4603 public:
4604 void invoke_do_copy(bool reverse = false);
4605 void invoke_do_copy2(const Field *from_field, Field *to_field);
4606
4607 Field *from_field() const { return m_from_field; }
4608
4609 Field *to_field() const { return m_to_field; }
4610};
4611
4614
4615/**
4616 Calculate the length of the in-memory representation of the column from
4617 information which can be retrieved from dd::Column or Ha_fk_column_type
4618 describing it.
4619
4620 This function calculates the amount of memory necessary to store values
4621 in the record buffer. It is used in cases when we want to calculate
4622 this value from the description of column in the form compatible with
4623 dd::Column without constructing full-blown Field object.
4624
4625 @note The implementation is based on Create_field::init() and
4626 Create_field::create_length_to_internal_length().
4627
4628 @param type Column DD type.
4629 @param char_length Column length as stored in DD.
4630 @param elements_count Number of elements in column of ENUM/SET type.
4631 @param treat_bit_as_char Indicates whether this BIT column is represented
4632 as char column internally.
4633 @param numeric_scale Column numeric scale as stored in DD.
4634 @param is_unsigned Column unsignedness.
4635*/
4636
4638 size_t elements_count, bool treat_bit_as_char,
4639 uint numeric_scale, bool is_unsigned);
4640
4642 uint32 decimals, bool is_unsigned, uint32 elements);
4645 bool no_conversions);
4647 int conversion_err,
4648 my_decimal *value);
4649
4650/**
4651 Generate a Create_field from an Item.
4652
4653 This function generates a Create_field from an Item by first creating a
4654 temporary table Field from the Item, and then creating the Create_field from
4655 this Field (there is currently no way to go directly from Item to
4656 Create_field). It is used several places:
4657 - In CREATE TABLE AS SELECT for creating the target table definition.
4658 - In functional indexes for creating the hidden generated column from the
4659 indexed expression.
4660
4661 @param thd Thread handler
4662 @param source_item The item to generate a Create_field from
4663 @param tmp_table A table object which is used to generate a temporary table
4664 field, as described above. This doesn't need to be an
4665 existing table.
4666 @return A Create_field generated from the input item, or nullptr
4667 in case of errors.
4668*/
4669Create_field *generate_create_field(THD *thd, Item *source_item,
4670 TABLE *tmp_table);
4671
4675}
4676
4677/**
4678 @returns the expression if the input field is a hidden generated column that
4679 represents a functional key part. If not, return the field name. In case of
4680 a functional index; the expression is allocated on the THD's MEM_ROOT.
4681*/
4682const char *get_field_name_or_expression(THD *thd, const Field *field);
4683
4684/**
4685 Perform per item-type checks to determine if the expression is allowed for
4686 a generated column, default value expression, a functional index or a check
4687 constraint. Note that validation of the specific function is done later in
4688 procedures open_table_from_share and fix_value_generator_fields.
4689
4690 @param expression the expression to check for validity
4691 @param name used for error reporting
4692 @param source Source of value generator(a generated column, a
4693 regular column with generated default value or
4694 a check constraint).
4695 @return false if ok, true otherwise
4696*/
4697bool pre_validate_value_generator_expr(Item *expression, const char *name,
4699#endif /* FIELD_INCLUDED */
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
unsigned int my_time_binary_length(unsigned int dec)
Calculate binary size of packed numeric time representation.
Definition: binary_log_funcs.cpp:55
unsigned int my_timestamp_binary_length(unsigned int dec)
Calculate on-disk size of a timestamp value.
Definition: binary_log_funcs.cpp:84
unsigned int my_datetime_binary_length(unsigned int dec)
Calculate binary size of packed datetime representation.
Definition: binary_log_funcs.cpp:69
Definition: sql_bitmap.h:154
Class is used as a BLOB field value storage for intermediate GROUP_CONCAT results.
Definition: table.h:1333
Definition: field.h:4572
String tmp
Definition: field.h:4587
Copy_field()=default
void(Copy_field *, const Field *, Field *) Copy_func
Convenience definition of a copy function returned by get_copy_func.
Definition: field.h:4583
Field * to_field() const
Definition: field.h:4609
Copy_field(Field *to, Field *from)
Definition: field.h:4591
Field * from_field() const
Definition: field.h:4607
This class represents the cost of evaluating an Item.
Definition: item.h:790
This class is a substitute for the Field classes during CREATE TABLE.
Definition: field.h:1909
my_decimal * val_decimal(my_decimal *) const final
Definition: field.h:1962
type_conversion_status store(longlong, bool) final
Definition: field.h:1934
bool is_wrapper_field() const final
If true, it's a Create_field_wrapper (a sub-class of Field used during CREATE/ALTER that we mustn't c...
Definition: field.h:1983
const Create_field * m_field
Definition: field.h:1910
Create_field_wrapper(const Create_field *fld)
Definition: field.cc:10492
type_conversion_status store_date(Date_val) final
Store a date value into a string column.
Definition: field.h:1946
type_conversion_status store_time(MYSQL_TIME *, uint8) final
Store MYSQL_TIME value with the given amount of decimal digits into a field.
Definition: field.h:1950
size_t make_sort_key(uchar *, size_t) const final
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:1976
int cmp(const uchar *, const uchar *) const final
Definition: field.h:1970
void sql_type(String &) const final
Definition: field.h:1974
Item_result numeric_context_result_type() const final
Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + ...
Definition: field.cc:10505
Item_result result_type() const final
Definition: field.cc:10501
longlong val_int(void) const final
Definition: field.h:1958
String * val_str(String *, String *) const final
Definition: field.h:1966
type_conversion_status store(const char *, size_t, const CHARSET_INFO *) final
Definition: field.h:1925
type_conversion_status store(double) final
Definition: field.h:1930
uint32 pack_length() const final
Definition: field.cc:10518
double val_real(void) const final
Definition: field.h:1954
type_conversion_status store_time(Time_val, uint8) final
Store a time value into a string column.
Definition: field.h:1942
const CHARSET_INFO * charset() const final
Definition: field.cc:10514
Field * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:1980
uint32 max_display_length() const final
Definition: field.cc:10522
type_conversion_status store_decimal(const my_decimal *) final
Definition: field.h:1938
enum_field_types type() const final
Definition: field.cc:10510
Create_field is a description a field/column that may or may not exists in a table.
Definition: create_field.h:51
Date_val is a temporal type that represents dates within the range 0000-01-01 and 9999-12-31.
Definition: my_temporal.h:421
Definition: my_temporal.h:341
Definition: sql_error.h:228
BIT field represented as chars for non-MyISAM tables.
Definition: field.h:4480
enum ha_base_keytype key_type() const final
Definition: field.h:4490
Field_bit_as_char(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg)
Definition: field.h:4485
Field_bit_as_char * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:4496
Definition: field.h:4377
uchar * bit_ptr
Definition: field.h:4379
uchar bit_ofs
Definition: field.h:4380
bool eq(const Field *field) const final
Definition: field.h:4453
void get_image(uchar *buff, size_t length, const CHARSET_INFO *) const final
Definition: field.h:4418
uint row_pack_length() const final
Definition: field.h:4437
int cmp(const uchar *a, const uchar *b) const final
Definition: field.h:4401
enum_field_types type() const final
Definition: field.h:4386
uint bit_len
Definition: field.h:4381
void set_image(const uchar *buff, size_t length, const CHARSET_INFO *cs) final
Definition: field.h:4421
int cmp_binary_offset(ptrdiff_t row_offset) const final
Definition: field.h:4409
uint32 pack_length() const final
Definition: field.h:4434
Field_bit * clone(MEM_ROOT *mem_root) const override
Makes a shallow copy of the Field object.
Definition: field.h:4464
uint bytes_in_rec
Definition: field.h:4382
uint32 pack_length_in_rec() const final
Definition: field.h:4435
uint32 max_display_length() const final
Definition: field.h:4388
void set_key_image(const uchar *buff, size_t length) final
Definition: field.h:4426
enum ha_base_keytype key_type() const override
Definition: field.h:4387
type_conversion_status store(const char *to, size_t length, const CHARSET_INFO *charset) override
Definition: field.cc:8789
size_t make_sort_key(uchar *buff, size_t length) const final
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:4430
Item_result result_type() const final
Definition: field.h:4389
void move_field_offset(ptrdiff_t ptr_diff) final
Definition: field.h:4459
int key_cmp(const uchar *a, const uchar *b) const final
Definition: field.h:4413
Definition: field.h:3447
type_conversion_status store(const char *to, size_t length, const CHARSET_INFO *charset) override
Definition: field.cc:7030
bool match_collation_to_optimize_range() const override
Definition: field.h:3576
const uchar * data_ptr() const final
Get a const pointer to the BLOB data of this field.
Definition: field.h:3638
String old_value
In order to support update of virtual generated columns of blob type, we need to allocate the space b...
Definition: field.h:3475
const uchar * get_blob_data() const
Get a const pointer to the BLOB data of this field.
Definition: field.h:3631
size_t get_field_buffer_size()
Definition: field.h:3619
bool m_uses_backup
Whether the field uses table's backup value storage.
Definition: field.h:3526
Field_blob(const Field_blob &field)
Copy static information and reset dynamic information.
Definition: field.h:3560
Field_blob * clone(MEM_ROOT *mem_root) const override
Makes a shallow copy of the Field object.
Definition: field.h:3669
uint32 pack_length_no_ptr() const
Return the packed length without the pointer size added.
Definition: field.h:3614
uint row_pack_length() const final
Definition: field.h:3615
uint packlength
The number of bytes used to represent the length of the blob.
Definition: field.h:3461
void set_keep_old_value(bool old_value_flag)
Mark that the BLOB stored in value should be copied before updating it.
Definition: field.h:3704
uint32 max_data_length() const override
Get the maximum size of the data in packed format.
Definition: field.h:3616
uint32 pack_length() const final
Definition: field.h:3602
void store_length(uint32 number)
Definition: field.h:3621
enum_field_types type() const override
Definition: field.h:3575
uchar * get_blob_data(ptrdiff_t row_offset=0)
Get a non-const pointer to the BLOB data of this field.
Definition: field.h:3633
Field_blob(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, const CHARSET_INFO *cs, bool set_packlength)
Definition: field.h:3543
static uchar * get_blob_data(const uchar *position)
Get the BLOB data pointer stored at the specified position in the record buffer.
Definition: field.h:3645
uint32 key_length() const override
Definition: field.h:3599
String value
The 'value'-object is a cache fronting the storage engine.
Definition: field.h:3466
void keep_old_value()
Save the current BLOB value to avoid that it gets overwritten.
Definition: field.h:3750
void set_ptr(const uchar *length, const uchar *data)
Definition: field.h:3652
int cmp(const uchar *a, const uchar *b) const final
Definition: field.h:3590
size_t make_sort_key(uchar *buff, size_t length) const override
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.cc:7315
void store_in_allocated_space(const char *from, uint32 length)
Use to store the blob value into an allocated space.
Definition: field.h:3767
enum ha_base_keytype key_type() const override
Definition: field.h:3577
void set_ptr_offset(ptrdiff_t ptr_diff, uint32 length, const uchar *data)
Definition: field.h:3656
bool has_charset() const override
Definition: field.h:3684
void store_ptr_and_length(const char *from, uint32 length)
Store ptr and length.
Definition: field.h:3533
void set_ptr(uint32 length, const uchar *data)
Definition: field.h:3661
String m_blob_backup
Backup String for table's blob fields.
Definition: field.h:3519
uint32 data_length(ptrdiff_t row_offset=0) const final
Definition: field.h:3624
bool m_keep_old_value
Whether we need to move the content of 'value' to 'old_value' before updating the BLOB stored in 'val...
Definition: field.h:3496
Definition: field.h:3099
Field_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg)
Definition: field.h:3108
enum_field_types real_type() const final
Definition: field.h:3118
bool zero_pack() const final
Definition: field.h:3130
enum ha_base_keytype key_type() const final
Definition: field.h:3119
Field_date * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3133
Field_date(bool is_nullable_arg, const char *field_name_arg)
Definition: field.h:3113
enum_field_types type() const final
Definition: field.h:3117
Definition: field.h:3242
uint pack_length_from_metadata(uint field_metadata) const final
Definition: field.h:3289
enum_field_types type() const final
Definition: field.h:3285
Field_datetime(bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg)
Constructor for Field_datetime.
Definition: field.h:3272
Field_datetime * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3280
Field_datetime(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg)
Constructor for Field_datetime.
Definition: field.h:3260
Field_datetime(const char *field_name_arg)
Definition: field.h:3277
bool zero_pack() const final
Definition: field.h:3294
enum_field_types binlog_type() const final
Definition: field.h:3287
enum_field_types real_type() const final
Definition: field.h:3286
uint32 pack_length() const final
Definition: field.h:3288
Definition: field.h:2141
enum ha_base_keytype key_type() const final
Definition: field.h:2150
const uchar * unpack(uchar *to, const uchar *from, uint param_data) final
Unpack a field from row data.
Definition: field.h:2170
enum_field_types type() const final
Definition: field.h:2149
uchar * pack(uchar *to, const uchar *from, size_t max_length) const final
Pack the field into a format suitable for storage and transfer.
Definition: field.h:2173
Field_decimal(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2143
Field_decimal * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2166
Definition: field.h:2543
Field_double(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg, bool unsigned_arg)
Definition: field.h:2556
Field_double * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2583
enum ha_base_keytype key_type() const final
Definition: field.h:2569
Field_double(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2545
Field_double(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg)
Definition: field.h:2551
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2588
Field_double(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg, bool unsigned_arg, bool not_fixed_arg)
Definition: field.h:2561
enum_field_types type() const final
Definition: field.h:2568
Definition: field.h:4260
bool has_charset() const override
Definition: field.h:4310
bool optimize_range(uint, uint) const final
Whether this field can be used for index range scans when in the given keypart of the given index.
Definition: field.h:4308
uint pack_length_from_metadata(uint field_metadata) const final
Definition: field.h:4303
Field_enum(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint packlength_arg, TYPELIB *typelib_arg, const CHARSET_INFO *charset_arg)
Definition: field.h:4266
enum_field_types real_type() const override
Definition: field.h:4302
bool match_collation_to_optimize_range() const final
Definition: field.h:4284
Field_enum * clone(MEM_ROOT *mem_root) const override
Makes a shallow copy of the Field object.
Definition: field.h:4313
TYPELIB * typelib
Definition: field.h:4265
Field_enum(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, uint packlength_arg, TYPELIB *typelib_arg, const CHARSET_INFO *charset_arg)
Definition: field.h:4276
uint packlength
Definition: field.h:4262
enum Item_result cast_to_int_type() const final
Definition: field.h:4286
const CHARSET_INFO * sort_charset() const final
Definition: field.h:4312
enum Item_result cmp_type() const final
Definition: field.h:4285
bool zero_pack() const override
Definition: field.h:4307
uint row_pack_length() const final
Definition: field.h:4306
enum_field_types type() const final
Definition: field.h:4283
Definition: field.h:2499
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2532
Field_float(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2501
Field_float(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg, bool unsigned_arg)
Definition: field.h:2507
Field_float * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2527
enum ha_base_keytype key_type() const final
Definition: field.h:2513
enum_field_types type() const final
Definition: field.h:2512
Definition: field.h:3850
std::optional< gis::srid_t > get_srid() const
Definition: field.h:3904
enum geometry_type geom_type
Definition: field.h:3858
type_conversion_status reset() final
Non-nullable GEOMETRY types cannot have defaults, but the underlying blob must still be reset.
Definition: field.h:3889
geometry_type get_geometry_type() const final
Definition: field.h:3897
Field_geom * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3898
Field_geom(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, enum geometry_type geom_type_arg, std::optional< gis::srid_t > srid)
Definition: field.h:3868
bool match_collation_to_optimize_range() const final
Definition: field.h:3876
const std::optional< gis::srid_t > m_srid
Definition: field.h:3852
Field_geom(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, uint blob_pack_length, enum geometry_type geom_type_arg, std::optional< gis::srid_t > srid)
Definition: field.h:3860
enum_field_types type() const final
Definition: field.h:3875
enum ha_base_keytype key_type() const final
Definition: field.h:3874
A field that stores a JSON value.
Definition: field.h:3908
size_t make_sort_key(uchar *to, size_t length) const override
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.cc:8126
Field_json(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg)
Definition: field.h:3919
bool has_charset() const final
JSON columns don't have an associated charset.
Definition: field.h:3943
Field_json(uchar *ptr_arg, uchar *null_ptr_arg, uint null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, uint blob_pack_length)
Definition: field.h:3913
const CHARSET_INFO * charset() const override
Return a text charset so that string functions automatically convert the field value to string and tr...
Definition: field.h:3930
const CHARSET_INFO * sort_charset() const final
Sort should treat the field as binary and not attempt any conversions.
Definition: field.h:3937
enum_field_types type() const override
Definition: field.h:3923
Definition: field.h:2396
Field_long * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2431
enum_field_types type() const final
Definition: field.h:2411
uchar * pack(uchar *to, const uchar *from, size_t max_length) const final
Pack the field into a format suitable for storage and transfer.
Definition: field.h:2435
uint32 max_display_length() const final
Definition: field.h:2428
enum ha_base_keytype key_type() const final
Definition: field.h:2412
enum Item_result result_type() const final
Definition: field.h:2410
Field_long(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, bool unsigned_arg)
Definition: field.h:2405
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2443
const uchar * unpack(uchar *to, const uchar *from, uint param_data) final
Unpack a field from row data.
Definition: field.h:2438
Field_long(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2400
Definition: field.h:2448
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2494
Field_longlong(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2452
enum_field_types type() const final
Definition: field.h:2463
uchar * pack(uchar *to, const uchar *from, size_t max_length) const final
Pack the field into a format suitable for storage and transfer.
Definition: field.h:2486
uint32 max_display_length() const final
Definition: field.h:2481
enum Item_result result_type() const final
Definition: field.h:2462
Field_longlong * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2482
bool can_be_compared_as_longlong() const final
Definition: field.h:2480
const uchar * unpack(uchar *to, const uchar *from, uint param_data) final
Unpack a field from row data.
Definition: field.h:2489
Field_longlong(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, bool unsigned_arg)
Definition: field.h:2457
enum ha_base_keytype key_type() const final
Definition: field.h:2464
Definition: field.h:2085
bool is_updatable() const final
Checks whether a string field is part of write_set.
Definition: field.cc:10433
type_conversion_status report_if_important_data(const char *ptr, const char *end, bool count_spaces)
Definition: field.cc:6055
type_conversion_status check_string_copy_error(const char *well_formed_error_pos, const char *cannot_convert_error_pos, const char *from_end_pos, const char *end, bool count_spaces, const CHARSET_INFO *from_cs, const CHARSET_INFO *to_cs)
Report "not well formed" or "cannot convert" error after storing a character string info a field.
Definition: field.cc:6006
uint32 max_data_length() const override
Get the maximum size of the data in packed format.
Definition: field.cc:6189
Field_longstr(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, const CHARSET_INFO *charset_arg)
Definition: field.h:2098
type_conversion_status store_decimal(const my_decimal *d) override
Decimal representation of Field_str.
Definition: field.cc:6183
Definition: field.h:2356
uint32 max_display_length() const final
Definition: field.h:2386
enum Item_result result_type() const final
Definition: field.h:2368
Field_medium * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2387
Field_medium(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, bool unsigned_arg)
Definition: field.h:2363
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2391
enum_field_types type() const final
Definition: field.h:2369
enum ha_base_keytype key_type() const final
Definition: field.h:2370
Field_medium(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2358
Definition: field.h:2179
uint precision
Definition: field.h:2197
enum_field_types type() const final
Definition: field.h:2212
Field_new_decimal * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2244
uint32 max_display_length() const final
Definition: field.h:2238
uint bin_size
Definition: field.h:2198
Item_result result_type() const final
Definition: field.h:2214
uint32 pack_length() const final
Definition: field.h:2239
void set_keep_precision(bool arg)
Definition: field.h:2251
enum ha_base_keytype key_type() const final
Definition: field.h:2213
Definition: field.h:2601
int cmp(const uchar *, const uchar *) const final
Definition: field.h:2626
double val_real() const final
Definition: field.h:2619
enum_field_types type() const final
Definition: field.h:2608
type_conversion_status store(const char *, size_t, const CHARSET_INFO *) final
Definition: field.h:2609
type_conversion_status reset() final
Definition: field.h:2618
String * val_str(String *, String *value2) const final
Definition: field.h:2622
my_decimal * val_decimal(my_decimal *) const final
Definition: field.h:2621
type_conversion_status store(double) final
Store double value in Field_string or Field_varstring.
Definition: field.h:2613
longlong val_int() const final
Definition: field.h:2620
type_conversion_status store(longlong, bool) final
Definition: field.h:2614
size_t make_sort_key(uchar *, size_t len) const final
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:2628
Field_null(uchar *ptr_arg, uint32 len_arg, uchar auto_flags_arg, const char *field_name_arg, const CHARSET_INFO *cs)
Definition: field.h:2603
type_conversion_status store_decimal(const my_decimal *) final
Decimal representation of Field_str.
Definition: field.h:2615
uint32 max_display_length() const final
Definition: field.h:2631
uint32 pack_length() const final
Definition: field.h:2629
Field_null * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2632
Definition: field.h:1987
uint repertoire() const final
Definition: field.h:2010
uint row_pack_length() const final
Definition: field.h:2024
uint decimals() const final
Definition: field.h:2013
bool zerofill
True if the column was declared with the ZEROFILL attribute.
Definition: field.h:2002
bool eq_def(const Field *field) const final
Definition: field.cc:8669
my_decimal * val_decimal(my_decimal *) const override
Return decimal value of integer field.
Definition: field.cc:2232
bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const override
Retrieve field value and return the result as a datetime/timestamp.
Definition: field.cc:2245
bool is_unsigned() const final
Whether the field is signed or not.
Definition: field.h:2007
const CHARSET_INFO * charset() const final
Definition: field.h:2011
Field_num(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg, bool zero_arg, bool unsigned_arg)
Numeric fields base class constructor.
Definition: field.cc:1664
type_conversion_status check_int(const CHARSET_INFO *cs, const char *str, size_t length, const char *int_end, int error)
Test if given number is a int.
Definition: field.cc:1708
type_conversion_status store_time(Time_val time, uint8 dec_arg) override
Store a time value into a string column.
Definition: field.cc:1784
Item_result result_type() const override
Definition: field.h:2008
uint32 pack_length_from_metadata(uint) const override
Definition: field.h:2025
bool val_date(Date_val *date, my_time_flags_t flags) const override
Retrieve field value and return the result as a date.
Definition: field.cc:2240
type_conversion_status get_int(const CHARSET_INFO *cs, const char *from, size_t len, longlong *rnd, ulonglong unsigned_max, longlong signed_min, longlong signed_max)
Definition: field.cc:1751
enum Derivation derivation() const final
Definition: field.h:2009
type_conversion_status store_date(Date_val date) override
Store a date value into a string column.
Definition: field.cc:1788
const uint8 dec
Definition: field.h:1996
bool val_time(Time_val *time) const override
Retrieve field value and return the result as a time.
Definition: field.cc:2250
const bool unsigned_flag
Whether the field is signed or not.
Definition: field.h:1993
uint is_equal(const Create_field *new_field) const override
Check whether two numeric fields can be considered 'equal' for table alteration purposes.
Definition: field.cc:8685
type_conversion_status store_decimal(const my_decimal *) override
Storing decimal in integer fields.
Definition: field.cc:2209
void prepend_zeros(String *value) const
Definition: field.cc:1677
Definition: field.h:2110
bool not_fixed
Definition: field.h:2112
uint32 max_display_length() const final
Definition: field.h:2136
Field_real(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2119
Truncate_result
Definition: field.h:2113
Definition: field.h:4325
bool has_charset() const final
Definition: field.h:4356
Field_set * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:4357
enum_field_types real_type() const final
Definition: field.h:4355
type_conversion_status store(double nr) final
Store double value in Field_string or Field_varstring.
Definition: field.h:4344
Field_set(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, uint32 packlength_arg, TYPELIB *typelib_arg, const CHARSET_INFO *charset_arg)
Definition: field.h:4336
Field_set(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint32 packlength_arg, TYPELIB *typelib_arg, const CHARSET_INFO *charset_arg)
Definition: field.h:4327
bool zero_pack() const final
Definition: field.h:4352
type_conversion_status store(const char *to, size_t length, const CHARSET_INFO *charset) final
Definition: field.cc:8406
Definition: field.h:2305
uint32 max_display_length() const final
Definition: field.h:2337
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2351
const uchar * unpack(uchar *to, const uchar *from, uint param_data) final
Unpack a field from row data.
Definition: field.h:2346
Field_short(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2307
Field_short(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, bool unsigned_arg)
Definition: field.h:2312
enum_field_types type() const final
Definition: field.h:2320
uchar * pack(uchar *to, const uchar *from, size_t max_length) const final
Pack the field into a format suitable for storage and transfer.
Definition: field.h:2342
Field_short * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:2338
enum ha_base_keytype key_type() const final
Definition: field.h:2321
enum Item_result result_type() const final
Definition: field.h:2319
Field_short(uint32 len_arg, const char *field_name_arg, bool unsigned_arg)
Definition: field.h:2317
Definition: field.h:2037
enum Derivation field_derivation
Definition: field.h:2040
void set_field_length(uint32 length) final
Definition: field.h:2062
Item_result numeric_context_result_type() const final
Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + ...
Definition: field.h:2047
type_conversion_status store(double nr) override
Store double value in Field_string or Field_varstring.
Definition: field.cc:6116
type_conversion_status store(longlong nr, bool unsigned_val) override=0
uint is_equal(const Create_field *new_field) const override
Whether a field being created is type-compatible with an existing one.
Definition: field.cc:6151
type_conversion_status store(const char *to, size_t length, const CHARSET_INFO *cs) override=0
uint repertoire() const final
Definition: field.h:2056
type_conversion_status store_decimal(const my_decimal *) override
Decimal representation of Field_str.
Definition: field.cc:2292
uint decimals() const override
Definition: field.h:2048
void add_to_cost(CostOfItem *cost) const override
Update '*cost' with the fact that this Field is accessed.
Definition: field.cc:6172
uint32 max_display_length() const override
Definition: field.h:2071
bool binary() const override
Definition: field.h:2070
void set_charset(const CHARSET_INFO *charset_arg)
Definition: field.h:2058
Field_str(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, const CHARSET_INFO *charset)
Definition: field.cc:2255
Item_result result_type() const override
Definition: field.h:2046
void make_send_field(Send_field *field) const override
Populates a Send_field object with metadata about the column represented by this Field object.
Definition: field.cc:2267
const CHARSET_INFO * charset() const override
Definition: field.h:2057
uint32 char_length_cache
Definition: field.h:2080
bool str_needs_quotes() const final
Definition: field.h:2072
void set_derivation(enum Derivation derivation_arg) final
Definition: field.h:2067
const CHARSET_INFO * field_charset
Definition: field.h:2039
enum Derivation derivation() const final
Definition: field.h:2066
Definition: field.h:3304
bool is_text_key_type() const final
Definition: field.h:3371
bool match_collation_to_optimize_range() const final
Definition: field.h:3318
uint row_pack_length() const final
Definition: field.h:3360
bool has_charset() const final
Definition: field.h:3363
type_conversion_status reset() final
Definition: field.h:3323
Field_string(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, const CHARSET_INFO *cs)
Definition: field.h:3306
uint pack_length_from_metadata(uint field_metadata) const final
Definition: field.h:3352
enum ha_base_keytype key_type() const final
Definition: field.h:3319
bool zero_pack() const final
Definition: field.h:3322
Field_string * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3366
Field_string(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, const CHARSET_INFO *cs)
Definition: field.h:3311
enum_field_types type() const final
Definition: field.h:3317
Abstract class for types with date and time: DATETIME, DATETIME(N), TIMESTAMP, TIMESTAMP(N).
Definition: field.h:2935
Field_temporal_with_date_and_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg)
Constructor for Field_temporal_with_date_and_time.
Definition: field.h:2952
uint decimals() const final
Definition: field.h:2959
uint row_pack_length() const final
Definition: field.h:2969
const CHARSET_INFO * sort_charset() const final
Definition: field.h:2960
int cmp(const uchar *a_ptr, const uchar *b_ptr) const final
Definition: field.h:2966
size_t make_sort_key(uchar *to, size_t length) const final
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:2962
int do_save_field_metadata(uchar *metadata_ptr) const final
Retrieve the field metadata for fields.
Definition: field.h:2937
Abstract class for types with date with optional time, with or without fractional part: DATE,...
Definition: field.h:2873
virtual bool get_date_internal(MYSQL_TIME *ltime) const =0
Low level function to get value into MYSQL_TIME, without checking for being valid.
virtual bool get_date_internal_at_utc(MYSQL_TIME *ltime) const
Definition: field.h:2881
Field_temporal_with_date(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 int_length_arg, uint8 dec_arg)
Constructor for Field_temporal.
Definition: field.h:2915
Definition: field.h:2641
Item_result numeric_context_result_type() const final
Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + ...
Definition: field.h:2825
enum Item_result cmp_type() const final
Definition: field.h:2828
uint repertoire() const final
Definition: field.h:2830
bool str_needs_quotes() const final
Definition: field.h:2823
virtual type_conversion_status store_internal(const MYSQL_TIME *ltime, int *error)=0
Low level routine to store a MYSQL_TIME value into a field.
bool can_be_compared_as_longlong() const final
Definition: field.h:2832
const CHARSET_INFO * charset() const final
Definition: field.h:2831
static my_time_flags_t temporal_flags(sql_mode_t mode)
Flags for evaluation of temporal values, based on current SQL mode.
Definition: field.h:2860
uint32 max_display_length() const final
Definition: field.h:2822
my_time_flags_t get_date_flags(const THD *thd) const
Definition: field.h:2847
bool binary() const final
Definition: field.h:2833
my_time_flags_t date_flags() const
Flags that are passed as "flag" argument to check_date(), int_to_datetime(), str_to_datetime().
Definition: field.cc:4781
static uint8 normalize_dec(uint8 dec_arg)
Adjust number of decimal digits from DECIMAL_NOT_SPECIFIED to DATETIME_MAX_DECIMALS.
Definition: field.h:2649
uint8 get_dec() const
Definition: field.h:2843
virtual my_time_flags_t date_flags(const THD *thd) const
Flags that are passed as "flag" argument to store functions, and to e.g.
Definition: field.h:2767
virtual bool convert_str_to_TIME(const char *str, size_t len, const CHARSET_INFO *cs, MYSQL_TIME *ltime, MYSQL_TIME_STATUS *status)=0
Convert a string to MYSQL_TIME, according to the field type.
virtual type_conversion_status store_internal_adjust_frac(MYSQL_TIME *ltime, int *warnings)=0
Low level routine to store a MYSQL_TIME value into a field with rounding/truncation according to the ...
Item_result result_type() const final
Definition: field.h:2821
enum Derivation derivation() const final
Definition: field.h:2829
Field_temporal(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint32 len_arg, uint8 dec_arg)
Constructor for Field_temporal.
Definition: field.h:2811
uint8 get_fractional_digits() const
Definition: field.h:2851
double val_real() const override
Definition: field.h:2839
uint8 dec
Definition: field.h:2643
virtual type_conversion_status convert_number_to_TIME(longlong val, bool unsigned_val, int nanoseconds, MYSQL_TIME *ltime, int *warning)=0
Convert a number with fractional part with nanosecond precision into MYSQL_TIME, according to the fie...
Field implementing TIME(N) data type, where N=0..6.
Definition: field.h:3143
Field_time(bool is_nullable_arg, const char *field_name_arg, uint8 dec_arg)
Constructor for Field_time.
Definition: field.h:3195
bool zero_pack() const final
Definition: field.h:3227
int cmp(const uchar *a_ptr, const uchar *b_ptr) const final
Definition: field.h:3234
int do_save_field_metadata(uchar *metadata_ptr) const final
Retrieve the field metadata for fields.
Definition: field.h:3145
enum_field_types binlog_type() const final
Definition: field.h:3205
uint row_pack_length() const final
Definition: field.h:3225
Field_time * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3198
uint pack_length_from_metadata(uint field_metadata) const final
Definition: field.h:3220
enum_field_types type() const final
Definition: field.h:3203
size_t make_sort_key(uchar *to, size_t length) const final
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:3230
enum_field_types real_type() const final
Definition: field.h:3204
uint decimals() const final
Definition: field.h:3202
const CHARSET_INFO * sort_charset() const final
Definition: field.h:3228
Field_time(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, uint8 dec_arg)
Constructor for Field_time.
Definition: field.h:3185
Definition: field.h:2997
uint pack_length_from_metadata(uint field_metadata) const final
Definition: field.h:3038
bool zero_pack() const final
Definition: field.h:3035
Field_timestamp * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3027
enum_field_types real_type() const final
Definition: field.h:3033
enum_field_types binlog_type() const final
Definition: field.h:3034
uint32 pack_length() const final
Definition: field.h:3037
enum_field_types type() const final
Definition: field.h:3032
Definition: field.h:2254
ulonglong get_max_int_value() const final
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:2300
Field_tiny(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, bool zero_arg, bool unsigned_arg)
Definition: field.h:2256
uint32 max_display_length() const final
Definition: field.h:2284
enum_field_types type() const override
Definition: field.h:2267
uchar * pack(uchar *to, const uchar *from, size_t max_length) const final
Pack the field into a format suitable for storage and transfer.
Definition: field.h:2289
enum Item_result result_type() const final
Definition: field.h:2266
Field_tiny * clone(MEM_ROOT *mem_root) const override
Makes a shallow copy of the Field object.
Definition: field.h:2285
const uchar * unpack(uchar *to, const uchar *from, uint param_data) final
Unpack a field from row data.
Definition: field.h:2294
enum ha_base_keytype key_type() const final
Definition: field.h:2268
uint32 pack_length() const final
Definition: field.h:2282
Field_tiny(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, bool unsigned_arg)
Definition: field.h:2261
Field that stores array of values of the same type.
Definition: field.h:4086
bool binary() const override
Definition: field.h:4129
enum_field_types m_elt_type
The array element's real type.
Definition: field.h:4090
bool is_array() const override
Whether the field is a typed array.
Definition: field.h:4126
uint decimals() const override
Definition: field.h:4128
const CHARSET_INFO * charset() const override
Return a text charset so that string functions automatically convert the field value to string and tr...
Definition: field.h:4133
enum_field_types real_type() const override
Definition: field.h:4119
uint pack_length_from_metadata(uint) const override
Definition: field.h:4251
bool match_collation_to_optimize_range() const override
Multi-valued index always works only as a pre-filter for actual condition check, and the latter alway...
Definition: field.h:4181
enum_field_types binlog_type() const override
Definition: field.h:4120
int key_cmp(const uchar *, const uchar *) const override
These methods are used by handler to prevent returning a row past the end_range during range access.
Definition: field.h:4156
uint m_elt_decimals
Element's decimals.
Definition: field.h:4092
const bool unsigned_flag
Definition: field.h:4095
enum_field_types type() const override
Definition: field.h:4116
uint32 get_length_bytes() const override
Return number of bytes the field's length takes.
Definition: field.h:4215
uint32 char_length() const override
maximum possible character length for blob.
Definition: field.h:4112
const CHARSET_INFO * m_elt_charset
Element's charset.
Definition: field.h:4094
bool is_unsigned() const final
Whether the field is signed or not.
Definition: field.h:4125
size_t make_sort_key(uchar *to, size_t max_len) const override
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:4220
Definition: field.h:3377
bool match_collation_to_optimize_range() const final
Definition: field.h:3388
uint32 pack_length() const final
Definition: field.h:3392
bool is_text_key_type() const final
Definition: field.h:3437
const uchar * data_ptr() const final
Return a const pointer to the actual data in the record buffer.
Definition: field.h:3436
bool zero_pack() const final
Definition: field.h:3391
Field_varstring * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3429
bool has_charset() const final
Definition: field.h:3423
uint32 key_length() const final
Definition: field.h:3395
uint32 length_bytes
Definition: field.h:3442
enum_field_types type() const final
Definition: field.h:3387
uint32 get_length_bytes() const override
Return number of bytes the field's length takes.
Definition: field.h:3438
Definition: field.h:3791
uint32 char_length() const override
maximum possible character length for blob.
Definition: field.h:3835
enum_field_types real_type() const final
Definition: field.h:3837
enum_field_types type() const final
Definition: field.h:3836
Field_vector(uchar *ptr_arg, uint32 len_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO *cs)
Definition: field.h:3802
Field_vector(uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, const CHARSET_INFO *cs)
Definition: field.h:3812
uint32 get_max_dimensions() const
Definition: field.h:3798
Field_vector * clone(MEM_ROOT *mem_root) const override
Makes a shallow copy of the Field object.
Definition: field.h:3830
uint32 max_data_length() const override
Get the maximum size of the data in packed format.
Definition: field.h:3834
void sql_type(String &res) const override
Definition: field.h:3823
Field_vector(const Field_vector &field)
Definition: field.h:3819
static uint32 dimension_bytes(uint32 dimensions)
Definition: field.h:3795
Definition: field.h:3066
Limits
Definition: field.h:3068
Field_year(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg)
Definition: field.h:3069
Field_year * clone(MEM_ROOT *mem_root) const final
Makes a shallow copy of the Field object.
Definition: field.h:3093
enum_field_types type() const final
Definition: field.h:3076
Field_year(bool is_nullable_arg, const char *field_name_arg)
Definition: field.h:3073
Definition: field.h:573
Field(const Field &)=default
Key_map get_covering_prefix_keys() const
Get covering prefix keys.
Definition: field.cc:10256
uchar * pack(uchar *to) const
Definition: field.h:1517
uchar * pack_int16(uchar *to, const uchar *from, size_t max_length) const
Definition: field.cc:10389
virtual void set_default()
Definition: field.cc:10270
void reset_warnings()
Definition: field.h:900
virtual int cmp_binary(const uchar *a, const uchar *b, uint32 max_length=~0L) const
Definition: field.h:1186
virtual enum_field_types real_type() const
Definition: field.h:1159
virtual type_conversion_status store(double nr)=0
virtual bool pack_diff(uchar **to, ulonglong value_options) const
Write the field for the binary log in diff format.
Definition: field.h:1566
virtual uint max_packed_col_length() const
This is a wrapper around pack_length() used by filesort() to determine how many bytes we need for pac...
Definition: field.h:1577
Key_map part_of_sortkey
Definition: field.h:691
const char * orig_table_name
Pointer to original table name, only non-NULL for a temporary table.
Definition: field.h:683
virtual const uchar * data_ptr() const
Return a const pointer to the actual data in the record buffer.
Definition: field.h:1771
bool is_virtual_gcol() const
Definition: field.h:827
const uchar * unpack_int24(uchar *to, const uchar *from) const
Definition: field.cc:10406
virtual uint32 pack_length_in_rec() const
Definition: field.h:1061
const char ** table_name
Definition: field.h:684
uint null_offset() const
Definition: field.cc:10278
const uchar * unpack_int16(uchar *to, const uchar *from) const
Definition: field.cc:10395
virtual bool compatible_field_size(uint metadata, Relay_log_info *, uint16, int *order) const
Check to see if field size is compatible with destination.
Definition: field.cc:2022
LEX_CSTRING masking_policy() const
Returns the name of the masking policy, or an empty string if no masking policy is defined on this co...
Definition: field.h:849
imagetype
Definition: field.h:726
@ itRAW
Definition: field.h:726
@ itMBR
Definition: field.h:726
const CHARSET_INFO * charset_for_protocol() const
Definition: field.h:1619
void reset_tmp_nullable()
Turn off temporary nullability for the field.
Definition: field.h:910
virtual int do_save_field_metadata(uchar *metadata_ptr) const
Retrieve the field metadata for fields.
Definition: field.h:1876
virtual ulonglong get_max_int_value() const
Get the upper limit of the MySQL integral and floating-point type.
Definition: field.h:1759
void set_tmp_null()
Set field to temporary value NULL.
Definition: field.cc:1378
virtual bool send_to_protocol(Protocol *protocol) const
Send the value of this field over the protocol using the correct Protocol::store*() function which ma...
Definition: field.cc:1983
virtual uint decimals() const
Definition: field.h:1202
virtual Field * new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
Definition: field.cc:2386
uint32 field_length
Definition: field.h:739
static constexpr size_t MAX_SHORT_BLOB_WIDTH
Definition: field.h:733
virtual Item_result cast_to_int_type() const
Definition: field.h:1038
void set_null_ptr(uchar *p_null_ptr, uint p_null_bit)
Definition: field.h:1299
void copy_data(ptrdiff_t src_record_offset)
Definition: field.cc:1971
bool m_is_tmp_null
This is a flag with the following semantics:
Definition: field.h:661
static constexpr size_t MAX_LONG_BLOB_WIDTH
Definition: field.h:735
type_conversion_status store_time(MYSQL_TIME *ltime)
Store MYSQL_TYPE value into a field when the number of fractional digits is not important or is not k...
Definition: field.h:980
void operator=(Field &)=delete
virtual type_conversion_status validate_stored_val(THD *thd)
Validate the value stored in a field.
Definition: field.h:1746
static uchar dummy_null_buffer
Definition: field.h:674
virtual bool is_array() const
Whether the field is a typed array.
Definition: field.h:1826
virtual bool optimize_range(uint idx, uint part) const
Whether this field can be used for index range scans when in the given keypart of the given index.
Definition: field.cc:2354
bool has_insert_default_general_value_expression() const
Checks if the field is marked as having a general expression to generate default values.
Definition: field.h:593
Key_map key_start
Definition: field.h:687
void set_null(ptrdiff_t row_offset=0)
Set field to value NULL.
Definition: field.cc:1931
virtual type_conversion_status store_decimal(const my_decimal *d)=0
virtual bool binary() const
Definition: field.h:1154
longlong val_int(uchar *new_ptr)
Definition: field.h:1458
Value_generator * gcol_info
Definition: field.h:814
ha_storage_media field_storage_type() const
Definition: field.h:1723
int cmp(const uchar *str) const
Definition: field.h:1180
virtual bool str_needs_quotes() const
Definition: field.h:1022
static constexpr size_t MAX_VARCHAR_WIDTH
Definition: field.h:729
virtual void get_image(uchar *buff, size_t length, const CHARSET_INFO *) const
Definition: field.h:1408
static constexpr size_t MAX_TINY_BLOB_WIDTH
Definition: field.h:732
const char * field_name
Definition: field.h:684
void set_field_ptr(uchar *ptr_arg)
Definition: field.h:1789
void clear_flag(unsigned flag)
Definition: field.h:752
uchar * pack_int24(uchar *to, const uchar *from, size_t max_length) const
Definition: field.cc:10400
Value_generator * m_default_val_expr
Holds the expression to be used to generate default values.
Definition: field.h:830
const uchar * field_ptr() const
Return a const pointer to where the field is stored in the record buffer.
Definition: field.h:1779
virtual void add_to_cost(CostOfItem *cost) const
Update '*cost' with the fact that this Field is accessed.
Definition: field.cc:1403
virtual longlong val_date_temporal() const
Returns DATE/DATETIME value in packed longlong format.
Definition: field.h:993
virtual uint32 pack_length() const
Definition: field.h:1054
void set_hidden(dd::Column::enum_hidden_type hidden)
Sets the hidden type for this field.
Definition: field.h:837
LEX_CSTRING comment
Definition: field.h:685
uint16 m_field_index
Definition: field.h:747
virtual const CHARSET_INFO * charset() const
Definition: field.h:1617
void set_notnull(ptrdiff_t row_offset=0)
Set field to value NOT NULL.
Definition: field.cc:1946
virtual uint32 get_length_bytes() const
Return number of bytes the field's length takes.
Definition: field.h:1833
virtual size_t make_sort_key(uchar *buff, size_t length, size_t trunc_pos) const
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
Definition: field.h:1349
bool gcol_expr_is_equal(const Create_field *field) const
Check whether generated columns' expressions are the same.
Definition: field.cc:6146
virtual uint32 max_display_length() const =0
enum_auto_flags
Flags for Field::auto_flags / Create_field::auto_flags bitmaps.
Definition: field.h:708
@ ON_UPDATE_NOW
ON UPDATE CURRENT_TIMESTAMP.
Definition: field.h:712
@ GENERATED_FROM_EXPRESSION
DEFAULT (expression)
Definition: field.h:713
@ NONE
Definition: field.h:709
@ DEFAULT_NOW
DEFAULT CURRENT_TIMESTAMP.
Definition: field.h:711
@ NEXT_NUMBER
AUTO_INCREMENT.
Definition: field.h:710
String * val_int_as_str(String *val_buffer, bool unsigned_flag) const
Interpret field value as an integer but return the result as a string.
Definition: field.cc:1835
virtual uint32 data_length(ptrdiff_t row_offset=0) const
Definition: field.h:1078
virtual void set_image(const uchar *buff, size_t length, const CHARSET_INFO *)
Definition: field.h:1413
virtual bool has_charset() const
Definition: field.h:1623
virtual void set_derivation(enum Derivation)
Definition: field.h:1638
bool is_null_in_record(const uchar *record) const
Check if the Field has value NULL or the record specified by argument has value NULL for this Field.
Definition: field.h:1265
void reset_tmp_null()
Reset temporary NULL value for field.
Definition: field.h:915
virtual uchar * pack_with_metadata_bytes(uchar *to, const uchar *from, uint max_length) const
This function does the same thing as pack(), except for the difference that max_length does not mean ...
Definition: field.h:1539
virtual enum_field_types type() const =0
virtual bool zero_pack() const
Definition: field.h:1155
virtual void move_field_offset(ptrdiff_t ptr_diff)
Definition: field.h:1403
bool has_masking_policy() const
Does this column have a masking policy?
Definition: field.h:845
Key_map part_of_key
Keys that includes this field except of prefix keys.
Definition: field.h:688
virtual type_conversion_status store_packed(longlong nr)
Store a temporal value in packed longlong format into a field.
Definition: field.h:952
bool is_hidden_by_user() const
Definition: field.h:879
Field * new_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
Definition: field.h:1371
bool handle_old_value() const
Whether field's old valued have to be handled.
Definition: field.h:1845
TABLE * table
Pointer to TABLE object that owns this field.
Definition: field.h:679
uint16 field_index() const
Returns field index.
Definition: field.h:1863
virtual type_conversion_status store(longlong nr, bool unsigned_val)=0
virtual bool get_timestamp(my_timeval *tm, int *warnings) const
Returns a UTC component in struct timeval format.
Definition: field.cc:2328
void move_field(uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg)
Definition: field.h:1397
const uchar * unpack_int32(uchar *to, const uchar *from) const
Definition: field.cc:10417
virtual void init(TABLE *table_arg)
Definition: field.cc:10280
bool is_null(ptrdiff_t row_offset=0) const
Check whether the full table's row is NULL or the Field has value NULL.
Definition: field.h:1218
virtual my_decimal * val_decimal(my_decimal *) const =0
bool has_insert_default_datetime_value_expression() const
Checks if the field is marked as having a datetime value expression to generate default values on ins...
Definition: field.h:604
void evaluate_update_default_function()
Evaluates the UPDATE default function, if one exists, and stores the result in the record buffer.
Definition: field.cc:2405
LEX_CSTRING m_engine_attribute
Definition: field.h:792
void set_tmp_nullable()
Turn on temporary nullability for the field.
Definition: field.h:905
const uchar * unpack_int64(uchar *to, const uchar *from) const
Definition: field.cc:10428
virtual void set_field_index(uint16 field_index)
Sets field index.
Definition: field.h:1854
type_conversion_status check_constraints(int mysql_errno)
Check NOT NULL constraint on the field after temporary nullability is disabled.
Definition: field.cc:1888
Key_map part_of_prefixkey
Prefix keys.
Definition: field.h:690
bool is_real_null(ptrdiff_t row_offset=0) const
Check whether the Field has value NULL (temporary or actual).
Definition: field.h:1250
bool is_tmp_nullable() const
Definition: field.h:924
String * val_str(String *str, uchar *new_ptr)
Definition: field.h:1466
uchar null_bit
Definition: field.h:756
virtual double val_real() const =0
virtual bool val_date(Date_val *date, my_time_flags_t flags) const
Retrieve field value and return the result as a date.
Definition: field.cc:2304
virtual bool can_be_compared_as_longlong() const
Definition: field.h:1366
virtual longlong val_int() const =0
uchar * pack_int32(uchar *to, const uchar *from, size_t max_length) const
Definition: field.cc:10411
bool m_is_tmp_nullable
Flag: if the NOT-NULL field can be temporary NULL.
Definition: field.h:651
virtual void make_send_field(Send_field *send_field) const
Populates a Send_field object with metadata about the column represented by this Field object.
Definition: field.cc:2146
virtual size_t make_sort_key(uchar *buff, size_t length) const =0
Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comp...
virtual const CHARSET_INFO * sort_charset() const
Definition: field.h:1622
virtual Item_result numeric_context_result_type() const
Returns Item_result type of a field when it appears in numeric context such as: SELECT time_column + ...
Definition: field.h:1034
bool m_indexed
True if this field belongs to some index (unlike part_of_key, the index might have only a prefix).
Definition: field.h:790
virtual int cmp_binary_offset(ptrdiff_t row_offset) const
Definition: field.h:1193
virtual bool is_updatable() const
Checks whether a string field is part of write_set.
Definition: field.h:1799
virtual bool eq_def(const Field *field) const
Definition: field.cc:8519
const uchar * unpack(const uchar *from)
Definition: field.h:1521
geometry_type
Definition: field.h:716
@ GEOM_GEOMETRYCOLLECTION
Definition: field.h:724
@ GEOM_POLYGON
Definition: field.h:720
@ GEOM_MULTILINESTRING
Definition: field.h:722
@ GEOM_POINT
Definition: field.h:718
@ GEOM_MULTIPOINT
Definition: field.h:721
@ GEOM_MULTIPOLYGON
Definition: field.h:723
@ GEOM_LINESTRING
Definition: field.h:719
@ GEOM_GEOMETRY
Definition: field.h:717
virtual int cmp_max(const uchar *a, const uchar *b, uint max_len) const
Definition: field.h:1181
virtual bool val_time(Time_val *time) const
Retrieve field value and return the result as a time.
Definition: field.cc:2320
virtual Item_result result_type() const =0
uint32 flags
Definition: field.h:746
bool is_nullable() const
Definition: field.h:1291
bool warn_if_overflow(int op_result)
Process decimal library return codes and issue warnings for overflow and truncation.
Definition: field.cc:1817
static bool type_can_have_key_part(enum_field_types)
Check whether a field type can be partially indexed by a key.
Definition: field.cc:1645
bool set_warning(Sql_condition::enum_severity_level level, unsigned int code, int cut_increment)
Produce warning or note about data saved into field.
Definition: field.h:1661
virtual bool val_datetime(Datetime_val *dt, my_time_flags_t flags) const
Retrieve field value and return the result as a datetime/timestamp.
Definition: field.cc:2312
virtual type_conversion_status store(const char *to, size_t length, const CHARSET_INFO *cs)=0
LEX_CSTRING m_masking_policy
Holds the name of the masking policy applied to the field.
Definition: field.h:810
virtual geometry_type get_geometry_type() const
Definition: field.h:1702
uint null_offset(const uchar *record) const
Definition: field.h:1293
virtual bool is_text_key_type() const
Definition: field.h:1203
virtual String * val_str(String *, String *) const =0
virtual uchar * pack(uchar *to, const uchar *from, size_t max_length) const
Pack the field into a format suitable for storage and transfer.
Definition: field.cc:2070
static Item_result result_merge_type(enum_field_types)
Detect Item_result by given field type of UNION merge result.
Definition: field.cc:1522
virtual bool eq(const Field *field) const
Definition: field.h:1043
Field * new_key_field(MEM_ROOT *root, TABLE *new_table, uchar *new_ptr) const
Definition: field.h:1381
bool is_tmp_null() const
Definition: field.h:932
virtual uint32 key_length() const
Definition: field.h:1157
bool is_gcol() const
Definition: field.h:826
dd::Column::enum_hidden_type m_hidden
Definition: field.h:640
void set_storage_type(ha_storage_media storage_type_arg)
Definition: field.h:1727
static enum_field_types field_type_merge(enum_field_types, enum_field_types)
Return type of which can carry value of both given types in UNION result.
Definition: field.cc:1397
uchar * m_null_ptr
Byte where the NULL bit is stored inside a record.
Definition: field.h:646
virtual uint32 max_data_length() const
Get the maximum size of the data in packed format.
Definition: field.h:1088
virtual Item_result cmp_type() const
Definition: field.h:1037
column_format_type column_format() const
Definition: field.h:1732
virtual const uchar * unpack(uchar *to, const uchar *from, uint param_data)
Unpack a field from row data.
Definition: field.cc:2101
uchar auto_flags
Bitmap of flags indicating if field value is auto-generated by default and/or on update,...
Definition: field.h:766
bool is_hidden_by_system() const
Definition: field.h:869
virtual int cmp(const uchar *, const uchar *) const =0
String * val_str(String *str) const
Definition: field.h:1003
unsigned int m_warnings_pushed
Definition: field.h:807
void set_check_for_truncated_fields(enum_check_fields check_for_truncated_fields)
Remember the value of THD::check_for_truncated_fields to handle possible NOT-NULL constraint errors a...
Definition: field.h:1285
uchar * pack_int64(uchar *to, const uchar *from, size_t max_length) const
Definition: field.cc:10422
virtual longlong val_date_temporal_at_utc() const
Definition: field.h:998
const char * orig_db_name
Pointer to original database name, only non-NULL for a temporary table.
Definition: field.h:681
uchar * get_null_ptr()
Definition: field.h:677
virtual uint32 char_length() const
Definition: field.h:1698
bool is_field_for_functional_index() const
Definition: field.h:890
virtual uint pack_length_from_metadata(uint field_metadata) const
Definition: field.h:1064
LEX_CSTRING m_secondary_engine_attribute
Definition: field.h:793
virtual int key_cmp(const uchar *str, uint length) const
Definition: field.h:1199
bool is_hidden() const
Definition: field.h:858
virtual void store_timestamp(const my_timeval *)
Stores a timestamp value in timeval format in a field.
Definition: field.h:1136
enum_check_fields m_check_for_truncated_fields_saved
The value of THD::check_for_truncated_fields at the moment of setting m_is_tmp_null attribute.
Definition: field.h:667
void evaluate_insert_default_function()
Evaluates the INSERT default function and stores the result in the field.
Definition: field.cc:2397
virtual int cmp_offset(ptrdiff_t row_offset) const
Definition: field.h:1190
bool is_created_from_null_item
If true, this field was created in create_tmp_field_from_item from a NULL value.
Definition: field.h:776
uint32 all_flags() const
Definition: field.h:755
int save_field_metadata(uchar *first_byte)
Definition: field.h:1069
virtual Field * clone(MEM_ROOT *mem_root) const =0
Makes a shallow copy of the Field object.
bool stored_in_db
Indication that the field is physically stored in tables rather than just generated on SQL queries.
Definition: field.h:820
virtual type_conversion_status store_time(Time_val time, uint8 dec_arg)
Store a time value into a string column.
Definition: field.cc:2045
virtual enum Derivation derivation() const
Definition: field.h:1636
virtual type_conversion_status store_date(Date_val date)
Store a date value into a string column.
Definition: field.cc:2059
uchar * ptr
Holds the position to the field in record.
Definition: field.h:637
static constexpr size_t MAX_MEDIUM_BLOB_WIDTH
Definition: field.h:734
virtual void set_field_length(uint32 length)
Definition: field.h:740
virtual int key_cmp(const uchar *a, const uchar *b) const
Definition: field.h:1196
virtual bool is_unsigned() const
Whether the field is signed or not.
Definition: field.h:825
bool has_update_default_datetime_value_expression() const
Checks if the field is marked as having a datetime value expression to generate default values on upd...
Definition: field.h:616
virtual enum_field_types binlog_type() const
Definition: field.h:1160
bool is_part_of_actual_key(THD *thd, uint cur_index, KEY *cur_index_info) const
Check whether field is part of the index taking the index extensions flag into account.
Definition: field.cc:9839
dd::Column::enum_hidden_type hidden() const
Definition: field.h:852
void dbug_print() const
Definition: field.h:1709
longlong convert_decimal2longlong(const my_decimal *val, bool unsigned_flag, bool *has_overflow)
Conversion from decimal to longlong.
Definition: field.cc:2172
virtual ~Field()=default
uchar * field_ptr()
Return a pointer to where the field is stored in the record buffer.
Definition: field.h:1787
virtual enum ha_base_keytype key_type() const
Definition: field.h:1156
virtual uint is_equal(const Create_field *new_field) const
Whether a field being created is type-compatible with an existing one.
Definition: field.cc:1384
virtual size_t get_key_image(uchar *buff, size_t length, imagetype type) const
Definition: field.h:1444
virtual void mem_free()
Definition: field.h:1367
virtual bool match_collation_to_optimize_range() const
Definition: field.h:1635
virtual uint repertoire() const
Definition: field.h:1637
virtual void hash(ulong *nr, ulong *nr2) const
Definition: field.cc:1955
bool has_insert_default_constant_expression() const
Checks if the field is marked as having a constant expression to generate default values.
Definition: field.h:628
virtual uint row_pack_length() const
Definition: field.h:1068
virtual bool is_wrapper_field() const
If true, it's a Create_field_wrapper (a sub-class of Field used during CREATE/ALTER that we mustn't c...
Definition: field.h:784
virtual void sql_type(String &str) const =0
virtual type_conversion_status reset()
Definition: field.h:1090
void set_flag(unsigned flag)
Definition: field.h:751
void set_masking_policy(LEX_CSTRING masking_policy)
Sets the name of the masking policy to apply to this column.
Definition: field.h:840
enum_pushed_warnings
Definition: field.h:796
@ NO_DEFAULT_FOR_FIELD_PUSHED
Definition: field.h:798
@ NO_DEFAULT_FOR_VIEW_FIELD_PUSHED
Definition: field.h:799
@ BAD_NULL_ERROR_PUSHED
Definition: field.h:797
virtual Field * new_field(MEM_ROOT *root, TABLE *new_table) const
Definition: field.cc:2358
void set_column_format(column_format_type column_format_arg)
Definition: field.h:1736
uint offset(uchar *record) const
Definition: field.h:1579
virtual void set_key_image(const uchar *buff, size_t length)
Definition: field.h:1449
bool is_flag_set(unsigned flag) const
Definition: field.h:750
Key_map part_of_key_not_extended
All keys that include this field, but not extended by the storage engine to include primary key colum...
Definition: field.h:696
longlong val_int_offset(ptrdiff_t row_offset)
Definition: field.h:1452
Definition: item.h:4529
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:929
Represents a JSON array container, i.e.
Definition: json_dom.h:520
Vector of logical diffs describing changes to a JSON column.
Definition: json_diff.h:141
Abstraction for accessing JSON values irrespective of whether they are (started out as) binary JSON v...
Definition: json_dom.h:1268
Definition: key.h:113
Definition: protocol.h:33
Definition: rpl_rli.h:205
Definition: field.h:4555
const char * col_name
Definition: field.h:4559
ulong length
Definition: field.h:4560
uint charsetnr
Definition: field.h:4561
bool field
Definition: field.h:4568
enum_field_types type
Definition: field.h:4562
Send_field()=default
const char * db_name
Definition: field.h:4557
const char * org_table_name
Definition: field.h:4558
enum_severity_level
Enumeration value describing the severity of the condition.
Definition: sql_error.h:66
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
void takeover(String &s)
Takeover the buffer owned by another string.
Definition: sql_string.h:467
void mem_free()
Definition: sql_string.h:402
char * c_ptr_safe()
Returns a pointer to a C-style null-terminated string.
Definition: sql_string.h:290
const CHARSET_INFO * charset() const
Definition: sql_string.h:242
const char * ptr() const
Definition: sql_string.h:251
size_t length() const
Definition: sql_string.h:243
size_t alloced_length() const
Definition: sql_string.h:244
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Time_val is a temporal type that represents only time.
Definition: my_temporal.h:57
This class represents abstract time zone and provides basic interface for MYSQL_TIME <-> my_time_t co...
Definition: tztime.h:49
Used for storing information associated with generated column, default values generated from expressi...
Definition: field.h:481
void set_field_stored(bool stored)
Definition: field.h:534
void set_field_type(enum_field_types fld_type)
Definition: field.h:517
uint num_non_virtual_base_cols
How many non-virtual base columns in base_columns_map.
Definition: field.h:570
bool stored_in_db
Indicates if the field is physically stored in the database.
Definition: field.h:568
bool register_base_columns(TABLE *table)
Calculate the base_columns_map and num_non_virtual_base_cols members of this generated column.
Definition: table.cc:2568
enum_field_types field_type
Real field type.
Definition: field.h:566
void backup_stmt_unsafe_flags(uint32 backup_binlog_stmt_flags)
Set the binary log flags in m_backup_binlog_stmt_flags.
Definition: field.h:523
uint non_virtual_base_columns() const
Get the number of non virtual base columns that this generated column needs.
Definition: field.h:542
Item * expr_item
Item representing the generation expression.
Definition: field.h:491
void dup_expr_str(MEM_ROOT *root, const char *src, size_t len)
Duplicates a string into expr_str.
Definition: table.cc:2592
uint32 get_stmt_unsafe_flags()
Get the binary log flags from m_backup_binlog_stmt_flags.
Definition: field.h:531
MY_BITMAP base_columns_map
Bitmap records base columns which a generated column depends on.
Definition: field.h:513
uint32 m_backup_binlog_stmt_flags
Bit field indicating the type of statement for binary logging.
Definition: field.h:508
void print_expr(THD *thd, String *out)
Writes the generation expression into a String with proper syntax.
Definition: table.cc:2598
Item * item_list
List of all items created when parsing and resolving generated expression.
Definition: field.h:511
bool get_field_stored() const
Definition: field.h:533
enum_field_types get_real_type() const
Definition: field.h:515
LEX_STRING expr_str
Text of the expression.
Definition: field.h:499
enum_hidden_type
Definition: column.h:96
@ HT_HIDDEN_SQL
The column is visible to the server, but hidden from the user.
@ HT_HIDDEN_SE
The column is completely invisible to the server.
@ HT_VISIBLE
The column is visible (a normal column)
@ HT_HIDDEN_USER
User table column marked as INVISIBLE by using the column visibility attribute.
my_decimal class limits 'decimal_t' type to what we need in MySQL.
Definition: my_decimal.h:97
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
#define L
Definition: ctype-tis620.cc:74
uint64_t sql_mode_t
Definition: dd_event.h:39
#define E_DEC_TRUNCATED
Definition: decimal.h:148
#define E_DEC_DIV_ZERO
Definition: decimal.h:150
#define E_DEC_BAD_NUM
Definition: decimal.h:151
#define E_DEC_OK
Definition: decimal.h:147
#define E_DEC_OOM
Definition: decimal.h:152
#define E_DEC_OVERFLOW
Definition: decimal.h:149
static constexpr int DECIMAL_NOT_SPECIFIED
Definition: dtoa.h:54
This file contains basic method for field types.
bool is_temporal_type(enum_field_types type)
Tests if field type is temporal, i.e.
Definition: field_common_properties.h:139
This file contains the field type.
enum_field_types
Column types for MySQL Note: Keep include/mysql/components/services/bits/stored_program_bits....
Definition: field_types.h:55
@ MYSQL_TYPE_TIME2
Internal to MySQL.
Definition: field_types.h:75
@ MYSQL_TYPE_VARCHAR
Definition: field_types.h:71
@ MYSQL_TYPE_LONGLONG
Definition: field_types.h:64
@ MYSQL_TYPE_LONG_BLOB
Definition: field_types.h:86
@ MYSQL_TYPE_BLOB
Definition: field_types.h:87
@ MYSQL_TYPE_TINY
Definition: field_types.h:57
@ MYSQL_TYPE_TIME
Definition: field_types.h:67
@ MYSQL_TYPE_SET
Definition: field_types.h:83
@ MYSQL_TYPE_NEWDATE
Internal to MySQL.
Definition: field_types.h:70
@ MYSQL_TYPE_VECTOR
Definition: field_types.h:77
@ MYSQL_TYPE_JSON
Definition: field_types.h:80
@ MYSQL_TYPE_STRING
Definition: field_types.h:89
@ MYSQL_TYPE_NULL
Definition: field_types.h:62
@ MYSQL_TYPE_ENUM
Definition: field_types.h:82
@ MYSQL_TYPE_TINY_BLOB
Definition: field_types.h:84
@ MYSQL_TYPE_LONG
Definition: field_types.h:59
@ MYSQL_TYPE_BIT
Definition: field_types.h:72
@ MYSQL_TYPE_INVALID
Definition: field_types.h:78
@ MYSQL_TYPE_GEOMETRY
Definition: field_types.h:90
@ MYSQL_TYPE_NEWDECIMAL
Definition: field_types.h:81
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:56
@ MYSQL_TYPE_TYPED_ARRAY
Used for replication only.
Definition: field_types.h:76
@ MYSQL_TYPE_DOUBLE
Definition: field_types.h:61
@ MYSQL_TYPE_MEDIUM_BLOB
Definition: field_types.h:85
@ MYSQL_TYPE_DATETIME2
Internal to MySQL.
Definition: field_types.h:74
@ MYSQL_TYPE_SHORT
Definition: field_types.h:58
@ MYSQL_TYPE_DATE
Definition: field_types.h:66
@ MYSQL_TYPE_FLOAT
Definition: field_types.h:60
@ MYSQL_TYPE_TIMESTAMP
Definition: field_types.h:63
@ MYSQL_TYPE_INT24
Definition: field_types.h:65
@ MYSQL_TYPE_DATETIME
Definition: field_types.h:68
@ MYSQL_TYPE_TIMESTAMP2
Definition: field_types.h:73
@ MYSQL_TYPE_YEAR
Definition: field_types.h:69
static const std::string dec("DECRYPTION")
#define ENUM_FLAG
field is an enum
Definition: mysql_com.h:164
#define FIELD_FLAGS_COLUMN_FORMAT
Field column format, bit 24-25.
Definition: mysql_com.h:186
#define BLOB_FLAG
Field is a blob.
Definition: mysql_com.h:158
#define SET_FLAG
field is a set
Definition: mysql_com.h:167
#define BINARY_FLAG
Field is binary
Definition: mysql_com.h:161
#define FIELD_FLAGS_STORAGE_MEDIA
Field storage media, bit 22-23.
Definition: mysql_com.h:184
static int flag
Definition: hp_test1.cc:40
static int rnd(int max_value)
Definition: hp_test2.cc:551
enum_mysql_timestamp_type
Definition: mysql_time.h:45
constexpr const LEX_CSTRING EMPTY_CSTR
Definition: lex_string.h:49
A better implementation of the UNIX ctype(3) library.
static constexpr uint32_t MY_REPERTOIRE_UNICODE30
Definition: m_ctype.h:156
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_bin
Definition: ctype-bin.cc:499
MYSQL_STRINGS_EXPORT CHARSET_INFO my_charset_utf8mb4_bin
Definition: ctype-utf8.cc:7813
MYSQL_STRINGS_EXPORT unsigned my_charset_repertoire(const CHARSET_INFO *cs)
Definition: ctype.cc:821
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
ha_base_keytype
Definition: my_base.h:444
@ HA_KEYTYPE_VARBINARY2
Definition: my_base.h:465
@ HA_KEYTYPE_BINARY
Definition: my_base.h:447
@ HA_KEYTYPE_USHORT_INT
Definition: my_base.h:453
@ HA_KEYTYPE_ULONGLONG
Definition: my_base.h:456
@ HA_KEYTYPE_UINT24
Definition: my_base.h:458
@ HA_KEYTYPE_VARTEXT2
Definition: my_base.h:464
@ HA_KEYTYPE_FLOAT
Definition: my_base.h:450
@ HA_KEYTYPE_BIT
Definition: my_base.h:466
@ HA_KEYTYPE_ULONG_INT
Definition: my_base.h:454
@ HA_KEYTYPE_SHORT_INT
Definition: my_base.h:448
@ HA_KEYTYPE_NUM
Definition: my_base.h:452
@ HA_KEYTYPE_DOUBLE
Definition: my_base.h:451
@ HA_KEYTYPE_LONG_INT
Definition: my_base.h:449
@ HA_KEYTYPE_INT8
Definition: my_base.h:459
@ HA_KEYTYPE_INT24
Definition: my_base.h:457
@ HA_KEYTYPE_TEXT
Definition: my_base.h:446
@ HA_KEYTYPE_LONGLONG
Definition: my_base.h:455
ha_storage_media
Definition: my_base.h:116
@ HA_SM_DEFAULT
Definition: my_base.h:117
#define DBUG_PRINT(keyword, arglist)
Definition: my_dbug.h:181
#define DBUG_FILE
Definition: my_dbug.h:194
#define DBUG_EVALUATE_IF(keyword, a1, a2)
Definition: my_dbug.h:179
#define DBUG_TRACE
Definition: my_dbug.h:146
Utility functions for converting between ulonglong and double.
static constexpr double LLONG_MAX_DOUBLE
Definition: my_double2ulonglong.h:57
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
#define MY_INT32_NUM_DECIMAL_DIGITS
Definition: my_inttypes.h:100
uint16_t uint16
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:67
Server classes for temporal handling (DATE, TIME, DATETIME)
Interface for low level time utilities.
constexpr const my_time_flags_t TIME_NO_INVALID_DATES
Don't allow invalid dates like 2000-02-31.
Definition: my_time.h:108
constexpr const my_time_flags_t TIME_NO_ZERO_IN_DATE
Don't allow zero day or zero month.
Definition: my_time.h:102
constexpr const int MYSQL_TIME_WARN_INVALID_TIMESTAMP
Definition: my_time.h:123
constexpr const int MYSQL_TIME_NOTE_TRUNCATED
Definition: my_time.h:125
constexpr const int MYSQL_TIME_WARN_TRUNCATED
Conversion warnings.
Definition: my_time.h:121
constexpr const my_time_flags_t TIME_NO_ZERO_DATE
Don't allow 0000-00-00 date.
Definition: my_time.h:105
constexpr const int DATETIME_MAX_DECIMALS
Definition: my_time.h:146
constexpr const int MYSQL_TIME_WARN_ZERO_IN_DATE
Definition: my_time.h:126
constexpr const int MYSQL_TIME_WARN_OUT_OF_RANGE
Definition: my_time.h:122
unsigned int my_time_flags_t
Flags to str_to_datetime and int_to_datetime.
Definition: my_time.h:87
constexpr const int MYSQL_TIME_WARN_ZERO_DATE
Definition: my_time.h:124
constexpr const my_time_flags_t TIME_FRAC_TRUNCATE
Whether to truncate or round fractional time component.
Definition: my_time.h:96
unsigned int STDCALL mysql_errno(MYSQL *mysql)
Definition: client.cc:9331
Common definition between mysql server & client.
static int interval
Definition: mysqladmin.cc:72
void warning(const char *format,...)
static int record
Definition: mysqltest.cc:195
void copy(Shards< COUNT > &dst, const Shards< COUNT > &src) noexcept
Copy the counters, overwrite destination.
Definition: ut0counter.h:354
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
constexpr value_type zerofill
Definition: classic_protocol_constants.h:274
constexpr value_type is_unsigned
Definition: classic_protocol_constants.h:273
static PFS_engine_table_share_proxy share
Definition: connection_control_pfs_table.cc:92
Definition: commit_order_queue.h:34
enum_column_types
Definition: column.h:53
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
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
RangeReverse< Range > reverse(Range &x)
Iterate over a range in reverse.
Definition: utilities.h:132
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
std::string truncate(const std::string &str, const size_t max_length)
Truncates the given string to max_length code points.
Definition: utils_string.cc:418
mode
Definition: file_handle.h:61
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2888
required uint32 status
Definition: replication_asynchronous_connection_failover.proto:61
repeated Source source
Definition: replication_asynchronous_connection_failover.proto:42
required string type
Definition: replication_group_member_actions.proto:34
static void make_hash_key(const char *username, const char *hostname, std::string &key)
Make hash key.
Definition: sha2_password.cc:944
Create_field * generate_create_field(THD *thd, Item *source_item, TABLE *tmp_table)
Generate a Create_field from an Item.
Definition: field.cc:10526
bool is_temporal_real_type(enum_field_types type)
Tests if field real type is temporal, i.e.
Definition: field.h:347
Field * make_field(MEM_ROOT *mem_root_arg, TABLE_SHARE *share, uchar *ptr, size_t field_length, uchar *null_pos, uchar null_bit, enum_field_types field_type, const CHARSET_INFO *field_charset, Field::geometry_type geom_type, uchar auto_flags, TYPELIB *interval, const char *field_name, bool is_nullable, bool is_zerofill, bool is_unsigned, uint decimals, bool treat_bit_as_char, uint pack_length_override, std::optional< gis::srid_t > srid, bool is_array)
This function should only be called from legacy code.
Definition: field.cc:9386
type_conversion_status
Status when storing a value in a field or converting from one datatype to another.
Definition: field.h:200
@ TYPE_ERR_BAD_VALUE
Store/convert incompatible values, like converting "foo" to a date.
Definition: field.h:243
@ TYPE_OK
Storage/conversion went fine.
Definition: field.h:202
@ TYPE_NOTE_TIME_TRUNCATED
A minor problem when converting between temporal values, e.g.
Definition: field.h:207
@ TYPE_ERR_OOM
Out of memory.
Definition: field.h:245
@ TYPE_NOTE_TRUNCATED
Value was stored, but something was cut.
Definition: field.h:217
@ TYPE_ERR_NULL_CONSTRAINT_VIOLATION
Trying to store NULL in a NOT NULL field.
Definition: field.h:238
@ TYPE_WARN_OUT_OF_RANGE
Value outside min/max limit of datatype.
Definition: field.h:222
@ TYPE_WARN_TRUNCATED
Value was stored, but something was cut.
Definition: field.h:231
@ TYPE_WARN_INVALID_STRING
Value has invalid string data.
Definition: field.h:236
enum_check_fields
Definition: field.h:169
@ CHECK_FIELD_ERROR_FOR_NULL
Definition: field.h:172
@ CHECK_FIELD_IGNORE
Definition: field.h:170
@ CHECK_FIELD_WARN
Definition: field.h:171
void copy_integer(uchar *to, size_t to_length, const uchar *from, size_t from_length, bool is_unsigned)
Copies an integer value to a format comparable with memcmp().
Definition: field.h:450
type_conversion_status set_field_to_null_with_conversions(Field *field, bool no_conversions)
Set field to NULL or TIMESTAMP or to next auto_increment number.
Definition: field_conv.cc:154
uint32 calc_key_length(enum_field_types sql_type, uint32 length, uint32 decimals, bool is_unsigned, uint32 elements)
Calculate key length for field from its type, length and other attributes.
Definition: field.cc:9224
bool pre_validate_value_generator_expr(Item *expression, const char *name, Value_generator_source source)
Perform per item-type checks to determine if the expression is allowed for a generated column,...
Definition: field.cc:1341
#define MY_REPERTOIRE_NUMERIC
Definition: field.h:256
enum_field_types real_type_to_type(enum_field_types real_type)
Convert temporal real types as returned by field->real_type() to field type as returned by field->typ...
Definition: field.h:391
Value_generator_source
Enum to indicate source for which value generator is used.
Definition: field.h:471
@ VGS_DEFAULT_EXPRESSION
Definition: field.h:473
@ VGS_CHECK_CONSTRAINT
Definition: field.h:474
@ VGS_GENERATED_COLUMN
Definition: field.h:472
type_conversion_status decimal_err_to_type_conv_status(int dec_error)
Definition: field.h:292
enum_field_types blob_type_from_pack_length(uint pack_length)
Return the appropriate MYSQL_TYPE_X_BLOB value based on the pack_length.
Definition: field.h:414
uint get_set_pack_length(int elements)
Definition: field.h:287
bool fields_are_memcpyable(const Field *to, const Field *from)
Check if one can copy from “from” to “to” with a simple memcpy(), with pack_length() as the length.
Definition: field_conv.cc:730
#define my_charset_numeric
Definition: field.h:255
type_conversion_status set_field_to_null(Field *field)
Definition: field_conv.cc:94
uint get_enum_pack_length(int elements)
Definition: field.h:283
size_t calc_pack_length(enum_field_types type, size_t length)
Definition: field.cc:9267
type_conversion_status field_conv_slow(Field *to, const Field *from)
Copy the value in "from" (assumed to be non-NULL) to "to", doing any required conversions in the proc...
Definition: field_conv.cc:791
bool is_blob(enum_field_types sql_type)
Definition: field.h:4672
const char * get_field_name_or_expression(THD *thd, const Field *field)
Definition: field.cc:10614
#define portable_sizeof_char_ptr
Definition: field.h:119
column_format_type
Definition: field.h:188
@ COLUMN_FORMAT_TYPE_DEFAULT
Definition: field.h:189
@ COLUMN_FORMAT_TYPE_FIXED
Definition: field.h:190
@ COLUMN_FORMAT_TYPE_DYNAMIC
Definition: field.h:191
type_conversion_status time_warning_to_type_conversion_status(const int warn)
Convert warnings returned from str_to_time() and str_to_datetime() to their corresponding type_conver...
Definition: field.h:312
type_conversion_status store_internal_with_error_check(Field_new_decimal *field, int conversion_err, my_decimal *value)
Definition: field.cc:3138
enum_field_types get_blob_type_from_length(size_t length)
Definition: field.cc:9254
bool real_type_with_now_as_default(enum_field_types type)
Tests if field real type can have "DEFAULT CURRENT_TIMESTAMP", i.e.
Definition: field.h:366
bool real_type_with_now_on_update(enum_field_types type)
Tests if field real type can have "ON UPDATE CURRENT_TIMESTAMP", i.e.
Definition: field.h:379
Derivation
For use.
Definition: field.h:176
@ DERIVATION_UNUSED
Definition: field.h:183
@ DERIVATION_COERCIBLE
Definition: field.h:180
@ DERIVATION_SYSCONST
Definition: field.h:181
@ DERIVATION_EXPLICIT
Definition: field.h:184
@ DERIVATION_NONE
Definition: field.h:177
@ DERIVATION_NUMERIC
Definition: field.h:179
@ DERIVATION_NULL
Definition: field.h:178
@ DERIVATION_IMPLICIT
Definition: field.h:182
File containing constants that can be used throughout the server.
constexpr const 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 int MAX_DATETIME_WIDTH
YYYY-MM-DD HH:MM:SS.
Definition: sql_const.h:76
Our own string classes, used pervasively throughout the executor.
Truncate_result
Definition: sql_truncate.cc:140
case opt name
Definition: sslopt-case.h:29
Definition: m_ctype.h:421
unsigned mbmaxlen
Definition: m_ctype.h:445
MY_CHARSET_HANDLER * cset
Definition: m_ctype.h:453
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: mysql_lex_string.h:40
size_t length
Definition: mysql_lex_string.h:42
Definition: mysql_lex_string.h:35
Structure to return status from str_to_datetime(), str_to_time(), int_to_datetime(),...
Definition: my_time.h:173
Definition: mysql_time.h:82
Definition: my_bitmap.h:43
size_t(* lengthsp)(const CHARSET_INFO *, const char *ptr, size_t length)
Given a pointer and a length in bytes, returns a new length in bytes where all trailing space charact...
Definition: m_ctype.h:372
void(* fill)(const CHARSET_INFO *, char *to, size_t len, int fill)
Definition: m_ctype.h:399
This structure is shared between different table objects.
Definition: table.h:731
Definition: table.h:1456
bool has_null_row() const
Definition: table.h:2228
bool is_nullable() const
Return whether table is nullable.
Definition: table.h:2130
Definition: typelib.h:35
A structure to store a decimal value together with its precision and number of decimals TODO: HCS-100...
Definition: protocol_local_v2.h:43
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
constexpr sql_mode_t MODE_INVALID_DATES
Definition: system_variables.h:148
constexpr sql_mode_t MODE_TIME_TRUNCATE_FRACTIONAL
Definition: system_variables.h:161
constexpr sql_mode_t MODE_NO_ZERO_IN_DATE
Definition: system_variables.h:146
constexpr sql_mode_t MODE_NO_ZERO_DATE
Definition: system_variables.h:147
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
Definition: dtoa.cc:595