Commit 75841099 authored by evgen@moonbone.local's avatar evgen@moonbone.local

Fix bug #12993 View column rename broken in subselect

When view column aliased in subselect alias is set on ref which represents
field. When tmp table is created for subselect, it takes name of original field
not ref. Because of this alias on view column in subselect is lost. Which
results in reported error.

Now when alias is set on ref, it's set on ref real item too.
parent 97a058bc
......@@ -2186,3 +2186,9 @@ r_object_id users_names
120001a080000542 guser02
drop view v1, v2;
drop table t1, t2;
create table t1(f1 char(1));
create view v1 as select * from t1;
select * from (select f1 as f2 from v1) v where v.f2='a';
f2
drop view v1;
drop table t1;
......@@ -2059,3 +2059,12 @@ order by users_names;
drop view v1, v2;
drop table t1, t2;
#
# Bug #12993 View column rename broken in subselect
#
create table t1(f1 char(1));
create view v1 as select * from t1;
select * from (select f1 as f2 from v1) v where v.f2='a';
drop view v1;
drop table t1;
......@@ -2648,10 +2648,15 @@ find_field_in_view(THD *thd, TABLE_LIST *table_list,
*ref != NULL means that *ref contains the item that we need to
replace. If the item was aliased by the user, set the alias to
the replacing item.
We need to set alias on both ref itself and on ref real item.
*/
if (*ref && !(*ref)->is_autogenerated_name)
{
item->set_name((*ref)->name, (*ref)->name_length,
system_charset_info);
item->real_item()->set_name((*ref)->name, (*ref)->name_length,
system_charset_info);
}
if (register_tree_change)
thd->change_item_tree(ref, item);
else
......
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