MySQL 9.1.0
Source Code Documentation
Field_blob Class Reference

#include <field.h>

Inheritance diagram for Field_blob:
[legend]

Public Member Functions

 Field_blob (uchar *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg, TABLE_SHARE *share, uint blob_pack_length, const CHARSET_INFO *cs)
 
 Field_blob (uint32 len_arg, bool is_nullable_arg, const char *field_name_arg, const CHARSET_INFO *cs, bool set_packlength)
 
 Field_blob (const Field_blob &field)
 Copy static information and reset dynamic information. More...
 
 Field_blob (uint32 packlength_arg)
 
enum_field_types type () const override
 
bool match_collation_to_optimize_range () const override
 
enum ha_base_keytype key_type () const override
 
type_conversion_status store (const char *to, size_t length, const CHARSET_INFO *charset) override
 
type_conversion_status store (double nr) override
 Store double value in Field_string or Field_varstring. More...
 
type_conversion_status store (longlong nr, bool unsigned_val) override
 
type_conversion_status store (const Field *from)
 
double val_real () const override
 
longlong val_int () const override
 
Stringval_str (String *, String *) const override
 
my_decimalval_decimal (my_decimal *) const override
 
int cmp_max (const uchar *, const uchar *, uint max_length) const final
 
int cmp (const uchar *a, const uchar *b) const final
 
int cmp (const uchar *a, uint32 a_length, const uchar *b, uint32 b_length) const
 
int cmp_binary (const uchar *a, const uchar *b, uint32 max_length=~0L) const override
 
int key_cmp (const uchar *, const uchar *) const override
 
int key_cmp (const uchar *str, uint length) const override
 
uint32 key_length () const override
 
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 comparison. More...
 
size_t make_sort_key (uchar *to, size_t length, size_t trunc_pos) const final
 Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comparison. More...
 
uint32 pack_length () const final
 
uint32 pack_length_no_ptr () const
 Return the packed length without the pointer size added. More...
 
uint row_pack_length () const final
 
uint32 max_data_length () const override
 Get the maximum size of the data in packed format. More...
 
size_t get_field_buffer_size ()
 
void store_length (uchar *i_ptr, uint i_packlength, uint32 i_number)
 
void store_length (uint32 number)
 
uint32 data_length (ptrdiff_t row_offset=0) const final
 
uint32 get_length (ptrdiff_t row_offset=0) const
 
uint32 get_length (const uchar *ptr, uint packlength) const
 
uint32 get_length (const uchar *ptr_arg) const
 
const ucharget_blob_data () const
 Get a const pointer to the BLOB data of this field. More...
 
ucharget_blob_data (ptrdiff_t row_offset=0)
 Get a non-const pointer to the BLOB data of this field. More...
 
const uchardata_ptr () const final
 Get a const pointer to the BLOB data of this field. More...
 
void set_ptr (const uchar *length, const uchar *data)
 
void set_ptr_offset (ptrdiff_t ptr_diff, uint32 length, const uchar *data)
 
void set_ptr (uint32 length, const uchar *data)
 
size_t get_key_image (uchar *buff, size_t length, imagetype type) const override
 
void set_key_image (const uchar *buff, size_t length) final
 
void sql_type (String &str) const override
 
bool copy ()
 
Field_blobclone (MEM_ROOT *mem_root) const override
 Makes a shallow copy of the Field object. More...
 
ucharpack (uchar *to, const uchar *from, size_t max_length) const final
 Pack the field into a format suitable for storage and transfer. More...
 
ucharpack_with_metadata_bytes (uchar *to, const uchar *from, uint max_length) const final
 This function does the same thing as pack(), except for the difference that max_length does not mean the number of bytes in the output, but the maximum field length from the input (which must be exactly field->max_field_length()). More...
 
const ucharunpack (uchar *, const uchar *from, uint param_data) final
 Unpack a blob field from row data. More...
 
uint max_packed_col_length () const final
 This is a wrapper around pack_length() used by filesort() to determine how many bytes we need for packing "addon fields". More...
 
void mem_free () final
 
bool has_charset () const override
 
uint32 max_display_length () const final
 maximum possible display length for blob. More...
 
uint32 char_length () const override
 maximum possible character length for blob. More...
 
bool copy_blob_value (MEM_ROOT *mem_root)
 This function creates a separate copy of blob value. More...
 
uint is_equal (const Create_field *new_field) const override
 Whether a field being created is type-compatible with an existing one. More...
 
bool is_text_key_type () const final
 
void set_keep_old_value (bool old_value_flag)
 Mark that the BLOB stored in value should be copied before updating it. More...
 
void keep_old_value ()
 Save the current BLOB value to avoid that it gets overwritten. More...
 
void store_in_allocated_space (const char *from, uint32 length)
 Use to store the blob value into an allocated space. More...
 
bool backup_blob_field ()
 Backup data stored in 'value' into the backup_value. More...
 
void restore_blob_backup ()
 Restore backup value. More...
 
- Public Member Functions inherited from Field_longstr
 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)
 
type_conversion_status store_decimal (const my_decimal *d) override
 Decimal representation of Field_str. More...
 
bool is_updatable () const final
 Checks whether a string field is part of write_set. More...
 
- Public Member Functions inherited from Field_str
 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)
 
Item_result result_type () const override
 
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 + 1; SELECT SUM(time_column); Examples: More...
 
uint decimals () const override
 
void make_send_field (Send_field *field) const override
 Populates a Send_field object with metadata about the column represented by this Field object. More...
 
uint repertoire () const final
 
const CHARSET_INFOcharset () const override
 
void set_charset (const CHARSET_INFO *charset_arg)
 
void set_field_length (uint32 length) final
 
enum Derivation derivation () const final
 
void set_derivation (enum Derivation derivation_arg) final
 
bool binary () const override
 
bool str_needs_quotes () const final
 
void add_to_cost (CostOfItem *cost) const override
 Update '*cost' with the fact that this Field is accessed. More...
 
- Public Member Functions inherited from Field
 Field (const Field &)=default
 
void operator= (Field &)=delete
 
bool has_insert_default_general_value_expression () const
 Checks if the field is marked as having a general expression to generate default values. More...
 
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 inserts. More...
 
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 updates. More...
 
bool has_insert_default_constant_expression () const
 Checks if the field is marked as having a constant expression to generate default values. More...
 
ucharget_null_ptr ()
 
bool is_flag_set (unsigned flag) const
 
void set_flag (unsigned flag)
 
void clear_flag (unsigned flag)
 
uint32 all_flags () const
 
virtual bool is_wrapper_field () const
 If true, it's a Create_field_wrapper (a sub-class of Field used during CREATE/ALTER that we mustn't cast to other sub-classes of Field that aren't on a direct path of inheritance, e.g. More...
 
virtual bool is_unsigned () const
 Whether the field is signed or not. More...
 
bool is_gcol () const
 
bool is_virtual_gcol () const
 
void set_hidden (dd::Column::enum_hidden_type hidden)
 Sets the hidden type for this field. More...
 
dd::Column::enum_hidden_type hidden () const
 
bool is_hidden () const
 
bool is_hidden_by_system () const
 
bool is_hidden_by_user () const
 
bool is_field_for_functional_index () const
 
 Field (uchar *ptr_arg, uint32 length_arg, uchar *null_ptr_arg, uchar null_bit_arg, uchar auto_flags_arg, const char *field_name_arg)
 This is used as a table name when the table structure is not set up. More...
 
virtual ~Field ()=default
 
void reset_warnings ()
 
void set_tmp_nullable ()
 Turn on temporary nullability for the field. More...
 
void reset_tmp_nullable ()
 Turn off temporary nullability for the field. More...
 
void reset_tmp_null ()
 Reset temporary NULL value for field. More...
 
void set_tmp_null ()
 Set field to temporary value NULL. More...
 
bool is_tmp_nullable () const
 
bool is_tmp_null () const
 
virtual type_conversion_status store_packed (longlong nr)
 Store a temporal value in packed longlong format into a field. More...
 
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. More...
 
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 know. More...
 
type_conversion_status store (const char *to, size_t length, const CHARSET_INFO *cs, enum_check_fields check_level)
 
virtual longlong val_time_temporal () const
 Returns TIME value in packed longlong format. More...
 
virtual longlong val_date_temporal () const
 Returns DATE/DATETIME value in packed longlong format. More...
 
virtual longlong val_time_temporal_at_utc () const
 
virtual longlong val_date_temporal_at_utc () const
 
longlong val_temporal_by_field_type () const
 Returns "native" packed longlong representation of a TIME or DATE/DATETIME field depending on field type. More...
 
Stringval_str (String *str) const
 
Stringval_int_as_str (String *val_buffer, bool unsigned_flag) const
 Interpret field value as an integer but return the result as a string. More...
 
virtual Item_result cmp_type () const
 
virtual Item_result cast_to_int_type () const
 
bool gcol_expr_is_equal (const Create_field *field) const
 Check whether generated columns' expressions are the same. More...
 
virtual bool eq (const Field *field) const
 
virtual bool eq_def (const Field *field) const
 
virtual uint32 pack_length_in_rec () const
 
virtual bool compatible_field_size (uint metadata, Relay_log_info *, uint16, int *order) const
 Check to see if field size is compatible with destination. More...
 
virtual uint pack_length_from_metadata (uint field_metadata) const
 
int save_field_metadata (uchar *first_byte)
 
virtual type_conversion_status reset ()
 
virtual bool get_timestamp (my_timeval *tm, int *warnings) const
 Returns a UTC component in struct timeval format. More...
 
virtual void store_timestamp (const my_timeval *)
 Stores a timestamp value in timeval format in a field. More...
 
virtual void set_default ()
 
void evaluate_insert_default_function ()
 Evaluates the INSERT default function and stores the result in the field. More...
 
void evaluate_update_default_function ()
 Evaluates the UPDATE default function, if one exists, and stores the result in the record buffer. More...
 
virtual bool zero_pack () const
 
virtual enum_field_types real_type () const
 
virtual enum_field_types binlog_type () const
 
int cmp (const uchar *str) const
 
virtual int cmp_offset (ptrdiff_t row_offset) const
 
virtual int cmp_binary_offset (ptrdiff_t row_offset) const
 
bool is_null (ptrdiff_t row_offset=0) const
 Check whether the full table's row is NULL or the Field has value NULL. More...
 
bool is_real_null (ptrdiff_t row_offset=0) const
 Check whether the Field has value NULL (temporary or actual). More...
 
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. More...
 
void set_null (ptrdiff_t row_offset=0)
 Set field to value NULL. More...
 
void set_notnull (ptrdiff_t row_offset=0)
 Set field to value NOT NULL. More...
 
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)
 
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. More...
 
virtual bool can_be_compared_as_longlong () const
 
virtual Fieldnew_field (MEM_ROOT *root, TABLE *new_table) const
 
Fieldnew_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
 
virtual Fieldnew_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr, uchar *new_null_ptr, uint new_null_bit) const
 
Fieldnew_key_field (MEM_ROOT *root, TABLE *new_table, uchar *new_ptr) const
 
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 *)
 
longlong val_int_offset (ptrdiff_t row_offset)
 
longlong val_int (uchar *new_ptr)
 
Stringval_str (String *str, uchar *new_ptr)
 
virtual bool send_to_protocol (Protocol *protocol) const
 Send the value of this field over the protocol using the correct Protocol::store*() function which matches the type of the field. More...
 
ucharpack (uchar *to) const
 
const ucharunpack (const uchar *from)
 
virtual bool pack_diff (uchar **to, ulonglong value_options) const
 Write the field for the binary log in diff format. More...
 
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
 
const CHARSET_INFOcharset_for_protocol () const
 
virtual const CHARSET_INFOsort_charset () const
 
bool set_warning (Sql_condition::enum_severity_level level, unsigned int code, int cut_increment)
 Produce warning or note about data saved into field. More...
 
bool set_warning (Sql_condition::enum_severity_level level, uint code, int cut_increment, const char *view_db, const char *view_name)
 Produce warning or note about data saved into field. More...
 
bool warn_if_overflow (int op_result)
 Process decimal library return codes and issue warnings for overflow and truncation. More...
 
virtual void init (TABLE *table_arg)
 
longlong convert_decimal2longlong (const my_decimal *val, bool unsigned_flag, bool *has_overflow)
 Conversion from decimal to longlong. More...
 
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
 
virtual ulonglong get_max_int_value () const
 Get the upper limit of the MySQL integral and floating-point type. More...
 
const ucharfield_ptr () const
 Return a const pointer to where the field is stored in the record buffer. More...
 
ucharfield_ptr ()
 Return a pointer to where the field is stored in the record buffer. More...
 
void set_field_ptr (uchar *ptr_arg)
 
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. More...
 
Key_map get_covering_prefix_keys () const
 Get covering prefix keys. More...
 
virtual bool is_array () const
 Whether the field is a typed array. More...
 
virtual uint32 get_length_bytes () const
 Return number of bytes the field's length takes. More...
 
bool handle_old_value () const
 Whether field's old valued have to be handled. More...
 
virtual void set_field_index (uint16 field_index)
 Sets field index. More...
 
uint16 field_index () const
 Returns field index. More...
 

Protected Member Functions

void store_ptr_and_length (const char *from, uint32 length)
 Store ptr and length. More...
 
- Protected Member Functions inherited from Field_longstr
type_conversion_status check_string_copy_error (const char *well_formed_error_pos, const char *cannot_convert_error_pos, const char *from_end_pos, const char *end, bool count_spaces, const CHARSET_INFO *from_cs, const CHARSET_INFO *to_cs)
 Report "not well formed" or "cannot convert" error after storing a character string info a field. More...
 
- Protected Member Functions inherited from Field
ucharpack_int16 (uchar *to, const uchar *from, size_t max_length) const
 
const ucharunpack_int16 (uchar *to, const uchar *from) const
 
ucharpack_int24 (uchar *to, const uchar *from, size_t max_length) const
 
const ucharunpack_int24 (uchar *to, const uchar *from) const
 
ucharpack_int32 (uchar *to, const uchar *from, size_t max_length) const
 
const ucharunpack_int32 (uchar *to, const uchar *from) const
 
ucharpack_int64 (uchar *to, const uchar *from, size_t max_length) const
 
const ucharunpack_int64 (uchar *to, const uchar *from) const
 

Static Protected Member Functions

static ucharget_blob_data (const uchar *position)
 Get the BLOB data pointer stored at the specified position in the record buffer. More...
 

Protected Attributes

uint packlength
 The number of bytes used to represent the length of the blob. More...
 
String value
 The 'value'-object is a cache fronting the storage engine. More...
 
- Protected Attributes inherited from Field_str
const CHARSET_INFOfield_charset
 
enum Derivation field_derivation
 
- Protected Attributes inherited from Field
ucharptr
 Holds the position to the field in record. More...
 

Private Member Functions

virtual type_conversion_status store_internal (const char *from, size_t length, const CHARSET_INFO *cs)
 
type_conversion_status store_to_mem (const char *from, size_t length, const CHARSET_INFO *cs, size_t max_length, Blob_mem_storage *)
 Copy value to memory storage. More...
 
int do_save_field_metadata (uchar *first_byte) const override
 Save the field metadata for blob fields. More...
 

Private Attributes

String old_value
 In order to support update of virtual generated columns of blob type, we need to allocate the space blob needs on server for old_row and new_row respectively. More...
 
bool m_keep_old_value
 Whether we need to move the content of 'value' to 'old_value' before updating the BLOB stored in 'value'. More...
 
String m_blob_backup
 Backup String for table's blob fields. More...
 
bool m_uses_backup {false}
 Whether the field uses table's backup value storage. More...
 

Additional Inherited Members

- Public Types inherited from Field
enum  enum_auto_flags {
  NONE = 0 , NEXT_NUMBER = 1 , DEFAULT_NOW = 2 , ON_UPDATE_NOW = 4 ,
  GENERATED_FROM_EXPRESSION = 8
}
 Flags for Field::auto_flags / Create_field::auto_flags bitmaps. More...
 
enum  geometry_type {
  GEOM_GEOMETRY = 0 , GEOM_POINT = 1 , GEOM_LINESTRING = 2 , GEOM_POLYGON = 3 ,
  GEOM_MULTIPOINT = 4 , GEOM_MULTILINESTRING = 5 , GEOM_MULTIPOLYGON = 6 , GEOM_GEOMETRYCOLLECTION = 7
}
 
enum  imagetype { itRAW , itMBR }
 
- Static Public Member Functions inherited from Field
static bool type_can_have_key_part (enum_field_types)
 Check whether a field type can be partially indexed by a key. More...
 
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. More...
 
static Item_result result_merge_type (enum_field_types)
 Detect Item_result by given field type of UNION merge result. More...
 
- Public Attributes inherited from Field_str
uint32 char_length_cache
 
- Public Attributes inherited from Field
TABLEtable
 Pointer to TABLE object that owns this field. More...
 
const char * orig_db_name {nullptr}
 Pointer to original database name, only non-NULL for a temporary table. More...
 
const char * orig_table_name {nullptr}
 Pointer to original table name, only non-NULL for a temporary table. More...
 
const char ** table_name
 
const char * field_name
 
LEX_CSTRING comment
 
Key_map key_start
 
Key_map part_of_key
 Keys that includes this field except of prefix keys. More...
 
Key_map part_of_prefixkey
 Prefix keys. More...
 
Key_map part_of_sortkey
 
Key_map part_of_key_not_extended
 All keys that include this field, but not extended by the storage engine to include primary key columns. More...
 
uint32 field_length
 
uchar null_bit
 
uchar auto_flags
 Bitmap of flags indicating if field value is auto-generated by default and/or on update, and in which way. More...
 
bool is_created_from_null_item
 If true, this field was created in create_tmp_field_from_item from a NULL value. More...
 
bool m_indexed
 True if this field belongs to some index (unlike part_of_key, the index might have only a prefix). More...
 
LEX_CSTRING m_engine_attribute = EMPTY_CSTR
 
LEX_CSTRING m_secondary_engine_attribute = EMPTY_CSTR
 
Value_generatorgcol_info {nullptr}
 
bool stored_in_db
 Indication that the field is physically stored in tables rather than just generated on SQL queries. More...
 
Value_generatorm_default_val_expr {nullptr}
 Holds the expression to be used to generate default values. More...
 
- Static Public Attributes inherited from Field
static constexpr size_t MAX_VARCHAR_WIDTH {65535}
 
static constexpr size_t MAX_TINY_BLOB_WIDTH {255}
 
static constexpr size_t MAX_SHORT_BLOB_WIDTH {65535}
 
static constexpr size_t MAX_MEDIUM_BLOB_WIDTH {16777215}
 
static constexpr size_t MAX_LONG_BLOB_WIDTH {4294967295}
 
- Static Protected Attributes inherited from Field
static uchar dummy_null_buffer = ' '
 

Constructor & Destructor Documentation

◆ Field_blob() [1/4]

Field_blob::Field_blob ( uchar ptr_arg,
uchar null_ptr_arg,
uchar  null_bit_arg,
uchar  auto_flags_arg,
const char *  field_name_arg,
TABLE_SHARE share,
uint  blob_pack_length,
const CHARSET_INFO cs 
)

◆ Field_blob() [2/4]

Field_blob::Field_blob ( uint32  len_arg,
bool  is_nullable_arg,
const char *  field_name_arg,
const CHARSET_INFO cs,
bool  set_packlength 
)
inline

◆ Field_blob() [3/4]

Field_blob::Field_blob ( const Field_blob field)
inline

Copy static information and reset dynamic information.

◆ Field_blob() [4/4]

Field_blob::Field_blob ( uint32  packlength_arg)
explicit

Member Function Documentation

◆ backup_blob_field()

bool Field_blob::backup_blob_field ( )

Backup data stored in 'value' into the backup_value.

See also
Field_blob::backup_value
Returns
true if backup fails false otherwise

◆ char_length()

uint32 Field_blob::char_length ( ) const
overridevirtual

maximum possible character length for blob.

This method is used in Item_field::set_field to calculate max_length for Item.

For example: CREATE TABLE t2 SELECT CONCAT(tinyblob_utf8_column) FROM t1; must create a "VARCHAR(255) CHARACTER SET utf8" column.

Returns
length

Reimplemented from Field.

Reimplemented in Field_vector, and Field_typed_array.

◆ clone()

Field_blob * Field_blob::clone ( MEM_ROOT mem_root) const
inlineoverridevirtual

Makes a shallow copy of the Field object.

Note
This member function must be overridden in all concrete subclasses. Several of the Field subclasses are concrete even though they are not leaf classes, so the compiler will not always catch this.
Parameters
mem_rootMEM_ROOT to use for memory allocation.
Return values
NULLIf memory allocation failed.

Implements Field.

Reimplemented in Field_geom, Field_vector, Field_json, and Field_typed_array.

◆ cmp() [1/2]

int Field_blob::cmp ( const uchar a,
const uchar b 
) const
inlinefinalvirtual

Implements Field.

◆ cmp() [2/2]

int Field_blob::cmp ( const uchar a,
uint32  a_length,
const uchar b,
uint32  b_length 
) const

◆ cmp_binary()

int Field_blob::cmp_binary ( const uchar a,
const uchar b,
uint32  max_length = ~0L 
) const
overridevirtual

Reimplemented from Field.

Reimplemented in Field_json.

◆ cmp_max()

int Field_blob::cmp_max ( const uchar a_ptr,
const uchar b_ptr,
uint  max_length 
) const
finalvirtual

Reimplemented from Field.

◆ copy()

bool Field_blob::copy ( )

◆ copy_blob_value()

bool Field_blob::copy_blob_value ( MEM_ROOT mem_root)

This function creates a separate copy of blob value.

Parameters
[in]mem_rootmem_root that is used to allocate memory for 'copy_of_value'.
Returns
- Can fail if we are out of memory.
Return values
falseSuccess
trueFailure

◆ data_length()

uint32 Field_blob::data_length ( ptrdiff_t  row_offset = 0) const
inlinefinalvirtual

Reimplemented from Field.

◆ data_ptr()

const uchar * Field_blob::data_ptr ( ) const
inlinefinalvirtual

Get a const pointer to the BLOB data of this field.

Reimplemented from Field.

◆ do_save_field_metadata()

int Field_blob::do_save_field_metadata ( uchar metadata_ptr) const
overrideprivatevirtual

Save the field metadata for blob fields.

Saves the pack length in the first byte of the field metadata array at index of *metadata_ptr.

Parameters
metadata_ptrFirst byte of field metadata
Returns
number of bytes written to metadata_ptr

Reimplemented from Field.

Reimplemented in Field_typed_array.

◆ get_blob_data() [1/3]

const uchar * Field_blob::get_blob_data ( ) const
inline

Get a const pointer to the BLOB data of this field.

◆ get_blob_data() [2/3]

static uchar * Field_blob::get_blob_data ( const uchar position)
inlinestaticprotected

Get the BLOB data pointer stored at the specified position in the record buffer.

◆ get_blob_data() [3/3]

uchar * Field_blob::get_blob_data ( ptrdiff_t  row_offset = 0)
inline

Get a non-const pointer to the BLOB data of this field.

◆ get_field_buffer_size()

size_t Field_blob::get_field_buffer_size ( )
inline

◆ get_key_image()

size_t Field_blob::get_key_image ( uchar buff,
size_t  length,
imagetype  type 
) const
overridevirtual

Reimplemented from Field.

Reimplemented in Field_typed_array.

◆ get_length() [1/3]

uint32 Field_blob::get_length ( const uchar ptr,
uint  packlength 
) const

◆ get_length() [2/3]

uint32 Field_blob::get_length ( const uchar ptr_arg) const

◆ get_length() [3/3]

uint32 Field_blob::get_length ( ptrdiff_t  row_offset = 0) const

◆ has_charset()

bool Field_blob::has_charset ( ) const
inlineoverridevirtual

Reimplemented from Field.

Reimplemented in Field_json.

◆ is_equal()

uint Field_blob::is_equal ( const Create_field new_field) const
overridevirtual

Whether a field being created is type-compatible with an existing one.

Used by the ALTER TABLE code to evaluate whether the new definition of a table is compatible with the old definition so that it can determine if data needs to be copied over (table data change). Constraints and generation clause (default value, generation expression) are not checked by this function.

Parameters
new_fieldnew field definition from alter.
Return values
IS_EQUAL_YESif there is no change.
IS_EQUAL_PACK_LENGTHif the data are unchanged, but the length requirements have changed
IS_EQUAL_NOif there is an incompatible change requiring copy.

Reimplemented from Field_str.

Reimplemented in Field_geom, Field_json, and Field_vector.

◆ is_text_key_type()

bool Field_blob::is_text_key_type ( ) const
inlinefinalvirtual

Reimplemented from Field.

◆ keep_old_value()

void Field_blob::keep_old_value ( )
inline

Save the current BLOB value to avoid that it gets overwritten.

This is used when updating virtual generated columns that are BLOBs. Some storage engines require that we have both the old and new BLOB value for virtual generated columns that are indexed in order for the storage engine to be able to maintain the index. This function will transfer the buffer storing the current BLOB value from 'value' to 'old_value'. This avoids that the current BLOB value is over-written when the new BLOB value is saved into this field.

The reason this requires special handling when updating/deleting virtual columns of BLOB type is that the BLOB value is not known to the storage engine. For stored columns, the "old" BLOB value is read by the storage engine, Field_blob is made to point to the engine's internal buffer; Field_blob's internal buffer (Field_blob::value) isn't used and remains available to store the "new" value. For virtual generated columns, the "old" value is written directly into Field_blob::value when reading the record to be updated/deleted. This is done in update_generated_read_fields(). Since, in this case, the "old" value already occupies the place to store the "new" value, we must call this function before we write the "new" value into Field_blob::value object so that the "old" value does not get over-written. The table->record[1] buffer will have a pointer that points to the memory buffer inside old_value. The storage engine will use table->record[1] to read the old value for the BLOB and use table->record[0] to read the new value.

This function must be called before we store the new BLOB value in this field object.

◆ key_cmp() [1/2]

int Field_blob::key_cmp ( const uchar a,
const uchar b 
) const
overridevirtual

Reimplemented from Field.

Reimplemented in Field_typed_array.

◆ key_cmp() [2/2]

int Field_blob::key_cmp ( const uchar str,
uint  length 
) const
overridevirtual

Reimplemented from Field.

Reimplemented in Field_typed_array.

◆ key_length()

uint32 Field_blob::key_length ( ) const
inlineoverridevirtual

Reimplemented from Field.

Reimplemented in Field_typed_array.

◆ key_type()

enum ha_base_keytype Field_blob::key_type ( ) const
inlineoverridevirtual

Reimplemented from Field.

Reimplemented in Field_geom.

◆ make_sort_key() [1/2]

size_t Field_blob::make_sort_key ( uchar buff,
size_t  length 
) const
overridevirtual

Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comparison.

Integers are always in big-endian regardless of hardware architecture. At most length bytes are written into the buffer.

Parameters
buffThe buffer, assumed to be at least length bytes.
lengthNumber of bytes to write.
Return values
Thenumber of bytes actually written.
Note
This is now only used by replication; filesort makes its own sort keys based off of Items, not Fields.

Implements Field.

Reimplemented in Field_json, Field_typed_array, Field_json, Field_typed_array, and Field_typed_array.

◆ make_sort_key() [2/2]

size_t Field_blob::make_sort_key ( uchar buff,
size_t  length,
size_t  trunc_pos 
) const
finalvirtual

Writes a copy of the current value in the record buffer, suitable for sorting using byte-by-byte comparison.

Integers are always in big-endian regardless of hardware architecture. At most length bytes are written into the buffer. Field_string, Field_varstring and Field_blob classes are truncated after pos number of characters.

Parameters
buffThe buffer, assumed to be at least length bytes.
lengthNumber of bytes to write.
trunc_posNumber of characters which should be included before truncation.
Return values
Thenumber of bytes actually written.
Note
This is now only used by replication; filesort makes its own sort keys based off of Items, not Fields.

Reimplemented from Field.

Reimplemented in Field_json, and Field_typed_array.

◆ match_collation_to_optimize_range()

bool Field_blob::match_collation_to_optimize_range ( ) const
inlineoverridevirtual

Reimplemented from Field.

Reimplemented in Field_geom, and Field_typed_array.

◆ max_data_length()

uint32 Field_blob::max_data_length ( ) const
inlineoverridevirtual

Get the maximum size of the data in packed format.

Returns
Maximum data length of the field when packed using the Field::pack() function.

Reimplemented from Field_longstr.

Reimplemented in Field_vector.

◆ max_display_length()

uint32 Field_blob::max_display_length ( ) const
finalvirtual

maximum possible display length for blob.

Returns
length

Reimplemented from Field_str.

◆ max_packed_col_length()

uint Field_blob::max_packed_col_length ( ) const
finalvirtual

This is a wrapper around pack_length() used by filesort() to determine how many bytes we need for packing "addon fields".

Returns
maximum size of a row when stored in the filesort buffer.

Reimplemented from Field.

◆ mem_free()

void Field_blob::mem_free ( void  )
inlinefinalvirtual

Reimplemented from Field.

◆ pack()

uchar * Field_blob::pack ( uchar to,
const uchar from,
size_t  max_length 
) const
finalvirtual

Pack the field into a format suitable for storage and transfer.

To implement packing functionality, only the virtual function should be overridden. The other functions are just convenience functions and hence should not be overridden.

The actual format is opaque and will vary between types of Field (it is meant to be unpacked by unpack(), but be aware that it is used among others in the replication log, so you cannot change it without incurring a format break.

Note
The default implementation just copies the raw bytes of the record into the destination, but never more than max_length characters.
Parameters
toPointer to memory area where representation of field should be put.
fromPointer to memory area where record representation of field is stored, typically field->field_ptr().
max_lengthAvailable space in “to”, in bytes. pack() will not write more bytes than this; if the field is too short, the contents are not unpackable by unpack(). (It is nominally supposed to be a prefix of what would have been written with a full buffer, ie., the same as packing and then truncating the output, but not all Field classes follow this.)
Returns
The byte after the last byte in “to” written to. If the return value is equal to (to + max_length), it could either be that the value fit exactly, or that the buffer was too small; you cannot distinguish between the two cases based on the return value alone.

Reimplemented from Field.

◆ pack_length()

uint32 Field_blob::pack_length ( ) const
inlinefinalvirtual

Reimplemented from Field.

◆ pack_length_no_ptr()

uint32 Field_blob::pack_length_no_ptr ( ) const
inline

Return the packed length without the pointer size added.

This is used to determine the size of the actual data in the row buffer.

Returns
The length of the raw data itself without the pointer.

◆ pack_with_metadata_bytes()

uchar * Field_blob::pack_with_metadata_bytes ( uchar to,
const uchar from,
uint  max_length 
) const
finalvirtual

This function does the same thing as pack(), except for the difference that max_length does not mean the number of bytes in the output, but the maximum field length from the input (which must be exactly field->max_field_length()).

The difference is currently only relevant for Field_blob, but can be summed up as follows:

  • If the actual field length is longer than "max_length", by way of software bug or otherwise, the function may behave as if it were shorter, and write something that is still readable by unpack().
  • There is no bounds checking; the caller must verify that there is sufficient space in "to". Even in the case of truncation, "to" must be long enough to hold the untruncated field, as the return pointer would otherwise be invalid, causing undefined behavior as per the C++ standard.

Reimplemented from Field.

◆ restore_blob_backup()

void Field_blob::restore_blob_backup ( )

Restore backup value.

See also
Field_blob::backup_value

◆ row_pack_length()

uint Field_blob::row_pack_length ( ) const
inlinefinalvirtual

Reimplemented from Field.

◆ set_keep_old_value()

void Field_blob::set_keep_old_value ( bool  old_value_flag)
inline

Mark that the BLOB stored in value should be copied before updating it.

When updating virtual generated columns we need to keep the old 'value' for BLOBs since this can be needed when the storage engine does the update. During read of the record the old 'value' for the BLOB is evaluated and stored in 'value'. This function is to be used to specify that we need to copy this BLOB 'value' into 'old_value' before we compute the new BLOB 'value'. For more information

See also
Field_blob::keep_old_value().

◆ set_key_image()

void Field_blob::set_key_image ( const uchar buff,
size_t  length 
)
finalvirtual

Reimplemented from Field.

◆ set_ptr() [1/2]

void Field_blob::set_ptr ( const uchar length,
const uchar data 
)
inline

◆ set_ptr() [2/2]

void Field_blob::set_ptr ( uint32  length,
const uchar data 
)
inline

◆ set_ptr_offset()

void Field_blob::set_ptr_offset ( ptrdiff_t  ptr_diff,
uint32  length,
const uchar data 
)
inline

◆ sql_type()

void Field_blob::sql_type ( String str) const
overridevirtual

Implements Field.

Reimplemented in Field_vector, Field_geom, Field_typed_array, and Field_json.

◆ store() [1/4]

type_conversion_status Field_blob::store ( const char *  to,
size_t  length,
const CHARSET_INFO charset 
)
overridevirtual

◆ store() [2/4]

type_conversion_status Field_blob::store ( const Field from)

◆ store() [3/4]

type_conversion_status Field_blob::store ( double  nr)
overridevirtual

Store double value in Field_string or Field_varstring.

Pretty prints double number into field_length characters buffer.

Parameters
nrnumber

Reimplemented from Field_str.

Reimplemented in Field_vector, Field_geom, Field_vector, Field_geom, Field_json, and Field_typed_array.

◆ store() [4/4]

type_conversion_status Field_blob::store ( longlong  nr,
bool  unsigned_val 
)
overridevirtual

◆ store_in_allocated_space()

void Field_blob::store_in_allocated_space ( const char *  from,
uint32  length 
)
inline

Use to store the blob value into an allocated space.

◆ store_internal()

type_conversion_status Field_blob::store_internal ( const char *  from,
size_t  length,
const CHARSET_INFO cs 
)
privatevirtual

Reimplemented in Field_geom.

◆ store_length() [1/2]

void Field_blob::store_length ( uchar i_ptr,
uint  i_packlength,
uint32  i_number 
)

◆ store_length() [2/2]

void Field_blob::store_length ( uint32  number)
inline

◆ store_ptr_and_length()

void Field_blob::store_ptr_and_length ( const char *  from,
uint32  length 
)
inlineprotected

Store ptr and length.

◆ store_to_mem()

type_conversion_status Field_blob::store_to_mem ( const char *  from,
size_t  length,
const CHARSET_INFO cs,
size_t  max_length,
Blob_mem_storage  
)
private

Copy value to memory storage.

Store a blob value to memory storage.

Parameters
fromthe string value to store.
lengthlength of the string value.
cscharacter set of the string value.
max_lengthCut at this length safely (multibyte aware).

◆ type()

enum_field_types Field_blob::type ( ) const
inlineoverridevirtual

Implements Field.

Reimplemented in Field_vector, Field_geom, Field_json, and Field_typed_array.

◆ unpack()

const uchar * Field_blob::unpack ( uchar ,
const uchar from,
uint  param_data 
)
finalvirtual

Unpack a blob field from row data.

This method is used to unpack a blob field from a master whose size of the field is less than that of the slave. Note: This method is included to satisfy inheritance rules, but is not needed for blob fields. It simply is used as a pass-through to the original unpack() method for blob fields.

Parameters
fromSource of the data
param_dataThe "metadata", as stored in the Table_map_log_event for this field. This metadata is the number of bytes used to represent the length of the blob (1, 2, 3, or 4).
Returns
New pointer into memory based on from + length of the data

Reimplemented from Field.

◆ val_decimal()

my_decimal * Field_blob::val_decimal ( my_decimal decimal_value) const
overridevirtual

Implements Field.

Reimplemented in Field_json.

◆ val_int()

longlong Field_blob::val_int ( void  ) const
overridevirtual

Implements Field.

Reimplemented in Field_json.

◆ val_real()

double Field_blob::val_real ( void  ) const
overridevirtual

Implements Field.

Reimplemented in Field_json.

◆ val_str()

String * Field_blob::val_str ( String ,
String val_ptr 
) const
overridevirtual

Implements Field.

Reimplemented in Field_vector, and Field_json.

Member Data Documentation

◆ m_blob_backup

String Field_blob::m_blob_backup
private

Backup String for table's blob fields.

UPDATE of a virtual field (for index update) requires two values to be kept at the same time - 'new' and 'old' since SE (InnoDB) doesn't know the latter. In the case when there was an indexed record, it got deleted and When INSERT inserts into an index a record that coincides with a previously deleted one, InnoDB needs to recalculate value that was deleted in order to properly insert the new one. When two above overlap, a field have to keep 3 different values at the same time - 'new', 'old' and 'deleted'. This backup_value is used by

See also
my_eval_gcolumn_expr_helper() to save 'new' and provide space for 'deleted' to avoid thrashing the former. Unlike the old_value, backup_value is allocated once and reused for each new re-calculation, to avoid excessive [re-]allocations. It's freed at the end of statement. Since InnoDB consumes calculated values only after all needed table's virtual fields were calculated, we have to have such backup buffer for each field.

Also used for set operation hashing: we need to compare the new and the existing record with the same hash.

◆ m_keep_old_value

bool Field_blob::m_keep_old_value
private

Whether we need to move the content of 'value' to 'old_value' before updating the BLOB stored in 'value'.

This needs to be done for updates of BLOB columns that are virtual since the storage engine does not have its own copy of the old 'value'. This variable is set to true when we read the data into 'value'. It is reset when we move 'value' to 'old_value'. The purpose of having this is to avoid that we do the move operation from 'value' to 'old_value' more than one time per record. Currently, this variable is introduced because the following call in sql_data_change.cc: \/**

◆ m_uses_backup

bool Field_blob::m_uses_backup {false}
private

Whether the field uses table's backup value storage.

See also
TABLE::m_blob_backup. Used only for debug.

◆ old_value

String Field_blob::old_value
private

In order to support update of virtual generated columns of blob type, we need to allocate the space blob needs on server for old_row and new_row respectively.

This variable is used to record the allocated blob space for old_row.

◆ packlength

uint Field_blob::packlength
protected

The number of bytes used to represent the length of the blob.

◆ value

String Field_blob::value
protected

The 'value'-object is a cache fronting the storage engine.


The documentation for this class was generated from the following files: