~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisam.h

  • Committer: Eric Herman
  • Date: 2008-12-07 12:17:49 UTC
  • mto: (656.1.14 devel)
  • mto: This revision was merged to the branch mainline in revision 670.
  • Revision ID: eric@mysql.com-20081207121749-kv5yp8o1u3fxb0lz
added some essential notes to the README

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
extern "C" {
22
22
#endif
23
23
 
24
 
#ifndef _my_base_h
25
 
#include <my_base.h>
26
 
#endif
 
24
#include <drizzled/base.h>
27
25
#ifndef _m_ctype_h
28
 
#include <m_ctype.h>
 
26
#include <mystrings/m_ctype.h>
29
27
#endif
30
28
#ifndef _keycache_h
31
29
#include "keycache.h"
32
30
#endif
33
 
#include "my_handler.h"
34
 
#include <drizzle/plugin.h>
 
31
#include <storage/myisam/my_handler.h>
 
32
#include <mysys/iocache.h>
35
33
 
36
34
/*
37
35
  Limit max keys according to HA_MAX_POSSIBLE_KEY
71
69
  This means that clearing of high keys is ignored, setting one high key
72
70
  sets all high keys.
73
71
*/
74
 
#define MI_KEYMAP_BITS      (8 * SIZEOF_LONG_LONG)
75
 
#define MI_KEYMAP_HIGH_MASK (1ULL << (MI_KEYMAP_BITS - 1))
 
72
#define MI_KEYMAP_BITS      (64)
 
73
#define MI_KEYMAP_HIGH_MASK (1UL << (MI_KEYMAP_BITS - 1))
76
74
#define mi_get_mask_all_keys_active(_keys_) \
77
75
                            (((_keys_) < MI_KEYMAP_BITS) ? \
78
 
                             ((1ULL << (_keys_)) - 1ULL) : \
79
 
                             (~ 0ULL))
 
76
                             ((1UL << (_keys_)) - 1UL) : \
 
77
                             (~ 0UL))
80
78
 
81
79
#if MI_MAX_KEY > MI_KEYMAP_BITS
82
80
 
83
81
#define mi_is_key_active(_keymap_,_keyno_) \
84
82
                            (((_keyno_) < MI_KEYMAP_BITS) ? \
85
 
                             test((_keymap_) & (1ULL << (_keyno_))) : \
 
83
                             test((_keymap_) & (1UL << (_keyno_))) : \
86
84
                             test((_keymap_) & MI_KEYMAP_HIGH_MASK))
87
85
#define mi_set_key_active(_keymap_,_keyno_) \
88
86
                            (_keymap_)|= (((_keyno_) < MI_KEYMAP_BITS) ? \
89
 
                                          (1ULL << (_keyno_)) : \
 
87
                                          (1UL << (_keyno_)) : \
90
88
                                          MI_KEYMAP_HIGH_MASK)
91
89
#define mi_clear_key_active(_keymap_,_keyno_) \
92
90
                            (_keymap_)&= (((_keyno_) < MI_KEYMAP_BITS) ? \
93
 
                                          (~ (1ULL << (_keyno_))) : \
94
 
                                          (~ (0ULL)) /*ignore*/ )
 
91
                                          (~ (1UL << (_keyno_))) : \
 
92
                                          (~ (0UL)) /*ignore*/ )
95
93
 
96
94
#else
97
95
 
98
96
#define mi_is_key_active(_keymap_,_keyno_) \
99
 
                            test((_keymap_) & (1ULL << (_keyno_)))
 
97
                            test((_keymap_) & (1UL << (_keyno_)))
100
98
#define mi_set_key_active(_keymap_,_keyno_) \
101
 
                            (_keymap_)|= (1ULL << (_keyno_))
 
99
                            (_keymap_)|= (1UL << (_keyno_))
102
100
#define mi_clear_key_active(_keymap_,_keyno_) \
103
 
                            (_keymap_)&= (~ (1ULL << (_keyno_)))
 
101
                            (_keymap_)&= (~ (1UL << (_keyno_)))
104
102
 
105
103
#endif
106
104
 
140
138
  uint64_t auto_increment;
141
139
  uint64_t key_map;                     /* Which keys are used */
142
140
  char  *data_file_name, *index_file_name;
143
 
  uint  keys;                           /* Number of keys in use */
 
141
  uint32_t  keys;                               /* Number of keys in use */
144
142
  uint  options;                        /* HA_OPTION_... used */
145
143
  int   errkey,                         /* With key was dupplicated on err */
146
144
        sortkey;                        /* clustered by this key */
148
146
  time_t create_time;                   /* When table was created */
149
147
  time_t check_time;
150
148
  time_t update_time;
151
 
  uint  reflength;
 
149
  uint32_t  reflength;
152
150
  ulong record_offset;
153
151
  ulong *rec_per_key;                   /* for sql optimizing */
154
152
} MI_ISAMINFO;
162
160
  uint64_t auto_increment;
163
161
  uint64_t data_file_length;
164
162
  uint64_t key_file_length;
165
 
  uint old_options;
 
163
  uint32_t old_options;
166
164
  uint8_t language;
167
 
  my_bool with_auto_increment;
 
165
  bool with_auto_increment;
168
166
} MI_CREATE_INFO;
169
167
 
170
168
struct st_myisam_info;                  /* For referense */
190
188
  HA_KEYSEG *seg,*end;
191
189
 
192
190
  int (*bin_search)(struct st_myisam_info *info,struct st_mi_keydef *keyinfo,
193
 
                    uchar *page,uchar *key,
194
 
                    uint key_len,uint comp_flag,uchar * *ret_pos,
195
 
                    uchar *buff, my_bool *was_last_key);
196
 
  uint (*get_key)(struct st_mi_keydef *keyinfo,uint nod_flag,uchar * *page,
197
 
                  uchar *key);
198
 
  int (*pack_key)(struct st_mi_keydef *keyinfo,uint nod_flag,uchar *next_key,
199
 
                  uchar *org_key, uchar *prev_key, uchar *key,
 
191
                    unsigned char *page,unsigned char *key,
 
192
                    uint32_t key_len,uint32_t comp_flag,unsigned char * *ret_pos,
 
193
                    unsigned char *buff, bool *was_last_key);
 
194
  uint32_t (*get_key)(struct st_mi_keydef *keyinfo,uint32_t nod_flag,unsigned char * *page,
 
195
                  unsigned char *key);
 
196
  int (*pack_key)(struct st_mi_keydef *keyinfo,uint32_t nod_flag,unsigned char *next_key,
 
197
                  unsigned char *org_key, unsigned char *prev_key, unsigned char *key,
200
198
                  struct st_mi_s_param *s_temp);
201
 
  void (*store_key)(struct st_mi_keydef *keyinfo, uchar *key_pos,
 
199
  void (*store_key)(struct st_mi_keydef *keyinfo, unsigned char *key_pos,
202
200
                    struct st_mi_s_param *s_temp);
203
 
  int (*ck_insert)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen);
204
 
  int (*ck_delete)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen);
 
201
  int (*ck_insert)(struct st_myisam_info *inf, uint32_t k_nr, unsigned char *k, uint32_t klen);
 
202
  int (*ck_delete)(struct st_myisam_info *inf, uint32_t k_nr, unsigned char *k, uint32_t klen);
205
203
} MI_KEYDEF;
206
204
 
207
205
 
210
208
typedef struct st_unique_def            /* Segment definition of unique */
211
209
{
212
210
  uint16_t keysegs;                     /* Number of key-segment */
213
 
  uchar key;                            /* Mapped to which key */
 
211
  unsigned char key;                            /* Mapped to which key */
214
212
  uint8_t null_are_equal;
215
213
  HA_KEYSEG *seg,*end;
216
214
} MI_UNIQUEDEF;
219
217
{
220
218
  uint16_t *table;
221
219
  uint   quick_table_bits;
222
 
  uchar  *intervalls;
 
220
  unsigned char  *intervalls;
223
221
} MI_DECODE_TREE;
224
222
 
225
223
 
241
239
 
242
240
#ifndef NOT_PACKED_DATABASES
243
241
  void (*unpack)(struct st_columndef *rec,struct st_mi_bit_buff *buff,
244
 
                 uchar *start,uchar *end);
 
242
                 unsigned char *start,unsigned char *end);
245
243
  enum en_fieldtype base_type;
246
 
  uint space_length_bits,pack_type;
 
244
  uint32_t space_length_bits,pack_type;
247
245
  MI_DECODE_TREE *huff_tree;
248
246
#endif
249
247
} MI_COLUMNDEF;
250
248
 
251
249
 
252
250
extern char * myisam_log_filename;              /* Name of logfile */
253
 
extern ulong myisam_block_size;
254
 
extern ulong myisam_concurrent_insert;
 
251
extern uint32_t myisam_block_size;
 
252
extern uint32_t myisam_concurrent_insert;
255
253
extern bool myisam_flush,myisam_delay_key_write,myisam_single_user;
256
254
extern my_off_t myisam_max_temp_length;
257
 
extern ulong myisam_bulk_insert_tree_size, myisam_data_pointer_size;
 
255
extern uint32_t myisam_bulk_insert_tree_size, myisam_data_pointer_size;
258
256
 
259
257
        /* Prototypes for myisam-functions */
260
258
 
261
259
extern int mi_close(struct st_myisam_info *file);
262
 
extern int mi_delete(struct st_myisam_info *file,const uchar *buff);
 
260
extern int mi_delete(struct st_myisam_info *file,const unsigned char *buff);
263
261
extern struct st_myisam_info *mi_open(const char *name,int mode,
264
 
                                      uint wait_if_locked);
 
262
                                      uint32_t wait_if_locked);
265
263
extern int mi_panic(enum ha_panic_function function);
266
 
extern int mi_rfirst(struct st_myisam_info *file,uchar *buf,int inx);
267
 
extern int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key,
 
264
extern int mi_rfirst(struct st_myisam_info *file,unsigned char *buf,int inx);
 
265
extern int mi_rkey(MI_INFO *info, unsigned char *buf, int inx, const unsigned char *key,
268
266
                   key_part_map keypart_map, enum ha_rkey_function search_flag);
269
 
extern int mi_rlast(struct st_myisam_info *file,uchar *buf,int inx);
270
 
extern int mi_rnext(struct st_myisam_info *file,uchar *buf,int inx);
271
 
extern int mi_rnext_same(struct st_myisam_info *info, uchar *buf);
272
 
extern int mi_rprev(struct st_myisam_info *file,uchar *buf,int inx);
273
 
extern int mi_rrnd(struct st_myisam_info *file,uchar *buf, my_off_t pos);
 
267
extern int mi_rlast(struct st_myisam_info *file,unsigned char *buf,int inx);
 
268
extern int mi_rnext(struct st_myisam_info *file,unsigned char *buf,int inx);
 
269
extern int mi_rnext_same(struct st_myisam_info *info, unsigned char *buf);
 
270
extern int mi_rprev(struct st_myisam_info *file,unsigned char *buf,int inx);
 
271
extern int mi_rrnd(struct st_myisam_info *file,unsigned char *buf, my_off_t pos);
274
272
extern int mi_scan_init(struct st_myisam_info *file);
275
 
extern int mi_scan(struct st_myisam_info *file,uchar *buf);
276
 
extern int mi_rsame(struct st_myisam_info *file,uchar *record,int inx);
277
 
extern int mi_rsame_with_pos(struct st_myisam_info *file,uchar *record,
 
273
extern int mi_scan(struct st_myisam_info *file,unsigned char *buf);
 
274
extern int mi_rsame(struct st_myisam_info *file,unsigned char *record,int inx);
 
275
extern int mi_rsame_with_pos(struct st_myisam_info *file,unsigned char *record,
278
276
                             int inx, my_off_t pos);
279
 
extern int mi_update(struct st_myisam_info *file,const uchar *old,
280
 
                     uchar *new_record);
281
 
extern int mi_write(struct st_myisam_info *file,uchar *buff);
 
277
extern int mi_update(struct st_myisam_info *file,const unsigned char *old,
 
278
                     unsigned char *new_record);
 
279
extern int mi_write(struct st_myisam_info *file,unsigned char *buff);
282
280
extern my_off_t mi_position(struct st_myisam_info *file);
283
 
extern int mi_status(struct st_myisam_info *info, MI_ISAMINFO *x, uint flag);
 
281
extern int mi_status(struct st_myisam_info *info, MI_ISAMINFO *x, uint32_t flag);
284
282
extern int mi_lock_database(struct st_myisam_info *file,int lock_type);
285
 
extern int mi_create(const char *name,uint keys,MI_KEYDEF *keydef,
286
 
                     uint columns, MI_COLUMNDEF *columndef,
287
 
                     uint uniques, MI_UNIQUEDEF *uniquedef,
288
 
                     MI_CREATE_INFO *create_info, uint flags);
 
283
extern int mi_create(const char *name,uint32_t keys,MI_KEYDEF *keydef,
 
284
                     uint32_t columns, MI_COLUMNDEF *columndef,
 
285
                     uint32_t uniques, MI_UNIQUEDEF *uniquedef,
 
286
                     MI_CREATE_INFO *create_info, uint32_t flags);
289
287
extern int mi_delete_table(const char *name);
290
288
extern int mi_rename(const char *from, const char *to);
291
289
extern int mi_extra(struct st_myisam_info *file,
297
295
extern int mi_log(int activate_log);
298
296
extern int mi_is_changed(struct st_myisam_info *info);
299
297
extern int mi_delete_all_rows(struct st_myisam_info *info);
300
 
extern ulong _mi_calc_blob_length(uint length , const uchar *pos);
301
 
extern uint mi_get_pointer_length(uint64_t file_length, uint def);
 
298
extern ulong _mi_calc_blob_length(uint32_t length , const unsigned char *pos);
 
299
extern uint32_t mi_get_pointer_length(uint64_t file_length, uint32_t def);
302
300
 
303
301
/* this is used to pass to mysql_myisamchk_table */
304
302
 
366
364
 
367
365
typedef struct st_sort_key_blocks               /* Used when sorting */
368
366
{
369
 
  uchar *buff,*end_pos;
370
 
  uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
371
 
  uint last_length;
 
367
  unsigned char *buff,*end_pos;
 
368
  unsigned char lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
 
369
  uint32_t last_length;
372
370
  int inited;
373
371
} SORT_KEY_BLOCKS;
374
372
 
375
373
 
376
 
/* 
377
 
  MyISAM supports several statistics collection methods. Currently statistics 
378
 
  collection method is not stored in MyISAM file and has to be specified for 
 
374
/*
 
375
  MyISAM supports several statistics collection methods. Currently statistics
 
376
  collection method is not stored in MyISAM file and has to be specified for
379
377
  each table analyze/repair operation in  MI_CHECK::stats_method.
380
378
*/
381
379
 
382
 
typedef enum 
 
380
typedef enum
383
381
{
384
382
  /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */
385
383
  MI_STATS_METHOD_NULLS_NOT_EQUAL,
402
400
  ha_checksum record_checksum,glob_crc;
403
401
  ulong use_buffers,read_buffer_length,write_buffer_length,
404
402
        sort_buffer_length,sort_key_blocks;
405
 
  uint out_flag,warning_printed,error_printed,verbose;
406
 
  uint opt_sort_key,total_files,max_level;
407
 
  uint testflag, key_cache_block_size;
 
403
  uint32_t out_flag,warning_printed,error_printed,verbose;
 
404
  uint32_t opt_sort_key,total_files,max_level;
 
405
  uint32_t testflag, key_cache_block_size;
408
406
  uint8_t language;
409
 
  my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
410
 
  my_bool retry_repair, force_sort;
 
407
  bool using_global_keycache, opt_lock_memory, opt_follow_links;
 
408
  bool retry_repair, force_sort;
411
409
  char temp_filename[FN_REFLEN],*isam_file_name;
412
410
  MY_TMPDIR *tmpdir;
413
411
  int tmpfile_createflag;
414
412
  myf myf_rw;
415
413
  IO_CACHE read_cache;
416
 
  
417
 
  /* 
 
414
 
 
415
  /*
418
416
    The next two are used to collect statistics, see update_key_parts for
419
417
    description.
420
418
  */
421
419
  uint64_t unique_count[MI_MAX_KEY_SEG+1];
422
420
  uint64_t notnull_count[MI_MAX_KEY_SEG+1];
423
 
  
 
421
 
424
422
  ha_checksum key_crc[HA_MAX_POSSIBLE_KEY];
425
423
  ulong rec_per_key_part[MI_MAX_KEY_SEG*HA_MAX_POSSIBLE_KEY];
426
 
  void *thd;
 
424
  void *session;
427
425
  const char *db_name, *table_name;
428
426
  const char *op_name;
429
427
  enum_mi_stats_method stats_method;
433
431
{
434
432
  my_off_t filelength,dupp,buff_length;
435
433
  ha_rows max_records;
436
 
  uint current_key, total_keys;
 
434
  uint32_t current_key, total_keys;
437
435
  myf myf_rw;
438
436
  enum data_file_type new_data_file_type;
439
437
  MI_INFO *info;
440
438
  MI_CHECK *param;
441
 
  uchar *buff;
 
439
  unsigned char *buff;
442
440
  SORT_KEY_BLOCKS *key_block,*key_block_end;
443
441
  /* sync things */
444
 
  uint got_error, threads_running;
 
442
  uint32_t got_error, threads_running;
445
443
  pthread_mutex_t mutex;
446
444
  pthread_cond_t  cond;
447
445
} SORT_INFO;
449
447
/* functions in mi_check */
450
448
void myisamchk_init(MI_CHECK *param);
451
449
int chk_status(MI_CHECK *param, MI_INFO *info);
452
 
int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag);
 
450
int chk_del(MI_CHECK *param, register MI_INFO *info, uint32_t test_flag);
453
451
int chk_size(MI_CHECK *param, MI_INFO *info);
454
452
int chk_key(MI_CHECK *param, MI_INFO *info);
455
453
int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend);
461
459
int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
462
460
                      const char * name, int rep_quick);
463
461
int change_to_newfile(const char * filename, const char * old_ext,
464
 
                      const char * new_ext, uint raid_chunks,
 
462
                      const char * new_ext, uint32_t raid_chunks,
465
463
                      myf myflags);
466
464
void lock_memory(MI_CHECK *param);
467
465
void update_auto_increment_key(MI_CHECK *param, MI_INFO *info,
468
 
                               my_bool repair);
469
 
int update_state_info(MI_CHECK *param, MI_INFO *info,uint update);
 
466
                               bool repair);
 
467
int update_state_info(MI_CHECK *param, MI_INFO *info,uint32_t update);
470
468
void update_key_parts(MI_KEYDEF *keyinfo, ulong *rec_per_key_part,
471
 
                      uint64_t *unique, uint64_t *notnull, 
 
469
                      uint64_t *unique, uint64_t *notnull,
472
470
                      uint64_t records);
473
471
int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
474
472
             my_off_t length, const char *type);
475
 
int movepoint(MI_INFO *info,uchar *record,my_off_t oldpos,
476
 
              my_off_t newpos, uint prot_key);
477
 
int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile);
 
473
int movepoint(MI_INFO *info,unsigned char *record,my_off_t oldpos,
 
474
              my_off_t newpos, uint32_t prot_key);
 
475
int write_data_suffix(SORT_INFO *sort_info, bool fix_datafile);
478
476
int test_if_almost_full(MI_INFO *info);
479
477
int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename);
480
 
my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, uint64_t key_map,
481
 
                            my_bool force);
 
478
bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, uint64_t key_map,
 
479
                            bool force);
482
480
 
483
 
int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows);
484
 
void mi_flush_bulk_insert(MI_INFO *info, uint inx);
 
481
int mi_init_bulk_insert(MI_INFO *info, uint32_t cache_size, ha_rows rows);
 
482
void mi_flush_bulk_insert(MI_INFO *info, uint32_t inx);
485
483
void mi_end_bulk_insert(MI_INFO *info);
486
 
int mi_assign_to_key_cache(MI_INFO *info, uint64_t key_map, 
 
484
int mi_assign_to_key_cache(MI_INFO *info, uint64_t key_map,
487
485
                           KEY_CACHE *key_cache);
488
486
void mi_change_key_cache(KEY_CACHE *old_key_cache,
489
487
                         KEY_CACHE *new_key_cache);
490
 
int mi_preload(MI_INFO *info, uint64_t key_map, my_bool ignore_leaves);
 
488
int mi_preload(MI_INFO *info, uint64_t key_map, bool ignore_leaves);
491
489
 
492
490
#ifdef  __cplusplus
493
491
}