MySQL  8.0.27
Source Code Documentation
ha_myisam.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2000, 2021, Oracle and/or its affiliates.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation. The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 
24 /**
25  @file storage/myisam/ha_myisam.h
26  MyISAM storage engine.
27 */
28 
29 #include <stddef.h>
30 #include <sys/types.h>
31 
32 #include "ft_global.h"
33 #include "my_icp.h"
34 #include "my_inttypes.h"
35 #include "myisam.h"
36 #include "sql/handler.h" /* handler */
37 #include "sql/table.h" /* TABLE_SHARE */
38 #include "sql_string.h"
39 #include "typelib.h"
40 
41 struct TABLE_SHARE;
42 struct HA_CREATE_INFO;
43 
44 #define HA_RECOVER_DEFAULT 1 /* Automatic recover active */
45 #define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */
46 #define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */
47 #define HA_RECOVER_QUICK 8 /* Don't check rows in data file */
48 #define HA_RECOVER_OFF 16 /* No automatic recover */
49 
51 extern const char *myisam_recover_names[];
53 extern const char *myisam_stats_method_names[];
54 
55 int table2myisam(TABLE *table_arg, MI_KEYDEF **keydef_out,
56  MI_COLUMNDEF **recinfo_out, uint *records_out);
57 int check_definition(MI_KEYDEF *t1_keyinfo, MI_COLUMNDEF *t1_recinfo,
58  uint t1_keys, uint t1_recs, MI_KEYDEF *t2_keyinfo,
59  MI_COLUMNDEF *t2_recinfo, uint t2_keys, uint t2_recs,
60  bool strict);
61 
63 
65  public:
67  ~Myisam_handler_share() override = default;
69 };
70 
71 class ha_myisam : public handler {
76  int repair(THD *thd, MI_CHECK &param, bool optimize);
77 
78  public:
79  ha_myisam(handlerton *hton, TABLE_SHARE *table_arg);
80  ~ha_myisam() override = default;
81  handler *clone(const char *name, MEM_ROOT *mem_root) override;
82  const char *table_type() const override { return "MyISAM"; }
83  enum ha_key_alg get_default_index_algorithm() const override {
84  return HA_KEY_ALG_BTREE;
85  }
86  bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override {
87  return key_alg == HA_KEY_ALG_BTREE || key_alg == HA_KEY_ALG_RTREE;
88  }
89  ulonglong table_flags() const override { return int_table_flags; }
90  int index_init(uint idx, bool sorted) override;
91  int index_end() override;
92  int rnd_end() override;
93 
94  ulong index_flags(uint inx, uint, bool) const override {
95  if (table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) return 0;
96 
99 
100  // @todo: Check if spatial indexes really have all these properties
101  if (table_share->key_info[inx].flags & HA_SPATIAL)
103 
104  return flags;
105  }
106  uint max_supported_keys() const override { return MI_MAX_KEY; }
107  uint max_supported_key_length() const override { return MI_MAX_KEY_LENGTH; }
109  [[maybe_unused]]) const override {
110  return MI_MAX_KEY_LENGTH;
111  }
112  uint checksum() const override;
113 
114  int open(const char *name, int mode, uint test_if_locked,
115  const dd::Table *table_def) override;
116  int close(void) override;
117  int write_row(uchar *buf) override;
118  int update_row(const uchar *old_data, uchar *new_data) override;
119  int delete_row(const uchar *buf) override;
120  int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
121  enum ha_rkey_function find_flag) override;
122  int index_read_idx_map(uchar *buf, uint index, const uchar *key,
123  key_part_map keypart_map,
124  enum ha_rkey_function find_flag) override;
125  int index_read_last_map(uchar *buf, const uchar *key,
126  key_part_map keypart_map) override;
127  int index_next(uchar *buf) override;
128  int index_prev(uchar *buf) override;
129  int index_first(uchar *buf) override;
130  int index_last(uchar *buf) override;
131  int index_next_same(uchar *buf, const uchar *key, uint keylen) override;
132  int ft_init() override {
133  if (!ft_handler) return 1;
135  return 0;
136  }
138  return ft_init_search(flags, file, inx, pointer_cast<uchar *>(key->ptr()),
139  (uint)key->length(), key->charset(),
140  table->record[0]);
141  }
142  int ft_read(uchar *buf) override;
143  int rnd_init(bool scan) override;
144  int rnd_next(uchar *buf) override;
145  int rnd_pos(uchar *buf, uchar *pos) override;
146  void position(const uchar *record) override;
147  int info(uint) override;
148  int extra(enum ha_extra_function operation) override;
149  int extra_opt(enum ha_extra_function operation, ulong cache_size) override;
150  int reset(void) override;
151  int external_lock(THD *thd, int lock_type) override;
152  int delete_all_rows(void) override;
153  int disable_indexes(uint mode) override;
154  int enable_indexes(uint mode) override;
155  int indexes_are_disabled(void) override;
156  void start_bulk_insert(ha_rows rows) override;
157  int end_bulk_insert() override;
158  ha_rows records_in_range(uint inx, key_range *min_key,
159  key_range *max_key) override;
160  void update_create_info(HA_CREATE_INFO *create_info) override;
161  int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
162  dd::Table *table_def) override;
164  enum thr_lock_type lock_type) override;
165  void get_auto_increment(ulonglong offset, ulonglong increment,
166  ulonglong nb_desired_values, ulonglong *first_value,
167  ulonglong *nb_reserved_values) override;
168  int rename_table(const char *from, const char *to,
169  const dd::Table *from_table_def,
170  dd::Table *to_table_def) override;
171  int delete_table(const char *name, const dd::Table *table_def) override;
172  int check(THD *thd, HA_CHECK_OPT *check_opt) override;
173  int analyze(THD *thd, HA_CHECK_OPT *check_opt) override;
174  int repair(THD *thd, HA_CHECK_OPT *check_opt) override;
175  bool check_and_repair(THD *thd) override;
176  bool is_crashed() const override;
177  bool auto_repair() const override {
179  }
180  int optimize(THD *thd, HA_CHECK_OPT *check_opt) override;
181  int assign_to_keycache(THD *thd, HA_CHECK_OPT *check_opt) override;
182  int preload_keys(THD *thd, HA_CHECK_OPT *check_opt) override;
184  uint table_changes) override;
185  MI_INFO *file_ptr(void) { return file; }
186 
187  public:
188  /**
189  * Multi Range Read interface
190  */
191  int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
192  uint n_ranges, uint mode,
193  HANDLER_BUFFER *buf) override;
194  int multi_range_read_next(char **range_info) override;
196  void *seq_init_param, uint n_ranges,
197  uint *bufsz, uint *flags,
198  Cost_estimate *cost) override;
199  ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
200  uint *bufsz, uint *flags,
201  Cost_estimate *cost) override;
202 
203  /* Index condition pushdown implementation */
204  Item *idx_cond_push(uint keyno, Item *idx_cond) override;
205 
206  private:
208  friend ICP_RESULT index_cond_func_myisam(void *arg);
209 };
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
Used to store optimizer cost estimates.
Definition: handler.h:3423
Definition: handler.h:6698
Base class to be used by handlers different shares.
Definition: handler.h:3673
Base class that is used to represent any kind of expression in a relational query.
Definition: item.h:802
ulong flags
dupp key and pack flags
Definition: key.h:117
Definition: ha_myisam.h:64
Myisam_handler_share()
Definition: ha_myisam.h:66
~Myisam_handler_share() override=default
MYISAM_SHARE * m_share
Definition: ha_myisam.h:68
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:165
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:821
Definition: table.h:46
Definition: ha_myisam.h:71
int enable_indexes(uint mode) override
Definition: ha_myisam.cc:1325
MI_INFO * file
Definition: ha_myisam.h:72
int extra_opt(enum ha_extra_function operation, ulong cache_size) override
Definition: ha_myisam.cc:1724
int rnd_pos(uchar *buf, uchar *pos) override
Definition: ha_myisam.cc:1625
int disable_indexes(uint mode) override
Definition: ha_myisam.cc:1280
void start_bulk_insert(ha_rows rows) override
Definition: ha_myisam.cc:1419
int info(uint) override
General method to gather info from handler.
Definition: ha_myisam.cc:1636
int write_row(uchar *buf) override
Definition: ha_myisam.cc:828
int index_end() override
Definition: ha_myisam.cc:1532
bool is_crashed() const override
Check if the table is crashed.
Definition: ha_myisam.cc:1500
DsMrr_impl ds_mrr
Definition: ha_myisam.h:207
int extra(enum ha_extra_function operation) override
Definition: ha_myisam.cc:1709
void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values) override
Reserves an interval of auto_increment values from the handler.
Definition: ha_myisam.cc:1830
int check(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_myisam.cc:842
int external_lock(THD *thd, int lock_type) override
Definition: ha_myisam.cc:1734
void position(const uchar *record) override
Definition: ha_myisam.cc:1631
int assign_to_keycache(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_myisam.cc:1163
uint max_supported_key_part_length(HA_CREATE_INFO *create_info[[maybe_unused]]) const override
Definition: ha_myisam.h:108
Item * idx_cond_push(uint keyno, Item *idx_cond) override
Definition: ha_myisam.cc:2066
int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def) override
Definition: ha_myisam.cc:710
char * index_file_name
Definition: ha_myisam.h:74
int multi_range_read_next(char **range_info) override
Get next record in MRR scan.
Definition: ha_myisam.cc:2036
uint max_supported_keys() const override
Definition: ha_myisam.h:106
int index_next_same(uchar *buf, const uchar *key, uint keylen) override
Definition: ha_myisam.cc:1603
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_myisam.h:82
void update_create_info(HA_CREATE_INFO *create_info) override
Definition: ha_myisam.cc:1750
int index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) override
Positions an index cursor to the index specified in argument.
Definition: ha_myisam.cc:1555
ulonglong table_flags() const override
Definition: ha_myisam.h:89
int preload_keys(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_myisam.cc:1205
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint mode, HANDLER_BUFFER *buf) override
Multi Range Read interface.
Definition: ha_myisam.cc:2029
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_myisam.cc:1742
int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map) override
The following functions works like index_read, but it find the last row with the current key value or...
Definition: ha_myisam.cc:1565
ulong index_flags(uint inx, uint, bool) const override
Definition: ha_myisam.h:94
int end_bulk_insert() override
Definition: ha_myisam.cc:1455
int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) override
Positions an index cursor to the index specified in the handle ('active_index').
Definition: ha_myisam.cc:1546
int rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def) override
Default rename_table() and delete_table() rename/delete files with a given name and extensions from h...
Definition: ha_myisam.cc:1825
MI_INFO * file_ptr(void)
Definition: ha_myisam.h:185
int rnd_init(bool scan) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_myisam.cc:1614
int delete_row(const uchar *buf) override
Definition: ha_myisam.cc:1510
bool is_index_algorithm_supported(enum ha_key_alg key_alg) const override
Check if SE supports specific key algorithm.
Definition: ha_myisam.h:86
bool auto_repair() const override
Check if the table can be automatically repaired.
Definition: ha_myisam.h:177
ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys, uint *bufsz, uint *flags, Cost_estimate *cost) override
Get cost and other information about MRR scan over some sequence of ranges.
Definition: ha_myisam.cc:2055
int delete_all_rows(void) override
Delete all rows in a table.
Definition: ha_myisam.cc:1728
int index_next(uchar *buf) override
Definition: ha_myisam.cc:1575
int analyze(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_myisam.cc:921
int update_row(const uchar *old_data, uchar *new_data) override
Definition: ha_myisam.cc:1505
int ft_read(uchar *buf) override
Definition: ha_myisam.cc:1903
uint checksum() const override
Definition: ha_myisam.cc:1915
enum ha_key_alg get_default_index_algorithm() const override
Get default key algorithm for SE.
Definition: ha_myisam.h:83
int rnd_end() override
Definition: ha_myisam.cc:1541
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key) override
Definition: ha_myisam.cc:1898
bool can_enable_indexes
Definition: ha_myisam.h:75
handler * clone(const char *name, MEM_ROOT *mem_root) override
Definition: ha_myisam.cc:649
int delete_table(const char *name, const dd::Table *table_def) override
Delete a table.
Definition: ha_myisam.cc:1730
char * data_file_name
Definition: ha_myisam.h:74
int repair(THD *thd, MI_CHECK &param, bool optimize)
Definition: ha_myisam.cc:1012
int close(void) override
Definition: ha_myisam.cc:808
int index_last(uchar *buf) override
Definition: ha_myisam.cc:1596
int index_init(uint idx, bool sorted) override
Definition: ha_myisam.cc:1525
~ha_myisam() override=default
ha_myisam(handlerton *hton, TABLE_SHARE *table_arg)
Definition: ha_myisam.cc:635
uint max_supported_key_length() const override
Definition: ha_myisam.h:107
int indexes_are_disabled(void) override
Check if indexes are disabled.
Definition: ha_myisam.cc:1401
int index_first(uchar *buf) override
Definition: ha_myisam.cc:1589
ulonglong int_table_flags
Definition: ha_myisam.h:73
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_myisam.cc:1759
FT_INFO * ft_init_ext(uint flags, uint inx, String *key) override
Definition: ha_myisam.h:137
int index_prev(uchar *buf) override
Definition: ha_myisam.cc:1582
ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint *bufsz, uint *flags, Cost_estimate *cost) override
Get cost and other information about MRR scan over a known list of ranges.
Definition: ha_myisam.cc:2040
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes) override
Definition: ha_myisam.cc:1917
int ft_init() override
Definition: ha_myisam.h:132
bool check_and_repair(THD *thd) override
Definition: ha_myisam.cc:1476
friend ICP_RESULT index_cond_func_myisam(void *arg)
Definition: ha_myisam.cc:1515
int reset(void) override
Reset state of file to after 'open'.
Definition: ha_myisam.cc:1713
int rnd_next(uchar *buf) override
Definition: ha_myisam.cc:1619
int optimize(THD *thd, HA_CHECK_OPT *check_opt) override
Definition: ha_myisam.cc:992
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4131
TABLE_SHARE * table_share
Definition: handler.h:4138
FT_INFO * ft_handler
Definition: handler.h:4216
TABLE * table
Definition: handler.h:4139
A table definition from the master.
Definition: rpl_utility.h:247
static MEM_ROOT mem_root
Definition: client_plugin.cc:109
Dialog Client Authentication nullptr
Definition: dialog.cc:352
char * pos
Definition: do_ctype.cc:76
Some definitions for full-text indices.
FT_INFO * ft_init_search(uint, void *, uint, uchar *, uint, const CHARSET_INFO *, uchar *)
Definition: ft_static.cc:63
const char * myisam_recover_names[]
Definition: ha_myisam.cc:72
ulonglong myisam_recover_options
Definition: ha_myisam.cc:63
int check_definition(MI_KEYDEF *t1_keyinfo, MI_COLUMNDEF *t1_recinfo, uint t1_keys, uint t1_recs, MI_KEYDEF *t2_keyinfo, MI_COLUMNDEF *t2_recinfo, uint t2_keys, uint t2_recs, bool strict)
Definition: ha_myisam.cc:444
TYPELIB myisam_recover_typelib
Definition: ha_myisam.cc:74
int table2myisam(TABLE *table_arg, MI_KEYDEF **keydef_out, MI_COLUMNDEF **recinfo_out, uint *records_out)
Definition: ha_myisam.cc:251
const char * myisam_stats_method_names[]
Definition: ha_myisam.cc:77
ICP_RESULT index_cond_func_myisam(void *arg)
Definition: ha_myisam.cc:1515
#define HA_RECOVER_OFF
Definition: ha_myisam.h:48
static int flags[50]
Definition: hp_test1.cc:39
static uint keys
Definition: hp_test2.cc:45
#define HA_SPATIAL
Spatial key.
Definition: my_base.h:507
ha_key_alg
Definition: my_base.h:96
@ HA_KEY_ALG_RTREE
Definition: my_base.h:107
@ HA_KEY_ALG_BTREE
Definition: my_base.h:106
@ HA_KEY_ALG_FULLTEXT
Definition: my_base.h:109
ha_rkey_function
Definition: my_base.h:77
ulong key_part_map
Definition: my_base.h:1006
my_off_t ha_rows
Definition: my_base.h:1138
ha_extra_function
Definition: my_base.h:183
enum icp_result ICP_RESULT
Values returned by index_cond_func_xxx functions.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
unsigned char uchar
Definition: my_inttypes.h:51
This file should be included when using myisam functions.
#define MI_MAX_KEY_LENGTH
Definition: myisam.h:63
#define MI_MAX_KEY
Definition: myisam.h:55
Definition: buf0block_hint.cc:29
Definition: os0file.h:85
mode
Definition: file_handle.h:59
required string key
Definition: replication_asynchronous_connection_failover.proto:59
#define HA_READ_NEXT
Definition: handler.h:526
#define HA_KEY_SCAN_NOT_ROR
Definition: handler.h:569
#define HA_KEYREAD_ONLY
Definition: handler.h:564
#define HA_READ_ORDER
Definition: handler.h:542
#define HA_READ_RANGE
Definition: handler.h:549
#define HA_DO_INDEX_COND_PUSHDOWN
Definition: handler.h:570
#define HA_READ_PREV
Definition: handler.h:530
Our own string classes, used pervasively throughout the executor.
case opt name
Definition: sslopt-case.h:32
Definition: ft_global.h:71
struct _ft_vft * please
Definition: ft_global.h:72
Definition: handler.h:3362
Definition: handler.h:3349
Definition: handler.h:2764
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:78
Definition: myisam.h:343
Definition: myisam.h:228
Definition: myisamdef.h:251
Definition: myisam.h:173
Definition: myisamdef.h:176
Definition: handler.h:3370
This structure is shared between different table objects.
Definition: table.h:688
KEY * key_info
Definition: table.h:744
Definition: table.h:1394
uchar * record[2]
Definition: table.h:1437
Definition: thr_lock.h:123
Definition: typelib.h:34
void(* reinit_search)(FT_INFO *)
Definition: ft_global.h:52
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2391
Definition: my_base.h:1122
Definition: mi_test3.cc:54
thr_lock_type
Definition: thr_lock.h:50
unsigned int uint
Definition: uca-dump.cc:29
static uint64_t cache_size
Definition: xcom_cache.cc:360