~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

Removed SCCS references.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
/* Describe, check and repair of MyISAM tables */
17
17
 
18
 
#include <drizzled/global.h>
 
18
#include "fulltext.h"
19
19
 
20
 
#include <mystrings/m_ctype.h>
 
20
#include <m_ctype.h>
21
21
#include <stdarg.h>
22
 
#include <mysys/my_getopt.h>
23
 
#include <mysys/my_bit.h>
24
 
#include <myisam.h>
25
 
#include <mystrings/m_string.h>
 
22
#include <my_getopt.h>
 
23
#include <my_bit.h>
26
24
#ifdef HAVE_SYS_VADVICE_H
27
25
#include <sys/vadvise.h>
28
26
#endif
29
27
#ifdef HAVE_SYS_MMAN_H
30
28
#include <sys/mman.h>
31
29
#endif
32
 
#include <drizzled/util/test.h>
33
 
 
34
 
#include "myisamdef.h"
35
 
 
36
 
static uint32_t decode_bits;
 
30
SET_STACK_SIZE(9000)                    /* Minimum stack size for program */
 
31
 
 
32
#ifndef USE_RAID
 
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)
 
35
#endif
 
36
 
 
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;
45
47
 
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","?",
51
53
  "?"};
52
54
 
69
71
static int myisamchk(MI_CHECK *param, char *filename);
70
72
static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
71
73
static int mi_sort_records(MI_CHECK *param, register MI_INFO *info,
72
 
                           char * name, uint32_t sort_key,
73
 
                           bool write_info, bool update_index);
 
74
                           char * name, uint sort_key,
 
75
                           my_bool write_info, my_bool update_index);
74
76
static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
75
77
                             MI_KEYDEF *keyinfo,
76
 
                             my_off_t page,unsigned char *buff,uint32_t sortkey,
77
 
                             File new_file, bool update_index);
 
78
                             my_off_t page,uchar *buff,uint sortkey,
 
79
                             File new_file, my_bool update_index);
78
80
 
79
81
MI_CHECK check_param;
80
82
 
97
99
    int new_error=myisamchk(&check_param, *(argv++));
98
100
    if ((check_param.testflag & T_REP_ANY) != T_REP)
99
101
      check_param.testflag&= ~T_REP;
100
 
    fflush(stdout);
101
 
    fflush(stderr);
 
102
    VOID(fflush(stdout));
 
103
    VOID(fflush(stderr));
102
104
    if ((check_param.error_printed | check_param.warning_printed) &&
103
105
        (check_param.testflag & T_FORCE_CREATE) &&
104
106
        (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
105
107
                                   T_SORT_INDEX))))
106
108
    {
107
 
      uint32_t old_testflag=check_param.testflag;
 
109
      uint old_testflag=check_param.testflag;
108
110
      if (!(check_param.testflag & T_REP))
109
111
        check_param.testflag|= T_REP_BY_SORT;
110
112
      check_param.testflag&= ~T_EXTEND;                 /* Don't needed  */
111
113
      error|=myisamchk(&check_param, argv[-1]);
112
114
      check_param.testflag= old_testflag;
113
 
      fflush(stdout);
114
 
      fflush(stderr);
 
115
      VOID(fflush(stdout));
 
116
      VOID(fflush(stderr));
115
117
    }
116
118
    else
117
119
      error|=new_error;
118
120
    if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
119
121
    {
120
122
      puts("\n---------\n");
121
 
      fflush(stdout);
 
123
      VOID(fflush(stdout));
122
124
    }
123
125
  }
124
126
  if (check_param.total_files > 1)
131
133
  }
132
134
  free_defaults(default_argv);
133
135
  free_tmpdir(&myisamchk_tmpdir);
 
136
  ft_free_stopwords();
134
137
  my_end(check_param.testflag & T_INFO ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
135
138
  exit(error);
136
139
#ifndef _lint
143
146
  OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE,
144
147
  OPT_KEY_CACHE_BLOCK_SIZE, OPT_MYISAM_BLOCK_SIZE,
145
148
  OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE,
146
 
  OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS,
 
149
  OPT_SORT_KEY_BLOCKS, OPT_DECODE_BITS, OPT_FT_MIN_WORD_LEN,
 
150
  OPT_FT_MAX_WORD_LEN, OPT_FT_STOPWORD_FILE,
147
151
  OPT_MAX_RECORD_LENGTH, OPT_AUTO_CLOSE, OPT_STATS_METHOD
148
152
};
149
153
 
152
156
  {"analyze", 'a',
153
157
   "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.",
154
158
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
159
#ifdef __NETWARE__
 
160
  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
 
161
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
162
#endif
155
163
  {"block-search", 'b',
156
164
   "No help available.",
157
165
   0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
160
168
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
161
169
  {"character-sets-dir", OPT_CHARSETS_DIR,
162
170
   "Directory where character sets are.",
163
 
   (char**) &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
171
   (uchar**) &charsets_dir, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
164
172
  {"check", 'c',
165
173
   "Check table for errors.",
166
174
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
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},
 
181
#ifndef DBUG_OFF
 
182
  {"debug", '#',
 
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},
 
185
#endif
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},
233
246
#endif
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},
250
263
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
251
264
  {"sort-records", 'R',
252
265
   "Sort records according to an index. This makes your data much more localized and may speed up things. (It may be VERY slow to do a sort the first time!)",
253
 
   (char**) &check_param.opt_sort_key,
254
 
   (char**) &check_param.opt_sort_key,
 
266
   (uchar**) &check_param.opt_sort_key,
 
267
   (uchar**) &check_param.opt_sort_key,
255
268
   0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
256
269
  {"tmpdir", 't',
257
270
   "Path for temporary files.",
258
 
   (char**) &opt_tmpdir,
 
271
   (uchar**) &opt_tmpdir,
259
272
   0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
260
273
  {"update-state", 'U',
261
274
   "Mark tables as crashed if any errors were found.",
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,
 
324
    0, 1, 0},
 
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}
316
339
};
317
340
 
318
341
 
 
342
#include <help_start.h>
 
343
 
319
344
static void print_version(void)
320
345
{
321
346
  printf("%s  Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
322
347
         MACHINE_TYPE);
 
348
  NETWARE_SET_SCREEN_MODE(1);
323
349
}
324
350
 
325
351
 
332
358
  puts("Used without options all tables on the command will be checked for errors");
333
359
  printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname_short);
334
360
  printf("\nGlobal options:\n");
 
361
#ifndef DBUG_OFF
 
362
  printf("\
 
363
  -#, --debug=...     Output debug log. Often this is 'd:t:o,filename'.\n");
 
364
#endif
335
365
  printf("\
336
366
  -?, --help          Display this help and exit.\n\
337
367
  -O, --set-variable var=option.\n\
340
370
                      directly with '--variable-name=value'.\n\
341
371
  -t, --tmpdir=path   Path for temporary files. Multiple paths can be\n\
342
372
                      specified, separated by ");
343
 
#if defined( __WIN__)
 
373
#if defined( __WIN__) || defined(__NETWARE__)
344
374
   printf("semicolon (;)");
345
375
#else
346
376
   printf("colon (:)");
436
466
  my_print_variables(my_long_options);
437
467
}
438
468
 
 
469
#include <help_end.h>
 
470
 
439
471
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
440
 
                                           "nulls_ignored", NULL};
 
472
                                           "nulls_ignored", NullS};
441
473
TYPELIB myisam_stats_method_typelib= {
442
474
  array_elements(myisam_stats_method_names) - 1, "",
443
475
  myisam_stats_method_names, NULL};
444
476
 
445
477
         /* Read options */
446
478
 
447
 
static bool
 
479
static my_bool
448
480
get_one_option(int optid,
449
481
               const struct my_option *opt __attribute__((unused)),
450
482
               char *argument)
451
483
{
452
484
  switch (optid) {
 
485
#ifdef __NETWARE__
 
486
  case OPT_AUTO_CLOSE:
 
487
    setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
 
488
    break;
 
489
#endif
453
490
  case 'a':
454
491
    if (argument == disabled_my_option)
455
492
      check_param.testflag&= ~T_STATISTICS;
541
578
      check_param.testflag|= T_FAST;
542
579
    break;
543
580
  case 'k':
544
 
    check_param.keys_in_use= (uint64_t) strtoll(argument, NULL, 10);
 
581
    check_param.keys_in_use= (ulonglong) strtoll(argument, NULL, 10);
545
582
    break;
546
583
  case 'm':
547
584
    if (argument == disabled_my_option)
637
674
    else
638
675
      check_param.testflag|= T_UPDATE_STATE;
639
676
    break;
 
677
  case '#':
 
678
    if (argument == disabled_my_option)
 
679
    {
 
680
      DBUG_POP();
 
681
    }
 
682
    else
 
683
    {
 
684
      DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace");
 
685
    }
 
686
    break;
640
687
  case 'V':
641
688
    print_version();
642
689
    exit(0);
713
760
  if ((check_param.testflag & T_UNPACK) &&
714
761
      (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
715
762
  {
716
 
    fprintf(stderr,
717
 
            "%s: --unpack can't be used with --quick or --sort-records\n",
718
 
            my_progname_short);
 
763
    VOID(fprintf(stderr,
 
764
                 "%s: --unpack can't be used with --quick or --sort-records\n",
 
765
                 my_progname_short));
719
766
    exit(1);
720
767
  }
721
768
  if ((check_param.testflag & T_READONLY) &&
723
770
       (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
724
771
        T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
725
772
  {
726
 
    fprintf(stderr,
727
 
            "%s: Can't use --readonly when repairing or sorting\n",
728
 
            my_progname_short);
 
773
    VOID(fprintf(stderr,
 
774
                 "%s: Can't use --readonly when repairing or sorting\n",
 
775
                 my_progname_short));
729
776
    exit(1);
730
777
  }
731
778
 
751
798
{
752
799
  int error,lock_type,recreate;
753
800
  int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
754
 
  uint32_t raid_chunks;
 
801
  uint raid_chunks;
755
802
  MI_INFO *info;
756
803
  File datafile;
757
804
  char llbuff[22],llbuff2[22];
758
 
  bool state_updated=0;
 
805
  my_bool state_updated=0;
759
806
  MYISAM_SHARE *share;
 
807
  DBUG_ENTER("myisamchk");
760
808
 
761
809
  param->out_flag=error=param->warning_printed=param->error_printed=
762
810
    recreate=0;
806
854
                  my_errno,filename);
807
855
      break;
808
856
    }
809
 
    return(1);
 
857
    DBUG_RETURN(1);
810
858
  }
811
859
  share=info->s;
812
860
  share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */
821
869
  */
822
870
  if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
823
871
  {
824
 
    bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
 
872
    my_bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
825
873
 
826
874
    if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
827
875
        ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
853
901
      {
854
902
        mi_check_print_error(param,"%d when closing MyISAM-table '%s'",
855
903
                             my_errno,filename);
856
 
        return(1);
 
904
        DBUG_RETURN(1);
857
905
      }
858
 
      return(0);
 
906
      DBUG_RETURN(0);
859
907
    }
860
908
  }
861
909
  if ((param->testflag & (T_REP_ANY | T_STATISTICS |
878
926
      param->language= set_collation->number;
879
927
    if (recreate_table(param, &info,filename))
880
928
    {
881
 
      fprintf(stderr,
882
 
              "MyISAM-table '%s' is not fixed because of errors\n",
883
 
              filename);
 
929
      VOID(fprintf(stderr,
 
930
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
931
              filename));
884
932
      return(-1);
885
933
    }
886
934
    recreate=1;
905
953
  }
906
954
  else
907
955
  {
 
956
    if (!stopwords_inited++)
 
957
      ft_init_stopwords();
908
958
 
909
959
    if (!(param->testflag & T_READONLY))
910
960
      lock_type = F_WRLCK;                      /* table is changed */
931
981
    {
932
982
      if (param->testflag & T_REP_ANY)
933
983
      {
934
 
        uint64_t tmp=share->state.key_map;
 
984
        ulonglong tmp=share->state.key_map;
935
985
        mi_copy_keys_active(share->state.key_map, share->base.keys,
936
986
                            param->keys_in_use);
937
987
        if (tmp != share->state.key_map)
971
1021
      }
972
1022
      if (!error && param->testflag & T_SORT_RECORDS)
973
1023
      {
974
 
        uint32_t key;
975
1024
        /*
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
978
1027
        */
979
 
        bool update_index=1;
980
 
        for (key=0 ; key < share->base.keys; key++)
981
 
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
982
 
            update_index=0;
 
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,
 
1033
                                   raid_chunks,
 
1034
                                   MYF(0));
 
1035
          if (mi_open_datafile(info,info->s, -1))
 
1036
            error=1;
 
1037
          param->out_flag&= ~O_NEW_DATA; /* We are using new datafile */
 
1038
          param->read_cache.file=info->dfile;
 
1039
        }
 
1040
#endif
 
1041
        if (! error)
 
1042
        {
 
1043
          uint key;
 
1044
          /*
 
1045
            We can't update the index in mi_sort_records if we have a
 
1046
            prefix compressed or fulltext index
 
1047
          */
 
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))
 
1051
              update_index=0;
983
1052
 
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),
987
 
                              update_index);
988
 
        datafile=info->dfile;   /* This is now locked */
989
 
        if (!error && !update_index)
990
 
        {
991
 
          if (param->verbose)
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),
 
1056
                                update_index);
 
1057
          datafile=info->dfile; /* This is now locked */
 
1058
          if (!error && !update_index)
 
1059
          {
 
1060
            if (param->verbose)
 
1061
              puts("Table had a compressed index;  We must now recreate the index");
 
1062
            error=mi_repair_by_sort(param,info,filename,1);
 
1063
          }
994
1064
        }
995
1065
      }
996
1066
      if (!error && param->testflag & T_SORT_INDEX)
1029
1099
          !(param->testflag & (T_FAST | T_FORCE_CREATE)))
1030
1100
      {
1031
1101
        if (param->testflag & (T_EXTEND | T_MEDIUM))
1032
 
          init_key_cache(dflt_key_cache,opt_key_cache_block_size,
1033
 
                         param->use_buffers, 0, 0);
1034
 
        init_io_cache(&param->read_cache,datafile,
1035
 
                      (uint) param->read_buffer_length,
1036
 
                      READ_CACHE,
1037
 
                      (param->start_check_pos ?
1038
 
                       param->start_check_pos :
1039
 
                       share->pack.header_length),
1040
 
                      1,
1041
 
                      MYF(MY_WME));
 
1102
          VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
 
1103
                              param->use_buffers, 0, 0));
 
1104
        VOID(init_io_cache(&param->read_cache,datafile,
 
1105
                           (uint) param->read_buffer_length,
 
1106
                           READ_CACHE,
 
1107
                           (param->start_check_pos ?
 
1108
                            param->start_check_pos :
 
1109
                            share->pack.header_length),
 
1110
                           1,
 
1111
                           MYF(MY_WME)));
1042
1112
        lock_memory(param);
1043
1113
        if ((info->s->options & (HA_OPTION_PACK_RECORD |
1044
1114
                                 HA_OPTION_COMPRESS_RECORD)) ||
1045
1115
            (param->testflag & (T_EXTEND | T_MEDIUM)))
1046
1116
          error|=chk_data_link(param, info, param->testflag & T_EXTEND);
1047
1117
        error|=flush_blocks(param, share->key_cache, share->kfile);
1048
 
        end_io_cache(&param->read_cache);
 
1118
        VOID(end_io_cache(&param->read_cache));
1049
1119
      }
1050
1120
      if (!error)
1051
1121
      {
1066
1136
  if ((param->testflag & T_AUTO_INC) ||
1067
1137
      ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
1068
1138
    update_auto_increment_key(param, info,
1069
 
                              (bool) !test(param->testflag & T_AUTO_INC));
 
1139
                              (my_bool) !test(param->testflag & T_AUTO_INC));
1070
1140
 
1071
1141
  if (!(param->testflag & T_DESCRIPT))
1072
1142
  {
1078
1148
                                (state_updated ? UPDATE_STAT : 0) |
1079
1149
                                ((param->testflag & T_SORT_RECORDS) ?
1080
1150
                                 UPDATE_SORT : 0)));
 
1151
    VOID(lock_file(param, share->kfile,0L,F_UNLCK,"indexfile",filename));
1081
1152
    info->update&= ~HA_STATE_CHANGED;
1082
1153
  }
1083
1154
  mi_lock_database(info, F_UNLCK);
1085
1156
  if (mi_close(info))
1086
1157
  {
1087
1158
    mi_check_print_error(param,"%d when closing MyISAM-table '%s'",my_errno,filename);
1088
 
    return(1);
 
1159
    DBUG_RETURN(1);
1089
1160
  }
1090
1161
  if (error == 0)
1091
1162
  {
1098
1169
      error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1099
1170
                               MYF(0));
1100
1171
  }
1101
 
  fflush(stdout); fflush(stderr);
 
1172
  VOID(fflush(stdout)); VOID(fflush(stderr));
1102
1173
  if (param->error_printed)
1103
1174
  {
1104
1175
    if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1105
1176
    {
1106
 
      fprintf(stderr,
1107
 
              "MyISAM-table '%s' is not fixed because of errors\n",
1108
 
              filename);
 
1177
      VOID(fprintf(stderr,
 
1178
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
1179
                   filename));
1109
1180
      if (param->testflag & T_REP_ANY)
1110
 
        fprintf(stderr,
1111
 
                "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n");
 
1181
        VOID(fprintf(stderr,
 
1182
                     "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"));
1112
1183
    }
1113
1184
    else if (!(param->error_printed & 2) &&
1114
1185
             !(param->testflag & T_FORCE_CREATE))
1115
 
      fprintf(stderr,
1116
 
              "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
1117
 
              filename);
 
1186
      VOID(fprintf(stderr,
 
1187
      "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
 
1188
              filename));
1118
1189
  }
1119
1190
  else if (param->warning_printed &&
1120
1191
           ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
1121
1192
                          T_FORCE_CREATE)))
1122
 
    fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
1123
 
            filename);
1124
 
  fflush(stderr);
1125
 
  return(error);
 
1193
    VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
 
1194
                 filename));
 
1195
  VOID(fflush(stderr));
 
1196
  DBUG_RETURN(error);
1126
1197
} /* myisamchk */
1127
1198
 
1128
1199
 
1130
1201
 
1131
1202
static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
1132
1203
{
1133
 
  uint32_t key,keyseg_nr,field,start;
 
1204
  uint key,keyseg_nr,field,start;
1134
1205
  register MI_KEYDEF *keyinfo;
1135
1206
  register HA_KEYSEG *keyseg;
1136
1207
  register const char *text;
1138
1209
  enum en_fieldtype type;
1139
1210
  MYISAM_SHARE *share=info->s;
1140
1211
  char llbuff[22],llbuff2[22];
 
1212
  DBUG_ENTER("describe");
1141
1213
 
1142
1214
  printf("\nMyISAM file:         %s\n",name);
1143
1215
  fputs("Record format:       ",stdout);
1167
1239
    }
1168
1240
    pos=buff;
1169
1241
    if (share->state.changed & STATE_CRASHED)
1170
 
      my_stpcpy(buff,"crashed");
 
1242
      strmov(buff,"crashed");
1171
1243
    else
1172
1244
    {
1173
1245
      if (share->state.open_count)
1174
 
        pos=my_stpcpy(pos,"open,");
 
1246
        pos=strmov(pos,"open,");
1175
1247
      if (share->state.changed & STATE_CHANGED)
1176
 
        pos=my_stpcpy(pos,"changed,");
 
1248
        pos=strmov(pos,"changed,");
1177
1249
      else
1178
 
        pos=my_stpcpy(pos,"checked,");
 
1250
        pos=strmov(pos,"checked,");
1179
1251
      if (!(share->state.changed & STATE_NOT_ANALYZED))
1180
 
        pos=my_stpcpy(pos,"analyzed,");
 
1252
        pos=strmov(pos,"analyzed,");
1181
1253
      if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
1182
 
        pos=my_stpcpy(pos,"optimized keys,");
 
1254
        pos=strmov(pos,"optimized keys,");
1183
1255
      if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
1184
 
        pos=my_stpcpy(pos,"sorted index pages,");
 
1256
        pos=strmov(pos,"sorted index pages,");
1185
1257
      pos[-1]=0;                                /* Remove extra ',' */
1186
1258
    }      
1187
1259
    printf("Status:              %s\n",buff);
1191
1263
             share->base.auto_key,
1192
1264
             llstr(share->state.auto_increment,llbuff));
1193
1265
    }
 
1266
    if (share->base.raid_type)
 
1267
    {
 
1268
      printf("RAID:                Type:  %u   Chunks: %u  Chunksize: %lu\n",
 
1269
             share->base.raid_type,
 
1270
             share->base.raid_chunks,
 
1271
             share->base.raid_chunksize);
 
1272
    }
1194
1273
    if (share->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
1195
1274
      printf("Checksum:  %23s\n",llstr(info->state->checksum,llbuff));
1196
1275
;
1201
1280
  printf("Data records:        %13s  Deleted blocks:     %13s\n",
1202
1281
         llstr(info->state->records,llbuff),llstr(info->state->del,llbuff2));
1203
1282
  if (param->testflag & T_SILENT)
1204
 
    return;                             /* This is enough */
 
1283
    DBUG_VOID_RETURN;                           /* This is enough */
1205
1284
 
1206
1285
  if (param->testflag & T_VERBOSE)
1207
1286
  {
1232
1311
  printf("Recordlength:        %13d\n",(int) share->base.pack_reclength);
1233
1312
  if (! mi_is_all_keys_active(share->state.key_map, share->base.keys))
1234
1313
  {
1235
 
    int64_t2str(share->state.key_map,buff,2);
 
1314
    longlong2str(share->state.key_map,buff,2);
1236
1315
    printf("Using only keys '%s' of %d possibly keys\n",
1237
1316
           buff, share->base.keys);
1238
1317
  }
1240
1319
  printf("Key Start Len Index   Type");
1241
1320
  if (param->testflag & T_VERBOSE)
1242
1321
    printf("                     Rec/key         Root  Blocksize");
1243
 
  putchar('\n');
 
1322
  VOID(putchar('\n'));
1244
1323
 
1245
1324
  for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
1246
1325
       key < share->base.keys;
1248
1327
  {
1249
1328
    keyseg=keyinfo->seg;
1250
1329
    if (keyinfo->flag & HA_NOSAME) text="unique ";
 
1330
    else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
1251
1331
    else text="multip.";
1252
1332
 
1253
1333
    pos=buff;
1254
1334
    if (keyseg->flag & HA_REVERSE_SORT)
1255
1335
      *pos++ = '-';
1256
 
    pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1336
    pos=strmov(pos,type_names[keyseg->type]);
1257
1337
    *pos++ = ' ';
1258
1338
    *pos=0;
1259
1339
    if (keyinfo->flag & HA_PACK_KEY)
1260
 
      pos=my_stpcpy(pos,prefix_packed_txt);
 
1340
      pos=strmov(pos,prefix_packed_txt);
1261
1341
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
1262
 
      pos=my_stpcpy(pos,bin_packed_txt);
 
1342
      pos=strmov(pos,bin_packed_txt);
1263
1343
    if (keyseg->flag & HA_SPACE_PACK)
1264
 
      pos=my_stpcpy(pos,diff_txt);
 
1344
      pos=strmov(pos,diff_txt);
1265
1345
    if (keyseg->flag & HA_BLOB_PART)
1266
 
      pos=my_stpcpy(pos,blob_txt);
 
1346
      pos=strmov(pos,blob_txt);
1267
1347
    if (keyseg->flag & HA_NULL_PART)
1268
 
      pos=my_stpcpy(pos,null_txt);
 
1348
      pos=strmov(pos,null_txt);
1269
1349
    *pos=0;
1270
1350
 
1271
1351
    printf("%-4d%-6ld%-3d %-8s%-21s",
1278
1358
      printf("%11lu %12s %10d",
1279
1359
             share->state.rec_per_key_part[keyseg_nr++],
1280
1360
             buff,keyinfo->block_length);
1281
 
    putchar('\n');
 
1361
    VOID(putchar('\n'));
1282
1362
    while ((++keyseg)->type != HA_KEYTYPE_END)
1283
1363
    {
1284
1364
      pos=buff;
1285
1365
      if (keyseg->flag & HA_REVERSE_SORT)
1286
1366
        *pos++ = '-';
1287
 
      pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1367
      pos=strmov(pos,type_names[keyseg->type]);
1288
1368
      *pos++= ' ';
1289
1369
      if (keyseg->flag & HA_SPACE_PACK)
1290
 
        pos=my_stpcpy(pos,diff_txt);
 
1370
        pos=strmov(pos,diff_txt);
1291
1371
      if (keyseg->flag & HA_BLOB_PART)
1292
 
        pos=my_stpcpy(pos,blob_txt);
 
1372
        pos=strmov(pos,blob_txt);
1293
1373
      if (keyseg->flag & HA_NULL_PART)
1294
 
        pos=my_stpcpy(pos,null_txt);
 
1374
        pos=strmov(pos,null_txt);
1295
1375
      *pos=0;
1296
1376
      printf("    %-6ld%-3d         %-21s",
1297
1377
             (long) keyseg->start+1,keyseg->length,buff);
1298
1378
      if (param->testflag & T_VERBOSE)
1299
1379
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
1300
 
      putchar('\n');
 
1380
      VOID(putchar('\n'));
1301
1381
    }
1302
1382
    keyseg++;
1303
1383
  }
1308
1388
    for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
1309
1389
         key < share->state.header.uniques; key++, uniqueinfo++)
1310
1390
    {
1311
 
      bool new_row=0;
 
1391
      my_bool new_row=0;
1312
1392
      char null_bit[8],null_pos[8];
1313
1393
      printf("%-8d%-5d",key+1,uniqueinfo->key+1);
1314
1394
      for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
1335
1415
    printf("\nField Start Length Nullpos Nullbit Type");
1336
1416
    if (share->options & HA_OPTION_COMPRESS_RECORD)
1337
1417
      printf("                         Huff tree  Bits");
1338
 
    putchar('\n');
 
1418
    VOID(putchar('\n'));
1339
1419
    start=1;
1340
1420
    for (field=0 ; field < share->base.fields ; field++)
1341
1421
    {
1343
1423
        type=share->rec[field].base_type;
1344
1424
      else
1345
1425
        type=(enum en_fieldtype) share->rec[field].type;
1346
 
      end=my_stpcpy(buff,field_pack[type]);
 
1426
      end=strmov(buff,field_pack[type]);
1347
1427
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1348
1428
      {
1349
1429
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
1350
 
          end=my_stpcpy(end,", not_always");
 
1430
          end=strmov(end,", not_always");
1351
1431
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
1352
 
          end=my_stpcpy(end,", no empty");
 
1432
          end=strmov(end,", no empty");
1353
1433
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
1354
1434
        {
1355
1435
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
1356
 
          end= strchr(end, '\0');
 
1436
          end=strend(end);
1357
1437
        }
1358
1438
      }
1359
1439
      if (buff[0] == ',')
1360
 
        my_stpcpy(buff,buff+2);
 
1440
        strmov(buff,buff+2);
1361
1441
      int10_to_str((long) share->rec[field].length,length,10);
1362
1442
      null_bit[0]=null_pos[0]=0;
1363
1443
      if (share->rec[field].null_bit)
1374
1454
                 (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
1375
1455
                 share->rec[field].huff_tree->quick_table_bits);
1376
1456
      }
1377
 
      putchar('\n');
 
1457
      VOID(putchar('\n'));
1378
1458
      start+=share->rec[field].length;
1379
1459
    }
1380
1460
  }
1381
 
  return;
 
1461
  DBUG_VOID_RETURN;
1382
1462
} /* describe */
1383
1463
 
1384
1464
 
1386
1466
 
1387
1467
static int mi_sort_records(MI_CHECK *param,
1388
1468
                           register MI_INFO *info, char * name,
1389
 
                           uint32_t sort_key,
1390
 
                           bool write_info,
1391
 
                           bool update_index)
 
1469
                           uint sort_key,
 
1470
                           my_bool write_info,
 
1471
                           my_bool update_index)
1392
1472
{
1393
1473
  int got_error;
1394
 
  uint32_t key;
 
1474
  uint key;
1395
1475
  MI_KEYDEF *keyinfo;
1396
1476
  File new_file;
1397
 
  unsigned char *temp_buff;
 
1477
  uchar *temp_buff;
1398
1478
  ha_rows old_record_count;
1399
1479
  MYISAM_SHARE *share=info->s;
1400
1480
  char llbuff[22],llbuff2[22];
1401
1481
  SORT_INFO sort_info;
1402
1482
  MI_SORT_PARAM sort_param;
 
1483
  DBUG_ENTER("sort_records");
1403
1484
 
1404
 
  memset(&sort_info, 0, sizeof(sort_info));
1405
 
  memset(&sort_param, 0, sizeof(sort_param));
 
1485
  bzero((char*)&sort_info,sizeof(sort_info));
 
1486
  bzero((char*)&sort_param,sizeof(sort_param));
1406
1487
  sort_param.sort_info=&sort_info;
1407
1488
  sort_info.param=param;
1408
1489
  keyinfo= &share->keyinfo[sort_key];
1416
1497
                           "Can't sort table '%s' on key %d;  No such key",
1417
1498
                name,sort_key+1);
1418
1499
    param->error_printed=0;
1419
 
    return(0);                          /* Nothing to do */
 
1500
    DBUG_RETURN(0);                             /* Nothing to do */
 
1501
  }
 
1502
  if (keyinfo->flag & HA_FULLTEXT)
 
1503
  {
 
1504
    mi_check_print_warning(param,"Can't sort table '%s' on FULLTEXT key %d",
 
1505
                           name,sort_key+1);
 
1506
    param->error_printed=0;
 
1507
    DBUG_RETURN(0);                             /* Nothing to do */
1420
1508
  }
1421
1509
  if (share->data_file_type == COMPRESSED_RECORD)
1422
1510
  {
1423
1511
    mi_check_print_warning(param,"Can't sort read-only table '%s'", name);
1424
1512
    param->error_printed=0;
1425
 
    return(0);                          /* Nothing to do */
 
1513
    DBUG_RETURN(0);                             /* Nothing to do */
1426
1514
  }
1427
1515
  if (!(param->testflag & T_SILENT))
1428
1516
  {
1433
1521
             llstr(info->state->del,llbuff2));
1434
1522
  }
1435
1523
  if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
1436
 
    return(0);                          /* Nothing to do */
 
1524
    DBUG_RETURN(0);                             /* Nothing to do */
1437
1525
 
1438
1526
  init_key_cache(dflt_key_cache, opt_key_cache_block_size, param->use_buffers,
1439
1527
                 0, 0);
1443
1531
    goto err;
1444
1532
  info->opt_flag|=WRITE_CACHE_USED;
1445
1533
 
1446
 
  if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1534
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1447
1535
  {
1448
1536
    mi_check_print_error(param,"Not enough memory for key block");
1449
1537
    goto err;
1455
1543
    goto err;
1456
1544
  }
1457
1545
  fn_format(param->temp_filename,name,"", MI_NAME_DEXT,2+4+32);
1458
 
  new_file=my_create(fn_format(param->temp_filename,
1459
 
                               param->temp_filename,"",
1460
 
                               DATA_TMP_EXT,2+4),        
1461
 
                     0,param->tmpfile_createflag,
1462
 
                     MYF(0));
 
1546
  new_file=my_raid_create(fn_format(param->temp_filename,
 
1547
                                    param->temp_filename,"",
 
1548
                                    DATA_TMP_EXT,2+4),
 
1549
                          0,param->tmpfile_createflag,
 
1550
                          share->base.raid_type,
 
1551
                          share->base.raid_chunks,
 
1552
                          share->base.raid_chunksize,
 
1553
                          MYF(0));
1463
1554
  if (new_file < 0)
1464
1555
  {
1465
1556
    mi_check_print_error(param,"Can't create new tempfile: '%s'",
1476
1567
  for (key=0 ; key < share->base.keys ; key++)
1477
1568
    share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
1478
1569
 
1479
 
  if (my_pread(share->kfile,(unsigned char*) temp_buff,
 
1570
  if (my_pread(share->kfile,(uchar*) temp_buff,
1480
1571
               (uint) keyinfo->block_length,
1481
1572
               share->state.key_root[sort_key],
1482
1573
               MYF(MY_NABP+MY_WME)))
1511
1602
    goto err;
1512
1603
  }
1513
1604
 
1514
 
  my_close(info->dfile,MYF(MY_WME));
 
1605
  VOID(my_close(info->dfile,MYF(MY_WME)));
1515
1606
  param->out_flag|=O_NEW_DATA;                  /* Data in new file */
1516
1607
  info->dfile=new_file;                         /* Use new datafile */
1517
1608
  info->state->del=0;
1525
1616
 
1526
1617
  if (param->testflag & T_WRITE_LOOP)
1527
1618
  {
1528
 
    fputs("          \r",stdout); fflush(stdout);
 
1619
    VOID(fputs("          \r",stdout)); VOID(fflush(stdout));
1529
1620
  }
1530
1621
  got_error=0;
1531
1622
 
1532
1623
err:
1533
1624
  if (got_error && new_file >= 0)
1534
1625
  {
1535
 
    end_io_cache(&info->rec_cache);
 
1626
    VOID(end_io_cache(&info->rec_cache));
1536
1627
    (void) my_close(new_file,MYF(MY_WME));
1537
 
    (void) my_delete(param->temp_filename, MYF(MY_WME));
 
1628
    (void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
 
1629
                          MYF(MY_WME));
1538
1630
  }
1539
1631
  if (temp_buff)
1540
1632
  {
1541
 
    my_afree((unsigned char*) temp_buff);
 
1633
    my_afree((uchar*) temp_buff);
1542
1634
  }
1543
 
  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
1544
 
  if (rec_buff_ptr != NULL)
1545
 
    free(rec_buff_ptr);
1546
 
 
 
1635
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1636
          MYF(MY_ALLOW_ZERO_PTR));
1547
1637
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1548
 
  end_io_cache(&info->rec_cache);
1549
 
  free(sort_info.buff);
 
1638
  VOID(end_io_cache(&info->rec_cache));
 
1639
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1550
1640
  sort_info.buff=0;
1551
1641
  share->state.sortkey=sort_key;
1552
 
  return(flush_blocks(param, share->key_cache, share->kfile) |
 
1642
  DBUG_RETURN(flush_blocks(param, share->key_cache, share->kfile) |
1553
1643
              got_error);
1554
1644
} /* sort_records */
1555
1645
 
1558
1648
 
1559
1649
static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
1560
1650
                             MI_KEYDEF *keyinfo,
1561
 
                             my_off_t page, unsigned char *buff, uint32_t sort_key,
1562
 
                             File new_file,bool update_index)
 
1651
                             my_off_t page, uchar *buff, uint sort_key,
 
1652
                             File new_file,my_bool update_index)
1563
1653
{
1564
1654
  uint  nod_flag,used_length,key_length;
1565
 
  unsigned char *temp_buff,*keypos,*endpos;
 
1655
  uchar *temp_buff,*keypos,*endpos;
1566
1656
  my_off_t next_page,rec_pos;
1567
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
1657
  uchar lastkey[MI_MAX_KEY_BUFF];
1568
1658
  char llbuff[22];
1569
1659
  SORT_INFO *sort_info= sort_param->sort_info;
1570
1660
  MI_CHECK *param=sort_info->param;
 
1661
  DBUG_ENTER("sort_record_index");
1571
1662
 
1572
1663
  nod_flag=mi_test_if_nod(buff);
1573
1664
  temp_buff=0;
1574
1665
 
1575
1666
  if (nod_flag)
1576
1667
  {
1577
 
    if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1668
    if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1578
1669
    {
1579
1670
      mi_check_print_error(param,"Not Enough memory");
1580
 
      return(-1);
 
1671
      DBUG_RETURN(-1);
1581
1672
    }
1582
1673
  }
1583
1674
  used_length=mi_getint(buff);
1588
1679
    if (nod_flag)
1589
1680
    {
1590
1681
      next_page=_mi_kpos(nod_flag,keypos);
1591
 
      if (my_pread(info->s->kfile,(unsigned char*) temp_buff,
 
1682
      if (my_pread(info->s->kfile,(uchar*) temp_buff,
1592
1683
                  (uint) keyinfo->block_length, next_page,
1593
1684
                   MYF(MY_NABP+MY_WME)))
1594
1685
      {
1626
1717
      goto err;
1627
1718
  }
1628
1719
  /* Clear end of block to get better compression if the table is backuped */
1629
 
  memset(buff+used_length, 0, keyinfo->block_length-used_length);
1630
 
  if (my_pwrite(info->s->kfile,(unsigned char*) buff,(uint) keyinfo->block_length,
 
1720
  bzero((uchar*) buff+used_length,keyinfo->block_length-used_length);
 
1721
  if (my_pwrite(info->s->kfile,(uchar*) buff,(uint) keyinfo->block_length,
1631
1722
                page,param->myf_rw))
1632
1723
  {
1633
1724
    mi_check_print_error(param,"%d when updating keyblock",my_errno);
1634
1725
    goto err;
1635
1726
  }
1636
1727
  if (temp_buff)
1637
 
    my_afree((unsigned char*) temp_buff);
1638
 
  return(0);
 
1728
    my_afree((uchar*) temp_buff);
 
1729
  DBUG_RETURN(0);
1639
1730
err:
1640
1731
  if (temp_buff)
1641
 
    my_afree((unsigned char*) temp_buff);
1642
 
  return(1);
 
1732
    my_afree((uchar*) temp_buff);
 
1733
  DBUG_RETURN(1);
1643
1734
} /* sort_record_index */
1644
1735
 
1645
1736
 
1666
1757
  va_list args;
1667
1758
 
1668
1759
  va_start(args,fmt);
1669
 
  vfprintf(stdout, fmt, args);
1670
 
  fputc('\n',stdout);
 
1760
  VOID(vfprintf(stdout, fmt, args));
 
1761
  VOID(fputc('\n',stdout));
1671
1762
  va_end(args);
1672
1763
}
1673
1764
 
1676
1767
void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
1677
1768
{
1678
1769
  va_list args;
 
1770
  DBUG_ENTER("mi_check_print_warning");
1679
1771
 
1680
1772
  fflush(stdout);
1681
1773
  if (!param->warning_printed && !param->error_printed)
1688
1780
  param->warning_printed=1;
1689
1781
  va_start(args,fmt);
1690
1782
  fprintf(stderr,"%s: warning: ",my_progname_short);
1691
 
  vfprintf(stderr, fmt, args);
1692
 
  fputc('\n',stderr);
 
1783
  VOID(vfprintf(stderr, fmt, args));
 
1784
  VOID(fputc('\n',stderr));
1693
1785
  fflush(stderr);
1694
1786
  va_end(args);
1695
 
  return;
 
1787
  DBUG_VOID_RETURN;
1696
1788
}
1697
1789
 
1698
1790
/* VARARGS */
1700
1792
void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
1701
1793
{
1702
1794
  va_list args;
 
1795
  DBUG_ENTER("mi_check_print_error");
 
1796
  DBUG_PRINT("enter",("format: %s",fmt));
1703
1797
 
1704
1798
  fflush(stdout);
1705
1799
  if (!param->warning_printed && !param->error_printed)
1711
1805
  param->error_printed|=1;
1712
1806
  va_start(args,fmt);
1713
1807
  fprintf(stderr,"%s: error: ",my_progname_short);
1714
 
  vfprintf(stderr, fmt, args);
1715
 
  fputc('\n',stderr);
 
1808
  VOID(vfprintf(stderr, fmt, args));
 
1809
  VOID(fputc('\n',stderr));
1716
1810
  fflush(stderr);
1717
1811
  va_end(args);
1718
 
  return;
 
1812
  DBUG_VOID_RETURN;
1719
1813
}
1720
1814
 
 
1815
#include "mi_extrafunc.h"