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