Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-9701

CREATE VIEW with GROUP BY or ORDER BY and constant produces invalid definition

Details

    • 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)
      

      Attachments

        Activity

          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.

          sanja Oleksandr Byelkin added a comment - 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. —

          ok to push

          serg Sergei Golubchik added a comment - ok to push

          People

            sanja Oleksandr Byelkin
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.