472,983 Members | 2,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

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 6043
On Mar 20, 9:15 am, Michael.Guppenber...@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.Guppenber...@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.DOCID 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.DOCID = 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.DOCID 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.DOCID = 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.DOCID 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.DOCID = 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.DOCID 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.DOCID = 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.DOCID AS sourceid FROM DOCUMENT document_5_0, TRE
tre_5_1, TERM term_5_2, TERM term_5_3 WHERE document_5_0.DOCID =
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.DOCID AS sourceid FROM DOCUMENT document_6_0, TRE
tre_6_1, TERM term_6_2 WHERE document_6_0.DOCID = 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.DOCID 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.DOCID = 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.DOCID 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.DOCID = 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.DOCID 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.DOCID = 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.DOCID 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.DOCID = 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.DOCID AS sourceid FROM DOCUMENT document_5_0, TRE
tre_5_1, TERM term_5_2, TERM term_5_3 WHERE document_5_0.DOCID =
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.DOCID AS sourceid FROM DOCUMENT document_6_0, TRE
tre_6_1, TERM term_6_2 WHERE document_6_0.DOCID = 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
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...
2
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...
5
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
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...
1
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...
6
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...
2
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...
0
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...
4
by: ranjithgopalan | last post by:
Please help me to delete particular column by keeping primary key
0
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:...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.