YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/* table_list->tablehasbeenclosedandfreed.Donotreference uninitializeddata.open_tables()couldfail.
*/
table_list->table= NULL; /* Same applies to MDL ticket. */
table_list->mdl_request.ticket= NULL;
DEBUG_SYNC(thd, "ha_admin_try_alter");
tmp_disable_binlog(thd); // binlogging is done by caller if wanted /* Ignore if there is more than one table in the list */
save_next_global= table_list->next_global;
table_list->next_global= 0;
result_code= thd->check_and_open_tmp_table(table_list) ||
mysql_recreate_table(thd, table_list, recreate_info, table_copy);
table_list->next_global= save_next_global;
reenable_binlog(thd); /* mysql_recreate_table()canpushOKorERROR. Clear'OK'status.Ifthereisanerror,keepit: wewillstoretheerrormessageinaresultsetrow andthenclear.
*/ if (thd->get_stmt_da()->is_ok())
thd->get_stmt_da()->reset_diagnostics_area();
table_list->table= NULL;
DBUG_RETURN(result_code);
}
if (table->s->frm_version < FRM_VER_TRUE_VARCHAR &&
table->s->varchar_fields)
{
error= send_check_errmsg(thd, table_list, &msg_repair, "Failed repairing a very old .frm file as the " "data file format has changed between versions. " "Please dump the table in your old system with " "mysqldump and read it into this system with " "mysql or mysqlimport"); goto end;
}
/* Checkifthisisatabletypethatstoresindexanddataseparately, likeISAMorMyISAM.Weassumefixedorderofenginefilename extensionsarray.Firstelementofenginefilenameextensionsarray ismeta/indexfileextention.Secondelement-datafileextention.
*/
ext= table->file->bas_ext(); if (!ext[0] || !ext[1]) goto end; // No data file
/* A MERGE table must not come here. */
DBUG_ASSERT(table->file->ht->db_type != DB_TYPE_MRG_MYISAM);
// Name of data file
strxmov(from, table->s->normalized_path.str, ext[1], NullS); if (!mysql_file_stat(key_file_misc, from, &stat_info, MYF(0))) goto end; // Can't use USE_FRM flag
if (my_rename(from, tmp, MYF(MY_WME)))
{
error= send_check_errmsg(thd, table_list, &msg_repair, "Failed renaming data file"); goto end;
} if (dd_recreate_table(thd, table_list->db.str, table_list->table_name.str))
create_error= send_check_errmsg(thd, table_list, &msg_repair, "Failed generating table from .frm file"); /* 'FALSE'for'using_transactions'meansdon'tpostpone invalidationtilltheendofatransaction,butdoit immediately.
*/
query_cache_invalidate3(thd, table_list, FALSE); if (mysql_file_rename(key_file_misc, tmp, from, MYF(MY_WME)))
{
error= send_check_errmsg(thd, table_list, &msg_repair, "Failed restoring .MYD file"); goto end;
} if (create_error) goto end;
if (thd->locked_tables_list.locked_tables())
{ if (thd->locked_tables_list.reopen_tables(thd, false)) goto end; /* Restore the table in the table list with the new opened table */
table_list->table= pos_in_locked_tables->table;
} else
{ /* Nowweshouldbeabletoopenthepartiallyrepairedtable tofinishtherepairinthehandlerlateron.
*/ if (open_table(thd, table_list, &ot_ctx))
{
error= send_check_errmsg(thd, table_list, &msg_repair, "Failed to open partially repaired table"); goto end;
}
} /* Wehavenowfixedthetable.Howeverthefrmfileisstillofoldformat. Wecannotupdatethefrm_filetoFRM_VER_TRUE_VARCHARasthenewformat arenotcompatiblewiththedata.
*/
end:
thd->locked_tables_list.unlink_all_closed_tables(thd, NULL, 0); if (table == &tmp_table)
{
closefrm(table); if (share)
tdc_release_share(share);
} /* In case of a temporary table there will be no metadata lock. */ if (unlikely(error) && has_mdl_lock)
thd->release_transactional_locks();
/* open only one table from local list of command */ while (1)
{
open_error= open_only_one_table(thd, table,
no_errors_from_open,
(view_operator_func != NULL));
thd->open_options&= ~extra_open_options;
/* Ifopen_and_lock_tables()failed,close_thread_tables()willclose thetableandtable->tablecanthereforebeinvalid.
*/ if (unlikely(open_error))
table->table= NULL;
if (table->schema_table)
{
result_code= HA_ADMIN_NOT_IMPLEMENTED; goto send_result;
}
if (prepare_func)
{
DBUG_PRINT("admin", ("calling prepare_func")); switch ((*prepare_func)(thd, table, check_opt)) { case1: // error, message written to net
trans_rollback_stmt(thd);
trans_rollback(thd);
close_thread_tables(thd);
thd->release_transactional_locks();
DBUG_PRINT("admin", ("simple error, admin next table")); continue; case -1: // error, message could be written to net /* purecov: begin inspected */
DBUG_PRINT("admin", ("severe error, stop")); goto err; /* purecov: end */ default: // should be 0 otherwise
DBUG_PRINT("admin", ("prepare_func succeeded"));
;
}
}
/* CHECK/REPAIRTABLEcommandisonlycommandwhereVIEWallowedhereand thiscommanduseonlytemporarytablemethodforVIEWsresolving=> therecan'tbeVIEWtreesubstitutionofjoinview=>ifopeningtable succeedthentable->tablewillhaverealTABLEpointerasvalue(in caseofjoinviewsubstitutiontable->tablecanbe0,buthereitis impossible)
*/ if (!table->table)
{
DBUG_PRINT("admin", ("open table failed")); if (thd->get_stmt_da()->is_warning_info_empty())
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_CHECK_NO_SUCH_TABLE,
ER_THD(thd, ER_CHECK_NO_SUCH_TABLE)); /* if it was a view will check md5 sum */ if (table->view &&
view_check(thd, table, check_opt) == HA_ADMIN_WRONG_CHECKSUM)
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
ER_VIEW_CHECKSUM, ER_THD(thd, ER_VIEW_CHECKSUM)); if (thd->get_stmt_da()->is_error() &&
table_not_corrupt_error(thd->get_stmt_da()->sql_errno()))
result_code= HA_ADMIN_FAILED; else /* Default failure code is corrupt table */
result_code= HA_ADMIN_CORRUPT; goto send_result;
}
if (unlikely(!open_error))
{
TABLE *tab= table->table;
Field **field_ptr= tab->field;
MEM_ROOT_SAVEPOINT memroot_sv;
if (!lex->column_list)
{ /* Fields we have to read from the engine */
bitmap_clear_all(tab->read_set); /* Fields we want to have statistics for */
bitmap_clear_all(&tab->has_value_set);
/* Fields we have to read from the engine */
bitmap_clear_all(tab->read_set); /* Fields we want to have statistics for */
bitmap_clear_all(&tab->has_value_set);
while ((column_name= it++))
{
Field *field; enum enum_field_types type; if (tab->s->fieldnames.type_names == 0 ||
(pos= find_type(&tab->s->fieldnames, column_name->str,
column_name->length, 1)) <= 0)
{
compl_result_code= result_code= HA_ADMIN_INVALID; break;
}
pos--;
field= tab->field[pos];
type= field->type(); if (!(field->flags & LONG_UNIQUE_HASH_FIELD) &&
(type < MYSQL_TYPE_TINY_BLOB ||
type > MYSQL_TYPE_BLOB))
{
field->register_field_in_read_map();
bitmap_set_bit(&tab->has_value_set, field->field_index);
} else
push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN,
ER_NO_EIS_FOR_FIELD,
ER_THD(thd, ER_NO_EIS_FOR_FIELD),
column_name->str);
}
tab->file->column_bitmaps_signal(false);
} if (!lex->index_list)
tab->keys_in_use_for_query.init(tab->s->keys); else
{ int pos;
LEX_STRING *index_name;
List_iterator_fast<LEX_STRING> it(*lex->index_list);
tab->keys_in_use_for_query.clear_all(); while ((index_name= it++))
{ if (tab->s->keynames.type_names == 0 ||
(pos= find_type(&tab->s->keynames, index_name->str,
index_name->length, 1)) <= 0)
{
compl_result_code= result_code= HA_ADMIN_INVALID; break;
}
tab->keys_in_use_for_query.set_bit(--pos);
}
} /* Ensure that number of records are updated */
tab->file->info(HA_STATUS_VARIABLE);
root_make_savepoint(thd->mem_root, &memroot_sv); if (!(compl_result_code=
alloc_statistics_for_table(thd, tab,
&tab->has_value_set)) &&
!(compl_result_code=
collect_statistics_for_table(thd, tab)))
compl_result_code= update_statistics_for_table(thd, tab);
free_statistics_for_table(tab);
root_free_to_savepoint(&memroot_sv);
} else
compl_result_code= HA_ADMIN_FAILED;
case HA_ADMIN_OK:
protocol->store(&msg_status, system_charset_info);
protocol->store(STRING_WITH_LEN("OK"), system_charset_info); break;
case HA_ADMIN_FAILED:
protocol->store(&msg_status, system_charset_info);
protocol->store(STRING_WITH_LEN("Operation failed"),
system_charset_info); break;
case HA_ADMIN_REJECT:
protocol->store(&msg_status, system_charset_info);
protocol->store(STRING_WITH_LEN("Operation need committed state"),
system_charset_info);
open_for_modify= FALSE; break;
case HA_ADMIN_ALREADY_DONE:
protocol->store(&msg_status, system_charset_info);
protocol->store(STRING_WITH_LEN("Table is already up to date"),
system_charset_info); break;
case HA_ADMIN_CORRUPT:
protocol->store(&error_clex_str, system_charset_info);
protocol->store(STRING_WITH_LEN("Corrupt"), system_charset_info);
fatal_error=1; break;
case HA_ADMIN_INVALID:
protocol->store(&error_clex_str, system_charset_info);
protocol->store(STRING_WITH_LEN("Invalid argument"),
system_charset_info); break;
case HA_ADMIN_TRY_ALTER:
{
Alter_info *alter_info= &lex->alter_info;
protocol->store(STRING_WITH_LEN("note"), system_charset_info); if (alter_info->partition_flags & ALTER_PARTITION_ADMIN)
{
protocol->store(STRING_WITH_LEN( "Table does not support optimize on partitions. All partitions " "will be rebuilt and analyzed."),system_charset_info);
} else
{
protocol->store(STRING_WITH_LEN( "Table does not support optimize, doing recreate + analyze instead"),
system_charset_info);
} if (protocol->write()) goto err;
THD_STAGE_INFO(thd, stage_recreating_table);
DBUG_PRINT("info", ("HA_ADMIN_TRY_ALTER, trying analyze..."));
TABLE_LIST *save_next_local= table->next_local,
*save_next_global= table->next_global;
table->next_local= table->next_global= 0;
result_code= admin_recreate_table(thd, table, &recreate_info, 0);
recreate_used= 1;
trans_commit_stmt(thd);
trans_commit(thd);
thd->tmp_table_binlog_handled= 1;
close_thread_tables(thd);
thd->release_transactional_locks(); /* Clear references to TABLE and MDL_ticket after releasing them. */
table->mdl_request.ticket= NULL;
if (!result_code) // recreation went ok
{ /* Clear the ticket released above. */
table->mdl_request.ticket= NULL;
DEBUG_SYNC(thd, "ha_admin_open_ltable");
table->mdl_request.set_type(MDL_SHARED_WRITE); if (!thd->open_temporary_tables(table) &&
(table->table= open_ltable(thd, table, lock_type, 0)))
{
ulonglong save_flags; /* Store the original value of alter_info->flags */
save_flags= alter_info->flags;
/* ResettheALTER_PARTITION_ADMINbitinalter_info->flags toforceanalyzeonallpartitions.
*/
alter_info->partition_flags &= ~(ALTER_PARTITION_ADMIN);
result_code= table->table->file->ha_analyze(thd, check_opt); if (result_code == HA_ADMIN_ALREADY_DONE)
result_code= HA_ADMIN_OK; elseif (result_code) // analyze failed
table->table->file->print_error(result_code, MYF(0));
alter_info->flags= save_flags;
} else
result_code= -1; // open failed
} /* Start a new row for the final status row */
protocol->prepare_for_resend();
protocol->store(&table_name, system_charset_info);
protocol->store(operator_name, system_charset_info); if (result_code) // either mysql_recreate_table or analyze failed
{
DBUG_ASSERT(thd->is_error()); if (thd->is_error())
{ constchar *err_msg= thd->get_stmt_da()->message(); if (!thd->vio_ok())
{
sql_print_error("%s", err_msg);
} else
{ /* Hijack the row already in-progress. */
protocol->store(&error_clex_str, system_charset_info);
protocol->store(err_msg, strlen(err_msg), system_charset_info); if (protocol->write()) goto err; /* Start off another row for HA_ADMIN_FAILED */
protocol->prepare_for_resend();
protocol->store(&table_name, system_charset_info);
protocol->store(operator_name, system_charset_info);
}
thd->clear_error();
} /* Make sure this table instance is not reused after the operation. */ if (table->table)
table->table->mark_table_for_reopen();
}
result_code= result_code ? HA_ADMIN_FAILED : HA_ADMIN_OK;
table->next_local= save_next_local;
table->next_global= save_next_global; goto send_result_message;
} case HA_ADMIN_WRONG_CHECKSUM:
{
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
protocol->store(ER_THD(thd, ER_VIEW_CHECKSUM),
strlen(ER_THD(thd, ER_VIEW_CHECKSUM)),
system_charset_info); break;
}
case HA_ADMIN_NEEDS_UPGRADE: case HA_ADMIN_NEEDS_DATA_CONVERSION: case HA_ADMIN_NEEDS_ALTER:
{ char buf[MYSQL_ERRMSG_SIZE];
size_t length; constchar *what_to_upgrade= table->view ? "VIEW" :
table->table->file->ha_table_flags() & HA_CAN_REPAIR ? "TABLE" : 0;
if (protocol->write()) goto err;
DEBUG_SYNC(thd, "admin_command_kill_after_modify");
}
thd->resume_subsequent_commits(suspended_wfc);
DBUG_EXECUTE_IF("inject_analyze_table_sleep", my_sleep(500000);); if (is_table_modified && is_cmd_replicated && !thd->lex->no_write_to_binlog)
{
thd->get_stmt_da()->set_overwrite_status(true); auto res= write_bin_log(thd, true, thd->query(), thd->query_length());
thd->get_stmt_da()->set_overwrite_status(false); if (res) goto err;
} else
{ /* Wedecidedtonotlogthequerytobinlog. Wemarkthequeryasloggedtoensurethattemporarytablesarenot markedwith'mark_as_not_binlogged()'onclose.
*/
thd->tmp_table_binlog_handled= 1;
}
my_eof(thd);
DBUG_RETURN(FALSE);
err: /* Make sure this table instance is not reused after the failure. */
trans_rollback_stmt(thd); if (stmt_causes_implicit_commit(thd, CF_IMPLICIT_COMMIT_END))
trans_rollback(thd); if (table && table->table)
{
table->table->mark_table_for_reopen();
table->table->mark_as_not_binlogged();
table->table= 0;
}
close_thread_tables(thd); // Shouldn't be needed
thd->release_transactional_locks();
thd->resume_subsequent_commits(suspended_wfc);
DBUG_RETURN(TRUE);
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.24Bemerkung:
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.