| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2000, 2026, Oracle and/or its affiliates. |
| 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 designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
#ifndef ha_innodb_h |
| 29 |
#define ha_innodb_h |
| 30 |
|
| 31 |
/* The InnoDB handler: the interface between MySQL and InnoDB. */ |
| 32 |
|
| 33 |
#include <assert.h> |
| 34 |
#include <sys/types.h> |
| 35 |
#include "create_field.h" |
| 36 |
#include "field.h" |
| 37 |
#include "handler.h" |
| 38 |
#include "mysql/components/services/clone_protocol_service.h" |
| 39 |
|
| 40 |
#include "row0pread-adapter.h" |
| 41 |
#include "row0pread-histogram.h" |
| 42 |
#include "trx0trx.h" |
| 43 |
|
| 44 |
/** "GEN_CLUST_INDEX" is the name reserved for InnoDB default |
| 45 |
system clustered index when there is no primary key. */ |
| 46 |
extern const char innobase_index_reserve_name[]; |
| 47 |
|
| 48 |
/** Clone protocol service. */ |
| 49 |
extern SERVICE_TYPE(clone_protocol) * clone_protocol_svc; |
| 50 |
|
| 51 |
/* Structure defines translation table between mysql index and InnoDB |
| 52 |
index structures */ |
| 53 |
struct innodb_idx_translate_t { |
| 54 |
ulint index_count; /*!< number of valid index entries |
| 55 |
in the index_mapping array */ |
| 56 |
|
| 57 |
ulint array_size; /*!< array size of index_mapping */ |
| 58 |
|
| 59 |
dict_index_t **index_mapping; /*!< index pointer array directly |
| 60 |
maps to index in InnoDB from MySQL |
| 61 |
array index */ |
| 62 |
}; |
| 63 |
|
| 64 |
/** InnoDB table share */ |
| 65 |
struct INNOBASE_SHARE { |
| 66 |
const char *table_name; /*!< InnoDB table name */ |
| 67 |
uint use_count; /*!< reference count, |
| 68 |
incremented in get_share() |
| 69 |
and decremented in |
| 70 |
free_share() */ |
| 71 |
void *table_name_hash; |
| 72 |
/*!< hash table chain node */ |
| 73 |
innodb_idx_translate_t idx_trans_tbl; /*!< index translation table between |
| 74 |
MySQL and InnoDB */ |
| 75 |
}; |
| 76 |
|
| 77 |
/** Prebuilt structures in an InnoDB table handle used within MySQL */ |
| 78 |
struct row_prebuilt_t; |
| 79 |
|
| 80 |
namespace dd { |
| 81 |
namespace cache { |
| 82 |
class Dictionary_client; |
| 83 |
} |
| 84 |
} // namespace dd |
| 85 |
|
| 86 |
/** The class defining a handle to an InnoDB table */ |
| 87 |
class ha_innobase : public handler { |
| 88 |
public: |
| 89 |
ha_innobase(handlerton *hton, TABLE_SHARE *table_arg); |
| 90 |
~ha_innobase() override = default; |
| 91 |
|
| 92 |
row_type get_real_row_type(const HA_CREATE_INFO *create_info) const override; |
| 93 |
|
| 94 |
const char *table_type() const override; |
| 95 |
|
| 96 |
enum ha_key_alg get_default_index_algorithm() const override { |
| 97 |
return HA_KEY_ALG_BTREE; |
| 98 |
} |
| 99 |
|
| 100 |
/** Check if SE supports specific key algorithm. */ |
| 101 |
bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override { |
| 102 |
/* This method is never used for FULLTEXT or SPATIAL keys. |
| 103 |
We rely on handler::ha_table_flags() to check if such keys |
| 104 |
are supported. */ |
| 105 |
assert(key_alg != HA_KEY_ALG_FULLTEXT && key_alg != HA_KEY_ALG_RTREE); |
| 106 |
return key_alg == HA_KEY_ALG_BTREE; |
| 107 |
} |
| 108 |
|
| 109 |
Table_flags table_flags() const override; |
| 110 |
|
| 111 |
ulong index_flags(uint idx, uint part, bool all_parts) const override; |
| 112 |
|
| 113 |
uint max_supported_keys() const override; |
| 114 |
|
| 115 |
uint max_supported_key_length() const override; |
| 116 |
|
| 117 |
uint max_supported_key_part_length( |
| 118 |
HA_CREATE_INFO *create_info) const override; |
| 119 |
|
| 120 |
int open(const char *name, int, uint open_flags, |
| 121 |
const dd::Table *table_def) override; |
| 122 |
|
| 123 |
handler *clone(const char *name, MEM_ROOT *mem_root) override; |
| 124 |
|
| 125 |
int close(void) override; |
| 126 |
|
| 127 |
double scan_time() override; |
| 128 |
|
| 129 |
double read_time(uint index, uint ranges, ha_rows rows) override; |
| 130 |
|
| 131 |
longlong get_memory_buffer_size() const override; |
| 132 |
|
| 133 |
int write_row(uchar *buf) override; |
| 134 |
|
| 135 |
int update_row(const uchar *old_data, uchar *new_data) override; |
| 136 |
|
| 137 |
int delete_row(const uchar *buf) override; |
| 138 |
|
| 139 |
/** Delete all rows from the table. |
| 140 |
@retval HA_ERR_WRONG_COMMAND if the table is transactional |
| 141 |
@retval 0 on success */ |
| 142 |
int delete_all_rows() override; |
| 143 |
|
| 144 |
bool was_semi_consistent_read() override; |
| 145 |
|
| 146 |
void try_semi_consistent_read(bool yes) override; |
| 147 |
|
| 148 |
void unlock_row() override; |
| 149 |
|
| 150 |
int index_init(uint index, bool sorted) override; |
| 151 |
|
| 152 |
int index_end() override; |
| 153 |
|
| 154 |
int index_read(uchar *buf, const uchar *key, uint key_len, |
| 155 |
ha_rkey_function find_flag) override; |
| 156 |
|
| 157 |
int index_read_last(uchar *buf, const uchar *key, uint key_len) override; |
| 158 |
|
| 159 |
int index_next(uchar *buf) override; |
| 160 |
|
| 161 |
int index_next_same(uchar *buf, const uchar *key, uint keylen) override; |
| 162 |
|
| 163 |
int index_prev(uchar *buf) override; |
| 164 |
|
| 165 |
int index_first(uchar *buf) override; |
| 166 |
|
| 167 |
int index_last(uchar *buf) override; |
| 168 |
|
| 169 |
int read_range_first(const key_range *start_key, const key_range *end_key, |
| 170 |
bool eq_range_arg, bool sorted) override; |
| 171 |
|
| 172 |
int read_range_next() override; |
| 173 |
|
| 174 |
int rnd_init(bool scan) override; |
| 175 |
|
| 176 |
int rnd_end() override; |
| 177 |
|
| 178 |
int rnd_next(uchar *buf) override; |
| 179 |
|
| 180 |
int rnd_pos(uchar *buf, uchar *pos) override; |
| 181 |
|
| 182 |
int ft_init() override; |
| 183 |
|
| 184 |
void ft_end(); |
| 185 |
|
| 186 |
FT_INFO *ft_init_ext(uint flags, uint inx, String *key) override; |
| 187 |
|
| 188 |
FT_INFO *ft_init_ext_with_hints(uint inx, String *key, |
| 189 |
Ft_hints *hints) override; |
| 190 |
|
| 191 |
int ft_read(uchar *buf) override; |
| 192 |
|
| 193 |
void position(const uchar *record) override; |
| 194 |
|
| 195 |
int info(uint) override; |
| 196 |
|
| 197 |
int enable_indexes(uint mode) override; |
| 198 |
|
| 199 |
int disable_indexes(uint mode) override; |
| 200 |
|
| 201 |
int analyze(THD *thd, HA_CHECK_OPT *check_opt) override; |
| 202 |
|
| 203 |
int optimize(THD *thd, HA_CHECK_OPT *check_opt) override; |
| 204 |
|
| 205 |
int discard_or_import_tablespace(bool discard, dd::Table *table_def) override; |
| 206 |
|
| 207 |
int extra(ha_extra_function operation) override; |
| 208 |
|
| 209 |
int reset() override; |
| 210 |
|
| 211 |
int external_lock(THD *thd, int lock_type) override; |
| 212 |
|
| 213 |
/** Initialize sampling. |
| 214 |
@param[out] scan_ctx A scan context created by this method that has to be |
| 215 |
used in sample_next |
| 216 |
@param[in] sampling_percentage percentage of records that need to be sampled |
| 217 |
@param[in] sampling_seed random seed that the random generator will use |
| 218 |
@param[in] sampling_method sampling method to be used; currently only |
| 219 |
SYSTEM sampling is supported |
| 220 |
@param[in] tablesample true if the sampling is for tablesample |
| 221 |
@return 0 for success, else one of the HA_xxx values in case of error. */ |
| 222 |
int sample_init(void *&scan_ctx, double sampling_percentage, |
| 223 |
int sampling_seed, enum_sampling_method sampling_method, |
| 224 |
const bool tablesample) override; |
| 225 |
|
| 226 |
/** Get the next record for sampling. |
| 227 |
@param[in] scan_ctx Scan context of the sampling |
| 228 |
@param[in] buf buffer to place the read record |
| 229 |
@return 0 for success, else one of the HA_xxx values in case of error. */ |
| 230 |
int sample_next(void *scan_ctx, uchar *buf) override; |
| 231 |
|
| 232 |
/** End sampling. |
| 233 |
@param[in] scan_ctx Scan context of the sampling |
| 234 |
@return 0 for success, else one of the HA_xxx values in case of error. */ |
| 235 |
int sample_end(void *scan_ctx) override; |
| 236 |
|
| 237 |
/** MySQL calls this function at the start of each SQL statement |
| 238 |
inside LOCK TABLES. Inside LOCK TABLES the "::external_lock" method |
| 239 |
does not work to mark SQL statement borders. Note also a special case: |
| 240 |
if a temporary table is created inside LOCK TABLES, MySQL has not |
| 241 |
called external_lock() at all on that table. |
| 242 |
MySQL-5.0 also calls this before each statement in an execution of a |
| 243 |
stored procedure. To make the execution more deterministic for |
| 244 |
binlogging, MySQL-5.0 locks all tables involved in a stored procedure |
| 245 |
with full explicit table locks (thd_in_lock_tables(thd) holds in |
| 246 |
store_lock()) before executing the procedure. |
| 247 |
@param[in] thd handle to the user thread |
| 248 |
@param[in] lock_type lock type |
| 249 |
@return 0 or error code */ |
| 250 |
int start_stmt(THD *thd, thr_lock_type lock_type) override; |
| 251 |
|
| 252 |
void position(uchar *record); |
| 253 |
|
| 254 |
int records(ha_rows *num_rows) override; |
| 255 |
|
| 256 |
ha_rows records_in_range(uint inx, key_range *min_key, |
| 257 |
key_range *max_key) override; |
| 258 |
|
| 259 |
ha_rows estimate_rows_upper_bound() override; |
| 260 |
|
| 261 |
void update_create_info(HA_CREATE_INFO *create_info) override; |
| 262 |
|
| 263 |
/** Get storage-engine private data for a data dictionary table. |
| 264 |
@param[in,out] dd_table data dictionary table definition |
| 265 |
@param reset reset counters |
| 266 |
@retval true an error occurred |
| 267 |
@retval false success */ |
| 268 |
bool get_se_private_data(dd::Table *dd_table, bool reset) override; |
| 269 |
|
| 270 |
/** Add hidden columns and indexes to an InnoDB table definition. |
| 271 |
@param[in,out] dd_table data dictionary cache object |
| 272 |
@return error number |
| 273 |
@retval 0 on success */ |
| 274 |
int get_extra_columns_and_keys(const HA_CREATE_INFO *, |
| 275 |
const List<Create_field> *, const KEY *, uint, |
| 276 |
dd::Table *dd_table) override; |
| 277 |
|
| 278 |
/** Set Engine specific data to dd::Table object for upgrade. |
| 279 |
@param[in,out] thd thread handle |
| 280 |
@param[in] db_name database name |
| 281 |
@param[in] table_name table name |
| 282 |
@param[in,out] dd_table data dictionary cache object |
| 283 |
@return 0 on success, non-zero on failure */ |
| 284 |
bool upgrade_table(THD *thd, const char *db_name, const char *table_name, |
| 285 |
dd::Table *dd_table) override; |
| 286 |
|
| 287 |
/** Create an InnoDB table. |
| 288 |
@param[in] name table name in filename-safe encoding |
| 289 |
@param[in] form table structure |
| 290 |
@param[in] create_info more information on the table |
| 291 |
@param[in,out] table_def dd::Table describing table to be |
| 292 |
created. Can be adjusted by SE, the changes will be saved into data-dictionary |
| 293 |
at statement commit time. |
| 294 |
@return error number |
| 295 |
@retval 0 on success */ |
| 296 |
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, |
| 297 |
dd::Table *table_def) override; |
| 298 |
|
| 299 |
/** Drop a table. |
| 300 |
@param[in] name table name |
| 301 |
@param[in] table_def dd::Table describing table to |
| 302 |
be dropped |
| 303 |
@return error number |
| 304 |
@retval 0 on success */ |
| 305 |
int delete_table(const char *name, const dd::Table *table_def) override; |
| 306 |
|
| 307 |
protected: |
| 308 |
/** Drop a table. |
| 309 |
@param[in] name table name |
| 310 |
@param[in] table_def dd::Table describing table to |
| 311 |
be dropped |
| 312 |
@param[in] sqlcom type of operation that the DROP is part of |
| 313 |
@return error number |
| 314 |
@retval 0 on success */ |
| 315 |
int delete_table(const char *name, const dd::Table *table_def, |
| 316 |
enum enum_sql_command sqlcom); |
| 317 |
|
| 318 |
public: |
| 319 |
int rename_table(const char *from, const char *to, |
| 320 |
const dd::Table *from_table, dd::Table *to_table) override; |
| 321 |
|
| 322 |
int check(THD *thd, HA_CHECK_OPT *check_opt) override; |
| 323 |
|
| 324 |
uint lock_count(void) const override; |
| 325 |
|
| 326 |
THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, |
| 327 |
thr_lock_type lock_type) override; |
| 328 |
|
| 329 |
void init_table_handle_for_HANDLER() override; |
| 330 |
|
| 331 |
void get_auto_increment(ulonglong offset, ulonglong increment, |
| 332 |
ulonglong nb_desired_values, ulonglong *first_value, |
| 333 |
ulonglong *nb_reserved_values) override; |
| 334 |
|
| 335 |
/** Do cleanup for auto increment calculation. */ |
| 336 |
void release_auto_increment() override; |
| 337 |
|
| 338 |
bool get_error_message(int error, String *buf) override; |
| 339 |
|
| 340 |
bool get_foreign_dup_key(char *, uint, char *, uint) override; |
| 341 |
|
| 342 |
bool primary_key_is_clustered() const override; |
| 343 |
|
| 344 |
int cmp_ref(const uchar *ref1, const uchar *ref2) const override; |
| 345 |
|
| 346 |
/** @defgroup ALTER_TABLE_INTERFACE On-line ALTER TABLE interface |
| 347 |
@see handler0alter.cc |
| 348 |
@{ */ |
| 349 |
|
| 350 |
/** Check if InnoDB supports a particular alter table in-place |
| 351 |
@param altered_table TABLE object for new version of table. |
| 352 |
@param ha_alter_info Structure describing changes to be done |
| 353 |
by ALTER TABLE and holding data used during in-place alter. |
| 354 |
|
| 355 |
@retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported |
| 356 |
@retval HA_ALTER_INPLACE_NO_LOCK Supported |
| 357 |
@retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE Supported, but requires |
| 358 |
lock during main phase and exclusive lock during prepare phase. |
| 359 |
@retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE Supported, prepare phase |
| 360 |
requires exclusive lock (any transactions that have accessed the table |
| 361 |
must commit or roll back first, and no transactions can access the table |
| 362 |
while prepare_inplace_alter_table() is executing) |
| 363 |
*/ |
| 364 |
enum_alter_inplace_result check_if_supported_inplace_alter( |
| 365 |
TABLE *altered_table, Alter_inplace_info *ha_alter_info) override; |
| 366 |
|
| 367 |
/** Allows InnoDB to update internal structures with concurrent |
| 368 |
writes blocked (provided that check_if_supported_inplace_alter() |
| 369 |
did not return HA_ALTER_INPLACE_NO_LOCK). |
| 370 |
This will be invoked before inplace_alter_table(). |
| 371 |
@param[in] altered_table TABLE object for new version of table. |
| 372 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 373 |
by ALTER TABLE and holding data used during in-place alter. |
| 374 |
@param[in] old_dd_tab dd::Table object describing old version |
| 375 |
of the table. |
| 376 |
@param[in,out] new_dd_tab dd::Table object for the new version of |
| 377 |
the table. Can be adjusted by this call. Changes to the table definition will |
| 378 |
be persisted in the data-dictionary at statement commit time. |
| 379 |
@retval true Failure |
| 380 |
@retval false Success |
| 381 |
*/ |
| 382 |
bool prepare_inplace_alter_table(TABLE *altered_table, |
| 383 |
Alter_inplace_info *ha_alter_info, |
| 384 |
const dd::Table *old_dd_tab, |
| 385 |
dd::Table *new_dd_tab) override; |
| 386 |
|
| 387 |
/** Alter the table structure in-place with operations |
| 388 |
specified using HA_ALTER_FLAGS and Alter_inplace_information. |
| 389 |
The level of concurrency allowed during this operation depends |
| 390 |
on the return value from check_if_supported_inplace_alter(). |
| 391 |
@param[in] altered_table TABLE object for new version of table. |
| 392 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 393 |
by ALTER TABLE and holding data used during in-place alter. |
| 394 |
@param[in] old_dd_tab dd::Table object describing old version |
| 395 |
of the table. |
| 396 |
@param[in,out] new_dd_tab dd::Table object for the new version of |
| 397 |
the table. Can be adjusted by this call. Changes to the table definition will |
| 398 |
be persisted in the data-dictionary at statement commit time. |
| 399 |
@retval true Failure |
| 400 |
@retval false Success |
| 401 |
*/ |
| 402 |
bool inplace_alter_table(TABLE *altered_table, |
| 403 |
Alter_inplace_info *ha_alter_info, |
| 404 |
const dd::Table *old_dd_tab, |
| 405 |
dd::Table *new_dd_tab) override; |
| 406 |
|
| 407 |
/** Commit or rollback the changes made during |
| 408 |
prepare_inplace_alter_table() and inplace_alter_table() inside |
| 409 |
the storage engine. Note that the allowed level of concurrency |
| 410 |
during this operation will be the same as for |
| 411 |
inplace_alter_table() and thus might be higher than during |
| 412 |
prepare_inplace_alter_table(). (E.g concurrent writes were |
| 413 |
blocked during prepare, but might not be during commit). |
| 414 |
@param[in] altered_table TABLE object for new version of table. |
| 415 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 416 |
by ALTER TABLE and holding data used during in-place alter. |
| 417 |
@param[in] commit True to commit or false to rollback. |
| 418 |
@param[in] old_dd_tab dd::Table object representing old |
| 419 |
version of the table |
| 420 |
@param[in,out] new_dd_tab dd::Table object representing new |
| 421 |
version of the table. Can be adjusted by this call. Changes to the table |
| 422 |
definition will be persisted in the data-dictionary at statement |
| 423 |
commit time. |
| 424 |
@retval true Failure |
| 425 |
@retval false Success */ |
| 426 |
bool commit_inplace_alter_table(TABLE *altered_table, |
| 427 |
Alter_inplace_info *ha_alter_info, |
| 428 |
bool commit, const dd::Table *old_dd_tab, |
| 429 |
dd::Table *new_dd_tab) override; |
| 430 |
/** @} */ |
| 431 |
|
| 432 |
using Reader = Parallel_reader_adapter; |
| 433 |
|
| 434 |
/** Initializes a parallel scan. It creates a scan_ctx that has to |
| 435 |
be used across all parallel_scan methods. Also, gets the number of threads |
| 436 |
that would be spawned for parallel scan. |
| 437 |
@param[out] scan_ctx A scan context created by this method |
| 438 |
that has to be used in |
| 439 |
parallel_scan |
| 440 |
@param[out] num_threads Number of threads to be spawned |
| 441 |
@param[in] use_reserved_threads true if reserved threads are to be used |
| 442 |
if we exhaust the max cap of number of |
| 443 |
parallel read threads that can be |
| 444 |
spawned at a time |
| 445 |
@return error code |
| 446 |
@retval 0 on success */ |
| 447 |
int parallel_scan_init(void *&scan_ctx, size_t *num_threads, |
| 448 |
bool use_reserved_threads) override; |
| 449 |
|
| 450 |
/** Start parallel read of InnoDB records. |
| 451 |
@param[in] scan_ctx A scan context created by parallel_scan_init |
| 452 |
@param[in] thread_ctxs Context for each of the spawned threads |
| 453 |
@param[in] init_fn Callback called by each parallel load |
| 454 |
thread at the beginning of the parallel load. |
| 455 |
@param[in] load_fn Callback called by each parallel load |
| 456 |
thread when processing of rows is required. |
| 457 |
@param[in] end_fn Callback called by each parallel load |
| 458 |
thread when processing of rows has ended. |
| 459 |
@return error code |
| 460 |
@retval 0 on success */ |
| 461 |
int parallel_scan(void *scan_ctx, void **thread_ctxs, Reader::Init_fn init_fn, |
| 462 |
Reader::Load_fn load_fn, Reader::End_fn end_fn) override; |
| 463 |
|
| 464 |
/** End of the parallel scan. |
| 465 |
@param[in] scan_ctx A scan context created by parallel_scan_init. */ |
| 466 |
void parallel_scan_end(void *scan_ctx) override; |
| 467 |
|
| 468 |
bool check_if_incompatible_data(HA_CREATE_INFO *info, |
| 469 |
uint table_changes) override; |
| 470 |
|
| 471 |
private: |
| 472 |
/** @name Multi Range Read interface |
| 473 |
@{ */ |
| 474 |
|
| 475 |
/** Initialize multi range read @see DsMrr_impl::dsmrr_init */ |
| 476 |
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param, |
| 477 |
uint n_ranges, uint mode, |
| 478 |
HANDLER_BUFFER *buf) override; |
| 479 |
|
| 480 |
/** Process next multi range read @see DsMrr_impl::dsmrr_next */ |
| 481 |
int multi_range_read_next(char **range_info) override; |
| 482 |
|
| 483 |
/** Initialize multi range read and get information. |
| 484 |
@see ha_myisam::multi_range_read_info_const |
| 485 |
@see DsMrr_impl::dsmrr_info_const */ |
| 486 |
ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, |
| 487 |
void *seq_init_param, uint n_ranges, |
| 488 |
uint *bufsz, uint *flags, |
| 489 |
bool *force_default_mrr, |
| 490 |
Cost_estimate *cost) override; |
| 491 |
|
| 492 |
/** Initialize multi range read and get information. |
| 493 |
@see DsMrr_impl::dsmrr_info */ |
| 494 |
ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys, |
| 495 |
uint *bufsz, uint *flags, |
| 496 |
Cost_estimate *cost) override; |
| 497 |
|
| 498 |
/** Attempt to push down an index condition. |
| 499 |
@param[in] keyno MySQL key number |
| 500 |
@param[in] idx_cond Index condition to be checked |
| 501 |
@return idx_cond if pushed; NULL if not pushed */ |
| 502 |
Item *idx_cond_push(uint keyno, Item *idx_cond) override; |
| 503 |
/** @} */ |
| 504 |
|
| 505 |
private: |
| 506 |
void update_thd(); |
| 507 |
|
| 508 |
int change_active_index(uint keynr); |
| 509 |
|
| 510 |
dberr_t innobase_lock_autoinc(); |
| 511 |
|
| 512 |
dberr_t innobase_set_max_autoinc(ulonglong auto_inc); |
| 513 |
|
| 514 |
dberr_t innobase_get_autoinc(ulonglong *value); |
| 515 |
|
| 516 |
void innobase_initialize_autoinc(); |
| 517 |
|
| 518 |
/** Resets a query execution 'template'. |
| 519 |
@see build_template() */ |
| 520 |
void reset_template(); |
| 521 |
|
| 522 |
/** Write Row Interface optimized for Intrinsic table. */ |
| 523 |
int intrinsic_table_write_row(uchar *record); |
| 524 |
|
| 525 |
/** Find out if a Record_buffer is wanted by this handler, and what is |
| 526 |
the maximum buffer size the handler wants. |
| 527 |
|
| 528 |
@param[out] max_rows gets set to the maximum number of records to |
| 529 |
allocate space for in the buffer |
| 530 |
@retval true if the handler wants a buffer |
| 531 |
@retval false if the handler does not want a buffer */ |
| 532 |
bool is_record_buffer_wanted(ha_rows *const max_rows) const override; |
| 533 |
|
| 534 |
/** TRUNCATE an InnoDB table. |
| 535 |
@param[in] name table name |
| 536 |
@param[in] form table definition |
| 537 |
@param[in,out] table_def dd::Table describing table to be |
| 538 |
truncated. Can be adjusted by SE, the changes will be saved into |
| 539 |
the data-dictionary at statement commit time. |
| 540 |
@return error number |
| 541 |
@retval 0 on success */ |
| 542 |
int truncate_impl(const char *name, TABLE *form, dd::Table *table_def); |
| 543 |
|
| 544 |
protected: |
| 545 |
/** Enter InnoDB engine after checking max allowed threads. |
| 546 |
@return mysql error code. */ |
| 547 |
int srv_concurrency_enter(); |
| 548 |
|
| 549 |
/** Leave Innodb, if no more tickets are left */ |
| 550 |
void srv_concurrency_exit(); |
| 551 |
|
| 552 |
void update_thd(THD *thd); |
| 553 |
|
| 554 |
int general_fetch(uchar *buf, uint direction, uint match_mode); |
| 555 |
|
| 556 |
virtual dict_index_t *innobase_get_index(uint keynr); |
| 557 |
|
| 558 |
/** Builds a 'template' to the m_prebuilt struct. The template is used in fast |
| 559 |
retrieval of just those column values MySQL needs in its processing. |
| 560 |
@param[in] whole_row true if access is needed to a whole row, false if |
| 561 |
accessing individual fields is enough */ |
| 562 |
void build_template(bool whole_row); |
| 563 |
|
| 564 |
/** Returns statistics information of the table to the MySQL interpreter, in |
| 565 |
various fields of the handle object. |
| 566 |
@param[in] flag what information is requested |
| 567 |
@param[in] is_analyze True if called from "::analyze()". |
| 568 |
@return HA_ERR_* error code or 0 */ |
| 569 |
virtual int info_low(uint flag, bool is_analyze); |
| 570 |
|
| 571 |
/** |
| 572 |
MySQL calls this method at the end of each statement. This method |
| 573 |
exists for readability only, called from reset(). The name reset() |
| 574 |
doesn't give any clue that it is called at the end of a statement. */ |
| 575 |
int end_stmt(); |
| 576 |
|
| 577 |
/** Implementation of prepare_inplace_alter_table() |
| 578 |
@tparam Table dd::Table or dd::Partition |
| 579 |
@param[in] altered_table TABLE object for new version of table. |
| 580 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 581 |
by ALTER TABLE and holding data used |
| 582 |
during in-place alter. |
| 583 |
@param[in] old_dd_tab dd::Table object representing old |
| 584 |
version of the table |
| 585 |
@param[in,out] new_dd_tab dd::Table object representing new |
| 586 |
version of the table |
| 587 |
@retval true Failure |
| 588 |
@retval false Success */ |
| 589 |
template <typename Table> |
| 590 |
bool prepare_inplace_alter_table_impl(TABLE *altered_table, |
| 591 |
Alter_inplace_info *ha_alter_info, |
| 592 |
const Table *old_dd_tab, |
| 593 |
Table *new_dd_tab); |
| 594 |
|
| 595 |
/** Implementation of inplace_alter_table() |
| 596 |
@tparam Table dd::Table or dd::Partition |
| 597 |
@param[in] altered_table TABLE object for new version of table. |
| 598 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 599 |
by ALTER TABLE and holding data used |
| 600 |
during in-place alter. |
| 601 |
the table. Can be adjusted by this call. Changes to the table definition will |
| 602 |
be persisted in the data-dictionary at statement commit time. |
| 603 |
@retval true Failure |
| 604 |
@retval false Success |
| 605 |
*/ |
| 606 |
template <typename Table> |
| 607 |
bool inplace_alter_table_impl(TABLE *altered_table, |
| 608 |
Alter_inplace_info *ha_alter_info); |
| 609 |
|
| 610 |
/** Implementation of commit_inplace_alter_table() |
| 611 |
@tparam Table dd::Table or dd::Partition |
| 612 |
@param[in] altered_table TABLE object for new version of table. |
| 613 |
@param[in,out] ha_alter_info Structure describing changes to be done |
| 614 |
by ALTER TABLE and holding data used |
| 615 |
during in-place alter. |
| 616 |
@param[in] commit True to commit or false to rollback. |
| 617 |
@param[in,out] new_dd_tab Table object for the new version of the |
| 618 |
table. Can be adjusted by this call. |
| 619 |
Changes to the table definition |
| 620 |
will be persisted in the data-dictionary |
| 621 |
at statement version of it. |
| 622 |
@retval true Failure |
| 623 |
@retval false Success */ |
| 624 |
template <typename Table> |
| 625 |
bool commit_inplace_alter_table_impl(TABLE *altered_table, |
| 626 |
Alter_inplace_info *ha_alter_info, |
| 627 |
bool commit, Table *new_dd_tab); |
| 628 |
|
| 629 |
/** |
| 630 |
Return max limits for a single set of multi-valued keys |
| 631 |
|
| 632 |
@param[out] num_keys number of keys to store |
| 633 |
@param[out] keys_length total length of keys, bytes |
| 634 |
*/ |
| 635 |
void mv_key_capacity(uint *num_keys, size_t *keys_length) const override; |
| 636 |
|
| 637 |
/** Can reuse the template. Mainly used for partition. |
| 638 |
@retval true Can reuse the mysql_template */ |
| 639 |
virtual bool can_reuse_mysql_template() const { return false; } |
| 640 |
|
| 641 |
/** The multi range read session object */ |
| 642 |
DsMrr_impl m_ds_mrr; |
| 643 |
|
| 644 |
/** Save CPU time with prebuilt/cached data structures */ |
| 645 |
row_prebuilt_t *m_prebuilt; |
| 646 |
|
| 647 |
/** Thread handle of the user currently using the handler; |
| 648 |
this is set in external_lock function */ |
| 649 |
THD *m_user_thd; |
| 650 |
|
| 651 |
/** information for MySQL table locking */ |
| 652 |
INNOBASE_SHARE *m_share; |
| 653 |
|
| 654 |
/** buffer used in updates */ |
| 655 |
uchar *m_upd_buf; |
| 656 |
|
| 657 |
/** the size of upd_buf in bytes */ |
| 658 |
ulint m_upd_buf_size; |
| 659 |
|
| 660 |
/** Flags that specify the handler instance (table) capability. */ |
| 661 |
Table_flags m_int_table_flags; |
| 662 |
|
| 663 |
/** this is set to 1 when we are starting a table scan but have |
| 664 |
not yet fetched any row, else false */ |
| 665 |
bool m_start_of_scan; |
| 666 |
|
| 667 |
/*!< match mode of the latest search: ROW_SEL_EXACT, |
| 668 |
ROW_SEL_EXACT_PREFIX, or undefined */ |
| 669 |
uint m_last_match_mode{0}; |
| 670 |
|
| 671 |
/** this field is used to remember the original select_lock_type that |
| 672 |
was decided in ha_innodb.cc,":: store_lock()", "::external_lock()", |
| 673 |
etc. */ |
| 674 |
ulint m_stored_select_lock_type; |
| 675 |
|
| 676 |
/** If mysql has locked with external_lock() */ |
| 677 |
bool m_mysql_has_locked; |
| 678 |
}; |
| 679 |
|
| 680 |
struct trx_t; |
| 681 |
|
| 682 |
extern const struct _ft_vft ft_vft_result; |
| 683 |
|
| 684 |
/** Return the number of read threads for this session. |
| 685 |
@param[in] thd Session instance, or nullptr to query the global |
| 686 |
innodb_parallel_read_threads value. */ |
| 687 |
ulong thd_parallel_read_threads(THD *thd); |
| 688 |
|
| 689 |
/** Structure Returned by ha_innobase::ft_init_ext() */ |
| 690 |
typedef struct new_ft_info { |
| 691 |
struct _ft_vft *please; |
| 692 |
struct _ft_vft_ext *could_you; |
| 693 |
row_prebuilt_t *ft_prebuilt; |
| 694 |
fts_result_t *ft_result; |
| 695 |
} NEW_FT_INFO; |
| 696 |
|
| 697 |
/** Allocates an InnoDB transaction for a MySQL handler object for DML. |
| 698 |
@param[in] hton Innobase handlerton. |
| 699 |
@param[in] thd MySQL thd (connection) object. |
| 700 |
@param[in] trx transaction to register. */ |
| 701 |
void innobase_register_trx(handlerton *hton, THD *thd, trx_t *trx); |
| 702 |
|
| 703 |
/** |
| 704 |
Allocates an InnoDB transaction for a MySQL handler object. |
| 705 |
@return InnoDB transaction handle */ |
| 706 |
trx_t *innobase_trx_allocate(THD *thd); /*!< in: user thread handle */ |
| 707 |
|
| 708 |
/** Maps a MySQL trx isolation level code to the InnoDB isolation level code. |
| 709 |
@param[in] iso MySQL isolation level code |
| 710 |
@return InnoDB isolation level */ |
| 711 |
trx_t::isolation_level_t innobase_trx_map_isolation_level( |
| 712 |
enum_tx_isolation iso); |
| 713 |
|
| 714 |
/** Match index columns between MySQL and InnoDB. |
| 715 |
This function checks whether the index column information |
| 716 |
is consistent between KEY info from mysql and that from innodb index. |
| 717 |
@param[in] key_info Index info from mysql |
| 718 |
@param[in] index_info Index info from InnoDB |
| 719 |
@return true if all column types match. */ |
| 720 |
bool innobase_match_index_columns(const KEY *key_info, |
| 721 |
const dict_index_t *index_info); |
| 722 |
|
| 723 |
/** This function checks each index name for a table against reserved |
| 724 |
system default primary index name 'GEN_CLUST_INDEX'. If a name |
| 725 |
matches, this function pushes an warning message to the client, |
| 726 |
and returns true. |
| 727 |
@return true if the index name matches the reserved name */ |
| 728 |
[[nodiscard]] bool innobase_index_name_is_reserved( |
| 729 |
THD *thd, /*!< in/out: MySQL connection */ |
| 730 |
const KEY *key_info, /*!< in: Indexes to be |
| 731 |
created */ |
| 732 |
ulint num_of_keys); /*!< in: Number of indexes to |
| 733 |
be created. */ |
| 734 |
|
| 735 |
/** Check if the explicit tablespace targeted is file_per_table. |
| 736 |
@param[in] create_info Metadata for the table to create. |
| 737 |
@return true if the table is intended to use a file_per_table tablespace. */ |
| 738 |
static inline bool tablespace_is_file_per_table( |
| 739 |
const HA_CREATE_INFO *create_info) { |
| 740 |
return (create_info->tablespace != nullptr && |
| 741 |
(0 == |
| 742 |
strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name))); |
| 743 |
} |
| 744 |
|
| 745 |
/** Check if table will be explicitly put in an existing shared general |
| 746 |
or system tablespace. |
| 747 |
@param[in] create_info Metadata for the table to create. |
| 748 |
@return true if the table will use a shared general or system tablespace. */ |
| 749 |
static inline bool tablespace_is_shared_space( |
| 750 |
const HA_CREATE_INFO *create_info) { |
| 751 |
return (create_info->tablespace != nullptr && |
| 752 |
create_info->tablespace[0] != '\0' && |
| 753 |
(0 != |
| 754 |
strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name))); |
| 755 |
} |
| 756 |
|
| 757 |
/** Check if table will be explicitly put in a general tablespace. |
| 758 |
@param[in] create_info Metadata for the table to create. |
| 759 |
@return true if the table will use a general tablespace. */ |
| 760 |
static inline bool tablespace_is_general_space( |
| 761 |
const HA_CREATE_INFO *create_info) { |
| 762 |
return ( |
| 763 |
create_info->tablespace != nullptr && |
| 764 |
create_info->tablespace[0] != '\0' && |
| 765 |
(0 != |
| 766 |
strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)) && |
| 767 |
(0 != strcmp(create_info->tablespace, dict_sys_t::s_temp_space_name)) && |
| 768 |
(0 != strcmp(create_info->tablespace, dict_sys_t::s_sys_space_name))); |
| 769 |
} |
| 770 |
|
| 771 |
/** Check if tablespace is shared tablespace. |
| 772 |
@param[in] tablespace_name Name of the tablespace |
| 773 |
@return true if tablespace is a shared tablespace. */ |
| 774 |
static inline bool is_shared_tablespace(const char *tablespace_name) { |
| 775 |
if (tablespace_name != nullptr && tablespace_name[0] != '\0' && |
| 776 |
(strcmp(tablespace_name, dict_sys_t::s_file_per_table_name) != 0)) { |
| 777 |
return true; |
| 778 |
} |
| 779 |
return false; |
| 780 |
} |
| 781 |
|
| 782 |
constexpr uint32_t SIZE_MB = 1024 * 1024; |
| 783 |
|
| 784 |
/** Validate AUTOEXTEND_SIZE attribute for a tablespace. |
| 785 |
@param[in] ext_size Value of autoextend_size attribute |
| 786 |
@return DB_SUCCESS if the value of AUTOEXTEND_SIZE is valid. */ |
| 787 |
static inline int validate_autoextend_size_value(uint64_t ext_size) { |
| 788 |
ut_ad(ext_size > 0); |
| 789 |
|
| 790 |
page_no_t extent_size_pages = fsp_get_extent_size_in_pages( |
| 791 |
{static_cast<uint32_t>(srv_page_size), |
| 792 |
static_cast<uint32_t>(srv_page_size), false}); |
| 793 |
|
| 794 |
/* Validate following for the AUTOEXTEND_SIZE attribute |
| 795 |
1. The autoextend_size should be a multiple of size of 4 extents |
| 796 |
2. The autoextend_size value should be between size of 4 extents and 4G */ |
| 797 |
if (ext_size < (FSP_FREE_ADD * extent_size_pages * srv_page_size) || |
| 798 |
ext_size > FSP_MAX_AUTOEXTEND_SIZE) { |
| 799 |
my_error(ER_INNODB_AUTOEXTEND_SIZE_OUT_OF_RANGE, MYF(0), |
| 800 |
(FSP_FREE_ADD * extent_size_pages * srv_page_size) / SIZE_MB, |
| 801 |
FSP_MAX_AUTOEXTEND_SIZE / SIZE_MB); |
| 802 |
return ER_INNODB_AUTOEXTEND_SIZE_OUT_OF_RANGE; |
| 803 |
} |
| 804 |
|
| 805 |
if ((ext_size / srv_page_size) % (FSP_FREE_ADD * extent_size_pages) != 0) { |
| 806 |
my_error(ER_INNODB_INVALID_AUTOEXTEND_SIZE_VALUE, MYF(0), |
| 807 |
FSP_FREE_ADD * extent_size_pages * srv_page_size / SIZE_MB); |
| 808 |
return ER_INNODB_INVALID_AUTOEXTEND_SIZE_VALUE; |
| 809 |
} |
| 810 |
|
| 811 |
return DB_SUCCESS; |
| 812 |
} |
| 813 |
|
| 814 |
/** Parse hint for table and its indexes, and update the information |
| 815 |
in dictionary. |
| 816 |
@param[in] thd Connection thread |
| 817 |
@param[in,out] table Target table |
| 818 |
@param[in] table_share Table definition */ |
| 819 |
void innobase_parse_hint_from_comment(THD *thd, dict_table_t *table, |
| 820 |
const TABLE_SHARE *table_share); |
| 821 |
|
| 822 |
/** Obtain the InnoDB transaction of a MySQL thread. |
| 823 |
@param[in,out] thd MySQL thread handler. |
| 824 |
@return reference to transaction pointer */ |
| 825 |
trx_t *&thd_to_trx(THD *thd); |
| 826 |
|
| 827 |
/** Class for handling create table information. */ |
| 828 |
class create_table_info_t { |
| 829 |
public: |
| 830 |
/** Constructor. |
| 831 |
Used in two ways: |
| 832 |
- all but file_per_table is used, when creating the table. |
| 833 |
- all but name/path is used, when validating options and using flags. */ |
| 834 |
create_table_info_t(THD *thd, TABLE *form, HA_CREATE_INFO *create_info, |
| 835 |
char *table_name, char *remote_path, char *tablespace, |
| 836 |
bool file_per_table, bool skip_strict, uint32_t old_flags, |
| 837 |
uint32_t old_flags2, bool is_partition) |
| 838 |
: m_thd(thd), |
| 839 |
m_trx(thd_to_trx(thd)), |
| 840 |
m_form(form), |
| 841 |
m_create_info(create_info), |
| 842 |
m_table_name(table_name), |
| 843 |
m_remote_path(remote_path), |
| 844 |
m_tablespace(tablespace), |
| 845 |
m_innodb_file_per_table(file_per_table), |
| 846 |
m_flags(old_flags), |
| 847 |
m_flags2(old_flags2), |
| 848 |
m_skip_strict(skip_strict), |
| 849 |
m_partition(is_partition) {} |
| 850 |
|
| 851 |
/** Initialize the object. */ |
| 852 |
int initialize(); |
| 853 |
|
| 854 |
/** Set m_tablespace_type. */ |
| 855 |
void set_tablespace_type(bool table_being_altered_is_file_per_table); |
| 856 |
|
| 857 |
/** Create the internal innodb table. |
| 858 |
@param[in] dd_table dd::Table or nullptr for intrinsic table |
| 859 |
@param[in] old_part_table dd::Table from an old partition for partitioned |
| 860 |
table, NULL otherwise. |
| 861 |
@return 0 or error number */ |
| 862 |
int create_table(const dd::Table *dd_table, const dd::Table *old_part_table); |
| 863 |
|
| 864 |
/** Update the internal data dictionary. */ |
| 865 |
int create_table_update_dict(); |
| 866 |
|
| 867 |
/** Update the global data dictionary. |
| 868 |
@param[in] dd_table dd::Table or dd::Partition |
| 869 |
@retval 0 On success |
| 870 |
@retval error number On failure */ |
| 871 |
template <typename Table> |
| 872 |
int create_table_update_global_dd(Table *dd_table); |
| 873 |
|
| 874 |
/** Validates the create options. Checks that the options |
| 875 |
KEY_BLOCK_SIZE, ROW_FORMAT, DATA DIRECTORY, TEMPORARY & TABLESPACE |
| 876 |
are compatible with each other and other settings. |
| 877 |
These CREATE OPTIONS are not validated here unless innodb_strict_mode |
| 878 |
is on. With strict mode, this function will report each problem it |
| 879 |
finds using a custom message with error code |
| 880 |
ER_ILLEGAL_HA_CREATE_OPTION, not its built-in message. |
| 881 |
@return NULL if valid, string name of bad option if not. */ |
| 882 |
const char *create_options_are_invalid(); |
| 883 |
|
| 884 |
private: |
| 885 |
/** Put a warning or error message to the error log for the |
| 886 |
DATA DIRECTORY option. |
| 887 |
@param[in] msg The reason that data directory is wrong. |
| 888 |
@param[in] ignore If true, append a message about ignoring |
| 889 |
the data directory location. */ |
| 890 |
void log_error_invalid_location(std::string &msg, bool ignore); |
| 891 |
|
| 892 |
public: |
| 893 |
/** Validate DATA DIRECTORY option. */ |
| 894 |
bool create_option_data_directory_is_valid(bool ignore = false); |
| 895 |
|
| 896 |
/** Validate TABLESPACE option. */ |
| 897 |
bool create_option_tablespace_is_valid(); |
| 898 |
|
| 899 |
/** Validate COMPRESSION option. */ |
| 900 |
bool create_option_compression_is_valid(); |
| 901 |
|
| 902 |
/** Prepare to create a table. */ |
| 903 |
int prepare_create_table(const char *name); |
| 904 |
|
| 905 |
/** Determine InnoDB table flags. |
| 906 |
If strict_mode=OFF, this will adjust the flags to what should be assumed. |
| 907 |
However, if an existing general tablespace is being targeted, we will NOT |
| 908 |
assume anything or adjust these flags. |
| 909 |
@retval true if successful, false if error */ |
| 910 |
bool innobase_table_flags(); |
| 911 |
|
| 912 |
/** Set flags and append '/' to remote path if necessary. */ |
| 913 |
void set_remote_path_flags(); |
| 914 |
|
| 915 |
/** Get table flags. */ |
| 916 |
uint32_t flags() const { return (m_flags); } |
| 917 |
|
| 918 |
/** Get table flags2. */ |
| 919 |
uint32_t flags2() const { return (m_flags2); } |
| 920 |
|
| 921 |
/** Reset table flags. */ |
| 922 |
void flags_reset() { m_flags = 0; } |
| 923 |
|
| 924 |
/** Reset table flags2. */ |
| 925 |
void flags2_reset() { m_flags2 = 0; } |
| 926 |
|
| 927 |
/** whether to skip strict check. */ |
| 928 |
bool skip_strict() const { return (m_skip_strict); } |
| 929 |
|
| 930 |
/** Return table name. */ |
| 931 |
const char *table_name() const { return (m_table_name); } |
| 932 |
|
| 933 |
THD *thd() const { return (m_thd); } |
| 934 |
|
| 935 |
inline bool is_intrinsic_temp_table() const { |
| 936 |
/* DICT_TF2_INTRINSIC implies DICT_TF2_TEMPORARY */ |
| 937 |
ut_ad(!(m_flags2 & DICT_TF2_INTRINSIC) || (m_flags2 & DICT_TF2_TEMPORARY)); |
| 938 |
return ((m_flags2 & DICT_TF2_INTRINSIC) != 0); |
| 939 |
} |
| 940 |
|
| 941 |
/** @return true only if table is temporary and not intrinsic */ |
| 942 |
inline bool is_temp_table() const { |
| 943 |
return (((m_flags2 & DICT_TF2_TEMPORARY) != 0) && |
| 944 |
((m_flags2 & DICT_TF2_INTRINSIC) == 0)); |
| 945 |
} |
| 946 |
|
| 947 |
/** Detach the just created table and its auxiliary tables if exist. */ |
| 948 |
void detach(); |
| 949 |
|
| 950 |
/** Normalizes a table name string. |
| 951 |
A normalized name consists of the database name catenated to '/' and |
| 952 |
table name. An example: test/mytable. On case insensitive file system |
| 953 |
normalization converts name to lower case. |
| 954 |
@param[in,out] norm_name Buffer to return the normalized name in. |
| 955 |
@param[in] name Table name string. |
| 956 |
@return true if successful. */ |
| 957 |
static bool normalize_table_name(char *norm_name, const char *name); |
| 958 |
|
| 959 |
private: |
| 960 |
/** Parses the table name into normal name and either temp path or |
| 961 |
remote path if needed.*/ |
| 962 |
int parse_table_name(const char *name); |
| 963 |
|
| 964 |
/** Create a table definition to an InnoDB database. |
| 965 |
@param[in] dd_table dd::Table or nullptr for intrinsic table |
| 966 |
@param[in] old_part_table dd::Table from an old partition for partitioned |
| 967 |
table, NULL otherwise. |
| 968 |
@return HA_* level error */ |
| 969 |
int create_table_def(const dd::Table *dd_table, |
| 970 |
const dd::Table *old_part_table); |
| 971 |
|
| 972 |
/** Initialize the autoinc of this table if necessary, which should |
| 973 |
be called before we flush logs, so autoinc counter can be persisted. */ |
| 974 |
void initialize_autoinc(); |
| 975 |
|
| 976 |
/** Connection thread handle. */ |
| 977 |
THD *m_thd; |
| 978 |
|
| 979 |
/** InnoDB transaction handle. */ |
| 980 |
trx_t *m_trx; |
| 981 |
|
| 982 |
/** Information on table columns and indexes. */ |
| 983 |
const TABLE *m_form; |
| 984 |
|
| 985 |
/** Create options. */ |
| 986 |
HA_CREATE_INFO *m_create_info; |
| 987 |
|
| 988 |
/** Table name */ |
| 989 |
char *m_table_name; |
| 990 |
/** Remote path (DATA DIRECTORY) or zero length-string */ |
| 991 |
char *m_remote_path; |
| 992 |
/** Tablespace name or zero length-string. */ |
| 993 |
char *m_tablespace; |
| 994 |
|
| 995 |
/** The newly created InnoDB table object. This is currently only |
| 996 |
used in this class, since the new table is not evictable until |
| 997 |
final success/failure, it can be accessed directly. */ |
| 998 |
dict_table_t *m_table; |
| 999 |
|
| 1000 |
/** Local copy of srv_file_per_table. */ |
| 1001 |
bool m_innodb_file_per_table; |
| 1002 |
|
| 1003 |
/** Allow file_per_table for this table either because: |
| 1004 |
1) the setting innodb_file_per_table=on, |
| 1005 |
2) it was explicitly requested by tablespace=innodb_file_per_table. |
| 1006 |
3) the table being altered is currently file_per_table */ |
| 1007 |
bool m_allow_file_per_table; |
| 1008 |
|
| 1009 |
/** After all considerations, this shows whether we will actually |
| 1010 |
create a table and tablespace using file-per-table. */ |
| 1011 |
bool m_use_file_per_table; |
| 1012 |
|
| 1013 |
/** Using DATA DIRECTORY */ |
| 1014 |
bool m_use_data_dir; |
| 1015 |
|
| 1016 |
/** Using a Shared General Tablespace */ |
| 1017 |
bool m_use_shared_space; |
| 1018 |
|
| 1019 |
/** Table flags */ |
| 1020 |
uint32_t m_flags; |
| 1021 |
|
| 1022 |
/** Table flags2 */ |
| 1023 |
uint32_t m_flags2; |
| 1024 |
|
| 1025 |
/** Skip strict check */ |
| 1026 |
bool m_skip_strict; |
| 1027 |
|
| 1028 |
/** True if this table is a partition */ |
| 1029 |
bool m_partition; |
| 1030 |
}; |
| 1031 |
|
| 1032 |
/** Class of basic DDL implementation, for CREATE/DROP/RENAME TABLE */ |
| 1033 |
class innobase_basic_ddl { |
| 1034 |
public: |
| 1035 |
/** Create an InnoDB table. |
| 1036 |
@tparam Table dd::Table or dd::Partition |
| 1037 |
@param[in,out] thd THD object |
| 1038 |
@param[in] name Table name, format: "db/table_name" |
| 1039 |
@param[in] form Table format; columns and index |
| 1040 |
information |
| 1041 |
@param[in] create_info Create info(including create statement |
| 1042 |
string) |
| 1043 |
@param[in,out] dd_tab dd::Table describing table to be created |
| 1044 |
@param[in] file_per_table whether to create a tablespace too |
| 1045 |
@param[in] evictable whether the caller wants the |
| 1046 |
dict_table_t to be kept in memory |
| 1047 |
@param[in] skip_strict whether to skip strict check for create |
| 1048 |
option |
| 1049 |
@param[in] old_flags old Table flags |
| 1050 |
@param[in] old_flags2 old Table flags2 |
| 1051 |
@param[in] old_dd_table Table def for old table. Used in truncate or |
| 1052 |
while adding a new partition |
| 1053 |
@return error number |
| 1054 |
@retval 0 on success */ |
| 1055 |
template <typename Table> |
| 1056 |
static int create_impl(THD *thd, const char *name, TABLE *form, |
| 1057 |
HA_CREATE_INFO *create_info, Table *dd_tab, |
| 1058 |
bool file_per_table, bool evictable, bool skip_strict, |
| 1059 |
uint32_t old_flags, uint32_t old_flags2, |
| 1060 |
const dd::Table *old_dd_table); |
| 1061 |
|
| 1062 |
/** Drop an InnoDB table. |
| 1063 |
@tparam Table dd::Table or dd::Partition |
| 1064 |
@param[in,out] thd THD object |
| 1065 |
@param[in] name table name |
| 1066 |
@param[in] dd_tab dd::Table describing table to be dropped |
| 1067 |
@param[in] td MySQL table definition |
| 1068 |
@return error number |
| 1069 |
@retval 0 on success */ |
| 1070 |
|
| 1071 |
template <typename Table> |
| 1072 |
static int delete_impl(THD *thd, const char *name, const Table *dd_tab, |
| 1073 |
const TABLE *td); |
| 1074 |
|
| 1075 |
/** Renames an InnoDB table. |
| 1076 |
@tparam Table dd::Table or dd::Partition |
| 1077 |
@param[in,out] thd THD object |
| 1078 |
@param[in] from old name of the table |
| 1079 |
@param[in] to new name of the table |
| 1080 |
@param[in] from_table dd::Table or dd::Partition of the table |
| 1081 |
with old name |
| 1082 |
@param[in] to_table dd::Table or dd::Partition of the table |
| 1083 |
with new name |
| 1084 |
@param[in] td MySQL table definition |
| 1085 |
@return error number |
| 1086 |
@retval 0 on success */ |
| 1087 |
|
| 1088 |
template <typename Table> |
| 1089 |
static int rename_impl(THD *thd, const char *from, const char *to, |
| 1090 |
const Table *from_table, const Table *to_table, |
| 1091 |
const TABLE *td); |
| 1092 |
}; |
| 1093 |
|
| 1094 |
/** Class to handle TRUNCATE for one InnoDB table or one partition */ |
| 1095 |
template <typename Table> |
| 1096 |
class innobase_truncate { |
| 1097 |
public: |
| 1098 |
/** Constructor |
| 1099 |
@param[in] thd THD object |
| 1100 |
@param[in] name normalized table name |
| 1101 |
@param[in] form Table format; columns and index information |
| 1102 |
@param[in] dd_table dd::Table or dd::Partition |
| 1103 |
@param[in] keep_autoinc true to remember original autoinc counter |
| 1104 |
@param[in] table_truncate true if this is full table truncate */ |
| 1105 |
innobase_truncate(THD *thd, const char *name, TABLE *form, Table *dd_table, |
| 1106 |
bool keep_autoinc, bool table_truncate) |
| 1107 |
: m_thd(thd), |
| 1108 |
m_name(name), |
| 1109 |
m_dd_table(dd_table), |
| 1110 |
m_trx(nullptr), |
| 1111 |
m_table(nullptr), |
| 1112 |
m_form(form), |
| 1113 |
m_create_info(), |
| 1114 |
m_file_per_table(false), |
| 1115 |
m_keep_autoinc(keep_autoinc), |
| 1116 |
m_table_truncate(table_truncate), |
| 1117 |
m_flags(0), |
| 1118 |
m_flags2(0) {} |
| 1119 |
|
| 1120 |
/** Destructor */ |
| 1121 |
~innobase_truncate(); |
| 1122 |
|
| 1123 |
/** Open the table/partition to be truncated |
| 1124 |
@param[out] innodb_table InnoDB table object opened |
| 1125 |
@return error number or 0 on success */ |
| 1126 |
int open_table(dict_table_t *&innodb_table); |
| 1127 |
|
| 1128 |
/** Do the truncate of the table/partition |
| 1129 |
@return error number or 0 on success */ |
| 1130 |
int exec(); |
| 1131 |
|
| 1132 |
private: |
| 1133 |
/** Prepare for truncate |
| 1134 |
@return error number or 0 on success */ |
| 1135 |
int prepare(); |
| 1136 |
|
| 1137 |
/** Do the real truncation |
| 1138 |
@return error number or 0 on success */ |
| 1139 |
int truncate(); |
| 1140 |
|
| 1141 |
/** Rename tablespace file name |
| 1142 |
@return error number or 0 on success */ |
| 1143 |
int rename_tablespace(); |
| 1144 |
|
| 1145 |
/** Cleanup */ |
| 1146 |
void cleanup(); |
| 1147 |
|
| 1148 |
/** Reload the FK related information |
| 1149 |
@return error number or 0 on success */ |
| 1150 |
int load_fk(); |
| 1151 |
|
| 1152 |
private: |
| 1153 |
/** THD object */ |
| 1154 |
THD *m_thd; |
| 1155 |
|
| 1156 |
/** Normalized table name */ |
| 1157 |
const char *m_name; |
| 1158 |
|
| 1159 |
/** dd::Table or dd::Partition */ |
| 1160 |
Table *m_dd_table; |
| 1161 |
|
| 1162 |
/** Transaction attached to current thd */ |
| 1163 |
trx_t *m_trx; |
| 1164 |
|
| 1165 |
/** InnoDB table object for the table/partition */ |
| 1166 |
dict_table_t *m_table; |
| 1167 |
|
| 1168 |
/** Table format */ |
| 1169 |
TABLE *m_form; |
| 1170 |
|
| 1171 |
/** Create information */ |
| 1172 |
HA_CREATE_INFO m_create_info; |
| 1173 |
|
| 1174 |
/** True if this table/partition is file per table */ |
| 1175 |
bool m_file_per_table; |
| 1176 |
|
| 1177 |
/** True if the original autoinc counter should be kept. It's |
| 1178 |
specified by caller, however if the table has no AUTOINC column, |
| 1179 |
it would be reset to false internally */ |
| 1180 |
bool m_keep_autoinc; |
| 1181 |
|
| 1182 |
/** For a prtition table, this is true if full table is truncated. If only |
| 1183 |
a partition is truncated, it is set to false. */ |
| 1184 |
bool m_table_truncate; |
| 1185 |
|
| 1186 |
/** flags of the table to be truncated, which should not change */ |
| 1187 |
uint32_t m_flags; |
| 1188 |
|
| 1189 |
/** flags2 of the table to be truncated, which should not change */ |
| 1190 |
uint32_t m_flags2; |
| 1191 |
}; |
| 1192 |
|
| 1193 |
/** |
| 1194 |
Initialize the table FTS stopword list |
| 1195 |
@return true if success */ |
| 1196 |
[[nodiscard]] bool innobase_fts_load_stopword( |
| 1197 |
dict_table_t *table, /*!< in: Table has the FTS */ |
| 1198 |
trx_t *trx, /*!< in: transaction */ |
| 1199 |
THD *thd); /*!< in: current thread */ |
| 1200 |
|
| 1201 |
/** Some defines for innobase_fts_check_doc_id_index() return value */ |
| 1202 |
enum fts_doc_id_index_enum { |
| 1203 |
FTS_INCORRECT_DOC_ID_INDEX, |
| 1204 |
FTS_EXIST_DOC_ID_INDEX, |
| 1205 |
FTS_NOT_EXIST_DOC_ID_INDEX |
| 1206 |
}; |
| 1207 |
|
| 1208 |
/** |
| 1209 |
Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME |
| 1210 |
on the Doc ID column. |
| 1211 |
@return the status of the FTS_DOC_ID index */ |
| 1212 |
[[nodiscard]] fts_doc_id_index_enum innobase_fts_check_doc_id_index( |
| 1213 |
const dict_table_t *table, /*!< in: table definition */ |
| 1214 |
const TABLE *altered_table, /*!< in: MySQL table |
| 1215 |
that is being altered */ |
| 1216 |
ulint *fts_doc_col_no); /*!< out: The column number for |
| 1217 |
Doc ID */ |
| 1218 |
|
| 1219 |
/** |
| 1220 |
Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME |
| 1221 |
on the Doc ID column in MySQL create index definition. |
| 1222 |
@return FTS_EXIST_DOC_ID_INDEX if there exists the FTS_DOC_ID index, |
| 1223 |
FTS_INCORRECT_DOC_ID_INDEX if the FTS_DOC_ID index is of wrong format */ |
| 1224 |
[[nodiscard]] fts_doc_id_index_enum innobase_fts_check_doc_id_index_in_def( |
| 1225 |
ulint n_key, /*!< in: Number of keys */ |
| 1226 |
const KEY *key_info); /*!< in: Key definitions */ |
| 1227 |
|
| 1228 |
/** |
| 1229 |
Copy table flags from MySQL's TABLE_SHARE into an InnoDB table object. |
| 1230 |
Those flags are stored in .frm file and end up in the MySQL table object, |
| 1231 |
but are frequently used inside InnoDB so we keep their copies into the |
| 1232 |
InnoDB table object. */ |
| 1233 |
void innobase_copy_frm_flags_from_table_share( |
| 1234 |
dict_table_t *innodb_table, /*!< in/out: InnoDB table */ |
| 1235 |
const TABLE_SHARE *table_share); /*!< in: table share */ |
| 1236 |
|
| 1237 |
/** Set up base columns for virtual column |
| 1238 |
@param[in] table the InnoDB table |
| 1239 |
@param[in] field MySQL field |
| 1240 |
@param[in,out] v_col virtual column to be set up */ |
| 1241 |
void innodb_base_col_setup(dict_table_t *table, const Field *field, |
| 1242 |
dict_v_col_t *v_col); |
| 1243 |
|
| 1244 |
/** Set up base columns for stored column |
| 1245 |
@param[in] table InnoDB table |
| 1246 |
@param[in] field MySQL field |
| 1247 |
@param[in,out] s_col stored column */ |
| 1248 |
void innodb_base_col_setup_for_stored(const dict_table_t *table, |
| 1249 |
const Field *field, dict_s_col_t *s_col); |
| 1250 |
|
| 1251 |
/** whether this is a stored column */ |
| 1252 |
static inline bool innobase_is_s_fld(const Field *field) { |
| 1253 |
return field->gcol_info && field->stored_in_db; |
| 1254 |
} |
| 1255 |
|
| 1256 |
/** Whether this is a computed multi-value virtual column. |
| 1257 |
This condition check should be equal to the following one: |
| 1258 |
(innobase_is_v_fld(field) && (field)->gcol_info->expr_item && |
| 1259 |
field->gcol_info->expr_item->returns_array()) |
| 1260 |
*/ |
| 1261 |
static inline bool innobase_is_multi_value_fld(const Field *field) { |
| 1262 |
return field->is_array(); |
| 1263 |
} |
| 1264 |
|
| 1265 |
static inline bool normalize_table_name(char *norm_name, const char *name) { |
| 1266 |
return create_table_info_t::normalize_table_name(norm_name, name); |
| 1267 |
} |
| 1268 |
|
| 1269 |
/** Note that a transaction has been registered with MySQL. |
| 1270 |
@param[in] trx Transaction. |
| 1271 |
@return true if transaction is registered with MySQL 2PC coordinator */ |
| 1272 |
inline bool trx_is_registered_for_2pc(const trx_t *trx) { |
| 1273 |
return (trx->is_registered == 1); |
| 1274 |
} |
| 1275 |
|
| 1276 |
/** Converts an InnoDB error code to a MySQL error code. |
| 1277 |
Also tells to MySQL about a possible transaction rollback inside InnoDB caused |
| 1278 |
by a lock wait timeout or a deadlock. |
| 1279 |
@param[in] error InnoDB error code. |
| 1280 |
@param[in] flags InnoDB table flags or 0. |
| 1281 |
@param[in] thd MySQL thread or NULL. |
| 1282 |
@return MySQL error code */ |
| 1283 |
int convert_error_code_to_mysql(dberr_t error, uint32_t flags, THD *thd); |
| 1284 |
|
| 1285 |
/** Converts a search mode flag understood by MySQL to a flag understood |
| 1286 |
by InnoDB. |
| 1287 |
@param[in] find_flag MySQL search mode flag. |
| 1288 |
@return InnoDB search mode flag. */ |
| 1289 |
page_cur_mode_t convert_search_mode_to_innobase( |
| 1290 |
enum ha_rkey_function find_flag); |
| 1291 |
|
| 1292 |
extern bool innobase_stats_on_metadata; |
| 1293 |
|
| 1294 |
/** Calculate Record Per Key value. |
| 1295 |
Need to exclude the NULL value if innodb_stats_method is set to "nulls_ignored" |
| 1296 |
@param[in] index InnoDB index. |
| 1297 |
@param[in] i The column we are calculating rec per key. |
| 1298 |
@param[in] records Estimated total records. |
| 1299 |
@return estimated record per key value */ |
| 1300 |
rec_per_key_t innodb_rec_per_key(const dict_index_t *index, ulint i, |
| 1301 |
ha_rows records); |
| 1302 |
|
| 1303 |
/** Build template for the virtual columns and their base columns. This |
| 1304 |
is done when the table first opened. |
| 1305 |
@param[in] table MySQL TABLE |
| 1306 |
@param[in] ib_table InnoDB dict_table_t |
| 1307 |
@param[in,out] s_templ InnoDB template structure |
| 1308 |
@param[in] add_v new virtual columns added along with |
| 1309 |
add index call |
| 1310 |
@param[in] locked true if dict_sys mutex is held |
| 1311 |
@param[in] share_tbl_name original MySQL table name */ |
| 1312 |
void innobase_build_v_templ(const TABLE *table, const dict_table_t *ib_table, |
| 1313 |
dict_vcol_templ_t *s_templ, |
| 1314 |
const dict_add_v_col_t *add_v, bool locked, |
| 1315 |
const char *share_tbl_name); |
| 1316 |
|
| 1317 |
/** Callback used by MySQL server layer to initialize |
| 1318 |
the table virtual columns' template |
| 1319 |
@param[in] table MySQL TABLE |
| 1320 |
@param[in,out] ib_table InnoDB table */ |
| 1321 |
void innobase_build_v_templ_callback(const TABLE *table, void *ib_table); |
| 1322 |
|
| 1323 |
/** Callback function definition, used by MySQL server layer to initialized |
| 1324 |
the table virtual columns' template */ |
| 1325 |
typedef void (*my_gcolumn_templatecallback_t)(const TABLE *, void *); |
| 1326 |
|
| 1327 |
/** Drop the statistics for a specified table, and mark it as discard |
| 1328 |
after DDL |
| 1329 |
@param[in,out] thd THD object |
| 1330 |
@param[in,out] table InnoDB table object */ |
| 1331 |
void innobase_discard_table(THD *thd, dict_table_t *table); |
| 1332 |
#endif /* ha_innodb_h */ |