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