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