MySQL 9.1.0
Source Code Documentation
|
#include "sql/table.h"
#include "my_config.h"
#include <errno.h>
#include <fcntl.h>
#include <scope_guard.h>
#include <stdio.h>
#include <algorithm>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include "ft_global.h"
#include "m_string.h"
#include "map_helpers.h"
#include "memory_debugging.h"
#include "my_alloc.h"
#include "my_byteorder.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_macros.h"
#include "my_pointer_arithmetic.h"
#include "my_psi_config.h"
#include "my_sqlcommand.h"
#include "my_thread_local.h"
#include "myisam.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/mysql_lex_string.h"
#include "mysql/plugin.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/psi/mysql_mutex.h"
#include "mysql/psi/mysql_table.h"
#include "mysql/psi/psi_table.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/strings/m_ctype.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysql_version.h"
#include "mysqld_error.h"
#include "nulls.h"
#include "sql-common/json_diff.h"
#include "sql-common/json_dom.h"
#include "sql-common/json_path.h"
#include "sql-common/my_decimal.h"
#include "sql/auth/auth_acls.h"
#include "sql/auth/auth_common.h"
#include "sql/auth/sql_security_ctx.h"
#include "sql/binlog.h"
#include "sql/dd/cache/dictionary_client.h"
#include "sql/dd/dd.h"
#include "sql/dd/dictionary.h"
#include "sql/dd/types/abstract_table.h"
#include "sql/dd/types/table.h"
#include "sql/dd/types/view.h"
#include "sql/debug_sync.h"
#include "sql/derror.h"
#include "sql/error_handler.h"
#include "sql/field.h"
#include "sql/filesort.h"
#include "sql/gis/srid.h"
#include "sql/histograms/table_histograms.h"
#include "sql/item.h"
#include "sql/item_cmpfunc.h"
#include "sql/item_json_func.h"
#include "sql/join_optimizer/access_path.h"
#include "sql/join_optimizer/bit_utils.h"
#include "sql/key.h"
#include "sql/log.h"
#include "sql/mysqld.h"
#include "sql/nested_join.h"
#include "sql/opt_trace.h"
#include "sql/opt_trace_context.h"
#include "sql/parse_file.h"
#include "sql/partition_info.h"
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/query_result.h"
#include "sql/sql_base.h"
#include "sql/sql_check_constraint.h"
#include "sql/sql_class.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_opt_exec_shared.h"
#include "sql/sql_optimizer.h"
#include "sql/sql_parse.h"
#include "sql/sql_partition.h"
#include "sql/sql_plugin.h"
#include "sql/sql_select.h"
#include "sql/sql_table.h"
#include "sql/sql_tablespace.h"
#include "sql/sql_union.h"
#include "sql/strfunc.h"
#include "sql/system_variables.h"
#include "sql/table_cache.h"
#include "sql/table_trigger_dispatcher.h"
#include "sql/thd_raii.h"
#include "sql/thr_malloc.h"
#include "sql/trigger_def.h"
#include "sql_const.h"
#include "sql_string.h"
#include "string_with_len.h"
#include "strxmov.h"
#include "strxnmov.h"
#include "template_utils.h"
#include "thr_mutex.h"
Classes | |
class | MaterializedPathCache |
This class caches table_paths for materialized tables. More... | |
struct | MaterializedPathCache::RefPath |
struct | Partial_update_info |
A struct that contains execution time state used for partial update of JSON columns. More... | |
Namespaces | |
namespace | anonymous_namespace{table.cc} |
Macros | |
#define | FIELDFLAG_DECIMAL 1 |
#define | FIELDFLAG_BINARY 1 |
#define | FIELDFLAG_NUMBER 2 |
#define | FIELDFLAG_ZEROFILL 4 |
#define | FIELDFLAG_PACK 120 |
#define | FIELDFLAG_INTERVAL 256 |
#define | FIELDFLAG_BITFIELD 512 |
#define | FIELDFLAG_BLOB 1024 |
#define | FIELDFLAG_GEOM 2048 |
#define | FIELDFLAG_JSON |
#define | FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */ |
#define | FIELDFLAG_LEFT_FULLSCREEN 8192 |
#define | FIELDFLAG_RIGHT_FULLSCREEN 16384 |
#define | FIELDFLAG_FORMAT_NUMBER 16384 |
#define | FIELDFLAG_NO_DEFAULT 16384 /* sql */ |
#define | FIELDFLAG_SUM ((uint)32768) |
#define | FIELDFLAG_MAYBE_NULL ((uint)32768) |
#define | FIELDFLAG_PACK_SHIFT 3 |
#define | FIELDFLAG_DEC_SHIFT 8 |
#define | FIELDFLAG_MAX_DEC 31 |
#define | FIELDFLAG_NUM_SCREEN_TYPE 0x7F01 |
#define | FIELDFLAG_ALFA_SCREEN_TYPE 0x7800 |
#define | MTYP_TYPENR(type) (type & 127) /* Remove bits from type */ |
#define | FIELD_NR_MASK 16383 /* To get fieldnumber */ |
#define | STORAGE_TYPE_MASK 7 |
#define | COLUMN_FORMAT_MASK 7 |
#define | COLUMN_FORMAT_SHIFT 3 |
Functions | |
static Item_ident * | create_view_field (THD *thd, Table_ref *view, Item **field_ref, const char *name, Name_resolution_context *context) |
static void | open_table_error (THD *thd, TABLE_SHARE *share, int error, int db_errno) |
bool | is_system_table_name (const char *name, size_t length) |
Return true if a table name matches one of the system table names. More... | |
char * | fn_rext (char *name) |
Returns pointer to '.frm' extension of the file name. More... | |
TABLE_CATEGORY | get_table_category (const LEX_CSTRING &db, const LEX_CSTRING &name) |
TABLE_SHARE * | alloc_table_share (const char *db, const char *table_name, const char *key, size_t key_length, bool open_secondary) |
Allocate and setup a TABLE_SHARE structure. More... | |
void | init_tmp_table_share (THD *thd, TABLE_SHARE *share, const char *key, size_t key_length, const char *table_name, const char *path, MEM_ROOT *mem_root) |
Initialize share for temporary tables. More... | |
bool | assert_ref_count_is_locked (const TABLE_SHARE *share) |
Assert that the LOCK_open mutex is held when the reference count of a TABLE_SHARE is accessed. More... | |
void | free_table_share (TABLE_SHARE *share) |
Free table share and memory used by it. More... | |
void | setup_key_part_field (TABLE_SHARE *share, handler *handler_file, uint primary_key_n, KEY *keyinfo, uint key_n, uint key_part_n, uint *usable_parts, bool part_of_key_not_extended) |
Setup key-related fields of Field object for given key and key part. More... | |
uint | add_pk_parts_to_sk (KEY *sk, uint sk_n, KEY *pk, uint pk_n, TABLE_SHARE *share, handler *handler_file, uint *usable_parts, bool use_extended_sk) |
Generate extended secondary keys by adding primary key parts to the existing secondary key. More... | |
int | f_is_dec (int x) |
int | f_is_num (int x) |
int | f_is_zerofill (int x) |
int | f_is_packed (int x) |
int | f_packtype (int x) |
uint8 | f_decimals (int x) |
int | f_is_alpha (int x) |
int | f_is_binary (int x) |
int | f_is_enum (int x) |
int | f_is_bitfield (int x) |
int | f_is_blob (int x) |
int | f_is_geom (int x) |
int | f_is_json (int x) |
int | f_is_equ (int x) |
int | f_settype (int x) |
int | f_maybe_null (int x) |
int | f_no_default (int x) |
int | f_bit_as_char (int x) |
static int | read_string (File file, uchar **to, size_t length) |
Read string from a file with malloc. More... | |
int | anonymous_namespace{table.cc}::hexchar_to_int (char c) |
convert a hex digit into number. More... | |
void | anonymous_namespace{table.cc}::unhex_type2 (TYPELIB *interval) |
Un-hex all elements in a typelib. More... | |
static uint | find_field (Field **fields, uchar *record, uint start, uint length) |
Search after a field with given start & length If an exact field isn't found, return longest field with starts at right position. More... | |
static void | fix_type_pointers (const char ***array, TYPELIB *point_to_type, uint types, char **names) |
fix a str_type to a array type typeparts separated with some char. More... | |
static ulong | get_form_pos (File file, uchar *head) |
Find where a form starts. More... | |
static int | make_field_from_frm (THD *thd, TABLE_SHARE *share, FRM_context *frm_context, uint new_frm_ver, uint field_idx, uchar *strpos, uchar *format_section_fields, char **comment_pos, char **gcol_screen_pos, uchar **null_pos, uint *null_bit_pos, int *errarg) |
Auxiliary function which creates Field object from in-memory representation of .FRM file. More... | |
static int | open_binary_frm (THD *thd, TABLE_SHARE *share, FRM_context *frm_context, uchar *head, File file) |
Read data from a binary .frm file from MySQL 3.23 - 5.0 into TABLE_SHARE. More... | |
static bool | validate_value_generator_expr (Item *expr, Value_generator_source source, const char *source_name, int column_index) |
Validate the expression to see whether there are invalid Item objects. More... | |
static bool | fix_value_generator_fields (THD *thd, TABLE *table, Value_generator *val_generator, Value_generator_source source, const char *source_name, Field *field) |
Resolve the generated expression, generated default value of the column or check constraint expression. More... | |
bool | unpack_value_generator (THD *thd, TABLE *table, Value_generator **val_generator, Value_generator_source source, const char *source_name, Field *field, bool is_create_table, bool *error_reported) |
Unpacks the definition of a value generator in all its forms: generated column, default expression or checked constraint. More... | |
bool | unpack_partition_info (THD *thd, TABLE *outparam, TABLE_SHARE *share, handlerton *engine_type, bool is_create_table) |
Unpack the partition expression. More... | |
bool | create_key_part_field_with_prefix_length (TABLE *table, MEM_ROOT *root) |
Create a copy of the key_info from TABLE_SHARE object to TABLE object. More... | |
int | open_table_from_share (THD *thd, TABLE_SHARE *share, const char *alias, uint db_stat, uint prgflag, uint ha_open_flags, TABLE *outparam, bool is_create_table, const dd::Table *table_def_param) |
Open a table based on a TABLE_SHARE. More... | |
int | closefrm (TABLE *table, bool free_share) |
Free information allocated by openfrm. More... | |
void | free_blobs (TABLE *table) |
void | free_blob_buffers_and_reset (TABLE *table, uint32 size) |
Reclaims temporary blob storage which is bigger than a threshold. More... | |
int | set_zone (int nr, int min_zone, int max_zone) |
void | append_unescaped (String *res, const char *pos, size_t length) |
Store an SQL quoted string. More... | |
void | update_create_info_from_table (HA_CREATE_INFO *create_info, TABLE *table) |
int | rename_file_ext (const char *from, const char *to, const char *ext) |
bool | get_field (MEM_ROOT *mem, Field *field, String *res) |
Allocate string field in MEM_ROOT and return it as String. More... | |
char * | get_field (MEM_ROOT *mem, Field *field) |
Allocate string field in MEM_ROOT and return it as NULL-terminated string. More... | |
Ident_name_check | check_db_name (const char *name, size_t length) |
Check if database name is valid. More... | |
Ident_name_check | check_and_convert_db_name (LEX_STRING *org_name, bool preserve_lettercase) |
Check if database name is valid, and convert to lower case if necessary. More... | |
Ident_name_check | check_table_name (const char *name, size_t length) |
Function to check if table name is valid or not. More... | |
bool | check_column_name (const char *name) |
static bool | save_bitmap (MEM_ROOT *mem_root, const MY_BITMAP &from, MY_BITMAP *to) |
Save the contents of the "from" bitmap in "to". More... | |
static bool | merge_join_conditions (THD *thd, Table_ref *table, Item **pcond) |
Return merged WHERE clause and join conditions for a view. More... | |
void | init_mdl_requests (Table_ref *table_list) |
Helper function which allows to allocate metadata lock request objects for all elements of table list. More... | |
static bool | add_derived_key (THD *thd, List< Derived_key > &derived_key_list, Field *field, table_map ref_by_tbl) |
A helper function to add a derived key to the list of possible keys. More... | |
static int | Derived_key_comp (Derived_key *e1, Derived_key *e2) |
static void | ShiftTailLeft (Key_map *map, uint start) |
Shift contents of 'map' one bit left from position start+1 and on. More... | |
static bool | SupersededByKeyInShare (const TABLE_SHARE &share, const Derived_key &key) |
Check if 'key' is redundant. More... | |
static bool | SupersededByLaterKey (List_iterator< Derived_key > tail, uint fields) |
Check if the derived key that is the head of 'tail' is redundant. More... | |
bool | is_simple_order (ORDER *order) |
Test if the order list consists of simple field expressions. More... | |
void | repoint_field_to_record (TABLE *table, uchar *old_rec, uchar *new_rec) |
Repoint a table's fields from old_rec to new_rec. More... | |
static bool | update_generated_columns (TABLE *table, const MY_BITMAP *columns, bool virtual_only, MY_BITMAP *updated_columns) |
Updates the values of the generated columns in the record buffer. More... | |
bool | update_generated_read_fields (uchar *buf, TABLE *table, uint active_index) |
Evaluate necessary virtual generated columns. More... | |
bool | update_generated_write_fields (const MY_BITMAP *bitmap, TABLE *table) |
Calculate data for each generated field marked for write in the corresponding column map. More... | |
static int | read_frm_file (THD *thd, TABLE_SHARE *share, FRM_context *frm_context, const std::string &table, bool is_fix_view_cols_and_deps) |
Open and Read .frm file. More... | |
int | create_table_share_for_upgrade (THD *thd, const char *path, TABLE_SHARE *share, FRM_context *frm_context, const char *db_name, const char *table_name, bool is_fix_view_cols_and_deps) |
Create TABLE_SHARE from .frm file. More... | |
bool | assert_invalid_dict_is_locked (const TABLE *table) |
Assert that LOCK_thd_data is held when TABLE::m_invalid_dict is accessed. More... | |
bool | assert_invalid_stats_is_locked (const TABLE *table) |
Assert that caller holds lock on the table cache when TABLE::m_invalid_stats is accessed. More... | |
Variables | |
LEX_CSTRING | INFORMATION_SCHEMA_NAME = {STRING_WITH_LEN("information_schema")} |
LEX_CSTRING | PERFORMANCE_SCHEMA_DB_NAME |
LEX_CSTRING | MYSQL_SCHEMA_NAME = {STRING_WITH_LEN("mysql")} |
LEX_CSTRING | MYSQL_TABLESPACE_NAME = {STRING_WITH_LEN("mysql")} |
LEX_CSTRING | GENERAL_LOG_NAME = {STRING_WITH_LEN("general_log")} |
LEX_CSTRING | SLOW_LOG_NAME = {STRING_WITH_LEN("slow_log")} |
LEX_CSTRING | RLI_INFO_NAME = {STRING_WITH_LEN("slave_relay_log_info")} |
LEX_CSTRING | MI_INFO_NAME = {STRING_WITH_LEN("slave_master_info")} |
LEX_CSTRING | WORKER_INFO_NAME = {STRING_WITH_LEN("slave_worker_info")} |
LEX_CSTRING | GTID_EXECUTED_NAME = {STRING_WITH_LEN("gtid_executed")} |
LEX_CSTRING | PARSE_GCOL_KEYWORD = {STRING_WITH_LEN("parse_gcol_expr")} |
static const longlong | FRM_VER = 6 |
static const longlong | FRM_VER_TRUE_VARCHAR = (FRM_VER + 4) |
#define COLUMN_FORMAT_MASK 7 |
#define COLUMN_FORMAT_SHIFT 3 |
#define FIELD_NR_MASK 16383 /* To get fieldnumber */ |
#define FIELDFLAG_ALFA_SCREEN_TYPE 0x7800 |
#define FIELDFLAG_BINARY 1 |
#define FIELDFLAG_BITFIELD 512 |
#define FIELDFLAG_BLOB 1024 |
#define FIELDFLAG_DEC_SHIFT 8 |
#define FIELDFLAG_DECIMAL 1 |
#define FIELDFLAG_FORMAT_NUMBER 16384 |
#define FIELDFLAG_GEOM 2048 |
#define FIELDFLAG_INTERVAL 256 |
#define FIELDFLAG_JSON |
#define FIELDFLAG_LEFT_FULLSCREEN 8192 |
#define FIELDFLAG_MAX_DEC 31 |
#define FIELDFLAG_MAYBE_NULL ((uint)32768) |
#define FIELDFLAG_NO_DEFAULT 16384 /* sql */ |
#define FIELDFLAG_NUM_SCREEN_TYPE 0x7F01 |
#define FIELDFLAG_NUMBER 2 |
#define FIELDFLAG_PACK 120 |
#define FIELDFLAG_PACK_SHIFT 3 |
#define FIELDFLAG_RIGHT_FULLSCREEN 16384 |
#define FIELDFLAG_SUM ((uint)32768) |
#define FIELDFLAG_TREAT_BIT_AS_CHAR 4096 /* use Field_bit_as_char */ |
#define FIELDFLAG_ZEROFILL 4 |
#define STORAGE_TYPE_MASK 7 |
|
static |
A helper function to add a derived key to the list of possible keys.
thd | thread handler |
derived_key_list | list of all possible derived keys |
field | referenced field |
ref_by_tbl | the table that refers to given field |
The possible key to be used for join with table with ref_by_tbl table map is extended to include 'field'. If ref_by_tbl == 0 then the key that includes all referred fields is extended.
A key is generated for each equi-join pair (derived table, another table). Each generated key consists of fields of derived table used in equi-join. Example:
In this case for the derived table tt one key will be generated. It will consist of two parts f1 and f2. Example:
In this case for the derived table tt two keys will be generated. One key over f1 field, and another key over f2 field. Currently optimizer may choose to use only one such key, thus the second one will be dropped after the range optimizer is finished. See also JOIN::finalize_derived_keys function. Example:
In this case for the derived table tt one key will be generated. It will consist of one field - f1. In all cases beside one-per-table keys one additional key is generated. It includes all fields referenced by other tables.
Implementation is split in three steps:
The above procedure is implemented in 4 functions:
This design is used for derived tables, views and CTEs. As a CTE can be multi-referenced, some points are worth noting:
WHERE 1=(subq))
, due to optimize_cond() an example of "inside": WHERE col<>(subq)
, as make_join_plan() calls estimate_rowcount() which calls the range optimizer for <>, which evaluates subq an example of "after": WHERE key_col=(subq)
, due to create_ref_for_key().QB1 owns the window, then X1 is local, X2 and X3 are nonlocal.
EEEEEEEEEE----------- ^ s->first_unused_keys ^ s->keys
EEEEEEEEEEPPPPPPP--- ^ s->first_unused_keys ^ s->keys
! ! ! EEEEEEEEEEPPPPPPP--- ^ s->first_unused_keys ^ s->keys
! !! EEEEEEEEEEPPPPPPP--- ^ s->first_unused_keys ^ s->keys
The locally-used keys become existing keys and are made visible to nonlocal references. The unnecessary keys are chopped.
! !! EEEEEEEEEEEE----- ^ s->first_unused_keys ^ s->keys
true | OOM |
false | otherwise |
uint add_pk_parts_to_sk | ( | KEY * | sk, |
uint | sk_n, | ||
KEY * | pk, | ||
uint | pk_n, | ||
TABLE_SHARE * | share, | ||
handler * | handler_file, | ||
uint * | usable_parts, | ||
bool | use_extended_sk | ||
) |
Generate extended secondary keys by adding primary key parts to the existing secondary key.
A primary key part is added if such part doesn't present in the secondary key or the part in the secondary key is a prefix of the key field. Key parts are added till: .) all parts were added .) number of key parts became bigger that MAX_REF_PARTS .) total key length became longer than MAX_REF_LENGTH depending on what occurs first first. Unlike existing secondary key parts which are initialized at open_binary_frm(), newly added ones are initialized here by copying KEY_PART_INFO structure from primary key part and calling setup_key_part_field().
Function updates sk->actual/unused_key_parts and sk->actual_flags.
[in] | sk | Secondary key |
[in] | sk_n | Secondary key number |
[in] | pk | Primary key |
[in] | pk_n | Primary key number |
[in] | share | Pointer to TABLE_SHARE |
[in] | handler_file | Pointer to handler |
[in,out] | usable_parts | Pointer to usable_parts variable |
[in] | use_extended_sk | TRUE if use_index_extensions is ON |
Number | of added key parts |
TABLE_SHARE * alloc_table_share | ( | const char * | db, |
const char * | table_name, | ||
const char * | key, | ||
size_t | key_length, | ||
bool | open_secondary | ||
) |
Allocate and setup a TABLE_SHARE structure.
db | schema name. |
table_name | table name. |
key | table cache key (db \0 table_name \0...) |
key_length | length of the key |
open_secondary | true if the TABLE_SHARE represents a table in a secondary storage engine |
NULL | error (out of memory, too long path name) |
void append_unescaped | ( | String * | res, |
const char * | pos, | ||
size_t | length | ||
) |
Store an SQL quoted string.
res | result String |
pos | string to be quoted |
length | it's length |
NOTE This function works correctly with utf8 or single-byte charset strings. May fail with some multibyte charsets though.
bool assert_invalid_dict_is_locked | ( | const TABLE * | table | ) |
Assert that LOCK_thd_data is held when TABLE::m_invalid_dict is accessed.
table | pointer to TABLE object |
bool assert_invalid_stats_is_locked | ( | const TABLE * | table | ) |
Assert that caller holds lock on the table cache when TABLE::m_invalid_stats is accessed.
table | pointer to TABLE object |
bool assert_ref_count_is_locked | ( | const TABLE_SHARE * | share | ) |
Assert that the LOCK_open mutex is held when the reference count of a TABLE_SHARE is accessed.
share | the TABLE_SHARE |
Ident_name_check check_and_convert_db_name | ( | LEX_STRING * | org_name, |
bool | preserve_lettercase | ||
) |
Check if database name is valid, and convert to lower case if necessary.
org_name | Name of database and length |
preserve_lettercase | Preserve lettercase if true |
Ident_name_check::OK | Identifier name is Ok (Success) |
Ident_name_check::WRONG | Identifier name is Wrong (ER_WRONG_TABLE_NAME) |
Ident_name_check::TOO_LONG | Identifier name is too long if it is greater than 64 characters (ER_TOO_LONG_IDENT) |
bool check_column_name | ( | const char * | name | ) |
Ident_name_check check_db_name | ( | const char * | name, |
size_t | length | ||
) |
Check if database name is valid.
name | Name of database |
length | Length of name |
Ident_name_check::OK | Identifier name is Ok (Success) |
Ident_name_check::WRONG | Identifier name is Wrong (ER_WRONG_TABLE_NAME) |
Ident_name_check::TOO_LONG | Identifier name is too long if it is greater than 64 characters (ER_TOO_LONG_IDENT) |
Ident_name_check check_table_name | ( | const char * | name, |
size_t | length | ||
) |
Function to check if table name is valid or not.
If it is invalid, return appropriate error in each case to the caller.
name | Table name |
length | Length of table name |
Ident_name_check::OK | Identifier name is Ok (Success) |
Ident_name_check::WRONG | Identifier name is Wrong (ER_WRONG_TABLE_NAME) |
Ident_name_check::TOO_LONG | Identifier name is too long if it is greater than 64 characters (ER_TOO_LONG_IDENT) |
int closefrm | ( | TABLE * | table, |
bool | free_share | ||
) |
Free information allocated by openfrm.
table | TABLE object to free |
free_share | Is 1 if we also want to free table_share |
Create a copy of the key_info from TABLE_SHARE object to TABLE object.
Wherever prefix key is present, allocate a new Field object, having its field_length set to the prefix key length, and point the table's matching key_part->field to this new Field object.
This ensures that unpack_partition_info() reads the correct prefix length of partitioned fields
int create_table_share_for_upgrade | ( | THD * | thd, |
const char * | path, | ||
TABLE_SHARE * | share, | ||
FRM_context * | frm_context, | ||
const char * | db, | ||
const char * | table, | ||
bool | is_fix_view_cols_and_deps | ||
) |
Create TABLE_SHARE from .frm file.
FRM_context object is used to store the value removed from TABLE_SHARE. These values are used only for .frm file parsing.
[in] | thd | Thread handle. |
[in] | path | Path of the frm file. |
[out] | share | TABLE_SHARE to be populated. |
[out] | frm_context | FRM_context object. |
[in] | db | Database name. |
[in] | table | Table name. |
[in] | is_fix_view_cols_and_deps | Fix view column data, table and routine dependency. |
0 | ON SUCCESS |
-1 | ON FAILURE |
-2 | ON LESS SEVER FAILURE (see read_frm_file) |
|
static |
|
static |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Search after a field with given start & length If an exact field isn't found, return longest field with starts at right position.
0 | error |
field | number +1 success |
|
static |
fix a str_type to a array type typeparts separated with some char.
different types are separated with a '\0'
[out] | array | Pointer to interval array |
[in] | point_to_type | Pointer to intervals |
[in] | types | number of intervals |
[out] | names | name of intervals |
|
static |
Resolve the generated expression, generated default value of the column or check constraint expression.
thd | The thread object |
table | The table to which the column belongs |
val_generator | The expression to resolve |
source | Source of value generator(a generated column, a regular column with generated default value or a check constraint). |
source_name | Name of the source (generated column, a regular column with generated default value or a check constraint). |
field | Field to which the val_generator is attached to for generated columns and default expression. |
true | An error occurred, something was wrong with the function. |
false | Ok, generated expression is fixed successfully |
char * fn_rext | ( | char * | name | ) |
Returns pointer to '.frm' extension of the file name.
name | file name |
Checks file name part starting with the rightmost '.' character, and returns it if it is equal to '.frm'.
Reclaims temporary blob storage which is bigger than a threshold.
Resets blob pointer. Unsets m_keep_old_value.
table | A handle to the TABLE object containing blob fields |
size | The threshold value. |
void free_blobs | ( | TABLE * | table | ) |
void free_table_share | ( | TABLE_SHARE * | share | ) |
Free table share and memory used by it.
share | Table share |
Allocate string field in MEM_ROOT and return it as NULL-terminated string.
mem | MEM_ROOT for allocating |
field | Field for retrieving of string |
NullS | string is empty |
other | pointer to NULL-terminated string value of field |
Allocate string field in MEM_ROOT and return it as String.
mem | MEM_ROOT for allocating |
field | Field for retrieving of string |
res | result String |
1 | string is empty |
0 | all ok |
Find where a form starts.
[in] | file | File handler |
[in] | head | The start of the form file. |
The | form position. |
TABLE_CATEGORY get_table_category | ( | const LEX_CSTRING & | db, |
const LEX_CSTRING & | name | ||
) |
void init_mdl_requests | ( | Table_ref * | table_list | ) |
Helper function which allows to allocate metadata lock request objects for all elements of table list.
void init_tmp_table_share | ( | THD * | thd, |
TABLE_SHARE * | share, | ||
const char * | key, | ||
size_t | key_length, | ||
const char * | table_name, | ||
const char * | path, | ||
MEM_ROOT * | mem_root | ||
) |
Initialize share for temporary tables.
thd | thread handle |
share | Share to fill |
key | Table_cache_key, as generated from create_table_def_key. must start with db name. |
key_length | Length of key |
table_name | Table name |
path | Path to file (possible in lower case) without .frm |
mem_root | MEM_ROOT to transfer (move) to the TABLE_SHARE; if NULL a new one is initialized. |
If table is not put in thd->temporary_tables (happens only when one uses OPEN TEMPORARY) then one can specify 'db' as key and use key_length= 0 as neither table_cache_key or key_length will be used).
bool is_simple_order | ( | ORDER * | order | ) |
Test if the order list consists of simple field expressions.
order | Linked list of ORDER BY arguments |
|
inline |
Return true if a table name matches one of the system table names.
Currently these are:
help_category, help_keyword, help_relation, help_topic, proc, event time_zone, time_zone_leap_second, time_zone_name, time_zone_transition, time_zone_transition_type
This function trades accuracy for speed, so may return false positives. Presumably mysql.* database is for internal purposes only and should not contain user tables.
|
static |
Auxiliary function which creates Field object from in-memory representation of .FRM file.
NOTES: This function is added to read .frm file in upgrade scenario. It should not be used any where else in the code. This function will be removed later.
thd | Connection context. | |
share | TABLE_SHARE for which Field object needs to be constructed. | |
frm_context | FRM_context for the structures removed from TABLE_SHARE. | |
new_frm_ver | .FRM file version. | |
field_idx | Field index in TABLE_SHARE::field array. | |
strpos | Pointer to part of .FRM's screens section describing the field to be created. | |
format_section_fields | Array where each byte contains packed values of COLUMN_FORMAT/STORAGE options for corresponding column. | |
[in,out] | comment_pos | Pointer to part of column comments section of .FRM which corresponds to current field. Advanced to the position corresponding to comment for the next column. |
[in,out] | gcol_screen_pos | Pointer to part of generated columns section of .FRM which corresponds to current generated field. If field to be created is generated advanced to the position for the next column |
[in,out] | null_pos | Current byte in the record preamble to be used for field's null/leftover bits if necessary. |
[in,out] | null_bit_pos | Current bit in the current preamble byte to be used for field's null/ leftover bits if necessary. |
[out] | errarg | Additional argument for the error to be reported. |
0 | Success. |
non-0 | Error number ( |
Return merged WHERE clause and join conditions for a view.
thd | thread handle | |
table | table for the VIEW | |
[out] | pcond | Pointer to the built condition (NULL if none) |
This function returns the result of ANDing the WHERE clause and the join conditions of the given view.
|
static |
Read data from a binary .frm file from MySQL 3.23 - 5.0 into TABLE_SHARE.
This function is added to read .frm file in upgrade scenario. It should not be used any where else in the code. This function will be removed later.
thd | thread handle |
share | TABLE_SHARE to be populated. |
frm_context | structures removed from TABLE_SHARE |
head | frm file header |
file | File handle |
|
static |
int open_table_from_share | ( | THD * | thd, |
TABLE_SHARE * | share, | ||
const char * | alias, | ||
uint | db_stat, | ||
uint | prgflag, | ||
uint | ha_open_flags, | ||
TABLE * | outparam, | ||
bool | is_create_table, | ||
const dd::Table * | table_def_param | ||
) |
Open a table based on a TABLE_SHARE.
thd | Thread handler |
share | Table definition |
alias | Alias for table |
db_stat | Open flags (for example HA_OPEN_KEYFILE| HA_OPEN_RNDFILE..) can be 0 (example in ha_example_table) |
prgflag | READ_ALL etc.. |
ha_open_flags | HA_OPEN_ABORT_IF_LOCKED etc.. |
outparam | Result table. |
is_create_table | Indicates that table is opened as part of CREATE or ALTER and does not yet exist in SE. |
table_def_param | dd::Table object describing the table to be opened in SE. Can be nullptr, which case this function will try to retrieve such object from the data-dictionary before opening table in SE. |
0 | ok |
1 | Error (see open_table_error) |
2 | Error (see open_table_error) |
4 | Error (see open_table_error) |
7 | Table definition has changed in engine |
8 | Table row format has changed in engine |
|
static |
Open and Read .frm file.
Based on header, it is decided if its a table or view. Prepare TABLE_SHARE if its a table. Prepare File_parser if its a view.
thd | thread handle |
share | TABLE_SHARE object to be filled. |
frm_context | FRM_context for structures removed from TABLE_SHARE |
table | table name |
is_fix_view_cols_and_deps | Flag to indicate that we are recreating view to create view dependency entry in DD tables |
true | Error |
false | Success |
0 | Sucess |
-1 | Error |
-2 | Less severe error, file can safely be ignored (used for ndbinfo tables when ndbinfo storage engine is not enabled) |
Read string from a file with malloc.
[in] | file | file handler |
[out] | to | pointer to read string |
[in] | length | length of string |
0 | Error |
1 | Success |
int rename_file_ext | ( | const char * | from, |
const char * | to, | ||
const char * | ext | ||
) |
Repoint a table's fields from old_rec to new_rec.
table | the table of fields needed to be repointed |
old_rec | the original record buffer fields point to |
new_rec | the target record buff fields need to repoint |
Save the contents of the "from" bitmap in "to".
int set_zone | ( | int | nr, |
int | min_zone, | ||
int | max_zone | ||
) |
void setup_key_part_field | ( | TABLE_SHARE * | share, |
handler * | handler_file, | ||
uint | primary_key_n, | ||
KEY * | keyinfo, | ||
uint | key_n, | ||
uint | key_part_n, | ||
uint * | usable_parts, | ||
bool | part_of_key_not_extended | ||
) |
Setup key-related fields of Field object for given key and key part.
[in] | share | Pointer to TABLE_SHARE |
[in] | handler_file | Pointer to handler |
[in] | primary_key_n | Primary key number |
[in] | keyinfo | Pointer to processed key |
[in] | key_n | Processed key number |
[in] | key_part_n | Processed key part number |
[in,out] | usable_parts | Pointer to usable_parts variable |
[in] | part_of_key_not_extended | Set when column is part of the Key and not appended by the storage engine from primary key columns. |
|
static |
Shift contents of 'map' one bit left from position start+1 and on.
|
static |
Check if 'key' is redundant.
This is the case if 'key' is a prefix of (or equal to) a key already present in 'share'.
share | The table share that 'key' refers to. |
key | The key we wish to check if is redundant. |
|
static |
Check if the derived key that is the head of 'tail' is redundant.
This is the case if that key is a (proper) prefix of a key later in 'tail'.
tail | An iterator into the list of derived keys, currently pointing to the key we wish to check against those later in the list. |
fields | The number of fields in the table. |
bool unpack_partition_info | ( | THD * | thd, |
TABLE * | outparam, | ||
TABLE_SHARE * | share, | ||
handlerton * | engine_type, | ||
bool | is_create_table | ||
) |
Unpack the partition expression.
Parse the partition expression to produce an Item.
[in] | thd | Thread handler |
[in] | outparam | Table object |
[in] | share | TABLE_SHARE object |
[in] | engine_type | Engine type of the partitions. |
[in] | is_create_table | Indicates that table is opened as part of CREATE or ALTER and does not yet exist in SE |
true | Failure. |
false | Success. |
bool unpack_value_generator | ( | THD * | thd, |
TABLE * | table, | ||
Value_generator ** | val_generator, | ||
Value_generator_source | source, | ||
const char * | source_name, | ||
Field * | field, | ||
bool | is_create_table, | ||
bool * | error_reported | ||
) |
Unpacks the definition of a value generator in all its forms: generated column, default expression or checked constraint.
The function parses the text definition of this expression, resolves its items and runs validation and calculates the base_columns_map which is used for tracking the columns the expression depends on.
[in] | thd | Thread handler |
[in] | table | Table having the value generator to be unpacked |
[in,out] | val_generator | Contains the expression in string format, and, if successful will be replaced by the parser with a new one having the unpacked expression. |
[in] | source | Source of value generator(a generated column, a regular column with generated default value or a check constraint). |
[in] | source_name | Name of the source (generated column, a regular column with generated default value or a check constraint). |
[in] | field | The column the value generator depends on. Can be null for checked constraints which do not depend on a single column. |
[in] | is_create_table | Indicates that table is opened as part of CREATE or ALTER and does not yet exist in SE |
[out] | error_reported | updated flag for the caller that no other error messages are to be generated. |
true | Failure. |
false | Success. |
void update_create_info_from_table | ( | HA_CREATE_INFO * | create_info, |
TABLE * | table | ||
) |
|
static |
Updates the values of the generated columns in the record buffer.
table | the table where the generated columns live | |
columns | bitmap of columns to update (typically table->read_set or table->write_set) | |
virtual_only | if true, only update virtual column; otherwise update both virtual and stored generated columns | |
[in,out] | updated_columns | a bitmap in which bits will be set for each column updated by this function, or nullptr if the caller doesn't care |
Evaluate necessary virtual generated columns.
This is used right after reading a row from the storage engine.
[in,out] | buf | the buffer to store data |
table | the TABLE object | |
active_index | the number of key for index scan (MAX_KEY is default) |
Calculate data for each generated field marked for write in the corresponding column map.
bitmap | Bitmap over fields to update |
table | the TABLE object |
false | Success |
true | Error occurred during the generation/calculation of a generated field value |
|
static |
Validate the expression to see whether there are invalid Item objects.
Needs to be done after fix_fields to allow checking references to other generated columns, default value expressions or check constraints.
expr | Pointer to the expression |
source | Source of value generator(a generated column, a regular column with generated default value or a check constraint). |
source_name | Name of the source (generated column, a regular column with generated default value or a check constraint). |
column_index | The column order. |
true | The generated expression has some invalid objects |
false | No illegal objects in the generated expression |
|
static |
LEX_CSTRING GENERAL_LOG_NAME = {STRING_WITH_LEN("general_log")} |
LEX_CSTRING GTID_EXECUTED_NAME = {STRING_WITH_LEN("gtid_executed")} |
LEX_CSTRING INFORMATION_SCHEMA_NAME = {STRING_WITH_LEN("information_schema")} |
LEX_CSTRING MI_INFO_NAME = {STRING_WITH_LEN("slave_master_info")} |
LEX_CSTRING MYSQL_SCHEMA_NAME = {STRING_WITH_LEN("mysql")} |
LEX_CSTRING MYSQL_TABLESPACE_NAME = {STRING_WITH_LEN("mysql")} |
LEX_CSTRING PARSE_GCOL_KEYWORD = {STRING_WITH_LEN("parse_gcol_expr")} |
LEX_CSTRING PERFORMANCE_SCHEMA_DB_NAME |
LEX_CSTRING RLI_INFO_NAME = {STRING_WITH_LEN("slave_relay_log_info")} |
LEX_CSTRING SLOW_LOG_NAME = {STRING_WITH_LEN("slow_log")} |
LEX_CSTRING WORKER_INFO_NAME = {STRING_WITH_LEN("slave_worker_info")} |