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