MySQL 8.3.0
Source Code Documentation
dd_table_share.cc File Reference
#include "sql/dd_table_share.h"
#include "my_config.h"
#include <string.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <string>
#include <type_traits>
#include "lex_string.h"
#include "m_string.h"
#include "map_helpers.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_bitmap.h"
#include "my_compare.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_macros.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/components/services/log_builtins.h"
#include "mysql/components/services/log_shared.h"
#include "mysql/my_loglevel.h"
#include "mysql/plugin.h"
#include "mysql/strings/dtoa.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysqld_error.h"
#include "sql/aggregated_stats.h"
#include "sql/dd/collection.h"
#include "sql/dd/dd_table.h"
#include "sql/dd/dd_tablespace.h"
#include "sql/dd/impl/utils.h"
#include "sql/dd/properties.h"
#include "sql/dd/string_type.h"
#include "sql/dd/types/check_constraint.h"
#include "sql/dd/types/column.h"
#include "sql/dd/types/column_type_element.h"
#include "sql/dd/types/foreign_key.h"
#include "sql/dd/types/foreign_key_element.h"
#include "sql/dd/types/index.h"
#include "sql/dd/types/index_element.h"
#include "sql/dd/types/partition.h"
#include "sql/dd/types/partition_value.h"
#include "sql/dd/types/table.h"
#include "sql/default_values.h"
#include "sql/error_handler.h"
#include "sql/field.h"
#include "sql/gis/srid.h"
#include "sql/handler.h"
#include "sql/histograms/table_histograms.h"
#include "sql/key.h"
#include "sql/log.h"
#include "sql/partition_element.h"
#include "sql/partition_info.h"
#include "sql/sql_bitmap.h"
#include "sql/sql_check_constraint.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_error.h"
#include "sql/sql_list.h"
#include "sql/sql_partition.h"
#include "sql/sql_plugin.h"
#include "sql/sql_plugin_ref.h"
#include "sql/sql_table.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table.h"
#include "sql/thd_raii.h"
#include "typelib.h"

Classes

class  Open_table_error_handler
 

Functions

enum_field_types dd_get_old_field_type (dd::enum_column_types type)
 
static enum ha_key_alg dd_get_old_index_algorithm_type (dd::Index::enum_index_algorithm type)
 For enum in dd::Index. More...
 
bool is_suitable_for_primary_key (KEY_PART_INFO *key_part, Field *table_field)
 Check if the given key_part is suitable to be promoted as part of primary key. More...
 
static bool prepare_share (THD *thd, TABLE_SHARE *share, const dd::Table *table_def)
 Finalize preparation of TABLE_SHARE from dd::Table object by filling in remaining info about columns and keys. More...
 
static bool fill_tablespace_from_dd (THD *thd, TABLE_SHARE *share, const dd::Table *tab_obj)
 Fill tablespace name from dd::Tablespace. More...
 
static row_type dd_get_old_row_format (dd::Table::enum_row_format new_format)
 Convert row format value used in DD to corresponding value in old row_type enum. More...
 
static bool fill_share_from_dd (THD *thd, TABLE_SHARE *share, const dd::Table *tab_obj)
 Fill TABLE_SHARE from dd::Table object. More...
 
static uint column_preamble_bits (const dd::Column *col_obj)
 Calculate number of bits used for the column in the record preamble (aka null bits number). More...
 
void get_auto_flags (const dd::Column &col_obj, uint &auto_flags)
 
static Fieldmake_field (const dd::Column &col_obj, const CHARSET_INFO *charset, TABLE_SHARE *share, uchar *ptr, uchar *null_pos, size_t null_bit)
 
static bool fill_column_from_dd (THD *thd, TABLE_SHARE *share, const dd::Column *col_obj, uchar *null_pos, uint null_bit_pos, uchar *rec_pos, uint field_nr)
 Add Field constructed according to column metadata from dd::Column object to TABLE_SHARE. More...
 
static bool fill_columns_from_dd (THD *thd, TABLE_SHARE *share, const dd::Table *tab_obj)
 Populate TABLE_SHARE::field array according to column metadata from dd::Table object. More...
 
static void fill_index_element_from_dd (TABLE_SHARE *share, const dd::Index_element *idx_elem_obj, KEY_PART_INFO *keypart)
 Fill KEY_INFO_PART from dd::Index_element object. More...
 
static void fill_index_elements_from_dd (TABLE_SHARE *share, const dd::Index *idx_obj, int key_nr)
 Fill KEY::key_part array according to metadata from dd::Index object. More...
 
static bool fill_index_from_dd (THD *thd, TABLE_SHARE *share, const dd::Index *idx_obj, uint key_nr)
 Add KEY constructed according to index metadata from dd::Index object to the TABLE_SHARE. More...
 
static bool is_spatial_index_usable (const dd::Index &index)
 Check if this is a spatial index that can be used. More...
 
static bool fill_indexes_from_dd (THD *thd, TABLE_SHARE *share, const dd::Table *tab_obj)
 Fill TABLE_SHARE::key_info array according to index metadata from dd::Table object. More...
 
static char * copy_option_string (MEM_ROOT *mem_root, const dd::Properties &options, const dd::String_type &key)
 
static void get_partition_options (MEM_ROOT *mem_root, partition_element *part_elem, const dd::Properties &part_options)
 
static bool get_part_column_values (MEM_ROOT *mem_root, partition_info *part_info, partition_element *part_elem, const dd::Partition *part_obj)
 
static bool setup_partition_from_dd (THD *thd, MEM_ROOT *mem_root, partition_info *part_info, partition_element *part_elem, const dd::Partition *part_obj, bool is_subpart)
 
static bool set_field_list (MEM_ROOT *mem_root, dd::String_type &str, List< char > *field_list)
 Set field_list. More...
 
static bool fill_partitioning_from_dd (THD *thd, TABLE_SHARE *share, const dd::Table *tab_obj)
 Fill TABLE_SHARE with partitioning details from dd::Partition. More...
 
static bool fill_foreign_keys_from_dd (TABLE_SHARE *share, const dd::Table *tab_obj)
 Fill TABLE_SHARE with information about foreign keys from dd::Table. More...
 
static bool fill_check_constraints_from_dd (TABLE_SHARE *share, const dd::Table *tab_obj)
 Fill check constraints from dd::Table object to the TABLE_SHARE. More...
 
bool open_table_def (THD *thd, TABLE_SHARE *share, const dd::Table &table_def)
 Read the table definition from the data-dictionary. More...
 
bool open_table_def_suppress_invalid_meta_data (THD *thd, TABLE_SHARE *share, const dd::Table &table_def)
 Read the table definition from the data-dictionary. More...
 

Variables

struct aggregated_stats global_aggregated_stats
 

Function Documentation

◆ column_preamble_bits()

static uint column_preamble_bits ( const dd::Column col_obj)
static

Calculate number of bits used for the column in the record preamble (aka null bits number).

◆ copy_option_string()

static char * copy_option_string ( MEM_ROOT mem_root,
const dd::Properties options,
const dd::String_type key 
)
static

◆ dd_get_old_field_type()

enum_field_types dd_get_old_field_type ( dd::enum_column_types  type)

◆ dd_get_old_index_algorithm_type()

static enum ha_key_alg dd_get_old_index_algorithm_type ( dd::Index::enum_index_algorithm  type)
static

For enum in dd::Index.

◆ dd_get_old_row_format()

static row_type dd_get_old_row_format ( dd::Table::enum_row_format  new_format)
static

Convert row format value used in DD to corresponding value in old row_type enum.

◆ fill_check_constraints_from_dd()

static bool fill_check_constraints_from_dd ( TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Fill check constraints from dd::Table object to the TABLE_SHARE.

Parameters
[in,out]shareTABLE_SHARE instance.
[in]tab_objTable instance.
Return values
falseOn Success.
trueOn failure.

◆ fill_column_from_dd()

static bool fill_column_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Column col_obj,
uchar null_pos,
uint  null_bit_pos,
uchar rec_pos,
uint  field_nr 
)
static

Add Field constructed according to column metadata from dd::Column object to TABLE_SHARE.

◆ fill_columns_from_dd()

static bool fill_columns_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Populate TABLE_SHARE::field array according to column metadata from dd::Table object.

◆ fill_foreign_keys_from_dd()

static bool fill_foreign_keys_from_dd ( TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Fill TABLE_SHARE with information about foreign keys from dd::Table.

◆ fill_index_element_from_dd()

static void fill_index_element_from_dd ( TABLE_SHARE share,
const dd::Index_element idx_elem_obj,
KEY_PART_INFO keypart 
)
static

Fill KEY_INFO_PART from dd::Index_element object.

◆ fill_index_elements_from_dd()

static void fill_index_elements_from_dd ( TABLE_SHARE share,
const dd::Index idx_obj,
int  key_nr 
)
static

Fill KEY::key_part array according to metadata from dd::Index object.

◆ fill_index_from_dd()

static bool fill_index_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Index idx_obj,
uint  key_nr 
)
static

Add KEY constructed according to index metadata from dd::Index object to the TABLE_SHARE.

◆ fill_indexes_from_dd()

static bool fill_indexes_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Fill TABLE_SHARE::key_info array according to index metadata from dd::Table object.

◆ fill_partitioning_from_dd()

static bool fill_partitioning_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Fill TABLE_SHARE with partitioning details from dd::Partition.

Set up as much as possible to ease creating new TABLE instances by copying from the TABLE_SHARE.

Also to prevent future memory duplication partition definitions (names etc) are stored on the TABLE_SHARE and can be referenced from each TABLE instance.

Note that [sub]part_expr still needs to be parsed from [sub]part_func_string for each TABLE instance to use the correct mem_root etc. To be as compatible with the .frm way to open a table as possible we currently generate the full partitioning clause which will be parsed for each new TABLE instance. TODO-PARTITION:

  • Create a way to handle Item expressions to be shared/copied from the TABLE_SHARE.
  • On the open of the first TABLE instance, copy the field images to the TABLE_SHARE::partition_info for each partition value.
Parameters
thdThread context.
shareShare to be updated with partitioning details.
tab_objdd::Table object to get partition info from.
Returns
false if success, else true.

◆ fill_share_from_dd()

static bool fill_share_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Fill TABLE_SHARE from dd::Table object.

◆ fill_tablespace_from_dd()

static bool fill_tablespace_from_dd ( THD thd,
TABLE_SHARE share,
const dd::Table tab_obj 
)
static

Fill tablespace name from dd::Tablespace.

◆ get_auto_flags()

void get_auto_flags ( const dd::Column col_obj,
uint &  auto_flags 
)
inline

◆ get_part_column_values()

static bool get_part_column_values ( MEM_ROOT mem_root,
partition_info part_info,
partition_element part_elem,
const dd::Partition part_obj 
)
static

◆ get_partition_options()

static void get_partition_options ( MEM_ROOT mem_root,
partition_element part_elem,
const dd::Properties part_options 
)
static

◆ is_spatial_index_usable()

static bool is_spatial_index_usable ( const dd::Index index)
static

Check if this is a spatial index that can be used.

That is, if there is a spatial index on a geometry column without the SRID specified, we will hide the index so that the optimizer won't consider the index during optimization/execution.

Parameters
indexThe index to verify
Return values
trueif the index is an usable spatial index, or if it isn't a spatial index.
falseif the index is a spatial index on a geometry column without an SRID specified.

◆ is_suitable_for_primary_key()

bool is_suitable_for_primary_key ( KEY_PART_INFO key_part,
Field table_field 
)

Check if the given key_part is suitable to be promoted as part of primary key.

Parameters
key_part- pointer to KEY_PART_INTO which we are checking.
table_field- Pointer to Field of column used by key_part.
Returns
true - Is suitable for primary key. false - if not.

◆ make_field()

static Field * make_field ( const dd::Column col_obj,
const CHARSET_INFO charset,
TABLE_SHARE share,
uchar ptr,
uchar null_pos,
size_t  null_bit 
)
static

◆ open_table_def()

bool open_table_def ( THD thd,
TABLE_SHARE share,
const dd::Table table_def 
)

Read the table definition from the data-dictionary.

Parameters
thdThread handler
shareFill this with table definition
table_defA data-dictionary Table-object describing table to be used for opening, instead of reading information from DD.
Note
This function is called when the table definition is not cached in table_def_cache. The data is returned in 'share', which is allocated by alloc_table_share().. The code assumes that share is initialized.
Returns
false OK true Error

◆ open_table_def_suppress_invalid_meta_data()

bool open_table_def_suppress_invalid_meta_data ( THD thd,
TABLE_SHARE share,
const dd::Table table_def 
)

Read the table definition from the data-dictionary.

Parameters
thdThread handler
shareFill this with table definition
table_defA data-dictionary Table-object describing table to be used for opening.
Note
This function is called from InnoDB, and will suppress errors due to: Invalid collations. Missing FTS parser.
Returns
false OK true Error

◆ prepare_share()

static bool prepare_share ( THD thd,
TABLE_SHARE share,
const dd::Table table_def 
)
static

Finalize preparation of TABLE_SHARE from dd::Table object by filling in remaining info about columns and keys.

This code similar to code in open_binary_frm(). Can be re-written independent to other efforts later.

◆ set_field_list()

static bool set_field_list ( MEM_ROOT mem_root,
dd::String_type str,
List< char > *  field_list 
)
static

Set field_list.

To append each field to the field_list it will parse the submitted partition_expression string.

Must be in sync with get_field_list_str!

Parameters
[in]mem_rootWhere to allocate the memory for the list entries.
[in]strString object containing the column names.
[in,out]field_listList to add field names to.
Returns
false on success, else true.

◆ setup_partition_from_dd()

static bool setup_partition_from_dd ( THD thd,
MEM_ROOT mem_root,
partition_info part_info,
partition_element part_elem,
const dd::Partition part_obj,
bool  is_subpart 
)
static

Variable Documentation

◆ global_aggregated_stats

struct aggregated_stats global_aggregated_stats
extern