Loading libmysql/Makefile.shared +2 −2 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ my_getopt.lo my_gethostbyname.lo # Not needed in the minimum library mysysobjects2 = getvar.lo my_lib.lo mysysobjects2 = my_lib.lo mysysobjects = $(mysysobjects1) $(mysysobjects2) target_libadd = $(mysysobjects) $(mystringsobjects) $(dbugobjects) \ $(vio_objects) Loading myisam/mi_cache.c +2 −2 Original line number Diff line number Diff line Loading @@ -72,8 +72,8 @@ int _mi_read_cache(IO_CACHE *info, byte *buff, my_off_t pos, uint length, in_buff_length=0; if (flag & READING_NEXT || info->share) { if (pos != (info->pos_in_file + (uint) (info->read_end - info->request_pos))) if (pos != (info->pos_in_file + (uint) (info->read_end - info->request_pos))) { info->pos_in_file=pos; /* Force start here */ info->read_pos=info->read_end=info->request_pos; /* Everything used */ Loading myisam/mi_check.c +88 −58 Original line number Diff line number Diff line Loading @@ -1203,7 +1203,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, for (i=0 ; i < share->state.header.max_block_size ; i++) share->state.key_del[i]= HA_OFFSET_ERROR; /* I think mi_repair and mi_repair_by_sort should do the same /* I think mi_repair and mi_repair_by_sort should do the same (according, e.g. to ha_myisam::repair), but as mi_repair doesn't touch key_map it cannot be used to T_CREATE_MISSING_KEYS. That is what the next line is for... (serg) Loading Loading @@ -1737,8 +1738,22 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, type,my_errno); DBUG_RETURN(1); } /* Fix table or given index using sorting */ /* saves new table in temp_filename */ /* Repair table or given index using sorting SYNOPSIS mi_repair_by_sort() param Repair parameters info MyISAM handler to repair name Name of table (for warnings) rep_quick set to <> 0 if we should not change data file RESULT 0 ok <>0 Error */ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, const char * name, int rep_quick) Loading Loading @@ -1956,8 +1971,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, goto err; } } share->state.state.data_file_length = info->state->data_file_length = sort_param.filepos; share->state.state.data_file_length = info->state->data_file_length= sort_param.filepos; /* Only whole records */ share->state.version=(ulong) time((time_t*) 0); my_close(info->dfile,MYF(0)); Loading Loading @@ -2079,19 +2094,35 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, DBUG_RETURN(got_error); } /* same as mi_repair_by_sort */ /* but do it multithreaded */ /* Threaded repair of table using sorting SYNOPSIS mi_repair_by_sort_r() param Repair parameters info MyISAM handler to repair name Name of table (for warnings) rep_quick set to <> 0 if we should not change data file DESCRIPTION Same as mi_repair_by_sort but do it multithreaded Each key is handled by a separate thread. RESULT 0 ok <>0 Error */ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, const char * name, int rep_quick) { int got_error; uint i,key; ulong length; uint i,key, total_key_length; ulong rec_length; ha_rows start_records; my_off_t new_header_length,del; File new_file; MI_SORT_PARAM *sort_param=0, *sinfo; MI_SORT_PARAM *sort_param=0; MYISAM_SHARE *share=info->s; ulong *rec_per_key_part; MI_KEYSEG *keyseg; Loading Loading @@ -2193,14 +2224,14 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); if (share->data_file_type == DYNAMIC_RECORD) length=max(share->base.min_pack_length+1,share->base.min_block_length); rec_length=max(share->base.min_pack_length+1,share->base.min_block_length); else if (share->data_file_type == COMPRESSED_RECORD) length=share->base.min_block_length; rec_length=share->base.min_block_length; else length=share->base.pack_reclength; rec_length=share->base.pack_reclength; sort_info.max_records= ((param->testflag & T_CREATE_MISSING_KEYS) ? info->state->records : (ha_rows) (sort_info.filelength/length+1)); (ha_rows) (sort_info.filelength/rec_length+1)); del=info->state->del; param->glob_crc=0; Loading @@ -2215,7 +2246,7 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, mi_check_print_error(param,"Not enough memory!"); goto err; } length=0; total_key_length=0; rec_per_key_part= param->rec_per_key_part; info->state->records=info->state->del=share->state.split=0; info->state->empty=0; Loading @@ -2235,10 +2266,8 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, i--; continue; } if ((!(param->testflag & T_SILENT))) printf ("- Fixing index %d\n",key+1); sort_param[i].key_read=(sort_param[i].keyinfo->flag & HA_FULLTEXT) ? sort_ft_key_read : sort_key_read; sort_param[i].key_read= ((sort_param[i].keyinfo->flag & HA_FULLTEXT) ? sort_ft_key_read : sort_key_read); sort_param[i].key_cmp=sort_key_cmp; sort_param[i].key_write=sort_key_write; sort_param[i].lock_in_memory=lock_memory; Loading @@ -2249,8 +2278,8 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, sort_param[i].filepos=new_header_length; sort_param[i].max_pos=sort_param[i].pos=share->pack.header_length; sort_param[i].record=((char *)(sort_param+share->base.keys))+ (share->base.pack_reclength * i); sort_param[i].record= (((char *)(sort_param+share->base.keys))+ (share->base.pack_reclength * i)); sort_param[i].key_length=share->rec_reflength; for (keyseg=sort_param[i].keyinfo->seg; keyseg->type != HA_KEYTYPE_END; Loading @@ -2264,8 +2293,7 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, if (keyseg->flag & HA_NULL_PART) sort_param[i].key_length++; } length+=sort_param[i].key_length; total_key_length+=sort_param[i].key_length; if (sort_param[i].keyinfo->flag & HA_FULLTEXT) sort_param[i].key_length+=ft_max_word_len_for_sort-ft_max_word_len; Loading @@ -2292,7 +2320,7 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, #if 1 param->sort_buffer_length/sort_info.total_keys; #else param->sort_buffer_length*sort_param[i].key_length/length; param->sort_buffer_length*sort_param[i].key_length/total_key_length; #endif if (pthread_create(& sort_param[i].thr, 0, (void *(*)(void*))_thr_find_all_keys, sort_param+i)) Loading @@ -2310,14 +2338,14 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, pthread_cond_wait(&sort_info.cond, &sort_info.mutex); pthread_mutex_unlock(&sort_info.mutex); if (got_error=_thr_write_keys(sort_param)) if ((got_error= _thr_write_keys(sort_param))) { param->retry_repair=1; goto err; } got_error=1; got_error=1; /* Assume the following may go wrong */ if (sort_param[0].fix_datafile) if (sort_param->fix_datafile) { if (write_data_suffix(&sort_info,1) || end_io_cache(&info->rec_cache)) goto err; Loading @@ -2330,8 +2358,8 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, goto err; } } share->state.state.data_file_length = info->state->data_file_length = sort_param->filepos; share->state.state.data_file_length= info->state->data_file_length= sort_param->filepos; /* Only whole records */ share->state.version=(ulong) time((time_t*) 0); my_close(info->dfile,MYF(0)); Loading Loading @@ -2457,7 +2485,8 @@ static int sort_key_read(MI_SORT_PARAM *sort_param, void *key) "Found too many records; Can`t continue"); DBUG_RETURN(1); } sort_param->real_key_length=(info->s->rec_reflength+ sort_param->real_key_length= (info->s->rec_reflength+ _mi_make_key(info, sort_param->key, (uchar*) key, sort_param->record, sort_param->filepos)); DBUG_RETURN(sort_write_record(sort_param)); Loading Loading @@ -2981,7 +3010,8 @@ int sort_write_record(MI_SORT_PARAM *sort_param) /* Compare two keys from _create_index_by_sort */ static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a, const void *b) static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a, const void *b) { uint not_used; return (_mi_key_cmp(sort_param->keyinfo->seg,*((uchar**) a),*((uchar**) b), Loading @@ -3000,7 +3030,8 @@ static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a) if (sort_info->key_block->inited) { cmp=_mi_key_cmp(sort_param->keyinfo->seg, sort_info->key_block->lastkey, (uchar*) a, USE_WHOLE_KEY,SEARCH_FIND | SEARCH_UPDATE ,&diff_pos); (uchar*) a, USE_WHOLE_KEY, SEARCH_FIND | SEARCH_UPDATE, &diff_pos); sort_param->unique[diff_pos-1]++; } else Loading Loading @@ -3638,8 +3669,7 @@ void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows) */ my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map, my_bool force) ulonglong key_map, my_bool force) { MYISAM_SHARE *share=info->s; MI_KEYDEF *key=share->keyinfo; Loading myisam/sort.c +105 −58 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <queues.h> /* static variables */ #undef MIN_SORT_MEMORY #undef MYF_RW #undef DISK_BUFFER_SIZE Loading @@ -48,7 +49,7 @@ typedef struct st_buffpek { extern void print_error _VARARGS((const char *fmt,...)); /* functions defined in this file */ /* Functions defined in this file */ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info,uint keys, uchar **sort_keys, Loading @@ -57,7 +58,8 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info,uint keys, IO_CACHE *tempfile_for_exceptions); static int NEAR_F write_keys(MI_SORT_PARAM *info,uchar * *sort_keys, uint count, BUFFPEK *buffpek,IO_CACHE *tempfile); static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile); static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile); static int NEAR_F write_index(MI_SORT_PARAM *info,uchar * *sort_keys, uint count); static int NEAR_F merge_many_buff(MI_SORT_PARAM *info,uint keys, Loading @@ -72,8 +74,21 @@ static int NEAR_F merge_buffers(MI_SORT_PARAM *info,uint keys, BUFFPEK *Fb, BUFFPEK *Tb); static int NEAR_F merge_index(MI_SORT_PARAM *,uint,uchar **,BUFFPEK *, int, IO_CACHE *); /* Creates a index of sorted keys */ /* Returns 0 if everything went ok */ /* Creates a index of sorted keys SYNOPSIS _create_index_by_sort() info Sort parameters no_messages Set to 1 if no output sortbuff_size Size if sortbuffer to allocate RESULT 0 ok <> 0 Error */ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong sortbuff_size) Loading Loading @@ -248,7 +263,8 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info, uint keys, DBUG_RETURN(HA_POS_ERROR); /* Aborted by get_key */ /* purecov: inspected */ if (buffpek->elements) { if (write_keys(info,sort_keys,idx,(BUFFPEK *)alloc_dynamic(buffpek),tempfile)) if (write_keys(info,sort_keys,idx,(BUFFPEK *)alloc_dynamic(buffpek), tempfile)) DBUG_RETURN(HA_POS_ERROR); /* purecov: inspected */ *maxbuffer=buffpek->elements-1; } Loading @@ -258,21 +274,22 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info, uint keys, DBUG_RETURN((*maxbuffer)*(keys-1)+idx); } /* find_all_keys */ /* Search after all keys and place them in a temp. file */ void *_thr_find_all_keys(MI_SORT_PARAM *info) { int error,skr; int error; uint memavl,old_memavl,keys,sort_length; uint idx, maxbuffer; uchar **sort_keys; MI_KEYSEG *keyseg; my_b_clear(&info->tempfile); my_b_clear(&info->tempfile_for_exceptions); bzero((char*) &info->buffpek,sizeof(info->buffpek)); bzero((char*) &info->unique, sizeof(info->unique)); sort_keys= (uchar **) NULL; error= 1; sort_keys= (uchar **) NULL; error= 1; if (info->sort_info->got_error) goto err; Loading @@ -280,12 +297,15 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) idx= info->sort_info->max_records; sort_length= info->key_length; maxbuffer=1; while (memavl >= MIN_SORT_MEMORY) { if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= (my_off_t) memavl) keys= idx+1; else { uint skr; do { skr=maxbuffer; Loading @@ -299,9 +319,10 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) } } while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr); } if ((sort_keys=(uchar **)my_malloc(keys*(sort_length+sizeof(char*))+ ((info->keyinfo->flag & HA_FULLTEXT) ? HA_FT_MAXLEN : 0), MYF(0)))) ((info->keyinfo->flag & HA_FULLTEXT) ? HA_FT_MAXLEN : 0), MYF(0)))) { if (my_init_dynamic_array(&info->buffpek, sizeof(BUFFPEK), maxbuffer, maxbuffer/2)) Loading @@ -318,7 +339,6 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) mi_check_print_error(info->sort_info->param,"Sort buffer to small"); /* purecov: tested */ goto err; /* purecov: tested */ } // (*info->lock_in_memory)(info->sort_info->param);/* Everything is allocated */ if (info->sort_info->param->testflag & T_VERBOSE) printf("Key %d - Allocating buffer for %d keys\n",info->key+1,keys); Loading @@ -340,7 +360,8 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) if (++idx == keys) { if (write_keys(info,sort_keys,idx-1, (BUFFPEK *)alloc_dynamic(&info->buffpek), &info->tempfile)) (BUFFPEK *)alloc_dynamic(&info->buffpek), &info->tempfile)) goto err; sort_keys[0]=(uchar*) (sort_keys+keys); Loading @@ -353,8 +374,8 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) goto err; if (info->buffpek.elements) { if (write_keys(info,sort_keys,idx,(BUFFPEK *) alloc_dynamic(&info->buffpek),&info->tempfile)) if (write_keys(info,sort_keys, idx, (BUFFPEK *) alloc_dynamic(&info->buffpek), &info->tempfile)) goto err; info->keys=(info->buffpek.elements-1)*(keys-1)+idx; } Loading @@ -372,6 +393,7 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) delete_dynamic(& info->buffpek); close_cached_file(&info->tempfile); close_cached_file(&info->tempfile_for_exceptions); ok: remove_io_thread(&info->read_cache); pthread_mutex_lock(&info->sort_info->mutex); Loading @@ -381,20 +403,24 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) return NULL; } /* _thr_find_all_keys */ int _thr_write_keys(MI_SORT_PARAM *sort_param) { SORT_INFO *sort_info=sort_param->sort_info; MI_CHECK *param=sort_info->param; ulong length, keys; ulong *rec_per_key_part=param->rec_per_key_part; int i, got_error=sort_info->got_error; int got_error=sort_info->got_error; uint i; MI_INFO *info=sort_info->info; MYISAM_SHARE *share=info->s; MI_SORT_PARAM *sinfo; byte *mergebuf=0; LINT_INIT(length); for (i=0, sinfo=sort_param ; i<sort_info->total_keys ; i++, sinfo++, rec_per_key_part+=sinfo->keyinfo->keysegs) for (i=0, sinfo=sort_param ; i < sort_info->total_keys ; i++, sinfo++, rec_per_key_part+=sinfo->keyinfo->keysegs) { if (!sinfo->sort_keys) { Loading @@ -408,8 +434,11 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) if (!sinfo->buffpek.elements) { if (param->testflag & T_VERBOSE) printf("Key %d - Dumping %lu keys\n",sinfo->key+1, sinfo->keys); if (write_index(sinfo,sinfo->sort_keys,(uint) sinfo->keys) || { printf("Key %d - Dumping %u keys\n",sinfo->key+1, sinfo->keys); fflush(stdout); } if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) || flush_pending_blocks(sinfo)) got_error=1; } Loading @@ -417,12 +446,14 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) sinfo->sort_keys=0; } for (i=0, sinfo=sort_param ; i<sort_info->total_keys ; i++, sinfo++, delete_dynamic(& sinfo->buffpek), for (i=0, sinfo=sort_param ; i < sort_info->total_keys ; i++, sinfo++, delete_dynamic(&sinfo->buffpek), close_cached_file(&sinfo->tempfile), close_cached_file(&sinfo->tempfile_for_exceptions)) { if (got_error) continue; if (got_error) continue; if (sinfo->buffpek.elements) { uint maxbuffer=sinfo->buffpek.elements-1; Loading @@ -444,7 +475,7 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) if (maxbuffer >= MERGEBUFF2) { if (param->testflag & T_VERBOSE) printf("Key %d - Merging %lu keys\n",sinfo->key+1, sinfo->keys); printf("Key %d - Merging %u keys\n",sinfo->key+1, sinfo->keys); if (merge_many_buff(sinfo, keys, (uchar **)mergebuf, dynamic_element(&sinfo->buffpek, 0, BUFFPEK *), &maxbuffer, &sinfo->tempfile)) Loading @@ -463,8 +494,8 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) printf("Key %d - Last merge and dumping keys", sinfo->key+1); if (merge_index(sinfo, keys, (uchar **)mergebuf, dynamic_element(&sinfo->buffpek,0,BUFFPEK *), maxbuffer,&sinfo->tempfile) || flush_pending_blocks(sinfo)) maxbuffer,&sinfo->tempfile) || flush_pending_blocks(sinfo)) { got_error=1; continue; Loading @@ -484,10 +515,10 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) continue; } while (!got_error && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)&key_length, sizeof(key_length)) && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)mergebuf, while (!got_error && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)&key_length, sizeof(key_length)) && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)mergebuf, (uint) key_length)) { if (_mi_ck_write(info,sinfo->key,(uchar*) mergebuf, Loading Loading @@ -526,7 +557,8 @@ static int NEAR_F write_keys(MI_SORT_PARAM *info, register uchar **sort_keys, } /* write_keys */ static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) { uint key_length=info->real_key_length; DBUG_ENTER("write_key"); Loading @@ -542,6 +574,7 @@ static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) DBUG_RETURN(0); } /* write_key */ /* Write index */ static int NEAR_F write_index(MI_SORT_PARAM *info, register uchar **sort_keys, Loading @@ -552,8 +585,10 @@ static int NEAR_F write_index(MI_SORT_PARAM *info, register uchar **sort_keys, qsort2((gptr) sort_keys,(size_t) count,sizeof(byte*), (qsort2_cmp) info->key_cmp,info); while (count--) { if ((*info->key_write)(info,*sort_keys++)) DBUG_RETURN(-1); /* purecov: inspected */ } DBUG_RETURN(0); } /* write_index */ Loading Loading @@ -604,8 +639,18 @@ static int NEAR_F merge_many_buff(MI_SORT_PARAM *info, uint keys, } /* merge_many_buff */ /* Read data to buffer */ /* This returns (uint) -1 if something goes wrong */ /* Read data to buffer SYNOPSIS read_to_buffer() fromfile File to read from buffpek Where to read from sort_length max length to read RESULT > 0 Ammount of bytes read -1 Error */ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, uint sort_length) Loading @@ -627,8 +672,10 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, } /* read_to_buffer */ /* Merge buffers to one buffer */ /* If to_file == 0 then use info->key_write */ /* Merge buffers to one buffer If to_file == 0 then use info->key_write */ static int NEAR_F merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file, Loading myisammrg/myrg_delete.c +2 −4 Original line number Diff line number Diff line Loading @@ -18,12 +18,10 @@ #include "myrg_def.h" int myrg_delete( MYRG_INFO *info, const byte *record) int myrg_delete(MYRG_INFO *info, const byte *record) { if (!info->current_table) return my_errno=HA_ERR_NO_ACTIVE_RECORD ; return (my_errno= HA_ERR_NO_ACTIVE_RECORD); return mi_delete(info->current_table->table,record); } Loading
libmysql/Makefile.shared +2 −2 Original line number Diff line number Diff line Loading @@ -62,7 +62,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ my_getopt.lo my_gethostbyname.lo # Not needed in the minimum library mysysobjects2 = getvar.lo my_lib.lo mysysobjects2 = my_lib.lo mysysobjects = $(mysysobjects1) $(mysysobjects2) target_libadd = $(mysysobjects) $(mystringsobjects) $(dbugobjects) \ $(vio_objects) Loading
myisam/mi_cache.c +2 −2 Original line number Diff line number Diff line Loading @@ -72,8 +72,8 @@ int _mi_read_cache(IO_CACHE *info, byte *buff, my_off_t pos, uint length, in_buff_length=0; if (flag & READING_NEXT || info->share) { if (pos != (info->pos_in_file + (uint) (info->read_end - info->request_pos))) if (pos != (info->pos_in_file + (uint) (info->read_end - info->request_pos))) { info->pos_in_file=pos; /* Force start here */ info->read_pos=info->read_end=info->request_pos; /* Everything used */ Loading
myisam/mi_check.c +88 −58 Original line number Diff line number Diff line Loading @@ -1203,7 +1203,8 @@ int mi_repair(MI_CHECK *param, register MI_INFO *info, for (i=0 ; i < share->state.header.max_block_size ; i++) share->state.key_del[i]= HA_OFFSET_ERROR; /* I think mi_repair and mi_repair_by_sort should do the same /* I think mi_repair and mi_repair_by_sort should do the same (according, e.g. to ha_myisam::repair), but as mi_repair doesn't touch key_map it cannot be used to T_CREATE_MISSING_KEYS. That is what the next line is for... (serg) Loading Loading @@ -1737,8 +1738,22 @@ int filecopy(MI_CHECK *param, File to,File from,my_off_t start, type,my_errno); DBUG_RETURN(1); } /* Fix table or given index using sorting */ /* saves new table in temp_filename */ /* Repair table or given index using sorting SYNOPSIS mi_repair_by_sort() param Repair parameters info MyISAM handler to repair name Name of table (for warnings) rep_quick set to <> 0 if we should not change data file RESULT 0 ok <>0 Error */ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, const char * name, int rep_quick) Loading Loading @@ -1956,8 +1971,8 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, goto err; } } share->state.state.data_file_length = info->state->data_file_length = sort_param.filepos; share->state.state.data_file_length = info->state->data_file_length= sort_param.filepos; /* Only whole records */ share->state.version=(ulong) time((time_t*) 0); my_close(info->dfile,MYF(0)); Loading Loading @@ -2079,19 +2094,35 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, DBUG_RETURN(got_error); } /* same as mi_repair_by_sort */ /* but do it multithreaded */ /* Threaded repair of table using sorting SYNOPSIS mi_repair_by_sort_r() param Repair parameters info MyISAM handler to repair name Name of table (for warnings) rep_quick set to <> 0 if we should not change data file DESCRIPTION Same as mi_repair_by_sort but do it multithreaded Each key is handled by a separate thread. RESULT 0 ok <>0 Error */ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, const char * name, int rep_quick) { int got_error; uint i,key; ulong length; uint i,key, total_key_length; ulong rec_length; ha_rows start_records; my_off_t new_header_length,del; File new_file; MI_SORT_PARAM *sort_param=0, *sinfo; MI_SORT_PARAM *sort_param=0; MYISAM_SHARE *share=info->s; ulong *rec_per_key_part; MI_KEYSEG *keyseg; Loading Loading @@ -2193,14 +2224,14 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, my_seek(param->read_cache.file,0L,MY_SEEK_END,MYF(0)); if (share->data_file_type == DYNAMIC_RECORD) length=max(share->base.min_pack_length+1,share->base.min_block_length); rec_length=max(share->base.min_pack_length+1,share->base.min_block_length); else if (share->data_file_type == COMPRESSED_RECORD) length=share->base.min_block_length; rec_length=share->base.min_block_length; else length=share->base.pack_reclength; rec_length=share->base.pack_reclength; sort_info.max_records= ((param->testflag & T_CREATE_MISSING_KEYS) ? info->state->records : (ha_rows) (sort_info.filelength/length+1)); (ha_rows) (sort_info.filelength/rec_length+1)); del=info->state->del; param->glob_crc=0; Loading @@ -2215,7 +2246,7 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, mi_check_print_error(param,"Not enough memory!"); goto err; } length=0; total_key_length=0; rec_per_key_part= param->rec_per_key_part; info->state->records=info->state->del=share->state.split=0; info->state->empty=0; Loading @@ -2235,10 +2266,8 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, i--; continue; } if ((!(param->testflag & T_SILENT))) printf ("- Fixing index %d\n",key+1); sort_param[i].key_read=(sort_param[i].keyinfo->flag & HA_FULLTEXT) ? sort_ft_key_read : sort_key_read; sort_param[i].key_read= ((sort_param[i].keyinfo->flag & HA_FULLTEXT) ? sort_ft_key_read : sort_key_read); sort_param[i].key_cmp=sort_key_cmp; sort_param[i].key_write=sort_key_write; sort_param[i].lock_in_memory=lock_memory; Loading @@ -2249,8 +2278,8 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, sort_param[i].filepos=new_header_length; sort_param[i].max_pos=sort_param[i].pos=share->pack.header_length; sort_param[i].record=((char *)(sort_param+share->base.keys))+ (share->base.pack_reclength * i); sort_param[i].record= (((char *)(sort_param+share->base.keys))+ (share->base.pack_reclength * i)); sort_param[i].key_length=share->rec_reflength; for (keyseg=sort_param[i].keyinfo->seg; keyseg->type != HA_KEYTYPE_END; Loading @@ -2264,8 +2293,7 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, if (keyseg->flag & HA_NULL_PART) sort_param[i].key_length++; } length+=sort_param[i].key_length; total_key_length+=sort_param[i].key_length; if (sort_param[i].keyinfo->flag & HA_FULLTEXT) sort_param[i].key_length+=ft_max_word_len_for_sort-ft_max_word_len; Loading @@ -2292,7 +2320,7 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, #if 1 param->sort_buffer_length/sort_info.total_keys; #else param->sort_buffer_length*sort_param[i].key_length/length; param->sort_buffer_length*sort_param[i].key_length/total_key_length; #endif if (pthread_create(& sort_param[i].thr, 0, (void *(*)(void*))_thr_find_all_keys, sort_param+i)) Loading @@ -2310,14 +2338,14 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, pthread_cond_wait(&sort_info.cond, &sort_info.mutex); pthread_mutex_unlock(&sort_info.mutex); if (got_error=_thr_write_keys(sort_param)) if ((got_error= _thr_write_keys(sort_param))) { param->retry_repair=1; goto err; } got_error=1; got_error=1; /* Assume the following may go wrong */ if (sort_param[0].fix_datafile) if (sort_param->fix_datafile) { if (write_data_suffix(&sort_info,1) || end_io_cache(&info->rec_cache)) goto err; Loading @@ -2330,8 +2358,8 @@ int mi_repair_by_sort_r(MI_CHECK *param, register MI_INFO *info, goto err; } } share->state.state.data_file_length = info->state->data_file_length = sort_param->filepos; share->state.state.data_file_length= info->state->data_file_length= sort_param->filepos; /* Only whole records */ share->state.version=(ulong) time((time_t*) 0); my_close(info->dfile,MYF(0)); Loading Loading @@ -2457,7 +2485,8 @@ static int sort_key_read(MI_SORT_PARAM *sort_param, void *key) "Found too many records; Can`t continue"); DBUG_RETURN(1); } sort_param->real_key_length=(info->s->rec_reflength+ sort_param->real_key_length= (info->s->rec_reflength+ _mi_make_key(info, sort_param->key, (uchar*) key, sort_param->record, sort_param->filepos)); DBUG_RETURN(sort_write_record(sort_param)); Loading Loading @@ -2981,7 +3010,8 @@ int sort_write_record(MI_SORT_PARAM *sort_param) /* Compare two keys from _create_index_by_sort */ static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a, const void *b) static int sort_key_cmp(MI_SORT_PARAM *sort_param, const void *a, const void *b) { uint not_used; return (_mi_key_cmp(sort_param->keyinfo->seg,*((uchar**) a),*((uchar**) b), Loading @@ -3000,7 +3030,8 @@ static int sort_key_write(MI_SORT_PARAM *sort_param, const void *a) if (sort_info->key_block->inited) { cmp=_mi_key_cmp(sort_param->keyinfo->seg, sort_info->key_block->lastkey, (uchar*) a, USE_WHOLE_KEY,SEARCH_FIND | SEARCH_UPDATE ,&diff_pos); (uchar*) a, USE_WHOLE_KEY, SEARCH_FIND | SEARCH_UPDATE, &diff_pos); sort_param->unique[diff_pos-1]++; } else Loading Loading @@ -3638,8 +3669,7 @@ void mi_disable_non_unique_index(MI_INFO *info, ha_rows rows) */ my_bool mi_test_if_sort_rep(MI_INFO *info, ha_rows rows, ulonglong key_map, my_bool force) ulonglong key_map, my_bool force) { MYISAM_SHARE *share=info->s; MI_KEYDEF *key=share->keyinfo; Loading
myisam/sort.c +105 −58 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ #include <queues.h> /* static variables */ #undef MIN_SORT_MEMORY #undef MYF_RW #undef DISK_BUFFER_SIZE Loading @@ -48,7 +49,7 @@ typedef struct st_buffpek { extern void print_error _VARARGS((const char *fmt,...)); /* functions defined in this file */ /* Functions defined in this file */ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info,uint keys, uchar **sort_keys, Loading @@ -57,7 +58,8 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info,uint keys, IO_CACHE *tempfile_for_exceptions); static int NEAR_F write_keys(MI_SORT_PARAM *info,uchar * *sort_keys, uint count, BUFFPEK *buffpek,IO_CACHE *tempfile); static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile); static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile); static int NEAR_F write_index(MI_SORT_PARAM *info,uchar * *sort_keys, uint count); static int NEAR_F merge_many_buff(MI_SORT_PARAM *info,uint keys, Loading @@ -72,8 +74,21 @@ static int NEAR_F merge_buffers(MI_SORT_PARAM *info,uint keys, BUFFPEK *Fb, BUFFPEK *Tb); static int NEAR_F merge_index(MI_SORT_PARAM *,uint,uchar **,BUFFPEK *, int, IO_CACHE *); /* Creates a index of sorted keys */ /* Returns 0 if everything went ok */ /* Creates a index of sorted keys SYNOPSIS _create_index_by_sort() info Sort parameters no_messages Set to 1 if no output sortbuff_size Size if sortbuffer to allocate RESULT 0 ok <> 0 Error */ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong sortbuff_size) Loading Loading @@ -248,7 +263,8 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info, uint keys, DBUG_RETURN(HA_POS_ERROR); /* Aborted by get_key */ /* purecov: inspected */ if (buffpek->elements) { if (write_keys(info,sort_keys,idx,(BUFFPEK *)alloc_dynamic(buffpek),tempfile)) if (write_keys(info,sort_keys,idx,(BUFFPEK *)alloc_dynamic(buffpek), tempfile)) DBUG_RETURN(HA_POS_ERROR); /* purecov: inspected */ *maxbuffer=buffpek->elements-1; } Loading @@ -258,21 +274,22 @@ static ha_rows NEAR_F find_all_keys(MI_SORT_PARAM *info, uint keys, DBUG_RETURN((*maxbuffer)*(keys-1)+idx); } /* find_all_keys */ /* Search after all keys and place them in a temp. file */ void *_thr_find_all_keys(MI_SORT_PARAM *info) { int error,skr; int error; uint memavl,old_memavl,keys,sort_length; uint idx, maxbuffer; uchar **sort_keys; MI_KEYSEG *keyseg; my_b_clear(&info->tempfile); my_b_clear(&info->tempfile_for_exceptions); bzero((char*) &info->buffpek,sizeof(info->buffpek)); bzero((char*) &info->unique, sizeof(info->unique)); sort_keys= (uchar **) NULL; error= 1; sort_keys= (uchar **) NULL; error= 1; if (info->sort_info->got_error) goto err; Loading @@ -280,12 +297,15 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) idx= info->sort_info->max_records; sort_length= info->key_length; maxbuffer=1; while (memavl >= MIN_SORT_MEMORY) { if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= (my_off_t) memavl) keys= idx+1; else { uint skr; do { skr=maxbuffer; Loading @@ -299,9 +319,10 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) } } while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr); } if ((sort_keys=(uchar **)my_malloc(keys*(sort_length+sizeof(char*))+ ((info->keyinfo->flag & HA_FULLTEXT) ? HA_FT_MAXLEN : 0), MYF(0)))) ((info->keyinfo->flag & HA_FULLTEXT) ? HA_FT_MAXLEN : 0), MYF(0)))) { if (my_init_dynamic_array(&info->buffpek, sizeof(BUFFPEK), maxbuffer, maxbuffer/2)) Loading @@ -318,7 +339,6 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) mi_check_print_error(info->sort_info->param,"Sort buffer to small"); /* purecov: tested */ goto err; /* purecov: tested */ } // (*info->lock_in_memory)(info->sort_info->param);/* Everything is allocated */ if (info->sort_info->param->testflag & T_VERBOSE) printf("Key %d - Allocating buffer for %d keys\n",info->key+1,keys); Loading @@ -340,7 +360,8 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) if (++idx == keys) { if (write_keys(info,sort_keys,idx-1, (BUFFPEK *)alloc_dynamic(&info->buffpek), &info->tempfile)) (BUFFPEK *)alloc_dynamic(&info->buffpek), &info->tempfile)) goto err; sort_keys[0]=(uchar*) (sort_keys+keys); Loading @@ -353,8 +374,8 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) goto err; if (info->buffpek.elements) { if (write_keys(info,sort_keys,idx,(BUFFPEK *) alloc_dynamic(&info->buffpek),&info->tempfile)) if (write_keys(info,sort_keys, idx, (BUFFPEK *) alloc_dynamic(&info->buffpek), &info->tempfile)) goto err; info->keys=(info->buffpek.elements-1)*(keys-1)+idx; } Loading @@ -372,6 +393,7 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) delete_dynamic(& info->buffpek); close_cached_file(&info->tempfile); close_cached_file(&info->tempfile_for_exceptions); ok: remove_io_thread(&info->read_cache); pthread_mutex_lock(&info->sort_info->mutex); Loading @@ -381,20 +403,24 @@ void *_thr_find_all_keys(MI_SORT_PARAM *info) return NULL; } /* _thr_find_all_keys */ int _thr_write_keys(MI_SORT_PARAM *sort_param) { SORT_INFO *sort_info=sort_param->sort_info; MI_CHECK *param=sort_info->param; ulong length, keys; ulong *rec_per_key_part=param->rec_per_key_part; int i, got_error=sort_info->got_error; int got_error=sort_info->got_error; uint i; MI_INFO *info=sort_info->info; MYISAM_SHARE *share=info->s; MI_SORT_PARAM *sinfo; byte *mergebuf=0; LINT_INIT(length); for (i=0, sinfo=sort_param ; i<sort_info->total_keys ; i++, sinfo++, rec_per_key_part+=sinfo->keyinfo->keysegs) for (i=0, sinfo=sort_param ; i < sort_info->total_keys ; i++, sinfo++, rec_per_key_part+=sinfo->keyinfo->keysegs) { if (!sinfo->sort_keys) { Loading @@ -408,8 +434,11 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) if (!sinfo->buffpek.elements) { if (param->testflag & T_VERBOSE) printf("Key %d - Dumping %lu keys\n",sinfo->key+1, sinfo->keys); if (write_index(sinfo,sinfo->sort_keys,(uint) sinfo->keys) || { printf("Key %d - Dumping %u keys\n",sinfo->key+1, sinfo->keys); fflush(stdout); } if (write_index(sinfo, sinfo->sort_keys, sinfo->keys) || flush_pending_blocks(sinfo)) got_error=1; } Loading @@ -417,12 +446,14 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) sinfo->sort_keys=0; } for (i=0, sinfo=sort_param ; i<sort_info->total_keys ; i++, sinfo++, delete_dynamic(& sinfo->buffpek), for (i=0, sinfo=sort_param ; i < sort_info->total_keys ; i++, sinfo++, delete_dynamic(&sinfo->buffpek), close_cached_file(&sinfo->tempfile), close_cached_file(&sinfo->tempfile_for_exceptions)) { if (got_error) continue; if (got_error) continue; if (sinfo->buffpek.elements) { uint maxbuffer=sinfo->buffpek.elements-1; Loading @@ -444,7 +475,7 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) if (maxbuffer >= MERGEBUFF2) { if (param->testflag & T_VERBOSE) printf("Key %d - Merging %lu keys\n",sinfo->key+1, sinfo->keys); printf("Key %d - Merging %u keys\n",sinfo->key+1, sinfo->keys); if (merge_many_buff(sinfo, keys, (uchar **)mergebuf, dynamic_element(&sinfo->buffpek, 0, BUFFPEK *), &maxbuffer, &sinfo->tempfile)) Loading @@ -463,8 +494,8 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) printf("Key %d - Last merge and dumping keys", sinfo->key+1); if (merge_index(sinfo, keys, (uchar **)mergebuf, dynamic_element(&sinfo->buffpek,0,BUFFPEK *), maxbuffer,&sinfo->tempfile) || flush_pending_blocks(sinfo)) maxbuffer,&sinfo->tempfile) || flush_pending_blocks(sinfo)) { got_error=1; continue; Loading @@ -484,10 +515,10 @@ int _thr_write_keys(MI_SORT_PARAM *sort_param) continue; } while (!got_error && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)&key_length, sizeof(key_length)) && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)mergebuf, while (!got_error && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)&key_length, sizeof(key_length)) && !my_b_read(&sinfo->tempfile_for_exceptions,(byte*)mergebuf, (uint) key_length)) { if (_mi_ck_write(info,sinfo->key,(uchar*) mergebuf, Loading Loading @@ -526,7 +557,8 @@ static int NEAR_F write_keys(MI_SORT_PARAM *info, register uchar **sort_keys, } /* write_keys */ static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) { uint key_length=info->real_key_length; DBUG_ENTER("write_key"); Loading @@ -542,6 +574,7 @@ static int NEAR_F write_key(MI_SORT_PARAM *info, uchar *key, IO_CACHE *tempfile) DBUG_RETURN(0); } /* write_key */ /* Write index */ static int NEAR_F write_index(MI_SORT_PARAM *info, register uchar **sort_keys, Loading @@ -552,8 +585,10 @@ static int NEAR_F write_index(MI_SORT_PARAM *info, register uchar **sort_keys, qsort2((gptr) sort_keys,(size_t) count,sizeof(byte*), (qsort2_cmp) info->key_cmp,info); while (count--) { if ((*info->key_write)(info,*sort_keys++)) DBUG_RETURN(-1); /* purecov: inspected */ } DBUG_RETURN(0); } /* write_index */ Loading Loading @@ -604,8 +639,18 @@ static int NEAR_F merge_many_buff(MI_SORT_PARAM *info, uint keys, } /* merge_many_buff */ /* Read data to buffer */ /* This returns (uint) -1 if something goes wrong */ /* Read data to buffer SYNOPSIS read_to_buffer() fromfile File to read from buffpek Where to read from sort_length max length to read RESULT > 0 Ammount of bytes read -1 Error */ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, uint sort_length) Loading @@ -627,8 +672,10 @@ static uint NEAR_F read_to_buffer(IO_CACHE *fromfile, BUFFPEK *buffpek, } /* read_to_buffer */ /* Merge buffers to one buffer */ /* If to_file == 0 then use info->key_write */ /* Merge buffers to one buffer If to_file == 0 then use info->key_write */ static int NEAR_F merge_buffers(MI_SORT_PARAM *info, uint keys, IO_CACHE *from_file, Loading
myisammrg/myrg_delete.c +2 −4 Original line number Diff line number Diff line Loading @@ -18,12 +18,10 @@ #include "myrg_def.h" int myrg_delete( MYRG_INFO *info, const byte *record) int myrg_delete(MYRG_INFO *info, const byte *record) { if (!info->current_table) return my_errno=HA_ERR_NO_ACTIVE_RECORD ; return (my_errno= HA_ERR_NO_ACTIVE_RECORD); return mi_delete(info->current_table->table,record); }