Support CREATE VIEW and DROP VIEW
Final Release Note
Description
VIEWs are like dynamic SELECT statements, except that when the underlying data changes, the VIEW changes. SQL tutorials liken them to virtual tables. The purpose of this note is to propose a slightly different view of VIEWs, philosophically similar to the way that AIM works, although the details are different.
-
Just as AIM cross references and are persistent in globals, the essence of the proposal here is that VIEWs actually exist as a table. A CREATE VIEW under the covers with this proposal is actually a CREATE TABLE, with the table having some special properties.
-
Just as AIM cross references need not be journaled and replicated, and after an unclean shutdown AIM cross references can be deleted and recreated on demand, VIEWs can be created so that in the event of an unclean shutdown, they can be deleted so that any VIEW can be recreated on demand when needed. Of course, just as AIM cross references can be journaled and replicated for operational convenience, the globals in the proposed implementation of VIEWs can be journaled and replicated.
For a CREATE VIEW, Octo:
-
Creates a table with a name consisting of a prefix
%ydbOctoV
followed by a hash of the query created with $ZYHASH(). Unlike SELECT statements, where literals are parameterized (since SELECT with LASTNAME = 'SMITH' is effectively the same query as one with LASTNAME = 'JONES'), literals are not parameterized for views (since a VIEW with LASTNAME = 'SMITH' is different from one with LASTNAME = 'JONES'). -
Creates triggers to populate the global nodes when the source global nodes change. Note that since VIEWs are in global variables, this makes it handy for VIEWs to be built on other VIEWs.
-
Runs M code to populate the global.
At this point, the VIEW is complete. VIEW globals can be queried, have metadata managed by AIM, etc. Since VIEWs are simply views of underlying data, they are READONLY by default.