diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index f9a27e572dd..9dcf0833c18 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -1528,3 +1528,10 @@ substring_index(t,':',2) 12:24 drop view v1; drop table t1; +create table t1 (s1 tinyint); +create view v1 as select * from t1 where s1 <> 0 with local check option; +create view v2 as select * from v1 with cascaded check option; +insert into v2 values (0); +ERROR HY000: CHECK OPTION failed 'test.v2' +drop view v2, v1; +drop table t1; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 570fffa9b5b..716ed4aa6b3 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -1471,3 +1471,14 @@ select substring_index(t,':',2) from t1; select substring_index(t,':',2) from v1; drop view v1; drop table t1; + +# +# test of cascaded check option for whiew without WHERE clause +# +create table t1 (s1 tinyint); +create view v1 as select * from t1 where s1 <> 0 with local check option; +create view v2 as select * from v1 with cascaded check option; +-- error 1369 +insert into v2 values (0); +drop view v2, v1; +drop table t1; diff --git a/sql/table.cc b/sql/table.cc index bfe5395c3db..42eb2455e85 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1586,14 +1586,16 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) field_translation= transl; /* TODO: sort this list? Use hash for big number of fields */ - if (where) + if (where || + (effective_with_check == VIEW_CHECK_CASCADED && + ancestor->check_option)) { Item_arena *arena= thd->current_arena, backup; TABLE_LIST *tbl= this; if (arena->is_conventional()) arena= 0; // For easier test - if (!where->fixed && where->fix_fields(thd, ancestor, &where)) + if (where && !where->fixed && where->fix_fields(thd, ancestor, &where)) goto err; if (arena) @@ -1601,7 +1603,8 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) if (effective_with_check) { - check_option= where->copy_andor_structure(thd); + if (where) + check_option= where->copy_andor_structure(thd); if (effective_with_check == VIEW_CHECK_CASCADED) { check_option= and_conds(check_option, ancestor->check_option); @@ -1612,7 +1615,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) check that it is not VIEW in which we insert with INSERT SELECT (in this case we can't add view WHERE condition to main SELECT_LEX) */ - if (!no_where_clause) + if (where && !no_where_clause) { /* Go up to join tree and try to find left join */ for (; tbl; tbl= tbl->embedding)