Commit d714ba23 authored by serg@serg.mysql.com's avatar serg@serg.mysql.com

REPAIR ... USE_FRM

parent 48a96769
...@@ -17687,7 +17687,7 @@ to set the column to some other value than 0. ...@@ -17687,7 +17687,7 @@ to set the column to some other value than 0.
@findex REPAIR TABLE @findex REPAIR TABLE
@example @example
REPAIR TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED] REPAIR TABLE tbl_name[,tbl_name...] [QUICK] [EXTENDED] [USE_FRM]
@end example @end example
@code{REPAIR TABLE} only works on @code{MyISAM} tables and is the same @code{REPAIR TABLE} only works on @code{MyISAM} tables and is the same
...@@ -17724,6 +17724,10 @@ by row instead of creating one index at a time with sorting; This may be ...@@ -17724,6 +17724,10 @@ by row instead of creating one index at a time with sorting; This may be
better than sorting on fixed-length keys if you have long @code{char()} better than sorting on fixed-length keys if you have long @code{char()}
keys that compress very good. keys that compress very good.
As of MySQL 4.0.2 there is @code{USE_FRM} mode for @code{REPAIR}.
Use it if @code{.MYI} file is missing or its header is corrupted.
In this mode MySQL will recreate the table, using information from
@code{.frm} file. This kind of repair cannot be done with @code{myisamchk}.
@node Table maintenance, Maintenance regimen, REPAIR TABLE, Disaster Prevention @node Table maintenance, Maintenance regimen, REPAIR TABLE, Disaster Prevention
@subsection Using @code{myisamchk} for Table Maintenance and Crash Recovery @subsection Using @code{myisamchk} for Table Maintenance and Crash Recovery
...@@ -18387,6 +18391,9 @@ a copy in case something goes wrong.) ...@@ -18387,6 +18391,9 @@ a copy in case something goes wrong.)
Go back to Stage 2. @code{myisamchk -r -q} should work now. (This shouldn't Go back to Stage 2. @code{myisamchk -r -q} should work now. (This shouldn't
be an endless loop.) be an endless loop.)
As of MySQL 4.0.2 you can also use @code{REPAIR ... USE_FRM}
that does the whole procedure automatically.
@noindent @noindent
@strong{Stage 4: Very difficult repair} @strong{Stage 4: Very difficult repair}
...@@ -48761,6 +48768,8 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}. ...@@ -48761,6 +48768,8 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@itemize @bullet @itemize @bullet
@item @item
@code{REPAIR ... USE_FRM} added.
@item
Fixed bug with indexless boolean full-text search. Fixed bug with indexless boolean full-text search.
@item @item
Fixed bug that sometimes appeared when full-text search was used Fixed bug that sometimes appeared when full-text search was used
...@@ -295,7 +295,7 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def); ...@@ -295,7 +295,7 @@ extern uint mi_get_pointer_length(ulonglong file_length, uint def);
#define T_QUICK (1L << 30) #define T_QUICK (1L << 30)
#define T_RETRY_WITHOUT_QUICK (1L << 31) #define T_RETRY_WITHOUT_QUICK (1L << 31)
/* flags used by myisamchk.c or/and ha_myisam.cc that do NOT passed /* flags used by myisamchk.c or/and ha_myisam.cc that are NOT passed
* to mi_check.c follows: * to mi_check.c follows:
* */ * */
......
...@@ -870,7 +870,8 @@ static int send_check_errmsg(THD* thd, TABLE_LIST* table, ...@@ -870,7 +870,8 @@ static int send_check_errmsg(THD* thd, TABLE_LIST* table,
return 1; return 1;
} }
static int prepare_for_restore(THD* thd, TABLE_LIST* table) static int prepare_for_restore(THD* thd, TABLE_LIST* table,
HA_CHECK_OPT *check_opt)
{ {
DBUG_ENTER("prepare_for_restore"); DBUG_ENTER("prepare_for_restore");
...@@ -919,6 +920,57 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table) ...@@ -919,6 +920,57 @@ static int prepare_for_restore(THD* thd, TABLE_LIST* table)
DBUG_RETURN(0); DBUG_RETURN(0);
} }
static int prepare_for_repair(THD* thd, TABLE_LIST* table,
HA_CHECK_OPT *check_opt)
{
DBUG_ENTER("prepare_for_repair");
if (!(check_opt->sql_flags & TT_USEFRM))
{
DBUG_RETURN(0);
}
else
{
char from[FN_REFLEN],to[FN_REFLEN];
char* db = thd->db ? thd->db : table->db;
sprintf(from, "%s/%s/%s", mysql_real_data_home, db, table->name);
fn_format(from, from, "", MI_NAME_DEXT, 4);
sprintf(to,"%s-%lx_%lx", from, current_pid, thd->thread_id);
my_rename(to, from, MYF(MY_WME));
if (lock_and_wait_for_table_name(thd,table))
DBUG_RETURN(-1);
if (my_rename(from, to, MYF(MY_WME)))
{
unlock_table_name(thd, table);
DBUG_RETURN(send_check_errmsg(thd, table, "repair",
"Failed renaming .MYD file"));
}
if (mysql_truncate(thd, table, 1))
{
unlock_table_name(thd, table);
DBUG_RETURN(send_check_errmsg(thd, table, "repair",
"Failed generating table from .frm file"));
}
if (my_rename(to, from, MYF(MY_WME)))
{
unlock_table_name(thd, table);
DBUG_RETURN(send_check_errmsg(thd, table, "repair",
"Failed restoring .MYD file"));
}
}
// now we should be able to open the partially repaired table
// to finish the repair in the handler later on
if (!(table->table = reopen_name_locked_table(thd, table)))
unlock_table_name(thd, table);
DBUG_RETURN(0);
}
static int mysql_admin_table(THD* thd, TABLE_LIST* tables, static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
HA_CHECK_OPT* check_opt, HA_CHECK_OPT* check_opt,
...@@ -926,7 +978,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -926,7 +978,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
thr_lock_type lock_type, thr_lock_type lock_type,
bool open_for_modify, bool open_for_modify,
uint extra_open_options, uint extra_open_options,
int (*prepare_func)(THD *, TABLE_LIST *), int (*prepare_func)(THD *, TABLE_LIST *, HA_CHECK_OPT *),
int (handler::*operator_func) int (handler::*operator_func)
(THD *, HA_CHECK_OPT *)) (THD *, HA_CHECK_OPT *))
{ {
...@@ -960,7 +1012,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -960,7 +1012,7 @@ static int mysql_admin_table(THD* thd, TABLE_LIST* tables,
packet->length(0); packet->length(0);
if (prepare_func) if (prepare_func)
{ {
switch ((*prepare_func)(thd, table)) { switch ((*prepare_func)(thd, table, check_opt)) {
case 1: continue; // error, message written to net case 1: continue; // error, message written to net
case -1: goto err; // error, message could be written to net case -1: goto err; // error, message could be written to net
default: ; // should be 0 otherwise default: ; // should be 0 otherwise
...@@ -1106,7 +1158,8 @@ int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt) ...@@ -1106,7 +1158,8 @@ int mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
{ {
DBUG_ENTER("mysql_repair_table"); DBUG_ENTER("mysql_repair_table");
DBUG_RETURN(mysql_admin_table(thd, tables, check_opt, DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
"repair", TL_WRITE, 1, HA_OPEN_FOR_REPAIR, 0, "repair", TL_WRITE, 1, HA_OPEN_FOR_REPAIR,
&prepare_for_repair,
&handler::repair)); &handler::repair));
} }
......
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