473,796 Members | 2,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keeping MQT in-sync

Hello everyone,

I am currently trying to create a materialized query table which
should be in-sync all the time. So my first attempt was to use the
"REFRESH IMMEDIATE" option of the create table statement. However, due
to the complexity of the underlying query, this is not allowed.

As performance is not an issue and I absolutely want to have the MQT
in-sync my next try was to create a trigger on the base tables of the
MQT. This trigger should have called "REFRESH TABLE" on my MQT. Again,
this did not work (the CLI did not accept my trigger definition).

The next idea was to create a stored procedure refreshing the view;
but again, this did not work although "REFRESH TABLE" is explicitly
listed as an allowed statement in stored procedures modifying sql
data.

Has anybody got an idea how to overcome these problems? I did not post
my SQL-statements on purpose because I don't want to make my question
more complicated than it is; maybe there is no solution to my problem?
If anyone has detailed ideas what the problem might be, I can post any
of my statements at any time.

Thanks in advance & regards,
Michael

Mar 20 '07 #1
8 6102
On Mar 20, 9:15 am, Michael.Guppenb er...@gmail.com wrote:
Hello everyone,

I am currently trying to create a materialized query table which
should be in-sync all the time. So my first attempt was to use the
"REFRESH IMMEDIATE" option of the create table statement. However, due
to the complexity of the underlying query, this is not allowed.

As performance is not an issue and I absolutely want to have the MQT
in-sync my next try was to create a trigger on the base tables of the
MQT. This trigger should have called "REFRESH TABLE" on my MQT. Again,
this did not work (the CLI did not accept my trigger definition).

The next idea was to create a stored procedure refreshing the view;
but again, this did not work although "REFRESH TABLE" is explicitly
listed as an allowed statement in stored procedures modifying sql
data.

Has anybody got an idea how to overcome these problems? I did not post
my SQL-statements on purpose because I don't want to make my question
more complicated than it is; maybe there is no solution to my problem?
If anyone has detailed ideas what the problem might be, I can post any
of my statements at any time.

Thanks in advance & regards,
Michael
Probably the best course of action is to identify the reason why the
MQT can't be REFRESHed IMMEDIATEly. There are many reasons why it
cannot be, but thankfully DB2 will report the specific reason when it
throws the error. If you can reply with the cause, we can possibly
find a workaround.

--Jeff

Mar 20 '07 #2
Ian
jefftyzzer wrote:
On Mar 20, 9:15 am, Michael.Guppenb er...@gmail.com wrote:
>Hello everyone,

I am currently trying to create a materialized query table which
should be in-sync all the time. So my first attempt was to use the
"REFRESH IMMEDIATE" option of the create table statement. However, due
to the complexity of the underlying query, this is not allowed.

As performance is not an issue and I absolutely want to have the MQT
in-sync my next try was to create a trigger on the base tables of the
MQT. This trigger should have called "REFRESH TABLE" on my MQT. Again,
this did not work (the CLI did not accept my trigger definition).

The next idea was to create a stored procedure refreshing the view;
but again, this did not work although "REFRESH TABLE" is explicitly
listed as an allowed statement in stored procedures modifying sql
data.

Has anybody got an idea how to overcome these problems? I did not post
my SQL-statements on purpose because I don't want to make my question
more complicated than it is; maybe there is no solution to my problem?
If anyone has detailed ideas what the problem might be, I can post any
of my statements at any time.

Thanks in advance & regards,
Michael

Probably the best course of action is to identify the reason why the
MQT can't be REFRESHed IMMEDIATEly. There are many reasons why it
cannot be, but thankfully DB2 will report the specific reason when it
throws the error. If you can reply with the cause, we can possibly
find a workaround.
I would also recommend this.

If it's not possible to create the refresh immediate MQT, and you're
willing to call 'REFRESH MQT' every time there is a change to the base
table, I'd be curious to see why? During the refresh the MQT will be
locked (i.e. unavailable for your app). If the refresh is quick this
may not be a problem, but if it is quick, I wonder if you really need
the MQT in the first place?

Also: What's the error you get when trying to call 'REFRESH TABLE'
from your stored proc? This does work fine.

Mar 20 '07 #3
Hello Ian, hello Jeff,

first of all - thank you for your quick reply. So I will go a little
more into detail here:
Probably the best course of action is to identify the reason why the
MQT can't be REFRESHed IMMEDIATEly. There are many reasons why it
cannot be, but thankfully DB2 will report the specific reason when it
throws the error. If you can reply with the cause, we can possibly
find a workaround.
The reason why i cannot have the MQT refreshed immediately is, as far
as I understand, because of the number of joins contained in the
underlying query (I hope the statement will be readable in your
newsclients...) :

CREATE TABLE V_Doc_TRE (class, sourceid, tragetid) AS(
SELECT 'DOCUMENT' AS class, DOCID AS sourceid, DOCID as targetid FROM
DOCUMENT
UNION
SELECT 'TERM' AS class,term_1_7. TERMID AS targetid ,
document_1_0.DO CID AS sourceid FROM DOCUMENT document_1_0, TRE
tre_1_1, TERM term_1_2, TERM term_1_3, TERM term_1_4, TERM term_1_5,
TERM term_1_6, TERM term_1_7 WHERE document_1_0.DO CID = tre_1_1.DOCID
AND tre_1_1.TERMID = term_1_2.TERMID AND term_1_2.PARENT =
term_1_3.TERMID AND term_1_3.PARENT = term_1_4.TERMID AND
term_1_4.PARENT = term_1_5.TERMID AND term_1_5.PARENT =
term_1_6.TERMID AND term_1_6.PARENT = term_1_7.TERMID
UNION
SELECT 'TERM' AS class,term_2_6. TERMID AS targetid ,
document_2_0.DO CID AS sourceid FROM DOCUMENT document_2_0, TRE
tre_2_1, TERM term_2_2, TERM term_2_3, TERM term_2_4, TERM term_2_5,
TERM term_2_6 WHERE document_2_0.DO CID = tre_2_1.DOCID AND
tre_2_1.TERMID = term_2_2.TERMID AND term_2_2.PARENT = term_2_3.TERMID
AND term_2_3.PARENT = term_2_4.TERMID AND term_2_4.PARENT =
term_2_5.TERMID AND term_2_5.PARENT = term_2_6.TERMID
UNION
SELECT 'TERM' AS class,term_3_5. TERMID AS targetid ,
document_3_0.DO CID AS sourceid FROM DOCUMENT document_3_0, TRE
tre_3_1, TERM term_3_2, TERM term_3_3, TERM term_3_4, TERM term_3_5
WHERE document_3_0.DO CID = tre_3_1.DOCID AND tre_3_1.TERMID =
term_3_2.TERMID AND term_3_2.PARENT = term_3_3.TERMID AND
term_3_3.PARENT = term_3_4.TERMID AND term_3_4.PARENT =
term_3_5.TERMID
UNION
SELECT 'TERM' AS class,term_4_4. TERMID AS targetid ,
document_4_0.DO CID AS sourceid FROM DOCUMENT document_4_0, TRE
tre_4_1, TERM term_4_2, TERM term_4_3, TERM term_4_4 WHERE
document_4_0.DO CID = tre_4_1.DOCID AND tre_4_1.TERMID =
term_4_2.TERMID AND term_4_2.PARENT = term_4_3.TERMID AND
term_4_3.PARENT = term_4_4.TERMID
UNION
SELECT 'TERM' AS class,term_5_3. TERMID AS targetid ,
document_5_0.DO CID AS sourceid FROM DOCUMENT document_5_0, TRE
tre_5_1, TERM term_5_2, TERM term_5_3 WHERE document_5_0.DO CID =
tre_5_1.DOCID AND tre_5_1.TERMID = term_5_2.TERMID AND term_5_2.PARENT
= term_5_3.TERMID
UNION
SELECT 'TERM' AS class,term_6_2. TERMID AS targetid ,
document_6_0.DO CID AS sourceid FROM DOCUMENT document_6_0, TRE
tre_6_1, TERM term_6_2 WHERE document_6_0.DO CID = tre_6_1.DOCID AND
tre_6_1.TERMID = term_6_2.TERMID
) DATA INITIALLY DEFERRED REFRESH IMMEDIATE
If it's not possible to create the refresh immediate MQT, and you're
willing to call 'REFRESH MQT' every time there is a change to the base
table, I'd be curious to see why? During the refresh the MQT will be
locked (i.e. unavailable for your app). If the refresh is quick this
may not be a problem, but if it is quick, I wonder if you really need
the MQT in the first place?
What I am trying to achieve with this (it is part of an academic
prototype) is that I want to precompute some "paths" in an object-
structure which will later be used to issue joins against this MQT so
that I do not have to do this path computation in every query. This is
also the reason why I do not mind about the performance of the
refresh: the object structure from which the paths will be computed
will change very infrequently, compared to the number of joins against
the MQT. So it is important to keep the MQT in-sync whenever I need
it, but I cannot predict when the base-tables will change so I want
the DB to keep it in sync instead of regularily issuing "REFRESH"-
commands from the "outside". Since my approach should be independent
of the application, there is also no way to change the application
(which might know when base-tables are updated) and make it update the
MQT.
Also: What's the error you get when trying to call 'REFRESH TABLE'
from your stored proc? This does work fine.
My first try was to install the following trigger (yes, '@' is
configured as delimiter in CLI :)):

CREATE TRIGGER updateView AFTER INSERT ON TERM
FOR EACH STATEMENT
MODE DB2SQL
BEGIN ATOMIC
REFRESH TABLE V_Doc_TRE;
END@

which gives me a

sqlcode : -104
sqlstate : 42601

Then I tried to create the stored procedure and call that procedure
from a similar trigger:

CREATE PROCEDURE refreshView ()
LANGUAGE SQL
MODIFIES SQL DATA
BEGIN
REFRESH TABLE V_Doc_TRE;
END@

which again leads to

sqlcode : -104
sqlstate : 42601

I always thought there was a semantic problem with this procedure, but
if it works for you, Ian, maybe there is just some syntactic mistake?

Thanks again,
Michael

Mar 21 '07 #4
No ideas? Starts getting urgent for me ...

Regards,
Michael

Mar 23 '07 #5
Mi************* *****@gmail.com wrote:
Hello Ian, hello Jeff,

first of all - thank you for your quick reply. So I will go a little
more into detail here:
Probably the best course of action is to identify the reason why the
MQT can't be REFRESHed IMMEDIATEly. There are many reasons why it
cannot be, but thankfully DB2 will report the specific reason when it
throws the error. If you can reply with the cause, we can possibly
find a workaround.

The reason why i cannot have the MQT refreshed immediately is, as far
as I understand, because of the number of joins contained in the
underlying query (I hope the statement will be readable in your
newsclients...) :
I dont think that is the problem. I think you will need an aggregate (
and I think it will have to be count(*) ), if you want refresh
immediate. Atleast that was the case with V8. Try the following and see
if it works ( not saying that it is a good idea though )
CREATE TABLE V_Doc_TRE (class, sourceid, tragetid) AS(
select class,sourceid, targetid, count(*) from (
SELECT 'DOCUMENT' AS class, DOCID AS sourceid, DOCID as targetid FROM
DOCUMENT
UNION
SELECT 'TERM' AS class,term_1_7. TERMID AS targetid ,
document_1_0.DO CID AS sourceid FROM DOCUMENT document_1_0, TRE
tre_1_1, TERM term_1_2, TERM term_1_3, TERM term_1_4, TERM term_1_5,
TERM term_1_6, TERM term_1_7 WHERE document_1_0.DO CID = tre_1_1.DOCID
AND tre_1_1.TERMID = term_1_2.TERMID AND term_1_2.PARENT =
term_1_3.TERMID AND term_1_3.PARENT = term_1_4.TERMID AND
term_1_4.PARENT = term_1_5.TERMID AND term_1_5.PARENT =
term_1_6.TERMID AND term_1_6.PARENT = term_1_7.TERMID
UNION
SELECT 'TERM' AS class,term_2_6. TERMID AS targetid ,
document_2_0.DO CID AS sourceid FROM DOCUMENT document_2_0, TRE
tre_2_1, TERM term_2_2, TERM term_2_3, TERM term_2_4, TERM term_2_5,
TERM term_2_6 WHERE document_2_0.DO CID = tre_2_1.DOCID AND
tre_2_1.TERMID = term_2_2.TERMID AND term_2_2.PARENT = term_2_3.TERMID
AND term_2_3.PARENT = term_2_4.TERMID AND term_2_4.PARENT =
term_2_5.TERMID AND term_2_5.PARENT = term_2_6.TERMID
UNION
SELECT 'TERM' AS class,term_3_5. TERMID AS targetid ,
document_3_0.DO CID AS sourceid FROM DOCUMENT document_3_0, TRE
tre_3_1, TERM term_3_2, TERM term_3_3, TERM term_3_4, TERM term_3_5
WHERE document_3_0.DO CID = tre_3_1.DOCID AND tre_3_1.TERMID =
term_3_2.TERMID AND term_3_2.PARENT = term_3_3.TERMID AND
term_3_3.PARENT = term_3_4.TERMID AND term_3_4.PARENT =
term_3_5.TERMID
UNION
SELECT 'TERM' AS class,term_4_4. TERMID AS targetid ,
document_4_0.DO CID AS sourceid FROM DOCUMENT document_4_0, TRE
tre_4_1, TERM term_4_2, TERM term_4_3, TERM term_4_4 WHERE
document_4_0.DO CID = tre_4_1.DOCID AND tre_4_1.TERMID =
term_4_2.TERMID AND term_4_2.PARENT = term_4_3.TERMID AND
term_4_3.PARENT = term_4_4.TERMID
UNION
SELECT 'TERM' AS class,term_5_3. TERMID AS targetid ,
document_5_0.DO CID AS sourceid FROM DOCUMENT document_5_0, TRE
tre_5_1, TERM term_5_2, TERM term_5_3 WHERE document_5_0.DO CID =
tre_5_1.DOCID AND tre_5_1.TERMID = term_5_2.TERMID AND term_5_2.PARENT
= term_5_3.TERMID
UNION
SELECT 'TERM' AS class,term_6_2. TERMID AS targetid ,
document_6_0.DO CID AS sourceid FROM DOCUMENT document_6_0, TRE
tre_6_1, TERM term_6_2 WHERE document_6_0.DO CID = tre_6_1.DOCID AND
tre_6_1.TERMID = term_6_2.TERMID
) X (class,sourceid ,targetid)
) DATA INITIALLY DEFERRED REFRESH IMMEDIATE

/Lennart

Mar 24 '07 #6
Lennart wrote:
Mi************* *****@gmail.com wrote:
>Hello Ian, hello Jeff,

first of all - thank you for your quick reply. So I will go a little
more into detail here:
>Probably the best course of action is to identify the reason why the
MQT can't be REFRESHed IMMEDIATEly. There are many reasons why it
cannot be, but thankfully DB2 will report the specific reason when it
throws the error. If you can reply with the cause, we can possibly
find a workaround.

The reason why i cannot have the MQT refreshed immediately is, as far
as I understand, because of the number of joins contained in the
underlying query (I hope the statement will be readable in your
newsclients... ):

I dont think that is the problem. I think you will need an aggregate (
and I think it will have to be count(*) ), if you want refresh
immediate. Atleast that was the case with V8.
You could use a REPLICATED MQT without aggregates.

--
Knut Stolze
DB2 z/OS Utilities Development
IBM Germany
Mar 25 '07 #7
Unfortunately, none of your proposals (adding aggregates, using
replicated MQT) did work for me. Instead of focusing on how to get the
MQT "refreshed immediate", I would rather like to find out why my
stored procedure refreshing the table cannot be issued.. Any ideas
about that?

This

CREATE PROCEDURE refreshView ()
LANGUAGE SQL
MODIFIES SQL DATA
BEGIN
REFRESH TABLE V_Doc_TRE;
END@

does not work, as I mentioned above, and I do not know why ...

Regards,
Michael

Mar 26 '07 #8
I think I found a solution. Instead of writing a SQL-Stored Procedure,
I embedded the "REFRESH TABLE"-statement into an external procedure
written in Java which can then be called from the respective trigger.
I still have to test it, but I think it should work.

Thanks to all who answered.

Regards,
Michael

Mar 28 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3082
by: Lian | last post by:
Hi all, i find that when i widen a image,the height of the image become larger too. How can i make the image wider without keeping the scale, which means the height keep unchanged. Thank you for suggestions.
2
2699
by: Raja Kannan | last post by:
Is there a way to remove text portion from the HTML keeping the HTML Tags using the browser, say javascript RegEx or something ? I have seen lot of examples removing HTML tags to get the text but how the reverse of it ? any sample code or any suggestion would be appreciated.
5
1658
by: Mike Turco | last post by:
I've been upgrading since VB3 and Access 2. How long do I have to keep these CD's around as proof of valid licensing?
2
11759
by: bobh | last post by:
Hi All, I have a report which has several sub-reports on it, Each sub-report has its own record source and child/parent link. Sometimes a sub-report may not have data for an entered policy nbr and on the report thier is just an empty space where that sub-report would be when that happens. How do I get the sub-report to still display on the report when it has no data????
1
1206
by: Jason James | last post by:
Hi All, I have created a class that references MS Word. The class will happily control Word, adding text, etc. However, when I have finished with the VB app I want to close the app, but not Word so that user can continue on their own.
6
13816
by: laredotornado | last post by:
Hello, Assuming I have the functions, "isNumber" and "isEmpty", how would I write the HTML INPUT type="text" element such that a person cannot exit the element unless they have typed in a valid number (as defined by the function isNumber) or left the field empty (as defined by isEmpty)? Thus, if they have typed in "aaa" and then pressed "Tab" to go the next element, they'd get a warning message, and be returned to the old element? ...
2
2769
by: metaperl | last post by:
I'm actually taking Microsoft's 2779 and just finished a lab where we kept track of our changes to the database. However, I'm not happy with the scripts interface because it does not tell me the chronological order of my changes to the database. Could someone share with me their technique for keeping track of database changes? I'm actually thinking a set of tables would be best, because sometimes
0
1442
by: NSD | last post by:
Which Oracle program to use for adminitration and book-keeping Hello there, I am new to Oracle and I need to know how I can insert my company's data (administration and book - keeping) into an Oracle program. I have the Oracle Database Express Edition demo version, but I cannot do anything with that. It is, I believe, a program for emplyees data, which I don't need at the moment. Which program can I choose from Oracle to do these two...
4
2984
by: ranjithgopalan | last post by:
Please help me to delete particular column by keeping primary key
0
942
by: bruce | last post by:
hi jackie, if you don't mind... can i ask what you're looking to accomplish? are you looking to simply get the text/string data, or something else??? -----Original Message----- From: python-list-bounces+bedouglas=earthlink.net@python.org On Behalf
0
9530
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.