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));
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)
1730
for (i=0 ; i < share->base.keys ; i++)
1732
if ((((ulonglong) 1 << i) & key_map) &&
1733
(share->keyinfo[i].flag & HA_FULLTEXT))
1735
mi_check_print_error(param,
1736
"Can`t use repair_by_sort with FULLTEXT key");
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));
1817
sort_info->wordlist=NULL;
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;
1875
if (sort_info->keyinfo->flag & HA_FULLTEXT)
1877
sort_param.max_records=sort_info->max_records=
1878
(ha_rows) (sort_info->filelength/MAX_WORD_LEN_FOR_SORT+1);
1880
sort_param.key_read=sort_ft_key_read;
1881
sort_param.key_length+=MAX_WORD_LEN_FOR_SORT-MAX_WORD_LEN;
1884
sort_param.key_read=sort_key_read;
1889
1886
if (_create_index_by_sort(&sort_param,
1890
1887
(my_bool) (!(param->testflag & T_VERBOSE)),
1891
1888
(uint) param->sort_buffer_length))
1931
1928
info->state->data_file_length=sort_info->max_pos;
1933
if (flush_pending_blocks(param))
1930
/*if (flush_pending_blocks(param))
1936
1933
param->read_cache.file=info->dfile; /* re-init read cache */
1937
1934
reinit_io_cache(¶m->read_cache,READ_CACHE,share->pack.header_length,1,
2055
2052
"Found too many records; Can`t continue");
2056
2053
DBUG_RETURN(1);
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 */
2060
static int sort_ft_key_read(SORT_INFO *sort_info, void *key)
2065
DBUG_ENTER("sort_ft_key_read");
2067
info=sort_info->info;
2069
if (!sort_info->wordlist)
2073
if ((error=sort_get_next_record(sort_info)))
2075
if (!(wptr=_mi_ft_parserecord(info,sort_info->key,key,sort_info->record)))
2077
error=sort_write_record(sort_info);
2080
sort_info->wordptr=sort_info->wordlist=wptr;
2085
wptr=(FT_WORD*)(sort_info->wordptr);
2088
sort_info->real_key_length=info->s->rec_reflength+_ft_make_key(info,
2089
sort_info->key,key,wptr++,sort_info->filepos);
2092
my_free((char*) sort_info->wordlist, MYF(0));
2093
sort_info->wordlist=0;
2096
sort_info->wordptr=(void*)wptr;
2100
} /* sort_ft_key_read */
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 */
2715
2753
/* Fix all pending blocks and flush everything to disk */
2717
static int flush_pending_blocks(MI_CHECK *param)
2755
int flush_pending_blocks(MI_CHECK *param)
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++)
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)
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))