1
/* Copyright (C) 2000-2006 MySQL AB
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.
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.
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 */
16
/* This file is included by all internal myisam files */
18
#include "myisam.h" /* Structs & some defines */
19
#include "myisampack.h" /* packing of keys */
22
#include <my_pthread.h>
25
#include <my_no_pthread.h>
28
#if defined(my_write) && !defined(MAP_TO_USE_RAID)
29
#undef my_write /* undef map from my_nosys; We need test-if-disk full */
32
typedef struct st_mi_status_info
34
ha_rows records; /* Rows in table */
35
ha_rows del; /* Removed rows */
36
my_off_t empty; /* lost space in datafile */
37
my_off_t key_empty; /* lost space in indexfile */
38
my_off_t key_file_length;
39
my_off_t data_file_length;
43
typedef struct st_mi_state_info
45
struct { /* Fileheader */
46
uchar file_version[4];
48
uchar header_length[2];
49
uchar state_info_length[2];
50
uchar base_info_length[2];
52
uchar key_parts[2]; /* Key parts */
53
uchar unique_key_parts[2]; /* Key parts + unique parts */
54
uchar keys; /* number of keys in file */
55
uchar uniques; /* number of UNIQUE definitions */
56
uchar language; /* Language for indexes */
57
uchar max_block_size_index; /* max keyblock size */
59
uchar not_used; /* To align to 8 */
63
ha_rows split; /* number of split blocks */
64
my_off_t dellink; /* Link to next removed block */
65
ulonglong auto_increment;
66
ulong process; /* process that updated table last */
67
ulong unique; /* Unique number for this process */
68
ulong update_count; /* Updated for each write lock */
70
ulong *rec_per_key_part;
71
my_off_t *key_root; /* Start of key trees */
72
my_off_t *key_del; /* delete links for trees */
73
my_off_t rec_per_key_rows; /* Rows when calculating rec_per_key */
75
ulong sec_index_changed; /* Updated when new sec_index */
76
ulong sec_index_used; /* which extra index are in use */
77
ulonglong key_map; /* Which keys are in use */
78
ha_checksum checksum; /* Table checksum */
79
ulong version; /* timestamp of create */
80
time_t create_time; /* Time when created database */
81
time_t recover_time; /* Time for last recover */
82
time_t check_time; /* Time for last check */
83
uint sortkey; /* sorted by this key (not used) */
85
uint8 changed; /* Changed since myisamchk */
87
/* the following isn't saved on disk */
88
uint state_diff_length; /* Should be 0 */
89
uint state_length; /* Length of state header in file */
93
#define MI_STATE_INFO_SIZE (24+14*8+7*4+2*2+8)
94
#define MI_STATE_KEY_SIZE 8
95
#define MI_STATE_KEYBLOCK_SIZE 8
96
#define MI_STATE_KEYSEG_SIZE 4
97
#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)
98
#define MI_KEYDEF_SIZE (2+ 5*2)
99
#define MI_UNIQUEDEF_SIZE (2+1+1)
100
#define HA_KEYSEG_SIZE (6+ 2*2 + 4*2)
101
#define MI_COLUMNDEF_SIZE (2*3+1)
102
#define MI_BASE_INFO_SIZE (5*8 + 8*4 + 4 + 4*2 + 16)
103
#define MI_INDEX_BLOCK_MARGIN 16 /* Safety margin for .MYI tables */
105
typedef struct st_mi_base_info
107
my_off_t keystart; /* Start of keys */
108
my_off_t max_data_file_length;
109
my_off_t max_key_file_length;
110
my_off_t margin_key_file_length;
111
ha_rows records,reloc; /* Create information */
112
ulong mean_row_length; /* Create information */
113
ulong reclength; /* length of unpacked record */
114
ulong pack_reclength; /* Length of full packed rec. */
115
ulong min_pack_length;
116
ulong max_pack_length; /* Max possibly length of packed rec.*/
117
ulong min_block_length;
118
ulong fields, /* fields in table */
119
pack_fields; /* packed fields in table */
120
uint rec_reflength; /* = 2-8 */
121
uint key_reflength; /* = 2-8 */
122
uint keys; /* same as in state.header */
123
uint auto_key; /* Which key-1 is a auto key */
124
uint blobs; /* Number of blobs */
125
uint pack_bits; /* Length of packed bits */
126
uint max_key_block_length; /* Max block length */
127
uint max_key_length; /* Max key length */
128
/* Extra allocation when using dynamic record format */
129
uint extra_alloc_bytes;
130
uint extra_alloc_procent;
131
/* Info about raid */
132
uint raid_type,raid_chunks;
133
ulong raid_chunksize;
134
/* The following are from the header */
135
uint key_parts,all_key_parts;
139
/* Structs used intern in database */
141
typedef struct st_mi_blob /* Info of record */
143
ulong offset; /* Offset to blob in record */
144
uint pack_length; /* Type of packed length */
145
ulong length; /* Calc:ed for each record */
149
typedef struct st_mi_isam_pack {
155
#define MAX_NONMAPPED_INSERTS 1000
157
typedef struct st_mi_isam_share { /* Shared between opens */
160
MI_KEYDEF ft2_keyinfo; /* Second-level ft-key definition */
161
MI_KEYDEF *keyinfo; /* Key definitions */
162
MI_UNIQUEDEF *uniqueinfo; /* unique definitions */
163
HA_KEYSEG *keyparts; /* key part info */
164
MI_COLUMNDEF *rec; /* Pointer to field information */
165
MI_PACK pack; /* Data about packed records */
166
MI_BLOB *blobs; /* Pointer to blobs */
167
LIST *in_use; /* List of threads using this table */
168
char *unique_file_name; /* realpath() of index file */
169
char *data_file_name, /* Resolved path names from symlinks */
171
uchar *file_map; /* mem-map of file if possible */
172
KEY_CACHE *key_cache; /* ref to the current key cache */
173
MI_DECODE_TREE *decode_trees;
174
uint16 *decode_tables;
175
int (*read_record)(struct st_myisam_info*, my_off_t, uchar*);
176
int (*write_record)(struct st_myisam_info*, const uchar*);
177
int (*update_record)(struct st_myisam_info*, my_off_t, const uchar*);
178
int (*delete_record)(struct st_myisam_info*);
179
int (*read_rnd)(struct st_myisam_info*, uchar*, my_off_t, my_bool);
180
int (*compare_record)(struct st_myisam_info*, const uchar *);
181
/* Function to use for a row checksum. */
182
ha_checksum (*calc_checksum)(struct st_myisam_info*, const uchar *);
183
int (*compare_unique)(struct st_myisam_info*, MI_UNIQUEDEF *,
184
const uchar *record, my_off_t pos);
185
size_t (*file_read)(MI_INFO *, uchar *, size_t, my_off_t, myf);
186
size_t (*file_write)(MI_INFO *, const uchar *, size_t, my_off_t, myf);
187
invalidator_by_filename invalidator; /* query cache invalidator */
188
ulong this_process; /* processid */
189
ulong last_process; /* For table-change-check */
190
ulong last_version; /* Version on start */
191
ulong options; /* Options used */
192
ulong min_pack_length; /* Theese are used by packed data */
193
ulong max_pack_length;
194
ulong state_diff_length;
195
uint rec_reflength; /* rec_reflength in use now */
196
uint unique_name_length;
197
uint32 ftparsers; /* Number of distinct ftparsers + 1 */
198
File kfile; /* Shared keyfile */
199
File data_file; /* Shared data file */
200
int mode; /* mode of file on open */
201
uint reopen; /* How many times reopened */
202
uint w_locks,r_locks,tot_locks; /* Number of read/write locks */
203
uint blocksize; /* blocksize of keyfile */
205
enum data_file_type data_file_type;
206
/* Below flag is needed to make log tables work with concurrent insert */
207
my_bool is_log_table;
209
my_bool changed, /* If changed since lock */
210
global_changed, /* If changed since open */
212
temporary,delay_key_write,
216
pthread_mutex_t intern_lock; /* Locking for use with _locking */
217
rw_lock_t *key_root_lock;
219
my_off_t mmaped_length;
220
uint nonmmaped_inserts; /* counter of writing in non-mmaped
226
typedef uint mi_bit_type;
228
typedef struct st_mi_bit_buff { /* Used for packing of record */
229
mi_bit_type current_byte;
231
uchar *pos,*end,*blob_pos,*blob_end;
236
typedef my_bool (*index_cond_func_t)(void *param);
238
struct st_myisam_info {
239
MYISAM_SHARE *s; /* Shared between open:s */
240
MI_STATUS_INFO *state,save_state;
241
MI_BLOB *blobs; /* Pointer to blobs */
242
MI_BIT_BUFF bit_buff;
243
/* accumulate indexfile changes between write's */
245
DYNAMIC_ARRAY *ft1_to_ft2; /* used only in ft1->ft2 conversion */
246
MEM_ROOT ft_memroot; /* used by the parser */
247
MYSQL_FTPARSER_PARAM *ftparser_param; /* share info between init/deinit */
248
LIST in_use; /* Thread using this table */
249
char *filename; /* parameter to open filename */
250
uchar *buff, /* Temp area for key */
251
*lastkey,*lastkey2; /* Last used search key */
252
uchar *first_mbr_key; /* Searhed spatial key */
253
uchar *rec_buff; /* Tempbuff for recordpack */
254
uchar *int_keypos, /* Save position for next/previous */
255
*int_maxpos; /* -""- */
256
uint int_nod_flag; /* -""- */
257
uint32 int_keytree_version; /* -""- */
258
int (*read_record)(struct st_myisam_info*, my_off_t, uchar*);
259
invalidator_by_filename invalidator; /* query cache invalidator */
260
ulong this_unique; /* uniq filenumber or thread */
261
ulong last_unique; /* last unique number */
262
ulong this_loop; /* counter for this open */
263
ulong last_loop; /* last used counter */
264
my_off_t lastpos, /* Last record position */
265
nextpos; /* Position to next record */
266
my_off_t save_lastpos;
267
my_off_t pos; /* Intern variable */
268
my_off_t last_keypage; /* Last key page read */
269
my_off_t last_search_keypage; /* Last keypage when searching */
270
my_off_t dupp_key_pos;
271
ha_checksum checksum; /* Temp storage for row checksum */
272
/* QQ: the folloing two xxx_length fields should be removed,
273
as they are not compatible with parallel repair */
274
ulong packed_length,blob_length; /* Length of found, packed record */
275
int dfile; /* The datafile */
276
uint opt_flag; /* Optim. for space/speed */
277
uint update; /* If file changed since open */
278
int lastinx; /* Last used index */
279
uint lastkey_length; /* Length of key in lastkey */
280
uint last_rkey_length; /* Last length in mi_rkey() */
281
enum ha_rkey_function last_key_func; /* CONTAIN, OVERLAP, etc */
282
uint save_lastkey_length;
283
uint pack_key_length; /* For MYISAMMRG */
284
uint16 last_used_keyseg; /* For MyISAMMRG */
285
int errkey; /* Got last error on this key */
286
int lock_type; /* How database was locked */
287
int tmp_lock_type; /* When locked by readinfo */
288
uint data_changed; /* Somebody has changed data */
289
uint save_update; /* When using KEY_READ */
292
IO_CACHE rec_cache; /* When cacheing records */
293
uint preload_buff_size; /* When preloading indexes */
294
myf lock_wait; /* is 0 or MY_DONT_WAIT */
295
my_bool was_locked; /* Was locked in panic */
296
my_bool append_insert_at_end; /* Set if concurrent insert */
298
my_bool page_changed; /* If info->buff can't be used for rnext */
299
my_bool buff_used; /* If info->buff has to be reread for rnext */
300
my_bool once_flags; /* For MYISAMMRG */
302
index_cond_func_t index_cond_func; /* Index condition function */
303
void *index_cond_func_arg; /* parameter for the func */
305
my_bool owned_by_merge; /* This MyISAM table is part of a merge union */
310
uchar *rtree_recursion_state; /* For RTREE */
311
int rtree_recursion_depth;
314
typedef struct st_buffpek {
315
my_off_t file_pos; /* Where we are in the sort file */
316
uchar *base,*key; /* Key pointers */
317
ha_rows count; /* Number of rows in table */
318
ulong mem_count; /* numbers of keys in memory */
319
ulong max_keys; /* Max keys in buffert */
322
typedef struct st_mi_sort_param
325
IO_CACHE read_cache, tempfile, tempfile_for_exceptions;
326
DYNAMIC_ARRAY buffpek;
327
MI_BIT_BUFF bit_buff; /* For parallel repair of packrec. */
330
The next two are used to collect statistics, see update_key_parts for
333
ulonglong unique[MI_MAX_KEY_SEG+1];
334
ulonglong notnull[MI_MAX_KEY_SEG+1];
336
my_off_t pos,max_pos,filepos,start_recpos;
337
uint key, key_length,real_key_length,sortbuff_size;
338
uint maxbuffers, keys, find_length, sort_keys_length;
339
my_bool fix_datafile, master;
340
my_bool calc_checksum; /* calculate table checksum */
343
SORT_INFO *sort_info;
346
void *wordlist, *wordptr;
350
int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *);
351
int (*key_read)(struct st_mi_sort_param *,void *);
352
int (*key_write)(struct st_mi_sort_param *, const void *);
353
void (*lock_in_memory)(MI_CHECK *);
354
int (*write_keys)(struct st_mi_sort_param *, register uchar **,
355
uint , struct st_buffpek *, IO_CACHE *);
356
unsigned int (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint);
357
int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,uchar *,
361
/* Some defines used by isam-funktions */
363
#define USE_WHOLE_KEY MI_MAX_KEY_BUFF*2 /* Use whole key in _mi_search() */
364
#define F_EXTRA_LCK -1
366
/* bits in opt_flag */
367
#define MEMMAP_USED 32
368
#define REMEMBER_OLD_POS 64
370
#define WRITEINFO_UPDATE_KEYFILE 1
371
#define WRITEINFO_NO_UNLOCK 2
374
#define USE_PACKED_KEYS 1
375
#define RRND_PRESERVE_LASTINX 2
377
/* bits in state.changed */
379
#define STATE_CHANGED 1
380
#define STATE_CRASHED 2
381
#define STATE_CRASHED_ON_REPAIR 4
382
#define STATE_NOT_ANALYZED 8
383
#define STATE_NOT_OPTIMIZED_KEYS 16
384
#define STATE_NOT_SORTED_PAGES 32
386
/* options to mi_read_cache */
388
#define READING_NEXT 1
389
#define READING_HEADER 2
391
#define mi_getint(x) ((uint) mi_uint2korr(x) & 32767)
392
#define mi_putint(x,y,nod) { uint16 boh=(nod ? (uint16) 32768 : 0) + (uint16) (y);\
393
mi_int2store(x,boh); }
394
#define mi_test_if_nod(x) (x[0] & 128 ? info->s->base.key_reflength : 0)
395
#define mi_report_crashed(A, B) _mi_report_crashed((A), (B), __FILE__, __LINE__)
396
#define mi_mark_crashed(x) do{(x)->s->state.changed|= STATE_CRASHED; \
397
DBUG_PRINT("error", ("Marked table crashed")); \
398
mi_report_crashed((x), 0); \
400
#define mi_mark_crashed_on_repair(x) do{(x)->s->state.changed|= \
401
STATE_CRASHED|STATE_CRASHED_ON_REPAIR; \
402
(x)->update|= HA_STATE_CHANGED; \
403
DBUG_PRINT("error", \
404
("Marked table crashed")); \
406
#define mi_is_crashed(x) ((x)->s->state.changed & STATE_CRASHED)
407
#define mi_is_crashed_on_repair(x) ((x)->s->state.changed & STATE_CRASHED_ON_REPAIR)
408
#define mi_print_error(SHARE, ERRNO) \
409
mi_report_error((ERRNO), (SHARE)->index_file_name)
411
/* Functions to store length of space packed keys, VARCHAR or BLOB keys */
413
#define store_key_length(key,length) \
414
{ if ((length) < 255) \
415
{ *(key)=(length); } \
417
{ *(key)=255; mi_int2store((key)+1,(length)); } \
420
#define get_key_full_length(length,key) \
421
{ if ((uchar) *(key) != 255) \
422
length= ((uint) (uchar) *((key)++))+1; \
424
{ length=mi_uint2korr((key)+1)+3; (key)+=3; } \
427
#define get_key_full_length_rdonly(length,key) \
428
{ if ((uchar) *(key) != 255) \
429
length= ((uint) (uchar) *((key)))+1; \
431
{ length=mi_uint2korr((key)+1)+3; } \
434
#define get_pack_length(length) ((length) >= 255 ? 3 : 1)
436
#define MI_MIN_BLOCK_LENGTH 20 /* Because of delete-link */
437
#define MI_EXTEND_BLOCK_LENGTH 20 /* Don't use to small record-blocks */
438
#define MI_SPLIT_LENGTH ((MI_EXTEND_BLOCK_LENGTH+4)*2)
439
#define MI_MAX_DYN_BLOCK_HEADER 20 /* Max prefix of record-block */
440
#define MI_BLOCK_INFO_HEADER_LENGTH 20
441
#define MI_DYN_DELETE_BLOCK_HEADER 20 /* length of delete-block-header */
442
#define MI_DYN_MAX_BLOCK_LENGTH ((1L << 24)-4L)
443
#define MI_DYN_MAX_ROW_LENGTH (MI_DYN_MAX_BLOCK_LENGTH - MI_SPLIT_LENGTH)
444
#define MI_DYN_ALIGN_SIZE 4 /* Align blocks on this */
445
#define MI_MAX_DYN_HEADER_BYTE 13 /* max header byte for dynamic rows */
446
#define MI_MAX_BLOCK_LENGTH ((((ulong) 1 << 24)-1) & (~ (ulong) (MI_DYN_ALIGN_SIZE-1)))
447
#define MI_REC_BUFF_OFFSET ALIGN_SIZE(MI_DYN_DELETE_BLOCK_HEADER+sizeof(uint32))
449
#define MEMMAP_EXTRA_MARGIN 7 /* Write this as a suffix for file */
451
#define PACK_TYPE_SELECTED 1 /* Bits in field->pack_type */
452
#define PACK_TYPE_SPACE_FIELDS 2
453
#define PACK_TYPE_ZERO_FILL 4
454
#define MI_FOUND_WRONG_KEY 32738 /* Impossible value from ha_key_cmp */
456
#define MI_MAX_KEY_BLOCK_SIZE (MI_MAX_KEY_BLOCK_LENGTH/MI_MIN_KEY_BLOCK_LENGTH)
457
#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))
458
#define MI_MAX_KEYPTR_SIZE 5 /* For calculating block lengths */
459
#define MI_MIN_KEYBLOCK_LENGTH 50 /* When to split delete blocks */
461
#define MI_MIN_SIZE_BULK_INSERT_TREE 16384 /* this is per key */
462
#define MI_MIN_ROWS_TO_USE_BULK_INSERT 100
463
#define MI_MIN_ROWS_TO_DISABLE_INDEXES 100
464
#define MI_MIN_ROWS_TO_USE_WRITE_CACHE 10
466
/* The UNIQUE check is done with a hashed long key */
468
#define MI_UNIQUE_HASH_TYPE HA_KEYTYPE_ULONG_INT
469
#define mi_unique_store(A,B) mi_int4store((A),(B))
472
extern pthread_mutex_t THR_LOCK_myisam;
474
#if !defined(THREAD) || defined(DONT_USE_RW_LOCKS)
475
#define rw_wrlock(A) {}
476
#define rw_rdlock(A) {}
477
#define rw_unlock(A) {}
480
/* Some extern variables */
482
extern LIST *myisam_open_list;
483
extern uchar myisam_file_magic[], myisam_pack_file_magic[];
484
extern uint myisam_read_vec[], myisam_readnext_vec[];
485
extern uint myisam_quick_table_bits;
486
extern File myisam_log_file;
487
extern ulong myisam_pid;
489
/* This is used by _mi_calc_xxx_key_length och _mi_store_key */
491
typedef struct st_mi_s_param
493
uint ref_length,key_length,
497
part_of_prev_key,prev_length,pack_marker;
498
uchar *key, *prev_key,*next_key_pos;
499
my_bool store_not_null;
502
/* Prototypes for intern functions */
504
extern int _mi_read_dynamic_record(MI_INFO *info,my_off_t filepos,uchar *buf);
505
extern int _mi_write_dynamic_record(MI_INFO*, const uchar*);
506
extern int _mi_update_dynamic_record(MI_INFO*, my_off_t, const uchar*);
507
extern int _mi_delete_dynamic_record(MI_INFO *info);
508
extern int _mi_cmp_dynamic_record(MI_INFO *info,const uchar *record);
509
extern int _mi_read_rnd_dynamic_record(MI_INFO *, uchar *,my_off_t, my_bool);
510
extern int _mi_write_blob_record(MI_INFO*, const uchar*);
511
extern int _mi_update_blob_record(MI_INFO*, my_off_t, const uchar*);
512
extern int _mi_read_static_record(MI_INFO *info, my_off_t filepos,uchar *buf);
513
extern int _mi_write_static_record(MI_INFO*, const uchar*);
514
extern int _mi_update_static_record(MI_INFO*, my_off_t, const uchar*);
515
extern int _mi_delete_static_record(MI_INFO *info);
516
extern int _mi_cmp_static_record(MI_INFO *info,const uchar *record);
517
extern int _mi_read_rnd_static_record(MI_INFO*, uchar *,my_off_t, my_bool);
518
extern int _mi_ck_write(MI_INFO *info,uint keynr,uchar *key,uint length);
519
extern int _mi_ck_real_write_btree(MI_INFO *info, MI_KEYDEF *keyinfo,
520
uchar *key, uint key_length,
521
my_off_t *root, uint comp_flag);
522
extern int _mi_enlarge_root(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key, my_off_t *root);
523
extern int _mi_insert(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
524
uchar *anc_buff,uchar *key_pos,uchar *key_buff,
525
uchar *father_buff, uchar *father_keypos,
526
my_off_t father_page, my_bool insert_last);
527
extern int _mi_split_page(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
528
uchar *buff,uchar *key_buff, my_bool insert_last);
529
extern uchar *_mi_find_half_pos(uint nod_flag,MI_KEYDEF *keyinfo,uchar *page,
530
uchar *key,uint *return_key_length,
532
extern int _mi_calc_static_key_length(MI_KEYDEF *keyinfo,uint nod_flag,
533
uchar *key_pos, uchar *org_key,
535
uchar *key, MI_KEY_PARAM *s_temp);
536
extern int _mi_calc_var_key_length(MI_KEYDEF *keyinfo,uint nod_flag,
537
uchar *key_pos, uchar *org_key,
539
uchar *key, MI_KEY_PARAM *s_temp);
540
extern int _mi_calc_var_pack_key_length(MI_KEYDEF *keyinfo,uint nod_flag,
541
uchar *key_pos, uchar *org_key,
543
uchar *key, MI_KEY_PARAM *s_temp);
544
extern int _mi_calc_bin_pack_key_length(MI_KEYDEF *keyinfo,uint nod_flag,
545
uchar *key_pos,uchar *org_key,
547
uchar *key, MI_KEY_PARAM *s_temp);
548
void _mi_store_static_key(MI_KEYDEF *keyinfo, uchar *key_pos,
549
MI_KEY_PARAM *s_temp);
550
void _mi_store_var_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos,
551
MI_KEY_PARAM *s_temp);
553
void _mi_store_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos,
554
MI_KEY_PARAM *s_temp);
556
void _mi_store_bin_pack_key(MI_KEYDEF *keyinfo, uchar *key_pos,
557
MI_KEY_PARAM *s_temp);
559
extern int _mi_ck_delete(MI_INFO *info,uint keynr,uchar *key,uint key_length);
560
extern int _mi_readinfo(MI_INFO *info,int lock_flag,int check_keybuffer);
561
extern int _mi_writeinfo(MI_INFO *info,uint options);
562
extern int _mi_test_if_changed(MI_INFO *info);
563
extern int _mi_mark_file_changed(MI_INFO *info);
564
extern int _mi_decrement_open_count(MI_INFO *info);
565
extern int _mi_check_index(MI_INFO *info,int inx);
566
extern int _mi_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,uint key_len,
567
uint nextflag,my_off_t pos);
568
extern int _mi_bin_search(struct st_myisam_info *info,MI_KEYDEF *keyinfo,
569
uchar *page,uchar *key,uint key_len,uint comp_flag,
570
uchar * *ret_pos,uchar *buff, my_bool *was_last_key);
571
extern int _mi_seq_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page,
572
uchar *key,uint key_len,uint comp_flag,
573
uchar **ret_pos,uchar *buff, my_bool *was_last_key);
574
extern int _mi_prefix_search(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *page,
575
uchar *key,uint key_len,uint comp_flag,
576
uchar **ret_pos,uchar *buff, my_bool *was_last_key);
577
extern my_off_t _mi_kpos(uint nod_flag,uchar *after_key);
578
extern void _mi_kpointer(MI_INFO *info,uchar *buff,my_off_t pos);
579
extern my_off_t _mi_dpos(MI_INFO *info, uint nod_flag,uchar *after_key);
580
extern my_off_t _mi_rec_pos(MYISAM_SHARE *info, uchar *ptr);
581
extern void _mi_dpointer(MI_INFO *info, uchar *buff,my_off_t pos);
582
extern int ha_key_cmp(HA_KEYSEG *keyseg, uchar *a,uchar *b,
583
uint key_length,uint nextflag,uint *diff_length);
584
extern uint _mi_get_static_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar * *page,
586
extern uint _mi_get_pack_key(MI_KEYDEF *keyinfo,uint nod_flag,uchar * *page,
588
extern uint _mi_get_binary_pack_key(MI_KEYDEF *keyinfo, uint nod_flag,
589
uchar **page_pos, uchar *key);
590
extern uchar *_mi_get_last_key(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *keypos,
591
uchar *lastkey,uchar *endpos,
592
uint *return_key_length);
593
extern uchar *_mi_get_key(MI_INFO *info, MI_KEYDEF *keyinfo, uchar *page,
594
uchar *key, uchar *keypos, uint *return_key_length);
595
extern uint _mi_keylength(MI_KEYDEF *keyinfo,uchar *key);
596
extern uint _mi_keylength_part(MI_KEYDEF *keyinfo, register uchar *key,
598
extern uchar *_mi_move_key(MI_KEYDEF *keyinfo,uchar *to,uchar *from);
599
extern int _mi_search_next(MI_INFO *info,MI_KEYDEF *keyinfo,uchar *key,
600
uint key_length,uint nextflag,my_off_t pos);
601
extern int _mi_search_first(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos);
602
extern int _mi_search_last(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos);
603
extern uchar *_mi_fetch_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t page,
604
int level,uchar *buff,int return_buffer);
605
extern int _mi_write_keypage(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t page,
606
int level, uchar *buff);
607
extern int _mi_dispose(MI_INFO *info,MI_KEYDEF *keyinfo,my_off_t pos,
609
extern my_off_t _mi_new(MI_INFO *info,MI_KEYDEF *keyinfo,int level);
610
extern uint _mi_make_key(MI_INFO *info,uint keynr,uchar *key,
611
const uchar *record,my_off_t filepos);
612
extern uint _mi_pack_key(register MI_INFO *info, uint keynr, uchar *key,
613
uchar *old, key_part_map keypart_map,
614
HA_KEYSEG **last_used_keyseg);
615
extern int _mi_read_key_record(MI_INFO *info,my_off_t filepos,uchar *buf);
616
extern int _mi_read_cache(IO_CACHE *info,uchar *buff,my_off_t pos,
617
uint length,int re_read_if_possibly);
618
extern ulonglong retrieve_auto_increment(MI_INFO *info,const uchar *record);
620
extern uchar *mi_alloc_rec_buff(MI_INFO *,ulong, uchar**);
621
#define mi_get_rec_buff_ptr(info,buf) \
622
((((info)->s->options & HA_OPTION_PACK_RECORD) && (buf)) ? \
623
(buf) - MI_REC_BUFF_OFFSET : (buf))
624
#define mi_get_rec_buff_len(info,buf) \
625
(*((uint32 *)(mi_get_rec_buff_ptr(info,buf))))
627
extern ulong _mi_rec_unpack(MI_INFO *info,uchar *to,uchar *from,
629
extern my_bool _mi_rec_check(MI_INFO *info,const uchar *record, uchar *packpos,
630
ulong packed_length, my_bool with_checkum);
631
extern int _mi_write_part_record(MI_INFO *info,my_off_t filepos,ulong length,
632
my_off_t next_filepos,uchar **record,
633
ulong *reclength,int *flag);
634
extern void _mi_print_key(FILE *stream,HA_KEYSEG *keyseg,const uchar *key,
636
extern my_bool _mi_read_pack_info(MI_INFO *info,pbool fix_keys);
637
extern int _mi_read_pack_record(MI_INFO *info,my_off_t filepos,uchar *buf);
638
extern int _mi_read_rnd_pack_record(MI_INFO*, uchar *,my_off_t, my_bool);
639
extern int _mi_pack_rec_unpack(MI_INFO *info, MI_BIT_BUFF *bit_buff,
640
uchar *to, uchar *from, ulong reclength);
641
extern ulonglong mi_safe_mul(ulonglong a,ulonglong b);
642
extern int _mi_ft_update(MI_INFO *info, uint keynr, uchar *keybuf,
643
const uchar *oldrec, const uchar *newrec, my_off_t pos);
648
typedef struct st_mi_block_info { /* Parameter to _mi_get_block_info */
649
uchar header[MI_BLOCK_INFO_HEADER_LENGTH];
655
my_off_t next_filepos;
656
my_off_t prev_filepos;
661
/* bits in return from _mi_get_block_info */
663
#define BLOCK_FIRST 1
665
#define BLOCK_DELETED 4
666
#define BLOCK_ERROR 8 /* Wrong data */
667
#define BLOCK_SYNC_ERROR 16 /* Right data at wrong place */
668
#define BLOCK_FATAL_ERROR 32 /* hardware-error */
670
#define NEED_MEM ((uint) 10*4*(IO_SIZE+32)+32) /* Nead for recursion */
672
#define BUFFERS_WHEN_SORTING 16 /* Alloc for sort-key-tree */
673
#define WRITE_COUNT MY_HOW_OFTEN_TO_WRITE
674
#define INDEX_TMP_EXT ".TMM"
675
#define DATA_TMP_EXT ".TMD"
677
#define UPDATE_TIME 1
678
#define UPDATE_STAT 2
679
#define UPDATE_SORT 4
680
#define UPDATE_AUTO_INC 8
681
#define UPDATE_OPEN_COUNT 16
683
#define USE_BUFFER_INIT (((1024L*512L-MALLOC_OVERHEAD)/IO_SIZE)*IO_SIZE)
684
#define READ_BUFFER_INIT (1024L*256L-MALLOC_OVERHEAD)
685
#define SORT_BUFFER_INIT (2048L*1024L-MALLOC_OVERHEAD)
686
#define MIN_SORT_BUFFER (4096-MALLOC_OVERHEAD)
688
enum myisam_log_commands {
689
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
692
#define myisam_log(a,b,c,d) if (myisam_log_file >= 0) _myisam_log(a,b,c,d)
693
#define myisam_log_command(a,b,c,d,e) if (myisam_log_file >= 0) _myisam_log_command(a,b,c,d,e)
694
#define myisam_log_record(a,b,c,d,e) if (myisam_log_file >= 0) _myisam_log_record(a,b,c,d,e)
696
#define fast_mi_writeinfo(INFO) if (!(INFO)->s->tot_locks) (void) _mi_writeinfo((INFO),0)
697
#define fast_mi_readinfo(INFO) ((INFO)->lock_type == F_UNLCK) && _mi_readinfo((INFO),F_RDLCK,1)
703
extern uint _mi_get_block_info(MI_BLOCK_INFO *,File, my_off_t);
704
extern uint _mi_rec_pack(MI_INFO *info,uchar *to,const uchar *from);
705
extern uint _mi_pack_get_block_info(MI_INFO *myisam, MI_BIT_BUFF *bit_buff,
706
MI_BLOCK_INFO *info, uchar **rec_buff_p,
707
File file, my_off_t filepos);
708
extern void _my_store_blob_length(uchar *pos,uint pack_length,uint length);
709
extern void _myisam_log(enum myisam_log_commands command,MI_INFO *info,
710
const uchar *buffert,uint length);
711
extern void _myisam_log_command(enum myisam_log_commands command,
712
MI_INFO *info, const uchar *buffert,
713
uint length, int result);
714
extern void _myisam_log_record(enum myisam_log_commands command,MI_INFO *info,
715
const uchar *record,my_off_t filepos,
717
extern void mi_report_error(int errcode, const char *file_name);
718
extern my_bool _mi_memmap_file(MI_INFO *info);
719
extern void _mi_unmap_file(MI_INFO *info);
720
extern uint save_pack_length(uint version, uchar *block_buff, ulong length);
721
extern uint read_pack_length(uint version, const uchar *buf, ulong *length);
722
extern uint calc_pack_length(uint version, ulong length);
723
extern size_t mi_mmap_pread(MI_INFO *info, uchar *Buffer,
724
size_t Count, my_off_t offset, myf MyFlags);
725
extern size_t mi_mmap_pwrite(MI_INFO *info, const uchar *Buffer,
726
size_t Count, my_off_t offset, myf MyFlags);
727
extern size_t mi_nommap_pread(MI_INFO *info, uchar *Buffer,
728
size_t Count, my_off_t offset, myf MyFlags);
729
extern size_t mi_nommap_pwrite(MI_INFO *info, const uchar *Buffer,
730
size_t Count, my_off_t offset, myf MyFlags);
732
uint mi_state_info_write(File file, MI_STATE_INFO *state, uint pWrite);
733
uchar *mi_state_info_read(uchar *ptr, MI_STATE_INFO *state);
734
uint mi_state_info_read_dsk(File file, MI_STATE_INFO *state, my_bool pRead);
735
uint mi_base_info_write(File file, MI_BASE_INFO *base);
736
uchar *my_n_base_info_read(uchar *ptr, MI_BASE_INFO *base);
737
int mi_keyseg_write(File file, const HA_KEYSEG *keyseg);
738
uchar *mi_keyseg_read(uchar *ptr, HA_KEYSEG *keyseg);
739
uint mi_keydef_write(File file, MI_KEYDEF *keydef);
740
uchar *mi_keydef_read(uchar *ptr, MI_KEYDEF *keydef);
741
uint mi_uniquedef_write(File file, MI_UNIQUEDEF *keydef);
742
uchar *mi_uniquedef_read(uchar *ptr, MI_UNIQUEDEF *keydef);
743
uint mi_recinfo_write(File file, MI_COLUMNDEF *recinfo);
744
uchar *mi_recinfo_read(uchar *ptr, MI_COLUMNDEF *recinfo);
745
extern int mi_disable_indexes(MI_INFO *info);
746
extern int mi_enable_indexes(MI_INFO *info);
747
extern int mi_indexes_are_disabled(MI_INFO *info);
748
ulong _my_calc_total_blob_length(MI_INFO *info, const uchar *record);
749
ha_checksum mi_checksum(MI_INFO *info, const uchar *buf);
750
ha_checksum mi_static_checksum(MI_INFO *info, const uchar *buf);
751
my_bool mi_check_unique(MI_INFO *info, MI_UNIQUEDEF *def, uchar *record,
752
ha_checksum unique_hash, my_off_t pos);
753
ha_checksum mi_unique_hash(MI_UNIQUEDEF *def, const uchar *buf);
754
int _mi_cmp_static_unique(MI_INFO *info, MI_UNIQUEDEF *def,
755
const uchar *record, my_off_t pos);
756
int _mi_cmp_dynamic_unique(MI_INFO *info, MI_UNIQUEDEF *def,
757
const uchar *record, my_off_t pos);
758
int mi_unique_comp(MI_UNIQUEDEF *def, const uchar *a, const uchar *b,
759
my_bool null_are_equal);
760
void mi_get_status(void* param, int concurrent_insert);
761
void mi_update_status(void* param);
762
void mi_restore_status(void* param);
763
void mi_copy_status(void* to,void *from);
764
my_bool mi_check_status(void* param);
765
void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows);
767
extern MI_INFO *test_if_reopen(char *filename);
768
my_bool check_table_is_closed(const char *name, const char *where);
769
int mi_open_datafile(MI_INFO *info, MYISAM_SHARE *share, File file_to_dup);
770
int mi_open_keyfile(MYISAM_SHARE *share);
771
void mi_setup_functions(register MYISAM_SHARE *share);
772
my_bool mi_dynmap_file(MI_INFO *info, my_off_t size);
773
void mi_remap_file(MI_INFO *info, my_off_t size);
775
int mi_check_index_cond(register MI_INFO *info, uint keynr, uchar *record);
776
void _mi_report_crashed(MI_INFO *file, const char *message,
777
const char *sfile, uint sline);
779
/* Functions needed by mi_check */
780
volatile int *killed_ptr(MI_CHECK *param);
781
void mi_check_print_error _VARARGS((MI_CHECK *param, const char *fmt,...));
782
void mi_check_print_warning _VARARGS((MI_CHECK *param, const char *fmt,...));
783
void mi_check_print_info _VARARGS((MI_CHECK *param, const char *fmt,...));
784
int flush_pending_blocks(MI_SORT_PARAM *param);
785
int sort_ft_buf_flush(MI_SORT_PARAM *sort_param);
786
int thr_write_keys(MI_SORT_PARAM *sort_param);
788
pthread_handler_t thr_find_all_keys(void *arg);
790
int flush_blocks(MI_CHECK *param, KEY_CACHE *key_cache, File file);
792
int sort_write_record(MI_SORT_PARAM *sort_param);
793
int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong);
795
extern void mi_set_index_cond_func(MI_INFO *info, index_cond_func_t func,