~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/heap/heap.h

  • Committer: Jay Pipes
  • Date: 2008-09-11 16:03:22 UTC
  • mto: (383.5.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 386.
  • Revision ID: jay@mysql.com-20080911160322-vrl0k1djo6q6ytv1
Removed SQL_MODE variances from comment_table.test and ensured correct error thrown when a comment that is too long was input.  After moving to proto buffer definition for table, the 2048 length will go away.

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 _heap_h
 
20
#define _heap_h
 
21
#ifdef  __cplusplus
 
22
extern "C" {
 
23
#endif
23
24
 
24
25
#include <drizzled/base.h>
25
 
#include <drizzled/common.h>
26
 
#include "drizzled/internal/my_pthread.h"
27
 
#include <drizzled/thr_lock.h>
28
 
 
29
 
#include <plugin/myisam/my_handler.h>
30
 
#include "drizzled/tree.h"
31
 
 
32
 
#include <vector>
 
26
#include <mysys/my_pthread.h>
 
27
#include <mysys/thr_lock.h>
 
28
 
 
29
#include <mysys/my_handler.h>
 
30
#include <mysys/my_tree.h>
33
31
 
34
32
        /* defines used by heap-funktions */
35
33
 
45
43
  uint32_t max_records;
46
44
  uint64_t data_length;
47
45
  uint64_t index_length;
48
 
  uint32_t reclength;                   /* Length of one record */
 
46
  uint reclength;                       /* Length of one record */
49
47
  int errkey;
50
48
  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
49
} HEAPINFO;
64
50
 
65
51
 
67
53
 
68
54
typedef struct st_heap_ptrs
69
55
{
70
 
  unsigned char *blocks[HP_PTRS_IN_NOD];                /* pointers to HP_PTRS or records */
 
56
  uchar *blocks[HP_PTRS_IN_NOD];                /* pointers to HP_PTRS or records */
71
57
} HP_PTRS;
72
58
 
73
59
struct st_level_info
74
60
{
75
61
  /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
76
 
  uint32_t free_ptrs_in_block;
77
 
 
 
62
  uint free_ptrs_in_block;
 
63
  
78
64
  /*
79
65
    Maximum number of records that can be 'contained' inside of each element
80
 
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for
 
66
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for 
81
67
    level 2 - HP_PTRS_IN_NOD^2 and so forth.
82
68
  */
83
69
  uint32_t records_under_level;
84
70
 
85
71
  /*
86
 
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this
 
72
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this 
87
73
    level.
88
74
  */
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
 
  { }
 
75
  HP_PTRS *last_blocks;                 
96
76
};
97
77
 
98
78
 
102
82
  is recbuffer bytes.
103
83
  The internal representation is as follows:
104
84
  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
 
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 
107
87
  lower levels.
108
88
  At the highest level there is one top block. It is stored in HP_BLOCK::root.
109
89
 
110
 
  See hp_find_block for a description of how record pointer is obtained from
 
90
  See hp_find_block for a description of how record pointer is obtained from 
111
91
  its index.
112
 
  See hp_get_new_block
 
92
  See hp_get_new_block 
113
93
*/
114
94
 
115
95
typedef struct st_heap_block
116
96
{
117
 
  HP_PTRS *root;                        /* Top-level block */
 
97
  HP_PTRS *root;                        /* Top-level block */ 
118
98
  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 */
 
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 */
122
102
  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
103
} HP_BLOCK;
133
104
 
134
105
struct st_heap_info;                    /* For referense */
135
106
 
136
107
typedef struct st_hp_keydef             /* Key definition with open */
137
108
{
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) */
 
109
  uint flag;                            /* HA_NOSAME | HA_NULL_PART_KEY */
 
110
  uint keysegs;                         /* Number of key-segment */
 
111
  uint length;                          /* Length of key (automatic) */
 
112
  uint8_t algorithm;                    /* HASH / BTREE */
141
113
  HA_KEYSEG *seg;
142
114
  HP_BLOCK block;                       /* Where keys are saved */
143
115
  /*
144
116
    Number of buckets used in hash table. Used only to provide
145
117
    #records estimates for heap key scans.
146
118
  */
147
 
  drizzled::ha_rows hash_buckets;
 
119
  ha_rows hash_buckets; 
 
120
  TREE rb_tree;
 
121
  int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
 
122
                   const uchar *record, uchar *recpos);
 
123
  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);
148
126
} HP_KEYDEF;
149
127
 
 
128
typedef struct st_heap_columndef              /* column information */
 
129
{
 
130
  int16_t  type;                                /* en_fieldtype */
 
131
  uint32_t length;                      /* length of field */
 
132
  uint32_t offset;                      /* Offset to position in row */
 
133
  uint8_t  null_bit;                    /* If column may be 0 */
 
134
  uint16_t null_pos;                    /* position for null marker */
 
135
  uint8_t  length_bytes;  /* length of the size, 1 o 2 bytes */
 
136
} HP_COLUMNDEF;
 
137
 
150
138
typedef struct st_heap_dataspace   /* control data for data space */
151
139
{
152
140
  HP_BLOCK block;
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 */
 
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 */
160
149
  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
150
} HP_DATASPACE;
174
151
 
175
152
 
176
153
typedef struct st_heap_share
177
154
{
178
155
  HP_KEYDEF  *keydef;
 
156
  HP_COLUMNDEF *column_defs;
179
157
  HP_DATASPACE recordspace;  /* Describes "block", which contains actual records */
180
158
 
181
159
  uint32_t min_records,max_records;     /* Params to open */
182
160
  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 */
188
 
  uint32_t changed;
189
 
  uint32_t keys,max_key_length;
190
 
  uint32_t column_count;
191
 
  uint32_t currently_disabled_keys;    /* saved value from "keys" when disabled */
192
 
  uint32_t open_count;
193
 
 
194
 
 
195
 
  std::string name;                     /* Name of "memory-file" */
 
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
  
 
173
  char * name;                  /* Name of "memory-file" */
 
174
  THR_LOCK lock;
 
175
  pthread_mutex_t intern_lock;          /* Locking for use with _locking */
196
176
  bool delete_on_close;
197
 
  uint32_t auto_key;
198
 
  uint32_t auto_key_type;                       /* real type of the auto key segment */
 
177
  LIST open_list;
 
178
  uint auto_key;
 
179
  uint auto_key_type;                   /* real type of the auto key segment */
199
180
  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
181
} HP_SHARE;
225
182
 
226
183
struct st_hp_hash_info;
227
184
 
228
185
typedef struct st_heap_info
229
186
{
230
 
private:
231
187
  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
 
  unsigned char *current_ptr;
 
188
  uchar *current_ptr;
245
189
  struct st_hp_hash_info *current_hash_ptr;
246
190
  uint32_t current_record,next_block;
247
191
  int lastinx,errkey;
248
192
  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;
 
193
  uint opt_flag,update;
 
194
  uchar *lastkey;                       /* Last used key with rkey */
 
195
  uchar *recbuf;                         /* Record buffer for rb-tree keys */
 
196
  enum ha_rkey_function last_find_flag;
 
197
  TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
 
198
  TREE_ELEMENT **last_pos;
 
199
  uint lastkey_len;
 
200
  bool implicit_emptied;
 
201
  THR_LOCK_DATA lock;
 
202
  LIST open_list;
254
203
} HP_INFO;
255
204
 
256
205
 
257
206
typedef struct st_heap_create_info
258
207
{
259
 
  uint32_t auto_key;                        /* keynr [1 - maxkey] for auto key */
260
 
  uint32_t auto_key_type;
261
 
  uint32_t max_chunk_size;
 
208
  uint auto_key;                        /* keynr [1 - maxkey] for auto key */
 
209
  uint auto_key_type;
 
210
  uint max_chunk_size;
 
211
  uint is_dynamic;  
262
212
  uint64_t max_table_size;
263
213
  uint64_t auto_increment;
264
214
  bool with_auto_increment;
271
221
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
272
222
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
273
223
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);
 
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);
277
227
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);
 
228
extern int heap_scan(register HP_INFO *info, uchar *record);
 
229
extern int heap_delete(HP_INFO *info,const uchar *buff);
280
230
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,
282
 
           uint32_t columns, 
283
 
           uint32_t key_part_size,
284
 
           uint32_t reclength, uint32_t keys_memory_size,
 
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,
285
235
           uint32_t max_records, uint32_t min_records,
286
236
           HP_CREATE_INFO *create_info, HP_SHARE **share);
287
237
 
288
238
extern int heap_delete_table(const char *name);
289
 
extern int heap_extra(HP_INFO *info,enum drizzled::ha_extra_function function);
 
239
extern void heap_drop_table(HP_INFO *info);
 
240
extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
290
241
extern int heap_reset(HP_INFO *info);
291
242
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);
 
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);
298
249
extern void heap_clear(HP_INFO *info);
 
250
extern void heap_clear_keys(HP_INFO *info);
299
251
extern int heap_disable_indexes(HP_INFO *info);
300
252
extern int heap_enable_indexes(HP_INFO *info);
301
253
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);
 
254
extern void heap_update_auto_increment(HP_INFO *info, const uchar *record);
 
255
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
 
256
                               key_range *max_key);
 
257
int hp_panic(enum ha_panic_function flag);
 
258
int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key,
 
259
              key_part_map keypart_map, enum ha_rkey_function find_flag);
 
260
extern uchar * heap_find(HP_INFO *info,int inx,const uchar *key);
 
261
extern int heap_check_heap(HP_INFO *info, bool print_status);
 
262
extern uchar *heap_position(HP_INFO *info);
309
263
 
310
264
/* The following is for programs that uses the old HEAP interface where
311
 
   pointer to rows where a long instead of a (unsigned char*).
 
265
   pointer to rows where a long instead of a (uchar*).
312
266
*/
313
267
 
314
 
typedef unsigned char *HEAP_PTR;
 
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
315
279
 
316
 
#endif /* PLUGIN_MEMORY_HEAP_H */
 
280
#ifdef  __cplusplus
 
281
}
 
282
#endif
 
283
#endif