MySQL 26.10.0
Source Code Documentation
ha_innodb.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2000, 2026, 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"
40
41#include "row0pread-adapter.h"
42#include "row0pread-histogram.h"
43#include "trx0trx.h"
44#include "ut0atomic_sysvar.h"
45
46/** A sysvar which controls how much can we round up the autoinc value when
47persisting it to DDTableBuffer. The larger the value, the less often we have to
48perform this costly write, but the larger the gap in numbers in case we crash.*/
50
51/** "GEN_CLUST_INDEX" is the name reserved for InnoDB default
52system clustered index when there is no primary key. */
53extern const char innobase_index_reserve_name[];
54
55/** Clone protocol service. */
56extern SERVICE_TYPE(clone_protocol) * clone_protocol_svc;
57
58/* Structure defines translation table between mysql index and InnoDB
59index structures */
61 ulint index_count; /*!< number of valid index entries
62 in the index_mapping array */
63
64 ulint array_size; /*!< array size of index_mapping */
65
66 dict_index_t **index_mapping; /*!< index pointer array directly
67 maps to index in InnoDB from MySQL
68 array index */
69};
70
71/** InnoDB table share */
73 const char *table_name; /*!< InnoDB table name */
74 uint use_count; /*!< reference count,
75 incremented in get_share()
76 and decremented in
77 free_share() */
79 /*!< hash table chain node */
80 innodb_idx_translate_t idx_trans_tbl; /*!< index translation table between
81 MySQL and InnoDB */
82};
83
84/** Prebuilt structures in an InnoDB table handle used within MySQL */
85struct row_prebuilt_t;
86
87namespace dd {
88namespace cache {
89class Dictionary_client;
90}
91} // namespace dd
92
93/** The class defining a handle to an InnoDB table */
94class ha_innobase : public handler {
95 public:
96 ha_innobase(handlerton *hton, TABLE_SHARE *table_arg);
97 ~ha_innobase() override = default;
98
99 row_type get_real_row_type(const HA_CREATE_INFO *create_info) const override;
100
101 const char *table_type() const override;
102
104 return HA_KEY_ALG_BTREE;
105 }
106
107 /** Check if SE supports specific key algorithm. */
108 bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override {
109 /* This method is never used for FULLTEXT or SPATIAL keys.
110 We rely on handler::ha_table_flags() to check if such keys
111 are supported. */
112 assert(key_alg != HA_KEY_ALG_FULLTEXT && key_alg != HA_KEY_ALG_RTREE);
113 return key_alg == HA_KEY_ALG_BTREE;
114 }
115
116 Table_flags table_flags() const override;
117
118 ulong index_flags(uint idx, uint part, bool all_parts) const override;
119
120 uint max_supported_keys() const override;
121
122 uint max_supported_key_length() const override;
123
125 HA_CREATE_INFO *create_info) const override;
126
127 int open(const char *name, int, uint open_flags,
128 const dd::Table *table_def) override;
129
130 handler *clone(const char *name, MEM_ROOT *mem_root) override;
131
132 int close(void) override;
133
134 double scan_time() override;
135
136 double read_time(uint index, uint ranges, ha_rows rows) override;
137
138 longlong get_memory_buffer_size() const override;
139
140 int write_row(uchar *buf) override;
141
142 int update_row(const uchar *old_data, uchar *new_data) override;
143
144 int delete_row(const uchar *buf) override;
145
146 /** Delete all rows from the table.
147 @retval HA_ERR_WRONG_COMMAND if the table is transactional
148 @retval 0 on success */
149 int delete_all_rows() override;
150
151 bool was_semi_consistent_read() override;
152
153 void try_semi_consistent_read(bool yes) override;
154
155 void unlock_row() override;
156
157 int index_init(uint index, bool sorted) override;
158
159 int index_end() override;
160
161 int index_read(uchar *buf, const uchar *key, uint key_len,
162 ha_rkey_function find_flag) override;
163
164 int index_read_last(uchar *buf, const uchar *key, uint key_len) override;
165
166 int index_next(uchar *buf) override;
167
168 int index_next_same(uchar *buf, const uchar *key, uint keylen) override;
169
170 int index_prev(uchar *buf) override;
171
172 int index_first(uchar *buf) override;
173
174 int index_last(uchar *buf) override;
175
176 int read_range_first(const key_range *start_key, const key_range *end_key,
177 bool eq_range_arg, bool sorted) override;
178
179 int read_range_next() override;
180
181 int rnd_init(bool scan) override;
182
183 int rnd_end() override;
184
185 int rnd_next(uchar *buf) override;
186
187 int rnd_pos(uchar *buf, uchar *pos) override;
188
189 int ft_init() override;
190
191 void ft_end();
192
193 FT_INFO *ft_init_ext(uint flags, uint inx, String *key) override;
194
196 Ft_hints *hints) override;
197
198 int ft_read(uchar *buf) override;
199
200 void position(const uchar *record) override;
201
202 int info(uint) override;
203
204 int enable_indexes(uint mode) override;
205
206 int disable_indexes(uint mode) override;
207
208 int analyze(THD *thd, HA_CHECK_OPT *check_opt) override;
209
210 int optimize(THD *thd, HA_CHECK_OPT *check_opt) override;
211
212 int discard_or_import_tablespace(bool discard, dd::Table *table_def) override;
213
214 int extra(ha_extra_function operation) override;
215
216 int reset() override;
217
218 int external_lock(THD *thd, int lock_type) override;
219
220 /** Initialize sampling.
221 @param[out] scan_ctx A scan context created by this method that has to be
222 used in sample_next
223 @param[in] sampling_percentage percentage of records that need to be sampled
224 @param[in] sampling_seed random seed that the random generator will use
225 @param[in] sampling_method sampling method to be used; currently only
226 SYSTEM sampling is supported
227 @param[in] tablesample true if the sampling is for tablesample
228 @return 0 for success, else one of the HA_xxx values in case of error. */
229 int sample_init(void *&scan_ctx, double sampling_percentage,
230 int sampling_seed, enum_sampling_method sampling_method,
231 const bool tablesample) override;
232
233 /** Get the next record for sampling.
234 @param[in] scan_ctx Scan context of the sampling
235 @param[in] buf buffer to place the read record
236 @return 0 for success, else one of the HA_xxx values in case of error. */
237 int sample_next(void *scan_ctx, uchar *buf) override;
238
239 /** End sampling.
240 @param[in] scan_ctx Scan context of the sampling
241 @return 0 for success, else one of the HA_xxx values in case of error. */
242 int sample_end(void *scan_ctx) override;
243
244 /** MySQL calls this function at the start of each SQL statement
245 inside LOCK TABLES. Inside LOCK TABLES the "::external_lock" method
246 does not work to mark SQL statement borders. Note also a special case:
247 if a temporary table is created inside LOCK TABLES, MySQL has not
248 called external_lock() at all on that table.
249 MySQL-5.0 also calls this before each statement in an execution of a
250 stored procedure. To make the execution more deterministic for
251 binlogging, MySQL-5.0 locks all tables involved in a stored procedure
252 with full explicit table locks (thd_in_lock_tables(thd) holds in
253 store_lock()) before executing the procedure.
254 @param[in] thd handle to the user thread
255 @param[in] lock_type lock type
256 @return 0 or error code */
257 int start_stmt(THD *thd, thr_lock_type lock_type) override;
258
260
261 int records(ha_rows *num_rows) override;
262
263 ha_rows records_in_range(uint inx, key_range *min_key,
264 key_range *max_key) override;
265
267
268 void update_create_info(HA_CREATE_INFO *create_info) override;
269
270 /** Get storage-engine private data for a data dictionary table.
271 @param[in,out] dd_table data dictionary table definition
272 @param reset reset counters
273 @retval true an error occurred
274 @retval false success */
275 bool get_se_private_data(dd::Table *dd_table, bool reset) override;
276
277 /** Add hidden columns and indexes to an InnoDB table definition.
278 @param[in,out] dd_table data dictionary cache object
279 @return error number
280 @retval 0 on success */
282 const List<Create_field> *, const KEY *, uint,
283 dd::Table *dd_table) override;
284
285 /** Set Engine specific data to dd::Table object for upgrade.
286 @param[in,out] thd thread handle
287 @param[in] db_name database name
288 @param[in] table_name table name
289 @param[in,out] dd_table data dictionary cache object
290 @return 0 on success, non-zero on failure */
291 bool upgrade_table(THD *thd, const char *db_name, const char *table_name,
292 dd::Table *dd_table) override;
293
294 /** Create an InnoDB table.
295 @param[in] name table name in filename-safe encoding
296 @param[in] form table structure
297 @param[in] create_info more information on the table
298 @param[in,out] table_def dd::Table describing table to be
299 created. Can be adjusted by SE, the changes will be saved into data-dictionary
300 at statement commit time.
301 @return error number
302 @retval 0 on success */
303 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
304 dd::Table *table_def) override;
305
306 /** Drop a table.
307 @param[in] name table name
308 @param[in] table_def dd::Table describing table to
309 be dropped
310 @return error number
311 @retval 0 on success */
312 int delete_table(const char *name, const dd::Table *table_def) override;
313
314 protected:
315 /** Drop a table.
316 @param[in] name table name
317 @param[in] table_def dd::Table describing table to
318 be dropped
319 @param[in] sqlcom type of operation that the DROP is part of
320 @return error number
321 @retval 0 on success */
322 int delete_table(const char *name, const dd::Table *table_def,
323 enum enum_sql_command sqlcom);
324
325 public:
326 int rename_table(const char *from, const char *to,
327 const dd::Table *from_table, dd::Table *to_table) override;
328
329 int check(THD *thd, HA_CHECK_OPT *check_opt) override;
330
331 uint lock_count(void) const override;
332
334 thr_lock_type lock_type) override;
335
336 void init_table_handle_for_HANDLER() override;
337
338 void get_auto_increment(ulonglong offset, ulonglong increment,
339 ulonglong nb_desired_values, ulonglong *first_value,
340 ulonglong *nb_reserved_values) override;
341
342 /** Do cleanup for auto increment calculation. */
343 void release_auto_increment() override;
344
345 bool get_error_message(int error, String *buf) override;
346
347 bool get_foreign_dup_key(char *, uint, char *, uint) override;
348
349 bool primary_key_is_clustered() const override;
350
351 int cmp_ref(const uchar *ref1, const uchar *ref2) const override;
352
353 /** @defgroup ALTER_TABLE_INTERFACE On-line ALTER TABLE interface
354 @see handler0alter.cc
355 @{ */
356
357 /** Check if InnoDB supports a particular alter table in-place
358 @param altered_table TABLE object for new version of table.
359 @param ha_alter_info Structure describing changes to be done
360 by ALTER TABLE and holding data used during in-place alter.
361
362 @retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported
363 @retval HA_ALTER_INPLACE_NO_LOCK Supported
364 @retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE Supported, but requires
365 lock during main phase and exclusive lock during prepare phase.
366 @retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE Supported, prepare phase
367 requires exclusive lock (any transactions that have accessed the table
368 must commit or roll back first, and no transactions can access the table
369 while prepare_inplace_alter_table() is executing)
370 */
372 TABLE *altered_table, Alter_inplace_info *ha_alter_info) override;
373
374 /** Allows InnoDB to update internal structures with concurrent
375 writes blocked (provided that check_if_supported_inplace_alter()
376 did not return HA_ALTER_INPLACE_NO_LOCK).
377 This will be invoked before inplace_alter_table().
378 @param[in] altered_table TABLE object for new version of table.
379 @param[in,out] ha_alter_info Structure describing changes to be done
380 by ALTER TABLE and holding data used during in-place alter.
381 @param[in] old_dd_tab dd::Table object describing old version
382 of the table.
383 @param[in,out] new_dd_tab dd::Table object for the new version of
384 the table. Can be adjusted by this call. Changes to the table definition will
385 be persisted in the data-dictionary at statement commit time.
386 @retval true Failure
387 @retval false Success
388 */
389 bool prepare_inplace_alter_table(TABLE *altered_table,
390 Alter_inplace_info *ha_alter_info,
391 const dd::Table *old_dd_tab,
392 dd::Table *new_dd_tab) override;
393
394 /** Alter the table structure in-place with operations
395 specified using HA_ALTER_FLAGS and Alter_inplace_information.
396 The level of concurrency allowed during this operation depends
397 on the return value from check_if_supported_inplace_alter().
398 @param[in] altered_table TABLE object for new version of table.
399 @param[in,out] ha_alter_info Structure describing changes to be done
400 by ALTER TABLE and holding data used during in-place alter.
401 @param[in] old_dd_tab dd::Table object describing old version
402 of the table.
403 @param[in,out] new_dd_tab dd::Table object for the new version of
404 the table. Can be adjusted by this call. Changes to the table definition will
405 be persisted in the data-dictionary at statement commit time.
406 @retval true Failure
407 @retval false Success
408 */
409 bool inplace_alter_table(TABLE *altered_table,
410 Alter_inplace_info *ha_alter_info,
411 const dd::Table *old_dd_tab,
412 dd::Table *new_dd_tab) override;
413
414 /** Commit or rollback the changes made during
415 prepare_inplace_alter_table() and inplace_alter_table() inside
416 the storage engine. Note that the allowed level of concurrency
417 during this operation will be the same as for
418 inplace_alter_table() and thus might be higher than during
419 prepare_inplace_alter_table(). (E.g concurrent writes were
420 blocked during prepare, but might not be during commit).
421 @param[in] altered_table TABLE object for new version of table.
422 @param[in,out] ha_alter_info Structure describing changes to be done
423 by ALTER TABLE and holding data used during in-place alter.
424 @param[in] commit True to commit or false to rollback.
425 @param[in] old_dd_tab dd::Table object representing old
426 version of the table
427 @param[in,out] new_dd_tab dd::Table object representing new
428 version of the table. Can be adjusted by this call. Changes to the table
429 definition will be persisted in the data-dictionary at statement
430 commit time.
431 @retval true Failure
432 @retval false Success */
433 bool commit_inplace_alter_table(TABLE *altered_table,
434 Alter_inplace_info *ha_alter_info,
435 bool commit, const dd::Table *old_dd_tab,
436 dd::Table *new_dd_tab) override;
437 /** @} */
438
440
441 /** Initializes a parallel scan. It creates a scan_ctx that has to
442 be used across all parallel_scan methods. Also, gets the number of threads
443 that would be spawned for parallel scan.
444 @param[out] scan_ctx A scan context created by this method
445 that has to be used in parallel_scan
446 @param[out] num_threads Number of threads to be spawned
447 @param[in] use_reserved_threads true if reserved threads are to be used
448 if we exhaust the max cap of number of
449 parallel read threads that can be
450 spawned at a time
451 @param[in] max_desired_threads Maximum number of desired read threads;
452 passing 0 has no effect, it is ignored;
453 upper-limited by the current value of
454 innodb_parallel_read_threads.
455 @return error code
456 @retval 0 on success */
457 int parallel_scan_init(void *&scan_ctx, size_t *num_threads,
458 bool use_reserved_threads,
459 size_t max_desired_threads) override;
460
461 /** Start parallel read of InnoDB records.
462 @param[in] scan_ctx A scan context created by parallel_scan_init
463 @param[in] thread_ctxs Context for each of the spawned threads
464 @param[in] init_fn Callback called by each parallel load
465 thread at the beginning of the parallel load.
466 @param[in] load_fn Callback called by each parallel load
467 thread when processing of rows is required.
468 @param[in] end_fn Callback called by each parallel load
469 thread when processing of rows has ended.
470 @return error code
471 @retval 0 on success */
472 int parallel_scan(void *scan_ctx, void **thread_ctxs, Reader::Init_fn init_fn,
473 Reader::Load_fn load_fn, Reader::End_fn end_fn) override;
474
475 /** End of the parallel scan.
476 @param[in] scan_ctx A scan context created by parallel_scan_init. */
477 void parallel_scan_end(void *scan_ctx) override;
478
479 /** Check if the table is ready for bulk load
480 @param[in] thd user session
481 @return true iff bulk load can be done on the table. */
482 bool bulk_load_check(THD *thd) const override;
483
484 /** Check the table for any foreign key constraint violations.
485 @return 0 when there are no violations (success) */
486 int check_foreign_constraints(THD *thd, size_t n_threads) const override;
487
488 /** Used during bulk load on a non-empty table, called after the CSV file
489 input is exhausted and we need to copy any existing data from the original
490 table to the duplicated one.
491 @param[in] load_ctx SE load context
492 @param[in] thread_idx loader thread index
493 @param[in] wait_cbk stat callbacks.
494 @return 0 if successful, HA_ERR_GENERIC otherwise. */
496 void *load_ctx, size_t thread_idx,
497 Bulk_load::Stat_callbacks &wait_cbk) const override;
498
499 /** Sets the source table data (table name and key range boundaries) for all
500 loaders.
501 @param[in,out] load_ctx SE load context
502 @param[in] source_table_data vector containing the source table data
503 @return true if successful, false otherwise. */
505 void *load_ctx,
506 const std::vector<Bulk_load::Source_table_data> &source_table_data)
507 const override;
508
509 /** Generates a temporary table name to be used for table duplication during
510 bulk load.
511 @return a temporary table name. */
512 std::string bulk_load_generate_temporary_table_name() const override;
513
514 /** Get the row ID range of the table that we're bulk loading into. Only used
515 when the table has a generated clustered index and is not empty.
516 @param[out] min Minimum ROW_ID in table
517 @param[out] max Maximum ROW_ID in table
518 @return true if successful, false otherwise. */
519 bool bulk_load_get_row_id_range(size_t &min, size_t &max) const override;
520
521 /** Check whether the table is empty */
522 bool is_table_empty() const override;
523
524 /** Get the total memory available for bulk load in innodb buffer pool.
525 @param[in] thd user session
526 @return available memory for bulk load */
527 size_t bulk_load_available_memory(THD *thd) const override;
528
529 /** Begin parallel bulk data load to the table.
530 @param[in] thd user session
531 @param[in] keynr key number to identify the index.
532 @param[in] data_size total data size in bytes
533 @param[in] memory buffer pool memory to be used
534 @param[in] num_threads Number of concurrent threads used for load.
535 @return bulk load context or nullptr if unsuccessful. */
536 void *bulk_load_begin(THD *thd, size_t keynr, size_t data_size, size_t memory,
537 size_t num_threads) override;
538
539 /** Execute bulk load operation. To be called by each of the concurrent
540 threads idenified by thread index.
541 @param[in,out] thd user session
542 @param[in,out] load_ctx load execution context
543 @param[in] thread_idx index of the thread executing
544 @param[in] rows rows to be loaded to the table
545 @param[in] wait_cbk Stat callbacks
546 @return error code. */
547 int bulk_load_execute(THD *thd, void *load_ctx, size_t thread_idx,
548 const Rows_mysql &rows,
549 Bulk_load::Stat_callbacks &wait_cbk) override;
550
551 /** Open a blob for write operation.
552 @param[in,out] thd user session
553 @param[in,out] load_ctx load execution context
554 @param[in] thread_idx index of the thread executing
555 @param[out] blob_ctx a blob context
556 @param[out] blobref a blob reference to be placed in the record.
557 @return 0 on success, error code on failure */
558 int open_blob(THD *thd [[maybe_unused]], void *load_ctx, size_t thread_idx,
559 Blob_context &blob_ctx, unsigned char *blobref) override;
560
561 /** Write to a blob
562 @param[in,out] thd user session
563 @param[in,out] load_ctx load execution context
564 @param[in] thread_idx index of the thread executing
565 @param[in] blob_ctx a blob context
566 @param[out] blobref buffer to hold a blob reference.
567 @param[in] data data to be written to blob.
568 @param[in] data_len length of data to be written in bytes.
569 @return 0 on success, error code on failure */
570 int write_blob(THD *thd [[maybe_unused]], void *load_ctx, size_t thread_idx,
571 Blob_context blob_ctx, unsigned char *blobref,
572 const unsigned char *data, size_t data_len) override;
573
574 /** Close the blob
575 @param[in,out] thd user session
576 @param[in,out] load_ctx load execution context
577 @param[in] thread_idx index of the thread executing
578 @param[in] blob_ctx a blob context
579 @param[out] blobref blob reference will be populated in the provided
580 buffer. The buffer should have enough space (@ref lob::ref_t::SIZE) to hold
581 a blob reference.
582 @return 0 on success, error code on failure */
583 int close_blob(THD *thd [[maybe_unused]], void *load_ctx, size_t thread_idx,
584 Blob_context blob_ctx, byte *blobref) override;
585
586 /** End bulk load operation. Must be called after all execution threads have
587 completed. Must be called even if the bulk load execution failed.
588 @param[in,out] thd user session
589 @param[in,out] load_ctx load execution context
590 @param[in] is_error true, if bulk load execution have failed
591 @return error code. */
592 int bulk_load_end(THD *thd, void *load_ctx, bool is_error) override;
593
595 ulonglong auto_increment_value) override;
596
598 uint table_changes) override;
599
600 private:
601 /** @name Multi Range Read interface
602 @{ */
603
604 /** Initialize multi range read @see DsMrr_impl::dsmrr_init */
605 int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
606 uint n_ranges, uint mode,
607 HANDLER_BUFFER *buf) override;
608
609 /** Process next multi range read @see DsMrr_impl::dsmrr_next */
610 int multi_range_read_next(char **range_info) override;
611
612 /** Initialize multi range read and get information.
613 @see ha_myisam::multi_range_read_info_const
614 @see DsMrr_impl::dsmrr_info_const */
616 void *seq_init_param, uint n_ranges,
617 uint *bufsz, uint *flags,
618 bool *force_default_mrr,
619 Cost_estimate *cost) override;
620
621 /** Initialize multi range read and get information.
622 @see DsMrr_impl::dsmrr_info */
623 ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
624 uint *bufsz, uint *flags,
625 Cost_estimate *cost) override;
626
627 /** Attempt to push down an index condition.
628 @param[in] keyno MySQL key number
629 @param[in] idx_cond Index condition to be checked
630 @return idx_cond if pushed; NULL if not pushed */
631 Item *idx_cond_push(uint keyno, Item *idx_cond) override;
632 /** @} */
633
634 private:
635 void update_thd();
636
637 int change_active_index(uint keynr);
638
640
642
644
646
647 /** Resets a query execution 'template'.
648 @see build_template() */
649 void reset_template();
650
651 /** Write Row Interface optimized for Intrinsic table. */
653
654 /** Find out if a Record_buffer is wanted by this handler, and what is
655 the maximum buffer size the handler wants.
656
657 @param[out] max_rows gets set to the maximum number of records to
658 allocate space for in the buffer
659 @retval true if the handler wants a buffer
660 @retval false if the handler does not want a buffer */
661 bool is_record_buffer_wanted(ha_rows *const max_rows) const override;
662
663 /** TRUNCATE an InnoDB table.
664 @param[in] name table name
665 @param[in] form table definition
666 @param[in,out] table_def dd::Table describing table to be
667 truncated. Can be adjusted by SE, the changes will be saved into
668 the data-dictionary at statement commit time.
669 @return error number
670 @retval 0 on success */
671 int truncate_impl(const char *name, TABLE *form, dd::Table *table_def);
672
673 protected:
674 /** Enter InnoDB engine after checking max allowed threads.
675 @return mysql error code. */
677
678 /** Leave Innodb, if no more tickets are left */
680
681 void update_thd(THD *thd);
682
683 int general_fetch(uchar *buf, uint direction, uint match_mode);
684
685 virtual dict_index_t *innobase_get_index(uint keynr);
686
687 /** Builds a 'template' to the m_prebuilt struct. The template is used in fast
688 retrieval of just those column values MySQL needs in its processing.
689 @param[in] whole_row true if access is needed to a whole row, false if
690 accessing individual fields is enough */
691 void build_template(bool whole_row);
692
693 /** Returns statistics information of the table to the MySQL interpreter, in
694 various fields of the handle object.
695 @param[in] flag what information is requested
696 HA_STATUS_NO_LOCK is supported only for:
697 ha_statistics::delete_length
698 it is not supported for others like:
699 ha_statistics::records
700 But it will not lock for the duration of stats
701 calculation. Only during copy to make sure
702 stats are consistent.
703 @param[in] is_analyze True if called from "::analyze()".
704 @return HA_ERR_* error code or 0 */
705 virtual int info_low(uint flag, bool is_analyze);
706
707 /**
708 MySQL calls this method at the end of each statement. This method
709 exists for readability only, called from reset(). The name reset()
710 doesn't give any clue that it is called at the end of a statement. */
711 int end_stmt();
712
713 /** Implementation of prepare_inplace_alter_table()
714 @tparam Table dd::Table or dd::Partition
715 @param[in] altered_table TABLE object for new version of table.
716 @param[in,out] ha_alter_info Structure describing changes to be done
717 by ALTER TABLE and holding data used
718 during in-place alter.
719 @param[in] old_dd_tab dd::Table object representing old
720 version of the table
721 @param[in,out] new_dd_tab dd::Table object representing new
722 version of the table
723 @retval true Failure
724 @retval false Success */
725 template <typename Table>
726 bool prepare_inplace_alter_table_impl(TABLE *altered_table,
727 Alter_inplace_info *ha_alter_info,
728 const Table *old_dd_tab,
729 Table *new_dd_tab);
730
731 /** Implementation of inplace_alter_table()
732 @tparam Table dd::Table or dd::Partition
733 @param[in] altered_table TABLE object for new version of table.
734 @param[in,out] ha_alter_info Structure describing changes to be done
735 by ALTER TABLE and holding data used
736 during in-place alter.
737 the table. Can be adjusted by this call. Changes to the table definition will
738 be persisted in the data-dictionary at statement commit time.
739 @retval true Failure
740 @retval false Success
741 */
742 template <typename Table>
743 bool inplace_alter_table_impl(TABLE *altered_table,
744 Alter_inplace_info *ha_alter_info);
745
746 /** Implementation of commit_inplace_alter_table()
747 @tparam Table dd::Table or dd::Partition
748 @param[in] altered_table TABLE object for new version of table.
749 @param[in,out] ha_alter_info Structure describing changes to be done
750 by ALTER TABLE and holding data used
751 during in-place alter.
752 @param[in] commit True to commit or false to rollback.
753 @param[in,out] new_dd_tab Table object for the new version of the
754 table. Can be adjusted by this call.
755 Changes to the table definition
756 will be persisted in the data-dictionary
757 at statement version of it.
758 @retval true Failure
759 @retval false Success */
760 template <typename Table>
761 bool commit_inplace_alter_table_impl(TABLE *altered_table,
762 Alter_inplace_info *ha_alter_info,
763 bool commit, Table *new_dd_tab);
764
765 /**
766 Return max limits for a single set of multi-valued keys
767
768 @param[out] num_keys number of keys to store
769 @param[out] keys_length total length of keys, bytes
770 */
771 void mv_key_capacity(uint *num_keys, size_t *keys_length) const override;
772
773 /** Can reuse the template. Mainly used for partition.
774 @retval true Can reuse the mysql_template */
775 virtual bool can_reuse_mysql_template() const { return false; }
776
777 /** The multi range read session object */
779
780 /** Save CPU time with prebuilt/cached data structures */
782
783 /** Thread handle of the user currently using the handler;
784 this is set in external_lock function */
786
787 /** information for MySQL table locking */
789
790 /** buffer used in updates */
792
793 /** the size of upd_buf in bytes */
795
796 /** Flags that specify the handler instance (table) capability. */
798
799 /** this is set to 1 when we are starting a table scan but have
800 not yet fetched any row, else false */
802
803 /*!< match mode of the latest search: ROW_SEL_EXACT,
804 ROW_SEL_EXACT_PREFIX, or undefined */
806
807 /** this field is used to remember the original select_lock_type that
808 was decided in ha_innodb.cc,":: store_lock()", "::external_lock()",
809 etc. */
811
812 /** If mysql has locked with external_lock() */
814
815 /** Get the table stats.
816 @param[in] flag flag indicating which statistics to return
817 @param[in] ib_table table
818 @param[out] n_rows estimated number of rows
819 @param[out] stat_clustered_index_size size of the clustered index
820 @param[out] stat_sum_of_other_index_sizes total size of all indexes */
821 void info_low_table_stats(uint flag, const dict_table_t *ib_table,
822 uint64_t &n_rows, ulint &stat_clustered_index_size,
823 ulint &stat_sum_of_other_index_sizes) const;
824
825 /** Get number of records per key. Save them into array ib_table->key_info.
826 @param[in] flag flag indicating which statistics to return
827 @param[in,out] ib_table table */
828 void info_low_key(uint flag, const dict_table_t *ib_table);
829};
830
831struct trx_t;
832
833extern const struct _ft_vft ft_vft_result;
834
835/** Return the number of read threads for this session.
836@param[in] thd Session instance, or nullptr to query the global
837 innodb_parallel_read_threads value. */
839
840/** Structure Returned by ha_innobase::ft_init_ext() */
841typedef struct new_ft_info {
847
848/** Allocates an InnoDB transaction for a MySQL handler object for DML.
849@param[in] hton Innobase handlerton.
850@param[in] thd MySQL thd (connection) object.
851@param[in] trx transaction to register. */
852void innobase_register_trx(handlerton *hton, THD *thd, trx_t *trx);
853
854/**
855Allocates an InnoDB transaction for a MySQL handler object.
856@return InnoDB transaction handle */
857trx_t *innobase_trx_allocate(THD *thd); /*!< in: user thread handle */
858
859/** Maps a MySQL trx isolation level code to the InnoDB isolation level code.
860@param[in] iso MySQL isolation level code
861@return InnoDB isolation level */
864
865/** Match index columns between MySQL and InnoDB.
866This function checks whether the index column information
867is consistent between KEY info from mysql and that from innodb index.
868@param[in] key_info Index info from mysql
869@param[in] index_info Index info from InnoDB
870@return true if all column types match. */
871bool innobase_match_index_columns(const KEY *key_info,
872 const dict_index_t *index_info);
873
874/** This function checks each index name for a table against reserved
875 system default primary index name 'GEN_CLUST_INDEX'. If a name
876 matches, this function pushes an warning message to the client,
877 and returns true.
878 @return true if the index name matches the reserved name */
879[[nodiscard]] bool innobase_index_name_is_reserved(
880 THD *thd, /*!< in/out: MySQL connection */
881 const KEY *key_info, /*!< in: Indexes to be
882 created */
883 ulint num_of_keys); /*!< in: Number of indexes to
884 be created. */
885
886/** Check if the explicit tablespace targeted is file_per_table.
887@param[in] create_info Metadata for the table to create.
888@return true if the table is intended to use a file_per_table tablespace. */
890 const HA_CREATE_INFO *create_info) {
891 return (create_info->tablespace != nullptr &&
892 (0 ==
893 strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)));
894}
895
896/** Check if table will be explicitly put in an existing shared general
897or system tablespace.
898@param[in] create_info Metadata for the table to create.
899@return true if the table will use a shared general or system tablespace. */
900static inline bool tablespace_is_shared_space(
901 const HA_CREATE_INFO *create_info) {
902 return (create_info->tablespace != nullptr &&
903 create_info->tablespace[0] != '\0' &&
904 (0 !=
905 strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)));
906}
907
908/** Check if table will be explicitly put in a general tablespace.
909@param[in] create_info Metadata for the table to create.
910@return true if the table will use a general tablespace. */
912 const HA_CREATE_INFO *create_info) {
913 return (
914 create_info->tablespace != nullptr &&
915 create_info->tablespace[0] != '\0' &&
916 (0 !=
917 strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)) &&
918 (0 != strcmp(create_info->tablespace, dict_sys_t::s_temp_space_name)) &&
919 (0 != strcmp(create_info->tablespace, dict_sys_t::s_sys_space_name)));
920}
921
922/** Check if tablespace is shared tablespace.
923@param[in] tablespace_name Name of the tablespace
924@return true if tablespace is a shared tablespace. */
925static inline bool is_shared_tablespace(const char *tablespace_name) {
926 if (tablespace_name != nullptr && tablespace_name[0] != '\0' &&
927 (strcmp(tablespace_name, dict_sys_t::s_file_per_table_name) != 0)) {
928 return true;
929 }
930 return false;
931}
932
933constexpr uint32_t SIZE_MB = 1024 * 1024;
934
935/** Validate AUTOEXTEND_SIZE attribute for a tablespace.
936@param[in] ext_size Value of autoextend_size attribute
937@return DB_SUCCESS if the value of AUTOEXTEND_SIZE is valid. */
938static inline int validate_autoextend_size_value(uint64_t ext_size) {
939 ut_ad(ext_size > 0);
940
941 page_no_t extent_size_pages = fsp_get_extent_size_in_pages(
942 {static_cast<uint32_t>(srv_page_size),
943 static_cast<uint32_t>(srv_page_size), false});
944
945 /* Validate following for the AUTOEXTEND_SIZE attribute
946 1. The autoextend_size should be a multiple of size of 4 extents
947 2. The autoextend_size value should be between size of 4 extents and 4G */
948 if (ext_size < (FSP_FREE_ADD * extent_size_pages * srv_page_size) ||
949 ext_size > FSP_MAX_AUTOEXTEND_SIZE) {
950 my_error(ER_INNODB_AUTOEXTEND_SIZE_OUT_OF_RANGE, MYF(0),
951 (FSP_FREE_ADD * extent_size_pages * srv_page_size) / SIZE_MB,
953 return ER_INNODB_AUTOEXTEND_SIZE_OUT_OF_RANGE;
954 }
955
956 if ((ext_size / srv_page_size) % (FSP_FREE_ADD * extent_size_pages) != 0) {
957 my_error(ER_INNODB_INVALID_AUTOEXTEND_SIZE_VALUE, MYF(0),
958 FSP_FREE_ADD * extent_size_pages * srv_page_size / SIZE_MB);
959 return ER_INNODB_INVALID_AUTOEXTEND_SIZE_VALUE;
960 }
961
962 return DB_SUCCESS;
963}
964
965/** Parse hint for table and its indexes, and update the information
966in dictionary.
967@param[in] thd Connection thread
968@param[in,out] table Target table
969@param[in] table_share Table definition */
971 const TABLE_SHARE *table_share);
972
973/** Obtain the InnoDB transaction of a MySQL thread.
974@param[in,out] thd MySQL thread handler.
975@return reference to transaction pointer */
976trx_t *&thd_to_trx(THD *thd);
977
978/** Class for handling create table information. */
980 public:
981 /** Constructor.
982 Used in two ways:
983 - all but file_per_table is used, when creating the table.
984 - all but name/path is used, when validating options and using flags. */
986 char *table_name, char *remote_path, char *tablespace,
987 bool file_per_table, bool skip_strict, uint32_t old_flags,
988 uint32_t old_flags2, bool is_partition)
989 : m_thd(thd),
991 m_form(form),
992 m_create_info(create_info),
994 m_remote_path(remote_path),
995 m_tablespace(tablespace),
996 m_innodb_file_per_table(file_per_table),
997 m_flags(old_flags),
998 m_flags2(old_flags2),
1001
1002 /** Initialize the object. */
1003 int initialize();
1004
1005 /** Set m_tablespace_type. */
1006 void set_tablespace_type(bool table_being_altered_is_file_per_table);
1007
1008 /** Create the internal innodb table.
1009 @param[in] dd_table dd::Table or nullptr for intrinsic table
1010 @param[in] old_part_table dd::Table from an old partition for partitioned
1011 table, NULL otherwise.
1012 @return 0 or error number */
1013 int create_table(const dd::Table *dd_table, const dd::Table *old_part_table);
1014
1015 /** Update the internal data dictionary. */
1017
1018 /** Update the global data dictionary.
1019 @param[in] dd_table dd::Table or dd::Partition
1020 @retval 0 On success
1021 @retval error number On failure */
1022 template <typename Table>
1023 int create_table_update_global_dd(Table *dd_table);
1024
1025 /** Validates the create options. Checks that the options
1026 KEY_BLOCK_SIZE, ROW_FORMAT, DATA DIRECTORY, TEMPORARY & TABLESPACE
1027 are compatible with each other and other settings.
1028 These CREATE OPTIONS are not validated here unless innodb_strict_mode
1029 is on. With strict mode, this function will report each problem it
1030 finds using a custom message with error code
1031 ER_ILLEGAL_HA_CREATE_OPTION, not its built-in message.
1032 @return NULL if valid, string name of bad option if not. */
1033 const char *create_options_are_invalid();
1034
1035 private:
1036 /** Put a warning or error message to the error log for the
1037 DATA DIRECTORY option.
1038 @param[in] msg The reason that data directory is wrong.
1039 @param[in] ignore If true, append a message about ignoring
1040 the data directory location. */
1041 void log_error_invalid_location(std::string &msg, bool ignore);
1042
1043 /** Validate DATA DIRECTORY option. */
1045
1046 public:
1047 /** Validate TABLESPACE option. */
1049
1050 /** Validate COMPRESSION option. */
1052
1053 /** Prepare to create a table. */
1054 int prepare_create_table(const char *name);
1055
1056 /** Determine InnoDB table flags.
1057 If strict_mode=OFF, this will adjust the flags to what should be assumed.
1058 However, if an existing general tablespace is being targeted, we will NOT
1059 assume anything or adjust these flags.
1060 @retval true if successful, false if error */
1061 bool innobase_table_flags();
1062
1063 /** Set flags and append '/' to remote path if necessary. */
1064 void set_remote_path_flags();
1065
1066 /** Get table flags. */
1067 uint32_t flags() const { return (m_flags); }
1068
1069 /** Get table flags2. */
1070 uint32_t flags2() const { return (m_flags2); }
1071
1072 /** Reset table flags. */
1073 void flags_reset() { m_flags = 0; }
1074
1075 /** Reset table flags2. */
1076 void flags2_reset() { m_flags2 = 0; }
1077
1078 /** whether to skip strict check. */
1079 bool skip_strict() const { return (m_skip_strict); }
1080
1081 /** Return table name. */
1082 const char *table_name() const { return (m_table_name); }
1083
1084 THD *thd() const { return (m_thd); }
1085
1086 inline bool is_intrinsic_temp_table() const {
1087 /* DICT_TF2_INTRINSIC implies DICT_TF2_TEMPORARY */
1089 return ((m_flags2 & DICT_TF2_INTRINSIC) != 0);
1090 }
1091
1092 /** @return true only if table is temporary and not intrinsic */
1093 inline bool is_temp_table() const {
1094 return (((m_flags2 & DICT_TF2_TEMPORARY) != 0) &&
1095 ((m_flags2 & DICT_TF2_INTRINSIC) == 0));
1096 }
1097
1098 /** Detach the just created table and its auxiliary tables if exist. */
1099 void detach();
1100
1101 /** Normalizes a table name string.
1102 A normalized name consists of the database name catenated to '/' and
1103 table name. An example: test/mytable. On case insensitive file system
1104 normalization converts name to lower case.
1105 @param[in,out] norm_name Buffer to return the normalized name in.
1106 @param[in] name Table name string.
1107 @return true if successful. */
1108 static bool normalize_table_name(char *norm_name, const char *name);
1109
1110 private:
1111 /** Parses the table name into normal name and either temp path or
1112 remote path if needed.*/
1113 int parse_table_name(const char *name);
1114
1115 /** Create a table definition to an InnoDB database.
1116 @param[in] dd_table dd::Table or nullptr for intrinsic table
1117 @param[in] old_part_table dd::Table from an old partition for partitioned
1118 table, NULL otherwise.
1119 @return HA_* level error */
1120 int create_table_def(const dd::Table *dd_table,
1121 const dd::Table *old_part_table);
1122
1123 /** Initialize the autoinc of this table if necessary, which should
1124 be called before we flush logs, so autoinc counter can be persisted. */
1125 void initialize_autoinc();
1126
1127 /** Connection thread handle. */
1129
1130 /** InnoDB transaction handle. */
1132
1133 /** Information on table columns and indexes. */
1135
1136 /** Create options. */
1138
1139 /** Table name */
1141 /** Remote path (DATA DIRECTORY) or zero length-string */
1143 /** Tablespace name or zero length-string. */
1145
1146 /** The newly created InnoDB table object. This is currently only
1147 used in this class, since the new table is not evictable until
1148 final success/failure, it can be accessed directly. */
1150
1151 /** Local copy of srv_file_per_table. */
1153
1154 /** Allow file_per_table for this table either because:
1155 1) the setting innodb_file_per_table=on,
1156 2) it was explicitly requested by tablespace=innodb_file_per_table.
1157 3) the table being altered is currently file_per_table */
1159
1160 /** After all considerations, this shows whether we will actually
1161 create a table and tablespace using file-per-table. */
1163
1164 /** Using DATA DIRECTORY */
1166
1167 /** Using a Shared General Tablespace */
1169
1170 /** Table flags */
1171 uint32_t m_flags;
1172
1173 /** Table flags2 */
1174 uint32_t m_flags2;
1175
1176 /** Skip strict check */
1178
1179 /** True if this table is a partition */
1181};
1182
1183/** Class of basic DDL implementation, for CREATE/DROP/RENAME TABLE */
1185 public:
1186 /** Create an InnoDB table.
1187 @tparam Table dd::Table or dd::Partition
1188 @param[in,out] thd THD object
1189 @param[in] name Table name, format: "db/table_name"
1190 @param[in] form Table format; columns and index
1191 information
1192 @param[in] create_info Create info(including create statement
1193 string)
1194 @param[in,out] dd_tab dd::Table describing table to be created
1195 @param[in] file_per_table whether to create a tablespace too
1196 @param[in] evictable whether the caller wants the
1197 dict_table_t to be kept in memory
1198 @param[in] skip_strict whether to skip strict check for create
1199 option
1200 @param[in] old_flags old Table flags
1201 @param[in] old_flags2 old Table flags2
1202 @param[in] old_dd_table Table def for old table. Used in truncate or
1203 while adding a new partition
1204 @return error number
1205 @retval 0 on success */
1206 template <typename Table>
1207 static int create_impl(THD *thd, const char *name, TABLE *form,
1208 HA_CREATE_INFO *create_info, Table *dd_tab,
1209 bool file_per_table, bool evictable, bool skip_strict,
1210 uint32_t old_flags, uint32_t old_flags2,
1211 const dd::Table *old_dd_table);
1212
1213 /** Drop an InnoDB table.
1214 @tparam Table dd::Table or dd::Partition
1215 @param[in,out] thd THD object
1216 @param[in] name table name
1217 @param[in] dd_tab dd::Table describing table to be dropped
1218 @param[in] td MySQL table definition
1219 @return error number
1220 @retval 0 on success */
1221
1222 template <typename Table>
1223 static int delete_impl(THD *thd, const char *name, const Table *dd_tab,
1224 const TABLE *td);
1225
1226 /** Renames an InnoDB table.
1227 @tparam Table dd::Table or dd::Partition
1228 @param[in,out] thd THD object
1229 @param[in] from old name of the table
1230 @param[in] to new name of the table
1231 @param[in] from_table dd::Table or dd::Partition of the table
1232 with old name
1233 @param[in] to_table dd::Table or dd::Partition of the table
1234 with new name
1235 @param[in] td MySQL table definition
1236 @return error number
1237 @retval 0 on success */
1238
1239 template <typename Table>
1240 static int rename_impl(THD *thd, const char *from, const char *to,
1241 const Table *from_table, const Table *to_table,
1242 const TABLE *td);
1243};
1244
1245/** Class to handle TRUNCATE for one InnoDB table or one partition */
1246template <typename Table>
1248 public:
1249 /** Constructor
1250 @param[in] thd THD object
1251 @param[in] name normalized table name
1252 @param[in] form Table format; columns and index information
1253 @param[in] dd_table dd::Table or dd::Partition
1254 @param[in] keep_autoinc true to remember original autoinc counter
1255 @param[in] table_truncate true if this is full table truncate */
1256 innobase_truncate(THD *thd, const char *name, TABLE *form, Table *dd_table,
1257 bool keep_autoinc, bool table_truncate)
1258 : m_thd(thd),
1259 m_name(name),
1260 m_dd_table(dd_table),
1261 m_trx(nullptr),
1263 m_form(form),
1264 m_create_info(),
1265 m_file_per_table(false),
1266 m_keep_autoinc(keep_autoinc),
1267 m_table_truncate(table_truncate),
1268 m_flags(0),
1269 m_flags2(0) {}
1270
1271 /** Destructor */
1273
1274 /** Open the table/partition to be truncated
1275 @param[out] innodb_table InnoDB table object opened
1276 @return error number or 0 on success */
1277 int open_table(dict_table_t *&innodb_table);
1278
1279 /** Do the truncate of the table/partition
1280 @return error number or 0 on success */
1281 int exec();
1282
1283 private:
1284 /** Prepare for truncate
1285 @return error number or 0 on success */
1286 int prepare();
1287
1288 /** Do the real truncation
1289 @return error number or 0 on success */
1290 int truncate();
1291
1292 /** Rename tablespace file name
1293 @return error number or 0 on success */
1294 int rename_tablespace();
1295
1296 /** Cleanup */
1297 void cleanup();
1298
1299 /** Reload the FK related information
1300 @return error number or 0 on success */
1301 int load_fk();
1302
1303 private:
1304 /** THD object */
1306
1307 /** Normalized table name */
1308 const char *m_name;
1309
1310 /** dd::Table or dd::Partition */
1312
1313 /** Transaction attached to current thd */
1315
1316 /** InnoDB table object for the table/partition */
1318
1319 /** Table format */
1321
1322 /** Create information */
1324
1325 /** True if this table/partition is file per table */
1327
1328 /** True if the original autoinc counter should be kept. It's
1329 specified by caller, however if the table has no AUTOINC column,
1330 it would be reset to false internally */
1332
1333 /** For a prtition table, this is true if full table is truncated. If only
1334 a partition is truncated, it is set to false. */
1336
1337 /** flags of the table to be truncated, which should not change */
1338 uint32_t m_flags;
1339
1340 /** flags2 of the table to be truncated, which should not change */
1341 uint32_t m_flags2;
1342};
1343
1344/**
1345Initialize the table FTS stopword list
1346@return true if success */
1347[[nodiscard]] bool innobase_fts_load_stopword(
1348 dict_table_t *table, /*!< in: Table has the FTS */
1349 trx_t *trx, /*!< in: transaction */
1350 THD *thd); /*!< in: current thread */
1351
1352/** Some defines for innobase_fts_check_doc_id_index() return value */
1358
1359/**
1360Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME
1361on the Doc ID column.
1362@return the status of the FTS_DOC_ID index */
1364 const dict_table_t *table, /*!< in: table definition */
1365 const TABLE *altered_table, /*!< in: MySQL table
1366 that is being altered */
1367 ulint *fts_doc_col_no); /*!< out: The column number for
1368 Doc ID */
1369
1370/**
1371Check whether the table has a unique index with FTS_DOC_ID_INDEX_NAME
1372on the Doc ID column in MySQL create index definition.
1373@return FTS_EXIST_DOC_ID_INDEX if there exists the FTS_DOC_ID index,
1374FTS_INCORRECT_DOC_ID_INDEX if the FTS_DOC_ID index is of wrong format */
1376 ulint n_key, /*!< in: Number of keys */
1377 const KEY *key_info); /*!< in: Key definitions */
1378
1379/**
1380Copy table flags from MySQL's TABLE_SHARE into an InnoDB table object.
1381Those flags are stored in .frm file and end up in the MySQL table object,
1382but are frequently used inside InnoDB so we keep their copies into the
1383InnoDB table object. */
1385 dict_table_t *innodb_table, /*!< in/out: InnoDB table */
1386 const TABLE_SHARE *table_share); /*!< in: table share */
1387
1388/** Set up base columns for virtual column
1389@param[in] table the InnoDB table
1390@param[in] field MySQL field
1391@param[in,out] v_col virtual column to be set up */
1392void innodb_base_col_setup(dict_table_t *table, const Field *field,
1393 dict_v_col_t *v_col);
1394
1395/** Set up base columns for stored column
1396@param[in] table InnoDB table
1397@param[in] field MySQL field
1398@param[in,out] s_col stored column */
1400 const Field *field, dict_s_col_t *s_col);
1401
1402/** whether this is a stored column */
1403static inline bool innobase_is_s_fld(const Field *field) {
1404 return field->gcol_info && field->stored_in_db;
1405}
1406
1407/** Whether this is a computed multi-value virtual column.
1408This condition check should be equal to the following one:
1409(innobase_is_v_fld(field) && (field)->gcol_info->expr_item &&
1410 field->gcol_info->expr_item->returns_array())
1411*/
1412static inline bool innobase_is_multi_value_fld(const Field *field) {
1413 return field->is_array();
1414}
1415
1416static inline bool normalize_table_name(char *norm_name, const char *name) {
1418}
1419
1420/** Note that a transaction has been registered with MySQL.
1421@param[in] trx Transaction.
1422@return true if transaction is registered with MySQL 2PC coordinator */
1423inline bool trx_is_registered_for_2pc(const trx_t *trx) {
1424 return (trx->is_registered == 1);
1425}
1426
1427/** Converts an InnoDB error code to a MySQL error code.
1428Also tells to MySQL about a possible transaction rollback inside InnoDB caused
1429by a lock wait timeout or a deadlock.
1430@param[in] error InnoDB error code.
1431@param[in] flags InnoDB table flags or 0.
1432@param[in] thd MySQL thread or NULL.
1433@return MySQL error code */
1435
1436/** Converts a search mode flag understood by MySQL to a flag understood
1437by InnoDB.
1438@param[in] find_flag MySQL search mode flag.
1439@return InnoDB search mode flag. */
1441 enum ha_rkey_function find_flag);
1442
1443extern bool innobase_stats_on_metadata;
1444
1445/** Calculate Record Per Key value.
1446Need to exclude the NULL value if innodb_stats_method is set to "nulls_ignored"
1447@param[in] index InnoDB index.
1448@param[in] i The column we are calculating rec per key.
1449@param[in] records Estimated total records.
1450@return estimated record per key value */
1452 ha_rows records);
1453
1454/** Build template for the virtual columns and their base columns. This
1455is done when the table first opened.
1456@param[in] table MySQL TABLE
1457@param[in] ib_table InnoDB dict_table_t
1458@param[in,out] s_templ InnoDB template structure
1459@param[in] add_v new virtual columns added along with
1460 add index call
1461@param[in] locked true if dict_sys mutex is held
1462@param[in] share_tbl_name original MySQL table name */
1463void innobase_build_v_templ(const TABLE *table, const dict_table_t *ib_table,
1464 dict_vcol_templ_t *s_templ,
1465 const dict_add_v_col_t *add_v, bool locked,
1466 const char *share_tbl_name);
1467
1468/** Callback used by MySQL server layer to initialize
1469the table virtual columns' template
1470@param[in] table MySQL TABLE
1471@param[in,out] ib_table InnoDB table */
1472void innobase_build_v_templ_callback(const TABLE *table, void *ib_table);
1473
1474/** Callback function definition, used by MySQL server layer to initialized
1475the table virtual columns' template */
1476typedef void (*my_gcolumn_templatecallback_t)(const TABLE *, void *);
1477
1478/** Drop the statistics for a specified table, and mark it as discard
1479after DDL
1480@param[in,out] thd THD object
1481@param[in,out] table InnoDB table object */
1483#endif /* ha_innodb_h */
uint32_t page_no_t
Page number.
Definition: api0api.h:47
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:247
Services for bulk data conversion and load to SE.
Class describing changes to be done by ALTER TABLE.
Definition: handler.h:3525
A helper class for numeric sysvars which can be read in thread-safe way.
Definition: ut0atomic_sysvar.h:36
Used to store optimizer cost estimates.
Definition: handler.h:4040
Definition: handler.h:7570
Definition: field.h:573
virtual bool is_array() const
Whether the field is a typed array.
Definition: field.h:1840
Value_generator * gcol_info
Definition: field.h:820
bool stored_in_db
Indication that the field is physically stored in tables rather than just generated on SQL queries.
Definition: field.h:826
Wrapper for struct ft_hints.
Definition: handler.h:4307
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:935
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:327
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:169
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:979
bool is_intrinsic_temp_table() const
Definition: ha_innodb.h:1086
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:1162
int prepare_create_table(const char *name)
Prepare to create a table.
Definition: ha_innodb.cc:13942
const char * table_name() const
Return table name.
Definition: ha_innodb.h:1082
uint32_t m_flags
Table flags.
Definition: ha_innodb.h:1171
THD * m_thd
Connection thread handle.
Definition: ha_innodb.h:1128
bool create_option_tablespace_is_valid()
Validate TABLESPACE option.
Definition: ha_innodb.cc:12680
char * m_remote_path
Remote path (DATA DIRECTORY) or zero length-string.
Definition: ha_innodb.h:1142
int create_table_update_global_dd(Table *dd_table)
Update the global data dictionary.
Definition: ha_innodb.cc:14316
bool create_option_compression_is_valid()
Validate COMPRESSION option.
Definition: ha_innodb.cc:12923
void flags2_reset()
Reset table flags2.
Definition: ha_innodb.h:1076
void initialize_autoinc()
Initialize the autoinc of this table if necessary, which should be called before we flush logs,...
Definition: ha_innodb.cc:13879
HA_CREATE_INFO * m_create_info
Create options.
Definition: ha_innodb.h:1137
bool is_temp_table() const
Definition: ha_innodb.h:1093
int initialize()
Initialize the object.
Definition: ha_innodb.cc:13851
dict_table_t * m_table
The newly created InnoDB table object.
Definition: ha_innodb.h:1149
void detach()
Detach the just created table and its auxiliary tables if exist.
Definition: ha_innodb.cc:13690
trx_t * m_trx
InnoDB transaction handle.
Definition: ha_innodb.h:1131
bool m_partition
True if this table is a partition.
Definition: ha_innodb.h:1180
uint32_t flags2() const
Get table flags2.
Definition: ha_innodb.h:1070
int create_table(const dd::Table *dd_table, const dd::Table *old_part_table)
Create the internal innodb table.
Definition: ha_innodb.cc:14056
static bool normalize_table_name(char *norm_name, const char *name)
Normalizes a table name string.
Definition: ha_innodb.cc:6721
bool m_use_data_dir
Using DATA DIRECTORY.
Definition: ha_innodb.h:1165
char * m_tablespace
Tablespace name or zero length-string.
Definition: ha_innodb.h:1144
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:1158
bool m_use_shared_space
Using a Shared General Tablespace.
Definition: ha_innodb.h:1168
uint32_t m_flags2
Table flags2.
Definition: ha_innodb.h:1174
bool m_skip_strict
Skip strict check.
Definition: ha_innodb.h:1177
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:13356
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:985
int create_table_update_dict()
Update the internal data dictionary.
Definition: ha_innodb.cc:14265
void set_tablespace_type(bool table_being_altered_is_file_per_table)
Set m_tablespace_type.
Definition: ha_innodb.cc:13820
bool m_innodb_file_per_table
Local copy of srv_file_per_table.
Definition: ha_innodb.h:1152
bool innobase_table_flags()
Determine InnoDB table flags.
Definition: ha_innodb.cc:13424
const TABLE * m_form
Information on table columns and indexes.
Definition: ha_innodb.h:1134
void set_remote_path_flags()
Set flags and append '/' to remote path if necessary.
Definition: ha_innopart.cc:2378
char * m_table_name
Table name.
Definition: ha_innodb.h:1140
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:12485
uint32_t flags() const
Get table flags.
Definition: ha_innodb.h:1067
bool skip_strict() const
whether to skip strict check.
Definition: ha_innodb.h:1079
void flags_reset()
Reset table flags.
Definition: ha_innodb.h:1073
THD * thd() const
Definition: ha_innodb.h:1084
const char * create_options_are_invalid()
Validates the create options.
Definition: ha_innodb.cc:12987
bool create_option_data_directory_is_valid(bool ignore=false)
Validate DATA DIRECTORY option.
Definition: ha_innodb.cc:12506
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:11638
Definition: table.h:47
The class defining a handle to an InnoDB table.
Definition: ha_innodb.h:94
THD * m_user_thd
Thread handle of the user currently using the handler; this is set in external_lock function.
Definition: ha_innodb.h:785
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:24322
int reset() override
MySQL calls this method at the end of each statement.
Definition: ha_innodb.cc:18811
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:11531
int ft_init() override
Initialize FT index scan.
Definition: ha_innodb.cc:11181
bool is_table_empty() const override
Check whether the table is empty.
Definition: handler0alter.cc:11319
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:1533
Table_flags table_flags() const override
Get the table flags to use for the statement.
Definition: ha_innodb.cc:6610
DsMrr_impl m_ds_mrr
The multi range read session object.
Definition: ha_innodb.h:778
int disable_indexes(uint mode) override
Disable indexes.
Definition: ha_innodb.cc:18397
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:10977
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:791
Item * idx_cond_push(uint keyno, Item *idx_cond) override
Attempt to push down an index condition.
Definition: ha_innodb.cc:24284
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:10819
uint m_last_match_mode
Definition: ha_innodb.h:805
int rnd_pos(uchar *buf, uchar *pos) override
Fetches a row from the table based on a row reference.
Definition: ha_innodb.cc:11150
int extra(ha_extra_function operation) override
Tells something additional to the handler about how to do things.
Definition: ha_innodb.cc:18681
void build_template(bool whole_row)
Builds a 'template' to the m_prebuilt struct.
Definition: ha_innodb.cc:8643
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:15403
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:24303
double scan_time() override
How many seeks it will take to read through the table.
Definition: ha_innodb.cc:17169
void innobase_initialize_autoinc()
Set the autoinc column max value.
Definition: ha_innodb.cc:7338
int discard_or_import_tablespace(bool discard, dd::Table *table_def) override
Discards or imports an InnoDB tablespace.
Definition: ha_innodb.cc:15436
handler * clone(const char *name, MEM_ROOT *mem_root) override
Definition: ha_innodb.cc:7927
int bulk_load_preserve_auto_increment(ulonglong auto_increment_value) override
Preserve the AUTO_INCREMENT value that was in effect before an empty-table bulk load recreated the ta...
Definition: handler0alter.cc:11727
void srv_concurrency_exit()
Leave Innodb, if no more tickets are left.
Definition: ha_innodb.cc:2968
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:23834
bool primary_key_is_clustered() const override
Determines if the primary key is clustered index.
Definition: ha_innodb.cc:6719
int intrinsic_table_write_row(uchar *record)
Write Row Interface optimized for Intrinsic table.
Definition: ha_innodb.cc:9035
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:18825
void info_low_table_stats(uint flag, const dict_table_t *ib_table, uint64_t &n_rows, ulint &stat_clustered_index_size, ulint &stat_sum_of_other_index_sizes) const
Get the table stats.
Definition: ha_innodb.cc:17815
void info_low_key(uint flag, const dict_table_t *ib_table)
Get number of records per key.
Definition: ha_innodb.cc:17726
ulong index_flags(uint idx, uint part, bool all_parts) const override
Returns the operations supported for indexes.
Definition: ha_innodb.cc:6649
int rnd_end() override
Ends a table scan.
Definition: ha_innodb.cc:11115
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:10034
int index_end() override
Currently does nothing.
Definition: ha_innodb.cc:10359
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:17002
virtual dict_index_t * innobase_get_index(uint keynr)
Get the index for a handle.
Definition: ha_innodb.cc:10674
std::string bulk_load_generate_temporary_table_name() const override
Generates a temporary table name to be used for table duplication during bulk load.
Definition: handler0alter.cc:11299
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_innodb.cc:7944
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:15090
int multi_range_read_next(char **range_info) override
Process next multi range read.
Definition: ha_innodb.cc:23819
row_prebuilt_t * m_prebuilt
Save CPU time with prebuilt/cached data structures.
Definition: ha_innodb.h:781
bool m_mysql_has_locked
If mysql has locked with external_lock()
Definition: ha_innodb.h:813
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:10914
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:11451
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:11121
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:5544
int enable_indexes(uint mode) override
Enable indexes.
Definition: ha_innodb.cc:18371
ha_innobase(handlerton *hton, TABLE_SHARE *table_arg)
Construct ha_innobase handler.
Definition: ha_innodb.cc:2974
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:3024
int rnd_init(bool scan) override
Initialize a table scan.
Definition: ha_innodb.cc:11094
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:10903
INNOBASE_SHARE * m_share
information for MySQL table locking
Definition: ha_innodb.h:788
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:1600
int bulk_load_end(THD *thd, void *load_ctx, bool is_error) override
End bulk load operation.
Definition: handler0alter.cc:11562
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:810
dberr_t innobase_set_max_autoinc(ulonglong auto_inc)
Store the autoinc value in the table.
Definition: ha_innodb.cc:9016
virtual bool can_reuse_mysql_template() const
Can reuse the template.
Definition: ha_innodb.h:775
void position(const uchar *record) override
Store a reference to the current row to 'ref' field of the handle.
Definition: ha_innodb.cc:11536
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:23811
void unlock_row() override
Removes a new lock set on a row, if it was not read optimistically.
Definition: ha_innodb.cc:10279
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:7542
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:801
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:16873
void position(uchar *record)
bool was_semi_consistent_read() override
Definition: ha_innodb.cc:10327
int close(void) override
Closes a handle to an InnoDB table.
Definition: ha_innodb.cc:7961
int srv_concurrency_enter()
Enter InnoDB engine after checking max allowed threads.
Definition: ha_innodb.cc:2961
int end_stmt()
MySQL calls this method at the end of each statement.
Definition: ha_innodb.cc:18769
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:15325
bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override
Check if SE supports specific key algorithm.
Definition: ha_innodb.h:108
ha_rows estimate_rows_upper_bound() override
Gives an UPPER BOUND to the number of rows in a table.
Definition: ha_innodb.cc:17122
void ft_end()
Definition: ha_innodb.cc:11521
bool get_error_message(int error, String *buf) override
See comment in handler.cc.
Definition: ha_innodb.cc:20140
int open(const char *name, int, uint open_flags, const dd::Table *table_def) override
Open an InnoDB table.
Definition: ha_innodb.cc:7459
uint max_supported_key_length() const override
Returns the maximum key length.
Definition: ha_innodb.cc:6693
longlong get_memory_buffer_size() const override
Return the size of the InnoDB memory buffer.
Definition: ha_innodb.cc:17233
int change_active_index(uint keynr)
Changes the active index of a handle.
Definition: ha_innodb.cc:10718
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:16911
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:19789
uint lock_count(void) const override
Returns number of THR_LOCK locks used for one instance of InnoDB table.
Definition: ha_innodb.cc:19773
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:20546
dberr_t innobase_get_autoinc(ulonglong *value)
Read the next autoinc value.
Definition: ha_innodb.cc:19963
void reset_template()
Resets a query execution 'template'.
Definition: ha_innodb.cc:3174
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:20001
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:11324
size_t m_upd_buf_size
the size of upd_buf in bytes
Definition: ha_innodb.h:794
int info(uint) override
Returns statistics information of the table to the MySQL interpreter, in various fields of the handle...
Definition: ha_innodb.cc:17832
int delete_table(const char *name, const dd::Table *table_def) override
Drop a table.
Definition: ha_innodb.cc:15636
FT_INFO * ft_init_ext(uint flags, uint inx, String *key) override
Initialize FT index scan.
Definition: ha_innodb.cc:11201
uint max_supported_keys() const override
Returns the maximum number of keys.
Definition: ha_innodb.cc:6688
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:18969
int cmp_ref(const uchar *ref1, const uchar *ref2) const override
Compares two 'refs'.
Definition: ha_innodb.cc:20208
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:11541
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:18425
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:10939
bool inplace_alter_table_impl(TABLE *altered_table, Alter_inplace_info *ha_alter_info)
Implementation of inplace_alter_table()
Definition: handler0alter.cc:6239
int ft_read(uchar *buf) override
Fetch next result from the FT result set.
Definition: ha_innodb.cc:11385
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:15308
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:3204
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:10960
int bulk_load_copy_existing_data(void *load_ctx, size_t thread_idx, Bulk_load::Stat_callbacks &wait_cbk) const override
Used during bulk load on a non-empty table, called after the CSV file input is exhausted and we need ...
Definition: handler0alter.cc:11280
int truncate_impl(const char *name, TABLE *form, dd::Table *table_def)
TRUNCATE an InnoDB table.
Definition: ha_innodb.cc:15562
int sample_end(void *scan_ctx) override
End sampling.
Definition: ha_innodb.cc:11074
int index_init(uint index, bool sorted) override
Initializes a handle to use an index.
Definition: ha_innodb.cc:10346
int read_range_next() override
Read next row between two endpoints.
Definition: ha_innodb.cc:11088
Table_flags m_int_table_flags
Flags that specify the handler instance (table) capability.
Definition: ha_innodb.h:797
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:11552
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:10661
void try_semi_consistent_read(bool yes) override
Tell the engine whether it should avoid unnecessary lock waits.
Definition: ha_innodb.cc:10333
dberr_t innobase_lock_autoinc()
This special handling is really to overcome the limitations of MySQL's binlogging.
Definition: ha_innodb.cc:8950
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:6560
FT_INFO * ft_init_ext_with_hints(uint inx, String *key, Ft_hints *hints) override
Initialize FT index scan.
Definition: ha_innodb.cc:11329
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:23823
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:10469
bool bulk_load_get_row_id_range(size_t &min, size_t &max) const override
Get the row ID range of the table that we're bulk loading into.
Definition: handler0alter.cc:11330
void parallel_scan_end(void *scan_ctx) override
End of the parallel scan.
Definition: handler0alter.cc:1623
void update_create_info(HA_CREATE_INFO *create_info) override
Update create_info.
Definition: ha_innodb.cc:13158
void release_auto_increment() override
Do cleanup for auto increment calculation.
Definition: ha_innodb.cc:19984
int check_foreign_constraints(THD *thd, size_t n_threads) const override
Check the table for any foreign key constraint violations.
Definition: ha0check.cc:107
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:10927
int write_row(uchar *buf) override
Stores a row in an InnoDB database, to the table specified in this handle.
Definition: ha_innodb.cc:9280
enum ha_key_alg get_default_index_algorithm() const override
Get default key algorithm for SE.
Definition: ha_innodb.h:103
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Tries to check that an InnoDB table is not corrupted.
Definition: ha_innodb.cc:18474
bool bulk_load_set_source_table_data(void *load_ctx, const std::vector< Bulk_load::Source_table_data > &source_table_data) const override
Sets the source table data (table name and key range boundaries) for all loaders.
Definition: handler0alter.cc:11312
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:11082
int delete_all_rows() override
Delete all rows from the table.
Definition: ha_innodb.cc:10260
bool bulk_load_check(THD *thd) const override
Check if the table is ready for bulk load.
Definition: handler0alter.cc:11249
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:11507
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:17515
int sample_next(void *scan_ctx, uchar *buf) override
Get the next record for sampling.
Definition: ha_innodb.cc:11057
const char * table_type() const override
Returns the table type (storage engine name).
Definition: ha_innodb.cc:6644
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:17203
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:18443
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:20164
~ha_innobase() override=default
int delete_row(const uchar *buf) override
Deletes a row given as the parameter.
Definition: ha_innodb.cc:10207
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4753
void * Blob_context
Definition: handler.h:4758
ulonglong Table_flags
Definition: handler.h:4757
Class of basic DDL implementation, for CREATE/DROP/RENAME TABLE.
Definition: ha_innodb.h:1184
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:14632
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:14405
static int delete_impl(THD *thd, const char *name, const Table *dd_tab, const TABLE *td)
Drop an InnoDB table.
Definition: ha_innodb.cc:14523
Class to handle TRUNCATE for one InnoDB table or one partition.
Definition: ha_innodb.h:1247
dict_table_t * m_table
InnoDB table object for the table/partition.
Definition: ha_innodb.h:1317
trx_t * m_trx
Transaction attached to current thd.
Definition: ha_innodb.h:1314
int open_table(dict_table_t *&innodb_table)
Open the table/partition to be truncated.
Definition: ha_innodb.cc:14763
bool m_keep_autoinc
True if the original autoinc counter should be kept.
Definition: ha_innodb.h:1331
Table * m_dd_table
dd::Table or dd::Partition
Definition: ha_innodb.h:1311
int truncate()
Do the real truncation.
Definition: ha_innodb.cc:14861
uint32_t m_flags2
flags2 of the table to be truncated, which should not change
Definition: ha_innodb.h:1341
TABLE * m_form
Table format.
Definition: ha_innodb.h:1320
HA_CREATE_INFO m_create_info
Create information.
Definition: ha_innodb.h:1323
int rename_tablespace()
Rename tablespace file name.
Definition: ha_innodb.cc:14956
bool m_file_per_table
True if this table/partition is file per table.
Definition: ha_innodb.h:1326
int load_fk()
Reload the FK related information.
Definition: ha_innodb.cc:15020
int prepare()
Prepare for truncate.
Definition: ha_innodb.cc:14794
int exec()
Do the truncate of the table/partition.
Definition: ha_innodb.cc:15051
innobase_truncate(THD *thd, const char *name, TABLE *form, Table *dd_table, bool keep_autoinc, bool table_truncate)
Constructor.
Definition: ha_innodb.h:1256
~innobase_truncate()
Destructor.
Definition: ha_innodb.cc:14752
uint32_t m_flags
flags of the table to be truncated, which should not change
Definition: ha_innodb.h:1338
void cleanup()
Cleanup.
Definition: ha_innodb.cc:15003
bool m_table_truncate
For a prtition table, this is true if full table is truncated.
Definition: ha_innodb.h:1335
THD * m_thd
THD object.
Definition: ha_innodb.h:1305
const char * m_name
Normalized table name.
Definition: ha_innodb.h:1308
A table definition from the master.
Definition: rpl_utility.h:251
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:270
constexpr uint32_t DICT_TF2_INTRINSIC
Intrinsic table bit Intrinsic table is table created internally by MySQL modules viz.
Definition: dict0mem.h:293
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:1665
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:1025
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:1629
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:1507
void my_error(int nr, myf MyFlags,...)
Fill in and print a previously registered error message.
Definition: my_error.cc:217
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:6908
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:11604
const struct _ft_vft ft_vft_result
Definition: ha_innodb.cc:626
static bool normalize_table_name(char *norm_name, const char *name)
Definition: ha_innodb.h:1416
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:900
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:17334
static bool is_shared_tablespace(const char *tablespace_name)
Check if tablespace is shared tablespace.
Definition: ha_innodb.h:925
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:715
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:2112
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:1053
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:7055
bool trx_is_registered_for_2pc(const trx_t *trx)
Note that a transaction has been registered with MySQL.
Definition: ha_innodb.h:1423
static int validate_autoextend_size_value(uint64_t ext_size)
Validate AUTOEXTEND_SIZE attribute for a tablespace.
Definition: ha_innodb.h:938
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:13746
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:889
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:11573
fts_doc_id_index_enum
Some defines for innobase_fts_check_doc_id_index() return value.
Definition: ha_innodb.h:1353
@ FTS_EXIST_DOC_ID_INDEX
Definition: ha_innodb.h:1355
@ FTS_INCORRECT_DOC_ID_INDEX
Definition: ha_innodb.h:1354
@ FTS_NOT_EXIST_DOC_ID_INDEX
Definition: ha_innodb.h:1356
trx_t * innobase_trx_allocate(THD *thd)
Allocates an InnoDB transaction for a MySQL handler object.
Definition: ha_innodb.cc:2787
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:7071
const mysql_service_clone_protocol_t * clone_protocol_svc
Clone protocol service.
Definition: ha_innodb.cc:289
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:911
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:2917
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:3037
static bool innobase_is_s_fld(const Field *field)
whether this is a stored column
Definition: ha_innodb.h:1403
static bool innobase_is_multi_value_fld(const Field *field)
Whether this is a computed multi-value virtual column.
Definition: ha_innodb.h:1412
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:2936
bool innobase_fts_load_stopword(dict_table_t *table, trx_t *trx, THD *thd)
Initialize the table FTS stopword list.
Definition: ha_innodb.cc:13188
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:1476
trx_t *& thd_to_trx(THD *thd)
Obtain the InnoDB transaction of a MySQL thread.
Definition: ha_innodb.cc:2045
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:10377
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:3003
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:18936
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:21815
constexpr uint32_t SIZE_MB
Definition: ha_innodb.h:933
bool innobase_stats_on_metadata
Definition: ha_innodb.cc:362
ulong thd_parallel_read_threads(THD *thd)
Return the number of read threads for this session.
Definition: ha_innodb.cc:2052
Atomic_sysvar< ulong > innodb_autoinc_preallocate
A sysvar which controls how much can we round up the autoinc value when persisting it to DDTableBuffe...
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:1229
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:195
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:44
bool is_partition(const std::string &dict_name)
Check if it is a table partition.
Definition: dict0dd.cc:7311
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Definition: aligned_atomic.h:44
entry::Table Table
Definition: select.h:51
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
ValueType max(X &&first)
Definition: gtid.h:103
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:207
enum_tx_isolation
Definition: handler.h:3340
row_type
Definition: handler.h:692
enum_sampling_method
Definition: handler.h:723
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:933
Definition: ft_global.h:72
Definition: handler.h:3979
Definition: handler.h:3966
Struct to hold information about the table that should be created.
Definition: handler.h:3356
const char * tablespace
Definition: handler.h:3362
InnoDB table share.
Definition: ha_innodb.h:72
const char * table_name
InnoDB table name.
Definition: ha_innodb.h:73
innodb_idx_translate_t idx_trans_tbl
index translation table between MySQL and InnoDB
Definition: ha_innodb.h:80
void * table_name_hash
hash table chain node
Definition: ha_innodb.h:78
uint use_count
reference count, incremented in get_share() and decremented in free_share()
Definition: ha_innodb.h:74
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: handler.h:3987
This structure is shared between different table objects.
Definition: table.h:731
Definition: table.h:1456
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:831
Data structure for an index.
Definition: dict0mem.h:1069
Data structure for a stored column in a table.
Definition: dict0mem.h:843
static const char * s_file_per_table_name
The hard-coded tablespace name innodb_file_per_table.
Definition: dict0dict.h:1171
static const char * s_sys_space_name
The name of the hard-coded system tablespace.
Definition: dict0dict.h:1162
static const char * s_temp_space_name
The name of the predefined temporary tablespace.
Definition: dict0dict.h:1165
Data structure for a database table.
Definition: dict0mem.h:1927
Data structure for a virtual column in a table.
Definition: dict0mem.h:811
Structure defines template related to virtual columns and their base columns.
Definition: dict0mem.h:1864
Query result.
Definition: fts0fts.h:315
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2852
Definition: ha_innodb.h:60
dict_index_t ** index_mapping
index pointer array directly maps to index in InnoDB from MySQL array index
Definition: ha_innodb.h:66
ulint array_size
array size of index_mapping
Definition: ha_innodb.h:64
ulint index_count
number of valid index entries in the index_mapping array
Definition: ha_innodb.h:61
Definition: my_base.h:1213
Structure Returned by ha_innobase::ft_init_ext()
Definition: ha_innodb.h:841
struct _ft_vft_ext * could_you
Definition: ha_innodb.h:843
row_prebuilt_t * ft_prebuilt
Definition: ha_innodb.h:844
fts_result_t * ft_result
Definition: ha_innodb.h:845
struct _ft_vft * please
Definition: ha_innodb.h:842
A struct for (sometimes lazily) prebuilt structures in an Innobase table handle used within MySQL; th...
Definition: row0mysql.h:515
Definition: trx0trx.h:670
bool is_registered
Definition: trx0trx.h:864
isolation_level_t
Definition: trx0trx.h:671
static PFS_engine_table_share_proxy table_share
Definition: table_disk_forecast.cc:33
thr_lock_type
Definition: thr_lock.h:51
The transaction.
ulong srv_page_size
Definition: srv0srv.cc:389
unsigned long int ulint
Definition: univ.i:403
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109