Materialized Query Tables (MQT) in DB2


We have a project requirement which involves writing program that run on tables that are static. Our database is subject to constant change because the website is 24*7.

The database we use is DB2 on AS400. We were told by a consulting architect that using MQT might help us achieve what we are trying to do. And it was told that using an MQT might give us better performance as well.

Since I am new to the concept of MQT, i wanted to read on how to create, use and maintain a MQT. Any pointers or documents or web links which have details on MQT will be appreciated.

Who is Participating?
momi_sabagConnect With a Mentor Commented:
although i'm not sure that this is exactly what you are looking for
MQT's should be use when you want DB2 to dynamically decide if to run your query against the base tables or against the MQT (you query is coded against the base tables).
In your case, your query should be coded against the MQT because you want a static view of the data,
so you can use any method of just freezing the data to a speceific poinit in time (by either copy it to other tables, or add a timestamp column and always get the rows up to a certain point in time)
Kent OlsenData Warehouse Architect / DBACommented:

Can you post more of your requirements?  Also, why was an MQT recommended?  An MQT can be a wonderful thing, but their use can have a significant overhead, particularly when the data is very dynamic.

Essentially, an MQT is a table that contains a snapshot (or aggregation) of part of the base table.  Every time that the table is updated the MQT is also a candidate for update.

bhagataliAuthor Commented:
Hi Kent,

The finance department in my company needs a report that can only be accurate if the data in the tables remain static. The report that is generated uses various columns from 3-4 tables. The report creation itself can take an hour or more to complete. To maintain accuracy on the report the finance team requested that we run the report on a database which doesn't change while the report is processing. With our website being 24*7, 1 hour is too big of a time frame for no changes to be occurring to the actual tables. It was then recommended that we use MQT to achieve 2 things:

1) Get a static snapshot of the columns from the tables we use.
2) Improve the overall performance of the reporting job.

Do you think the requirement warrants a look into the whole MQT thing or do you think there is a better way of doing this?

momi_sabag>> Thanks a lot for the link. The details in the link are helpful.

Kent OlsenConnect With a Mentor Data Warehouse Architect / DBACommented:
Hi Ali,

Regarding the MQT, you'll have to weigh the overhead of building it with the urgency of creating the report.  If management is prone to picking up the phone and saying "I need that report ASAP" then you certainly need to takes steps to meet that.  If the conversation goes "Can I have that report by tomorrow?" you've got a bit more flexibility.

Keep in mind that an MQT is essentially a view where the results of that view are stored in another table.  You have options regarding how the update to the MQT is done so you may be able to stagger the potentially resource-heavy update to the MQT so that it doesn't impact your production environment.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.