mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Bug #11755431 (former 47205)
MAP 'REPAIR TABLE' TO RECREATE +ANALYZE FOR ENGINES NOT SUPPORTING NATIVE REPAIR Executing 'mysqlcheck --check-upgrade --auto-repair ...' will first issue 'CHECK TABLE FOR UPGRADE' for all tables in the database in order to check if the tables are compatible with the current version of MySQL. Any tables that are found incompatible are then upgraded using 'REPAIR TABLE'. The problem was that some engines (e.g. InnoDB) do not support 'REPAIR TABLE'. This caused any such tables to be left incompatible. As a result such tables were not properly fixed by the mysql_upgrade tool. This patch fixes the problem by first changing 'CHECK TABLE FOR UPGRADE' to return a different error message if the engine does not support REPAIR. Instead of "Table upgrade required. Please do "REPAIR TABLE ..." it will report "Table rebuild required. Please do "ALTER TABLE ... FORCE ..." Second, the patch changes mysqlcheck to do 'ALTER TABLE ... FORCE' instead of 'REPAIR TABLE' in these cases. This patch also fixes 'ALTER TABLE ... FORCE' to actually rebuild the table. This change should be reflected in the documentation. Before this patch, 'ALTER TABLE ... FORCE' was unused (See Bug#11746162) Test case added to mysqlcheck.test
This commit is contained in:
@ -42,7 +42,7 @@ static char *opt_password = 0, *current_user = 0,
|
||||
*default_charset= 0, *current_host= 0;
|
||||
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
|
||||
static int first_error = 0;
|
||||
DYNAMIC_ARRAY tables4repair;
|
||||
DYNAMIC_ARRAY tables4repair, tables4rebuild;
|
||||
#ifdef HAVE_SMEM
|
||||
static char *shared_memory_base_name=0;
|
||||
#endif
|
||||
@ -626,6 +626,27 @@ static int fix_database_storage_name(const char *name)
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int rebuild_table(char *name)
|
||||
{
|
||||
char *query, *ptr;
|
||||
int rc= 0;
|
||||
query= (char*)my_malloc(sizeof(char) * (12 + fixed_name_length(name) + 6 + 1),
|
||||
MYF(MY_WME));
|
||||
if (!query)
|
||||
return 1;
|
||||
ptr= strmov(query, "ALTER TABLE ");
|
||||
ptr= fix_table_name(ptr, name);
|
||||
ptr= strxmov(ptr, " FORCE", NullS);
|
||||
if (mysql_real_query(sock, query, (uint)(ptr - query)))
|
||||
{
|
||||
fprintf(stderr, "Failed to %s\n", query);
|
||||
fprintf(stderr, "Error: %s\n", mysql_error(sock));
|
||||
rc= 1;
|
||||
}
|
||||
my_free(query);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int process_one_db(char *database)
|
||||
{
|
||||
if (what_to_do == DO_UPGRADE)
|
||||
@ -739,7 +760,7 @@ static void print_result()
|
||||
MYSQL_ROW row;
|
||||
char prev[NAME_LEN*2+2];
|
||||
uint i;
|
||||
my_bool found_error=0;
|
||||
my_bool found_error=0, table_rebuild=0;
|
||||
|
||||
res = mysql_use_result(sock);
|
||||
|
||||
@ -758,8 +779,14 @@ static void print_result()
|
||||
*/
|
||||
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
|
||||
strcmp(row[3],"OK"))
|
||||
insert_dynamic(&tables4repair, (uchar*) prev);
|
||||
{
|
||||
if (table_rebuild)
|
||||
insert_dynamic(&tables4rebuild, (uchar*) prev);
|
||||
else
|
||||
insert_dynamic(&tables4repair, (uchar*) prev);
|
||||
}
|
||||
found_error=0;
|
||||
table_rebuild=0;
|
||||
if (opt_silent)
|
||||
continue;
|
||||
}
|
||||
@ -769,7 +796,11 @@ static void print_result()
|
||||
{
|
||||
printf("%s\n%-9s: %s", row[0], row[2], row[3]);
|
||||
if (strcmp(row[2],"note"))
|
||||
{
|
||||
found_error=1;
|
||||
if (opt_auto_repair && strstr(row[3], "ALTER TABLE") != NULL)
|
||||
table_rebuild=1;
|
||||
}
|
||||
}
|
||||
else
|
||||
printf("%-9s: %s", row[2], row[3]);
|
||||
@ -778,7 +809,12 @@ static void print_result()
|
||||
}
|
||||
/* add the last table to be repaired to the list */
|
||||
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
|
||||
insert_dynamic(&tables4repair, (uchar*) prev);
|
||||
{
|
||||
if (table_rebuild)
|
||||
insert_dynamic(&tables4rebuild, (uchar*) prev);
|
||||
else
|
||||
insert_dynamic(&tables4repair, (uchar*) prev);
|
||||
}
|
||||
mysql_free_result(res);
|
||||
}
|
||||
|
||||
@ -876,7 +912,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (opt_auto_repair &&
|
||||
my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64))
|
||||
(my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64) ||
|
||||
my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16,64)))
|
||||
{
|
||||
first_error = 1;
|
||||
goto end;
|
||||
@ -894,7 +931,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
uint i;
|
||||
|
||||
if (!opt_silent && tables4repair.elements)
|
||||
if (!opt_silent && (tables4repair.elements || tables4rebuild.elements))
|
||||
puts("\nRepairing tables");
|
||||
what_to_do = DO_REPAIR;
|
||||
for (i = 0; i < tables4repair.elements ; i++)
|
||||
@ -902,11 +939,16 @@ int main(int argc, char **argv)
|
||||
char *name= (char*) dynamic_array_ptr(&tables4repair, i);
|
||||
handle_request_for_tables(name, fixed_name_length(name));
|
||||
}
|
||||
for (i = 0; i < tables4rebuild.elements ; i++)
|
||||
rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i));
|
||||
}
|
||||
end:
|
||||
dbDisconnect(current_host);
|
||||
if (opt_auto_repair)
|
||||
{
|
||||
delete_dynamic(&tables4repair);
|
||||
delete_dynamic(&tables4rebuild);
|
||||
}
|
||||
my_free(opt_password);
|
||||
#ifdef HAVE_SMEM
|
||||
my_free(shared_memory_base_name);
|
||||
|
Reference in New Issue
Block a user