January 2008
Intermediate to advanced
384 pages
8h 1m
English
Another approach is to store the text of the CREATE VIEW statement and work it into the parse tree of the SELECT, INSERT, UPDATE, or DELETE statements that use it. This allows the optimizer to blend the VIEW definition into the final query plan. For example, you can create a VIEW based on a particular department, thus:
CREATE VIEW SalesDept (dept_name, city_name, ...)
AS SELECT 'Sales', city_name, ...
FROM Departments
WHERE dept_name = 'Sales';and then use it as a query thus:
SELECT * FROM SalesDept WHERE city_name = 'New York';
The parser expands the VIEW into text (or an intermediate tokenized form) within the FROM clause. The query would become, in effect,
SELECT * FROM (SELECT 'Sales', city_name, ... FROM Departments ...
Read now
Unlock full access