MySQL 8.4.3
Source Code Documentation
|
#include <assert.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <algorithm>
#include <optional>
#include "decimal.h"
#include "field_types.h"
#include "lex_string.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_bitmap.h"
#include "my_dbug.h"
#include "my_double2ulonglong.h"
#include "my_inttypes.h"
#include "my_time.h"
#include "mysql/binlog/event/export/binary_log_funcs.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysql_time.h"
#include "sql/dd/types/column.h"
#include "sql/field_common_properties.h"
#include "sql/gis/srid.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/table.h"
#include "sql_string.h"
#include "template_utils.h"
Go to the source code of this file.
Classes | |
class | Value_generator |
Used for storing information associated with generated column, default values generated from expression or check constraint expression. More... | |
class | Field |
class | Create_field_wrapper |
This class is a substitute for the Field classes during CREATE TABLE. More... | |
class | Field_num |
class | Field_str |
class | Field_longstr |
class | Field_real |
class | Field_decimal |
class | Field_new_decimal |
class | Field_tiny |
class | Field_short |
class | Field_medium |
class | Field_long |
class | Field_longlong |
class | Field_float |
class | Field_double |
class | Field_null |
class | Field_temporal |
class | Field_temporal_with_date |
Abstract class for types with date with optional time, with or without fractional part: DATE, DATETIME, DATETIME(N), TIMESTAMP, TIMESTAMP(N). More... | |
class | Field_temporal_with_date_and_time |
Abstract class for types with date and time, with or without fractional part: DATETIME, DATETIME(N), TIMESTAMP, TIMESTAMP(N). More... | |
class | Field_temporal_with_date_and_timef |
Abstract class for types with date and time, with fractional part: DATETIME, DATETIME(N), TIMESTAMP, TIMESTAMP(N). More... | |
class | Field_timestamp |
class | Field_timestampf |
class | Field_year |
class | Field_newdate |
class | Field_time_common |
Abstract class for TIME and TIME(N). More... | |
class | Field_time |
class | Field_timef |
class | Field_datetime |
class | Field_datetimef |
class | Field_string |
class | Field_varstring |
class | Field_blob |
class | Field_geom |
class | Field_json |
A field that stores a JSON value. More... | |
class | Field_typed_array |
Field that stores array of values of the same type. More... | |
class | Field_enum |
class | Field_set |
class | Field_bit |
class | Field_bit_as_char |
BIT field represented as chars for non-MyISAM tables. More... | |
class | Send_field |
class | Copy_field |
Macros | |
#define | portable_sizeof_char_ptr 8 |
#define | IS_EQUAL_NO 0 |
#define | IS_EQUAL_YES 1 |
#define | IS_EQUAL_PACK_LENGTH 2 |
#define | my_charset_numeric my_charset_latin1 |
#define | MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII |
#define | ASSERT_COLUMN_MARKED_FOR_READ |
#define | ASSERT_COLUMN_MARKED_FOR_WRITE |
Enumerations | |
enum | enum_check_fields : int { CHECK_FIELD_IGNORE = 0 , CHECK_FIELD_WARN , CHECK_FIELD_ERROR_FOR_NULL } |
enum | Derivation { DERIVATION_IGNORABLE = 6 , DERIVATION_NUMERIC = 5 , DERIVATION_COERCIBLE = 4 , DERIVATION_SYSCONST = 3 , DERIVATION_IMPLICIT = 2 , DERIVATION_NONE = 1 , DERIVATION_EXPLICIT = 0 } |
For use. More... | |
enum | column_format_type { COLUMN_FORMAT_TYPE_DEFAULT = 0 , COLUMN_FORMAT_TYPE_FIXED = 1 , COLUMN_FORMAT_TYPE_DYNAMIC = 2 } |
enum | type_conversion_status { TYPE_OK = 0 , TYPE_NOTE_TIME_TRUNCATED , TYPE_NOTE_TRUNCATED , TYPE_WARN_OUT_OF_RANGE , TYPE_WARN_TRUNCATED , TYPE_WARN_INVALID_STRING , TYPE_ERR_NULL_CONSTRAINT_VIOLATION , TYPE_ERR_BAD_VALUE , TYPE_ERR_OOM } |
Status when storing a value in a field or converting from one datatype to another. More... | |
enum | Value_generator_source : short { VGS_GENERATED_COLUMN = 0 , VGS_DEFAULT_EXPRESSION , VGS_CHECK_CONSTRAINT } |
Enum to indicate source for which value generator is used. More... | |
Functions | |
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. More... | |
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 process. More... | |
uint | get_enum_pack_length (int elements) |
uint | get_set_pack_length (int elements) |
type_conversion_status | decimal_err_to_type_conv_status (int dec_error) |
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_conversion_status codes. More... | |
bool | is_temporal_real_type (enum_field_types type) |
Tests if field real type is temporal, i.e. More... | |
bool | real_type_with_now_as_default (enum_field_types type) |
Tests if field real type can have "DEFAULT CURRENT_TIMESTAMP", i.e. More... | |
bool | real_type_with_now_on_update (enum_field_types type) |
Tests if field real type can have "ON UPDATE CURRENT_TIMESTAMP", i.e. More... | |
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->type(). More... | |
enum_field_types | blob_type_from_pack_length (uint pack_length) |
Return the appropriate MYSQL_TYPE_X_BLOB value based on the pack_length. More... | |
template<bool Is_big_endian> | |
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(). More... | |
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. More... | |
Field * | make_field (const Create_field &create_field, TABLE_SHARE *share, const char *field_name, size_t field_length, uchar *ptr, uchar *null_pos, size_t null_bit) |
Instantiates a Field object with the given name and record buffer values. More... | |
Field * | make_field (const Create_field &create_field, TABLE_SHARE *share, uchar *ptr, uchar *null_pos, size_t null_bit) |
Instantiates a Field object with the given record buffer values. More... | |
Field * | make_field (const Create_field &create_field, TABLE_SHARE *share) |
Instantiates a Field object without a record buffer. More... | |
enum_field_types | get_blob_type_from_length (size_t length) |
size_t | calc_pack_length (enum_field_types type, size_t length) |
size_t | calc_pack_length (dd::enum_column_types type, size_t char_length, size_t elements_count, bool treat_bit_as_char, uint numeric_scale, bool is_unsigned) |
Calculate the length of the in-memory representation of the column from information which can be retrieved from dd::Column or Ha_fk_column_type describing it. More... | |
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. More... | |
type_conversion_status | set_field_to_null (Field *field) |
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. More... | |
type_conversion_status | store_internal_with_error_check (Field_new_decimal *field, int conversion_err, my_decimal *value) |
Create_field * | generate_create_field (THD *thd, Item *source_item, TABLE *tmp_table) |
Generate a Create_field from an Item. More... | |
bool | is_blob (enum_field_types sql_type) |
const char * | get_field_name_or_expression (THD *thd, const Field *field) |
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, default value expression, a functional index or a check constraint. More... | |
#define ASSERT_COLUMN_MARKED_FOR_READ |
#define ASSERT_COLUMN_MARKED_FOR_WRITE |
#define IS_EQUAL_NO 0 |
#define IS_EQUAL_PACK_LENGTH 2 |
#define IS_EQUAL_YES 1 |
#define my_charset_numeric my_charset_latin1 |
#define MY_REPERTOIRE_NUMERIC MY_REPERTOIRE_ASCII |
#define portable_sizeof_char_ptr 8 |
enum column_format_type |
enum Derivation |
enum enum_check_fields : int |
Status when storing a value in a field or converting from one datatype to another.
The values should be listed in order of increasing seriousness so that if two type_conversion_status variables are compared, the bigger one is most serious.
enum Value_generator_source : short |
|
inline |
Return the appropriate MYSQL_TYPE_X_BLOB value based on the pack_length.
pack_length | pack_length for BLOB |
MYSQL_TYPE_X_BLOB | corresponding to pack_length. |
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.
TODO: Get rid of this function as its code is redundant with Field::key_length() code. However creation of Field object using make_field() just to call Field::key_length() is probably overkill.
size_t calc_pack_length | ( | dd::enum_column_types | type, |
size_t | char_length, | ||
size_t | elements_count, | ||
bool | treat_bit_as_char, | ||
uint | numeric_scale, | ||
bool | is_unsigned | ||
) |
Calculate the length of the in-memory representation of the column from information which can be retrieved from dd::Column or Ha_fk_column_type describing it.
This function calculates the amount of memory necessary to store values in the record buffer. It is used in cases when we want to calculate this value from the description of column in the form compatible with dd::Column without constructing full-blown Field object.
type | Column DD type. |
char_length | Column length as stored in DD. |
elements_count | Number of elements in column of ENUM/SET type. |
treat_bit_as_char | Indicates whether this BIT column is represented as char column internally. |
numeric_scale | Column numeric scale as stored in DD. |
is_unsigned | Column unsignedness. |
size_t calc_pack_length | ( | enum_field_types | type, |
size_t | length | ||
) |
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().
The format is characterized by the following:
The function template can be instantiated to copy from little or big endian values.
Is_big_endian | True if the source integer is big endian. |
to | Where to write the integer. |
to_length | Size in bytes of the destination buffer. |
from | Where to read the integer. |
from_length | Size in bytes of the source integer |
is_unsigned | True if the source integer is an unsigned value. |
|
inline |
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 process.
Note that you should only call this if fields_are_memcpyable() is false, since it does an actual conversion on the slow path (and it is not properly tested whether it gives the correct result in all cases if fields_are_memcpyable() is true).
You should never call this with to == from, as they are no-ops.
Check if one can copy from “from” to “to” with a simple memcpy(), with pack_length() as the length.
This is the case if the types of the two fields are the same and we don't have special copying rules for the type (e.g., blobs, which require allocation, or time functions that require checking for special SQL modes).
You should never call this with to == from, as such copies are no-ops and memcpy() has undefined behavior with overlapping memory areas.
Create_field * generate_create_field | ( | THD * | thd, |
Item * | source_item, | ||
TABLE * | tmp_table | ||
) |
Generate a Create_field from an Item.
This function generates a Create_field from an Item by first creating a temporary table Field from the Item, and then creating the Create_field from this Field (there is currently no way to go directly from Item to Create_field). It is used several places:
thd | Thread handler |
source_item | The item to generate a Create_field from |
tmp_table | A table object which is used to generate a temporary table field, as described above. This doesn't need to be an existing table. |
enum_field_types get_blob_type_from_length | ( | size_t | length | ) |
|
inline |
|
inline |
|
inline |
|
inline |
Tests if field real type is temporal, i.e.
represents all existing implementations of DATE, TIME, DATETIME or TIMESTAMP types in SQL.
type | Field real type, as returned by field->real_type() |
true | If field real type is temporal |
false | If field real type is not temporal |
Field * make_field | ( | const Create_field & | create_field, |
TABLE_SHARE * | share | ||
) |
Instantiates a Field object without a record buffer.
create_field | The column meta data. |
share | The table share object. |
Field * make_field | ( | const Create_field & | create_field, |
TABLE_SHARE * | share, | ||
const char * | field_name, | ||
size_t | field_length, | ||
uchar * | ptr, | ||
uchar * | null_pos, | ||
size_t | null_bit | ||
) |
Instantiates a Field object with the given name and record buffer values.
create_field | The column meta data. |
share | The table share object. |
field_name | Create_field::field_name is overridden with this value when instantiating the Field object. |
field_length | Create_field::length is overridden with this value when instantiating the Field object. |
ptr | The address of the data bytes. |
null_pos | The address of the null bytes. |
null_bit | The position of the column's null bit within the row's null bytes. |
Field * make_field | ( | const Create_field & | create_field, |
TABLE_SHARE * | share, | ||
uchar * | ptr, | ||
uchar * | null_pos, | ||
size_t | null_bit | ||
) |
Instantiates a Field object with the given record buffer values.
create_field | The column meta data. |
share | The table share object. |
ptr | The start of the record buffer. |
null_pos | The address of the null bytes. |
null_bit | The position of the column's null bit within the row's null bytes. |
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.
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, default value expression, a functional index or a check constraint.
Note that validation of the specific function is done later in procedures open_table_from_share and fix_value_generator_fields.
expression | the expression to check for validity |
name | used for error reporting |
source | Source of value generator(a generated column, a regular column with generated default value or a check constraint). |
|
inline |
Convert temporal real types as returned by field->real_type() to field type as returned by field->type().
real_type | Real type. |
Field | type. |
|
inline |
Tests if field real type can have "DEFAULT CURRENT_TIMESTAMP", i.e.
represents TIMESTAMP types in SQL.
type | Field type, as returned by field->real_type(). |
true | If field real type can have "DEFAULT CURRENT_TIMESTAMP". |
false | If field real type can not have "DEFAULT CURRENT_TIMESTAMP". |
|
inline |
Tests if field real type can have "ON UPDATE CURRENT_TIMESTAMP", i.e.
represents TIMESTAMP types in SQL.
type | Field type, as returned by field->real_type(). |
true | If field real type can have "ON UPDATE CURRENT_TIMESTAMP". |
false | If field real type can not have "ON UPDATE CURRENT_TIMESTAMP". |
type_conversion_status set_field_to_null | ( | Field * | field | ) |
The following piece of code is run for the case when a BLOB column that has value NULL is queried with GROUP BY NULL and the result is inserted into a some table's column declared having primitive type (e.g. INT) and NOT NULL.
For example, the following test case will hit this piece of code: CREATE TABLE t1 (a BLOB); CREATE TABLE t2 (a INT NOT NULL);
INSERT t1 VALUES (NULL); INSERT INTO t2(a) SELECT a FROM t1 GROUP BY NULL; <<== Hit here
In general, when set_field_to_null() is called a Field has to be either declared as NULL-able or be marked as temporary NULL-able. But in case of INSERT SELECT from a BLOB field and when GROUP BY NULL is specified the Field object for a destination column doesn't set neither NULL-able nor temporary NULL-able (see setup_copy_fields()).
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.
field | Field to update |
no_conversions | Set to 1 if we should return 1 if field can't take null values. If set to 0 we will do store the 'default value' if the field is a special field. If not we will give an error. |
0 | Field could take 0 or an automatic conversion was used |
-1 | Field could not take NULL and no conversion was used. If no_conversion was not set, an error message is printed |
type_conversion_status store_internal_with_error_check | ( | Field_new_decimal * | field, |
int | conversion_err, | ||
my_decimal * | value | ||
) |
|
inline |
Convert warnings returned from str_to_time() and str_to_datetime() to their corresponding type_conversion_status codes.