Commit 0d47945b authored by Monty's avatar Monty

Fixed bug in aria_chk that overwrote sort_buffer_length

This bug happens when one runs aria_chk on multiple tables. It does not
affect REPAIR TABLE.
aria_chk tries to optimize the sort buffer size to minimize memory usage
when used with small tables. The bug was that the adjusted value was
used as a base for the next table, which could cause problems.
parent b4f24c74
......@@ -87,7 +87,7 @@ typedef struct st_handler_check_param
/* Following is used to check if rows are visible */
ulonglong max_trid, max_found_trid;
ulonglong not_visible_rows_found;
ulonglong sort_buffer_length;
ulonglong sort_buffer_length, orig_sort_buffer_length;
ulonglong use_buffers; /* Used as param to getopt() */
size_t read_buffer_length, write_buffer_length, sort_key_blocks;
time_t backup_time; /* To sign backup files */
......
......@@ -434,8 +434,8 @@ static struct my_option my_long_options[] =
~0UL, (long) MALLOC_OVERHEAD, (long) 1L, 0},
{ "sort_buffer_size", OPT_SORT_BUFFER_SIZE,
"Size of sort buffer. Used by --recover",
&check_param.sort_buffer_length,
&check_param.sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
&check_param.orig_sort_buffer_length,
&check_param.orig_sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX, MALLOC_OVERHEAD, 1L, 0},
{ "sort_key_blocks", OPT_SORT_KEY_BLOCKS,
"Internal buffer for sorting keys; Don't touch :)",
......
......@@ -1481,7 +1481,7 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt)
param->testflag= ((check_opt->flags & ~(T_EXTEND)) |
T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM |
(check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size);
param->backup_time= check_opt->start_time;
start_records= file->state->records;
old_proc_info= thd_proc_info(thd, "Checking table");
......@@ -1552,7 +1552,7 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt)
param->thd= thd;
param->op_name= "zerofill";
param->testflag= check_opt->flags | T_SILENT | T_ZEROFILL;
param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size);
param->db_name= table->s->db.str;
param->table_name= table->alias.c_ptr();
......@@ -1588,7 +1588,7 @@ int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt)
param->op_name= "optimize";
param->testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE |
T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size);
thd_progress_init(thd, 1);
if ((error= repair(thd, param, 1)) && param->retry_repair)
{
......@@ -2056,7 +2056,7 @@ int ha_maria::enable_indexes(uint mode)
}
param->myf_rw &= ~MY_WAIT_IF_FULL;
param->sort_buffer_length= THDVAR(thd,sort_buffer_size);
param->orig_sort_buffer_length= THDVAR(thd,sort_buffer_size);
param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
param->tmpdir= &mysql_tmpdir_list;
if ((error= (repair(thd, param, 0) != HA_ADMIN_OK)) && param->retry_repair)
......
......@@ -114,7 +114,7 @@ void maria_chk_init(HA_CHECK *param)
param->use_buffers= PAGE_BUFFER_INIT;
param->read_buffer_length=READ_BUFFER_INIT;
param->write_buffer_length=READ_BUFFER_INIT;
param->sort_buffer_length=SORT_BUFFER_INIT;
param->orig_sort_buffer_length=SORT_BUFFER_INIT;
param->sort_key_blocks=BUFFERS_WHEN_SORTING;
param->tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
param->myf_rw=MYF(MY_NABP | MY_WME | MY_WAIT_IF_FULL);
......@@ -2483,6 +2483,8 @@ static int initialize_variables_for_repair(HA_CHECK *param,
tmp= (size_t) MY_MIN(sort_info->filelength,
(my_off_t) (SIZE_T_MAX/10/threads));
tmp= MY_MAX(tmp * 8 * threads, (size_t) 65536); /* Some margin */
param->sort_buffer_length= MY_MIN(param->orig_sort_buffer_length,
tmp);
set_if_smaller(param->sort_buffer_length, tmp);
/* Protect against too big sort buffer length */
#if SIZEOF_SIZE_T >= 8
......
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