[MDEV-10660] View with a window function replaces column expression with its alias, making the view invalid Created: 2016-08-24  Updated: 2017-02-05  Resolved: 2017-02-05

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - Window functions, Views
Affects Version/s: 10.2
Fix Version/s: 10.2.4

Type: Bug Priority: Major
Reporter: nick ivanov Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: 10.2-rc
Environment:

Red Hat Enterprise Linux Server release 6.6



 Description   

If one creates a view that 1) contains one or more window functions as column expression and 2) provides aliases for such columns, the column expressions get replaced by the aliases in the view definition, thus rendering the view invalid. An attempt to reference such view results in "ERROR 1356 (HY000): View 'XXX' references invalid table(s) or column(s) ..."

To reproduce:

MariaDB [onedb]> create or replace view v_test (tab_name, rnk) as select table_name, rank() over (order by table_name)  from information_schema.tables;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [onedb]> show create view v_test;
+--------+-------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| View   | Create View                                                                                                                               | character_set_client | collation_connection |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
| v_test | CREATE VIEW "v_test" AS select "information_schema"."tables"."TABLE_NAME" AS "tab_name","rnk" AS "rnk" from "information_schema"."tables" | utf8                 | utf8_general_ci      |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+
1 row in set, 1 warning (0.00 sec)

Notice how the view definition has `"rnk" AS "rnk"` as the second column – the alias "rnk" replaced the column expression.

It happens when you provide a column list in the view DDL – "create view blah (<column list>)" and also when you supply individual column aliases – "create view blah as select rank() over () as <alias>"



 Comments   
Comment by Elena Stepanova [ 2016-08-26 ]

Thanks for the report.

Comment by Igor Babaev [ 2017-02-05 ]

The fix for this bug was pushed into the 10.2 tree.

Generated at Thu Feb 08 07:43:57 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.