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