~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/myisam/myisam.h

  • Committer: Brian Aker
  • Date: 2010-01-22 00:53:13 UTC
  • Revision ID: brian@gaz-20100122005313-jmizcbcdi1lt4tcx
Revert db patch.

Show diffs side-by-side

added added

removed removed

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