00001 /* Copyright (C) 2000,2004 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* This file is included by all internal myisam files */ 00018 00019 #include "myisam.h" /* Structs & some defines */ 00020 #include "myisampack.h" /* packing of keys */ 00021 #include <my_tree.h> 00022 #ifdef THREAD 00023 #include <my_pthread.h> 00024 #include <thr_lock.h> 00025 #else 00026 #include <my_no_pthread.h> 00027 #endif 00028 00029 #if defined(my_write) && !defined(MAP_TO_USE_RAID) 00030 #undef my_write /* undef map from my_nosys; We need test-if-disk full */ 00031 #endif 00032 00033 typedef struct st_mi_status_info 00034 { 00035 ha_rows records; /* Rows in table */ 00036 ha_rows del; /* Removed rows */ 00037 my_off_t empty; /* lost space in datafile */ 00038 my_off_t key_empty; /* lost space in indexfile */ 00039 my_off_t key_file_length; 00040 my_off_t data_file_length; 00041 ha_checksum checksum; 00042 } MI_STATUS_INFO; 00043 00044 typedef struct st_mi_state_info 00045 { 00046 struct { /* Fileheader */ 00047 uchar file_version[4]; 00048 uchar options[2]; 00049 uchar header_length[2]; 00050 uchar state_info_length[2]; 00051 uchar base_info_length[2]; 00052 uchar base_pos[2]; 00053 uchar key_parts[2]; /* Key parts */ 00054 uchar unique_key_parts[2]; /* Key parts + unique parts */ 00055 uchar keys; /* number of keys in file */ 00056 uchar uniques; /* number of UNIQUE definitions */ 00057 uchar language; /* Language for indexes */ 00058 uchar max_block_size_index; /* max keyblock size */ 00059 uchar fulltext_keys; 00060 uchar not_used; /* To align to 8 */ 00061 } header; 00062 00063 MI_STATUS_INFO state; 00064 ha_rows split; /* number of split blocks */ 00065 my_off_t dellink; /* Link to next removed block */ 00066 ulonglong auto_increment; 00067 ulong process; /* process that updated table last */ 00068 ulong unique; /* Unique number for this process */ 00069 ulong update_count; /* Updated for each write lock */ 00070 ulong status; 00071 ulong *rec_per_key_part; 00072 my_off_t *key_root; /* Start of key trees */ 00073 my_off_t *key_del; /* delete links for trees */ 00074 my_off_t rec_per_key_rows; /* Rows when calculating rec_per_key */ 00075 00076 ulong sec_index_changed; /* Updated when new sec_index */ 00077 ulong sec_index_used; /* which extra index are in use */ 00078 ulonglong key_map; /* Which keys are in use */ 00079 ulong version; /* timestamp of create */ 00080 time_t create_time; /* Time when created database */ 00081 time_t recover_time; /* Time for last recover */ 00082 time_t check_time; /* Time for last check */ 00083 uint sortkey; /* sorted by this key (not used) */ 00084 uint open_count; 00085 uint8 changed; /* Changed since myisamchk */ 00086 00087 /* the following isn't saved on disk */ 00088 uint state_diff_length; /* Should be 0 */ 00089 uint state_length; /* Length of state header in file */ 00090 ulong *key_info; 00091 } MI_STATE_INFO; 00092 00093 #define MI_STATE_INFO_SIZE (24+14*8+7*4+2*2+8) 00094 #define MI_STATE_KEY_SIZE 8 00095 #define MI_STATE_KEYBLOCK_SIZE 8 00096 #define MI_STATE_KEYSEG_SIZE 4 00097 #define MI_STATE_EXTRA_SIZE ((MI_MAX_KEY+MI_MAX_KEY_BLOCK_SIZE)*MI_STATE_KEY_SIZE + MI_MAX_KEY*MI_MAX_KEY_SEG*MI_STATE_KEYSEG_SIZE) 00098 #define MI_KEYDEF_SIZE (2+ 5*2) 00099 #define MI_UNIQUEDEF_SIZE (2+1+1) 00100 #define HA_KEYSEG_SIZE (6+ 2*2 + 4*2) 00101 #define MI_COLUMNDEF_SIZE (2*3+1) 00102 #define MI_BASE_INFO_SIZE (5*8 + 8*4 + 4 + 4*2 + 16) 00103 #define MI_INDEX_BLOCK_MARGIN 16 /* Safety margin for .MYI tables */ 00104 00105 typedef struct st_mi_base_info 00106 { 00107 my_off_t keystart; /* Start of keys */ 00108 my_off_t max_data_file_length; 00109 my_off_t max_key_file_length; 00110 my_off_t margin_key_file_length; 00111 ha_rows records,reloc; /* Create information */ 00112 ulong mean_row_length; /* Create information */ 00113 ulong reclength; /* length of unpacked record */ 00114 ulong pack_reclength; /* Length of full packed rec. */ 00115 ulong min_pack_length; 00116 ulong max_pack_length; /* Max possibly length of packed rec.*/ 00117 ulong min_block_length; 00118 ulong fields, /* fields in table */ 00119 pack_fields; /* packed fields in table */ 00120 uint rec_reflength; /* = 2-8 */ 00121 uint key_reflength; /* = 2-8 */ 00122 uint keys; /* same as in state.header */ 00123 uint auto_key; /* Which key-1 is a auto key */ 00124 uint blobs; /* Number of blobs */ 00125 uint pack_bits; /* Length of packed bits */ 00126 uint max_key_block_length; /* Max block length */ 00127 uint max_key_length; /* Max key length */ 00128 /* Extra allocation when using dynamic record format */ 00129 uint extra_alloc_bytes; 00130 uint extra_alloc_procent; 00131 /* Info about raid */ 00132 uint raid_type,raid_chunks; 00133 ulong raid_chunksize; 00134 /* The following are from the header */ 00135 uint key_parts,all_key_parts; 00136 } MI_BASE_INFO; 00137 00138 00139 /* Structs used intern in database */ 00140 00141 typedef struct st_mi_blob /* Info of record */ 00142 { 00143 ulong offset; /* Offset to blob in record */ 00144 uint pack_length; /* Type of packed length */ 00145 ulong length; /* Calc:ed for each record */ 00146 } MI_BLOB; 00147 00148 00149 typedef struct st_mi_isam_pack { 00150 ulong header_length; 00151 uint ref_length; 00152 uchar version; 00153 } MI_PACK; 00154 00155 #define MAX_NONMAPPED_INSERTS 1000 00156 00157 typedef struct st_mi_isam_share { /* Shared between opens */ 00158 MI_STATE_INFO state; 00159 MI_BASE_INFO base; 00160 MI_KEYDEF ft2_keyinfo; /* Second-level ft-key definition */ 00161 MI_KEYDEF *keyinfo; /* Key definitions */ 00162 MI_UNIQUEDEF *uniqueinfo; /* unique definitions */ 00163 HA_KEYSEG *keyparts; /* key part info */ 00164 MI_COLUMNDEF *rec; /* Pointer to field information */ 00165 MI_PACK pack; /* Data about packed records */ 00166 MI_BLOB *blobs; /* Pointer to blobs */ 00167 char *unique_file_name; /* realpath() of index file */ 00168 char *data_file_name, /* Resolved path names from symlinks */ 00169 *index_file_name; 00170 byte *file_map; /* mem-map of file if possible */ 00171 KEY_CACHE *key_cache; /* ref to the current key cache */ 00172 MI_DECODE_TREE *decode_trees; 00173 uint16 *decode_tables; 00174 int (*read_record)(struct st_myisam_info*, my_off_t, byte*); 00175 int (*write_record)(struct st_myisam_info*, const byte*); 00176 int (*update_record)(struct st_myisam_info*, my_off_t, const byte*); 00177 int (*delete_record)(struct st_myisam_info*); 00178 int (*read_rnd)(struct st_myisam_info*, byte*, my_off_t, my_bool); 00179 int (*compare_record)(struct st_myisam_info*, const byte *); 00180 ha_checksum (*calc_checksum)(struct st_myisam_info*, const byte *); 00181 int (*compare_unique)(struct st_myisam_info*, MI_UNIQUEDEF *, 00182 const byte *record, my_off_t pos); 00183 uint (*file_read)(MI_INFO *, byte *, uint, my_off_t, myf); 00184 uint (*file_write)(MI_INFO *, byte *, uint, my_off_t, myf); 00185 invalidator_by_filename invalidator; /* query cache invalidator */ 00186 ulong this_process; /* processid */ 00187 ulong last_process; /* For table-change-check */ 00188 ulong last_version; /* Version on start */ 00189 ulong options; /* Options used */ 00190 ulong min_pack_length; /* Theese are used by packed data */ 00191 ulong max_pack_length; 00192 ulong state_diff_length; 00193 uint rec_reflength; /* rec_reflength in use now */ 00194 uint unique_name_length; 00195 uint32 ftparsers; /* Number of distinct ftparsers + 1 */ 00196 File kfile; /* Shared keyfile */ 00197 File data_file; /* Shared data file */ 00198 int mode; /* mode of file on open */ 00199 uint reopen; /* How many times reopened */ 00200 uint w_locks,r_locks,tot_locks; /* Number of read/write locks */ 00201 uint blocksize; /* blocksize of keyfile */ 00202 myf write_flag; 00203 enum data_file_type data_file_type; 00204 /* Below flag is needed to make log tables work with concurrent insert */ 00205 my_bool is_log_table; 00206 00207 my_bool changed, /* If changed since lock */ 00208 global_changed, /* If changed since open */ 00209 not_flushed, 00210 temporary,delay_key_write, 00211 concurrent_insert; 00212 #ifdef THREAD 00213 THR_LOCK lock; 00214 pthread_mutex_t intern_lock; /* Locking for use with _locking */ 00215 rw_lock_t *key_root_lock; 00216 #endif 00217 my_off_t mmaped_length; 00218 uint nonmmaped_inserts; /* counter of writing in non-mmaped 00219 area */ 00220 rw_lock_t mmap_lock; 00221 } MYISAM_SHARE; 00222 00223 00224 typedef uint mi_bit_type; 00225 00226 typedef struct st_mi_bit_buff { /* Used for packing of record */ 00227 mi_bit_type current_byte; 00228 uint bits; 00229 uchar *pos,*end,*blob_pos,*blob_end; 00230 uint error; 00231 } MI_BIT_BUFF; 00232 00233 struct st_myisam_info { 00234 MYISAM_SHARE *s; /* Shared between open:s */ 00235 MI_STATUS_INFO *state,save_state; 00236 MI_BLOB *blobs; /* Pointer to blobs */ 00237 MI_BIT_BUFF bit_buff; 00238 /* accumulate indexfile changes between write's */ 00239 TREE *bulk_insert; 00240 DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */ 00241 MEM_ROOT ft_memroot; /* used by the parser */ 00242 MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */ 00243 char *filename; /* parameter to open filename */ 00244 uchar *buff, /* Temp area for key */ 00245 *lastkey,*lastkey2; /* Last used search key */ 00246 uchar *first_mbr_key; /* Searhed spatial key */ 00247 byte *rec_buff; /* Tempbuff for recordpack */ 00248 uchar *int_keypos, /* Save position for next/previous */ 00249 *int_maxpos; /* -""- */ 00250 uint int_nod_flag; /* -""- */ 00251 uint32 int_keytree_version; /* -""- */ 00252 int (*read_record)(struct st_myisam_info*, my_off_t, byte*); 00253 invalidator_by_filename invalidator; /* query cache invalidator */ 00254 ulong this_unique; /* uniq filenumber or thread */ 00255 ulong last_unique; /* last unique number */ 00256 ulong this_loop; /* counter for this open */ 00257 ulong last_loop; /* last used counter */ 00258 my_off_t lastpos, /* Last record position */ 00259 nextpos; /* Position to next record */ 00260 my_off_t save_lastpos; 00261 my_off_t pos; /* Intern variable */ 00262 my_off_t last_keypage; /* Last key page read */ 00263 my_off_t last_search_keypage; /* Last keypage when searching */ 00264 my_off_t dupp_key_pos; 00265 ha_checksum checksum; 00266 /* QQ: the folloing two xxx_length fields should be removed, 00267 as they are not compatible with parallel repair */ 00268 ulong packed_length,blob_length; /* Length of found, packed record */ 00269 int dfile; /* The datafile */ 00270 uint opt_flag; /* Optim. for space/speed */ 00271 uint update; /* If file changed since open */ 00272 int lastinx; /* Last used index */ 00273 uint lastkey_length; /* Length of key in lastkey */ 00274 uint last_rkey_length; /* Last length in mi_rkey() */ 00275 enum ha_rkey_function last_key_func; /* CONTAIN, OVERLAP, etc */ 00276 uint save_lastkey_length; 00277 uint pack_key_length; /* For MYISAMMRG */ 00278 int errkey; /* Got last error on this key */ 00279 int lock_type; /* How database was locked */ 00280 int tmp_lock_type; /* When locked by readinfo */ 00281 uint data_changed; /* Somebody has changed data */ 00282 uint save_update; /* When using KEY_READ */ 00283 int save_lastinx; 00284 LIST open_list; 00285 IO_CACHE rec_cache; /* When cacheing records */ 00286 uint preload_buff_size; /* When preloading indexes */ 00287 myf lock_wait; /* is 0 or MY_DONT_WAIT */ 00288 my_bool was_locked; /* Was locked in panic */ 00289 my_bool append_insert_at_end; /* Set if concurrent insert */ 00290 my_bool quick_mode; 00291 my_bool page_changed; /* If info->buff can't be used for rnext */ 00292 my_bool buff_used; /* If info->buff has to be reread for rnext */ 00293 my_bool once_flags; /* For MYISAMMRG */ 00294 #ifdef THREAD 00295 THR_LOCK_DATA lock; 00296 #endif 00297 uchar *rtree_recursion_state; /* For RTREE */ 00298 int rtree_recursion_depth; 00299 }; 00300 00301 typedef struct st_buffpek { 00302 my_off_t file_pos; /* Where we are in the sort file */ 00303 uchar *base,*key; /* Key pointers */ 00304 ha_rows count; /* Number of rows in table */ 00305 ulong mem_count; /* numbers of keys in memory */ 00306 ulong max_keys; /* Max keys in buffert */ 00307 } BUFFPEK; 00308 00309 typedef struct st_mi_sort_param 00310 { 00311 pthread_t thr; 00312 IO_CACHE read_cache, tempfile, tempfile_for_exceptions; 00313 DYNAMIC_ARRAY buffpek; 00314 00315 /* 00316 The next two are used to collect statistics, see update_key_parts for 00317 description. 00318 */ 00319 ulonglong unique[MI_MAX_KEY_SEG+1]; 00320 ulonglong notnull[MI_MAX_KEY_SEG+1]; 00321 00322 my_off_t pos,max_pos,filepos,start_recpos; 00323 uint key, key_length,real_key_length,sortbuff_size; 00324 uint maxbuffers, keys, find_length, sort_keys_length; 00325 my_bool fix_datafile, master; 00326 MI_KEYDEF *keyinfo; 00327 HA_KEYSEG *seg; 00328 SORT_INFO *sort_info; 00329 uchar **sort_keys; 00330 byte *rec_buff; 00331 void *wordlist, *wordptr; 00332 MEM_ROOT wordroot; 00333 char *record; 00334 MY_TMPDIR *tmpdir; 00335 int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *); 00336 int (*key_read)(struct st_mi_sort_param *,void *); 00337 int (*key_write)(struct st_mi_sort_param *, const void *); 00338 void (*lock_in_memory)(MI_CHECK *); 00339 NEAR int (*write_keys)(struct st_mi_sort_param *, register uchar **, 00340 uint , struct st_buffpek *, IO_CACHE *); 00341 NEAR uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint); 00342 NEAR int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,char *, 00343 uint, uint); 00344 } MI_SORT_PARAM; 00345 /* Some defines used by isam-funktions */ 00346 00347 #define USE_WHOLE_KEY MI_MAX_KEY_BUFF*2 /* Use whole key in _mi_search() */ 00348 #define F_EXTRA_LCK -1 00349 00350 /* bits in opt_flag */ 00351 #define MEMMAP_USED 32 00352 #define REMEMBER_OLD_POS 64 00353 00354 #define WRITEINFO_UPDATE_KEYFILE 1 00355 #define WRITEINFO_NO_UNLOCK 2 00356 00357 /* once_flags */ 00358 #define USE_PACKED_KEYS 1 00359 #define RRND_PRESERVE_LASTINX 2 00360 00361 /* bits in state.changed */ 00362 00363 #define STATE_CHANGED 1 00364 #define STATE_CRASHED 2 00365 #define STATE_CRASHED_ON_REPAIR 4 00366 #define STATE_NOT_ANALYZED 8 00367 #define STATE_NOT_OPTIMIZED_KEYS 16 00368 #define STATE_NOT_SORTED_PAGES 32 00369 00370 /* options to mi_read_cache */ 00371 00372 #define READING_NEXT 1 00373 #define READING_HEADER 2 00374 00375 #define mi_getint(x) ((uint) mi_uint2korr(x) & 32767) 00376 #define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\ 00377 mi_int2store(x,boh); } 00378 #define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0) 00379 #define mi_mark_crashed(x) (x)->s->state.changed|=STATE_CRASHED 00380 #define mi_mark_crashed_on_repair(x) { (x)->s->state.changed|=STATE_CRASHED|STATE_CRASHED_ON_REPAIR ; (x)->update|= HA_STATE_CHANGED; } 00381 #define mi_is_crashed(x) ((x)->s->state.changed & STATE_CRASHED) 00382 #define mi_is_crashed_on_repair(x) ((x)->s->state.changed & STATE_CRASHED_ON_REPAIR) 00383 #define mi_print_error(SHARE, ERRNO) \ 00384 mi_report_error((ERRNO), (SHARE)->index_file_name) 00385 00386 /* Functions to store length of space packed keys, VARCHAR or BLOB keys */ 00387 00388 #define store_key_length_inc(key,length) \ 00389 { if ((length) < 255) \ 00390 { *(key)++=(length); } \ 00391 else \ 00392 { *(key)=255; mi_int2store((key)+1,(length)); (key)+=3; } \ 00393 } 00394 00395 #define store_key_length(key,length) \ 00396 { if ((length) < 255) \ 00397 { *(key)=(length); } \ 00398 else \ 00399 { *(key)=255; mi_int2store((key)+1,(length)); } \ 00400 } 00401 00402 #define get_key_full_length(length,key) \ 00403 { if ((uchar) *(key) != 255) \ 00404 length= ((uint) (uchar) *((key)++))+1; \ 00405 else \ 00406 { length=mi_uint2korr((key)+1)+3; (key)+=3; } \ 00407 } 00408 00409 #define get_key_full_length_rdonly(length,key) \ 00410 { if ((uchar) *(key) != 255) \ 00411 length= ((uint) (uchar) *((key)))+1; \ 00412 else \ 00413 { length=mi_uint2korr((key)+1)+3; } \ 00414 } 00415 00416 #define get_pack_length(length) ((length) >= 255 ? 3 : 1) 00417 00418 #define MI_MIN_BLOCK_LENGTH 20 /* Because of delete-link */ 00419 #define MI_EXTEND_BLOCK_LENGTH 20 /* Don't use to small record-blocks */ 00420 #define MI_SPLIT_LENGTH ((MI_EXTEND_BLOCK_LENGTH+4)*2) 00421 #define MI_MAX_DYN_BLOCK_HEADER 20 /* Max prefix of record-block */ 00422 #define MI_BLOCK_INFO_HEADER_LENGTH 20 00423 #define MI_DYN_DELETE_BLOCK_HEADER 20 /* length of delete-block-header */ 00424 #define MI_DYN_MAX_BLOCK_LENGTH ((1L << 24)-4L) 00425 #define MI_DYN_MAX_ROW_LENGTH (MI_DYN_MAX_BLOCK_LENGTH - MI_SPLIT_LENGTH) 00426 #define MI_DYN_ALIGN_SIZE 4 /* Align blocks on this */ 00427 #define MI_MAX_DYN_HEADER_BYTE 13 /* max header byte for dynamic rows */ 00428 #define MI_MAX_BLOCK_LENGTH ((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1))) 00429 #define MI_REC_BUFF_OFFSET ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER+sizeof(uint32)) 00430 00431 #define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for file */ 00432 00433 #define PACK_TYPE_SELECTED 1 /* Bits in field->pack_type */ 00434 #define PACK_TYPE_SPACE_FIELDS 2 00435 #define PACK_TYPE_ZERO_FILL 4 00436 #define MI_FOUND_WRONG_KEY 32738 /* Impossible value from ha_key_cmp */ 00437 00438 #define MI_MAX_KEY_BLOCK_SIZE (MI_MAX_KEY_BLOCK_LENGTH/MI_MIN_KEY_BLOCK_LENGTH) 00439 #define MI_BLOCK_SIZE(key_length,data_pointer,key_pointer,block_size) (((((key_length)+(data_pointer)+(key_pointer))*4+(key_pointer)+2)/(block_size)+1)*(block_size)) 00440 #define MI_MAX_KEYPTR_SIZE 5 /* For calculating block lengths */ 00441 #define MI_MIN_KEYBLOCK_LENGTH 50 /* When to split delete blocks */ 00442 00443 #define MI_MIN_SIZE_BULK_INSERT_TREE 16384 /* this is per key */ 00444 #define MI_MIN_ROWS_TO_USE_BULK_INSERT 100 00445 #define MI_MIN_ROWS_TO_DISABLE_INDEXES 100 00446 #define MI_MIN_ROWS_TO_USE_WRITE_CACHE 10 00447 00448 /* The UNIQUE check is done with a hashed long key */ 00449 00450 #define MI_UNIQUE_HASH_TYPE HA_KEYTYPE_ULONG_INT 00451 #define mi_unique_store(A,B) mi_int4store((A),(B)) 00452 00453 #ifdef THREAD 00454 extern pthread_mutex_t THR_LOCK_myisam; 00455 #endif 00456 #if !defined(THREAD) || defined(DONT_USE_RW_LOCKS) 00457 #define rw_wrlock(A) {} 00458 #define rw_rdlock(A) {} 00459 #define rw_unlock(A) {} 00460 #endif 00461 00462 /* Some extern variables */ 00463 00464 extern LIST *myisam_open_list; 00465 extern uchar NEAR myisam_file_magic[],NEAR myisam_pack_file_magic[]; 00466 extern uint NEAR myisam_read_vec[],NEAR myisam_readnext_vec[]; 00467 extern uint myisam_quick_table_bits; 00468 extern File myisam_log_file; 00469 extern ulong myisam_pid; 00470 00471 /* This is used by _mi_calc_xxx_key_length och _mi_store_key */ 00472 00473 typedef struct st_mi_s_param 00474 { 00475 uint ref_length,key_length, 00476 n_ref_length, 00477 n_length, 00478 totlength, 00479 part_of_prev_key,prev_length,pack_marker; 00480 uchar *key, *prev_key,*next_key_pos; 00481 bool store_not_null; 00482 } MI_KEY_PARAM; 00483 00484 /* Prototypes for intern functions */ 00485 00486 extern int _mi_read_dynamic_record(MI_INFO *info,my_off_t filepos,byte *buf); 00487 extern int _mi_write_dynamic_record(MI_INFO*, const byte*); 00488 extern int _mi_update_dynamic_record(MI_INFO*, my_off_t, const byte*); 00489 extern int _mi_delete_dynamic_record(MI_INFO *info); 00490 extern int _mi_cmp_dynamic_record(MI_INFO *info,const byte *record); 00491 extern int _mi_read_rnd_dynamic_record(MI_INFO *, byte *,my_off_t, my_bool); 00492 extern int _mi_write_blob_record(MI_INFO*, const byte*); 00493 extern int _mi_update_blob_record(MI_INFO*, my_off_t, const byte*); 00494 extern int _mi_read_static_record(MI_INFO *info, my_off_t filepos,byte *buf); 00495 extern int _mi_write_static_record(MI_INFO*, const byte*); 00496 extern int _mi_update_static_record(MI_INFO*, my_off_t, const byte*); 00497 extern int _mi_delete_static_record(MI_INFO *info); 00498 extern int _mi_cmp_static_record(MI_INFO *info,const byte *record); 00499 extern int _mi_read_rnd_static_record(MI_INFO*, byte *,my_off_t, my_bool); 00500 extern int _mi_ck_write(MI_INFO *info,uint keynr,uchar *key,uint length); 00501 extern int _mi_ck_real_write_btree(MI_INFO *info, MI_KEYDEF *keyinfo, 00502 uchar *key, uint key_length, 00503 my_off_t *root, uint comp_flag); 00504 extern int _mi_enlarge_root(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, my_off_t *root); 00505 extern int _mi_insert(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, 00506 uchar *anc_buff,uchar *key_pos,uchar *key_buff, 00507 uchar *father_buff, uchar *father_keypos, 00508 my_off_t father_page, my_bool insert_last); 00509 extern int _mi_split_page(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, 00510 uchar *buff,uchar *key_buff, my_bool insert_last); 00511 extern uchar *_mi_find_half_pos(uint nod_flag,MI_KEYDEF *keyinfo,uchar *page, 00512 uchar *key,uint *return_key_length, 00513 uchar **after_key); 00514 extern int _mi_calc_static_key_length(MI_KEYDEF *keyinfo,uint nod_flag, 00515 uchar *key_pos, uchar *org_key, 00516 uchar *key_buff, 00517 uchar *key, MI_KEY_PARAM *s_temp); 00518 extern int _mi_calc_var_key_length(MI_KEYDEF *keyinfo,uint nod_flag, 00519 uchar *key_pos, uchar *org_key, 00520 uchar *key_buff, 00521 uchar *key, MI_KEY_PARAM *s_temp); 00522 extern int _mi_calc_var_pack_key_length(MI_KEYDEF *keyinfo,uint nod_flag, 00523 uchar *key_pos, uchar *org_key, 00524 uchar *prev_key, 00525 uchar *key, MI_KEY_PARAM *s_temp); 00526 extern int _mi_calc_bin_pack_key_length(MI_KEYDEF *keyinfo,uint nod_flag, 00527 uchar *key_pos,uchar *org_key, 00528 uchar *prev_key, 00529 uchar *key, MI_KEY_PARAM *s_temp); 00530 void _mi_store_static_key(MI_KEYDEF *keyinfo, uchar *key_pos, 00531 MI_KEY_PARAM *s_temp); 00532 void _mi_store_var_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos, 00533 MI_KEY_PARAM *s_temp); 00534 #ifdef NOT_USED 00535 void _mi_store_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos, 00536 MI_KEY_PARAM *s_temp); 00537 #endif 00538 void _mi_store_bin_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos, 00539 MI_KEY_PARAM *s_temp); 00540 00541 extern int _mi_ck_delete(MI_INFO *info,uint keynr,uchar *key,uint key_length); 00542 extern int _mi_readinfo(MI_INFO *info,int lock_flag,int check_keybuffer); 00543 extern int _mi_writeinfo(MI_INFO *info,uint options); 00544 extern int _mi_test_if_changed(MI_INFO *info); 00545 extern int _mi_mark_file_changed(MI_INFO *info); 00546 extern int _mi_decrement_open_count(MI_INFO *info); 00547 extern int _mi_check_index(MI_INFO *info,int inx); 00548 extern int _mi_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,uint key_len, 00549 uint nextflag,my_off_t pos); 00550 extern int _mi_bin_search(struct st_myisam_info *info,MI_KEYDEF *keyinfo, 00551 uchar *page,uchar *key,uint key_len,uint comp_flag, 00552 uchar * *ret_pos,uchar *buff, my_bool *was_last_key); 00553 extern int _mi_seq_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, 00554 uchar *key,uint key_len,uint comp_flag, 00555 uchar **ret_pos,uchar *buff, my_bool *was_last_key); 00556 extern int _mi_prefix_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page, 00557 uchar *key,uint key_len,uint comp_flag, 00558 uchar **ret_pos,uchar *buff, my_bool *was_last_key); 00559 extern my_off_t _mi_kpos(uint nod_flag,uchar *after_key); 00560 extern void _mi_kpointer(MI_INFO *info,uchar *buff,my_off_t pos); 00561 extern my_off_t _mi_dpos(MI_INFO *info, uint nod_flag,uchar *after_key); 00562 extern my_off_t _mi_rec_pos(MYISAM_SHARE *info, uchar *ptr); 00563 extern void _mi_dpointer(MI_INFO *info, uchar *buff,my_off_t pos); 00564 extern int ha_key_cmp(HA_KEYSEG *keyseg, uchar *a,uchar *b, 00565 uint key_length,uint nextflag,uint *diff_length); 00566 extern uint _mi_get_static_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar * *page, 00567 uchar *key); 00568 extern uint _mi_get_pack_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar * *page, 00569 uchar *key); 00570 extern uint _mi_get_binary_pack_key(MI_KEYDEF *keyinfo, uint nod_flag, 00571 uchar **page_pos, uchar *key); 00572 extern uchar *_mi_get_last_key(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *keypos, 00573 uchar *lastkey,uchar *endpos, 00574 uint *return_key_length); 00575 extern uchar *_mi_get_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *page, 00576 uchar *key, uchar *keypos, uint *return_key_length); 00577 extern uint _mi_keylength(MI_KEYDEF *keyinfo,uchar *key); 00578 extern uint _mi_keylength_part(MI_KEYDEF *keyinfo, register uchar *key, 00579 HA_KEYSEG *end); 00580 extern uchar *_mi_move_key(MI_KEYDEF *keyinfo,uchar *to,uchar *from); 00581 extern int _mi_search_next(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, 00582 uint key_length,uint nextflag,my_off_t pos); 00583 extern int _mi_search_first(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos); 00584 extern int _mi_search_last(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos); 00585 extern uchar *_mi_fetch_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t page, 00586 int level,uchar *buff,int return_buffer); 00587 extern int _mi_write_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t page, 00588 int level, uchar *buff); 00589 extern int _mi_dispose(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos, 00590 int level); 00591 extern my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo,int level); 00592 extern uint _mi_make_key(MI_INFO *info,uint keynr,uchar *key, 00593 const byte *record,my_off_t filepos); 00594 extern uint _mi_pack_key(MI_INFO *info,uint keynr,uchar *key,uchar *old, 00595 uint key_length, HA_KEYSEG **last_used_keyseg); 00596 extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,byte *buf); 00597 extern int _mi_read_cache(IO_CACHE *info,byte *buff,my_off_t pos, 00598 uint length,int re_read_if_possibly); 00599 extern ulonglong retrieve_auto_increment(MI_INFO *info,const byte *record); 00600 00601 extern byte *mi_alloc_rec_buff(MI_INFO *,ulong, byte**); 00602 #define mi_get_rec_buff_ptr(info,buf) \ 00603 ((((info)->s->options & HA_OPTION_PACK_RECORD) && (buf)) ? \ 00604 (buf) - MI_REC_BUFF_OFFSET : (buf)) 00605 #define mi_get_rec_buff_len(info,buf) \ 00606 (*((uint32 *)(mi_get_rec_buff_ptr(info,buf)))) 00607 00608 extern ulong _mi_rec_unpack(MI_INFO *info,byte *to,byte *from, 00609 ulong reclength); 00610 extern my_bool _mi_rec_check(MI_INFO *info,const char *record, byte *packpos, 00611 ulong packed_length, my_bool with_checkum); 00612 extern int _mi_write_part_record(MI_INFO *info,my_off_t filepos,ulong length, 00613 my_off_t next_filepos,byte **record, 00614 ulong *reclength,int *flag); 00615 extern void _mi_print_key(FILE *stream,HA_KEYSEG *keyseg,const uchar *key, 00616 uint length); 00617 extern my_bool _mi_read_pack_info(MI_INFO *info,pbool fix_keys); 00618 extern int _mi_read_pack_record(MI_INFO *info,my_off_t filepos,byte *buf); 00619 extern int _mi_read_rnd_pack_record(MI_INFO*, byte *,my_off_t, my_bool); 00620 extern int _mi_pack_rec_unpack(MI_INFO *info,byte *to,byte *from, 00621 ulong reclength); 00622 extern ulonglong mi_safe_mul(ulonglong a,ulonglong b); 00623 extern int _mi_ft_update(MI_INFO *info, uint keynr, byte *keybuf, 00624 const byte *oldrec, const byte *newrec, my_off_t pos); 00625 00626 struct st_sort_info; 00627 00628 00629 typedef struct st_mi_block_info { /* Parameter to _mi_get_block_info */ 00630 uchar header[MI_BLOCK_INFO_HEADER_LENGTH]; 00631 ulong rec_len; 00632 ulong data_len; 00633 ulong block_len; 00634 ulong blob_len; 00635 my_off_t filepos; 00636 my_off_t next_filepos; 00637 my_off_t prev_filepos; 00638 uint second_read; 00639 uint offset; 00640 } MI_BLOCK_INFO; 00641 00642 /* bits in return from _mi_get_block_info */ 00643 00644 #define BLOCK_FIRST 1 00645 #define BLOCK_LAST 2 00646 #define BLOCK_DELETED 4 00647 #define BLOCK_ERROR 8 /* Wrong data */ 00648 #define BLOCK_SYNC_ERROR 16 /* Right data at wrong place */ 00649 #define BLOCK_FATAL_ERROR 32 /* hardware-error */ 00650 00651 #define NEED_MEM ((uint) 10*4*(IO_SIZE+32)+32) /* Nead for recursion */ 00652 #define MAXERR 20 00653 #define BUFFERS_WHEN_SORTING 16 /* Alloc for sort-key-tree */ 00654 #define WRITE_COUNT MY_HOW_OFTEN_TO_WRITE 00655 #define INDEX_TMP_EXT ".TMM" 00656 #define DATA_TMP_EXT ".TMD" 00657 00658 #define UPDATE_TIME 1 00659 #define UPDATE_STAT 2 00660 #define UPDATE_SORT 4 00661 #define UPDATE_AUTO_INC 8 00662 #define UPDATE_OPEN_COUNT 16 00663 00664 #define USE_BUFFER_INIT (((1024L*512L-MALLOC_OVERHEAD)/IO_SIZE)*IO_SIZE) 00665 #define READ_BUFFER_INIT (1024L*256L-MALLOC_OVERHEAD) 00666 #define SORT_BUFFER_INIT (2048L*1024L-MALLOC_OVERHEAD) 00667 #define MIN_SORT_BUFFER (4096-MALLOC_OVERHEAD) 00668 00669 enum myisam_log_commands { 00670 MI_LOG_OPEN,MI_LOG_WRITE,MI_LOG_UPDATE,MI_LOG_DELETE,MI_LOG_CLOSE,MI_LOG_EXTRA,MI_LOG_LOCK,MI_LOG_DELETE_ALL 00671 }; 00672 00673 #define myisam_log(a,b,c,d) if (myisam_log_file >= 0) _myisam_log(a,b,c,d) 00674 #define myisam_log_command(a,b,c,d,e) if (myisam_log_file >= 0) _myisam_log_command(a,b,c,d,e) 00675 #define myisam_log_record(a,b,c,d,e) if (myisam_log_file >= 0) _myisam_log_record(a,b,c,d,e) 00676 00677 #define fast_mi_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _mi_writeinfo((INFO),0) 00678 #define fast_mi_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _mi_readinfo((INFO),F_RDLCK,1) 00679 00680 #ifdef __cplusplus 00681 extern "C" { 00682 #endif 00683 00684 extern uint _mi_get_block_info(MI_BLOCK_INFO *,File, my_off_t); 00685 extern uint _mi_rec_pack(MI_INFO *info,byte *to,const byte *from); 00686 extern uint _mi_pack_get_block_info(MI_INFO *, MI_BLOCK_INFO *, File, my_off_t); 00687 extern void _my_store_blob_length(byte *pos,uint pack_length,uint length); 00688 extern void _myisam_log(enum myisam_log_commands command,MI_INFO *info, 00689 const byte *buffert,uint length); 00690 extern void _myisam_log_command(enum myisam_log_commands command, 00691 MI_INFO *info, const byte *buffert, 00692 uint length, int result); 00693 extern void _myisam_log_record(enum myisam_log_commands command,MI_INFO *info, 00694 const byte *record,my_off_t filepos, 00695 int result); 00696 extern void mi_report_error(int errcode, const char *file_name); 00697 extern my_bool _mi_memmap_file(MI_INFO *info); 00698 extern void _mi_unmap_file(MI_INFO *info); 00699 extern uint save_pack_length(uint version, byte *block_buff, ulong length); 00700 extern uint read_pack_length(uint version, const uchar *buf, ulong *length); 00701 extern uint calc_pack_length(uint version, ulong length); 00702 extern uint mi_mmap_pread(MI_INFO *info, byte *Buffer, 00703 uint Count, my_off_t offset, myf MyFlags); 00704 extern uint mi_mmap_pwrite(MI_INFO *info, byte *Buffer, 00705 uint Count, my_off_t offset, myf MyFlags); 00706 extern uint mi_nommap_pread(MI_INFO *info, byte *Buffer, 00707 uint Count, my_off_t offset, myf MyFlags); 00708 extern uint mi_nommap_pwrite(MI_INFO *info, byte *Buffer, 00709 uint Count, my_off_t offset, myf MyFlags); 00710 00711 uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite); 00712 uchar *mi_state_info_read(uchar *ptr, MI_STATE_INFO *state); 00713 uint mi_state_info_read_dsk(File file, MI_STATE_INFO *state, my_bool pRead); 00714 uint mi_base_info_write(File file, MI_BASE_INFO *base); 00715 uchar *my_n_base_info_read(uchar *ptr, MI_BASE_INFO *base); 00716 int mi_keyseg_write(File file, const HA_KEYSEG *keyseg); 00717 char *mi_keyseg_read(char *ptr, HA_KEYSEG *keyseg); 00718 uint mi_keydef_write(File file, MI_KEYDEF *keydef); 00719 char *mi_keydef_read(char *ptr, MI_KEYDEF *keydef); 00720 uint mi_uniquedef_write(File file, MI_UNIQUEDEF *keydef); 00721 char *mi_uniquedef_read(char *ptr, MI_UNIQUEDEF *keydef); 00722 uint mi_recinfo_write(File file, MI_COLUMNDEF *recinfo); 00723 char *mi_recinfo_read(char *ptr, MI_COLUMNDEF *recinfo); 00724 extern int mi_disable_indexes(MI_INFO *info); 00725 extern int mi_enable_indexes(MI_INFO *info); 00726 extern int mi_indexes_are_disabled(MI_INFO *info); 00727 ulong _my_calc_total_blob_length(MI_INFO *info, const byte *record); 00728 ha_checksum mi_checksum(MI_INFO *info, const byte *buf); 00729 ha_checksum mi_static_checksum(MI_INFO *info, const byte *buf); 00730 my_bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, byte *record, 00731 ha_checksum unique_hash, my_off_t pos); 00732 ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const byte *buf); 00733 int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def, 00734 const byte *record, my_off_t pos); 00735 int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def, 00736 const byte *record, my_off_t pos); 00737 int mi_unique_comp(MI_UNIQUEDEF *def, const byte *a, const byte *b, 00738 my_bool null_are_equal); 00739 void mi_get_status(void* param, int concurrent_insert); 00740 void mi_update_status(void* param); 00741 void mi_copy_status(void* to,void *from); 00742 my_bool mi_check_status(void* param); 00743 void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows); 00744 00745 extern MI_INFO *test_if_reopen(char *filename); 00746 my_bool check_table_is_closed(const char *name, const char *where); 00747 int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup); 00748 int mi_open_keyfile(MYISAM_SHARE *share); 00749 void mi_setup_functions(register MYISAM_SHARE *share); 00750 my_bool mi_dynmap_file(MI_INFO *info, my_off_t size); 00751 void mi_remap_file(MI_INFO *info, my_off_t size); 00752 00753 /* Functions needed by mi_check */ 00754 volatile int *killed_ptr(MI_CHECK *param); 00755 void mi_check_print_error _VARARGS((MI_CHECK *param, const char *fmt,...)); 00756 void mi_check_print_warning _VARARGS((MI_CHECK *param, const char *fmt,...)); 00757 void mi_check_print_info _VARARGS((MI_CHECK *param, const char *fmt,...)); 00758 int flush_pending_blocks(MI_SORT_PARAM *param); 00759 int sort_ft_buf_flush(MI_SORT_PARAM *sort_param); 00760 int thr_write_keys(MI_SORT_PARAM *sort_param); 00761 #ifdef THREAD 00762 pthread_handler_t thr_find_all_keys(void *arg); 00763 #endif 00764 int flush_blocks(MI_CHECK *param, KEY_CACHE *key_cache, File file); 00765 00766 int sort_write_record(MI_SORT_PARAM *sort_param); 00767 int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong); 00768 00769 #ifdef __cplusplus 00770 } 00771 #endif 00772
1.4.7

