Skip to content

Commit 2e698f8

Browse files
author
cmiller@zippy.cornsilk.net
committed
Backport:
Patch contributed by Jocelyn Fournier. CLA received 2007-02-27. B-g#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.
1 parent 9816842 commit 2e698f8

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

client/mysqlcheck.c

+15-12
Original file line numberDiff line numberDiff line change
@@ -453,14 +453,17 @@ static int process_all_tables_in_db(char *database)
453453
{
454454
MYSQL_RES *res;
455455
MYSQL_ROW row;
456+
uint num_columns;
456457

457458
LINT_INIT(res);
458459
if (use_db(database))
459460
return 1;
460-
if (mysql_query(sock, "SHOW TABLE STATUS") ||
461+
if (mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") ||
461462
!((res= mysql_store_result(sock))))
462463
return 1;
463464

465+
num_columns= mysql_num_fields(res);
466+
464467
if (opt_all_in_1)
465468
{
466469
/*
@@ -483,12 +486,11 @@ static int process_all_tables_in_db(char *database)
483486
}
484487
for (end = tables + 1; (row = mysql_fetch_row(res)) ;)
485488
{
486-
/* Skip tables with an engine of NULL (probably a view). */
487-
if (row[1])
488-
{
489-
end= fix_table_name(end, row[0]);
490-
*end++= ',';
491-
}
489+
if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
490+
continue;
491+
492+
end= fix_table_name(end, row[0]);
493+
*end++= ',';
492494
}
493495
*--end = 0;
494496
if (tot_length)
@@ -498,11 +500,12 @@ static int process_all_tables_in_db(char *database)
498500
else
499501
{
500502
while ((row = mysql_fetch_row(res)))
501-
/* Skip tables with an engine of NULL (probably a view). */
502-
if (row[1])
503-
{
504-
handle_request_for_tables(row[0], strlen(row[0]));
505-
}
503+
{
504+
if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
505+
continue;
506+
507+
handle_request_for_tables(row[0], strlen(row[0]));
508+
}
506509
}
507510
mysql_free_result(res);
508511
return 0;

mysql-test/r/mysqlcheck.result

+10
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ test.t1 OK
4141
test.t1 OK
4242
drop view v1;
4343
drop table t1;
44+
create database d_bug25347;
45+
use d_bug25347;
46+
create table t_bug25347 (a int);
47+
create view v_bug25347 as select * from t_bug25347;
48+
removing and creating
49+
d_bug25347.t_bug25347 OK
50+
drop view v_bug25347;
51+
drop table t_bug25347;
52+
drop database d_bug25347;
53+
use test;
4454
End of 5.0 tests

mysql-test/t/mysqlcheck.test

+16
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,20 @@ create view v1 as select * from t1;
3131
drop view v1;
3232
drop table t1;
3333

34+
#
35+
# Bug#25347: mysqlcheck -A -r doesn't repair table marked as crashed
36+
#
37+
create database d_bug25347;
38+
use d_bug25347;
39+
create table t_bug25347 (a int);
40+
create view v_bug25347 as select * from t_bug25347;
41+
--echo removing and creating
42+
--exec rm $MYSQLTEST_VARDIR/master-data/d_bug25347/t_bug25347.MYI;
43+
--exec touch $MYSQLTEST_VARDIR/master-data/d_bug25347/t_bug25347.MYI;
44+
--exec $MYSQL_CHECK --repair --databases d_bug25347
45+
drop view v_bug25347;
46+
drop table t_bug25347;
47+
drop database d_bug25347;
48+
use test;
49+
3450
--echo End of 5.0 tests

0 commit comments

Comments
 (0)