[MDEV-9701] CREATE VIEW with GROUP BY or ORDER BY and constant produces invalid definition Created: 2016-03-08  Updated: 2016-03-18  Resolved: 2016-03-18

Status: Closed
Project: MariaDB Server
Component/s: Views
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 10.1.13

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Fixed Votes: 0
Labels: upstream-fixed

Sprint: 10.1.13

 Description   

Test case

CREATE TABLE B ( i INT );
INSERT INTO B VALUES (1),(2);
 
CREATE VIEW v1 AS 
SELECT 3 AS three, COUNT(*) FROM B GROUP BY three;
 
SELECT * FROM v1;

Result

MariaDB [test]> SELECT * FROM v1;
ERROR 1356 (HY000): View 'test.v1' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

Here is the reason (note the constant in GROUP BY):

MariaDB [test]> SHOW CREATE VIEW v1 \G
*************************** 1. row ***************************
                View: v1
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 3 AS `three`,count(0) AS `COUNT(*)` from `B` group by 3
character_set_client: utf8
collation_connection: utf8_general_ci

Reproducible on current 5.5.48, 10.0.24, 10.1.12.
Also reproducible on MySQL 5.5, but fixed in MySQL 5.6:

MySQL [test]> SELECT * FROM v1;
+-------+----------+
| three | COUNT(*) |
+-------+----------+
|     3 |        2 |
+-------+----------+
1 row in set (0.00 sec)
 
MySQL [test]> SHOW CREATE VIEW v1 \G
*************************** 1. row ***************************
                View: v1
         Create View: CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select 3 AS `three`,count(0) AS `COUNT(*)` from `B` group by `three`
character_set_client: utf8
collation_connection: utf8_general_ci
1 row in set (0.00 sec)



 Comments   
Comment by Oleksandr Byelkin [ 2016-03-16 ]

revision-id: 72b709ac7503ae6dd2b5e9049322fefb90b0ebbe (mariadb-10.1.12-16-g72b709a)
parent(s): 9b53d84d14a9b031d193f6beae382a232aa738e3
committer: Oleksandr Byelkin
timestamp: 2016-03-16 19:49:17 +0100
message:

MDEV-9701: CREATE VIEW with GROUP BY or ORDER BY and constant produces invalid definition

Fixed printing integer constant in the ORDER clause (MySQL solution)
Removed workaround for double resolving counter in the ORDER.

Comment by Sergei Golubchik [ 2016-03-18 ]

ok to push

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