Commit f1baa629 authored by Ashish Agarwal's avatar Ashish Agarwal

BUG#11754145 - 45702: IMPOSSIBE TO SPECIFY MYISAM_SORT_BUFFER > 4GB

                      ON 64 BIT MACHINES

PROBLEM: When sorting index during repair of
         myisam tables, due to improper casting
         of buffer size variables value of myisam_
         sort_buffer_size is not set greater than
         4GB.

SOLUTION: Proper casting of buffer size variable.
          myisam_buffer_size changed to unsigned
          long long to handle size > 4GB on
          linux as well as windows.
parent 04f197c0
...@@ -401,14 +401,14 @@ typedef struct st_mi_check_param ...@@ -401,14 +401,14 @@ typedef struct st_mi_check_param
ulonglong max_data_file_length; ulonglong max_data_file_length;
ulonglong keys_in_use; ulonglong keys_in_use;
ulonglong max_record_length; ulonglong max_record_length;
ulonglong sort_buffer_length;
my_off_t search_after_block; my_off_t search_after_block;
my_off_t new_file_pos,key_file_blocks; my_off_t new_file_pos,key_file_blocks;
my_off_t keydata,totaldata,key_blocks,start_check_pos; my_off_t keydata,totaldata,key_blocks,start_check_pos;
ha_rows total_records,total_deleted; ha_rows total_records,total_deleted;
ha_checksum record_checksum,glob_crc; ha_checksum record_checksum,glob_crc;
ulonglong use_buffers; ulonglong use_buffers;
ulong read_buffer_length,write_buffer_length, ulong read_buffer_length, write_buffer_length, sort_key_blocks;
sort_buffer_length,sort_key_blocks;
uint out_flag,warning_printed,error_printed,verbose; uint out_flag,warning_printed,error_printed,verbose;
uint opt_sort_key,total_files,max_level; uint opt_sort_key,total_files,max_level;
uint testflag, key_cache_block_size; uint testflag, key_cache_block_size;
......
...@@ -77,10 +77,10 @@ static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG, ...@@ -77,10 +77,10 @@ static MYSQL_THDVAR_ULONG(repair_threads, PLUGIN_VAR_RQCMDARG,
"disables parallel repair", NULL, NULL, "disables parallel repair", NULL, NULL,
1, 1, ULONG_MAX, 1); 1, 1, ULONG_MAX, 1);
static MYSQL_THDVAR_ULONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG, static MYSQL_THDVAR_ULONGLONG(sort_buffer_size, PLUGIN_VAR_RQCMDARG,
"The buffer that is allocated when sorting the index when doing " "The buffer that is allocated when sorting the index when doing "
"a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE", NULL, NULL, "a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE", NULL, NULL,
8192*1024, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), ULONG_MAX, 1); 8192 * 1024, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), SIZE_T_MAX, 1);
static MYSQL_SYSVAR_BOOL(use_mmap, opt_myisam_use_mmap, PLUGIN_VAR_NOCMDARG, static MYSQL_SYSVAR_BOOL(use_mmap, opt_myisam_use_mmap, PLUGIN_VAR_NOCMDARG,
"Use memory mapping for reading and writing MyISAM tables", NULL, NULL, FALSE); "Use memory mapping for reading and writing MyISAM tables", NULL, NULL, FALSE);
......
...@@ -35,7 +35,6 @@ typedef struct st_ha_create_information HA_CREATE_INFO; ...@@ -35,7 +35,6 @@ typedef struct st_ha_create_information HA_CREATE_INFO;
#define HA_RECOVER_QUICK 8 /* Don't check rows in data file */ #define HA_RECOVER_QUICK 8 /* Don't check rows in data file */
#define HA_RECOVER_OFF 16 /* No automatic recover */ #define HA_RECOVER_OFF 16 /* No automatic recover */
extern ulong myisam_sort_buffer_size;
extern TYPELIB myisam_recover_typelib; extern TYPELIB myisam_recover_typelib;
extern const char *myisam_recover_names[]; extern const char *myisam_recover_names[];
extern ulonglong myisam_recover_options; extern ulonglong myisam_recover_options;
......
...@@ -2429,7 +2429,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info, ...@@ -2429,7 +2429,7 @@ int mi_repair_by_sort(MI_CHECK *param, register MI_INFO *info,
if (_create_index_by_sort(&sort_param, if (_create_index_by_sort(&sort_param,
(my_bool) (!(param->testflag & T_VERBOSE)), (my_bool) (!(param->testflag & T_VERBOSE)),
(uint) param->sort_buffer_length)) param->sort_buffer_length))
{ {
param->retry_repair=1; param->retry_repair=1;
goto err; goto err;
......
...@@ -297,9 +297,9 @@ static struct my_option my_long_options[] = ...@@ -297,9 +297,9 @@ static struct my_option my_long_options[] =
INT_MAX32, (long) MALLOC_OVERHEAD, (long) 1L, 0}, INT_MAX32, (long) MALLOC_OVERHEAD, (long) 1L, 0},
{ "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "", { "sort_buffer_size", OPT_SORT_BUFFER_SIZE, "",
&check_param.sort_buffer_length, &check_param.sort_buffer_length,
&check_param.sort_buffer_length, 0, GET_ULONG, REQUIRED_ARG, &check_param.sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
(long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD), (long) SORT_BUFFER_INIT, (long) (MIN_SORT_BUFFER + MALLOC_OVERHEAD),
ULONG_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0}, SIZE_T_MAX, (long) MALLOC_OVERHEAD, (long) 1L, 0},
{ "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "", { "sort_key_blocks", OPT_SORT_KEY_BLOCKS, "",
&check_param.sort_key_blocks, &check_param.sort_key_blocks,
&check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG, &check_param.sort_key_blocks, 0, GET_ULONG, REQUIRED_ARG,
......
...@@ -320,9 +320,10 @@ typedef struct st_mi_sort_param ...@@ -320,9 +320,10 @@ typedef struct st_mi_sort_param
*/ */
ulonglong unique[MI_MAX_KEY_SEG+1]; ulonglong unique[MI_MAX_KEY_SEG+1];
ulonglong notnull[MI_MAX_KEY_SEG+1]; ulonglong notnull[MI_MAX_KEY_SEG+1];
ulonglong sortbuff_size;
my_off_t pos,max_pos,filepos,start_recpos; my_off_t pos,max_pos,filepos,start_recpos;
uint key, key_length,real_key_length,sortbuff_size; uint key, key_length,real_key_length;
uint maxbuffers, keys, find_length, sort_keys_length; uint maxbuffers, keys, find_length, sort_keys_length;
my_bool fix_datafile, master; my_bool fix_datafile, master;
my_bool calc_checksum; /* calculate table checksum */ my_bool calc_checksum; /* calculate table checksum */
...@@ -771,7 +772,7 @@ pthread_handler_t thr_find_all_keys(void *arg); ...@@ -771,7 +772,7 @@ pthread_handler_t thr_find_all_keys(void *arg);
int flush_blocks(MI_CHECK *param, KEY_CACHE *key_cache, File file); int flush_blocks(MI_CHECK *param, KEY_CACHE *key_cache, File file);
int sort_write_record(MI_SORT_PARAM *sort_param); int sort_write_record(MI_SORT_PARAM *sort_param);
int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ulong); int _create_index_by_sort(MI_SORT_PARAM *info, my_bool no_messages, ulonglong);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -99,10 +99,11 @@ my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, uchar *bufs); ...@@ -99,10 +99,11 @@ my_var_write(MI_SORT_PARAM *info, IO_CACHE *to_file, uchar *bufs);
*/ */
int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
ulong sortbuff_size) ulonglong sortbuff_size)
{ {
int error,maxbuffer,skr; int error,maxbuffer,skr;
uint memavl,old_memavl,keys,sort_length; uint sort_length, keys;
ulonglong memavl, old_memavl;
DYNAMIC_ARRAY buffpek; DYNAMIC_ARRAY buffpek;
ha_rows records; ha_rows records;
uchar **sort_keys; uchar **sort_keys;
...@@ -134,6 +135,9 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages, ...@@ -134,6 +135,9 @@ int _create_index_by_sort(MI_SORT_PARAM *info,my_bool no_messages,
sort_length= info->key_length; sort_length= info->key_length;
LINT_INIT(keys); LINT_INIT(keys);
if ((memavl - sizeof(BUFFPEK)) / (sort_length + sizeof(char *)) > UINT_MAX32)
memavl= sizeof(BUFFPEK) + UINT_MAX32 * (sort_length + sizeof(char *));
while (memavl >= MIN_SORT_BUFFER) while (memavl >= MIN_SORT_BUFFER)
{ {
if ((records < UINT_MAX32) && if ((records < UINT_MAX32) &&
...@@ -308,7 +312,8 @@ pthread_handler_t thr_find_all_keys(void *arg) ...@@ -308,7 +312,8 @@ pthread_handler_t thr_find_all_keys(void *arg)
{ {
MI_SORT_PARAM *sort_param= (MI_SORT_PARAM*) arg; MI_SORT_PARAM *sort_param= (MI_SORT_PARAM*) arg;
int error; int error;
uint memavl,old_memavl,keys,sort_length; ulonglong memavl, old_memavl;
uint keys, sort_length;
uint idx, maxbuffer; uint idx, maxbuffer;
uchar **sort_keys=0; uchar **sort_keys=0;
...@@ -349,6 +354,10 @@ pthread_handler_t thr_find_all_keys(void *arg) ...@@ -349,6 +354,10 @@ pthread_handler_t thr_find_all_keys(void *arg)
sort_length= sort_param->key_length; sort_length= sort_param->key_length;
maxbuffer= 1; maxbuffer= 1;
if ((memavl - sizeof(BUFFPEK)) / (sort_length +
sizeof(char *)) > UINT_MAX32)
memavl= sizeof(BUFFPEK) + UINT_MAX32 * (sort_length + sizeof(char *));
while (memavl >= MIN_SORT_BUFFER) while (memavl >= MIN_SORT_BUFFER)
{ {
if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <=
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment