Commit 17a1b194 authored by Marko Mäkelä's avatar Marko Mäkelä

Fix some GCC 6.3.0 warnings in MyISAM and Maria.

The C++ standard does not allow references to be NULL.
Assign the return value of THD::alloc() to a pointer,
not to a reference.
parent 30cac41c
/* Copyright (C) 2004-2008 MySQL AB & MySQL Finland AB & TCX DataKonsult AB /* Copyright (C) 2004-2008 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
Copyright (C) 2008-2009 Sun Microsystems, Inc. Copyright (C) 2008-2009 Sun Microsystems, Inc.
Copyright (c) 2009, 2014, SkySQL Ab. Copyright (c) 2009, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -1271,75 +1271,75 @@ int ha_maria::write_row(uchar * buf) ...@@ -1271,75 +1271,75 @@ int ha_maria::write_row(uchar * buf)
int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
{ {
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
MARIA_SHARE *share= file->s; MARIA_SHARE *share= file->s;
const char *old_proc_info; const char *old_proc_info;
TRN *old_trn= file->trn; TRN *old_trn= file->trn;
if (!file || !&param) return HA_ADMIN_INTERNAL_ERROR; if (!file || !param) return HA_ADMIN_INTERNAL_ERROR;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "check"; param->op_name= "check";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->alias.c_ptr(); param->table_name= table->alias.c_ptr();
param.testflag= check_opt->flags | T_CHECK | T_SILENT; param->testflag= check_opt->flags | T_CHECK | T_SILENT;
param.stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method); param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
if (!(table->db_stat & HA_READ_ONLY)) if (!(table->db_stat & HA_READ_ONLY))
param.testflag |= T_STATISTICS; param->testflag |= T_STATISTICS;
param.using_global_keycache= 1; param->using_global_keycache= 1;
if (!maria_is_crashed(file) && if (!maria_is_crashed(file) &&
(((param.testflag & T_CHECK_ONLY_CHANGED) && (((param->testflag & T_CHECK_ONLY_CHANGED) &&
!(share->state.changed & (STATE_CHANGED | STATE_CRASHED_FLAGS | !(share->state.changed & (STATE_CHANGED | STATE_CRASHED_FLAGS |
STATE_IN_REPAIR)) && STATE_IN_REPAIR)) &&
share->state.open_count == 0) || share->state.open_count == 0) ||
((param.testflag & T_FAST) && (share->state.open_count == ((param->testflag & T_FAST) && (share->state.open_count ==
(uint) (share->global_changed ? 1 : (uint) (share->global_changed ? 1 :
0))))) 0)))))
return HA_ADMIN_ALREADY_DONE; return HA_ADMIN_ALREADY_DONE;
maria_chk_init_for_check(&param, file); maria_chk_init_for_check(param, file);
if ((file->s->state.changed & (STATE_CRASHED_FLAGS | STATE_MOVED)) == if ((file->s->state.changed & (STATE_CRASHED_FLAGS | STATE_MOVED)) ==
STATE_MOVED) STATE_MOVED)
{ {
_ma_check_print_error(&param, "%s", zerofill_error_msg); _ma_check_print_error(param, "%s", zerofill_error_msg);
return HA_ADMIN_CORRUPT; return HA_ADMIN_CORRUPT;
} }
old_proc_info= thd_proc_info(thd, "Checking status"); old_proc_info= thd_proc_info(thd, "Checking status");
thd_progress_init(thd, 3); thd_progress_init(thd, 3);
error= maria_chk_status(&param, file); // Not fatal error= maria_chk_status(param, file); // Not fatal
if (maria_chk_size(&param, file)) if (maria_chk_size(param, file))
error= 1; error= 1;
if (!error) if (!error)
error|= maria_chk_del(&param, file, param.testflag); error|= maria_chk_del(param, file, param->testflag);
thd_proc_info(thd, "Checking keys"); thd_proc_info(thd, "Checking keys");
thd_progress_next_stage(thd); thd_progress_next_stage(thd);
if (!error) if (!error)
error= maria_chk_key(&param, file); error= maria_chk_key(param, file);
thd_proc_info(thd, "Checking data"); thd_proc_info(thd, "Checking data");
thd_progress_next_stage(thd); thd_progress_next_stage(thd);
if (!error) if (!error)
{ {
if ((!(param.testflag & T_QUICK) && if ((!(param->testflag & T_QUICK) &&
((share->options & ((share->options &
(HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) || (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ||
(param.testflag & (T_EXTEND | T_MEDIUM)))) || maria_is_crashed(file)) (param->testflag & (T_EXTEND | T_MEDIUM)))) || maria_is_crashed(file))
{ {
ulonglong old_testflag= param.testflag; ulonglong old_testflag= param->testflag;
param.testflag |= T_MEDIUM; param->testflag |= T_MEDIUM;
if (!(error= init_io_cache(&param.read_cache, file->dfile.file, if (!(error= init_io_cache(&param->read_cache, file->dfile.file,
my_default_record_cache_size, READ_CACHE, my_default_record_cache_size, READ_CACHE,
share->pack.header_length, 1, MYF(MY_WME)))) share->pack.header_length, 1, MYF(MY_WME))))
{ {
error= maria_chk_data_link(&param, file, error= maria_chk_data_link(param, file,
test(param.testflag & T_EXTEND)); test(param->testflag & T_EXTEND));
end_io_cache(&(param.read_cache)); end_io_cache(&param->read_cache);
} }
param.testflag= old_testflag; param->testflag= old_testflag;
} }
} }
if (!error) if (!error)
...@@ -1347,7 +1347,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) ...@@ -1347,7 +1347,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
if ((share->state.changed & (STATE_CHANGED | if ((share->state.changed & (STATE_CHANGED |
STATE_CRASHED_FLAGS | STATE_CRASHED_FLAGS |
STATE_IN_REPAIR | STATE_NOT_ANALYZED)) || STATE_IN_REPAIR | STATE_NOT_ANALYZED)) ||
(param.testflag & T_STATISTICS) || maria_is_crashed(file)) (param->testflag & T_STATISTICS) || maria_is_crashed(file))
{ {
file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
mysql_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
...@@ -1355,7 +1355,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) ...@@ -1355,7 +1355,7 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED_FLAGS | share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED_FLAGS |
STATE_IN_REPAIR); STATE_IN_REPAIR);
if (!(table->db_stat & HA_READ_ONLY)) if (!(table->db_stat & HA_READ_ONLY))
error= maria_update_state_info(&param, file, error= maria_update_state_info(param, file,
UPDATE_TIME | UPDATE_OPEN_COUNT | UPDATE_TIME | UPDATE_OPEN_COUNT |
UPDATE_STAT); UPDATE_STAT);
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
...@@ -1386,33 +1386,33 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt) ...@@ -1386,33 +1386,33 @@ int ha_maria::check(THD * thd, HA_CHECK_OPT * check_opt)
int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt) int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt)
{ {
int error= 0; int error= 0;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
MARIA_SHARE *share= file->s; MARIA_SHARE *share= file->s;
const char *old_proc_info; const char *old_proc_info;
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "analyze"; param->op_name= "analyze";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->alias.c_ptr(); param->table_name= table->alias.c_ptr();
param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | param->testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
T_DONT_CHECK_CHECKSUM); T_DONT_CHECK_CHECKSUM);
param.using_global_keycache= 1; param->using_global_keycache= 1;
param.stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method); param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
if (!(share->state.changed & STATE_NOT_ANALYZED)) if (!(share->state.changed & STATE_NOT_ANALYZED))
return HA_ADMIN_ALREADY_DONE; return HA_ADMIN_ALREADY_DONE;
old_proc_info= thd_proc_info(thd, "Scanning"); old_proc_info= thd_proc_info(thd, "Scanning");
thd_progress_init(thd, 1); thd_progress_init(thd, 1);
error= maria_chk_key(&param, file); error= maria_chk_key(param, file);
if (!error) if (!error)
{ {
mysql_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
error= maria_update_state_info(&param, file, UPDATE_STAT); error= maria_update_state_info(param, file, UPDATE_STAT);
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
} }
else if (!maria_is_crashed(file) && !thd->killed) else if (!maria_is_crashed(file) && !thd->killed)
...@@ -1425,44 +1425,44 @@ int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt) ...@@ -1425,44 +1425,44 @@ int ha_maria::analyze(THD *thd, HA_CHECK_OPT * check_opt)
int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
ha_rows start_records; ha_rows start_records;
const char *old_proc_info; const char *old_proc_info;
if (!file || !&param) if (!file || !param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "repair"; param->op_name= "repair";
param.testflag= ((check_opt->flags & ~(T_EXTEND)) | param->testflag= ((check_opt->flags & ~(T_EXTEND)) |
T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM |
(check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
param.backup_time= check_opt->start_time; param->backup_time= check_opt->start_time;
start_records= file->state->records; start_records= file->state->records;
old_proc_info= thd_proc_info(thd, "Checking table"); old_proc_info= thd_proc_info(thd, "Checking table");
thd_progress_init(thd, 1); thd_progress_init(thd, 1);
while ((error= repair(thd, &param, 0)) && param.retry_repair) while ((error= repair(thd, param, 0)) && param->retry_repair)
{ {
param.retry_repair= 0; param->retry_repair= 0;
if (test_all_bits(param.testflag, if (test_all_bits(param->testflag,
(uint) (T_RETRY_WITHOUT_QUICK | T_QUICK))) (uint) (T_RETRY_WITHOUT_QUICK | T_QUICK)))
{ {
param.testflag&= ~(T_RETRY_WITHOUT_QUICK | T_QUICK); param->testflag&= ~(T_RETRY_WITHOUT_QUICK | T_QUICK);
/* Ensure we don't loose any rows when retrying without quick */ /* Ensure we don't loose any rows when retrying without quick */
param.testflag|= T_SAFE_REPAIR; param->testflag|= T_SAFE_REPAIR;
if (thd->vio_ok()) if (thd->vio_ok())
_ma_check_print_info(&param, "Retrying repair without quick"); _ma_check_print_info(param, "Retrying repair without quick");
else else
sql_print_information("Retrying repair of: '%s' without quick", sql_print_information("Retrying repair of: '%s' without quick",
table->s->path.str); table->s->path.str);
continue; continue;
} }
param.testflag &= ~T_QUICK; param->testflag &= ~T_QUICK;
if ((param.testflag & T_REP_BY_SORT)) if (param->testflag & T_REP_BY_SORT)
{ {
param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP; param->testflag= (param->testflag & ~T_REP_BY_SORT) | T_REP;
sql_print_information("Retrying repair of: '%s' with keycache", sql_print_information("Retrying repair of: '%s' with keycache",
table->s->path.str); table->s->path.str);
continue; continue;
...@@ -1486,20 +1486,20 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt) ...@@ -1486,20 +1486,20 @@ int ha_maria::repair(THD * thd, HA_CHECK_OPT *check_opt)
int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
TRN *old_trn; TRN *old_trn;
MARIA_SHARE *share= file->s; MARIA_SHARE *share= file->s;
if (!file || !&param) if (!file || !param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
old_trn= file->trn; old_trn= file->trn;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "zerofill"; param->op_name= "zerofill";
param.testflag= check_opt->flags | T_SILENT | T_ZEROFILL; param->testflag= check_opt->flags | T_SILENT | T_ZEROFILL;
param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
error=maria_zerofill(&param, file, share->open_file_name.str); error=maria_zerofill(param, file, share->open_file_name.str);
/* Reset trn, that may have been set by repair */ /* Reset trn, that may have been set by repair */
_ma_set_trn_for_table(file, old_trn); _ma_set_trn_for_table(file, old_trn);
...@@ -1509,7 +1509,7 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) ...@@ -1509,7 +1509,7 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt)
TrID create_trid= trnman_get_min_safe_trid(); TrID create_trid= trnman_get_min_safe_trid();
mysql_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
share->state.changed|= STATE_NOT_MOVABLE; share->state.changed|= STATE_NOT_MOVABLE;
maria_update_state_info(&param, file, UPDATE_TIME | UPDATE_OPEN_COUNT); maria_update_state_info(param, file, UPDATE_TIME | UPDATE_OPEN_COUNT);
_ma_update_state_lsns_sub(share, LSN_IMPOSSIBLE, create_trid, _ma_update_state_lsns_sub(share, LSN_IMPOSSIBLE, create_trid,
TRUE, TRUE); TRUE, TRUE);
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
...@@ -1520,24 +1520,24 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt) ...@@ -1520,24 +1520,24 @@ int ha_maria::zerofill(THD * thd, HA_CHECK_OPT *check_opt)
int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt) int ha_maria::optimize(THD * thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!file || !&param) if (!file || !param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "optimize"; param->op_name= "optimize";
param.testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE | param->testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE |
T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
thd_progress_init(thd, 1); thd_progress_init(thd, 1);
if ((error= repair(thd, &param, 1)) && param.retry_repair) if ((error= repair(thd, param, 1)) && param->retry_repair)
{ {
sql_print_warning("Warning: Optimize table got errno %d on %s.%s, retrying", sql_print_warning("Warning: Optimize table got errno %d on %s.%s, retrying",
my_errno, param.db_name, param.table_name); my_errno, param->db_name, param->table_name);
param.testflag &= ~T_REP_BY_SORT; param->testflag &= ~T_REP_BY_SORT;
error= repair(thd, &param, 0); error= repair(thd, param, 0);
} }
thd_progress_end(thd); thd_progress_end(thd);
return error; return error;
...@@ -1782,17 +1782,17 @@ int ha_maria::assign_to_keycache(THD * thd, HA_CHECK_OPT *check_opt) ...@@ -1782,17 +1782,17 @@ int ha_maria::assign_to_keycache(THD * thd, HA_CHECK_OPT *check_opt)
if (error != HA_ADMIN_OK) if (error != HA_ADMIN_OK)
{ {
/* Send error to user */ /* Send error to user */
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "assign_to_keycache"; param->op_name= "assign_to_keycache";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->s->table_name.str; param->table_name= table->s->table_name.str;
param.testflag= 0; param->testflag= 0;
_ma_check_print_error(&param, errmsg); _ma_check_print_error(param, errmsg);
} }
DBUG_RETURN(error); DBUG_RETURN(error);
#else #else
...@@ -1846,17 +1846,17 @@ int ha_maria::preload_keys(THD * thd, HA_CHECK_OPT *check_opt) ...@@ -1846,17 +1846,17 @@ int ha_maria::preload_keys(THD * thd, HA_CHECK_OPT *check_opt)
errmsg= buf; errmsg= buf;
} }
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
maria_chk_init(&param); maria_chk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "preload_keys"; param->op_name= "preload_keys";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->s->table_name.str; param->table_name= table->s->table_name.str;
param.testflag= 0; param->testflag= 0;
_ma_check_print_error(&param, "%s", errmsg); _ma_check_print_error(param, "%s", errmsg);
DBUG_RETURN(HA_ADMIN_FAILED); DBUG_RETURN(HA_ADMIN_FAILED);
} }
DBUG_RETURN(HA_ADMIN_OK); DBUG_RETURN(HA_ADMIN_OK);
...@@ -1957,22 +1957,22 @@ int ha_maria::enable_indexes(uint mode) ...@@ -1957,22 +1957,22 @@ int ha_maria::enable_indexes(uint mode)
else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE) else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE)
{ {
THD *thd= table->in_use; THD *thd= table->in_use;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
const char *save_proc_info= thd_proc_info(thd, "Creating index"); const char *save_proc_info= thd_proc_info(thd, "Creating index");
maria_chk_init(&param); maria_chk_init(param);
param.op_name= "recreating_index"; param->op_name= "recreating_index";
param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | param->testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
T_CREATE_MISSING_KEYS | T_SAFE_REPAIR); T_CREATE_MISSING_KEYS | T_SAFE_REPAIR);
/* /*
Don't lock and unlock table if it's locked. Don't lock and unlock table if it's locked.
Normally table should be locked. This test is mostly for safety. Normally table should be locked. This test is mostly for safety.
*/ */
if (likely(file->lock_type != F_UNLCK)) if (likely(file->lock_type != F_UNLCK))
param.testflag|= T_NO_LOCKS; param->testflag|= T_NO_LOCKS;
if (bulk_insert_single_undo == BULK_INSERT_SINGLE_UNDO_AND_NO_REPAIR) if (bulk_insert_single_undo == BULK_INSERT_SINGLE_UNDO_AND_NO_REPAIR)
{ {
...@@ -1981,23 +1981,23 @@ int ha_maria::enable_indexes(uint mode) ...@@ -1981,23 +1981,23 @@ int ha_maria::enable_indexes(uint mode)
Don't bump create_rename_lsn, because UNDO_BULK_INSERT Don't bump create_rename_lsn, because UNDO_BULK_INSERT
should not be skipped in case of crash during repair. should not be skipped in case of crash during repair.
*/ */
param.testflag|= T_NO_CREATE_RENAME_LSN; param->testflag|= T_NO_CREATE_RENAME_LSN;
} }
param.myf_rw &= ~MY_WAIT_IF_FULL; param->myf_rw &= ~MY_WAIT_IF_FULL;
param.sort_buffer_length= THDVAR(thd,sort_buffer_size); param->sort_buffer_length= THDVAR(thd,sort_buffer_size);
param.stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method); param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
param.tmpdir= &mysql_tmpdir_list; param->tmpdir= &mysql_tmpdir_list;
if ((error= (repair(thd, &param, 0) != HA_ADMIN_OK)) && param.retry_repair) if ((error= (repair(thd, param, 0) != HA_ADMIN_OK)) && param->retry_repair)
{ {
sql_print_warning("Warning: Enabling keys got errno %d on %s.%s, " sql_print_warning("Warning: Enabling keys got errno %d on %s.%s, "
"retrying", "retrying",
my_errno, param.db_name, param.table_name); my_errno, param->db_name, param->table_name);
/* This should never fail normally */ /* This should never fail normally */
DBUG_ASSERT(thd->killed != 0); DBUG_ASSERT(thd->killed != 0);
/* Repairing by sort failed. Now try standard repair method. */ /* Repairing by sort failed. Now try standard repair method. */
param.testflag &= ~T_REP_BY_SORT; param->testflag &= ~T_REP_BY_SORT;
error= (repair(thd, &param, 0) != HA_ADMIN_OK); error= (repair(thd, param, 0) != HA_ADMIN_OK);
/* /*
If the standard repair succeeded, clear all error messages which If the standard repair succeeded, clear all error messages which
might have been set by the first repair. They can still be seen might have been set by the first repair. They can still be seen
......
/* /*
Copyright (c) 2000, 2012, Oracle and/or its affiliates. Copyright (c) 2000, 2012, Oracle and/or its affiliates.
Copyright (c) 2009, 2014, SkySQL Ab. Copyright (c) 2009, 2017, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -856,59 +856,59 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -856,59 +856,59 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
{ {
if (!file) return HA_ADMIN_INTERNAL_ERROR; if (!file) return HA_ADMIN_INTERNAL_ERROR;
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
const char *old_proc_info=thd->proc_info; const char *old_proc_info=thd->proc_info;
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
thd_proc_info(thd, "Checking table"); thd_proc_info(thd, "Checking table");
myisamchk_init(&param); myisamchk_init(param);
param.thd = thd; param->thd = thd;
param.op_name = "check"; param->op_name = "check";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->alias.c_ptr(); param->table_name= table->alias.c_ptr();
param.testflag = check_opt->flags | T_CHECK | T_SILENT; param->testflag = check_opt->flags | T_CHECK | T_SILENT;
param.stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method); param->stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method);
if (!(table->db_stat & HA_READ_ONLY)) if (!(table->db_stat & HA_READ_ONLY))
param.testflag|= T_STATISTICS; param->testflag|= T_STATISTICS;
param.using_global_keycache = 1; param->using_global_keycache = 1;
if (!mi_is_crashed(file) && if (!mi_is_crashed(file) &&
(((param.testflag & T_CHECK_ONLY_CHANGED) && (((param->testflag & T_CHECK_ONLY_CHANGED) &&
!(share->state.changed & (STATE_CHANGED | STATE_CRASHED | !(share->state.changed & (STATE_CHANGED | STATE_CRASHED |
STATE_CRASHED_ON_REPAIR)) && STATE_CRASHED_ON_REPAIR)) &&
share->state.open_count == 0) || share->state.open_count == 0) ||
((param.testflag & T_FAST) && (share->state.open_count == ((param->testflag & T_FAST) && (share->state.open_count ==
(uint) (share->global_changed ? 1 : 0))))) (uint) (share->global_changed ? 1 : 0)))))
return HA_ADMIN_ALREADY_DONE; return HA_ADMIN_ALREADY_DONE;
error = chk_status(&param, file); // Not fatal error = chk_status(param, file); // Not fatal
error = chk_size(&param, file); error = chk_size(param, file);
if (!error) if (!error)
error |= chk_del(&param, file, param.testflag); error |= chk_del(param, file, param->testflag);
if (!error) if (!error)
error = chk_key(&param, file); error = chk_key(param, file);
if (!error) if (!error)
{ {
if ((!(param.testflag & T_QUICK) && if ((!(param->testflag & T_QUICK) &&
((share->options & ((share->options &
(HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) || (HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) ||
(param.testflag & (T_EXTEND | T_MEDIUM)))) || (param->testflag & (T_EXTEND | T_MEDIUM)))) ||
mi_is_crashed(file)) mi_is_crashed(file))
{ {
ulonglong old_testflag= param.testflag; ulonglong old_testflag= param->testflag;
param.testflag|=T_MEDIUM; param->testflag|=T_MEDIUM;
if (!(error= init_io_cache(&param.read_cache, file->dfile, if (!(error= init_io_cache(&param->read_cache, file->dfile,
my_default_record_cache_size, READ_CACHE, my_default_record_cache_size, READ_CACHE,
share->pack.header_length, 1, MYF(MY_WME)))) share->pack.header_length, 1, MYF(MY_WME))))
{ {
error= chk_data_link(&param, file, test(param.testflag & T_EXTEND)); error= chk_data_link(param, file, test(param->testflag & T_EXTEND));
end_io_cache(&(param.read_cache)); end_io_cache(&(param->read_cache));
} }
param.testflag= old_testflag; param->testflag= old_testflag;
} }
} }
if (!error) if (!error)
...@@ -916,7 +916,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -916,7 +916,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
if ((share->state.changed & (STATE_CHANGED | if ((share->state.changed & (STATE_CHANGED |
STATE_CRASHED_ON_REPAIR | STATE_CRASHED_ON_REPAIR |
STATE_CRASHED | STATE_NOT_ANALYZED)) || STATE_CRASHED | STATE_NOT_ANALYZED)) ||
(param.testflag & T_STATISTICS) || (param->testflag & T_STATISTICS) ||
mi_is_crashed(file)) mi_is_crashed(file))
{ {
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
...@@ -924,7 +924,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -924,7 +924,7 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED |
STATE_CRASHED_ON_REPAIR); STATE_CRASHED_ON_REPAIR);
if (!(table->db_stat & HA_READ_ONLY)) if (!(table->db_stat & HA_READ_ONLY))
error=update_state_info(&param,file,UPDATE_TIME | UPDATE_OPEN_COUNT | error=update_state_info(param,file,UPDATE_TIME | UPDATE_OPEN_COUNT |
UPDATE_STAT); UPDATE_STAT);
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE |
...@@ -951,30 +951,30 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt) ...@@ -951,30 +951,30 @@ int ha_myisam::check(THD* thd, HA_CHECK_OPT* check_opt)
int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
{ {
int error=0; int error=0;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
MYISAM_SHARE* share = file->s; MYISAM_SHARE* share = file->s;
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
myisamchk_init(&param); myisamchk_init(param);
param.thd = thd; param->thd = thd;
param.op_name= "analyze"; param->op_name= "analyze";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->alias.c_ptr(); param->table_name= table->alias.c_ptr();
param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | param->testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS |
T_DONT_CHECK_CHECKSUM); T_DONT_CHECK_CHECKSUM);
param.using_global_keycache = 1; param->using_global_keycache = 1;
param.stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method); param->stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method);
if (!(share->state.changed & STATE_NOT_ANALYZED)) if (!(share->state.changed & STATE_NOT_ANALYZED))
return HA_ADMIN_ALREADY_DONE; return HA_ADMIN_ALREADY_DONE;
error = chk_key(&param, file); error = chk_key(param, file);
if (!error) if (!error)
{ {
mysql_mutex_lock(&share->intern_lock); mysql_mutex_lock(&share->intern_lock);
error=update_state_info(&param,file,UPDATE_STAT); error=update_state_info(param,file,UPDATE_STAT);
mysql_mutex_unlock(&share->intern_lock); mysql_mutex_unlock(&share->intern_lock);
} }
else if (!mi_is_crashed(file) && !thd->killed) else if (!mi_is_crashed(file) && !thd->killed)
...@@ -986,37 +986,37 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt) ...@@ -986,37 +986,37 @@ int ha_myisam::analyze(THD *thd, HA_CHECK_OPT* check_opt)
int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
ha_rows start_records; ha_rows start_records;
if (!file || !&param) return HA_ADMIN_INTERNAL_ERROR; if (!file || !param) return HA_ADMIN_INTERNAL_ERROR;
myisamchk_init(&param); myisamchk_init(param);
param.thd = thd; param->thd = thd;
param.op_name= "repair"; param->op_name= "repair";
param.testflag= ((check_opt->flags & ~(T_EXTEND)) | param->testflag= ((check_opt->flags & ~(T_EXTEND)) |
T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM |
(check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); (check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT));
param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
param.backup_time= check_opt->start_time; param->backup_time= check_opt->start_time;
start_records=file->state->records; start_records=file->state->records;
while ((error=repair(thd,param,0)) && param.retry_repair) while ((error=repair(thd,*param,0)) && param->retry_repair)
{ {
param.retry_repair=0; param->retry_repair=0;
if (test_all_bits(param.testflag, if (test_all_bits(param->testflag,
(uint) (T_RETRY_WITHOUT_QUICK | T_QUICK))) (uint) (T_RETRY_WITHOUT_QUICK | T_QUICK)))
{ {
param.testflag&= ~(T_RETRY_WITHOUT_QUICK | T_QUICK); param->testflag&= ~(T_RETRY_WITHOUT_QUICK | T_QUICK);
/* Ensure we don't loose any rows when retrying without quick */ /* Ensure we don't loose any rows when retrying without quick */
param.testflag|= T_SAFE_REPAIR; param->testflag|= T_SAFE_REPAIR;
sql_print_information("Retrying repair of: '%s' including modifying data file", sql_print_information("Retrying repair of: '%s' including modifying data file",
table->s->path.str); table->s->path.str);
continue; continue;
} }
param.testflag&= ~T_QUICK; param->testflag&= ~T_QUICK;
if ((param.testflag & T_REP_BY_SORT)) if ((param->testflag & T_REP_BY_SORT))
{ {
param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP; param->testflag= (param->testflag & ~T_REP_BY_SORT) | T_REP;
sql_print_information("Retrying repair of: '%s' with keycache", sql_print_information("Retrying repair of: '%s' with keycache",
table->s->path.str); table->s->path.str);
continue; continue;
...@@ -1038,22 +1038,22 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt) ...@@ -1038,22 +1038,22 @@ int ha_myisam::repair(THD* thd, HA_CHECK_OPT *check_opt)
int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt) int ha_myisam::optimize(THD* thd, HA_CHECK_OPT *check_opt)
{ {
int error; int error;
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!file || !&param) return HA_ADMIN_INTERNAL_ERROR; if (!file || !param) return HA_ADMIN_INTERNAL_ERROR;
myisamchk_init(&param); myisamchk_init(param);
param.thd = thd; param->thd = thd;
param.op_name= "optimize"; param->op_name= "optimize";
param.testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE | param->testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE |
T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX);
param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
if ((error= repair(thd,param,1)) && param.retry_repair) if ((error= repair(thd,*param,1)) && param->retry_repair)
{ {
sql_print_warning("Warning: Optimize table got errno %d on %s.%s, retrying", sql_print_warning("Warning: Optimize table got errno %d on %s.%s, retrying",
my_errno, param.db_name, param.table_name); my_errno, param->db_name, param->table_name);
param.testflag&= ~T_REP_BY_SORT; param->testflag&= ~T_REP_BY_SORT;
error= repair(thd,param,1); error= repair(thd,*param,1);
} }
return error; return error;
} }
...@@ -1253,17 +1253,17 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt) ...@@ -1253,17 +1253,17 @@ int ha_myisam::assign_to_keycache(THD* thd, HA_CHECK_OPT *check_opt)
if (error != HA_ADMIN_OK) if (error != HA_ADMIN_OK)
{ {
/* Send error to user */ /* Send error to user */
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
myisamchk_init(&param); myisamchk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "assign_to_keycache"; param->op_name= "assign_to_keycache";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->s->table_name.str; param->table_name= table->s->table_name.str;
param.testflag= 0; param->testflag= 0;
mi_check_print_error(&param, errmsg); mi_check_print_error(param, errmsg);
} }
DBUG_RETURN(error); DBUG_RETURN(error);
} }
...@@ -1320,16 +1320,16 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt) ...@@ -1320,16 +1320,16 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
err: err:
{ {
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
if (!&param) if (!param)
return HA_ADMIN_INTERNAL_ERROR; return HA_ADMIN_INTERNAL_ERROR;
myisamchk_init(&param); myisamchk_init(param);
param.thd= thd; param->thd= thd;
param.op_name= "preload_keys"; param->op_name= "preload_keys";
param.db_name= table->s->db.str; param->db_name= table->s->db.str;
param.table_name= table->s->table_name.str; param->table_name= table->s->table_name.str;
param.testflag= 0; param->testflag= 0;
mi_check_print_error(&param, errmsg); mi_check_print_error(param, errmsg);
DBUG_RETURN(error); DBUG_RETURN(error);
} }
} }
...@@ -1434,42 +1434,42 @@ int ha_myisam::enable_indexes(uint mode) ...@@ -1434,42 +1434,42 @@ int ha_myisam::enable_indexes(uint mode)
{ {
THD *thd= table->in_use; THD *thd= table->in_use;
int was_error= thd->is_error(); int was_error= thd->is_error();
HA_CHECK &param= *(HA_CHECK*) thd->alloc(sizeof(param)); HA_CHECK *param= (HA_CHECK*) thd->alloc(sizeof *param);
const char *save_proc_info=thd->proc_info; const char *save_proc_info=thd->proc_info;
if (!&param) if (!param)
DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR); DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);
thd_proc_info(thd, "Creating index"); thd_proc_info(thd, "Creating index");
myisamchk_init(&param); myisamchk_init(param);
param.op_name= "recreating_index"; param->op_name= "recreating_index";
param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | param->testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
T_CREATE_MISSING_KEYS); T_CREATE_MISSING_KEYS);
/* /*
Don't lock and unlock table if it's locked. Don't lock and unlock table if it's locked.
Normally table should be locked. This test is mostly for safety. Normally table should be locked. This test is mostly for safety.
*/ */
if (likely(file->lock_type != F_UNLCK)) if (likely(file->lock_type != F_UNLCK))
param.testflag|= T_NO_LOCKS; param->testflag|= T_NO_LOCKS;
param.myf_rw&= ~MY_WAIT_IF_FULL; param->myf_rw&= ~MY_WAIT_IF_FULL;
param.sort_buffer_length= THDVAR(thd, sort_buffer_size); param->sort_buffer_length= THDVAR(thd, sort_buffer_size);
param.stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method); param->stats_method= (enum_handler_stats_method)THDVAR(thd, stats_method);
param.tmpdir=&mysql_tmpdir_list; param->tmpdir=&mysql_tmpdir_list;
if ((error= (repair(thd,param,0) != HA_ADMIN_OK)) && param.retry_repair) if ((error= (repair(thd,*param,0) != HA_ADMIN_OK)) && param->retry_repair)
{ {
sql_print_warning("Warning: Enabling keys got errno %d on %s.%s, retrying", sql_print_warning("Warning: Enabling keys got errno %d on %s.%s, retrying",
my_errno, param.db_name, param.table_name); my_errno, param->db_name, param->table_name);
/* /*
Repairing by sort failed. Now try standard repair method. Repairing by sort failed. Now try standard repair method.
Still we want to fix only index file. If data file corruption Still we want to fix only index file. If data file corruption
was detected (T_RETRY_WITHOUT_QUICK), we shouldn't do much here. was detected (T_RETRY_WITHOUT_QUICK), we shouldn't do much here.
Let implicit repair do this job. Let implicit repair do this job.
*/ */
if (!(param.testflag & T_RETRY_WITHOUT_QUICK)) if (!(param->testflag & T_RETRY_WITHOUT_QUICK))
{ {
param.testflag&= ~T_REP_BY_SORT; param->testflag&= ~T_REP_BY_SORT;
error= (repair(thd,param,0) != HA_ADMIN_OK); error= (repair(thd,*param,0) != HA_ADMIN_OK);
} }
/* /*
If the standard repair succeeded, clear all error messages which If the standard repair succeeded, clear all error messages which
......
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