Field类用于描述表中的列或属性。Field是对列数据类型以及属性的定义。Field类是一个抽象类。Field类有许多的具体子类。几乎每种类型的列都有相对应的Field子类。
sql下的Field.h文件 ,其继承派生关系如下
Field基类->Field_Num类->Field_real类->Field_decimal类
->Field_float
->Field_double
->Field_new_decimal类
->Field_tiny类->Field_year
->Field_short类
->Field_medium类
->Field_long类
->Field_longlong
->Field_bit类->Field_bit_as_char
->Field_str类->Field_longstr类->Field_string
->Field_varstring
->Field_blob->Field_geom
->Field_json->Field_typed_array
->Field_null
->Field_enum->Field_set
->Field_temporal类->Field_temporal_with_date类->Field_temporal_with_date_and_time类->Field_temporal_with_date_and_timef->Field_timestampf
->Field_datetimef
->Field_timestamp
->Field_newdate
->Field_datetime
->Field_time_common->Field_time
->Field_timef
公共函数
Field (const Field &)=default
void operator= (Field &)=delete
//检查该字段是否标记为具有通用表达式以生成默认值
bool has_insert_default_general_value_expression () const
//检查该字段是否标记为具有日期时间值表达式以在插入时生成默认值。
bool has_insert_default_datetime_value_expression () const
//检查该字段是否标记为具有日期时间值表达式以在更新时生成默认值。
bool has_update_default_datetime_value_expression () const
uchar * get_null_ptr ()
virtual void set_field_length (uint32 length)
bool is_flag_set (unsigned flag) const
void set_flag (unsigned flag)
void clear_flag (unsigned flag)
uint32 all_flags () const
//字段时有符号的还是无符号的
virtual bool is_unsigned () const
bool is_gcol () const
bool is_virtual_gcol () const
//设置此字段的隐藏类型
void set_hidden (dd::Column::enum_hidden_type hidden)
dd::Column::enum_hidden_type hidden () const
bool is_hidden_from_user () const
//该字段是否具备函数索引
bool is_field_for_functional_index () const
virtual ~Field ()=default
void reset_warnings ()
//打开该字段的临时可空性
void set_tmp_nullable ()
//关闭该字段的临时为空性
void reset_tmp_nullable ()
//重置字段的临时NULL值。
void reset_tmp_null ()
//设置字段的临时null值
void set_tmp_null ()
bool is_tmp_nullable () const
bool is_tmp_null () const
virtual type_conversion_status store (const char *to, size_t length, const CHARSET_INFO *cs)=0
virtual type_conversion_status store (double nr)=0
virtual type_conversion_status store (longlong nr, bool unsigned_val)=0
//将时间值以打包longlong格式存储到字段中
virtual type_conversion_status store_packed (longlong nr)
virtual type_conversion_status store_decimal (const my_decimal *d)=0
//将具有给定十进制位数的MYSQL_TIME值存储到字段中。
virtual type_conversion_status store_time (MYSQL_TIME *ltime, uint8 dec_arg)
//当小数位数不重要或未知时,将MYSQL_TYPE值存储到字段中
type_conversion_status store_time (MYSQL_TIME *ltime)
type_conversion_status store (const char *to, size_t length, const CHARSET_INFO *cs, enum_check_fields check_level)
virtual double val_real () const =0
virtual longlong val_int () const =0
//以打包longlong格式返回TIME值
virtual longlong val_time_temporal () const
//以打包longlong格式返回DATE/DATETIME值
virtual longlong val_date_temporal () const
virtual longlong val_time_temporal_at_utc () const
virtual longlong val_date_temporal_at_utc () const
//根据字段类型返回TIME或DATE / DATETIME字段的“本机”打包longlong表示形式
longlong val_temporal_by_field_type () const
virtual my_decimal * val_decimal (my_decimal *) const =0
String * val_str (String *str) const
virtual String * val_str (String *, String *) const =0
//将字段值解释为整数,但将结果作为字符串返回。
String * val_int_as_str (String *val_buffer, bool unsigned_flag) const
virtual bool str_needs_quotes () const
virtual Item_result result_type () const =0
// 当它出现在数字上下文中时,返回字段的Item_result类型,例如:SELECT time_column + 1; SELECT SUM(time_column);
virtual Item_result numeric_context_result_type () const
virtual Item_result cmp_type () const
virtual Item_result cast_to_int_type () const
//检查生成的列的表达式是否相同。
bool gcol_expr_is_equal (const Create_field *field) const
virtual bool eq (const Field *field) const
virtual bool eq_def (const Field *field) const
virtual uint32 pack_length () const
virtual uint32 pack_length_in_rec () const
//检查字段大小是否与目标兼容
virtual bool compatible_field_size (uint metadata, Relay_log_info *, uint16, int *order) const
virtual uint pack_length_from_metadata (uint field_metadata) const
virtual uint row_pack_length () const
int save_field_metadata (uchar *first_byte)
virtual uint32 data_length (ptrdiff_t row_offset=0) const
//以压缩格式获取数据的最大大小。
virtual uint32 max_data_length () const
virtual type_conversion_status reset ()
//以struct timeval格式返回UTC组件。
virtual bool get_timestamp (struct timeval *tm, int *warnings) const
// 在字段中以timeval格式存储时间戳记值
virtual void store_timestamp (const timeval *)
virtual void set_default ()
//评估INSERT默认功能并将结果存储在字段中
void evaluate_insert_default_function ()
//评估UPDATE默认函数(如果存在),并将结果存储在记录缓冲区中
void evaluate_update_default_function ()
virtual bool binary () const
virtual bool zero_pack () const
virtual enum ha_base_keytype key_type () const
virtual uint32 key_length () const
virtual enum_field_types type () const =0
virtual enum_field_types real_type () const
virtual enum_field_types binlog_type () const
int cmp (const uchar *str) const
virtual int cmp_max (const uchar *a, const uchar *b, uint max_len) const
virtual int cmp (const uchar *, const uchar *) const =0
virtual int cmp_binary (const uchar *a, const uchar *b, uint32 max_length=~0L) const
virtual int cmp_offset (ptrdiff_t row_offset) const
virtual int cmp_binary_offset (ptrdiff_t row_offset) const
virtual int key_cmp (const uchar *a, const uchar *b) const
virtual int key_cmp (const uchar *str, uint length) const
virtual uint decimals () const
virtual bool is_text_key_type () const
virtual void sql_type (String &str) const =0
//检查整个表的行是否为NULL或字段的值为NULL
bool is_null (ptrdiff_t row_offset=0) const
//检查字段的值为NULL(临时还是实际)
bool is_real_null (ptrdiff_t row_offset=0) const
//检查此字段的值是否为NULL或参数指定的记录是否为此字段值NULL
bool is_null_in_record (const uchar *record) const
//设置字段的值为null
void set_null (ptrdiff_t row_offset=0)
//设置字段的值为not null
void set_notnull (ptrdiff_t row_offset=0)
//
type_conversion_status check_constraints (int mysql_errno)
Check NOT NULL constraint on the field after temporary nullability is disabled. More...
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 after BEFORE-trigger execution is finished. More...
bool is_nullable () const
uint null_offset (const uchar *record) const
uint null_offset () const
void set_null_ptr (uchar *p_null_ptr, uint p_null_bit)
//使用有关此Field对象表示的列的元数据填充Send_field对象
virtual void make_send_field (Send_field *send_field) const
//将当前值的副本写到记录缓冲区中,适合使用逐字节比较进行排序
virtual size_t make_sort_key (uchar *buff, size_t length) const =0
virtual bool optimize_range (uint idx, uint part) const
virtual bool can_be_compared_as_longlong () const
virtual void mem_free ()
virtual Field * new_field (MEM_ROOT *root, TABLE *new_table) const
Field * new_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
virtual Field * new_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
Field * new_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr) const
//对字段对象做浅拷贝
virtual Field * clone (MEM_ROOT *mem_root) const =0
void move_field (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg)
virtual void move_field_offset (ptrdiff_t ptr_diff)
virtual void get_image (uchar *buff, size_t length, const CHARSET_INFO *) const
virtual void set_image (const uchar *buff, size_t length, const CHARSET_INFO *)
virtual size_t get_key_image (uchar *buff, size_t length, imagetype type) const
virtual void set_key_image (const uchar *buff, size_t length)
longlong val_int_offset (ptrdiff_t row_offset)
longlong val_int (uchar *new_ptr)
String * val_str (String *str, uchar *new_ptr)
//使用与字段类型匹配的正确Protocol :: store *()函数通过协议发送此字段的值。
virtual bool send_to_protocol (Protocol *protocol) const
//将字段打包成适合存储和传输的格式
virtual uchar * pack (uchar *to, const uchar *from, size_t max_length) const
uchar * pack (uchar *to) const
//从行数据中解压缩字段。
virtual const uchar * unpack (uchar *to, const uchar *from, uint param_data)
const uchar * unpack (const uchar *from)
//此函数与pack()的功能相同,不同之处在于max_length并不表示输出中的字节数,而是输入的最大字段长度(必须精确地是field-> max_field_length())
virtual uchar * pack_with_metadata_bytes (uchar *to, const uchar *from, uint max_length) const
//以diff格式写入二进制日志的字段
virtual bool pack_diff (uchar **to, ulonglong value_options) const
virtual uint max_packed_col_length () const
uint offset (uchar *record) const
void copy_data (ptrdiff_t src_record_offset)
virtual bool get_date (MYSQL_TIME *ltime, my_time_flags_t fuzzydate) const
virtual bool get_time (MYSQL_TIME *ltime) const
virtual const CHARSET_INFO * charset () const
const CHARSET_INFO * charset_for_protocol () const
virtual const CHARSET_INFO * sort_charset () const
virtual bool has_charset () const
virtual bool match_collation_to_optimize_range () const
virtual enum Derivation derivation () const
virtual uint repertoire () const
virtual void set_derivation (enum Derivation)
//是否发出有关已保存到字段中的数据的警告或注释
bool set_warning (Sql_condition::enum_severity_level level, unsigned int code, int cut_increment)
//是否发出有关已保存到字段中的数据的警告或注释。
bool set_warning (Sql_condition::enum_severity_level level, uint code, int cut_increment, const char *view_db, const char *view_name)
//是否处理十进制库返回码,并发出溢出和截断警告
bool warn_if_overflow (int op_result)
virtual void init (TABLE *table_arg)
virtual uint32 max_display_length () const =0
//创建的字段是否与现有字段类型兼容。
virtual uint is_equal (const Create_field *new_field) const
//从十进制转换为longlong
longlong convert_decimal2longlong (const my_decimal *val, bool unsigned_flag, bool *has_overflow)
virtual uint32 char_length () const
virtual geometry_type get_geometry_type () const
void dbug_print () const
ha_storage_media field_storage_type () const
void set_storage_type (ha_storage_media storage_type_arg)
column_format_type column_format () const
void set_column_format (column_format_type column_format_arg)
virtual type_conversion_status validate_stored_val (THD *thd)
virtual void hash (ulong *nr, ulong *nr2) const
//获取MySQL整数和浮点类型的上限。
virtual ulonglong get_max_int_value () const
//返回指向记录缓冲区中实际数据的const指针
virtual const uchar * data_ptr () const
//返回指向字段在记录缓冲区中存储位置的const指针
const uchar * field_ptr () const
//返回指向字段在记录缓冲区中存储位置的指针
uchar * field_ptr ()
void set_field_ptr (uchar *ptr_arg)
//检查字符串字段是否为write_set的一部分。
virtual bool is_updatable () const
//考虑到索引扩展标志,检查字段是否为索引的一部分。
bool is_part_of_actual_key (THD *thd, uint cur_index, KEY *cur_index_info) const
//获取覆盖前缀键
Key_map get_covering_prefix_keys () const
//该字段是否为类型数组。
virtual bool is_array () const
//返回字段长度占用的字节数。
virtual uint32 get_length_bytes () const
//是否必须处理字段的旧值。
bool handle_old_value () const
//设置字段索引
virtual void set_field_index (uint16 fieldC++_index)
//返回字段索引
uint16 field_index () const
公共属性
TABLE * table
//指向原始数据库名称的指针,对于临时表仅是非NULL
const char * orig_db_name {nullptr}
//指向原始表名的指针,对于临时表仅非空
const char * orig_table_name {nullptr}
const char ** table_name
const char * field_name
LEX_CSTRING comment
Key_map key_start
//除前缀键外,包含此字段的键
Key_map part_of_key
//前缀关键字
Key_map part_of_prefixkey
Key_map part_of_sortkey
//包含此字段但存储引擎未扩展以包含主键列的所有键
Key_map part_of_key_not_extended
uint32 field_length
uchar null_bit
//标志的位图,指示默认情况下和/或更新时是否自动生成字段值,以及采用哪种方式。
uchar auto_flags
//如果为true,则从NULL值在create_tmp_field_from_item中创建此字段。
bool is_created_from_null_item
//如果此字段属于某个索引,则为true(与part_of_key不同,该索引可能仅具有前缀)。
bool m_indexed
LEX_CSTRING m_engine_attribute = EMPTY_CSTR
LEX_CSTRING m_secondary_engine_attribute = EMPTY_CSTR
Value_generator * gcol_info {nullptr}
bool stored_in_db
//包含用于生成默认值的表达式
Value_generator * m_default_val_expr {nullptr}
静态公共成员函数
//检查字段类型是否可以通过键部分索引
static bool type_can_have_key_part (enum_field_types)
//其返回类型可以在UNION结果中携带两个给定类型的值。
static enum_field_types field_type_merge (enum_field_types, enum_field_types)
static Item_result result_merge_type (enum_field_types)
私有属性
dd::Column::enum_hidden_type m_hidden
//NULL位存储在记录内的字节。
uchar * m_null_ptr
//标志:NOT-NULL字段是否可以为临时NULL
bool m_is_tmp_nullable
//这是具有以下语义的标志:
bool m_is_tmp_null
//设置m_is_tmp_null属性时的THD :: check_for_truncated_fields值
enum_check_fields m_check_for_truncated_fields_saved
uint32 flags {0}
uint16 m_field_indexl
unsigned int m_warnings_pushed