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

sanja at askmonty.org sanja at askmonty.org
Mon Feb 9 03:48:46 EET 2015


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

------------------------------------------------------------
revno: 4407
revision-id: sanja at askmonty.org-20150209014828-kx3cr36hgrvjhtrg
parent: svoj at mariadb.org-20150114135038-v50g2cul4vce63h8
committer: sanja at askmonty.org
branch nick: work-maria-5.5-MDEV-6916-check_view
timestamp: Mon 2015-02-09 02:48:28 +0100
message:
  MDEV-6916: Upgrade from MySQL to MariaDB breaks already created views
  
  CHECK/REPAIR commands and mysql_upgradesupport 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-09 01:48:28 +0000
@@ -40,7 +40,8 @@ static char mysql_path[FN_REFLEN];
 static char mysqlcheck_path[FN_REFLEN];
 
 static my_bool opt_force, opt_verbose, debug_info_flag, debug_check_flag,
-               opt_systables_only, opt_version_check;
+               opt_systables_only, opt_version_check,
+               opt_mysql_upgrade= 0, opt_skip_mysql_upgrade= 0;
 static my_bool opt_not_used, opt_silent;
 static uint my_end_arg= 0;
 static char *opt_user= (char*)"root";
@@ -150,6 +151,14 @@ static struct my_option my_long_options[
    &opt_not_used, &opt_not_used, 0, GET_BOOL, NO_ARG, 1, 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},
+  {"mysql-upgrade", 'y',
+    "Skip automatic detection MySQL and assume that we upgrade it",
+    &opt_mysql_upgrade, &opt_mysql_upgrade, 0, GET_BOOL, NO_ARG,
+    0, 0, 0, 0, 0, 0},
+  {"skip-mysql-upgrade", 'Y',
+    "Skip view algorithm upgrade from MySQL",
+    &opt_skip_mysql_upgrade, &opt_skip_mysql_upgrade, 0, GET_BOOL, NO_ARG,
+    0, 0, 0, 0, 0, 0},
   {"version-check", 'k', "Run this program only if its \'server version\' "
    "matches the version of the server to which it's connecting, (enabled by "
    "default); use --skip-version-check to avoid this check. Note: the \'server "
@@ -344,6 +353,14 @@ get_one_option(int optid, const struct m
   case OPT_DEFAULT_AUTH:                        /* --default-auth */
     add_one_option(&conn_args, opt, argument);
     break;
+  case 'y':
+    opt_mysql_upgrade= 1;
+    add_option= FALSE;
+    break;
+  case 'Y':
+    opt_skip_mysql_upgrade= 1;
+    add_option= FALSE;
+    break;
   }
 
   if (add_option)
@@ -754,6 +771,23 @@ static int run_mysqlcheck_upgrade(void)
                   NULL);
 }
 
+static int run_mysqlcheck_views(void)
+{
+  if (!opt_mysql_upgrade)
+    return 0;
+  verbose("Phase 0: 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",
+                  "--mysql-upgrade",
+                  opt_verbose ? "--verbose": "",
+                  opt_silent ? "--silent": "",
+                  "2>&1",
+                  NULL);
+}
 
 static int run_mysqlcheck_fixnames(void)
 {
@@ -928,6 +962,28 @@ static int check_version_match(void)
     return 0;
 }
 
+#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);
+}
+
 
 int main(int argc, char **argv)
 {
@@ -997,11 +1053,20 @@ int main(int argc, char **argv)
   if (opt_version_check && check_version_match())
     die("Upgrade failed");
 
+  if (!opt_systables_only && !opt_skip_mysql_upgrade)
+  {
+    if (!opt_mysql_upgrade)
+      opt_mysql_upgrade= is_mysql();
+  }
+  else
+    opt_mysql_upgrade= 0;
+
   /*
     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	2014-02-17 10:00:51 +0000
+++ b/client/mysqlcheck.c	2015-02-09 01:48:28 +0000
@@ -42,7 +42,8 @@ static my_bool opt_alldbs = 0, opt_check
                opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
                opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
                tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
-               opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0;
+               opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
+               opt_mysql_upgrade= 0;
 static my_bool opt_write_binlog= 1, opt_flush_tables= 0;
 static uint verbose = 0, opt_mysql_port=0;
 static int my_end_arg;
@@ -196,6 +197,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},
+  {"mysql-upgrade", 'y',
+   "Fix view algorithm view field if it is not new MariaDB view.",
+   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
   {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
 };
 
@@ -332,7 +336,13 @@ get_one_option(int optid, const struct m
   case 'v':
     verbose++;
     break;
-  case 'V': print_version(); exit(0);
+  case 'V':
+    print_version(); exit(0);
+    break;
+  case 'y':
+    what_to_do= DO_REPAIR;
+    opt_mysql_upgrade= 1;
+    break;
   case OPT_MYSQL_PROTOCOL:
     opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
                                     opt->name);
@@ -595,7 +605,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_mysql_upgrade)
+          continue;
+      }
+      else
+      {
+        if (opt_mysql_upgrade)
+          continue;
+      }
 
       end= fix_table_name(end, row[0]);
       *end++= ',';
@@ -611,7 +629,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_mysql_upgrade)
+          continue;
+      }
+      else
+      {
+        if (opt_mysql_upgrade)
+          continue;
+      }
       if (system_database &&
           (!strcmp(row[0], "general_log") ||
            !strcmp(row[0], "slow_log")))
@@ -756,10 +782,12 @@ static int handle_request_for_tables(cha
     if (opt_upgrade)            end = strmov(end, " FOR UPGRADE");
     break;
   case DO_REPAIR:
-    op= (opt_write_binlog) ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG";
+    op= ((opt_write_binlog || opt_mysql_upgrade) ?
+         "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG");
     if (opt_quick)              end = strmov(end, " QUICK");
     if (opt_extended)           end = strmov(end, " EXTENDED");
     if (opt_frm)                end = strmov(end, " USE_FRM");
+    if (opt_mysql_upgrade)      end = strmov(end, " FROM MYSQL");
     break;
   case DO_ANALYZE:
     op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
@@ -776,14 +804,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_mysql_upgrade ? "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_mysql_upgrade ? " VIEW " : " TABLE "));
     ptr= fix_table_name(ptr, tables);
     strmake(table_name_buff, org, min((int) sizeof(table_name_buff)-1,
                                       (int) (ptr - org)));

=== modified file 'include/myisamchk.h'
--- a/include/myisamchk.h	2014-01-22 14:29:36 +0000
+++ b/include/myisamchk.h	2015-02-09 01:48:28 +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

=== 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-09 01:48:28 +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 0: Fixing views
+test.v1                                            view is repaired
+test.v2                                            view is repaired
+test.v3                                            view is repaired
+test.v4                                            OK
+Phase 1/3: Fixing table and database names
+Phase 2/3: 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 3/3: 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/view.result'
--- a/mysql-test/r/view.result	2014-12-21 18:23:28 +0000
+++ b/mysql-test/r/view.result	2015-02-09 01:48:28 +0000
@@ -5398,6 +5398,94 @@ 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	view 'test.v1' has no field mariadb server in its .frm file
+test.v1	check	status	needs repair
+test.v2	check	Note	view 'test.v2' has no field mariadb server in its .frm file
+test.v2	check	status	needs repair
+test.v3	check	Note	view 'test.v3' has no field mariadb server in its .frm file
+test.v3	check	status	needs repair
+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	view is repaired
+test.v2	repair	status	view is repaired
+test.v3	repair	status	view is repaired
+test.v4	repair	status	view is repaired
+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;
+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-09 01:48:28 +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-09 01:48:28 +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-09 01:48:28 +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-09 01:48:28 +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-09 01:48:28 +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-09 01:48:28 +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

=== 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-09 01:48:28 +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-09 01:48:28 +0000
@@ -5345,6 +5345,61 @@ 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;
+drop table t1;
 --echo # -----------------------------------------------------------------
 --echo # -- End of 5.5 tests.
 --echo # -----------------------------------------------------------------

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2015-01-13 18:28:03 +0000
+++ b/sql/handler.h	2015-02-09 01:48:28 +0000
@@ -42,6 +42,7 @@
 
 // the following is for checking tables
 
+#define HA_ADMIN_VIEW_REPAIR_IS_DONE 2
 #define HA_ADMIN_ALREADY_DONE	  1
 #define HA_ADMIN_OK               0
 #define HA_ADMIN_NOT_IMPLEMENTED -1
@@ -56,6 +57,7 @@
 #define HA_ADMIN_NEEDS_UPGRADE  -10
 #define HA_ADMIN_NEEDS_ALTER    -11
 #define HA_ADMIN_NEEDS_CHECK    -12
+#define HA_ADMIN_NEEDS_REPAIR   -13
 
 /* Bits in table_flags() to show what database can do */
 

=== modified file 'sql/lex.h'
--- a/sql/lex.h	2012-09-05 15:23:51 +0000
+++ b/sql/lex.h	2015-02-09 01:48:28 +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-09 01:48:28 +0000
@@ -6565,3 +6565,9 @@ ER_QUERY_EXCEEDED_ROWS_EXAMINED_LIMIT
 ER_NO_SUCH_TABLE_IN_ENGINE 42S02 
         eng "Table '%-.192s.%-.192s' doesn't exist in engine"
         swe "Det finns ingen tabell som heter '%-.192s.%-.192s' i handlern"
+ER_NO_MARIADB_SERVER_FIELD
+        eng "view '%-.192s.%-.192s' has no field mariadb server in its .frm file"
+ER_VIEW_REPAIR_IS_DONE
+        eng "view is repaired"
+ER_NEEDS_REPAIR
+        eng "needs repair"

=== 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-09 01:48:28 +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;
     }
 
@@ -867,6 +879,22 @@ send_result_message:
       fatal_error=1;
       break;
     }
+    case HA_ADMIN_VIEW_REPAIR_IS_DONE:
+    {
+      protocol->store(STRING_WITH_LEN("status"), system_charset_info);
+      protocol->store(ER(ER_VIEW_REPAIR_IS_DONE),
+                      strlen(ER(ER_VIEW_REPAIR_IS_DONE)),
+                      system_charset_info);
+      break;
+    }
+    case HA_ADMIN_NEEDS_REPAIR:
+    {
+      protocol->store(STRING_WITH_LEN("status"), system_charset_info);
+      protocol->store(ER(ER_NEEDS_REPAIR),
+                      strlen(ER(ER_NEEDS_REPAIR)),
+                      system_charset_info);
+      break;
+    }
 
     default:				// Probably HA_ADMIN_INTERNAL_ERROR
       {
@@ -1071,7 +1099,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,7 +1154,7 @@ 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)

=== 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-09 01:48:28 +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);
@@ -3019,12 +3020,17 @@ bool open_table(THD *thd, TABLE_LIST *ta
   else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB)
     DBUG_RETURN(FALSE);
 
+
 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-09 01:48:28 +0000
@@ -28,7 +28,7 @@
 #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_view.h" // view_check
 #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-09 01:48:28 +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,81 @@ 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;
+  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;
+  }
+  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;
+  }
+  view->mariadb_version= MYSQL_VERSION_ID;
+
+  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);
+  }
+  sql_print_information("View '%-.192s'.'%-.192s': algorithm swapped to '%s'",
+                        view->db, view->table_name,
+                        (view->algorithm == VIEW_ALGORITHM_MERGE)?
+                        "MERGE":"TEMPTABLE");
+
+
+  DBUG_RETURN(HA_ADMIN_VIEW_REPAIR_IS_DONE);
+}
+
+
 /*
   Register VIEW (write .frm & process .frm's history backups)
 
@@ -927,17 +1022,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 +1150,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 +1721,7 @@ err:
 
   SYNOPSIS
     mysql_drop_view()
-    thd		- thread handler
+    thd		- thread handle
     views	- views to delete
     drop_mode	- cascade/check
 
@@ -1755,7 +1842,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 +2028,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_NO_MARIADB_SERVER_FIELD,
+                            ER(ER_NO_MARIADB_SERVER_FIELD),
+                            view->db,
+                            view->table_name);
+    DBUG_RETURN(HA_ADMIN_NEEDS_REPAIR);
+  }
+  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)
+  {
+    DBUG_RETURN(mariadb_fix_view(thd, view, wrong_checksum, swap_alg));
+  }
+  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-09 01:48:28 +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-09 01:48:28 +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,11 +7192,16 @@ 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;
             lex->no_write_to_binlog= $2;
+            if (lex->no_write_to_binlog && lex->only_view)
+            {
+              my_parse_error(ER(ER_SYNTAX_ERROR));
+              MYSQL_YYABORT;
+            }
             lex->check_opt.init();
             lex->alter_info.reset();
             /* Will be overriden during execution. */
@@ -7204,6 +7210,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 +7240,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 +7273,7 @@ binlog_base64_event:
         ;
 
 check:
-          CHECK_SYM table_or_tables
+          CHECK_SYM table_or_view
           {
             LEX *lex=Lex;
 
@@ -7275,6 +7291,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 +7405,7 @@ keycache:
             LEX *lex=Lex;
             lex->sql_command= SQLCOM_ASSIGN_TO_KEYCACHE;
             lex->ident= $6;
+            lex->only_view= FALSE;
           }
         ;
 
@@ -7426,6 +7450,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 +13211,7 @@ keyword_sp:
         | MULTIPOINT               {}
         | MULTIPOLYGON             {}
         | MUTEX_SYM                {}
+        | MYSQL_SYM                {}
         | MYSQL_ERRNO_SYM          {}
         | NAME_SYM                 {}
         | NAMES_SYM                {}
@@ -13785,7 +13811,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