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

made different fields for view updatebility in principle and updatability...

made different fields for view updatebility in principle and updatability during this execution (BUG#4601)
parent 5be6861f
...@@ -977,9 +977,19 @@ ERROR HY000: View 'test.v1' references invalid table(s) or column(s) ...@@ -977,9 +977,19 @@ ERROR HY000: View 'test.v1' references invalid table(s) or column(s)
drop view v1; drop view v1;
create view v1 (a,a) as select 'a','a'; create view v1 (a,a) as select 'a','a';
ERROR 42S21: Duplicate column name 'a' ERROR 42S21: Duplicate column name 'a'
create procedure p11 () begin declare v int; create view v1 as select v; end;// create procedure p1 () begin declare v int; create view v1 as select v; end;//
Warnings: Warnings:
Warning 1310 Referring to uninitialized variable v Warning 1310 Referring to uninitialized variable v
call p11(); call p1();
ERROR HY000: View's SELECT contains a variable or parameter ERROR HY000: View's SELECT contains a variable or parameter
drop procedure p11; drop procedure p1;
create table t1 (col1 int,col2 char(22));
insert into t1 values(5,'Hello, world of views');
create view v1 as select * from t1;
create view v2 as select * from v1;
update v2 set col2='Hello, view world';
select * from t1;
col1 col2
5 Hello, view world
drop view v2, v1;
drop table t1;
...@@ -905,8 +905,20 @@ create view v1 (a,a) as select 'a','a'; ...@@ -905,8 +905,20 @@ create view v1 (a,a) as select 'a','a';
# SP variables inside view test # SP variables inside view test
# #
delimiter //; delimiter //;
create procedure p11 () begin declare v int; create view v1 as select v; end;// create procedure p1 () begin declare v int; create view v1 as select v; end;//
delimiter ;// delimiter ;//
-- error 1350 -- error 1350
call p11(); call p1();
drop procedure p11; drop procedure p1;
#
# updateablity should be transitive
#
create table t1 (col1 int,col2 char(22));
insert into t1 values(5,'Hello, world of views');
create view v1 as select * from t1;
create view v2 as select * from v1;
update v2 set col2='Hello, view world';
select * from t1;
drop view v2, v1;
drop table t1;
...@@ -3856,19 +3856,19 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant, ...@@ -3856,19 +3856,19 @@ void fill_effective_table_privileges(THD *thd, GRANT_INFO *grant,
/* db privileges */ /* db privileges */
grant->privilege|= acl_get(thd->host, thd->ip, thd->priv_user, db, 0); grant->privilege|= acl_get(thd->host, thd->ip, thd->priv_user, db, 0);
/* table privileges */ /* table privileges */
rw_rdlock(&LOCK_grant);
if (grant->version != grant_version) if (grant->version != grant_version)
{ {
rw_rdlock(&LOCK_grant);
grant->grant_table= grant->grant_table=
table_hash_search(thd->host, thd->ip, db, table_hash_search(thd->host, thd->ip, db,
thd->priv_user, thd->priv_user,
table, 0); /* purecov: inspected */ table, 0); /* purecov: inspected */
grant->version= grant_version; /* purecov: inspected */ grant->version= grant_version; /* purecov: inspected */
rw_unlock(&LOCK_grant);
} }
if (grant->grant_table != 0) if (grant->grant_table != 0)
{ {
grant->privilege|= grant->grant_table->privs; grant->privilege|= grant->grant_table->privs;
} }
rw_unlock(&LOCK_grant);
} }
#endif #endif
...@@ -330,7 +330,7 @@ static File_option view_parameters[]= ...@@ -330,7 +330,7 @@ static File_option view_parameters[]=
FILE_OPTIONS_STRING}, FILE_OPTIONS_STRING},
{{view_field_names[1], 3}, offsetof(TABLE_LIST, md5), {{view_field_names[1], 3}, offsetof(TABLE_LIST, md5),
FILE_OPTIONS_STRING}, FILE_OPTIONS_STRING},
{{view_field_names[2], 9}, offsetof(TABLE_LIST, updatable), {{view_field_names[2], 9}, offsetof(TABLE_LIST, updatable_view),
FILE_OPTIONS_ULONGLONG}, FILE_OPTIONS_ULONGLONG},
{{view_field_names[3], 9}, offsetof(TABLE_LIST, algorithm), {{view_field_names[3], 9}, offsetof(TABLE_LIST, algorithm),
FILE_OPTIONS_ULONGLONG}, FILE_OPTIONS_ULONGLONG},
...@@ -472,7 +472,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -472,7 +472,7 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
thd->lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED; thd->lex->create_view_algorithm= VIEW_ALGORITHM_UNDEFINED;
} }
view->algorithm= thd->lex->create_view_algorithm; view->algorithm= thd->lex->create_view_algorithm;
if ((view->updatable= (can_be_merged && if ((view->updatable_view= (can_be_merged &&
view->algorithm != VIEW_ALGORITHM_TMEPTABLE))) view->algorithm != VIEW_ALGORITHM_TMEPTABLE)))
{ {
// TODO: change here when we will support UNIONs // TODO: change here when we will support UNIONs
...@@ -480,9 +480,9 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -480,9 +480,9 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view,
tbl; tbl;
tbl= tbl->next_local) tbl= tbl->next_local)
{ {
if (tbl->view != 0 && !tbl->updatable) if (tbl->view != 0 && !tbl->updatable_view)
{ {
view->updatable= 0; view->updatable_view= 0;
break; break;
} }
} }
...@@ -663,6 +663,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) ...@@ -663,6 +663,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
DBUG_ASSERT(view_table != 0); DBUG_ASSERT(view_table != 0);
table->effective_algorithm= VIEW_ALGORITHM_MERGE; table->effective_algorithm= VIEW_ALGORITHM_MERGE;
table->updatable= (table->updatable_view != 0);
if (old_next) if (old_next)
{ {
...@@ -692,12 +693,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) ...@@ -692,12 +693,7 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table)
table->effective_algorithm= VIEW_ALGORITHM_TMEPTABLE; table->effective_algorithm= VIEW_ALGORITHM_TMEPTABLE;
lex->select_lex.linkage= DERIVED_TABLE_TYPE; lex->select_lex.linkage= DERIVED_TABLE_TYPE;
if (table->updatable)
{
//TOTO: warning: can't be updateable, .frm edited by hand. version
//downgrade?
table->updatable= 0; table->updatable= 0;
}
/* SELECT tree link */ /* SELECT tree link */
lex->unit.include_down(table->select_lex); lex->unit.include_down(table->select_lex);
......
...@@ -215,8 +215,8 @@ typedef struct st_table_list ...@@ -215,8 +215,8 @@ typedef struct st_table_list
LEX_STRING view_name; /* save view name */ LEX_STRING view_name; /* save view name */
LEX_STRING timestamp; /* GMT time stamp of last operation */ LEX_STRING timestamp; /* GMT time stamp of last operation */
ulonglong file_version; /* version of file's field set */ ulonglong file_version; /* version of file's field set */
ulonglong updatable_view; /* VIEW can be updated */
ulonglong revision; /* revision control number */ ulonglong revision; /* revision control number */
ulonglong updatable; /* Is VIEW updateable */
ulonglong algorithm; /* 0 any, 1 tmp tables , 2 merging */ ulonglong algorithm; /* 0 any, 1 tmp tables , 2 merging */
uint effective_algorithm; /* which algorithm was really used */ uint effective_algorithm; /* which algorithm was really used */
GRANT_INFO grant; GRANT_INFO grant;
...@@ -224,6 +224,7 @@ typedef struct st_table_list ...@@ -224,6 +224,7 @@ typedef struct st_table_list
uint outer_join; /* Which join type */ uint outer_join; /* Which join type */
uint shared; /* Used in multi-upd */ uint shared; /* Used in multi-upd */
uint32 db_length, real_name_length; uint32 db_length, real_name_length;
bool updatable; /* VIEW/TABLE can be updated now */
bool straight; /* optimize with prev table */ bool straight; /* optimize with prev table */
bool updating; /* for replicate-do/ignore table */ bool updating; /* for replicate-do/ignore table */
bool force_index; /* prefer index over table scan */ bool force_index; /* prefer index over table scan */
......
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