Edin I. Aganagic shares his tips on how to increase incremental refresh/maintenance performance of MQTs in DB2.
- Create an index on the GROUP BY columns. It helps speed up MQT look-ups needed to decide whether existing row needs to be changed, new one inserted, or last one deleted
- If not aggregating, create the index on the set of columns that form a unique key usually by concatenating the unique key columns of the individual base tables.
- If possible, define the base table columns used in the GROUP BY clause of REFRESH IMMEDIATE MQTs as NOT NULL makes finding matching rows in the MQT easier
- Define RI relationships wherever applicable allows various loss-less join specific optimizations (even not enforced)
- Always keep the base table and MQT statistics up-to-date and it helps the optimizer choose an optimal access plan