MySQL  8.0.17
Source Code Documentation
ha_myisam.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
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 "my_macros.h"
36 #include "myisam.h"
37 #include "sql/handler.h" /* handler */
38 #include "sql/table.h" /* TABLE_SHARE */
39 #include "sql_string.h"
40 #include "typelib.h"
41 
42 struct TABLE_SHARE;
43 struct HA_CREATE_INFO;
44 
45 #define HA_RECOVER_DEFAULT 1 /* Automatic recover active */
46 #define HA_RECOVER_BACKUP 2 /* Make a backupfile on recover */
47 #define HA_RECOVER_FORCE 4 /* Recover even if we loose rows */
48 #define HA_RECOVER_QUICK 8 /* Don't check rows in data file */
49 #define HA_RECOVER_OFF 16 /* No automatic recover */
50 
52 extern const char *myisam_recover_names[];
54 extern const char *myisam_stats_method_names[];
55 
56 int table2myisam(TABLE *table_arg, MI_KEYDEF **keydef_out,
57  MI_COLUMNDEF **recinfo_out, uint *records_out);
58 int check_definition(MI_KEYDEF *t1_keyinfo, MI_COLUMNDEF *t1_recinfo,
59  uint t1_keys, uint t1_recs, MI_KEYDEF *t2_keyinfo,
60  MI_COLUMNDEF *t2_recinfo, uint t2_keys, uint t2_recs,
61  bool strict);
62 
66 
68  public:
72 };
73 
74 class ha_myisam : public handler {
79  int repair(THD *thd, MI_CHECK &param, bool optimize);
80 
81  public:
82  ha_myisam(handlerton *hton, TABLE_SHARE *table_arg);
84  handler *clone(const char *name, MEM_ROOT *mem_root);
85  const char *table_type() const { return "MyISAM"; }
86  virtual enum ha_key_alg get_default_index_algorithm() const {
87  return HA_KEY_ALG_BTREE;
88  }
89  virtual bool is_index_algorithm_supported(enum ha_key_alg key_alg) const {
90  return key_alg == HA_KEY_ALG_BTREE || key_alg == HA_KEY_ALG_RTREE;
91  }
93  int index_init(uint idx, bool sorted);
94  int index_end();
95  int rnd_end();
96 
97  ulong index_flags(uint inx, uint, bool) const {
98  if (table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) return 0;
99 
102 
103  // @todo: Check if spatial indexes really have all these properties
104  if (table_share->key_info[inx].flags & HA_SPATIAL)
106 
107  return flags;
108  }
109  uint max_supported_keys() const { return MI_MAX_KEY; }
112  HA_CREATE_INFO *create_info MY_ATTRIBUTE((unused))) const {
113  return MI_MAX_KEY_LENGTH;
114  }
115  uint checksum() const;
116 
117  int open(const char *name, int mode, uint test_if_locked,
118  const dd::Table *table_def);
119  int close(void);
120  int write_row(uchar *buf);
121  int update_row(const uchar *old_data, uchar *new_data);
122  int delete_row(const uchar *buf);
123  int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
124  enum ha_rkey_function find_flag);
125  int index_read_idx_map(uchar *buf, uint index, const uchar *key,
126  key_part_map keypart_map,
127  enum ha_rkey_function find_flag);
128  int index_read_last_map(uchar *buf, const uchar *key,
129  key_part_map keypart_map);
130  int index_next(uchar *buf);
131  int index_prev(uchar *buf);
132  int index_first(uchar *buf);
133  int index_last(uchar *buf);
134  int index_next_same(uchar *buf, const uchar *key, uint keylen);
135  int ft_init() {
136  if (!ft_handler) return 1;
138  return 0;
139  }
141  return ft_init_search(flags, file, inx, pointer_cast<uchar *>(key->ptr()),
142  (uint)key->length(), key->charset(),
143  table->record[0]);
144  }
145  int ft_read(uchar *buf);
146  int rnd_init(bool scan);
147  int rnd_next(uchar *buf);
148  int rnd_pos(uchar *buf, uchar *pos);
149  void position(const uchar *record);
150  int info(uint);
151  int extra(enum ha_extra_function operation);
152  int extra_opt(enum ha_extra_function operation, ulong cache_size);
153  int reset(void);
154  int external_lock(THD *thd, int lock_type);
155  int delete_all_rows(void);
156  int disable_indexes(uint mode);
157  int enable_indexes(uint mode);
158  int indexes_are_disabled(void);
159  void start_bulk_insert(ha_rows rows);
160  int end_bulk_insert();
161  ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
162  void update_create_info(HA_CREATE_INFO *create_info);
163  int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info,
166  enum thr_lock_type lock_type);
167  virtual void get_auto_increment(ulonglong offset, ulonglong increment,
168  ulonglong nb_desired_values,
169  ulonglong *first_value,
170  ulonglong *nb_reserved_values);
171  int rename_table(const char *from, const char *to,
172  const dd::Table *from_table_def, dd::Table *to_table_def);
173  int delete_table(const char *name, const dd::Table *table_def);
174  int check(THD *thd, HA_CHECK_OPT *check_opt);
175  int analyze(THD *thd, HA_CHECK_OPT *check_opt);
176  int repair(THD *thd, HA_CHECK_OPT *check_opt);
177  bool check_and_repair(THD *thd);
178  bool is_crashed() const;
180  int optimize(THD *thd, HA_CHECK_OPT *check_opt);
181  int assign_to_keycache(THD *thd, HA_CHECK_OPT *check_opt);
182  int preload_keys(THD *thd, HA_CHECK_OPT *check_opt);
183  bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes);
184  MI_INFO *file_ptr(void) { return file; }
185 
186  public:
187  /**
188  * Multi Range Read interface
189  */
190  int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
191  uint n_ranges, uint mode, HANDLER_BUFFER *buf);
192  int multi_range_read_next(char **range_info);
194  void *seq_init_param, uint n_ranges,
195  uint *bufsz, uint *flags,
196  Cost_estimate *cost);
197  ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
198  uint *bufsz, uint *flags, Cost_estimate *cost);
199 
200  /* Index condition pushdown implementation */
201  Item *idx_cond_push(uint keyno, Item *idx_cond);
202 
203  private:
205  friend ICP_RESULT index_cond_func_myisam(void *arg);
206 };
uint checksum() const
Definition: ha_myisam.cc:1936
int analyze(THD *thd, HA_CHECK_OPT *check_opt)
Definition: ha_myisam.cc:935
#define HA_RECOVER_OFF
Definition: ha_myisam.h:49
Some common macros.
unsigned long long int ulonglong
Definition: my_inttypes.h:74
int assign_to_keycache(THD *thd, HA_CHECK_OPT *check_opt)
Definition: ha_myisam.cc:1177
int external_lock(THD *thd, int lock_type)
Is not invoked for non-transactional temporary tables.
Definition: ha_myisam.cc:1755
Definition: thr_lock.h:123
const char * myisam_recover_names[]
Definition: ha_myisam.cc:71
MI_INFO * file
Definition: ha_myisam.h:75
unsigned char uchar
Definition: my_inttypes.h:51
Our own string classes, used pervasively throughout the executor.
ICP_RESULT index_cond_func_myisam(void *arg)
Definition: ha_myisam.cc:1533
t pos
Definition: dbug_analyze.cc:148
uint max_supported_keys() const
Definition: ha_myisam.h:109
ulonglong int_table_flags
Definition: ha_myisam.h:76
const char * table_type() const
The following can be called without an open handler.
Definition: ha_myisam.h:85
Definition: handler.h:3173
Base class to be used by handlers different shares.
Definition: handler.h:3512
uchar * record[2]
Definition: table.h:1327
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)
Get cost and other information about MRR scan over a known list of ranges.
Definition: ha_myisam.cc:2061
const string name("\ame\)
Definition: mi_test3.cc:54
This structure is shared between different table objects.
Definition: table.h:646
#define HA_READ_PREV
Definition: handler.h:532
int optimize(THD *thd, HA_CHECK_OPT *check_opt)
Definition: ha_myisam.cc:1006
ulong key_part_map
Definition: my_base.h:998
KEY * key_info
Definition: table.h:698
Some integer typedefs for easier portability.
Definition: ha_myisam.h:74
char * data_file_name
Definition: ha_myisam.h:77
int ft_init()
Definition: ha_myisam.h:135
int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def)
Definition: ha_myisam.cc:724
enum ha_key_alg algorithm
Definition: key.h:131
#define C_MODE_START
Definition: my_macros.h:39
int update_row(const uchar *old_data, uchar *new_data)
Update a single row.
Definition: ha_myisam.cc:1521
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:443
#define HA_SPATIAL
Spatial key.
Definition: my_base.h:508
#define HA_READ_NEXT
Definition: handler.h:528
Definition: handler.h:3188
int delete_row(const uchar *buf)
Definition: ha_myisam.cc:1526
Sergei Dialog Client Authentication NULL
Definition: dialog.cc:352
ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key)
Find number of records in a range.
Definition: ha_myisam.cc:1919
Item * idx_cond_push(uint keyno, Item *idx_cond)
Push down an index condition to the handler.
Definition: ha_myisam.cc:2087
ulonglong myisam_recover_options
Definition: ha_myisam.cc:62
Definition: my_base.h:107
Definition: myisam.h:223
ha_rkey_function
Definition: my_base.h:77
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:3987
int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map)
The following functions works like index_read, but it find the last row with the current key value or...
Definition: ha_myisam.cc:1585
int rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def)
Default rename_table() and delete_table() rename/delete files with a given name and extensions from h...
Definition: ha_myisam.cc:1846
int index_next(uchar *buf)
Definition: ha_myisam.cc:1595
Definition: myisamdef.h:175
TABLE_SHARE * table_share
Definition: handler.h:3994
Using this class is fraught with peril, and you need to be very careful when doing so...
Definition: sql_string.h:159
int delete_table(const char *name, const dd::Table *table_def)
Delete a table.
Definition: ha_myisam.cc:1751
void update_create_info(HA_CREATE_INFO *create_info)
Update create info as part of ALTER TABLE.
Definition: ha_myisam.cc:1771
Definition: table.h:1294
TYPELIB myisam_recover_typelib
Definition: ha_myisam.cc:73
int indexes_are_disabled(void)
Check if indexes are disabled.
Definition: ha_myisam.cc:1415
#define HA_KEYREAD_ONLY
Definition: handler.h:566
int multi_range_read_next(char **range_info)
Get next record in MRR scan.
Definition: ha_myisam.cc:2057
bool is_crashed() const
Check if the table is crashed.
Definition: ha_myisam.cc:1516
int index_next_same(uchar *buf, const uchar *key, uint keylen)
Definition: ha_myisam.cc:1623
uint max_supported_key_length() const
Definition: ha_myisam.h:110
friend ICP_RESULT index_cond_func_myisam(void *arg)
Definition: ha_myisam.cc:1533
ulong flags
dupp key and pack flags
Definition: key.h:116
Definition: myisam.h:339
~ha_myisam()
Definition: ha_myisam.h:83
char * index(const char *, int c)
Definition: mysql.cc:2847
enum icp_result ICP_RESULT
Values returned by index_cond_func_xxx functions.
int table2myisam(TABLE *table_arg, MI_KEYDEF **keydef_out, MI_COLUMNDEF **recinfo_out, uint *records_out)
Definition: ha_myisam.cc:249
FT_INFO * ft_handler
Definition: handler.h:4072
int enable_indexes(uint mode)
Enable indexes again.
Definition: ha_myisam.cc:1339
thr_lock_type
Definition: thr_lock.h:50
int index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Positions an index cursor to the index specified in argument.
Definition: ha_myisam.cc:1575
This file should be included when using myisam functions.
const char * myisam_stats_method_names[]
Definition: ha_myisam.cc:76
int check(THD *thd, HA_CHECK_OPT *check_opt)
Definition: ha_myisam.cc:856
virtual void get_auto_increment(ulonglong offset, ulonglong increment, ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values)
Reserves an interval of auto_increment values from the handler.
Definition: ha_myisam.cc:1851
bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes)
Part of old, deprecated in-place ALTER API.
Definition: ha_myisam.cc:1938
ha_myisam(handlerton *hton, TABLE_SHARE *table_arg)
Definition: ha_myisam.cc:634
int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param, uint n_ranges, uint mode, HANDLER_BUFFER *buf)
Multi Range Read interface.
Definition: ha_myisam.cc:2050
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type)
Is not invoked for non-transactional temporary tables.
Definition: ha_myisam.cc:1763
virtual bool is_index_algorithm_supported(enum ha_key_alg key_alg) const
Check if SE supports specific key algorithm.
Definition: ha_myisam.h:89
DsMrr_impl ds_mrr
Definition: ha_myisam.h:204
struct _ft_vft * please
Definition: ft_global.h:72
#define HA_READ_RANGE
Definition: handler.h:551
int disable_indexes(uint mode)
Disable indexes for a while.
Definition: ha_myisam.cc:1294
static uint keys
Definition: hp_test2.cc:43
Definition: item.h:666
#define MI_MAX_KEY
Definition: myisam.h:54
unsigned int uint
Definition: uca-dump.cc:29
int close(void)
Definition: ha_myisam.cc:822
#define HA_DO_INDEX_COND_PUSHDOWN
Definition: handler.h:572
int end_bulk_insert()
Definition: ha_myisam.cc:1470
int preload_keys(THD *thd, HA_CHECK_OPT *check_opt)
Definition: ha_myisam.cc:1219
Definition: my_base.h:106
int extra(enum ha_extra_function operation)
Storage engine specific implementation of ha_extra()
Definition: ha_myisam.cc:1730
virtual enum ha_key_alg get_default_index_algorithm() const
Get default key algorithm for SE.
Definition: ha_myisam.h:86
void position(const uchar *record)
Definition: ha_myisam.cc:1652
int repair(THD *thd, MI_CHECK &param, bool optimize)
Definition: ha_myisam.cc:1026
Definition: handler.h:6555
int index_prev(uchar *buf)
Definition: ha_myisam.cc:1602
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2275
Definition: ha_myisam.h:67
Definition: my_base.h:109
FT_INFO * ft_init_search(uint, void *, uint, uchar *, uint, const CHARSET_INFO *, uchar *)
Definition: ft_static.cc:63
int delete_all_rows(void)
Delete all rows in a table.
Definition: ha_myisam.cc:1749
ulonglong table_flags() const
Definition: ha_myisam.h:92
MYISAM_SHARE * m_share
Definition: ha_myisam.h:71
Myisam_handler_share()
Definition: ha_myisam.h:69
Definition: my_base.h:1114
static const char * key
Definition: suite_stubs.c:14
Definition: typelib.h:34
static MEM_ROOT mem_root
Definition: client_plugin.cc:107
int info(uint)
General method to gather info from handler.
Definition: ha_myisam.cc:1657
Definition: handler.h:3196
int reset(void)
Reset state of file to after &#39;open&#39;.
Definition: ha_myisam.cc:1734
Definition: myisamdef.h:252
int index_last(uchar *buf)
Definition: ha_myisam.cc:1616
ha_key_alg
Definition: my_base.h:96
void(* reinit_search)(FT_INFO *)
Definition: ft_global.h:52
int index_first(uchar *buf)
Definition: ha_myisam.cc:1609
#define C_MODE_END
Definition: my_macros.h:40
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const
Definition: ha_myisam.h:111
Definition: handler.h:2607
#define HA_KEY_SCAN_NOT_ROR
Definition: handler.h:571
int write_row(uchar *buf)
Write a row.
Definition: ha_myisam.cc:842
Definition: ft_global.h:71
int index_end()
Definition: ha_myisam.cc:1552
int rnd_end()
Definition: ha_myisam.cc:1561
A table definition from the master.
Definition: rpl_utility.h:245
handler * clone(const char *name, MEM_ROOT *mem_root)
Definition: ha_myisam.cc:648
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:77
void start_bulk_insert(ha_rows rows)
Definition: ha_myisam.cc:1433
int index_init(uint idx, bool sorted)
Definition: ha_myisam.cc:1545
ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys, uint *bufsz, uint *flags, Cost_estimate *cost)
Get cost and other information about MRR scan over some sequence of ranges.
Definition: ha_myisam.cc:2076
static int flags[50]
Definition: hp_test1.cc:39
int ft_read(uchar *buf)
Definition: ha_myisam.cc:1924
MI_INFO * file_ptr(void)
Definition: ha_myisam.h:184
#define MI_MAX_KEY_LENGTH
Definition: myisam.h:62
#define HA_READ_ORDER
Definition: handler.h:544
TABLE * table
Definition: handler.h:3995
Some definitions for full-text indices.
Definition: myisam.h:168
Definition: table.h:43
Used to store optimizer cost estimates.
Definition: handler.h:3262
int extra_opt(enum ha_extra_function operation, ulong cache_size)
Definition: ha_myisam.cc:1745
int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag)
Positions an index cursor to the index specified in the handle (&#39;active_index&#39;).
Definition: ha_myisam.cc:1566
unsigned long ulong
Definition: my_inttypes.h:48
int rnd_pos(uchar *buf, uchar *pos)
Definition: ha_myisam.cc:1646
int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info, dd::Table *table_def)
Create table (implementation).
Definition: ha_myisam.cc:1780
bool can_enable_indexes
Definition: ha_myisam.h:78
int rnd_next(uchar *buf)
Definition: ha_myisam.cc:1640
my_off_t ha_rows
Definition: my_base.h:1130
char * index_file_name
Definition: ha_myisam.h:77
bool auto_repair() const
Check if the table can be automatically repaired.
Definition: ha_myisam.h:179
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:777
bool check_and_repair(THD *thd)
Check and repair the table if necessary.
Definition: ha_myisam.cc:1491
ulong index_flags(uint inx, uint, bool) const
Definition: ha_myisam.h:97
ha_extra_function
Definition: my_base.h:183
FT_INFO * ft_init_ext(uint flags, uint inx, String *key)
Definition: ha_myisam.h:140
int rnd_init(bool scan)
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1)...
Definition: ha_myisam.cc:1635
~Myisam_handler_share()
Definition: ha_myisam.h:70