Eneboo - Documentación para desarrolladores
src/libmysql_std/include/heap.h
Ir a la documentación de este archivo.
00001 /* Copyright (C) 2000,2004 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; version 2 of the License.
00006 
00007    This program is distributed in the hope that it will be useful,
00008    but WITHOUT ANY WARRANTY; without even the implied warranty of
00009    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010    GNU General Public License for more details.
00011 
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software
00014    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00015 
00016 /* This file should be included when using heap_database_functions */
00017 /* Author: Michael Widenius */
00018 
00019 #ifndef _heap_h
00020 #define _heap_h
00021 #ifdef  __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 #ifndef _my_base_h
00026 #include <my_base.h>
00027 #endif
00028 #ifdef THREAD
00029 #include <my_pthread.h>
00030 #include <thr_lock.h>
00031 #endif
00032 
00033 #include "my_handler.h"
00034 #include "my_tree.h"
00035 
00036         /* defines used by heap-funktions */
00037 
00038 #define HP_MAX_LEVELS   4               /* 128^5 records is enough */
00039 #define HP_PTRS_IN_NOD  128
00040 
00041         /* struct used with heap_funktions */
00042 
00043 typedef struct st_heapinfo              /* Struct from heap_info */
00044 {
00045   ulong records;                        /* Records in database */
00046   ulong deleted;                        /* Deleted records in database */
00047   ulong max_records;
00048   ulonglong data_length;
00049   ulonglong index_length;
00050   uint reclength;                       /* Length of one record */
00051   int errkey;
00052   ulonglong auto_increment;
00053 } HEAPINFO;
00054 
00055 
00056         /* Structs used by heap-database-handler */
00057 
00058 typedef struct st_heap_ptrs
00059 {
00060   byte *blocks[HP_PTRS_IN_NOD];         /* pointers to HP_PTRS or records */
00061 } HP_PTRS;
00062 
00063 struct st_level_info
00064 {
00065   /* Number of unused slots in *last_blocks HP_PTRS block (0 for 0th level) */
00066   uint free_ptrs_in_block;
00067   
00068   /*
00069     Maximum number of records that can be 'contained' inside of each element
00070     of last_blocks array. For level 0 - 1, for level 1 - HP_PTRS_IN_NOD, for 
00071     level 2 - HP_PTRS_IN_NOD^2 and so forth.
00072   */
00073   uint records_under_level;
00074 
00075   /*
00076     Ptr to last allocated HP_PTRS (or records buffer for level 0) on this 
00077     level.
00078   */
00079   HP_PTRS *last_blocks;                 
00080 };
00081 
00082 
00083 /*
00084   Heap table records and hash index entries are stored in HP_BLOCKs.
00085   HP_BLOCK is used as a 'growable array' of fixed-size records. Size of record
00086   is recbuffer bytes.
00087   The internal representation is as follows:
00088   HP_BLOCK is a hierarchical structure of 'blocks'.
00089   A block at level 0 is an array records_in_block records. 
00090   A block at higher level is an HP_PTRS structure with pointers to blocks at 
00091   lower levels.
00092   At the highest level there is one top block. It is stored in HP_BLOCK::root.
00093 
00094   See hp_find_block for a description of how record pointer is obtained from 
00095   its index.
00096   See hp_get_new_block 
00097 */
00098 
00099 typedef struct st_heap_block
00100 {
00101   HP_PTRS *root;                        /* Top-level block */ 
00102   struct st_level_info level_info[HP_MAX_LEVELS+1];
00103   uint levels;                          /* number of used levels */
00104   uint records_in_block;                /* Records in one heap-block */
00105   uint recbuffer;                       /* Length of one saved record */
00106   ulong last_allocated; /* number of records there is allocated space for */
00107 } HP_BLOCK;
00108 
00109 struct st_heap_info;                    /* For referense */
00110 
00111 typedef struct st_hp_keydef             /* Key definition with open */
00112 {
00113   uint flag;                            /* HA_NOSAME |HA_NULL_PART_KEY */
00114   uint keysegs;                         /* Number of key-segment */
00115   uint length;                          /* Length of key (automatic) */
00116   uint8 algorithm;                      /* HASH / BTREE */
00117   HA_KEYSEG *seg;
00118   HP_BLOCK block;                       /* Where keys are saved */
00119   /*
00120     Number of buckets used in hash table. Used only to provide
00121     #records estimates for heap key scans.
00122   */
00123   ha_rows hash_buckets; 
00124   TREE rb_tree;
00125   int (*write_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
00126                    const byte *record, byte *recpos);
00127   int (*delete_key)(struct st_heap_info *info, struct st_hp_keydef *keyinfo,
00128                    const byte *record, byte *recpos, int flag);
00129   uint (*get_key_length)(struct st_hp_keydef *keydef, const byte *key);
00130 } HP_KEYDEF;
00131 
00132 typedef struct st_heap_share
00133 {
00134   HP_BLOCK block;
00135   HP_KEYDEF  *keydef;
00136   ulong min_records,max_records;        /* Params to open */
00137   ulonglong data_length,index_length,max_table_size;
00138   uint key_stat_version;                /* version to indicate insert/delete */
00139   uint records;                         /* records */
00140   uint blength;                         /* records rounded up to 2^n */
00141   uint deleted;                         /* Deleted records in database */
00142   uint reclength;                       /* Length of one record */
00143   uint changed;
00144   uint keys,max_key_length;
00145   uint currently_disabled_keys;    /* saved value from "keys" when disabled */
00146   uint open_count;
00147   byte *del_link;                       /* Link to next block with del. rec */
00148   my_string name;                       /* Name of "memory-file" */
00149 #ifdef THREAD
00150   THR_LOCK lock;
00151   pthread_mutex_t intern_lock;          /* Locking for use with _locking */
00152 #endif
00153   my_bool delete_on_close;
00154   LIST open_list;
00155   uint auto_key;
00156   uint auto_key_type;                   /* real type of the auto key segment */
00157   ulonglong auto_increment;
00158 } HP_SHARE;
00159 
00160 struct st_hp_hash_info;
00161 
00162 typedef struct st_heap_info
00163 {
00164   HP_SHARE *s;
00165   byte *current_ptr;
00166   struct st_hp_hash_info *current_hash_ptr;
00167   ulong current_record,next_block;
00168   int lastinx,errkey;
00169   int  mode;                            /* Mode of file (READONLY..) */
00170   uint opt_flag,update;
00171   byte *lastkey;                        /* Last used key with rkey */
00172   byte *recbuf;                         /* Record buffer for rb-tree keys */
00173   enum ha_rkey_function last_find_flag;
00174   TREE_ELEMENT *parents[MAX_TREE_HEIGHT+1];
00175   TREE_ELEMENT **last_pos;
00176   uint lastkey_len;
00177   my_bool implicit_emptied;
00178 #ifdef THREAD
00179   THR_LOCK_DATA lock;
00180 #endif
00181   LIST open_list;
00182 } HP_INFO;
00183 
00184 
00185 typedef struct st_heap_create_info
00186 {
00187   uint auto_key;                        /* keynr [1 - maxkey] for auto key */
00188   uint auto_key_type;
00189   ulonglong max_table_size;
00190   ulonglong auto_increment;
00191   my_bool with_auto_increment;
00192 } HP_CREATE_INFO;
00193 
00194         /* Prototypes for heap-functions */
00195 
00196 extern HP_INFO *heap_open(const char *name, int mode);
00197 extern int heap_close(HP_INFO *info);
00198 extern int heap_write(HP_INFO *info,const byte *buff);
00199 extern int heap_update(HP_INFO *info,const byte *old,const byte *newdata);
00200 extern int heap_rrnd(HP_INFO *info,byte *buf,byte *pos);
00201 extern int heap_scan_init(HP_INFO *info);
00202 extern int heap_scan(register HP_INFO *info, byte *record);
00203 extern int heap_delete(HP_INFO *info,const byte *buff);
00204 extern int heap_info(HP_INFO *info,HEAPINFO *x,int flag);
00205 extern int heap_create(const char *name, uint keys, HP_KEYDEF *keydef,
00206                        uint reclength, ulong max_records, ulong min_records,
00207                        HP_CREATE_INFO *create_info);
00208 extern int heap_delete_table(const char *name);
00209 extern int heap_extra(HP_INFO *info,enum ha_extra_function function);
00210 extern int heap_rename(const char *old_name,const char *new_name);
00211 extern int heap_panic(enum ha_panic_function flag);
00212 extern int heap_rsame(HP_INFO *info,byte *record,int inx);
00213 extern int heap_rnext(HP_INFO *info,byte *record);
00214 extern int heap_rprev(HP_INFO *info,byte *record);
00215 extern int heap_rfirst(HP_INFO *info,byte *record,int inx);
00216 extern int heap_rlast(HP_INFO *info,byte *record,int inx);
00217 extern void heap_clear(HP_INFO *info);
00218 extern void heap_clear_keys(HP_INFO *info);
00219 extern int heap_disable_indexes(HP_INFO *info);
00220 extern int heap_enable_indexes(HP_INFO *info);
00221 extern int heap_indexes_are_disabled(HP_INFO *info);
00222 extern void heap_update_auto_increment(HP_INFO *info, const byte *record);
00223 ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
00224                                key_range *max_key);
00225 int heap_rkey(HP_INFO *info, byte *record, int inx, const byte *key, 
00226               uint key_len, enum ha_rkey_function find_flag);
00227 extern gptr heap_find(HP_INFO *info,int inx,const byte *key);
00228 extern int heap_check_heap(HP_INFO *info, my_bool print_status);
00229 extern byte *heap_position(HP_INFO *info);
00230 
00231 /* The following is for programs that uses the old HEAP interface where
00232    pointer to rows where a long instead of a (byte*).
00233 */
00234 
00235 #if defined(WANT_OLD_HEAP_VERSION) || defined(OLD_HEAP_VERSION)
00236 extern int heap_rrnd_old(HP_INFO *info,byte *buf,ulong pos);
00237 extern ulong heap_position_old(HP_INFO *info);
00238 #endif
00239 #ifdef OLD_HEAP_VERSION
00240 typedef ulong HEAP_PTR;
00241 #define heap_position(A) heap_position_old(A)
00242 #define heap_rrnd(A,B,C) heap_rrnd_old(A,B,C)
00243 #else
00244 typedef byte *HEAP_PTR;
00245 #endif
00246 
00247 #ifdef  __cplusplus
00248 }
00249 #endif
00250 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'