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