Materialized Query Tables (MQT) in DB2

Posted on 2010-11-10
Medium Priority
Last Modified: 2012-05-10

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.

Question by:bhagatali
  • 2
  • 2
LVL 37

Accepted Solution

momi_sabag earned 500 total points
ID: 34103427
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)
LVL 46

Expert Comment

by:Kent Olsen
ID: 34103958

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.


Author Comment

ID: 34105093
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.

LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 500 total points
ID: 34105250
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.


Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.

Join & Write a Comment

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question