Materialized Views - 2
The other day I was asked about the approach I took to refreshing materialized views. To be honest I use my own techniques - others do similar things.
In a data warehouse summary table very little actually changes; there is perhaps a small window were new data is added, but even allowing for late arriving data the vast majority of data is unchanging. Perhaps this is untrue with type 1 SCD summaries where items may migrate between parents, but the SC part of SCD is slowly changing so this may not occur that often.
In the data warehouses I run, we tend to rely heavily on range partitioning on date. This gives improved maintainability, and perhaps more importantly allows us to use partition elimination to boost query performance by reducing the amount of data to be manipulated. It is also the key to the way we maintain mviews. We simply do the following for each partition to be refreshed:
- Truncate partition
- Make bitmap indexes unusable
- Append into now empty partition
- Rebuild unusable indexes
- it removes the need to construct denormailsed reference data tables for the higher level aggregations - query rewrite requires a FK relationship between reference and fact
- it allows all of the summaries to be considered for rewrite - in nesting only the first tier summaries are considered and then the rewritten query tested for rewrite against the next tier, but what if the best first tier query did not lead to best overall? We use the wrong summary