mirror of
https://github.com/MariaDB/server.git
synced 2025-08-07 00:04:31 +03:00
Allow inheriting check options if view have not WHERE clause (BUG#5988)
mysql-test/r/view.result: test of cascaded check option for whiew without WHERE clause mysql-test/t/view.test: test of cascaded check option for whiew without WHERE clause sql/table.cc: Allow inheriting check options if view have not WHERE clause
This commit is contained in:
@@ -1528,3 +1528,10 @@ substring_index(t,':',2)
|
|||||||
12:24
|
12:24
|
||||||
drop view v1;
|
drop view v1;
|
||||||
drop table t1;
|
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;
|
||||||
|
@@ -1471,3 +1471,14 @@ select substring_index(t,':',2) from t1;
|
|||||||
select substring_index(t,':',2) from v1;
|
select substring_index(t,':',2) from v1;
|
||||||
drop view v1;
|
drop view v1;
|
||||||
drop table t1;
|
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;
|
||||||
|
11
sql/table.cc
11
sql/table.cc
@@ -1586,14 +1586,16 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
|
|||||||
field_translation= transl;
|
field_translation= transl;
|
||||||
/* TODO: sort this list? Use hash for big number of fields */
|
/* 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;
|
Item_arena *arena= thd->current_arena, backup;
|
||||||
TABLE_LIST *tbl= this;
|
TABLE_LIST *tbl= this;
|
||||||
if (arena->is_conventional())
|
if (arena->is_conventional())
|
||||||
arena= 0; // For easier test
|
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;
|
goto err;
|
||||||
|
|
||||||
if (arena)
|
if (arena)
|
||||||
@@ -1601,7 +1603,8 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
|
|||||||
|
|
||||||
if (effective_with_check)
|
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)
|
if (effective_with_check == VIEW_CHECK_CASCADED)
|
||||||
{
|
{
|
||||||
check_option= and_conds(check_option, ancestor->check_option);
|
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
|
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)
|
(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 */
|
/* Go up to join tree and try to find left join */
|
||||||
for (; tbl; tbl= tbl->embedding)
|
for (; tbl; tbl= tbl->embedding)
|
||||||
|
Reference in New Issue
Block a user