~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

Merge/fix in FAQ.

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 <my_global.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>
 
22
#include <my_getopt.h>
 
23
#include <my_bit.h>
24
24
#include <myisam.h>
25
 
#include <mystrings/m_string.h>
 
25
#include <m_string.h>
26
26
#ifdef HAVE_SYS_VADVICE_H
27
27
#include <sys/vadvise.h>
28
28
#endif
29
29
#ifdef HAVE_SYS_MMAN_H
30
30
#include <sys/mman.h>
31
31
#endif
 
32
SET_STACK_SIZE(9000)                    /* Minimum stack size for program */
32
33
 
33
34
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
34
35
#define my_raid_delete(A,B,C) my_delete(A,B)
35
36
 
36
37
#include "myisamdef.h"
37
38
 
38
 
static uint32_t decode_bits;
 
39
static uint decode_bits;
39
40
static char **default_argv;
40
41
static const char *load_default_groups[]= { "myisamchk", 0 };
41
42
static const char *set_collation_name, *opt_tmpdir;
42
 
static const CHARSET_INFO *set_collation;
 
43
static CHARSET_INFO *set_collation;
43
44
static long opt_myisam_block_size;
44
45
static long opt_key_cache_block_size;
45
46
static const char *my_progname_short;
71
72
static int myisamchk(MI_CHECK *param, char *filename);
72
73
static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
73
74
static int mi_sort_records(MI_CHECK *param, register MI_INFO *info,
74
 
                           char * name, uint32_t sort_key,
75
 
                           bool write_info, bool update_index);
 
75
                           char * name, uint sort_key,
 
76
                           my_bool write_info, my_bool update_index);
76
77
static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
77
78
                             MI_KEYDEF *keyinfo,
78
 
                             my_off_t page,unsigned char *buff,uint32_t sortkey,
79
 
                             File new_file, bool update_index);
 
79
                             my_off_t page,uchar *buff,uint sortkey,
 
80
                             File new_file, my_bool update_index);
80
81
 
81
82
MI_CHECK check_param;
82
83
 
99
100
    int new_error=myisamchk(&check_param, *(argv++));
100
101
    if ((check_param.testflag & T_REP_ANY) != T_REP)
101
102
      check_param.testflag&= ~T_REP;
102
 
    fflush(stdout);
103
 
    fflush(stderr);
 
103
    VOID(fflush(stdout));
 
104
    VOID(fflush(stderr));
104
105
    if ((check_param.error_printed | check_param.warning_printed) &&
105
106
        (check_param.testflag & T_FORCE_CREATE) &&
106
107
        (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
107
108
                                   T_SORT_INDEX))))
108
109
    {
109
 
      uint32_t old_testflag=check_param.testflag;
 
110
      uint old_testflag=check_param.testflag;
110
111
      if (!(check_param.testflag & T_REP))
111
112
        check_param.testflag|= T_REP_BY_SORT;
112
113
      check_param.testflag&= ~T_EXTEND;                 /* Don't needed  */
113
114
      error|=myisamchk(&check_param, argv[-1]);
114
115
      check_param.testflag= old_testflag;
115
 
      fflush(stdout);
116
 
      fflush(stderr);
 
116
      VOID(fflush(stdout));
 
117
      VOID(fflush(stderr));
117
118
    }
118
119
    else
119
120
      error|=new_error;
120
121
    if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
121
122
    {
122
123
      puts("\n---------\n");
123
 
      fflush(stdout);
 
124
      VOID(fflush(stdout));
124
125
    }
125
126
  }
126
127
  if (check_param.total_files > 1)
154
155
  {"analyze", 'a',
155
156
   "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.",
156
157
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
158
#ifdef __NETWARE__
 
159
  {"autoclose", OPT_AUTO_CLOSE, "Auto close the screen on exit for Netware.",
 
160
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
161
#endif
157
162
  {"block-search", 'b',
158
163
   "No help available.",
159
164
   0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
277
282
  { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
278
283
    (char**) &check_param.use_buffers, (char**) &check_param.use_buffers, 0,
279
284
    GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
280
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
 
285
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
281
286
  { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,  "",
282
287
    (char**) &opt_key_cache_block_size,
283
288
    (char**) &opt_key_cache_block_size, 0,
291
296
    (char**) &check_param.read_buffer_length,
292
297
    (char**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
293
298
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
294
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
299
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
295
300
  { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
296
301
    (char**) &check_param.write_buffer_length,
297
302
    (char**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
298
303
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
299
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
304
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
300
305
  { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
301
306
    (char**) &check_param.sort_buffer_length,
302
307
    (char**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
303
308
    (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
304
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
309
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
305
310
  { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
306
311
    (char**) &check_param.sort_key_blocks,
307
312
    (char**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
318
323
};
319
324
 
320
325
 
 
326
#include <help_start.h>
 
327
 
321
328
static void print_version(void)
322
329
{
323
330
  printf("%s  Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
342
349
                      directly with '--variable-name=value'.\n\
343
350
  -t, --tmpdir=path   Path for temporary files. Multiple paths can be\n\
344
351
                      specified, separated by ");
345
 
#if defined( __WIN__)
 
352
#if defined( __WIN__) || defined(__NETWARE__)
346
353
   printf("semicolon (;)");
347
354
#else
348
355
   printf("colon (:)");
438
445
  my_print_variables(my_long_options);
439
446
}
440
447
 
 
448
#include <help_end.h>
 
449
 
441
450
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
442
 
                                           "nulls_ignored", NULL};
 
451
                                           "nulls_ignored", NullS};
443
452
TYPELIB myisam_stats_method_typelib= {
444
453
  array_elements(myisam_stats_method_names) - 1, "",
445
454
  myisam_stats_method_names, NULL};
715
724
  if ((check_param.testflag & T_UNPACK) &&
716
725
      (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
717
726
  {
718
 
    fprintf(stderr,
719
 
            "%s: --unpack can't be used with --quick or --sort-records\n",
720
 
            my_progname_short);
 
727
    VOID(fprintf(stderr,
 
728
                 "%s: --unpack can't be used with --quick or --sort-records\n",
 
729
                 my_progname_short));
721
730
    exit(1);
722
731
  }
723
732
  if ((check_param.testflag & T_READONLY) &&
725
734
       (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
726
735
        T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
727
736
  {
728
 
    fprintf(stderr,
729
 
            "%s: Can't use --readonly when repairing or sorting\n",
730
 
            my_progname_short);
 
737
    VOID(fprintf(stderr,
 
738
                 "%s: Can't use --readonly when repairing or sorting\n",
 
739
                 my_progname_short));
731
740
    exit(1);
732
741
  }
733
742
 
753
762
{
754
763
  int error,lock_type,recreate;
755
764
  int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
756
 
  uint32_t raid_chunks;
 
765
  uint raid_chunks;
757
766
  MI_INFO *info;
758
767
  File datafile;
759
768
  char llbuff[22],llbuff2[22];
760
 
  bool state_updated=0;
 
769
  my_bool state_updated=0;
761
770
  MYISAM_SHARE *share;
762
771
 
763
772
  param->out_flag=error=param->warning_printed=param->error_printed=
823
832
  */
824
833
  if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
825
834
  {
826
 
    bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
 
835
    my_bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
827
836
 
828
837
    if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
829
838
        ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
880
889
      param->language= set_collation->number;
881
890
    if (recreate_table(param, &info,filename))
882
891
    {
883
 
      fprintf(stderr,
884
 
              "MyISAM-table '%s' is not fixed because of errors\n",
885
 
              filename);
 
892
      VOID(fprintf(stderr,
 
893
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
894
              filename));
886
895
      return(-1);
887
896
    }
888
897
    recreate=1;
973
982
      }
974
983
      if (!error && param->testflag & T_SORT_RECORDS)
975
984
      {
976
 
        uint32_t key;
 
985
        uint key;
977
986
        /*
978
987
          We can't update the index in mi_sort_records if we have a
979
988
          prefix compressed or fulltext index
980
989
        */
981
 
        bool update_index=1;
 
990
        my_bool update_index=1;
982
991
        for (key=0 ; key < share->base.keys; key++)
983
 
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
 
992
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
984
993
            update_index=0;
985
994
 
986
995
        error=mi_sort_records(param,info,filename,param->opt_sort_key,
987
996
                           /* what is the following parameter for ? */
988
 
                              (bool) !(param->testflag & T_REP),
 
997
                              (my_bool) !(param->testflag & T_REP),
989
998
                              update_index);
990
999
        datafile=info->dfile;   /* This is now locked */
991
1000
        if (!error && !update_index)
1031
1040
          !(param->testflag & (T_FAST | T_FORCE_CREATE)))
1032
1041
      {
1033
1042
        if (param->testflag & (T_EXTEND | T_MEDIUM))
1034
 
          init_key_cache(dflt_key_cache,opt_key_cache_block_size,
1035
 
                         param->use_buffers, 0, 0);
1036
 
        init_io_cache(&param->read_cache,datafile,
1037
 
                      (uint) param->read_buffer_length,
1038
 
                      READ_CACHE,
1039
 
                      (param->start_check_pos ?
1040
 
                       param->start_check_pos :
1041
 
                       share->pack.header_length),
1042
 
                      1,
1043
 
                      MYF(MY_WME));
 
1043
          VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
 
1044
                              param->use_buffers, 0, 0));
 
1045
        VOID(init_io_cache(&param->read_cache,datafile,
 
1046
                           (uint) param->read_buffer_length,
 
1047
                           READ_CACHE,
 
1048
                           (param->start_check_pos ?
 
1049
                            param->start_check_pos :
 
1050
                            share->pack.header_length),
 
1051
                           1,
 
1052
                           MYF(MY_WME)));
1044
1053
        lock_memory(param);
1045
1054
        if ((info->s->options & (HA_OPTION_PACK_RECORD |
1046
1055
                                 HA_OPTION_COMPRESS_RECORD)) ||
1047
1056
            (param->testflag & (T_EXTEND | T_MEDIUM)))
1048
1057
          error|=chk_data_link(param, info, param->testflag & T_EXTEND);
1049
1058
        error|=flush_blocks(param, share->key_cache, share->kfile);
1050
 
        end_io_cache(&param->read_cache);
 
1059
        VOID(end_io_cache(&param->read_cache));
1051
1060
      }
1052
1061
      if (!error)
1053
1062
      {
1068
1077
  if ((param->testflag & T_AUTO_INC) ||
1069
1078
      ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
1070
1079
    update_auto_increment_key(param, info,
1071
 
                              (bool) !test(param->testflag & T_AUTO_INC));
 
1080
                              (my_bool) !test(param->testflag & T_AUTO_INC));
1072
1081
 
1073
1082
  if (!(param->testflag & T_DESCRIPT))
1074
1083
  {
1100
1109
      error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1101
1110
                               MYF(0));
1102
1111
  }
1103
 
  fflush(stdout); fflush(stderr);
 
1112
  VOID(fflush(stdout)); VOID(fflush(stderr));
1104
1113
  if (param->error_printed)
1105
1114
  {
1106
1115
    if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1107
1116
    {
1108
 
      fprintf(stderr,
1109
 
              "MyISAM-table '%s' is not fixed because of errors\n",
1110
 
              filename);
 
1117
      VOID(fprintf(stderr,
 
1118
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
1119
                   filename));
1111
1120
      if (param->testflag & T_REP_ANY)
1112
 
        fprintf(stderr,
1113
 
                "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n");
 
1121
        VOID(fprintf(stderr,
 
1122
                     "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"));
1114
1123
    }
1115
1124
    else if (!(param->error_printed & 2) &&
1116
1125
             !(param->testflag & T_FORCE_CREATE))
1117
 
      fprintf(stderr,
1118
 
              "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
1119
 
              filename);
 
1126
      VOID(fprintf(stderr,
 
1127
      "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
 
1128
              filename));
1120
1129
  }
1121
1130
  else if (param->warning_printed &&
1122
1131
           ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
1123
1132
                          T_FORCE_CREATE)))
1124
 
    fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
1125
 
            filename);
1126
 
  fflush(stderr);
 
1133
    VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
 
1134
                 filename));
 
1135
  VOID(fflush(stderr));
1127
1136
  return(error);
1128
1137
} /* myisamchk */
1129
1138
 
1132
1141
 
1133
1142
static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
1134
1143
{
1135
 
  uint32_t key,keyseg_nr,field,start;
 
1144
  uint key,keyseg_nr,field,start;
1136
1145
  register MI_KEYDEF *keyinfo;
1137
1146
  register HA_KEYSEG *keyseg;
1138
1147
  register const char *text;
1169
1178
    }
1170
1179
    pos=buff;
1171
1180
    if (share->state.changed & STATE_CRASHED)
1172
 
      my_stpcpy(buff,"crashed");
 
1181
      strmov(buff,"crashed");
1173
1182
    else
1174
1183
    {
1175
1184
      if (share->state.open_count)
1176
 
        pos=my_stpcpy(pos,"open,");
 
1185
        pos=strmov(pos,"open,");
1177
1186
      if (share->state.changed & STATE_CHANGED)
1178
 
        pos=my_stpcpy(pos,"changed,");
 
1187
        pos=strmov(pos,"changed,");
1179
1188
      else
1180
 
        pos=my_stpcpy(pos,"checked,");
 
1189
        pos=strmov(pos,"checked,");
1181
1190
      if (!(share->state.changed & STATE_NOT_ANALYZED))
1182
 
        pos=my_stpcpy(pos,"analyzed,");
 
1191
        pos=strmov(pos,"analyzed,");
1183
1192
      if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
1184
 
        pos=my_stpcpy(pos,"optimized keys,");
 
1193
        pos=strmov(pos,"optimized keys,");
1185
1194
      if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
1186
 
        pos=my_stpcpy(pos,"sorted index pages,");
 
1195
        pos=strmov(pos,"sorted index pages,");
1187
1196
      pos[-1]=0;                                /* Remove extra ',' */
1188
1197
    }      
1189
1198
    printf("Status:              %s\n",buff);
1249
1258
  printf("Key Start Len Index   Type");
1250
1259
  if (param->testflag & T_VERBOSE)
1251
1260
    printf("                     Rec/key         Root  Blocksize");
1252
 
  putchar('\n');
 
1261
  VOID(putchar('\n'));
1253
1262
 
1254
1263
  for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
1255
1264
       key < share->base.keys;
1257
1266
  {
1258
1267
    keyseg=keyinfo->seg;
1259
1268
    if (keyinfo->flag & HA_NOSAME) text="unique ";
 
1269
    else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
1260
1270
    else text="multip.";
1261
1271
 
1262
1272
    pos=buff;
1263
1273
    if (keyseg->flag & HA_REVERSE_SORT)
1264
1274
      *pos++ = '-';
1265
 
    pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1275
    pos=strmov(pos,type_names[keyseg->type]);
1266
1276
    *pos++ = ' ';
1267
1277
    *pos=0;
1268
1278
    if (keyinfo->flag & HA_PACK_KEY)
1269
 
      pos=my_stpcpy(pos,prefix_packed_txt);
 
1279
      pos=strmov(pos,prefix_packed_txt);
1270
1280
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
1271
 
      pos=my_stpcpy(pos,bin_packed_txt);
 
1281
      pos=strmov(pos,bin_packed_txt);
1272
1282
    if (keyseg->flag & HA_SPACE_PACK)
1273
 
      pos=my_stpcpy(pos,diff_txt);
 
1283
      pos=strmov(pos,diff_txt);
1274
1284
    if (keyseg->flag & HA_BLOB_PART)
1275
 
      pos=my_stpcpy(pos,blob_txt);
 
1285
      pos=strmov(pos,blob_txt);
1276
1286
    if (keyseg->flag & HA_NULL_PART)
1277
 
      pos=my_stpcpy(pos,null_txt);
 
1287
      pos=strmov(pos,null_txt);
1278
1288
    *pos=0;
1279
1289
 
1280
1290
    printf("%-4d%-6ld%-3d %-8s%-21s",
1287
1297
      printf("%11lu %12s %10d",
1288
1298
             share->state.rec_per_key_part[keyseg_nr++],
1289
1299
             buff,keyinfo->block_length);
1290
 
    putchar('\n');
 
1300
    VOID(putchar('\n'));
1291
1301
    while ((++keyseg)->type != HA_KEYTYPE_END)
1292
1302
    {
1293
1303
      pos=buff;
1294
1304
      if (keyseg->flag & HA_REVERSE_SORT)
1295
1305
        *pos++ = '-';
1296
 
      pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1306
      pos=strmov(pos,type_names[keyseg->type]);
1297
1307
      *pos++= ' ';
1298
1308
      if (keyseg->flag & HA_SPACE_PACK)
1299
 
        pos=my_stpcpy(pos,diff_txt);
 
1309
        pos=strmov(pos,diff_txt);
1300
1310
      if (keyseg->flag & HA_BLOB_PART)
1301
 
        pos=my_stpcpy(pos,blob_txt);
 
1311
        pos=strmov(pos,blob_txt);
1302
1312
      if (keyseg->flag & HA_NULL_PART)
1303
 
        pos=my_stpcpy(pos,null_txt);
 
1313
        pos=strmov(pos,null_txt);
1304
1314
      *pos=0;
1305
1315
      printf("    %-6ld%-3d         %-21s",
1306
1316
             (long) keyseg->start+1,keyseg->length,buff);
1307
1317
      if (param->testflag & T_VERBOSE)
1308
1318
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
1309
 
      putchar('\n');
 
1319
      VOID(putchar('\n'));
1310
1320
    }
1311
1321
    keyseg++;
1312
1322
  }
1317
1327
    for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
1318
1328
         key < share->state.header.uniques; key++, uniqueinfo++)
1319
1329
    {
1320
 
      bool new_row=0;
 
1330
      my_bool new_row=0;
1321
1331
      char null_bit[8],null_pos[8];
1322
1332
      printf("%-8d%-5d",key+1,uniqueinfo->key+1);
1323
1333
      for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
1344
1354
    printf("\nField Start Length Nullpos Nullbit Type");
1345
1355
    if (share->options & HA_OPTION_COMPRESS_RECORD)
1346
1356
      printf("                         Huff tree  Bits");
1347
 
    putchar('\n');
 
1357
    VOID(putchar('\n'));
1348
1358
    start=1;
1349
1359
    for (field=0 ; field < share->base.fields ; field++)
1350
1360
    {
1352
1362
        type=share->rec[field].base_type;
1353
1363
      else
1354
1364
        type=(enum en_fieldtype) share->rec[field].type;
1355
 
      end=my_stpcpy(buff,field_pack[type]);
 
1365
      end=strmov(buff,field_pack[type]);
1356
1366
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1357
1367
      {
1358
1368
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
1359
 
          end=my_stpcpy(end,", not_always");
 
1369
          end=strmov(end,", not_always");
1360
1370
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
1361
 
          end=my_stpcpy(end,", no empty");
 
1371
          end=strmov(end,", no empty");
1362
1372
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
1363
1373
        {
1364
1374
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
1365
 
          end= strchr(end, '\0');
 
1375
          end=strend(end);
1366
1376
        }
1367
1377
      }
1368
1378
      if (buff[0] == ',')
1369
 
        my_stpcpy(buff,buff+2);
 
1379
        strmov(buff,buff+2);
1370
1380
      int10_to_str((long) share->rec[field].length,length,10);
1371
1381
      null_bit[0]=null_pos[0]=0;
1372
1382
      if (share->rec[field].null_bit)
1383
1393
                 (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
1384
1394
                 share->rec[field].huff_tree->quick_table_bits);
1385
1395
      }
1386
 
      putchar('\n');
 
1396
      VOID(putchar('\n'));
1387
1397
      start+=share->rec[field].length;
1388
1398
    }
1389
1399
  }
1395
1405
 
1396
1406
static int mi_sort_records(MI_CHECK *param,
1397
1407
                           register MI_INFO *info, char * name,
1398
 
                           uint32_t sort_key,
1399
 
                           bool write_info,
1400
 
                           bool update_index)
 
1408
                           uint sort_key,
 
1409
                           my_bool write_info,
 
1410
                           my_bool update_index)
1401
1411
{
1402
1412
  int got_error;
1403
 
  uint32_t key;
 
1413
  uint key;
1404
1414
  MI_KEYDEF *keyinfo;
1405
1415
  File new_file;
1406
 
  unsigned char *temp_buff;
 
1416
  uchar *temp_buff;
1407
1417
  ha_rows old_record_count;
1408
1418
  MYISAM_SHARE *share=info->s;
1409
1419
  char llbuff[22],llbuff2[22];
1410
1420
  SORT_INFO sort_info;
1411
1421
  MI_SORT_PARAM sort_param;
1412
1422
 
1413
 
  memset(&sort_info, 0, sizeof(sort_info));
1414
 
  memset(&sort_param, 0, sizeof(sort_param));
 
1423
  bzero((char*)&sort_info,sizeof(sort_info));
 
1424
  bzero((char*)&sort_param,sizeof(sort_param));
1415
1425
  sort_param.sort_info=&sort_info;
1416
1426
  sort_info.param=param;
1417
1427
  keyinfo= &share->keyinfo[sort_key];
1427
1437
    param->error_printed=0;
1428
1438
    return(0);                          /* Nothing to do */
1429
1439
  }
 
1440
  if (keyinfo->flag & HA_FULLTEXT)
 
1441
  {
 
1442
    mi_check_print_warning(param,"Can't sort table '%s' on FULLTEXT key %d",
 
1443
                           name,sort_key+1);
 
1444
    param->error_printed=0;
 
1445
    return(0);                          /* Nothing to do */
 
1446
  }
1430
1447
  if (share->data_file_type == COMPRESSED_RECORD)
1431
1448
  {
1432
1449
    mi_check_print_warning(param,"Can't sort read-only table '%s'", name);
1452
1469
    goto err;
1453
1470
  info->opt_flag|=WRITE_CACHE_USED;
1454
1471
 
1455
 
  if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1472
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1456
1473
  {
1457
1474
    mi_check_print_error(param,"Not enough memory for key block");
1458
1475
    goto err;
1488
1505
  for (key=0 ; key < share->base.keys ; key++)
1489
1506
    share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
1490
1507
 
1491
 
  if (my_pread(share->kfile,(unsigned char*) temp_buff,
 
1508
  if (my_pread(share->kfile,(uchar*) temp_buff,
1492
1509
               (uint) keyinfo->block_length,
1493
1510
               share->state.key_root[sort_key],
1494
1511
               MYF(MY_NABP+MY_WME)))
1523
1540
    goto err;
1524
1541
  }
1525
1542
 
1526
 
  my_close(info->dfile,MYF(MY_WME));
 
1543
  VOID(my_close(info->dfile,MYF(MY_WME)));
1527
1544
  param->out_flag|=O_NEW_DATA;                  /* Data in new file */
1528
1545
  info->dfile=new_file;                         /* Use new datafile */
1529
1546
  info->state->del=0;
1537
1554
 
1538
1555
  if (param->testflag & T_WRITE_LOOP)
1539
1556
  {
1540
 
    fputs("          \r",stdout); fflush(stdout);
 
1557
    VOID(fputs("          \r",stdout)); VOID(fflush(stdout));
1541
1558
  }
1542
1559
  got_error=0;
1543
1560
 
1544
1561
err:
1545
1562
  if (got_error && new_file >= 0)
1546
1563
  {
1547
 
    end_io_cache(&info->rec_cache);
 
1564
    VOID(end_io_cache(&info->rec_cache));
1548
1565
    (void) my_close(new_file,MYF(MY_WME));
1549
1566
    (void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
1550
1567
                          MYF(MY_WME));
1551
1568
  }
1552
1569
  if (temp_buff)
1553
1570
  {
1554
 
    my_afree((unsigned char*) temp_buff);
 
1571
    my_afree((uchar*) temp_buff);
1555
1572
  }
1556
 
  void * rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
1557
 
  if (rec_buff_ptr != NULL)
1558
 
    free(rec_buff_ptr);
1559
 
 
 
1573
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1574
          MYF(MY_ALLOW_ZERO_PTR));
1560
1575
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1561
 
  end_io_cache(&info->rec_cache);
1562
 
  free(sort_info.buff);
 
1576
  VOID(end_io_cache(&info->rec_cache));
 
1577
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1563
1578
  sort_info.buff=0;
1564
1579
  share->state.sortkey=sort_key;
1565
1580
  return(flush_blocks(param, share->key_cache, share->kfile) |
1571
1586
 
1572
1587
static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
1573
1588
                             MI_KEYDEF *keyinfo,
1574
 
                             my_off_t page, unsigned char *buff, uint32_t sort_key,
1575
 
                             File new_file,bool update_index)
 
1589
                             my_off_t page, uchar *buff, uint sort_key,
 
1590
                             File new_file,my_bool update_index)
1576
1591
{
1577
1592
  uint  nod_flag,used_length,key_length;
1578
 
  unsigned char *temp_buff,*keypos,*endpos;
 
1593
  uchar *temp_buff,*keypos,*endpos;
1579
1594
  my_off_t next_page,rec_pos;
1580
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
1595
  uchar lastkey[MI_MAX_KEY_BUFF];
1581
1596
  char llbuff[22];
1582
1597
  SORT_INFO *sort_info= sort_param->sort_info;
1583
1598
  MI_CHECK *param=sort_info->param;
1587
1602
 
1588
1603
  if (nod_flag)
1589
1604
  {
1590
 
    if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1605
    if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1591
1606
    {
1592
1607
      mi_check_print_error(param,"Not Enough memory");
1593
1608
      return(-1);
1601
1616
    if (nod_flag)
1602
1617
    {
1603
1618
      next_page=_mi_kpos(nod_flag,keypos);
1604
 
      if (my_pread(info->s->kfile,(unsigned char*) temp_buff,
 
1619
      if (my_pread(info->s->kfile,(uchar*) temp_buff,
1605
1620
                  (uint) keyinfo->block_length, next_page,
1606
1621
                   MYF(MY_NABP+MY_WME)))
1607
1622
      {
1639
1654
      goto err;
1640
1655
  }
1641
1656
  /* Clear end of block to get better compression if the table is backuped */
1642
 
  memset(buff+used_length, 0, keyinfo->block_length-used_length);
1643
 
  if (my_pwrite(info->s->kfile,(unsigned char*) buff,(uint) keyinfo->block_length,
 
1657
  bzero((uchar*) buff+used_length,keyinfo->block_length-used_length);
 
1658
  if (my_pwrite(info->s->kfile,(uchar*) buff,(uint) keyinfo->block_length,
1644
1659
                page,param->myf_rw))
1645
1660
  {
1646
1661
    mi_check_print_error(param,"%d when updating keyblock",my_errno);
1647
1662
    goto err;
1648
1663
  }
1649
1664
  if (temp_buff)
1650
 
    my_afree((unsigned char*) temp_buff);
 
1665
    my_afree((uchar*) temp_buff);
1651
1666
  return(0);
1652
1667
err:
1653
1668
  if (temp_buff)
1654
 
    my_afree((unsigned char*) temp_buff);
 
1669
    my_afree((uchar*) temp_buff);
1655
1670
  return(1);
1656
1671
} /* sort_record_index */
1657
1672
 
1679
1694
  va_list args;
1680
1695
 
1681
1696
  va_start(args,fmt);
1682
 
  vfprintf(stdout, fmt, args);
1683
 
  fputc('\n',stdout);
 
1697
  VOID(vfprintf(stdout, fmt, args));
 
1698
  VOID(fputc('\n',stdout));
1684
1699
  va_end(args);
1685
1700
}
1686
1701
 
1701
1716
  param->warning_printed=1;
1702
1717
  va_start(args,fmt);
1703
1718
  fprintf(stderr,"%s: warning: ",my_progname_short);
1704
 
  vfprintf(stderr, fmt, args);
1705
 
  fputc('\n',stderr);
 
1719
  VOID(vfprintf(stderr, fmt, args));
 
1720
  VOID(fputc('\n',stderr));
1706
1721
  fflush(stderr);
1707
1722
  va_end(args);
1708
1723
  return;
1724
1739
  param->error_printed|=1;
1725
1740
  va_start(args,fmt);
1726
1741
  fprintf(stderr,"%s: error: ",my_progname_short);
1727
 
  vfprintf(stderr, fmt, args);
1728
 
  fputc('\n',stderr);
 
1742
  VOID(vfprintf(stderr, fmt, args));
 
1743
  VOID(fputc('\n',stderr));
1729
1744
  fflush(stderr);
1730
1745
  va_end(args);
1731
1746
  return;