[MDEV-10825] Feature Request: Persist exact view definitions DDL Created: 2016-09-17  Updated: 2021-04-17

Status: Open
Project: MariaDB Server
Component/s: Views
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Natan Vivo Assignee: Vicențiu Ciorbaru
Resolution: Unresolved Votes: 2
Labels: None


 Description   

I'd like to see mariadb persisting the exact view definition DDL.

When defining a view, we usually format and set correct indentation for the query. But apparently, MariaDB doesn't store the text definition of the query, and after defined show create view shows a formatted version of the query. This makes very annoying to define complex views in MariaDB.

For example, this definition:

CREATE or replace VIEW sampleview AS
 
  -- some information about what this view is supposed to do
 
  SELECT 
    -- some regular fields
    field1,
    field2, 
    field3,
 
    -- computed state
    CASE
      -- 1 = user is active and 
      WHEN field1 = 1 AND field2 = 'abc' THEN 1
      -- another comment for this case
      WHEN field3 IN (1, 2, 3) then 2
      ELSE 3
    END AS SomeState
  
  FROM sampletable
;

After creation can only be retrieved as:

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `sampleview` AS select `sampletable`.`field1` AS `field1`,`sampletable`.`field2` AS `field2`,`sampletable`.`field3` AS `field3`,(case when ((`sampletable`.`field1` = 1) and (`sampletable`.`field2` = 'abc')) then 1 when (`sampletable`.`field3` in (1,2,3)) then 2 else 3 end) AS `SomeState` from `sampletable`

This not only has lost the comments and formatting, but added a lot of aliases and parentheses that even with some code fomatter makes it hard to understand and edit.

Having worked with SQL Server (which stores the exact DDL of the view) for a long time and mariadb for the last few years, I miss this simple feature. Complex views a dozens or hundreds of lines may have comments per line, and formatting that helps understand the purpose and functionality of the view. Editing views in mysql/mariadb is painful.

Storing the exact view definition shouldn't affect anything, and show create view could retrieve this text instead. A keyword could be added to allow retrieving the computed version of the view.



 Comments   
Comment by Sergei Golubchik [ 2017-05-27 ]

Exact view definition is actually stored in the view's frm file, but there is no command to show it at the moment.

It's a reasonable request to implement some way to show the original view definition.

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