MySQL  8.0.20
Source Code Documentation
ha_innodb.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2000, 2019, 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  virtual bool get_error_message(int error, String *buf) override;
333 
334  virtual bool get_foreign_dup_key(char *, uint, char *, uint) override;
335 
336  bool primary_key_is_clustered() const override;
337 
338  int cmp_ref(const uchar *ref1, const uchar *ref2) const override;
339 
340  /** On-line ALTER TABLE interface @see handler0alter.cc @{ */
341 
342  /** Check if InnoDB supports a particular alter table in-place
343  @param altered_table TABLE object for new version of table.
344  @param ha_alter_info Structure describing changes to be done
345  by ALTER TABLE and holding data used during in-place alter.
346 
347  @retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported
348  @retval HA_ALTER_INPLACE_NO_LOCK Supported
349  @retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE
350  Supported, but requires lock during main phase and
351  exclusive lock during prepare phase.
352  @retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE
353  Supported, prepare phase requires exclusive lock. */
354  enum_alter_inplace_result check_if_supported_inplace_alter(
355  TABLE *altered_table, Alter_inplace_info *ha_alter_info) override;
356 
357  /** Allows InnoDB to update internal structures with concurrent
358  writes blocked (provided that check_if_supported_inplace_alter()
359  did not return HA_ALTER_INPLACE_NO_LOCK).
360  This will be invoked before inplace_alter_table().
361 
362  @param[in] altered_table TABLE object for new version of table.
363  @param[in,out] ha_alter_info Structure describing changes to be done
364  by ALTER TABLE and holding data used during in-place alter.
365  @param[in] old_dd_tab dd::Table object describing old version
366  of the table.
367  @param[in,out] new_dd_tab dd::Table object for the new version of
368  the table. Can be adjusted by this call. Changes to the table definition will
369  be persisted in the data-dictionary at statement commit time.
370 
371  @retval true Failure
372  @retval false Success
373  */
374  bool prepare_inplace_alter_table(TABLE *altered_table,
375  Alter_inplace_info *ha_alter_info,
376  const dd::Table *old_dd_tab,
377  dd::Table *new_dd_tab) override;
378 
379  /** Alter the table structure in-place with operations
380  specified using HA_ALTER_FLAGS and Alter_inplace_information.
381  The level of concurrency allowed during this operation depends
382  on the return value from check_if_supported_inplace_alter().
383 
384  @param[in] altered_table TABLE object for new version of table.
385  @param[in,out] ha_alter_info Structure describing changes to be done
386  by ALTER TABLE and holding data used during in-place alter.
387  @param[in] old_dd_tab dd::Table object describing old version
388  of the table.
389  @param[in,out] new_dd_tab dd::Table object for the new version of
390  the table. Can be adjusted by this call. Changes to the table definition will
391  be persisted in the data-dictionary at statement commit time.
392 
393  @retval true Failure
394  @retval false Success
395  */
396  bool inplace_alter_table(TABLE *altered_table,
397  Alter_inplace_info *ha_alter_info,
398  const dd::Table *old_dd_tab,
399  dd::Table *new_dd_tab) override;
400 
401  /** Commit or rollback the changes made during
402  prepare_inplace_alter_table() and inplace_alter_table() inside
403  the storage engine. Note that the allowed level of concurrency
404  during this operation will be the same as for
405  inplace_alter_table() and thus might be higher than during
406  prepare_inplace_alter_table(). (E.g concurrent writes were
407  blocked during prepare, but might not be during commit).
408 
409  @param[in] altered_table TABLE object for new version of table.
410  @param[in,out] ha_alter_info Structure describing changes to be done
411  by ALTER TABLE and holding data used during in-place alter.
412  @param commit true => Commit, false => Rollback.
413  @param old_dd_tab dd::Table object describing old version
414  of the table.
415  @param new_dd_tab dd::Table object for the new version of the
416  table. Can be adjusted by this call. Changes to the table
417  definition will be persisted in the data-dictionary at statement
418  commit time.
419  @retval true Failure
420  @retval false Success
421  */
422  bool commit_inplace_alter_table(TABLE *altered_table,
423  Alter_inplace_info *ha_alter_info,
424  bool commit, const dd::Table *old_dd_tab,
425  dd::Table *new_dd_tab) override;
426  /** @} */
427 
429 
430  /** Initializes a parallel scan. It creates a scan_ctx that has to
431  be used across all parallel_scan methods. Also, gets the number of threads
432  that would be spawned for parallel scan.
433  @param[out] scan_ctx A scan context created by this method
434  that has to be used in
435  parallel_scan
436  @param[out] num_threads Number of threads to be spawned
437  @return error code
438  @retval 0 on success */
439  int parallel_scan_init(void *&scan_ctx, size_t &num_threads) override;
440 
441  /** Start parallel read of InnoDB records.
442  @param[in] scan_ctx A scan context created by parallel_scan_init
443  @param[in] thread_ctxs Context for each of the spawned threads
444  @param[in] init_fn Callback called by each parallel load
445  thread at the beginning of the parallel load.
446  @param[in] load_fn Callback called by each parallel load
447  thread when processing of rows is required.
448  @param[in] end_fn Callback called by each parallel load
449  thread when processing of rows has ended.
450  @return error code
451  @retval 0 on success */
452  int parallel_scan(void *scan_ctx, void **thread_ctxs, Reader::Init_fn init_fn,
453  Reader::Load_fn load_fn, Reader::End_fn end_fn) override;
454 
455  /** End of the parallel scan.
456  @param[in] scan_ctx A scan context created by parallel_scan_init. */
457  void parallel_scan_end(void *scan_ctx) override;
458 
459  bool check_if_incompatible_data(HA_CREATE_INFO *info,
460  uint table_changes) override;
461 
462  private:
463  /** @name Multi Range Read interface @{ */
464 
465  /** Initialize multi range read @see DsMrr_impl::dsmrr_init
466  @param seq
467  @param seq_init_param
468  @param n_ranges
469  @param mode
470  @param buf */
471  int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
472  uint n_ranges, uint mode,
473  HANDLER_BUFFER *buf) override;
474 
475  /** Process next multi range read @see DsMrr_impl::dsmrr_next
476  @param range_info */
477  int multi_range_read_next(char **range_info) override;
478 
479  /** Initialize multi range read and get information.
480  @see ha_myisam::multi_range_read_info_const
481  @see DsMrr_impl::dsmrr_info_const
482  @param keyno
483  @param seq
484  @param seq_init_param
485  @param n_ranges
486  @param bufsz
487  @param flags
488  @param cost */
489  ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
490  void *seq_init_param, uint n_ranges,
491  uint *bufsz, uint *flags,
492  Cost_estimate *cost) override;
493 
494  /** Initialize multi range read and get information.
495  @see DsMrr_impl::dsmrr_info
496  @param keyno
497  @param n_ranges
498  @param keys
499  @param bufsz
500  @param flags
501  @param cost */
502  ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
503  uint *bufsz, uint *flags,
504  Cost_estimate *cost) override;
505 
506  /** Attempt to push down an index condition.
507  @param[in] keyno MySQL key number
508  @param[in] idx_cond Index condition to be checked
509  @return idx_cond if pushed; NULL if not pushed */
510  Item *idx_cond_push(uint keyno, Item *idx_cond) override;
511  /* @} */
512 
513  private:
514  void update_thd();
515 
516  int change_active_index(uint keynr);
517 
518  dberr_t innobase_lock_autoinc();
519 
520  dberr_t innobase_set_max_autoinc(ulonglong auto_inc);
521 
522  dberr_t innobase_get_autoinc(ulonglong *value);
523 
524  void innobase_initialize_autoinc();
525 
526  /** Resets a query execution 'template'.
527  @see build_template() */
528  void reset_template();
529 
530  /** Write Row Interface optimized for Intrinsic table. */
531  int intrinsic_table_write_row(uchar *record);
532 
533  /** Find out if a Record_buffer is wanted by this handler, and what is
534  the maximum buffer size the handler wants.
535 
536  @param[out] max_rows gets set to the maximum number of records to
537  allocate space for in the buffer
538  @retval true if the handler wants a buffer
539  @retval false if the handler does not want a buffer */
540  bool is_record_buffer_wanted(ha_rows *const max_rows) const override;
541 
542  /** TRUNCATE an InnoDB table.
543  @param[in] name table name
544  @param[in] form table definition
545  @param[in,out] table_def dd::Table describing table to be
546  truncated. Can be adjusted by SE, the changes will be saved into
547  the data-dictionary at statement commit time.
548  @return error number
549  @retval 0 on success */
550  int truncate_impl(const char *name, TABLE *form, dd::Table *table_def);
551 
552  protected:
553  /** Enter InnoDB engine after checking max allowed threads */
554  void srv_concurrency_enter();
555 
556  /** Leave Innodb, if no more tickets are left */
557  void srv_concurrency_exit();
558 
559  void update_thd(THD *thd);
560 
561  int general_fetch(uchar *buf, uint direction, uint match_mode);
562 
563  virtual dict_index_t *innobase_get_index(uint keynr);
564 
565  /** Builds a 'template' to the prebuilt struct.
566 
567  The template is used in fast retrieval of just those column
568  values MySQL needs in its processing.
569  @param whole_row true if access is needed to a whole row,
570  false if accessing individual fields is enough */
571  void build_template(bool whole_row);
572 
573  /** Returns statistics information of the table to the MySQL
574  interpreter, in various fields of the handle object.
575  @param[in] flag what information is requested
576  @param[in] is_analyze True if called from "::analyze()"
577  @return HA_ERR_* error code or 0 */
578  virtual int info_low(uint flag, bool is_analyze);
579 
580  /**
581  MySQL calls this method at the end of each statement. This method
582  exists for readability only, called from reset(). The name reset()
583  doesn't give any clue that it is called at the end of a statement. */
584  int end_stmt();
585 
586  /** Implementation of prepare_inplace_alter_table()
587  @tparam Table dd::Table or dd::Partition
588  @param[in] altered_table TABLE object for new version of table.
589  @param[in,out] ha_alter_info Structure describing changes to be done
590  by ALTER TABLE and holding data used
591  during in-place alter.
592  @param[in] old_dd_tab dd::Table object representing old
593  version of the table
594  @param[in,out] new_dd_tab dd::Table object representing new
595  version of the table
596  @retval true Failure
597  @retval false Success */
598  template <typename Table>
599  bool prepare_inplace_alter_table_impl(TABLE *altered_table,
600  Alter_inplace_info *ha_alter_info,
601  const Table *old_dd_tab,
602  Table *new_dd_tab);
603 
604  /** Implementation of inplace_alter_table()
605  @tparam Table dd::Table or dd::Partition
606  @param[in] altered_table TABLE object for new version of table.
607  @param[in,out] ha_alter_info Structure describing changes to be done
608  by ALTER TABLE and holding data used
609  during in-place alter.
610  @param[in] old_dd_tab dd::Table object representing old
611  version of the table
612  @param[in,out] new_dd_tab dd::Table object representing new
613  version of the table
614  @retval true Failure
615  @retval false Success */
616  template <typename Table>
617  bool inplace_alter_table_impl(TABLE *altered_table,
618  Alter_inplace_info *ha_alter_info,
619  const Table *old_dd_tab, Table *new_dd_tab);
620 
621  /** Implementation of commit_inplace_alter_table()
622  @tparam Table dd::Table or dd::Partition
623  @param[in] altered_table TABLE object for new version of table.
624  @param[in,out] ha_alter_info Structure describing changes to be done
625  by ALTER TABLE and holding data used
626  during in-place alter.
627  @param[in] commit True to commit or false to rollback.
628  @param[in] old_dd_tab Table object describing old version
629  of the table.
630  @param[in,out] new_dd_tab Table object for the new version of the
631  table. Can be adjusted by this call.
632  Changes to the table definition
633  will be persisted in the data-dictionary
634  at statement version of it.
635  @retval true Failure
636  @retval false Success */
637  template <typename Table>
638  bool commit_inplace_alter_table_impl(TABLE *altered_table,
639  Alter_inplace_info *ha_alter_info,
640  bool commit, const Table *old_dd_tab,
641  Table *new_dd_tab);
642 
643  /**
644  Return max limits for a single set of multi-valued keys
645 
646  @param[out] num_keys number of keys to store
647  @param[out] keys_length total length of keys, bytes
648  */
649  void mv_key_capacity(uint *num_keys, size_t *keys_length) const override;
650 
651  /** The multi range read session object */
653 
654  /** Save CPU time with prebuilt/cached data structures */
656 
657  /** Thread handle of the user currently using the handler;
658  this is set in external_lock function */
660 
661  /** information for MySQL table locking */
663 
664  /** buffer used in updates */
666 
667  /** the size of upd_buf in bytes */
669 
670  /** Flags that specificy the handler instance (table) capability. */
671  Table_flags m_int_table_flags;
672 
673  /** this is set to 1 when we are starting a table scan but have
674  not yet fetched any row, else false */
676 
677  /*!< match mode of the latest search: ROW_SEL_EXACT,
678  ROW_SEL_EXACT_PREFIX, or undefined */
679  uint m_last_match_mode{0};
680 
681  /** this field is used to remember the original select_lock_type that
682  was decided in ha_innodb.cc,":: store_lock()", "::external_lock()",
683  etc. */
685 
686  /** If mysql has locked with external_lock() */
688 };
689 
690 struct trx_t;
691 
692 extern const struct _ft_vft ft_vft_result;
693 
694 /** Return the number of read threads for this session.
695 @param[in] thd Session instance, or nullptr to query the global
696  innodb_parallel_read_threads value. */
697 ulong thd_parallel_read_threads(THD *thd);
698 
699 /** Structure Returned by ha_innobase::ft_init_ext() */
700 typedef struct new_ft_info {
701  struct _ft_vft *please;
705 } NEW_FT_INFO;
706 
707 /** Allocates an InnoDB transaction for a MySQL handler object for DML.
708 @param[in] hton Innobase handlerton.
709 @param[in] thd MySQL thd (connection) object.
710 @param[in] trx transaction to register. */
711 void innobase_register_trx(handlerton *hton, THD *thd, trx_t *trx);
712 
713 /**
714 Allocates an InnoDB transaction for a MySQL handler object.
715 @return InnoDB transaction handle */
716 trx_t *innobase_trx_allocate(THD *thd); /*!< in: user thread handle */
717 
718 /** Match index columns between MySQL and InnoDB.
719 This function checks whether the index column information
720 is consistent between KEY info from mysql and that from innodb index.
721 @param[in] key_info Index info from mysql
722 @param[in] index_info Index info from InnoDB
723 @return true if all column types match. */
724 bool innobase_match_index_columns(const KEY *key_info,
725  const dict_index_t *index_info);
726 
727 /** This function checks each index name for a table against reserved
728  system default primary index name 'GEN_CLUST_INDEX'. If a name
729  matches, this function pushes an warning message to the client,
730  and returns true.
731  @return true if the index name matches the reserved name */
733  THD *thd, /*!< in/out: MySQL connection */
734  const KEY *key_info, /*!< in: Indexes to be
735  created */
736  ulint num_of_keys) /*!< in: Number of indexes to
737  be created. */
738  MY_ATTRIBUTE((warn_unused_result));
739 
740 /** Check if the explicit tablespace targeted is file_per_table.
741 @param[in] create_info Metadata for the table to create.
742 @return true if the table is intended to use a file_per_table tablespace. */
743 UNIV_INLINE
745  return (create_info->tablespace != nullptr &&
746  (0 ==
747  strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)));
748 }
749 
750 /** Check if table will be explicitly put in an existing shared general
751 or system tablespace.
752 @param[in] create_info Metadata for the table to create.
753 @return true if the table will use a shared general or system tablespace. */
754 UNIV_INLINE
755 bool tablespace_is_shared_space(const HA_CREATE_INFO *create_info) {
756  return (create_info->tablespace != nullptr &&
757  create_info->tablespace[0] != '\0' &&
758  (0 !=
759  strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)));
760 }
761 
762 /** Check if table will be explicitly put in a general tablespace.
763 @param[in] create_info Metadata for the table to create.
764 @return true if the table will use a general tablespace. */
765 UNIV_INLINE
766 bool tablespace_is_general_space(const HA_CREATE_INFO *create_info) {
767  return (
768  create_info->tablespace != nullptr &&
769  create_info->tablespace[0] != '\0' &&
770  (0 !=
771  strcmp(create_info->tablespace, dict_sys_t::s_file_per_table_name)) &&
772  (0 != strcmp(create_info->tablespace, dict_sys_t::s_temp_space_name)) &&
773  (0 != strcmp(create_info->tablespace, dict_sys_t::s_sys_space_name)));
774 }
775 
776 /** Check if tablespace is shared tablespace.
777 @param[in] tablespace_name Name of the tablespace
778 @return true if tablespace is a shared tablespace. */
779 UNIV_INLINE
780 bool is_shared_tablespace(const char *tablespace_name) {
781  if (tablespace_name != nullptr && tablespace_name[0] != '\0' &&
782  (strcmp(tablespace_name, dict_sys_t::s_file_per_table_name) != 0)) {
783  return true;
784  }
785  return false;
786 }
787 
788 /** Parse hint for table and its indexes, and update the information
789 in dictionary.
790 @param[in] thd Connection thread
791 @param[in,out] table Target table
792 @param[in] table_share Table definition */
794  const TABLE_SHARE *table_share);
795 
796 /** Obtain the InnoDB transaction of a MySQL thread.
797 @param[in,out] thd MySQL thread handler.
798 @return reference to transaction pointer */
799 trx_t *&thd_to_trx(THD *thd);
800 
801 /** Class for handling create table information. */
803  public:
804  /** Constructor.
805  Used in two ways:
806  - all but file_per_table is used, when creating the table.
807  - all but name/path is used, when validating options and using flags. */
808  create_table_info_t(THD *thd, TABLE *form, HA_CREATE_INFO *create_info,
809  char *table_name, char *remote_path, char *tablespace,
810  bool file_per_table, bool skip_strict, uint32_t old_flags,
811  uint32_t old_flags2)
812  : m_thd(thd),
813  m_trx(thd_to_trx(thd)),
814  m_form(form),
815  m_create_info(create_info),
816  m_table_name(table_name),
817  m_remote_path(remote_path),
818  m_tablespace(tablespace),
819  m_innodb_file_per_table(file_per_table),
820  m_flags(old_flags),
821  m_flags2(old_flags2),
822  m_skip_strict(skip_strict) {}
823 
824  /** Initialize the object. */
825  int initialize();
826 
827  /** Set m_tablespace_type. */
828  void set_tablespace_type(bool table_being_altered_is_file_per_table);
829 
830  /** Create the internal innodb table.
831  @param[in] dd_table dd::Table or nullptr for intrinsic table
832  @return 0 or error number */
833  int create_table(const dd::Table *dd_table);
834 
835  /** Update the internal data dictionary. */
836  int create_table_update_dict();
837 
838  /** Update the global data dictionary.
839  @param[in] dd_table table object
840  @return 0 On success
841  @retval error number On failure*/
842  template <typename Table>
843  int create_table_update_global_dd(Table *dd_table);
844 
845  /** Validates the create options. Checks that the options
846  KEY_BLOCK_SIZE, ROW_FORMAT, DATA DIRECTORY, TEMPORARY & TABLESPACE
847  are compatible with each other and other settings.
848  These CREATE OPTIONS are not validated here unless innodb_strict_mode
849  is on. With strict mode, this function will report each problem it
850  finds using a custom message with error code
851  ER_ILLEGAL_HA_CREATE_OPTION, not its built-in message.
852  @return NULL if valid, string name of bad option if not. */
853  const char *create_options_are_invalid();
854 
855  /** Validate DATA DIRECTORY option. */
856  bool create_option_data_directory_is_valid();
857  /** Validate TABLESPACE option. */
858  bool create_option_tablespace_is_valid();
859 
860  /** Validate COMPRESSION option. */
861  bool create_option_compression_is_valid();
862 
863  /** Prepare to create a table. */
864  int prepare_create_table(const char *name);
865 
866  /** Determines InnoDB table flags.
867  If strict_mode=OFF, this will adjust the flags to what should be assumed.
868  @retval true if successful, false if error */
869  bool innobase_table_flags();
870 
871  /** Set flags and append '/' to remote path if necessary. */
872  void set_remote_path_flags();
873 
874  /** Get table flags. */
875  uint32_t flags() const { return (m_flags); }
876 
877  /** Get table flags2. */
878  uint32_t flags2() const { return (m_flags2); }
879 
880  /** Reset table flags. */
881  void flags_reset() { m_flags = 0; }
882 
883  /** Reset table flags2. */
884  void flags2_reset() { m_flags2 = 0; }
885 
886  /** whether to skip strict check. */
887  bool skip_strict() const { return (m_skip_strict); }
888 
889  /** Return table name. */
890  const char *table_name() const { return (m_table_name); }
891 
892  THD *thd() const { return (m_thd); }
893 
894  inline bool is_intrinsic_temp_table() const {
895  /* DICT_TF2_INTRINSIC implies DICT_TF2_TEMPORARY */
896  ut_ad(!(m_flags2 & DICT_TF2_INTRINSIC) || (m_flags2 & DICT_TF2_TEMPORARY));
897  return ((m_flags2 & DICT_TF2_INTRINSIC) != 0);
898  }
899 
900  /** @return true only if table is temporary and not intrinsic */
901  inline bool is_temp_table() const {
902  return (((m_flags2 & DICT_TF2_TEMPORARY) != 0) &&
903  ((m_flags2 & DICT_TF2_INTRINSIC) == 0));
904  }
905 
906  /** Detach the just created table and its auxiliary tables if exist. */
907  void detach();
908 
909  /** Normalizes a table name string.
910  A normalized name consists of the database name catenated to '/' and
911  table name. An example: test/mytable. On case insensitive file system
912  normalization converts name to lower case.
913  @param[in,out] norm_name Buffer to return the normalized name in.
914  @param[in] name Table name string.
915  @return true if successful. */
916  static bool normalize_table_name(char *norm_name, const char *name);
917 
918  private:
919  /** Parses the table name into normal name and either temp path or
920  remote path if needed.*/
921  int parse_table_name(const char *name);
922 
923  /** Create the internal innodb table definition.
924  @param[in] dd_table dd::Table or nullptr for intrinsic table
925  @return ER_* level error */
926  int create_table_def(const dd::Table *dd_table);
927 
928  /** Initialize the autoinc of this table if necessary, which should
929  be called before we flush logs, so autoinc counter can be persisted. */
930  void initialize_autoinc();
931 
932  /** Connection thread handle. */
934 
935  /** InnoDB transaction handle. */
937 
938  /** Information on table columns and indexes. */
939  const TABLE *m_form;
940 
941  /** Create options. */
943 
944  /** Table name */
946  /** Remote path (DATA DIRECTORY) or zero length-string */
948  /** Tablespace name or zero length-string. */
950 
951  /** The newly created InnoDB table object. This is currently only
952  used in this class, since the new table is not evictable until
953  final success/failure, it can be accessed directly. */
955 
956  /** Local copy of srv_file_per_table. */
958 
959  /** Allow file_per_table for this table either because:
960  1) the setting innodb_file_per_table=on,
961  2) it was explicitly requested by tablespace=innodb_file_per_table.
962  3) the table being altered is currently file_per_table */
964 
965  /** After all considerations, this shows whether we will actually
966  create a table and tablespace using file-per-table. */
968 
969  /** Using DATA DIRECTORY */
971 
972  /** Using a Shared General Tablespace */
974 
975  /** Table flags */
976  uint32_t m_flags;
977 
978  /** Table flags2 */
979  uint32_t m_flags2;
980 
981  /** Skip strict check */
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:3538
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:973
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:967
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:659
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:3191
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:2718
bool m_use_data_dir
Using DATA DIRECTORY.
Definition: ha_innodb.h:970
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:668
This structure is shared between different table objects.
Definition: table.h:654
Class for handling create table information.
Definition: ha_innodb.h:802
trx_t * innobase_trx_allocate(THD *thd)
Allocates an InnoDB transaction for a MySQL handler object.
Definition: ha_innodb.cc:2492
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:6087
Definition: trx0trx.h:800
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:12064
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:662
bool skip_strict() const
whether to skip strict check.
Definition: ha_innodb.h:887
Definition: field.h:694
THD * m_thd
Connection thread handle.
Definition: ha_innodb.h:933
const TABLE * m_form
Information on table columns and indexes.
Definition: ha_innodb.h:939
enum_sql_command
Definition: my_sqlcommand.h:45
Definition: handler.h:3204
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:675
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:10688
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:1828
Data structure for a database table.
Definition: dict0mem.h:1520
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:684
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:662
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
dberr_t open(bool create_new_db) noexcept
Startup the background thread(s) and create the instance.
Definition: buf0dblwr.cc:1712
Definition: my_base.h:107
const char * table_name() const
Return table name.
Definition: ha_innodb.h:890
ha_rkey_function
Definition: my_base.h:77
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3986
Table_flags m_int_table_flags
Flags that specificy the handler instance (table) capability.
Definition: ha_innodb.h:671
#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:15637
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:49
char * m_tablespace
Tablespace name or zero length-string.
Definition: ha_innodb.h:949
struct _ft_vft_ext * could_you
Definition: ha_innodb.h:702
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:2202
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Definition: app_data.c:426
Definition: table.h:1306
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:655
Table * m_dd_table
dd::Table or dd::Partition
Definition: ha_innodb.h:1102
struct _ft_vft * please
Definition: ha_innodb.h:701
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:6232
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:963
fts_result_t * ft_result
Definition: ha_innodb.h:704
handler::Load_cbk Load_fn
Definition: row0pread-adapter.h:47
uint32_t flags2() const
Get table flags2.
Definition: ha_innodb.h:878
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:2627
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:884
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:780
THD * thd() const
Definition: ha_innodb.h:892
bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
Open a base table.
Definition: sql_base.cc:2763
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:871
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:881
static void prepare(pax_msg *p, pax_op op)
Definition: xcom_base.c:1383
void * table_name_hash
hash table chain node
Definition: ha_innodb.h:63
#define rnd_init(X)
Definition: mi_test3.cc:40
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:894
page_cur_mode_t
Definition: page0types.h:173
dict_table_t * m_table
The newly created InnoDB table object.
Definition: ha_innodb.h:954
dberr_t create() noexcept
Create the dblwr data structures in the system tablespace.
Definition: buf0dblwr.cc:1823
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:10657
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:755
HA_CREATE_INFO * m_create_info
Create options.
Definition: ha_innodb.h:942
static uint keys
Definition: hp_test2.cc:45
uint32_t m_flags2
Table flags2.
Definition: ha_innodb.h:979
Definition: item.h:740
unsigned int uint
Definition: uca-dump.cc:29
handler::Load_init_cbk Init_fn
Definition: row0pread-adapter.h:51
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
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:947
Definition: my_base.h:106
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)
Constructor.
Definition: ha_innodb.h:808
bool is_temp_table() const
Definition: ha_innodb.h:901
Definition: handler.h:6565
Class describing changes to be done by ALTER TABLE.
Definition: handler.h:2758
bool m_skip_strict
Skip strict check.
Definition: ha_innodb.h:982
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:744
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2269
#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:6248
Definition: my_base.h:109
bool m_innodb_file_per_table
Local copy of srv_file_per_table.
Definition: ha_innodb.h:957
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:2541
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:1116
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:16058
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:1462
qep_row::extra extra
Definition: opt_explain.cc:106
#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:3212
ulong thd_parallel_read_threads(THD *thd)
Return the number of read threads for this session.
Definition: ha_innodb.cc:1772
DsMrr_impl m_ds_mrr
The multi range read session object.
Definition: ha_innodb.h:652
static int flag
Definition: hp_test1.cc:39
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:766
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:936
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:20332
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:642
Data structure for a stored column in a table.
Definition: dict0mem.h:674
const char * tablespace
Definition: handler.h:2630
Definition: handler.h:2625
uchar * m_upd_buf
buffer used in updates
Definition: ha_innodb.h:665
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:9503
enum_sampling_method
Definition: handler.h:696
The transaction.
char * m_table_name
Table name.
Definition: ha_innodb.h:945
Definition: test_sql_stmt.cc:150
const string value("\alue\)
Definition: ft_global.h:71
row_prebuilt_t * ft_prebuilt
Definition: ha_innodb.h:703
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:978
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:2616
uint32_t flags() const
Get table flags.
Definition: ha_innodb.h:875
static int yes(xcom_port port)
Definition: xcom_base.c:979
Definition: table.h:45
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:3278
#define DICT_TF2_TEMPORARY
TEMPORARY; TRUE for tables from CREATE TEMPORARY TABLE.
Definition: dict0mem.h:256
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:12623
#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:1762
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:700
my_off_t ha_rows
Definition: my_base.h:1132
uint32_t m_flags
Table flags.
Definition: ha_innodb.h:976
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:765
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
const char * table_name
Definition: rules_table_service.cc:55
Data structure for an index.
Definition: dict0mem.h:879
bool m_mysql_has_locked
If mysql has locked with external_lock()
Definition: ha_innodb.h:687