~mdcallag/+junk/5.1-map

« back to all changes in this revision

Viewing changes to myisam/mi_check.c

  • Committer: sasha at sashanet
  • Date: 2001-04-12 01:09:00 UTC
  • mfrom: (669.1.1)
  • Revision ID: sp1r-sasha@mysql.sashanet.com-20010412010900-14282
Ugly merge of 3.23 changes into 4.0 - fix up needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
/* Descript, check and repair of ISAM tables */
18
18
 
19
 
#include "fulltext.h"
 
19
#include "ftdefs.h"
20
20
#include <m_ctype.h>
21
21
#include <stdarg.h>
22
22
#include <getopt.h>
45
45
static int sort_one_index(MI_CHECK *param, MI_INFO *info,MI_KEYDEF *keyinfo,
46
46
                          my_off_t pagepos, File new_file);
47
47
static int sort_key_read(SORT_INFO *sort_info,void *key);
 
48
static int sort_ft_key_read(SORT_INFO *sort_info,void *key);
48
49
static int sort_get_next_record(SORT_INFO *sort_info);
49
50
static int sort_key_cmp(SORT_INFO *sort_info, const void *a,const void *b);
50
51
static int sort_key_write(SORT_INFO *sort_info, const void *a);
53
54
static int sort_insert_key(MI_CHECK *param, reg1 SORT_KEY_BLOCKS *key_block,
54
55
                           uchar *key, my_off_t prev_block);
55
56
static int sort_delete_record(MI_CHECK *param);
56
 
static int flush_pending_blocks(MI_CHECK *param);
 
57
/*static int flush_pending_blocks(MI_CHECK *param);*/
57
58
static SORT_KEY_BLOCKS  *alloc_key_blocks(MI_CHECK *param, uint blocks,
58
59
                                          uint buffer_length);
59
60
static void update_key_parts(MI_KEYDEF *keyinfo,
1722
1723
    printf("Data records: %s\n", llstr(start_records,llbuff));
1723
1724
  }
1724
1725
 
1725
 
  /* Hmm, repair_by_sort uses find_all_keys, and find_all_keys strictly
1726
 
     implies "one row - one key per keynr", while for ft_key one row/keynr
1727
 
     can produce as many keys as the number of unique words in the text
1728
 
     that's why I disabled repair_by_sort for ft-keys. (serg)
1729
 
  */
1730
 
  for (i=0 ; i < share->base.keys ; i++)
1731
 
  {
1732
 
    if ((((ulonglong) 1 << i) & key_map) && 
1733
 
        (share->keyinfo[i].flag & HA_FULLTEXT))
1734
 
    {
1735
 
      mi_check_print_error(param,
1736
 
                           "Can`t use repair_by_sort with FULLTEXT key");
1737
 
      DBUG_RETURN(1);
1738
 
    }
1739
 
  }
1740
 
 
1741
1726
  bzero((char*) sort_info,sizeof(*sort_info));
1742
1727
  if (!(sort_info->key_block=
1743
1728
        alloc_key_blocks(param,
1829
1814
  param->read_cache.end_of_file=sort_info->filelength=
1830
1815
    my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0));
1831
1816
 
 
1817
  sort_info->wordlist=NULL;
 
1818
 
1832
1819
  if (share->data_file_type == DYNAMIC_RECORD)
1833
1820
    length=max(share->base.min_pack_length+1,share->base.min_block_length);
1834
1821
  else if (share->data_file_type == COMPRESSED_RECORD)
1840
1827
     (ha_rows) (sort_info->filelength/length+1));
1841
1828
  sort_param.key_cmp=sort_key_cmp;
1842
1829
  sort_param.key_write=sort_key_write;
1843
 
  sort_param.key_read=sort_key_read;
1844
1830
  sort_param.lock_in_memory=lock_memory;
1845
1831
  sort_param.tmpdir=param->tmpdir;
1846
1832
  sort_param.myf_rw=param->myf_rw;
1886
1872
    info->state->records=info->state->del=share->state.split=0;
1887
1873
    info->state->empty=0;
1888
1874
 
 
1875
    if (sort_info->keyinfo->flag & HA_FULLTEXT)
 
1876
    {
 
1877
      sort_param.max_records=sort_info->max_records=
 
1878
        (ha_rows) (sort_info->filelength/MAX_WORD_LEN_FOR_SORT+1);
 
1879
 
 
1880
      sort_param.key_read=sort_ft_key_read;
 
1881
      sort_param.key_length+=MAX_WORD_LEN_FOR_SORT-MAX_WORD_LEN;
 
1882
    }
 
1883
    else
 
1884
      sort_param.key_read=sort_key_read;
 
1885
 
1889
1886
    if (_create_index_by_sort(&sort_param,
1890
1887
                              (my_bool) (!(param->testflag & T_VERBOSE)),
1891
1888
                              (uint) param->sort_buffer_length))
1930
1927
    else
1931
1928
      info->state->data_file_length=sort_info->max_pos;
1932
1929
 
1933
 
    if (flush_pending_blocks(param))
1934
 
      goto err;
 
1930
    /*if (flush_pending_blocks(param))
 
1931
      goto err;*/
1935
1932
 
1936
1933
    param->read_cache.file=info->dfile;         /* re-init read cache */
1937
1934
    reinit_io_cache(&param->read_cache,READ_CACHE,share->pack.header_length,1,
2055
2052
                         "Found too many records; Can`t continue");
2056
2053
    DBUG_RETURN(1);
2057
2054
  }
2058
 
  (void) _mi_make_key(info,sort_info->key,key,sort_info->record,
2059
 
                      sort_info->filepos);
 
2055
  sort_info->real_key_length=info->s->rec_reflength+_mi_make_key(info,
 
2056
                      sort_info->key,key,sort_info->record,sort_info->filepos);
2060
2057
  DBUG_RETURN(sort_write_record(sort_info));
2061
2058
} /* sort_key_read */
2062
2059
 
 
2060
static int sort_ft_key_read(SORT_INFO *sort_info, void *key)
 
2061
{
 
2062
  int error;
 
2063
  MI_INFO *info;
 
2064
  FT_WORD *wptr;
 
2065
  DBUG_ENTER("sort_ft_key_read");
 
2066
 
 
2067
  info=sort_info->info;
 
2068
 
 
2069
  if (!sort_info->wordlist)
 
2070
  {
 
2071
    do
 
2072
    {
 
2073
      if ((error=sort_get_next_record(sort_info)))
 
2074
        DBUG_RETURN(error);
 
2075
      if (!(wptr=_mi_ft_parserecord(info,sort_info->key,key,sort_info->record)))
 
2076
        DBUG_RETURN(1);
 
2077
      error=sort_write_record(sort_info);
 
2078
    }
 
2079
    while (!wptr->pos);
 
2080
    sort_info->wordptr=sort_info->wordlist=wptr;
 
2081
  }
 
2082
  else
 
2083
  {
 
2084
    error=0;
 
2085
    wptr=(FT_WORD*)(sort_info->wordptr);
 
2086
  }
 
2087
 
 
2088
  sort_info->real_key_length=info->s->rec_reflength+_ft_make_key(info,
 
2089
                              sort_info->key,key,wptr++,sort_info->filepos);
 
2090
  if (!wptr->pos)
 
2091
  {
 
2092
    my_free((char*) sort_info->wordlist, MYF(0));
 
2093
    sort_info->wordlist=0;
 
2094
  }
 
2095
  else
 
2096
    sort_info->wordptr=(void*)wptr;
 
2097
 
 
2098
 
 
2099
  DBUG_RETURN(error);
 
2100
} /* sort_ft_key_read */
2063
2101
 
2064
2102
        /* Read next record from file using parameters in sort_info */
2065
2103
        /* Return -1 if end of file, 0 if ok and > 0 if error */
2714
2752
 
2715
2753
        /* Fix all pending blocks and flush everything to disk */
2716
2754
 
2717
 
static int flush_pending_blocks(MI_CHECK *param)
 
2755
int flush_pending_blocks(MI_CHECK *param)
2718
2756
{
2719
2757
  uint nod_flag,length;
2720
2758
  my_off_t filepos,key_file_length;
3181
3219
    return FALSE;                               /* Can't use sort */
3182
3220
  for (i=0 ; i < share->base.keys ; i++,key++)
3183
3221
  {
3184
 
/* It's to disable repair_by_sort for ft-keys.
3185
 
   Another solution would be to make ft-keys just too_big_key_for_sort,
3186
 
   but then they won't be disabled by dectivate_non_unique_index
3187
 
   and so they will be created at the first stage. As ft-key creation
3188
 
   is very time-consuming process, it's better to leave it to repair stage
3189
 
   but this repair shouldn't be repair_by_sort (serg)
3190
 
 */
3191
 
    if ((!force && mi_too_big_key_for_sort(key,rows)) ||
3192
 
        (key->flag & HA_FULLTEXT))
 
3222
    if (!force && mi_too_big_key_for_sort(key,rows))
3193
3223
      return FALSE;
3194
3224
  }
3195
3225
  return TRUE;