~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
19
#ifndef _heap_h
20
#define _heap_h
21
#ifdef	__cplusplus
22
extern "C" {
23
#endif
24
25
#ifndef _my_base_h
26
#include <my_base.h>
27
#endif
212.5.13 by Monty Taylor
Moved my_sys/my_pthread/my_nosys and mysys_err to mysys.
28
#include <mysys/my_pthread.h>
212.5.7 by Monty Taylor
Move thr_*h to mysys.
29
#include <mysys/thr_lock.h>
1 by brian
clean slate
30
212.5.27 by Monty Taylor
Moved my_handler to mysys.
31
#include <mysys/my_handler.h>
212.5.15 by Monty Taylor
Moved my_tree.
32
#include <mysys/my_tree.h>
1 by brian
clean slate
33
34
	/* defines used by heap-funktions */
35
36
#define HP_MAX_LEVELS	4		/* 128^5 records is enough */
37
#define HP_PTRS_IN_NOD	128
38
39
	/* struct used with heap_funktions */
40
41
typedef struct st_heapinfo		/* Struct from heap_info */
42
{
43
  ulong records;			/* Records in database */
44
  ulong deleted;			/* Deleted records in database */
45
  ulong max_records;
151 by Brian Aker
Ulonglong to uint64_t
46
  uint64_t data_length;
47
  uint64_t index_length;
1 by brian
clean slate
48
  uint reclength;			/* Length of one record */
49
  int errkey;
151 by Brian Aker
Ulonglong to uint64_t
50
  uint64_t auto_increment;
1 by brian
clean slate
51
} HEAPINFO;
52
53
54
	/* Structs used by heap-database-handler */
55
56
typedef struct st_heap_ptrs
57
{
58
  uchar *blocks[HP_PTRS_IN_NOD];		/* pointers to HP_PTRS or records */
59
} HP_PTRS;
60
61
struct st_level_info
62
{
63
  /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
64
  uint free_ptrs_in_block;
65
  
66
  /*
67
    Maximum number of records that can be 'contained' inside of each element
68
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for 
69
    level 2 - HP_PTRS_IN_NOD^2 and so forth.
70
  */
71
  ulong records_under_level;
72
73
  /*
74
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this 
75
    level.
76
  */
77
  HP_PTRS *last_blocks;			
78
};
79
80
81
/*
82
  Heap table records and hash index entries are stored in HP_BLOCKs.
83
  HP_BLOCK is used as a 'growable array' of fixed-size records. Size of record
84
  is recbuffer bytes.
85
  The internal representation is as follows:
86
  HP_BLOCK is a hierarchical structure of 'blocks'.
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 
89
  lower levels.
90
  At the highest level there is one top block. It is stored in HP_BLOCK::root.
91
92
  See hp_find_block for a description of how record pointer is obtained from 
93
  its index.
94
  See hp_get_new_block 
95
*/
96
97
typedef struct st_heap_block
98
{
99
  HP_PTRS *root;                        /* Top-level block */ 
100
  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 */
105
} HP_BLOCK;
106
107
struct st_heap_info;			/* For referense */
108
109
typedef struct st_hp_keydef		/* Key definition with open */
110
{
111
  uint flag;				/* HA_NOSAME | HA_NULL_PART_KEY */
112
  uint keysegs;				/* Number of key-segment */
113
  uint length;				/* Length of key (automatic) */
206 by Brian Aker
Removed final uint dead types.
114
  uint8_t algorithm;			/* HASH / BTREE */
1 by brian
clean slate
115
  HA_KEYSEG *seg;
116
  HP_BLOCK block;			/* Where keys are saved */
117
  /*
118
    Number of buckets used in hash table. Used only to provide
119
    #records estimates for heap key scans.
120
  */
121
  ha_rows hash_buckets; 
122
  TREE rb_tree;
123
  int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
124
		   const uchar *record, uchar *recpos);
125
  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);
128
} HP_KEYDEF;
129
130
typedef struct st_heap_share
131
{
132
  HP_BLOCK block;
133
  HP_KEYDEF  *keydef;
134
  ulong min_records,max_records;	/* Params to open */
151 by Brian Aker
Ulonglong to uint64_t
135
  uint64_t data_length,index_length,max_table_size;
1 by brian
clean slate
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 */
146
  char * name;			/* Name of "memory-file" */
147
  THR_LOCK lock;
148
  pthread_mutex_t intern_lock;		/* Locking for use with _locking */
149
  my_bool delete_on_close;
150
  LIST open_list;
151
  uint auto_key;
152
  uint auto_key_type;			/* real type of the auto key segment */
151 by Brian Aker
Ulonglong to uint64_t
153
  uint64_t auto_increment;
1 by brian
clean slate
154
} HP_SHARE;
155
156
struct st_hp_hash_info;
157
158
typedef struct st_heap_info
159
{
160
  HP_SHARE *s;
161
  uchar *current_ptr;
162
  struct st_hp_hash_info *current_hash_ptr;
163
  ulong current_record,next_block;
164
  int lastinx,errkey;
165
  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 */
169
  enum ha_rkey_function last_find_flag;
170
  TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
171
  TREE_ELEMENT **last_pos;
172
  uint lastkey_len;
173
  my_bool implicit_emptied;
174
  THR_LOCK_DATA lock;
175
  LIST open_list;
176
} HP_INFO;
177
178
179
typedef struct st_heap_create_info
180
{
181
  uint auto_key;                        /* keynr [1 - maxkey] for auto key */
182
  uint auto_key_type;
151 by Brian Aker
Ulonglong to uint64_t
183
  uint64_t max_table_size;
184
  uint64_t auto_increment;
1 by brian
clean slate
185
  my_bool with_auto_increment;
186
  my_bool internal_table;
187
} HP_CREATE_INFO;
188
189
	/* Prototypes for heap-functions */
190
191
extern HP_INFO *heap_open(const char *name, int mode);
192
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
193
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
194
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);
198
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);
201
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);
205
extern int heap_delete_table(const char *name);
206
extern void heap_drop_table(HP_INFO *info);
207
extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
208
extern int heap_reset(HP_INFO *info);
209
extern int heap_rename(const char *old_name,const char *new_name);
210
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);
216
extern void heap_clear(HP_INFO *info);
217
extern void heap_clear_keys(HP_INFO *info);
218
extern int heap_disable_indexes(HP_INFO *info);
219
extern int heap_enable_indexes(HP_INFO *info);
220
extern int heap_indexes_are_disabled(HP_INFO *info);
221
extern void heap_update_auto_increment(HP_INFO *info, const uchar *record);
222
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
223
                               key_range *max_key);
224
int hp_panic(enum ha_panic_function flag);
225
int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key,
226
              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);
230
231
/* The following is for programs that uses the old HEAP interface where
232
   pointer to rows where a long instead of a (uchar*).
233
*/
234
235
#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);
238
#endif
239
#ifdef OLD_HEAP_VERSION
240
typedef ulong HEAP_PTR;
241
#define heap_position(A) heap_position_old(A)
242
#define heap_rrnd(A,B,C) heap_rrnd_old(A,B,C)
243
#else
244
typedef uchar *HEAP_PTR;
245
#endif
246
247
#ifdef	__cplusplus
248
}
249
#endif
250
#endif