mirror of
https://github.com/MariaDB/server.git
synced 2025-01-30 18:41:56 +01:00
e572c745dc
ha_innobase::referenced_by_foreign_key(): Protect the check with dict_sys.freeze(), to prevent races with TRUNCATE TABLE. The test innodb.instant_alter_crash has been adjusted for this additional locking. dict_table_is_referenced_by_foreign_key(): Removed (merged to the only caller). create_table_info_t::create_table(): Ignore missing indexes for FOREIGN KEY constraints if foreign_key_checks=0. create_table_info_t::create_table_update_dict(): Rewritten as a static function. Do not return any error. ha_innobase::create(): When trx!=nullptr and we are operating on a persistent table, do not rollback, commit, or release the data dictionary latch. ha_innobase::truncate(): Protect the entire critical section with an exclusive dict_sys.latch, so that ha_innobase::referenced_by_foreign_key() on referenced tables will return a consistent result. In case of a failure, invoke dict_load_foreigns() to restore also any FOREIGN KEY constraints. ha_innobase::free_foreign_key_create_info(): Define inline. lock_release(): Disregard innodb_evict_tables_on_commit_debug=ON when dict_sys.locked() holds. It would hold when fts_load_stopword() is invoked by create_table_info_t::create_table_update_dict(). dict_sys_t::locked(): Return whether the current thread is holding the exclusive dict_sys.latch. dict_sys_t::frozen_not_locked(): Return whether any thread is holding a shared dict_sys.latch. In the test main.mysql_upgrade, the InnoDB persistent statistics will no longer be recalculated in ha_innobase::open() as part of CHECK TABLE ... FOR UPGRADE. They were deleted earlier in the test. Tested by: Matthias Leich
220 lines
8.8 KiB
C++
220 lines
8.8 KiB
C++
/*****************************************************************************
|
|
|
|
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
|
|
Copyright (c) 2017, 2022, MariaDB Corporation.
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA
|
|
|
|
*****************************************************************************/
|
|
|
|
/**************************************************//**
|
|
@file include/dict0load.h
|
|
Loads to the memory cache database object definitions
|
|
from dictionary tables
|
|
|
|
Created 4/24/1996 Heikki Tuuri
|
|
*******************************************************/
|
|
|
|
#ifndef dict0load_h
|
|
#define dict0load_h
|
|
|
|
#include "dict0types.h"
|
|
#include "trx0types.h"
|
|
#include "ut0byte.h"
|
|
#include "mem0mem.h"
|
|
#include "btr0types.h"
|
|
|
|
#include <deque>
|
|
|
|
/** A stack of table names related through foreign key constraints */
|
|
typedef std::deque<const char*, ut_allocator<const char*> > dict_names_t;
|
|
|
|
/** Check each tablespace found in the data dictionary.
|
|
Then look at each table defined in SYS_TABLES that has a space_id > 0
|
|
to find all the file-per-table tablespaces.
|
|
|
|
In a crash recovery we already have some tablespace objects created from
|
|
processing the REDO log. We will compare the
|
|
space_id information in the data dictionary to what we find in the
|
|
tablespace file. In addition, more validation will be done if recovery
|
|
was needed and force_recovery is not set.
|
|
|
|
We also scan the biggest space id, and store it to fil_system. */
|
|
void dict_check_tablespaces_and_store_max_id();
|
|
|
|
/** Make sure the data_file_name is saved in dict_table_t if needed.
|
|
@param[in,out] table Table object */
|
|
void dict_get_and_save_data_dir_path(dict_table_t* table);
|
|
|
|
/***********************************************************************//**
|
|
Loads a table object based on the table id.
|
|
@return table; NULL if table does not exist */
|
|
dict_table_t*
|
|
dict_load_table_on_id(
|
|
/*==================*/
|
|
table_id_t table_id, /*!< in: table id */
|
|
dict_err_ignore_t ignore_err); /*!< in: errors to ignore
|
|
when loading the table */
|
|
/********************************************************************//**
|
|
This function is called when the database is booted.
|
|
Loads system table index definitions except for the clustered index which
|
|
is added to the dictionary cache at booting before calling this function. */
|
|
void
|
|
dict_load_sys_table(
|
|
/*================*/
|
|
dict_table_t* table); /*!< in: system table */
|
|
/***********************************************************************//**
|
|
Loads foreign key constraints where the table is either the foreign key
|
|
holder or where the table is referenced by a foreign key. Adds these
|
|
constraints to the data dictionary.
|
|
|
|
The foreign key constraint is loaded only if the referenced table is also
|
|
in the dictionary cache. If the referenced table is not in dictionary
|
|
cache, then it is added to the output parameter (fk_tables).
|
|
|
|
@return DB_SUCCESS or error code */
|
|
dberr_t
|
|
dict_load_foreigns(
|
|
/*===============*/
|
|
const char* table_name, /*!< in: table name */
|
|
const char** col_names, /*!< in: column names, or NULL
|
|
to use table->col_names */
|
|
trx_id_t trx_id, /*!< in: DDL transaction id,
|
|
or 0 to check
|
|
recursive load of tables
|
|
chained by FK */
|
|
bool check_charsets, /*!< in: whether to check
|
|
charset compatibility */
|
|
dict_err_ignore_t ignore_err, /*!< in: error to be ignored */
|
|
dict_names_t& fk_tables) /*!< out: stack of table names
|
|
which must be loaded
|
|
subsequently to load all the
|
|
foreign key constraints. */
|
|
MY_ATTRIBUTE((nonnull(1)));
|
|
|
|
/********************************************************************//**
|
|
This function opens a system table, and return the first record.
|
|
@return first record of the system table */
|
|
const rec_t*
|
|
dict_startscan_system(
|
|
/*==================*/
|
|
btr_pcur_t* pcur, /*!< out: persistent cursor to
|
|
the record */
|
|
mtr_t* mtr, /*!< in: the mini-transaction */
|
|
dict_table_t* table); /*!< in: system table */
|
|
/********************************************************************//**
|
|
This function get the next system table record as we scan the table.
|
|
@return the record if found, NULL if end of scan. */
|
|
const rec_t*
|
|
dict_getnext_system(
|
|
/*================*/
|
|
btr_pcur_t* pcur, /*!< in/out: persistent cursor
|
|
to the record */
|
|
mtr_t* mtr); /*!< in: the mini-transaction */
|
|
|
|
/** Load a table definition from a SYS_TABLES record to dict_table_t.
|
|
Do not load any columns or indexes.
|
|
@param[in,out] mtr mini-transaction
|
|
@param[in] uncommitted whether to use READ UNCOMMITTED isolation level
|
|
@param[in] rec SYS_TABLES record
|
|
@param[out,own] table table, or nullptr
|
|
@return error message
|
|
@retval nullptr on success */
|
|
const char *dict_load_table_low(mtr_t *mtr, bool uncommitted,
|
|
const rec_t *rec, dict_table_t **table)
|
|
MY_ATTRIBUTE((nonnull, warn_unused_result));
|
|
|
|
/********************************************************************//**
|
|
This function parses a SYS_INDEXES record and populate a dict_index_t
|
|
structure with the information from the record. For detail information
|
|
about SYS_INDEXES fields, please refer to dict_boot() function.
|
|
@return error message, or NULL on success */
|
|
const char*
|
|
dict_process_sys_indexes_rec(
|
|
/*=========================*/
|
|
mem_heap_t* heap, /*!< in/out: heap memory */
|
|
const rec_t* rec, /*!< in: current SYS_INDEXES rec */
|
|
dict_index_t* index, /*!< out: dict_index_t to be
|
|
filled */
|
|
table_id_t* table_id); /*!< out: table id */
|
|
/********************************************************************//**
|
|
This function parses a SYS_COLUMNS record and populate a dict_column_t
|
|
structure with the information from the record.
|
|
@return error message, or NULL on success */
|
|
const char*
|
|
dict_process_sys_columns_rec(
|
|
/*=========================*/
|
|
mem_heap_t* heap, /*!< in/out: heap memory */
|
|
const rec_t* rec, /*!< in: current SYS_COLUMNS rec */
|
|
dict_col_t* column, /*!< out: dict_col_t to be filled */
|
|
table_id_t* table_id, /*!< out: table id */
|
|
const char** col_name, /*!< out: column name */
|
|
ulint* nth_v_col); /*!< out: if virtual col, this is
|
|
records its sequence number */
|
|
|
|
/** This function parses a SYS_VIRTUAL record and extract virtual column
|
|
information
|
|
@param[in,out] heap heap memory
|
|
@param[in] rec current SYS_COLUMNS rec
|
|
@param[in,out] table_id table id
|
|
@param[in,out] pos virtual column position
|
|
@param[in,out] base_pos base column position
|
|
@return error message, or NULL on success */
|
|
const char*
|
|
dict_process_sys_virtual_rec(
|
|
const rec_t* rec,
|
|
table_id_t* table_id,
|
|
ulint* pos,
|
|
ulint* base_pos);
|
|
/********************************************************************//**
|
|
This function parses a SYS_FIELDS record and populate a dict_field_t
|
|
structure with the information from the record.
|
|
@return error message, or NULL on success */
|
|
const char*
|
|
dict_process_sys_fields_rec(
|
|
/*========================*/
|
|
mem_heap_t* heap, /*!< in/out: heap memory */
|
|
const rec_t* rec, /*!< in: current SYS_FIELDS rec */
|
|
dict_field_t* sys_field, /*!< out: dict_field_t to be
|
|
filled */
|
|
ulint* pos, /*!< out: Field position */
|
|
index_id_t* index_id, /*!< out: current index id */
|
|
index_id_t last_id); /*!< in: previous index id */
|
|
/********************************************************************//**
|
|
This function parses a SYS_FOREIGN record and populate a dict_foreign_t
|
|
structure with the information from the record. For detail information
|
|
about SYS_FOREIGN fields, please refer to dict_load_foreign() function
|
|
@return error message, or NULL on success */
|
|
const char*
|
|
dict_process_sys_foreign_rec(
|
|
/*=========================*/
|
|
mem_heap_t* heap, /*!< in/out: heap memory */
|
|
const rec_t* rec, /*!< in: current SYS_FOREIGN rec */
|
|
dict_foreign_t* foreign); /*!< out: dict_foreign_t to be
|
|
filled */
|
|
/********************************************************************//**
|
|
This function parses a SYS_FOREIGN_COLS record and extract necessary
|
|
information from the record and return to caller.
|
|
@return error message, or NULL on success */
|
|
const char*
|
|
dict_process_sys_foreign_col_rec(
|
|
/*=============================*/
|
|
mem_heap_t* heap, /*!< in/out: heap memory */
|
|
const rec_t* rec, /*!< in: current SYS_FOREIGN_COLS rec */
|
|
const char** name, /*!< out: foreign key constraint name */
|
|
const char** for_col_name, /*!< out: referencing column name */
|
|
const char** ref_col_name, /*!< out: referenced column name
|
|
in referenced table */
|
|
ulint* pos); /*!< out: column position */
|
|
|
|
#endif
|