MySQL 9.2.0
Source Code Documentation
ha_innodb.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2000, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 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"
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
45system clustered index when there is no primary key. */
46extern const char innobase_index_reserve_name[];
47
48/** Clone protocol service. */
49extern SERVICE_TYPE(clone_protocol) * clone_protocol_svc;
50
51/* Structure defines translation table between mysql index and InnoDB
52index structures */
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 */
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() */
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 */
78struct row_prebuilt_t;
79
80namespace dd {
81namespace cache {
82class Dictionary_client;
83}
84} // namespace dd
85
86/** The class defining a handle to an InnoDB table */
87class 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
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
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
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
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
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 */
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
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 */
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
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 parallel_scan
439 @param[out] num_threads Number of threads to be spawned
440 @param[in] use_reserved_threads true if reserved threads are to be used
441 if we exhaust the max cap of number of
442 parallel read threads that can be
443 spawned at a time
444 @param[in] max_desired_threads Maximum number of desired read threads;
445 passing 0 has no effect, it is ignored;
446 upper-limited by the current value of
447 innodb_parallel_read_threads.
448 @return error code
449 @retval 0 on success */
450 int parallel_scan_init(void *&scan_ctx, size_t *num_threads,
451 bool use_reserved_threads,
452 size_t max_desired_threads) override;
453
454 /** Start parallel read of InnoDB records.
455 @param[in] scan_ctx A scan context created by parallel_scan_init
456 @param[in] thread_ctxs Context for each of the spawned threads
457 @param[in] init_fn Callback called by each parallel load
458 thread at the beginning of the parallel load.
459 @param[in] load_fn Callback called by each parallel load
460 thread when processing of rows is required.
461 @param[in] end_fn Callback called by each parallel load
462 thread when processing of rows has ended.
463 @return error code
464 @retval 0 on success */
465 int parallel_scan(void *scan_ctx, void **thread_ctxs, Reader::Init_fn init_fn,
466 Reader::Load_fn load_fn, Reader::End_fn end_fn) override;
467
468 /** End of the parallel scan.
469 @param[in] scan_ctx A scan context created by parallel_scan_init. */
470 void parallel_scan_end(void *scan_ctx) override;
471
472 /** Check if the table is ready for bulk load
473 @param[in] thd user session
474 @return true iff bulk load can be done on the table. */
475 bool bulk_load_check(THD *thd) const override;
476
477 /** Get the total memory available for bulk load in innodb buffer pool.
478 @param[in] thd user session
479 @return available memory for bulk load */
480 size_t bulk_load_available_memory(THD *thd) const override;
481
482 /** Begin parallel bulk data load to the table.
483 @param[in] thd user session
484 @param[in] keynr key number to identify the index.
485 @param[in] data_size total data size in bytes
486 @param[in] memory buffer pool memory to be used
487 @param[in] num_threads Number of concurrent threads used for load.
488 @return bulk load context or nullptr if unsuccessful. */
489 void *bulk_load_begin(THD *thd, size_t keynr, size_t data_size, size_t memory,
490 size_t num_threads) override;
491
492 /** Execute bulk load operation. To be called by each of the concurrent
493 threads idenified by thread index.
494 @param[in,out] thd user session
495 @param[in,out] load_ctx load execution context
496 @param[in] thread_idx index of the thread executing
497 @param[in] rows rows to be loaded to the table
498 @param[in] wait_cbk Stat callbacks
499 @return error code. */
500 int bulk_load_execute(THD *thd, void *load_ctx, size_t thread_idx,
501 const Rows_mysql &rows,
502 Bulk_load::Stat_callbacks &wait_cbk) override;
503
504 /** Open a blob for write operation.
505 @param[in,out] thd user session
506 @param[in,out] load_ctx load execution context
507 @param[in] thread_idx index of the thread executing
508 @param[out] blob_ctx a blob context
509 @param[out] blobref a blob reference to be placed in the record.
510 @return 0 on success, error code on failure */
511 int open_blob(THD *thd [[maybe_unused]], void *load_ctx, size_t thread_idx,
512 Blob_context &blob_ctx, unsigned char *blobref) override;
513
514 /** Write to a blob
515 @param[in,out] thd user session
516 @param[in,out] load_ctx load execution context
517 @param[in] thread_idx index of the thread executing
518 @param[in] blob_ctx a blob context
519 @param[out] blobref buffer to hold a blob reference.
520 @param[in] data data to be written to blob.
521 @param[in] data_len length of data to be written in bytes.
522 @return 0 on success, error code on failure */
523 int write_blob(THD *thd [[maybe_unused]], void *load_ctx, size_t thread_idx,
524 Blob_context blob_ctx, unsigned char *blobref,
525 const unsigned char *data, size_t data_len) override;
526
527 /** Close the blob
528 @param[in,out] thd user session
529 @param[in,out] load_ctx load execution context
530 @param[in] thread_idx index of the thread executing
531 @param[in] blob_ctx a blob context
532 @param[out] blobref blob reference will be populated in the provided
533 buffer. The buffer should have enough space (@ref lob::ref_t::SIZE) to hold
534 a blob reference.
535 @return 0 on success, error code on failure */
536 int close_blob(THD *thd [[maybe_unused]], void *load_ctx, size_t thread_idx,
537 Blob_context blob_ctx, byte *blobref) override;
538
539 /** End bulk load operation. Must be called after all execution threads have
540 completed. Must be called even if the bulk load execution failed.
541 @param[in,out] thd user session
542 @param[in,out] load_ctx load execution context
543 @param[in] is_error true, if bulk load execution have failed
544 @return error code. */
545 int bulk_load_end(THD *thd, void *load_ctx, bool is_error) override;
546
548 uint table_changes) override;
549
550 private:
551 /** @name Multi Range Read interface
552 @{ */
553
554 /** Initialize multi range read @see DsMrr_impl::dsmrr_init */
555 int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
556 uint n_ranges, uint mode,
557 HANDLER_BUFFER *buf) override;
558
559 /** Process next multi range read @see DsMrr_impl::dsmrr_next */
560 int multi_range_read_next(char **range_info) override;
561
562 /** Initialize multi range read and get information.
563 @see ha_myisam::multi_range_read_info_const
564 @see DsMrr_impl::dsmrr_info_const */
566 void *seq_init_param, uint n_ranges,
567 uint *bufsz, uint *flags,
568 bool *force_default_mrr,
569 Cost_estimate *cost) override;
570
571 /** Initialize multi range read and get information.
572 @see DsMrr_impl::dsmrr_info */
573 ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
574 uint *bufsz, uint *flags,
575 Cost_estimate *cost) override;
576
577 /** Attempt to push down an index condition.
578 @param[in] keyno MySQL key number
579 @param[in] idx_cond Index condition to be checked
580 @return idx_cond if pushed; NULL if not pushed */
581 Item *idx_cond_push(uint keyno, Item *idx_cond) override;
582 /** @} */
583
584 private:
585 void update_thd();
586
587 int change_active_index(uint keynr);
588
590
592
594
596
597 /** Resets a query execution 'template'.
598 @see build_template() */
599 void reset_template();
600
601 /** Write Row Interface optimized for Intrinsic table. */
603
604 /** Find out if a Record_buffer is wanted by this handler, and what is
605 the maximum buffer size the handler wants.
606
607 @param[out] max_rows gets set to the maximum number of records to
608 allocate space for in the buffer
609 @retval true if the handler wants a buffer
610 @retval false if the handler does not want a buffer */
611 bool is_record_buffer_wanted(ha_rows *const max_rows) const override;
612
613 /** TRUNCATE an InnoDB table.
614 @param[in] name table name
615 @param[in] form table definition
616 @param[in,out] table_def dd::Table describing table to be
617 truncated. Can be adjusted by SE, the changes will be saved into
618 the data-dictionary at statement commit time.
619 @return error number
620 @retval 0 on success */
621 int truncate_impl(const char *name, TABLE *form, dd::Table *table_def);
622
623 protected:
624 /** Enter InnoDB engine after checking max allowed threads.
625 @return mysql error code. */
627
628 /** Leave Innodb, if no more tickets are left */
630
631 void update_thd(THD *thd);
632
633 int general_fetch(uchar *buf, uint direction, uint match_mode);
634
635 virtual dict_index_t *innobase_get_index(uint keynr);
636
637 /** Builds a 'template' to the m_prebuilt struct. The template is used in fast
638 retrieval of just those column values MySQL needs in its processing.
639 @param[in] whole_row true if access is needed to a whole row, false if
640 accessing individual fields is enough */
641 void build_template(bool whole_row);
642
643 /** Returns statistics information of the table to the MySQL interpreter, in
644 various fields of the handle object.
645 @param[in] flag what information is requested
646 @param[in] is_analyze True if called from "::analyze()".
647 @return HA_ERR_* error code or 0 */
648 virtual int info_low(uint flag, bool is_analyze);
649
650 /**
651 MySQL calls this method at the end of each statement. This method
652 exists for readability only, called from reset(). The name reset()
653 doesn't give any clue that it is called at the end of a statement. */
654 int end_stmt();
655
656 /** Implementation of prepare_inplace_alter_table()
657 @tparam Table dd::Table or dd::Partition
658 @param[in] altered_table TABLE object for new version of table.
659 @param[in,out] ha_alter_info Structure describing changes to be done
660 by ALTER TABLE and holding data used
661 during in-place alter.
662 @param[in] old_dd_tab dd::Table object representing old
663 version of the table
664 @param[in,out] new_dd_tab dd::Table object representing new
665 version of the table
666 @retval true Failure
667 @retval false Success */
668 template <typename Table>
669 bool prepare_inplace_alter_table_impl(TABLE *altered_table,
670 Alter_inplace_info *ha_alter_info,
671 const Table *old_dd_tab,
672 Table *new_dd_tab);
673
674 /** Implementation of inplace_alter_table()
675 @tparam Table dd::Table or dd::Partition
676 @param[in] altered_table TABLE object for new version of table.
677 @param[in,out] ha_alter_info Structure describing changes to be done
678 by ALTER TABLE and holding data used
679 during in-place alter.
680 the table. Can be adjusted by this call. Changes to the table definition will
681 be persisted in the data-dictionary at statement commit time.
682 @retval true Failure
683 @retval false Success
684 */
685 template <typename Table>
686 bool inplace_alter_table_impl(TABLE *altered_table,
687 Alter_inplace_info *ha_alter_info);
688
689 /** Implementation of commit_inplace_alter_table()
690 @tparam Table dd::Table or dd::Partition
691 @param[in] altered_table TABLE object for new version of table.
692 @param[in,out] ha_alter_info Structure describing changes to be done
693 by ALTER TABLE and holding data used
694 during in-place alter.
695 @param[in] commit True to commit or false to rollback.
696 @param[in,out] new_dd_tab Table object for the new version of the
697 table. Can be adjusted by this call.
698 Changes to the table definition
699 will be persisted in the data-dictionary
700 at statement version of it.
701 @retval true Failure
702 @retval false Success */
703 template <typename Table>
704 bool commit_inplace_alter_table_impl(TABLE *altered_table,
705 Alter_inplace_info *ha_alter_info,
706 bool commit, Table *new_dd_tab);
707
708 /**
709 Return max limits for a single set of multi-valued keys
710
711 @param[out] num_keys number of keys to store
712 @param[out] keys_length total length of keys, bytes
713 */
714 void mv_key_capacity(uint *num_keys, size_t *keys_length) const override;
715
716 /** Can reuse the template. Mainly used for partition.
717 @retval true Can reuse the mysql_template */
718 virtual bool can_reuse_mysql_template() const { return false; }
719
720 /** The multi range read session object */
722
723 /** Save CPU time with prebuilt/cached data structures */
725
726 /** Thread handle of the user currently using the handler;
727 this is set in external_lock function */
729
730 /** information for MySQL table locking */
732
733 /** buffer used in updates */
735
736 /** the size of upd_buf in bytes */
738
739 /** Flags that specify the handler instance (table) capability. */
741
742 /** this is set to 1 when we are starting a table scan but have
743 not yet fetched any row, else false */
745
746 /*!< match mode of the latest search: ROW_SEL_EXACT,
747 ROW_SEL_EXACT_PREFIX, or undefined */
749
750 /** this field is used to remember the original select_lock_type that
751 was decided in ha_innodb.cc,":: store_lock()", "::external_lock()",
752 etc. */
754
755 /** If mysql has locked with external_lock() */
757};
758
759struct trx_t;
760
761extern const struct _ft_vft ft_vft_result;
762
763/** Return the number of read threads for this session.
764@param[in] thd Session instance, or nullptr to query the global
765 innodb_parallel_read_threads value. */
767
768/** Structure Returned by ha_innobase::ft_init_ext() */
769typedef struct new_ft_info {
775
776/** Allocates an InnoDB transaction for a MySQL handler object for DML.
777@param[in] hton Innobase handlerton.
778@param[in] thd MySQL thd (connection) object.
779@param[in] trx transaction to register. */
780void innobase_register_trx(handlerton *hton, THD *thd, trx_t *trx);
781
782/**
783Allocates an InnoDB transaction for a MySQL handler object.
784@return InnoDB transaction handle */
785trx_t *innobase_trx_allocate(THD *thd); /*!< in: user thread handle */
786
787/** Maps a MySQL trx isolation level code to the InnoDB isolation level code.
788@param[in] iso MySQL isolation level code
789@return InnoDB isolation level */
792
793/** Match index columns between MySQL and InnoDB.
794This function checks whether the index column information
795is consistent between KEY info from mysql and that from innodb index.
796@param[in] key_info Index info from mysql
797@param[in] index_info Index info from InnoDB
798@return true if all column types match. */
799bool innobase_match_index_columns(const KEY *key_info,
800 const dict_index_t *index_info);
801
802/** This function checks each index name for a table against reserved
803 system default primary index name 'GEN_CLUST_INDEX'. If a name
804 matches, this function pushes an warning message to the client,
805 and returns true.
806 @return true if the index name matches the reserved name */
807[[nodiscard]] bool innobase_index_name_is_reserved(
808 THD *thd, /*!< in/out: MySQL connection */
809 const KEY *key_info, /*!< in: Indexes to be
810 created */
811 ulint num_of_keys); /*!< in: Number of indexes to
812 be created. */
813
814/** Check if the explicit tablespace targeted is file_per_table.
815@param[in] create_info Metadata for the table to create.
816@return true if the table is intended to use a file_per_table tablespace. */
818 const HA_CREATE_INFO *create_info) {
819 return (create_info->tablespace != nullptr &&
820 (0 ==
821 strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)));
822}
823
824/** Check if table will be explicitly put in an existing shared general
825or system tablespace.
826@param[in] create_info Metadata for the table to create.
827@return true if the table will use a shared general or system tablespace. */
828static inline bool tablespace_is_shared_space(
829 const HA_CREATE_INFO *create_info) {
830 return (create_info->tablespace != nullptr &&
831 create_info->tablespace[0] != '\0' &&
832 (0 !=
833 strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)));
834}
835
836/** Check if table will be explicitly put in a general tablespace.
837@param[in] create_info Metadata for the table to create.
838@return true if the table will use a general tablespace. */
840 const HA_CREATE_INFO *create_info) {
841 return (
842 create_info->tablespace != nullptr &&
843 create_info->tablespace[0] != '\0' &&
844 (0 !=
845 strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)) &&
846 (0 != strcmp(create_info->tablespace, dict_sys_t::s_temp_space_name)) &&
847 (0 != strcmp(create_info->tablespace, dict_sys_t::s_sys_space_name)));
848}
849
850/** Check if tablespace is shared tablespace.
851@param[in] tablespace_name Name of the tablespace
852@return true if tablespace is a shared tablespace. */
853static inline bool is_shared_tablespace(const char *tablespace_name) {
854 if (tablespace_name != nullptr && tablespace_name[0] != '\0' &&
855 (strcmp(tablespace_name, dict_sys_t::s_file_per_table_name) != 0)) {
856 return true;
857 }
858 return false;
859}
860
861constexpr uint32_t SIZE_MB = 1024 * 1024;
862
863/** Validate AUTOEXTEND_SIZE attribute for a tablespace.
864@param[in] ext_size Value of autoextend_size attribute
865@return DB_SUCCESS if the value of AUTOEXTEND_SIZE is valid. */
866static inline int validate_autoextend_size_value(uint64_t ext_size) {
867 ut_ad(ext_size > 0);
868
869 page_no_t extent_size_pages = fsp_get_extent_size_in_pages(
870 {static_cast<uint32_t>(srv_page_size),
871 static_cast<uint32_t>(srv_page_size), false});
872
873 /* Validate following for the AUTOEXTEND_SIZE attribute
874 1. The autoextend_size should be a multiple of size of 4 extents
875 2. The autoextend_size value should be between size of 4 extents and 4G */
876 if (ext_size < (FSP_FREE_ADD * extent_size_pages * srv_page_size) ||
877 ext_size > FSP_MAX_AUTOEXTEND_SIZE) {
878 my_error(ER_INNODB_AUTOEXTEND_SIZE_OUT_OF_RANGE, MYF(0),
879 (FSP_FREE_ADD * extent_size_pages * srv_page_size) / SIZE_MB,
881 return ER_INNODB_AUTOEXTEND_SIZE_OUT_OF_RANGE;
882 }
883
884 if ((ext_size / srv_page_size) % (FSP_FREE_ADD * extent_size_pages) != 0) {
885 my_error(ER_INNODB_INVALID_AUTOEXTEND_SIZE_VALUE, MYF(0),
886 FSP_FREE_ADD * extent_size_pages * srv_page_size / SIZE_MB);
887 return ER_INNODB_INVALID_AUTOEXTEND_SIZE_VALUE;
888 }
889
890 return DB_SUCCESS;
891}
892
893/** Parse hint for table and its indexes, and update the information
894in dictionary.
895@param[in] thd Connection thread
896@param[in,out] table Target table
897@param[in] table_share Table definition */
899 const TABLE_SHARE *table_share);
900
901/** Obtain the InnoDB transaction of a MySQL thread.
902@param[in,out] thd MySQL thread handler.
903@return reference to transaction pointer */
904trx_t *&thd_to_trx(THD *thd);
905
906/** Class for handling create table information. */
908 public:
909 /** Constructor.
910 Used in two ways:
911 - all but file_per_table is used, when creating the table.
912 - all but name/path is used, when validating options and using flags. */
914 char *table_name, char *remote_path, char *tablespace,
915 bool file_per_table, bool skip_strict, uint32_t old_flags,
916 uint32_t old_flags2, bool is_partition)
917 : m_thd(thd),
919 m_form(form),
920 m_create_info(create_info),
922 m_remote_path(remote_path),
923 m_tablespace(tablespace),
924 m_innodb_file_per_table(file_per_table),
925 m_flags(old_flags),
926 m_flags2(old_flags2),
929
930 /** Initialize the object. */
931 int initialize();
932
933 /** Set m_tablespace_type. */
934 void set_tablespace_type(bool table_being_altered_is_file_per_table);
935
936 /** Create the internal innodb table.
937 @param[in] dd_table dd::Table or nullptr for intrinsic table
938 @param[in] old_part_table dd::Table from an old partition for partitioned
939 table, NULL otherwise.
940 @return 0 or error number */
941 int create_table(const dd::Table *dd_table, const dd::Table *old_part_table);
942
943 /** Update the internal data dictionary. */
945
946 /** Update the global data dictionary.
947 @param[in] dd_table dd::Table or dd::Partition
948 @retval 0 On success
949 @retval error number On failure */
950 template <typename Table>
951 int create_table_update_global_dd(Table *dd_table);
952
953 /** Validates the create options. Checks that the options
954 KEY_BLOCK_SIZE, ROW_FORMAT, DATA DIRECTORY, TEMPORARY & TABLESPACE
955 are compatible with each other and other settings.
956 These CREATE OPTIONS are not validated here unless innodb_strict_mode
957 is on. With strict mode, this function will report each problem it
958 finds using a custom message with error code
959 ER_ILLEGAL_HA_CREATE_OPTION, not its built-in message.
960 @return NULL if valid, string name of bad option if not. */
961 const char *create_options_are_invalid();
962
963 private:
964 /** Put a warning or error message to the error log for the
965 DATA DIRECTORY option.
966 @param[in] msg The reason that data directory is wrong.
967 @param[in] ignore If true, append a message about ignoring
968 the data directory location. */
969 void log_error_invalid_location(std::string &msg, bool ignore);
970
971 public:
972 /** Validate DATA DIRECTORY option. */
974
975 /** Validate TABLESPACE option. */
977
978 /** Validate COMPRESSION option. */
980
981 /** Prepare to create a table. */
982 int prepare_create_table(const char *name);
983
984 /** Determine InnoDB table flags.
985 If strict_mode=OFF, this will adjust the flags to what should be assumed.
986 However, if an existing general tablespace is being targeted, we will NOT
987 assume anything or adjust these flags.
988 @retval true if successful, false if error */
990
991 /** Set flags and append '/' to remote path if necessary. */
993
994 /** Get table flags. */
995 uint32_t flags() const { return (m_flags); }
996
997 /** Get table flags2. */
998 uint32_t flags2() const { return (m_flags2); }
999
1000 /** Reset table flags. */
1001 void flags_reset() { m_flags = 0; }
1002
1003 /** Reset table flags2. */
1004 void flags2_reset() { m_flags2 = 0; }
1005
1006 /** whether to skip strict check. */
1007 bool skip_strict() const { return (m_skip_strict); }
1008
1009 /** Return table name. */
1010 const char *table_name() const { return (m_table_name); }
1011
1012 THD *thd() const { return (m_thd); }
1013
1014 inline bool is_intrinsic_temp_table() const {
1015 /* DICT_TF2_INTRINSIC implies DICT_TF2_TEMPORARY */
1017 return ((m_flags2 & DICT_TF2_INTRINSIC) != 0);
1018 }
1019
1020 /** @return true only if table is temporary and not intrinsic */
1021 inline bool is_temp_table() const {
1022 return (((m_flags2 & DICT_TF2_TEMPORARY) != 0) &&
1023 ((m_flags2 & DICT_TF2_INTRINSIC) == 0));
1024 }
1025
1026 /** Detach the just created table and its auxiliary tables if exist. */
1027 void detach();
1028
1029 /** Normalizes a table name string.
1030 A normalized name consists of the database name catenated to '/' and
1031 table name. An example: test/mytable. On case insensitive file system
1032 normalization converts name to lower case.
1033 @param[in,out] norm_name Buffer to return the normalized name in.
1034 @param[in] name Table name string.
1035 @return true if successful. */
1036 static bool normalize_table_name(char *norm_name, const char *name);
1037
1038 private:
1039 /** Parses the table name into normal name and either temp path or
1040 remote path if needed.*/
1041 int parse_table_name(const char *name);
1042
1043 /** Create a table definition to an InnoDB database.
1044 @param[in] dd_table dd::Table or nullptr for intrinsic table
1045 @param[in] old_part_table dd::Table from an old partition for partitioned
1046 table, NULL otherwise.
1047 @return HA_* level error */
1048 int create_table_def(const dd::Table *dd_table,
1049 const dd::Table *old_part_table);
1050
1051 /** Initialize the autoinc of this table if necessary, which should
1052 be called before we flush logs, so autoinc counter can be persisted. */
1053 void initialize_autoinc();
1054
1055 /** Connection thread handle. */
1057
1058 /** InnoDB transaction handle. */
1060
1061 /** Information on table columns and indexes. */
1063
1064 /** Create options. */
1066
1067 /** Table name */
1069 /** Remote path (DATA DIRECTORY) or zero length-string */
1071 /** Tablespace name or zero length-string. */
1073
1074 /** The newly created InnoDB table object. This is currently only
1075 used in this class, since the new table is not evictable until
1076 final success/failure, it can be accessed directly. */
1078
1079 /** Local copy of srv_file_per_table. */
1081
1082 /** Allow file_per_table for this table either because:
1083 1) the setting innodb_file_per_table=on,
1084 2) it was explicitly requested by tablespace=innodb_file_per_table.
1085 3) the table being altered is currently file_per_table */
1087
1088 /** After all considerations, this shows whether we will actually
1089 create a table and tablespace using file-per-table. */
1091
1092 /** Using DATA DIRECTORY */
1094
1095 /** Using a Shared General Tablespace */
1097
1098 /** Table flags */
1099 uint32_t m_flags;
1100
1101 /** Table flags2 */
1102 uint32_t m_flags2;
1103
1104 /** Skip strict check */
1106
1107 /** True if this table is a partition */
1109};
1110
1111/** Class of basic DDL implementation, for CREATE/DROP/RENAME TABLE */
1113 public:
1114 /** Create an InnoDB table.
1115 @tparam Table dd::Table or dd::Partition
1116 @param[in,out] thd THD object
1117 @param[in] name Table name, format: "db/table_name"
1118 @param[in] form Table format; columns and index
1119 information
1120 @param[in] create_info Create info(including create statement
1121 string)
1122 @param[in,out] dd_tab dd::Table describing table to be created
1123 @param[in] file_per_table whether to create a tablespace too
1124 @param[in] evictable whether the caller wants the
1125 dict_table_t to be kept in memory
1126 @param[in] skip_strict whether to skip strict check for create
1127 option
1128 @param[in] old_flags old Table flags
1129 @param[in] old_flags2 old Table flags2
1130 @param[in] old_dd_table Table def for old table. Used in truncate or
1131 while adding a new partition
1132 @return error number
1133 @retval 0 on success */
1134 template <typename Table>
1135 static int create_impl(THD *thd, const char *name, TABLE *form,
1136 HA_CREATE_INFO *create_info, Table *dd_tab,
1137 bool file_per_table, bool evictable, bool skip_strict,
1138 uint32_t old_flags, uint32_t old_flags2,
1139 const dd::Table *old_dd_table);
1140
1141 /** Drop an InnoDB table.
1142 @tparam Table dd::Table or dd::Partition
1143 @param[in,out] thd THD object
1144 @param[in] name table name
1145 @param[in] dd_tab dd::Table describing table to be dropped
1146 @param[in] td MySQL table definition
1147 @return error number
1148 @retval 0 on success */
1149
1150 template <typename Table>
1151 static int delete_impl(THD *thd, const char *name, const Table *dd_tab,
1152 const TABLE *td);
1153
1154 /** Renames an InnoDB table.
1155 @tparam Table dd::Table or dd::Partition
1156 @param[in,out] thd THD object
1157 @param[in] from old name of the table
1158 @param[in] to new name of the table
1159 @param[in] from_table dd::Table or dd::Partition of the table
1160 with old name
1161 @param[in] to_table dd::Table or dd::Partition of the table
1162 with new name
1163 @param[in] td MySQL table definition
1164 @return error number
1165 @retval 0 on success */
1166
1167 template <typename Table>
1168 static int rename_impl(THD *thd, const char *from, const char *to,
1169 const Table *from_table, const Table *to_table,
1170 const TABLE *td);
1171};
1172
1173/** Class to handle TRUNCATE for one InnoDB table or one partition */
1174template <typename Table>
1176 public:
1177 /** Constructor
1178 @param[in] thd THD object
1179 @param[in] name normalized table name
1180 @param[in] form Table format; columns and index information
1181 @param[in] dd_table dd::Table or dd::Partition
1182 @param[in] keep_autoinc true to remember original autoinc counter
1183 @param[in] table_truncate true if this is full table truncate */
1184 innobase_truncate(THD *thd, const char *name, TABLE *form, Table *dd_table,
1185 bool keep_autoinc, bool table_truncate)
1186 : m_thd(thd),
1187 m_name(name),
1188 m_dd_table(dd_table),
1189 m_trx(nullptr),
1191 m_form(form),
1192 m_create_info(),
1193 m_file_per_table(false),
1194 m_keep_autoinc(keep_autoinc),
1195 m_table_truncate(table_truncate),
1196 m_flags(0),
1197 m_flags2(0) {}
1198
1199 /** Destructor */
1201
1202 /** Open the table/partition to be truncated
1203 @param[out] innodb_table InnoDB table object opened
1204 @return error number or 0 on success */
1205 int open_table(dict_table_t *&innodb_table);
1206
1207 /** Do the truncate of the table/partition
1208 @return error number or 0 on success */
1209 int exec();
1210
1211 private:
1212 /** Prepare for truncate
1213 @return error number or 0 on success */
1214 int prepare();
1215
1216 /** Do the real truncation
1217 @return error number or 0 on success */
1218 int truncate();
1219
1220 /** Rename tablespace file name
1221 @return error number or 0 on success */
1222 int rename_tablespace();
1223
1224 /** Cleanup */
1225 void cleanup();
1226
1227 /** Reload the FK related information
1228 @return error number or 0 on success */
1229 int load_fk();
1230
1231 private:
1232 /** THD object */
1234
1235 /** Normalized table name */
1236 const char *m_name;
1237
1238 /** dd::Table or dd::Partition */
1240
1241 /** Transaction attached to current thd */
1243
1244 /** InnoDB table object for the table/partition */
1246
1247 /** Table format */
1249
1250 /** Create information */
1252
1253 /** True if this table/partition is file per table */
1255
1256 /** True if the original autoinc counter should be kept. It's
1257 specified by caller, however if the table has no AUTOINC column,
1258 it would be reset to false internally */
1260
1261 /** For a prtition table, this is true if full table is truncated. If only
1262 a partition is truncated, it is set to false. */
1264
1265 /** flags of the table to be truncated, which should not change */
1266 uint32_t m_flags;
1267
1268 /** flags2 of the table to be truncated, which should not change */
1269 uint32_t m_flags2;
1270};
1271
1272/**
1273Initialize the table FTS stopword list
1274@return true if success */
1275[[nodiscard]] bool innobase_fts_load_stopword(
1276 dict_table_t *table, /*!< in: Table has the FTS */
1277 trx_t *trx, /*!< in: transaction */
1278 THD *thd); /*!< in: current thread */
1279
1280/** Some defines for innobase_fts_check_doc_id_index() return value */
1286
1287/**
1288Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME
1289on the Doc ID column.
1290@return the status of the FTS_DOC_ID index */
1292 const dict_table_t *table, /*!< in: table definition */
1293 const TABLE *altered_table, /*!< in: MySQL table
1294 that is being altered */
1295 ulint *fts_doc_col_no); /*!< out: The column number for
1296 Doc ID */
1297
1298/**
1299Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME
1300on the Doc ID column in MySQL create index definition.
1301@return FTS_EXIST_DOC_ID_INDEX if there exists the FTS_DOC_ID index,
1302FTS_INCORRECT_DOC_ID_INDEX if the FTS_DOC_ID index is of wrong format */
1304 ulint n_key, /*!< in: Number of keys */
1305 const KEY *key_info); /*!< in: Key definitions */
1306
1307/**
1308Copy table flags from MySQL's TABLE_SHARE into an InnoDB table object.
1309Those flags are stored in .frm file and end up in the MySQL table object,
1310but are frequently used inside InnoDB so we keep their copies into the
1311InnoDB table object. */
1313 dict_table_t *innodb_table, /*!< in/out: InnoDB table */
1314 const TABLE_SHARE *table_share); /*!< in: table share */
1315
1316/** Set up base columns for virtual column
1317@param[in] table the InnoDB table
1318@param[in] field MySQL field
1319@param[in,out] v_col virtual column to be set up */
1320void innodb_base_col_setup(dict_table_t *table, const Field *field,
1321 dict_v_col_t *v_col);
1322
1323/** Set up base columns for stored column
1324@param[in] table InnoDB table
1325@param[in] field MySQL field
1326@param[in,out] s_col stored column */
1328 const Field *field, dict_s_col_t *s_col);
1329
1330/** whether this is a stored column */
1331static inline bool innobase_is_s_fld(const Field *field) {
1332 return field->gcol_info && field->stored_in_db;
1333}
1334
1335/** Whether this is a computed multi-value virtual column.
1336This condition check should be equal to the following one:
1337(innobase_is_v_fld(field) && (field)->gcol_info->expr_item &&
1338 field->gcol_info->expr_item->returns_array())
1339*/
1340static inline bool innobase_is_multi_value_fld(const Field *field) {
1341 return field->is_array();
1342}
1343
1344static inline bool normalize_table_name(char *norm_name, const char *name) {
1346}
1347
1348/** Note that a transaction has been registered with MySQL.
1349@param[in] trx Transaction.
1350@return true if transaction is registered with MySQL 2PC coordinator */
1351inline bool trx_is_registered_for_2pc(const trx_t *trx) {
1352 return (trx->is_registered == 1);
1353}
1354
1355/** Converts an InnoDB error code to a MySQL error code.
1356Also tells to MySQL about a possible transaction rollback inside InnoDB caused
1357by a lock wait timeout or a deadlock.
1358@param[in] error InnoDB error code.
1359@param[in] flags InnoDB table flags or 0.
1360@param[in] thd MySQL thread or NULL.
1361@return MySQL error code */
1363
1364/** Converts a search mode flag understood by MySQL to a flag understood
1365by InnoDB.
1366@param[in] find_flag MySQL search mode flag.
1367@return InnoDB search mode flag. */
1369 enum ha_rkey_function find_flag);
1370
1371extern bool innobase_stats_on_metadata;
1372
1373/** Calculate Record Per Key value.
1374Need to exclude the NULL value if innodb_stats_method is set to "nulls_ignored"
1375@param[in] index InnoDB index.
1376@param[in] i The column we are calculating rec per key.
1377@param[in] records Estimated total records.
1378@return estimated record per key value */
1380 ha_rows records);
1381
1382/** Build template for the virtual columns and their base columns. This
1383is done when the table first opened.
1384@param[in] table MySQL TABLE
1385@param[in] ib_table InnoDB dict_table_t
1386@param[in,out] s_templ InnoDB template structure
1387@param[in] add_v new virtual columns added along with
1388 add index call
1389@param[in] locked true if dict_sys mutex is held
1390@param[in] share_tbl_name original MySQL table name */
1391void innobase_build_v_templ(const TABLE *table, const dict_table_t *ib_table,
1392 dict_vcol_templ_t *s_templ,
1393 const dict_add_v_col_t *add_v, bool locked,
1394 const char *share_tbl_name);
1395
1396/** Callback used by MySQL server layer to initialize
1397the table virtual columns' template
1398@param[in] table MySQL TABLE
1399@param[in,out] ib_table InnoDB table */
1400void innobase_build_v_templ_callback(const TABLE *table, void *ib_table);
1401
1402/** Callback function definition, used by MySQL server layer to initialized
1403the table virtual columns' template */
1404typedef void (*my_gcolumn_templatecallback_t)(const TABLE *, void *);
1405
1406/** Drop the statistics for a specified table, and mark it as discard
1407after DDL
1408@param[in,out] thd THD object
1409@param[in,out] table InnoDB table object */
1411#endif /* ha_innodb_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:46
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
Class describing changes to be done by ALTER TABLE.
Definition: handler.h:3408
Used to store optimizer cost estimates.
Definition: handler.h:3920
Definition: handler.h:7379
Definition: field.h:577
virtual bool is_array() const
Whether the field is a typed array.
Definition: field.h:1803
Value_generator * gcol_info
Definition: field.h:815
bool stored_in_db
Indication that the field is physically stored in tables rather than just generated on SQL queries.
Definition: field.h:821
Wrapper for struct ft_hints.
Definition: handler.h:4187
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:930
Definition: key.h:113
Definition: sql_list.h:494
Traverse an index in the leaf page block list order and send records to adapter.
Definition: row0pread-adapter.h:43
handler::Load_init_cbk Init_fn
Definition: row0pread-adapter.h:55
handler::Load_end_cbk End_fn
Definition: row0pread-adapter.h:53
handler::Load_cbk Load_fn
Definition: row0pread-adapter.h:51
Implements the row and column memory management for parse and load operations.
Definition: bulk_data_service.h:291
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
Class for handling create table information.
Definition: ha_innodb.h:907
bool is_intrinsic_temp_table() const
Definition: ha_innodb.h:1014
bool m_use_file_per_table
After all considerations, this shows whether we will actually create a table and tablespace using fil...
Definition: ha_innodb.h:1090
int prepare_create_table(const char *name)
Prepare to create a table.
Definition: ha_innodb.cc:13956
const char * table_name() const
Return table name.
Definition: ha_innodb.h:1010
uint32_t m_flags
Table flags.
Definition: ha_innodb.h:1099
THD * m_thd
Connection thread handle.
Definition: ha_innodb.h:1056
bool create_option_tablespace_is_valid()
Validate TABLESPACE option.
Definition: ha_innodb.cc:12694
char * m_remote_path
Remote path (DATA DIRECTORY) or zero length-string.
Definition: ha_innodb.h:1070
int create_table_update_global_dd(Table *dd_table)
Update the global data dictionary.
Definition: ha_innodb.cc:14329
bool create_option_compression_is_valid()
Validate COMPRESSION option.
Definition: ha_innodb.cc:12937
void flags2_reset()
Reset table flags2.
Definition: ha_innodb.h:1004
void initialize_autoinc()
Initialize the autoinc of this table if necessary, which should be called before we flush logs,...
Definition: ha_innodb.cc:13893
HA_CREATE_INFO * m_create_info
Create options.
Definition: ha_innodb.h:1065
bool is_temp_table() const
Definition: ha_innodb.h:1021
int initialize()
Initialize the object.
Definition: ha_innodb.cc:13865
dict_table_t * m_table
The newly created InnoDB table object.
Definition: ha_innodb.h:1077
void detach()
Detach the just created table and its auxiliary tables if exist.
Definition: ha_innodb.cc:13704
trx_t * m_trx
InnoDB transaction handle.
Definition: ha_innodb.h:1059
bool m_partition
True if this table is a partition.
Definition: ha_innodb.h:1108
uint32_t flags2() const
Get table flags2.
Definition: ha_innodb.h:998
int create_table(const dd::Table *dd_table, const dd::Table *old_part_table)
Create the internal innodb table.
Definition: ha_innodb.cc:14070
static bool normalize_table_name(char *norm_name, const char *name)
Normalizes a table name string.
Definition: ha_innodb.cc:6750
bool m_use_data_dir
Using DATA DIRECTORY.
Definition: ha_innodb.h:1093
char * m_tablespace
Tablespace name or zero length-string.
Definition: ha_innodb.h:1072
bool m_allow_file_per_table
Allow file_per_table for this table either because: 1) the setting innodb_file_per_table=on,...
Definition: ha_innodb.h:1086
bool m_use_shared_space
Using a Shared General Tablespace.
Definition: ha_innodb.h:1096
uint32_t m_flags2
Table flags2.
Definition: ha_innodb.h:1102
bool m_skip_strict
Skip strict check.
Definition: ha_innodb.h:1105
int parse_table_name(const char *name)
Parses the table name into normal name and either temp path or remote path if needed.
Definition: ha_innodb.cc:13370
create_table_info_t(THD *thd, TABLE *form, HA_CREATE_INFO *create_info, char *table_name, char *remote_path, char *tablespace, bool file_per_table, bool skip_strict, uint32_t old_flags, uint32_t old_flags2, bool is_partition)
Constructor.
Definition: ha_innodb.h:913
int create_table_update_dict()
Update the internal data dictionary.
Definition: ha_innodb.cc:14278
void set_tablespace_type(bool table_being_altered_is_file_per_table)
Set m_tablespace_type.
Definition: ha_innodb.cc:13834
bool m_innodb_file_per_table
Local copy of srv_file_per_table.
Definition: ha_innodb.h:1080
bool innobase_table_flags()
Determine InnoDB table flags.
Definition: ha_innodb.cc:13438
const TABLE * m_form
Information on table columns and indexes.
Definition: ha_innodb.h:1062
void set_remote_path_flags()
Set flags and append '/' to remote path if necessary.
Definition: ha_innopart.cc:2375
char * m_table_name
Table name.
Definition: ha_innodb.h:1068
void log_error_invalid_location(std::string &msg, bool ignore)
Put a warning or error message to the error log for the DATA DIRECTORY option.
Definition: ha_innodb.cc:12506
uint32_t flags() const
Get table flags.
Definition: ha_innodb.h:995
bool skip_strict() const
whether to skip strict check.
Definition: ha_innodb.h:1007
void flags_reset()
Reset table flags.
Definition: ha_innodb.h:1001
THD * thd() const
Definition: ha_innodb.h:1012
const char * create_options_are_invalid()
Validates the create options.
Definition: ha_innodb.cc:13001
bool create_option_data_directory_is_valid(bool ignore=false)
Validate DATA DIRECTORY option.
Definition: ha_innodb.cc:12527
int create_table_def(const dd::Table *dd_table, const dd::Table *old_part_table)
Create a table definition to an InnoDB database.
Definition: ha_innodb.cc:11659
Definition: table.h:47
The class defining a handle to an InnoDB table.
Definition: ha_innodb.h:87
THD * m_user_thd
Thread handle of the user currently using the handler; this is set in external_lock function.
Definition: ha_innodb.h:728
void mv_key_capacity(uint *num_keys, size_t *keys_length) const override
Return max limits for a single set of multi-valued keys.
Definition: ha_innodb.cc:24158
int reset() override
MySQL calls this method at the end of each statement.
Definition: ha_innodb.cc:18770
int open_blob(THD *thd, void *load_ctx, size_t thread_idx, Blob_context &blob_ctx, unsigned char *blobref) override
Open a blob for write operation.
Definition: handler0alter.cc:11214
int ft_init() override
Initialize FT index scan.
Definition: ha_innodb.cc:11202
int parallel_scan_init(void *&scan_ctx, size_t *num_threads, bool use_reserved_threads, size_t max_desired_threads) override
Initializes a parallel scan.
Definition: handler0alter.cc:1463
Table_flags table_flags() const override
Get the table flags to use for the statement.
Definition: ha_innodb.cc:6639
DsMrr_impl m_ds_mrr
The multi range read session object.
Definition: ha_innodb.h:721
int disable_indexes(uint mode) override
Disable indexes.
Definition: ha_innodb.cc:18375
int sample_init(void *&scan_ctx, double sampling_percentage, int sampling_seed, enum_sampling_method sampling_method, const bool tablesample) override
Initialize sampling.
Definition: ha_innodb.cc:10997
int delete_table(const char *name, const dd::Table *table_def, enum enum_sql_command sqlcom)
Drop a table.
uchar * m_upd_buf
buffer used in updates
Definition: ha_innodb.h:734
Item * idx_cond_push(uint keyno, Item *idx_cond) override
Attempt to push down an index condition.
Definition: ha_innodb.cc:24116
int general_fetch(uchar *buf, uint direction, uint match_mode)
Reads the next or previous row from a cursor, which must have previously been positioned using index_...
Definition: ha_innodb.cc:10839
uint m_last_match_mode
Definition: ha_innodb.h:748
int rnd_pos(uchar *buf, uchar *pos) override
Fetches a row from the table based on a row reference.
Definition: ha_innodb.cc:11171
int extra(ha_extra_function operation) override
Tells something additional to the handler about how to do things.
Definition: ha_innodb.cc:18649
void build_template(bool whole_row)
Builds a 'template' to the m_prebuilt struct.
Definition: ha_innodb.cc:8689
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create an InnoDB table.
Definition: ha_innodb.cc:15406
bool is_record_buffer_wanted(ha_rows *const max_rows) const override
Find out if a Record_buffer is wanted by this handler, and what is the maximum buffer size the handle...
Definition: ha_innodb.cc:24135
double scan_time() override
How many seeks it will take to read through the table.
Definition: ha_innodb.cc:17166
void innobase_initialize_autoinc()
Set the autoinc column max value.
Definition: ha_innodb.cc:7367
int discard_or_import_tablespace(bool discard, dd::Table *table_def) override
Discards or imports an InnoDB tablespace.
Definition: ha_innodb.cc:15439
handler * clone(const char *name, MEM_ROOT *mem_root) override
Definition: ha_innodb.cc:7956
void srv_concurrency_exit()
Leave Innodb, if no more tickets are left.
Definition: ha_innodb.cc:2950
ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys, uint *bufsz, uint *flags, Cost_estimate *cost) override
Initialize multi range read and get information.
Definition: ha_innodb.cc:23788
bool primary_key_is_clustered() const override
Determines if the primary key is clustered index.
Definition: ha_innodb.cc:6748
int intrinsic_table_write_row(uchar *record)
Write Row Interface optimized for Intrinsic table.
Definition: ha_innodb.cc:9081
int start_stmt(THD *thd, thr_lock_type lock_type) override
MySQL calls this function at the start of each SQL statement inside LOCK TABLES.
Definition: ha_innodb.cc:18784
ulong index_flags(uint idx, uint part, bool all_parts) const override
Returns the operations supported for indexes.
Definition: ha_innodb.cc:6678
int rnd_end() override
Ends a table scan.
Definition: ha_innodb.cc:11136
int update_row(const uchar *old_data, uchar *new_data) override
Updates a row given as a parameter to a new value.
Definition: ha_innodb.cc:10069
int index_end() override
Currently does nothing.
Definition: ha_innodb.cc:10379
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key) override
Estimates the number of index records in a range.
Definition: ha_innodb.cc:16999
virtual dict_index_t * innobase_get_index(uint keynr)
Get the index for a handle.
Definition: ha_innodb.cc:10694
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_innodb.cc:7973
int get_extra_columns_and_keys(const HA_CREATE_INFO *, const List< Create_field > *, const KEY *, uint, dd::Table *dd_table) override
Add hidden columns and indexes to an InnoDB table definition.
Definition: ha_innodb.cc:15094
int multi_range_read_next(char **range_info) override
Process next multi range read.
Definition: ha_innodb.cc:23773
row_prebuilt_t * m_prebuilt
Save CPU time with prebuilt/cached data structures.
Definition: ha_innodb.h:724
bool m_mysql_has_locked
If mysql has locked with external_lock()
Definition: ha_innodb.h:756
int index_next_same(uchar *buf, const uchar *key, uint keylen) override
Reads the next row matching to the key value given as the parameter.
Definition: ha_innodb.cc:10934
void * bulk_load_begin(THD *thd, size_t keynr, size_t data_size, size_t memory, size_t num_threads) override
Begin parallel bulk data load to the table.
Definition: handler0alter.cc:11146
int rnd_next(uchar *buf) override
Reads the next row in a table scan (also used to read the FIRST row in a table scan).
Definition: ha_innodb.cc:11142
bool prepare_inplace_alter_table_impl(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const Table *old_dd_tab, Table *new_dd_tab)
Implementation of prepare_inplace_alter_table()
Definition: handler0alter.cc:5431
int enable_indexes(uint mode) override
Enable indexes.
Definition: ha_innodb.cc:18349
ha_innobase(handlerton *hton, TABLE_SHARE *table_arg)
Construct ha_innobase handler.
Definition: ha_innodb.cc:2956
void update_thd()
Updates the user_thd field in a handle and also allocates a new InnoDB transaction handle if needed,...
Definition: ha_innodb.cc:3006
int rnd_init(bool scan) override
Initialize a table scan.
Definition: ha_innodb.cc:11115
int index_next(uchar *buf) override
Reads the next row from a cursor, which must have previously been positioned using index_read.
Definition: ha_innodb.cc:10923
INNOBASE_SHARE * m_share
information for MySQL table locking
Definition: ha_innodb.h:731
int parallel_scan(void *scan_ctx, void **thread_ctxs, Reader::Init_fn init_fn, Reader::Load_fn load_fn, Reader::End_fn end_fn) override
Start parallel read of InnoDB records.
Definition: handler0alter.cc:1532
int bulk_load_end(THD *thd, void *load_ctx, bool is_error) override
End bulk load operation.
Definition: handler0alter.cc:11245
ulint m_stored_select_lock_type
this field is used to remember the original select_lock_type that was decided in ha_innodb....
Definition: ha_innodb.h:753
dberr_t innobase_set_max_autoinc(ulonglong auto_inc)
Store the autoinc value in the table.
Definition: ha_innodb.cc:9062
virtual bool can_reuse_mysql_template() const
Can reuse the template.
Definition: ha_innodb.h:718
void position(const uchar *record) override
Store a reference to the current row to 'ref' field of the handle.
Definition: ha_innodb.cc:11557
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint mode, HANDLER_BUFFER *buf) override
Initialize multi range read.
Definition: ha_innodb.cc:23765
void unlock_row() override
Removes a new lock set on a row, if it was not read optimistically.
Definition: ha_innodb.cc:10299
bool commit_inplace_alter_table_impl(TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit, Table *new_dd_tab)
Implementation of commit_inplace_alter_table()
Definition: handler0alter.cc:7422
bool m_start_of_scan
this is set to 1 when we are starting a table scan but have not yet fetched any row,...
Definition: ha_innodb.h:744
int rename_table(const char *from, const char *to, const dd::Table *from_table, dd::Table *to_table) override
Renames an InnoDB table.
Definition: ha_innodb.cc:16870
void position(uchar *record)
bool was_semi_consistent_read() override
Definition: ha_innodb.cc:10347
int close(void) override
Closes a handle to an InnoDB table.
Definition: ha_innodb.cc:7990
int srv_concurrency_enter()
Enter InnoDB engine after checking max allowed threads.
Definition: ha_innodb.cc:2943
int end_stmt()
MySQL calls this method at the end of each statement.
Definition: ha_innodb.cc:18728
bool get_se_private_data(dd::Table *dd_table, bool reset) override
Get storage-engine private data for a data dictionary table.
Definition: ha_innodb.cc:15328
bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override
Check if SE supports specific key algorithm.
Definition: ha_innodb.h:101
ha_rows estimate_rows_upper_bound() override
Gives an UPPER BOUND to the number of rows in a table.
Definition: ha_innodb.cc:17119
void ft_end()
Definition: ha_innodb.cc:11542
bool get_error_message(int error, String *buf) override
See comment in handler.cc.
Definition: ha_innodb.cc:20107
int open(const char *name, int, uint open_flags, const dd::Table *table_def) override
Open an InnoDB table.
Definition: ha_innodb.cc:7488
uint max_supported_key_length() const override
Returns the maximum key length.
Definition: ha_innodb.cc:6722
longlong get_memory_buffer_size() const override
Return the size of the InnoDB memory buffer.
Definition: ha_innodb.cc:17230
int change_active_index(uint keynr)
Changes the active index of a handle.
Definition: ha_innodb.cc:10738
int records(ha_rows *num_rows) override
Returns the exact number of records that this client can see using this handler object.
Definition: ha_innodb.cc:16908
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, thr_lock_type lock_type) override
Supposed to convert a MySQL table lock stored in the 'lock' field of the handle to a proper type befo...
Definition: ha_innodb.cc:19752
uint lock_count(void) const override
Returns number of THR_LOCK locks used for one instance of InnoDB table.
Definition: ha_innodb.cc:19736
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes) override
Part of old, deprecated in-place ALTER API.
Definition: ha_innodb.cc:20513
dberr_t innobase_get_autoinc(ulonglong *value)
Read the next autoinc value.
Definition: ha_innodb.cc:19930
void reset_template()
Resets a query execution 'template'.
Definition: ha_innodb.cc:3156
ulint m_upd_buf_size
the size of upd_buf in bytes
Definition: ha_innodb.h:737
void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values) override
Returns the value of the auto-inc counter in *first_value and ~0 on failure.
Definition: ha_innodb.cc:19968
size_t bulk_load_available_memory(THD *thd) const override
Get the total memory available for bulk load in innodb buffer pool.
Definition: handler0alter.cc:11140
int info(uint) override
Returns statistics information of the table to the MySQL interpreter, in various fields of the handle...
Definition: ha_innodb.cc:17821
int delete_table(const char *name, const dd::Table *table_def) override
Drop a table.
Definition: ha_innodb.cc:15639
FT_INFO * ft_init_ext(uint flags, uint inx, String *key) override
Initialize FT index scan.
Definition: ha_innodb.cc:11222
uint max_supported_keys() const override
Returns the maximum number of keys.
Definition: ha_innodb.cc:6717
int external_lock(THD *thd, int lock_type) override
As MySQL will execute an external lock for every new table it uses when it starts to process an SQL s...
Definition: ha_innodb.cc:18928
int cmp_ref(const uchar *ref1, const uchar *ref2) const override
Compares two 'refs'.
Definition: ha_innodb.cc:20175
int write_blob(THD *thd, void *load_ctx, size_t thread_idx, Blob_context blob_ctx, unsigned char *blobref, const unsigned char *data, size_t data_len) override
Write to a blob.
Definition: handler0alter.cc:11224
int analyze(THD *thd, HA_CHECK_OPT *check_opt) override
Updates index cardinalities of the table, based on random dives into each index tree.
Definition: ha_innodb.cc:18403
int index_first(uchar *buf) override
Positions a cursor on the first record in an index and reads the corresponding row to buf.
Definition: ha_innodb.cc:10959
bool inplace_alter_table_impl(TABLE *altered_table, Alter_inplace_info *ha_alter_info)
Implementation of inplace_alter_table()
Definition: handler0alter.cc:6128
int ft_read(uchar *buf) override
Fetch next result from the FT result set.
Definition: ha_innodb.cc:11406
bool upgrade_table(THD *thd, const char *db_name, const char *table_name, dd::Table *dd_table) override
Set Engine specific data to dd::Table object for upgrade.
Definition: ha_innodb.cc:15318
void init_table_handle_for_HANDLER() override
Call this when you have opened a new table handle in HANDLER, before you call index_read_map() etc.
Definition: ha_innodb.cc:3186
int index_last(uchar *buf) override
Positions a cursor on the last record in an index and reads the corresponding row to buf.
Definition: ha_innodb.cc:10980
int truncate_impl(const char *name, TABLE *form, dd::Table *table_def)
TRUNCATE an InnoDB table.
Definition: ha_innodb.cc:15565
int sample_end(void *scan_ctx) override
End sampling.
Definition: ha_innodb.cc:11091
int index_init(uint index, bool sorted) override
Initializes a handle to use an index.
Definition: ha_innodb.cc:10366
int read_range_next() override
Read next row between two endpoints.
Definition: ha_innodb.cc:11106
Table_flags m_int_table_flags
Flags that specify the handler instance (table) capability.
Definition: ha_innodb.h:740
int close_blob(THD *thd, void *load_ctx, size_t thread_idx, Blob_context blob_ctx, byte *blobref) override
Close the blob.
Definition: handler0alter.cc:11235
int index_read_last(uchar *buf, const uchar *key, uint key_len) override
The following functions works like index_read, but it find the last row with the current key value or...
Definition: ha_innodb.cc:10681
void try_semi_consistent_read(bool yes) override
Tell the engine whether it should avoid unnecessary lock waits.
Definition: ha_innodb.cc:10353
dberr_t innobase_lock_autoinc()
This special handling is really to overcome the limitations of MySQL's binlogging.
Definition: ha_innodb.cc:8996
row_type get_real_row_type(const HA_CREATE_INFO *create_info) const override
Get real row type for the table created based on one specified by user, CREATE TABLE options and SE c...
Definition: ha_innodb.cc:6589
FT_INFO * ft_init_ext_with_hints(uint inx, String *key, Ft_hints *hints) override
Initialize FT index scan.
Definition: ha_innodb.cc:11350
ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint *bufsz, uint *flags, bool *force_default_mrr, Cost_estimate *cost) override
Initialize multi range read and get information.
Definition: ha_innodb.cc:23777
int index_read(uchar *buf, const uchar *key, uint key_len, ha_rkey_function find_flag) override
Positions an index cursor to the index specified in the handle.
Definition: ha_innodb.cc:10489
void parallel_scan_end(void *scan_ctx) override
End of the parallel scan.
Definition: handler0alter.cc:1555
void update_create_info(HA_CREATE_INFO *create_info) override
Update create_info.
Definition: ha_innodb.cc:13172
void release_auto_increment() override
Do cleanup for auto increment calculation.
Definition: ha_innodb.cc:19951
int index_prev(uchar *buf) override
Reads the previous row from a cursor, which must have previously been positioned using index_read.
Definition: ha_innodb.cc:10947
int write_row(uchar *buf) override
Stores a row in an InnoDB database, to the table specified in this handle.
Definition: ha_innodb.cc:9316
enum ha_key_alg get_default_index_algorithm() const override
Get default key algorithm for SE.
Definition: ha_innodb.h:96
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Tries to check that an InnoDB table is not corrupted.
Definition: ha_innodb.cc:18452
int read_range_first(const key_range *start_key, const key_range *end_key, bool eq_range_arg, bool sorted) override
Read first row between two ranges.
Definition: ha_innodb.cc:11099
int delete_all_rows() override
Delete all rows from the table.
Definition: ha_innodb.cc:10280
bool bulk_load_check(THD *thd) const override
Check if the table is ready for bulk load.
Definition: handler0alter.cc:11099
int bulk_load_execute(THD *thd, void *load_ctx, size_t thread_idx, const Rows_mysql &rows, Bulk_load::Stat_callbacks &wait_cbk) override
Execute bulk load operation.
Definition: handler0alter.cc:11192
virtual int info_low(uint flag, bool is_analyze)
Returns statistics information of the table to the MySQL interpreter, in various fields of the handle...
Definition: ha_innodb.cc:17505
int sample_next(void *scan_ctx, uchar *buf) override
Get the next record for sampling.
Definition: ha_innodb.cc:11074
const char * table_type() const override
Returns the table type (storage engine name).
Definition: ha_innodb.cc:6673
double read_time(uint index, uint ranges, ha_rows rows) override
Calculate the time it takes to read a set of ranges through an index This enables us to optimise read...
Definition: ha_innodb.cc:17200
int optimize(THD *thd, HA_CHECK_OPT *check_opt) override
This is mapped to "ALTER TABLE tablename ENGINE=InnoDB", which rebuilds the table in MySQL.
Definition: ha_innodb.cc:18421
bool get_foreign_dup_key(char *, uint, char *, uint) override
Retrieves the names of the table and the key for which there was a duplicate entry in the case of HA_...
Definition: ha_innodb.cc:20131
~ha_innobase() override=default
int delete_row(const uchar *buf) override
Deletes a row given as the parameter.
Definition: ha_innodb.cc:10227
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4633
void * Blob_context
Definition: handler.h:4638
ulonglong Table_flags
Definition: handler.h:4637
Class of basic DDL implementation, for CREATE/DROP/RENAME TABLE.
Definition: ha_innodb.h:1112
static int rename_impl(THD *thd, const char *from, const char *to, const Table *from_table, const Table *to_table, const TABLE *td)
Renames an InnoDB table.
Definition: ha_innodb.cc:14636
static int create_impl(THD *thd, const char *name, TABLE *form, HA_CREATE_INFO *create_info, Table *dd_tab, bool file_per_table, bool evictable, bool skip_strict, uint32_t old_flags, uint32_t old_flags2, const dd::Table *old_dd_table)
Create an InnoDB table.
Definition: ha_innodb.cc:14418
static int delete_impl(THD *thd, const char *name, const Table *dd_tab, const TABLE *td)
Drop an InnoDB table.
Definition: ha_innodb.cc:14533
Class to handle TRUNCATE for one InnoDB table or one partition.
Definition: ha_innodb.h:1175
dict_table_t * m_table
InnoDB table object for the table/partition.
Definition: ha_innodb.h:1245
trx_t * m_trx
Transaction attached to current thd.
Definition: ha_innodb.h:1242
int open_table(dict_table_t *&innodb_table)
Open the table/partition to be truncated.
Definition: ha_innodb.cc:14767
bool m_keep_autoinc
True if the original autoinc counter should be kept.
Definition: ha_innodb.h:1259
Table * m_dd_table
dd::Table or dd::Partition
Definition: ha_innodb.h:1239
int truncate()
Do the real truncation.
Definition: ha_innodb.cc:14865
uint32_t m_flags2
flags2 of the table to be truncated, which should not change
Definition: ha_innodb.h:1269
TABLE * m_form
Table format.
Definition: ha_innodb.h:1248
HA_CREATE_INFO m_create_info
Create information.
Definition: ha_innodb.h:1251
int rename_tablespace()
Rename tablespace file name.
Definition: ha_innodb.cc:14960
bool m_file_per_table
True if this table/partition is file per table.
Definition: ha_innodb.h:1254
int load_fk()
Reload the FK related information.
Definition: ha_innodb.cc:15024
int prepare()
Prepare for truncate.
Definition: ha_innodb.cc:14798
int exec()
Do the truncate of the table/partition.
Definition: ha_innodb.cc:15055
innobase_truncate(THD *thd, const char *name, TABLE *form, Table *dd_table, bool keep_autoinc, bool table_truncate)
Constructor.
Definition: ha_innodb.h:1184
~innobase_truncate()
Destructor.
Definition: ha_innodb.cc:14756
uint32_t m_flags
flags of the table to be truncated, which should not change
Definition: ha_innodb.h:1266
void cleanup()
Cleanup.
Definition: ha_innodb.cc:15007
bool m_table_truncate
For a prtition table, this is true if full table is truncated.
Definition: ha_innodb.h:1263
THD * m_thd
THD object.
Definition: ha_innodb.h:1233
const char * m_name
Normalized table name.
Definition: ha_innodb.h:1236
A table definition from the master.
Definition: rpl_utility.h:249
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
This service provides functions for clone plugin to connect and interact with remote server's clone p...
dberr_t
Definition: db0err.h:39
@ DB_SUCCESS
Definition: db0err.h:43
constexpr uint32_t DICT_TF2_TEMPORARY
TEMPORARY; true for tables from CREATE TEMPORARY TABLE.
Definition: dict0mem.h:269
constexpr uint32_t DICT_TF2_INTRINSIC
Intrinsic table bit Intrinsic table is table created internally by MySQL modules viz.
Definition: dict0mem.h:292
static page_no_t fsp_get_extent_size_in_pages(const page_size_t &page_size)
Calculate the number of physical pages in an extent for this file.
Definition: fsp0fsp.h:356
constexpr uint64_t FSP_MAX_AUTOEXTEND_SIZE
Definition: fsp0fsp.h:181
bool commit_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, bool commit, const dd::Table *old_dd_tab, dd::Table *new_dd_tab) override
Commit or rollback the changes made during prepare_inplace_alter_table() and inplace_alter_table() in...
Definition: handler0alter.cc:1597
enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *altered_table, Alter_inplace_info *ha_alter_info) override
Check if InnoDB supports a particular alter table in-place.
Definition: handler0alter.cc:963
bool inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_dd_tab, dd::Table *new_dd_tab) override
Alter the table structure in-place with operations specified using HA_ALTER_FLAGS and Alter_inplace_i...
Definition: handler0alter.cc:1561
bool prepare_inplace_alter_table(TABLE *altered_table, Alter_inplace_info *ha_alter_info, const dd::Table *old_dd_tab, dd::Table *new_dd_tab) override
Allows InnoDB to update internal structures with concurrent writes blocked (provided that check_if_su...
Definition: handler0alter.cc:1437
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:216
constexpr uint32_t FSP_FREE_ADD
This many free extents are added to the free list from above FSP_FREE_LIMIT at a time.
Definition: fsp0fsp.h:176
bool innobase_match_index_columns(const KEY *key_info, const dict_index_t *index_info)
Match index columns between MySQL and InnoDB.
Definition: ha_innodb.cc:6937
void innodb_base_col_setup_for_stored(const dict_table_t *table, const Field *field, dict_s_col_t *s_col)
Set up base columns for stored column.
Definition: ha_innodb.cc:11625
const struct _ft_vft ft_vft_result
Definition: ha_innodb.cc:596
static bool normalize_table_name(char *norm_name, const char *name)
Definition: ha_innodb.h:1344
static bool tablespace_is_shared_space(const HA_CREATE_INFO *create_info)
Check if table will be explicitly put in an existing shared general or system tablespace.
Definition: ha_innodb.h:828
rec_per_key_t innodb_rec_per_key(const dict_index_t *index, ulint i, ha_rows records)
Calculate Record Per Key value.
Definition: ha_innodb.cc:17331
static bool is_shared_tablespace(const char *tablespace_name)
Check if tablespace is shared tablespace.
Definition: ha_innodb.h:853
void innobase_discard_table(THD *thd, dict_table_t *table)
Drop the statistics for a specified table, and mark it as discard after DDL.
Definition: handler0alter.cc:705
int convert_error_code_to_mysql(dberr_t error, uint32_t flags, THD *thd)
Converts an InnoDB error code to a MySQL error code.
Definition: ha_innodb.cc:2094
const char innobase_index_reserve_name[]
"GEN_CLUST_INDEX" is the name reserved for InnoDB default system clustered index when there is no pri...
Definition: dict0mem.h:1025
void innobase_build_v_templ_callback(const TABLE *table, void *ib_table)
Callback used by MySQL server layer to initialize the table virtual columns' template.
Definition: ha_innodb.cc:7084
bool trx_is_registered_for_2pc(const trx_t *trx)
Note that a transaction has been registered with MySQL.
Definition: ha_innodb.h:1351
static int validate_autoextend_size_value(uint64_t ext_size)
Validate AUTOEXTEND_SIZE attribute for a tablespace.
Definition: ha_innodb.h:866
void innobase_parse_hint_from_comment(THD *thd, dict_table_t *table, const TABLE_SHARE *table_share)
Parse hint for table and its indexes, and update the information in dictionary.
Definition: ha_innodb.cc:13760
static bool tablespace_is_file_per_table(const HA_CREATE_INFO *create_info)
Check if the explicit tablespace targeted is file_per_table.
Definition: ha_innodb.h:817
void innodb_base_col_setup(dict_table_t *table, const Field *field, dict_v_col_t *v_col)
Set up base columns for virtual column.
Definition: ha_innodb.cc:11594
fts_doc_id_index_enum
Some defines for innobase_fts_check_doc_id_index() return value.
Definition: ha_innodb.h:1281
@ FTS_EXIST_DOC_ID_INDEX
Definition: ha_innodb.h:1283
@ FTS_INCORRECT_DOC_ID_INDEX
Definition: ha_innodb.h:1282
@ FTS_NOT_EXIST_DOC_ID_INDEX
Definition: ha_innodb.h:1284
trx_t * innobase_trx_allocate(THD *thd)
Allocates an InnoDB transaction for a MySQL handler object.
Definition: ha_innodb.cc:2769
void innobase_build_v_templ(const TABLE *table, const dict_table_t *ib_table, dict_vcol_templ_t *s_templ, const dict_add_v_col_t *add_v, bool locked, const char *share_tbl_name)
Build template for the virtual columns and their base columns.
Definition: ha_innodb.cc:7100
const mysql_service_clone_protocol_t * clone_protocol_svc
Clone protocol service.
Definition: ha_innodb.cc:280
static bool tablespace_is_general_space(const HA_CREATE_INFO *create_info)
Check if table will be explicitly put in a general tablespace.
Definition: ha_innodb.h:839
fts_doc_id_index_enum innobase_fts_check_doc_id_index(const dict_table_t *table, const TABLE *altered_table, ulint *fts_doc_col_no)
Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME on the Doc ID column.
Definition: handler0alter.cc:2850
void innobase_register_trx(handlerton *hton, THD *thd, trx_t *trx)
Allocates an InnoDB transaction for a MySQL handler object for DML.
Definition: ha_innodb.cc:3019
static bool innobase_is_s_fld(const Field *field)
whether this is a stored column
Definition: ha_innodb.h:1331
static bool innobase_is_multi_value_fld(const Field *field)
Whether this is a computed multi-value virtual column.
Definition: ha_innodb.h:1340
void innobase_copy_frm_flags_from_table_share(dict_table_t *innodb_table, const TABLE_SHARE *table_share)
Copy table flags from MySQL's TABLE_SHARE into an InnoDB table object.
Definition: ha_innodb.cc:2918
bool innobase_fts_load_stopword(dict_table_t *table, trx_t *trx, THD *thd)
Initialize the table FTS stopword list.
Definition: ha_innodb.cc:13202
void(* my_gcolumn_templatecallback_t)(const TABLE *, void *)
Callback function definition, used by MySQL server layer to initialized the table virtual columns' te...
Definition: ha_innodb.h:1404
trx_t *& thd_to_trx(THD *thd)
Obtain the InnoDB transaction of a MySQL thread.
Definition: ha_innodb.cc:2027
page_cur_mode_t convert_search_mode_to_innobase(enum ha_rkey_function find_flag)
Converts a search mode flag understood by MySQL to a flag understood by InnoDB.
Definition: ha_innodb.cc:10397
fts_doc_id_index_enum innobase_fts_check_doc_id_index_in_def(ulint n_key, const KEY *key_info)
Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME on the Doc ID column in MySQL c...
Definition: handler0alter.cc:2936
struct new_ft_info NEW_FT_INFO
Structure Returned by ha_innobase::ft_init_ext()
trx_t::isolation_level_t innobase_trx_map_isolation_level(enum_tx_isolation iso)
Maps a MySQL trx isolation level code to the InnoDB isolation level code.
Definition: ha_innodb.cc:18895
bool innobase_index_name_is_reserved(THD *thd, const KEY *key_info, ulint num_of_keys)
This function checks each index name for a table against reserved system default primary index name '...
Definition: ha_innodb.cc:21819
constexpr uint32_t SIZE_MB
Definition: ha_innodb.h:861
bool innobase_stats_on_metadata
Definition: ha_innodb.cc:348
ulong thd_parallel_read_threads(THD *thd)
Return the number of read threads for this session.
Definition: ha_innodb.cc:2034
static int flags[50]
Definition: hp_test1.cc:40
static int flag
Definition: hp_test1.cc:40
static uint keys
Definition: hp_test2.cc:49
float rec_per_key_t
Data type for records per key estimates that are stored in the KEY::rec_per_key_float[] array.
Definition: key.h:96
ha_key_alg
Definition: my_base.h:98
@ HA_KEY_ALG_RTREE
Definition: my_base.h:109
@ HA_KEY_ALG_BTREE
Definition: my_base.h:108
@ HA_KEY_ALG_FULLTEXT
Definition: my_base.h:111
ha_rkey_function
Definition: my_base.h:78
my_off_t ha_rows
Definition: my_base.h:1141
ha_extra_function
Definition: my_base.h:185
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
#define MYF(v)
Definition: my_inttypes.h:97
enum_sql_command
Definition: my_sqlcommand.h:46
void error(const char *format,...)
static bool ignore
Definition: mysqlimport.cc:70
static int record
Definition: mysqltest.cc:193
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
Definition: buf0block_hint.cc:30
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
bool is_partition(const std::string &dict_name)
Check if it is a table partition.
Definition: dict0dd.cc:7427
Definition: aligned_atomic.h:44
const char * table_name
Definition: rules_table_service.cc:56
const char * db_name
Definition: rules_table_service.cc:55
mode
Definition: file_handle.h:61
page_cur_mode_t
Definition: page0types.h:176
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Parallel read adapter interface.
Parallel read histogram interface.
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
enum_alter_inplace_result
Return values for check_if_supported_inplace_alter().
Definition: handler.h:202
enum_tx_isolation
Definition: handler.h:3237
row_type
Definition: handler.h:686
enum_sampling_method
Definition: handler.h:717
static bool commit(THD *thd)
Commit the current statement and transaction.
Definition: sql_cmd_srs.cc:152
case opt name
Definition: sslopt-case.h:29
TempTable public handler API declaration.
Callbacks for collecting time statistics.
Definition: bulk_data_service.h:838
Definition: ft_global.h:72
Definition: handler.h:3859
Definition: handler.h:3846
Struct to hold information about the table that should be created.
Definition: handler.h:3253
const char * tablespace
Definition: handler.h:3259
InnoDB table share.
Definition: ha_innodb.h:65
const char * table_name
InnoDB table name.
Definition: ha_innodb.h:66
innodb_idx_translate_t idx_trans_tbl
index translation table between MySQL and InnoDB
Definition: ha_innodb.h:73
void * table_name_hash
hash table chain node
Definition: ha_innodb.h:71
uint use_count
reference count, incremented in get_share() and decremented in free_share()
Definition: ha_innodb.h:67
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: handler.h:3867
This structure is shared between different table objects.
Definition: table.h:704
Definition: table.h:1421
Definition: thr_lock.h:124
Definition: ft_global.h:57
Definition: ft_global.h:48
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:830
Data structure for an index.
Definition: dict0mem.h:1041
Data structure for a stored column in a table.
Definition: dict0mem.h:842
static const char * s_file_per_table_name
The hard-coded tablespace name innodb_file_per_table.
Definition: dict0dict.h:1155
static const char * s_sys_space_name
The name of the hard-coded system tablespace.
Definition: dict0dict.h:1146
static const char * s_temp_space_name
The name of the predefined temporary tablespace.
Definition: dict0dict.h:1149
Data structure for a database table.
Definition: dict0mem.h:1913
Data structure for a virtual column in a table.
Definition: dict0mem.h:810
Structure defines template related to virtual columns and their base columns.
Definition: dict0mem.h:1850
Query result.
Definition: fts0fts.h:314
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2779
Definition: ha_innodb.h:53
dict_index_t ** index_mapping
index pointer array directly maps to index in InnoDB from MySQL array index
Definition: ha_innodb.h:59
ulint array_size
array size of index_mapping
Definition: ha_innodb.h:57
ulint index_count
number of valid index entries in the index_mapping array
Definition: ha_innodb.h:54
Definition: my_base.h:1125
Structure Returned by ha_innobase::ft_init_ext()
Definition: ha_innodb.h:769
struct _ft_vft_ext * could_you
Definition: ha_innodb.h:771
row_prebuilt_t * ft_prebuilt
Definition: ha_innodb.h:772
fts_result_t * ft_result
Definition: ha_innodb.h:773
struct _ft_vft * please
Definition: ha_innodb.h:770
A struct for (sometimes lazily) prebuilt structures in an Innobase table handle used within MySQL; th...
Definition: row0mysql.h:515
Definition: trx0trx.h:675
bool is_registered
Definition: trx0trx.h:867
isolation_level_t
Definition: trx0trx.h:676
thr_lock_type
Definition: thr_lock.h:51
The transaction.
ulong srv_page_size
Definition: srv0srv.cc:400
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105