~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/heap.h

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

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