diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 30043e066db..05aeda80c85 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3283,3 +3283,38 @@ DROP TABLE `t-2`; DROP VIEW `v-2`; DROP DATABASE `d-1`; USE test; +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT); +CREATE VIEW v1 AS SELECT * FROM t1; +ALTER VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` +ALTER DEFINER=no_such@user_1 VIEW v1 AS SELECT * FROM t1; +Warnings: +Note 1449 There is no 'no_such'@'user_1' registered +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`no_such`@`user_1` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` +Warnings: +Note 1449 There is no 'no_such'@'user_1' registered +ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +Warnings: +Note 1449 There is no 'no_such'@'user_1' registered +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=MERGE DEFINER=`no_such`@`user_1` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` +Warnings: +Note 1449 There is no 'no_such'@'user_1' registered +ALTER ALGORITHM=TEMPTABLE DEFINER=no_such@user_2 VIEW v1 AS SELECT * FROM t1; +Warnings: +Note 1449 There is no 'no_such'@'user_2' registered +SHOW CREATE VIEW v1; +View Create View +v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`no_such`@`user_2` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` +Warnings: +Note 1449 There is no 'no_such'@'user_2' registered +DROP VIEW v1; +DROP TABLE t1; +End of 5.1 tests. diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 520babafb7e..0915fb01e6f 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3175,3 +3175,30 @@ DROP TABLE `t-2`; DROP VIEW `v-2`; DROP DATABASE `d-1`; USE test; + + +# +# Test that ALTER VIEW accepts DEFINER and ALGORITHM, see bug#16425. +# +--disable_warnings +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT); +CREATE VIEW v1 AS SELECT * FROM t1; + +ALTER VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +ALTER DEFINER=no_such@user_1 VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +ALTER ALGORITHM=MERGE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +ALTER ALGORITHM=TEMPTABLE DEFINER=no_such@user_2 VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; + +DROP VIEW v1; +DROP TABLE t1; + + +--echo End of 5.1 tests. diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 5d24fb4fa65..1e666e475a0 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -492,7 +492,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); Currently there is 287 shift/reduce conflict. We should not introduce new conflicts any more. */ -%expect 287 +%expect 286 /* Comments for TOKENS. @@ -1246,7 +1246,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); statement sp_suid sp_c_chistics sp_a_chistics sp_chistic sp_c_chistic xa load_data opt_field_or_var_spec fields_or_vars opt_load_data_set_spec - definer view_replace_or_algorithm view_replace view_algorithm_opt + definer view_replace_or_algorithm view_replace view_algorithm view_or_trigger_or_sp_or_event view_or_trigger_or_sp_or_event_tail view_suid view_tail view_list_opt view_list view_select @@ -5154,18 +5154,25 @@ alter: lex->sql_command= SQLCOM_ALTER_FUNCTION; lex->spname= $3; } - | ALTER view_algorithm_opt definer view_suid - VIEW_SYM table_ident - { - THD *thd= YYTHD; - LEX *lex= thd->lex; - lex->sql_command= SQLCOM_CREATE_VIEW; - lex->create_view_mode= VIEW_ALTER; - /* first table in list is target VIEW name */ - lex->select_lex.add_table_to_list(thd, $6, NULL, TL_OPTION_UPDATING); - } - view_list_opt AS view_select view_check_option - {} + | ALTER view_algorithm definer + { + Lex->create_view_mode= VIEW_ALTER; + } + view_tail + {} + | ALTER definer + /* + We have two separate rules for ALTER VIEW rather that + optional view_algorithm above, to resolve the ambiguity + with the ALTER EVENT below. + */ + { + LEX *lex= Lex; + lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; + lex->create_view_mode= VIEW_ALTER; + } + view_tail + {} | ALTER definer EVENT_SYM sp_name /* BE CAREFUL when you add a new rule to update the block where @@ -11298,13 +11305,6 @@ view_algorithm: { Lex->create_view_algorithm= VIEW_ALGORITHM_TMPTABLE; } ; -view_algorithm_opt: - /* empty */ - { Lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; } - | view_algorithm - {} - ; - view_suid: /* empty */ { Lex->create_view_suid= VIEW_SUID_DEFAULT; }