Skip to content

Design of language changes for views. #209.

beoran requested to merge beoran/ql:209-view-design into view

Syntax only changes for views. This is the design doc that goes with these syntax changes.

// CREATE VIEW
//
// Create view statements create new views.
// A view is a virtual table based on the results of a single SELECT statement.
// A view contains rows and columns, just like a real table. The fields of
// a view are the fields from the result of the SELECT statement. The rows of
// a view are the rows of the result of the SELECT statement, which are updated
// every time the view is queried.
//
// The SELECT statement used for a view is subject to certain limitations:
// 1. The SELECT statement must be executable at the moment the view is created.
// 2. The SELECT statement may not refer to tables or views that do not exists.
// 3. The SELECT statement may not contain QL parameters.
//
// In QL, all views are read only.
//
// A view may optionally have a specification which contains a list of 
// columns the view should have. For each of these view columns, a type can
// optionally be mentioned to which the column's value will be converted to.
// If that conversion fails, a select from that view will yield an error.
// If specified, the amount of fields of a view must match the amount of fields
// returned by the view's query.
//
//  CreateViewStmt = "CREATE" "VIEW" ["IF" "NOT" "EXISTS"] ViewName 
//  [ ViewSpecification ]  AS SelectStmt .
//
//  ViewSpecification = "(" ViewColumnDef { "," ViewColumnDef } [ "," ] ")" .
//
//  ViewColumnDef = ColumnName [ Type ].
//  ViewName = identifier .
//
// The optional IF NOT EXISTS clause makes the statement a no operation if the
// view already exists.
//
// Unusable views
//
// While the validity of a view is checked when it is created, it is possible
// that one of the following statements makes a view unusable:
// * DROP TABLE of a table selected from in a view will make that view unusable. 
// * DROP TABLE of a view selected from in a view query will make the latter view unusable. 
// * ALTER TABLE DROP COLUMN of a named column selected from in a view will make 
//   that view unusable.
//
// Unusable views are kept stored in the database, and can be made usable again 
// by adding the missing tables or columns once more. However, selecting from
// an unusable view is not possible and will return an error.
// 
// Furthermore the following statements may change the resulting columns 
// of a view if they were selected though wildcards: 
// * ALTER TABLE DROP COLUMN will result in the dropped column being omitted from the view.
// * ALTER TABLE ADD will result in the added column being omitted added to the view.
//

Let's discuss this design! :)

Closes #209

Edited by beoran

Merge request reports