[Commits] Rev 4428: MDEV-6916: Upgrade from MySQL to MariaDB breaks already created views in file:///home/bell/maria/bzr/work-maria-5.5-MDEV-6916-repair_view/

sanja at askmonty.org sanja at askmonty.org
Fri Feb 13 14:47:57 EET 2015


At file:///home/bell/maria/bzr/work-maria-5.5-MDEV-6916-repair_view/

------------------------------------------------------------
revno: 4428
revision-id: sanja at askmonty.org-20150213124726-9rn55t3qqx7yzy9q
parent: jplindst at mariadb.org-20150210121723-1gxyej083cf1nv8h
committer: sanja at askmonty.org
branch nick: work-maria-5.5-MDEV-6916-repair_view
timestamp: Fri 2015-02-13 13:47:26 +0100
message:
  MDEV-6916: Upgrade from MySQL to MariaDB breaks already created views
  
  CHECK/REPAIR commands and mysql_upgrade support for upgrade from MySQL server support.
-------------- next part --------------
=== modified file 'client/mysql_upgrade.c'
--- a/client/mysql_upgrade.c	2014-03-27 21:26:58 +0000
+++ b/client/mysql_upgrade.c	2015-02-13 12:47:26 +0000
@@ -738,7 +738,7 @@ static void print_conn_args(const char *
 
 static int run_mysqlcheck_upgrade(void)
 {
-  verbose("Phase 2/3: Checking and upgrading tables");
+  verbose("Phase 3/4: Checking and upgrading tables");
   print_conn_args("mysqlcheck");
   return run_tool(mysqlcheck_path,
                   NULL, /* Send output from mysqlcheck directly to screen */
@@ -755,9 +755,50 @@ static int run_mysqlcheck_upgrade(void)
 }
 
 
+#define EVENTS_STRUCT_LEN 7000
+
+my_bool is_mysql()
+{
+  my_bool ret= TRUE;
+  DYNAMIC_STRING ds_events_struct;
+
+  if (init_dynamic_string(&ds_events_struct, NULL,
+                          EVENTS_STRUCT_LEN, EVENTS_STRUCT_LEN))
+    die("Out of memory");
+
+  if (run_query("show create table mysql.event",
+                &ds_events_struct, FALSE) ||
+      strstr(ds_events_struct.str, "IGNORE_BAD_TABLE_OPTIONS") != NULL)
+    ret= FALSE;
+  else
+    verbose("MySQL upgrade detected");
+
+  dynstr_free(&ds_events_struct);
+  return(ret);
+}
+
+
+static int run_mysqlcheck_views(void)
+{
+  if (opt_systables_only || !is_mysql())
+    return 0;
+  verbose("Phase 1/4: Fixing views");
+  print_conn_args("mysqlcheck");
+  return run_tool(mysqlcheck_path,
+                  NULL, /* Send output from mysqlcheck directly to screen */
+                  "--no-defaults",
+                  ds_args.str,
+                  "--all-databases",
+                  "--upgrade-view=from_mysql",
+                  opt_verbose ? "--verbose": "",
+                  opt_silent ? "--silent": "",
+                  "2>&1",
+                  NULL);
+}
+
 static int run_mysqlcheck_fixnames(void)
 {
-  verbose("Phase 1/3: Fixing table and database names");
+  verbose("Phase 2/4: Fixing table and database names");
   print_conn_args("mysqlcheck");
   return run_tool(mysqlcheck_path,
                   NULL, /* Send output from mysqlcheck directly to screen */
@@ -838,7 +879,7 @@ static int run_sql_fix_privilege_tables(
   if (init_dynamic_string(&ds_result, "", 512, 512))
     die("Out of memory");
 
-  verbose("Phase 3/3: Running 'mysql_fix_privilege_tables'...");
+  verbose("Phase 4/4: Running 'mysql_fix_privilege_tables'...");
   run_query(mysql_fix_privilege_tables,
             &ds_result, /* Collect result */
             TRUE);
@@ -1001,7 +1042,8 @@ int main(int argc, char **argv)
     Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
   */
   if ((!opt_systables_only &&
-       (run_mysqlcheck_fixnames() || run_mysqlcheck_upgrade())) ||
+       (run_mysqlcheck_views() ||
+        run_mysqlcheck_fixnames() || run_mysqlcheck_upgrade())) ||
       run_sql_fix_privilege_tables())
   {
     /*

=== modified file 'client/mysqlcheck.c'
--- a/client/mysqlcheck.c	2015-01-28 10:49:55 +0000
+++ b/client/mysqlcheck.c	2015-02-13 12:47:26 +0000
@@ -54,9 +54,16 @@ static int first_error = 0;
 DYNAMIC_ARRAY tables4repair, tables4rebuild, alter_table_cmds;
 static char *shared_memory_base_name=0;
 static uint opt_protocol=0;
+enum enum_upgrade_view
+  {VIEW_UPGRADE_NO= 0, VIEW_UPGRADE_YES, VIEW_UPGRADE_FROM_MYSQL};
+static ulong opt_upgrade_view= VIEW_UPGRADE_NO;
 
 enum operations { DO_CHECK=1, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
 
+const char *upgrade_view_type[] = {"NO", "YES", "FROM_MYSQL", NullS};
+TYPELIB upgrade_view_typelib = {array_elements(upgrade_view_type) - 1, "",
+  upgrade_view_type, NULL};
+
 static struct my_option my_long_options[] =
 {
   {"all-databases", 'A',
@@ -196,6 +203,9 @@ static struct my_option my_long_options[
    NO_ARG, 0, 0, 0, 0, 0, 0},
   {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
    NO_ARG, 0, 0, 0, 0, 0, 0},
+  {"upgrade-view", 0, "Set fixing view level.",
+   &opt_upgrade_view, &opt_upgrade_view, &upgrade_view_typelib,
+   GET_ENUM, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 };
 
@@ -363,6 +373,18 @@ static int get_options(int *argc, char *
   if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
     exit(ho_error);
 
+  if (opt_upgrade_view)
+  {
+    if (what_to_do && what_to_do != DO_REPAIR)
+    {
+      fprintf(stderr, "Error:  %s doesn't support multiple contradicting commands.\n",
+              my_progname);
+      DBUG_RETURN(1);
+
+    }
+    what_to_do= DO_REPAIR;
+  }
+
   if (!what_to_do)
   {
     size_t pnlen= strlen(my_progname);
@@ -587,7 +609,15 @@ static int process_all_tables_in_db(char
     for (end = tables + 1; (row = mysql_fetch_row(res)) ;)
     {
       if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
-        continue;
+      {
+        if (!opt_upgrade_view)
+          continue;
+      }
+      else
+      {
+        if (opt_upgrade_view)
+          continue;
+      }
 
       end= fix_table_name(end, row[0]);
       *end++= ',';
@@ -603,7 +633,15 @@ static int process_all_tables_in_db(char
     {
       /* Skip views if we don't perform renaming. */
       if ((what_to_do != DO_UPGRADE) && (num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
-        continue;
+      {
+        if (!opt_upgrade_view)
+          continue;
+      }
+      else
+      {
+        if (opt_upgrade_view)
+          continue;
+      }
       if (system_database &&
           (!strcmp(row[0], "general_log") ||
            !strcmp(row[0], "slow_log")))
@@ -752,6 +790,8 @@ static int handle_request_for_tables(cha
     if (opt_quick)              end = strmov(end, " QUICK");
     if (opt_extended)           end = strmov(end, " EXTENDED");
     if (opt_frm)                end = strmov(end, " USE_FRM");
+    if (opt_upgrade_view ==
+        VIEW_UPGRADE_FROM_MYSQL)end = strmov(end, " FROM MYSQL");
     break;
   case DO_ANALYZE:
     op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
@@ -768,14 +808,17 @@ static int handle_request_for_tables(cha
   if (opt_all_in_1)
   {
     /* No backticks here as we added them before */
-    query_length= sprintf(query, "%s TABLE %s %s", op, tables, options);
+    query_length= sprintf(query, "%s %s %s %s", op,
+                          (opt_upgrade_view? "VIEW" : "TABLE"),
+                          tables, options);
     table_name= tables;
   }
   else
   {
     char *ptr, *org;
 
-    org= ptr= strmov(strmov(query, op), " TABLE ");
+    org= ptr= strmov(strmov(query, op),
+                     (opt_upgrade_view ? " VIEW " : " TABLE "));
     ptr= fix_table_name(ptr, tables);
     strmake(table_name_buff, org, min((int) sizeof(table_name_buff)-1,
                                       (int) (ptr - org)));
@@ -785,7 +828,8 @@ static int handle_request_for_tables(cha
   }
   if (mysql_real_query(sock, query, query_length))
   {
-    sprintf(message, "when executing '%s TABLE ... %s'", op, options);
+    sprintf(message, "when executing '%s %s ... %s'", op,
+            (opt_upgrade_view? "VIEW" : "TABLE"), options);
     DBerror(sock, message);
     my_free(query);
     DBUG_RETURN(1);

=== modified file 'include/myisamchk.h'
--- a/include/myisamchk.h	2014-01-22 14:29:36 +0000
+++ b/include/myisamchk.h	2015-02-13 12:47:26 +0000
@@ -34,6 +34,7 @@
 
 #define TT_USEFRM               1
 #define TT_FOR_UPGRADE          2
+#define TT_FROM_MYSQL           4
 
 /* Bits set in out_flag */
 #define O_NEW_DATA	2

=== modified file 'mysql-test/r/log_tables_upgrade.result'
--- a/mysql-test/r/log_tables_upgrade.result	2011-07-02 20:08:51 +0000
+++ b/mysql-test/r/log_tables_upgrade.result	2015-02-13 12:47:26 +0000
@@ -11,8 +11,8 @@ Table	Op	Msg_type	Msg_text
 test.bug49823	repair	status	OK
 RENAME TABLE general_log TO renamed_general_log;
 RENAME TABLE test.bug49823 TO general_log;
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -44,7 +44,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 DROP TABLE general_log;
 RENAME TABLE renamed_general_log TO general_log;

=== modified file 'mysql-test/r/mysql_upgrade.result'
--- a/mysql-test/r/mysql_upgrade.result	2014-04-27 22:56:53 +0000
+++ b/mysql-test/r/mysql_upgrade.result	2015-02-13 12:47:26 +0000
@@ -1,6 +1,6 @@
 Run mysql_upgrade once
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -31,13 +31,13 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 Run it again - should say already completed
 This installation of MySQL is already upgraded to VERSION, use --force if you still need to run mysql_upgrade
 Force should run it regardless of wether it's been run before
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -68,13 +68,13 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 CREATE USER mysqltest1@'%' IDENTIFIED by 'sakila';
 GRANT ALL ON *.* TO mysqltest1@'%';
 Run mysql_upgrade with password protected account
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -105,7 +105,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 DROP USER mysqltest1@'%';
 Version check failed. Got the following error when calling the 'mysql' command line client
@@ -115,8 +115,8 @@ Run mysql_upgrade with a non existing se
 mysqlcheck: Got error: 2005: Unknown MySQL server host 'not_existing_host' (errno) when trying to connect
 FATAL ERROR: Upgrade failed
 set GLOBAL sql_mode='STRICT_ALL_TABLES,ANSI_QUOTES,NO_ZERO_DATE';
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -147,7 +147,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 set GLOBAL sql_mode=default;
 #
@@ -158,8 +158,8 @@ CREATE PROCEDURE testproc() BEGIN END;
 UPDATE mysql.proc SET character_set_client = NULL WHERE name LIKE 'testproc';
 UPDATE mysql.proc SET collation_connection = NULL WHERE name LIKE 'testproc';
 UPDATE mysql.proc SET db_collation = NULL WHERE name LIKE 'testproc';
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -190,7 +190,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 CALL testproc();
 DROP PROCEDURE testproc;
@@ -204,8 +204,8 @@ WARNING: NULL values of the 'db_collatio
 GRANT USAGE ON *.* TO 'user3'@'%';
 GRANT ALL PRIVILEGES ON `roelt`.`test2` TO 'user3'@'%';
 Run mysql_upgrade with all privileges on a user
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -236,7 +236,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 SHOW GRANTS FOR 'user3'@'%';
 Grants for user3@%
@@ -245,7 +245,7 @@ GRANT ALL PRIVILEGES ON `roelt`.`test2`
 DROP USER 'user3'@'%';
 End of 5.1 tests
 The --upgrade-system-tables option was used, databases won't be touched.
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 #
 # Bug#11827359 60223: MYSQL_UPGRADE PROBLEM WITH OPTION
@@ -253,8 +253,8 @@ OK
 #
 # Droping the previously created mysql_upgrade_info file..
 # Running mysql_upgrade with --skip-write-binlog..
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -285,7 +285,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 #
 # MDEV-4332 Increase username length from 16 characters
@@ -313,8 +313,8 @@ GRANT INSERT ON mysql.user TO very_long_
 GRANT UPDATE (User) ON mysql.db TO very_long_user_name_number_1;
 GRANT UPDATE (User) ON mysql.db TO very_long_user_name_number_2;
 CREATE PROCEDURE test.pr() BEGIN END;
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -345,7 +345,7 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK
 SELECT definer FROM mysql.proc WHERE db = 'test' AND name = 'pr';
 definer

=== modified file 'mysql-test/r/mysql_upgrade_ssl.result'
--- a/mysql-test/r/mysql_upgrade_ssl.result	2011-07-02 20:08:51 +0000
+++ b/mysql-test/r/mysql_upgrade_ssl.result	2015-02-13 12:47:26 +0000
@@ -1,8 +1,8 @@
 #
 # Bug#55672 mysql_upgrade dies with internal error 
 #
-Phase 1/3: Fixing table and database names
-Phase 2/3: Checking and upgrading tables
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
 Processing databases
 information_schema
 mtr
@@ -33,5 +33,5 @@ mysql.time_zone_transition_type
 mysql.user                                         OK
 performance_schema
 test
-Phase 3/3: Running 'mysql_fix_privilege_tables'...
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
 OK

=== added file 'mysql-test/r/mysql_upgrade_view.result'
--- a/mysql-test/r/mysql_upgrade_view.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/r/mysql_upgrade_view.result	2015-02-13 12:47:26 +0000
@@ -0,0 +1,74 @@
+drop table if exists t1,v1,v2,v3,v4;
+drop view if exists t1,v1,v2,v3,v4;
+flush tables;
+create table t1(a int);
+create algorithm=temptable view v4 as select a from t1;
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v2;
+View	Create View	character_set_client	collation_connection
+v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v3;
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v4;
+View	Create View	character_set_client	collation_connection
+v4	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1`	latin1	latin1_swedish_ci
+MySQL upgrade detected
+Phase 1/4: Fixing views
+test.v1                                            OK
+test.v2                                            OK
+test.v3                                            OK
+test.v4                                            OK
+Phase 2/4: Fixing table and database names
+Phase 3/4: Checking and upgrading tables
+Processing databases
+information_schema
+mtr
+mtr.global_suppressions                            OK
+mtr.test_suppressions                              OK
+mysql
+mysql.columns_priv                                 OK
+mysql.db                                           OK
+mysql.ev_bk                                        OK
+mysql.event                                        OK
+mysql.func                                         OK
+mysql.help_category                                OK
+mysql.help_keyword                                 OK
+mysql.help_relation                                OK
+mysql.help_topic                                   OK
+mysql.host                                         OK
+mysql.ndb_binlog_index                             OK
+mysql.plugin                                       OK
+mysql.proc                                         OK
+mysql.procs_priv                                   OK
+mysql.proxies_priv                                 OK
+mysql.servers                                      OK
+mysql.tables_priv                                  OK
+mysql.time_zone                                    OK
+mysql.time_zone_leap_second                        OK
+mysql.time_zone_name                               OK
+mysql.time_zone_transition                         OK
+mysql.time_zone_transition_type                    OK
+mysql.user                                         OK
+performance_schema
+test
+test.t1                                            OK
+Phase 4/4: Running 'mysql_fix_privilege_tables'...
+OK
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v2;
+View	Create View	character_set_client	collation_connection
+v2	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v3;
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v4;
+View	Create View	character_set_client	collation_connection
+v4	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1`	latin1	latin1_swedish_ci
+flush tables;
+drop view v1,v2,v3,v4;
+drop table t1;

=== modified file 'mysql-test/r/mysqlcheck.result'
--- a/mysql-test/r/mysqlcheck.result	2015-01-28 10:49:55 +0000
+++ b/mysql-test/r/mysqlcheck.result	2015-02-13 12:47:26 +0000
@@ -298,7 +298,7 @@ DROP TABLE bug47205;
 # Should indicate that REPAIR TABLE is needed
 CHECK TABLE bug47205 FOR UPGRADE;
 Table	Op	Msg_type	Msg_text
-test.bug47205	check	error	Table upgrade required. Please do "REPAIR TABLE `bug47205`" or dump/reload to fix it!
+test.bug47205	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `bug47205`" or dump/reload to fix it!
 # Running mysqlcheck to check and upgrade
 test.bug47205                                      Needs upgrade
 

=== modified file 'mysql-test/r/perror.result'
--- a/mysql-test/r/perror.result	2014-01-22 14:29:36 +0000
+++ b/mysql-test/r/perror.result	2015-02-13 12:47:26 +0000
@@ -2,5 +2,5 @@ Illegal error code: 10000
 MySQL error code 1062 (ER_DUP_ENTRY): Duplicate entry '%-.192s' for key %d
 MySQL error code 1408 (ER_STARTUP): %s: ready for connections.
 Version: '%s'  socket: '%s'  port: %d  %s
-MySQL error code 1459 (ER_TABLE_NEEDS_UPGRADE): Table upgrade required. Please do "REPAIR TABLE `%-.32s`" or dump/reload to fix it!
+MySQL error code 1459 (ER_TABLE_NEEDS_UPGRADE): Table/view upgrade required. Please do "REPAIR TABLE/VIEW %`-.32s" or dump/reload to fix it!
 MySQL error code 1461 (ER_MAX_PREPARED_STMT_COUNT_REACHED): Can't create more than max_prepared_stmt_count statements (current value: %lu)

=== modified file 'mysql-test/r/repair.result'
--- a/mysql-test/r/repair.result	2014-01-22 13:16:57 +0000
+++ b/mysql-test/r/repair.result	2015-02-13 12:47:26 +0000
@@ -126,7 +126,7 @@ id
 # Run CHECK TABLE, it should indicate table need a REPAIR TABLE
 CHECK TABLE t1 FOR UPGRADE;
 Table	Op	Msg_type	Msg_text
-test.t1	check	error	Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
+test.t1	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `t1`" or dump/reload to fix it!
 # REPAIR old table USE_FRM should fail
 REPAIR TABLE t1 USE_FRM;
 Table	Op	Msg_type	Msg_text

=== modified file 'mysql-test/r/upgrade.result'
--- a/mysql-test/r/upgrade.result	2011-05-11 11:09:48 +0000
+++ b/mysql-test/r/upgrade.result	2015-02-13 12:47:26 +0000
@@ -60,7 +60,7 @@ drop table `txu#p#p1`;
 # check the table created using mysql 4.0
 CHECK TABLE t1;
 Table	Op	Msg_type	Msg_text
-test.t1	check	error	Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
+test.t1	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `t1`" or dump/reload to fix it!
 # query the table created using mysql 4.0
 SELECT * FROM t1;
 c1	c2	c3

=== modified file 'mysql-test/r/varbinary.result'
--- a/mysql-test/r/varbinary.result	2013-05-08 09:36:17 +0000
+++ b/mysql-test/r/varbinary.result	2015-02-13 12:47:26 +0000
@@ -91,7 +91,7 @@ length(a)	length(b)
 255	3
 CHECK TABLE t1 FOR UPGRADE;
 Table	Op	Msg_type	Msg_text
-test.t1	check	error	Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
+test.t1	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `t1`" or dump/reload to fix it!
 REPAIR TABLE t1;
 Table	Op	Msg_type	Msg_text
 test.t1	repair	status	OK

=== modified file 'mysql-test/r/view.result'
--- a/mysql-test/r/view.result	2014-12-21 18:23:28 +0000
+++ b/mysql-test/r/view.result	2015-02-13 12:47:26 +0000
@@ -5398,6 +5398,135 @@ DROP VIEW v1;
 DROP TABLE t1, t2;
 create view v1 as select 1;
 drop view v1;
+#
+#CHECK/REPAIR VIEW syntax
+#
+create table t1 (a int);
+create view v1 as select a from t1;
+check view v1, t1;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+test.t1	check	Error	Table 'test.t1' doesn't exist
+test.t1	check	status	Operation failed
+check view v1 FOR UPGRADE;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+check view v1 QUICK;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+check view v1 FAST;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+check view v1 EXTENDED;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+check view v1 CHANGED;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+repair view v1, t1;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+test.t1	repair	Error	Table 'test.t1' doesn't exist
+test.t1	repair	status	Operation failed
+repair view v1 FROM MYSQL;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+repair table t1 FROM MYSQL;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+repair view v1 QUICK;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+repair view v1 EXTENDED;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+repair view v1 USE_FRM;
+ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
+drop view v1;
+drop table t1;
+#
+#CHECK/REPAIR VIEW
+#
+create table t1(a int);
+create view v5 as select a from t1;
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v2;
+View	Create View	character_set_client	collation_connection
+v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v3;
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+check view v1,v2,v3,v4,v5 FOR UPGRADE;
+Table	Op	Msg_type	Msg_text
+test.v1	check	Note	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `v1`" or dump/reload to fix it!
+test.v1	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `v1`" or dump/reload to fix it!
+test.v2	check	Note	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `v2`" or dump/reload to fix it!
+test.v2	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `v2`" or dump/reload to fix it!
+test.v3	check	Note	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `v3`" or dump/reload to fix it!
+test.v3	check	error	Table/view upgrade required. Please do "REPAIR TABLE/VIEW `v3`" or dump/reload to fix it!
+test.v4	check	note	View text checksum failed
+test.v5	check	status	OK
+repair view v1,v2,v3,v4,v5 FROM MYSQL;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+test.v2	repair	status	OK
+test.v3	repair	status	OK
+test.v4	repair	status	OK
+test.v5	repair	status	OK
+check view v1,v2,v3,v4,v5 FOR UPGRADE;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+test.v2	check	status	OK
+test.v3	check	status	OK
+test.v4	check	status	OK
+test.v5	check	status	OK
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v2;
+View	Create View	character_set_client	collation_connection
+v2	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v3;
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+drop view v1,v2,v3,v4,v5;
+create view v5 as select a from t1;
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v2;
+View	Create View	character_set_client	collation_connection
+v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v3;
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+check view v1,v2,v3,v4,v5;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+test.v2	check	status	OK
+test.v3	check	status	OK
+test.v4	check	note	View text checksum failed
+test.v5	check	status	OK
+repair view v1,v2,v3,v4,v5;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+test.v2	repair	status	OK
+test.v3	repair	status	OK
+test.v4	repair	status	OK
+test.v5	repair	status	OK
+check view v1,v2,v3,v4,v5;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+test.v2	check	status	OK
+test.v3	check	status	OK
+test.v4	check	status	OK
+test.v5	check	status	OK
+show create view v1;
+View	Create View	character_set_client	collation_connection
+v1	CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v2;
+View	Create View	character_set_client	collation_connection
+v2	CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+show create view v3;
+View	Create View	character_set_client	collation_connection
+v3	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1`	utf8	utf8_general_ci
+drop view v1,v2,v3,v4,v5;
+drop table t1;
 # -----------------------------------------------------------------
 # -- End of 5.5 tests.
 # -----------------------------------------------------------------

=== added directory 'mysql-test/std_data/mysql_upgrade'
=== added file 'mysql-test/std_data/mysql_upgrade/event.MYD'

=== added file 'mysql-test/std_data/mysql_upgrade/event.MYI'
???????? ????? a/mysql-test/std_data/mysql_upgrade/event.MYI	1970-01-01 00:00:00 +0000 ?? b/mysql-test/std_data/mysql_upgrade/event.MYI	2015-02-13 12:47:26 +0000 ?????????????

=== added file 'mysql-test/std_data/mysql_upgrade/event.frm'
???????? ????? a/mysql-test/std_data/mysql_upgrade/event.frm	1970-01-01 00:00:00 +0000 ?? b/mysql-test/std_data/mysql_upgrade/event.frm	2015-02-13 12:47:26 +0000 ?????????????

=== added file 'mysql-test/std_data/mysql_upgrade/v1.frm'
--- a/mysql-test/std_data/mysql_upgrade/v1.frm	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/mysql_upgrade/v1.frm	2015-02-13 12:47:26 +0000
@@ -0,0 +1,15 @@
+TYPE=VIEW
+query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
+md5=5e6eaf216e7b016fcedfd4e1113517af
+updatable=0
+algorithm=1
+definer_user=root
+definer_host=localhost
+suid=2
+with_check_option=0
+timestamp=2014-12-11 15:26:20
+create-version=1
+source=select a from t1
+client_cs_name=utf8
+connection_cl_name=utf8_general_ci
+view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`

=== added file 'mysql-test/std_data/mysql_upgrade/v2.frm'
--- a/mysql-test/std_data/mysql_upgrade/v2.frm	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/mysql_upgrade/v2.frm	2015-02-13 12:47:26 +0000
@@ -0,0 +1,15 @@
+TYPE=VIEW
+query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
+md5=5e6eaf216e7b016fcedfd4e1113517af
+updatable=1
+algorithm=2
+definer_user=root
+definer_host=localhost
+suid=2
+with_check_option=0
+timestamp=2014-12-11 15:26:29
+create-version=1
+source=select a from t1
+client_cs_name=utf8
+connection_cl_name=utf8_general_ci
+view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`

=== added file 'mysql-test/std_data/mysql_upgrade/v3.frm'
--- a/mysql-test/std_data/mysql_upgrade/v3.frm	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/mysql_upgrade/v3.frm	2015-02-13 12:47:26 +0000
@@ -0,0 +1,15 @@
+TYPE=VIEW
+query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
+md5=5e6eaf216e7b016fcedfd4e1113517af
+updatable=0
+algorithm=0
+definer_user=root
+definer_host=localhost
+suid=2
+with_check_option=0
+timestamp=2014-12-11 15:26:20
+create-version=1
+source=select a from t1
+client_cs_name=utf8
+connection_cl_name=utf8_general_ci
+view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`

=== added file 'mysql-test/std_data/mysql_upgrade/v4.frm'
--- a/mysql-test/std_data/mysql_upgrade/v4.frm	1970-01-01 00:00:00 +0000
+++ b/mysql-test/std_data/mysql_upgrade/v4.frm	2015-02-13 12:47:26 +0000
@@ -0,0 +1,16 @@
+TYPE=VIEW
+query=select `test`.`t1`.`a` AS `a` from `test`.`t1`
+md5=5e6eaf216e7b016fcedfd4e1113517a0
+updatable=1
+algorithm=0
+definer_user=root
+definer_host=localhost
+suid=2
+with_check_option=0
+timestamp=2015-02-08 19:21:14
+create-version=1
+source=select a from t1
+client_cs_name=latin1
+connection_cl_name=latin1_swedish_ci
+view_body_utf8=select `test`.`t1`.`a` AS `a` from `test`.`t1`
+mariadb-version=50542

=== modified file 'mysql-test/suite/archive/archive.result'
--- a/mysql-test/suite/archive/archive.result	2012-04-03 21:16:38 +0000
+++ b/mysql-test/suite/archive/archive.result	2015-02-13 12:47:26 +0000
@@ -12731,11 +12731,11 @@ id	id	name	name
 DROP TABLE t1,t2;
 flush tables;
 SHOW CREATE TABLE t1;
-ERROR HY000: Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
+ERROR HY000: Table/view upgrade required. Please do "REPAIR TABLE/VIEW `t1`" or dump/reload to fix it!
 SELECT * FROM t1;
-ERROR HY000: Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
+ERROR HY000: Table/view upgrade required. Please do "REPAIR TABLE/VIEW `t1`" or dump/reload to fix it!
 INSERT INTO t1 (col1, col2) VALUES (1, "value");
-ERROR HY000: Table upgrade required. Please do "REPAIR TABLE `t1`" or dump/reload to fix it!
+ERROR HY000: Table/view upgrade required. Please do "REPAIR TABLE/VIEW `t1`" or dump/reload to fix it!
 REPAIR TABLE t1;
 Table	Op	Msg_type	Msg_text
 test.t1	repair	status	OK

=== modified file 'mysql-test/suite/rpl/r/rpl_view.result'
--- a/mysql-test/suite/rpl/r/rpl_view.result	2010-12-19 17:07:28 +0000
+++ b/mysql-test/suite/rpl/r/rpl_view.result	2015-02-13 12:47:26 +0000
@@ -112,4 +112,37 @@ v1	CREATE ALGORITHM=UNDEFINED DEFINER=`r
 DROP VIEW v1;
 DROP TABLE t1;
 End of 5.0 tests
+create table t1(a int);
+create view v1 as select a from t1;
+reset master;
+#should be replicated
+repair view v1;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+#should not be replicated
+repair LOCAL view v1;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+#should not be replicated (independently of LOCAL or not)
+repair view v1 from mysql;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+# CHECK should not be replicated
+check view v1;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+# CHECK should not be replicated
+check view v1 for upgrade;
+Table	Op	Msg_type	Msg_text
+test.v1	check	status	OK
+#should be replicated
+repair view v1;
+Table	Op	Msg_type	Msg_text
+test.v1	repair	status	OK
+show binlog events limit 1,100;
+Log_name	Pos	Event_type	Server_id	End_log_pos	Info
+x	x	x	x	x	use `test`; repair view v1
+x	x	x	x	x	use `test`; repair view v1
+drop view v1;
+drop table t1;
 include/rpl_end.inc

=== modified file 'mysql-test/suite/rpl/t/rpl_view.test'
--- a/mysql-test/suite/rpl/t/rpl_view.test	2010-12-19 17:15:12 +0000
+++ b/mysql-test/suite/rpl/t/rpl_view.test	2015-02-13 12:47:26 +0000
@@ -177,4 +177,27 @@ DROP TABLE t1;
 sync_slave_with_master;
 
 --echo End of 5.0 tests
+
+
+create table t1(a int);
+create view v1 as select a from t1;
+reset master;
+--echo #should be replicated
+repair view v1;
+--echo #should not be replicated
+repair LOCAL view v1;
+--echo #should not be replicated (independently of LOCAL or not)
+repair view v1 from mysql;
+--echo # CHECK should not be replicated
+check view v1;
+--echo # CHECK should not be replicated
+check view v1 for upgrade;
+--echo #should be replicated
+repair view v1;
+--replace_column 1 x 2 x 3 x 4 x 5 x
+show binlog events limit 1,100;
+drop view v1;
+drop table t1;
+
+
 --source include/rpl_end.inc

=== added file 'mysql-test/t/mysql_upgrade_view.test'
--- a/mysql-test/t/mysql_upgrade_view.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/t/mysql_upgrade_view.test	2015-02-13 12:47:26 +0000
@@ -0,0 +1,53 @@
+
+--disable_warnings
+drop table if exists t1,v1,v2,v3,v4;
+drop view if exists t1,v1,v2,v3,v4;
+--enable_warnings
+
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--copy_file $MYSQLD_DATADIR/mysql/event.MYI $MYSQLD_DATADIR/mysql/ev_bk.MYI
+--copy_file $MYSQLD_DATADIR/mysql/event.MYD $MYSQLD_DATADIR/mysql/ev_bk.MYD
+--copy_file $MYSQLD_DATADIR/mysql/event.frm $MYSQLD_DATADIR/mysql/ev_bk.frm
+--remove_file $MYSQLD_DATADIR/mysql/event.MYI
+--remove_file $MYSQLD_DATADIR/mysql/event.MYD
+--remove_file $MYSQLD_DATADIR/mysql/event.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.MYI $MYSQLD_DATADIR/mysql/event.MYI
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.MYD $MYSQLD_DATADIR/mysql/event.MYD
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.frm $MYSQLD_DATADIR/mysql/event.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm
+
+flush tables;
+
+create table t1(a int);
+create algorithm=temptable view v4 as select a from t1;
+show create view v1;
+show create view v2;
+show create view v3;
+show create view v4;
+
+--replace_result $MYSQLTEST_VARDIR var
+--exec $MYSQL_UPGRADE --force 2>&1
+
+show create view v1;
+show create view v2;
+show create view v3;
+show create view v4;
+
+--remove_file $MYSQLD_DATADIR/mysql/event.MYI
+--remove_file $MYSQLD_DATADIR/mysql/event.MYD
+--remove_file $MYSQLD_DATADIR/mysql/event.frm
+--copy_file $MYSQLD_DATADIR/mysql/ev_bk.MYI $MYSQLD_DATADIR/mysql/event.MYI
+--copy_file $MYSQLD_DATADIR/mysql/ev_bk.MYD $MYSQLD_DATADIR/mysql/event.MYD
+--copy_file $MYSQLD_DATADIR/mysql/ev_bk.frm $MYSQLD_DATADIR/mysql/event.frm
+--remove_file $MYSQLD_DATADIR/mysql/ev_bk.MYI
+--remove_file $MYSQLD_DATADIR/mysql/ev_bk.MYD
+--remove_file $MYSQLD_DATADIR/mysql/ev_bk.frm
+flush tables;
+
+drop view v1,v2,v3,v4;
+drop table t1;
+
+#select sleep(100);

=== modified file 'mysql-test/t/view.test'
--- a/mysql-test/t/view.test	2014-12-21 18:23:28 +0000
+++ b/mysql-test/t/view.test	2015-02-13 12:47:26 +0000
@@ -5345,6 +5345,81 @@ create view v1 as select 1;
 
 drop view v1;
 
+--echo #
+--echo #CHECK/REPAIR VIEW syntax
+--echo #
+
+create table t1 (a int);
+create view v1 as select a from t1;
+
+check view v1, t1;
+check view v1 FOR UPGRADE;
+--error ER_PARSE_ERROR
+check view v1 QUICK;
+--error ER_PARSE_ERROR
+check view v1 FAST;
+--error ER_PARSE_ERROR
+check view v1 EXTENDED;
+--error ER_PARSE_ERROR
+check view v1 CHANGED;
+repair view v1, t1;
+repair view v1 FROM MYSQL;
+--error ER_PARSE_ERROR
+repair table t1 FROM MYSQL;
+--error ER_PARSE_ERROR
+repair view v1 QUICK;
+--error ER_PARSE_ERROR
+repair view v1 EXTENDED;
+--error ER_PARSE_ERROR
+repair view v1 USE_FRM;
+
+drop view v1;
+drop table t1;
+
+--echo #
+--echo #CHECK/REPAIR VIEW
+--echo #
+create table t1(a int);
+let $MYSQLD_DATADIR= `select @@datadir`;
+
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v4.frm $MYSQLD_DATADIR/test/v4.frm
+create view v5 as select a from t1;
+
+show create view v1;
+show create view v2;
+show create view v3;
+check view v1,v2,v3,v4,v5 FOR UPGRADE;
+repair view v1,v2,v3,v4,v5 FROM MYSQL;
+check view v1,v2,v3,v4,v5 FOR UPGRADE;
+show create view v1;
+show create view v2;
+show create view v3;
+
+drop view v1,v2,v3,v4,v5;
+
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm
+--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v4.frm $MYSQLD_DATADIR/test/v4.frm
+create view v5 as select a from t1;
+
+show create view v1;
+show create view v2;
+show create view v3;
+check view v1,v2,v3,v4,v5;
+repair view v1,v2,v3,v4,v5;
+check view v1,v2,v3,v4,v5;
+show create view v1;
+show create view v2;
+show create view v3;
+
+drop view v1,v2,v3,v4,v5;
+drop table t1;
+
+
 --echo # -----------------------------------------------------------------
 --echo # -- End of 5.5 tests.
 --echo # -----------------------------------------------------------------

=== modified file 'sql/lex.h'
--- a/sql/lex.h	2012-09-05 15:23:51 +0000
+++ b/sql/lex.h	2015-02-13 12:47:26 +0000
@@ -376,6 +376,7 @@ static SYMBOL symbols[] = {
   { "MULTIPOINT",	SYM(MULTIPOINT)},
   { "MULTIPOLYGON",	SYM(MULTIPOLYGON)},
   { "MUTEX",  SYM(MUTEX_SYM)},
+  { "MYSQL",            SYM(MYSQL_SYM)},
   { "MYSQL_ERRNO",      SYM(MYSQL_ERRNO_SYM)},
   { "NAME",             SYM(NAME_SYM)},
   { "NAMES",		SYM(NAMES_SYM)},

=== modified file 'sql/share/errmsg-utf8.txt'
--- a/sql/share/errmsg-utf8.txt	2014-05-27 06:45:01 +0000
+++ b/sql/share/errmsg-utf8.txt	2015-02-13 12:47:26 +0000
@@ -5584,8 +5584,7 @@ ER_SP_WRONG_NAME 42000
         eng "Incorrect routine name '%-.192s'"
         ger "Ung?ltiger Routinenname '%-.192s'"
 ER_TABLE_NEEDS_UPGRADE
-        eng "Table upgrade required. Please do \"REPAIR TABLE `%-.32s`\" or dump/reload to fix it!"
-        ger "Tabellenaktualisierung erforderlich. Bitte zum Reparieren \"REPAIR TABLE `%-.32s`\" eingeben!"
+        eng "Table/view upgrade required. Please do \"REPAIR TABLE/VIEW %`-.32s\" or dump/reload to fix it!"
 ER_SP_NO_AGGREGATE 42000
         eng "AGGREGATE is not supported for stored functions"
         ger "AGGREGATE wird bei gespeicherten Funktionen nicht unterst?tzt"

=== modified file 'sql/sql_admin.cc'
--- a/sql/sql_admin.cc	2014-05-03 16:12:17 +0000
+++ b/sql/sql_admin.cc	2015-02-13 12:47:26 +0000
@@ -314,7 +314,8 @@ static bool mysql_admin_table(THD* thd,
                                                   HA_CHECK_OPT *),
                               int (handler::*operator_func)(THD *,
                                                             HA_CHECK_OPT *),
-                              int (view_operator_func)(THD *, TABLE_LIST*))
+                              int (view_operator_func)(THD *, TABLE_LIST*,
+                                                       HA_CHECK_OPT *))
 {
   TABLE_LIST *table;
   SELECT_LEX *select= &thd->lex->select_lex;
@@ -380,7 +381,18 @@ static bool mysql_admin_table(THD* thd,
       lex->query_tables_own_last= 0;
 
       if (view_operator_func == NULL)
+      {
         table->required_type=FRMTYPE_TABLE;
+        DBUG_ASSERT(!lex->only_view);
+      }
+      else if (lex->only_view)
+      {
+        table->required_type= FRMTYPE_VIEW;
+      }
+      else if (!lex->only_view && lex->sql_command == SQLCOM_REPAIR)
+      {
+        table->required_type= FRMTYPE_TABLE;
+      }
 
       if (lex->sql_command == SQLCOM_CHECK ||
           lex->sql_command == SQLCOM_REPAIR ||
@@ -506,9 +518,9 @@ static bool mysql_admin_table(THD* thd,
     }
 
     /*
-      CHECK TABLE command is only command where VIEW allowed here and this
-      command use only temporary teble method for VIEWs resolving => there
-      can't be VIEW tree substitition of join view => if opening table
+      CHECK/REPAIR TABLE command is only command where VIEW allowed here and
+      this command use only temporary table method for VIEWs resolving =>
+      there can't be VIEW tree substitition of join view => if opening table
       succeed then table->table will have real TABLE pointer as value (in
       case of join view substitution table->table can be 0, but here it is
       impossible)
@@ -521,7 +533,7 @@ static bool mysql_admin_table(THD* thd,
                      ER_CHECK_NO_SUCH_TABLE, ER(ER_CHECK_NO_SUCH_TABLE));
       /* if it was a view will check md5 sum */
       if (table->view &&
-          view_checksum(thd, table) == HA_ADMIN_WRONG_CHECKSUM)
+          view_check(thd, table, check_opt) == HA_ADMIN_WRONG_CHECKSUM)
         push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                      ER_VIEW_CHECKSUM, ER(ER_VIEW_CHECKSUM));
       if (thd->stmt_da->is_error() &&
@@ -536,7 +548,7 @@ static bool mysql_admin_table(THD* thd,
     if (table->view)
     {
       DBUG_PRINT("admin", ("calling view_operator_func"));
-      result_code= (*view_operator_func)(thd, table);
+      result_code= (*view_operator_func)(thd, table, check_opt);
       goto send_result;
     }
 
@@ -857,7 +869,8 @@ send_result_message:
       size_t length;
 
       protocol->store(STRING_WITH_LEN("error"), system_charset_info);
-      if (table->table->file->ha_table_flags() & HA_CAN_REPAIR)
+      if (lex->only_view ||
+          table->table->file->ha_table_flags() & HA_CAN_REPAIR)
         length= my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE),
                             table->table_name);
       else
@@ -1071,7 +1084,7 @@ bool Check_table_statement::execute(THD
 
   res= mysql_admin_table(thd, first_table, &m_lex->check_opt, "check",
                          lock_type, 0, 0, HA_OPEN_FOR_REPAIR, 0,
-                         &handler::ha_check, &view_checksum);
+                         &handler::ha_check, &view_check);
 
   m_lex->select_lex.table_list.first= first_table;
   m_lex->query_tables= first_table;
@@ -1126,10 +1139,11 @@ bool Repair_table_statement::execute(THD
                          TL_WRITE, 1,
                          test(m_lex->check_opt.sql_flags & TT_USEFRM),
                          HA_OPEN_FOR_REPAIR, &prepare_for_repair,
-                         &handler::ha_repair, 0);
+                         &handler::ha_repair, &view_repair);
 
   /* ! we write after unlocking the table */
-  if (!res && !m_lex->no_write_to_binlog)
+  if (!res && !m_lex->no_write_to_binlog &&
+      !(m_lex->check_opt.sql_flags & TT_FROM_MYSQL))
   {
     /*
       Presumably, REPAIR and binlog writing doesn't require synchronization

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2014-10-31 13:07:29 +0000
+++ b/sql/sql_base.cc	2015-02-13 12:47:26 +0000
@@ -643,7 +643,8 @@ found:
     open_table_error(share, share->error, share->open_errno, share->errarg);
     DBUG_RETURN(0);
   }
-  if (share->is_view && !(db_flags & OPEN_VIEW))
+  if ((share->is_view && !(db_flags & OPEN_VIEW)) ||
+      (!share->is_view && (db_flags & OPEN_VIEW_ONLY)))
   {
     open_table_error(share, 1, ENOENT, 0);
     DBUG_RETURN(0);
@@ -3024,7 +3025,11 @@ retry_share:
   mysql_mutex_lock(&LOCK_open);
 
   if (!(share= get_table_share_with_discover(thd, table_list, key,
-                                             key_length, OPEN_VIEW,
+                                             key_length,
+                                             (OPEN_VIEW |
+                                              ((table_list->required_type ==
+                                                FRMTYPE_VIEW) ?
+                                               OPEN_VIEW_ONLY : 0)),
                                              &error,
                                              hash_value)))
   {

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2015-01-14 11:10:13 +0000
+++ b/sql/sql_table.cc	2015-02-13 12:47:26 +0000
@@ -28,7 +28,6 @@
 #include "sql_base.h"   // open_table_uncached, lock_table_names
 #include "lock.h"       // mysql_unlock_tables
 #include "strfunc.h"    // find_type2, find_set
-#include "sql_view.h" // view_checksum 
 #include "sql_truncate.h"                       // regenerate_locked_table 
 #include "sql_partition.h"                      // mem_alloc_error,
                                                 // generate_partition_syntax,

=== modified file 'sql/sql_view.cc'
--- a/sql/sql_view.cc	2014-12-21 18:23:28 +0000
+++ b/sql/sql_view.cc	2015-02-13 12:47:26 +0000
@@ -729,6 +729,26 @@ err:
 }
 
 
+static void make_view_filename(LEX_STRING *dir, char *dir_buff,
+                               size_t dir_buff_len,
+                               LEX_STRING *path, char *path_buff,
+                               size_t path_buff_len,
+                               LEX_STRING *file,
+                               TABLE_LIST *view)
+{
+  /* print file name */
+  dir->length= build_table_filename(dir_buff, dir_buff_len - 1,
+                                   view->db, "", "", 0);
+  dir->str= dir_buff;
+
+  path->length= build_table_filename(path_buff, path_buff_len - 1,
+                                     view->db, view->table_name, reg_ext, 0);
+  path->str= path_buff;
+
+  file->str= path->str + dir->length;
+  file->length= path->length - dir->length;
+}
+
 /* number of required parameters for making view */
 static const int required_view_parameters= 15;
 
@@ -791,6 +811,96 @@ static File_option view_parameters[]=
 static LEX_STRING view_file_type[]= {{(char*) STRING_WITH_LEN("VIEW") }};
 
 
+int mariadb_fix_view(THD *thd, TABLE_LIST *view, bool wrong_checksum,
+                     bool swap_alg)
+{
+  char dir_buff[FN_REFLEN + 1], path_buff[FN_REFLEN + 1];
+  LEX_STRING dir, file, path;
+  bool alg_chenged= 0, checksum_fixed= 0, mariadbversion_added= 0;
+  DBUG_ENTER("mariadb_fix_view");
+
+  if (view->algorithm == VIEW_ALGORITHM_UNDEFINED &&
+      !wrong_checksum && view->mariadb_version)
+    DBUG_RETURN(HA_ADMIN_OK);
+
+  make_view_filename(&dir, dir_buff, sizeof(dir_buff),
+                     &path, path_buff, sizeof(path_buff),
+                     &file, view);
+  /* init timestamp */
+  if (!view->timestamp.str)
+    view->timestamp.str= view->timestamp_buffer;
+
+  /* check old .frm */
+  {
+    char path_buff[FN_REFLEN];
+    LEX_STRING path;
+    File_parser *parser;
+
+    path.str= path_buff;
+    fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME);
+    path.length= strlen(path_buff);
+    if (access(path.str, F_OK))
+      DBUG_RETURN(HA_ADMIN_INVALID);
+
+    if (!(parser= sql_parse_prepare(&path, thd->mem_root, 0)))
+      DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);
+
+    if (!parser->ok() || !is_equal(&view_type, parser->type()))
+      DBUG_RETURN(HA_ADMIN_INVALID);
+  }
+
+  if (swap_alg && view->algorithm != VIEW_ALGORITHM_UNDEFINED)
+  {
+    DBUG_ASSERT(view->algorithm == VIEW_ALGORITHM_MERGE ||
+                view->algorithm == VIEW_ALGORITHM_TMPTABLE);
+    if (view->algorithm == VIEW_ALGORITHM_MERGE)
+      view->algorithm= VIEW_ALGORITHM_TMPTABLE;
+    else
+      view->algorithm= VIEW_ALGORITHM_MERGE;
+    alg_chenged= 1;
+  }
+  if (wrong_checksum)
+  {
+    if (view->md5.length != 32)
+    {
+       if ((view->md5.str= (char *)thd->alloc(32 + 1)) == NULL)
+         DBUG_RETURN(HA_ADMIN_FAILED);
+    }
+    view->calc_md5(view->md5.str);
+    view->md5.length= 32;
+    checksum_fixed= 1;
+  }
+  if (!view->mariadb_version)
+  {
+    view->mariadb_version= MYSQL_VERSION_ID;
+    mariadbversion_added= 1;
+  }
+
+  if (sql_create_definition_file(&dir, &file, view_file_type,
+                                (uchar*)view, view_parameters))
+  {
+    sql_print_error("View '%-.192s'.'%-.192s': algorithm swap error.",
+                    view->db, view->table_name);
+    DBUG_RETURN(HA_ADMIN_INTERNAL_ERROR);
+  }
+
+  if (alg_chenged)
+    sql_print_information("View '%-.192s'.'%-.192s': algorithm swapped to '%s'",
+                          view->db, view->table_name,
+                          (view->algorithm == VIEW_ALGORITHM_MERGE)?
+                          "MERGE":"TEMPTABLE");
+  if (checksum_fixed)
+    sql_print_information("View '%-.192s'.'%-.192s': checksum fixed",
+                          view->db, view->table_name);
+  if (mariadbversion_added)
+    sql_print_information("View '%-.192s'.'%-.192s': mariadb-version added",
+                          view->db, view->table_name);
+
+
+  DBUG_RETURN(HA_ADMIN_OK);
+}
+
+
 /*
   Register VIEW (write .frm & process .frm's history backups)
 
@@ -927,17 +1037,9 @@ static int mysql_register_view(THD *thd,
   }
 loop_out:
   /* print file name */
-  dir.length= build_table_filename(dir_buff, sizeof(dir_buff) - 1,
-                                   view->db, "", "", 0);
-  dir.str= dir_buff;
-
-  path.length= build_table_filename(path_buff, sizeof(path_buff) - 1,
-                                    view->db, view->table_name, reg_ext, 0);
-  path.str= path_buff;
-
-  file.str= path.str + dir.length;
-  file.length= path.length - dir.length;
-
+  make_view_filename(&dir, dir_buff, sizeof(dir_buff),
+                     &path, path_buff, sizeof(path_buff),
+                     &file, view);
   /* init timestamp */
   if (!view->timestamp.str)
     view->timestamp.str= view->timestamp_buffer;
@@ -1063,7 +1165,7 @@ err:
 
   SYNOPSIS
     mysql_make_view()
-    thd			Thread handler
+    thd			Thread handle
     parser		parser object
     table		TABLE_LIST structure for filling
     flags               flags
@@ -1634,7 +1736,7 @@ err:
 
   SYNOPSIS
     mysql_drop_view()
-    thd		- thread handler
+    thd		- thread handle
     views	- views to delete
     drop_mode	- cascade/check
 
@@ -1755,7 +1857,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIS
 
   SYNOPSIS
     check_key_in_view()
-    thd     thread handler
+    thd     thread handle
     view    view for check with opened table
 
   DESCRIPTION
@@ -1941,6 +2043,63 @@ int view_checksum(THD *thd, TABLE_LIST *
           HA_ADMIN_OK);
 }
 
+/**
+  Check view
+
+  @param thd             thread handle
+  @param view            view for check
+  @param check_opt       check options
+
+  @retval HA_ADMIN_OK               OK
+  @retval HA_ADMIN_NOT_IMPLEMENTED  it is not VIEW
+  @retval HA_ADMIN_WRONG_CHECKSUM   check sum is wrong
+*/
+int view_check(THD *thd, TABLE_LIST *view, HA_CHECK_OPT *check_opt)
+{
+  int res;
+  DBUG_ENTER("view_check");
+  if ((res= view_checksum(thd, view)) != HA_ADMIN_OK)
+    DBUG_RETURN(res);
+  if (((check_opt->sql_flags & TT_FOR_UPGRADE) &&
+       !view->mariadb_version))
+  {
+    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+                            ER_TABLE_NEEDS_UPGRADE,
+                            ER(ER_TABLE_NEEDS_UPGRADE),
+                            view->table_name);
+    DBUG_RETURN(HA_ADMIN_NEEDS_UPGRADE);
+  }
+  DBUG_RETURN(HA_ADMIN_OK);
+}
+
+
+/**
+  Repair view
+
+  @param thd             thread handle
+  @param view            view for check
+  @param check_opt       check options
+
+  @retval HA_ADMIN_OK               OK
+  @retval HA_ADMIN_NOT_IMPLEMENTED  it is not VIEW
+  @retval HA_ADMIN_WRONG_CHECKSUM   check sum is wrong
+*/
+
+int view_repair(THD *thd, TABLE_LIST *view, HA_CHECK_OPT *check_opt)
+{
+  DBUG_ENTER("view_repair");
+  bool swap_alg=
+    ((check_opt->sql_flags & TT_FROM_MYSQL) &&
+     (!view->mariadb_version));
+  bool wrong_checksum= view_checksum(thd, view);
+  if (wrong_checksum || swap_alg || !view->mariadb_version)
+  {
+    int res= mariadb_fix_view(thd, view, wrong_checksum, swap_alg);
+    DBUG_RETURN(res);
+  }
+  DBUG_RETURN(HA_ADMIN_OK);
+}
+
 /*
   rename view
 

=== modified file 'sql/sql_view.h'
--- a/sql/sql_view.h	2011-06-30 15:46:53 +0000
+++ b/sql/sql_view.h	2015-02-13 12:47:26 +0000
@@ -44,6 +44,8 @@ bool check_key_in_view(THD *thd, TABLE_L
 bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view);
 
 int view_checksum(THD *thd, TABLE_LIST *view);
+int view_check(THD *thd, TABLE_LIST *view, HA_CHECK_OPT *check_opt);
+int view_repair(THD *thd, TABLE_LIST *view, HA_CHECK_OPT *check_opt);
 
 extern TYPELIB updatable_views_with_limit_typelib;
 

=== modified file 'sql/sql_yacc.yy'
--- a/sql/sql_yacc.yy	2014-11-08 18:54:42 +0000
+++ b/sql/sql_yacc.yy	2015-02-13 12:47:26 +0000
@@ -1145,6 +1145,7 @@ bool my_yyoverflow(short **a, YYSTYPE **
 %token  MULTIPOINT
 %token  MULTIPOLYGON
 %token  MUTEX_SYM
+%token  MYSQL_SYM
 %token  MYSQL_ERRNO_SYM
 %token  NAMES_SYM                     /* SQL-2003-N */
 %token  NAME_SYM                      /* SQL-2003-N */
@@ -7191,7 +7192,7 @@ opt_checksum_type:
         ;
 
 repair:
-          REPAIR opt_no_write_to_binlog table_or_tables
+          REPAIR opt_no_write_to_binlog table_or_view
           {
             LEX *lex=Lex;
             lex->sql_command = SQLCOM_REPAIR;
@@ -7204,6 +7205,15 @@ repair:
           table_list opt_mi_repair_type
           {
             LEX* lex= thd->lex;
+            if ((lex->only_view &&
+                 ((lex->check_opt.flags & (T_QUICK | T_EXTEND)) ||
+                   (lex->check_opt.sql_flags & TT_USEFRM))) ||
+                (!lex->only_view &&
+                 (lex->check_opt.sql_flags & TT_FROM_MYSQL)))
+            {
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
+            }
             DBUG_ASSERT(!lex->m_stmt);
             lex->m_stmt= new (thd->mem_root) Repair_table_statement(lex);
             if (lex->m_stmt == NULL)
@@ -7225,6 +7235,7 @@ mi_repair_type:
           QUICK        { Lex->check_opt.flags|= T_QUICK; }
         | EXTENDED_SYM { Lex->check_opt.flags|= T_EXTEND; }
         | USE_FRM      { Lex->check_opt.sql_flags|= TT_USEFRM; }
+        | FROM MYSQL_SYM { Lex->check_opt.sql_flags|= TT_FROM_MYSQL; }
         ;
 
 analyze:
@@ -7257,7 +7268,7 @@ binlog_base64_event:
         ;
 
 check:
-          CHECK_SYM table_or_tables
+          CHECK_SYM table_or_view
           {
             LEX *lex=Lex;
 
@@ -7275,6 +7286,13 @@ check:
           table_list opt_mi_check_type
           {
             LEX* lex= thd->lex;
+            if (lex->only_view &&
+                (lex->check_opt.flags & (T_QUICK | T_FAST | T_EXTEND |
+                                         T_CHECK_ONLY_CHANGED)))
+            {
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
+            }
             DBUG_ASSERT(!lex->m_stmt);
             lex->m_stmt= new (thd->mem_root) Check_table_statement(lex);
             if (lex->m_stmt == NULL)
@@ -7382,6 +7400,7 @@ keycache:
             LEX *lex=Lex;
             lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
             lex->ident= $6;
+            lex->only_view= FALSE;
           }
         ;
 
@@ -7426,6 +7445,7 @@ preload:
             LEX *lex=Lex;
             lex->sql_command=SQLCOM_PRELOAD_KEYS;
             lex->alter_info.reset();
+            lex->only_view= FALSE;
           }
           preload_list_or_parts
           {}
@@ -13186,6 +13206,7 @@ keyword_sp:
         | MULTIPOINT               {}
         | MULTIPOLYGON             {}
         | MUTEX_SYM                {}
+        | MYSQL_SYM                {}
         | MYSQL_ERRNO_SYM          {}
         | NAME_SYM                 {}
         | NAMES_SYM                {}
@@ -13785,7 +13806,18 @@ lock:
 
 table_or_tables:
           TABLE_SYM
+         { Lex->only_view= FALSE; }
+        | TABLES
+         { Lex->only_view= FALSE; }
+        ;
+
+table_or_view:
+          TABLE_SYM
+         { Lex->only_view= FALSE; }
         | TABLES
+         { Lex->only_view= FALSE; }
+        | VIEW_SYM
+         { Lex->only_view= TRUE; }
         ;
 
 table_lock_list:



More information about the commits mailing list