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

Merge

parents 76c0154e bc98f214
...@@ -977,6 +977,22 @@ ERROR HY000: View 'test.v1' references invalid table(s) or column(s) ...@@ -977,6 +977,22 @@ 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 p1 () begin declare v int; create view v1 as select v; end;//
Warnings:
Warning 1310 Referring to uninitialized variable v
call p1();
ERROR HY000: View's SELECT contains a variable or parameter
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;
create table t1 (a int, b int); create table t1 (a int, b int);
create view v1 as select a, sum(b) from t1 group by a; create view v1 as select a, sum(b) from t1 group by a;
select b from v1 use index (some_index) where b=1; select b from v1 use index (some_index) where b=1;
......
...@@ -901,6 +901,28 @@ drop view v1; ...@@ -901,6 +901,28 @@ drop view v1;
-- error 1060 -- error 1060
create view v1 (a,a) as select 'a','a'; create view v1 (a,a) as select 'a','a';
#
# SP variables inside view test
#
delimiter //;
create procedure p1 () begin declare v int; create view v1 as select v; end;//
delimiter ;//
-- error 1350
call p1();
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;
# #
# check 'use index' on view with temporary table # check 'use index' on view with temporary table
# #
......
...@@ -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
...@@ -1760,7 +1760,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables) ...@@ -1760,7 +1760,7 @@ int open_and_lock_tables(THD *thd, TABLE_LIST *tables)
DBUG_ENTER("open_and_lock_tables"); DBUG_ENTER("open_and_lock_tables");
uint counter; uint counter;
if (open_tables(thd, tables, &counter) || lock_tables(thd, tables, counter)) if (open_tables(thd, tables, &counter) || lock_tables(thd, tables, counter))
DBUG_RETURN(-1); /* purecov: inspected */ DBUG_RETURN(thd->net.report_error ? -1 : 1); /* purecov: inspected */
DBUG_RETURN(mysql_handle_derived(thd->lex)); DBUG_RETURN(mysql_handle_derived(thd->lex));
} }
......
...@@ -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,17 +472,17 @@ static int mysql_register_view(THD *thd, TABLE_LIST *view, ...@@ -472,17 +472,17 @@ 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
for (TABLE_LIST *tbl= (TABLE_LIST *)thd->lex->select_lex.table_list.first; for (TABLE_LIST *tbl= (TABLE_LIST *)thd->lex->select_lex.table_list.first;
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) table->updatable= 0;
{
//TOTO: warning: can't be updateable, .frm edited by hand. version
//downgrade?
table->updatable= 0;
}
/* SELECT tree link */ /* SELECT tree link */
lex->unit.include_down(table->select_lex); lex->unit.include_down(table->select_lex);
......
...@@ -1987,7 +1987,8 @@ sp_elseifs: ...@@ -1987,7 +1987,8 @@ sp_elseifs:
sp_case: sp_case:
expr THEN_SYM expr THEN_SYM
{ {
sp_head *sp= Lex->sphead; LEX *lex= Lex;
sp_head *sp= lex->sphead;
sp_pcontext *ctx= Lex->spcont; sp_pcontext *ctx= Lex->spcont;
uint ip= sp->instructions(); uint ip= sp->instructions();
sp_instr_jump_if_not *i; sp_instr_jump_if_not *i;
...@@ -2005,6 +2006,7 @@ sp_case: ...@@ -2005,6 +2006,7 @@ sp_case:
Item *expr= new Item_func_eq(var, $1); Item *expr= new Item_func_eq(var, $1);
i= new sp_instr_jump_if_not(ip, expr); i= new sp_instr_jump_if_not(ip, expr);
lex->variables_used= 1;
} }
sp->push_backpatch(i, ctx->push_label((char *)"", 0)); sp->push_backpatch(i, ctx->push_label((char *)"", 0));
sp->add_instr(i); sp->add_instr(i);
...@@ -6170,6 +6172,7 @@ simple_ident: ...@@ -6170,6 +6172,7 @@ simple_ident:
$1.str); $1.str);
} }
$$ = (Item*) new Item_splocal($1, spv->offset); $$ = (Item*) new Item_splocal($1, spv->offset);
lex->variables_used= 1;
} }
else else
{ {
......
...@@ -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