MySQL  8.0.16
Source Code Documentation
Create_field Class Reference

Create_field is a description a field/column that may or may not exists in a table. More...

#include <create_field.h>

Inheritance diagram for Create_field:
Json_table_column

Public Member Functions

size_t max_display_width_in_codepoints () const
 
size_t max_display_width_in_bytes () const
 
size_t pack_length () const
 
size_t key_length () const
 
bool explicit_display_width () const
 
void set_max_display_width_from_create_field (const Create_field &create_field)
 Set the maximum display width based on another Create_field. More...
 
 Create_field ()
 
 Create_field (Field *field, Field *orig_field)
 Constructs a column definition from an object representing an actual column. More...
 
Create_fieldclone (MEM_ROOT *mem_root) const
 
bool is_gcol () const
 
bool is_virtual_gcol () const
 
void init_for_tmp_table (enum_field_types sql_type_arg, uint32 max_length, uint32 decimals, bool maybe_null, bool is_unsigned, uint pack_length_override, const char *field_name="")
 Init for a tmp table field. More...
 
bool init (THD *thd, const char *field_name, enum_field_types type, const char *length, const char *decimals, uint type_modifier, Item *default_value, Item *on_update_value, LEX_STRING *comment, const char *change, List< String > *interval_list, const CHARSET_INFO *cs, bool has_explicit_collation, uint uint_geom_type, Value_generator *gcol_info, Value_generator *default_val_expr, Nullable< gis::srid_t > srid, dd::Column::enum_hidden_type hidden)
 Initialize a column definition object. More...
 
ha_storage_media field_storage_type () const
 
column_format_type column_format () const
 

Public Attributes

dd::Column::enum_hidden_type hidden
 
const char * field_name
 
const char * change
 Name of column modified by ALTER TABLE's CHANGE/MODIFY COLUMN clauses, NULL for columns added. More...
 
const char * after
 
LEX_STRING comment
 
Itemconstant_default
 The declared default value, if any, otherwise NULL. More...
 
enum_field_types sql_type
 
uint decimals
 
uint flags {0}
 
uchar auto_flags {Field::NONE}
 Bitmap of flags indicating if field value should be auto-generated by default and/or on update, and in which way. More...
 
TYPELIBinterval
 
List< Stringinterval_list
 
const CHARSET_INFOcharset
 
bool is_explicit_collation
 
Field::geometry_type geom_type
 
Fieldfield
 
uint offset
 
bool maybe_null
 Indicate whether column is nullable, zerofill or unsigned. More...
 
bool is_zerofill
 
bool is_unsigned
 
bool treat_bit_as_char
 Indicates that storage engine doesn't support optimized BIT field storage. More...
 
uint pack_length_override {0}
 Row based replication code sometimes needs to create ENUM and SET fields with pack length which doesn't correspond to number of elements in interval TYPELIB. More...
 
Value_generatorgcol_info {nullptr}
 
bool stored_in_db
 
Value_generatorm_default_val_expr {nullptr}
 Holds the expression to be used to generate default values. More...
 
Nullable< gis::srid_tm_srid
 

Private Attributes

size_t m_max_display_width_in_codepoints {0}
 The maximum display width of this column. More...
 
bool m_explicit_display_width {false}
 Whether or not the display width was given explicitly by the user. More...
 

Static Private Attributes

static constexpr size_t TINYBLOB_MAX_SIZE_IN_BYTES {255}
 The maximum number of bytes a TINYBLOB can hold. More...
 
static constexpr size_t BLOB_MAX_SIZE_IN_BYTES {65535}
 The maximum number of bytes a BLOB can hold. More...
 
static constexpr size_t MEDIUMBLOB_MAX_SIZE_IN_BYTES {16777215}
 The maximum number of bytes a MEDIUMBLOB can hold. More...
 
static constexpr size_t LONGBLOB_MAX_SIZE_IN_BYTES {4294967295}
 The maximum number of bytes a LONGBLOB can hold. More...
 

Detailed Description

Create_field is a description a field/column that may or may not exists in a table.

The main usage of Create_field is to contain the description of a column given by the user (usually given with CREATE TABLE). It is also used to describe changes to be carried out on a column (usually given with ALTER TABLE ... CHANGE COLUMN).

Constructor & Destructor Documentation

◆ Create_field() [1/2]

Create_field::Create_field ( )
inline

◆ Create_field() [2/2]

Create_field::Create_field ( Field old_field,
Field orig_field 
)

Constructs a column definition from an object representing an actual column.

This is a reverse-engineering procedure that creates a column definition object as produced by the parser (Create_field) from a resolved column object (Field).

Parameters
old_fieldThe column object from which the column definition is constructed.
orig_fieldUsed for copying default values. This parameter may be NULL, but if present it is used for copying default values.

Default values are copied into an Item_string unless:

  • The default value is a function.
  • There is no default value.
  • old_field is a BLOB column.
  • old_field has its data pointer improperly initialized.

Member Function Documentation

◆ clone()

Create_field* Create_field::clone ( MEM_ROOT mem_root) const
inline

◆ column_format()

column_format_type Create_field::column_format ( ) const
inline

◆ explicit_display_width()

bool Create_field::explicit_display_width ( ) const
inline
Return values
trueif the maximum column length was given explicitly by the user.
falseif the user didn't specify any maximum length.

◆ field_storage_type()

ha_storage_media Create_field::field_storage_type ( ) const
inline

◆ init()

bool Create_field::init ( THD thd,
const char *  fld_name,
enum_field_types  fld_type,
const char *  display_width_in_codepoints,
const char *  fld_decimals,
uint  fld_type_modifier,
Item fld_default_value,
Item fld_on_update_value,
LEX_STRING fld_comment,
const char *  fld_change,
List< String > *  fld_interval_list,
const CHARSET_INFO fld_charset,
bool  has_explicit_collation,
uint  fld_geom_type,
Value_generator fld_gcol_info,
Value_generator fld_default_val_expr,
Nullable< gis::srid_t srid,
dd::Column::enum_hidden_type  hidden 
)

Initialize a column definition object.

Column definition objects can be used to construct Field objects.

Parameters
thdSession/Thread handle.
fld_nameColumn name.
fld_typeColumn type.
display_width_in_codepointsThe column display width, counted in number of code points.
fld_decimalsNumber of digits to the right of the decimal point (if any.)
fld_type_modifierAdditional type information.
fld_default_valueColumn default constant or datetime expression (if any.)
fld_on_update_valueThe expression in the ON UPDATE clause.
fld_commentColumn comment.
fld_changeColumn change.
fld_interval_listInterval list (if any.)
fld_charsetColumn charset.
has_explicit_collationColumn has an explicit COLLATE attribute.
fld_geom_typeColumn geometry type (if any.)
fld_gcol_infoGenerated column data
fld_default_val_exprThe expression for generating default values
sridThe SRID specification. This might be null (has_value() may return false).
hiddenWhether this column should be hidden or not.
Return values
falseon success.
trueon error.

◆ init_for_tmp_table()

void Create_field::init_for_tmp_table ( enum_field_types  sql_type_arg,
uint32  length_arg,
uint32  decimals_arg,
bool  maybe_null_arg,
bool  is_unsigned_arg,
uint  pack_length_override_arg,
const char *  fld_name = "" 
)

Init for a tmp table field.

To be extended if need be.

◆ is_gcol()

bool Create_field::is_gcol ( ) const
inline

◆ is_virtual_gcol()

bool Create_field::is_virtual_gcol ( ) const
inline

◆ key_length()

size_t Create_field::key_length ( ) const
Returns
the key length for this column.

◆ max_display_width_in_bytes()

size_t Create_field::max_display_width_in_bytes ( ) const
Returns
the maximum display width of this column, in number of bytes. For numeric types, temporal types, YEAR and BIT, this method returns the same as max_display_width_in_codepoints(). For character types (CHAR, VARCHAR, TEXT etc) the returned value depends on max_display_width_in_codepoints() and the character set of this column.

◆ max_display_width_in_codepoints()

size_t Create_field::max_display_width_in_codepoints ( ) const
Returns
the maximum display width of this column, in number of. code points. See m_max_display_width_in_codepoints for an explanation of "display width" and "code point".

◆ pack_length()

size_t Create_field::pack_length ( ) const
Returns
the pack length for this column, which is the number of bytes needed to store this column in memory. Note that blob returns a length variable + the size of a pointer to an external memory location where the actual data is stored. So LONGBLOB would return 4 bytes for the length variable + 8 bytes for the pointer to the data (12 bytes in total).

◆ set_max_display_width_from_create_field()

void Create_field::set_max_display_width_from_create_field ( const Create_field create_field)
inline

Set the maximum display width based on another Create_field.

Member Data Documentation

◆ after

const char* Create_field::after

◆ auto_flags

uchar Create_field::auto_flags {Field::NONE}

Bitmap of flags indicating if field value should be auto-generated by default and/or on update, and in which way.

See also
Field::enum_auto_flags for possible options.

◆ BLOB_MAX_SIZE_IN_BYTES

constexpr size_t Create_field::BLOB_MAX_SIZE_IN_BYTES {65535}
staticprivate

The maximum number of bytes a BLOB can hold.

◆ change

const char* Create_field::change

Name of column modified by ALTER TABLE's CHANGE/MODIFY COLUMN clauses, NULL for columns added.

◆ charset

const CHARSET_INFO* Create_field::charset

◆ comment

LEX_STRING Create_field::comment

◆ constant_default

Item* Create_field::constant_default

The declared default value, if any, otherwise NULL.

Note that this member is NULL if the default is a function. If the column definition has a function declared as the default, the information is found in Create_field::auto_flags.

See also
Create_field::auto_flags

◆ decimals

uint Create_field::decimals

◆ field

Field* Create_field::field

◆ field_name

const char* Create_field::field_name

◆ flags

uint Create_field::flags {0}

◆ gcol_info

Value_generator* Create_field::gcol_info {nullptr}

◆ geom_type

Field::geometry_type Create_field::geom_type

◆ hidden

dd::Column::enum_hidden_type Create_field::hidden

◆ interval

TYPELIB* Create_field::interval

◆ interval_list

List<String> Create_field::interval_list

◆ is_explicit_collation

bool Create_field::is_explicit_collation

◆ is_unsigned

bool Create_field::is_unsigned

◆ is_zerofill

bool Create_field::is_zerofill

◆ LONGBLOB_MAX_SIZE_IN_BYTES

constexpr size_t Create_field::LONGBLOB_MAX_SIZE_IN_BYTES {4294967295}
staticprivate

The maximum number of bytes a LONGBLOB can hold.

◆ m_default_val_expr

Value_generator* Create_field::m_default_val_expr {nullptr}

Holds the expression to be used to generate default values.

◆ m_explicit_display_width

bool Create_field::m_explicit_display_width {false}
private

Whether or not the display width was given explicitly by the user.

◆ m_max_display_width_in_codepoints

size_t Create_field::m_max_display_width_in_codepoints {0}
private

The maximum display width of this column.

The "display width" is the number of code points that is needed to print out the string represenation of a value. It can be given by the user both explicitly and implicitly. If a user creates a table with the columns "a VARCHAR(3), b INT(3)", both columns are given an explicit display width of 3 code points. But if a user creates a table with the columns "a INT, b TINYINT UNSIGNED", the first column has an implicit display width of 11 (-2147483648 is the longest value for a signed int) and the second column has an implicit display width of 3 (255 is the longest value for an unsigned tinyint). This is related to storage size for some types (VARCHAR, BLOB etc), but not for all types (an INT is four bytes regardless of the display width).

A "code point" is bascially a numeric value. For instance, ASCII compromises of 128 code points (0x00 to 0x7F), while unicode contains way more. In most cases a code point represents a single graphical unit (aka grapheme), but not always. For instance, É may consists of two code points where one is the letter E and the other one is the quotation mark above the letter.

◆ m_srid

Nullable<gis::srid_t> Create_field::m_srid

◆ maybe_null

bool Create_field::maybe_null

Indicate whether column is nullable, zerofill or unsigned.

Initialized based on flags and other members at prepare_create_field()/ init_for_tmp_table() stage.

◆ MEDIUMBLOB_MAX_SIZE_IN_BYTES

constexpr size_t Create_field::MEDIUMBLOB_MAX_SIZE_IN_BYTES {16777215}
staticprivate

The maximum number of bytes a MEDIUMBLOB can hold.

◆ offset

uint Create_field::offset

◆ pack_length_override

uint Create_field::pack_length_override {0}

Row based replication code sometimes needs to create ENUM and SET fields with pack length which doesn't correspond to number of elements in interval TYPELIB.

When this member is non-zero ENUM/SET field to be created will use its value as pack length instead of one calculated from number elements in its interval.

Initialized at prepare_create_field()/init_for_tmp_table() stage.

◆ sql_type

enum_field_types Create_field::sql_type

◆ stored_in_db

bool Create_field::stored_in_db

◆ TINYBLOB_MAX_SIZE_IN_BYTES

constexpr size_t Create_field::TINYBLOB_MAX_SIZE_IN_BYTES {255}
staticprivate

The maximum number of bytes a TINYBLOB can hold.

◆ treat_bit_as_char

bool Create_field::treat_bit_as_char

Indicates that storage engine doesn't support optimized BIT field storage.

Note
We also use safe/non-optimized version of BIT field for special cases like virtual temporary tables.

Initialized at mysql_prepare_create_table()/sp_prepare_create_field()/ init_for_tmp_table() stage.


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