~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/heap.h

  • Committer: Monty Taylor
  • Date: 2010-03-02 19:10:25 UTC
  • mto: (1317.1.8)
  • mto: This revision was merged to the branch mainline in revision 1322.
  • Revision ID: mordred@inaugust.com-20100302191025-zoxjz4xwkoa6160h
Prevent unauthorized users from changing schema.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
2
 
  Copyright (C) Brian Aker
3
 
    Copyright (C) 2000,2004 MySQL AB
 
1
/* Copyright (C) 2000,2004 MySQL AB
4
2
 
5
3
   This program is free software; you can redistribute it and/or modify
6
4
   it under the terms of the GNU General Public License as published by
13
11
 
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 */
17
15
 
18
16
/* This file should be included when using heap_database_functions */
19
17
/* Author: Michael Widenius */
20
18
 
21
 
#ifndef PLUGIN_MEMORY_HEAP_H
22
 
#define PLUGIN_MEMORY_HEAP_H
 
19
#ifndef PLUGIN_HEAP_HEAP_H
 
20
#define PLUGIN_HEAP_HEAP_H
23
21
 
24
22
#include <drizzled/base.h>
25
23
#include <drizzled/common.h>
27
25
#include <drizzled/thr_lock.h>
28
26
 
29
27
#include <plugin/myisam/my_handler.h>
30
 
#include "drizzled/tree.h"
31
 
 
32
 
#include <vector>
 
28
#include "drizzled/my_tree.h"
33
29
 
34
30
        /* defines used by heap-funktions */
35
31
 
48
44
  uint32_t reclength;                   /* Length of one record */
49
45
  int errkey;
50
46
  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
 
 
63
47
} HEAPINFO;
64
48
 
65
49
 
87
71
    level.
88
72
  */
89
73
  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
 
  { }
96
74
};
97
75
 
98
76
 
120
98
  uint32_t records_in_block;            /* Records in one heap-block */
121
99
  uint32_t recbuffer;                   /* Length of one saved record */
122
100
  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
 
  }
132
101
} HP_BLOCK;
133
102
 
134
103
struct st_heap_info;                    /* For referense */
138
107
  uint32_t flag;                                /* HA_NOSAME | HA_NULL_PART_KEY */
139
108
  uint32_t keysegs;                             /* Number of key-segment */
140
109
  uint32_t length;                              /* Length of key (automatic) */
 
110
  uint8_t algorithm;                    /* HASH / BTREE */
141
111
  HA_KEYSEG *seg;
142
112
  HP_BLOCK block;                       /* Where keys are saved */
143
113
  /*
145
115
    #records estimates for heap key scans.
146
116
  */
147
117
  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);
148
124
} HP_KEYDEF;
149
125
 
 
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
 
150
136
typedef struct st_heap_dataspace   /* control data for data space */
151
137
{
152
138
  HP_BLOCK block;
157
143
  uint32_t chunk_dataspace_length;  /* Length of payload that will be placed into one chunk */
158
144
  uint32_t offset_status;           /* Offset of the status flag relative to the chunk start */
159
145
  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 */
160
147
  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
 
 
173
148
} HP_DATASPACE;
174
149
 
175
150
 
176
151
typedef struct st_heap_share
177
152
{
178
153
  HP_KEYDEF  *keydef;
 
154
  HP_COLUMNDEF *column_defs;
179
155
  HP_DATASPACE recordspace;  /* Describes "block", which contains actual records */
180
156
 
181
157
  uint32_t min_records,max_records;     /* Params to open */
192
168
  uint32_t open_count;
193
169
 
194
170
 
195
 
  std::string name;                     /* Name of "memory-file" */
 
171
  char * name;                  /* Name of "memory-file" */
 
172
  drizzled::THR_LOCK lock;
 
173
  pthread_mutex_t intern_lock;          /* Locking for use with _locking */
196
174
  bool delete_on_close;
197
175
  uint32_t auto_key;
198
176
  uint32_t auto_key_type;                       /* real type of the auto key segment */
199
177
  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
 
 
224
178
} HP_SHARE;
225
179
 
226
180
struct st_hp_hash_info;
227
181
 
228
182
typedef struct st_heap_info
229
183
{
230
 
private:
231
184
  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
 
 
244
185
  unsigned char *current_ptr;
245
186
  struct st_hp_hash_info *current_hash_ptr;
246
187
  uint32_t current_record,next_block;
247
188
  int lastinx,errkey;
248
189
  int  mode;                            /* Mode of file (READONLY..) */
249
190
  uint32_t opt_flag,update;
250
 
  std::vector <unsigned char> lastkey;                  /* Last used key with rkey */
 
191
  unsigned char *lastkey;                       /* Last used key with rkey */
 
192
  unsigned char *recbuf;                         /* Record buffer for rb-tree keys */
251
193
  enum drizzled::ha_rkey_function last_find_flag;
 
194
  drizzled::TREE_ELEMENT *parents[drizzled::MAX_TREE_HEIGHT+1];
 
195
  drizzled::TREE_ELEMENT **last_pos;
252
196
  uint32_t lastkey_len;
 
197
  bool implicit_emptied;
253
198
  drizzled::THR_LOCK_DATA lock;
254
199
} HP_INFO;
255
200
 
259
204
  uint32_t auto_key;                        /* keynr [1 - maxkey] for auto key */
260
205
  uint32_t auto_key_type;
261
206
  uint32_t max_chunk_size;
 
207
  uint32_t is_dynamic;
262
208
  uint64_t max_table_size;
263
209
  uint64_t auto_increment;
264
210
  bool with_auto_increment;
279
225
extern int heap_delete(HP_INFO *info,const unsigned char *buff);
280
226
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
281
227
extern int heap_create(const char *name, uint32_t keys, HP_KEYDEF *keydef,
282
 
           uint32_t columns, 
283
 
           uint32_t key_part_size,
 
228
           uint32_t columns, HP_COLUMNDEF *columndef,
 
229
           uint32_t max_key_fieldnr, uint32_t key_part_size,
284
230
           uint32_t reclength, uint32_t keys_memory_size,
285
231
           uint32_t max_records, uint32_t min_records,
286
232
           HP_CREATE_INFO *create_info, HP_SHARE **share);
287
233
 
288
234
extern int heap_delete_table(const char *name);
 
235
extern void heap_drop_table(HP_INFO *info);
289
236
extern int heap_extra(HP_INFO *info,enum drizzled::ha_extra_function function);
290
237
extern int heap_reset(HP_INFO *info);
291
238
extern int heap_rename(const char *old_name,const char *new_name);
300
247
extern int heap_enable_indexes(HP_INFO *info);
301
248
extern int heap_indexes_are_disabled(HP_INFO *info);
302
249
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);
303
253
int hp_panic(enum drizzled::ha_panic_function flag);
304
254
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
305
255
              drizzled::key_part_map keypart_map,
306
256
              enum drizzled::ha_rkey_function find_flag);
307
257
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);
308
259
extern unsigned char *heap_position(HP_INFO *info);
309
260
 
310
261
/* The following is for programs that uses the old HEAP interface where
313
264
 
314
265
typedef unsigned char *HEAP_PTR;
315
266
 
316
 
#endif /* PLUGIN_MEMORY_HEAP_H */
 
267
#endif /* PLUGIN_HEAP_HEAP_H */