1749.3.3
by Brian Aker
Remove another layer of dead code in heap. |
1 |
/*
|
2 |
Copyright (C) Brian Aker
|
|
3 |
Copyright (C) 2000,2004 MySQL AB
|
|
1
by brian
clean slate |
4 |
|
5 |
This program is free software; you can redistribute it and/or modify
|
|
6 |
it under the terms of the GNU General Public License as published by
|
|
7 |
the Free Software Foundation; version 2 of the License.
|
|
8 |
||
9 |
This program is distributed in the hope that it will be useful,
|
|
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
GNU General Public License for more details.
|
|
13 |
||
14 |
You should have received a copy of the GNU General Public License
|
|
15 |
along with this program; if not, write to the Free Software
|
|
1802.10.2
by Monty Taylor
Update all of the copyright headers to include the correct address. |
16 |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
1
by brian
clean slate |
17 |
|
18 |
/* This file should be included when using heap_database_functions */
|
|
19 |
/* Author: Michael Widenius */
|
|
20 |
||
2234
by Brian Aker
Mass removal of ifdef/endif in favor of pragma once. |
21 |
#pragma once
|
1122.2.10
by Monty Taylor
Fixed all of the include guards. |
22 |
|
243.1.11
by Jay Pipes
* Added include guards in a couple places, and removed unecessary |
23 |
#include <drizzled/base.h> |
1241.9.43
by Monty Taylor
Merged trunk. Also renamed thr_lock. Doh. I hate it when I do both. |
24 |
#include <drizzled/thr_lock.h> |
1
by brian
clean slate |
25 |
|
992.1.25
by Monty Taylor
Moved myisam to new plugin system. |
26 |
#include <plugin/myisam/my_handler.h> |
1
by brian
clean slate |
27 |
|
1707.1.3
by Brian Aker
Switch to using vector. |
28 |
#include <vector> |
29 |
||
1
by brian
clean slate |
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; |
1697.2.2
by Brian Aker
Encapsulate some of heap. |
47 |
|
48 |
st_heapinfo(): |
|
49 |
records(0), |
|
50 |
deleted(0), |
|
51 |
max_records(), |
|
52 |
data_length(0), |
|
53 |
index_length(0), |
|
54 |
reclength(0), |
|
55 |
errkey(0), |
|
56 |
auto_increment(0) |
|
57 |
{ } |
|
58 |
||
1
by brian
clean slate |
59 |
} HEAPINFO; |
60 |
||
61 |
||
62 |
/* Structs used by heap-database-handler */
|
|
63 |
||
64 |
typedef struct st_heap_ptrs |
|
65 |
{
|
|
481
by Brian Aker
Remove all of uchar. |
66 |
unsigned char *blocks[HP_PTRS_IN_NOD]; /* pointers to HP_PTRS or records */ |
1
by brian
clean slate |
67 |
} HP_PTRS; |
68 |
||
69 |
struct st_level_info |
|
70 |
{
|
|
71 |
/* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
|
|
482
by Brian Aker
Remove uint. |
72 |
uint32_t free_ptrs_in_block; |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
73 |
|
1
by brian
clean slate |
74 |
/*
|
75 |
Maximum number of records that can be 'contained' inside of each element
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
76 |
of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for
|
1
by brian
clean slate |
77 |
level 2 - HP_PTRS_IN_NOD^2 and so forth.
|
78 |
*/
|
|
291
by Brian Aker
Head ulong conversion. |
79 |
uint32_t records_under_level; |
1
by brian
clean slate |
80 |
|
81 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
82 |
Ptr to last allocated HP_PTRS (or records buffer for level 0) on this
|
1
by brian
clean slate |
83 |
level.
|
84 |
*/
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
85 |
HP_PTRS *last_blocks; |
1697.2.2
by Brian Aker
Encapsulate some of heap. |
86 |
|
87 |
st_level_info(): |
|
88 |
free_ptrs_in_block(0), |
|
89 |
records_under_level(0), |
|
90 |
last_blocks(0) |
|
91 |
{ } |
|
1
by brian
clean slate |
92 |
};
|
93 |
||
94 |
||
95 |
/*
|
|
96 |
Heap table records and hash index entries are stored in HP_BLOCKs.
|
|
97 |
HP_BLOCK is used as a 'growable array' of fixed-size records. Size of record
|
|
98 |
is recbuffer bytes.
|
|
99 |
The internal representation is as follows:
|
|
100 |
HP_BLOCK is a hierarchical structure of 'blocks'.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
101 |
A block at level 0 is an array records_in_block records.
|
102 |
A block at higher level is an HP_PTRS structure with pointers to blocks at
|
|
1
by brian
clean slate |
103 |
lower levels.
|
104 |
At the highest level there is one top block. It is stored in HP_BLOCK::root.
|
|
105 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
106 |
See hp_find_block for a description of how record pointer is obtained from
|
1
by brian
clean slate |
107 |
its index.
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
108 |
See hp_get_new_block
|
1
by brian
clean slate |
109 |
*/
|
110 |
||
111 |
typedef struct st_heap_block |
|
112 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
113 |
HP_PTRS *root; /* Top-level block */ |
1
by brian
clean slate |
114 |
struct st_level_info level_info[HP_MAX_LEVELS+1]; |
482
by Brian Aker
Remove uint. |
115 |
uint32_t levels; /* number of used levels */ |
116 |
uint32_t records_in_block; /* Records in one heap-block */ |
|
117 |
uint32_t recbuffer; /* Length of one saved record */ |
|
291
by Brian Aker
Head ulong conversion. |
118 |
uint32_t last_allocated; /* number of records there is allocated space for */ |
1697.2.2
by Brian Aker
Encapsulate some of heap. |
119 |
|
120 |
st_heap_block() : |
|
121 |
root(NULL), |
|
122 |
levels(0), |
|
123 |
records_in_block(0), |
|
124 |
recbuffer(0), |
|
125 |
last_allocated(0) |
|
126 |
{
|
|
127 |
}
|
|
1
by brian
clean slate |
128 |
} HP_BLOCK; |
129 |
||
130 |
struct st_heap_info; /* For referense */ |
|
131 |
||
132 |
typedef struct st_hp_keydef /* Key definition with open */ |
|
133 |
{
|
|
482
by Brian Aker
Remove uint. |
134 |
uint32_t flag; /* HA_NOSAME | HA_NULL_PART_KEY */ |
135 |
uint32_t keysegs; /* Number of key-segment */ |
|
136 |
uint32_t length; /* Length of key (automatic) */ |
|
1
by brian
clean slate |
137 |
HA_KEYSEG *seg; |
138 |
HP_BLOCK block; /* Where keys are saved */ |
|
139 |
/*
|
|
140 |
Number of buckets used in hash table. Used only to provide
|
|
141 |
#records estimates for heap key scans.
|
|
142 |
*/
|
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
143 |
drizzled::ha_rows hash_buckets; |
1
by brian
clean slate |
144 |
} HP_KEYDEF; |
145 |
||
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
146 |
typedef struct st_heap_dataspace /* control data for data space */ |
147 |
{
|
|
148 |
HP_BLOCK block; |
|
482
by Brian Aker
Remove uint. |
149 |
uint32_t chunk_count; /* Total chunks ever allocated in this dataspace */ |
150 |
uint32_t del_chunk_count; /* Deleted chunks count */ |
|
481
by Brian Aker
Remove all of uchar. |
151 |
unsigned char *del_link; /* Link to last deleted chunk */ |
482
by Brian Aker
Remove uint. |
152 |
uint32_t chunk_length; /* Total length of one chunk */ |
153 |
uint32_t chunk_dataspace_length; /* Length of payload that will be placed into one chunk */ |
|
154 |
uint32_t offset_status; /* Offset of the status flag relative to the chunk start */ |
|
155 |
uint32_t offset_link; /* Offset of the linking pointer relative to the chunk start */ |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
156 |
uint64_t total_data_length; /* Total size allocated within this data space */ |
1697.2.2
by Brian Aker
Encapsulate some of heap. |
157 |
|
158 |
st_heap_dataspace() : |
|
159 |
chunk_count(0), |
|
160 |
del_chunk_count(0), |
|
161 |
del_link(0), |
|
162 |
chunk_length(0), |
|
163 |
chunk_dataspace_length(0), |
|
164 |
offset_status(0), |
|
165 |
offset_link(0), |
|
166 |
total_data_length(0) |
|
167 |
{ } |
|
168 |
||
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
169 |
} HP_DATASPACE; |
170 |
||
171 |
||
1
by brian
clean slate |
172 |
typedef struct st_heap_share |
173 |
{
|
|
174 |
HP_KEYDEF *keydef; |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
175 |
HP_DATASPACE recordspace; /* Describes "block", which contains actual records */ |
176 |
||
291
by Brian Aker
Head ulong conversion. |
177 |
uint32_t min_records,max_records; /* Params to open */ |
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
178 |
uint64_t index_length,max_table_size; |
482
by Brian Aker
Remove uint. |
179 |
uint32_t key_stat_version; /* version to indicate insert/delete */ |
180 |
uint32_t records; /* Actual record (row) count */ |
|
181 |
uint32_t blength; /* used_chunk_count rounded up to 2^n */ |
|
182 |
uint32_t fixed_data_length; /* Length of record's fixed part, which contains keys and always fits into the first chunk */ |
|
183 |
uint32_t fixed_column_count; /* Number of columns stored in fixed_data_length */ |
|
184 |
uint32_t changed; |
|
185 |
uint32_t keys,max_key_length; |
|
186 |
uint32_t column_count; |
|
187 |
uint32_t currently_disabled_keys; /* saved value from "keys" when disabled */ |
|
188 |
uint32_t open_count; |
|
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
189 |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
190 |
|
1707.1.2
by Brian Aker
std::string usage for name, remove strdup. |
191 |
std::string name; /* Name of "memory-file" */ |
280
by Brian Aker
Removed my_bool from heap engine. |
192 |
bool delete_on_close; |
482
by Brian Aker
Remove uint. |
193 |
uint32_t auto_key; |
194 |
uint32_t auto_key_type; /* real type of the auto key segment */ |
|
151
by Brian Aker
Ulonglong to uint64_t |
195 |
uint64_t auto_increment; |
1697.2.2
by Brian Aker
Encapsulate some of heap. |
196 |
|
197 |
st_heap_share() : |
|
198 |
keydef(0), |
|
199 |
min_records(0), |
|
200 |
max_records(0), |
|
201 |
index_length(0), |
|
202 |
max_table_size(0), |
|
203 |
key_stat_version(0), |
|
204 |
records(0), |
|
205 |
blength(0), |
|
206 |
fixed_data_length(0), |
|
207 |
fixed_column_count(0), |
|
208 |
changed(0), |
|
209 |
keys(0), |
|
210 |
max_key_length(0), |
|
211 |
column_count(0), |
|
212 |
currently_disabled_keys(0), |
|
213 |
open_count(0), |
|
214 |
delete_on_close(0), |
|
215 |
auto_key(0), |
|
216 |
auto_key_type(0), |
|
217 |
auto_increment(0) |
|
218 |
{ } |
|
219 |
||
1
by brian
clean slate |
220 |
} HP_SHARE; |
221 |
||
222 |
struct st_hp_hash_info; |
|
223 |
||
224 |
typedef struct st_heap_info |
|
225 |
{
|
|
1697.2.1
by Brian Aker
Encapsulate the internal share for HEAP. |
226 |
private: |
1
by brian
clean slate |
227 |
HP_SHARE *s; |
1697.2.1
by Brian Aker
Encapsulate the internal share for HEAP. |
228 |
public: |
229 |
||
230 |
HP_SHARE *getShare() |
|
231 |
{
|
|
232 |
return s; |
|
233 |
}
|
|
234 |
||
235 |
void setShare(HP_SHARE *s_arg) |
|
236 |
{
|
|
237 |
s= s_arg; |
|
238 |
}
|
|
239 |
||
481
by Brian Aker
Remove all of uchar. |
240 |
unsigned char *current_ptr; |
1
by brian
clean slate |
241 |
struct st_hp_hash_info *current_hash_ptr; |
291
by Brian Aker
Head ulong conversion. |
242 |
uint32_t current_record,next_block; |
1
by brian
clean slate |
243 |
int lastinx,errkey; |
244 |
int mode; /* Mode of file (READONLY..) */ |
|
482
by Brian Aker
Remove uint. |
245 |
uint32_t opt_flag,update; |
1707.1.3
by Brian Aker
Switch to using vector. |
246 |
std::vector <unsigned char> lastkey; /* Last used key with rkey */ |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
247 |
enum drizzled::ha_rkey_function last_find_flag; |
482
by Brian Aker
Remove uint. |
248 |
uint32_t lastkey_len; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
249 |
drizzled::THR_LOCK_DATA lock; |
1
by brian
clean slate |
250 |
} HP_INFO; |
251 |
||
252 |
||
253 |
typedef struct st_heap_create_info |
|
254 |
{
|
|
482
by Brian Aker
Remove uint. |
255 |
uint32_t auto_key; /* keynr [1 - maxkey] for auto key */ |
256 |
uint32_t auto_key_type; |
|
257 |
uint32_t max_chunk_size; |
|
151
by Brian Aker
Ulonglong to uint64_t |
258 |
uint64_t max_table_size; |
259 |
uint64_t auto_increment; |
|
280
by Brian Aker
Removed my_bool from heap engine. |
260 |
bool with_auto_increment; |
261 |
bool internal_table; |
|
1
by brian
clean slate |
262 |
} HP_CREATE_INFO; |
263 |
||
264 |
/* Prototypes for heap-functions */
|
|
265 |
||
266 |
extern HP_INFO *heap_open(const char *name, int mode); |
|
267 |
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode); |
|
268 |
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode); |
|
269 |
extern int heap_close(HP_INFO *info); |
|
481
by Brian Aker
Remove all of uchar. |
270 |
extern int heap_write(HP_INFO *info,const unsigned char *record); |
271 |
extern int heap_update(HP_INFO *info,const unsigned char *old_record,const unsigned char *new_record); |
|
272 |
extern int heap_rrnd(HP_INFO *info,unsigned char *buf,unsigned char *pos); |
|
1
by brian
clean slate |
273 |
extern int heap_scan_init(HP_INFO *info); |
481
by Brian Aker
Remove all of uchar. |
274 |
extern int heap_scan(register HP_INFO *info, unsigned char *record); |
275 |
extern int heap_delete(HP_INFO *info,const unsigned char *buff); |
|
1
by brian
clean slate |
276 |
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag); |
482
by Brian Aker
Remove uint. |
277 |
extern int heap_create(const char *name, uint32_t keys, HP_KEYDEF *keydef, |
1749.3.5
by Brian Aker
Remove columndef (special case to build columndef (which is no longer |
278 |
uint32_t columns, |
279 |
uint32_t key_part_size, |
|
482
by Brian Aker
Remove uint. |
280 |
uint32_t reclength, uint32_t keys_memory_size, |
291
by Brian Aker
Head ulong conversion. |
281 |
uint32_t max_records, uint32_t min_records, |
244.1.1
by Harrison Fisk
Port Ebay/Google memory storage engine variable width columns. |
282 |
HP_CREATE_INFO *create_info, HP_SHARE **share); |
283 |
||
1
by brian
clean slate |
284 |
extern int heap_delete_table(const char *name); |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
285 |
extern int heap_extra(HP_INFO *info,enum drizzled::ha_extra_function function); |
1
by brian
clean slate |
286 |
extern int heap_reset(HP_INFO *info); |
287 |
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. |
288 |
extern int heap_panic(enum drizzled::ha_panic_function flag); |
481
by Brian Aker
Remove all of uchar. |
289 |
extern int heap_rsame(HP_INFO *info,unsigned char *record,int inx); |
290 |
extern int heap_rnext(HP_INFO *info,unsigned char *record); |
|
291 |
extern int heap_rprev(HP_INFO *info,unsigned char *record); |
|
292 |
extern int heap_rfirst(HP_INFO *info,unsigned char *record,int inx); |
|
293 |
extern int heap_rlast(HP_INFO *info,unsigned char *record,int inx); |
|
1
by brian
clean slate |
294 |
extern void heap_clear(HP_INFO *info); |
295 |
extern int heap_disable_indexes(HP_INFO *info); |
|
296 |
extern int heap_enable_indexes(HP_INFO *info); |
|
297 |
extern int heap_indexes_are_disabled(HP_INFO *info); |
|
481
by Brian Aker
Remove all of uchar. |
298 |
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. |
299 |
int hp_panic(enum drizzled::ha_panic_function flag); |
481
by Brian Aker
Remove all of uchar. |
300 |
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. |
301 |
drizzled::key_part_map keypart_map, |
302 |
enum drizzled::ha_rkey_function find_flag); |
|
481
by Brian Aker
Remove all of uchar. |
303 |
extern unsigned char * heap_find(HP_INFO *info,int inx,const unsigned char *key); |
304 |
extern unsigned char *heap_position(HP_INFO *info); |