~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/myisam/mi_check.c

  • Committer: Monty Taylor
  • Date: 2008-10-05 01:41:06 UTC
  • Revision ID: monty@inaugust.com-20081005014106-bulqe4kp7i6ipts1
Moved qsort declarations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
#ifdef HAVE_SYS_MMAN_H
53
53
#include <sys/mman.h>
54
54
#endif
55
 
#include <drizzled/util/test.h>
56
 
 
57
 
 
58
 
/* Functions defined in this file */
59
 
 
60
 
static int check_k_link(MI_CHECK *param, MI_INFO *info,uint32_t nr);
 
55
 
 
56
#ifndef USE_RAID
 
57
#define my_raid_create(A,B,C,D,E,F,G) my_create(A,B,C,G)
 
58
#define my_raid_delete(A,B,C) my_delete(A,B)
 
59
#endif
 
60
 
 
61
        /* Functions defined in this file */
 
62
 
 
63
static int check_k_link(MI_CHECK *param, MI_INFO *info,uint nr);
61
64
static int chk_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
62
 
                     my_off_t page, unsigned char *buff, ha_rows *keys,
63
 
                     ha_checksum *key_checksum, uint32_t level);
64
 
static uint32_t isam_key_length(MI_INFO *info,MI_KEYDEF *keyinfo);
 
65
                     my_off_t page, uchar *buff, ha_rows *keys,
 
66
                     ha_checksum *key_checksum, uint level);
 
67
static uint isam_key_length(MI_INFO *info,MI_KEYDEF *keyinfo);
65
68
static ha_checksum calc_checksum(ha_rows count);
66
69
static int writekeys(MI_SORT_PARAM *sort_param);
67
70
static int sort_one_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
71
74
static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,const void *b);
72
75
static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a);
73
76
static my_off_t get_record_for_key(MI_INFO *info,MI_KEYDEF *keyinfo,
74
 
                                unsigned char *key);
 
77
                                uchar *key);
75
78
static int sort_insert_key(MI_SORT_PARAM  *sort_param,
76
79
                           register SORT_KEY_BLOCKS *key_block,
77
 
                           unsigned char *key, my_off_t prev_block);
 
80
                           uchar *key, my_off_t prev_block);
78
81
static int sort_delete_record(MI_SORT_PARAM *sort_param);
79
82
/*static int flush_pending_blocks(MI_CHECK *param);*/
80
 
static SORT_KEY_BLOCKS  *alloc_key_blocks(MI_CHECK *param, uint32_t blocks,
81
 
                                          uint32_t buffer_length);
82
 
static ha_checksum mi_byte_checksum(const unsigned char *buf, uint32_t length);
 
83
static SORT_KEY_BLOCKS  *alloc_key_blocks(MI_CHECK *param, uint blocks,
 
84
                                          uint buffer_length);
 
85
static ha_checksum mi_byte_checksum(const uchar *buf, uint length);
83
86
static void set_data_file_type(SORT_INFO *sort_info, MYISAM_SHARE *share);
84
87
 
85
88
void myisamchk_init(MI_CHECK *param)
117
120
  if (share->state.open_count != (uint) (info->s->global_changed ? 1 : 0))
118
121
  {
119
122
    /* Don't count this as a real warning, as check can correct this ! */
120
 
    uint32_t save=param->warning_printed;
 
123
    uint save=param->warning_printed;
121
124
    mi_check_print_warning(param,
122
125
                           share->state.open_count==1 ? 
123
126
                           "%d client is using or hasn't closed the table properly" : 
132
135
 
133
136
        /* Check delete links */
134
137
 
135
 
int chk_del(MI_CHECK *param, register MI_INFO *info, uint32_t test_flag)
 
138
int chk_del(MI_CHECK *param, register MI_INFO *info, uint test_flag)
136
139
{
137
140
  register ha_rows i;
138
 
  uint32_t delete_link_length;
 
141
  uint delete_link_length;
139
142
  my_off_t empty, next_link, old_link= 0;
140
143
  char buff[22],buff2[22];
141
144
 
167
170
        printf(" %9s",llstr(next_link,buff));
168
171
      if (next_link >= info->state->data_file_length)
169
172
        goto wrong;
170
 
      if (my_pread(info->dfile, (unsigned char*) buff,delete_link_length,
 
173
      if (my_pread(info->dfile, (uchar*) buff,delete_link_length,
171
174
                   next_link,MYF(MY_NABP)))
172
175
      {
173
176
        if (test_flag & T_VERBOSE) puts("");
198
201
      else
199
202
      {
200
203
        param->record_checksum+=(ha_checksum) next_link;
201
 
        next_link=_mi_rec_pos(info->s,(unsigned char*) buff+1);
 
204
        next_link=_mi_rec_pos(info->s,(uchar*) buff+1);
202
205
        empty+=info->s->base.pack_reclength;
203
206
      }
204
207
    }
239
242
 
240
243
        /* Check delete links in index file */
241
244
 
242
 
static int check_k_link(MI_CHECK *param, register MI_INFO *info, uint32_t nr)
 
245
static int check_k_link(MI_CHECK *param, register MI_INFO *info, uint nr)
243
246
{
244
247
  my_off_t next_link;
245
 
  uint32_t block_size=(nr+1)*MI_MIN_KEY_BLOCK_LENGTH;
 
248
  uint block_size=(nr+1)*MI_MIN_KEY_BLOCK_LENGTH;
246
249
  ha_rows records;
247
250
  char llbuff[21], llbuff2[21];
248
 
  unsigned char *buff;
 
251
  uchar *buff;
249
252
 
250
253
  if (param->testflag & T_VERBOSE)
251
254
    printf("block_size %4u:", block_size); /* purecov: tested */
289
292
    */
290
293
    if (!(buff=key_cache_read(info->s->key_cache,
291
294
                              info->s->kfile, next_link, DFLT_INIT_HITS,
292
 
                              (unsigned char*) info->buff, MI_MIN_KEY_BLOCK_LENGTH,
 
295
                              (uchar*) info->buff, MI_MIN_KEY_BLOCK_LENGTH,
293
296
                              MI_MIN_KEY_BLOCK_LENGTH, 1)))
294
297
    {
295
298
      /* purecov: begin tested */
392
395
 
393
396
int chk_key(MI_CHECK *param, register MI_INFO *info)
394
397
{
395
 
  uint32_t key,found_keys=0,full_text_keys=0,result=0;
 
398
  uint key,found_keys=0,full_text_keys=0,result=0;
396
399
  ha_rows keys;
397
400
  ha_checksum old_record_checksum,init_checksum;
398
401
  my_off_t all_keydata,all_totaldata,key_totlength,length;
520
523
      /* Check that there isn't a row with auto_increment = 0 in the table */
521
524
      mi_extra(info,HA_EXTRA_KEYREAD,0);
522
525
      memset(info->lastkey, 0, keyinfo->seg->length);
523
 
      if (!mi_rkey(info, info->rec_buff, key, (const unsigned char*) info->lastkey,
 
526
      if (!mi_rkey(info, info->rec_buff, key, (const uchar*) info->lastkey,
524
527
                   (key_part_map)1, HA_READ_KEY_EXACT))
525
528
      {
526
529
        /* Don't count this as a real warning, as myisamchk can't correct it */
527
 
        uint32_t save=param->warning_printed;
 
530
        uint save=param->warning_printed;
528
531
        mi_check_print_warning(param, "Found row where the auto_increment "
529
532
                               "column has the value 0");
530
533
        param->warning_printed=save;
573
576
 
574
577
 
575
578
static int chk_index_down(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
576
 
                     my_off_t page, unsigned char *buff, ha_rows *keys,
577
 
                     ha_checksum *key_checksum, uint32_t level)
 
579
                     my_off_t page, uchar *buff, ha_rows *keys,
 
580
                     ha_checksum *key_checksum, uint level)
578
581
{
579
582
  char llbuff[22],llbuff2[22];
580
583
 
644
647
 
645
648
static
646
649
void mi_collect_stats_nonulls_first(HA_KEYSEG *keyseg, uint64_t *notnull,
647
 
                                    unsigned char *key)
 
650
                                    uchar *key)
648
651
{
649
 
  uint32_t first_null, kp;
 
652
  uint first_null, kp;
650
653
  first_null= ha_find_null(keyseg, key) - keyseg;
651
654
  /*
652
655
    All prefix tuples that don't include keypart_{first_null} are not-null
684
687
 
685
688
static
686
689
int mi_collect_stats_nonulls_next(HA_KEYSEG *keyseg, uint64_t *notnull,
687
 
                                  unsigned char *prev_key, unsigned char *last_key)
 
690
                                  uchar *prev_key, uchar *last_key)
688
691
{
689
 
  uint32_t diffs[2];
690
 
  uint32_t first_null_seg, kp;
 
692
  uint diffs[2];
 
693
  uint first_null_seg, kp;
691
694
  HA_KEYSEG *seg;
692
695
 
693
696
  /* 
719
722
        /* Check if index is ok */
720
723
 
721
724
static int chk_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
722
 
                     my_off_t page, unsigned char *buff, ha_rows *keys,
723
 
                     ha_checksum *key_checksum, uint32_t level)
 
725
                     my_off_t page, uchar *buff, ha_rows *keys,
 
726
                     ha_checksum *key_checksum, uint level)
724
727
{
725
728
  int flag;
726
 
  uint32_t used_length,comp_flag,nod_flag,key_length=0;
727
 
  unsigned char key[HA_MAX_POSSIBLE_KEY_BUFF],*temp_buff,*keypos,*old_keypos,*endpos;
 
729
  uint used_length,comp_flag,nod_flag,key_length=0;
 
730
  uchar key[HA_MAX_POSSIBLE_KEY_BUFF],*temp_buff,*keypos,*old_keypos,*endpos;
728
731
  my_off_t next_page,record;
729
732
  char llbuff[22];
730
 
  uint32_t diff_pos[2];
 
733
  uint diff_pos[2];
731
734
 
732
 
  if (!(temp_buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
735
  if (!(temp_buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
733
736
  {
734
737
    mi_check_print_error(param,"Not enough memory for keyblock");
735
738
    return(-1);
811
814
                                         key);
812
815
      }
813
816
    }
814
 
    (*key_checksum)+= mi_byte_checksum((unsigned char*) key,
 
817
    (*key_checksum)+= mi_byte_checksum((uchar*) key,
815
818
                                       key_length- info->s->rec_reflength);
816
819
    record= _mi_dpos(info,0,key+key_length);
817
820
    if (record >= info->state->data_file_length)
827
830
                llstr(page,llbuff), used_length, (keypos - buff));
828
831
    goto err;
829
832
  }
830
 
  my_afree((unsigned char*) temp_buff);
 
833
  my_afree((uchar*) temp_buff);
831
834
  return(0);
832
835
 err:
833
 
  my_afree((unsigned char*) temp_buff);
 
836
  my_afree((uchar*) temp_buff);
834
837
  return(1);
835
838
} /* chk_index */
836
839
 
859
862
 
860
863
        /* Calc length of key in normal isam */
861
864
 
862
 
static uint32_t isam_key_length(MI_INFO *info, register MI_KEYDEF *keyinfo)
 
865
static uint isam_key_length(MI_INFO *info, register MI_KEYDEF *keyinfo)
863
866
{
864
 
  uint32_t length;
 
867
  uint length;
865
868
  HA_KEYSEG *keyseg;
866
869
 
867
870
  length= info->s->rec_reflength;
881
884
  ha_rows records, del_blocks;
882
885
  my_off_t used, empty, pos, splits, start_recpos= 0,
883
886
           del_length, link_used, start_block;
884
 
  unsigned char *record= NULL, *to= NULL;
 
887
  uchar *record= NULL, *to= NULL;
885
888
  char llbuff[22],llbuff2[22],llbuff3[22];
886
889
  ha_checksum intern_record_checksum;
887
890
  ha_checksum key_checksum[HA_MAX_POSSIBLE_KEY];
931
934
      goto err2;
932
935
    switch (info->s->data_file_type) {
933
936
    case STATIC_RECORD:
934
 
      if (my_b_read(&param->read_cache,(unsigned char*) record,
 
937
      if (my_b_read(&param->read_cache,(uchar*) record,
935
938
                    info->s->base.pack_reclength))
936
939
        goto err;
937
940
      start_recpos=pos;
951
954
      block_info.next_filepos=pos;
952
955
      do
953
956
      {
954
 
        if (_mi_read_cache(&param->read_cache,(unsigned char*) block_info.header,
 
957
        if (_mi_read_cache(&param->read_cache,(uchar*) block_info.header,
955
958
                           (start_block=block_info.next_filepos),
956
959
                           sizeof(block_info.header),
957
960
                           (flag ? 0 : READING_NEXT) | READING_HEADER))
1055
1058
          got_error=1;
1056
1059
          break;
1057
1060
        }
1058
 
        if (_mi_read_cache(&param->read_cache,(unsigned char*) to,block_info.filepos,
 
1061
        if (_mi_read_cache(&param->read_cache,(uchar*) to,block_info.filepos,
1059
1062
                           (uint) block_info.data_len,
1060
1063
                           flag == 1 ? READING_NEXT : 0))
1061
1064
          goto err;
1136
1139
        if (mi_is_key_active(info->s->state.key_map, key))
1137
1140
        {
1138
1141
          {
1139
 
            uint32_t key_length=_mi_make_key(info,key,info->lastkey,record,
 
1142
            uint key_length=_mi_make_key(info,key,info->lastkey,record,
1140
1143
                                         start_recpos);
1141
1144
            if (extend)
1142
1145
            {
1156
1159
              }
1157
1160
            }
1158
1161
            else
1159
 
              key_checksum[key]+=mi_byte_checksum((unsigned char*) info->lastkey,
 
1162
              key_checksum[key]+=mi_byte_checksum((uchar*) info->lastkey,
1160
1163
                                                  key_length);
1161
1164
          }
1162
1165
        }
1265
1268
    printf("Lost space:   %12s    Linkdata:     %10s\n",
1266
1269
           llstr(empty,llbuff),llstr(link_used,llbuff2));
1267
1270
  }
1268
 
  free(mi_get_rec_buff_ptr(info, record));
 
1271
  my_free(mi_get_rec_buff_ptr(info, record), MYF(0));
1269
1272
  return (error);
1270
1273
 err:
1271
1274
  mi_check_print_error(param,"got error: %d when reading datafile at record: %s",my_errno, llstr(records,llbuff));
1272
1275
 err2:
1273
 
  free(mi_get_rec_buff_ptr(info, record));
 
1276
  my_free(mi_get_rec_buff_ptr(info, record), MYF(0));
1274
1277
  param->testflag|=T_RETRY_WITHOUT_QUICK;
1275
1278
  return(1);
1276
1279
} /* chk_data_link */
1333
1336
{
1334
1337
  MYISAM_SHARE *share= info->s;
1335
1338
  MI_STATE_INFO *state= &share->state;
1336
 
  uint32_t i;
 
1339
  uint i;
1337
1340
  int error;
1338
1341
 
1339
1342
  /*
1461
1464
  if (!rep_quick)
1462
1465
  {
1463
1466
    /* Get real path for data file */
1464
 
    if ((new_file=my_create(fn_format(param->temp_filename,
1465
 
                                      share->data_file_name, "",
1466
 
                                      DATA_TMP_EXT, 2+4),
1467
 
                            0,param->tmpfile_createflag,
1468
 
                            MYF(0))) < 0)
 
1467
    if ((new_file=my_raid_create(fn_format(param->temp_filename,
 
1468
                                           share->data_file_name, "",
 
1469
                                           DATA_TMP_EXT, 2+4),
 
1470
                                 0,param->tmpfile_createflag,
 
1471
                                 share->base.raid_type,
 
1472
                                 share->base.raid_chunks,
 
1473
                                 share->base.raid_chunksize,
 
1474
                                 MYF(0))) < 0)
1469
1475
    {
1470
1476
      mi_check_print_error(param,"Can't create new tempfile: '%s'",
1471
 
                           param->temp_filename);
 
1477
                           param->temp_filename);
1472
1478
      goto err;
1473
1479
    }
1474
1480
    if (new_header_length &&
1475
1481
        filecopy(param,new_file,info->dfile,0L,new_header_length,
1476
 
                 "datafile-header"))
 
1482
                 "datafile-header"))
1477
1483
      goto err;
1478
1484
    info->s->state.dellink= HA_OFFSET_ERROR;
1479
1485
    info->rec_cache.file=new_file;
1629
1635
    if (new_file >= 0)
1630
1636
    {
1631
1637
      my_close(new_file,MYF(0));
1632
 
      my_delete(param->temp_filename, MYF(MY_WME));
 
1638
      my_raid_delete(param->temp_filename,info->s->base.raid_chunks,
 
1639
                     MYF(MY_WME));
1633
1640
      info->rec_cache.file=-1; /* don't flush data to new_file, it's closed */
1634
1641
    }
1635
1642
    mi_mark_crashed_on_repair(info);
1636
1643
  }
1637
 
 
1638
 
  void * rec_buff_ptr= NULL;
1639
 
  rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.rec_buff);
1640
 
  if (rec_buff_ptr != NULL)
1641
 
    free(rec_buff_ptr);
1642
 
  rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
1643
 
  if (rec_buff_ptr != NULL)
1644
 
    free(rec_buff_ptr);
1645
 
  rec_buff_ptr= NULL;
1646
 
 
1647
 
  free(sort_info.buff);
 
1644
  my_free(mi_get_rec_buff_ptr(info, sort_param.rec_buff),
 
1645
                            MYF(MY_ALLOW_ZERO_PTR));
 
1646
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
1647
          MYF(MY_ALLOW_ZERO_PTR));
 
1648
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
1648
1649
  end_io_cache(&param->read_cache);
1649
1650
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
1650
1651
  end_io_cache(&info->rec_cache);
1651
1652
  got_error|=flush_blocks(param, share->key_cache, share->kfile);
1652
1653
  if (!got_error && param->testflag & T_UNPACK)
1653
1654
  {
1654
 
    share->state.header.options[0]&= (unsigned char) ~HA_OPTION_COMPRESS_RECORD;
 
1655
    share->state.header.options[0]&= (uchar) ~HA_OPTION_COMPRESS_RECORD;
1655
1656
    share->pack.header_length=0;
1656
1657
    share->data_file_type=sort_info.new_data_file_type;
1657
1658
  }
1665
1666
 
1666
1667
static int writekeys(MI_SORT_PARAM *sort_param)
1667
1668
{
1668
 
  register uint32_t i;
1669
 
  unsigned char    *key;
 
1669
  register uint i;
 
1670
  uchar    *key;
1670
1671
  MI_INFO  *info=   sort_param->sort_info->info;
1671
 
  unsigned char    *buff=   sort_param->record;
 
1672
  uchar    *buff=   sort_param->record;
1672
1673
  my_off_t filepos= sort_param->filepos;
1673
1674
 
1674
1675
  key=info->lastkey+info->s->base.max_key_length;
1677
1678
    if (mi_is_key_active(info->s->state.key_map, i))
1678
1679
    {
1679
1680
      {
1680
 
        uint32_t key_length=_mi_make_key(info,i,key,buff,filepos);
 
1681
        uint key_length=_mi_make_key(info,i,key,buff,filepos);
1681
1682
        if (_mi_ck_write(info,i,key,key_length))
1682
1683
          goto err;
1683
1684
      }
1694
1695
      if (mi_is_key_active(info->s->state.key_map, i))
1695
1696
      {
1696
1697
        {
1697
 
          uint32_t key_length=_mi_make_key(info,i,key,buff,filepos);
 
1698
          uint key_length=_mi_make_key(info,i,key,buff,filepos);
1698
1699
          if (_mi_ck_delete(info,i,key,key_length))
1699
1700
            break;
1700
1701
        }
1710
1711
 
1711
1712
        /* Change all key-pointers that points to a records */
1712
1713
 
1713
 
int movepoint(register MI_INFO *info, unsigned char *record, my_off_t oldpos,
1714
 
              my_off_t newpos, uint32_t prot_key)
 
1714
int movepoint(register MI_INFO *info, uchar *record, my_off_t oldpos,
 
1715
              my_off_t newpos, uint prot_key)
1715
1716
{
1716
 
  register uint32_t i;
1717
 
  unsigned char *key;
1718
 
  uint32_t key_length;
 
1717
  register uint i;
 
1718
  uchar *key;
 
1719
  uint key_length;
1719
1720
 
1720
1721
  key=info->lastkey+info->s->base.max_key_length;
1721
1722
  for (i=0 ; i < info->s->base.keys; i++)
1725
1726
      key_length=_mi_make_key(info,i,key,record,oldpos);
1726
1727
      if (info->s->keyinfo[i].flag & HA_NOSAME)
1727
1728
      {                                 /* Change pointer direct */
1728
 
        uint32_t nod_flag;
 
1729
        uint nod_flag;
1729
1730
        MI_KEYDEF *keyinfo;
1730
1731
        keyinfo=info->s->keyinfo+i;
1731
1732
        if (_mi_search(info,keyinfo,key,USE_WHOLE_KEY,
1788
1789
 
1789
1790
int mi_sort_index(MI_CHECK *param, register MI_INFO *info, char * name)
1790
1791
{
1791
 
  register uint32_t key;
 
1792
  register uint key;
1792
1793
  register MI_KEYDEF *keyinfo;
1793
1794
  File new_file;
1794
1795
  my_off_t index_pos[HA_MAX_POSSIBLE_KEY];
1795
 
  uint32_t r_locks,w_locks;
 
1796
  uint r_locks,w_locks;
1796
1797
  int old_lock;
1797
1798
  MYISAM_SHARE *share=info->s;
1798
1799
  MI_STATE_INFO old_state;
1886
1887
static int sort_one_index(MI_CHECK *param, MI_INFO *info, MI_KEYDEF *keyinfo,
1887
1888
                          my_off_t pagepos, File new_file)
1888
1889
{
1889
 
  uint32_t length,nod_flag,used_length, key_length;
1890
 
  unsigned char *buff,*keypos,*endpos;
1891
 
  unsigned char key[HA_MAX_POSSIBLE_KEY_BUFF];
 
1890
  uint length,nod_flag,used_length, key_length;
 
1891
  uchar *buff,*keypos,*endpos;
 
1892
  uchar key[HA_MAX_POSSIBLE_KEY_BUFF];
1892
1893
  my_off_t new_page_pos,next_page;
1893
1894
  char llbuff[22];
1894
1895
 
1895
1896
  new_page_pos=param->new_file_pos;
1896
1897
  param->new_file_pos+=keyinfo->block_length;
1897
1898
 
1898
 
  if (!(buff=(unsigned char*) my_alloca((uint) keyinfo->block_length)))
 
1899
  if (!(buff=(uchar*) my_alloca((uint) keyinfo->block_length)))
1899
1900
  {
1900
1901
    mi_check_print_error(param,"Not enough memory for key block");
1901
1902
    return(-1);
1932
1933
  /* Fill block with zero and write it to the new index file */
1933
1934
  length=mi_getint(buff);
1934
1935
  memset(buff+length, 0, keyinfo->block_length-length);
1935
 
  if (my_pwrite(new_file,(unsigned char*) buff,(uint) keyinfo->block_length,
 
1936
  if (my_pwrite(new_file,(uchar*) buff,(uint) keyinfo->block_length,
1936
1937
                new_page_pos,MYF(MY_NABP | MY_WAIT_IF_FULL)))
1937
1938
  {
1938
1939
    mi_check_print_error(param,"Can't write indexblock, error: %d",my_errno);
1939
1940
    goto err;
1940
1941
  }
1941
 
  my_afree((unsigned char*) buff);
 
1942
  my_afree((uchar*) buff);
1942
1943
  return(0);
1943
1944
err:
1944
 
  my_afree((unsigned char*) buff);
 
1945
  my_afree((uchar*) buff);
1945
1946
  return(1);
1946
1947
} /* sort_one_index */
1947
1948
 
1957
1958
 
1958
1959
int change_to_newfile(const char * filename, const char * old_ext,
1959
1960
                      const char * new_ext,
1960
 
                      uint32_t raid_chunks __attribute__((unused)),
 
1961
                      uint raid_chunks __attribute__((unused)),
1961
1962
                      myf MyFlags)
1962
1963
{
1963
1964
  char old_filename[FN_REFLEN],new_filename[FN_REFLEN];
1987
1988
  my_seek(from,start,MY_SEEK_SET,MYF(0));
1988
1989
  while (length > buff_length)
1989
1990
  {
1990
 
    if (my_read(from,(unsigned char*) buff,buff_length,MYF(MY_NABP)) ||
1991
 
        my_write(to,(unsigned char*) buff,buff_length,param->myf_rw))
 
1991
    if (my_read(from,(uchar*) buff,buff_length,MYF(MY_NABP)) ||
 
1992
        my_write(to,(uchar*) buff,buff_length,param->myf_rw))
1992
1993
      goto err;
1993
1994
    length-= buff_length;
1994
1995
  }
1995
 
  if (my_read(from,(unsigned char*) buff,(uint) length,MYF(MY_NABP)) ||
1996
 
      my_write(to,(unsigned char*) buff,(uint) length,param->myf_rw))
 
1996
  if (my_read(from,(uchar*) buff,(uint) length,MYF(MY_NABP)) ||
 
1997
      my_write(to,(uchar*) buff,(uint) length,param->myf_rw))
1997
1998
    goto err;
1998
1999
  if (buff != tmp_buff)
1999
 
    free(buff);
 
2000
    my_free(buff,MYF(0));
2000
2001
  return(0);
2001
2002
err:
2002
2003
  if (buff != tmp_buff)
2003
 
    free(buff);
 
2004
    my_free(buff,MYF(0));
2004
2005
  mi_check_print_error(param,"Can't copy %s to tempfile, error %d",
2005
2006
                       type,my_errno);
2006
2007
  return(1);
2026
2027
                      const char * name, int rep_quick)
2027
2028
{
2028
2029
  int got_error;
2029
 
  uint32_t i;
 
2030
  uint i;
2030
2031
  ulong length;
2031
2032
  ha_rows start_records;
2032
2033
  my_off_t new_header_length,del;
2082
2083
  if (!rep_quick)
2083
2084
  {
2084
2085
    /* Get real path for data file */
2085
 
    if ((new_file=my_create(fn_format(param->temp_filename,
2086
 
                                      share->data_file_name, "",
2087
 
                                      DATA_TMP_EXT, 2+4),
2088
 
                            0,param->tmpfile_createflag,
2089
 
                            MYF(0))) < 0)
 
2086
    if ((new_file=my_raid_create(fn_format(param->temp_filename,
 
2087
                                           share->data_file_name, "",
 
2088
                                           DATA_TMP_EXT, 2+4),
 
2089
                                 0,param->tmpfile_createflag,
 
2090
                                 share->base.raid_type,
 
2091
                                 share->base.raid_chunks,
 
2092
                                 share->base.raid_chunksize,
 
2093
                                 MYF(0))) < 0)
2090
2094
    {
2091
2095
      mi_check_print_error(param,"Can't create new tempfile: '%s'",
2092
 
                           param->temp_filename);
 
2096
                           param->temp_filename);
2093
2097
      goto err;
2094
2098
    }
2095
2099
    if (new_header_length &&
2327
2331
    if (new_file >= 0)
2328
2332
    {
2329
2333
      my_close(new_file,MYF(0));
2330
 
      my_delete(param->temp_filename, MYF(MY_WME));
 
2334
      my_raid_delete(param->temp_filename,share->base.raid_chunks,
 
2335
                     MYF(MY_WME));
2331
2336
      if (info->dfile == new_file)
2332
 
        info->dfile= -1;
 
2337
        info->dfile= -1;
2333
2338
    }
2334
2339
    mi_mark_crashed_on_repair(info);
2335
2340
  }
2337
2342
    share->state.changed&= ~STATE_NOT_OPTIMIZED_KEYS;
2338
2343
  share->state.changed|=STATE_NOT_SORTED_PAGES;
2339
2344
 
2340
 
  void * rec_buff_ptr= NULL;
2341
 
  rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.rec_buff);
2342
 
  if (rec_buff_ptr != NULL)
2343
 
    free(rec_buff_ptr);
2344
 
  rec_buff_ptr= mi_get_rec_buff_ptr(info, sort_param.record);
2345
 
  if (rec_buff_ptr != NULL)
2346
 
    free(rec_buff_ptr);
2347
 
  rec_buff_ptr= NULL;
2348
 
 
2349
 
  free((unsigned char*) sort_info.key_block);
2350
 
  free(sort_info.buff);
 
2345
  my_free(mi_get_rec_buff_ptr(info, sort_param.rec_buff),
 
2346
                            MYF(MY_ALLOW_ZERO_PTR));
 
2347
  my_free(mi_get_rec_buff_ptr(info, sort_param.record),
 
2348
          MYF(MY_ALLOW_ZERO_PTR));
 
2349
  my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR));
 
2350
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
2351
2351
  end_io_cache(&param->read_cache);
2352
2352
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
2353
2353
  if (!got_error && (param->testflag & T_UNPACK))
2354
2354
  {
2355
 
    share->state.header.options[0]&= (unsigned char) ~HA_OPTION_COMPRESS_RECORD;
 
2355
    share->state.header.options[0]&= (uchar) ~HA_OPTION_COMPRESS_RECORD;
2356
2356
    share->pack.header_length=0;
2357
2357
  }
2358
2358
  return(got_error);
2404
2404
                        const char * name, int rep_quick)
2405
2405
{
2406
2406
  int got_error;
2407
 
  uint32_t i,key, total_key_length, istep;
 
2407
  uint i,key, total_key_length, istep;
2408
2408
  ulong rec_length;
2409
2409
  ha_rows start_records;
2410
2410
  my_off_t new_header_length,del;
2492
2492
  if (!rep_quick)
2493
2493
  {
2494
2494
    /* Get real path for data file */
2495
 
    if ((new_file=my_create(fn_format(param->temp_filename,
2496
 
                                      share->data_file_name, "",
2497
 
                                      DATA_TMP_EXT,
2498
 
                                      2+4),
2499
 
                            0,param->tmpfile_createflag,
2500
 
                            MYF(0))) < 0)
 
2495
    if ((new_file=my_raid_create(fn_format(param->temp_filename,
 
2496
                                           share->data_file_name, "",
 
2497
                                           DATA_TMP_EXT,
 
2498
                                           2+4),
 
2499
                                 0,param->tmpfile_createflag,
 
2500
                                 share->base.raid_type,
 
2501
                                 share->base.raid_chunks,
 
2502
                                 share->base.raid_chunksize,
 
2503
                                 MYF(0))) < 0)
2501
2504
    {
2502
2505
      mi_check_print_error(param,"Can't create new tempfile: '%s'",
2503
2506
                           param->temp_filename);
2616
2619
    sort_param[i].filepos=new_header_length;
2617
2620
    sort_param[i].max_pos=sort_param[i].pos=share->pack.header_length;
2618
2621
 
2619
 
    sort_param[i].record= (((unsigned char *)(sort_param+share->base.keys))+
 
2622
    sort_param[i].record= (((uchar *)(sort_param+share->base.keys))+
2620
2623
                           (max_pack_reclength * i));
2621
2624
    if (!mi_alloc_rec_buff(info, -1, &sort_param[i].rec_buff))
2622
2625
    {
2837
2840
    if (new_file >= 0)
2838
2841
    {
2839
2842
      my_close(new_file,MYF(0));
2840
 
      my_delete(param->temp_filename, MYF(MY_WME));
 
2843
      my_raid_delete(param->temp_filename,share->base.raid_chunks,
 
2844
                     MYF(MY_WME));
2841
2845
      if (info->dfile == new_file)
2842
 
        info->dfile= -1;
 
2846
        info->dfile= -1;
2843
2847
    }
2844
2848
    mi_mark_crashed_on_repair(info);
2845
2849
  }
2850
2854
  pthread_cond_destroy (&sort_info.cond);
2851
2855
  pthread_mutex_destroy(&sort_info.mutex);
2852
2856
 
2853
 
  free((unsigned char*) sort_info.key_block);
2854
 
  free((unsigned char*) sort_param);
2855
 
  free(sort_info.buff);
 
2857
  my_free((uchar*) sort_info.key_block,MYF(MY_ALLOW_ZERO_PTR));
 
2858
  my_free((uchar*) sort_param,MYF(MY_ALLOW_ZERO_PTR));
 
2859
  my_free(sort_info.buff,MYF(MY_ALLOW_ZERO_PTR));
2856
2860
  end_io_cache(&param->read_cache);
2857
2861
  info->opt_flag&= ~(READ_CACHE_USED | WRITE_CACHE_USED);
2858
2862
  if (!got_error && (param->testflag & T_UNPACK))
2859
2863
  {
2860
 
    share->state.header.options[0]&= (unsigned char) ~HA_OPTION_COMPRESS_RECORD;
 
2864
    share->state.header.options[0]&= (uchar) ~HA_OPTION_COMPRESS_RECORD;
2861
2865
    share->pack.header_length=0;
2862
2866
  }
2863
2867
  return(got_error);
2882
2886
  }
2883
2887
  sort_param->real_key_length=
2884
2888
    (info->s->rec_reflength+
2885
 
     _mi_make_key(info, sort_param->key, (unsigned char*) key,
 
2889
     _mi_make_key(info, sort_param->key, (uchar*) key,
2886
2890
                  sort_param->record, sort_param->filepos));
2887
2891
#ifdef HAVE_purify
2888
2892
  memset(key+sort_param->real_key_length, 0,
2927
2931
{
2928
2932
  int searching;
2929
2933
  int parallel_flag;
2930
 
  uint32_t found_record,b_type,left_length;
 
2934
  uint found_record,b_type,left_length;
2931
2935
  my_off_t pos;
2932
 
  unsigned char *to= NULL;
 
2936
  uchar *to= NULL;
2933
2937
  MI_BLOCK_INFO block_info;
2934
2938
  SORT_INFO *sort_info=sort_param->sort_info;
2935
2939
  MI_CHECK *param=sort_info->param;
3005
3009
                     llstr(param->search_after_block,llbuff),
3006
3010
                     llstr(sort_param->start_recpos,llbuff2));
3007
3011
        if (_mi_read_cache(&sort_param->read_cache,
3008
 
                           (unsigned char*) block_info.header,pos,
 
3012
                           (uchar*) block_info.header,pos,
3009
3013
                           MI_BLOCK_INFO_HEADER_LENGTH,
3010
3014
                           (! found_record ? READING_NEXT : 0) |
3011
3015
                           parallel_flag | READING_HEADER))
3032
3036
             (block_info.rec_len < (uint) share->base.min_pack_length ||
3033
3037
              block_info.rec_len > (uint) share->base.max_pack_length)))
3034
3038
        {
3035
 
          uint32_t i;
 
3039
          uint i;
3036
3040
          if (param->testflag & T_VERBOSE || searching == 0)
3037
3041
            mi_check_print_info(param,
3038
3042
                                "Wrong bytesec: %3d-%3d-%3d at %10s; Skipped",
3191
3195
          streched over the end of the previous buffer contents.
3192
3196
        */
3193
3197
        {
3194
 
          uint32_t header_len= (uint) (block_info.filepos - pos);
3195
 
          uint32_t prefetch_len= (MI_BLOCK_INFO_HEADER_LENGTH - header_len);
 
3198
          uint header_len= (uint) (block_info.filepos - pos);
 
3199
          uint prefetch_len= (MI_BLOCK_INFO_HEADER_LENGTH - header_len);
3196
3200
 
3197
3201
          if (prefetch_len > block_info.data_len)
3198
3202
            prefetch_len= block_info.data_len;
3293
3297
{
3294
3298
  int flag;
3295
3299
  ulong block_length,reclength;
3296
 
  unsigned char *from;
 
3300
  uchar *from;
3297
3301
  SORT_INFO *sort_info=sort_param->sort_info;
3298
3302
  MI_CHECK *param=sort_info->param;
3299
3303
  MI_INFO *info=sort_info->info;
3385
3389
static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a,
3386
3390
                        const void *b)
3387
3391
{
3388
 
  uint32_t not_used[2];
3389
 
  return (ha_key_cmp(sort_param->seg, *((unsigned char* const *) a), *((unsigned char* const *) b),
 
3392
  uint not_used[2];
 
3393
  return (ha_key_cmp(sort_param->seg, *((uchar* const *) a), *((uchar* const *) b),
3390
3394
                     USE_WHOLE_KEY, SEARCH_SAME, not_used));
3391
3395
} /* sort_key_cmp */
3392
3396
 
3393
3397
 
3394
3398
static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a)
3395
3399
{
3396
 
  uint32_t diff_pos[2];
 
3400
  uint diff_pos[2];
3397
3401
  char llbuff[22],llbuff2[22];
3398
3402
  SORT_INFO *sort_info=sort_param->sort_info;
3399
3403
  MI_CHECK *param= sort_info->param;
3402
3406
  if (sort_info->key_block->inited)
3403
3407
  {
3404
3408
    cmp=ha_key_cmp(sort_param->seg,sort_info->key_block->lastkey,
3405
 
                   (unsigned char*) a, USE_WHOLE_KEY,SEARCH_FIND | SEARCH_UPDATE,
 
3409
                   (uchar*) a, USE_WHOLE_KEY,SEARCH_FIND | SEARCH_UPDATE,
3406
3410
                   diff_pos);
3407
3411
    if (param->stats_method == MI_STATS_METHOD_NULLS_NOT_EQUAL)
3408
3412
      ha_key_cmp(sort_param->seg,sort_info->key_block->lastkey,
3409
 
                 (unsigned char*) a, USE_WHOLE_KEY, 
 
3413
                 (uchar*) a, USE_WHOLE_KEY, 
3410
3414
                 SEARCH_FIND | SEARCH_NULL_ARE_NOT_EQUAL, diff_pos);
3411
3415
    else if (param->stats_method == MI_STATS_METHOD_IGNORE_NULLS)
3412
3416
    {
3413
3417
      diff_pos[0]= mi_collect_stats_nonulls_next(sort_param->seg,
3414
3418
                                                 sort_param->notnull,
3415
3419
                                                 sort_info->key_block->lastkey,
3416
 
                                                 (unsigned char*)a);
 
3420
                                                 (uchar*)a);
3417
3421
    }
3418
3422
    sort_param->unique[diff_pos[0]-1]++;
3419
3423
  }
3422
3426
    cmp= -1;
3423
3427
    if (param->stats_method == MI_STATS_METHOD_IGNORE_NULLS)
3424
3428
      mi_collect_stats_nonulls_first(sort_param->seg, sort_param->notnull,
3425
 
                                     (unsigned char*)a);
 
3429
                                     (uchar*)a);
3426
3430
  }
3427
3431
  if ((sort_param->keyinfo->flag & HA_NOSAME) && cmp == 0)
3428
3432
  {
3429
3433
    sort_info->dupp++;
3430
3434
    sort_info->info->lastpos=get_record_for_key(sort_info->info,
3431
3435
                                                sort_param->keyinfo,
3432
 
                                                (unsigned char*) a);
 
3436
                                                (uchar*) a);
3433
3437
    mi_check_print_warning(param,
3434
3438
                           "Duplicate key for record at %10s against record at %10s",
3435
3439
                           llstr(sort_info->info->lastpos,llbuff),
3442
3446
    return (sort_delete_record(sort_param));
3443
3447
  }
3444
3448
  return (sort_insert_key(sort_param,sort_info->key_block,
3445
 
                          (unsigned char*) a, HA_OFFSET_ERROR));
 
3449
                          (uchar*) a, HA_OFFSET_ERROR));
3446
3450
} /* sort_key_write */
3447
3451
 
3448
3452
 
3449
3453
        /* get pointer to record from a key */
3450
3454
 
3451
3455
static my_off_t get_record_for_key(MI_INFO *info, MI_KEYDEF *keyinfo,
3452
 
                                   unsigned char *key)
 
3456
                                   uchar *key)
3453
3457
{
3454
3458
  return _mi_dpos(info,0,key+_mi_keylength(keyinfo,key));
3455
3459
} /* get_record_for_key */
3458
3462
        /* Insert a key in sort-key-blocks */
3459
3463
 
3460
3464
static int sort_insert_key(MI_SORT_PARAM *sort_param,
3461
 
                           register SORT_KEY_BLOCKS *key_block, unsigned char *key,
 
3465
                           register SORT_KEY_BLOCKS *key_block, uchar *key,
3462
3466
                           my_off_t prev_block)
3463
3467
{
3464
 
  uint32_t a_length,t_length,nod_flag;
 
3468
  uint a_length,t_length,nod_flag;
3465
3469
  my_off_t filepos,key_file_length;
3466
 
  unsigned char *anc_buff,*lastkey;
 
3470
  uchar *anc_buff,*lastkey;
3467
3471
  MI_KEY_PARAM s_temp;
3468
3472
  MI_INFO *info;
3469
3473
  MI_KEYDEF *keyinfo=sort_param->keyinfo;
3496
3500
    _mi_kpointer(info,key_block->end_pos,prev_block);
3497
3501
 
3498
3502
  t_length=(*keyinfo->pack_key)(keyinfo,nod_flag,
3499
 
                                (unsigned char*) 0,lastkey,lastkey,key,
 
3503
                                (uchar*) 0,lastkey,lastkey,key,
3500
3504
                                 &s_temp);
3501
3505
  (*keyinfo->store_key)(keyinfo, key_block->end_pos+nod_flag,&s_temp);
3502
3506
  a_length+=t_length;
3523
3527
    if (_mi_write_keypage(info, keyinfo, filepos, DFLT_INIT_HITS, anc_buff))
3524
3528
      return(1);
3525
3529
  }
3526
 
  else if (my_pwrite(info->s->kfile,(unsigned char*) anc_buff,
 
3530
  else if (my_pwrite(info->s->kfile,(uchar*) anc_buff,
3527
3531
                     (uint) keyinfo->block_length,filepos, param->myf_rw))
3528
3532
    return(1);
3529
3533
 
3541
3545
 
3542
3546
static int sort_delete_record(MI_SORT_PARAM *sort_param)
3543
3547
{
3544
 
  uint32_t i;
 
3548
  uint i;
3545
3549
  int old_file,error;
3546
 
  unsigned char *key;
 
3550
  uchar *key;
3547
3551
  SORT_INFO *sort_info=sort_param->sort_info;
3548
3552
  MI_CHECK *param=sort_info->param;
3549
3553
  MI_INFO *info=sort_info->info;
3576
3580
 
3577
3581
    for (i=0 ; i < sort_info->current_key ; i++)
3578
3582
    {
3579
 
      uint32_t key_length=_mi_make_key(info,i,key,sort_param->record,info->lastpos);
 
3583
      uint key_length=_mi_make_key(info,i,key,sort_param->record,info->lastpos);
3580
3584
      if (_mi_ck_delete(info,i,key,key_length))
3581
3585
      {
3582
3586
        mi_check_print_error(param,"Can't delete key %d from record to be removed",i+1);
3597
3601
 
3598
3602
int flush_pending_blocks(MI_SORT_PARAM *sort_param)
3599
3603
{
3600
 
  uint32_t nod_flag,length;
 
3604
  uint nod_flag,length;
3601
3605
  my_off_t filepos,key_file_length;
3602
3606
  SORT_KEY_BLOCKS *key_block;
3603
3607
  SORT_INFO *sort_info= sort_param->sort_info;
3625
3629
                            DFLT_INIT_HITS, key_block->buff))
3626
3630
        return(1);
3627
3631
    }
3628
 
    else if (my_pwrite(info->s->kfile,(unsigned char*) key_block->buff,
 
3632
    else if (my_pwrite(info->s->kfile,(uchar*) key_block->buff,
3629
3633
                       (uint) keyinfo->block_length,filepos, myf_rw))
3630
3634
      return(1);
3631
3635
    nod_flag=1;
3636
3640
 
3637
3641
        /* alloc space and pointers for key_blocks */
3638
3642
 
3639
 
static SORT_KEY_BLOCKS *alloc_key_blocks(MI_CHECK *param, uint32_t blocks,
3640
 
                                         uint32_t buffer_length)
 
3643
static SORT_KEY_BLOCKS *alloc_key_blocks(MI_CHECK *param, uint blocks,
 
3644
                                         uint buffer_length)
3641
3645
{
3642
 
  register uint32_t i;
 
3646
  register uint i;
3643
3647
  SORT_KEY_BLOCKS *block;
3644
3648
 
3645
3649
  if (!(block=(SORT_KEY_BLOCKS*) my_malloc((sizeof(SORT_KEY_BLOCKS)+
3652
3656
  for (i=0 ; i < blocks ; i++)
3653
3657
  {
3654
3658
    block[i].inited=0;
3655
 
    block[i].buff=(unsigned char*) (block+blocks)+(buffer_length+IO_SIZE)*i;
 
3659
    block[i].buff=(uchar*) (block+blocks)+(buffer_length+IO_SIZE)*i;
3656
3660
  }
3657
3661
  return(block);
3658
3662
} /* alloc_key_blocks */
3682
3686
  MI_COLUMNDEF *recdef,*rec,*end;
3683
3687
  MI_UNIQUEDEF *uniquedef,*u_ptr,*u_end;
3684
3688
  MI_STATUS_INFO status_info;
3685
 
  uint32_t unpack,key_parts;
 
3689
  uint unpack,key_parts;
3686
3690
  ha_rows max_records;
3687
3691
  uint64_t file_length,tmp_length;
3688
3692
  MI_CREATE_INFO create_info;
3702
3706
  if (!(keysegs=(HA_KEYSEG*) my_alloca(sizeof(HA_KEYSEG)*
3703
3707
                                       (key_parts+share.base.keys))))
3704
3708
  {
3705
 
    my_afree((unsigned char*) keyinfo);
 
3709
    my_afree((uchar*) keyinfo);
3706
3710
    return(1);
3707
3711
  }
3708
3712
  if (!(recdef=(MI_COLUMNDEF*)
3709
3713
        my_alloca(sizeof(MI_COLUMNDEF)*(share.base.fields+1))))
3710
3714
  {
3711
 
    my_afree((unsigned char*) keyinfo);
3712
 
    my_afree((unsigned char*) keysegs);
 
3715
    my_afree((uchar*) keyinfo);
 
3716
    my_afree((uchar*) keysegs);
3713
3717
    return(1);
3714
3718
  }
3715
3719
  if (!(uniquedef=(MI_UNIQUEDEF*)
3716
3720
        my_alloca(sizeof(MI_UNIQUEDEF)*(share.state.header.uniques+1))))
3717
3721
  {
3718
 
    my_afree((unsigned char*) recdef);
3719
 
    my_afree((unsigned char*) keyinfo);
3720
 
    my_afree((unsigned char*) keysegs);
 
3722
    my_afree((uchar*) recdef);
 
3723
    my_afree((uchar*) keyinfo);
 
3724
    my_afree((uchar*) keysegs);
3721
3725
    return(1);
3722
3726
  }
3723
3727
 
3832
3836
    goto end;
3833
3837
  error=0;
3834
3838
end:
3835
 
  my_afree((unsigned char*) uniquedef);
3836
 
  my_afree((unsigned char*) keyinfo);
3837
 
  my_afree((unsigned char*) recdef);
3838
 
  my_afree((unsigned char*) keysegs);
 
3839
  my_afree((uchar*) uniquedef);
 
3840
  my_afree((uchar*) keyinfo);
 
3841
  my_afree((uchar*) recdef);
 
3842
  my_afree((uchar*) keysegs);
3839
3843
  return(error);
3840
3844
}
3841
3845
 
3848
3852
 
3849
3853
  if (info->s->options & HA_OPTION_COMPRESS_RECORD && fix_datafile)
3850
3854
  {
3851
 
    unsigned char buff[MEMMAP_EXTRA_MARGIN];
 
3855
    uchar buff[MEMMAP_EXTRA_MARGIN];
3852
3856
    memset(buff, 0, sizeof(buff));
3853
3857
    if (my_b_write(&info->rec_cache,buff,sizeof(buff)))
3854
3858
    {
3863
3867
 
3864
3868
        /* Update state and myisamchk_time of indexfile */
3865
3869
 
3866
 
int update_state_info(MI_CHECK *param, MI_INFO *info,uint32_t update)
 
3870
int update_state_info(MI_CHECK *param, MI_INFO *info,uint update)
3867
3871
{
3868
3872
  MYISAM_SHARE *share=info->s;
3869
3873
 
3874
3878
  }
3875
3879
  if (update & UPDATE_STAT)
3876
3880
  {
3877
 
    uint32_t i, key_parts= mi_uint2korr(share->state.header.key_parts);
 
3881
    uint i, key_parts= mi_uint2korr(share->state.header.key_parts);
3878
3882
    share->state.rec_per_key_rows=info->state->records;
3879
3883
    share->state.changed&= ~STATE_NOT_ANALYZED;
3880
3884
    if (info->state->records)
3908
3912
  }
3909
3913
  {                                             /* Force update of status */
3910
3914
    int error;
3911
 
    uint32_t r_locks=share->r_locks,w_locks=share->w_locks;
 
3915
    uint r_locks=share->r_locks,w_locks=share->w_locks;
3912
3916
    share->r_locks= share->w_locks= share->tot_locks= 0;
3913
3917
    error=_mi_writeinfo(info,WRITEINFO_NO_UNLOCK);
3914
3918
    share->r_locks=r_locks;
3938
3942
void update_auto_increment_key(MI_CHECK *param, MI_INFO *info,
3939
3943
                               bool repair_only)
3940
3944
{
3941
 
  unsigned char *record= 0;
 
3945
  uchar *record= 0;
3942
3946
 
3943
3947
  if (!info->s->base.auto_key ||
3944
3948
      ! mi_is_key_active(info->s->state.key_map, info->s->base.auto_key - 1))
3968
3972
    if (my_errno != HA_ERR_END_OF_FILE)
3969
3973
    {
3970
3974
      mi_extra(info,HA_EXTRA_NO_KEYREAD,0);
3971
 
      free(mi_get_rec_buff_ptr(info, record));
 
3975
      my_free(mi_get_rec_buff_ptr(info, record), MYF(0));
3972
3976
      mi_check_print_error(param,"%d when reading last record",my_errno);
3973
3977
      return;
3974
3978
    }
3983
3987
      set_if_bigger(info->s->state.auto_increment, param->auto_increment_value);
3984
3988
  }
3985
3989
  mi_extra(info,HA_EXTRA_NO_KEYREAD,0);
3986
 
  free(mi_get_rec_buff_ptr(info, record));
 
3990
  my_free(mi_get_rec_buff_ptr(info, record), MYF(0));
3987
3991
  update_state_info(param, info, UPDATE_AUTO_INC);
3988
3992
  return;
3989
3993
}
4046
4050
{
4047
4051
  uint64_t count=0,tmp, unique_tuples;
4048
4052
  uint64_t tuples= records;
4049
 
  uint32_t parts;
 
4053
  uint parts;
4050
4054
  for (parts=0 ; parts < keyinfo->keysegs  ; parts++)
4051
4055
  {
4052
4056
    count+=unique[parts];
4083
4087
}
4084
4088
 
4085
4089
 
4086
 
static ha_checksum mi_byte_checksum(const unsigned char *buf, uint32_t length)
 
4090
static ha_checksum mi_byte_checksum(const uchar *buf, uint length)
4087
4091
{
4088
4092
  ha_checksum crc;
4089
 
  const unsigned char *end=buf+length;
 
4093
  const uchar *end=buf+length;
4090
4094
  for (crc=0; buf != end; buf++)
4091
 
    crc=((crc << 1) + *((unsigned char*) buf)) +
 
4095
    crc=((crc << 1) + *((uchar*) buf)) +
4092
4096
      test(crc & (((ha_checksum) 1) << (8*sizeof(ha_checksum)-1)));
4093
4097
  return crc;
4094
4098
}
4095
4099
 
4096
4100
static bool mi_too_big_key_for_sort(MI_KEYDEF *key, ha_rows rows)
4097
4101
{
4098
 
  uint32_t key_maxlength=key->maxlength;
 
4102
  uint key_maxlength=key->maxlength;
4099
4103
  return (key->flag & (HA_BINARY_PACK_KEY | HA_VAR_LENGTH_KEY) &&
4100
4104
          ((uint64_t) rows * key_maxlength >
4101
4105
           (uint64_t) myisam_max_temp_length));
4114
4118
{
4115
4119
  MYISAM_SHARE *share=info->s;
4116
4120
  MI_KEYDEF    *key=share->keyinfo;
4117
 
  uint32_t          i;
 
4121
  uint          i;
4118
4122
 
4119
4123
  assert(info->state->records == 0 &&
4120
4124
              (!rows || rows >= MI_MIN_ROWS_TO_DISABLE_INDEXES));
4141
4145
{
4142
4146
  MYISAM_SHARE *share=info->s;
4143
4147
  MI_KEYDEF *key=share->keyinfo;
4144
 
  uint32_t i;
 
4148
  uint i;
4145
4149
 
4146
4150
  /*
4147
4151
    mi_repair_by_sort only works if we have at least one key. If we don't