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

          elenst Elena Stepanova created issue -
          elenst Elena Stepanova made changes -
          Field Original Value New Value
          Summary CREATE VIEW with GROUP BY and constant produces invalid definition CREATE VIEW with GROUP BY or ORDER BY and constant produces invalid definition
          elenst Elena Stepanova made changes -
          Status Open [ 1 ] Confirmed [ 10101 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Sprint 10.1.13 [ 42 ]
          ratzpo Rasmus Johansson (Inactive) made changes -
          Rank Ranked lower
          sanja Oleksandr Byelkin made changes -
          Status Confirmed [ 10101 ] In Progress [ 3 ]

          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. —
          sanja Oleksandr Byelkin made changes -
          Assignee Oleksandr Byelkin [ sanja ] Sergei Golubchik [ serg ]
          Status In Progress [ 3 ] In Review [ 10002 ]

          ok to push

          serg Sergei Golubchik added a comment - ok to push
          serg Sergei Golubchik made changes -
          Assignee Sergei Golubchik [ serg ] Oleksandr Byelkin [ sanja ]
          Status In Review [ 10002 ] Stalled [ 10000 ]
          sanja Oleksandr Byelkin made changes -
          Status Stalled [ 10000 ] In Progress [ 3 ]
          sanja Oleksandr Byelkin made changes -
          Fix Version/s 10.1.13 [ 21803 ]
          Fix Version/s 10.1 [ 16100 ]
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 74510 ] MariaDB v4 [ 150205 ]

          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.