Eneboo - Documentación para desarrolladores
src/libmysql_macosx/include/myisam.h
Ir a la documentación de este archivo.
00001 /* Copyright (C) 2000 MySQL AB
00002 
00003    This program is free software; you can redistribute it and/or modify
00004    it under the terms of the GNU General Public License as published by
00005    the Free Software Foundation; either version 2 of the License, or
00006    (at your option) any later version.
00007 
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012 
00013    You should have received a copy of the GNU General Public License
00014    along with this program; if not, write to the Free Software
00015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00016 
00017 /* This file should be included when using myisam_funktions */
00018 
00019 #ifndef _myisam_h
00020 #define _myisam_h
00021 #ifdef  __cplusplus
00022 extern "C" {
00023 #endif
00024 
00025 #ifndef _my_base_h
00026 #include <my_base.h>
00027 #endif
00028 #ifndef _m_ctype_h
00029 #include <m_ctype.h>
00030 #endif
00031 #ifndef _keycache_h
00032 #include "keycache.h"
00033 #endif
00034 #include "my_handler.h"
00035 
00036         /* defines used by myisam-funktions */
00037 
00038 /* The following defines can be increased if necessary */
00039 #define MI_MAX_KEY      64              /* Max allowed keys */
00040 #define MI_MAX_KEY_SEG  16              /* Max segments for key */
00041 #define MI_MAX_KEY_LENGTH 1000
00042 
00043 #define MI_MAX_KEY_BUFF  (MI_MAX_KEY_LENGTH+MI_MAX_KEY_SEG*6+8+8)
00044 #define MI_MAX_POSSIBLE_KEY_BUFF (1024+6+6)     /* For myisam_chk */
00045 #define MI_MAX_POSSIBLE_KEY     64              /* For myisam_chk */
00046 #define MI_MAX_MSG_BUF      1024 /* used in CHECK TABLE, REPAIR TABLE */
00047 #define MI_NAME_IEXT    ".MYI"
00048 #define MI_NAME_DEXT    ".MYD"
00049 /* Max extra space to use when sorting keys */
00050 #define MI_MAX_TEMP_LENGTH      2*1024L*1024L*1024L
00051 
00052 /* Possible values for myisam_block_size (must be power of 2) */
00053 #define MI_KEY_BLOCK_LENGTH     1024    /* default key block length */
00054 #define MI_MIN_KEY_BLOCK_LENGTH 1024    /* Min key block length */
00055 #define MI_MAX_KEY_BLOCK_LENGTH 16384
00056 
00057 #define mi_portable_sizeof_char_ptr 8
00058 
00059         /* Param to/from mi_info */
00060 
00061 typedef struct st_mi_isaminfo           /* Struct from h_info */
00062 {
00063   ha_rows records;                      /* Records in database */
00064   ha_rows deleted;                      /* Deleted records in database */
00065   my_off_t recpos;                      /* Pos for last used record */
00066   my_off_t newrecpos;                   /* Pos if we write new record */
00067   my_off_t dupp_key_pos;                /* Position to record with dupp key */
00068   my_off_t data_file_length,            /* Length of data file */
00069            max_data_file_length,
00070            index_file_length,
00071            max_index_file_length,
00072            delete_length;
00073   ulong reclength;                      /* Recordlength */
00074   ulong mean_reclength;                 /* Mean recordlength (if packed) */
00075   ulonglong auto_increment;
00076   ulonglong key_map;                    /* Which keys are used */
00077   char  *data_file_name, *index_file_name;
00078   uint  keys;                           /* Number of keys in use */
00079   uint  options;                        /* HA_OPTION_... used */
00080   int   errkey,                         /* With key was dupplicated on err */
00081         sortkey;                        /* clustered by this key */
00082   File  filenr;                         /* (uniq) filenr for datafile */
00083   time_t create_time;                   /* When table was created */
00084   time_t check_time;
00085   time_t update_time;
00086   uint  reflength;
00087   ulong record_offset;
00088   ulong *rec_per_key;                   /* for sql optimizing */
00089   uint raid_type,raid_chunks;
00090   ulong raid_chunksize;
00091 } MI_ISAMINFO;
00092 
00093 
00094 typedef struct st_mi_create_info
00095 {
00096   const char *index_file_name, *data_file_name; /* If using symlinks */
00097   ha_rows max_rows;
00098   ha_rows reloc_rows;
00099   ulonglong auto_increment;
00100   ulonglong data_file_length;
00101   ulonglong key_file_length;
00102   uint raid_type,raid_chunks;
00103   ulong raid_chunksize;
00104   uint old_options;
00105   uint8 language;
00106   my_bool with_auto_increment;
00107 } MI_CREATE_INFO;
00108 
00109 struct st_myisam_info;                  /* For referense */
00110 typedef struct st_myisam_info MI_INFO;
00111 
00112 struct st_mi_s_param;
00113 
00114 typedef struct st_mi_keydef             /* Key definition with open & info */
00115 {
00116   uint16 keysegs;                       /* Number of key-segment */
00117   uint16 flag;                          /* NOSAME, PACK_USED */
00118 
00119   uint8  key_alg;                       /* BTREE, RTREE */
00120   uint16 block_length;                  /* Length of keyblock (auto) */
00121   uint16 underflow_block_length;        /* When to execute underflow */
00122   uint16 keylength;                     /* Tot length of keyparts (auto) */
00123   uint16 minlength;                     /* min length of (packed) key (auto) */
00124   uint16 maxlength;                     /* max length of (packed) key (auto) */
00125   uint16 block_size;                    /* block_size (auto) */
00126   uint32 version;                       /* For concurrent read/write */
00127 
00128   HA_KEYSEG *seg,*end;
00129   int (*bin_search)(struct st_myisam_info *info,struct st_mi_keydef *keyinfo,
00130                     uchar *page,uchar *key,
00131                     uint key_len,uint comp_flag,uchar * *ret_pos,
00132                     uchar *buff, my_bool *was_last_key);
00133   uint (*get_key)(struct st_mi_keydef *keyinfo,uint nod_flag,uchar * *page,
00134                   uchar *key);
00135   int (*pack_key)(struct st_mi_keydef *keyinfo,uint nod_flag,uchar *next_key,
00136                   uchar *org_key, uchar *prev_key, uchar *key,
00137                   struct st_mi_s_param *s_temp);
00138   void (*store_key)(struct st_mi_keydef *keyinfo, uchar *key_pos,
00139                     struct st_mi_s_param *s_temp);
00140   int (*ck_insert)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen);
00141   int (*ck_delete)(struct st_myisam_info *inf, uint k_nr, uchar *k, uint klen);
00142 } MI_KEYDEF;
00143 
00144 
00145 #define MI_UNIQUE_HASH_LENGTH   4
00146 
00147 typedef struct st_unique_def            /* Segment definition of unique */
00148 {
00149   uint16 keysegs;                       /* Number of key-segment */
00150   uchar key;                            /* Mapped to which key */
00151   uint8 null_are_equal;
00152   HA_KEYSEG *seg,*end;
00153 } MI_UNIQUEDEF;
00154 
00155 typedef struct st_mi_decode_tree        /* Decode huff-table */
00156 {
00157   uint16 *table;
00158   uint   quick_table_bits;
00159   byte   *intervalls;
00160 } MI_DECODE_TREE;
00161 
00162 
00163 struct st_mi_bit_buff;
00164 
00165 /*
00166   Note that null markers should always be first in a row !
00167   When creating a column, one should only specify:
00168   type, length, null_bit and null_pos
00169 */
00170 
00171 typedef struct st_columndef             /* column information */
00172 {
00173   int16  type;                          /* en_fieldtype */
00174   uint16 length;                        /* length of field */
00175   uint32 offset;                        /* Offset to position in row */
00176   uint8  null_bit;                      /* If column may be 0 */
00177   uint16 null_pos;                      /* position for null marker */
00178 
00179 #ifndef NOT_PACKED_DATABASES
00180   void (*unpack)(struct st_columndef *rec,struct st_mi_bit_buff *buff,
00181                  uchar *start,uchar *end);
00182   enum en_fieldtype base_type;
00183   uint space_length_bits,pack_type;
00184   MI_DECODE_TREE *huff_tree;
00185 #endif
00186 } MI_COLUMNDEF;
00187 
00188 /* invalidator function reference for Query Cache */
00189 typedef void (* invalidator_by_filename)(const char * filename);
00190 
00191 extern my_string myisam_log_filename;           /* Name of logfile */
00192 extern uint myisam_block_size;
00193 extern my_bool myisam_flush,myisam_delay_key_write,myisam_single_user;
00194 extern my_bool myisam_concurrent_insert;
00195 extern my_off_t myisam_max_temp_length,myisam_max_extra_temp_length;
00196 extern ulong myisam_bulk_insert_tree_size, myisam_data_pointer_size;
00197 
00198         /* Prototypes for myisam-functions */
00199 
00200 extern int mi_close(struct st_myisam_info *file);
00201 extern int mi_delete(struct st_myisam_info *file,const byte *buff);
00202 extern struct st_myisam_info *mi_open(const char *name,int mode,
00203                                       uint wait_if_locked);
00204 extern int mi_panic(enum ha_panic_function function);
00205 extern int mi_rfirst(struct st_myisam_info *file,byte *buf,int inx);
00206 extern int mi_rkey(struct st_myisam_info *file,byte *buf,int inx,
00207                    const byte *key,
00208                    uint key_len, enum ha_rkey_function search_flag);
00209 extern int mi_rlast(struct st_myisam_info *file,byte *buf,int inx);
00210 extern int mi_rnext(struct st_myisam_info *file,byte *buf,int inx);
00211 extern int mi_rnext_same(struct st_myisam_info *info, byte *buf);
00212 extern int mi_rprev(struct st_myisam_info *file,byte *buf,int inx);
00213 extern int mi_rrnd(struct st_myisam_info *file,byte *buf, my_off_t pos);
00214 extern int mi_scan_init(struct st_myisam_info *file);
00215 extern int mi_scan(struct st_myisam_info *file,byte *buf);
00216 extern int mi_rsame(struct st_myisam_info *file,byte *record,int inx);
00217 extern int mi_rsame_with_pos(struct st_myisam_info *file,byte *record,
00218                              int inx, my_off_t pos);
00219 extern int mi_update(struct st_myisam_info *file,const byte *old,
00220                      byte *new_record);
00221 extern int mi_write(struct st_myisam_info *file,byte *buff);
00222 extern my_off_t mi_position(struct st_myisam_info *file);
00223 extern int mi_status(struct st_myisam_info *info, MI_ISAMINFO *x, uint flag);
00224 extern int mi_lock_database(struct st_myisam_info *file,int lock_type);
00225 extern int mi_create(const char *name,uint keys,MI_KEYDEF *keydef,
00226                      uint columns, MI_COLUMNDEF *columndef,
00227                      uint uniques, MI_UNIQUEDEF *uniquedef,
00228                      MI_CREATE_INFO *create_info, uint flags);
00229 extern int mi_delete_table(const char *name);
00230 extern int mi_rename(const char *from, const char *to);
00231 extern int mi_extra(struct st_myisam_info *file,
00232                     enum ha_extra_function function,
00233                     void *extra_arg);
00234 extern ha_rows mi_records_in_range(struct st_myisam_info *info,int inx,
00235                                    key_range *min_key, key_range *max_key);
00236 extern int mi_log(int activate_log);
00237 extern int mi_is_changed(struct st_myisam_info *info);
00238 extern int mi_delete_all_rows(struct st_myisam_info *info);
00239 extern ulong _mi_calc_blob_length(uint length , const byte *pos);
00240 extern uint mi_get_pointer_length(ulonglong file_length, uint def);
00241 
00242 /* this is used to pass to mysql_myisamchk_table -- by Sasha Pachev */
00243 
00244 #define   MYISAMCHK_REPAIR 1  /* equivalent to myisamchk -r */
00245 #define   MYISAMCHK_VERIFY 2  /* Verify, run repair if failure */
00246 
00247 /*
00248   Definitions needed for myisamchk.c
00249 
00250   Entries marked as "QQ to be removed" are NOT used to
00251   pass check/repair options to mi_check.c. They are used
00252   internally by myisamchk.c or/and ha_myisam.cc and should NOT
00253   be stored together with other flags. They should be removed
00254   from the following list to make addition of new flags possible.
00255 */
00256 
00257 #define T_AUTO_INC              1
00258 #define T_AUTO_REPAIR           2              /* QQ to be removed */
00259 #define T_BACKUP_DATA           4
00260 #define T_CALC_CHECKSUM         8
00261 #define T_CHECK                 16             /* QQ to be removed */
00262 #define T_CHECK_ONLY_CHANGED    32             /* QQ to be removed */
00263 #define T_CREATE_MISSING_KEYS   64
00264 #define T_DESCRIPT              128
00265 #define T_DONT_CHECK_CHECKSUM   256
00266 #define T_EXTEND                512
00267 #define T_FAST                  (1L << 10)     /* QQ to be removed */
00268 #define T_FORCE_CREATE          (1L << 11)     /* QQ to be removed */
00269 #define T_FORCE_UNIQUENESS      (1L << 12)
00270 #define T_INFO                  (1L << 13)
00271 #define T_MEDIUM                (1L << 14)
00272 #define T_QUICK                 (1L << 15)     /* QQ to be removed */
00273 #define T_READONLY              (1L << 16)     /* QQ to be removed */
00274 #define T_REP                   (1L << 17)
00275 #define T_REP_BY_SORT           (1L << 18)     /* QQ to be removed */
00276 #define T_REP_PARALLEL          (1L << 19)     /* QQ to be removed */
00277 #define T_RETRY_WITHOUT_QUICK   (1L << 20)
00278 #define T_SAFE_REPAIR           (1L << 21)
00279 #define T_SILENT                (1L << 22)
00280 #define T_SORT_INDEX            (1L << 23)     /* QQ to be removed */
00281 #define T_SORT_RECORDS          (1L << 24)     /* QQ to be removed */
00282 #define T_STATISTICS            (1L << 25)
00283 #define T_UNPACK                (1L << 26)
00284 #define T_UPDATE_STATE          (1L << 27)
00285 #define T_VERBOSE               (1L << 28)
00286 #define T_VERY_SILENT           (1L << 29)
00287 #define T_WAIT_FOREVER          (1L << 30)
00288 #define T_WRITE_LOOP            ((ulong) 1L << 31)
00289 
00290 #define T_REP_ANY               (T_REP | T_REP_BY_SORT | T_REP_PARALLEL)
00291 
00292 /*
00293   Flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
00294   to mi_check.c follows:
00295 */
00296 
00297 #define TT_USEFRM               1
00298 
00299 #define O_NEW_INDEX     1               /* Bits set in out_flag */
00300 #define O_NEW_DATA      2
00301 #define O_DATA_LOST     4
00302 
00303 /* these struct is used by my_check to tell it what to do */
00304 
00305 typedef struct st_sort_key_blocks               /* Used when sorting */
00306 {
00307   uchar *buff,*end_pos;
00308   uchar lastkey[MI_MAX_POSSIBLE_KEY_BUFF];
00309   uint last_length;
00310   int inited;
00311 } SORT_KEY_BLOCKS;
00312 
00313 
00314 /* 
00315   MyISAM supports several statistics collection methods. Currently statistics 
00316   collection method is not stored in MyISAM file and has to be specified for 
00317   each table analyze/repair operation in  MI_CHECK::stats_method.
00318 */
00319 
00320 typedef enum 
00321 {
00322   /* Treat NULLs as inequal when collecting statistics (default for 4.1/5.0) */
00323   MI_STATS_METHOD_NULLS_NOT_EQUAL,
00324   /* Treat NULLs as equal when collecting statistics (like 4.0 did) */
00325   MI_STATS_METHOD_NULLS_EQUAL
00326 } enum_mi_stats_method;
00327 
00328 typedef struct st_mi_check_param
00329 {
00330   ulonglong auto_increment_value;
00331   ulonglong max_data_file_length;
00332   ulonglong keys_in_use;
00333   ulonglong max_record_length;
00334   my_off_t search_after_block;
00335   my_off_t new_file_pos,key_file_blocks;
00336   my_off_t keydata,totaldata,key_blocks,start_check_pos;
00337   ha_rows total_records,total_deleted;
00338   ha_checksum record_checksum,glob_crc;
00339   ulong use_buffers,read_buffer_length,write_buffer_length,
00340         sort_buffer_length,sort_key_blocks;
00341   uint out_flag,warning_printed,error_printed,verbose;
00342   uint opt_sort_key,total_files,max_level;
00343   uint testflag, key_cache_block_size;
00344   uint8 language;
00345   my_bool using_global_keycache, opt_lock_memory, opt_follow_links;
00346   my_bool retry_repair, force_sort, calc_checksum;
00347   char temp_filename[FN_REFLEN],*isam_file_name;
00348   MY_TMPDIR *tmpdir;
00349   int tmpfile_createflag;
00350   myf myf_rw;
00351   IO_CACHE read_cache;
00352   ulonglong unique_count[MI_MAX_KEY_SEG+1];
00353   ha_checksum key_crc[MI_MAX_POSSIBLE_KEY];
00354   ulong rec_per_key_part[MI_MAX_KEY_SEG*MI_MAX_POSSIBLE_KEY];
00355   void *thd;
00356   char *db_name,*table_name;
00357   char *op_name;
00358   enum_mi_stats_method stats_method;
00359 } MI_CHECK;
00360 
00361 typedef struct st_sort_ft_buf
00362 {
00363   uchar *buf, *end;
00364   int   count;
00365   uchar lastkey[MI_MAX_KEY_BUFF];
00366 } SORT_FT_BUF;
00367 
00368 typedef struct st_sort_info
00369 {
00370   my_off_t filelength,dupp,buff_length;
00371   ha_rows max_records;
00372   uint current_key, total_keys;
00373   myf myf_rw;
00374   enum data_file_type new_data_file_type;
00375   MI_INFO *info;
00376   MI_CHECK *param;
00377   char *buff;
00378   SORT_KEY_BLOCKS *key_block,*key_block_end;
00379   SORT_FT_BUF *ft_buf;
00380   /* sync things */
00381   uint got_error, threads_running;
00382 #ifdef THREAD
00383   pthread_mutex_t mutex;
00384   pthread_cond_t  cond;
00385 #endif
00386 } SORT_INFO;
00387 
00388 /* functions in mi_check */
00389 void myisamchk_init(MI_CHECK *param);
00390 int chk_status(MI_CHECK *param, MI_INFO *info);
00391 int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag);
00392 int chk_size(MI_CHECK *param, MI_INFO *info);
00393 int chk_key(MI_CHECK *param, MI_INFO *info);
00394 int chk_data_link(MI_CHECK *param, MI_INFO *info,int extend);
00395 int mi_repair(MI_CHECK *param, register MI_INFO *info,
00396               my_string name, int rep_quick);
00397 int mi_sort_index(MI_CHECK *param, register MI_INFO *info, my_string name);
00398 int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
00399                       const char * name, int rep_quick);
00400 int mi_repair_parallel(MI_CHECK *param, register MI_INFO *info,
00401                       const char * name, int rep_quick);
00402 int change_to_newfile(const char * filename, const char * old_ext,
00403                       const char * new_ext, uint raid_chunks,
00404                       myf myflags);
00405 int lock_file(MI_CHECK *param, File file, my_off_t start, int lock_type,
00406               const char *filetype, const char *filename);
00407 void lock_memory(MI_CHECK *param);
00408 void update_auto_increment_key(MI_CHECK *param, MI_INFO *info,
00409                                my_bool repair);
00410 int update_state_info(MI_CHECK *param, MI_INFO *info,uint update);
00411 void update_key_parts(MI_KEYDEF *keyinfo, ulong *rec_per_key_part,
00412                              ulonglong *unique, ulonglong records);
00413 int filecopy(MI_CHECK *param, File to,File from,my_off_t start,
00414              my_off_t length, const char *type);
00415 int movepoint(MI_INFO *info,byte *record,my_off_t oldpos,
00416               my_off_t newpos, uint prot_key);
00417 int write_data_suffix(SORT_INFO *sort_info, my_bool fix_datafile);
00418 int test_if_almost_full(MI_INFO *info);
00419 int recreate_table(MI_CHECK *param, MI_INFO **org_info, char *filename);
00420 void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows);
00421 my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map,
00422                             my_bool force);
00423 
00424 int mi_init_bulk_insert(MI_INFO *info, ulong cache_size, ha_rows rows);
00425 void mi_flush_bulk_insert(MI_INFO *info, uint inx);
00426 void mi_end_bulk_insert(MI_INFO *info);
00427 int mi_assign_to_key_cache(MI_INFO *info, ulonglong key_map, 
00428                            KEY_CACHE *key_cache);
00429 void mi_change_key_cache(KEY_CACHE *old_key_cache,
00430                          KEY_CACHE *new_key_cache);
00431 int mi_preload(MI_INFO *info, ulonglong key_map, my_bool ignore_leaves);
00432 
00433 #ifdef  __cplusplus
00434 }
00435 #endif
00436 #endif
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'