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

Item name for VIEW added to find_field_in_table (BUG#5147)

parent b836d2dd
...@@ -1151,3 +1151,18 @@ avg(vg_column) ...@@ -1151,3 +1151,18 @@ avg(vg_column)
0.0000 0.0000
drop view v1; drop view v1;
drop table t1; drop table t1;
create table t1 (col1 bigint not null, primary key (col1));
create table t2 (col1 bigint not null, key (col1));
create view v1 as select * from t1;
create view v2 as select * from t2;
insert into v1 values (1);
insert into v2 values (1);
create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
select * from v3;
a b
1 1
show create view v3;
Table Create Table
v3 CREATE VIEW `test`.`v3` AS select `v1`.`col1` AS `a`,`v2`.`col1` AS `b` from `test`.`v1` join `test`.`v2` where (`v1`.`col1` = `v2`.`col1`)
drop view v3, v2, v1;
drop table t2, t1;
...@@ -1091,3 +1091,18 @@ create view v1 as select count(tg_column) as vg_column from t1; ...@@ -1091,3 +1091,18 @@ create view v1 as select count(tg_column) as vg_column from t1;
select avg(vg_column) from v1; select avg(vg_column) from v1;
drop view v1; drop view v1;
drop table t1; drop table t1;
#
# VIEW of VIEW with column renaming
#
create table t1 (col1 bigint not null, primary key (col1));
create table t2 (col1 bigint not null, key (col1));
create view v1 as select * from t1;
create view v2 as select * from t2;
insert into v1 values (1);
insert into v2 values (1);
create view v3 (a,b) as select v1.col1 as a, v2.col1 as b from v1, v2 where v1.col1 = v2.col1;
select * from v3;
show create view v3;
drop view v3, v2, v1;
drop table t2, t1;
...@@ -632,9 +632,11 @@ extern const Field *view_ref_found; ...@@ -632,9 +632,11 @@ extern const Field *view_ref_found;
Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, Field *find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
Item **ref, bool report_error, Item **ref, bool report_error,
bool check_privileges); bool check_privileges);
Field *find_field_in_table(THD *thd, TABLE_LIST *tables, const char *name, Field *
find_field_in_table(THD *thd, TABLE_LIST *table_list,
const char *name, const char *item_name,
uint length, Item **ref, uint length, Item **ref,
bool check_grant_table, bool check_grant_view, bool check_grants_table, bool check_grants_view,
bool allow_rowid, bool allow_rowid,
uint *cached_field_index_ptr); uint *cached_field_index_ptr);
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
......
...@@ -2310,6 +2310,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, ...@@ -2310,6 +2310,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{ {
uint unused_field_idx= NO_CACHED_FIELD_INDEX; uint unused_field_idx= NO_CACHED_FIELD_INDEX;
if (!find_field_in_table(thd, table_list, column->column.ptr(), if (!find_field_in_table(thd, table_list, column->column.ptr(),
column->column.ptr(),
column->column.length(), 0, 0, 0, 0, column->column.length(), 0, 0, 0, 0,
&unused_field_idx)) &unused_field_idx))
{ {
......
...@@ -1924,6 +1924,7 @@ const Field *view_ref_found= (Field*) 0x2; ...@@ -1924,6 +1924,7 @@ const Field *view_ref_found= (Field*) 0x2;
thd thread handler thd thread handler
table_list table where to find table_list table where to find
name name of field name name of field
item_name name of item if it will be created (VIEW)
length length of name length length of name
ref expression substituted in VIEW should be ref expression substituted in VIEW should be
passed using this reference (return passed using this reference (return
...@@ -1940,8 +1941,10 @@ const Field *view_ref_found= (Field*) 0x2; ...@@ -1940,8 +1941,10 @@ const Field *view_ref_found= (Field*) 0x2;
# pointer to field # pointer to field
*/ */
Field *find_field_in_table(THD *thd, TABLE_LIST *table_list, Field *
const char *name, uint length, Item **ref, find_field_in_table(THD *thd, TABLE_LIST *table_list,
const char *name, const char *item_name,
uint length, Item **ref,
bool check_grants_table, bool check_grants_view, bool check_grants_table, bool check_grants_view,
bool allow_rowid, bool allow_rowid,
uint *cached_field_index_ptr) uint *cached_field_index_ptr)
...@@ -1972,7 +1975,7 @@ Field *find_field_in_table(THD *thd, TABLE_LIST *table_list, ...@@ -1972,7 +1975,7 @@ Field *find_field_in_table(THD *thd, TABLE_LIST *table_list,
if (arena) if (arena)
thd->set_n_backup_item_arena(arena, &backup); thd->set_n_backup_item_arena(arena, &backup);
*ref= new Item_ref(trans + i, 0, table_list->view_name.str, *ref= new Item_ref(trans + i, 0, table_list->view_name.str,
name); item_name);
if (arena) if (arena)
thd->restore_backup_item_arena(arena, &backup); thd->restore_backup_item_arena(arena, &backup);
/* as far as Item_ref have defined refernce it do not need tables */ /* as far as Item_ref have defined refernce it do not need tables */
...@@ -2163,7 +2166,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, ...@@ -2163,7 +2166,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
(!db || !tables->db || !tables->db[0] || !strcmp(db,tables->db))) (!db || !tables->db || !tables->db[0] || !strcmp(db,tables->db)))
{ {
found_table=1; found_table=1;
Field *find= find_field_in_table(thd, tables, name, length, ref, Field *find= find_field_in_table(thd, tables, name, item->name,
length, ref,
(test(tables->table->grant. (test(tables->table->grant.
want_privilege) && want_privilege) &&
check_privileges), check_privileges),
...@@ -2226,7 +2230,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables, ...@@ -2226,7 +2230,8 @@ find_field_in_tables(THD *thd, Item_ident *item, TABLE_LIST *tables,
return (Field*) not_found_field; return (Field*) not_found_field;
} }
Field *field= find_field_in_table(thd, tables, name, length, ref, Field *field= find_field_in_table(thd, tables, name, item->name,
length, ref,
(test(tables->table->grant. (test(tables->table->grant.
want_privilege) && want_privilege) &&
check_privileges), check_privileges),
...@@ -2684,6 +2689,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name, ...@@ -2684,6 +2689,7 @@ insert_fields(THD *thd, TABLE_LIST *tables, const char *db_name,
/* Skip duplicate field names if NATURAL JOIN is used */ /* Skip duplicate field names if NATURAL JOIN is used */
if (!natural_join_table || if (!natural_join_table ||
!find_field_in_table(thd, natural_join_table, field_name, !find_field_in_table(thd, natural_join_table, field_name,
field_name,
strlen(field_name), &not_used_item, 0, 0, 0, strlen(field_name), &not_used_item, 0, 0, 0,
&not_used_field_index)) &not_used_field_index))
{ {
...@@ -2890,6 +2896,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds) ...@@ -2890,6 +2896,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
uint not_used_field_index= NO_CACHED_FIELD_INDEX; uint not_used_field_index= NO_CACHED_FIELD_INDEX;
if ((t2_field= find_field_in_table(thd, tab2, t1_field_name, if ((t2_field= find_field_in_table(thd, tab2, t1_field_name,
t1_field_name,
strlen(t1_field_name), &item_t2, strlen(t1_field_name), &item_t2,
0, 0, 0, 0, 0, 0,
&not_used_field_index))) &not_used_field_index)))
......
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