Db2

Db2

Connect with Db2, Informix, Netezza, open source, and other data experts to gain value from your data, share insights, and solve problems.

 View Only
Expand all | Collapse all

Problems Refreshing an MQT

  • 1.  Problems Refreshing an MQT

    Posted 20 days ago

    In an attempt to get away from a VERY long running view, I opted to move to using an MQT, populating it with the data from that view.  However, when I try to perform the refresh, it fails with "The transaction log for the database is full".  I know how to increase the logs, and I will do so if there is no other recourse, but I thought I would ask the community if there is something better to do that what I am doing.

    This is for our Data Warehouse, and the MQT statement will gather over 112 million rows of data to refresh the table with.  That process, itself takes hours before failing.  Am I wrong?  Is there something better to do than change the View to an MQT?  I just feel that this process of refreshing the MQT is taking way to long.

    Any ideas would be very appreciated.

    (Just for added context, I have performed hours of analysis to improve the performance of the view and have added multiple indexes to improve it, but it is still horribly slow.  and unfortunately, I am running DB2 on Windows....and I am not happy about that either).



    ------------------------------
    Edward Spencer
    ------------------------------


  • 2.  RE: Problems Refreshing an MQT

    Posted 20 days ago

    You may alter your mqt to user-maintained and load it with its query with ADMIN_CMD.

    Look at the syntax with `query-statement` at the link below.

    It should help with log full...

    https://www.ibm.com/docs/en/db2/11.5.x?topic=commands-load-using-admin-cmd#sdx-synid_query-statement



    ------------------------------
    Mark Barinstein
    ------------------------------



  • 3.  RE: Problems Refreshing an MQT

    Posted 20 days ago

    You may replace the MQT with a manually maintained table (acts like a MQT), then use staging and LOAD for data refresh.



    ------------------------------
    Madhusudan S M
    ------------------------------



  • 4.  RE: Problems Refreshing an MQT

    Posted 19 days ago

    An ordinal table doesn't act as MQT.

    One of the MQT's features is an ability to automatically route original user's queries to it without an application rewrite.

    If the latest is not a big problem or db2 optimizer doesn't want to do the job correctly, or not all the desired original queries can be routed to use it, than yes, an ordinal user maintained table could be the option.



    ------------------------------
    Mark Barinstein
    ------------------------------



  • 5.  RE: Problems Refreshing an MQT

    Posted 16 days ago

    The reference was made exclusively to user-maintained MQT and not an ordinal table.



    ------------------------------
    Madhusudan S M
    ------------------------------



  • 6.  RE: Problems Refreshing an MQT

    Posted 20 days ago
    Edited by Madhusudan S M 20 days ago

    You may replace the MQT with a manually maintained table (acts like a MQT), then use staging and LOAD for  data refresh.

    LOAD is much faster because it bypasses logging 




  • 7.  RE: Problems Refreshing an MQT

    Posted 17 days ago

    Hi Edward,

    i don't have a system to test this right now, but I would try activating NOT LOGGED INITIALLY for the MQT at creation time and right before the REFRESH-statement with an ALTER TABLE command



    ------------------------------
    Miguel Sanjurjo
    Chief Database Architect
    BITMARCK Technik GmbH
    Pinneberg
    ------------------------------



  • 8.  RE: Problems Refreshing an MQT

    Posted 17 days ago

    This is something that I was thinking about using, but the issue I have is that we use HADR, and IBM states that NOT LOGGED INITIALLY should not be used if HADR is implemented.  Thank you for your thoughts though, it is very much appreciated. 

    I guess I should have added that we use HADR.

    Edward Spencer



    ------------------------------
    Edward Spencer
    ------------------------------



  • 9.  RE: Problems Refreshing an MQT

    Posted 17 days ago

    I would try and avoid NOT LOGGED INITIALLY and/or NONRECOVERABLE LOAD if you have HADR Edward. It will leave the Standby table inaccessible and it's not always easy to spot when that has happened. 

    (if you run this on your Standby, it should show where this has occurred:

    db2diag -g msg:=ADM5571W -fmt "Time: %{tsyear}-%{tsmonth}-%{tsday} %{tshour}:%{tsmin}:%{tssec} %level %appid %msg %data"

    )

    If it's an MQT then it's not such a problem, as you can drop it and recreate in the event of a failover, but I'd still avoid those situations if at all possible.

    Regards

    Mark Gillis



    ------------------------------
    Mark Gillis
    Principal Consultant
    Triton Consulting
    ------------------------------



  • 10.  RE: Problems Refreshing an MQT

    Posted 16 days ago

    HADR definitely makes this kind of stuff harder. A standard nonrecoverable LOAD is also not an option in this HADR-case, by the way...

    You could either live with the fact, that this MQT will have to be rebuilt after each HADR-takeover, or instead of refreshing a MQT decide to LOAD a table with the COPY YES option. If configured correctly, the HADR-standby node will automatically load this copy. The data will therefore be there after the takeover.

    I had good experience using TSM for that purpuse and setting DB2_LOAD_COPY_NO_OVERRIDE='COPY YES USE TSM' (or something similar to that...)



    ------------------------------
    Miguel Sanjurjo
    Chief Database Architect
    BITMARCK Technik GmbH
    Pinneberg
    ------------------------------



  • 11.  RE: Problems Refreshing an MQT

    Posted 17 days ago

    Edward,

    If your query from View is taking way too long, first thing to do would be to tune it.  If not tuned then refresh MQT will take way too long as well.  So study what is wrong with access path.  DB2 access path step cost estimates can help show where the access path is performing badly (if complex).

    Collecting Getpage numbers per object accessed can help too.

    I think the idea to make MQT not Logged is O.K. Since its only derived data, however I fear that an MQT might not be best solution. Perhaps its a last resort, attempting to bypass the problem, but I think tuning the View might will be advisable.

    I assume you plan to select from the MQT directly in place of using the View.

    More detail about the view and how it is used would help. e.g. When select from the view, do you provide filtering predicates that you hope will push down to give a good access path or its just a large 122M row extract?  When predicate push down is not working, then a Table Function with Parameters is an alternative, as those params can supply to the deep inside filtering predicates, overcoming predicate push down problems. 

    Mick Hannan (SQL Performance Specialist)



    ------------------------------
    Michael Hannan
    ------------------------------



  • 12.  RE: Problems Refreshing an MQT

    Posted 16 days ago

    Hello Edward,

    Statistical views could be an alternative option to MQT: locate bottlenecks in execution plans of heavy queries referencing the view, where the cardinalities estimated by the optimiser do not match the actual cardinalities, and create statistical views for the corresponding subqueries :

    https://www.ibm.com/docs/en/db2/12.1.0?topic=optimization-statishttps://www.ibm.com/docs/en/db2/12.1.0?topic=optimization-statistical-viewstical-views

    Hope this helps.

    Regards

    -- 

    Yves-Antoine Emmanuelli



    ------------------------------
    Yves-Antoine Emmanuelli
    ------------------------------
    -------------------------------------------
    Message d'origine:
    Envoyé: Fri June 27, 2025 09:56 AM
    Depuis: Edward Spencer
    Sujet: Problems Refreshing an MQT

    In an attempt to get away from a VERY long running view, I opted to move to using an MQT, populating it with the data from that view.  However, when I try to perform the refresh, it fails with "The transaction log for the database is full".  I know how to increase the logs, and I will do so if there is no other recourse, but I thought I would ask the community if there is something better to do that what I am doing.

    This is for our Data Warehouse, and the MQT statement will gather over 112 million rows of data to refresh the table with.  That process, itself takes hours before failing.  Am I wrong?  Is there something better to do than change the View to an MQT?  I just feel that this process of refreshing the MQT is taking way to long.

    Any ideas would be very appreciated.

    (Just for added context, I have performed hours of analysis to improve the performance of the view and have added multiple indexes to improve it, but it is still horribly slow.  and unfortunately, I am running DB2 on Windows....and I am not happy about that either).



    ------------------------------
    Edward Spencer
    ------------------------------


  • 13.  RE: Problems Refreshing an MQT

    Posted 9 days ago

    Thank you all for your input and for sharing.   I do have a lot to think about on this one, but one of the things that came to light is that many of the tables loaded in our data warehouse are loaded using "Not Recoverable",  This in mind, HADR is virtually useless to us.  We are rethinking it as well.  The development of the Data Warehouse jobs was not something I was ever a part of.  It seems many of out Data Warehouse tables are cleared out and reloaded every night rather than adding delta data.  Not happy about this.

    Anyway, thanks again.



    ------------------------------
    Edward Spencer
    ------------------------------