~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000,2004 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
16
/* This file should be included when using heap_database_functions */
17
/* Author: Michael Widenius */
18
1122.2.10 by Monty Taylor
Fixed all of the include guards.
19
#ifndef PLUGIN_HEAP_HEAP_H
20
#define PLUGIN_HEAP_HEAP_H
21
243.1.11 by Jay Pipes
* Added include guards in a couple places, and removed unecessary
22
#include <drizzled/base.h>
543 by Monty Taylor
Renamed drizzle_common again. Removed sql_common. (empty)
23
#include <drizzled/common.h>
1241.9.64 by Monty Taylor
Moved remaining non-public portions of mysys and mystrings to drizzled/internal.
24
#include "drizzled/internal/my_pthread.h"
1241.9.43 by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both.
25
#include <drizzled/thr_lock.h>
1 by brian
clean slate
26
992.1.25 by Monty Taylor
Moved myisam to new plugin system.
27
#include <plugin/myisam/my_handler.h>
1241.9.55 by Monty Taylor
Moved tree into drizzled/
28
#include "drizzled/my_tree.h"
1 by brian
clean slate
29
30
	/* defines used by heap-funktions */
31
32
#define HP_MAX_LEVELS	4		/* 128^5 records is enough */
33
#define HP_PTRS_IN_NOD	128
34
35
	/* struct used with heap_funktions */
36
37
typedef struct st_heapinfo		/* Struct from heap_info */
38
{
291 by Brian Aker
Head ulong conversion.
39
  uint32_t records;			/* Records in database */
40
  uint32_t deleted;			/* Deleted records in database */
41
  uint32_t max_records;
151 by Brian Aker
Ulonglong to uint64_t
42
  uint64_t data_length;
43
  uint64_t index_length;
482 by Brian Aker
Remove uint.
44
  uint32_t reclength;			/* Length of one record */
1 by brian
clean slate
45
  int errkey;
151 by Brian Aker
Ulonglong to uint64_t
46
  uint64_t auto_increment;
1 by brian
clean slate
47
} HEAPINFO;
48
49
50
	/* Structs used by heap-database-handler */
51
52
typedef struct st_heap_ptrs
53
{
481 by Brian Aker
Remove all of uchar.
54
  unsigned char *blocks[HP_PTRS_IN_NOD];		/* pointers to HP_PTRS or records */
1 by brian
clean slate
55
} HP_PTRS;
56
57
struct st_level_info
58
{
59
  /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
482 by Brian Aker
Remove uint.
60
  uint32_t free_ptrs_in_block;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
61
1 by brian
clean slate
62
  /*
63
    Maximum number of records that can be 'contained' inside of each element
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
64
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for
1 by brian
clean slate
65
    level 2 - HP_PTRS_IN_NOD^2 and so forth.
66
  */
291 by Brian Aker
Head ulong conversion.
67
  uint32_t records_under_level;
1 by brian
clean slate
68
69
  /*
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
70
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this
1 by brian
clean slate
71
    level.
72
  */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
73
  HP_PTRS *last_blocks;
1 by brian
clean slate
74
};
75
76
77
/*
78
  Heap table records and hash index entries are stored in HP_BLOCKs.
79
  HP_BLOCK is used as a 'growable array' of fixed-size records. Size of record
80
  is recbuffer bytes.
81
  The internal representation is as follows:
82
  HP_BLOCK is a hierarchical structure of 'blocks'.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
83
  A block at level 0 is an array records_in_block records.
84
  A block at higher level is an HP_PTRS structure with pointers to blocks at
1 by brian
clean slate
85
  lower levels.
86
  At the highest level there is one top block. It is stored in HP_BLOCK::root.
87
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
88
  See hp_find_block for a description of how record pointer is obtained from
1 by brian
clean slate
89
  its index.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
90
  See hp_get_new_block
1 by brian
clean slate
91
*/
92
93
typedef struct st_heap_block
94
{
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
95
  HP_PTRS *root;                        /* Top-level block */
1 by brian
clean slate
96
  struct st_level_info level_info[HP_MAX_LEVELS+1];
482 by Brian Aker
Remove uint.
97
  uint32_t levels;                          /* number of used levels */
98
  uint32_t records_in_block;		/* Records in one heap-block */
99
  uint32_t recbuffer;			/* Length of one saved record */
291 by Brian Aker
Head ulong conversion.
100
  uint32_t last_allocated; /* number of records there is allocated space for */
1 by brian
clean slate
101
} HP_BLOCK;
102
103
struct st_heap_info;			/* For referense */
104
105
typedef struct st_hp_keydef		/* Key definition with open */
106
{
482 by Brian Aker
Remove uint.
107
  uint32_t flag;				/* HA_NOSAME | HA_NULL_PART_KEY */
108
  uint32_t keysegs;				/* Number of key-segment */
109
  uint32_t length;				/* Length of key (automatic) */
206 by Brian Aker
Removed final uint dead types.
110
  uint8_t algorithm;			/* HASH / BTREE */
1 by brian
clean slate
111
  HA_KEYSEG *seg;
112
  HP_BLOCK block;			/* Where keys are saved */
113
  /*
114
    Number of buckets used in hash table. Used only to provide
115
    #records estimates for heap key scans.
116
  */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
117
  drizzled::ha_rows hash_buckets;
118
  drizzled::TREE rb_tree;
1 by brian
clean slate
119
  int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
481 by Brian Aker
Remove all of uchar.
120
		   const unsigned char *record, unsigned char *recpos);
1 by brian
clean slate
121
  int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
481 by Brian Aker
Remove all of uchar.
122
		   const unsigned char *record, unsigned char *recpos, int flag);
482 by Brian Aker
Remove uint.
123
  uint32_t (*get_key_length)(struct st_hp_keydef *keydef, const unsigned char *key);
1 by brian
clean slate
124
} HP_KEYDEF;
125
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
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;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
135
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
136
typedef struct st_heap_dataspace   /* control data for data space */
137
{
138
  HP_BLOCK block;
482 by Brian Aker
Remove uint.
139
  uint32_t chunk_count;             /* Total chunks ever allocated in this dataspace */
140
  uint32_t del_chunk_count;         /* Deleted chunks count */
481 by Brian Aker
Remove all of uchar.
141
  unsigned char *del_link;               /* Link to last deleted chunk */
482 by Brian Aker
Remove uint.
142
  uint32_t chunk_length;            /* Total length of one chunk */
143
  uint32_t chunk_dataspace_length;  /* Length of payload that will be placed into one chunk */
144
  uint32_t offset_status;           /* Offset of the status flag relative to the chunk start */
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 */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
147
  uint64_t total_data_length;  /* Total size allocated within this data space */
148
} HP_DATASPACE;
149
150
1 by brian
clean slate
151
typedef struct st_heap_share
152
{
153
  HP_KEYDEF  *keydef;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
154
  HP_COLUMNDEF *column_defs;
155
  HP_DATASPACE recordspace;  /* Describes "block", which contains actual records */
156
291 by Brian Aker
Head ulong conversion.
157
  uint32_t min_records,max_records;	/* Params to open */
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
158
  uint64_t index_length,max_table_size;
482 by Brian Aker
Remove uint.
159
  uint32_t key_stat_version;                /* version to indicate insert/delete */
160
  uint32_t records;             /* Actual record (row) count */
161
  uint32_t blength;                                     /* used_chunk_count rounded up to 2^n */
162
  uint32_t fixed_data_length;     /* Length of record's fixed part, which contains keys and always fits into the first chunk */
163
  uint32_t fixed_column_count;  /* Number of columns stored in fixed_data_length */
164
  uint32_t changed;
165
  uint32_t keys,max_key_length;
166
  uint32_t column_count;
167
  uint32_t currently_disabled_keys;    /* saved value from "keys" when disabled */
168
  uint32_t open_count;
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
169
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
170
1 by brian
clean slate
171
  char * name;			/* Name of "memory-file" */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
172
  drizzled::THR_LOCK lock;
1 by brian
clean slate
173
  pthread_mutex_t intern_lock;		/* Locking for use with _locking */
280 by Brian Aker
Removed my_bool from heap engine.
174
  bool delete_on_close;
482 by Brian Aker
Remove uint.
175
  uint32_t auto_key;
176
  uint32_t auto_key_type;			/* real type of the auto key segment */
151 by Brian Aker
Ulonglong to uint64_t
177
  uint64_t auto_increment;
1 by brian
clean slate
178
} HP_SHARE;
179
180
struct st_hp_hash_info;
181
182
typedef struct st_heap_info
183
{
184
  HP_SHARE *s;
481 by Brian Aker
Remove all of uchar.
185
  unsigned char *current_ptr;
1 by brian
clean slate
186
  struct st_hp_hash_info *current_hash_ptr;
291 by Brian Aker
Head ulong conversion.
187
  uint32_t current_record,next_block;
1 by brian
clean slate
188
  int lastinx,errkey;
189
  int  mode;				/* Mode of file (READONLY..) */
482 by Brian Aker
Remove uint.
190
  uint32_t opt_flag,update;
481 by Brian Aker
Remove all of uchar.
191
  unsigned char *lastkey;			/* Last used key with rkey */
192
  unsigned char *recbuf;                         /* Record buffer for rb-tree keys */
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
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;
482 by Brian Aker
Remove uint.
196
  uint32_t lastkey_len;
280 by Brian Aker
Removed my_bool from heap engine.
197
  bool implicit_emptied;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
198
  drizzled::THR_LOCK_DATA lock;
1 by brian
clean slate
199
} HP_INFO;
200
201
202
typedef struct st_heap_create_info
203
{
482 by Brian Aker
Remove uint.
204
  uint32_t auto_key;                        /* keynr [1 - maxkey] for auto key */
205
  uint32_t auto_key_type;
206
  uint32_t max_chunk_size;
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
207
  uint32_t is_dynamic;
151 by Brian Aker
Ulonglong to uint64_t
208
  uint64_t max_table_size;
209
  uint64_t auto_increment;
280 by Brian Aker
Removed my_bool from heap engine.
210
  bool with_auto_increment;
211
  bool internal_table;
1 by brian
clean slate
212
} HP_CREATE_INFO;
213
214
	/* Prototypes for heap-functions */
215
216
extern HP_INFO *heap_open(const char *name, int mode);
217
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
218
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
219
extern int heap_close(HP_INFO *info);
481 by Brian Aker
Remove all of uchar.
220
extern int heap_write(HP_INFO *info,const unsigned char *record);
221
extern int heap_update(HP_INFO *info,const unsigned char *old_record,const unsigned char *new_record);
222
extern int heap_rrnd(HP_INFO *info,unsigned char *buf,unsigned char *pos);
1 by brian
clean slate
223
extern int heap_scan_init(HP_INFO *info);
481 by Brian Aker
Remove all of uchar.
224
extern int heap_scan(register HP_INFO *info, unsigned char *record);
225
extern int heap_delete(HP_INFO *info,const unsigned char *buff);
1 by brian
clean slate
226
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
482 by Brian Aker
Remove uint.
227
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,
230
           uint32_t reclength, uint32_t keys_memory_size,
291 by Brian Aker
Head ulong conversion.
231
           uint32_t max_records, uint32_t min_records,
244.1.1 by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns.
232
           HP_CREATE_INFO *create_info, HP_SHARE **share);
233
1 by brian
clean slate
234
extern int heap_delete_table(const char *name);
235
extern void heap_drop_table(HP_INFO *info);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
236
extern int heap_extra(HP_INFO *info,enum drizzled::ha_extra_function function);
1 by brian
clean slate
237
extern int heap_reset(HP_INFO *info);
238
extern int heap_rename(const char *old_name,const char *new_name);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
239
extern int heap_panic(enum drizzled::ha_panic_function flag);
481 by Brian Aker
Remove all of uchar.
240
extern int heap_rsame(HP_INFO *info,unsigned char *record,int inx);
241
extern int heap_rnext(HP_INFO *info,unsigned char *record);
242
extern int heap_rprev(HP_INFO *info,unsigned char *record);
243
extern int heap_rfirst(HP_INFO *info,unsigned char *record,int inx);
244
extern int heap_rlast(HP_INFO *info,unsigned char *record,int inx);
1 by brian
clean slate
245
extern void heap_clear(HP_INFO *info);
246
extern int heap_disable_indexes(HP_INFO *info);
247
extern int heap_enable_indexes(HP_INFO *info);
248
extern int heap_indexes_are_disabled(HP_INFO *info);
481 by Brian Aker
Remove all of uchar.
249
extern void heap_update_auto_increment(HP_INFO *info, const unsigned char *record);
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
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
int hp_panic(enum drizzled::ha_panic_function flag);
481 by Brian Aker
Remove all of uchar.
254
int heap_rkey(HP_INFO *info, unsigned char *record, int inx, const unsigned char *key,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
255
              drizzled::key_part_map keypart_map,
256
              enum drizzled::ha_rkey_function find_flag);
481 by Brian Aker
Remove all of uchar.
257
extern unsigned char * heap_find(HP_INFO *info,int inx,const unsigned char *key);
280 by Brian Aker
Removed my_bool from heap engine.
258
extern int heap_check_heap(HP_INFO *info, bool print_status);
481 by Brian Aker
Remove all of uchar.
259
extern unsigned char *heap_position(HP_INFO *info);
1 by brian
clean slate
260
261
/* The following is for programs that uses the old HEAP interface where
481 by Brian Aker
Remove all of uchar.
262
   pointer to rows where a long instead of a (unsigned char*).
1 by brian
clean slate
263
*/
264
481 by Brian Aker
Remove all of uchar.
265
typedef unsigned char *HEAP_PTR;
1 by brian
clean slate
266
1122.2.10 by Monty Taylor
Fixed all of the include guards.
267
#endif /* PLUGIN_HEAP_HEAP_H */