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