Skip to content

Commit 0d47945

Browse files
committed
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.
1 parent b4f24c7 commit 0d47945

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

include/myisamchk.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ typedef struct st_handler_check_param
8787
/* Following is used to check if rows are visible */
8888
ulonglong max_trid, max_found_trid;
8989
ulonglong not_visible_rows_found;
90-
ulonglong sort_buffer_length;
90+
ulonglong sort_buffer_length, orig_sort_buffer_length;
9191
ulonglong use_buffers; /* Used as param to getopt() */
9292
size_t read_buffer_length, write_buffer_length, sort_key_blocks;
9393
time_t backup_time; /* To sign backup files */

storage/maria/aria_chk.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ static struct my_option my_long_options[] =
434434
~0UL, (long) MALLOC_OVERHEAD, (long) 1L, 0},
435435
{ "sort_buffer_size", OPT_SORT_BUFFER_SIZE,
436436
"Size of sort buffer. Used by --recover",
437-
&check_param.sort_buffer_length,
438-
&check_param.sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
437+
&check_param.orig_sort_buffer_length,
438+
&check_param.orig_sort_buffer_length, 0, GET_ULL, REQUIRED_ARG,
439439
SORT_BUFFER_INIT, MIN_SORT_BUFFER, SIZE_T_MAX, MALLOC_OVERHEAD, 1L, 0},
440440
{ "sort_key_blocks", OPT_SORT_KEY_BLOCKS,
441441
"Internal buffer for sorting keys; Don't touch :)",

storage/maria/ha_maria.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt)
14811481
param->testflag= ((check_opt->flags & ~(T_EXTEND)) |
14821482
T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM |
14831483
(check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
1484-
param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
1484+
param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size);
14851485
param->backup_time= check_opt->start_time;
14861486
start_records= file->state->records;
14871487
old_proc_info= thd_proc_info(thd, "Checking table");
@@ -1552,7 +1552,7 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt)
15521552
param->thd= thd;
15531553
param->op_name= "zerofill";
15541554
param->testflag= check_opt->flags | T_SILENT | T_ZEROFILL;
1555-
param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
1555+
param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size);
15561556
param->db_name= table->s->db.str;
15571557
param->table_name= table->alias.c_ptr();
15581558

@@ -1588,7 +1588,7 @@ int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt)
15881588
param->op_name= "optimize";
15891589
param->testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE |
15901590
T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
1591-
param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
1591+
param->orig_sort_buffer_length= THDVAR(thd, sort_buffer_size);
15921592
thd_progress_init(thd, 1);
15931593
if ((error= repair(thd, param, 1)) && param->retry_repair)
15941594
{
@@ -2056,7 +2056,7 @@ int ha_maria::enable_indexes(uint mode)
20562056
}
20572057

20582058
param->myf_rw &= ~MY_WAIT_IF_FULL;
2059-
param->sort_buffer_length= THDVAR(thd,sort_buffer_size);
2059+
param->orig_sort_buffer_length= THDVAR(thd,sort_buffer_size);
20602060
param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
20612061
param->tmpdir= &mysql_tmpdir_list;
20622062
if ((error= (repair(thd, param, 0) != HA_ADMIN_OK)) && param->retry_repair)

storage/maria/ma_check.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void maria_chk_init(HA_CHECK *param)
114114
param->use_buffers= PAGE_BUFFER_INIT;
115115
param->read_buffer_length=READ_BUFFER_INIT;
116116
param->write_buffer_length=READ_BUFFER_INIT;
117-
param->sort_buffer_length=SORT_BUFFER_INIT;
117+
param->orig_sort_buffer_length=SORT_BUFFER_INIT;
118118
param->sort_key_blocks=BUFFERS_WHEN_SORTING;
119119
param->tmpfile_createflag=O_RDWR | O_TRUNC | O_EXCL;
120120
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,
24832483
tmp= (size_t) MY_MIN(sort_info->filelength,
24842484
(my_off_t) (SIZE_T_MAX/10/threads));
24852485
tmp= MY_MAX(tmp * 8 * threads, (size_t) 65536); /* Some margin */
2486+
param->sort_buffer_length= MY_MIN(param->orig_sort_buffer_length,
2487+
tmp);
24862488
set_if_smaller(param->sort_buffer_length, tmp);
24872489
/* Protect against too big sort buffer length */
24882490
#if SIZEOF_SIZE_T >= 8

0 commit comments

Comments
 (0)