MySQL 8.4.3
Source Code Documentation
|
#include "sql/field.h"
#include <float.h>
#include <stddef.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <optional>
#include "decimal.h"
#include "my_alloc.h"
#include "my_byteorder.h"
#include "my_compare.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_double2ulonglong.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_time_t.h"
#include "myisampack.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/int2str.h"
#include "mysql/strings/m_ctype.h"
#include "mysqld_error.h"
#include "scope_guard.h"
#include "sql-common/json_binary.h"
#include "sql-common/json_diff.h"
#include "sql-common/json_dom.h"
#include "sql-common/json_error_handler.h"
#include "sql-common/my_decimal.h"
#include "sql/create_field.h"
#include "sql/current_thd.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/types/table.h"
#include "sql/dd_table_share.h"
#include "sql/derror.h"
#include "sql/filesort.h"
#include "sql/gis/rtree_support.h"
#include "sql/gis/srid.h"
#include "sql/handler.h"
#include "sql/item.h"
#include "sql/item_json_func.h"
#include "sql/item_timefunc.h"
#include "sql/join_optimizer/bit_utils.h"
#include "sql/key.h"
#include "sql/log_event.h"
#include "sql/mysqld.h"
#include "sql/mysqld_cs.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/spatial.h"
#include "sql/sql_class.h"
#include "sql/sql_exception_handler.h"
#include "sql/sql_lex.h"
#include "sql/sql_time.h"
#include "sql/sql_tmp_table.h"
#include "sql/srs_fetcher.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/transaction_info.h"
#include "sql/tztime.h"
#include "string_with_len.h"
#include "template_utils.h"
#include "typelib.h"
Classes | |
struct | Check_field_param |
Namespaces | |
namespace | dd |
The version of the current data dictionary table definitions. | |
namespace | anonymous_namespace{field.cc} |
Function to compare two unsigned integers for their relative order. | |
Macros | |
#define | FLAGSTR(V, F) ((V) & (F) ? #F " " : "") |
#define | MAX_EXPONENT 1024 |
#define | DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER |
#define | LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128 |
#define | DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128 |
#define | BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) ((ulong)((1LL << std::min(arg, 4U) * 8) - 1LL)) |
#define | FIELDTYPE_TEAR_FROM (MYSQL_TYPE_BIT + 1) |
#define | FIELDTYPE_TEAR_TO (243 - 1) |
#define | FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO)) |
Functions | |
bool | anonymous_namespace{field.cc}::sql_type_prevents_inplace (const Field &from, const Create_field &to) |
Predicate to determine if a field type change prevents alter from being done inplace. More... | |
bool | anonymous_namespace{field.cc}::length_prevents_inplace (const Field &from, const Create_field &to) |
Predicate to determine if a length change prevents alter from being done inplace. More... | |
bool | anonymous_namespace{field.cc}::charset_prevents_inplace (const Field_str &from, const Create_field &to) |
Predicate to determine if a charset change prevents alter from being done inplace. More... | |
bool | anonymous_namespace{field.cc}::change_prevents_inplace (const Field_str &from, const Create_field &to) |
Predicate to determine if the difference between a Field and the new Create_field prevents alter from being done inplace. More... | |
int | field_type2index (enum_field_types field_type) |
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... | |
static Geometry::wkbType | geometry_type_to_wkb_type (Field::geometry_type t) |
Convert Field::geometry_type to the corresponding Geometry::wkbType. More... | |
static bool | test_if_important_data (const CHARSET_INFO *cs, const char *str, const char *strend) |
int | anonymous_namespace{field.cc}::compare (unsigned int a, unsigned int b) |
static void | push_numerical_conversion_warning (THD *thd, const char *str, uint length, const CHARSET_INFO *cs, const char *typestr, int error, const char *field_name="UNKNOWN", ulong row_num=0) |
Output a warning for erroneous conversion of strings to numerical values. More... | |
static void | set_decimal_warning (THD *thd, Field_new_decimal *field, int dec_error, my_decimal *dec_value, const char *from, size_t length, const CHARSET_INFO *charset_arg) |
Emits a warning for the decimal conversion error. More... | |
static size_t | field_well_formed_copy_nchars (const CHARSET_INFO *to_cs, char *to, size_t to_length, const CHARSET_INFO *from_cs, const char *from, size_t from_length, size_t nchars, const char **well_formed_error_pos, const char **cannot_convert_error_pos, const char **from_end_pos) |
Copy string with optional character set conversion. More... | |
static void | append_zerofill_and_unsigned (const Field_num *field, String *res) |
Appends the UNSIGNED and ZEROFILL attributes to a String if a Field_num has these attributes. More... | |
static void | integer_sql_type (const Field_num *field, const char *type_name, String *res) |
Writes an integer type specification to a string. More... | |
type_conversion_status | store_internal_with_error_check (Field_new_decimal *field, int err, my_decimal *value) |
static int | my_datetime_number_to_str (char *pos, longlong tmp) |
Convert a number in format YYMMDDhhmmss to string. More... | |
static type_conversion_status | datetime_store_internal (TABLE *table, ulonglong tmp, uchar *ptr) |
Store a DATETIME in a 8-byte integer to record. More... | |
static longlong | datetime_get_internal (TABLE *table, uchar *ptr) |
Read a DATETIME from record to a 8-byte integer. More... | |
static void | store_blob_length (uchar *i_ptr, uint i_packlength, uint32 i_number) |
static longlong | enum_val_int (const uchar *ptr, uint packlength, bool low_byte_first) |
static bool | compare_type_names (const CHARSET_INFO *charset, TYPELIB *t1, TYPELIB *t2) |
Compare the first t1::count type names. 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... | |
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... | |
Field * | make_field (MEM_ROOT *mem_root, 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... | |
static void | handle_int16 (uchar *to, const uchar *from, size_t max_length, bool low_byte_first_from, bool low_byte_first_to) |
static void | handle_int24 (uchar *to, const uchar *from, size_t max_length, bool low_byte_first_from, bool low_byte_first_to) |
static void | handle_int32 (uchar *to, const uchar *from, size_t max_length, bool low_byte_first_from, bool low_byte_first_to) |
static void | handle_int64 (uchar *to, const uchar *from, size_t max_length, bool low_byte_first_from, bool low_byte_first_to) |
Create_field * | generate_create_field (THD *thd, Item *source_item, TABLE *tmp_table) |
Generate a Create_field from an Item. More... | |
const char * | get_field_name_or_expression (THD *thd, const Field *field) |
Variables | |
const char | field_separator = ',' |
Static variables. More... | |
static enum_field_types | field_types_merge_rules [FIELDTYPE_NUM][FIELDTYPE_NUM] |
static Item_result | field_types_result_type [FIELDTYPE_NUM] |
#define BLOB_PACK_LENGTH_TO_MAX_LENGH | ( | arg | ) | ((ulong)((1LL << std::min(arg, 4U) * 8) - 1LL)) |
#define DECIMAL_TO_STRING_CONVERSION_BUFFER_SIZE 128 |
#define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE FLOATING_POINT_BUFFER |
#define FIELDTYPE_NUM (FIELDTYPE_TEAR_FROM + (255 - FIELDTYPE_TEAR_TO)) |
#define FIELDTYPE_TEAR_FROM (MYSQL_TYPE_BIT + 1) |
#define FIELDTYPE_TEAR_TO (243 - 1) |
#define FLAGSTR | ( | V, | |
F | |||
) | ((V) & (F) ? #F " " : "") |
#define LONGLONG_TO_STRING_CONVERSION_BUFFER_SIZE 128 |
#define MAX_EXPONENT 1024 |
Appends the UNSIGNED and ZEROFILL attributes to a String if a Field_num has these attributes.
field | the field with the attributes to append | |
[in,out] | res | the String to append to |
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 | ||
) |
|
static |
Compare the first t1::count type names.
Read a DATETIME from record to a 8-byte integer.
table | Table |
ptr | Where to read from |
An | integer in format YYYYMMDDhhmmss |
|
inlinestatic |
Store a DATETIME in a 8-byte integer to record.
table | Table |
tmp | The number, in YYYYMMDDhhmmss format |
ptr | Where to store to |
|
inline |
|
static |
Copy string with optional character set conversion.
This calls helper function well_formed_copy_nchars to copy string with optional character set conversion. Specially, it checks if the ASCII code point exceeds code range. If YES, it allows the input but raises a warning.
to_cs | Character set of "to" string |
to | Store result here |
to_length | Maximum length of "to" string |
from_cs | From character set |
from | Copy from here |
from_length | Length of from string |
nchars | Copy not more that nchars characters |
well_formed_error_pos | Return position when "from" is not well formed or NULL otherwise. |
cannot_convert_error_pos | Return position where a not convertible character met, or NULL otherwise. |
from_end_pos | Return position where scanning of "from" string stopped. |
length | of bytes copied to 'to' |
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. |
|
static |
Convert Field::geometry_type to the corresponding Geometry::wkbType.
t | The geometry_type to convert |
enum_field_types get_blob_type_from_length | ( | size_t | length | ) |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
Writes an integer type specification to a string.
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, |
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.
|
inlinestatic |
Convert a number in format YYMMDDhhmmss to string.
Straight coded to avoid problem with slow longlong arithmetic and sprintf.
[out] | pos | pointer to convert to. |
tmp | number with datetime value. |
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). |
|
static |
Output a warning for erroneous conversion of strings to numerical values.
For use with ER_TRUNCATED_WRONG_VALUE[_FOR_FIELD]
thd | THD object |
str | pointer to string that failed to be converted |
length | length of string |
cs | charset for string |
typestr | string describing type converted to |
error | error value to output |
field_name | (for *_FOR_FIELD) name of field |
row_num | (for *_FOR_FIELD) row number |
|
static |
Emits a warning for the decimal conversion error.
May modify dec_value if there was conversion overflow or bad number.
thd | Thread handler | |
field | Field to operate on | |
dec_error | decimal library return code (E_DEC_* see include/decimal.h) | |
[in,out] | dec_value | Decimal value returned by conversion function. |
from | Value converted from | |
length | Length of 'from' | |
charset_arg | Charset of 'from' |
type_conversion_status store_internal_with_error_check | ( | Field_new_decimal * | field, |
int | err, | ||
my_decimal * | value | ||
) |
|
static |
const char field_separator = ',' |
Static variables.
|
static |
|
static |