Details
-
Task
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
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.