MySQL  8.0.20
Source Code Documentation
dict0load.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2019, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/dict0load.h
28  Loads to the memory cache database object definitions
29  from dictionary tables
30 
31  Created 4/24/1996 Heikki Tuuri
32  *******************************************************/
33 
34 #ifndef dict0load_h
35 #define dict0load_h
36 
37 #include "btr0types.h"
38 #include "dict0types.h"
39 #include "fil0fil.h"
40 #include "mem0mem.h"
41 #include "trx0types.h"
42 #include "univ.i"
43 #include "ut0byte.h"
44 #include "ut0new.h"
45 
46 #include <deque>
47 
48 /** A stack of table names related through foreign key constraints */
49 typedef std::deque<const char *, ut_allocator<const char *>> dict_names_t;
50 
51 /** enum that defines all system table IDs. @see SYSTEM_TABLE_NAME[] */
62 
63  /* This must be last item. Defines the number of system tables. */
65 };
66 
67 /** Status bit for dict_process_sys_tables_rec_and_mtr_commit() */
69  DICT_TABLE_LOAD_FROM_RECORD = 0, /*!< Directly populate a dict_table_t
70  structure with information from
71  a SYS_TABLES record */
72  DICT_TABLE_LOAD_FROM_CACHE = 1 /*!< Check first whether dict_table_t
73  is in the cache, if so, return it */
74 };
75 
76 extern const char *SYSTEM_TABLE_NAME[];
77 
78 /** Finds the first table name in the given database.
79  @return own: table name, NULL if does not exist; the caller must free
80  the memory in the string! */
82  const char *name); /*!< in: database name which ends to '/' */
83 
84 /** Get the first filepath from SYS_DATAFILES for a given space_id.
85 @param[in] space_id Tablespace ID
86 @return First filepath (caller must invoke ut_free() on it)
87 @retval NULL if no SYS_DATAFILES entry was found. */
88 char *dict_get_first_path(ulint space_id);
89 
90 /** Make sure the data_file_name is saved in dict_table_t if needed.
91 Try to read it from the fil_system first, then from SYS_DATAFILES.
92 @param[in] table Table object
93 @param[in] dict_mutex_own true if dict_sys->mutex is owned already */
94 void dict_get_and_save_data_dir_path(dict_table_t *table, bool dict_mutex_own);
95 
96 /** Make sure the tablespace name is saved in dict_table_t if needed.
97 Try to read it from the file dictionary first, then from SYS_TABLESPACES.
98 @param[in] table Table object
99 @param[in] dict_mutex_own true if dict_sys->mutex is owned already */
100 void dict_get_and_save_space_name(dict_table_t *table, bool dict_mutex_own);
101 
102 /** Loads a table definition and also all its index definitions, and also
103 the cluster definition if the table is a member in a cluster. Also loads
104 all foreign key constraints where the foreign key is in the table or where
105 a foreign key references columns in this table.
106 @param[in] name Table name in the dbname/tablename format
107 @param[in] cached true=add to cache, false=do not
108 @param[in] ignore_err Error to be ignored when loading
109  table and its index definition
110 @return table, NULL if does not exist; if the table is stored in an
111 .ibd file, but the file does not exist, then we set the ibd_file_missing
112 flag in the table object we return. */
113 dict_table_t *dict_load_table(const char *name, bool cached,
114  dict_err_ignore_t ignore_err);
115 
116 /** This function is called when the database is booted.
117  Loads system table index definitions except for the clustered index which
118  is added to the dictionary cache at booting before calling this function. */
119 void dict_load_sys_table(dict_table_t *table); /*!< in: system table */
120 /** Loads foreign key constraints where the table is either the foreign key
121  holder or where the table is referenced by a foreign key. Adds these
122  constraints to the data dictionary.
123 
124  The foreign key constraint is loaded only if the referenced table is also
125  in the dictionary cache. If the referenced table is not in dictionary
126  cache, then it is added to the output parameter (fk_tables).
127 
128  @return DB_SUCCESS or error code */
130  const char *table_name, /*!< in: table name */
131  const char **col_names, /*!< in: column names, or NULL
132  to use table->col_names */
133  bool check_recursive, /*!< in: Whether to check
134  recursive load of tables
135  chained by FK */
136  bool check_charsets, /*!< in: whether to check
137  charset compatibility */
138  dict_err_ignore_t ignore_err, /*!< in: error to be ignored */
139  dict_names_t &fk_tables) /*!< out: stack of table names
140  which must be loaded
141  subsequently to load all the
142  foreign key constraints. */
143  MY_ATTRIBUTE((warn_unused_result));
144 
145 /** This function opens a system table, and return the first record.
146  @return first record of the system table */
148  btr_pcur_t *pcur, /*!< out: persistent cursor to
149  the record */
150  mtr_t *mtr, /*!< in: the mini-transaction */
151  dict_system_id_t system_id); /*!< in: which system table to open */
152 /** This function get the next system table record as we scan the table.
153  @return the record if found, NULL if end of scan. */
154 const rec_t *dict_getnext_system(btr_pcur_t *pcur, /*!< in/out: persistent
155  cursor to the record */
156  mtr_t *mtr); /*!< in: the mini-transaction */
157 
158 /** This function parses a SYS_TABLESPACES record, extracts necessary
159  information from the record and returns to caller.
160  @return error message, or NULL on success */
161 const char *dict_process_sys_tablespaces(
162  mem_heap_t *heap, /*!< in/out: heap memory */
163  const rec_t *rec, /*!< in: current SYS_TABLESPACES rec */
164  space_id_t *space, /*!< out: space id */
165  const char **name, /*!< out: tablespace name */
166  uint32_t *flags); /*!< out: tablespace flags */
167 /** Opens a tablespace for dict_load_table_one()
168 @param[in,out] table A table that refers to the tablespace to open
169 @param[in,out] heap A memory heap
170 @param[in] ignore_err Whether to ignore an error. */
171 void dict_load_tablespace(dict_table_t *table, mem_heap_t *heap,
172  dict_err_ignore_t ignore_err);
173 
174 /** Using the table->heap, copy the null-terminated filepath into
175 table->data_dir_path. The data directory patch is derived form the
176 filepath by stripping the the table->name.m_name component suffix.
177 @param[in,out] table table obj
178 @param[in] filepath filepath of tablespace */
179 void dict_save_data_dir_path(dict_table_t *table, char *filepath);
180 
181 /** Load all tablespaces during upgrade */
183 
184 /* Comparator for missing_spaces. */
186  bool operator()(const fil_space_t *lhs, const fil_space_t *rhs) const {
187  return (lhs->id < rhs->id);
188  }
189 };
190 
191 /* This is set of tablespaces that are not found in SYS_TABLESPACES.
192 InnoDB tablespaces before 5.6 are not registered in SYS_TABLESPACES.
193 So we maintain a std::set, which is later used to register the
194 tablespaces to dictionary table mysql.tablespaces */
195 using missing_sys_tblsp_t = std::set<fil_space_t *, space_compare>;
197 
198 #endif
dict_err_ignore_t
Error to ignore when we load table dictionary into memory.
Definition: dict0types.h:277
const char * SYSTEM_TABLE_NAME[]
Following are the InnoDB system tables.
Definition: dict0load.cc:69
space_id_t id
Tablespace ID.
Definition: fil0fil.h:226
std::deque< const char *, ut_allocator< const char * > > dict_names_t
A stack of table names related through foreign key constraints.
Definition: dict0load.h:49
Definition: dict0load.h:59
The low-level file system.
Definition: dict0load.h:54
bool operator()(const fil_space_t *lhs, const fil_space_t *rhs) const
Definition: dict0load.h:186
void dict_load_tablespace(dict_table_t *table, mem_heap_t *heap, dict_err_ignore_t ignore_err)
Opens a tablespace for dict_load_table_one()
Definition: dict0load.cc:2186
dict_table_t * dict_load_table(const char *name, bool cached, dict_err_ignore_t ignore_err)
Loads a table definition and also all its index definitions, and also the cluster definition if the t...
Definition: dict0load.cc:2148
Tablespace or log data space.
Definition: fil0fil.h:218
Data structure for a database table.
Definition: dict0mem.h:1520
dict_system_id_t
enum that defines all system table IDs.
Definition: dict0load.h:52
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:343
Definition: btr0pcur.h:177
static const char * filepath
Definition: myisamlog.cc:93
The index tree general types.
void dict_save_data_dir_path(dict_table_t *table, char *filepath)
Using the table->heap, copy the null-terminated filepath into table->data_dir_path.
Definition: dict0load.cc:2030
Data dictionary global types.
Definition: dict0load.h:56
Directly populate a dict_table_t structure with information from a SYS_TABLES record.
Definition: dict0load.h:69
byte rec_t
Definition: rem0types.h:39
missing_sys_tblsp_t missing_spaces
Definition: dict0load.cc:92
Definition: dict0load.h:57
dberr_t
Definition: db0err.h:38
Instrumented memory allocator.
char * dict_get_first_table_name_in_db(const char *name)
Finds the first table name in the given database.
Definition: dict0load.cc:146
case opt name
Definition: sslopt-case.h:32
char * dict_get_first_path(ulint space_id)
Get the first filepath from SYS_DATAFILES for a given space_id.
Definition: dict0load.cc:974
Check first whether dict_table_t is in the cache, if so, return it.
Definition: dict0load.h:72
Definition: dict0load.h:58
Utilities for byte operations.
Transaction system global type definitions.
Definition: dict0load.h:64
void dict_get_and_save_space_name(dict_table_t *table, bool dict_mutex_own)
Make sure the tablespace name is saved in dict_table_t if needed.
Definition: dict0load.cc:2099
void dict_load_sys_table(dict_table_t *table)
This function is called when the database is booted.
Definition: dict0load.cc:2577
Definition: dict0load.h:53
const char * dict_process_sys_tablespaces(mem_heap_t *heap, const rec_t *rec, space_id_t *space, const char **name, uint32_t *flags)
This function parses a SYS_TABLESPACES record, extracts necessary information from the record and ret...
Definition: dict0load.cc:915
Definition: dict0load.h:185
The memory management.
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
Definition: dict0load.h:61
dberr_t dict_load_foreigns(const char *table_name, const char **col_names, bool check_recursive, bool check_charsets, dict_err_ignore_t ignore_err, dict_names_t &fk_tables)
Loads foreign key constraints where the table is either the foreign key holder or where the table is ...
Definition: dict0load.cc:2889
const rec_t * dict_getnext_system(btr_pcur_t *pcur, mtr_t *mtr)
This function get the next system table record as we scan the table.
Definition: dict0load.cc:276
std::set< fil_space_t *, space_compare > missing_sys_tblsp_t
Definition: dict0load.h:195
void dict_load_tablespaces_for_upgrade()
Load all tablespaces during upgrade.
Definition: dict0load.cc:3045
dict_table_info_t
Status bit for dict_process_sys_tables_rec_and_mtr_commit()
Definition: dict0load.h:68
Definition: dict0load.h:55
const rec_t * dict_startscan_system(btr_pcur_t *pcur, mtr_t *mtr, dict_system_id_t system_id)
This function opens a system table, and return the first record.
Definition: dict0load.cc:250
static double cached
Definition: xcom_statistics.c:97
static int flags[50]
Definition: hp_test1.cc:39
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
Definition: dict0load.h:60
const char * table_name
Definition: rules_table_service.cc:55
void dict_get_and_save_data_dir_path(dict_table_t *table, bool dict_mutex_own)
Make sure the data_file_name is saved in dict_table_t if needed.
Definition: dict0load.cc:2066