Bug #5147 Views: Wrong column names
Submitted: 23 Aug 2004 0:27 Modified: 25 Nov 2004 9:32
Reporter: Peter Gulutzan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.2-alpha-debug OS:Linux (SuSE 8.2)
Assigned to: Oleksandr Byelkin CPU Architecture:Any

[23 Aug 2004 0:27] Peter Gulutzan
Description:
The column names of a view should be the same as what 
I say in the SELECT. But it isn't. I use "AS column", 
but MySQL doesn't use "column" when I select from the 
view. It uses the original column names as if I didn't 
say AS. It only happens for views of views, and joins. 

How to repeat:
mysql> create table i1 (col1 bigint not null, primary key (col1)) engine=innodb; 
Query OK, 0 rows affected (0.39 sec) 
 
mysql> create table i2 (col1 bigint not null, key (col1), foreign key (col1) references i1 
(col1)) engine=innodb; 
Query OK, 0 rows affected (0.11 sec) 
 
mysql> create view vi1 as select * from i1; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> create view vi2 as select * from i2; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> insert into vi1 values (1); 
Query OK, 1 row affected (0.04 sec) 
 
mysql> insert into vi2 values (1); 
Query OK, 1 row affected (0.05 sec) 
 
mysql> create view vi3 as select vi1.col1 as a, vi2.col1 as b from vi1, vi2 where vi1.col1 = 
vi2.col1; 
Query OK, 0 rows affected (0.03 sec) 
 
mysql> select * from vi3; 
+------+------+ 
| col1 | col1 | 
+------+------+ 
|    1 |    1 | 
+------+------+ 
1 row in set (0.00 sec)
[26 Aug 2004 23:09] Oleksandr Byelkin
ChangeSet 
  1.1735 04/08/27 00:08:59 bell@sanja.is.com.ua +5 -0 
  Item name for VIEW added to find_field_in_table (BUG#5147)
[27 Aug 2004 8:34] Oleksandr Byelkin
Thank you for bugreport. bugfix is pushed intou source repository.
[12 Sep 2004 13:35] Peter Gulutzan
For the example that I gave originally, the bug is fixed. But for other situations, the column 
names are still wrong. A new example: 
mysql> create table tx (s1 int); 
Query OK, 0 rows affected (0.28 sec) 
 
mysql> create view vx1 as select s1 from tx; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> create view vx2 as select s1 as select_list_name from vx1; 
Query OK, 0 rows affected (0.00 sec) 
 
mysql> insert into vx2 values (1); 
Query OK, 1 row affected (0.00 sec) 
 
mysql> select * from vx2; 
+------+ 
| s1   | 
+------+ 
|    1 | 
+------+ 
1 row in set (0.00 sec) 
 
So this bug should be opened again.
[14 Sep 2004 16:32] Oleksandr Byelkin
ChangeSet 
  1.1759 04/09/14 19:28:29 bell@sanja.is.com.ua +25 -0 
  fixed merged view fields names (BUG#5147) 
  support of merged VIEW over several tables added (WL#1809)
[25 Nov 2004 9:32] Oleksandr Byelkin
Thank you for bugreport! Bugfix is pushed now into our internal repository.