~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to include/heap.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
28
#ifdef THREAD
 
29
#include <my_pthread.h>
 
30
#include <thr_lock.h>
 
31
#endif
 
32
 
 
33
#include "my_handler.h"
 
34
#include "my_tree.h"
 
35
 
 
36
        /* defines used by heap-funktions */
 
37
 
 
38
#define HP_MAX_LEVELS   4               /* 128^5 records is enough */
 
39
#define HP_PTRS_IN_NOD  128
 
40
 
 
41
        /* struct used with heap_funktions */
 
42
 
 
43
typedef struct st_heapinfo              /* Struct from heap_info */
 
44
{
 
45
  ulong records;                        /* Records in database */
 
46
  ulong deleted;                        /* Deleted records in database */
 
47
  ulong max_records;
 
48
  ulonglong data_length;
 
49
  ulonglong index_length;
 
50
  uint reclength;                       /* Length of one record */
 
51
  int errkey;
 
52
  ulonglong auto_increment;
 
53
} HEAPINFO;
 
54
 
 
55
 
 
56
        /* Structs used by heap-database-handler */
 
57
 
 
58
typedef struct st_heap_ptrs
 
59
{
 
60
  uchar *blocks[HP_PTRS_IN_NOD];                /* pointers to HP_PTRS or records */
 
61
} HP_PTRS;
 
62
 
 
63
struct st_level_info
 
64
{
 
65
  /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
 
66
  uint free_ptrs_in_block;
 
67
  
 
68
  /*
 
69
    Maximum number of records that can be 'contained' inside of each element
 
70
    of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for 
 
71
    level 2 - HP_PTRS_IN_NOD^2 and so forth.
 
72
  */
 
73
  ulong records_under_level;
 
74
 
 
75
  /*
 
76
    Ptr to last allocated HP_PTRS (or records buffer for level 0) on this 
 
77
    level.
 
78
  */
 
79
  HP_PTRS *last_blocks;                 
 
80
};
 
81
 
 
82
 
 
83
/*
 
84
  Heap table records and hash index entries are stored in HP_BLOCKs.
 
85
  HP_BLOCK is used as a 'growable array' of fixed-size records. Size of record
 
86
  is recbuffer bytes.
 
87
  The internal representation is as follows:
 
88
  HP_BLOCK is a hierarchical structure of 'blocks'.
 
89
  A block at level 0 is an array records_in_block records. 
 
90
  A block at higher level is an HP_PTRS structure with pointers to blocks at 
 
91
  lower levels.
 
92
  At the highest level there is one top block. It is stored in HP_BLOCK::root.
 
93
 
 
94
  See hp_find_block for a description of how record pointer is obtained from 
 
95
  its index.
 
96
  See hp_get_new_block 
 
97
*/
 
98
 
 
99
typedef struct st_heap_block
 
100
{
 
101
  HP_PTRS *root;                        /* Top-level block */ 
 
102
  struct st_level_info level_info[HP_MAX_LEVELS+1];
 
103
  uint levels;                          /* number of used levels */
 
104
  uint records_in_block;                /* Records in one heap-block */
 
105
  uint recbuffer;                       /* Length of one saved record */
 
106
  ulong last_allocated; /* number of records there is allocated space for */
 
107
} HP_BLOCK;
 
108
 
 
109
struct st_heap_info;                    /* For referense */
 
110
 
 
111
typedef struct st_hp_keydef             /* Key definition with open */
 
112
{
 
113
  uint flag;                            /* HA_NOSAME | HA_NULL_PART_KEY */
 
114
  uint keysegs;                         /* Number of key-segment */
 
115
  uint length;                          /* Length of key (automatic) */
 
116
  uint8 algorithm;                      /* HASH / BTREE */
 
117
  HA_KEYSEG *seg;
 
118
  HP_BLOCK block;                       /* Where keys are saved */
 
119
  /*
 
120
    Number of buckets used in hash table. Used only to provide
 
121
    #records estimates for heap key scans.
 
122
  */
 
123
  ha_rows hash_buckets; 
 
124
  TREE rb_tree;
 
125
  int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
 
126
                   const uchar *record, uchar *recpos);
 
127
  int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
 
128
                   const uchar *record, uchar *recpos, int flag);
 
129
  uint (*get_key_length)(struct st_hp_keydef *keydef, const uchar *key);
 
130
} HP_KEYDEF;
 
131
 
 
132
typedef struct st_heap_share
 
133
{
 
134
  HP_BLOCK block;
 
135
  HP_KEYDEF  *keydef;
 
136
  ulong min_records,max_records;        /* Params to open */
 
137
  ulonglong data_length,index_length,max_table_size;
 
138
  uint key_stat_version;                /* version to indicate insert/delete */
 
139
  uint records;                         /* records */
 
140
  uint blength;                         /* records rounded up to 2^n */
 
141
  uint deleted;                         /* Deleted records in database */
 
142
  uint reclength;                       /* Length of one record */
 
143
  uint changed;
 
144
  uint keys,max_key_length;
 
145
  uint currently_disabled_keys;    /* saved value from "keys" when disabled */
 
146
  uint open_count;
 
147
  uchar *del_link;                      /* Link to next block with del. rec */
 
148
  char * name;                  /* Name of "memory-file" */
 
149
#ifdef THREAD
 
150
  THR_LOCK lock;
 
151
  pthread_mutex_t intern_lock;          /* Locking for use with _locking */
 
152
#endif
 
153
  my_bool delete_on_close;
 
154
  LIST open_list;
 
155
  uint auto_key;
 
156
  uint auto_key_type;                   /* real type of the auto key segment */
 
157
  ulonglong auto_increment;
 
158
} HP_SHARE;
 
159
 
 
160
struct st_hp_hash_info;
 
161
 
 
162
typedef struct st_heap_info
 
163
{
 
164
  HP_SHARE *s;
 
165
  uchar *current_ptr;
 
166
  struct st_hp_hash_info *current_hash_ptr;
 
167
  ulong current_record,next_block;
 
168
  int lastinx,errkey;
 
169
  int  mode;                            /* Mode of file (READONLY..) */
 
170
  uint opt_flag,update;
 
171
  uchar *lastkey;                       /* Last used key with rkey */
 
172
  uchar *recbuf;                         /* Record buffer for rb-tree keys */
 
173
  enum ha_rkey_function last_find_flag;
 
174
  TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
 
175
  TREE_ELEMENT **last_pos;
 
176
  uint lastkey_len;
 
177
  my_bool implicit_emptied;
 
178
#ifdef THREAD
 
179
  THR_LOCK_DATA lock;
 
180
#endif
 
181
  LIST open_list;
 
182
} HP_INFO;
 
183
 
 
184
 
 
185
typedef struct st_heap_create_info
 
186
{
 
187
  uint auto_key;                        /* keynr [1 - maxkey] for auto key */
 
188
  uint auto_key_type;
 
189
  ulonglong max_table_size;
 
190
  ulonglong auto_increment;
 
191
  my_bool with_auto_increment;
 
192
  my_bool internal_table;
 
193
} HP_CREATE_INFO;
 
194
 
 
195
        /* Prototypes for heap-functions */
 
196
 
 
197
extern HP_INFO *heap_open(const char *name, int mode);
 
198
extern HP_INFO *heap_open_from_share(HP_SHARE *share, int mode);
 
199
extern HP_INFO *heap_open_from_share_and_register(HP_SHARE *share, int mode);
 
200
extern int heap_close(HP_INFO *info);
 
201
extern int heap_write(HP_INFO *info,const uchar *buff);
 
202
extern int heap_update(HP_INFO *info,const uchar *old,const uchar *newdata);
 
203
extern int heap_rrnd(HP_INFO *info,uchar *buf,uchar *pos);
 
204
extern int heap_scan_init(HP_INFO *info);
 
205
extern int heap_scan(register HP_INFO *info, uchar *record);
 
206
extern int heap_delete(HP_INFO *info,const uchar *buff);
 
207
extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
 
208
extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
 
209
                       uint reclength, ulong max_records, ulong min_records,
 
210
                       HP_CREATE_INFO *create_info, HP_SHARE **share);
 
211
extern int heap_delete_table(const char *name);
 
212
extern void heap_drop_table(HP_INFO *info);
 
213
extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
 
214
extern int heap_reset(HP_INFO *info);
 
215
extern int heap_rename(const char *old_name,const char *new_name);
 
216
extern int heap_panic(enum ha_panic_function flag);
 
217
extern int heap_rsame(HP_INFO *info,uchar *record,int inx);
 
218
extern int heap_rnext(HP_INFO *info,uchar *record);
 
219
extern int heap_rprev(HP_INFO *info,uchar *record);
 
220
extern int heap_rfirst(HP_INFO *info,uchar *record,int inx);
 
221
extern int heap_rlast(HP_INFO *info,uchar *record,int inx);
 
222
extern void heap_clear(HP_INFO *info);
 
223
extern void heap_clear_keys(HP_INFO *info);
 
224
extern int heap_disable_indexes(HP_INFO *info);
 
225
extern int heap_enable_indexes(HP_INFO *info);
 
226
extern int heap_indexes_are_disabled(HP_INFO *info);
 
227
extern void heap_update_auto_increment(HP_INFO *info, const uchar *record);
 
228
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
 
229
                               key_range *max_key);
 
230
int hp_panic(enum ha_panic_function flag);
 
231
int heap_rkey(HP_INFO *info, uchar *record, int inx, const uchar *key,
 
232
              key_part_map keypart_map, enum ha_rkey_function find_flag);
 
233
extern uchar * heap_find(HP_INFO *info,int inx,const uchar *key);
 
234
extern int heap_check_heap(HP_INFO *info, my_bool print_status);
 
235
extern uchar *heap_position(HP_INFO *info);
 
236
 
 
237
/* The following is for programs that uses the old HEAP interface where
 
238
   pointer to rows where a long instead of a (uchar*).
 
239
*/
 
240
 
 
241
#if defined(WANT_OLD_HEAP_VERSION) || defined(OLD_HEAP_VERSION)
 
242
extern int heap_rrnd_old(HP_INFO *info,uchar *buf,ulong pos);
 
243
extern ulong heap_position_old(HP_INFO *info);
 
244
#endif
 
245
#ifdef OLD_HEAP_VERSION
 
246
typedef ulong HEAP_PTR;
 
247
#define heap_position(A) heap_position_old(A)
 
248
#define heap_rrnd(A,B,C) heap_rrnd_old(A,B,C)
 
249
#else
 
250
typedef uchar *HEAP_PTR;
 
251
#endif
 
252
 
 
253
#ifdef  __cplusplus
 
254
}
 
255
#endif
 
256
#endif