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