MySQL 9.1.0
Source Code Documentation
table.cc File Reference
#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_identcreate_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_SHAREalloc_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)
 

Macro Definition Documentation

◆ COLUMN_FORMAT_MASK

#define COLUMN_FORMAT_MASK   7

◆ COLUMN_FORMAT_SHIFT

#define COLUMN_FORMAT_SHIFT   3

◆ FIELD_NR_MASK

#define FIELD_NR_MASK   16383 /* To get fieldnumber */

◆ FIELDFLAG_ALFA_SCREEN_TYPE

#define FIELDFLAG_ALFA_SCREEN_TYPE   0x7800

◆ FIELDFLAG_BINARY

#define FIELDFLAG_BINARY   1

◆ FIELDFLAG_BITFIELD

#define FIELDFLAG_BITFIELD   512

◆ FIELDFLAG_BLOB

#define FIELDFLAG_BLOB   1024

◆ FIELDFLAG_DEC_SHIFT

#define FIELDFLAG_DEC_SHIFT   8

◆ FIELDFLAG_DECIMAL

#define FIELDFLAG_DECIMAL   1

◆ FIELDFLAG_FORMAT_NUMBER

#define FIELDFLAG_FORMAT_NUMBER   16384

◆ FIELDFLAG_GEOM

#define FIELDFLAG_GEOM   2048

◆ FIELDFLAG_INTERVAL

#define FIELDFLAG_INTERVAL   256

◆ FIELDFLAG_JSON

#define FIELDFLAG_JSON
Value:
4096 /* mangled with decimals and \
with bitfields! */

◆ FIELDFLAG_LEFT_FULLSCREEN

#define FIELDFLAG_LEFT_FULLSCREEN   8192

◆ FIELDFLAG_MAX_DEC

#define FIELDFLAG_MAX_DEC   31

◆ FIELDFLAG_MAYBE_NULL

#define FIELDFLAG_MAYBE_NULL   ((uint)32768)

◆ FIELDFLAG_NO_DEFAULT

#define FIELDFLAG_NO_DEFAULT   16384 /* sql */

◆ FIELDFLAG_NUM_SCREEN_TYPE

#define FIELDFLAG_NUM_SCREEN_TYPE   0x7F01

◆ FIELDFLAG_NUMBER

#define FIELDFLAG_NUMBER   2

◆ FIELDFLAG_PACK

#define FIELDFLAG_PACK   120

◆ FIELDFLAG_PACK_SHIFT

#define FIELDFLAG_PACK_SHIFT   3

◆ FIELDFLAG_RIGHT_FULLSCREEN

#define FIELDFLAG_RIGHT_FULLSCREEN   16384

◆ FIELDFLAG_SUM

#define FIELDFLAG_SUM   ((uint)32768)

◆ FIELDFLAG_TREAT_BIT_AS_CHAR

#define FIELDFLAG_TREAT_BIT_AS_CHAR   4096 /* use Field_bit_as_char */

◆ FIELDFLAG_ZEROFILL

#define FIELDFLAG_ZEROFILL   4

◆ MTYP_TYPENR

#define MTYP_TYPENR (   type)    (type & 127) /* Remove bits from type */

◆ STORAGE_TYPE_MASK

#define STORAGE_TYPE_MASK   7

Function Documentation

◆ add_derived_key()

static bool add_derived_key ( THD thd,
List< Derived_key > &  derived_key_list,
Field field,
table_map  ref_by_tbl 
)
static

A helper function to add a derived key to the list of possible keys.

Parameters
thdthread handler
derived_key_listlist of all possible derived keys
fieldreferenced field
ref_by_tblthe 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.

Note
Procedure of keys generation for result tables of materialized derived tables/views for allowing ref access to them.

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:

SELECT * FROM (SELECT f1, f2, count(*) FROM t1 GROUP BY f1) tt JOIN
t1 ON tt.f1=t1.f3 and tt.f2=t1.f4;
Definition: sql_optimizer.h:133
static int count
Definition: myisam_ftdump.cc:45
const std::string SELECT("SELECT")
Name of the static privileges.
@ FROM
Definition: sql_yacc.h:250
@ BY
Definition: sql_yacc.h:101

In this case for the derived table tt one key will be generated. It will consist of two parts f1 and f2. Example:

SELECT * FROM (SELECT f1, f2, count(*) FROM t1 GROUP BY f1) tt JOIN
t1 ON tt.f1=t1.f3 JOIN
t2 ON tt.f2=t2.f4;

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:

SELECT * FROM (SELECT f1, f2, count(*) FROM t1 GROUP BY f1) tt JOIN
t1 ON tt.f1=a_function(t1.f3);

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:

  1. gather information on all used fields of derived tables/view and store it in lists of possible keys, one per a derived table/view.
  2. add keys to result tables of derived tables/view using info from above lists. (...Planner selects best key...)
  3. drop unused keys from the table.

The above procedure is implemented in 4 functions:

  1. Table_ref::update_derived_keys() Create/extend list of possible keys for one derived table/view based on given field/used tables info. (Step one)
  2. JOIN::generate_derived_keys() This function is called from update_ref_and_keys when all possible info on keys is gathered and it's safe to add keys - no keys or key parts would be missed. Walk over list of derived tables/views and call to Table_ref::generate_keys to actually generate keys. (Step two)
  3. Table_ref::generate_keys() Walks over list of possible keys for this derived table/view to add keys to the result table. Calls to TABLE::add_tmp_key() to actually add keys (i.e. KEY objects in TABLE::key_info). (Step two)
  4. TABLE::add_tmp_key() Creates one index description according to given bitmap of used fields. (Step two) [ Planner runs and possibly chooses one key, stored in Key_use->key ] JOIN::finalize_derived_keys Walk over list of derived tables/views to destroy unused keys. (Step three)

This design is used for derived tables, views and CTEs. As a CTE can be multi-referenced, some points are worth noting:

Definitions

  • let's call the CTE 'X'
  • Key creation/deletion happens in a window between the start of update_derived_keys() and the end of finalize_derived_keys().

Key array locking

  • Evaluation of constant subqueries (and thus their optimization) may happen either before, inside, or after the window above: an example of "before": 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().
  • let's say that a being-optimized query block 'QB1' is entering that window; other query blocks are QB2, etc; let's say (subq) above is QB2, a subquery of QB1.
  • While QB1 is in this window, it is possible, as we saw above, that QB2 gets optimized. Because it is not safe to have two query blocks reading/writing possible keys for a same table at the same time, a locking mechanism is in place: TABLE_SHARE::owner_of_possible_tmp_keys is a record of which query block entered first the window for this table and hasn't left it yet; only that query block is allowed to read/write possible keys for this table.

Key array growth

  • let's say that a being-optimized query block 'QB1' is entering the window; other query blocks are QB2 (not necessarily the same QB2 as in previous paragraph), etc.
  • let's call "local" the references to X in QB1, let's call "nonlocal" the ones in other query blocks. For example,
with X(n) as (select 1)
select /+ QB_NAME(QB2) *_/ n from X as X2
where X2.n = (select /+* QB_NAME(QB1) *_/ X1.n from X as X1)
union
select n+2 from X as X3;
static char * where
Definition: mysqldump.cc:152
#define _(str)
Definition: win_i18n.h:33
#define X(b)
Definition: xcom_base.cc:9161
int n
Definition: xcom_base.cc:509

QB1 owns the window, then X1 is local, X2 and X3 are nonlocal.

  • when QB1 enters the window, update_derived_keys() starts for the local reference X1, other references to X may already have keys, defined by previously optimized query blocks on their references (e.g. QB2 on X2). At that stage the TABLE_SHARE::key_info array is of size TABLE_SHARE::keys, and the TABLE_SHARE::first_unused_tmp_key member points to 'where any new key should be added in this array', so it's equal to TABLE_SHARE::keys. Let's call the keys defined by QB2 the "existing keys": they exist at this point and will continue to do so. X2 in QB2 is already set up to read with such key. Here's the key_info array, with cell 0 to the left, "E" meaning "an existing key, created by previous optimizations", "-" meaning "an empty cell created by alloc_keys()".
EEEEEEEEEE-----------
          ^ s->first_unused_keys
          ^ s->keys
  • generate_keys() extends the key_info array and adds "possible" keys to the end. "Possible" is defined as "not yet existing", "might be dropped in the end". Even if a possible key is a duplicate of an existing key, it is added. TABLE_SHARE::keys is increased to include existing and possible keys. All TABLEs referencing X, local or not, are kept in sync (i.e. any possible key is added to all key_info arrays). But possible keys are set to be unusable by nonlocal references, so that the decision to drop those keys can be left to the window's owner. Key_info array now is ("P" means "possible key"):
EEEEEEEEEEPPPPPPP---
          ^ s->first_unused_keys
                 ^ s->keys
  • All possible keys are unused, at this stage.
  • Planner selects the best key for each local reference, among existing and possible keys, it is recorded in Key_use.
  • finalize_derived_keys() looks at local references, and gathers the list of (existing and possible) keys which the Planner has chosen for them. We call this list the list of locally-used keys, marked below with "!":
    !       !  !
EEEEEEEEEEPPPPPPP---
          ^ s->first_unused_keys
                 ^ s->keys
  • Any possible key which isn't locally-used is unnecessary.
  • finalize_derived_keys() re-organizes the possible locally-used keys and unnecessary keys, and does needed updates to TABLEs' bitmaps.
    !     !!
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
  • After that, another query block can be optimized.
  • So, query block after query block, optimization phases grow the key_info array.
  • If a reference is considered constant in a query block and the Optimizer decides to evaluate it, this triggers materialization (creation in engine), which freezes the key definition: other query blocks will not be allowed to add keys.
Return values
trueOOM
falseotherwise

◆ add_pk_parts_to_sk()

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.

Parameters
[in]skSecondary key
[in]sk_nSecondary key number
[in]pkPrimary key
[in]pk_nPrimary key number
[in]sharePointer to TABLE_SHARE
[in]handler_filePointer to handler
[in,out]usable_partsPointer to usable_parts variable
[in]use_extended_skTRUE if use_index_extensions is ON
Return values
Numberof added key parts

◆ alloc_table_share()

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.

Parameters
dbschema name.
table_nametable name.
keytable cache key (db \0 table_name \0...)
key_lengthlength of the key
open_secondarytrue if the TABLE_SHARE represents a table in a secondary storage engine
Returns
pointer to allocated table share
Return values
NULLerror (out of memory, too long path name)

◆ append_unescaped()

void append_unescaped ( String res,
const char *  pos,
size_t  length 
)

Store an SQL quoted string.

Parameters
resresult String
posstring to be quoted
lengthit's length

NOTE This function works correctly with utf8 or single-byte charset strings. May fail with some multibyte charsets though.

◆ assert_invalid_dict_is_locked()

bool assert_invalid_dict_is_locked ( const TABLE table)

Assert that LOCK_thd_data is held when TABLE::m_invalid_dict is accessed.

Parameters
tablepointer to TABLE object
Returns
true if the assertion holds, terminates the process otherwise

◆ assert_invalid_stats_is_locked()

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.

Parameters
tablepointer to TABLE object
Returns
true if the assertion holds, terminates the process otherwise

◆ assert_ref_count_is_locked()

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.

Parameters
sharethe TABLE_SHARE
Returns
true if the assertion holds, terminates the process otherwise

◆ check_and_convert_db_name()

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.

Parameters
org_nameName of database and length
preserve_lettercasePreserve lettercase if true
Note
If lower_case_table_names is true and preserve_lettercase is false then database is converted to lower case
Return values
Ident_name_check::OKIdentifier name is Ok (Success)
Ident_name_check::WRONGIdentifier name is Wrong (ER_WRONG_TABLE_NAME)
Ident_name_check::TOO_LONGIdentifier name is too long if it is greater than 64 characters (ER_TOO_LONG_IDENT)
Note
In case of Ident_name_check::WRONG and Ident_name_check::TOO_LONG, this function reports an error (my_error)

◆ check_column_name()

bool check_column_name ( const char *  name)

◆ check_db_name()

Ident_name_check check_db_name ( const char *  name,
size_t  length 
)

Check if database name is valid.

Parameters
nameName of database
lengthLength of name
Return values
Ident_name_check::OKIdentifier name is Ok (Success)
Ident_name_check::WRONGIdentifier name is Wrong (ER_WRONG_TABLE_NAME)
Ident_name_check::TOO_LONGIdentifier name is too long if it is greater than 64 characters (ER_TOO_LONG_IDENT)
Note
In case of Ident_name_check::WRONG and Ident_name_check::TOO_LONG, this function reports an error (my_error)

◆ check_table_name()

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.

Parameters
nameTable name
lengthLength of table name
Return values
Ident_name_check::OKIdentifier name is Ok (Success)
Ident_name_check::WRONGIdentifier name is Wrong (ER_WRONG_TABLE_NAME)
Ident_name_check::TOO_LONGIdentifier name is too long if it is greater than 64 characters (ER_TOO_LONG_IDENT)
Note
Reporting error to the user is the responsibility of the caller.

◆ closefrm()

int closefrm ( TABLE table,
bool  free_share 
)

Free information allocated by openfrm.

Parameters
tableTABLE object to free
free_shareIs 1 if we also want to free table_share

◆ create_key_part_field_with_prefix_length()

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.

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

◆ create_table_share_for_upgrade()

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.

Parameters
[in]thdThread handle.
[in]pathPath of the frm file.
[out]shareTABLE_SHARE to be populated.
[out]frm_contextFRM_context object.
[in]dbDatabase name.
[in]tableTable name.
[in]is_fix_view_cols_and_depsFix view column data, table and routine dependency.
Return values
0ON SUCCESS
-1ON FAILURE
-2ON LESS SEVER FAILURE (see read_frm_file)

◆ create_view_field()

static Item_ident * create_view_field ( THD thd,
Table_ref view,
Item **  field_ref,
const char *  name,
Name_resolution_context context 
)
static

◆ Derived_key_comp()

static int Derived_key_comp ( Derived_key e1,
Derived_key e2 
)
static

◆ f_bit_as_char()

int f_bit_as_char ( int  x)
inline

◆ f_decimals()

uint8 f_decimals ( int  x)
inline

◆ f_is_alpha()

int f_is_alpha ( int  x)
inline

◆ f_is_binary()

int f_is_binary ( int  x)
inline

◆ f_is_bitfield()

int f_is_bitfield ( int  x)
inline

◆ f_is_blob()

int f_is_blob ( int  x)
inline

◆ f_is_dec()

int f_is_dec ( int  x)
inline

◆ f_is_enum()

int f_is_enum ( int  x)
inline

◆ f_is_equ()

int f_is_equ ( int  x)
inline

◆ f_is_geom()

int f_is_geom ( int  x)
inline

◆ f_is_json()

int f_is_json ( int  x)
inline

◆ f_is_num()

int f_is_num ( int  x)
inline

◆ f_is_packed()

int f_is_packed ( int  x)
inline

◆ f_is_zerofill()

int f_is_zerofill ( int  x)
inline

◆ f_maybe_null()

int f_maybe_null ( int  x)
inline

◆ f_no_default()

int f_no_default ( int  x)
inline

◆ f_packtype()

int f_packtype ( int  x)
inline

◆ f_settype()

int f_settype ( int  x)
inline

◆ find_field()

static uint find_field ( Field **  fields,
uchar record,
uint  start,
uint  length 
)
static

Search after a field with given start & length If an exact field isn't found, return longest field with starts at right position.

Note
This is needed because in some .frm fields 'fieldnr' was saved wrong. 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.
Return values
0error
fieldnumber +1 success

◆ fix_type_pointers()

static void fix_type_pointers ( const char ***  array,
TYPELIB point_to_type,
uint  types,
char **  names 
)
static

fix a str_type to a array type typeparts separated with some char.

different types are separated with a '\0'

Note
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.
Parameters
[out]arrayPointer to interval array
[in]point_to_typePointer to intervals
[in]typesnumber of intervals
[out]namesname of intervals

◆ fix_value_generator_fields()

static bool fix_value_generator_fields ( THD thd,
TABLE table,
Value_generator val_generator,
Value_generator_source  source,
const char *  source_name,
Field field 
)
static

Resolve the generated expression, generated default value of the column or check constraint expression.

Parameters
thdThe thread object
tableThe table to which the column belongs
val_generatorThe expression to resolve
sourceSource of value generator(a generated column, a regular column with generated default value or a check constraint).
source_nameName of the source (generated column, a regular column with generated default value or a check constraint).
fieldField to which the val_generator is attached to for generated columns and default expression.
Return values
trueAn error occurred, something was wrong with the function.
falseOk, generated expression is fixed successfully

◆ fn_rext()

char * fn_rext ( char *  name)

Returns pointer to '.frm' extension of the file name.

Parameters
namefile name

Checks file name part starting with the rightmost '.' character, and returns it if it is equal to '.frm'.

Returns
Pointer to the '.frm' extension. If there is no extension, or extension is not '.frm', pointer at the end of file name.

◆ free_blob_buffers_and_reset()

void free_blob_buffers_and_reset ( TABLE table,
uint32  size 
)

Reclaims temporary blob storage which is bigger than a threshold.

Resets blob pointer. Unsets m_keep_old_value.

Parameters
tableA handle to the TABLE object containing blob fields
sizeThe threshold value.

◆ free_blobs()

void free_blobs ( TABLE table)

◆ free_table_share()

void free_table_share ( TABLE_SHARE share)

Free table share and memory used by it.

Parameters
shareTable share

◆ get_field() [1/2]

char * get_field ( MEM_ROOT mem,
Field field 
)

Allocate string field in MEM_ROOT and return it as NULL-terminated string.

Parameters
memMEM_ROOT for allocating
fieldField for retrieving of string
Return values
NullSstring is empty
otherpointer to NULL-terminated string value of field

◆ get_field() [2/2]

bool get_field ( MEM_ROOT mem,
Field field,
String res 
)

Allocate string field in MEM_ROOT and return it as String.

Parameters
memMEM_ROOT for allocating
fieldField for retrieving of string
resresult String
Return values
1string is empty
0all ok

◆ get_form_pos()

static ulong get_form_pos ( File  file,
uchar head 
)
static

Find where a form starts.

Note
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.
Parameters
[in]fileFile handler
[in]headThe start of the form file.
Remarks
If formname is NULL then only formnames is read.
Return values
Theform position.

◆ get_table_category()

TABLE_CATEGORY get_table_category ( const LEX_CSTRING db,
const LEX_CSTRING name 
)

◆ init_mdl_requests()

void init_mdl_requests ( Table_ref table_list)

Helper function which allows to allocate metadata lock request objects for all elements of table list.

◆ init_tmp_table_share()

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.

Parameters
thdthread handle
shareShare to fill
keyTable_cache_key, as generated from create_table_def_key. must start with db name.
key_lengthLength of key
table_nameTable name
pathPath to file (possible in lower case) without .frm
mem_rootMEM_ROOT to transfer (move) to the TABLE_SHARE; if NULL a new one is initialized.
Note
This is different from alloc_table_share() because temporary tables don't have to be shared between threads or put into the table def cache, so we can do some things notable simpler and faster

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).

◆ is_simple_order()

bool is_simple_order ( ORDER order)

Test if the order list consists of simple field expressions.

Parameters
orderLinked list of ORDER BY arguments
Returns
true if order is empty or consist of simple field expressions

◆ is_system_table_name()

bool is_system_table_name ( const char *  name,
size_t  length 
)
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.

◆ make_field_from_frm()

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 
)
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.

Parameters
thdConnection context.
shareTABLE_SHARE for which Field object needs to be constructed.
frm_contextFRM_context for the structures removed from TABLE_SHARE.
new_frm_ver.FRM file version.
field_idxField index in TABLE_SHARE::field array.
strposPointer to part of .FRM's screens section describing the field to be created.
format_section_fieldsArray where each byte contains packed values of COLUMN_FORMAT/STORAGE options for corresponding column.
[in,out]comment_posPointer 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_posPointer 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_posCurrent byte in the record preamble to be used for field's null/leftover bits if necessary.
[in,out]null_bit_posCurrent bit in the current preamble byte to be used for field's null/ leftover bits if necessary.
[out]errargAdditional argument for the error to be reported.
Return values
0Success.
non-0Error number (
See also
open_table_def() for details).

◆ merge_join_conditions()

static bool merge_join_conditions ( THD thd,
Table_ref table,
Item **  pcond 
)
static

Return merged WHERE clause and join conditions for a view.

Parameters
thdthread handle
tabletable for the VIEW
[out]pcondPointer 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.

Returns
false for success, true for error

◆ open_binary_frm()

static int open_binary_frm ( THD thd,
TABLE_SHARE share,
FRM_context frm_context,
uchar head,
File  file 
)
static

Read data from a binary .frm file from MySQL 3.23 - 5.0 into TABLE_SHARE.

Note
Much of the logic here is duplicated in create_tmp_table() (see sql_select.cc). Hence, changes to this function may have to be repeated there.

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.

Parameters
thdthread handle
shareTABLE_SHARE to be populated.
frm_contextstructures removed from TABLE_SHARE
headfrm file header
fileFile handle

◆ open_table_error()

static void open_table_error ( THD thd,
TABLE_SHARE share,
int  error,
int  db_errno 
)
static

◆ open_table_from_share()

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.

Parameters
thdThread handler
shareTable definition
aliasAlias for table
db_statOpen flags (for example HA_OPEN_KEYFILE| HA_OPEN_RNDFILE..) can be 0 (example in ha_example_table)
prgflagREAD_ALL etc..
ha_open_flagsHA_OPEN_ABORT_IF_LOCKED etc..
outparamResult table.
is_create_tableIndicates that table is opened as part of CREATE or ALTER and does not yet exist in SE.
table_def_paramdd::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.
Return values
0ok
1Error (see open_table_error)
2Error (see open_table_error)
4Error (see open_table_error)
7Table definition has changed in engine
8Table row format has changed in engine

◆ read_frm_file()

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 
)
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.

Parameters
thdthread handle
shareTABLE_SHARE object to be filled.
frm_contextFRM_context for structures removed from TABLE_SHARE
tabletable name
is_fix_view_cols_and_depsFlag to indicate that we are recreating view to create view dependency entry in DD tables
Return values
trueError
falseSuccess
0Sucess
-1Error
-2Less severe error, file can safely be ignored (used for ndbinfo tables when ndbinfo storage engine is not enabled)

◆ read_string()

static int read_string ( File  file,
uchar **  to,
size_t  length 
)
static

Read string from a file with malloc.

Note
We add an \0 at end of the read string to make reading of C strings easier. 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.
Parameters
[in]filefile handler
[out]topointer to read string
[in]lengthlength of string
Return values
0Error
1Success

◆ rename_file_ext()

int rename_file_ext ( const char *  from,
const char *  to,
const char *  ext 
)

◆ repoint_field_to_record()

void repoint_field_to_record ( TABLE table,
uchar old_rec,
uchar new_rec 
)

Repoint a table's fields from old_rec to new_rec.

Parameters
tablethe table of fields needed to be repointed
old_recthe original record buffer fields point to
new_recthe target record buff fields need to repoint

◆ save_bitmap()

static bool save_bitmap ( MEM_ROOT mem_root,
const MY_BITMAP from,
MY_BITMAP to 
)
static

Save the contents of the "from" bitmap in "to".

◆ set_zone()

int set_zone ( int  nr,
int  min_zone,
int  max_zone 
)

◆ setup_key_part_field()

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.

Parameters
[in]sharePointer to TABLE_SHARE
[in]handler_filePointer to handler
[in]primary_key_nPrimary key number
[in]keyinfoPointer to processed key
[in]key_nProcessed key number
[in]key_part_nProcessed key part number
[in,out]usable_partsPointer to usable_parts variable
[in]part_of_key_not_extendedSet when column is part of the Key and not appended by the storage engine from primary key columns.

◆ ShiftTailLeft()

static void ShiftTailLeft ( Key_map map,
uint  start 
)
static

Shift contents of 'map' one bit left from position start+1 and on.

◆ SupersededByKeyInShare()

static bool SupersededByKeyInShare ( const TABLE_SHARE share,
const Derived_key key 
)
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'.

Parameters
shareThe table share that 'key' refers to.
keyThe key we wish to check if is redundant.
Returns
'true' if 'key' is redundant.

◆ SupersededByLaterKey()

static bool SupersededByLaterKey ( List_iterator< Derived_key tail,
uint  fields 
)
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'.

Parameters
tailAn iterator into the list of derived keys, currently pointing to the key we wish to check against those later in the list.
fieldsThe number of fields in the table.
Returns
'true' if the head of 'tail' is redundant.

◆ unpack_partition_info()

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.

Parameters
[in]thdThread handler
[in]outparamTable object
[in]shareTABLE_SHARE object
[in]engine_typeEngine type of the partitions.
[in]is_create_tableIndicates that table is opened as part of CREATE or ALTER and does not yet exist in SE
Return values
trueFailure.
falseSuccess.

◆ unpack_value_generator()

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.

Parameters
[in]thdThread handler
[in]tableTable having the value generator to be unpacked
[in,out]val_generatorContains the expression in string format, and, if successful will be replaced by the parser with a new one having the unpacked expression.
[in]sourceSource of value generator(a generated column, a regular column with generated default value or a check constraint).
[in]source_nameName of the source (generated column, a regular column with generated default value or a check constraint).
[in]fieldThe column the value generator depends on. Can be null for checked constraints which do not depend on a single column.
[in]is_create_tableIndicates that table is opened as part of CREATE or ALTER and does not yet exist in SE
[out]error_reportedupdated flag for the caller that no other error messages are to be generated.
Return values
trueFailure.
falseSuccess.

◆ update_create_info_from_table()

void update_create_info_from_table ( HA_CREATE_INFO create_info,
TABLE table 
)

◆ update_generated_columns()

static bool update_generated_columns ( TABLE table,
const MY_BITMAP columns,
bool  virtual_only,
MY_BITMAP updated_columns 
)
static

Updates the values of the generated columns in the record buffer.

Parameters
tablethe table where the generated columns live
columnsbitmap of columns to update (typically table->read_set or table->write_set)
virtual_onlyif true, only update virtual column; otherwise update both virtual and stored generated columns
[in,out]updated_columnsa bitmap in which bits will be set for each column updated by this function, or nullptr if the caller doesn't care
Returns
true on error, false on success

◆ update_generated_read_fields()

bool update_generated_read_fields ( uchar buf,
TABLE table,
uint  active_index 
)

Evaluate necessary virtual generated columns.

This is used right after reading a row from the storage engine.

Note
this is not necessary for stored generated columns, as they are provided by the storage engine.
Parameters
[in,out]bufthe buffer to store data
tablethe TABLE object
active_indexthe number of key for index scan (MAX_KEY is default)
Returns
true if error.

◆ update_generated_write_fields()

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.

Note
We need calculate data for both virtual and stored generated fields.
Parameters
bitmapBitmap over fields to update
tablethe TABLE object
Return values
falseSuccess
trueError occurred during the generation/calculation of a generated field value

◆ validate_value_generator_expr()

static bool validate_value_generator_expr ( Item expr,
Value_generator_source  source,
const char *  source_name,
int  column_index 
)
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.

Parameters
exprPointer to the expression
sourceSource of value generator(a generated column, a regular column with generated default value or a check constraint).
source_nameName of the source (generated column, a regular column with generated default value or a check constraint).
column_indexThe column order.
Return values
trueThe generated expression has some invalid objects
falseNo illegal objects in the generated expression

Variable Documentation

◆ FRM_VER

const longlong FRM_VER = 6
static

◆ FRM_VER_TRUE_VARCHAR

const longlong FRM_VER_TRUE_VARCHAR = (FRM_VER + 4)
static

◆ GENERAL_LOG_NAME

LEX_CSTRING GENERAL_LOG_NAME = {STRING_WITH_LEN("general_log")}

◆ GTID_EXECUTED_NAME

LEX_CSTRING GTID_EXECUTED_NAME = {STRING_WITH_LEN("gtid_executed")}

◆ INFORMATION_SCHEMA_NAME

LEX_CSTRING INFORMATION_SCHEMA_NAME = {STRING_WITH_LEN("information_schema")}

◆ MI_INFO_NAME

LEX_CSTRING MI_INFO_NAME = {STRING_WITH_LEN("slave_master_info")}

◆ MYSQL_SCHEMA_NAME

LEX_CSTRING MYSQL_SCHEMA_NAME = {STRING_WITH_LEN("mysql")}

◆ MYSQL_TABLESPACE_NAME

LEX_CSTRING MYSQL_TABLESPACE_NAME = {STRING_WITH_LEN("mysql")}

◆ PARSE_GCOL_KEYWORD

LEX_CSTRING PARSE_GCOL_KEYWORD = {STRING_WITH_LEN("parse_gcol_expr")}

◆ PERFORMANCE_SCHEMA_DB_NAME

LEX_CSTRING PERFORMANCE_SCHEMA_DB_NAME
Initial value:
= {
STRING_WITH_LEN("performance_schema")}
#define STRING_WITH_LEN(X)
Definition: string_with_len.h:29

◆ RLI_INFO_NAME

LEX_CSTRING RLI_INFO_NAME = {STRING_WITH_LEN("slave_relay_log_info")}

◆ SLOW_LOG_NAME

LEX_CSTRING SLOW_LOG_NAME = {STRING_WITH_LEN("slow_log")}

◆ WORKER_INFO_NAME

LEX_CSTRING WORKER_INFO_NAME = {STRING_WITH_LEN("slave_worker_info")}