Commit f806b4d4 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views

create a separate list of views to repair, and repair them
in a separate loop.
parent 535b514e
......@@ -53,6 +53,7 @@ static char *opt_password = 0, *current_user = 0,
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
static int first_error = 0;
DYNAMIC_ARRAY tables4repair, tables4rebuild, alter_table_cmds;
DYNAMIC_ARRAY views4repair;
static char *shared_memory_base_name=0;
static uint opt_protocol=0;
......@@ -956,6 +957,7 @@ static void print_result()
uint length_of_db;
uint i;
my_bool found_error=0, table_rebuild=0;
DYNAMIC_ARRAY *array4repair= &tables4repair;
DBUG_ENTER("print_result");
res = mysql_use_result(sock);
......@@ -992,9 +994,10 @@ static void print_result()
else
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4repair, (uchar*) table_name);
insert_dynamic(array4repair, (uchar*) table_name);
}
}
array4repair= &tables4repair;
found_error=0;
table_rebuild=0;
prev_alter[0]= 0;
......@@ -1010,8 +1013,11 @@ static void print_result()
we have to run upgrade on it. In this case we write a nicer message
than "Please do "REPAIR TABLE""...
*/
if (!strcmp(row[2],"error") && strstr(row[3],"REPAIR TABLE"))
if (!strcmp(row[2],"error") && strstr(row[3],"REPAIR "))
{
printf("%-50s %s", row[0], "Needs upgrade");
array4repair= strstr(row[3], "VIEW") ? &views4repair : &tables4repair;
}
else
printf("%s\n%-9s: %s", row[0], row[2], row[3]);
if (opt_auto_repair && strcmp(row[2],"note"))
......@@ -1061,7 +1067,7 @@ static void print_result()
else
{
char *table_name= prev + (length_of_db+1);
insert_dynamic(&tables4repair, (uchar*) table_name);
insert_dynamic(array4repair, (uchar*) table_name);
}
}
mysql_free_result(res);
......@@ -1173,6 +1179,7 @@ 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(&views4repair, sizeof(char)*(NAME_LEN*2+2),16,64) ||
my_init_dynamic_array(&tables4rebuild, sizeof(char)*(NAME_LEN*2+2),16,64) ||
my_init_dynamic_array(&alter_table_cmds, MAX_ALTER_STR_SIZE, 0, 1)))
goto end;
......@@ -1201,6 +1208,13 @@ int main(int argc, char **argv)
rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i));
for (i = 0; i < alter_table_cmds.elements ; i++)
run_query((char*) dynamic_array_ptr(&alter_table_cmds, i));
if (!opt_silent && views4repair.elements)
puts("\nRepairing views");
for (i = 0; i < views4repair.elements ; i++)
{
char *name= (char*) dynamic_array_ptr(&views4repair, i);
handle_request_for_tables(name, fixed_name_length(name), TRUE);
}
}
ret= test(first_error);
......@@ -1208,8 +1222,10 @@ int main(int argc, char **argv)
dbDisconnect(current_host);
if (opt_auto_repair)
{
delete_dynamic(&views4repair);
delete_dynamic(&tables4repair);
delete_dynamic(&tables4rebuild);
delete_dynamic(&alter_table_cmds);
}
end1:
my_free(opt_password);
......
......@@ -330,3 +330,12 @@ test.v1 OK
mysqlcheck --process-views --check-upgrade test
test.v1 OK
drop view v1;
create table t1(a int);
mysqlcheck --process-views --check-upgrade --auto-repair test
test.t1 OK
test.v1 Needs upgrade
Repairing views
test.v1 OK
drop view v1;
drop table t1;
......@@ -7,6 +7,7 @@
# check that CSV engine was compiled in, as the result of the test
# depends on the presence of the log tables (which are CSV-based).
--source include/have_csv.inc
let $MYSQLD_DATADIR= `select @@datadir`;
#
# Clean up after previous tests
......@@ -65,7 +66,6 @@ create table t_bug25347 (a int) engine=myisam;
create view v_bug25347 as select * from t_bug25347;
insert into t_bug25347 values (1),(2),(3);
flush tables;
let $MYSQLD_DATADIR= `select @@datadir`;
--echo removing and creating
--remove_file $MYSQLD_DATADIR/d_bug25347/t_bug25347.MYI
--write_file $MYSQLD_DATADIR/d_bug25347/t_bug25347.MYI
......@@ -117,7 +117,6 @@ DROP TABLE t1, t2;
create table t1(a int) engine=myisam;
create view v1 as select * from t1;
show tables;
let $MYSQLD_DATADIR= `select @@datadir`;
--copy_file $MYSQLD_DATADIR/test/v1.frm $MYSQLD_DATADIR/test/v-1.frm
show tables;
--exec $MYSQL_CHECK --check-upgrade --databases test
......@@ -162,24 +161,23 @@ CREATE TABLE `#mysql50#c@d` (a INT) engine=myisam;
CREATE TABLE t1 (a INT) engine=myisam;
# Create 5.0 like triggers
let $MYSQLTEST_VARDIR= `select @@datadir`;
--write_file $MYSQLTEST_VARDIR/a@b/c@d.TRG
--write_file $MYSQLD_DATADIR/a@b/c@d.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr1 BEFORE INSERT ON `c@d` FOR EACH ROW SET NEW.a = 10 * NEW.a'
sql_modes=0
definers='root@localhost'
EOF
--write_file $MYSQLTEST_VARDIR/a@b/tr1.TRN
--write_file $MYSQLD_DATADIR/a@b/tr1.TRN
TYPE=TRIGGERNAME
trigger_table=c@d
EOF
--write_file $MYSQLTEST_VARDIR/a@b/t1.TRG
--write_file $MYSQLD_DATADIR/a@b/t1.TRG
TYPE=TRIGGERS
triggers='CREATE DEFINER=`root`@`localhost` TRIGGER tr2 BEFORE INSERT ON `a@b`.t1 FOR EACH ROW SET NEW.a = 100 * NEW.a'
sql_modes=0
definers='root@localhost'
EOF
--write_file $MYSQLTEST_VARDIR/a@b/tr2.TRN
--write_file $MYSQLD_DATADIR/a@b/tr2.TRN
TYPE=TRIGGERNAME
trigger_table=t1
EOF
......@@ -253,7 +251,6 @@ INSERT INTO bug47205 VALUES ("foobar");
FLUSH TABLE bug47205;
--echo # Replace the FRM with a 5.0 FRM that will require upgrade
let $MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/test/bug47205.frm
--copy_file std_data/bug47205.frm $MYSQLD_DATADIR/test/bug47205.frm
......@@ -280,7 +277,6 @@ CREATE TABLE bug47205(a VARCHAR(20) PRIMARY KEY)
FLUSH TABLE bug47205;
--echo # Replace the FRM with a 5.0 FRM that will require upgrade
let $MYSQLD_DATADIR= `select @@datadir`;
--remove_file $MYSQLD_DATADIR/test/bug47205.frm
--copy_file std_data/bug47205.frm $MYSQLD_DATADIR/test/bug47205.frm
......@@ -344,3 +340,13 @@ create view v1 as select 1;
--exec $MYSQL_CHECK --process-views --check-upgrade test
drop view v1;
#
# MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views
#
create table t1(a int);
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
--echo mysqlcheck --process-views --check-upgrade --auto-repair test
--exec $MYSQL_CHECK --process-views --check-upgrade --auto-repair test
drop view v1;
drop table t1;
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