~jlukas79/+junk/mysql-server

« back to all changes in this revision

Viewing changes to include/myisam.h

manual merge 6.0-main --> 6.0-bka-review

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
/* This file should be included when using myisam_funktions */
 
16
/**
 
17
  @file
 
18
  This file should be included when using MyISAM functions.
 
19
*/
17
20
 
18
21
#ifndef _myisam_h
19
22
#define _myisam_h
31
34
#include "keycache.h"
32
35
#endif
33
36
#include "my_handler.h"
 
37
#include <myisamchk.h>
34
38
#include <mysql/plugin.h>
 
39
#include <hash.h>
35
40
 
36
41
/*
37
 
  There is a hard limit for the maximum number of keys as there are only
38
 
  8 bits in the index file header for the number of keys in a table.
39
 
  This means that 0..255 keys can exist for a table. The idea of
40
 
  MI_MAX_POSSIBLE_KEY is to ensure that one can use myisamchk & tools on
41
 
  a MyISAM table for which one has more keys than MyISAM is normally
42
 
  compiled for. If you don't have this, you will get a core dump when
43
 
  running myisamchk compiled for 128 keys on a table with 255 keys.
 
42
  Limit max keys according to HA_MAX_POSSIBLE_KEY; See myisamchk.h for details
44
43
*/
45
 
#define MI_MAX_POSSIBLE_KEY         255             /* For myisam_chk */
46
 
#if MAX_INDEXES > MI_MAX_POSSIBLE_KEY
47
 
#define MI_MAX_KEY                  MI_MAX_POSSIBLE_KEY /* Max allowed keys */
 
44
 
 
45
#if MAX_INDEXES > HA_MAX_POSSIBLE_KEY
 
46
#define MI_MAX_KEY                  HA_MAX_POSSIBLE_KEY /* Max allowed keys */
48
47
#else
49
48
#define MI_MAX_KEY                  MAX_INDEXES         /* Max allowed keys */
50
49
#endif
56
55
#define MI_MAX_KEY_LENGTH           1332            /* Max length in bytes */
57
56
#define MI_MAX_KEY_SEG              16              /* Max segments for key */
58
57
 
59
 
#define MI_MAX_POSSIBLE_KEY_BUFF (MI_MAX_KEY_LENGTH + 6 + 6) /* For mi_check */
 
58
#define MI_MAX_POSSIBLE_KEY_BUFF    HA_MAX_POSSIBLE_KEY_BUFF
60
59
 
61
60
#define MI_MAX_KEY_BUFF  (MI_MAX_KEY_LENGTH+MI_MAX_KEY_SEG*6+8+8)
62
61
#define MI_MAX_MSG_BUF      1024 /* used in CHECK TABLE, REPAIR TABLE */
70
69
#define MI_MIN_KEY_BLOCK_LENGTH 1024    /* Min key block length */
71
70
#define MI_MAX_KEY_BLOCK_LENGTH 16384
72
71
 
73
 
#define mi_portable_sizeof_char_ptr 8
74
 
 
75
72
/*
76
73
  In the following macros '_keyno_' is 0 .. keys-1.
77
74
  If there can be more keys than bits in the key_map, the highest bit
242
239
 
243
240
typedef struct st_columndef             /* column information */
244
241
{
245
 
  int16  type;                          /* en_fieldtype */
 
242
  enum en_fieldtype type;
246
243
  uint16 length;                        /* length of field */
247
244
  uint32 offset;                        /* Offset to position in row */
248
245
  uint8  null_bit;                      /* If column may be 0 */
257
254
#endif
258
255
} MI_COLUMNDEF;
259
256
 
260
 
/* invalidator function reference for Query Cache */
261
 
typedef void (* invalidator_by_filename)(const char * filename);
262
 
 
263
 
extern char * myisam_log_filename;              /* Name of logfile */
 
257
/** Physical logging is always compiled in. Undefine if want to benchmark */
 
258
#define HAVE_MYISAM_PHYSICAL_LOGGING 1
 
259
extern char * myisam_logical_log_filename;
264
260
extern ulong myisam_block_size;
265
261
extern ulong myisam_concurrent_insert;
266
262
extern my_bool myisam_flush,myisam_delay_key_write,myisam_single_user;
303
299
                    enum ha_extra_function function,
304
300
                    void *extra_arg);
305
301
extern int mi_reset(struct st_myisam_info *file);
306
 
extern ha_rows mi_records_in_range(MI_INFO *info, int inx,
 
302
extern ha_rows mi_records_in_range(MI_INFO *info,int inx,
307
303
                                   key_range *min_key, key_range *max_key);
308
 
extern int mi_log(int activate_log);
 
304
/** Open/close actions allowed on a MyISAM log */
 
305
enum enum_mi_log_action
 
306
{
 
307
  MI_LOG_ACTION_OPEN,
 
308
  MI_LOG_ACTION_CLOSE_CONSISTENT, MI_LOG_ACTION_CLOSE_INCONSISTENT
 
309
};
 
310
enum enum_mi_log_type { MI_LOG_PHYSICAL, MI_LOG_LOGICAL };
 
311
extern int mi_log(enum enum_mi_log_action action, enum enum_mi_log_type type,
 
312
                  const char *log_filename, const HASH *tables);
309
313
extern int mi_is_changed(struct st_myisam_info *info);
310
314
extern int mi_delete_all_rows(struct st_myisam_info *info);
311
315
extern ulong _mi_calc_blob_length(uint length , const uchar *pos);
312
316
extern uint mi_get_pointer_length(ulonglong file_length, uint def);
313
317
 
314
 
/* this is used to pass to mysql_myisamchk_table -- by Sasha Pachev */
 
318
/* this is used to pass to mysql_myisamchk_table */
315
319
 
316
320
#define   MYISAMCHK_REPAIR 1  /* equivalent to myisamchk -r */
317
321
#define   MYISAMCHK_VERIFY 2  /* Verify, run repair if failure */
318
322
 
319
 
/*
320
 
  Definitions needed for myisamchk.c
321
 
 
322
 
  Entries marked as "QQ to be removed" are NOT used to
323
 
  pass check/repair options to mi_check.c. They are used
324
 
  internally by myisamchk.c or/and ha_myisam.cc and should NOT
325
 
  be stored together with other flags. They should be removed
326
 
  from the following list to make addition of new flags possible.
327
 
*/
328
 
 
329
 
#define T_AUTO_INC              1
330
 
#define T_AUTO_REPAIR           2              /* QQ to be removed */
331
 
#define T_BACKUP_DATA           4
332
 
#define T_CALC_CHECKSUM         8
333
 
#define T_CHECK                 16             /* QQ to be removed */
334
 
#define T_CHECK_ONLY_CHANGED    32             /* QQ to be removed */
335
 
#define T_CREATE_MISSING_KEYS   64
336
 
#define T_DESCRIPT              128
337
 
#define T_DONT_CHECK_CHECKSUM   256
338
 
#define T_EXTEND                512
339
 
#define T_FAST                  (1L << 10)     /* QQ to be removed */
340
 
#define T_FORCE_CREATE          (1L << 11)     /* QQ to be removed */
341
 
#define T_FORCE_UNIQUENESS      (1L << 12)
342
 
#define T_INFO                  (1L << 13)
343
 
#define T_MEDIUM                (1L << 14)
344
 
#define T_QUICK                 (1L << 15)     /* QQ to be removed */
345
 
#define T_READONLY              (1L << 16)     /* QQ to be removed */
346
 
#define T_REP                   (1L << 17)
347
 
#define T_REP_BY_SORT           (1L << 18)     /* QQ to be removed */
348
 
#define T_REP_PARALLEL          (1L << 19)     /* QQ to be removed */
349
 
#define T_RETRY_WITHOUT_QUICK   (1L << 20)
350
 
#define T_SAFE_REPAIR           (1L << 21)
351
 
#define T_SILENT                (1L << 22)
352
 
#define T_SORT_INDEX            (1L << 23)     /* QQ to be removed */
353
 
#define T_SORT_RECORDS          (1L << 24)     /* QQ to be removed */
354
 
#define T_STATISTICS            (1L << 25)
355
 
#define T_UNPACK                (1L << 26)
356
 
#define T_UPDATE_STATE          (1L << 27)
357
 
#define T_VERBOSE               (1L << 28)
358
 
#define T_VERY_SILENT           (1L << 29)
359
 
#define T_WAIT_FOREVER          (1L << 30)
360
 
#define T_WRITE_LOOP            ((ulong) 1L << 31)
361
 
 
362
 
#define T_REP_ANY               (T_REP | T_REP_BY_SORT | T_REP_PARALLEL)
363
 
 
364
 
/*
365
 
  Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
366
 
  to mi_check.c follows:
367
 
*/
368
 
 
369
 
#define TT_USEFRM               1
370
 
#define TT_FOR_UPGRADE          2
371
 
 
372
 
#define O_NEW_INDEX     1               /* Bits set in out_flag */
373
 
#define O_NEW_DATA      2
374
 
#define O_DATA_LOST     4
375
 
 
376
 
/* these struct is used by my_check to tell it what to do */
377
 
 
378
 
typedef struct st_sort_key_blocks               /* Used when sorting */
379
 
{
380
 
  uchar *buff,*end_pos;
381
 
  uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
382
 
  uint last_length;
383
 
  int inited;
384
 
} SORT_KEY_BLOCKS;
385
 
 
386
 
 
387
 
/* 
388
 
  MyISAM supports several statistics collection methods. Currently statistics 
389
 
  collection method is not stored in MyISAM file and has to be specified for 
390
 
  each table analyze/repair operation in  MI_CHECK::stats_method.
391
 
*/
392
 
 
393
 
typedef enum 
394
 
{
395
 
  /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */
396
 
  MI_STATS_METHOD_NULLS_NOT_EQUAL,
397
 
  /* Treat NULLs as equal when collecting statistics (like 4.0 did) */
398
 
  MI_STATS_METHOD_NULLS_EQUAL,
399
 
  /* Ignore NULLs - count only tuples without NULLs in the index components */
400
 
  MI_STATS_METHOD_IGNORE_NULLS
401
 
} enum_mi_stats_method;
402
 
 
403
 
typedef struct st_mi_check_param
404
 
{
405
 
  ulonglong auto_increment_value;
406
 
  ulonglong max_data_file_length;
407
 
  ulonglong keys_in_use;
408
 
  ulonglong max_record_length;
409
 
  my_off_t search_after_block;
410
 
  my_off_t new_file_pos,key_file_blocks;
411
 
  my_off_t keydata,totaldata,key_blocks,start_check_pos;
412
 
  ha_rows total_records,total_deleted;
413
 
  ha_checksum record_checksum,glob_crc;
414
 
  ulong use_buffers,read_buffer_length,write_buffer_length,
415
 
        sort_buffer_length,sort_key_blocks;
416
 
  uint out_flag,warning_printed,error_printed,verbose;
417
 
  uint opt_sort_key,total_files,max_level;
418
 
  uint testflag, key_cache_block_size;
419
 
  uint8 language;
420
 
  my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
421
 
  my_bool retry_repair, force_sort;
422
 
  char temp_filename[FN_REFLEN],*isam_file_name;
 
323
typedef uint mi_bit_type;
 
324
 
 
325
typedef struct st_mi_bit_buff
 
326
{                                       /* Used for packing of record */
 
327
  mi_bit_type current_byte;
 
328
  uint bits;
 
329
  uchar *pos, *end, *blob_pos, *blob_end;
 
330
  uint error;
 
331
} MI_BIT_BUFF;
 
332
 
 
333
 
 
334
typedef struct st_sort_info
 
335
{
 
336
#ifdef THREAD
 
337
  /* sync things */
 
338
  pthread_mutex_t mutex;
 
339
  pthread_cond_t cond;
 
340
#endif
 
341
  MI_INFO *info;
 
342
  HA_CHECK *param;
 
343
  uchar *buff;
 
344
  SORT_KEY_BLOCKS *key_block, *key_block_end;
 
345
  SORT_FT_BUF *ft_buf;
 
346
  my_off_t filelength, dupp, buff_length;
 
347
  ha_rows max_records;
 
348
  uint current_key, total_keys;
 
349
  uint got_error, threads_running;
 
350
  myf myf_rw;
 
351
  enum data_file_type new_data_file_type;
 
352
} MI_SORT_INFO;
 
353
 
 
354
typedef struct st_mi_sort_param
 
355
{
 
356
  pthread_t thr;
 
357
  IO_CACHE read_cache, tempfile, tempfile_for_exceptions;
 
358
  DYNAMIC_ARRAY buffpek;
 
359
  MI_BIT_BUFF   bit_buff;               /* For parallel repair of packrec. */
 
360
  
 
361
  MI_KEYDEF *keyinfo;
 
362
  MI_SORT_INFO *sort_info;
 
363
  HA_KEYSEG *seg;
 
364
  uchar **sort_keys;
 
365
  uchar *rec_buff;
 
366
  void *wordlist, *wordptr;
 
367
  MEM_ROOT wordroot;
 
368
  uchar *record;
423
369
  MY_TMPDIR *tmpdir;
424
 
  int tmpfile_createflag;
425
 
  myf myf_rw;
426
 
  IO_CACHE read_cache;
427
 
  
 
370
 
428
371
  /* 
429
372
    The next two are used to collect statistics, see update_key_parts for
430
373
    description.
431
374
  */
432
 
  ulonglong unique_count[MI_MAX_KEY_SEG+1];
433
 
  ulonglong notnull_count[MI_MAX_KEY_SEG+1];
434
 
  
435
 
  ha_checksum key_crc[MI_MAX_POSSIBLE_KEY];
436
 
  ulong rec_per_key_part[MI_MAX_KEY_SEG*MI_MAX_POSSIBLE_KEY];
437
 
  void *thd;
438
 
  const char *db_name, *table_name;
439
 
  const char *op_name;
440
 
  enum_mi_stats_method stats_method;
441
 
} MI_CHECK;
442
 
 
443
 
typedef struct st_sort_ft_buf
444
 
{
445
 
  uchar *buf, *end;
446
 
  int   count;
447
 
  uchar lastkey[MI_MAX_KEY_BUFF];
448
 
} SORT_FT_BUF;
449
 
 
450
 
typedef struct st_sort_info
451
 
{
452
 
  my_off_t filelength,dupp,buff_length;
453
 
  ha_rows max_records;
454
 
  uint current_key, total_keys;
455
 
  myf myf_rw;
456
 
  enum data_file_type new_data_file_type;
457
 
  MI_INFO *info;
458
 
  MI_CHECK *param;
459
 
  uchar *buff;
460
 
  SORT_KEY_BLOCKS *key_block,*key_block_end;
461
 
  SORT_FT_BUF *ft_buf;
462
 
  /* sync things */
463
 
  uint got_error, threads_running;
464
 
#ifdef THREAD
465
 
  pthread_mutex_t mutex;
466
 
  pthread_cond_t  cond;
467
 
#endif
468
 
} SORT_INFO;
 
375
  ulonglong unique[HA_MAX_KEY_SEG+1];
 
376
  ulonglong notnull[HA_MAX_KEY_SEG+1];
 
377
 
 
378
  my_off_t pos,max_pos,filepos,start_recpos;
 
379
  uint key, key_length,real_key_length,sortbuff_size;
 
380
  uint maxbuffers, keys, find_length, sort_keys_length;
 
381
  my_bool fix_datafile, master;
 
382
  my_bool calc_checksum;                /* calculate table checksum */
 
383
 
 
384
  int (*key_cmp)(struct st_mi_sort_param *, const void *, const void *);
 
385
  int (*key_read)(struct st_mi_sort_param *,void *);
 
386
  int (*key_write)(struct st_mi_sort_param *, const void *);
 
387
  void (*lock_in_memory)(HA_CHECK *);
 
388
  NEAR int (*write_keys)(struct st_mi_sort_param *, register uchar **,
 
389
                     uint , struct st_buffpek *, IO_CACHE *);
 
390
  NEAR uint (*read_to_buffer)(IO_CACHE *,struct st_buffpek *, uint);
 
391
  NEAR int (*write_key)(struct st_mi_sort_param *, IO_CACHE *,uchar *,
 
392
                       uint, uint);
 
393
} MI_SORT_PARAM;
 
394
 
469
395
 
470
396
/* functions in mi_check */
471
 
void myisamchk_init(MI_CHECK *param);
472
 
int chk_status(MI_CHECK *param, MI_INFO *info);
473
 
int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag);
474
 
int chk_size(MI_CHECK *param, MI_INFO *info);
475
 
int chk_key(MI_CHECK *param, MI_INFO *info);
476
 
int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend);
477
 
int mi_repair(MI_CHECK *param, register MI_INFO *info,
 
397
void myisamchk_init(HA_CHECK *param);
 
398
int chk_status(HA_CHECK *param, MI_INFO *info);
 
399
int chk_del(HA_CHECK *param, register MI_INFO *info, ulonglong test_flag);
 
400
int chk_size(HA_CHECK *param, MI_INFO *info);
 
401
int chk_key(HA_CHECK *param, MI_INFO *info);
 
402
int chk_data_link(HA_CHECK *param, MI_INFO *info, my_bool extend);
 
403
int mi_repair(HA_CHECK *param, register MI_INFO *info,
478
404
              char * name, int rep_quick);
479
 
int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name);
480
 
int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
 
405
int mi_sort_index(HA_CHECK *param, register MI_INFO *info, char * name);
 
406
int mi_repair_by_sort(HA_CHECK *param, register MI_INFO *info,
481
407
                      const char * name, int rep_quick);
482
 
int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
 
408
int mi_repair_parallel(HA_CHECK *param, register MI_INFO *info,
483
409
                      const char * name, int rep_quick);
484
410
int change_to_newfile(const char * filename, const char * old_ext,
485
411
                      const char * new_ext, uint raid_chunks,
486
412
                      myf myflags);
487
 
int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type,
 
413
int lock_file(HA_CHECK *param, File file, my_off_t start, int lock_type,
488
414
              const char *filetype, const char *filename);
489
 
void lock_memory(MI_CHECK *param);
490
 
void update_auto_increment_key(MI_CHECK *param, MI_INFO *info,
 
415
void lock_memory(HA_CHECK *param);
 
416
void update_auto_increment_key(HA_CHECK *param, MI_INFO *info,
491
417
                               my_bool repair);
492
 
int update_state_info(MI_CHECK *param, MI_INFO *info,uint update);
 
418
int update_state_info(HA_CHECK *param, MI_INFO *info,uint update);
493
419
void update_key_parts(MI_KEYDEF *keyinfo, ulong *rec_per_key_part,
494
420
                      ulonglong *unique, ulonglong *notnull, 
495
421
                      ulonglong records);
496
 
int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
 
422
int filecopy(HA_CHECK *param, File to,File from,my_off_t start,
497
423
             my_off_t length, const char *type);
498
424
int movepoint(MI_INFO *info,uchar *record,my_off_t oldpos,
499
425
              my_off_t newpos, uint prot_key);
500
 
int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile);
 
426
int write_data_suffix(MI_SORT_INFO *sort_info, my_bool fix_datafile);
501
427
int test_if_almost_full(MI_INFO *info);
502
 
int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename);
 
428
int recreate_table(HA_CHECK *param, MI_INFO **org_info, char *filename);
503
429
void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows);
504
430
my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map,
505
431
                            my_bool force);
513
439
                         KEY_CACHE *new_key_cache);
514
440
int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves);
515
441
 
 
442
int write_data_suffix(MI_SORT_INFO *sort_info, my_bool fix_datafile);
 
443
int flush_pending_blocks(MI_SORT_PARAM *param);
 
444
int sort_ft_buf_flush(MI_SORT_PARAM *sort_param);
 
445
int thr_write_keys(MI_SORT_PARAM *sort_param);
 
446
int sort_write_record(MI_SORT_PARAM *sort_param);
 
447
int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong);
 
448
 
516
449
#ifdef  __cplusplus
517
450
}
518
451
#endif