16
16
/* Describe, check and repair of MyISAM tables */
18
#include <drizzled/global.h>
20
#include <mystrings/m_ctype.h>
21
21
#include <stdarg.h>
22
#include <mysys/my_getopt.h>
23
#include <mysys/my_bit.h>
25
#include <mystrings/m_string.h>
22
#include <my_getopt.h>
26
24
#ifdef HAVE_SYS_VADVICE_H
27
25
#include <sys/vadvise.h>
29
27
#ifdef HAVE_SYS_MMAN_H
30
28
#include <sys/mman.h>
32
#include <drizzled/util/test.h>
34
#include "myisamdef.h"
36
static uint32_t decode_bits;
30
SET_STACK_SIZE(9000) /* Minimum stack size for program */
33
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
34
#define my_raid_delete(A,B,C) my_delete(A,B)
37
static uint decode_bits;
37
38
static char **default_argv;
38
39
static const char *load_default_groups[]= { "myisamchk", 0 };
39
40
static const char *set_collation_name, *opt_tmpdir;
40
static const CHARSET_INFO *set_collation;
41
static CHARSET_INFO *set_collation;
41
42
static long opt_myisam_block_size;
42
43
static long opt_key_cache_block_size;
43
44
static const char *my_progname_short;
45
static int stopwords_inited= 0;
44
46
static MY_TMPDIR myisamchk_tmpdir;
46
48
static const char *type_names[]=
47
49
{ "impossible","char","binary", "short", "long", "float",
48
50
"double","number","unsigned short",
49
"unsigned long","int64_t","uint64_t","int24",
51
"unsigned long","longlong","ulonglong","int24",
50
52
"uint24","int8","varchar", "varbin","?",
170
178
{"correct-checksum", OPT_CORRECT_CHECKSUM,
171
179
"Correct checksum information for table.",
172
180
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
183
"Output debug log. Often this is 'd:t:o,filename'.",
184
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
173
186
{"description", 'd',
174
187
"Prints some information about table.",
175
188
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
176
189
{"data-file-length", 'D',
177
190
"Max length of data file (when recreating data-file when it's full).",
178
(char**) &check_param.max_data_file_length,
179
(char**) &check_param.max_data_file_length,
191
(uchar**) &check_param.max_data_file_length,
192
(uchar**) &check_param.max_data_file_length,
180
193
0, GET_LL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
181
194
{"extend-check", 'e',
182
195
"If used when checking a table, ensure that the table is 100 percent consistent, which will take a long time. If used when repairing a table, try to recover every possible row from the data file. Normally this will also find a lot of garbage rows; Don't use this option with repair if you are not totally desperate.",
198
211
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
199
212
{"keys-used", 'k',
200
213
"Tell MyISAM to update only some specific keys. # is a bit mask of which keys to use. This can be used to get faster inserts.",
201
(char**) &check_param.keys_in_use,
202
(char**) &check_param.keys_in_use,
214
(uchar**) &check_param.keys_in_use,
215
(uchar**) &check_param.keys_in_use,
203
216
0, GET_ULL, REQUIRED_ARG, -1, 0, 0, 0, 0, 0},
204
217
{"max-record-length", OPT_MAX_RECORD_LENGTH,
205
218
"Skip rows bigger than this if myisamchk can't allocate memory to hold it",
206
(char**) &check_param.max_record_length,
207
(char**) &check_param.max_record_length,
208
0, GET_ULL, REQUIRED_ARG, INT64_MAX, 0, INT64_MAX, 0, 0, 0},
219
(uchar**) &check_param.max_record_length,
220
(uchar**) &check_param.max_record_length,
221
0, GET_ULL, REQUIRED_ARG, LONGLONG_MAX, 0, LONGLONG_MAX, 0, 0, 0},
209
222
{"medium-check", 'm',
210
223
"Faster than extend-check, but only finds 99.99% of all errors. Should be good enough for most cases.",
211
224
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
234
247
{"set-auto-increment", 'A',
235
248
"Force auto_increment to start at this or higher value. If no value is given, then sets the next auto_increment value to the highest used value for the auto key + 1.",
236
(char**) &check_param.auto_increment_value,
237
(char**) &check_param.auto_increment_value,
249
(uchar**) &check_param.auto_increment_value,
250
(uchar**) &check_param.auto_increment_value,
238
251
0, GET_ULL, OPT_ARG, 0, 0, 0, 0, 0, 0},
239
252
{"set-collation", OPT_SET_COLLATION,
240
253
"Change the collation used by the index",
241
(char**) &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
254
(uchar**) &set_collation_name, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
242
255
{"set-variable", 'O',
243
256
"Change the value of a variable. Please note that this option is deprecated; you can set variables directly with --variable-name=value.",
244
257
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
273
286
"Wait if table is locked.",
274
287
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
275
288
{ "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
276
(char**) &check_param.use_buffers, (char**) &check_param.use_buffers, 0,
289
(uchar**) &check_param.use_buffers, (uchar**) &check_param.use_buffers, 0,
277
290
GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
278
INT32_MAX, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
291
(long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
279
292
{ "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE, "",
280
(char**) &opt_key_cache_block_size,
281
(char**) &opt_key_cache_block_size, 0,
293
(uchar**) &opt_key_cache_block_size,
294
(uchar**) &opt_key_cache_block_size, 0,
282
295
GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
283
296
MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
284
297
{ "myisam_block_size", OPT_MYISAM_BLOCK_SIZE, "",
285
(char**) &opt_myisam_block_size, (char**) &opt_myisam_block_size, 0,
298
(uchar**) &opt_myisam_block_size, (uchar**) &opt_myisam_block_size, 0,
286
299
GET_LONG, REQUIRED_ARG, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH,
287
300
MI_MAX_KEY_BLOCK_LENGTH, 0, MI_MIN_KEY_BLOCK_LENGTH, 0},
288
301
{ "read_buffer_size", OPT_READ_BUFFER_SIZE, "",
289
(char**) &check_param.read_buffer_length,
290
(char**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
302
(uchar**) &check_param.read_buffer_length,
303
(uchar**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
291
304
(long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
292
INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
305
(long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
293
306
{ "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
294
(char**) &check_param.write_buffer_length,
295
(char**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
307
(uchar**) &check_param.write_buffer_length,
308
(uchar**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
296
309
(long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
297
INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
310
(long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
298
311
{ "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
299
(char**) &check_param.sort_buffer_length,
300
(char**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
312
(uchar**) &check_param.sort_buffer_length,
313
(uchar**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
301
314
(long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
302
INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
315
(long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
303
316
{ "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
304
(char**) &check_param.sort_key_blocks,
305
(char**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
317
(uchar**) &check_param.sort_key_blocks,
318
(uchar**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
306
319
BUFFERS_WHEN_SORTING, 4L, 100L, 0L, 1L, 0},
307
{ "decode_bits", OPT_DECODE_BITS, "", (char**) &decode_bits,
308
(char**) &decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
320
{ "decode_bits", OPT_DECODE_BITS, "", (uchar**) &decode_bits,
321
(uchar**) &decode_bits, 0, GET_UINT, REQUIRED_ARG, 9L, 4L, 17L, 0L, 1L, 0},
322
{ "ft_min_word_len", OPT_FT_MIN_WORD_LEN, "", (uchar**) &ft_min_word_len,
323
(uchar**) &ft_min_word_len, 0, GET_ULONG, REQUIRED_ARG, 4, 1, HA_FT_MAXCHARLEN,
325
{ "ft_max_word_len", OPT_FT_MAX_WORD_LEN, "", (uchar**) &ft_max_word_len,
326
(uchar**) &ft_max_word_len, 0, GET_ULONG, REQUIRED_ARG, HA_FT_MAXCHARLEN, 10,
327
HA_FT_MAXCHARLEN, 0, 1, 0},
328
{ "ft_stopword_file", OPT_FT_STOPWORD_FILE,
329
"Use stopwords from this file instead of built-in list.",
330
(uchar**) &ft_stopword_file, (uchar**) &ft_stopword_file, 0, GET_STR,
331
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
309
332
{"stats_method", OPT_STATS_METHOD,
310
333
"Specifies how index statistics collection code should treat NULLs. "
311
334
"Possible values of name are \"nulls_unequal\" (default behavior for 4.1/5.0), "
312
335
"\"nulls_equal\" (emulate 4.0 behavior), and \"nulls_ignored\".",
313
(char**) &myisam_stats_method_str, (char**) &myisam_stats_method_str, 0,
336
(uchar**) &myisam_stats_method_str, (uchar**) &myisam_stats_method_str, 0,
314
337
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
315
338
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
342
#include <help_start.h>
319
344
static void print_version(void)
321
346
printf("%s Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
348
NETWARE_SET_SCREEN_MODE(1);
972
1022
if (!error && param->testflag & T_SORT_RECORDS)
976
We can't update the index in mi_sort_records if we have a
977
prefix compressed or fulltext index
1025
The data file is nowadays reopened in the repair code so we should
1026
soon remove the following reopen-code
980
for (key=0 ; key < share->base.keys; key++)
981
if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
1028
#ifndef TO_BE_REMOVED
1029
if (param->out_flag & O_NEW_DATA)
1030
{ /* Change temp file to org file */
1031
VOID(my_close(info->dfile,MYF(MY_WME))); /* Close new file */
1032
error|=change_to_newfile(filename,MI_NAME_DEXT,DATA_TMP_EXT,
1035
if (mi_open_datafile(info,info->s, -1))
1037
param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */
1038
param->read_cache.file=info->dfile;
1045
We can't update the index in mi_sort_records if we have a
1046
prefix compressed or fulltext index
1048
my_bool update_index=1;
1049
for (key=0 ; key < share->base.keys; key++)
1050
if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
984
error=mi_sort_records(param,info,filename,param->opt_sort_key,
985
/* what is the following parameter for ? */
986
(bool) !(param->testflag & T_REP),
988
datafile=info->dfile; /* This is now locked */
989
if (!error && !update_index)
992
puts("Table had a compressed index; We must now recreate the index");
993
error=mi_repair_by_sort(param,info,filename,1);
1053
error=mi_sort_records(param,info,filename,param->opt_sort_key,
1054
/* what is the following parameter for ? */
1055
(my_bool) !(param->testflag & T_REP),
1057
datafile=info->dfile; /* This is now locked */
1058
if (!error && !update_index)
1061
puts("Table had a compressed index; We must now recreate the index");
1062
error=mi_repair_by_sort(param,info,filename,1);
996
1066
if (!error && param->testflag & T_SORT_INDEX)