Oracle Views: Are calculated columns always evaluated even when they are not considered in a query?
April 21, 2009 2:14 PM
Subscribe
Oracle Views: Are calculated columns always evaluated even when they are not considered in a query?
I'd like some advice regarding Oracle views. Are fields always evaluated regardless of whether they are required in the results set?
Let's say I have tables PRODUCTS and ORDERS. And I create a view called PRODUCTS_VIEW which consists of something like:
SELECT
PRODUCT.ID,
PRODUCT.NAME,
fcnGetMostRecentOrderDate(PRODUCT.ID) AS MostRecentOrderDate,
fcnGetTotalOrdersCount(PRODUCT.ID) AS TotalOrdersCount,
fcnGetMaxOrderVolumn(PRODUCT.ID) AS MaxOrderVolumn
and so on
FROM
PRODUCTS,
ORDERS
I.e. a flat view that encapsulates all possible attributes--I estimate around 20 static and 60 calculated fields.
This is for reporting purposes, either queried directly or perhaps wrapped up in an API. Maintainability is important, if I need a new attribute then I can easily add a new field as necessary. Performance is certainly a factor but, since it's only for reporting purposes, there is a degree of flexibility.
If I run a query that only considers 2 or 3 fields e.g.
SELECT PRODUCT.NAME, MostRecentOrderDate
FROM PRODUCTS_VIEW
WHERE... say....CLIENT = Heinz
Would it still evaluate *all* the other calculated fields? (I think it does unfortunately: and I'm concerned that performance would degrade as new fields are added.)
If it *does* behave thus is there a way around it? I suppose a materialized view is an option. Or is this an inappropriate use? I am avoiding dynamic SQL since I would rather consolidate the logic into something that can be made (easily) accessible through ODBC, ADO, a bundle of Web Service methods etc. Note that a data warehouse approach (e.g. a daily dump of denormalised data) is not appropriate since data updates need to reflected immediately.
Thanks.
posted by NailsTheCat to computers & internet (7 comments total)
1 user marked this as a favorite
posted by spatula at 2:40 PM on April 21