mirror of
https://github.com/MariaDB/server.git
synced 2025-12-24 11:21:21 +03:00
merge with 5.1
This commit is contained in:
101
sql/sql_table.cc
101
sql/sql_table.cc
@@ -48,6 +48,7 @@ static int mysql_prepare_create_table(THD *, HA_CREATE_INFO *, Alter_info *,
|
||||
bool, uint *, handler *, KEY **, uint *, int);
|
||||
static bool mysql_prepare_alter_table(THD *, TABLE *, HA_CREATE_INFO *,
|
||||
Alter_info *);
|
||||
static bool admin_recreate_table(THD *thd, TABLE_LIST *table_list);
|
||||
|
||||
#ifndef DBUG_OFF
|
||||
|
||||
@@ -4219,7 +4220,7 @@ mysql_rename_table(handlerton *base, const char *old_db,
|
||||
char from[FN_REFLEN + 1], to[FN_REFLEN + 1],
|
||||
lc_from[FN_REFLEN + 1], lc_to[FN_REFLEN + 1];
|
||||
char *from_base= from, *to_base= to;
|
||||
char tmp_name[NAME_LEN+1];
|
||||
char tmp_name[SAFE_NAME_LEN+1];
|
||||
handler *file;
|
||||
int error=0;
|
||||
DBUG_ENTER("mysql_rename_table");
|
||||
@@ -4614,6 +4615,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
|
||||
Protocol *protocol= thd->protocol;
|
||||
LEX *lex= thd->lex;
|
||||
int result_code;
|
||||
bool need_repair_or_alter= 0;
|
||||
DBUG_ENTER("mysql_admin_table");
|
||||
|
||||
if (end_active_trans(thd))
|
||||
@@ -4634,7 +4636,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
|
||||
|
||||
for (table= tables; table; table= table->next_local)
|
||||
{
|
||||
char table_name[NAME_LEN*2+2];
|
||||
char table_name[SAFE_NAME_LEN*2+2];
|
||||
char* db = table->db;
|
||||
bool fatal_error=0;
|
||||
|
||||
@@ -4842,32 +4844,38 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
|
||||
if (operator_func == &handler::ha_repair &&
|
||||
!(check_opt->sql_flags & TT_USEFRM))
|
||||
{
|
||||
if ((table->table->file->check_old_types() == HA_ADMIN_NEEDS_ALTER) ||
|
||||
(table->table->file->ha_check_for_upgrade(check_opt) ==
|
||||
HA_ADMIN_NEEDS_ALTER))
|
||||
handler *file= table->table->file;
|
||||
int check_old_types= file->check_old_types();
|
||||
int check_for_upgrade= file->ha_check_for_upgrade(check_opt);
|
||||
|
||||
if (check_old_types == HA_ADMIN_NEEDS_ALTER ||
|
||||
check_for_upgrade == HA_ADMIN_NEEDS_ALTER)
|
||||
{
|
||||
DBUG_PRINT("admin", ("recreating table"));
|
||||
ha_autocommit_or_rollback(thd, 1);
|
||||
close_thread_tables(thd);
|
||||
tmp_disable_binlog(thd); // binlogging is done by caller if wanted
|
||||
result_code= mysql_recreate_table(thd, table);
|
||||
reenable_binlog(thd);
|
||||
/*
|
||||
mysql_recreate_table() can push OK or ERROR.
|
||||
Clear 'OK' status. If there is an error, keep it:
|
||||
we will store the error message in a result set row
|
||||
and then clear.
|
||||
*/
|
||||
if (thd->main_da.is_ok())
|
||||
thd->main_da.reset_diagnostics_area();
|
||||
/* We use extra_open_options to be able to open crashed tables */
|
||||
thd->open_options|= extra_open_options;
|
||||
result_code= admin_recreate_table(thd, table);
|
||||
thd->open_options= ~extra_open_options;
|
||||
goto send_result;
|
||||
}
|
||||
if (check_old_types || check_for_upgrade)
|
||||
{
|
||||
/* If repair is not implemented for the engine, run ALTER TABLE */
|
||||
need_repair_or_alter= 1;
|
||||
}
|
||||
}
|
||||
|
||||
DBUG_PRINT("admin", ("calling operator_func '%s'", operator_name));
|
||||
result_code = (table->table->file->*operator_func)(thd, check_opt);
|
||||
DBUG_PRINT("admin", ("operator_func returned: %d", result_code));
|
||||
|
||||
if (result_code == HA_ADMIN_NOT_IMPLEMENTED && need_repair_or_alter)
|
||||
{
|
||||
/*
|
||||
repair was not implemented and we need to upgrade the table
|
||||
to a new version so we recreate the table with ALTER TABLE
|
||||
*/
|
||||
result_code= admin_recreate_table(thd, table);
|
||||
}
|
||||
send_result:
|
||||
|
||||
lex->cleanup_after_one_table_open();
|
||||
@@ -4967,23 +4975,13 @@ send_result_message:
|
||||
system_charset_info);
|
||||
if (protocol->write())
|
||||
goto err;
|
||||
ha_autocommit_or_rollback(thd, 0);
|
||||
close_thread_tables(thd);
|
||||
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;
|
||||
tmp_disable_binlog(thd); // binlogging is done by caller if wanted
|
||||
result_code= mysql_recreate_table(thd, table);
|
||||
reenable_binlog(thd);
|
||||
/*
|
||||
mysql_recreate_table() can push OK or ERROR.
|
||||
Clear 'OK' status. If there is an error, keep it:
|
||||
we will store the error message in a result set row
|
||||
and then clear.
|
||||
*/
|
||||
if (thd->main_da.is_ok())
|
||||
thd->main_da.reset_diagnostics_area();
|
||||
|
||||
result_code= admin_recreate_table(thd, table);
|
||||
|
||||
ha_autocommit_or_rollback(thd, 0);
|
||||
close_thread_tables(thd);
|
||||
if (!result_code) // recreation went ok
|
||||
@@ -6973,6 +6971,14 @@ view_err:
|
||||
if (!error && (new_name != table_name || new_db != db))
|
||||
{
|
||||
thd_proc_info(thd, "rename");
|
||||
|
||||
/*
|
||||
Workaround InnoDB ending the transaction when the table instance
|
||||
is unlocked/closed (close_cached_table below), otherwise the trx
|
||||
state will differ between the server and storage engine layers.
|
||||
*/
|
||||
ha_autocommit_or_rollback(thd, 0);
|
||||
|
||||
/*
|
||||
Then do a 'simple' rename of the table. First we need to close all
|
||||
instances of 'source' table.
|
||||
@@ -7520,6 +7526,11 @@ view_err:
|
||||
mysql_unlock_tables(thd, thd->lock);
|
||||
thd->lock=0;
|
||||
}
|
||||
/*
|
||||
If LOCK TABLES list is not empty and contains this table,
|
||||
unlock the table and remove the table from this list.
|
||||
*/
|
||||
mysql_lock_remove(thd, thd->locked_tables, table, FALSE);
|
||||
/* Remove link to old table and rename the new one */
|
||||
close_temporary_table(thd, table, 1, 1);
|
||||
/* Should pass the 'new_name' as we store table name in the cache */
|
||||
@@ -8019,6 +8030,30 @@ err:
|
||||
}
|
||||
|
||||
|
||||
/* Prepare, run and cleanup for mysql_recreate_table() */
|
||||
|
||||
static bool admin_recreate_table(THD *thd, TABLE_LIST *table_list)
|
||||
{
|
||||
bool result_code;
|
||||
DBUG_ENTER("admin_recreate_table");
|
||||
|
||||
ha_autocommit_or_rollback(thd, 1);
|
||||
close_thread_tables(thd);
|
||||
tmp_disable_binlog(thd); // binlogging is done by caller if wanted
|
||||
result_code= mysql_recreate_table(thd, table_list);
|
||||
reenable_binlog(thd);
|
||||
/*
|
||||
mysql_recreate_table() can push OK or ERROR.
|
||||
Clear 'OK' status. If there is an error, keep it:
|
||||
we will store the error message in a result set row
|
||||
and then clear.
|
||||
*/
|
||||
if (thd->main_da.is_ok())
|
||||
thd->main_da.reset_diagnostics_area();
|
||||
DBUG_RETURN(result_code);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Recreates tables by calling mysql_alter_table().
|
||||
|
||||
@@ -8075,7 +8110,7 @@ bool mysql_checksum_table(THD *thd, TABLE_LIST *tables,
|
||||
/* Open one table after the other to keep lock time as short as possible. */
|
||||
for (table= tables; table; table= table->next_local)
|
||||
{
|
||||
char table_name[NAME_LEN*2+2];
|
||||
char table_name[SAFE_NAME_LEN*2+2];
|
||||
TABLE *t;
|
||||
|
||||
strxmov(table_name, table->db ,".", table->table_name, NullS);
|
||||
|
||||
Reference in New Issue
Block a user