Commit 92653760 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

new behaviour of CHECK option build, for mor efficience and more correct:

check option build only according most top VIEW  CHECK OPTION TYPE  (BUG#5993)
parent 1bd699e0
...@@ -1556,5 +1556,17 @@ select * from v1; ...@@ -1556,5 +1556,17 @@ select * from v1;
s1 s1
select * from t1; select * from t1;
s1 s1
drop trigger t1.t1_bi;
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;
create view v2 as select * from v1 where s1 <> 1 with cascaded check option;
insert into v2 values (0);
ERROR HY000: CHECK OPTION failed 'test.v2'
select * from v2;
s1
select * from t1;
s1
drop view v2, v1;
drop table t1;
...@@ -1507,7 +1507,19 @@ create view v1 as select * from t1 where s1 <> 127 with check option; ...@@ -1507,7 +1507,19 @@ create view v1 as select * from t1 where s1 <> 127 with check option;
insert into v1 values (0); insert into v1 values (0);
select * from v1; select * from v1;
select * from t1; select * from t1;
drop trigger t1.t1_bi;
drop view v1; drop view v1;
drop table t1; drop table t1;
#
# CASCADED should be used for all underlaying VIEWs
#
create table t1 (s1 tinyint);
create view v1 as select * from t1 where s1 <> 0;
create view v2 as select * from v1 where s1 <> 1 with cascaded check option;
-- error 1369
insert into v2 values (0);
select * from v2;
select * from t1;
drop view v2, v1;
drop table t1;
...@@ -2697,7 +2697,9 @@ bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds) ...@@ -2697,7 +2697,9 @@ bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds)
table->keys_in_use_for_query.subtract(map); table->keys_in_use_for_query.subtract(map);
} }
table->used_keys.intersect(table->keys_in_use_for_query); table->used_keys.intersect(table->keys_in_use_for_query);
if (table_list->ancestor && table_list->setup_ancestor(thd, conds)) if (table_list->ancestor &&
table_list->setup_ancestor(thd, conds,
table_list->effective_with_check))
DBUG_RETURN(1); DBUG_RETURN(1);
} }
if (tablenr > MAX_TABLES) if (tablenr > MAX_TABLES)
......
...@@ -1497,8 +1497,10 @@ void st_table_list::set_ancestor() ...@@ -1497,8 +1497,10 @@ void st_table_list::set_ancestor()
SYNOPSIS SYNOPSIS
st_table_list::setup_ancestor() st_table_list::setup_ancestor()
thd - thread handler thd - thread handler
conds - condition of this JOIN conds - condition of this JOIN
check_opt_type - WHITH CHECK OPTION type (VIEW_CHECK_NONE,
VIEW_CHECK_LOCAL, VIEW_CHECK_CASCADED)
DESCRIPTION DESCRIPTION
It is: It is:
...@@ -1513,7 +1515,8 @@ void st_table_list::set_ancestor() ...@@ -1513,7 +1515,8 @@ void st_table_list::set_ancestor()
1 - error 1 - error
*/ */
bool st_table_list::setup_ancestor(THD *thd, Item **conds) bool st_table_list::setup_ancestor(THD *thd, Item **conds,
uint8 check_opt_type)
{ {
Item **transl; Item **transl;
SELECT_LEX *select= &view->select_lex; SELECT_LEX *select= &view->select_lex;
...@@ -1527,7 +1530,10 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) ...@@ -1527,7 +1530,10 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
DBUG_ENTER("st_table_list::setup_ancestor"); DBUG_ENTER("st_table_list::setup_ancestor");
if (ancestor->ancestor && if (ancestor->ancestor &&
ancestor->setup_ancestor(thd, conds)) ancestor->setup_ancestor(thd, conds,
(check_opt_type == VIEW_CHECK_CASCADED ?
VIEW_CHECK_CASCADED :
VIEW_CHECK_NONE)))
DBUG_RETURN(1); DBUG_RETURN(1);
if (field_translation) if (field_translation)
...@@ -1587,7 +1593,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) ...@@ -1587,7 +1593,7 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
/* 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 && (check_opt_type == VIEW_CHECK_CASCADED &&
ancestor->check_option)) ancestor->check_option))
{ {
Item_arena *arena= thd->current_arena, backup; Item_arena *arena= thd->current_arena, backup;
...@@ -1601,11 +1607,11 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds) ...@@ -1601,11 +1607,11 @@ bool st_table_list::setup_ancestor(THD *thd, Item **conds)
if (arena) if (arena)
thd->set_n_backup_item_arena(arena, &backup); thd->set_n_backup_item_arena(arena, &backup);
if (effective_with_check) if (check_opt_type)
{ {
if (where) if (where)
check_option= where->copy_andor_structure(thd); check_option= where->copy_andor_structure(thd);
if (effective_with_check == VIEW_CHECK_CASCADED) if (check_opt_type == VIEW_CHECK_CASCADED)
{ {
check_option= and_conds(check_option, ancestor->check_option); check_option= and_conds(check_option, ancestor->check_option);
} }
......
...@@ -281,7 +281,7 @@ typedef struct st_table_list ...@@ -281,7 +281,7 @@ typedef struct st_table_list
void calc_md5(char *buffer); void calc_md5(char *buffer);
void set_ancestor(); void set_ancestor();
int view_check_option(THD *thd, bool ignore_failure); int view_check_option(THD *thd, bool ignore_failure);
bool setup_ancestor(THD *thd, Item **conds); bool setup_ancestor(THD *thd, Item **conds, uint8 check_option);
bool placeholder() {return derived || view; } bool placeholder() {return derived || view; }
void print(THD *thd, String *str); void print(THD *thd, String *str);
inline st_table_list *next_independent() inline st_table_list *next_independent()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment