MySQL 9.1.0
Source Code Documentation
dict0upgrade.cc File Reference
#include "dict0upgrade.h"
#include <sql_backup_lock.h>
#include <sql_class.h>
#include <sql_show.h>
#include <sql_table.h>
#include <sql_tablespace.h>
#include <algorithm>
#include <regex>
#include "dict0boot.h"
#include "dict0crea.h"
#include "dict0dd.h"
#include "dict0dict.h"
#include "dict0load.h"
#include "ha_innodb.h"
#include "ha_innopart.h"
#include "log0buf.h"
#include "log0chkp.h"
#include "row0sel.h"
#include "srv0start.h"

Classes

struct  upgrade_space_t
 Tablespace information required to create a dd::Tablespace object. More...
 

Functions

static bool dd_upgrade_table_fk (dict_table_t *ib_table, dd::Table *dd_table)
 Fill foreign key information from InnoDB table to server table. More...
 
static dd::Tablespacedd_upgrade_get_tablespace (dd::cache::Dictionary_client *dd_client, dict_table_t *ib_table)
 Get Server Tablespace object for a InnoDB table. More...
 
static Fielddd_upgrade_get_field (const TABLE *srv_table, const char *name)
 Get field from Server table object. More...
 
static bool dd_has_explicit_pk (const dd::Table *dd_table)
 Return true if table has primary key given by user else false. More...
 
static bool dd_upgrade_match_single_col (const Field *field, const dict_col_t *col)
 Match InnoDB column object and Server column object. More...
 
static bool dd_upgrade_match_cols (const TABLE *srv_table, const dd::Table *dd_table, const dict_table_t *ib_table, bool skip_fts_col)
 
static uint32_t dd_upgrade_find_index (TABLE *srv_table, const char *name)
 Find key number from a server table object. More...
 
static bool dd_upgrade_match_index (TABLE *srv_table, dict_index_t *index)
 Match InnoDB index definition from Server object. More...
 
static bool dd_upgrade_check_for_autoinc (TABLE *srv_table, const char *&auto_inc_index_name, const char *&auto_inc_col_name)
 
static void dd_upgrade_set_auto_inc (const TABLE *srv_table, dd::Table *dd_table, uint64_t auto_inc_value)
 Set auto-inc field value in dd::Table object. More...
 
template<typename Index >
static void dd_upgrade_process_index (Index dd_index, dict_index_t *index, dd::Object_id dd_space_id, bool has_auto_inc, const char *auto_inc_index_name, const char *auto_inc_col_name, uint64_t *read_auto_inc)
 
static bool dd_upgrade_ensure_has_dd_space_id (THD *thd, dict_table_t *ib_table)
 Ensures that the ib_table->dd_space_id is properly initialized. More...
 
static bool dd_upgrade_partitions (THD *thd, const char *norm_name, dd::Table *dd_table, TABLE *srv_table)
 Migrate partitions to new dictionary. More...
 
static void dd_upgrade_set_row_type (dict_table_t *ib_table, dd::Table *dd_table)
 
bool dd_upgrade_fix_fts_column (dd::Table *dd_table, dict_table_t *ib_table)
 
bool dd_upgrade_table (THD *thd, const char *db_name, const char *table_name, dd::Table *dd_table, TABLE *srv_table)
 Migrate table from InnoDB Dictionary (INNODB SYS_*) tables to new Data Dictionary. More...
 
static uint32_t dd_upgrade_register_tablespace (dd::cache::Dictionary_client *dd_client, dd::Tablespace *dd_space, upgrade_space_t *upgrade_space)
 Register InnoDB tablespace to mysql dictionary table mysql.tablespaces. More...
 
int dd_upgrade_tablespace (THD *thd)
 Migrate tablespace entries from InnoDB SYS_TABLESPACES to new data dictionary. More...
 
bool upgrade_space_version (const uint32_t space_id, bool server_version_only)
 Add server and space version number to tablespace while upgrading. More...
 
bool upgrade_space_version (dd::Tablespace *tablespace)
 Add server version number to tablespace while upgrading. More...
 
int dd_upgrade_logs (THD *)
 Upgrade innodb undo logs after upgrade. More...
 
static void dd_upgrade_drop_sys_tables ()
 Drop all InnoDB Dictionary tables (SYS_*). More...
 
static void dd_upgrade_drop_57_backup_spaces ()
 Stat backup tables(innodb_*_stats_backup57) are created by server before upgrade and dropped after upgrade is successful. More...
 
static void dd_upgrade_fts_rename_cleanup (bool failed_upgrade)
 Rename back the FTS AUX tablespace names from 8.0 format to 5.7 format on upgrade failure, else mark FTS aux tables evictable. More...
 
int dd_upgrade_finish (THD *, bool failed_upgrade)
 If upgrade is successful, this API is used to flush innodb dirty pages to disk. More...
 

Variables

uint32_t dd_upgrade_indexes_num = 1
 
static std::vector< std::string > tables_with_fts
 Vector of tables that have FTS indexes. More...
 

Function Documentation

◆ dd_has_explicit_pk()

static bool dd_has_explicit_pk ( const dd::Table dd_table)
static

Return true if table has primary key given by user else false.

Parameters
[in]dd_tableServer table object
Return values
trueTable has PK given by user
falsePrimary Key is hidden and generated

◆ dd_upgrade_check_for_autoinc()

static bool dd_upgrade_check_for_autoinc ( TABLE srv_table,
const char *&  auto_inc_index_name,
const char *&  auto_inc_col_name 
)
static

◆ dd_upgrade_drop_57_backup_spaces()

static void dd_upgrade_drop_57_backup_spaces ( )
static

Stat backup tables(innodb_*_stats_backup57) are created by server before upgrade and dropped after upgrade is successful.

Innodb tablespaces for these tables still exists because InnoDB post DDL hook is skipped on bootstrap thread. This is a work around to cleanup the Innodb tablespaces till the time server could enable post DDL hook while dropping these tables.

◆ dd_upgrade_drop_sys_tables()

static void dd_upgrade_drop_sys_tables ( )
static

Drop all InnoDB Dictionary tables (SYS_*).

This is done only at the end of successful upgrade

◆ dd_upgrade_ensure_has_dd_space_id()

static bool dd_upgrade_ensure_has_dd_space_id ( THD thd,
dict_table_t ib_table 
)
static

Ensures that the ib_table->dd_space_id is properly initialized.

Parameters
[in]thdThe THD to identify as during lookup
[in]ib_tableThe instance to be initialized
Returns
true iff it succeeded

◆ dd_upgrade_find_index()

static uint32_t dd_upgrade_find_index ( TABLE srv_table,
const char *  name 
)
static

Find key number from a server table object.

Parameters
[in]srv_tableserver table object
[in]nameindex name
Return values
UINT32_MAXif index not found, else key number

◆ dd_upgrade_finish()

int dd_upgrade_finish ( THD thd,
bool  failed_upgrade 
)

If upgrade is successful, this API is used to flush innodb dirty pages to disk.

In case of server crash, this function sets storage engine for rollback any changes.

Parameters
[in,out]thdTHD
[in]failed_upgradetrue when upgrade failed
Returns
MySQL error code

◆ dd_upgrade_fix_fts_column()

bool dd_upgrade_fix_fts_column ( dd::Table dd_table,
dict_table_t ib_table 
)

◆ dd_upgrade_fts_rename_cleanup()

static void dd_upgrade_fts_rename_cleanup ( bool  failed_upgrade)
static

Rename back the FTS AUX tablespace names from 8.0 format to 5.7 format on upgrade failure, else mark FTS aux tables evictable.

Parameters
[in]failed_upgradetrue on upgrade failure, else false

◆ dd_upgrade_get_field()

static Field * dd_upgrade_get_field ( const TABLE srv_table,
const char *  name 
)
static

Get field from Server table object.

Parameters
[in]srv_tableserver table object
[in]nameField name
Returns
field object if found or null on failure.

◆ dd_upgrade_get_tablespace()

static dd::Tablespace * dd_upgrade_get_tablespace ( dd::cache::Dictionary_client dd_client,
dict_table_t ib_table 
)
static

Get Server Tablespace object for a InnoDB table.

The tablespace is acquired with MDL and for modification, so the caller can update the dd::Tablespace object returned.

Parameters
[in,out]dd_clientdictionary client to retrieve tablespace object
[in]ib_tableInnoDB table
Returns
dd::Tablespace object or nullptr

◆ dd_upgrade_logs()

int dd_upgrade_logs ( THD thd)

Upgrade innodb undo logs after upgrade.

Also increment the table_id offset by DICT_MAX_DD_TABLES. This offset increment is because the first 256 table_ids are reserved for dictionary.

Parameters
[in,out]thdTHD
Returns
MySQL error code

◆ dd_upgrade_match_cols()

static bool dd_upgrade_match_cols ( const TABLE srv_table,
const dd::Table dd_table,
const dict_table_t ib_table,
bool  skip_fts_col 
)
static

◆ dd_upgrade_match_index()

static bool dd_upgrade_match_index ( TABLE srv_table,
dict_index_t index 
)
static

Match InnoDB index definition from Server object.

Parameters
[in]srv_tableServer table object
[in]indexInnoDB index
Return values
falseIndex definition matches
trueIndex definition mismatch

◆ dd_upgrade_match_single_col()

static bool dd_upgrade_match_single_col ( const Field field,
const dict_col_t col 
)
static

Match InnoDB column object and Server column object.

Parameters
[in]fieldServer field object
[in]colInnoDB column object
Return values
falsecolumn definition matches
truecolumn definition mismatch

◆ dd_upgrade_partitions()

static bool dd_upgrade_partitions ( THD thd,
const char *  norm_name,
dd::Table dd_table,
TABLE srv_table 
)
static

Migrate partitions to new dictionary.

Parameters
[in]thdServer thread object
[in]norm_namepartition table name
[in,out]dd_tableServer new DD table object to be filled
[in]srv_tableServer table object
Returns
false on success, true on error

◆ dd_upgrade_process_index()

template<typename Index >
static void dd_upgrade_process_index ( Index  dd_index,
dict_index_t index,
dd::Object_id  dd_space_id,
bool  has_auto_inc,
const char *  auto_inc_index_name,
const char *  auto_inc_col_name,
uint64_t *  read_auto_inc 
)
static

◆ dd_upgrade_register_tablespace()

static uint32_t dd_upgrade_register_tablespace ( dd::cache::Dictionary_client dd_client,
dd::Tablespace dd_space,
upgrade_space_t upgrade_space 
)
static

Register InnoDB tablespace to mysql dictionary table mysql.tablespaces.

Parameters
[in]dd_clientdictionary client
[in]dd_spaceserver tablespace object
[in]upgrade_spaceupgrade tablespace object
Returns
0 on success, non-zero on error

◆ dd_upgrade_set_auto_inc()

static void dd_upgrade_set_auto_inc ( const TABLE srv_table,
dd::Table dd_table,
uint64_t  auto_inc_value 
)
static

Set auto-inc field value in dd::Table object.

Parameters
[in]srv_tableserver table object
[in,out]dd_tabledd table object to be filled
[in,out]auto_inc_valueauto_inc value

◆ dd_upgrade_set_row_type()

static void dd_upgrade_set_row_type ( dict_table_t ib_table,
dd::Table dd_table 
)
static

◆ dd_upgrade_table()

bool dd_upgrade_table ( THD thd,
const char *  db_name,
const char *  table_name,
dd::Table dd_table,
TABLE srv_table 
)

Migrate table from InnoDB Dictionary (INNODB SYS_*) tables to new Data Dictionary.

Since FTS tables contain table_id in their physical file name and during upgrade we reserve DICT_MAX_DD_TABLES for dictionary tables. So we rename FTS tablespace files

Parameters
[in]thdServer thread object
[in]db_namedatabase name
[in]table_nametable name
[in,out]dd_tablenew dictionary table object to be filled
[in]srv_tableserver table object
Returns
false on success, true on failure.

◆ dd_upgrade_table_fk()

static bool dd_upgrade_table_fk ( dict_table_t ib_table,
dd::Table dd_table 
)
static

Fill foreign key information from InnoDB table to server table.

Parameters
[in]ib_tableInnoDB table object
[in,out]dd_tableDD table object
Returns
false on success, otherwise true

◆ dd_upgrade_tablespace()

int dd_upgrade_tablespace ( THD thd)

Migrate tablespace entries from InnoDB SYS_TABLESPACES to new data dictionary.

FTS Tablespaces are not registered as they are handled differently. FTS tablespaces have table_id in their name and we increment table_id of each table by DICT_MAX_DD_TABLES

Parameters
[in,out]thdTHD
Returns
MySQL error code

◆ upgrade_space_version() [1/2]

bool upgrade_space_version ( const uint32_t  space_id,
bool  server_version_only 
)

Add server and space version number to tablespace while upgrading.

Parameters
[in]space_idspace id of tablespace
[in]server_version_onlyleave space version unchanged
Returns
false on success, true on failure.

◆ upgrade_space_version() [2/2]

bool upgrade_space_version ( dd::Tablespace tablespace)

Add server version number to tablespace while upgrading.

Parameters
[in]tablespacedd::Tablespace
Returns
false on success, true on failure.

Variable Documentation

◆ dd_upgrade_indexes_num

uint32_t dd_upgrade_indexes_num = 1

◆ tables_with_fts

std::vector<std::string> tables_with_fts
static

Vector of tables that have FTS indexes.

Used for reverting from 8.0 format FTS AUX table names to 5.7 FTS AUX table names