14
12
You should have received a copy of the GNU General Public License
15
13
along with this program; if not, write to the Free Software
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
16
/* This file should be included when using heap_database_functions */
19
17
/* Author: Michael Widenius */
21
#ifndef PLUGIN_MEMORY_HEAP_H
22
#define PLUGIN_MEMORY_HEAP_H
24
#include <drizzled/base.h>
25
#include <drizzled/common.h>
26
#include <drizzled/internal/my_pthread.h>
27
#include <drizzled/thr_lock.h>
29
#include <plugin/myisam/my_handler.h>
30
#include <drizzled/tree.h>
28
#include <my_pthread.h>
31
#include "my_handler.h"
34
34
/* defines used by heap-funktions */
102
84
is recbuffer bytes.
103
85
The internal representation is as follows:
104
86
HP_BLOCK is a hierarchical structure of 'blocks'.
105
A block at level 0 is an array records_in_block records.
106
A block at higher level is an HP_PTRS structure with pointers to blocks at
87
A block at level 0 is an array records_in_block records.
88
A block at higher level is an HP_PTRS structure with pointers to blocks at
108
90
At the highest level there is one top block. It is stored in HP_BLOCK::root.
110
See hp_find_block for a description of how record pointer is obtained from
92
See hp_find_block for a description of how record pointer is obtained from
115
97
typedef struct st_heap_block
117
HP_PTRS *root; /* Top-level block */
99
HP_PTRS *root; /* Top-level block */
118
100
struct st_level_info level_info[HP_MAX_LEVELS+1];
119
uint32_t levels; /* number of used levels */
120
uint32_t records_in_block; /* Records in one heap-block */
121
uint32_t recbuffer; /* Length of one saved record */
122
uint32_t last_allocated; /* number of records there is allocated space for */
101
uint levels; /* number of used levels */
102
uint records_in_block; /* Records in one heap-block */
103
uint recbuffer; /* Length of one saved record */
104
ulong last_allocated; /* number of records there is allocated space for */
134
107
struct st_heap_info; /* For referense */
136
109
typedef struct st_hp_keydef /* Key definition with open */
138
uint32_t flag; /* HA_NOSAME | HA_NULL_PART_KEY */
139
uint32_t keysegs; /* Number of key-segment */
140
uint32_t length; /* Length of key (automatic) */
111
uint flag; /* HA_NOSAME | HA_NULL_PART_KEY */
112
uint keysegs; /* Number of key-segment */
113
uint length; /* Length of key (automatic) */
114
uint8 algorithm; /* HASH / BTREE */
142
116
HP_BLOCK block; /* Where keys are saved */
144
118
Number of buckets used in hash table. Used only to provide
145
119
#records estimates for heap key scans.
147
drizzled::ha_rows hash_buckets;
121
ha_rows hash_buckets;
123
int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
124
const uchar *record, uchar *recpos);
125
int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
126
const uchar *record, uchar *recpos, int flag);
127
uint (*get_key_length)(struct st_hp_keydef *keydef, const uchar *key);
150
typedef struct st_heap_dataspace /* control data for data space */
130
typedef struct st_heap_share
153
uint32_t chunk_count; /* Total chunks ever allocated in this dataspace */
154
uint32_t del_chunk_count; /* Deleted chunks count */
155
unsigned char *del_link; /* Link to last deleted chunk */
156
uint32_t chunk_length; /* Total length of one chunk */
157
uint32_t chunk_dataspace_length; /* Length of payload that will be placed into one chunk */
158
uint32_t offset_status; /* Offset of the status flag relative to the chunk start */
159
uint32_t offset_link; /* Offset of the linking pointer relative to the chunk start */
160
uint64_t total_data_length; /* Total size allocated within this data space */
162
st_heap_dataspace() :
167
chunk_dataspace_length(0),
176
typedef struct st_heap_share
178
133
HP_KEYDEF *keydef;
179
HP_DATASPACE recordspace; /* Describes "block", which contains actual records */
181
uint32_t min_records,max_records; /* Params to open */
182
uint64_t index_length,max_table_size;
183
uint32_t key_stat_version; /* version to indicate insert/delete */
184
uint32_t records; /* Actual record (row) count */
185
uint32_t blength; /* used_chunk_count rounded up to 2^n */
186
uint32_t fixed_data_length; /* Length of record's fixed part, which contains keys and always fits into the first chunk */
187
uint32_t fixed_column_count; /* Number of columns stored in fixed_data_length */
189
uint32_t keys,max_key_length;
190
uint32_t column_count;
191
uint32_t currently_disabled_keys; /* saved value from "keys" when disabled */
195
std::string name; /* Name of "memory-file" */
196
bool delete_on_close;
198
uint32_t auto_key_type; /* real type of the auto key segment */
134
ulong min_records,max_records; /* Params to open */
135
uint64_t data_length,index_length,max_table_size;
136
uint key_stat_version; /* version to indicate insert/delete */
137
uint records; /* records */
138
uint blength; /* records rounded up to 2^n */
139
uint deleted; /* Deleted records in database */
140
uint reclength; /* Length of one record */
142
uint keys,max_key_length;
143
uint currently_disabled_keys; /* saved value from "keys" when disabled */
145
uchar *del_link; /* Link to next block with del. rec */
146
char * name; /* Name of "memory-file" */
148
pthread_mutex_t intern_lock; /* Locking for use with _locking */
149
my_bool delete_on_close;
152
uint auto_key_type; /* real type of the auto key segment */
199
153
uint64_t auto_increment;
210
fixed_data_length(0),
211
fixed_column_count(0),
216
currently_disabled_keys(0),
226
156
struct st_hp_hash_info;
228
158
typedef struct st_heap_info
239
void setShare(HP_SHARE *s_arg)
244
unsigned char *current_ptr;
245
162
struct st_hp_hash_info *current_hash_ptr;
246
uint32_t current_record,next_block;
163
ulong current_record,next_block;
247
164
int lastinx,errkey;
248
165
int mode; /* Mode of file (READONLY..) */
249
uint32_t opt_flag,update;
250
std::vector <unsigned char> lastkey; /* Last used key with rkey */
251
enum drizzled::ha_rkey_function last_find_flag;
252
uint32_t lastkey_len;
253
drizzled::THR_LOCK_DATA lock;
166
uint opt_flag,update;
167
uchar *lastkey; /* Last used key with rkey */
168
uchar *recbuf; /* Record buffer for rb-tree keys */
169
enum ha_rkey_function last_find_flag;
170
TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
171
TREE_ELEMENT **last_pos;
173
my_bool implicit_emptied;
257
179
typedef struct st_heap_create_info
259
uint32_t auto_key; /* keynr [1 - maxkey] for auto key */
260
uint32_t auto_key_type;
261
uint32_t max_chunk_size;
181
uint auto_key; /* keynr [1 - maxkey] for auto key */
262
183
uint64_t max_table_size;
263
184
uint64_t auto_increment;
264
bool with_auto_increment;
185
my_bool with_auto_increment;
186
my_bool internal_table;
266
187
} HP_CREATE_INFO;
268
189
/* Prototypes for heap-functions */
271
192
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
272
193
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
273
194
extern int heap_close(HP_INFO *info);
274
extern int heap_write(HP_INFO *info,const unsigned char *record);
275
extern int heap_update(HP_INFO *info,const unsigned char *old_record,const unsigned char *new_record);
276
extern int heap_rrnd(HP_INFO *info,unsigned char *buf,unsigned char *pos);
195
extern int heap_write(HP_INFO *info,const uchar *buff);
196
extern int heap_update(HP_INFO *info,const uchar *old,const uchar *newdata);
197
extern int heap_rrnd(HP_INFO *info,uchar *buf,uchar *pos);
277
198
extern int heap_scan_init(HP_INFO *info);
278
extern int heap_scan(register HP_INFO *info, unsigned char *record);
279
extern int heap_delete(HP_INFO *info,const unsigned char *buff);
199
extern int heap_scan(register HP_INFO *info, uchar *record);
200
extern int heap_delete(HP_INFO *info,const uchar *buff);
280
201
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
281
extern int heap_create(const char *name, uint32_t keys, HP_KEYDEF *keydef,
283
uint32_t key_part_size,
284
uint32_t reclength, uint32_t keys_memory_size,
285
uint32_t max_records, uint32_t min_records,
286
HP_CREATE_INFO *create_info, HP_SHARE **share);
202
extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
203
uint reclength, ulong max_records, ulong min_records,
204
HP_CREATE_INFO *create_info, HP_SHARE **share);
288
205
extern int heap_delete_table(const char *name);
289
extern int heap_extra(HP_INFO *info,enum drizzled::ha_extra_function function);
206
extern void heap_drop_table(HP_INFO *info);
207
extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
290
208
extern int heap_reset(HP_INFO *info);
291
209
extern int heap_rename(const char *old_name,const char *new_name);
292
extern int heap_panic(enum drizzled::ha_panic_function flag);
293
extern int heap_rsame(HP_INFO *info,unsigned char *record,int inx);
294
extern int heap_rnext(HP_INFO *info,unsigned char *record);
295
extern int heap_rprev(HP_INFO *info,unsigned char *record);
296
extern int heap_rfirst(HP_INFO *info,unsigned char *record,int inx);
297
extern int heap_rlast(HP_INFO *info,unsigned char *record,int inx);
210
extern int heap_panic(enum ha_panic_function flag);
211
extern int heap_rsame(HP_INFO *info,uchar *record,int inx);
212
extern int heap_rnext(HP_INFO *info,uchar *record);
213
extern int heap_rprev(HP_INFO *info,uchar *record);
214
extern int heap_rfirst(HP_INFO *info,uchar *record,int inx);
215
extern int heap_rlast(HP_INFO *info,uchar *record,int inx);
298
216
extern void heap_clear(HP_INFO *info);
217
extern void heap_clear_keys(HP_INFO *info);
299
218
extern int heap_disable_indexes(HP_INFO *info);
300
219
extern int heap_enable_indexes(HP_INFO *info);
301
220
extern int heap_indexes_are_disabled(HP_INFO *info);
302
extern void heap_update_auto_increment(HP_INFO *info, const unsigned char *record);
303
int hp_panic(enum drizzled::ha_panic_function flag);
304
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
305
drizzled::key_part_map keypart_map,
306
enum drizzled::ha_rkey_function find_flag);
307
extern unsigned char * heap_find(HP_INFO *info,int inx,const unsigned char *key);
308
extern unsigned char *heap_position(HP_INFO *info);
221
extern void heap_update_auto_increment(HP_INFO *info, const uchar *record);
222
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
224
int hp_panic(enum ha_panic_function flag);
225
int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key,
226
key_part_map keypart_map, enum ha_rkey_function find_flag);
227
extern uchar * heap_find(HP_INFO *info,int inx,const uchar *key);
228
extern int heap_check_heap(HP_INFO *info, my_bool print_status);
229
extern uchar *heap_position(HP_INFO *info);
310
231
/* The following is for programs that uses the old HEAP interface where
311
pointer to rows where a long instead of a (unsigned char*).
232
pointer to rows where a long instead of a (uchar*).
314
typedef unsigned char *HEAP_PTR;
235
#if defined(WANT_OLD_HEAP_VERSION) || defined(OLD_HEAP_VERSION)
236
extern int heap_rrnd_old(HP_INFO *info,uchar *buf,ulong pos);
237
extern ulong heap_position_old(HP_INFO *info);
239
#ifdef OLD_HEAP_VERSION
240
typedef ulong HEAP_PTR;
241
#define heap_position(A) heap_position_old(A)
242
#define heap_rrnd(A,B,C) heap_rrnd_old(A,B,C)
244
typedef uchar *HEAP_PTR;
316
#endif /* PLUGIN_MEMORY_HEAP_H */