myisam.h 19.2 KB
Newer Older
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
1
/* Copyright (C) 2000 MySQL AB
2

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
3 4
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
7
   This program is distributed in the hope that it will be useful,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
9 10
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
11

monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
12 13 14
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

/* This file should be included when using myisam_funktions */

#ifndef _myisam_h
#define _myisam_h
#ifdef	__cplusplus
extern "C" {
#endif

#ifndef _my_base_h
#include <my_base.h>
#endif
#ifndef _m_ctype_h
#include <m_ctype.h>
#endif
30 31 32
#ifndef _keycache_h
#include "keycache.h"
#endif
33
#include "my_handler.h"
34
#include <mysql/plugin.h>
bk@work.mysql.com's avatar
bk@work.mysql.com committed
35

36
/*
37
  Limit max keys according to HA_MAX_POSSIBLE_KEY
38
*/
39 40 41

#if MAX_INDEXES > HA_MAX_POSSIBLE_KEY
#define MI_MAX_KEY                  HA_MAX_POSSIBLE_KEY /* Max allowed keys */
42 43 44 45
#else
#define MI_MAX_KEY                  MAX_INDEXES         /* Max allowed keys */
#endif

46
#define MI_MAX_POSSIBLE_KEY_BUFF    HA_MAX_POSSIBLE_KEY_BUFF
47 48
/*
  The following defines can be increased if necessary.
49
  But beware the dependency of MI_MAX_POSSIBLE_KEY_BUFF and MI_MAX_KEY_LENGTH.
50
*/
51
#define MI_MAX_KEY_LENGTH           1000            /* Max length in bytes */
52
#define MI_MAX_KEY_SEG              16              /* Max segments for key */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
53 54 55 56 57

#define MI_MAX_KEY_BUFF  (MI_MAX_KEY_LENGTH+MI_MAX_KEY_SEG*6+8+8)
#define MI_MAX_MSG_BUF      1024 /* used in CHECK TABLE, REPAIR TABLE */
#define MI_NAME_IEXT	".MYI"
#define MI_NAME_DEXT	".MYD"
58
/* Max extra space to use when sorting keys */
59
#define MI_MAX_TEMP_LENGTH	2*1024L*1024L*1024L
bk@work.mysql.com's avatar
bk@work.mysql.com committed
60

61 62 63 64 65
/* Possible values for myisam_block_size (must be power of 2) */
#define MI_KEY_BLOCK_LENGTH	1024	/* default key block length */
#define MI_MIN_KEY_BLOCK_LENGTH	1024	/* Min key block length */
#define MI_MAX_KEY_BLOCK_LENGTH	16384

66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
/*
  In the following macros '_keyno_' is 0 .. keys-1.
  If there can be more keys than bits in the key_map, the highest bit
  is for all upper keys. They cannot be switched individually.
  This means that clearing of high keys is ignored, setting one high key
  sets all high keys.
*/
#define MI_KEYMAP_BITS      (8 * SIZEOF_LONG_LONG)
#define MI_KEYMAP_HIGH_MASK (ULL(1) << (MI_KEYMAP_BITS - 1))
#define mi_get_mask_all_keys_active(_keys_) \
                            (((_keys_) < MI_KEYMAP_BITS) ? \
                             ((ULL(1) << (_keys_)) - ULL(1)) : \
                             (~ ULL(0)))

#if MI_MAX_KEY > MI_KEYMAP_BITS

#define mi_is_key_active(_keymap_,_keyno_) \
                            (((_keyno_) < MI_KEYMAP_BITS) ? \
                             test((_keymap_) & (ULL(1) << (_keyno_))) : \
                             test((_keymap_) & MI_KEYMAP_HIGH_MASK))
#define mi_set_key_active(_keymap_,_keyno_) \
                            (_keymap_)|= (((_keyno_) < MI_KEYMAP_BITS) ? \
                                          (ULL(1) << (_keyno_)) : \
                                          MI_KEYMAP_HIGH_MASK)
#define mi_clear_key_active(_keymap_,_keyno_) \
                            (_keymap_)&= (((_keyno_) < MI_KEYMAP_BITS) ? \
                                          (~ (ULL(1) << (_keyno_))) : \
                                          (~ (ULL(0))) /*ignore*/ )

#else

#define mi_is_key_active(_keymap_,_keyno_) \
                            test((_keymap_) & (ULL(1) << (_keyno_)))
#define mi_set_key_active(_keymap_,_keyno_) \
                            (_keymap_)|= (ULL(1) << (_keyno_))
#define mi_clear_key_active(_keymap_,_keyno_) \
                            (_keymap_)&= (~ (ULL(1) << (_keyno_)))

#endif

#define mi_is_any_key_active(_keymap_) \
                            test((_keymap_))
#define mi_is_all_keys_active(_keymap_,_keys_) \
                            ((_keymap_) == mi_get_mask_all_keys_active(_keys_))
#define mi_set_all_keys_active(_keymap_,_keys_) \
                            (_keymap_)= mi_get_mask_all_keys_active(_keys_)
#define mi_clear_all_keys_active(_keymap_) \
                            (_keymap_)= 0
#define mi_intersect_keys_active(_to_,_from_) \
                            (_to_)&= (_from_)
#define mi_is_any_intersect_keys_active(_keymap1_,_keys_,_keymap2_) \
                            ((_keymap1_) & (_keymap2_) & \
                             mi_get_mask_all_keys_active(_keys_))
#define mi_copy_keys_active(_to_,_maxkeys_,_from_) \
                            (_to_)= (mi_get_mask_all_keys_active(_maxkeys_) & \
                                     (_from_))

bk@work.mysql.com's avatar
bk@work.mysql.com committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	/* Param to/from mi_info */

typedef struct st_mi_isaminfo		/* Struct from h_info */
{
  ha_rows records;			/* Records in database */
  ha_rows deleted;			/* Deleted records in database */
  my_off_t recpos;			/* Pos for last used record */
  my_off_t newrecpos;			/* Pos if we write new record */
  my_off_t dupp_key_pos;		/* Position to record with dupp key */
  my_off_t data_file_length,		/* Length of data file */
           max_data_file_length,
           index_file_length,
           max_index_file_length,
           delete_length;
  ulong reclength;			/* Recordlength */
  ulong mean_reclength;			/* Mean recordlength (if packed) */
  ulonglong auto_increment;
  ulonglong key_map;			/* Which keys are used */
141
  char  *data_file_name, *index_file_name;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
142
  uint  keys;				/* Number of keys in use */
monty@hundin.mysql.fi's avatar
monty@hundin.mysql.fi committed
143
  uint	options;			/* HA_OPTION_... used */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157
  int	errkey,				/* With key was dupplicated on err */
	sortkey;			/* clustered by this key */
  File	filenr;				/* (uniq) filenr for datafile */
  time_t create_time;			/* When table was created */
  time_t check_time;
  time_t update_time;
  uint  reflength;
  ulong record_offset;
  ulong *rec_per_key;			/* for sql optimizing */
} MI_ISAMINFO;


typedef struct st_mi_create_info
{
158
  const char *index_file_name, *data_file_name;	/* If using symlinks */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
159 160 161 162
  ha_rows max_rows;
  ha_rows reloc_rows;
  ulonglong auto_increment;
  ulonglong data_file_length;
sergefp@mysql.com's avatar
sergefp@mysql.com committed
163
  ulonglong key_file_length;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
164 165
  uint old_options;
  uint8 language;
166
  my_bool with_auto_increment;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
167 168 169
} MI_CREATE_INFO;

struct st_myisam_info;			/* For referense */
monty@mysql.com's avatar
monty@mysql.com committed
170
struct st_mi_isam_share;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
171 172 173 174 175
typedef struct st_myisam_info MI_INFO;
struct st_mi_s_param;

typedef struct st_mi_keydef		/* Key definition with open & info */
{
monty@mysql.com's avatar
monty@mysql.com committed
176
  struct st_mi_isam_share *share;       /* Pointer to base (set in mi_open) */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
177 178 179
  uint16 keysegs;			/* Number of key-segment */
  uint16 flag;				/* NOSAME, PACK_USED */

180
  uint8  key_alg;			/* BTREE, RTREE */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
181 182 183 184 185
  uint16 block_length;			/* Length of keyblock (auto) */
  uint16 underflow_block_length;	/* When to execute underflow */
  uint16 keylength;			/* Tot length of keyparts (auto) */
  uint16 minlength;			/* min length of (packed) key (auto) */
  uint16 maxlength;			/* max length of (packed) key (auto) */
186
  uint16 block_size_index;		/* block_size (auto) */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
187
  uint32 version;			/* For concurrent read/write */
188
  uint32 ftparser_nr;                   /* distinct ftparser number */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
189

190
  HA_KEYSEG *seg,*end;
191
  struct st_mysql_ftparser *parser;     /* Fulltext [pre]parser */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
192 193 194 195 196 197 198 199 200 201 202
  int (*bin_search)(struct st_myisam_info *info,struct st_mi_keydef *keyinfo,
		    uchar *page,uchar *key,
		    uint key_len,uint comp_flag,uchar * *ret_pos,
		    uchar *buff, my_bool *was_last_key);
  uint (*get_key)(struct st_mi_keydef *keyinfo,uint nod_flag,uchar * *page,
		  uchar *key);
  int (*pack_key)(struct st_mi_keydef *keyinfo,uint nod_flag,uchar *next_key,
		  uchar *org_key, uchar *prev_key, uchar *key,
		  struct st_mi_s_param *s_temp);
  void (*store_key)(struct st_mi_keydef *keyinfo, uchar *key_pos,
		    struct st_mi_s_param *s_temp);
203 204
  int (*ck_insert)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen);
  int (*ck_delete)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
205 206 207 208 209 210 211 212 213 214
} MI_KEYDEF;


#define MI_UNIQUE_HASH_LENGTH	4

typedef struct st_unique_def		/* Segment definition of unique */
{
  uint16 keysegs;			/* Number of key-segment */
  uchar key;				/* Mapped to which key */
  uint8 null_are_equal;
215
  HA_KEYSEG *seg,*end;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
216 217 218 219 220 221
} MI_UNIQUEDEF;

typedef struct st_mi_decode_tree	/* Decode huff-table */
{
  uint16 *table;
  uint	 quick_table_bits;
222
  uchar	 *intervalls;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
223 224 225 226 227
} MI_DECODE_TREE;


struct st_mi_bit_buff;

228 229 230 231 232
/*
  Note that null markers should always be first in a row !
  When creating a column, one should only specify:
  type, length, null_bit and null_pos
*/
bk@work.mysql.com's avatar
bk@work.mysql.com committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

typedef struct st_columndef		/* column information */
{
  int16  type;				/* en_fieldtype */
  uint16 length;			/* length of field */
  uint32 offset;			/* Offset to position in row */
  uint8  null_bit;			/* If column may be 0 */
  uint16 null_pos;			/* position for null marker */

#ifndef NOT_PACKED_DATABASES
  void (*unpack)(struct st_columndef *rec,struct st_mi_bit_buff *buff,
		 uchar *start,uchar *end);
  enum en_fieldtype base_type;
  uint space_length_bits,pack_type;
  MI_DECODE_TREE *huff_tree;
#endif
} MI_COLUMNDEF;


252
extern char * myisam_log_filename;		/* Name of logfile */
253 254
extern ulong myisam_block_size;
extern ulong myisam_concurrent_insert;
255
extern my_bool myisam_flush,myisam_delay_key_write,myisam_single_user;
256
extern my_off_t myisam_max_temp_length;
serg@serg.mylan's avatar
serg@serg.mylan committed
257
extern ulong myisam_bulk_insert_tree_size, myisam_data_pointer_size;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
258

259 260 261 262
/* usually used to check if a symlink points into the mysql data home */
/* which is normally forbidden                                        */
extern int (*myisam_test_invalid_symlink)(const char *filename);

bk@work.mysql.com's avatar
bk@work.mysql.com committed
263 264 265
	/* Prototypes for myisam-functions */

extern int mi_close(struct st_myisam_info *file);
266
extern int mi_delete(struct st_myisam_info *file,const uchar *buff);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
267 268 269
extern struct st_myisam_info *mi_open(const char *name,int mode,
				      uint wait_if_locked);
extern int mi_panic(enum ha_panic_function function);
270 271
extern int mi_rfirst(struct st_myisam_info *file,uchar *buf,int inx);
extern int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
272
                   key_part_map keypart_map, enum ha_rkey_function search_flag);
273 274 275 276 277
extern int mi_rlast(struct st_myisam_info *file,uchar *buf,int inx);
extern int mi_rnext(struct st_myisam_info *file,uchar *buf,int inx);
extern int mi_rnext_same(struct st_myisam_info *info, uchar *buf);
extern int mi_rprev(struct st_myisam_info *file,uchar *buf,int inx);
extern int mi_rrnd(struct st_myisam_info *file,uchar *buf, my_off_t pos);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
278
extern int mi_scan_init(struct st_myisam_info *file);
279 280 281
extern int mi_scan(struct st_myisam_info *file,uchar *buf);
extern int mi_rsame(struct st_myisam_info *file,uchar *record,int inx);
extern int mi_rsame_with_pos(struct st_myisam_info *file,uchar *record,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
282
			     int inx, my_off_t pos);
283 284 285
extern int mi_update(struct st_myisam_info *file,const uchar *old,
		     uchar *new_record);
extern int mi_write(struct st_myisam_info *file,uchar *buff);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
286 287 288 289
extern my_off_t mi_position(struct st_myisam_info *file);
extern int mi_status(struct st_myisam_info *info, MI_ISAMINFO *x, uint flag);
extern int mi_lock_database(struct st_myisam_info *file,int lock_type);
extern int mi_create(const char *name,uint keys,MI_KEYDEF *keydef,
290
		     uint columns, MI_COLUMNDEF *columndef,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
291 292 293 294 295
		     uint uniques, MI_UNIQUEDEF *uniquedef,
		     MI_CREATE_INFO *create_info, uint flags);
extern int mi_delete_table(const char *name);
extern int mi_rename(const char *from, const char *to);
extern int mi_extra(struct st_myisam_info *file,
296 297
		    enum ha_extra_function function,
		    void *extra_arg);
298
extern int mi_reset(struct st_myisam_info *file);
299
extern ha_rows mi_records_in_range(MI_INFO *info, int inx,
300
                                   key_range *min_key, key_range *max_key);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
301 302 303
extern int mi_log(int activate_log);
extern int mi_is_changed(struct st_myisam_info *info);
extern int mi_delete_all_rows(struct st_myisam_info *info);
304
extern ulong _mi_calc_blob_length(uint length , const uchar *pos);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
305 306
extern uint mi_get_pointer_length(ulonglong file_length, uint def);

307
/* this is used to pass to mysql_myisamchk_table */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
308

309 310
#define   MYISAMCHK_REPAIR 1  /* equivalent to myisamchk -r */
#define   MYISAMCHK_VERIFY 2  /* Verify, run repair if failure */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
311

312 313
/*
  Definitions needed for myisamchk.c
bk@work.mysql.com's avatar
bk@work.mysql.com committed
314

315
  Entries marked as "QQ to be removed" are NOT used to
316 317 318
  pass check/repair options to mi_check.c. They are used
  internally by myisamchk.c or/and ha_myisam.cc and should NOT
  be stored together with other flags. They should be removed
319
  from the following list to make addition of new flags possible.
320
*/
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
321

322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352
#define T_AUTO_INC              1
#define T_AUTO_REPAIR           2              /* QQ to be removed */
#define T_BACKUP_DATA           4
#define T_CALC_CHECKSUM         8
#define T_CHECK                 16             /* QQ to be removed */
#define T_CHECK_ONLY_CHANGED    32             /* QQ to be removed */
#define T_CREATE_MISSING_KEYS   64
#define T_DESCRIPT              128
#define T_DONT_CHECK_CHECKSUM   256
#define T_EXTEND                512
#define T_FAST                  (1L << 10)     /* QQ to be removed */
#define T_FORCE_CREATE          (1L << 11)     /* QQ to be removed */
#define T_FORCE_UNIQUENESS      (1L << 12)
#define T_INFO                  (1L << 13)
#define T_MEDIUM                (1L << 14)
#define T_QUICK                 (1L << 15)     /* QQ to be removed */
#define T_READONLY              (1L << 16)     /* QQ to be removed */
#define T_REP                   (1L << 17)
#define T_REP_BY_SORT           (1L << 18)     /* QQ to be removed */
#define T_REP_PARALLEL          (1L << 19)     /* QQ to be removed */
#define T_RETRY_WITHOUT_QUICK   (1L << 20)
#define T_SAFE_REPAIR           (1L << 21)
#define T_SILENT                (1L << 22)
#define T_SORT_INDEX            (1L << 23)     /* QQ to be removed */
#define T_SORT_RECORDS          (1L << 24)     /* QQ to be removed */
#define T_STATISTICS            (1L << 25)
#define T_UNPACK                (1L << 26)
#define T_UPDATE_STATE          (1L << 27)
#define T_VERBOSE               (1L << 28)
#define T_VERY_SILENT           (1L << 29)
#define T_WAIT_FOREVER          (1L << 30)
353
#define T_WRITE_LOOP            ((ulong) 1L << 31)
354 355

#define T_REP_ANY               (T_REP | T_REP_BY_SORT | T_REP_PARALLEL)
bk@work.mysql.com's avatar
bk@work.mysql.com committed
356

357 358 359 360
/*
  Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
  to mi_check.c follows:
*/
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
361 362

#define TT_USEFRM               1
363
#define TT_FOR_UPGRADE          2
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
364

bk@work.mysql.com's avatar
bk@work.mysql.com committed
365 366
#define O_NEW_INDEX	1		/* Bits set in out_flag */
#define O_NEW_DATA	2
367
#define O_DATA_LOST	4
bk@work.mysql.com's avatar
bk@work.mysql.com committed
368 369 370

/* these struct is used by my_check to tell it what to do */

371 372
typedef struct st_sort_key_blocks		/* Used when sorting */
{
bk@work.mysql.com's avatar
bk@work.mysql.com committed
373 374 375 376 377 378 379
  uchar *buff,*end_pos;
  uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
  uint last_length;
  int inited;
} SORT_KEY_BLOCKS;


380 381 382 383 384 385 386 387 388
/* 
  MyISAM supports several statistics collection methods. Currently statistics 
  collection method is not stored in MyISAM file and has to be specified for 
  each table analyze/repair operation in  MI_CHECK::stats_method.
*/

typedef enum 
{
  /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */
serg@serg.mylan's avatar
serg@serg.mylan committed
389
  MI_STATS_METHOD_NULLS_NOT_EQUAL,
390
  /* Treat NULLs as equal when collecting statistics (like 4.0 did) */
391
  MI_STATS_METHOD_NULLS_EQUAL,
392
  /* Ignore NULLs - count only tuples without NULLs in the index components */
393
  MI_STATS_METHOD_IGNORE_NULLS
394 395
} enum_mi_stats_method;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
396 397
typedef struct st_mi_check_param
{
398 399 400
  ulonglong auto_increment_value;
  ulonglong max_data_file_length;
  ulonglong keys_in_use;
401
  ulonglong max_record_length;
402 403 404 405 406
  my_off_t search_after_block;
  my_off_t new_file_pos,key_file_blocks;
  my_off_t keydata,totaldata,key_blocks,start_check_pos;
  ha_rows total_records,total_deleted;
  ha_checksum record_checksum,glob_crc;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
407 408
  ulong	use_buffers,read_buffer_length,write_buffer_length,
	sort_buffer_length,sort_key_blocks;
serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
409
  uint out_flag,warning_printed,error_printed,verbose;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
410
  uint opt_sort_key,total_files,max_level;
411
  uint testflag, key_cache_block_size;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
412 413
  uint8 language;
  my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
414
  my_bool retry_repair, force_sort;
415 416
  char temp_filename[FN_REFLEN],*isam_file_name;
  MY_TMPDIR *tmpdir;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
417 418 419
  int tmpfile_createflag;
  myf myf_rw;
  IO_CACHE read_cache;
420 421 422 423 424
  
  /* 
    The next two are used to collect statistics, see update_key_parts for
    description.
  */
bk@work.mysql.com's avatar
bk@work.mysql.com committed
425
  ulonglong unique_count[MI_MAX_KEY_SEG+1];
426 427
  ulonglong notnull_count[MI_MAX_KEY_SEG+1];
  
428 429
  ha_checksum key_crc[HA_MAX_POSSIBLE_KEY];
  ulong rec_per_key_part[MI_MAX_KEY_SEG*HA_MAX_POSSIBLE_KEY];
430
  void *thd;
431 432
  const char *db_name, *table_name;
  const char *op_name;
433
  enum_mi_stats_method stats_method;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
434 435
} MI_CHECK;

436 437 438 439 440 441
typedef struct st_sort_ft_buf
{
  uchar *buf, *end;
  int   count;
  uchar lastkey[MI_MAX_KEY_BUFF];
} SORT_FT_BUF;
442

serg@serg.mysql.com's avatar
serg@serg.mysql.com committed
443
typedef struct st_sort_info
444
{
445
  my_off_t filelength,dupp,buff_length;
bk@work.mysql.com's avatar
bk@work.mysql.com committed
446
  ha_rows max_records;
447
  uint current_key, total_keys;
448
  myf myf_rw;
449 450 451
  enum data_file_type new_data_file_type;
  MI_INFO *info;
  MI_CHECK *param;
452
  uchar *buff;
453
  SORT_KEY_BLOCKS *key_block,*key_block_end;
454 455
  SORT_FT_BUF *ft_buf;
  /* sync things */
456
  uint got_error, threads_running;
457
#ifdef THREAD
458 459
  pthread_mutex_t mutex;
  pthread_cond_t  cond;
460
#endif
461 462
} SORT_INFO;

bk@work.mysql.com's avatar
bk@work.mysql.com committed
463 464
/* functions in mi_check */
void myisamchk_init(MI_CHECK *param);
465
int chk_status(MI_CHECK *param, MI_INFO *info);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
466 467 468 469 470
int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag);
int chk_size(MI_CHECK *param, MI_INFO *info);
int chk_key(MI_CHECK *param, MI_INFO *info);
int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend);
int mi_repair(MI_CHECK *param, register MI_INFO *info,
471 472
	      char * name, int rep_quick);
int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
473 474
int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
		      const char * name, int rep_quick);
475 476
int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
		      const char * name, int rep_quick);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
477
int change_to_newfile(const char * filename, const char * old_ext,
478 479
		      const char * new_ext, uint raid_chunks,
		      myf myflags);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
480 481 482
int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type,
	      const char *filetype, const char *filename);
void lock_memory(MI_CHECK *param);
483 484
void update_auto_increment_key(MI_CHECK *param, MI_INFO *info,
			       my_bool repair);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
485
int update_state_info(MI_CHECK *param, MI_INFO *info,uint update);
486
void update_key_parts(MI_KEYDEF *keyinfo, ulong *rec_per_key_part,
487 488
                      ulonglong *unique, ulonglong *notnull, 
                      ulonglong records);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
489 490
int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
	     my_off_t length, const char *type);
491
int movepoint(MI_INFO *info,uchar *record,my_off_t oldpos,
bk@work.mysql.com's avatar
bk@work.mysql.com committed
492
	      my_off_t newpos, uint prot_key);
493
int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
494 495
int test_if_almost_full(MI_INFO *info);
int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename);
496
void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows);
497 498
my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map,
			    my_bool force);
bk@work.mysql.com's avatar
bk@work.mysql.com committed
499

500 501 502
int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows);
void mi_flush_bulk_insert(MI_INFO *info, uint inx);
void mi_end_bulk_insert(MI_INFO *info);
503
int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map, 
504 505 506
			   KEY_CACHE *key_cache);
void mi_change_key_cache(KEY_CACHE *old_key_cache,
			 KEY_CACHE *new_key_cache);
igor@rurik.mysql.com's avatar
igor@rurik.mysql.com committed
507
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves);
508

bk@work.mysql.com's avatar
bk@work.mysql.com committed
509 510 511 512
#ifdef	__cplusplus
}
#endif
#endif