1 /* Copyright (C) 2000 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; either version 2 of the License, or 6 (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 16 17 /* This file should be included when using nisam_funktions */ 18 /* Author: Michael Widenius */ 19 20 #ifndef _nisam_h 21 #define _nisam_h 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 #ifndef _my_base_h 27 #include <my_base.h> 28 #endif 29 /* defines used by nisam-funktions */ 30 31 #define N_MAXKEY 16 /* Max allowed keys */ 32 #define N_MAXKEY_SEG 16 /* Max segments for key */ 33 #define N_MAX_KEY_LENGTH 256 /* May be increased up to 500 */ 34 #define N_MAX_KEY_BUFF (N_MAX_KEY_LENGTH+N_MAXKEY_SEG+sizeof(double)-1) 35 #define N_MAX_POSSIBLE_KEY_BUFF 500+9 36 37 #define N_NAME_IEXT ".ISM" 38 #define N_NAME_DEXT ".ISD" 39 #define NI_POS_ERROR (~ (ulong) 0) 40 41 42 /* Param to/from nisam_info */ 43 44 typedef struct st_n_isaminfo /* Struct from h_info */ 45 { 46 ulong records; /* Records in database */ 47 ulong deleted; /* Deleted records in database */ 48 ulong recpos; /* Pos for last used record */ 49 ulong newrecpos; /* Pos if we write new record */ 50 ulong dupp_key_pos; /* Position to record with dupp key */ 51 ulong data_file_length, /* Length of data file */ 52 max_data_file_length, 53 index_file_length, 54 max_index_file_length, 55 delete_length; 56 uint reclength; /* Recordlength */ 57 uint mean_reclength; /* Mean recordlength (if packed) */ 58 uint keys; /* How many keys used */ 59 uint options; /* HA_OPTION_... used */ 60 int errkey, /* With key was dupplicated on err */ 61 sortkey; /* clustered by this key */ 62 File filenr; /* (uniq) filenr for datafile */ 63 time_t create_time; /* When table was created */ 64 time_t isamchk_time; 65 time_t update_time; 66 ulong *rec_per_key; /* for sql optimizing */ 67 } N_ISAMINFO; 68 69 70 /* Info saved on file for each info-part */ 71 72 #ifdef __WATCOMC__ 73 #pragma pack(2) 74 #define uint uint16 /* Same format as in MSDOS */ 75 #endif 76 77 #ifdef __ZTC__ 78 #pragma ZTC align 2 79 #define uint uint16 /* Same format as in MSDOS */ 80 #endif 81 82 typedef struct st_n_save_keyseg /* Key-portion */ 83 { 84 uint8 type; /* Typ av nyckel (f|r sort) */ 85 uint8 flag; /* HA_DIFF_LENGTH */ 86 uint16 start; /* Start of key in record */ 87 uint16 length; /* Keylength */ 88 } N_SAVE_KEYSEG; 89 90 typedef struct st_n_save_keydef /* Key definition with create & info */ 91 { 92 uint8 flag; /* NOSAME, PACK_USED */ 93 uint8 keysegs; /* Number of key-segment */ 94 uint16 block_length; /* Length of keyblock (auto) */ 95 uint16 keylength; /* Tot length of keyparts (auto) */ 96 uint16 minlength; /* min length of (packed) key (auto) */ 97 uint16 maxlength; /* max length of (packed) key (auto) */ 98 } N_SAVE_KEYDEF; 99 100 typedef struct st_n_save_recinfo /* Info of record */ 101 { 102 int16 type; /* en_fieldtype */ 103 uint16 length; /* length of field */ 104 } N_SAVE_RECINFO; 105 106 107 #ifdef __ZTC__ 108 #pragma ZTC align 109 #undef uint 110 #endif 111 112 #ifdef __WATCOMC__ 113 #pragma pack() 114 #undef uint 115 #endif 116 117 118 struct st_isam_info; /* For referense */ 119 120 #ifndef ISAM_LIBRARY 121 typedef struct st_isam_info N_INFO; 122 #endif 123 124 typedef struct st_n_keyseg /* Key-portion */ 125 { 126 N_SAVE_KEYSEG base; 127 } N_KEYSEG; 128 129 130 typedef struct st_n_keydef /* Key definition with open & info */ 131 { 132 N_SAVE_KEYDEF base; 133 N_KEYSEG seg[N_MAXKEY_SEG+1]; 134 int (*bin_search)(struct st_isam_info *info,struct st_n_keydef *keyinfo, 135 uchar *page,uchar *key, 136 uint key_len,uint comp_flag,uchar * *ret_pos, 137 uchar *buff); 138 uint (*get_key)(struct st_n_keydef *keyinfo,uint nod_flag,uchar * *page, 139 uchar *key); 140 } N_KEYDEF; 141 142 143 typedef struct st_decode_tree /* Decode huff-table */ 144 { 145 uint16 *table; 146 uint quick_table_bits; 147 byte *intervalls; 148 } DECODE_TREE; 149 150 151 struct st_bit_buff; 152 153 typedef struct st_n_recinfo /* Info of record */ 154 { 155 N_SAVE_RECINFO base; 156 #ifndef NOT_PACKED_DATABASES 157 void (*unpack)(struct st_n_recinfo *rec,struct st_bit_buff *buff, 158 uchar *start,uchar *end); 159 enum en_fieldtype base_type; 160 uint space_length_bits,pack_type; 161 DECODE_TREE *huff_tree; 162 #endif 163 } N_RECINFO; 164 165 166 extern my_string nisam_log_filename; /* Name of logfile */ 167 extern uint nisam_block_size; 168 extern my_bool nisam_flush; 169 170 /* Prototypes for nisam-functions */ 171 172 extern int nisam_close(struct st_isam_info *file); 173 extern int nisam_delete(struct st_isam_info *file,const byte *buff); 174 extern struct st_isam_info *nisam_open(const char *name,int mode, 175 uint wait_if_locked); 176 extern int nisam_panic(enum ha_panic_function function); 177 extern int nisam_rfirst(struct st_isam_info *file,byte *buf,int inx); 178 extern int nisam_rkey(struct st_isam_info *file,byte *buf,int inx, 179 const byte *key, 180 uint key_len, enum ha_rkey_function search_flag); 181 extern int nisam_rlast(struct st_isam_info *file,byte *buf,int inx); 182 extern int nisam_rnext(struct st_isam_info *file,byte *buf,int inx); 183 extern int nisam_rprev(struct st_isam_info *file,byte *buf,int inx); 184 extern int nisam_rrnd(struct st_isam_info *file,byte *buf,ulong pos); 185 extern int nisam_rsame(struct st_isam_info *file,byte *record,int inx); 186 extern int nisam_rsame_with_pos(struct st_isam_info *file,byte *record, 187 int inx,ulong pos); 188 extern int nisam_update(struct st_isam_info *file,const byte *old, 189 const byte *new_record); 190 extern int nisam_write(struct st_isam_info *file,const byte *buff); 191 extern int nisam_info(struct st_isam_info *file,N_ISAMINFO *x,int flag); 192 extern ulong nisam_position(struct st_isam_info *info); 193 extern int nisam_lock_database(struct st_isam_info *file,int lock_type); 194 extern int nisam_create(const char *name,uint keys,N_KEYDEF *keyinfo, 195 N_RECINFO *recinfo,ulong records, 196 ulong reloc,uint flags,uint options, 197 ulong data_file_length); 198 extern int nisam_extra(struct st_isam_info *file, 199 enum ha_extra_function function); 200 extern ulong nisam_records_in_range(struct st_isam_info *info,int inx, 201 const byte *start_key,uint start_key_len, 202 enum ha_rkey_function start_search_flag, 203 const byte *end_key,uint end_key_len, 204 enum ha_rkey_function end_search_flag); 205 extern int nisam_log(int activate_log); 206 extern int nisam_is_changed(struct st_isam_info *info); 207 extern uint _calc_blob_length(uint length , const byte *pos); 208 209 #ifdef __cplusplus 210 } 211 #endif 212 #endif 213