1/*
2 Copyright (c) 2000, 2011, 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 as published by
6 the Free Software Foundation; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16
17
18#ifdef USE_PRAGMA_INTERFACE
19#pragma interface /* gcc class implementation */
20#endif
21
22/* class for the the myisam merge handler */
23
24#include <myisammrg.h>
25
26/**
27 Represents one name of a MERGE child.
28
29 @todo: Add MYRG_SHARE and store chlidren names in the
30 share.
31*/
32
33class Mrg_child_def: public Sql_alloc
34{
35 /* Remembered MERGE child def version. See top comment in ha_myisammrg.cc */
36 enum_table_ref_type m_child_table_ref_type;
37 ulong m_child_def_version;
38public:
39 LEX_STRING db;
40 LEX_STRING name;
41
42 /* Access MERGE child def version. See top comment in ha_myisammrg.cc */
43 inline enum_table_ref_type get_child_table_ref_type()
44 {
45 return m_child_table_ref_type;
46 }
47 inline ulong get_child_def_version()
48 {
49 return m_child_def_version;
50 }
51 inline void set_child_def_version(enum_table_ref_type child_table_ref_type,
52 ulong version)
53 {
54 m_child_table_ref_type= child_table_ref_type;
55 m_child_def_version= version;
56 }
57
58 Mrg_child_def(char *db_arg, size_t db_len_arg,
59 char *table_name_arg, size_t table_name_len_arg)
60 {
61 db.str= db_arg;
62 db.length= db_len_arg;
63 name.str= table_name_arg;
64 name.length= table_name_len_arg;
65 m_child_def_version= ~0UL;
66 m_child_table_ref_type= TABLE_REF_NULL;
67 }
68};
69
70
71class ha_myisammrg: public handler
72{
73 MYRG_INFO *file;
74 my_bool is_cloned; /* This instance has been cloned */
75
76public:
77 MEM_ROOT children_mem_root; /* mem root for children list */
78 List<Mrg_child_def> child_def_list;
79 TABLE_LIST *children_l; /* children list */
80 TABLE_LIST **children_last_l; /* children list end */
81 uint test_if_locked; /* flags from ::open() */
82
83 ha_myisammrg(handlerton *hton, TABLE_SHARE *table_arg);
84 ~ha_myisammrg();
85 const char *index_type(uint key_number);
86 ulonglong table_flags() const
87 {
88 return (HA_REC_NOT_IN_SEQ | HA_AUTO_PART_KEY | HA_NO_TRANSACTIONS |
89 HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE |
90 HA_NULL_IN_KEY | HA_CAN_INDEX_BLOBS | HA_FILE_BASED |
91 HA_ANY_INDEX_MAY_BE_UNIQUE | HA_CAN_BIT_FIELD |
92 HA_HAS_RECORDS | HA_CAN_EXPORT |
93 HA_NO_COPY_ON_ALTER |
94 HA_DUPLICATE_POS | HA_CAN_MULTISTEP_MERGE);
95 }
96 ulong index_flags(uint inx, uint part, bool all_parts) const
97 {
98 return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ?
99 0 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE |
100 HA_READ_ORDER | HA_KEYREAD_ONLY);
101 }
102 uint max_supported_keys() const { return MI_MAX_KEY; }
103 uint max_supported_key_length() const { return HA_MAX_KEY_LENGTH; }
104 uint max_supported_key_part_length() const { return HA_MAX_KEY_LENGTH; }
105 double scan_time()
106 { return ulonglong2double(stats.data_file_length) / IO_SIZE + file->tables; }
107
108 int open(const char *name, int mode, uint test_if_locked);
109 int add_children_list(void);
110 int attach_children(void);
111 int detach_children(void);
112 virtual handler *clone(const char *name, MEM_ROOT *mem_root);
113 int close(void);
114 int write_row(uchar * buf);
115 int update_row(const uchar * old_data, const uchar * new_data);
116 int delete_row(const uchar * buf);
117 int index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
118 enum ha_rkey_function find_flag);
119 int index_read_idx_map(uchar *buf, uint index, const uchar *key,
120 key_part_map keypart_map,
121 enum ha_rkey_function find_flag);
122 int index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map);
123 int index_next(uchar * buf);
124 int index_prev(uchar * buf);
125 int index_first(uchar * buf);
126 int index_last(uchar * buf);
127 int index_next_same(uchar *buf, const uchar *key, uint keylen);
128 int rnd_init(bool scan);
129 int rnd_next(uchar *buf);
130 int rnd_pos(uchar * buf, uchar *pos);
131 void position(const uchar *record);
132 ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key);
133 int delete_all_rows();
134 int info(uint);
135 int reset(void);
136 int extra(enum ha_extra_function operation);
137 int extra_opt(enum ha_extra_function operation, ulong cache_size);
138 int external_lock(THD *thd, int lock_type);
139 uint lock_count(void) const;
140 int create_mrg(const char *name, HA_CREATE_INFO *create_info);
141 int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info);
142 THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
143 enum thr_lock_type lock_type);
144 void update_create_info(HA_CREATE_INFO *create_info);
145 void append_create_info(String *packet);
146 MYRG_INFO *myrg_info() { return file; }
147 TABLE *table_ptr() { return table; }
148 enum_alter_inplace_result check_if_supported_inplace_alter(TABLE *,
149 Alter_inplace_info *);
150 bool inplace_alter_table(TABLE *altered_table,
151 Alter_inplace_info *ha_alter_info);
152 int check(THD* thd, HA_CHECK_OPT* check_opt);
153 ha_rows records();
154 virtual uint count_query_cache_dependant_tables(uint8 *tables_type);
155 virtual my_bool
156 register_query_cache_dependant_tables(THD *thd,
157 Query_cache *cache,
158 Query_cache_block_table **block,
159 uint *n);
160 virtual void set_lock_type(enum thr_lock_type lock);
161};
162