~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memory/heap.h

  • Committer: Olaf van der Spek
  • Date: 2011-02-12 18:24:24 UTC
  • mto: (2167.1.2 build) (2172.1.4 build)
  • mto: This revision was merged to the branch mainline in revision 2168.
  • Revision ID: olafvdspek@gmail.com-20110212182424-kgnm9osi7qo97at2
casts

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000,2004 MySQL AB
 
1
/* 
 
2
  Copyright (C) Brian Aker
 
3
    Copyright (C) 2000,2004 MySQL AB
2
4
 
3
5
   This program is free software; you can redistribute it and/or modify
4
6
   it under the terms of the GNU General Public License as published by
11
13
 
12
14
   You should have received a copy of the GNU General Public License
13
15
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
16
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
17
 
16
18
/* This file should be included when using heap_database_functions */
17
19
/* Author: Michael Widenius */
18
20
 
19
 
#ifndef PLUGIN_HEAP_HEAP_H
20
 
#define PLUGIN_HEAP_HEAP_H
 
21
#ifndef PLUGIN_MEMORY_HEAP_H
 
22
#define PLUGIN_MEMORY_HEAP_H
21
23
 
22
24
#include <drizzled/base.h>
23
25
#include <drizzled/common.h>
27
29
#include <plugin/myisam/my_handler.h>
28
30
#include "drizzled/tree.h"
29
31
 
 
32
#include <vector>
 
33
 
30
34
        /* defines used by heap-funktions */
31
35
 
32
36
#define HP_MAX_LEVELS   4               /* 128^5 records is enough */
44
48
  uint32_t reclength;                   /* Length of one record */
45
49
  int errkey;
46
50
  uint64_t auto_increment;
 
51
 
 
52
  st_heapinfo():
 
53
    records(0),
 
54
    deleted(0),
 
55
    max_records(),
 
56
    data_length(0),
 
57
    index_length(0),
 
58
    reclength(0),
 
59
    errkey(0),
 
60
    auto_increment(0)
 
61
  { }
 
62
 
47
63
} HEAPINFO;
48
64
 
49
65
 
71
87
    level.
72
88
  */
73
89
  HP_PTRS *last_blocks;
 
90
 
 
91
  st_level_info():
 
92
    free_ptrs_in_block(0),
 
93
    records_under_level(0),
 
94
    last_blocks(0)
 
95
  { }
74
96
};
75
97
 
76
98
 
98
120
  uint32_t records_in_block;            /* Records in one heap-block */
99
121
  uint32_t recbuffer;                   /* Length of one saved record */
100
122
  uint32_t last_allocated; /* number of records there is allocated space for */
 
123
 
 
124
  st_heap_block() :
 
125
    root(NULL),
 
126
    levels(0),
 
127
    records_in_block(0),
 
128
    recbuffer(0),
 
129
    last_allocated(0)
 
130
  {
 
131
  }
101
132
} HP_BLOCK;
102
133
 
103
134
struct st_heap_info;                    /* For referense */
107
138
  uint32_t flag;                                /* HA_NOSAME | HA_NULL_PART_KEY */
108
139
  uint32_t keysegs;                             /* Number of key-segment */
109
140
  uint32_t length;                              /* Length of key (automatic) */
110
 
  uint8_t algorithm;                    /* HASH / BTREE */
111
141
  HA_KEYSEG *seg;
112
142
  HP_BLOCK block;                       /* Where keys are saved */
113
143
  /*
115
145
    #records estimates for heap key scans.
116
146
  */
117
147
  drizzled::ha_rows hash_buckets;
118
 
  drizzled::TREE rb_tree;
119
 
  int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
120
 
                   const unsigned char *record, unsigned char *recpos);
121
 
  int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
122
 
                   const unsigned char *record, unsigned char *recpos, int flag);
123
 
  uint32_t (*get_key_length)(struct st_hp_keydef *keydef, const unsigned char *key);
124
148
} HP_KEYDEF;
125
149
 
126
 
typedef struct st_heap_columndef              /* column information */
127
 
{
128
 
  int16_t  type;                                /* en_fieldtype */
129
 
  uint32_t length;                      /* length of field */
130
 
  uint32_t offset;                      /* Offset to position in row */
131
 
  uint8_t  null_bit;                    /* If column may be 0 */
132
 
  uint16_t null_pos;                    /* position for null marker */
133
 
  uint8_t  length_bytes;  /* length of the size, 1 o 2 bytes */
134
 
} HP_COLUMNDEF;
135
 
 
136
150
typedef struct st_heap_dataspace   /* control data for data space */
137
151
{
138
152
  HP_BLOCK block;
143
157
  uint32_t chunk_dataspace_length;  /* Length of payload that will be placed into one chunk */
144
158
  uint32_t offset_status;           /* Offset of the status flag relative to the chunk start */
145
159
  uint32_t offset_link;             /* Offset of the linking pointer relative to the chunk start */
146
 
  uint32_t is_variable_size;          /* Test whether records have variable size and so "next" pointer */
147
160
  uint64_t total_data_length;  /* Total size allocated within this data space */
 
161
 
 
162
  st_heap_dataspace() :
 
163
    chunk_count(0),
 
164
    del_chunk_count(0),
 
165
    del_link(0),
 
166
    chunk_length(0),
 
167
    chunk_dataspace_length(0),
 
168
    offset_status(0),
 
169
    offset_link(0),
 
170
    total_data_length(0)
 
171
  { }
 
172
 
148
173
} HP_DATASPACE;
149
174
 
150
175
 
151
176
typedef struct st_heap_share
152
177
{
153
178
  HP_KEYDEF  *keydef;
154
 
  HP_COLUMNDEF *column_defs;
155
179
  HP_DATASPACE recordspace;  /* Describes "block", which contains actual records */
156
180
 
157
181
  uint32_t min_records,max_records;     /* Params to open */
168
192
  uint32_t open_count;
169
193
 
170
194
 
171
 
  char * name;                  /* Name of "memory-file" */
172
 
  drizzled::THR_LOCK lock;
173
 
  pthread_mutex_t intern_lock;          /* Locking for use with _locking */
 
195
  std::string name;                     /* Name of "memory-file" */
174
196
  bool delete_on_close;
175
197
  uint32_t auto_key;
176
198
  uint32_t auto_key_type;                       /* real type of the auto key segment */
177
199
  uint64_t auto_increment;
 
200
 
 
201
  st_heap_share() :
 
202
    keydef(0),
 
203
    min_records(0),
 
204
    max_records(0),
 
205
    index_length(0),
 
206
    max_table_size(0),
 
207
    key_stat_version(0),
 
208
    records(0),
 
209
    blength(0),
 
210
    fixed_data_length(0),
 
211
    fixed_column_count(0),
 
212
    changed(0),
 
213
    keys(0),
 
214
    max_key_length(0),
 
215
    column_count(0),
 
216
    currently_disabled_keys(0),
 
217
    open_count(0),
 
218
    delete_on_close(0),
 
219
    auto_key(0),
 
220
    auto_key_type(0),
 
221
    auto_increment(0)
 
222
  { }
 
223
 
178
224
} HP_SHARE;
179
225
 
180
226
struct st_hp_hash_info;
181
227
 
182
228
typedef struct st_heap_info
183
229
{
 
230
private:
184
231
  HP_SHARE *s;
 
232
public:
 
233
 
 
234
  HP_SHARE *getShare()
 
235
  {
 
236
    return s;
 
237
  }
 
238
 
 
239
  void setShare(HP_SHARE *s_arg)
 
240
  {
 
241
    s= s_arg;
 
242
  }
 
243
 
185
244
  unsigned char *current_ptr;
186
245
  struct st_hp_hash_info *current_hash_ptr;
187
246
  uint32_t current_record,next_block;
188
247
  int lastinx,errkey;
189
248
  int  mode;                            /* Mode of file (READONLY..) */
190
249
  uint32_t opt_flag,update;
191
 
  unsigned char *lastkey;                       /* Last used key with rkey */
192
 
  unsigned char *recbuf;                         /* Record buffer for rb-tree keys */
 
250
  std::vector <unsigned char> lastkey;                  /* Last used key with rkey */
193
251
  enum drizzled::ha_rkey_function last_find_flag;
194
 
  drizzled::TREE_ELEMENT *parents[drizzled::MAX_TREE_HEIGHT+1];
195
 
  drizzled::TREE_ELEMENT **last_pos;
196
252
  uint32_t lastkey_len;
197
 
  bool implicit_emptied;
198
253
  drizzled::THR_LOCK_DATA lock;
199
254
} HP_INFO;
200
255
 
204
259
  uint32_t auto_key;                        /* keynr [1 - maxkey] for auto key */
205
260
  uint32_t auto_key_type;
206
261
  uint32_t max_chunk_size;
207
 
  uint32_t is_dynamic;
208
262
  uint64_t max_table_size;
209
263
  uint64_t auto_increment;
210
264
  bool with_auto_increment;
225
279
extern int heap_delete(HP_INFO *info,const unsigned char *buff);
226
280
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
227
281
extern int heap_create(const char *name, uint32_t keys, HP_KEYDEF *keydef,
228
 
           uint32_t columns, HP_COLUMNDEF *columndef,
229
 
           uint32_t max_key_fieldnr, uint32_t key_part_size,
 
282
           uint32_t columns, 
 
283
           uint32_t key_part_size,
230
284
           uint32_t reclength, uint32_t keys_memory_size,
231
285
           uint32_t max_records, uint32_t min_records,
232
286
           HP_CREATE_INFO *create_info, HP_SHARE **share);
233
287
 
234
288
extern int heap_delete_table(const char *name);
235
 
extern void heap_drop_table(HP_INFO *info);
236
289
extern int heap_extra(HP_INFO *info,enum drizzled::ha_extra_function function);
237
290
extern int heap_reset(HP_INFO *info);
238
291
extern int heap_rename(const char *old_name,const char *new_name);
247
300
extern int heap_enable_indexes(HP_INFO *info);
248
301
extern int heap_indexes_are_disabled(HP_INFO *info);
249
302
extern void heap_update_auto_increment(HP_INFO *info, const unsigned char *record);
250
 
drizzled::ha_rows hp_rb_records_in_range(HP_INFO *info,
251
 
                                         int inx, drizzled::key_range *min_key,
252
 
                                         drizzled::key_range *max_key);
253
303
int hp_panic(enum drizzled::ha_panic_function flag);
254
304
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
255
305
              drizzled::key_part_map keypart_map,
256
306
              enum drizzled::ha_rkey_function find_flag);
257
307
extern unsigned char * heap_find(HP_INFO *info,int inx,const unsigned char *key);
258
 
extern int heap_check_heap(HP_INFO *info, bool print_status);
259
308
extern unsigned char *heap_position(HP_INFO *info);
260
309
 
261
310
/* The following is for programs that uses the old HEAP interface where
264
313
 
265
314
typedef unsigned char *HEAP_PTR;
266
315
 
267
 
#endif /* PLUGIN_HEAP_HEAP_H */
 
316
#endif /* PLUGIN_MEMORY_HEAP_H */