Loading mysql-test/r/view.result +27 −1 Original line number Diff line number Diff line Loading @@ -2849,7 +2849,6 @@ SHOW TABLES; Tables_in_test t1 DROP TABLE t1; DROP VIEW IF EXISTS v1; DROP TABLE IF EXISTS t1; DROP VIEW IF EXISTS v1; DROP VIEW IF EXISTS v2; Loading @@ -2861,3 +2860,30 @@ CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890 VIEW v2 AS SELECT b FROM t1; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) DROP TABLE t1; DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP VIEW IF EXISTS v1, v2; DROP TABLE IF EXISTS t1; CREATE TABLE t1 (i INT); CREATE VIEW v1 AS SELECT * FROM t1; CREATE FUNCTION f1() RETURNS INT BEGIN INSERT INTO v1 VALUES (0); RETURN 0; END | SELECT f1(); f1() 0 CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; CREATE FUNCTION f2() RETURNS INT BEGIN INSERT INTO v2 VALUES (0); RETURN 0; END | SELECT f2(); ERROR HY000: The target table v2 of the INSERT is not updatable DROP FUNCTION f1; DROP FUNCTION f2; DROP VIEW v1, v2; DROP TABLE t1; End of 5.0 tests. mysql-test/t/view.test +50 −3 Original line number Diff line number Diff line Loading @@ -2715,9 +2715,6 @@ DROP VIEW t1,v1; SHOW TABLES; DROP TABLE t1; --disable_warnings DROP VIEW IF EXISTS v1; --enable_warnings # Loading Loading @@ -2745,3 +2742,53 @@ CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890 # Cleanup. DROP TABLE t1; # # BUG#17591: Updatable view not possible with trigger or stored # function # # During prelocking phase we didn't update lock type of view tables, # hence READ lock was always requested. # --disable_warnings DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP VIEW IF EXISTS v1, v2; DROP TABLE IF EXISTS t1; --enable_warnings CREATE TABLE t1 (i INT); CREATE VIEW v1 AS SELECT * FROM t1; delimiter |; CREATE FUNCTION f1() RETURNS INT BEGIN INSERT INTO v1 VALUES (0); RETURN 0; END | delimiter ;| SELECT f1(); CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; delimiter |; CREATE FUNCTION f2() RETURNS INT BEGIN INSERT INTO v2 VALUES (0); RETURN 0; END | delimiter ;| --error ER_NON_UPDATABLE_TABLE SELECT f2(); DROP FUNCTION f1; DROP FUNCTION f2; DROP VIEW v1, v2; DROP TABLE t1; --echo End of 5.0 tests. sql/sql_view.cc +30 −22 Original line number Diff line number Diff line Loading @@ -1052,6 +1052,31 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) table->next_global= view_tables; } bool view_is_mergeable= (table->algorithm != VIEW_ALGORITHM_TMPTABLE && lex->can_be_merged()); TABLE_LIST *view_main_select_tables; if (view_is_mergeable) { /* Currently 'view_main_select_tables' differs from 'view_tables' only then view has CONVERT_TZ() function in its select list. This may change in future, for example if we enable merging of views with subqueries in select list. */ view_main_select_tables= (TABLE_LIST*)lex->select_lex.table_list.first; /* Let us set proper lock type for tables of the view's main select since we may want to perform update or insert on view. This won't work for view containing union. But this is ok since we don't allow insert and update on such views anyway. */ for (tbl= view_main_select_tables; tbl; tbl= tbl->next_local) tbl->lock_type= table->lock_type; } /* If we are opening this view as part of implicit LOCK TABLES, then this view serves as simple placeholder and we should not continue Loading Loading @@ -1106,43 +1131,26 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) - VIEW SELECT allow merging - VIEW used in subquery or command support MERGE algorithm */ if (table->algorithm != VIEW_ALGORITHM_TMPTABLE && lex->can_be_merged() && if (view_is_mergeable && (table->select_lex->master_unit() != &old_lex->unit || old_lex->can_use_merged()) && !old_lex->can_not_use_merged()) { List_iterator_fast<TABLE_LIST> ti(view_select->top_join_list); /* Currently 'view_main_select_tables' differs from 'view_tables' only then view has CONVERT_TZ() function in its select list. This may change in future, for example if we enable merging of views with subqueries in select list. */ TABLE_LIST *view_main_select_tables= (TABLE_LIST*)lex->select_lex.table_list.first; /* lex should contain at least one table */ DBUG_ASSERT(view_main_select_tables != 0); List_iterator_fast<TABLE_LIST> ti(view_select->top_join_list); table->effective_algorithm= VIEW_ALGORITHM_MERGE; DBUG_PRINT("info", ("algorithm: MERGE")); table->updatable= (table->updatable_view != 0); table->effective_with_check= old_lex->get_effective_with_check(table); table->merge_underlying_list= view_main_select_tables; /* Let us set proper lock type for tables of the view's main select since we may want to perform update or insert on view. This won't work for view containing union. But this is ok since we don't allow insert and update on such views anyway. Also we fill correct wanted privileges. */ for (tbl= table->merge_underlying_list; tbl; tbl= tbl->next_local) { tbl->lock_type= table->lock_type; /* Fill correct wanted privileges. */ for (tbl= view_main_select_tables; tbl; tbl= tbl->next_local) tbl->grant.want_privilege= top_view->grant.orig_want_privilege; } /* prepare view context */ lex->select_lex.context.resolve_in_table_list_only(view_main_select_tables); Loading Loading
mysql-test/r/view.result +27 −1 Original line number Diff line number Diff line Loading @@ -2849,7 +2849,6 @@ SHOW TABLES; Tables_in_test t1 DROP TABLE t1; DROP VIEW IF EXISTS v1; DROP TABLE IF EXISTS t1; DROP VIEW IF EXISTS v1; DROP VIEW IF EXISTS v2; Loading @@ -2861,3 +2860,30 @@ CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890 VIEW v2 AS SELECT b FROM t1; ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghijQWERTY' is too long for host name (should be no longer than 60) DROP TABLE t1; DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP VIEW IF EXISTS v1, v2; DROP TABLE IF EXISTS t1; CREATE TABLE t1 (i INT); CREATE VIEW v1 AS SELECT * FROM t1; CREATE FUNCTION f1() RETURNS INT BEGIN INSERT INTO v1 VALUES (0); RETURN 0; END | SELECT f1(); f1() 0 CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; CREATE FUNCTION f2() RETURNS INT BEGIN INSERT INTO v2 VALUES (0); RETURN 0; END | SELECT f2(); ERROR HY000: The target table v2 of the INSERT is not updatable DROP FUNCTION f1; DROP FUNCTION f2; DROP VIEW v1, v2; DROP TABLE t1; End of 5.0 tests.
mysql-test/t/view.test +50 −3 Original line number Diff line number Diff line Loading @@ -2715,9 +2715,6 @@ DROP VIEW t1,v1; SHOW TABLES; DROP TABLE t1; --disable_warnings DROP VIEW IF EXISTS v1; --enable_warnings # Loading Loading @@ -2745,3 +2742,53 @@ CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890 # Cleanup. DROP TABLE t1; # # BUG#17591: Updatable view not possible with trigger or stored # function # # During prelocking phase we didn't update lock type of view tables, # hence READ lock was always requested. # --disable_warnings DROP FUNCTION IF EXISTS f1; DROP FUNCTION IF EXISTS f2; DROP VIEW IF EXISTS v1, v2; DROP TABLE IF EXISTS t1; --enable_warnings CREATE TABLE t1 (i INT); CREATE VIEW v1 AS SELECT * FROM t1; delimiter |; CREATE FUNCTION f1() RETURNS INT BEGIN INSERT INTO v1 VALUES (0); RETURN 0; END | delimiter ;| SELECT f1(); CREATE ALGORITHM=TEMPTABLE VIEW v2 AS SELECT * FROM t1; delimiter |; CREATE FUNCTION f2() RETURNS INT BEGIN INSERT INTO v2 VALUES (0); RETURN 0; END | delimiter ;| --error ER_NON_UPDATABLE_TABLE SELECT f2(); DROP FUNCTION f1; DROP FUNCTION f2; DROP VIEW v1, v2; DROP TABLE t1; --echo End of 5.0 tests.
sql/sql_view.cc +30 −22 Original line number Diff line number Diff line Loading @@ -1052,6 +1052,31 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) table->next_global= view_tables; } bool view_is_mergeable= (table->algorithm != VIEW_ALGORITHM_TMPTABLE && lex->can_be_merged()); TABLE_LIST *view_main_select_tables; if (view_is_mergeable) { /* Currently 'view_main_select_tables' differs from 'view_tables' only then view has CONVERT_TZ() function in its select list. This may change in future, for example if we enable merging of views with subqueries in select list. */ view_main_select_tables= (TABLE_LIST*)lex->select_lex.table_list.first; /* Let us set proper lock type for tables of the view's main select since we may want to perform update or insert on view. This won't work for view containing union. But this is ok since we don't allow insert and update on such views anyway. */ for (tbl= view_main_select_tables; tbl; tbl= tbl->next_local) tbl->lock_type= table->lock_type; } /* If we are opening this view as part of implicit LOCK TABLES, then this view serves as simple placeholder and we should not continue Loading Loading @@ -1106,43 +1131,26 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table) - VIEW SELECT allow merging - VIEW used in subquery or command support MERGE algorithm */ if (table->algorithm != VIEW_ALGORITHM_TMPTABLE && lex->can_be_merged() && if (view_is_mergeable && (table->select_lex->master_unit() != &old_lex->unit || old_lex->can_use_merged()) && !old_lex->can_not_use_merged()) { List_iterator_fast<TABLE_LIST> ti(view_select->top_join_list); /* Currently 'view_main_select_tables' differs from 'view_tables' only then view has CONVERT_TZ() function in its select list. This may change in future, for example if we enable merging of views with subqueries in select list. */ TABLE_LIST *view_main_select_tables= (TABLE_LIST*)lex->select_lex.table_list.first; /* lex should contain at least one table */ DBUG_ASSERT(view_main_select_tables != 0); List_iterator_fast<TABLE_LIST> ti(view_select->top_join_list); table->effective_algorithm= VIEW_ALGORITHM_MERGE; DBUG_PRINT("info", ("algorithm: MERGE")); table->updatable= (table->updatable_view != 0); table->effective_with_check= old_lex->get_effective_with_check(table); table->merge_underlying_list= view_main_select_tables; /* Let us set proper lock type for tables of the view's main select since we may want to perform update or insert on view. This won't work for view containing union. But this is ok since we don't allow insert and update on such views anyway. Also we fill correct wanted privileges. */ for (tbl= table->merge_underlying_list; tbl; tbl= tbl->next_local) { tbl->lock_type= table->lock_type; /* Fill correct wanted privileges. */ for (tbl= view_main_select_tables; tbl; tbl= tbl->next_local) tbl->grant.want_privilege= top_view->grant.orig_want_privilege; } /* prepare view context */ lex->select_lex.context.resolve_in_table_list_only(view_main_select_tables); Loading