~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/myisamchk.c

  • Committer: Monty Taylor
  • Date: 2008-07-15 21:40:58 UTC
  • mfrom: (77.1.113 codestyle32)
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: mordred@camelot-20080715214058-rm3phulldos9xehv
Merged from codestyle.

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
 
#include <drizzled/util/test.h>
 
32
SET_STACK_SIZE(9000)                    /* Minimum stack size for program */
 
33
 
 
34
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
 
35
#define my_raid_delete(A,B,C) my_delete(A,B)
33
36
 
34
37
#include "myisamdef.h"
35
38
 
36
 
static uint32_t decode_bits;
 
39
static uint decode_bits;
37
40
static char **default_argv;
38
41
static const char *load_default_groups[]= { "myisamchk", 0 };
39
42
static const char *set_collation_name, *opt_tmpdir;
40
 
static const CHARSET_INFO *set_collation;
 
43
static CHARSET_INFO *set_collation;
41
44
static long opt_myisam_block_size;
42
45
static long opt_key_cache_block_size;
43
46
static const char *my_progname_short;
69
72
static int myisamchk(MI_CHECK *param, char *filename);
70
73
static void descript(MI_CHECK *param, register MI_INFO *info, char * name);
71
74
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);
 
75
                           char * name, uint sort_key,
 
76
                           my_bool write_info, my_bool update_index);
74
77
static int sort_record_index(MI_SORT_PARAM *sort_param, MI_INFO *info,
75
78
                             MI_KEYDEF *keyinfo,
76
 
                             my_off_t page,unsigned char *buff,uint32_t sortkey,
77
 
                             File new_file, bool update_index);
 
79
                             my_off_t page,uchar *buff,uint sortkey,
 
80
                             File new_file, my_bool update_index);
78
81
 
79
82
MI_CHECK check_param;
80
83
 
97
100
    int new_error=myisamchk(&check_param, *(argv++));
98
101
    if ((check_param.testflag & T_REP_ANY) != T_REP)
99
102
      check_param.testflag&= ~T_REP;
100
 
    fflush(stdout);
101
 
    fflush(stderr);
 
103
    VOID(fflush(stdout));
 
104
    VOID(fflush(stderr));
102
105
    if ((check_param.error_printed | check_param.warning_printed) &&
103
106
        (check_param.testflag & T_FORCE_CREATE) &&
104
107
        (!(check_param.testflag & (T_REP | T_REP_BY_SORT | T_SORT_RECORDS |
105
108
                                   T_SORT_INDEX))))
106
109
    {
107
 
      uint32_t old_testflag=check_param.testflag;
 
110
      uint old_testflag=check_param.testflag;
108
111
      if (!(check_param.testflag & T_REP))
109
112
        check_param.testflag|= T_REP_BY_SORT;
110
113
      check_param.testflag&= ~T_EXTEND;                 /* Don't needed  */
111
114
      error|=myisamchk(&check_param, argv[-1]);
112
115
      check_param.testflag= old_testflag;
113
 
      fflush(stdout);
114
 
      fflush(stderr);
 
116
      VOID(fflush(stdout));
 
117
      VOID(fflush(stderr));
115
118
    }
116
119
    else
117
120
      error|=new_error;
118
121
    if (argc && (!(check_param.testflag & T_SILENT) || check_param.testflag & T_INFO))
119
122
    {
120
123
      puts("\n---------\n");
121
 
      fflush(stdout);
 
124
      VOID(fflush(stdout));
122
125
    }
123
126
  }
124
127
  if (check_param.total_files > 1)
152
155
  {"analyze", 'a',
153
156
   "Analyze distribution of keys. Will make some joins in MySQL faster. You can check the calculated distribution.",
154
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
155
162
  {"block-search", 'b',
156
163
   "No help available.",
157
164
   0, 0, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
170
177
  {"correct-checksum", OPT_CORRECT_CHECKSUM,
171
178
   "Correct checksum information for table.",
172
179
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
180
#ifndef DBUG_OFF
 
181
  {"debug", '#',
 
182
   "Output debug log. Often this is 'd:t:o,filename'.",
 
183
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
184
#endif
173
185
  {"description", 'd',
174
186
   "Prints some information about table.",
175
187
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
275
287
  { "key_buffer_size", OPT_KEY_BUFFER_SIZE, "",
276
288
    (char**) &check_param.use_buffers, (char**) &check_param.use_buffers, 0,
277
289
    GET_ULONG, REQUIRED_ARG, (long) USE_BUFFER_INIT, (long) MALLOC_OVERHEAD,
278
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
 
290
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) IO_SIZE, 0},
279
291
  { "key_cache_block_size", OPT_KEY_CACHE_BLOCK_SIZE,  "",
280
292
    (char**) &opt_key_cache_block_size,
281
293
    (char**) &opt_key_cache_block_size, 0,
289
301
    (char**) &check_param.read_buffer_length,
290
302
    (char**) &check_param.read_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
291
303
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
292
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
304
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
293
305
  { "write_buffer_size", OPT_WRITE_BUFFER_SIZE, "",
294
306
    (char**) &check_param.write_buffer_length,
295
307
    (char**) &check_param.write_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
296
308
    (long) READ_BUFFER_INIT, (long) MALLOC_OVERHEAD,
297
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
309
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
298
310
  { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
299
311
    (char**) &check_param.sort_buffer_length,
300
312
    (char**) &check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG,
301
313
    (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
302
 
    INT32_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
 
314
    (long) ~0L, (long) MALLOC_OVERHEAD, (long) 1L, 0},
303
315
  { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
304
316
    (char**) &check_param.sort_key_blocks,
305
317
    (char**) &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
316
328
};
317
329
 
318
330
 
 
331
#include <help_start.h>
 
332
 
319
333
static void print_version(void)
320
334
{
321
335
  printf("%s  Ver 2.7 for %s at %s\n", my_progname, SYSTEM_TYPE,
332
346
  puts("Used without options all tables on the command will be checked for errors");
333
347
  printf("Usage: %s [OPTIONS] tables[.MYI]\n", my_progname_short);
334
348
  printf("\nGlobal options:\n");
 
349
#ifndef DBUG_OFF
 
350
  printf("\
 
351
  -#, --debug=...     Output debug log. Often this is 'd:t:o,filename'.\n");
 
352
#endif
335
353
  printf("\
336
354
  -?, --help          Display this help and exit.\n\
337
355
  -O, --set-variable var=option.\n\
340
358
                      directly with '--variable-name=value'.\n\
341
359
  -t, --tmpdir=path   Path for temporary files. Multiple paths can be\n\
342
360
                      specified, separated by ");
343
 
#if defined( __WIN__)
 
361
#if defined( __WIN__) || defined(__NETWARE__)
344
362
   printf("semicolon (;)");
345
363
#else
346
364
   printf("colon (:)");
436
454
  my_print_variables(my_long_options);
437
455
}
438
456
 
 
457
#include <help_end.h>
 
458
 
439
459
const char *myisam_stats_method_names[] = {"nulls_unequal", "nulls_equal",
440
 
                                           "nulls_ignored", NULL};
 
460
                                           "nulls_ignored", NullS};
441
461
TYPELIB myisam_stats_method_typelib= {
442
462
  array_elements(myisam_stats_method_names) - 1, "",
443
463
  myisam_stats_method_names, NULL};
637
657
    else
638
658
      check_param.testflag|= T_UPDATE_STATE;
639
659
    break;
 
660
  case '#':
 
661
    if (argument == disabled_my_option)
 
662
    {
 
663
      DBUG_POP();
 
664
    }
 
665
    else
 
666
    {
 
667
      DBUG_PUSH(argument ? argument : "d:t:o,/tmp/myisamchk.trace");
 
668
    }
 
669
    break;
640
670
  case 'V':
641
671
    print_version();
642
672
    exit(0);
713
743
  if ((check_param.testflag & T_UNPACK) &&
714
744
      (check_param.testflag & (T_QUICK | T_SORT_RECORDS)))
715
745
  {
716
 
    fprintf(stderr,
717
 
            "%s: --unpack can't be used with --quick or --sort-records\n",
718
 
            my_progname_short);
 
746
    VOID(fprintf(stderr,
 
747
                 "%s: --unpack can't be used with --quick or --sort-records\n",
 
748
                 my_progname_short));
719
749
    exit(1);
720
750
  }
721
751
  if ((check_param.testflag & T_READONLY) &&
723
753
       (T_REP_ANY | T_STATISTICS | T_AUTO_INC |
724
754
        T_SORT_RECORDS | T_SORT_INDEX | T_FORCE_CREATE)))
725
755
  {
726
 
    fprintf(stderr,
727
 
            "%s: Can't use --readonly when repairing or sorting\n",
728
 
            my_progname_short);
 
756
    VOID(fprintf(stderr,
 
757
                 "%s: Can't use --readonly when repairing or sorting\n",
 
758
                 my_progname_short));
729
759
    exit(1);
730
760
  }
731
761
 
751
781
{
752
782
  int error,lock_type,recreate;
753
783
  int rep_quick= param->testflag & (T_QUICK | T_FORCE_UNIQUENESS);
754
 
  uint32_t raid_chunks;
 
784
  uint raid_chunks;
755
785
  MI_INFO *info;
756
786
  File datafile;
757
787
  char llbuff[22],llbuff2[22];
758
 
  bool state_updated=0;
 
788
  my_bool state_updated=0;
759
789
  MYISAM_SHARE *share;
 
790
  DBUG_ENTER("myisamchk");
760
791
 
761
792
  param->out_flag=error=param->warning_printed=param->error_printed=
762
793
    recreate=0;
806
837
                  my_errno,filename);
807
838
      break;
808
839
    }
809
 
    return(1);
 
840
    DBUG_RETURN(1);
810
841
  }
811
842
  share=info->s;
812
843
  share->options&= ~HA_OPTION_READ_ONLY_DATA; /* We are modifing it */
821
852
  */
822
853
  if (param->testflag & (T_FAST | T_CHECK_ONLY_CHANGED))
823
854
  {
824
 
    bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
 
855
    my_bool need_to_check= mi_is_crashed(info) || share->state.open_count != 0;
825
856
 
826
857
    if ((param->testflag & (T_REP_ANY | T_SORT_RECORDS)) &&
827
858
        ((share->state.changed & (STATE_CHANGED | STATE_CRASHED |
853
884
      {
854
885
        mi_check_print_error(param,"%d when closing MyISAM-table '%s'",
855
886
                             my_errno,filename);
856
 
        return(1);
 
887
        DBUG_RETURN(1);
857
888
      }
858
 
      return(0);
 
889
      DBUG_RETURN(0);
859
890
    }
860
891
  }
861
892
  if ((param->testflag & (T_REP_ANY | T_STATISTICS |
878
909
      param->language= set_collation->number;
879
910
    if (recreate_table(param, &info,filename))
880
911
    {
881
 
      fprintf(stderr,
882
 
              "MyISAM-table '%s' is not fixed because of errors\n",
883
 
              filename);
 
912
      VOID(fprintf(stderr,
 
913
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
914
              filename));
884
915
      return(-1);
885
916
    }
886
917
    recreate=1;
971
1002
      }
972
1003
      if (!error && param->testflag & T_SORT_RECORDS)
973
1004
      {
974
 
        uint32_t key;
 
1005
        uint key;
975
1006
        /*
976
1007
          We can't update the index in mi_sort_records if we have a
977
1008
          prefix compressed or fulltext index
978
1009
        */
979
 
        bool update_index=1;
 
1010
        my_bool update_index=1;
980
1011
        for (key=0 ; key < share->base.keys; key++)
981
 
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY))
 
1012
          if (share->keyinfo[key].flag & (HA_BINARY_PACK_KEY|HA_FULLTEXT))
982
1013
            update_index=0;
983
1014
 
984
1015
        error=mi_sort_records(param,info,filename,param->opt_sort_key,
985
1016
                           /* what is the following parameter for ? */
986
 
                              (bool) !(param->testflag & T_REP),
 
1017
                              (my_bool) !(param->testflag & T_REP),
987
1018
                              update_index);
988
1019
        datafile=info->dfile;   /* This is now locked */
989
1020
        if (!error && !update_index)
1029
1060
          !(param->testflag & (T_FAST | T_FORCE_CREATE)))
1030
1061
      {
1031
1062
        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));
 
1063
          VOID(init_key_cache(dflt_key_cache,opt_key_cache_block_size,
 
1064
                              param->use_buffers, 0, 0));
 
1065
        VOID(init_io_cache(&param->read_cache,datafile,
 
1066
                           (uint) param->read_buffer_length,
 
1067
                           READ_CACHE,
 
1068
                           (param->start_check_pos ?
 
1069
                            param->start_check_pos :
 
1070
                            share->pack.header_length),
 
1071
                           1,
 
1072
                           MYF(MY_WME)));
1042
1073
        lock_memory(param);
1043
1074
        if ((info->s->options & (HA_OPTION_PACK_RECORD |
1044
1075
                                 HA_OPTION_COMPRESS_RECORD)) ||
1045
1076
            (param->testflag & (T_EXTEND | T_MEDIUM)))
1046
1077
          error|=chk_data_link(param, info, param->testflag & T_EXTEND);
1047
1078
        error|=flush_blocks(param, share->key_cache, share->kfile);
1048
 
        end_io_cache(&param->read_cache);
 
1079
        VOID(end_io_cache(&param->read_cache));
1049
1080
      }
1050
1081
      if (!error)
1051
1082
      {
1066
1097
  if ((param->testflag & T_AUTO_INC) ||
1067
1098
      ((param->testflag & T_REP_ANY) && info->s->base.auto_key))
1068
1099
    update_auto_increment_key(param, info,
1069
 
                              (bool) !test(param->testflag & T_AUTO_INC));
 
1100
                              (my_bool) !test(param->testflag & T_AUTO_INC));
1070
1101
 
1071
1102
  if (!(param->testflag & T_DESCRIPT))
1072
1103
  {
1085
1116
  if (mi_close(info))
1086
1117
  {
1087
1118
    mi_check_print_error(param,"%d when closing MyISAM-table '%s'",my_errno,filename);
1088
 
    return(1);
 
1119
    DBUG_RETURN(1);
1089
1120
  }
1090
1121
  if (error == 0)
1091
1122
  {
1098
1129
      error|=change_to_newfile(filename,MI_NAME_IEXT,INDEX_TMP_EXT,0,
1099
1130
                               MYF(0));
1100
1131
  }
1101
 
  fflush(stdout); fflush(stderr);
 
1132
  VOID(fflush(stdout)); VOID(fflush(stderr));
1102
1133
  if (param->error_printed)
1103
1134
  {
1104
1135
    if (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX))
1105
1136
    {
1106
 
      fprintf(stderr,
1107
 
              "MyISAM-table '%s' is not fixed because of errors\n",
1108
 
              filename);
 
1137
      VOID(fprintf(stderr,
 
1138
                   "MyISAM-table '%s' is not fixed because of errors\n",
 
1139
                   filename));
1109
1140
      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");
 
1141
        VOID(fprintf(stderr,
 
1142
                     "Try fixing it by using the --safe-recover (-o), the --force (-f) option or by not using the --quick (-q) flag\n"));
1112
1143
    }
1113
1144
    else if (!(param->error_printed & 2) &&
1114
1145
             !(param->testflag & T_FORCE_CREATE))
1115
 
      fprintf(stderr,
1116
 
              "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
1117
 
              filename);
 
1146
      VOID(fprintf(stderr,
 
1147
      "MyISAM-table '%s' is corrupted\nFix it using switch \"-r\" or \"-o\"\n",
 
1148
              filename));
1118
1149
  }
1119
1150
  else if (param->warning_printed &&
1120
1151
           ! (param->testflag & (T_REP_ANY | T_SORT_RECORDS | T_SORT_INDEX |
1121
1152
                          T_FORCE_CREATE)))
1122
 
    fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
1123
 
            filename);
1124
 
  fflush(stderr);
1125
 
  return(error);
 
1153
    VOID(fprintf(stderr, "MyISAM-table '%s' is usable but should be fixed\n",
 
1154
                 filename));
 
1155
  VOID(fflush(stderr));
 
1156
  DBUG_RETURN(error);
1126
1157
} /* myisamchk */
1127
1158
 
1128
1159
 
1130
1161
 
1131
1162
static void descript(MI_CHECK *param, register MI_INFO *info, char * name)
1132
1163
{
1133
 
  uint32_t key,keyseg_nr,field,start;
 
1164
  uint key,keyseg_nr,field,start;
1134
1165
  register MI_KEYDEF *keyinfo;
1135
1166
  register HA_KEYSEG *keyseg;
1136
1167
  register const char *text;
1138
1169
  enum en_fieldtype type;
1139
1170
  MYISAM_SHARE *share=info->s;
1140
1171
  char llbuff[22],llbuff2[22];
 
1172
  DBUG_ENTER("describe");
1141
1173
 
1142
1174
  printf("\nMyISAM file:         %s\n",name);
1143
1175
  fputs("Record format:       ",stdout);
1167
1199
    }
1168
1200
    pos=buff;
1169
1201
    if (share->state.changed & STATE_CRASHED)
1170
 
      my_stpcpy(buff,"crashed");
 
1202
      strmov(buff,"crashed");
1171
1203
    else
1172
1204
    {
1173
1205
      if (share->state.open_count)
1174
 
        pos=my_stpcpy(pos,"open,");
 
1206
        pos=strmov(pos,"open,");
1175
1207
      if (share->state.changed & STATE_CHANGED)
1176
 
        pos=my_stpcpy(pos,"changed,");
 
1208
        pos=strmov(pos,"changed,");
1177
1209
      else
1178
 
        pos=my_stpcpy(pos,"checked,");
 
1210
        pos=strmov(pos,"checked,");
1179
1211
      if (!(share->state.changed & STATE_NOT_ANALYZED))
1180
 
        pos=my_stpcpy(pos,"analyzed,");
 
1212
        pos=strmov(pos,"analyzed,");
1181
1213
      if (!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))
1182
 
        pos=my_stpcpy(pos,"optimized keys,");
 
1214
        pos=strmov(pos,"optimized keys,");
1183
1215
      if (!(share->state.changed & STATE_NOT_SORTED_PAGES))
1184
 
        pos=my_stpcpy(pos,"sorted index pages,");
 
1216
        pos=strmov(pos,"sorted index pages,");
1185
1217
      pos[-1]=0;                                /* Remove extra ',' */
1186
1218
    }      
1187
1219
    printf("Status:              %s\n",buff);
1191
1223
             share->base.auto_key,
1192
1224
             llstr(share->state.auto_increment,llbuff));
1193
1225
    }
 
1226
    if (share->base.raid_type)
 
1227
    {
 
1228
      printf("RAID:                Type:  %u   Chunks: %u  Chunksize: %lu\n",
 
1229
             share->base.raid_type,
 
1230
             share->base.raid_chunks,
 
1231
             share->base.raid_chunksize);
 
1232
    }
1194
1233
    if (share->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD))
1195
1234
      printf("Checksum:  %23s\n",llstr(info->state->checksum,llbuff));
1196
1235
;
1201
1240
  printf("Data records:        %13s  Deleted blocks:     %13s\n",
1202
1241
         llstr(info->state->records,llbuff),llstr(info->state->del,llbuff2));
1203
1242
  if (param->testflag & T_SILENT)
1204
 
    return;                             /* This is enough */
 
1243
    DBUG_VOID_RETURN;                           /* This is enough */
1205
1244
 
1206
1245
  if (param->testflag & T_VERBOSE)
1207
1246
  {
1240
1279
  printf("Key Start Len Index   Type");
1241
1280
  if (param->testflag & T_VERBOSE)
1242
1281
    printf("                     Rec/key         Root  Blocksize");
1243
 
  putchar('\n');
 
1282
  VOID(putchar('\n'));
1244
1283
 
1245
1284
  for (key=keyseg_nr=0, keyinfo= &share->keyinfo[0] ;
1246
1285
       key < share->base.keys;
1248
1287
  {
1249
1288
    keyseg=keyinfo->seg;
1250
1289
    if (keyinfo->flag & HA_NOSAME) text="unique ";
 
1290
    else if (keyinfo->flag & HA_FULLTEXT) text="fulltext ";
1251
1291
    else text="multip.";
1252
1292
 
1253
1293
    pos=buff;
1254
1294
    if (keyseg->flag & HA_REVERSE_SORT)
1255
1295
      *pos++ = '-';
1256
 
    pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1296
    pos=strmov(pos,type_names[keyseg->type]);
1257
1297
    *pos++ = ' ';
1258
1298
    *pos=0;
1259
1299
    if (keyinfo->flag & HA_PACK_KEY)
1260
 
      pos=my_stpcpy(pos,prefix_packed_txt);
 
1300
      pos=strmov(pos,prefix_packed_txt);
1261
1301
    if (keyinfo->flag & HA_BINARY_PACK_KEY)
1262
 
      pos=my_stpcpy(pos,bin_packed_txt);
 
1302
      pos=strmov(pos,bin_packed_txt);
1263
1303
    if (keyseg->flag & HA_SPACE_PACK)
1264
 
      pos=my_stpcpy(pos,diff_txt);
 
1304
      pos=strmov(pos,diff_txt);
1265
1305
    if (keyseg->flag & HA_BLOB_PART)
1266
 
      pos=my_stpcpy(pos,blob_txt);
 
1306
      pos=strmov(pos,blob_txt);
1267
1307
    if (keyseg->flag & HA_NULL_PART)
1268
 
      pos=my_stpcpy(pos,null_txt);
 
1308
      pos=strmov(pos,null_txt);
1269
1309
    *pos=0;
1270
1310
 
1271
1311
    printf("%-4d%-6ld%-3d %-8s%-21s",
1278
1318
      printf("%11lu %12s %10d",
1279
1319
             share->state.rec_per_key_part[keyseg_nr++],
1280
1320
             buff,keyinfo->block_length);
1281
 
    putchar('\n');
 
1321
    VOID(putchar('\n'));
1282
1322
    while ((++keyseg)->type != HA_KEYTYPE_END)
1283
1323
    {
1284
1324
      pos=buff;
1285
1325
      if (keyseg->flag & HA_REVERSE_SORT)
1286
1326
        *pos++ = '-';
1287
 
      pos=my_stpcpy(pos,type_names[keyseg->type]);
 
1327
      pos=strmov(pos,type_names[keyseg->type]);
1288
1328
      *pos++= ' ';
1289
1329
      if (keyseg->flag & HA_SPACE_PACK)
1290
 
        pos=my_stpcpy(pos,diff_txt);
 
1330
        pos=strmov(pos,diff_txt);
1291
1331
      if (keyseg->flag & HA_BLOB_PART)
1292
 
        pos=my_stpcpy(pos,blob_txt);
 
1332
        pos=strmov(pos,blob_txt);
1293
1333
      if (keyseg->flag & HA_NULL_PART)
1294
 
        pos=my_stpcpy(pos,null_txt);
 
1334
        pos=strmov(pos,null_txt);
1295
1335
      *pos=0;
1296
1336
      printf("    %-6ld%-3d         %-21s",
1297
1337
             (long) keyseg->start+1,keyseg->length,buff);
1298
1338
      if (param->testflag & T_VERBOSE)
1299
1339
        printf("%11lu", share->state.rec_per_key_part[keyseg_nr++]);
1300
 
      putchar('\n');
 
1340
      VOID(putchar('\n'));
1301
1341
    }
1302
1342
    keyseg++;
1303
1343
  }
1308
1348
    for (key=0,uniqueinfo= &share->uniqueinfo[0] ;
1309
1349
         key < share->state.header.uniques; key++, uniqueinfo++)
1310
1350
    {
1311
 
      bool new_row=0;
 
1351
      my_bool new_row=0;
1312
1352
      char null_bit[8],null_pos[8];
1313
1353
      printf("%-8d%-5d",key+1,uniqueinfo->key+1);
1314
1354
      for (keyseg=uniqueinfo->seg ; keyseg->type != HA_KEYTYPE_END ; keyseg++)
1335
1375
    printf("\nField Start Length Nullpos Nullbit Type");
1336
1376
    if (share->options & HA_OPTION_COMPRESS_RECORD)
1337
1377
      printf("                         Huff tree  Bits");
1338
 
    putchar('\n');
 
1378
    VOID(putchar('\n'));
1339
1379
    start=1;
1340
1380
    for (field=0 ; field < share->base.fields ; field++)
1341
1381
    {
1343
1383
        type=share->rec[field].base_type;
1344
1384
      else
1345
1385
        type=(enum en_fieldtype) share->rec[field].type;
1346
 
      end=my_stpcpy(buff,field_pack[type]);
 
1386
      end=strmov(buff,field_pack[type]);
1347
1387
      if (share->options & HA_OPTION_COMPRESS_RECORD)
1348
1388
      {
1349
1389
        if (share->rec[field].pack_type & PACK_TYPE_SELECTED)
1350
 
          end=my_stpcpy(end,", not_always");
 
1390
          end=strmov(end,", not_always");
1351
1391
        if (share->rec[field].pack_type & PACK_TYPE_SPACE_FIELDS)
1352
 
          end=my_stpcpy(end,", no empty");
 
1392
          end=strmov(end,", no empty");
1353
1393
        if (share->rec[field].pack_type & PACK_TYPE_ZERO_FILL)
1354
1394
        {
1355
1395
          sprintf(end,", zerofill(%d)",share->rec[field].space_length_bits);
1356
 
          end= strchr(end, '\0');
 
1396
          end=strend(end);
1357
1397
        }
1358
1398
      }
1359
1399
      if (buff[0] == ',')
1360
 
        my_stpcpy(buff,buff+2);
 
1400
        strmov(buff,buff+2);
1361
1401
      int10_to_str((long) share->rec[field].length,length,10);
1362
1402
      null_bit[0]=null_pos[0]=0;
1363
1403
      if (share->rec[field].null_bit)
1374
1414
                 (uint) (share->rec[field].huff_tree-share->decode_trees)+1,
1375
1415
                 share->rec[field].huff_tree->quick_table_bits);
1376
1416
      }
1377
 
      putchar('\n');
 
1417
      VOID(putchar('\n'));
1378
1418
      start+=share->rec[field].length;
1379
1419
    }
1380
1420
  }
1381
 
  return;
 
1421
  DBUG_VOID_RETURN;
1382
1422
} /* describe */
1383
1423
 
1384
1424
 
1386
1426
 
1387
1427
static int mi_sort_records(MI_CHECK *param,
1388
1428
                           register MI_INFO *info, char * name,
1389
 
                           uint32_t sort_key,
1390
 
                           bool write_info,
1391
 
                           bool update_index)
 
1429
                           uint sort_key,
 
1430
                           my_bool write_info,
 
1431
                           my_bool update_index)
1392
1432
{
1393
1433
  int got_error;
1394
 
  uint32_t key;
 
1434
  uint key;
1395
1435
  MI_KEYDEF *keyinfo;
1396
1436
  File new_file;
1397
 
  unsigned char *temp_buff;
 
1437
  uchar *temp_buff;
1398
1438
  ha_rows old_record_count;
1399
1439
  MYISAM_SHARE *share=info->s;
1400
1440
  char llbuff[22],llbuff2[22];
1401
1441
  SORT_INFO sort_info;
1402
1442
  MI_SORT_PARAM sort_param;
 
1443
  DBUG_ENTER("sort_records");
1403
1444
 
1404
 
  memset(&sort_info, 0, sizeof(sort_info));
1405
 
  memset(&sort_param, 0, sizeof(sort_param));
 
1445
  bzero((char*)&sort_info,sizeof(sort_info));
 
1446
  bzero((char*)&sort_param,sizeof(sort_param));
1406
1447
  sort_param.sort_info=&sort_info;
1407
1448
  sort_info.param=param;
1408
1449
  keyinfo= &share->keyinfo[sort_key];
1416
1457
                           "Can't sort table '%s' on key %d;  No such key",
1417
1458
                name,sort_key+1);
1418
1459
    param->error_printed=0;
1419
 
    return(0);                          /* Nothing to do */
 
1460
    DBUG_RETURN(0);                             /* Nothing to do */
 
1461
  }
 
1462
  if (keyinfo->flag & HA_FULLTEXT)
 
1463
  {
 
1464
    mi_check_print_warning(param,"Can't sort table '%s' on FULLTEXT key %d",
 
1465
                           name,sort_key+1);
 
1466
    param->error_printed=0;
 
1467
    DBUG_RETURN(0);                             /* Nothing to do */
1420
1468
  }
1421
1469
  if (share->data_file_type == COMPRESSED_RECORD)
1422
1470
  {
1423
1471
    mi_check_print_warning(param,"Can't sort read-only table '%s'", name);
1424
1472
    param->error_printed=0;
1425
 
    return(0);                          /* Nothing to do */
 
1473
    DBUG_RETURN(0);                             /* Nothing to do */
1426
1474
  }
1427
1475
  if (!(param->testflag & T_SILENT))
1428
1476
  {
1433
1481
             llstr(info->state->del,llbuff2));
1434
1482
  }
1435
1483
  if (share->state.key_root[sort_key] == HA_OFFSET_ERROR)
1436
 
    return(0);                          /* Nothing to do */
 
1484
    DBUG_RETURN(0);                             /* Nothing to do */
1437
1485
 
1438
1486
  init_key_cache(dflt_key_cache, opt_key_cache_block_size, param->use_buffers,
1439
1487
                 0, 0);
1443
1491
    goto err;
1444
1492
  info->opt_flag|=WRITE_CACHE_USED;
1445
1493
 
1446
 
  if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1494
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1447
1495
  {
1448
1496
    mi_check_print_error(param,"Not enough memory for key block");
1449
1497
    goto err;
1455
1503
    goto err;
1456
1504
  }
1457
1505
  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));
 
1506
  new_file=my_raid_create(fn_format(param->temp_filename,
 
1507
                                    param->temp_filename,"",
 
1508
                                    DATA_TMP_EXT,2+4),
 
1509
                          0,param->tmpfile_createflag,
 
1510
                          share->base.raid_type,
 
1511
                          share->base.raid_chunks,
 
1512
                          share->base.raid_chunksize,
 
1513
                          MYF(0));
1463
1514
  if (new_file < 0)
1464
1515
  {
1465
1516
    mi_check_print_error(param,"Can't create new tempfile: '%s'",
1476
1527
  for (key=0 ; key < share->base.keys ; key++)
1477
1528
    share->keyinfo[key].flag|= HA_SORT_ALLOWS_SAME;
1478
1529
 
1479
 
  if (my_pread(share->kfile,(unsigned char*) temp_buff,
 
1530
  if (my_pread(share->kfile,(uchar*) temp_buff,
1480
1531
               (uint) keyinfo->block_length,
1481
1532
               share->state.key_root[sort_key],
1482
1533
               MYF(MY_NABP+MY_WME)))
1511
1562
    goto err;
1512
1563
  }
1513
1564
 
1514
 
  my_close(info->dfile,MYF(MY_WME));
 
1565
  VOID(my_close(info->dfile,MYF(MY_WME)));
1515
1566
  param->out_flag|=O_NEW_DATA;                  /* Data in new file */
1516
1567
  info->dfile=new_file;                         /* Use new datafile */
1517
1568
  info->state->del=0;
1525
1576
 
1526
1577
  if (param->testflag & T_WRITE_LOOP)
1527
1578
  {
1528
 
    fputs("          \r",stdout); fflush(stdout);
 
1579
    VOID(fputs("          \r",stdout)); VOID(fflush(stdout));
1529
1580
  }
1530
1581
  got_error=0;
1531
1582
 
1532
1583
err:
1533
1584
  if (got_error && new_file >= 0)
1534
1585
  {
1535
 
    end_io_cache(&info->rec_cache);
 
1586
    VOID(end_io_cache(&info->rec_cache));
1536
1587
    (void) my_close(new_file,MYF(MY_WME));
1537
 
    (void) my_delete(param->temp_filename, MYF(MY_WME));
 
1588
    (void) my_raid_delete(param->temp_filename, share->base.raid_chunks,
 
1589
                          MYF(MY_WME));
1538
1590
  }
1539
1591
  if (temp_buff)
1540
1592
  {
1541
 
    my_afree((unsigned char*) temp_buff);
 
1593
    my_afree((uchar*) temp_buff);
1542
1594
  }
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
 
 
 
1595
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1596
          MYF(MY_ALLOW_ZERO_PTR));
1547
1597
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1548
 
  end_io_cache(&info->rec_cache);
1549
 
  free(sort_info.buff);
 
1598
  VOID(end_io_cache(&info->rec_cache));
 
1599
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1550
1600
  sort_info.buff=0;
1551
1601
  share->state.sortkey=sort_key;
1552
 
  return(flush_blocks(param, share->key_cache, share->kfile) |
 
1602
  DBUG_RETURN(flush_blocks(param, share->key_cache, share->kfile) |
1553
1603
              got_error);
1554
1604
} /* sort_records */
1555
1605
 
1558
1608
 
1559
1609
static int sort_record_index(MI_SORT_PARAM *sort_param,MI_INFO *info,
1560
1610
                             MI_KEYDEF *keyinfo,
1561
 
                             my_off_t page, unsigned char *buff, uint32_t sort_key,
1562
 
                             File new_file,bool update_index)
 
1611
                             my_off_t page, uchar *buff, uint sort_key,
 
1612
                             File new_file,my_bool update_index)
1563
1613
{
1564
1614
  uint  nod_flag,used_length,key_length;
1565
 
  unsigned char *temp_buff,*keypos,*endpos;
 
1615
  uchar *temp_buff,*keypos,*endpos;
1566
1616
  my_off_t next_page,rec_pos;
1567
 
  unsigned char lastkey[MI_MAX_KEY_BUFF];
 
1617
  uchar lastkey[MI_MAX_KEY_BUFF];
1568
1618
  char llbuff[22];
1569
1619
  SORT_INFO *sort_info= sort_param->sort_info;
1570
1620
  MI_CHECK *param=sort_info->param;
 
1621
  DBUG_ENTER("sort_record_index");
1571
1622
 
1572
1623
  nod_flag=mi_test_if_nod(buff);
1573
1624
  temp_buff=0;
1574
1625
 
1575
1626
  if (nod_flag)
1576
1627
  {
1577
 
    if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1628
    if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1578
1629
    {
1579
1630
      mi_check_print_error(param,"Not Enough memory");
1580
 
      return(-1);
 
1631
      DBUG_RETURN(-1);
1581
1632
    }
1582
1633
  }
1583
1634
  used_length=mi_getint(buff);
1588
1639
    if (nod_flag)
1589
1640
    {
1590
1641
      next_page=_mi_kpos(nod_flag,keypos);
1591
 
      if (my_pread(info->s->kfile,(unsigned char*) temp_buff,
 
1642
      if (my_pread(info->s->kfile,(uchar*) temp_buff,
1592
1643
                  (uint) keyinfo->block_length, next_page,
1593
1644
                   MYF(MY_NABP+MY_WME)))
1594
1645
      {
1626
1677
      goto err;
1627
1678
  }
1628
1679
  /* 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,
 
1680
  bzero((uchar*) buff+used_length,keyinfo->block_length-used_length);
 
1681
  if (my_pwrite(info->s->kfile,(uchar*) buff,(uint) keyinfo->block_length,
1631
1682
                page,param->myf_rw))
1632
1683
  {
1633
1684
    mi_check_print_error(param,"%d when updating keyblock",my_errno);
1634
1685
    goto err;
1635
1686
  }
1636
1687
  if (temp_buff)
1637
 
    my_afree((unsigned char*) temp_buff);
1638
 
  return(0);
 
1688
    my_afree((uchar*) temp_buff);
 
1689
  DBUG_RETURN(0);
1639
1690
err:
1640
1691
  if (temp_buff)
1641
 
    my_afree((unsigned char*) temp_buff);
1642
 
  return(1);
 
1692
    my_afree((uchar*) temp_buff);
 
1693
  DBUG_RETURN(1);
1643
1694
} /* sort_record_index */
1644
1695
 
1645
1696
 
1666
1717
  va_list args;
1667
1718
 
1668
1719
  va_start(args,fmt);
1669
 
  vfprintf(stdout, fmt, args);
1670
 
  fputc('\n',stdout);
 
1720
  VOID(vfprintf(stdout, fmt, args));
 
1721
  VOID(fputc('\n',stdout));
1671
1722
  va_end(args);
1672
1723
}
1673
1724
 
1676
1727
void mi_check_print_warning(MI_CHECK *param, const char *fmt,...)
1677
1728
{
1678
1729
  va_list args;
 
1730
  DBUG_ENTER("mi_check_print_warning");
1679
1731
 
1680
1732
  fflush(stdout);
1681
1733
  if (!param->warning_printed && !param->error_printed)
1688
1740
  param->warning_printed=1;
1689
1741
  va_start(args,fmt);
1690
1742
  fprintf(stderr,"%s: warning: ",my_progname_short);
1691
 
  vfprintf(stderr, fmt, args);
1692
 
  fputc('\n',stderr);
 
1743
  VOID(vfprintf(stderr, fmt, args));
 
1744
  VOID(fputc('\n',stderr));
1693
1745
  fflush(stderr);
1694
1746
  va_end(args);
1695
 
  return;
 
1747
  DBUG_VOID_RETURN;
1696
1748
}
1697
1749
 
1698
1750
/* VARARGS */
1700
1752
void mi_check_print_error(MI_CHECK *param, const char *fmt,...)
1701
1753
{
1702
1754
  va_list args;
 
1755
  DBUG_ENTER("mi_check_print_error");
 
1756
  DBUG_PRINT("enter",("format: %s",fmt));
1703
1757
 
1704
1758
  fflush(stdout);
1705
1759
  if (!param->warning_printed && !param->error_printed)
1711
1765
  param->error_printed|=1;
1712
1766
  va_start(args,fmt);
1713
1767
  fprintf(stderr,"%s: error: ",my_progname_short);
1714
 
  vfprintf(stderr, fmt, args);
1715
 
  fputc('\n',stderr);
 
1768
  VOID(vfprintf(stderr, fmt, args));
 
1769
  VOID(fputc('\n',stderr));
1716
1770
  fflush(stderr);
1717
1771
  va_end(args);
1718
 
  return;
 
1772
  DBUG_VOID_RETURN;
1719
1773
}
1720
1774