~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/heap/heap.h

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
/* This file should be included when using heap_database_functions */
17
17
/* Author: Michael Widenius */
18
18
 
19
 
#ifndef _heap_h
20
 
#define _heap_h
 
19
#ifndef PLUGIN_HEAP_HEAP_H
 
20
#define PLUGIN_HEAP_HEAP_H
 
21
 
21
22
#ifdef  __cplusplus
22
23
extern "C" {
23
24
#endif
24
25
 
25
26
#include <drizzled/base.h>
26
 
#include <mysys/my_pthread.h>
27
 
#include <mysys/thr_lock.h>
 
27
#include <drizzled/common.h>
 
28
#include "drizzled/internal/my_pthread.h"
 
29
#include <drizzled/thr_lock.h>
28
30
 
29
 
#include <mysys/my_handler.h>
30
 
#include <mysys/my_tree.h>
 
31
#include <plugin/myisam/my_handler.h>
 
32
#include "drizzled/my_tree.h"
31
33
 
32
34
        /* defines used by heap-funktions */
33
35
 
43
45
  uint32_t max_records;
44
46
  uint64_t data_length;
45
47
  uint64_t index_length;
46
 
  uint reclength;                       /* Length of one record */
 
48
  uint32_t reclength;                   /* Length of one record */
47
49
  int errkey;
48
50
  uint64_t auto_increment;
49
51
} HEAPINFO;
53
55
 
54
56
typedef struct st_heap_ptrs
55
57
{
56
 
  uchar *blocks[HP_PTRS_IN_NOD];                /* pointers to HP_PTRS or records */
 
58
  unsigned char *blocks[HP_PTRS_IN_NOD];                /* pointers to HP_PTRS or records */
57
59
} HP_PTRS;
58
60
 
59
61
struct st_level_info
60
62
{
61
63
  /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
62
 
  uint free_ptrs_in_block;
63
 
  
 
64
  uint32_t free_ptrs_in_block;
 
65
 
64
66
  /*
65
67
    Maximum number of records that can be 'contained' inside of each element
66
 
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for 
 
68
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for
67
69
    level 2 - HP_PTRS_IN_NOD^2 and so forth.
68
70
  */
69
71
  uint32_t records_under_level;
70
72
 
71
73
  /*
72
 
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this 
 
74
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this
73
75
    level.
74
76
  */
75
 
  HP_PTRS *last_blocks;                 
 
77
  HP_PTRS *last_blocks;
76
78
};
77
79
 
78
80
 
82
84
  is recbuffer bytes.
83
85
  The internal representation is as follows:
84
86
  HP_BLOCK is a hierarchical structure of 'blocks'.
85
 
  A block at level 0 is an array records_in_block records. 
86
 
  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
87
89
  lower levels.
88
90
  At the highest level there is one top block. It is stored in HP_BLOCK::root.
89
91
 
90
 
  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
91
93
  its index.
92
 
  See hp_get_new_block 
 
94
  See hp_get_new_block
93
95
*/
94
96
 
95
97
typedef struct st_heap_block
96
98
{
97
 
  HP_PTRS *root;                        /* Top-level block */ 
 
99
  HP_PTRS *root;                        /* Top-level block */
98
100
  struct st_level_info level_info[HP_MAX_LEVELS+1];
99
 
  uint levels;                          /* number of used levels */
100
 
  uint records_in_block;                /* Records in one heap-block */
101
 
  uint recbuffer;                       /* Length of one saved record */
 
101
  uint32_t levels;                          /* number of used levels */
 
102
  uint32_t records_in_block;            /* Records in one heap-block */
 
103
  uint32_t recbuffer;                   /* Length of one saved record */
102
104
  uint32_t last_allocated; /* number of records there is allocated space for */
103
105
} HP_BLOCK;
104
106
 
106
108
 
107
109
typedef struct st_hp_keydef             /* Key definition with open */
108
110
{
109
 
  uint flag;                            /* HA_NOSAME | HA_NULL_PART_KEY */
110
 
  uint keysegs;                         /* Number of key-segment */
111
 
  uint length;                          /* Length of key (automatic) */
 
111
  uint32_t flag;                                /* HA_NOSAME | HA_NULL_PART_KEY */
 
112
  uint32_t keysegs;                             /* Number of key-segment */
 
113
  uint32_t length;                              /* Length of key (automatic) */
112
114
  uint8_t algorithm;                    /* HASH / BTREE */
113
115
  HA_KEYSEG *seg;
114
116
  HP_BLOCK block;                       /* Where keys are saved */
116
118
    Number of buckets used in hash table. Used only to provide
117
119
    #records estimates for heap key scans.
118
120
  */
119
 
  ha_rows hash_buckets; 
 
121
  ha_rows hash_buckets;
120
122
  TREE rb_tree;
121
123
  int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
122
 
                   const uchar *record, uchar *recpos);
 
124
                   const unsigned char *record, unsigned char *recpos);
123
125
  int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
124
 
                   const uchar *record, uchar *recpos, int flag);
125
 
  uint (*get_key_length)(struct st_hp_keydef *keydef, const uchar *key);
 
126
                   const unsigned char *record, unsigned char *recpos, int flag);
 
127
  uint32_t (*get_key_length)(struct st_hp_keydef *keydef, const unsigned char *key);
126
128
} HP_KEYDEF;
127
129
 
128
130
typedef struct st_heap_columndef              /* column information */
134
136
  uint16_t null_pos;                    /* position for null marker */
135
137
  uint8_t  length_bytes;  /* length of the size, 1 o 2 bytes */
136
138
} HP_COLUMNDEF;
137
 
 
 
139
 
138
140
typedef struct st_heap_dataspace   /* control data for data space */
139
141
{
140
142
  HP_BLOCK block;
141
 
  uint chunk_count;             /* Total chunks ever allocated in this dataspace */
142
 
  uint del_chunk_count;         /* Deleted chunks count */
143
 
  uchar *del_link;               /* Link to last deleted chunk */
144
 
  uint chunk_length;            /* Total length of one chunk */
145
 
  uint chunk_dataspace_length;  /* Length of payload that will be placed into one chunk */
146
 
  uint offset_status;           /* Offset of the status flag relative to the chunk start */
147
 
  uint offset_link;             /* Offset of the linking pointer relative to the chunk start */
148
 
  uint is_variable_size;          /* Test whether records have variable size and so "next" pointer */
 
143
  uint32_t chunk_count;             /* Total chunks ever allocated in this dataspace */
 
144
  uint32_t del_chunk_count;         /* Deleted chunks count */
 
145
  unsigned char *del_link;               /* Link to last deleted chunk */
 
146
  uint32_t chunk_length;            /* Total length of one chunk */
 
147
  uint32_t chunk_dataspace_length;  /* Length of payload that will be placed into one chunk */
 
148
  uint32_t offset_status;           /* Offset of the status flag relative to the chunk start */
 
149
  uint32_t offset_link;             /* Offset of the linking pointer relative to the chunk start */
 
150
  uint32_t is_variable_size;          /* Test whether records have variable size and so "next" pointer */
149
151
  uint64_t total_data_length;  /* Total size allocated within this data space */
150
152
} HP_DATASPACE;
151
153
 
158
160
 
159
161
  uint32_t min_records,max_records;     /* Params to open */
160
162
  uint64_t index_length,max_table_size;
161
 
  uint key_stat_version;                /* version to indicate insert/delete */
162
 
  uint records;             /* Actual record (row) count */
163
 
  uint blength;                                     /* used_chunk_count rounded up to 2^n */
164
 
  uint fixed_data_length;     /* Length of record's fixed part, which contains keys and always fits into the first chunk */
165
 
  uint fixed_column_count;  /* Number of columns stored in fixed_data_length */
166
 
  uint changed;
167
 
  uint keys,max_key_length;
168
 
  uint column_count;
169
 
  uint currently_disabled_keys;    /* saved value from "keys" when disabled */
170
 
  uint open_count;
171
 
 
172
 
  
 
163
  uint32_t key_stat_version;                /* version to indicate insert/delete */
 
164
  uint32_t records;             /* Actual record (row) count */
 
165
  uint32_t blength;                                     /* used_chunk_count rounded up to 2^n */
 
166
  uint32_t fixed_data_length;     /* Length of record's fixed part, which contains keys and always fits into the first chunk */
 
167
  uint32_t fixed_column_count;  /* Number of columns stored in fixed_data_length */
 
168
  uint32_t changed;
 
169
  uint32_t keys,max_key_length;
 
170
  uint32_t column_count;
 
171
  uint32_t currently_disabled_keys;    /* saved value from "keys" when disabled */
 
172
  uint32_t open_count;
 
173
 
 
174
 
173
175
  char * name;                  /* Name of "memory-file" */
174
176
  THR_LOCK lock;
175
177
  pthread_mutex_t intern_lock;          /* Locking for use with _locking */
176
178
  bool delete_on_close;
177
 
  LIST open_list;
178
 
  uint auto_key;
179
 
  uint auto_key_type;                   /* real type of the auto key segment */
 
179
  uint32_t auto_key;
 
180
  uint32_t auto_key_type;                       /* real type of the auto key segment */
180
181
  uint64_t auto_increment;
181
182
} HP_SHARE;
182
183
 
185
186
typedef struct st_heap_info
186
187
{
187
188
  HP_SHARE *s;
188
 
  uchar *current_ptr;
 
189
  unsigned char *current_ptr;
189
190
  struct st_hp_hash_info *current_hash_ptr;
190
191
  uint32_t current_record,next_block;
191
192
  int lastinx,errkey;
192
193
  int  mode;                            /* Mode of file (READONLY..) */
193
 
  uint opt_flag,update;
194
 
  uchar *lastkey;                       /* Last used key with rkey */
195
 
  uchar *recbuf;                         /* Record buffer for rb-tree keys */
 
194
  uint32_t opt_flag,update;
 
195
  unsigned char *lastkey;                       /* Last used key with rkey */
 
196
  unsigned char *recbuf;                         /* Record buffer for rb-tree keys */
196
197
  enum ha_rkey_function last_find_flag;
197
198
  TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
198
199
  TREE_ELEMENT **last_pos;
199
 
  uint lastkey_len;
 
200
  uint32_t lastkey_len;
200
201
  bool implicit_emptied;
201
202
  THR_LOCK_DATA lock;
202
 
  LIST open_list;
203
203
} HP_INFO;
204
204
 
205
205
 
206
206
typedef struct st_heap_create_info
207
207
{
208
 
  uint auto_key;                        /* keynr [1 - maxkey] for auto key */
209
 
  uint auto_key_type;
210
 
  uint max_chunk_size;
211
 
  uint is_dynamic;  
 
208
  uint32_t auto_key;                        /* keynr [1 - maxkey] for auto key */
 
209
  uint32_t auto_key_type;
 
210
  uint32_t max_chunk_size;
 
211
  uint32_t is_dynamic;
212
212
  uint64_t max_table_size;
213
213
  uint64_t auto_increment;
214
214
  bool with_auto_increment;
221
221
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
222
222
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
223
223
extern int heap_close(HP_INFO *info);
224
 
extern int heap_write(HP_INFO *info,const uchar *record);
225
 
extern int heap_update(HP_INFO *info,const uchar *old_record,const uchar *new_record);
226
 
extern int heap_rrnd(HP_INFO *info,uchar *buf,uchar *pos);
 
224
extern int heap_write(HP_INFO *info,const unsigned char *record);
 
225
extern int heap_update(HP_INFO *info,const unsigned char *old_record,const unsigned char *new_record);
 
226
extern int heap_rrnd(HP_INFO *info,unsigned char *buf,unsigned char *pos);
227
227
extern int heap_scan_init(HP_INFO *info);
228
 
extern int heap_scan(register HP_INFO *info, uchar *record);
229
 
extern int heap_delete(HP_INFO *info,const uchar *buff);
 
228
extern int heap_scan(register HP_INFO *info, unsigned char *record);
 
229
extern int heap_delete(HP_INFO *info,const unsigned char *buff);
230
230
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
231
 
extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
232
 
           uint columns, HP_COLUMNDEF *columndef,
233
 
           uint max_key_fieldnr, uint key_part_size,
234
 
           uint reclength, uint keys_memory_size,
 
231
extern int heap_create(const char *name, uint32_t keys, HP_KEYDEF *keydef,
 
232
           uint32_t columns, HP_COLUMNDEF *columndef,
 
233
           uint32_t max_key_fieldnr, uint32_t key_part_size,
 
234
           uint32_t reclength, uint32_t keys_memory_size,
235
235
           uint32_t max_records, uint32_t min_records,
236
236
           HP_CREATE_INFO *create_info, HP_SHARE **share);
237
237
 
241
241
extern int heap_reset(HP_INFO *info);
242
242
extern int heap_rename(const char *old_name,const char *new_name);
243
243
extern int heap_panic(enum ha_panic_function flag);
244
 
extern int heap_rsame(HP_INFO *info,uchar *record,int inx);
245
 
extern int heap_rnext(HP_INFO *info,uchar *record);
246
 
extern int heap_rprev(HP_INFO *info,uchar *record);
247
 
extern int heap_rfirst(HP_INFO *info,uchar *record,int inx);
248
 
extern int heap_rlast(HP_INFO *info,uchar *record,int inx);
 
244
extern int heap_rsame(HP_INFO *info,unsigned char *record,int inx);
 
245
extern int heap_rnext(HP_INFO *info,unsigned char *record);
 
246
extern int heap_rprev(HP_INFO *info,unsigned char *record);
 
247
extern int heap_rfirst(HP_INFO *info,unsigned char *record,int inx);
 
248
extern int heap_rlast(HP_INFO *info,unsigned char *record,int inx);
249
249
extern void heap_clear(HP_INFO *info);
250
 
extern void heap_clear_keys(HP_INFO *info);
251
250
extern int heap_disable_indexes(HP_INFO *info);
252
251
extern int heap_enable_indexes(HP_INFO *info);
253
252
extern int heap_indexes_are_disabled(HP_INFO *info);
254
 
extern void heap_update_auto_increment(HP_INFO *info, const uchar *record);
 
253
extern void heap_update_auto_increment(HP_INFO *info, const unsigned char *record);
255
254
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
256
255
                               key_range *max_key);
257
256
int hp_panic(enum ha_panic_function flag);
258
 
int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key,
 
257
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
259
258
              key_part_map keypart_map, enum ha_rkey_function find_flag);
260
 
extern uchar * heap_find(HP_INFO *info,int inx,const uchar *key);
 
259
extern unsigned char * heap_find(HP_INFO *info,int inx,const unsigned char *key);
261
260
extern int heap_check_heap(HP_INFO *info, bool print_status);
262
 
extern uchar *heap_position(HP_INFO *info);
 
261
extern unsigned char *heap_position(HP_INFO *info);
263
262
 
264
263
/* The following is for programs that uses the old HEAP interface where
265
 
   pointer to rows where a long instead of a (uchar*).
 
264
   pointer to rows where a long instead of a (unsigned char*).
266
265
*/
267
266
 
268
 
#if defined(WANT_OLD_HEAP_VERSION) || defined(OLD_HEAP_VERSION)
269
 
extern int heap_rrnd_old(HP_INFO *info,uchar *buf,uint32_t pos);
270
 
extern uint32_t heap_position_old(HP_INFO *info);
271
 
#endif
272
 
#ifdef OLD_HEAP_VERSION
273
 
typedef uint32_t HEAP_PTR;
274
 
#define heap_position(A) heap_position_old(A)
275
 
#define heap_rrnd(A,B,C) heap_rrnd_old(A,B,C)
276
 
#else
277
 
typedef uchar *HEAP_PTR;
278
 
#endif
 
267
typedef unsigned char *HEAP_PTR;
279
268
 
280
269
#ifdef  __cplusplus
281
270
}
282
271
#endif
283
 
#endif
 
272
 
 
273
#endif /* PLUGIN_HEAP_HEAP_H */