I have a set of approx 1 million rows (approx rowsize: 1.5kb) that needs to be "cached" so that many different parts of our application can utilize it.
These rows are a derived/denormalized "view" of compiled data from other tables. Generating this data isn't terribly expensive (30-60sec) but is far开发者_如何学Go too slow to generate "on the fly" as part of a view or table-valued function that the application can query directly. I want to update this data periodically, perhaps every few minutes.
My first thought is to have a scheduled job that updates a global temp table with this data every n minutes.
What's the best strategy, performance-wise? I'm not sure of the performance implications of storing it in a real table versus a global temp table (##tablename) versus other strategies I haven't thought of. I don't want to muck up the transaction logs with inserts to this table... it's all derived data and doesn't need to be persisted.
I'm using Microsoft SQL Server 2000. Upgrading during the timeframe of this project isn't an option, but if there's functionality in 2005/2008/2010 that would make this easier, I'd appreciate hearing about that.
I'd recommend using a materialized view (AKA indexed view).
Limitations:
- View definition must always return the same results from the same underlying data.
- Views cannot use non-deterministic functions.
- The first index on a View must be a clustered, UNIQUE index.
- If you use Group By, you must include the new COUNT_BIG(*) in the select list.
View definition cannot contain the following:
- TOP
- Text, ntext or image columns
- DISTINCT
- MIN, MAX, COUNT, STDEV, VARIANCE, AVG
- SUM on a nullable expression
- A derived table
- Rowset function
- Another view
- UNION
- Subqueries, outer joins, self joins
- Full-text predicates like CONTAIN or FREETEXT
- COMPUTE or COMPUTE BY
- Cannot include order by in view definition
精彩评论