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