Skip to content

Commit fc277cd

Browse files
committed
Add --fix-tables option to mysql-check
Mainly so that mysql_upgrade.c can use --skip-fix-tables Correct mysql_upgrade_view test output based on phases and previous error message changes.
1 parent 28b1731 commit fc277cd

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

client/mysql_upgrade.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ static int run_mysqlcheck_views(void)
793793
ds_args.str,
794794
"--all-databases",
795795
"--fix-view-algorithm",
796+
"--skip-fix-tables",
796797
opt_verbose ? "--verbose": "",
797798
opt_silent ? "--silent": "",
798799
opt_write_binlog ? "--write-binlog" : "--skip-write-binlog",

client/mysqlcheck.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
4343
opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
4444
tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
4545
opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
46-
opt_fix_view_algorithm= 0;
46+
opt_fix_view_algorithm= 0, opt_fix_tables= 1;
4747
static my_bool opt_write_binlog= 1, opt_flush_tables= 0;
4848
static uint verbose = 0, opt_mysql_port=0;
4949
static int my_end_arg;
@@ -200,6 +200,9 @@ static struct my_option my_long_options[] =
200200
{"fix-view-algorithm", 'y',
201201
"Fix view algorithm view field if it is not new MariaDB view.",
202202
&opt_fix_view_algorithm, &opt_fix_view_algorithm, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
203+
{"fix-tables", 'Y',
204+
"Fix tables. Usually the default however mysql_upgrade will run with --skip-fix-tables.",
205+
&opt_fix_tables, &opt_fix_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
203206
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
204207
};
205208

@@ -369,6 +372,12 @@ static int get_options(int *argc, char ***argv)
369372
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
370373
exit(ho_error);
371374

375+
if (what_to_do==DO_REPAIR && !(opt_fix_view_algorithm || opt_fix_tables))
376+
{
377+
fprintf(stderr, "Error: %s doesn't support repair command without either fix-view-algorithm or fix-tables specified.\n",
378+
my_progname);
379+
exit(1);
380+
}
372381
if (opt_fix_view_algorithm && what_to_do!=DO_REPAIR)
373382
{
374383
if (!what_to_do)
@@ -641,9 +650,10 @@ static int process_all_tables_in_db(char *database)
641650

642651
while ((row = mysql_fetch_row(res)))
643652
{
644-
if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
653+
if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0) &&
654+
opt_fix_view_algorithm)
645655
tot_views_length+= fixed_name_length(row[0]) + 2;
646-
else
656+
else if (opt_fix_tables)
647657
tot_length+= fixed_name_length(row[0]) + 2;
648658
}
649659
mysql_data_seek(res, 0);
@@ -671,6 +681,8 @@ static int process_all_tables_in_db(char *database)
671681
}
672682
else
673683
{
684+
if (!opt_fix_tables)
685+
continue;
674686
end= fix_table_name(end, row[0]);
675687
*end++= ',';
676688
}
@@ -696,7 +708,11 @@ static int process_all_tables_in_db(char *database)
696708
view= TRUE;
697709
}
698710
else
711+
{
712+
if (!opt_fix_tables)
713+
continue;
699714
view= FALSE;
715+
}
700716
if (system_database &&
701717
(!strcmp(row[0], "general_log") ||
702718
!strcmp(row[0], "slow_log")))

mysql-test/r/mysql_upgrade_view.result

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ show create view v4;
1616
View Create View character_set_client collation_connection
1717
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci
1818
MySQL upgrade detected
19-
Phase 0: Fixing views
20-
test.v1 view is repaired
21-
test.v2 view is repaired
22-
test.v3 view is repaired
19+
Phase 1/4: Fixing views
20+
test.v1 OK
21+
test.v2 OK
22+
test.v3 OK
2323
test.v4 OK
24-
Phase 1/3: Fixing table and database names
25-
Phase 2/3: Checking and upgrading tables
24+
Phase 2/4: Fixing table and database names
25+
Phase 3/4: Checking and upgrading tables
2626
Processing databases
2727
information_schema
2828
mtr
@@ -55,7 +55,7 @@ mysql.user OK
5555
performance_schema
5656
test
5757
test.t1 OK
58-
Phase 3/3: Running 'mysql_fix_privilege_tables'...
58+
Phase 4/4: Running 'mysql_fix_privilege_tables'...
5959
OK
6060
show create view v1;
6161
View Create View character_set_client collation_connection

0 commit comments

Comments
 (0)