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