Patch contributed by Jocelyn Fournier. CLA received 2007-02-27.

Bug#25347: mysqlcheck -A -r doesn't repair table marked as crashed

mysqlcheck tests nullness of the engine type to know whether the
"table" is a view or not.  That also falsely catches tables that 
are severly damaged.

Instead, use SHOW FULL TABLES to test whether a "table" is a view
or not.

(Don't add new function.  Instead, get original data a smarter way.)

Make it safe for use against databases before when views appeared.
parent c13d726f
...@@ -483,14 +483,17 @@ static int process_all_tables_in_db(char *database) ...@@ -483,14 +483,17 @@ static int process_all_tables_in_db(char *database)
{ {
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
uint num_columns;
LINT_INIT(res); LINT_INIT(res);
if (use_db(database)) if (use_db(database))
return 1; return 1;
if (mysql_query(sock, "SHOW TABLE STATUS") || if (mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") ||
!((res= mysql_store_result(sock)))) !((res= mysql_store_result(sock))))
return 1; return 1;
num_columns= mysql_num_fields(res);
if (opt_all_in_1) if (opt_all_in_1)
{ {
/* /*
...@@ -513,13 +516,12 @@ static int process_all_tables_in_db(char *database) ...@@ -513,13 +516,12 @@ static int process_all_tables_in_db(char *database)
} }
for (end = tables + 1; (row = mysql_fetch_row(res)) ;) for (end = tables + 1; (row = mysql_fetch_row(res)) ;)
{ {
/* Skip tables with an engine of NULL (probably a view). */ if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
if (row[1]) continue;
{
end= fix_table_name(end, row[0]); end= fix_table_name(end, row[0]);
*end++= ','; *end++= ',';
} }
}
*--end = 0; *--end = 0;
if (tot_length) if (tot_length)
handle_request_for_tables(tables + 1, tot_length - 1); handle_request_for_tables(tables + 1, tot_length - 1);
...@@ -531,6 +533,9 @@ static int process_all_tables_in_db(char *database) ...@@ -531,6 +533,9 @@ static int process_all_tables_in_db(char *database)
/* Skip tables with an engine of NULL (probably a view). */ /* Skip tables with an engine of NULL (probably a view). */
if (row[1]) if (row[1])
{ {
if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
continue;
handle_request_for_tables(row[0], fixed_name_length(row[0])); handle_request_for_tables(row[0], fixed_name_length(row[0]));
} }
} }
......
...@@ -46,4 +46,14 @@ create table `t 1`(a int); ...@@ -46,4 +46,14 @@ create table `t 1`(a int);
test.t 1 OK test.t 1 OK
test.t`1 OK test.t`1 OK
drop table `t``1`, `t 1`; drop table `t``1`, `t 1`;
create database d_bug25347;
use d_bug25347;
create table t_bug25347 (a int);
create view v_bug25347 as select * from t_bug25347;
removing and creating
d_bug25347.t_bug25347 OK
drop view v_bug25347;
drop table t_bug25347;
drop database d_bug25347;
use test;
End of 5.0 tests End of 5.0 tests
...@@ -40,4 +40,20 @@ create table `t 1`(a int); ...@@ -40,4 +40,20 @@ create table `t 1`(a int);
--exec $MYSQL_CHECK --databases test --exec $MYSQL_CHECK --databases test
drop table `t``1`, `t 1`; drop table `t``1`, `t 1`;
#
# Bug#25347: mysqlcheck -A -r doesn't repair table marked as crashed
#
create database d_bug25347;
use d_bug25347;
create table t_bug25347 (a int);
create view v_bug25347 as select * from t_bug25347;
--echo removing and creating
--exec rm $MYSQLTEST_VARDIR/master-data/d_bug25347/t_bug25347.MYI;
--exec touch $MYSQLTEST_VARDIR/master-data/d_bug25347/t_bug25347.MYI;
--exec $MYSQL_CHECK --repair --databases d_bug25347
drop view v_bug25347;
drop table t_bug25347;
drop database d_bug25347;
use test;
--echo End of 5.0 tests --echo End of 5.0 tests
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